Java Code Examples for java.awt.Dimension.getWidth()

The following are Jave code examples for showing how to use getWidth() of the java.awt.Dimension class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: iiif-apis   File: SizeRequest.java   View Source Code Vote up 6 votes
/**
 * Get the canonical form of this request.
 *
 * @See http://iiif.io/api/image/2.1/#canonical-uri-syntax
 */
public String getCanonicalForm(Dimension nativeSize, ImageApiProfile profile) {
  Dimension resolved = this.resolve(nativeSize, profile);
  // "w," requests are already canonical
  double nativeRatio = nativeSize.getWidth() / nativeSize.getHeight();
  double resolvedRatio = resolved.getWidth() / resolved.getHeight();
  if (resolved.equals(nativeSize)) {
    return "full";
  } else if (this.width != null && this.height == null) {
    return this.toString();
  } else if (Math.floor(resolvedRatio * nativeSize.getHeight()) == nativeSize.getWidth() ||
             Math.ceil(resolvedRatio * nativeSize.getHeight()) == nativeSize.getWidth()) {
    return String.format("%d,", resolved.width);
  } else {
    return String.format("%d,%d", resolved.width, resolved.height);
  }
}
 
Example 2
Project: ramus   File: PrintPreviewComponent.java   View Source Code Vote up 6 votes
public void setFitZoom(Dimension size) {
    Dimension2D pageSize = getPageSize();
    int pageCount = printable.getPageCount();
    if (pageCount == 0)
        return;
    double xy = (pageSize.getWidth() + W_SPACE)
            * (pageSize.getHeight() + W_SPACE) * (pageCount + 1);
    double mxy = size.getWidth() * size.getHeight();
    double zoom = Math.sqrt(mxy / xy);
    int columnCount = (int) (size.getWidth() / ((pageSize.getWidth() + W_SPACE
            / zoom) * zoom));
    if (columnCount <= 0)
        columnCount = 1;
    if (columnCount > pageCount)
        columnCount = pageCount;
    setup(columnCount, zoom);
}
 
Example 3
Project: incubator-netbeans   File: CustomizerPane.java   View Source Code Vote up 6 votes
public Dimension getPreferredSize() {
    if (isPreferredSizeSet()) {
        return super.getPreferredSize();
    }
    
    int height = Math.max(500, currentCustomizer.getPreferredSize().height + 50);
    int width = Math.max(800, currentCustomizer.getPreferredSize().width + 240);
    
    Dimension dim = super.getPreferredSize();
    if (dim == null) {
        return new Dimension(width, height);
    }
    if (dim.getWidth() < width || dim.getHeight() < height) {
        return new Dimension(width, height);
    }
    
    if (dim.getWidth() > MAX_WIDTH) {
        dim.width = MAX_WIDTH;
    }
    if (dim.getHeight() > MAX_HEIGHT) {
        dim.height = MAX_HEIGHT;
    }
    return dim;
}
 
Example 4
Project: incubator-netbeans   File: DragWindow.java   View Source Code Vote up 6 votes
private BufferedImage createContentImage( Component c, Dimension contentSize ) {
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    BufferedImage res = config.createCompatibleImage(contentSize.width, contentSize.height);
    Graphics2D g = res.createGraphics();
    //some components may be non-opaque so just black rectangle would be painted then
    g.setColor( Color.white );
    g.fillRect(0, 0, contentSize.width, contentSize.height);
    if( WinSysPrefs.HANDLER.getBoolean(WinSysPrefs.DND_SMALLWINDOWS, true) && c.getWidth() > 0 && c.getHeight() > 0 ) {
        double xScale = contentSize.getWidth() / c.getWidth();
        double yScale = contentSize.getHeight() / c.getHeight();
        g.setTransform(AffineTransform.getScaleInstance(xScale, yScale) );
    }
    c.paint(g);
    return res;
}
 
Example 5
Project: jmt   File: Mediator.java   View Source Code Vote up 6 votes
/**
 * Selects the specified cell and initiates editing.
 * The edit-attempt fails if the <code>CellEditor</code>
 * does not allow
 * editing for the specified item.
 */
public void startEditingAtCell(Object cell) {
	graph.startEditingAtCell(cell);
	if ((cell != null) && (cell instanceof JmtCell)) {
		JmtCell jcell = (JmtCell) cell;
		showStationParameterPanel(((CellComponent) jcell.getUserObject()).getKey(),
				StationParameterPanel.INPUT_SECTION, null);
		// Updates cell dimensions if name was changed too much...
		Hashtable<Object, Map> nest = new Hashtable<Object, Map>();
		Dimension cellDimension = jcell.getSize(graph);
		Map attr = jcell.getAttributes();
		Rectangle2D oldBounds = GraphConstants.getBounds(attr);
		if (oldBounds.getWidth() != cellDimension.getWidth()) {
			GraphConstants.setBounds(attr, new Rectangle2D.Double(oldBounds.getX(), oldBounds.getY(),
					cellDimension.getWidth(), cellDimension.getHeight()));
			nest.put(cell, attr);
			jcell.updatePortPositions(nest, GraphConstants.getIcon(attr), cellDimension);
			graph.getGraphLayoutCache().edit(nest);
		}
	}
	// Blocking region editing
	else if ((cell != null) && (cell instanceof BlockingRegion)) {
		showBlockingRegionParameterPanel(((BlockingRegion) cell).getKey());
	}
}
 
Example 6
Project: defense-solutions-proofs-of-concept   File: Utilities.java   View Source Code Vote up 5 votes
/**
 * Rescales an icon.
 * @param src the original icon.
 * @param newMinSize the minimum size of the new icon. The width and height of
 *                   the returned icon will be at least the width and height
 *                   respectively of newMinSize.
 * @param an ImageObserver.
 * @return the rescaled icon.
 */
public static ImageIcon rescale(ImageIcon src, Dimension newMinSize, ImageObserver observer) {
    double widthRatio =  newMinSize.getWidth() / (double) src.getIconWidth();
    double heightRatio = newMinSize.getHeight() / (double) src.getIconHeight();
    double scale = widthRatio > heightRatio ? widthRatio : heightRatio;
    
    int w = (int) Math.round(scale * src.getIconWidth());
    int h = (int) Math.round(scale * src.getIconHeight());
    BufferedImage dst = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = dst.createGraphics();
    g2.drawImage(src.getImage(), 0, 0, w, h, observer);
    g2.dispose();
    return new ImageIcon(dst);
}
 
Example 7
Project: KernelHive   File: InfrastructureGraphPanel.java   View Source Code Vote up 5 votes
public void releayout() {
	mxHierarchicalLayout layout = new mxHierarchicalLayout(graph, SwingConstants.NORTH);
	layout.execute(graph.getDefaultParent());

	mxRectangle graphSize = graph.getGraphBounds();
	Dimension viewPortSize = graphComponent.getViewport().getSize();

	double ratiox = viewPortSize.getWidth() / graphSize.getWidth();
	double ratioy = viewPortSize.getHeight() / graphSize.getHeight();
	double ratio = ratiox < ratioy ? ratiox : ratioy;

	graphComponent.zoom(ratio);
}
 
Example 8
Project: ramus   File: PrintPreviewComponent.java   View Source Code Vote up 5 votes
public void setFitZoom(double zoom, Dimension size) {
    if (zoom > 10)
        zoom = 10;
    if (zoom < 0.1)
        zoom = 0.1;
    int columnCount = 1;
    Dimension2D pageSize = getPageSize();
    while (((pageSize.getWidth() + W_SPACE / zoom) * columnCount + pageSize
            .getWidth()) * zoom < size.getWidth()) {
        columnCount++;
    }
    setup(columnCount, zoom);
}
 
Example 9
Project: AgentWorkbench   File: MainWindow.java   View Source Code Vote up 5 votes
/**
 * Return the size in relation (scaled) to the screen size.
 */
private Dimension getSizeRelatedToScreenSize() {
	// --- Default size ---------------------
	Dimension frameSize = new Dimension(1150, 640);

	// --- Scale relative to screen ---------
	double scale = 0.9;
	Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
	int frameWidth = (int) (screenDimension.getWidth() * scale);
	int frameHeight = (int) (screenDimension.getHeight() * scale);
	frameSize.setSize(frameWidth, frameHeight);

	return frameSize;
}
 
Example 10
Project: AgentWorkbench   File: ChangeDialog.java   View Source Code Vote up 5 votes
/**
 * This method initializes this.
 * @return void
 */
private void initialize() {
	
	String title = Language.translate("Letzte Änderungen") + " - ";
	title += Application.getGlobalInfo().getVersionInfo().getFullVersionInfo(true, null);
	this.setTitle(title);
	
	this.setIconImage(GlobalInfo.getInternalImage("AgentGUI.png"));
	this.setSize(850, 550);
	this.setModal(true);
	this.setResizable(true);
	this.setContentPane(getJContentPane());
	this.registerEscapeKeyStroke();
	
	// --- Set the Look and Feel of the Dialog ------------------
	this.setLookAndFeel();

	// --- Center dialog ----------------------------------------
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 
	Double newWidth  = screenSize.getWidth()  * 0.7;
	Double newHeight = screenSize.getHeight() * 0.8;
	int top  = (screenSize.height - newHeight.intValue()) / 2; 
    int left = (screenSize.width  - newWidth.intValue()) / 2;
    this.setSize(newWidth.intValue(), newHeight.intValue());
    this.setLocation(left, top);
	
}
 
Example 11
Project: QN-ACTR-Release   File: Mediator.java   View Source Code Vote up 5 votes
/**
 * Selects the specified cell and initiates editing.
 * The edit-attempt fails if the <code>CellEditor</code>
 * does not allow
 * editing for the specified item.
 */
public void startEditingAtCell(Object cell) {
	graph.startEditingAtCell(cell);
	if ((cell != null) && (cell instanceof JmtCell)) {
		JmtCell jcell = (JmtCell) cell;
		StationParameterPanel stationPanel = new jmt.gui.common.panels.StationParameterPanel(model, model,
				((CellComponent) jcell.getUserObject()).getKey());
		// Adds on the top a panel to change station name
		stationPanel.add(new StationNamePanel(model, ((CellComponent) jcell.getUserObject()).getKey()), BorderLayout.NORTH);
		dialogFactory.getDialog(stationPanel, "Editing " + jcell.getUserObject().toString() + " Properties...");

		// Updates cell dimensions if name was changed too much...
		Hashtable<Object, Map> nest = new Hashtable<Object, Map>();
		Dimension cellDimension = jcell.getSize(graph);
		Map attr = jcell.getAttributes();
		Rectangle2D oldBounds = GraphConstants.getBounds(attr);
		if (oldBounds.getWidth() != cellDimension.getWidth()) {
			GraphConstants.setBounds(attr, new Rectangle2D.Double(oldBounds.getX(), oldBounds.getY(), cellDimension.getWidth(), cellDimension
					.getHeight()));
			nest.put(cell, attr);
			jcell.updatePortPositions(nest, GraphConstants.getIcon(attr), cellDimension);
			graph.getGraphLayoutCache().edit(nest);
		}
	}
	// Blocking region editing
	else if ((cell != null) && (cell instanceof BlockingRegion)) {
		Object regionKey = ((BlockingRegion) cell).getKey();
		dialogFactory.getDialog(new BlockingRegionParameterPanel(model, model, regionKey), "Editing " + model.getRegionName(regionKey)
				+ " Properties...");
	}
}
 
Example 12
Project: rapidminer   File: ProcessRendererController.java   View Source Code Vote up 5 votes
/**
 * Ensures that the process is at least width wide.
 *
 * @param executionUnit
 *            the process to ensure the minimum width
 * @param width
 *            the mininum width
 */
void ensureWidth(final ExecutionUnit executionUnit, final int width) {
	Dimension old = new Dimension((int) model.getProcessWidth(executionUnit),
			(int) model.getProcessHeight(executionUnit));
	if (width > old.getWidth()) {
		model.setProcessWidth(executionUnit, width);
		balance();
		model.fireProcessSizeChanged();
	}
}
 
Example 13
Project: parabuild-ci   File: PaletteSample.java   View Source Code Vote up 5 votes
/**
 * Draws the sample.
 *
 * @param g  the graphics device.
 */
public void paintComponent(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(
        RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF
    );
    Dimension size = getSize();
    Insets insets = getInsets();
    double ww = size.getWidth() - insets.left - insets.right;
    double hh = size.getHeight() - insets.top - insets.bottom;

    g2.setStroke(new BasicStroke(1.0f));

    double y1 = insets.top;
    double y2 = y1 + hh;
    double xx = insets.left;
    Line2D line = new Line2D.Double();
    int count = 0;
    while (xx <= insets.left + ww) {
        count++;
        line.setLine(xx, y1, xx, y2);
        g2.setPaint(this.palette.getColor(count));
        g2.draw(line);
        xx += 1;
    }
}
 
Example 14
Project: Hydrograph   File: ComponentFigure.java   View Source Code Vote up 4 votes
private void showStatusToolTip(org.eclipse.swt.graphics.Point location) {

		if (!componentCanvas.isFocused())
			return;

		componentCanvas = getComponentCanvas();
		if (componentCanvas.getComponentTooltip() == null) {
			componentToolTip = getStatusToolTip(componentCanvas.getCanvasControl().getShell(), location);
			componentBounds = getComponentBounds();
			componentCanvas.issueToolTip(componentToolTip, componentBounds);

			componentToolTip.setVisible(true);
			setStatusToolTipFocusListener();
			org.eclipse.swt.graphics.Point tooltipSize = componentToolTip.computeSizeHint();
			// componentToolTip.setSizeConstraints(300, 100);
			if (tooltipSize.x > 300) {
				tooltipSize.x = 300;
			}
			componentToolTip.setSize(tooltipSize.x, tooltipSize.y);

			Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			double width = screenSize.getWidth();
			double height = screenSize.getHeight();

			int newX, newY;
			int offset = 10;
			if ((componentToolTip.getBounds().x + componentToolTip.getBounds().width) > width) {
				newX = componentToolTip.getBounds().x
						- (int) ((componentToolTip.getBounds().x + componentToolTip.getBounds().width) - width)
						- offset;
			} else {
				newX = componentToolTip.getBounds().x;
			}

			if ((componentToolTip.getBounds().y + componentToolTip.getBounds().height) > height) {
				newY = componentToolTip.getBounds().y - getBounds().height - componentToolTip.getBounds().height
						- offset;
			} else {
				newY = componentToolTip.getBounds().y;
			}
			org.eclipse.swt.graphics.Point newLocation = new org.eclipse.swt.graphics.Point(newX, newY);
			componentToolTip.setLocation(newLocation);

		}
	}
 
Example 15
Project: NoMoreOversleeps   File: WebcamCapture.java   View Source Code Vote up 4 votes
static WebcamData initCamera(String cc, String camName)
{
	LinkedHashMap<String, Webcam> detectedCameras = new LinkedHashMap<String, Webcam>();
	List<Webcam> cams = Webcam.getWebcams();
	Webcam webcam = null;
	for (Webcam cam : cams)
	{
		detectedCameras.put(cam.getName(), cam);
		if (cam.getName().startsWith(camName))
		{
			webcam = cam;
		}
	}
	if (webcam == null)
	{
		throw new WebcamInitException("Webcam listed in config was not found: " + camName);
	}
	WebcamData data = new WebcamData(cc, webcam);
	webcam.setImageTransformer(new WebcamTransformer());
	log.info("Initializing webcam: " + camName);
	Dimension[] sizes = webcam.getViewSizes();
	Dimension dimension = null;
	for (Dimension d : sizes)
	{
		log.info("Found image dimension: " + d.getWidth() + "x" + d.getHeight());
		if (d.getWidth() == 320)
		{
			dimension = d;
		}
	}
	if (dimension == null)
	{
		dimension = sizes[0];
	}
	log.info("Selected image dimension: " + dimension.getWidth() + "x" + dimension.getHeight());
	if (!webcam.getViewSize().equals(dimension))
	{
		webcam.setViewSize(dimension);
	}
	webcam.open(true);
	webcam.addWebcamListener(data);
	System.out.println(webcam.getViewSize());
	((WebcamDefaultDevice) webcam.getDevice()).FAULTY = false;
	return data;
}
 
Example 16
Project: FizeauExperimentSimulation   File: Frame.java   View Source Code Vote up 4 votes
public Frame() throws HeadlessException {

		super("Symulacja Efektu Fizeau");

		try {
			UIManager.setLookAndFeel(
					UIManager.getSystemLookAndFeelClassName());

		} catch (Exception e1) {

			e1.printStackTrace();
			System.out.println("błąd LF");
		}
		SwingUtilities.updateComponentTreeUI(Frame.this);

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		WIDTH = screenSize.getWidth();
		HEIGHT = screenSize.getHeight();

		setExtendedState(MAXIMIZED_BOTH); 
		setUndecorated(false);
		setPreferredSize(new Dimension((int)WIDTH,(int)HEIGHT));
		//setResizable(false);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setBackground(Color.WHITE);
		setLayout(new BorderLayout());

		chooser = new JFileChooser();

		this.animation = new AnimationPanel(200,500,5000,WIDTH,HEIGHT);
		this.bottom = new BottomPanel();

		this.add(this.animation, BorderLayout.CENTER);
		this.add(this.bottom, BorderLayout.SOUTH);
		pack();

		this.bottom.runButtonPanel.runButton.addActionListener(new RunButtonListener(this));
		this.bottom.settings.velSlider.addChangeListener(new SliderListener(this));
		this.bottom.runButtonPanel.fizeauButton.addActionListener(new FizeauButtonListener(this));
		this.bottom.settings.distance.addItemListener(new DistanceListener(this));
		this.bottom.settings.nTeeth.addItemListener(new ToothListener(this));
		this.bottom.runButtonPanel.saveButton.addActionListener(new SaveButtonListener(this));
	}
 
Example 17
Project: PictureTravelSuite   File: PictureTravelSuiteClass.java   View Source Code Vote up 4 votes
private void WatermarkCommand(String workingFile, Point offsetCorner) {
	if (!isRunning)
		return;
	addToLog("Adding watermark to " + workingFile, false);

	String[] command;
	String tmpdata;

	Dimension imgSize = GetImageSize(workingFile, picture_folderOutput);

	float dimension = (int) Max((float) imgSize.getWidth(),
			(float) imgSize.getHeight());

	dimension = (float) (((float) dimension) / 100.0
			* ((float) picture_watermarkSize.getSelectedItem()));
	dimension = (float) ((dimension < 15) ? 15.0 : dimension);

	String watermark = copyrightSymbol + " " + picture_photographerText.getText();
	command = new String[]{cmdExecutables.get("exiftool").toString(), "-d",
			"%Y", "-DateTimeOriginal", "-S", "-s",
			picture_folderOutput + File.separator + workingFile};

	tmpdata = executeCommand(command);
	watermark += (!tmpdata.isEmpty()) ? (" | " + tmpdata) : ("");

	float scaleFactor[] = {1, 1};
	switch (GetShape(imgSize)) {
		case 1 : // Horizontal
			scaleFactor[0] += (float) 0.1 * imgSize.getWidth()
					/ imgSize.getHeight();
			scaleFactor[1] += (float) 0.1 * imgSize.getHeight()
					/ imgSize.getWidth();
			break;
		case -1 : // Vertical
			scaleFactor[0] += (float) 0.1 * imgSize.getWidth()
					/ imgSize.getHeight();
			scaleFactor[1] += (float) 0.1 * imgSize.getHeight()
					/ imgSize.getWidth();
			break;
		default : // Square
			scaleFactor[0] += (float) 0.1;
			scaleFactor[1] += (float) 0.1;
			break;
	}
	offsetCorner = ScalePoint(offsetCorner, scaleFactor);

	String offset = GetOffset(
			picture_watermarkPosition.getSelectedItem().toString(), offsetCorner);

	try {
		command = new String[]{cmdExecutables.get("convert").toString(),
				picture_folderOutput + File.separator + workingFile, "-font",
				ExportResource(picture_watermarkFontArray
						.get(picture_watermarkFont.getSelectedIndex())),
				"-pointsize", Float.toString(dimension), "-gravity",
				picture_watermarkPosition.getSelectedItem().toString(), "-stroke",
				"#000C", "-strokewidth",
				Float.toString((float) (dimension / 10.0)), "-annotate",
				offset, watermark, "-stroke", "none", "-fill", "white",
				"-annotate", offset, watermark,
				picture_folderOutput + File.separator + workingFile};
		executeCommand(command);
	} catch (Exception e) {
		addToLog(e.getMessage(), Color.RED, false);
	}
}
 
Example 18
Project: Equella   File: CustomLinksSection.java   View Source Code Vote up 4 votes
@EventHandlerMethod
public void upload(SectionContext context, boolean onSave) throws IOException
{
	CustomLinksModel model = getModel(context);
	CustomLinkEditingSession session = linkService.loadSession(model.getSessionId());
	final CustomLinkEditingBean bean = session.getBean();

	if( Check.isEmpty(file.getFilename(context)) || file.getFileSize(context) <= 0 )
	{
		if( onSave )
		{
			session.getValidationErrors().remove("upload");
			return;
		}
		session.getValidationErrors().put("upload",
			CurrentLocale.get("com.tle.web.customlinks.edit.upload.error.empty"));
		return;
	}
	removeIcon(context);

	StagingFile stagingFile = new StagingFile(session.getPack().getStagingID());
	String filename = file.getFilename(context);
	String tempFilename = "TEMP-" + filename;
	try( InputStream stream = file.getInputStream(context) )
	{
		fileSystemService.write(stagingFile, tempFilename, stream, false);

		if( !imageMagickService.supported(mimeTypeService.getMimeTypeForFilename(filename)) )
		{
			session.getValidationErrors().put("upload",
				CurrentLocale.get("com.tle.web.customlinks.edit.upload.error.unsupported"));
			return;
		}
		Dimension dimensions = imageMagickService.getImageDimensions(stagingFile, tempFilename);
		if( dimensions.getHeight() > 20 || dimensions.getWidth() > 20 )
		{
			File temp = fileSystemService.getExternalFile(stagingFile, tempFilename);
			File newFile = fileSystemService.getExternalFile(stagingFile, filename);
			imageMagickService.sample(temp, newFile, String.valueOf(20), String.valueOf(20));
		}
		else
		{
			fileSystemService.copy(stagingFile, tempFilename, filename);
		}
		fileSystemService.removeFile(stagingFile, tempFilename);
	}

	bean.setFileName(filename);
	session.getValidationErrors().remove("upload");
}
 
Example 19
Project: rapidminer   File: ProcessRendererModel.java   View Source Code Vote up 3 votes
/**
 * Returns the width of the given process. Convenience method which simply returns the width of
 * {@link #getProcessSize(ExecutionUnit)}.
 *
 * @param process
 *            the process for which the width should be returned
 * @return the width or -1 if no process size has been stored
 */
public double getProcessWidth(ExecutionUnit process) {
	Dimension dim = processSizes.get(process);
	if (dim == null) {
		return -1;
	}
	return dim.getWidth();
}
 
Example 20
Project: incubator-netbeans   File: WizardUtils.java   View Source Code Vote up 2 votes
/**
 * @param icon file representing icon
 * @param expectedWidth expected width
 * @param expectedHeight expected height
 * @return true if icon corresponds to expected dimension
 */
public static boolean isValidIcon(final File icon, int expectedWidth, int expectedHeight) {
    Dimension iconDimension = getIconDimension(icon);
    return (expectedWidth == iconDimension.getWidth() &&
            expectedHeight == iconDimension.getHeight());
}