List of usage examples for java.awt Graphics getColor
public abstract Color getColor();
From source file:BottomBorder.java
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); int i;/*from w ww .ja v a 2 s .c o m*/ g.setColor(lineColor); for (i = 0; i < thickness; i++) { g.drawLine(x, y + height - i - 1, x + width, y + height - i - 1); } g.setColor(oldColor); }
From source file:RightSideBorder.java
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); int i;// w w w .j ava 2 s .c o m g.setColor(lineColor); for (i = 0; i < thickness; i++) { g.drawLine(x + width - i - 1, y, x + width - i - 1, y + height); } g.setColor(oldColor); }
From source file:RectangleBorder.java
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Color oldColor = g.getColor(); g.setColor(lineColor);/*from w ww. jav a 2 s . c o m*/ // top for (int i = 0; i < thickness.top; i++) { g.drawLine(x, y + i, x + width, y + i); } // bottom for (int i = 0; i < thickness.bottom; i++) { g.drawLine(x, y + height - i - 1, x + width, y + height - i - 1); } // right for (int i = 0; i < thickness.right; i++) { g.drawLine(x + width - i - 1, y, x + width - i - 1, y + height); } // left for (int i = 0; i < thickness.left; i++) { g.drawLine(x + i, y, x + i, y + height); } g.setColor(oldColor); }
From source file:Clock.java
public void paintComponent(Graphics g) { super.paintComponent(g); Color colorRetainer = g.getColor(); g.setColor(getBackground());/* w w w .ja va 2s . c o m*/ g.fillRect(0, 0, getWidth(), getHeight()); getBorder().paintBorder(this, g, 0, 0, getWidth(), getHeight()); calendar.setTime(new Date()); // get current time int hrs = calendar.get(Calendar.HOUR_OF_DAY); int min = calendar.get(Calendar.MINUTE); g.setColor(getForeground()); if (isDigital) { String time = "" + hrs + ":" + min; g.setFont(getFont()); FontMetrics fm = g.getFontMetrics(); int y = (getHeight() + fm.getAscent()) / 2; int x = (getWidth() - fm.stringWidth(time)) / 2; g.drawString(time, x, y); } else { int x = getWidth() / 2; int y = getHeight() / 2; int rh = getHeight() / 4; int rm = getHeight() / 3; double ah = ((double) hrs + min / 60.0) / 6.0 * Math.PI; double am = min / 30.0 * Math.PI; g.drawLine(x, y, (int) (x + rh * Math.sin(ah)), (int) (y - rh * Math.cos(ah))); g.drawLine(x, y, (int) (x + rm * Math.sin(am)), (int) (y - rm * Math.cos(am))); } g.setColor(colorRetainer); }
From source file:ro.nextreports.designer.ui.sqleditor.syntax.SyntaxView.java
@Override protected int drawUnselectedText(Graphics graphics, int x, int y, int p0, int p1) { Font saveFont = graphics.getFont(); Color saveColor = graphics.getColor(); SyntaxDocument doc = (SyntaxDocument) getDocument(); Segment segment = getLineBuffer(); try {/* w w w . java 2s.com*/ // Colour the parts Iterator<Token> tokens = doc.getTokens(p0, p1); int start = p0; while (tokens.hasNext()) { Token t = tokens.next(); // if there is a gap between the next token start and where we // should be starting (spaces not returned in tokens), then draw // it in the default type if (start < t.start) { SyntaxStyles.getInstance().setGraphicsStyle(graphics, TokenType.DEFAULT); doc.getText(start, t.start - start, segment); x = Utilities.drawTabbedText(segment, x, y, graphics, this, start); } // t and s are the actual start and length of what we should // put on the screen. assume these are the whole token.... int l = t.length; int s = t.start; // ... unless the token starts before p0: if (s < p0) { // token is before what is requested. adgust the length and s l -= (p0 - s); s = p0; } // if token end (s + l is still the token end pos) is greater // than p1, then just put up to p1 if (s + l > p1) { l = p1 - s; } doc.getText(s, l, segment); x = SyntaxStyles.getInstance().drawText(segment, x, y, graphics, this, t); start = t.start + t.length; } // now for any remaining text not tokenized: if (start < p1) { SyntaxStyles.getInstance().setGraphicsStyle(graphics, TokenType.DEFAULT); doc.getText(start, p1 - start, segment); x = Utilities.drawTabbedText(segment, x, y, graphics, this, start); } } catch (BadLocationException e) { System.err.println("Requested: " + e.offsetRequested()); LOG.error(e.getMessage(), e); } finally { graphics.setFont(saveFont); graphics.setColor(saveColor); } return x; }
From source file:Main.java
protected void paintComponent(Graphics g) { // this will paint the background super.paintComponent(g); Color oldColor = g.getColor(); g.setColor(isEnabled() ? getForeground() : getForeground().brighter()); // paint the arrows int w = getSize().width; int h = getSize().height; for (int i = 0; i < arrowCount; i++) { paintArrow(g, (w - arrowSize// w w w.j a v a 2 s.c o m * (direction == SwingConstants.EAST || direction == SwingConstants.WEST ? arrowCount : 1)) / 2 + arrowSize * (direction == SwingConstants.EAST || direction == SwingConstants.WEST ? i : 0), (h - arrowSize * (direction == SwingConstants.EAST || direction == SwingConstants.WEST ? 1 : arrowCount)) / 2 + arrowSize * (direction == SwingConstants.EAST || direction == SwingConstants.WEST ? 0 : i), g.getColor()); } g.setColor(oldColor); }
From source file:Main.java
private void paintArrow(Graphics g, int x, int y, Color highlight) { int mid, i, j; Color oldColor = g.getColor(); boolean isEnabled = isEnabled(); j = 0;/* w ww . j av a2 s . co m*/ arrowSize = Math.max(arrowSize, 2); mid = (arrowSize / 2) - 1; g.translate(x, y); switch (direction) { case NORTH: for (i = 0; i < arrowSize; i++) { g.drawLine(mid - i, i, mid + i, i); } if (!isEnabled) { g.setColor(highlight); g.drawLine(mid - i + 2, i, mid + i, i); } break; case SOUTH: if (!isEnabled) { g.translate(1, 1); g.setColor(highlight); for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } g.translate(-1, -1); g.setColor(oldColor); } j = 0; for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(mid - i, j, mid + i, j); j++; } break; case WEST: for (i = 0; i < arrowSize; i++) { g.drawLine(i, mid - i, i, mid + i); } if (!isEnabled) { g.setColor(highlight); g.drawLine(i, mid - i + 2, i, mid + i); } break; case EAST: if (!isEnabled) { g.translate(1, 1); g.setColor(highlight); for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(j, mid - i, j, mid + i); j++; } g.translate(-1, -1); g.setColor(oldColor); } j = 0; for (i = arrowSize - 1; i >= 0; i--) { g.drawLine(j, mid - i, j, mid + i); j++; } break; } g.translate(-x, -y); g.setColor(oldColor); }
From source file:ColorSwatch.java
/** * Paints this Icon into the provided graphics context. */// ww w . j av a 2s . c o m public void paintIcon(Component c, Graphics g, int x, int y) { if (ourSwatchIsVoid) return; Color oldColor = g.getColor(); if (ourSwatchIsMultiColor) { g.setColor(Color.white); g.fillRect(x, y, ourSwatchSize, ourSwatchSize); g.setColor(ourBorderColor); for (int i = 0; i < ourSwatchSize; i += 2) { g.drawLine(x + i, y, x + i, y + ourSwatchSize); } } else if (ourSwatchColor != null) { g.setColor(ourSwatchColor); g.fillRect(x, y, ourSwatchSize, ourSwatchSize); } else { g.setColor(Color.white); g.fillRect(x, y, ourSwatchSize, ourSwatchSize); g.setColor(ourBorderColor); g.drawLine(x, y, x + ourSwatchSize, y + ourSwatchSize); g.drawLine(x, y + ourSwatchSize, x + ourSwatchSize, y); } if (ourBorderPainted) { g.setColor(ourBorderColor); g.drawRect(x, y, ourSwatchSize, ourSwatchSize); } g.setColor(oldColor); }
From source file:util.ui.PictureAreaIcon.java
public void paintIcon(final Component c, Graphics g, int x, int y) { if (mScaledIcon == null) { return;/* ww w . j av a 2s . c om*/ } y += 2; Color color = g.getColor(); if (!colorsInEqualRange(c.getBackground(), c.getForeground()) && !mProgram.isExpired()) { g.setColor(c.getBackground()); g.fillRect(x, y, getIconWidth(), getIconHeight() - 2); } g.setColor(color); g.drawRect(x, y, getIconWidth() - 1, getIconHeight() - 3); y += 3; x += 3; if (mIsGrayFilter && !mIsExpired && mProgram.isExpired()) { ImageFilter filter = new GrayFilter(true, 60); mScaledIcon .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter))); mIsExpired = true; } if (c.getForeground().getAlpha() != 255) { ImageFilter filter = new RGBImageFilter() { public int filterRGB(int x, int y, int rgb) { if ((rgb & 0xff000000) != 0) { return (rgb & 0xffffff) | (c.getForeground().getAlpha() << 24); } return rgb; } }; mScaledIcon .setImage(c.createImage(new FilteredImageSource(mScaledIcon.getImage().getSource(), filter))); } mScaledIcon.paintIcon(c, g, x, y); /* if(!mProgram.isExpired()) { g.setColor(color); } else { g.setColor(color); } */ mCopyrightText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight()); if (mDescriptionLines > 0 && mDescriptionText != null) { mDescriptionText.paintIcon(null, g, x, y + mScaledIcon.getIconHeight() + mCopyrightText.getIconHeight() + 1); } g.setColor(color); }
From source file:edu.umn.cs.spatialHadoop.core.OGCESRIShape.java
@Override public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) { OGCGeometry geom = this.geom; Color shape_color = g.getColor(); if (geom instanceof OGCGeometryCollection) { OGCGeometryCollection geom_coll = (OGCGeometryCollection) geom; for (int i = 0; i < geom_coll.numGeometries(); i++) { OGCGeometry sub_geom = geom_coll.geometryN(i); // Recursive call to draw each geometry new OGCESRIShape(sub_geom).draw(g, fileMBR, imageWidth, imageHeight, scale); }// ww w. j a va 2s. co m } else if (geom.getEsriGeometry() instanceof MultiPath) { MultiPath path = (MultiPath) geom.getEsriGeometry(); double sub_geom_alpha = path.calculateLength2D() * scale; int color_alpha = sub_geom_alpha > 1.0 ? 255 : (int) Math.round(sub_geom_alpha * 255); if (color_alpha == 0) return; int[] xpoints = new int[path.getPointCount()]; int[] ypoints = new int[path.getPointCount()]; for (int i = 0; i < path.getPointCount(); i++) { double px = path.getPoint(i).getX(); double py = path.getPoint(i).getY(); // Transform a point in the polygon to image coordinates xpoints[i] = (int) Math.round((px - fileMBR.x1) * imageWidth / fileMBR.getWidth()); ypoints[i] = (int) Math.round((py - fileMBR.y1) * imageHeight / fileMBR.getHeight()); } // Draw the polygon g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); if (path instanceof Polygon) g.drawPolygon(xpoints, ypoints, path.getPointCount()); else if (path instanceof Polyline) g.drawPolyline(xpoints, ypoints, path.getPointCount()); } }