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

The following are Jave code examples for showing how to use getHeight() 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: litiengine   File: Camera.java   View Source Code Vote up 6 votes
protected Point2D clampToMap(Point2D focus) {
  if (Game.getEnvironment() == null || Game.getEnvironment().getMap() == null || !this.isClampToMap()) {
    return focus;
  }

  final Dimension mapSize = Game.getEnvironment().getMap().getSizeInPixels();
  final Dimension resolution = Game.getScreenManager().getResolution();

  double minX = resolution.getWidth() / this.getRenderScale() / 2.0;
  double maxX = mapSize.getWidth() - minX;
  double minY = resolution.getHeight() / this.getRenderScale() / 2.0;
  double maxY = mapSize.getHeight() - minY;

  double x = mapSize.getWidth() * this.getRenderScale() < resolution.getWidth() ? minX : MathUtilities.clamp(focus.getX(), minX, maxX);
  double y = mapSize.getHeight() * this.getRenderScale() < resolution.getHeight() ? minY : MathUtilities.clamp(focus.getY(), minY, maxY);

  return new Point2D.Double(x, y);
}
 
Example 2
Project: JavaGraph   File: JEdgeView.java   View Source Code Vote up 6 votes
/** Paints the main label in a JLabel, providing HTML formatting. */
private void paintMainLabel(Graphics g, Point2D p) {
    Dimension size = setTextInJLabel(this.jView);
    if (size != null && (size.getWidth() != 0 || size.getHeight() != 0)) {
        this.jLabel.setSize(size);
        int sw = (int) size.getWidth();
        int sh = (int) size.getHeight();
        Graphics2D g2 = (Graphics2D) g;
        int dx = -sw / 2;
        int offset = this.isMoveBelowZero ? 0 : Math.min(0, (int) (dx + p.getX()));
        g2.translate(p.getX() - offset, p.getY());
        if (isOpaque()) {
            g.setColor(getBackground());
            g.fillRect(-sw / 2 - 1, -sh / 2 - 1, sw + 2, sh + 2);
        }
        int dy = -sh / 2;
        g.setColor(this.fontColor);
        g.translate(dx, dy);
        //the fontMetrics stringWidth and height can be replaced by
        //getLabel().getPreferredSize() if needed
        this.jLabel.paint(g);
        g.translate(-dx, -dy);
        g2.translate(-p.getX() + offset, -p.getY());
    }
}
 
Example 3
Project: incubator-netbeans   File: ComponentPeer.java   View Source Code Vote up 6 votes
private int[] computeVisibleSpan() {
    Component parent = pane.getParent();
    
    if (parent instanceof JLayeredPane) {
        parent = parent.getParent();
    }

    if (parent instanceof JViewport) {
        JViewport vp = (JViewport) parent;

        Point start = vp.getViewPosition();
        Dimension size = vp.getExtentSize();
        Point end = new Point((int) (start.getX() + size.getWidth()), (int) (start.getY() + size.getHeight()));

        int startPosition = pane.viewToModel(start);
        int endPosition = pane.viewToModel(end);

        if (parentWithListener != vp) {
            vp.addChangeListener(WeakListeners.change(this, vp));
            parentWithListener = vp;
        }
        return new int[] {startPosition, endPosition};
    }

    return new int[] {0, pane.getDocument().getLength()};
}
 
Example 4
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 5
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 6
Project: batmapper   File: MapperLayout.java   View Source Code Vote up 6 votes
@Override
    public void initialize() {
        Dimension d = getSize();

        if (d != null) {

            double y = d.getHeight() / 2;
            double x = d.getWidth() / 2;

            Room startRoom = getStartRoomAndResetDraweds();
            if (startRoom == null) {
                return;
            }
//			System.out.println("iter drawing: "+x+" "+y);
            Point2D center = new Point2D.Double( x, y );
            iterativeDrawing( startRoom, center );
        }
    }
 
Example 7
Project: Backmemed   File: Config.java   View Source Code Vote up 6 votes
private static DisplayMode[] getDisplayModes(DisplayMode[] p_getDisplayModes_0_, Dimension p_getDisplayModes_1_)
{
    List list = new ArrayList();

    for (int i = 0; i < p_getDisplayModes_0_.length; ++i)
    {
        DisplayMode displaymode = p_getDisplayModes_0_[i];

        if ((double)displaymode.getWidth() == p_getDisplayModes_1_.getWidth() && (double)displaymode.getHeight() == p_getDisplayModes_1_.getHeight())
        {
            list.add(displaymode);
        }
    }

    DisplayMode[] adisplaymode = (DisplayMode[])((DisplayMode[])list.toArray(new DisplayMode[list.size()]));
    return adisplaymode;
}
 
Example 8
Project: PictureTravelSuite   File: PictureTravelSuiteClass.java   View Source Code Vote up 5 votes
private Dimension GetImageSize(String workingFile, File folderRef) {
	Dimension RawImageSize = GetRawImageSize(workingFile, folderRef);
	if (!Orientation(workingFile, folderRef).isEmpty() && !IsHorizontal(workingFile, folderRef)) {
		//addToLog("Switching coordinates", false);
		return (new Dimension((int) Math.round(RawImageSize.getHeight()), (int) Math.round(RawImageSize.getWidth())));
	}
	return (new Dimension((int) RawImageSize.getWidth(), (int) RawImageSize.getHeight()));
}
 
Example 9
Project: cuttlefish   File: CircleLayout.java   View Source Code Vote up 5 votes
public StaticLayout initializeLocations(Dimension d, Graph g)
{
	this.total_vertices = g.getVertices().size();
	vertex_number = 0;

	double height = d.getHeight();
	double width = d.getWidth();

	radius = 0.45 * Math.min(height, width);

	return super.initializeLocations(d, g);
}
 
Example 10
Project: jdk8u-jdk   File: XMBeanNotifications.java   View Source Code Vote up 5 votes
UserDataCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 200) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 200));
    }
}
 
Example 11
Project: openjdk-jdk10   File: XMBeanAttributes.java   View Source Code Vote up 5 votes
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 12
Project: jdk8u-jdk   File: XMBeanAttributes.java   View Source Code Vote up 5 votes
MaximizedCellRenderer(Component comp) {
    this.comp = comp;
    Dimension d = comp.getPreferredSize();
    if (d.getHeight() > 220) {
        comp.setPreferredSize(new Dimension((int) d.getWidth(), 220));
    }
}
 
Example 13
Project: rapidminer   File: ProcessRendererController.java   View Source Code Vote up 5 votes
/**
 * Ensures that the process is at least height heigh.
 *
 * @param executionUnit
 *            the process to ensure the minimum height
 * @param width
 *            the mininum height
 */
void ensureHeight(final ExecutionUnit executionUnit, final int height) {
	Dimension old = new Dimension((int) model.getProcessWidth(executionUnit),
			(int) model.getProcessHeight(executionUnit));
	if (height > old.getHeight()) {
		model.setProcessHeight(executionUnit, height);
		balance();
		model.fireProcessSizeChanged();
	}
}
 
Example 14
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 15
Project: Logisim   File: SplashScreen.java   View Source Code Vote up 5 votes
@Override
public void setVisible(boolean value) {
	if (value) {
		pack();
		Dimension dim = getToolkit().getScreenSize();
		int x = (int) (dim.getWidth() - getWidth()) / 2;
		int y = (int) (dim.getHeight() - getHeight()) / 2;
		setLocation(x, y);
	}
	super.setVisible(value);
}
 
Example 16
Project: cuttlefish   File: Coordinates.java   View Source Code Vote up 4 votes
public void scale(Dimension old, Dimension newDim) {
    this.x *= (newDim.getWidth() / old.getWidth());
    this.y *= (newDim.getHeight() / old.getHeight() );
}
 
Example 17
Project: letsmake-ledmatrix   File: VerticalFlowLayout.java   View Source Code Vote up 4 votes
/**
 * Description of the Method
 *
 * @param target Description of Parameter
 */
public void layoutContainer(Container target) {
    synchronized (target.getTreeLock()) {
        Insets insets = target.getInsets();
        int maxheight = target.getHeight() - (insets.top + insets.bottom);// + _vgap * 2);
        int nmembers = target.getComponentCount();
        int y = 0;

        Dimension preferredSize = preferredLayoutSize(target);
        Dimension targetSize = target.getSize();

        switch (_valign) {
            case TOP:
                y = insets.top;
                break;
            case CENTER:
                y = (targetSize.height - preferredSize.height) / 2;
                break;
            case BOTTOM:
                y = targetSize.height - preferredSize.height - insets.bottom;
                break;
        }

        for (int i = 0; i < nmembers; i++) {
            Component m = target.getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                m.setSize(d.width, d.height);

                if ((y + d.height) <= maxheight) {
                    if (y > 0) {
                        y += _vgap;
                    }

                    int x = 0;
                    switch (_halign) {
                        case LEFT:
                            x = insets.left;
                            break;
                        case CENTER:
                            x = (targetSize.width - d.width) / 2;
                            break;
                        case RIGHT:
                            x = targetSize.width - d.width - insets.right;
                            break;
                    }

                    m.setLocation(x, y);

                    y += d.getHeight();

                } else {
                    break;
                }
            }
        }
    }
}
 
Example 18
Project: rapidminer   File: AbstractChartPanel.java   View Source Code Vote up 4 votes
/**
 * Paints the component by drawing the chart to fill the entire component, but allowing for the
 * insets (which will be non-zero if a border has been set for this component). To increase
 * performance (at the expense of memory), an off-screen buffer image can be used.
 * 
 * @param g
 *            the graphics device for drawing on.
 */

@Override
public void paintComponent(Graphics g) {
	if (this.chart == null) {
		return;
	}
	Graphics2D g2 = (Graphics2D) g.create();

	// first determine the size of the chart rendering area...
	Dimension size = getSize();
	Insets insets = getInsets();
	Rectangle2D available = new Rectangle2D.Double(insets.left, insets.top,
			size.getWidth() - insets.left - insets.right, size.getHeight() - insets.top - insets.bottom);

	// work out if scaling is required...
	boolean scale = false;
	double drawWidth = available.getWidth();
	double drawHeight = available.getHeight();
	this.scaleX = 1.0;
	this.scaleY = 1.0;

	if (drawWidth < this.minimumDrawWidth) {
		this.scaleX = drawWidth / this.minimumDrawWidth;
		drawWidth = this.minimumDrawWidth;
		scale = true;
	} else if (drawWidth > this.maximumDrawWidth) {
		this.scaleX = drawWidth / this.maximumDrawWidth;
		drawWidth = this.maximumDrawWidth;
		scale = true;
	}

	if (drawHeight < this.minimumDrawHeight) {
		this.scaleY = drawHeight / this.minimumDrawHeight;
		drawHeight = this.minimumDrawHeight;
		scale = true;
	} else if (drawHeight > this.maximumDrawHeight) {
		this.scaleY = drawHeight / this.maximumDrawHeight;
		drawHeight = this.maximumDrawHeight;
		scale = true;
	}

	Rectangle2D chartArea = new Rectangle2D.Double(0.0, 0.0, drawWidth, drawHeight);
	// redrawing the chart every time...

	AffineTransform saved = g2.getTransform();
	g2.translate(insets.left, insets.top);
	if (scale) {
		AffineTransform st = AffineTransform.getScaleInstance(this.scaleX, this.scaleY);
		g2.transform(st);
	}
	this.chart.draw(g2, chartArea, this.anchor, this.info);
	g2.setTransform(saved);

	Iterator<Overlay> iterator = this.overlays.iterator();
	while (iterator.hasNext()) {
		Overlay overlay = iterator.next();
		overlay.paintOverlay(g2, this);
	}

	// redraw the zoom rectangle (if present) - if useBuffer is false,
	// we use XOR so we can XOR the rectangle away again without redrawing
	// the chart
	drawSelectionRectangle(g2);

	g2.dispose();

	this.anchor = null;
	this.verticalTraceLine = null;
	this.horizontalTraceLine = null;

}
 
Example 19
Project: rapidminer   File: SystemMonitor.java   View Source Code Vote up 4 votes
@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 20
Project: rapidminer   File: ProcessRendererModel.java   View Source Code Vote up 3 votes
/**
 * 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;
	}
	return dim.getHeight();
}