public void paint(Graphics g, JComponent c) { Dimension s = c.getSize(); if (WindowsMenuItemUI.isVistaPainting()) { int x = 1; Component parent = c.getParent(); if (parent instanceof JComponent) { Object gutterOffsetObject = ((JComponent) parent).getClientProperty(WindowsPopupMenuUI.GUTTER_OFFSET_KEY); if (gutterOffsetObject instanceof Integer) { /* * gutter offset is in parent's coordinates. * See comment in * WindowsPopupMenuUI.getTextOffset(JComponent) */ x = ((Integer) gutterOffsetObject).intValue() - c.getX(); x += WindowsPopupMenuUI.getGutterWidth(); } } Skin skin = XPStyle.getXP().getSkin(c, Part.MP_POPUPSEPARATOR); int skinHeight = skin.getHeight(); int y = (s.height - skinHeight) / 2; skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL); } else { int y = s.height / 2; g.setColor(c.getForeground()); g.drawLine(1, y - 1, s.width - 2, y - 1); g.setColor(c.getBackground()); g.drawLine(1, y, s.width - 2, y); } }
private void drawColorBar(Graphics g) { int minimum, maximum, height; minimum = 100; maximum = 500; height = 1; int finalI = 0; for (int i = 0; i < (maximum - minimum); i++) { float f = 0.75f * i / (float) (maximum - minimum); g.setColor(Color.getHSBColor(0.75f - f, 1.0f, 1.0f)); g.fillRect(getWidth() - 40, height * i + 50, 20, height); finalI = i; } g.setColor(Color.BLACK); g.drawString( String.valueOf(this.opticalReturnPowerController.getMaxValue()), getWidth() - 60, 48); // Max Value g.drawString( String.valueOf(this.opticalReturnPowerController.getMinValue()), getWidth() - 60, finalI + 63); // Min Value }
protected void paintText(Graphics g, JComponent com, Rectangle rect, String s) { JButtonLinkA bn = (JButtonLinkA) com; ButtonModel bnModel = bn.getModel(); Color color = bn.getForeground(); Object obj = null; if (bnModel.isEnabled()) { if (bnModel.isPressed()) bn.setForeground(bn.getActiveLinkColor()); else if (bn.isLinkVisited()) bn.setForeground(bn.getVisitedLinkColor()); else bn.setForeground(bn.getLinkColor()); } else { if (bn.getDisabledLinkColor() != null) bn.setForeground(bn.getDisabledLinkColor()); } super.paintText(g, com, rect, s); int behaviour = bn.getLinkBehavior(); boolean drawLine = false; if (behaviour == JButtonLinkA.HOVER_UNDERLINE) { if (bnModel.isRollover()) drawLine = true; } else if (behaviour == JButtonLinkA.ALWAYS_UNDERLINE || behaviour == JButtonLinkA.SYSTEM_DEFAULT) drawLine = true; if (!drawLine) return; FontMetrics fm = g.getFontMetrics(); int x = rect.x + getTextShiftOffset(); int y = (rect.y + fm.getAscent() + fm.getDescent() + getTextShiftOffset()) - 1; if (bnModel.isEnabled()) { g.setColor(bn.getForeground()); g.drawLine(x, y, (x + rect.width) - 1, y); } else { g.setColor(bn.getBackground().brighter()); g.drawLine(x, y, (x + rect.width) - 1, y); } }
public void paintComponent(Graphics g) { g.setColor(new Color(0x8090ff)); g.fillRect(0, 0, level.length * 16, level.height * 16); levelRenderer.render(g, 0); g.setColor(Color.BLACK); g.drawRect(xTile * 16 - 1, yTile * 16 - 1, 17, 17); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { JMenuItem b = (JMenuItem) c; ButtonModel model = b.getModel(); Color borderColorLo = AbstractLookAndFeel.getFrameColor(); Color borderColorHi = ColorHelper.brighter(AbstractLookAndFeel.getMenuSelectionBackgroundColor(), 40); if (c.getParent() instanceof JMenuBar) { if (model.isArmed() || model.isSelected()) { g.setColor(borderColorLo); g.drawLine(x, y, x + w - 1, y); g.drawLine(x, y, x, y + h - 1); g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1); g.setColor(borderColorHi); g.drawLine(x + 1, y + 1, x + w - 2, y + 1); g.drawLine(x + 1, y + 1, x + 1, y + h - 1); } } else { if (model.isArmed() || (c instanceof JMenu && model.isSelected())) { g.setColor(borderColorLo); g.drawLine(x, y, x + w - 1, y); g.drawLine(x, y + h - 1, x + w - 1, y + h - 1); g.setColor(borderColorHi); g.drawLine(x, y + 1, x + w - 2, y + 1); } } }
// färger, se sid 43 i boken // grafiska metoder, sid 248 i boken public void paintComponent(Graphics g) { // för att vara säker på att // "super"-klassen gör sitt // anropar vi den metoden, innan // vi skriver eller ritar super.paintComponent(g); g.drawLine(185, 10, 195, 40); // x1,y1 till x2,y2 g.drawLine(200, 10, 200, 40); g.drawLine(215, 10, 205, 40); g.setColor(Color.white); g.fillOval(50, 30, 300, 150); // x,y,b,h (x,y för ö v h) g.setColor(Color.red); g.drawArc(100, 100, 200, 50, 180, 180); // x,y,b,h,s,l g.setColor(Color.yellow); g.fillRect(200, 100, 30, 30); g.fill3DRect(150, 50, 30, 50, true); // true upphöjd figur g.fill3DRect(250, 50, 30, 50, true); // skriv ut en textsträng, samt ange läget i avståndet från // övre vänstra hörnet i x-led åt höger och i y-led neråt g.drawString("** Tjenare kompis !! **", 20, 20); f = new Font("Arial", Font.BOLD, 30); setBackground(Color.cyan); g.setFont(f); g.setColor(new Color(255, 175, 175)); g.drawString("YEEEEEEEES!!", 100, 250); }
// draws the button, based on the type of button (ImageIcon, Image, or String) public void draw(Graphics g) { if (visible) { // if its image/imageicon, draw it g.setColor(new Color(50, 200, 50)); g.fillRect(x - 1, y - 1, width + 2, height + 2); if (mode.equals("Image") || mode.equals("ImageIcon")) { if (enabled) { g.drawImage(image, x, y, null); } else { g.drawImage(BWimage, x, y, null); } // if its string, draw the string } else { g.setFont(new Font("Arial", Font.PLAIN, 20)); if (enabled) { g.setColor(Color.black); g.drawString(message, x + 20, y + 20); } else { g.setColor(new Color(255, 255, 255)); g.fillRect(x - 1, y - 1, width + 2, height + 2); g.setColor(Color.black); g.drawString(message, x + 20, y + 20); } } } }
@Override protected void paintText( final Graphics g, final JComponent c, final Rectangle textRect, final String text) { final AbstractButton b = (AbstractButton) c; final ButtonModel model = b.getModel(); final FontMetrics fm = SwingUtils.getFontMetrics(c, g); final int mnemonicIndex = b.getDisplayedMnemonicIndex(); // Drawing text if (model.isEnabled()) { // Normal text g.setColor(b.getForeground()); SwingUtils.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); } else { // Disabled text g.setColor(b.getBackground().brighter()); SwingUtils.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent()); g.setColor(b.getBackground().darker()); SwingUtils.drawStringUnderlineCharAt( g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1); } }
private void drawButton(Graphics g, int x, int y, String txt) { g.setColor(Color.white); g.fillRect(x, y, 30, 30); g.setColor(Color.black); g.drawRect(x, y, 30, 30); g.drawString(txt, x + 18, y + 18); }
/** * This is called to paint within the EditCanvas * * @param g Graphics * @param c DisplayCanvas to paint on. */ public void paint(Graphics g, DisplayCanvas c) { Rectangle nb = transformOutput(c, getBounds()); if (!getActive()) { Rectangle r = getBounds(); g.setColor(Color.lightGray); g.fillRect(r.x, r.y, r.width, r.height); } draw((Graphics2D) g, nb.x, nb.y, nb.width, nb.height); if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).getShowParams()) { int xoff = 0; FontMetrics fm = g.getFontMetrics(); g.setColor(Color.black); for (int i = 0; i < paramIds.length; i++) { String s = paramIds[i]; if (i > 0) { s = ", " + s; } g.drawString(s, nb.x + xoff, nb.y + nb.height + fm.getMaxDescent() + fm.getMaxAscent() + 4); xoff += fm.stringWidth(s); } } if ((c instanceof StationModelCanvas) && ((StationModelCanvas) c).shouldShowAlignmentPoints()) { paintRectPoint(g, c); } }
public void draw(Graphics g, Color c, boolean draw_name) { g.setColor(c); g.fillRect(this.x, this.y, this.sx, this.sy); g.setColor(Color.black); g.drawRect(this.x, this.y, this.sx, this.sy); if (draw_name) g.drawString(this.name, this.x, this.y); }
/** * The function prints out key to jumpshot data. */ int print (Graphics g, int x, int y, int width, int height) { Font f = g.getFont (); FontMetrics fm = getToolkit ().getFontMetrics (f); int charW = fm.stringWidth (" "), charH = fm.getHeight (); int hgap1 = charW, hgap2 = 2 * charW, vgap = fm.getAscent (); int rectW = 30, rectH = charH; //Dimensions of state rectangles int xcord = x, ycord = y; Enumeration enum = parent.stateDefs.elements (); while (enum.hasMoreElements ()) { RecDef s = (RecDef)enum.nextElement (); if (s.stateVector.size () > 0) { int strW = fm.stringWidth (s.description); if ((xcord + rectW + hgap1 + strW) > (width + x)) { xcord = x; ycord += (charH + vgap); } g.setColor (s.color); g.fillRect (xcord, ycord, rectW, rectH); g.setColor (Color.black); g.drawRect (xcord, ycord, rectW - 1, rectH - 1); g.drawString( s.description, xcord + rectW + hgap1, ycord + rectH - fm.getDescent () - 1); xcord += (rectW + hgap1 + strW + hgap2); } } return (ycord - y + (2 * charH)); }
public void paintComponent(Graphics g) { if (name == "" && serialport == "") { Map<String, String> boardPreferences = Base.getBoardPreferences(); if (boardPreferences != null) setBoardName(boardPreferences.get("name")); else setBoardName("-"); setSerialPort(Preferences.get("serial.port")); } g.setColor(background); Dimension size = getSize(); g.fillRect(0, 0, size.width, size.height); g.setFont(font); g.setColor(foreground); int baseline = (high + g.getFontMetrics().getAscent()) / 2; g.drawString(text, 6, baseline); g.setColor(messageForeground); String tmp = name + " on " + serialport; Rectangle2D bounds = g.getFontMetrics().getStringBounds(tmp, null); g.drawString(tmp, size.width - (int) bounds.getWidth() - 20, baseline); if (Base.isMacOS()) { g.drawImage(resize, size.width - 20, 0, this); } }
public void paint(Graphics canvas) { this.setBackground(Color.WHITE); canvas.setColor(Color.GREEN); canvas.fillPolygon(xBranches, yBranches, xBranches.length); canvas.setColor(Color.GRAY); canvas.fillPolygon(xTrunk, yTrunk, xTrunk.length); }
public void drawTo(Graphics g, Line line) { if (!calc.tileOnMap(t1) || !calc.tileOnMap(t2)) return; if (calc.tileOnMap(line.getTile1()) && calc.tileOnMap(line.getTile2())) { Point p1 = calc.tileToMinimap(t1); Point p2 = calc.tileToMinimap(t2); Point p3 = calc.tileToMinimap(line.getTile2()); Point p4 = calc.tileToMinimap(line.getTile1()); GeneralPath path = new GeneralPath(); path.moveTo(p1.x, p1.y); path.lineTo(p2.x, p2.y); path.lineTo(p3.x, p3.y); path.lineTo(p4.x, p4.y); path.closePath(); g.setColor(POLY_FILL); ((Graphics2D) g).fill(path); ((Graphics2D) g).draw(path); } Point last = null, p; g.setColor(Color.ORANGE); for (RSTile t : pathList) { if (calc.tileOnMap(t)) { p = calc.tileToMinimap(t); g.fillOval(p.x - 2, p.y - 2, 5, 5); if (last != null) g.drawLine(p.x, p.y, last.x, last.y); last = p; } else last = null; } }
protected void paintBackground(Graphics g, JComponent c, int x, int y, int w, int h) { JMenuItem b = (JMenuItem) c; ButtonModel model = b.getModel(); if (model.isArmed() || (c instanceof JMenu && model.isSelected())) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getMenuSelectionColors(), x, y, w, h); } else if (!AbstractLookAndFeel.getTheme().isMenuOpaque()) { Graphics2D g2D = (Graphics2D) g; Composite composite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance( AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha()); g2D.setComposite(alpha); g.setColor(AbstractLookAndFeel.getMenuBackgroundColor()); g.fillRect(x, y, w, h); g2D.setComposite(composite); } else { g.setColor(AbstractLookAndFeel.getMenuBackgroundColor()); g.fillRect(x, y, w, h); } if (menuItem.isSelected() && menuItem.isArmed()) { g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor()); } else { g.setColor(AbstractLookAndFeel.getMenuForegroundColor()); } }
private void drawSquare(Graphics g, int x, int y, Tetrominoes shape) { int squareWidth = (int) getSize().getWidth() / model.getWidth(); int squareHeight = (int) getSize().getHeight() / model.getHeight(); Color colors[] = { new Color(0, 0, 0), new Color(204, 102, 102), new Color(102, 204, 102), new Color(102, 102, 204), new Color(204, 204, 102), new Color(204, 102, 204), new Color(102, 204, 204), new Color(218, 170, 0) }; Color color = colors[shape.ordinal()]; g.setColor(color); g.fillRect(x + 1, y + 1, squareWidth - 2, squareHeight - 2); g.setColor(color.brighter()); g.drawLine(x, y + squareHeight - 1, x, y); g.drawLine(x, y, x + squareWidth - 1, y); g.setColor(color.darker()); g.drawLine(x + 1, y + squareHeight - 1, x + squareWidth - 1, y + squareHeight - 1); g.drawLine(x + squareWidth - 1, y + squareHeight - 1, x + squareWidth - 1, y + 1); }
/** * As of Java 2 platform v 1.4 this method should not be used or overriden. Use the paintText * method which takes the AbstractButton argument. */ protected void paintText(Graphics g, JComponent c, Rectangle textRect, String text) { AbstractButton b = (AbstractButton) c; ButtonModel model = b.getModel(); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g); int mnemonicIndex = b.getDisplayedMnemonicIndex(); /* Draw the Text */ if (model.isEnabled()) { /** * paint the text normally */ g.setColor(b.getForeground()); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex, textRect.x + getTextShiftOffset(), textRect.y + fm.getAscent() + getTextShiftOffset()); } else { /** * paint the text disabled ** */ g.setColor(b.getBackground().brighter()); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent()); g.setColor(b.getBackground().darker()); SwingUtilities2.drawStringUnderlineCharAt( c, g, text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1); } }
public void paint(Graphics g) { MetalBumps usedBumps; if (splitPane.hasFocus()) { usedBumps = focusBumps; g.setColor(primaryControlColor); } else { usedBumps = bumps; g.setColor(controlColor); } Rectangle clip = g.getClipBounds(); Insets insets = getInsets(); g.fillRect(clip.x, clip.y, clip.width, clip.height); Dimension size = getSize(); size.width -= inset * 2; size.height -= inset * 2; int drawX = inset; int drawY = inset; if (insets != null) { size.width -= (insets.left + insets.right); size.height -= (insets.top + insets.bottom); drawX += insets.left; drawY += insets.top; } usedBumps.setBumpArea(size); usedBumps.paintIcon(this, g, drawX, drawY); super.paint(g); }
private void paintBell(Graphics g) { P9TermPreferences preferences = P9Term.getPreferences(); if (preferences.getBoolean(P9TermPreferences.VISUAL_BELL) == false) { return; } Color foreground = preferences.getColor(P9TermPreferences.FOREGROUND_COLOR); if (preferences.getBoolean(P9TermPreferences.FANCY_BELL)) { // On decent hardware, we can produce a really tasteful effect by compositing a // semi-transparent rectangle over the terminal. // We need to choose a color that will show up against the background. // A reasonable assumption is that the user has already chosen such a color for the // foreground. Color color = new Color(foreground.getRed(), foreground.getGreen(), foreground.getBlue(), 100); g.setColor(color); g.fillRect(0, 0, getWidth(), getHeight()); } else { // On a remote X11 display (or really rubbish hardware) the compositing effect is // prohibitively expensive, so we offer XOR instead. Color background = preferences.getColor(P9TermPreferences.BACKGROUND_COLOR); ; final int R = blend(background.getRed(), foreground.getRed()); final int G = blend(background.getGreen(), foreground.getGreen()); final int B = blend(background.getBlue(), foreground.getBlue()); g.setColor(background); g.setXORMode(new Color(R, G, B)); g.fillRect(0, 0, getWidth(), getHeight()); g.setPaintMode(); } }
public void paintPalette(Graphics g) { boolean leftToRight = MetalUtils.isLeftToRight(frame); int width = getWidth(); int height = getHeight(); if (paletteBumps == null) { paletteBumps = new MetalBumps( 0, 0, MetalLookAndFeel.getPrimaryControlHighlight(), MetalLookAndFeel.getPrimaryControlInfo(), MetalLookAndFeel.getPrimaryControlShadow()); } Color background = MetalLookAndFeel.getPrimaryControlShadow(); Color darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow(); g.setColor(background); g.fillRect(0, 0, width, height); g.setColor(darkShadow); g.drawLine(0, height - 1, width, height - 1); int xOffset = leftToRight ? 4 : buttonsWidth + 4; int bumpLength = width - buttonsWidth - 2 * 4; int bumpHeight = getHeight() - 4; paletteBumps.setBumpArea(bumpLength, bumpHeight); paletteBumps.paintIcon(this, g, xOffset, 2); }
protected void paintBackground(Graphics g) { int draggedColumn = -1; if ((header != null) && (header.getTable() != null) && header.getDraggedColumn() != null) { draggedColumn = header.getColumnModel().getColumnIndex(header.getDraggedColumn().getIdentifier()); } int w = getWidth(); int h = getHeight(); if ((table != null) && table.isEnabled() && (col == rolloverCol || col == draggedColumn)) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getRolloverColors(), 0, 0, w, h); if (drawRolloverBar()) { g.setColor(AbstractLookAndFeel.getFocusColor()); g.drawLine(0, 0, w - 1, 0); g.drawLine(0, 1, w - 1, 1); g.drawLine(0, 2, w - 1, 2); } } else if (drawAllwaysActive() || JTattooUtilities.isFrameActive(header)) { if (header.getBackground() instanceof ColorUIResource) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getColHeaderColors(), 0, 0, w, h); } else { g.setColor(header.getBackground()); g.fillRect(0, 0, w, h); } } else { if (header.getBackground() instanceof ColorUIResource) { JTattooUtilities.fillHorGradient( g, AbstractLookAndFeel.getTheme().getInActiveColors(), 0, 0, w, h); } else { g.setColor(header.getBackground()); g.fillRect(0, 0, w, h); } } }
@Override public void paintDeterminate(Graphics g, JComponent c) { Insets b = progressBar.getInsets(); // area for border int barRectWidth = progressBar.getWidth() - b.right - b.left; int barRectHeight = progressBar.getHeight() - b.top - b.bottom; if (barRectWidth <= 0 || barRectHeight <= 0) { return; } // int cellLength = getCellLength(); // int cellSpacing = getCellSpacing(); // amount of progress to draw int amountFull = getAmountFull(b, barRectWidth, barRectHeight); // draw the cells if (progressBar.getOrientation() == SwingConstants.HORIZONTAL) { float x = amountFull / (float) barRectWidth; g.setColor(getColorFromPallet(pallet, x)); g.fillRect(b.left, b.top, amountFull, barRectHeight); } else { // VERTICAL float y = amountFull / (float) barRectHeight; g.setColor(getColorFromPallet(pallet, y)); g.fillRect(b.left, barRectHeight + b.bottom - amountFull, barRectWidth, amountFull); } // Deal with possible text painting if (progressBar.isStringPainted()) { paintString(g, b.left, b.top, barRectWidth, barRectHeight, amountFull, b); } }
public void paintComponent(Graphics g) { super.paintComponent(g); this.setBackground(Color.black); // Nested for loop to draw all rows and columns for (int x = 0; x < num.tileRow; x++) { for (int y = 0; y < num.tileCol; y++) { if (land.xTile[x][y].isDiscovered) { g.setColor(land.xTile[x][y].locColor); } else { g.setColor(Color.black); } g.fillRect( (land.xTile[x][y].xPos + num.xOff) * num.zoom, (land.xTile[x][y].yPos + num.yOff) * num.zoom, num.tileSq * num.zoom, num.tileSq * num.zoom); } } // Code to draw and animate player g.setColor(Color.red); g.fillRect( num.tileSq * num.zoom * num.tileSq, num.tileSq * num.zoom * num.tileSq, num.tileSq * num.zoom, num.tileSq * num.zoom); g.setColor(Color.white); g.fillRect(num.tileCol * 5 - 50, 0, 150, num.tileRow * 5 + 15); g.setColor(Color.black); g.fillRect(num.tileCol * 5 - 50, 0, 10, num.tileRow * 5 + 15); }
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { if (((JToolBar) c).isFloatable()) { Graphics2D g2D = (Graphics2D) g; Composite savedComposite = g2D.getComposite(); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f); g2D.setComposite(alpha); if (((JToolBar) c).getOrientation() == HORIZONTAL) { if (!JTattooUtilities.isLeftToRight(c)) { x += w - 15; } g.setColor(Color.white); g.drawLine(x + 3, y + 4, x + 3, h - 5); g.drawLine(x + 6, y + 3, x + 6, h - 4); g.drawLine(x + 9, y + 4, x + 9, h - 5); g.setColor(shadow); g.drawLine(x + 4, y + 4, x + 4, h - 5); g.drawLine(x + 7, y + 3, x + 7, h - 4); g.drawLine(x + 10, y + 4, x + 10, h - 5); } else { // vertical g.setColor(Color.white); g.drawLine(x + 3, y + 3, w - 4, y + 3); g.drawLine(x + 3, y + 6, w - 4, y + 6); g.drawLine(x + 3, y + 9, w - 4, y + 9); g.setColor(shadow); g.drawLine(x + 3, y + 4, w - 4, y + 4); g.drawLine(x + 3, y + 7, w - 4, y + 7); g.drawLine(x + 3, y + 10, w - 4, y + 10); } g2D.setComposite(savedComposite); } }
@Override public void paintComponent(Graphics g) { Graphics g2 = g.create(); Dimension d = getSize(); CPArtwork artwork = controller.getArtwork(); Object[] layers = artwork.getLayers(); g2.setColor(new Color(0x606060)); g2.fillRect(0, 0, d.width, d.height - layers.length * layerH); g2.setColor(Color.black); g2.translate(0, d.height - layerH); for (int i = 0; i < layers.length; i++) { drawLayer(g2, (CPLayer) layers[i], i == artwork.getActiveLayerNb()); g2.translate(0, -layerH); } if (layerDragReally) { g2.translate(0, layers.length * layerH - (d.height - layerH)); g2.drawRect(0, layerDragY - layerH / 2, d.width, layerH); int layerOver = (d.height - layerDragY) / layerH; if (layerOver <= layers.length && layerOver != layerDragNb && layerOver != layerDragNb + 1) { g2.fillRect(0, d.height - layerOver * layerH - 2, d.width, 4); } } }
// Show a message over frozen image in the display public void showMessage(String message) { Graphics g = getGraphics(); g.setColor(Color.black); g.fillRect(30, (getHeight() / 2) - 16, message.length() * 10, 25); g.setColor(Color.white); g.drawString(message, 40, getHeight() / 2); }
protected void paintComponent(Graphics g) { g.setColor(GroupedElementsRenderer.POPUP_SEPARATOR_FOREGROUND); if (hasCaption()) { Rectangle viewR = new Rectangle(0, getVgap(), getWidth() - 1, getHeight() - getVgap() - 1); Rectangle iconR = new Rectangle(); Rectangle textR = new Rectangle(); String s = SwingUtilities.layoutCompoundLabel( g.getFontMetrics(), myCaption, null, CENTER, myCaptionCentered ? CENTER : LEFT, CENTER, myCaptionCentered ? CENTER : LEFT, viewR, iconR, textR, 0); final int lineY = textR.y + textR.height / 2; if (s.equals(myCaption) && viewR.width - textR.width > 2 * getHgap()) { if (myCaptionCentered) { g.drawLine(0, lineY, textR.x - getHgap(), lineY); } g.drawLine(textR.x + textR.width + getHgap(), lineY, getWidth() - 1, lineY); } UIUtil.applyRenderingHints(g); g.setColor(GroupedElementsRenderer.POPUP_SEPARATOR_TEXT_FOREGROUND); g.drawString(s, textR.x, textR.y + g.getFontMetrics().getAscent()); } else { g.drawLine(0, getVgap(), getWidth() - 1, getVgap()); } }
private void drawYTicks(Graphics g) { int hPos = 0; int pPos = 0; for (int i = 0; i < yTicks; i++) { int drawPos = yVal(hPos, maxH) + r; if (hPos % hInc == 0) { // draw line g.setColor(Color.BLACK); g.drawLine(padding - 10, drawPos, padding, drawPos); // draw tick values for herbivores g.setColor(Color.BLUE); g.drawString("" + hPos, padding - 50, drawPos + r); // draw tick values for predators g.setColor(Color.RED); g.drawString("" + pPos, padding - 50, drawPos + r + 20); } hPos += hInc; pPos += pInc; } }
public void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(Color.GREEN); drawOneGraph(g, a); g.setColor(Color.BLUE); drawOneGraph(g, b); }