Java Code Examples for java.awt.Dimension#getHeight()

The following examples show how to use java.awt.Dimension#getHeight() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
void setScaledImage(final Dimension rect) {

        // fit to rect whilst retaining aspect ratio.
        final double widthRatio = rect.getWidth() / origImage.getWidth();
        final double heightRatio = rect.getHeight() / origImage.getHeight();
        final double aspectRatio = Math.min(widthRatio, heightRatio);

        scaledImage = ImageHelper.scale(
            origImage,
            (int) (origImage.getWidth() * aspectRatio),
            (int) (origImage.getHeight() * aspectRatio),
            isHighQuality
                ? RenderingHints.VALUE_INTERPOLATION_BILINEAR
                : RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,
            isHighQuality
        );
    }
 
Example 2
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
/**
 * Some quick and dirty image scaling - please note that for best performance
 * and quality you should use image rescaling libraries.
 */
@Override
public BufferedImage resample(BufferedImage bufferedImage, int width, int height) {

    Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
    Dimension boundaryDimension = new Dimension(width, height);
    Dimension scaledDimension = BufferedImageUtils.getScaledDimension(imageDimension, boundaryDimension);

    double scaleX = scaledDimension.getWidth() / bufferedImage.getWidth();
    double scaleY = scaledDimension.getHeight() / bufferedImage.getHeight();

    AffineTransform scaleTransform = AffineTransform.getScaleInstance(scaleX, scaleY);
    AffineTransformOp biLinearScaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);

    return biLinearScaleOp.filter(
            bufferedImage,
            new BufferedImage(scaledDimension.width, scaledDimension.height, bufferedImage.getType()));
}
 
Example 4
Source Project: astor   File: PaintSample.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Fills the component with the current Paint.
 *
 * @param g  the graphics device.
 */
public void paintComponent(Graphics g) {

    Graphics2D g2 = (Graphics2D) g;
    Dimension size = getSize();
    Insets insets = getInsets();
    double xx = insets.left;
    double yy = insets.top;
    double ww = size.getWidth() - insets.left - insets.right - 1;
    double hh = size.getHeight() - insets.top - insets.bottom - 1;
    Rectangle2D area = new Rectangle2D.Double(xx, yy, ww, hh);
    g2.setPaint(this.paint);
    g2.fill(area);
    g2.setPaint(Color.black);
    g2.draw(area);

}
 
Example 5
Source Project: binnavi   File: GuiHelper.java    License: Apache License 2.0 6 votes vote down vote up
/** Centers the child component relative to its parent component. */
public static final void centerChildToParent(
    final Component parent, final Component child, final boolean bStayOnScreen) {
  int x = (parent.getX() + (parent.getWidth() / 2)) - (child.getWidth() / 2);
  int y = (parent.getY() + (parent.getHeight() / 2)) - (child.getHeight() / 2);
  if (bStayOnScreen) {
    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension ss = new Dimension(tk.getScreenSize());
    if ((x + child.getWidth()) > ss.getWidth()) {
      x = (int) (ss.getWidth() - child.getWidth());
    }
    if ((y + child.getHeight()) > ss.getHeight()) {
      y = (int) (ss.getHeight() - child.getHeight());
    }
    if (x < 0) {
      x = 0;
    }
    if (y < 0) {
      y = 0;
    }
  }
  child.setLocation(x, y);
}
 
Example 6
public DerivationTreeTransformer(DerivationTree t, Dimension d, boolean isAnchored) {
  this.isAnchored = isAnchored;
  anchorPoint = new Point2D.Double(0, 0);
  graph = t;
  DelegateForest<Node, DerivationTreeEdge> del = new DelegateForest<>(t);
  del.setRoot(t.root);
  del.setRoot(t.sourceRoot);
  root = t.root;
  sourceRoot = t.sourceRoot;
  Y_DIST = d.getHeight() / (2 * (1 + distanceToLeaf(root)));
  int leafCount = 0;
  for (Node n : t.getVertices()) {
    if (t.outDegree(n) == 0) leafCount++;
  }
  X_DIST = d.getWidth() / leafCount;

  treeLayout = new TreeLayout<>(del, (int) Math.round(X_DIST));
}
 
Example 7
/**
 * Draws the sample.
 *
 * @param g  the graphics device.
 */
@Override
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 8
@Override
public Point getToolTipLocation(MouseEvent event)
{
	Dimension size = getSize();
	double oneRowUpHeight = (size.getHeight() * -1) - 5;
	return new Point((int) size.getWidth(), (int) oneRowUpHeight);
}
 
Example 9
Source Project: RipplePower   File: UIRes.java    License: Apache License 2.0 5 votes vote down vote up
public static Point getPointToCenter(Component component, Dimension dimension) {

		Dimension screenSize = getDefaultDeviceScreenSize();

		if (component == null) {

			if (dimension.height > screenSize.height) {
				dimension.height = screenSize.height;
			}

			if (dimension.width > screenSize.width) {
				dimension.width = screenSize.width;
			}

			return new Point((screenSize.width - dimension.width) / 2, (screenSize.height - dimension.height) / 2);
		}

		Dimension frameDim = component.getSize();
		Rectangle dRec = new Rectangle(component.getX(), component.getY(), (int) frameDim.getWidth(),
				(int) frameDim.getHeight());

		int dialogX = dRec.x + ((dRec.width - dimension.width) / 2);
		int dialogY = dRec.y + ((dRec.height - dimension.height) / 2);

		if (dialogX <= 0 || dialogY <= 0) {

			if (dimension.height > screenSize.height) {
				dimension.height = screenSize.height;
			}

			if (dimension.width > screenSize.width) {
				dimension.width = screenSize.width;
			}

			dialogX = (screenSize.width - dimension.width) / 2;
			dialogY = (screenSize.height - dimension.height) / 2;
		}

		return new Point(dialogX, dialogY);
	}
 
Example 10
/**
 * Returns the height of the given process. Convenience method which simply returns the height
 * of {@link #getProcessSize(ExecutionUnit)}.
 *
 * @param process
 * 		the process for which the height should be returned
 * @return the height or -1 if no process size has been stored
 */
public double getProcessHeight(ExecutionUnit process) {
	Dimension dim = processSizes.get(process);
	if (dim == null) {
		return -1;
	}
	if (getZoomFactor() > 1.0) {
		return dim.getHeight() * getZoomFactor();
	}
	return dim.getHeight();
}
 
Example 11
Source Project: astor   File: StrokeSample.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws a line using the sample stroke.
 *
 * @param g  the graphics device.
 */
public void paintComponent(Graphics g) {

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

    Point2D one =  new Point2D.Double(xx + 6, yy + hh / 2);
    Point2D two =  new Point2D.Double(xx + ww - 6, yy + hh / 2);

    Ellipse2D circle1 = new Ellipse2D.Double(one.getX() - 5, one.getY() - 5, 10, 10);
    Ellipse2D circle2 = new Ellipse2D.Double(two.getX() - 6, two.getY() - 5, 10, 10);

    g2.draw(circle1);
    g2.fill(circle1);
    g2.draw(circle2);
    g2.fill(circle2);

    // draw a line connecting the points
    Line2D line = new Line2D.Double(one, two);
    if (this.stroke != null) {
        g2.setStroke(this.stroke);
    }
    else {
        g2.setStroke(new BasicStroke(0.0f));
    }
    g2.draw(line);

}
 
Example 12
/**
 * Resize this picture to the default size.
 *
 * For PNG and JPEG resizes the image to 100%,
 * for other types, if the size can't be determined it will be 200x200 pixels.
 */
public void resize() {
    PictureShape<?,?> ps = getShape();
    Dimension dim = ps.getPictureData().getImageDimension();

    Rectangle2D origRect = ps.getAnchor();
    double x = origRect.getX();
    double y = origRect.getY();
    double w = dim.getWidth();
    double h = dim.getHeight();
    ps.setAnchor(new Rectangle2D.Double(x, y, w, h));
}
 
Example 13
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 14
private void checkProbandImageInput(ProbandImageInVO probandImage) throws ServiceException {
	if (probandImage.getDatas() != null && probandImage.getDatas().length > 0) {
		Integer probandImageSizeLimit = Settings.getIntNullable(SettingCodes.PROBAND_IMAGE_SIZE_LIMIT, Bundle.SETTINGS, DefaultSettings.PROBAND_IMAGE_SIZE_LIMIT);
		if (probandImageSizeLimit != null && probandImage.getDatas().length > probandImageSizeLimit) {
			throw L10nUtil.initServiceException(ServiceExceptionCodes.PROBAND_IMAGE_SIZE_LIMIT_EXCEEDED, CommonUtil.humanReadableByteCount(probandImageSizeLimit));
		}
		if (probandImage.getMimeType() == null) {
			throw L10nUtil.initServiceException(ServiceExceptionCodes.PROBAND_IMAGE_MIME_TYPE_REQUIRED);
		}
		Iterator<MimeType> it = this.getMimeTypeDao().findByMimeTypeModule(probandImage.getMimeType(), FileModule.PROBAND_IMAGE).iterator();
		if (!it.hasNext()) {
			throw L10nUtil.initServiceException(ServiceExceptionCodes.PROBAND_IMAGE_MIME_TYPE_UNKNOWN, probandImage.getMimeType());
		}
		if (!it.next().isImage()) {
			throw L10nUtil.initServiceException(ServiceExceptionCodes.PROBAND_IMAGE_MIME_TYPE_NO_IMAGE, probandImage.getMimeType());
		}
		Dimension imageDimension = CoreUtil.getImageDimension(probandImage.getDatas());
		if (imageDimension == null) {
			throw L10nUtil.initServiceException(ServiceExceptionCodes.PROBAND_IMAGE_CANNOT_READ_DIMENSIONS);
		} else {
			Integer probandImageMinWidth = Settings.getIntNullable(SettingCodes.PROBAND_IMAGE_MIN_WIDTH, Bundle.SETTINGS, DefaultSettings.PROBAND_IMAGE_MIN_WIDTH);
			Integer probandImageMinHeight = Settings.getIntNullable(SettingCodes.PROBAND_IMAGE_MIN_HEIGHT, Bundle.SETTINGS, DefaultSettings.PROBAND_IMAGE_MIN_HEIGHT);
			if (probandImageMinWidth != null && imageDimension.getWidth() < (double) probandImageMinWidth) {
				throw L10nUtil.initServiceException(ServiceExceptionCodes.PROBAND_IMAGE_WIDTH_LESS_THAN_LIMIT, probandImageMinWidth);
			}
			if (probandImageMinHeight != null && imageDimension.getHeight() < (double) probandImageMinHeight) {
				throw L10nUtil.initServiceException(ServiceExceptionCodes.PROBAND_IMAGE_HEIGHT_LESS_THAN_LIMIT, probandImageMinHeight);
			}
		}
	}
}
 
Example 15
/**
 * Draws the sample.
 *
 * @param g  the graphics device.
 */
@Override
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 16
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 17
@Override
public void paintComponent(Graphics g) {
	super.paintComponent(g);

	GeneralPath path = new GeneralPath();

	Dimension d = getSize();
	int monitorWidth = (int) d.getWidth() - 2 * MARGIN;
	int monitorHeight = (int) d.getHeight() - 2 * MARGIN;

	long total = Runtime.getRuntime().totalMemory();

	Graphics2D g2d = (Graphics2D) g;
	g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

	if (this.font == null) {
		this.font = g2d.getFont().deriveFont(12f);
	}

	g2d.setColor(Colors.WHITE);
	g2d.fillRect(MARGIN, MARGIN, monitorWidth, monitorHeight);

	path.moveTo(MARGIN, MARGIN + monitorHeight);
	for (int i = 0; i < memory.length; i++) {
		int index = (currentMeasurement + i) % memory.length;
		path.lineTo(MARGIN + i * monitorWidth / (memory.length - 1),
				MARGIN + monitorHeight - monitorHeight * memory[index] / total);
	}
	path.lineTo(MARGIN + monitorWidth, MARGIN + monitorHeight);
	path.closePath();

	g2d.setColor(gridColor);
	for (int x = 0; x < GRID_X + 1; x++) {
		g2d.drawLine(MARGIN + x * monitorWidth / GRID_X, MARGIN, MARGIN + x * monitorWidth / GRID_X,
				MARGIN + monitorHeight);
	}
	for (int y = 0; y < GRID_Y + 1; y++) {
		g2d.drawLine(MARGIN, MARGIN + y * monitorHeight / GRID_Y, MARGIN + monitorWidth,
				MARGIN + y * monitorHeight / GRID_Y);
	}

	Color currentMemoryColor = memoryColor;
	if (currentlyUsed > 0.2d * Runtime.getRuntime().maxMemory()) {
		double more = currentlyUsed - 0.2d * Runtime.getRuntime().maxMemory();
		double factor = more / (0.6d * Runtime.getRuntime().maxMemory());
		currentMemoryColor = getMemoryColor(Math.max(Math.min(1.0d, factor), 0.0d));
	}
	g2d.setColor(currentMemoryColor);
	g2d.fill(path);
	g2d.setColor(lineColor);
	g2d.draw(path);

	// text
	String maxString = Tools.formatSizeInBytes(total) + " used. Will use up to "
			+ Tools.formatSizeInBytes(Runtime.getRuntime().maxMemory());
	int totalHeight = 2 * font.getSize() + 2 * MARGIN;
	// MARGIN;
	if (totalHeight < getHeight()) {
		g2d.setFont(font);
		g2d.setColor(textColor);
		g2d.drawString(maxString, 2 * MARGIN, monitorHeight - font.getSize() + MARGIN);
	}
}
 
Example 18
Source Project: collect-earth   File: PropertiesDialog.java    License: MIT License 4 votes vote down vote up
private void centreWindow() {
	Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
	int x = (int) ((dimension.getWidth() - getWidth()) / 2);
	int y = (int) ((dimension.getHeight() - getHeight()) / 2);
	setLocation(x, y);
}
 
Example 19
Source Project: PathFinder   File: Canvas.java    License: Apache License 2.0 4 votes vote down vote up
public void updateMatrixIfDimensionChanged() {
	Dimension dimension = calculateDimension(getWidth(), getHeight(), parameters.getCellSize());
	if (dimension.getWidth() != matrix.getRows() || dimension.getHeight() != matrix.getColumns()) {
		updateMatrix();
	}
}
 
Example 20
Source Project: netbeans   File: WizardUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * @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());
}