List of usage examples for java.awt Graphics getColor
public abstract Color getColor();
From source file:Main.java
public static void setLabelCenter(JLabel label, String str, int width, int height) { Graphics g = label.getGraphics(); Color c = g.getColor(); g.setColor(Color.BLUE);//from ww w.jav a 2 s . c o m label.setText(str); int strWidth = SwingUtilities.computeStringWidth(g.getFontMetrics(), str); int lX = width / 2 - strWidth; int lY = g.getFont().getSize() / 2; //System.out.printf("\"label\"+%s X:%d,Y:%d\n",str,lX,lY); label.setBounds(lX, lY, strWidth, g.getFont().getSize()); g.setColor(c); }
From source file:GraphicsUtil.java
public static void drawOptimizedLine(Graphics g, int x1, int y1, int x2, int y2) { if (g.getColor().getAlpha() < 255 && (x1 == x2 || y1 == y2)) g.fillRect(x1 < x2 ? x1 : x2, y1 < y2 ? y1 : y2, Math.abs(x2 - x1) + 1, Math.abs(y2 - y1) + 1); else/*w w w .ja v a2s . c o m*/ g.drawLine(x1, y1, x2, y2); }
From source file:Main.java
public static void drawGroove(Graphics g, int x, int y, int w, int h, Color shadow, Color highlight) { Color oldColor = g.getColor(); // Make no net change to g g.translate(x, y);// w ww . j av a2 s . com g.setColor(shadow); g.drawRect(0, 0, w - 2, h - 2); g.setColor(highlight); g.drawLine(1, h - 3, 1, 1); g.drawLine(1, 1, w - 3, 1); g.drawLine(0, h - 1, w - 1, h - 1); g.drawLine(w - 1, h - 1, w - 1, 0); g.translate(-x, -y); g.setColor(oldColor); }
From source file:org.kalypso.kalypsomodel1d2d.ui.map.grid.LinePointCollector.java
private static final void drawHandles(final Graphics g, final int[] x, final int[] y, final int pointRectWidth, final int selection) { final Color oldColor = g.getColor(); g.setColor(oldColor.darker());//from w w w . j a v a2 s. c om // int sizeOuter = 4; final int halfRectWidth = pointRectWidth / 2; if (selection < 0) { for (int i = 0; i < y.length; i++) { g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth); } } else { int i; for (i = 0; i < selection; i++) { g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth); } // is is now selection g.drawOval(x[i] - pointRectWidth, y[i] - pointRectWidth, pointRectWidth + pointRectWidth, pointRectWidth + pointRectWidth); i++; for (; i < y.length; i++) { g.drawRect(x[i] - halfRectWidth, y[i] - halfRectWidth, pointRectWidth, pointRectWidth); } } g.setColor(oldColor); }
From source file:org.kalypso.ogc.gml.map.widgets.advanced.utils.GeometryPainter.java
public static void drawLineString(final IMapPanel mapPanel, final Graphics g, final Point[] myPoints, final Color color) throws GM_Exception { final List<java.awt.Point> awtPoints = new ArrayList<>(); final Set<Coordinate> coordinates = new LinkedHashSet<>(); for (final Point point : myPoints) { coordinates.add(point.getCoordinate()); final GM_Point gmp = (GM_Point) JTSAdapter.wrap(point); final java.awt.Point awt = MapUtilities.retransform(mapPanel, gmp); awtPoints.add(awt);//w w w . j a va 2 s .c o m } final Color original = g.getColor(); g.setColor(color); for (int i = 0; i < awtPoints.size() - 1; i++) { final java.awt.Point p1 = awtPoints.get(i); final java.awt.Point p2 = awtPoints.get(i + 1); g.drawLine(Double.valueOf(p1.getX()).intValue(), Double.valueOf(p1.getY()).intValue(), Double.valueOf(p2.getX()).intValue(), Double.valueOf(p2.getY()).intValue()); } g.setColor(original); }
From source file:Main.java
public void paint(Graphics g) { g.drawString(g.getColor() + "", 10, 30); }
From source file:Main.java
@Override public void paintComponent(Graphics gr) { Color c = gr.getColor(); setForeground(new Color(0, 0, 0, 0)); super.paintComponent(gr); setForeground(c);//from w w w. j a va 2 s .c o m gr.setColor(c); Graphics2D g = (Graphics2D) gr; g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); double pw = this.getPreferredSize().width; double ph = this.getPreferredSize().height; double w = this.getSize().width; double h = this.getSize().height; g.setColor(this.getForeground()); AffineTransform stretch = AffineTransform.getScaleInstance(w / pw, h / ph); g.setTransform(stretch); g.drawString(getText(), 0, this.getFont().getSize()); }
From source file:PlainColorIcon.java
public void paintIcon(Component c, Graphics g, int x, int y) { Color old_color = g.getColor(); g.setColor(color);//from w ww.j ava2 s. com g.fillRect(x, y, 10, 10); g.setColor(old_color); }
From source file:AlignLabels.java
public void paintIcon(Component c, Graphics g, int x, int y) { Color oldColor = g.getColor(); g.setColor(color);/*from w ww. j a v a 2 s . c o m*/ g.fill3DRect(x, y, getIconWidth(), getIconHeight(), true); g.setColor(oldColor); }
From source file:org.kalypso.ogc.gml.map.widgets.advanced.utils.GeometryPainter.java
public static void drawPolygon(final IMapPanel mapPanel, final Graphics g, final Polygon polygon, final Color border, final Color fill) { final LineString ring = polygon.getExteriorRing(); int[] x = new int[] {}; int[] y = new int[] {}; for (int i = 0; i < ring.getNumPoints(); i++) { try {/*from ww w .j a v a2s .c o m*/ final Point p = ring.getPointN(i); final GM_Point gmp = (GM_Point) JTSAdapter.wrap(p); final java.awt.Point awt = MapUtilities.retransform(mapPanel, gmp); x = ArrayUtils.add(x, awt.x); y = ArrayUtils.add(y, awt.y); } catch (final GM_Exception e) { KalypsoCorePlugin.getDefault().getLog().log(StatusUtilities.statusFromThrowable(e)); } } Assert.isTrue(x.length == y.length); final java.awt.Polygon poly = new java.awt.Polygon(x, y, x.length); final Color original = g.getColor(); g.setColor(fill); g.fillPolygon(poly); g.setColor(border); g.drawPolygon(poly); g.setColor(original); }