/** * Render the View to the given graphic context. This implementation render the interior first, * then the outline. */ public void paint(Graphics2D g, Rectangle2D a) { if (!a.intersects(getBounds())) return; if (image != null) { // paint bitmap g.drawImage(image, text2ModelTr, null); // debug: g.setPaint(Color.red); g.draw(this.bounds); super.paint(g, a); // possibly paint framebox if non-null } else { // paint textlayout super.paint(g, a); // possibly paint framebox if non-null AffineTransform oldAT = g.getTransform(); // paint text in black g.setPaint(Color.black); // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font // being mirrored... g.transform(text2ModelTr); // also include rotation textLayout.draw(g, 0.0f, 0.0f); // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre) // get back to previous transform g.setTransform(oldAT); if (DEBUG) { g.setPaint(Color.red); g.draw(bounds); } } }
// public void savePDF(){ // Rectangle suggestedPageSize = getITextPageSize(page1.getPageSize()); // Rectangle pageSize = rotatePageIfNecessary(suggestedPageSize); // //rotate if we need landscape // Document document = new Document(pageSize); // // PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(outputFile)); // document.open(); // Graphics2D graphics = cb.createGraphics(pageSize.getWidth(), pageSize.getHeight()); // // // call your GTRenderer here // GTRenderer draw = new StreamingRenderer(); // draw.setMapContent(mapContent); // // draw.paint(graphics, outputArea, mapContent.getLayerBounds() ); // // // cleanup // graphics.dispose(); // // //cleanup // document.close(); // writer.close(); // } public void saveImage(final MapContent map, final String file, final int imageWidth) { GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(map); Rectangle imageBounds = null; ReferencedEnvelope mapBounds = null; try { mapBounds = map.getMaxBounds(); double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0); imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth)); } catch (Exception e) { // failed to access mapContent layers throw new RuntimeException(e); } BufferedImage image = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB); Graphics2D gr = image.createGraphics(); gr.setPaint(Color.WHITE); gr.fill(imageBounds); try { renderer.paint(gr, imageBounds, mapBounds); File fileToSave = new File(file); ImageIO.write(image, "jpeg", fileToSave); } catch (Exception e) { e.printStackTrace(); } }
/** paint the canvas into a image file of given width and height */ public void writeToImage(String s, int w, int h) { String ext; File f; try { ext = s.substring(s.lastIndexOf(".") + 1); f = new File(s); } catch (Exception e) { System.out.println(e); return; } if (!ext.equals("jpg") && !ext.equals("png")) { System.out.println("Cannot write to file: Illegal extension " + ext); return; } boolean opq = true; if (theOpaque != null) opq = theOpaque; BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setBackground(Color.white); g2.setPaint(Color.black); g2.setStroke(new BasicStroke(1)); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); doBuffer(g2, true, new Rectangle(0, 0, w, h)); try { ImageIO.write(image, ext, f); } catch (Exception e) { System.out.println(e); } }
private void shadeExt(Graphics2D g2, int r, int g, int b, int a) { g2.setPaint(new Color(r, g, b, a)); g2.fillRect(0, 0, iw, rect.y); /* _N_ */ g2.fillRect( rect.x + rect.width + 1, rect.y, iw - rect.x - rect.width - 1, rect.height + 1); /* E */ g2.fillRect(0, rect.y, rect.x, rect.height + 1); /* W */ g2.fillRect(0, rect.y + rect.height + 1, iw, ih - rect.y - rect.height - 1); /* _S_ */ }
protected float drawBoxedString(Graphics2D g2, String s, Color c1, Color c2, double x) { // Calculate the width of the string. FontRenderContext frc = g2.getFontRenderContext(); TextLayout subLayout = new TextLayout(s, mFont, frc); float advance = subLayout.getAdvance(); // Fill the background rectangle with a gradient. GradientPaint gradient = new GradientPaint((float) x, 0, c1, (float) (x + advance), 0, c2); g2.setPaint(gradient); Rectangle2D bounds = mLayout.getBounds(); Rectangle2D back = new Rectangle2D.Double(x, 0, advance, bounds.getHeight()); g2.fill(back); // Draw the string over the gradient rectangle. g2.setPaint(Color.white); g2.setFont(mFont); g2.drawString(s, (float) x, (float) -bounds.getY()); return advance; }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setPaint(BACKGROUND); g2.fill( new Rectangle2D.Float( 0f, 0f, (float) g2.getClipBounds().width, (float) g2.getClipBounds().height)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); canvas.paint(g2); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(Color.black); g2d.setStroke(new BasicStroke()); g2d.setFont(new Font("Century Schoolbook", Font.PLAIN, 12)); if (d.isInitialized() && display_plot) { d.refreshData(); Float xLower = d.getXLower(); Float xUpper = d.getXUpper(); Float xInterval = d.getXInterval(); Float yLower = d.getYLower(); Float yUpper = d.getYUpper(); Float yInterval = d.getYInterval(); Float dx = xUpper - xLower; Float dy = yUpper - yLower; drawCenteredString(g2d, d.getTitle(), 250, 25, (float) 0.); drawCenteredString(g2d, d.getXTitle(), 250, 475, (float) 0.); drawCenteredString(g2d, d.getYTitle(), 25, 250, (float) -Math.PI / 2); drawCenteredString(g2d, xLower.toString(), 50, 475, (float) 0); drawCenteredString(g2d, xUpper.toString(), 450, 475, (float) 0); drawCenteredString(g2d, yLower.toString(), 25, 450, (float) 0); drawCenteredString(g2d, yUpper.toString(), 25, 50, (float) 0); g2d.setPaint(Color.gray); for (Float x = new Float(50); x <= 450; x += 400 * xInterval / dx) g2d.draw(new Line2D.Float(x, 450, x, 50)); for (Float y = new Float(50); y <= 450; y += 400 * yInterval / dy) g2d.draw(new Line2D.Float(45, y, 450, y)); g2d.setPaint(Color.red); Float diam = new Float(8); int num_points = d.getNumberOfPoints(); for (int i = 0; i < num_points; i++) { Float ex = 400 * (d.getPoint(i).x - xLower) / dx + 50; ex -= diam / 2; Float ey = -400 * (d.getPoint(i).y - yLower) / dy + 450; ey -= diam / 2; g2d.fill(new Ellipse2D.Float(ex, ey, diam, diam)); } } }
public static BufferedImage cropImage(BufferedImage bi, int x, int y, int w, int h) { BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w, h); g2.drawImage(bi, -x, -y, null); // this); g2.dispose(); return image; }
public static BufferedImage tileImage(BufferedImage im, int width, int height) { GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment() .getDefaultScreenDevice() .getDefaultConfiguration(); int transparency = Transparency.OPAQUE; // Transparency.BITMASK; BufferedImage compatible = gc.createCompatibleImage(width, height, transparency); Graphics2D g = (Graphics2D) compatible.getGraphics(); g.setPaint(new TexturePaint(im, new Rectangle(0, 0, im.getWidth(), im.getHeight()))); g.fillRect(0, 0, width, height); return compatible; }
/** * Method to draw a message as a string on the buffered image * * @param message the message to draw on the buffered image * @param xPos the x coordinate of the leftmost point of the string * @param yPos the y coordinate of the bottom of the string */ public void addMessage(String message, int xPos, int yPos) { // get a graphics context to use to draw on the buffered image Graphics2D graphics2d = bufferedImage.createGraphics(); // set the color to white graphics2d.setPaint(Color.white); // set the font to Helvetica bold style and size 16 graphics2d.setFont(new Font("Helvetica", Font.BOLD, 16)); // draw the message graphics2d.drawString(message, xPos, yPos); }
public static BufferedImage scaleImage(BufferedImage bi, double scale) { int w1 = (int) (Math.round(scale * bi.getWidth())); int h1 = (int) (Math.round(scale * bi.getHeight())); BufferedImage image = new BufferedImage(w1, h1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); g2.fillRect(0, 0, w1, h1); g2.drawImage(bi, 0, 0, w1, h1, null); // this); g2.dispose(); return image; }
private synchronized void doBuffer(Graphics2D g2, boolean opq, Rectangle rt) { origTransform = g2.getTransform(); if (opq && rt != null) g2.clearRect(rt.x, rt.y, rt.width, rt.height); g2.setPaint(origPaint); g2.setFont(origFont); g2.setStroke(origStroke); if (inBuffer) { // System.out.println("upps"); for (int i = 0; i < a1x.size(); i++) doPaint(g2, a1x.get(i), a2x.get(i)); origTransform = null; return; } for (int i = 0; i < a1.size(); i++) doPaint(g2, a1.get(i), a2.get(i)); origTransform = null; }
public static BufferedImage rotateImage(BufferedImage bi) { int w = bi.getWidth(); int h = bi.getHeight(); BufferedImage image = new BufferedImage(h, w, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); g2.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setPaint(Color.white); // getBackground()); g2.fillRect(0, 0, h, w); g2.rotate(90 * Math.PI / 180); g2.drawImage(bi, 0, -h, w, h, null); // this); g2.dispose(); return image; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(x, y); g2.setStroke(new BasicStroke(BORDER_WIDTH)); g2.setPaint(LINE_COLOR); g2.draw(BORDER); g2.setStroke(new BasicStroke(SLIT_WIDTH)); g2.setColor(UIManager.getColor("Panel.background")); int n = SLIT_NUM + 1; int v = ICON_SIZE / n; int m = n * v; for (int i = 1; i < n; i++) { int a = i * v; g2.drawLine(a, 0, a, m); g2.drawLine(0, a, m, a); } // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v); // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v); // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v); // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v); // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v); // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v); g2.setPaint(LINE_COLOR); Rectangle2D b = ARROW.getBounds(); Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d); AffineTransform toCenterAT = AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY()); g2.fill(toCenterAT.createTransformedShape(ARROW)); g2.dispose(); }
@Override public void paintComponent(Graphics window) { super.paintComponent(window); Image bufferedImage = createImage(getWidth(), getHeight()); Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); g2d.setPaint(gradient1); g2d.fillRect(0, 0, 300, 1000); if (showInstructions == true) { g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Instructions:", 10, 150); g2d.setFont(font3); g2d.drawString("To Play, Click New Game", 10, 200); g2d.drawString("Each game costs $1", 10, 230); g2d.drawString("Hit adds a card to your hand", 10, 260); g2d.drawString("Stand stops the game and", 10, 290); g2d.drawString("calculates each persons score", 10, 320); g2d.drawString("To play dealer, click Play Dealer", 10, 350); g2d.drawString("Enter your desired wager", 10, 380); g2d.drawString("Every time you score 20 or 21", 10, 470); g2d.drawString("you get one arcade token", 10, 500); g2d.drawString("Arcade Tokens can be redeemed", 10, 530); g2d.drawString("By closing instructions and clicking", 10, 560); g2d.drawString("Play Arcade Game", 10, 590); } else { g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Arcade Game:", 10, 250); g2d.setFont(font3); g2d.drawString("Select the game you would like", 10, 320); g2d.drawString("Click Play to Play.", 10, 350); g2d.drawString("Hold and Drag the Mouse", 10, 380); g2d.drawString("to move in Cube Runner", 10, 410); g2d.drawString("Press the mouse to sprint", 10, 440); g2d.drawString("in Spiral Game, and click", 10, 500); g2d.drawString("to Jump", 10, 530); g2d.drawString("Each game costs one token", 10, 560); g2d.drawString("", 10, 590); } g2d.setColor(Color.YELLOW); g2d.setFont(font1); g2d.drawString("Tokens: " + tempObject.tokens, 10, 700); window.drawImage(bufferedImage, 0, 0, this); }
protected void drawBackground(Graphics2D g2) { // Draw circles of different colors. int side = 45; int width = getSize().width; int height = getSize().height; Color[] colors = { Color.yellow, Color.cyan, Color.orange, Color.pink, Color.magenta, Color.lightGray }; for (int y = 0; y < height; y += side) { for (int x = 0; x < width; x += side) { Ellipse2D ellipse = new Ellipse2D.Float(x, y, side, side); int index = (x + y) / side % colors.length; g2.setPaint(colors[index]); g2.fill(ellipse); } } }
/** * Esta funcion se usa para pintar la barra de seleccion de los menus. Esta aqui para no repetirla * en todas partes... */ static void pintaBarraMenu(Graphics g, JMenuItem menuItem, Color bgColor) { ButtonModel model = menuItem.getModel(); Color oldColor = g.getColor(); int menuWidth = menuItem.getWidth(); int menuHeight = menuItem.getHeight(); if (menuItem.isOpaque()) { g.setColor(menuItem.getBackground()); g.fillRect(0, 0, menuWidth, menuHeight); } if ((menuItem instanceof JMenu && !(((JMenu) menuItem).isTopLevelMenu()) && model.isSelected()) || model.isArmed()) { RoundRectangle2D.Float boton = new RoundRectangle2D.Float(); boton.x = 1; boton.y = 0; boton.width = menuWidth - 3; boton.height = menuHeight - 1; boton.arcwidth = 8; boton.archeight = 8; GradientPaint grad = new GradientPaint(1, 1, getBrilloMenu(), 0, menuHeight, getSombraMenu()); Graphics2D g2D = (Graphics2D) g; g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setColor(bgColor); g2D.fill(boton); g.setColor(bgColor.darker()); g2D.draw(boton); g2D.setPaint(grad); g2D.fill(boton); g2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT); } g.setColor(oldColor); }
public void saveNewImage(MapContent map, String file) { GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(map); System.out.println("line 139"); Rectangle imageBounds = null; try { ReferencedEnvelope mapBounds = map.getMaxBounds(); double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0); int imageWidth = 600; imageBounds = new Rectangle(0, 0, imageWidth, (int) Math.round(imageWidth * heightToWidth)); } catch (Exception e) { } System.out.println("line 151"); // Rectangle imageSize = new Rectangle(600,600); BufferedImage image = new BufferedImage( imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_RGB); // darker red fill Graphics2D gr = image.createGraphics(); gr.setPaint(Color.WHITE); gr.fill(imageBounds); try { System.out.println("line 161"); renderer.paint(gr, imageBounds, map.getMaxBounds()); System.out.println("line 163"); File fileToSave = new File(file); System.out.println("line 166"); ImageIO.write(image, "jpeg", fileToSave); System.out.println("line 168"); } catch (IOException e) { } }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Dimension asz = this.getSize(); if (fullRefresh) { g2.clearRect(0, 0, asz.width, asz.height); fullRefresh = false; } g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); big.setColor(Color.black); offset.x = (int) (asz.width - iw) / 2; offset.y = (int) (asz.height - ih) / 2; big.drawImage(img, 0, 0, this); big.setPaint(Color.red); if ((rect.width > 0) && (rect.height > 0)) big.draw(rect); if (selected == 1) shadeExt(big, 0, 0, 0, 64); else if (selected == 2) { shadeExt(big, 0, 0, 0, 255); selected = 1; } g2.drawImage(bi, offset.x, offset.y, this); }
private synchronized void toBuffer(int s, Object a) { a1.add(s); a2.add(a); if (s == clear) { clearBuffer(); } if (s == opaque) theOpaque = (Boolean) a; if (s == setBackground) theBackground = (Color) a; if (inBuffer) return; if (isSetter(s)) return; Graphics g = getGraphics(); if (g == null) return; Graphics2D g2 = (Graphics2D) g; g2.setPaint(origPaint); g2.setFont(origFont); g2.setStroke(origStroke); for (int i = 0; i < a1.size() - 1; i++) { int s1 = a1.get(i); Object s2 = a2.get(i); if (isSetter(s1)) doPaint(g2, s1, s2); } doPaint((Graphics2D) g, s, a); }
// also clip, transform, composite, // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;} // --------------------------------------------------------- private void doPaint(Graphics2D g, int s, Object o) { // process an operation from the buffer // System.out.println(s); Object o1 = null, o2 = null, o3 = null, o4 = null, o5 = null, o6 = null, o7 = null, o8 = null, o9 = null, o10 = null, o11 = null; if (o instanceof Object[]) { Object[] a = (Object[]) o; if (a.length > 0) o1 = a[0]; if (a.length > 1) o2 = a[1]; if (a.length > 2) o3 = a[2]; if (a.length > 3) o4 = a[3]; if (a.length > 4) o5 = a[4]; if (a.length > 5) o6 = a[5]; if (a.length > 6) o7 = a[6]; if (a.length > 7) o8 = a[7]; if (a.length > 8) o9 = a[8]; if (a.length > 9) o10 = a[9]; if (a.length > 10) o11 = a[10]; } switch (s) { case clear: paintBackground(g, theBackground); break; // public void addRenderingHints(Map<?,?> hints) // {toBuffer("addRenderingHints",hints );} case addRenderingHints: g.addRenderingHints((Map<?, ?>) o); break; case clip1: g.clip((Shape) o); break; case draw1: g.draw((Shape) o); break; case draw3DRect: g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case drawGlyphVector: g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3); break; case drawImage1: g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4); break; case drawImage2: g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3); break; case drawRenderableImage: g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2); break; case drawRenderedImage: g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2); break; case drawString1: g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3); break; case drawString2: g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3); break; case drawString3: g.drawString((String) o1, (Float) o2, (Float) o3); break; case drawString4: g.drawString((String) o1, (Integer) o2, (Integer) o3); break; case fill: g.fill((Shape) o); break; case fill3DRect: g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case rotate1: g.rotate((Double) o); break; case rotate2: g.rotate((Double) o1, (Double) o2, (Double) o3); break; case scale1: g.scale((Double) o1, (Double) o2); break; case setBackground: g.setBackground( (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/ break; case setComposite: g.setComposite((Composite) o); break; case setPaint: g.setPaint((Paint) o); break; case setRenderingHint: g.setRenderingHint((RenderingHints.Key) o1, o2); break; case setRenderingHints: g.setRenderingHints((Map<?, ?>) o); break; case setStroke: g.setStroke((Stroke) o); break; case setTransform: g.setTransform(makeTransform(o)); break; case shear: g.shear((Double) o1, (Double) o2); break; case transform1: g.transform(makeTransform(o)); break; case translate1: g.translate((Double) o1, (Double) o2); break; case translate2: g.translate((Integer) o1, (Integer) o2); break; case clearRect: g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case copyArea: g.copyArea( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawArc: g.drawArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawBytes: g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawChars: g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawImage4: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5); break; case drawImage5: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4); break; case drawImage6: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Color) o6, (ImageObserver) o7); break; case drawImage7: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6); break; case drawImage8: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (Color) o10, (ImageObserver) o11); break; case drawImage9: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (ImageObserver) o10); break; case drawLine: g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawOval: g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawPolygon1: g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case drawPolygon2: g.drawPolygon((Polygon) o); break; case drawPolyline: g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3); break; case drawRect: g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawRoundRect: g.drawRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillArc: g.fillArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillOval: g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; // {toBuffer("fillPolygon",mkArg(xPoints, yPoints, nPoints) );} case fillPolygon1: g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case fillPolygon2: g.fillPolygon((Polygon) o); break; case fillRect: g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case fillRoundRect: g.fillRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case setClip1: g.setClip((Shape) o); break; case setColor: g.setColor((Color) o); break; case setFont: g.setFont((Font) o); break; case setPaintMode: g.setPaintMode(); break; case setXORMode: g.setXORMode((Color) o); break; case opaque: super.setOpaque((Boolean) o); break; case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break; { FontRenderContext frc = g.getFontRenderContext(); TextLayout tl = new TextLayout((String) o1, g.getFont(), frc); Shape s1 = tl.getOutline(null); AffineTransform af = g.getTransform(); g.translate((Integer) o2, (Integer) o3); g.draw(s1); g.setTransform(af); } ; break; default: System.out.println("Unknown image operation " + s); } }
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; int h = getHeight(); int w = getWidth(); double factor = (h - (MARGIN_BOTTOM * 1.0)) / RSSI_MAX_VALUE; double sSpacing = (w - MARGIN_RIGHT) / (TOTAL * 1.0); int sWidth = (int) (sSpacing - 1); if (sWidth == 0) sWidth = 1; // Set white background in the plot g.setColor(Color.white); g.fillRect(0, 0, w, h); // Gradient example (ytics background) GradientPaint greytowhite = new GradientPaint(w - MARGIN_RIGHT, 0, Color.WHITE, w, 0, Color.lightGray, false); g2.setPaint(greytowhite); g2.fillRect(w - MARGIN_RIGHT, 0, w, h); // Draw the light grey channels from 11 to 26 double xpos = 10; for (int i = 4; i < TOTAL - 4; i++) { if (i == 4 + 5 * (INTERFERED_CHANNEL - 11)) g.setColor(Color.cyan); else g.setColor(Color.lightGray); g.fillRect((int) (xpos + i * sSpacing), 0, (int) (sSpacing * 3), h - MARGIN_BOTTOM); i = i + 4; g.setColor(Color.blue); g.drawString( String.valueOf(((i - 8) / 5) + 11), (int) (xpos + (i - 4) * sSpacing), MARGIN_TOP); } g.drawString(String.valueOf("Channel"), (int) (w - MARGIN_RIGHT + 20), MARGIN_TOP); // Write the y-axis with dBm int base_dBm = -100; // The bottom corresponds to -100 dBm int ytics = 10; // How many tics on the y-axis for (int i = -ytics; i <= 0; i++) { g.setColor(Color.red); g.drawString( String.valueOf(((ytics + i) * (base_dBm / ytics)) + "dBm"), (int) (w - MARGIN_RIGHT + 20), (int) (h + i * (h / ytics)) - MARGIN_BOTTOM); // Dashed line for the ytics final float dash1[] = {10.0f}; final BasicStroke dashed = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash1, 0.0f); g2.setStroke(dashed); g2.drawLine( 0, (int) (h + i * (h / ytics)) - MARGIN_BOTTOM, (int) (w - MARGIN_RIGHT + 7), (int) (h + i * (h / ytics)) - MARGIN_BOTTOM); } // Write the x-axis with MHz g.setColor(Color.blue); int start_x_axis = 4; g.drawString(String.valueOf(2400 + "MHz"), (int) xpos, (int) h - start_x_axis); g.drawString(String.valueOf(2442.5 + "MHz"), (w - 119) / 2, (int) h - start_x_axis); g.drawString(String.valueOf(2485 + "MHz"), w - 119, (int) h - start_x_axis); // Draw the old RSSI in each MHz channel (grey) g.setColor(Color.gray); double xposition = xpos; for (int i = 0, n = rssi.length; i < n; i++) { int rssi = (int) (rssiMax[i] * factor); g.fillRect((int) xposition, h - MARGIN_BOTTOM - rssi, sWidth, rssi + 1); xposition += sSpacing; } // Draw the current RSSI in each MHz channel (black) g.setColor(Color.black); xposition = xpos; for (int i = 0, n = rssi.length; i < n; i++) { int rssiVal = (int) (rssi[i] * factor); g.fillRect((int) xposition, h - MARGIN_BOTTOM - rssiVal, sWidth, rssiVal + 1); xposition += sSpacing; } }
private void shadeRect(Graphics2D g2, int r, int g, int b, int a) { g2.setPaint(new Color(r, g, b, a)); g2.fillRect(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1); }