List of usage examples for java.awt Graphics drawRect
public void drawRect(int x, int y, int width, int height)
From source file:org.kalypso.model.flood.ui.map.EventManagementWidget.java
private void paintEnvelope(final Graphics g, final GM_Envelope envelope) { if (envelope == null) { return;//w w w. j a va 2 s .com } final GeoTransform projection = getMapPanel().getProjection(); final GM_Position minPoint = projection.getDestPoint(envelope.getMin()); final GM_Position maxPoint = projection.getDestPoint(envelope.getMax()); final int x = (int) Math.min(minPoint.getX(), maxPoint.getX()); final int y = (int) Math.min(minPoint.getY(), maxPoint.getY()); final int width = (int) Math.abs(minPoint.getX() - maxPoint.getX()); final int height = (int) Math.abs(minPoint.getY() - maxPoint.getY()); g.setColor(Color.RED); g.drawRect(x, y, width, height); }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
public void drawSelectionBox(Point p2) { Graphics g = this.getGraphics(); int x1 = Math.min(p1.x, p2.x); int y1 = Math.min(p1.y, p2.y); int width = Math.abs(p1.x - p2.x); int height = Math.abs(p1.y - p2.y); g.drawRect(x1, y1, width, height); repaint();//from www. j a v a 2s. co m }
From source file:JavaXWin.java
public void paintComponent(Graphics g) { super.paintComponent(g); m_height = getHeight();//from w w w. j av a2s. c o m m_width = getWidth(); g.setColor(C_BACKGROUND); g.fillRect(0, 0, m_width, m_height); Component[] components = m_desktop.getComponents(); m_widthratio = ((float) m_desktop.getWidth()) / ((float) m_width); m_heightratio = ((float) m_desktop.getHeight()) / ((float) m_height); for (int i = components.length - 1; i > -1; i--) { if (components[i].isVisible()) { g.setColor(C_UNSELECTED); if (components[i] instanceof JInternalFrame) { if (((JInternalFrame) components[i]).isSelected()) g.setColor(C_SELECTED); } else if (components[i] instanceof WindowWatcher) g.setColor(C_WWATCHER); g.fillRect((int) (((float) components[i].getX()) / m_widthratio), (int) (((float) components[i].getY()) / m_heightratio), (int) (((float) components[i].getWidth()) / m_widthratio), (int) (((float) components[i].getHeight()) / m_heightratio)); g.setColor(Color.black); g.drawRect((int) (((float) components[i].getX()) / m_widthratio), (int) (((float) components[i].getY()) / m_heightratio), (int) (((float) components[i].getWidth()) / m_widthratio), (int) (((float) components[i].getHeight()) / m_heightratio)); } } g.drawLine(m_width / 2, 0, m_width / 2, m_height); g.drawLine(0, m_height / 2, m_width, m_height / 2); }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.reporting.AnnotationReportCanvas.java
private void xorResizing(AnnotationObject selection, Point start_point, Point end_point) { Graphics g = getGraphics(); g.setXORMode(Color.white);/* w w w.j a v a 2 s.com*/ g.setColor(Color.gray); Rectangle rect = rectangles.get(selection); double scale = 1.; if (start_point.x > midx(rect)) { scale = Math.min((double) (end_point.x - start_point.x + rect.width / 2.) / (double) (rect.width / 2.), (double) (start_point.y - end_point.y + rect.height) / (double) (rect.height)); } else { scale = Math.min((double) (start_point.x - end_point.x + rect.width / 2.) / (double) (rect.width / 2.), (double) (start_point.y - end_point.y + rect.height) / (double) (rect.height)); } scale = Math.max(0., scale); g.drawRect((int) (midx(rect) - rect.width * scale / 2.), (int) (bottom(rect) - rect.height * scale), (int) (rect.width * scale), (int) (rect.height * scale)); }
From source file:ChartPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); if (values == null || values.length == 0) return;/*from ww w .ja v a2s .c om*/ double minValue = 0; double maxValue = 0; for (int i = 0; i < values.length; i++) { if (minValue > values[i]) minValue = values[i]; if (maxValue < values[i]) maxValue = values[i]; } Dimension d = getSize(); int clientWidth = d.width; int clientHeight = d.height; int barWidth = clientWidth / values.length; Font titleFont = new Font("SansSerif", Font.BOLD, 20); FontMetrics titleFontMetrics = g.getFontMetrics(titleFont); Font labelFont = new Font("SansSerif", Font.PLAIN, 10); FontMetrics labelFontMetrics = g.getFontMetrics(labelFont); int titleWidth = titleFontMetrics.stringWidth(title); int y = titleFontMetrics.getAscent(); int x = (clientWidth - titleWidth) / 2; g.setFont(titleFont); g.drawString(title, x, y); int top = titleFontMetrics.getHeight(); int bottom = labelFontMetrics.getHeight(); if (maxValue == minValue) return; double scale = (clientHeight - top - bottom) / (maxValue - minValue); y = clientHeight - labelFontMetrics.getDescent(); g.setFont(labelFont); for (int i = 0; i < values.length; i++) { int valueX = i * barWidth + 1; int valueY = top; int height = (int) (values[i] * scale); if (values[i] >= 0) valueY += (int) ((maxValue - values[i]) * scale); else { valueY += (int) (maxValue * scale); height = -height; } g.setColor(Color.red); g.fillRect(valueX, valueY, barWidth - 2, height); g.setColor(Color.black); g.drawRect(valueX, valueY, barWidth - 2, height); int labelWidth = labelFontMetrics.stringWidth(names[i]); x = i * barWidth + (barWidth - labelWidth) / 2; g.drawString(names[i], x, y); } }
From source file:com.jcraft.weirdx.DDXWindowImpSwing.java
public void paintComponent(Graphics g) { if (window.clss == InputOnly) { super.paintComponent(g); return;/*w w w . j a v a 2 s .c om*/ } if (offi == null) return; g.drawImage(offi, bw, bw, this); Rectangle r = g.getClip().getBounds(); if (bw > 0 && (r.x <= bw || r.y <= bw || (width + bw) <= (r.width + r.x) || (height + bw) <= (r.height + r.y))) { if (window.isBorderPixel()) { g.setColor(window.getColormap().getColor(window.border.pixel)); } else { g.setColor(Color.black); } for (int i = bw - 1; 0 <= i; i--) { g.drawRect(i, i, width + 2 * bw - i * 2 - 1, height + 2 * bw - i * 2 - 1); } } if (window.screen.windowmode == WeirdX.InBrowser || window == window.screen.root) { if (LogoImage.logoimage != null && window.x + r.x <= LogoImage.logoimagewidth && window.y + r.y <= LogoImage.logoimageheight) { g.drawImage(LogoImage.logoimage, 0, 0, LogoImage.logoimagewidth - (window.x - bw), LogoImage.logoimageheight - (window.y - bw), window.x - bw, window.y - bw, LogoImage.logoimagewidth, LogoImage.logoimageheight, this); } else { } } }
From source file:org.tinymediamanager.ui.components.ImageLabel.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (scaledImage != null) { int originalWidth = scaledImage.getWidth(null); int originalHeight = scaledImage.getHeight(null); // calculate new height/width int newWidth = 0; int newHeight = 0; int offsetX = 0; int offsetY = 0; if (drawBorder && !drawFullWidth) { Point size = ImageCache.calculateSize(this.getWidth() - 8, this.getHeight() - 8, originalWidth, originalHeight, true); // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x - 8; }/*from w w w. j a v a 2 s . co m*/ if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y - 8; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x - 8) / 2; offsetY = (this.getHeight() - size.y - 8) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); g.setColor(Color.BLACK); g.drawRect(offsetX, offsetY, size.x + 7, size.y + 7); g.setColor(Color.WHITE); g.fillRect(offsetX + 1, offsetY + 1, size.x + 6, size.y + 6); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX + 4, offsetY + 4, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX + 4, offsetY + 4, newWidth, newHeight, this); } else { Point size = null; if (drawFullWidth) { size = new Point(this.getWidth(), this.getWidth() * originalHeight / originalWidth); } else { size = ImageCache.calculateSize(this.getWidth(), this.getHeight(), originalWidth, originalHeight, true); } // calculate offsets if (position == Position.TOP_RIGHT || position == Position.BOTTOM_RIGHT) { offsetX = this.getWidth() - size.x; } if (position == Position.BOTTOM_LEFT || position == Position.BOTTOM_RIGHT) { offsetY = this.getHeight() - size.y; } if (position == Position.CENTER) { offsetX = (this.getWidth() - size.x) / 2; offsetY = (this.getHeight() - size.y) / 2; } newWidth = size.x; newHeight = size.y; // when the image size differs too much - reload and rescale the original image recreateScaledImageIfNeeded(originalWidth, originalHeight, newWidth, newHeight); // g.drawImage(Scaling.scale(originalImage, newWidth, newHeight), offsetX, offsetY, newWidth, newHeight, this); g.drawImage(scaledImage, offsetX, offsetY, newWidth, newHeight, this); } } else { // draw border and background if (drawBorder) { g.setColor(Color.BLACK); g.drawRect(0, 0, this.getWidth() - 1, this.getHeight() - 1); if (getParent().isOpaque()) { g.setColor(getParent().getBackground()); g.fillRect(1, 1, this.getWidth() - 2, this.getHeight() - 2); } } // calculate diagonal int diagonalSize = (int) Math .sqrt(this.getWidth() * this.getWidth() + this.getHeight() * this.getHeight()); // draw text String text = ""; if (alternativeText != null) { text = alternativeText; } else { text = BUNDLE.getString("image.nonefound"); //$NON-NLS-1$ } if (!getParent().isOpaque()) { text = ""; } Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); AffineTransform orig = g2.getTransform(); AffineTransform at = new AffineTransform(orig); at.translate(0, this.getHeight()); at.rotate(this.getWidth(), -this.getHeight()); g2.setTransform(at); g2.setColor(Color.BLACK); g2.setFont(FONT); FontMetrics fm = g2.getFontMetrics(); int x = (diagonalSize - fm.stringWidth(text)) / 2; int y = (fm.getAscent() - fm.getDescent()) / 2; g2.drawString(text, x, y); // g2.drawLine(0, 0, diagonalSize, 0); at.translate(0, -this.getHeight()); g2.setTransform(orig); } }
From source file:com.jcraft.weirdx.DDXWindowImp.java
public void paintComponent(Graphics g) { /* if(window.clss==InputOnly){ super.paintComponents(g);/*ww w . ja v a2 s . co m*/ return; }*/ if (offi == null) return; g.drawImage(offi, bw, bw, this); if (window == null) return; Rectangle r = g.getClip().getBounds(); if (bw > 0 && (r.x <= bw || r.y <= bw || (width + bw) <= (r.width + r.x) || (height + bw) <= (r.height + r.y))) { if (window.isBorderPixel()) { g.setColor(window.getColormap().getColor(window.border.pixel)); } else { g.setColor(Color.black); } for (int i = bw - 1; 0 <= i; i--) { g.drawRect(i, i, width + 2 * bw - i * 2 - 1, height + 2 * bw - i * 2 - 1); } } if (window.screen.windowmode == WeirdX.InBrowser || window == window.screen.root) { if (LogoImage.logoimage != null && window.x + r.x <= LogoImage.logoimagewidth && window.y + r.y <= LogoImage.logoimageheight) { g.drawImage(LogoImage.logoimage, 0, 0, LogoImage.logoimagewidth - (window.x - bw), LogoImage.logoimageheight - (window.y - bw), window.x - bw, window.y - bw, LogoImage.logoimagewidth, LogoImage.logoimageheight, this); } else { } } }
From source file:com.projity.contrib.calendar.JXXMonthView.java
/** * Paints the background for today. The default is a rectangle drawn in * using the color set by <code>setTodayBackground</code> * * @see #setTodayBackground//from w w w . ja v a 2 s . c om * @param g * Graphics object to paint to. * @param x * x-coordinate of upper left corner. * @param y * y-coordinate of upper left corner. * @param width * width of bounding box for the day. * @param height * height of bounding box for the day. */ protected void paintTodayBackground(Graphics g, int x, int y, int width, int height) { g.setColor(_todayBackgroundColor); g.drawRect(x, y, width - 1, height - 1); }
From source file:com.projity.contrib.calendar.JXXMonthView.java
/** * Paint the background for a selected day. The default is a filled * rectangle in the in the component's background color. * * @param g// w ww . ja v a 2 s . com * Graphics object to paint to. * @param x * x-coordinate of upper left corner. * @param y * y-coordinate of upper left corner. * @param width * width of bounding box for the day. * @param height * height of bounding box for the day. */ protected void paintSelectedDayBackground(Graphics g, int x, int y, int width, int height) { // g.setColor(getSelectedBackground()); // g.fillRect(x, y, width, height); // PROJITY_MODIFICATION g.setColor(_todayBackgroundColor); g.drawRect(x, y, width - 1, height - 1); }