List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
From source file:AppletMenuBarDemo.java
/** * This method is called to draw tell the component to redraw itself. If we * were implementing a Swing component, we'd override paintComponent() * instead//from www. ja v a 2 s .c o m */ public void paint(Graphics g) { if (remeasure) measure(); // Remeasure everything first, if needed // Figure out Y coordinate to draw at Dimension size = getSize(); int baseline = size.height - margins.bottom - descent; // Set the font to draw with g.setFont(getFont()); // Loop through the labels int nummenus = labels.size(); for (int i = 0; i < nummenus; i++) { // Set the drawing color. Highlight the current item if ((i == highlightedItem) && (highlightColor != null)) g.setColor(getHighlightColor()); else g.setColor(getForeground()); // Draw the menu label at the position computed in measure() g.drawString((String) labels.elementAt(i), startPositions[i], baseline); } // Now draw a groove at the bottom of the menubar. Color bg = getBackground(); g.setColor(bg.darker()); g.drawLine(0, size.height - 2, size.width, size.height - 2); g.setColor(bg.brighter()); g.drawLine(0, size.height - 1, size.width, size.height - 1); }
From source file:org.fhaes.fhfilechecker.FrameViewOutput.java
@Override public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { try {/*from w w w.j ava2s . com*/ // For catching IOException if (pageIndex != rememberedPageIndex) { // First time we've visited this page rememberedPageIndex = pageIndex; // If encountered EOF on previous page, done if (rememberedEOF) { return Printable.NO_SUCH_PAGE; } // Save current position in input file rememberedFilePointer = raf.getFilePointer(); } else { raf.seek(rememberedFilePointer); } g.setColor(Color.black); g.setFont(fnt); int x = (int) pf.getImageableX() + 10; int y = (int) pf.getImageableY() + 12; // Title line g.drawString("File: " + fileName + ", page: " + (pageIndex + 1), x, y); // Generate as many lines as will fit in imageable area y += 36; while (y + 12 < pf.getImageableY() + pf.getImageableHeight()) { String line = raf.readLine(); if (line == null) { rememberedEOF = true; break; } g.drawString(line, x, y); y += 12; } return Printable.PAGE_EXISTS; } catch (Exception e) { return Printable.NO_SUCH_PAGE; } }
From source file:edu.umn.cs.spatialHadoop.osm.OSMEdge.java
@Override public void draw(Graphics g, Rectangle fileMBR, int imageWidth, int imageHeight, double scale) { int x1 = (int) ((this.lon1 - fileMBR.x1) * imageWidth / fileMBR.getWidth()); int y1 = (int) ((this.lat1 - fileMBR.y1) * imageHeight / fileMBR.getHeight()); int x2 = (int) ((this.lon2 - fileMBR.x1) * imageWidth / fileMBR.getWidth()); int y2 = (int) ((this.lat2 - fileMBR.y1) * imageHeight / fileMBR.getHeight()); Color shape_color = g.getColor(); // Compute alpha to use based on edge length and image scale double geom_alpha = this.getLength() * scale; int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255); if (color_alpha == 0) return;// w w w. j av a 2 s .com g.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); g.drawLine(x1, y1, x2, y2); }
From source file:it.unibo.alchemist.boundary.monitors.Generic2DDisplay.java
private void drawFriedEgg(final Graphics g, final int x, final int y, final Color c1, final Color c2) { g.setColor(c1); g.fillOval(x - SELECTED_NODE_DRAWING_SIZE / 2, y - SELECTED_NODE_DRAWING_SIZE / 2, SELECTED_NODE_DRAWING_SIZE, SELECTED_NODE_DRAWING_SIZE); g.setColor(c2);/*from w w w. j a va 2s.c o m*/ g.fillOval(x - SELECTED_NODE_INTERNAL_SIZE / 2, y - SELECTED_NODE_INTERNAL_SIZE / 2, SELECTED_NODE_INTERNAL_SIZE, SELECTED_NODE_INTERNAL_SIZE); }
From source file:javazoom.jlgui.player.amp.visual.ui.SpectrumTimeAnalyzer.java
private void drawSpectrumAnalyserBar(Graphics pGraphics, int pX, int pY, int pWidth, int pHeight, int band) { float c = 0;//from w w w .ja va 2 s.c om for (int a = pY; a >= pY - pHeight; a -= barOffset) { c += saColorScale; if (c < spectrumAnalyserColors.length) { pGraphics.setColor(spectrumAnalyserColors[(int) c]); } pGraphics.fillRect(pX, a, pWidth, 1); } if ((peakColor != null) && (peaksEnabled == true)) { pGraphics.setColor(peakColor); if (pHeight > peaks[band]) { peaks[band] = pHeight; peaksDelay[band] = peakDelay; } else { peaksDelay[band]--; if (peaksDelay[band] < 0) peaks[band]--; if (peaks[band] < 0) peaks[band] = 0; } pGraphics.fillRect(pX, pY - peaks[band], pWidth, 1); } }
From source file:JXTransformer.java
public void paint(Graphics g) { //repaint the whole transformer in case the view component was repainted Rectangle clipBounds = g.getClipBounds(); if (clipBounds != null && !clipBounds.equals(visibleRect)) { repaint();//from w ww. j av a2 s .co m } //clear the background g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); if (view != null && at.getDeterminant() != 0) { Graphics2D g2 = (Graphics2D) g.create(); Insets insets = getInsets(); Rectangle bounds = getBounds(); //don't forget about insets bounds.x += insets.left; bounds.y += insets.top; bounds.width -= insets.left + insets.right; bounds.height -= insets.top + insets.bottom; double centerX1 = bounds.getCenterX(); double centerY1 = bounds.getCenterY(); Rectangle tb = getTransformedSize(); double centerX2 = tb.getCenterX(); double centerY2 = tb.getCenterY(); //set antialiasing by default g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); if (renderingHints != null) { g2.addRenderingHints(renderingHints); } //translate it to the center of the view component again double tx = centerX1 - centerX2 - getX(); double ty = centerY1 - centerY2 - getY(); g2.translate((int) tx, (int) ty); g2.transform(at); view.paint(g2); g2.dispose(); } //paint the border paintBorder(g); }
From source file:com.jcraft.weirdx.Draw.java
static void reqImageText8(Client c, XDrawable d, GC gc, int x, int y) throws IOException { int len = c.data; int n = c.length; //int foo;/*w w w .j a v a2 s .co m*/ InputOutput io = c.client; Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCFont); if (graphics == null) { io.readPad(n * 4); return; } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { io.readPad(4 * n); return; } } XFont font = gc.font; { io.readByte(c.bbuffer, 0, len); //java.awt.FontMetrics metric=graphics.getFontMetrics(); Color tmp = graphics.getColor(); graphics.setColor(d.getColormap().getColor(gc.bgPixel)); if (len > 0) { io.readPad((-len) & 3); } if (font.encoding != null) { len = font.encode(c.bbuffer, 0, len, c.cbuffer); } else { char ccc = 0; for (int i = 0; i < len; i++) { ccc = c.cbuffer[i] = (char) (c.bbuffer[i] & 0xff); if (ccc < 0x20) { if (ccc == 11) c.cbuffer[i] = (char) '+'; else if (ccc == 12) c.cbuffer[i] = (char) '+'; else if (ccc == 13) c.cbuffer[i] = (char) '+'; else if (ccc == 14) c.cbuffer[i] = (char) '+'; else if (ccc == 15) c.cbuffer[i] = (char) '+'; else if (ccc == 18) c.cbuffer[i] = (char) '-'; else if (ccc == 21) c.cbuffer[i] = (char) '+'; else if (ccc == 22) c.cbuffer[i] = (char) '+'; else if (ccc == 23) c.cbuffer[i] = (char) '+'; else if (ccc == 24) c.cbuffer[i] = (char) '+'; else if (ccc == 25) c.cbuffer[i] = (char) '|'; else c.cbuffer[i] = (char) 0x20; } } } graphics.fillRect(x, y - (font.ascent), font.charsWidth(c.cbuffer, 0, len), font.ascent + font.descent); graphics.setColor(tmp); graphics.drawChars(c.cbuffer, 0, len, x, y); } if (d instanceof XWindow) { ((XWindow) d).draw(x, y - (font.ascent), font.charsWidth(c.cbuffer, 0, len), font.ascent + font.descent); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:CornerCaret.java
public void paint(Graphics g) { JTextComponent comp = getComponent(); if (comp == null) return;//from w w w . j a v a 2s .co m int dot = getDot(); Rectangle r = null; try { r = comp.modelToView(dot); } catch (BadLocationException e) { return; } if (r == null) return; int dist = r.height * 4 / 5 - 3; // will be distance from r.y to top if ((x != r.x) || (y != r.y + dist)) { // paint() has been called directly, without a previous call to // damage(), so do some cleanup. (This happens, for example, when // the // text component is resized.) repaint(); // erase previous location of caret x = r.x; // set new values for x,y,width,height y = r.y + dist; width = 5; height = 5; } if (isVisible()) { g.setColor(comp.getCaretColor()); g.drawLine(r.x, r.y + dist, r.x, r.y + dist + 4); // 5 vertical // pixels g.drawLine(r.x, r.y + dist + 4, r.x + 4, r.y + dist + 4); // 5 horiz // px } }
From source file:ColorGradient.java
/** * Draw a color gradient from the top of the specified component to the * bottom. Start with the start color and change smoothly to the end *///www . j a v a 2 s.c o m public void fillGradient(Component c, Graphics g, Color start, Color end) { Rectangle bounds = this.getBounds(); // How big is the component? // Get the red, green, and blue components of the start and end // colors as floats between 0.0 and 1.0. Note that the Color class // also works with int values between 0 and 255 float r1 = start.getRed() / 255.0f; float g1 = start.getGreen() / 255.0f; float b1 = start.getBlue() / 255.0f; float r2 = end.getRed() / 255.0f; float g2 = end.getGreen() / 255.0f; float b2 = end.getBlue() / 255.0f; // Figure out how much each component should change at each y value float dr = (r2 - r1) / bounds.height; float dg = (g2 - g1) / bounds.height; float db = (b2 - b1) / bounds.height; // Now loop once for each row of pixels in the component for (int y = 0; y < bounds.height; y++) { g.setColor(new Color(r1, g1, b1)); // Set the color of the row g.drawLine(0, y, bounds.width - 1, y); // Draw the row r1 += dr; g1 += dg; b1 += db; // Increment color components } }
From source file:AlphaTest.java
/** * Draws the axes for the graph./*w ww. ja v a2 s . co m*/ */ protected void drawAxes(Graphics g, long lMaxTime) { drawGraphString(g, -1, "Alpha vs. Time (ms)", m_nGraphMaxWidth / 2, m_nGraphMaxHeight + 20); // draw the frame drawAreaRect(g, 0, 0, m_nMaxWidth, m_nMaxHeight); // draw the X axis drawGraphLine(g, 0, 0, m_nGraphMaxWidth, 0); // draw the Y axis drawGraphLine(g, 0, 0, 0, m_nGraphMaxHeight); // draw the horizontal Y axis lines for (double yAxisTick = 0; yAxisTick <= 1.0; yAxisTick += 0.2) { double yTick = yAxisTick * m_nGraphMaxHeight; g.setColor(Color.gray); drawGraphLine(g, 0, yTick, m_nGraphMaxWidth, yTick); g.setColor(Color.black); drawGraphString(g, 3, "" + yAxisTick, -20, yTick); } }