public void printEditorGlow(java.awt.Graphics g, Graphics graphics) { if (graphics.colorClicked) { if (Coordinates.revert(graphics.mouseX, graphics.mouseY).getX() >= 0 && Coordinates.revert(graphics.mouseX, graphics.mouseY).getX() <= 20) { if (Coordinates.revert(graphics.mouseX, graphics.mouseY).getY() >= 0 && Coordinates.revert(graphics.mouseX, graphics.mouseY).getY() <= 17) { int discreteX = (int) Coordinates.convert( Coordinates.revert(graphics.mouseX, graphics.mouseY).getX(), (int) Coordinates.revert(graphics.mouseX, graphics.mouseY).getY()) .getX(); int discreteY = (int) Coordinates.convert( Coordinates.revert(graphics.mouseX, graphics.mouseY).getX(), (int) Coordinates.revert(graphics.mouseX, graphics.mouseY).getY()) .getY(); g.drawImage(graphics.glow, discreteX, discreteY, null); } else { g.drawImage(graphics.glow, graphics.mouseX - 25, graphics.mouseY - 25, null); } } else { g.drawImage(graphics.glow, graphics.mouseX - 25, graphics.mouseY - 25, null); } } }
// ------------------------------------------------------------------------ // SCREEN PAINTER // Put some function here to paint whatever you want over the screen before and after // all edges and nodes have been painted. public void PaintScreenBefore(Graphics g) { Dimension d = MainClass.mainFrame.GetGraphDisplayPanel().getSize(); NodeInfo nodeInfo; int x = 0; int y = 0; int step = 10; for (; x < d.width; x += step) { for (y = 0; y < d.height; y += step) { double val = 0; double sum = 0; double total = 0; double min = 10000000; for (Enumeration nodes = proprietaryNodeInfo.elements(); nodes.hasMoreElements(); ) { nodeInfo = (NodeInfo) nodes.nextElement(); double dist = distance(x, y, nodeInfo.centerX, nodeInfo.centerY); if (nodeInfo.value != -1 && nodeInfo.nodeNumber.intValue() != 1) { // 121 if (dist < min) min = dist; val += ((double) nodeInfo.value) / dist / dist; sum += (1 / dist / dist); } } int reading = (int) (val / sum); reading = reading >> 2; if (reading > 255) reading = 255; g.setColor(new Color(reading, reading, reading)); g.fillRect(x, y, step, step); } } }
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { x = x + width - this.right; // g.setColor(table.getBackground()); // g.fillRect(x,y, width,height); g.setColor(table.getGridColor()); g.drawLine(x, y, x, y + height); }
// 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 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); } }
/** Overrides <code>Graphics.drawImage</code>. */ public boolean drawImage(Image img, int x, int y, ImageObserver observer) { DebugGraphicsInfo info = info(); if (debugLog()) { info.log(toShortString() + " Drawing image: " + img + " at: " + new Point(x, y)); } if (isDrawingBuffer()) { if (debugBuffered()) { Graphics debugGraphics = debugGraphics(); debugGraphics.drawImage(img, x, y, observer); debugGraphics.dispose(); } } else if (debugFlash()) { int i, count = (info.flashCount * 2) - 1; ImageProducer oldProducer = img.getSource(); ImageProducer newProducer = new FilteredImageSource(oldProducer, new DebugGraphicsFilter(info.flashColor)); Image newImage = Toolkit.getDefaultToolkit().createImage(newProducer); DebugGraphicsObserver imageObserver = new DebugGraphicsObserver(); Image imageToDraw; for (i = 0; i < count; i++) { imageToDraw = (i % 2) == 0 ? newImage : img; loadImage(imageToDraw); graphics.drawImage(imageToDraw, x, y, imageObserver); Toolkit.getDefaultToolkit().sync(); sleep(info.flashTime); } } return graphics.drawImage(img, x, y, observer); }
private void drawTextToImage() { Graphics g = image.getGraphics(); g.setFont(textFont); g.setColor(getMainFrame().getColorBoxForeground()); g.drawString(text, (int) (start.getX() / scale), (int) (start.getY() / scale)); repaint(); }
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); }
@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 render() { BufferStrategy bs = getBufferStrategy(); if (bs == null) { createBufferStrategy(3); return; } int xOffset = player.x - (screen.width / 2); int yOffset = player.y - (screen.height / 2); level.renderTiles(screen, xOffset, yOffset); level.renderEntities(screen); level.cleanUp(); screen.renderHud(); for (int y = 0; y < screen.height; y++) { for (int x = 0; x < screen.width; x++) { int colorCode = screen.pixels[x + y * screen.width]; if (colorCode < 255) pixels[x + y * WIDTH] = colors[colorCode]; } } Graphics g = bs.getDrawGraphics(); g.drawImage(image, 0, 0, getWidth(), getHeight(), null); g.dispose(); bs.show(); }
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); }
/** * 插入LOGO * * @param source 二维码图片 * @param imgPath LOGO图片地址 * @param needCompress 是否压缩 * @throws Exception */ private static void insertImage(BufferedImage source, String imgPath, boolean needCompress) throws Exception { File file = new File(imgPath); if (!file.exists()) { System.err.println("" + imgPath + " 该文件不存在!"); return; } Image src = ImageIO.read(new File(imgPath)); int width = src.getWidth(null); int height = src.getHeight(null); if (needCompress) { // 压缩LOGO if (width > WIDTH) { width = WIDTH; } if (height > HEIGHT) { height = HEIGHT; } Image image = src.getScaledInstance(width, height, Image.SCALE_SMOOTH); BufferedImage tag = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics g = tag.getGraphics(); g.drawImage(image, 0, 0, null); // 绘制缩小后的图 g.dispose(); src = image; } // 插入LOGO Graphics2D graph = source.createGraphics(); int x = (QRCODE_WIDTH - width) / 2; int y = (QRCODE_HEIGHT - height) / 2; graph.drawImage(src, x, y, width, height, null); Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); graph.setStroke(new BasicStroke(3f)); graph.draw(shape); graph.dispose(); }
@Override protected void paintComponent(Graphics g) { g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); final String text = getText(); final int len = text.length(); int x; if (centerText) { x = (getWidth() - widthOfW * len) / 2 + 1; } else { x = 5; } int y = (getHeight() - fontHeight) / 2 + fontAscent; Graphics2D g2d = (Graphics2D) g; Object oldHints = null; if (desktopAAHints != null) { oldHints = g2d.getRenderingHints(); g2d.addRenderingHints(desktopAAHints); } g.setColor(getForeground()); g2d.drawString(text, x, y); // Restore rendering hints appropriately. if (desktopAAHints != null) { g2d.addRenderingHints((Map) oldHints); } // separator g.setColor(Color.GRAY); g.drawLine(0, 0, 0, getHeight()); }
public void paint(Graphics g) { Dimension dim = getSize(); g.draw3DRect(1, 1, dim.width - 3, dim.height - 3, true); g.setColor(Color.black); g.drawRect(0, 0, dim.width - 1, dim.height - 1); }
public void paintThumb(Graphics g) { Icon icon = null; if (slider.getOrientation() == JSlider.HORIZONTAL) { if (isRollover && slider.isEnabled()) { icon = getThumbHorIconRollover(); } else { icon = getThumbHorIcon(); } } else { if (isRollover && slider.isEnabled()) { icon = getThumbVerIconRollover(); } else { icon = getThumbVerIcon(); } } Graphics2D g2D = (Graphics2D) g; Composite savedComposite = g2D.getComposite(); if (!slider.isEnabled()) { g.setColor(AbstractLookAndFeel.getBackgroundColor()); g.fillRect(thumbRect.x + 1, thumbRect.y + 1, thumbRect.width - 2, thumbRect.height - 2); AlphaComposite alpha = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f); g2D.setComposite(alpha); } icon.paintIcon(null, g, thumbRect.x, thumbRect.y); g2D.setComposite(savedComposite); }
public void paintIcon(Component c, Graphics g, int x, int y) { boolean enabled = c.isEnabled(); // paint the icon Icon paintedIcon = enabled ? icon : disabledIcon; if (paintedIcon != null) paintedIcon.paintIcon(c, g, x, y); // backup current color Color oldColor = g.getColor(); int insetx = 4; if (c instanceof JComponent) { Insets borderinset = ((JComponent) c).getBorder().getBorderInsets(c); insetx = borderinset.left; } if (paintedIcon != null) { g.translate(paintedIcon.getIconWidth() + X_GAP + insetx, 0); } arrow.paintIcon(c, g, x, y); if (paintedIcon != null) { g.translate(-paintedIcon.getIconWidth() - X_GAP - insetx, 0); } // restore previous color g.setColor(oldColor); }
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 }
public Icon getIcon(File f) { if (isDirLink(f)) { /* all of this nonsense is to get to the default file view */ System.out.println("get icon for: " + f); JFileChooser chooser = new JFileChooser(); ComponentUI ui = UIManager.getUI(chooser); System.out.println("got : " + ui); FileChooserUI fcui = (FileChooserUI) ui; fcui.installUI(chooser); FileView def = fcui.getFileView(chooser); // get the standard icon for a folder File tmp = new File("C:\\windows"); Icon folder = def.getIcon(tmp); int w = folder.getIconWidth(); int h = folder.getIconHeight(); // create a buffered image the same size as the icon Image img = new BufferedImage(w, h, BufferedImage.TYPE_4BYTE_ABGR); Graphics g = img.getGraphics(); // draw the normal icon folder.paintIcon(chooser, g, 0, 0); Image shortcut = new ImageIcon("shortcut.png").getImage(); g.drawImage(shortcut, 0, 0, null); g.dispose(); return new ImageIcon(img); } return super.getIcon(f); }
public void mergePastedImage() { if (pastedImage != null) { Graphics g = image.getGraphics(); g.drawImage(pastedImage, (int) (start.getX() / scale), (int) (start.getY() / scale), this); repaint(); } }
private Image createAuctionIcon(int width, int height) { Image buffer = createImage(width, height); Graphics canvas = buffer.getGraphics(); ArrayList<Integer> auctionColours = ((CTWorld) Simulator.pworld).getAuctionColours(); if ((auctionColours != null) && !auctionColours.isEmpty()) { int blockWidth = width / auctionColours.size(); int offset = 0; Iterator<Integer> iterator = auctionColours.iterator(); while (iterator.hasNext()) { Integer auctionColour = iterator.next(); Color color = getColor(auctionColour); canvas.setColor(color); canvas.fillRect(offset, 0, blockWidth, height); offset = offset + blockWidth; } } else { canvas.setColor(getColor(CTWorld.NEUTRAL)); canvas.fillRect(0, 0, width, height); } return buffer; }
public void paint(java.awt.Graphics g) { int w = m_bi.getWidth(this); int h = m_bi.getHeight(this); // int ww= (int)(w*(percentSize/100)); // int hh=(int)(h*(percentSize/100)); g.setColor(java.awt.Color.white); g.fillRect(0, 0, this.getWidth(), this.getHeight()); java.awt.Graphics2D g2d = (java.awt.Graphics2D) g; g2d.scale(percentSize / 100.0, percentSize / 100.0); int ml = (this.getWidth() / 2) - (w / 2); int mh = (this.getHeight() / 2) - (h / 2); if (m_bi != null) { g2d.drawImage(m_bi, ml, mh, this); } }
private void drawGoals() { Coord tempCoord; PixelCoord tempPixelCoord; Color tempColor; Set<String> playerNames = ((CTWorld) Simulator.pworld).getPlayerNames(); Iterator<String> iterator = playerNames.iterator(); int inset = (int) (((1.0 / 20.0) * ((double) tilesize / 2.0)) + ((double) tilesize / 4.0)); int size = (int) ((9.0 / 10.0) * ((double) tilesize / 2.0)); // Indicate Goal Tiles while (iterator.hasNext()) { String name = (String) iterator.next(); tempCoord = ((CTWorld) Simulator.pworld).getPlayerGoal(name); if (tempCoord != null) { tempPixelCoord = coord2pixelcoord(tempCoord); tempColor = getColor(((CTWorld) Simulator.pworld).getPlayerColour(name)); backBuffer.setColor(tempColor); backBuffer.fillOval(tempPixelCoord.x + inset, tempPixelCoord.y + inset, size, size); backBuffer.drawImage( scaledImagesBuffer.get("goal"), tempPixelCoord.x + tilesize / 4, tempPixelCoord.y + tilesize / 4, null); } } return; }
public Image getScreenshot() { BufferedImage image = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_4BYTE_ABGR); Graphics g = image.getGraphics(); paint(g); g.dispose(); return image; }
/* * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics, * int, int) */ public void paintIcon(Component c, Graphics g, int x, int y) { if (fig instanceof OperationsCompartmentContainer) { OperationsCompartmentContainer fc = (OperationsCompartmentContainer) fig; // added by Eric Lefevre 13 Mar 1999: we must check if the // FigText for operations is drawn before drawing things // over it if (!fc.isOperationsVisible()) { fig = null; return; } Rectangle fr = fc.getOperationsBounds(); int left = fr.x + 10; int height = fr.y + fr.height - 7; int right = fr.x + fr.width - 10; g.setColor(Color.red); int i = left; while (true) { g.drawLine(i, height, i + WAVE_LENGTH, height + WAVE_HEIGHT); i += WAVE_LENGTH; if (i >= right) break; g.drawLine(i, height + WAVE_HEIGHT, i + WAVE_LENGTH, height); i += WAVE_LENGTH; if (i >= right) break; g.drawLine(i, height, i + WAVE_LENGTH, height + WAVE_HEIGHT / 2); i += WAVE_LENGTH; if (i >= right) break; g.drawLine(i, height + WAVE_HEIGHT / 2, i + WAVE_LENGTH, height); i += WAVE_LENGTH; if (i >= right) break; } fig = null; } }
public void drawString(Graphics g) { Font Amonth = new Font("Century Gothic", Font.PLAIN, 45); g.setColor(Color.gray); g.setFont(Amonth); g.drawString(month.format(today.getTime()), 150, 45); Month = present.format(today.getTime()); }
/** * Draws a circle around the node * * @param n The node * @param color The circle color */ public void drawNode(Node n, Color color) { Point p = mv.getPoint(n); g.setColor(color); if (selected) { g.fillOval(p.x - 5, p.y - 5, 10, 10); } else g.drawOval(p.x - 5, p.y - 5, 10, 10); }
private void drawAxes(Graphics g) { g.drawLine(padding, height, width + padding, height); g.drawLine(padding, 0, padding, height); g.drawString("time", padding + width / 2, height + padding - 5); g.drawString("pop", 5, height / 2); }
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); } } }
static void drawALUIcon(ComponentDrawContext context, int x, int y) { Graphics g = context.getGraphics(); g.setColor(Color.BLACK); int xp[] = {x, x + 15, x + 15, x, x, x + 3, x}; int yp[] = {y, y + 5, y + 10, y + 15, y + 10, y + 8, y + 6}; g.drawPolygon(xp, yp, 7); }
/** * Draws a simple 3d border for the given component. * * @param c The component to draw its border. * @param g The graphics context. * @param x The x coordinate of the top left corner. * @param y The y coordinate of the top left corner. * @param w The width. * @param h The height. */ public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) { g.setColor(MetouiaLookAndFeel.getControlHighlight()); g.drawLine(0, 0, 0, h - 1); g.setColor(MetouiaLookAndFeel.getControlShadow()); g.drawLine(0, h - 1, w - 1, h - 1); }