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

The following are Jave code examples for showing how to use getHeight() of the java.awt.Rectangle 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: incubator-netbeans   File: OptionsDisplayerImpl.java   View Source Code Vote up 6 votes
private Point getUserLocation(GraphicsConfiguration gconf, OptionsPanel optionsPanel) {
      final Rectangle screenBounds = Utilities.getUsableScreenBounds(gconf);
      int x = NbPreferences.forModule(OptionsDisplayerImpl.class).getInt("OptionsX", Integer.MAX_VALUE);//NOI18N
      int y = NbPreferences.forModule(OptionsDisplayerImpl.class).getInt("OptionsY", Integer.MAX_VALUE);//NOI18N
      Dimension userSize = optionsPanel.getUserSize();
      if (x > screenBounds.x + screenBounds.getWidth() || y > screenBounds.y + screenBounds.getHeight()
              || x + userSize.width > screenBounds.x + screenBounds.getWidth() 
              || y + userSize.height > screenBounds.y + screenBounds.getHeight()
              || (x < screenBounds.x && screenBounds.x >= 0)
|| (x > screenBounds.x && screenBounds.x < 0)
|| (y < screenBounds.y && screenBounds.y >= 0)
|| (y > screenBounds.y && screenBounds.y < 0)){
          return null;
      } else {
          return new Point(x, y);
      }
  }
 
Example 2
Project: rapidminer   File: ScrollBarUI.java   View Source Code Vote up 6 votes
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
	int x = (int) trackBounds.getX();
	int y = (int) trackBounds.getY();
	int w = (int) trackBounds.getWidth();
	int h = (int) trackBounds.getHeight();

	g.setColor(Colors.SCROLLBAR_TRACK_BACKGROUND);
	g.fillRect(x - 1, y - 1, w + 2, h + 2);

	g.setColor(Colors.SCROLLBAR_TRACK_BORDER);
	if (this.scrollbar.getOrientation() == Adjustable.HORIZONTAL) {
		g.drawLine(x, y, x + w, y);
	} else {
		g.drawLine(x, y, x, y + h);
	}
}
 
Example 3
Project: geomapapp   File: SCSImage2.java   View Source Code Vote up 6 votes
public void doZoom( Point p, double factor ) {
Rectangle rect = getVisibleRect();
double x = p.getX() / zoom;
		double y = p.getY() / zoom;
		double w = rect.getWidth();
		double h = rect.getHeight();
		zoom *= factor;
zoomX = zoomY = zoom;
		int newX = (int) (x*zoom - w*.5d);
		int newY = (int) (y*zoom - h*.5d);
		invalidate();
		scrollPane.validate();
		JScrollBar sb = scrollPane.getHorizontalScrollBar();
		sb.setValue(newX);
		sb = scrollPane.getVerticalScrollBar();
		sb.setValue(newY);
		repaint();
}
 
Example 4
Project: Pixie   File: ResultPanel.java   View Source Code Vote up 6 votes
/**
 * Merges the given object map in the image object map, at the specified
 * coordinates.
 *
 * @param newObjMap - the object map that has to be merged in the result map
 * @param pos       - the position where the image has to be copied: info x - the top-left X coordinate where the image has to be copied info; y - the top-left Y coordinate where the image has to be copied info; width - the width of the image to be copied info; height - the height of the image to be copied
 * @param objId     - the object id as byte value (it is obtained by computing the image object id % 255)
 * @param mergeBkg  - true if both the background and object have to overwrite the existent content of the object map; false if only the object should be merged
 */
public void mergeCrop(byte[][] newObjMap, Rectangle pos, long objId, boolean mergeBkg) {
    byte mapId = getByteObjId(objId);

    // update objectMap
    for (int y = 0; y < pos.getHeight(); y++) {
        for (int x = 0; x < pos.getWidth(); x++) {

            if (mergeBkg) {
                // merge bakground in object map (overwrites the initial byte, no matter what was storred, with bkg)
                objMap[x + pos.x][y + pos.y] = (newObjMap[x][y] > 0) ? mapId : (byte) 0;

            } else {
                // merge just the pure object - when the pixel in the  object map is != 0
                objMap[x + pos.x][y + pos.y] = ((objMap[x + pos.x][y + pos.y] == mapId) && (newObjMap[x][y] == 0)) ? 0 : objMap[x + pos.x][y + pos.y];
                objMap[x + pos.x][y + pos.y] = (newObjMap[x][y] > 0) ? mapId : objMap[x + pos.x][y + pos.y];
            }
        }
    }
}
 
Example 5
Project: sumo   File: WorldScreen.java   View Source Code Vote up 6 votes
public static Point2D getScreentoWorld(double x, double y) throws Exception {
    Rectangle imageBounds=null;
    ReferencedEnvelope mapBounds=null;
    try{
//        mapBounds=map.getLayerBounds();
        imageBounds = mapFrame.getBounds();
        int width = (int)imageBounds.getWidth();
        int height = (int)imageBounds.getHeight();
    }catch(Exception e){
        
    } 
    
    AffineTransform world2screen =
    RendererUtilities.worldToScreenTransform(mapBounds, imageBounds);
    
    AffineTransform screen2world = world2screen.createInverse();
    Point2D pointScreenAbsolute = new Point2D.Double(x, y);
    Point2D pointScreen = screen2world.transform(pointScreenAbsolute, null); 
    return pointScreen;
}
 
Example 6
Project: geomapapp   File: XMap.java   View Source Code Vote up 6 votes
/**
 * Not Implemented.
 */
public double[] getWESN() {
	double[] wesn = new double[4];
	Rectangle r = getVisibleRect();
	if(mapBorder != null) {
		r = mapBorder.getInteriorRectangle(this, r.x, r.y, r.width, r.height);
	}
	Point2D.Double pt = new Point2D.Double( r.getX(), r.getY() );
	pt = (Point2D.Double)proj.getRefXY( getScaledPoint(pt));
	wesn[0] = pt.x;
	wesn[3] = pt.y;
	pt = new Point2D.Double( r.getX()+r.getWidth(),
				 r.getY()+r.getHeight() );
	pt = (Point2D.Double)proj.getRefXY( getScaledPoint(pt));
	wesn[1] = pt.x;
	wesn[2] = pt.y;
	return wesn;
}
 
Example 7
Project: incubator-netbeans   File: ButtonCellRenderer.java   View Source Code Vote up 5 votes
@Override
public Component getTableCellRendererComponent (
    JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column
) {
    JLabel c = (JLabel)defaultRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    
    if (value instanceof String) {
        Rectangle cellRect = table.getCellRect(row, column, false);
        String scCell = (String) value;
        Dimension d = new Dimension((int) cellRect.getWidth(), (int) cellRect.getHeight());
        if (panel == null)
            panel = new ShortcutCellPanel(scCell);
        panel.setText(scCell);
        panel.setSize(d);

        if (isSelected) {
            panel.setBgColor(table.getSelectionBackground());
            if (UIManager.getLookAndFeel ().getID ().equals ("GTK"))
                panel.setFgCOlor(table.getForeground(), true);
            else
                panel.setFgCOlor(table.getSelectionForeground(), true);
        } else {
            panel.setBgColor(c.getBackground());
            panel.setFgCOlor(c.getForeground(), false);
        }
        if (hasFocus) {
            panel.setBorder(c.getBorder());
        } else {
            panel.setBorder(null);
        }

        return panel;
    }
    else {
        return c;
    }
}
 
Example 8
Project: incubator-netbeans   File: DialogBoundsPreserver.java   View Source Code Vote up 5 votes
private boolean checkBounds(Rectangle r) {
    Rectangle[] screens = getScreenBounds();
    for (Rectangle screen : screens) {
        if (r.getX() >= screen.getX() && r.getY() >= screen.getY()
                && r.getX() + r.getWidth() < screen.getX() + screen.getWidth()
                && r.getY() + r.getHeight() < screen.getY() + screen.getHeight()) {
            return true;
        }
    }
    return false;
}
 
Example 9
Project: rapidminer   File: RadioButtonUI.java   View Source Code Vote up 5 votes
@Override
protected void paintFocus(Graphics g, Rectangle textRect, Dimension d) {
	int x = 0, y = 0, w = 0, h = 0;
	x = (int) textRect.getX() - 2;
	y = (int) textRect.getY();
	w = (int) textRect.getWidth() + 4;
	h = (int) textRect.getHeight();

	Graphics2D g2 = (Graphics2D) g;
	g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
	g2.setColor(Colors.RADIOBUTTON_BORDER_FOCUS);
	g2.setStroke(DASHED_STROKE);
	g2.drawRect(x, y, w, h);
}
 
Example 10
Project: rapidminer   File: OverviewPanel.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics graphics) {
	super.paintComponent(graphics);
	double scaleX = (double) getWidth() / (double) processRenderer.getWidth();
	double scaleY = (double) getHeight() / (double) processRenderer.getHeight();
	scale = Math.min(scaleX, scaleY);
	double scaledW = processRenderer.getWidth() * scale;
	double scaledH = processRenderer.getHeight() * scale;

	Graphics2D g = (Graphics2D) graphics.create();
	g.translate((getWidth() - scaledW) / 2d, (getHeight() - scaledH) / 2d);
	g.scale(scale, scale);

	g.setRenderingHints(ProcessDrawer.LOW_QUALITY_HINTS);
	processRenderer.getOverviewPanelDrawer().draw(g, true);

	g.setStroke(new BasicStroke((int) (1d / scale)));

	Rectangle visibleRect = processRenderer.getVisibleRect();
	Rectangle drawRect = new Rectangle((int) visibleRect.getX(), (int) visibleRect.getY(),
			(int) visibleRect.getWidth() - 1, (int) visibleRect.getHeight() - 1);

	g.setColor(FILL_COLOR);
	g.fill(drawRect);

	g.setColor(DRAW_COLOR);
	g.draw(drawRect);

	g.dispose();
}
 
Example 11
Project: VASSAL-src   File: ColoredBorder.java   View Source Code Vote up 5 votes
public void draw(GamePiece p, Graphics g, int x, int y,
                 Component obs, double zoom) {
  if (thickness > 0) {
    if (c != null) {
      // Find the border by outsetting the bounding box, and then scaling
      // the shape to fill the outset.
      final Shape s = p.getShape();
      final Rectangle br = s.getBounds();

      // Don't bother if the shape is empty.
      if (!br.isEmpty()) {
        final double xzoom = (br.getWidth()+1) / br.getWidth();
        final double yzoom = (br.getHeight()+1) / br.getHeight();
        final AffineTransform t = AffineTransform.getTranslateInstance(x,y);
        t.scale(xzoom*zoom, yzoom*zoom);

        final Graphics2D g2d = (Graphics2D) g;
        final Stroke str = g2d.getStroke();
        g2d.setStroke(
          new BasicStroke(Math.max(1, Math.round(zoom*thickness))));
        g2d.setColor(c);
        g2d.draw(t.createTransformedShape(s));
        g2d.setStroke(str);
      }
    }
    else {
      highlightSelectionBounds(p, g, x, y, obs, zoom);
    }
  }

  // Draw any additional highlighters
  for (Highlighter h : highlighters) {
    h.draw(p, g, x, y, obs, zoom);
  }
}
 
Example 12
Project: convertigo-eclipse   File: ColumnEditor.java   View Source Code Vote up 5 votes
public void handleSelectionChanged(com.twinsoft.twinj.twinxEvent0 twinxEvent0) {
        try {
            Rectangle selectedZone = javelin.getSelectionZone();
            boolean bSelected = (selectedZone != null) && (selectedZone.getWidth() != 0) && (selectedZone.getHeight() != 0);
            addButton.setEnabled(bSelected);
        } catch (Exception e) {
//            Studio.theApp.exception(e, "Unable to handle Javelin selection zone change.");
        }
    }
 
Example 13
Project: geomapapp   File: XMap.java   View Source Code Vote up 5 votes
/**
 * Gets the region currently displayed in Projection coordinates.
 * @return the region currently displayed in Projection coordinates.
 */
public Rectangle2D getClipRect2D() {
	Rectangle r = getVisibleRect();
	Dimension dim = getPreferredSize();
	r.width = Math.min(r.width, dim.width);
	r.height = Math.min(r.height, dim.height);
	AffineTransform at = new AffineTransform();
	if(rotation==1) {
		at.translate( 0., dim.getHeight() );
		at.rotate(-.5*Math.PI);
	} else if( rotation==2 ) {
		at.translate( dim.getWidth(), dim.getHeight() );
		at.rotate( Math.PI );
	} else if( rotation == 3) {
		at.translate( dim.getWidth(), 0. );
		at.rotate( .5*Math.PI );
	}
	if(rotation != 0) {
		Point2D p1 = at.transform(new Point(r.x,r.y), null);
		Point2D p2 = at.transform(new Point(r.x+r.width,r.y+r.width), null);
		r.x = (int) Math.min(p1.getX(), p2.getX());
		r.width = (int) Math.max(p1.getX(), p2.getX()) - r.x;
		r.y = (int) Math.min(p1.getY(), p2.getY());
		r.height = (int) Math.max(p1.getY(), p2.getY()) - r.y;
	}

	if(mapBorder != null) {
		Insets ins = mapBorder.getBorderInsets(this);
		r.width -= ins.left + ins.right;
		r.height -= ins.top + ins.bottom;
	}
	Rectangle2D.Double r2d = new Rectangle2D.Double(
			r.getX()/zoom, r.getY()/zoom,
			r.getWidth()/zoom, r.getHeight()/zoom);
	return r2d;
}
 
Example 14
Project: geomapapp   File: WWMap.java   View Source Code Vote up 5 votes
public int print(Graphics g, PageFormat fmt, int pageNo) {
	if( pageNo>0 ) return NO_SUCH_PAGE;
	Graphics2D g2 = (Graphics2D)g;
	Dimension dim = wwd.getPreferredSize();
	Rectangle r = wwd.getBounds();

	if(r.width>dim.width) r.width = dim.width;
	if(r.height>dim.height) r.height = dim.height;

	org.geomapapp.util.DateFmt df = new org.geomapapp.util.DateFmt();
	int secs = (int)(System.currentTimeMillis()/1000L);
	String date = df.format(secs);
	Font font = new Font("SansSerif", Font.PLAIN, 8);
	g.setFont( font );
	Rectangle2D r2d = font.getStringBounds(date, g2.getFontRenderContext());
//	g2.translate( r.getWidth()-20.-r2d.getWidth(), r.getHeight()+18. );
	g2.setColor( Color.black);

//	g.setClip( new Rectangle( 0, 0, r.width, r.height) );
	double w = fmt.getImageableWidth();
	double h = fmt.getImageableHeight();
	double x = fmt.getImageableX();
	double y = fmt.getImageableY();
	g2.translate(x, y);
	double scale = Math.min( w / r.getWidth(), h / r.getHeight());
	int xd = (int)(scale*r.getWidth()-10.-r2d.getWidth());
	int yd = (int)(scale*r.getHeight()+18.);
	g2.drawString( date, xd, yd);
	g2.translate( -r.getX()*scale, -r.getY()*scale );
	g2.scale( scale, scale);

	wwd.getContext().makeCurrent();
	BufferedImage image = Screenshot.readToBufferedImage(r.width, r.height);
	g2.drawImage(image, 0, 0, this);
	return PAGE_EXISTS;
}
 
Example 15
Project: incubator-netbeans   File: DefaultOutlineCellRenderer.java   View Source Code Vote up 4 votes
@Override
public void paintBorder(Component c, java.awt.Graphics g, int x, int y, int width, int height) {
    DefaultOutlineCellRenderer ren = (DefaultOutlineCellRenderer)
            ((JComponent) c).getClientProperty(DefaultOutlineCellRenderer.class);
    if (ren == null) {
        ren = (DefaultOutlineCellRenderer) c;
    }
    if (ren.isShowHandle() && !ren.isLeaf()) {
        Icon icon = ren.isExpanded() ? getExpandedIcon() : getCollapsedIcon();
        int iconY;
        int iconX = ren.getNestingDepth() * getNestingWidth();
        if (icon.getIconHeight() < height) {
            iconY = (height / 2) - (icon.getIconHeight() / 2);
        } else {
            iconY = 0;
        }
        if (isNimbus) {
            iconX += icon.getIconWidth()/3; // To look good
        }
        if (isGtk) {
            JLabel lbl = ren.isExpanded () ? lExpandedIcon : lCollapsedIcon;
            lbl.setSize (Math.max (getExpansionHandleWidth (), iconX + getExpansionHandleWidth ()), height);
            lbl.paint (g);
        } else {
            icon.paintIcon(c, g, iconX, iconY);
        }
    }
    JCheckBox chBox = ren.getCheckBox();
    if (chBox != null) {
        int chBoxX = getExpansionHandleWidth() + ren.getNestingDepth() * getNestingWidth();
        Rectangle bounds = chBox.getBounds();
        int chBoxY;
        if (bounds.getHeight() < height) {
            chBoxY = (height / 2) - (((int) bounds.getHeight()) / 2);
        } else {
            if (isNimbus) {
                chBoxY = 1;
            } else {
                chBoxY = 0;
            }
        }
        Dimension chDim = chBox.getSize();
        java.awt.Graphics gch = g.create(chBoxX, chBoxY, chDim.width, chDim.height);
        chBox.paint(gch);
    }
}
 
Example 16
Project: BrainControl   File: GraphPanel.java   View Source Code Vote up 4 votes
/**
	 * Painting of the Graph
	 */
	
	@Override
	public void paint(Graphics g) {

		
		//drawing the frame of the Graph
		Rectangle r = g.getClipBounds();
		g.setColor(Color.RED);
		g.drawRect(0, 0, (int)r.getWidth(), (int)r.getHeight());

		
		setBackground(Color.WHITE);
		
		g.setColor(Color.GRAY);
		
		
		final int minTime = Math.max(0, elapsedTime - coordinates.displayedTimeInterval);
//		final int maxTime = Math.max(elapsedTime, coordinates.displayedTimeInterval);
		final int graphWidth = (int)r.getWidth() - 2*offset;
		final int graphHeight = (int)r.getHeight() - 2*offset;
		
		//drawing the x axis
		g.drawLine(offset, (int)r.getHeight() - offset, (int)r.getWidth() - offset, (int)r.getHeight() - offset);
		//drawing the y axis
		g.drawLine(offset, offset, offset, (int)r.getHeight() - offset);
		
		g.setColor(Color.BLACK);
		
		//bold shows which reservoir is active and the name of it is to bold 
		if(reservoir.bold)
		{
			g.setFont(new Font("default", Font.BOLD, 14));
		}
		//draw name of reservoir
		g.drawString(reservoir.getName(), (int)(r.getWidth()/2-offset), offset);
		
		g.setFont(new Font("default", Font.PLAIN, 12));
		
		
		//String beginX = String.valueOf(minTime);
		//String endX = String.valueOf(coordinates.displayedTimeInterval + minTime);
		
		//label of the x axis
//		g.drawString(beginX, offset, (int)r.getHeight() - offset + 15);
//		g.drawString(endX, (int)r.getWidth() - offset,(int)r.getHeight() - offset + 15);
		
		//label of the y axis
		g.drawString("0", offset - 10, (int)r.getHeight() - offset);
		g.drawString("1", offset - 10, offset + 10);


		//drawing the graph: showing all the lines which connect the values that are saved in the list ReservoirCoordinate
		if(coordinates.size() > 1) {
			Iterator<ReservoirGuiCoordinate> it = coordinates.iterator();
			ReservoirGuiCoordinate lastCoordinate = it.next();
			Point lastGuiPoint = getGuiPoint(minTime, graphWidth, graphHeight, lastCoordinate);
			Point nextGuiPoint = null;
			while(it.hasNext()) {
				ReservoirGuiCoordinate nextCoordinate = it.next();
				nextGuiPoint = getGuiPoint(minTime, graphWidth, graphHeight, nextCoordinate);
				g.drawLine(lastGuiPoint.x, lastGuiPoint.y, nextGuiPoint.x, nextGuiPoint.y);
				lastGuiPoint = nextGuiPoint;
			}
		}
	
	}
 
Example 17
Project: ramus   File: HTMLPrintable.java   View Source Code Vote up 4 votes
private boolean printView(final Graphics2D graphics2D,
                          final Shape allocation, final View view) {
    boolean pageExists = false;
    final Rectangle clipRectangle = new Rectangle(0, 0, (int) (pageFormat
            .getImageableWidth() / SCALE), (int) clientHeight);
    Shape childAllocation;
    View childView;

    if (view.getViewCount() > 0) {
        for (int i = 0; i < view.getViewCount(); i++) {
            childAllocation = view.getChildAllocation(i, allocation);
            if (childAllocation != null) {
                childView = view.getView(i);
                if (printView(graphics2D, childAllocation, childView)) {
                    pageExists = true;
                }
            }
        }
    } else {
        if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) {

            if (allocation.getBounds().getHeight() > clipRectangle
                    .getHeight()
                    && allocation.intersects(clipRectangle)) {
                paintView(graphics2D, view, allocation);
                pageExists = true;
            } else {
                if (allocation.getBounds().getY() >= clipRectangle.getY()) {
                    if (allocation.getBounds().getMaxY() <= clipRectangle
                            .getMaxY()) {
                        paintView(graphics2D, view, allocation);
                        pageExists = true;

                    } else {
                        if (allocation.getBounds().getY() < pageEndY) {
                            pageEndY = allocation.getBounds().getY();
                        }
                    }
                }
            }
        }
    }
    return pageExists;
}
 
Example 18
Project: Tarski   File: mxGraphics2DCanvas.java   View Source Code Vote up 4 votes
/**
 * 
 */
public void drawImage(Rectangle bounds, String imageUrl, boolean preserveAspect, boolean flipH,
    boolean flipV) {
  if (imageUrl != null && bounds.getWidth() > 0 && bounds.getHeight() > 0) {
    Image img = loadImage(imageUrl);

    if (img != null) {
      int w, h;
      int x = bounds.x;
      int y = bounds.y;
      Dimension size = getImageSize(img);

      if (preserveAspect) {
        double s =
            Math.min(bounds.width / (double) size.width, bounds.height / (double) size.height);
        w = (int) (size.width * s);
        h = (int) (size.height * s);
        x += (bounds.width - w) / 2;
        y += (bounds.height - h) / 2;
      } else {
        w = bounds.width;
        h = bounds.height;
      }

      Image scaledImage = (w == size.width && h == size.height) ? img
          : img.getScaledInstance(w, h, IMAGE_SCALING);

      if (scaledImage != null) {
        AffineTransform af = null;

        if (flipH || flipV) {
          af = g.getTransform();
          int sx = 1;
          int sy = 1;
          int dx = 0;
          int dy = 0;

          if (flipH) {
            sx = -1;
            dx = -w - 2 * x;
          }

          if (flipV) {
            sy = -1;
            dy = -h - 2 * y;
          }

          g.scale(sx, sy);
          g.translate(dx, dy);
        }

        drawImageImpl(scaledImage, x, y);

        // Restores the previous transform
        if (af != null) {
          g.setTransform(af);
        }
      }
    }
  }
}
 
Example 19
Project: openjdk-jdk10   File: JComponentOperator.java   View Source Code Vote up 4 votes
@Override
public int getCenterYForClick() {
    Rectangle rect = getVisibleRect();
    return ((int) rect.getY()
            + (int) rect.getHeight() / 2);
}
 
Example 20
Project: openjdk-jdk10   File: JTableOperator.java   View Source Code Vote up 2 votes
/**
 * Returns a point at the center of the cell rectangle.
 *
 * @param row a row index
 * @param column a column index
 * @return a Point in component's coordinate system.
 */
public Point getPointToClick(int row, int column) {
    Rectangle rect = getCellRect(row, column, false);
    return (new Point((int) (rect.getX() + rect.getWidth() / 2),
            (int) (rect.getY() + rect.getHeight() / 2)));
}