public void render(GCModel model, String chartFilePath) throws IOException { GCPreferences gcPreferences = new GCPreferences(); gcPreferences.load(); final ModelChartImpl pane = new ModelChartImpl(); pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); pane.setModel(model, gcPreferences); pane.setFootprint(model.getFootprint()); pane.setMaxPause(model.getPause().getMax()); pane.setRunningTime(model.getRunningTime()); Dimension d = new Dimension(gcPreferences.getWindowWidth(), gcPreferences.getWindowHeight()); pane.setSize(d); pane.addNotify(); pane.validate(); pane.autoSetScaleFactor(); final BufferedImage image = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB); final Graphics2D graphics = image.createGraphics(); graphics.setBackground(Color.WHITE); graphics.clearRect(0, 0, image.getWidth(), image.getHeight()); pane.paint(graphics); ImageIO.write(image, "png", new File(chartFilePath)); }
public VolatileImage renderBackgroundLayer(int LayerNumber) { // create hardware accellerated background layer (Volatile Image) backgroundLayer[LayerNumber] = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = backgroundLayer[LayerNumber].createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect( 0, 0, backgroundLayer[LayerNumber].getWidth(), backgroundLayer[LayerNumber].getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); g2d.setColor(new Color(1f, 1f, 1f, 1f)); for (int i = 0; i < backgroundLayer[LayerNumber].getWidth(this) / backgroundImage[LayerNumber].getWidth(this); i++) { g2d.drawImage( backgroundImage[LayerNumber], i * backgroundImage[LayerNumber].getWidth(this), 0, this); } return backgroundLayer[LayerNumber]; }
/** 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); } }
/** {@inheritDoc} */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); g2d.setBackground(Color.white); int xDim = (int) (getWidth() / 56); int yDim = (int) (getHeight() / 66); g2d.drawLine(0, (agent[0].length) * yDim, Slope.getWidth() * xDim, (agent[0].length) * yDim); g2d.drawRect((Slope.getWidth() - 3) * xDim, 0, 15, Slope.getHeight() * yDim); for (int k = 0; k < Slope.getHeight(); k++) for (int l = 0; l < Slope.getWidth(); l++) { g2d.setColor(new Color(0, 0, 0, 1)); g2d.drawRect(k * getWidth() / 56, l * getHeight() / 66, 30, 30); } for (int i = 0; i < agent.length; i++) { for (int j = 0; j < agent[0].length; j++) { g2d.setColor(Color.blue); if (agent[i][j]) { // g2d.drawString("*", i*getWidth()/56, j*getHeight()/66); g2d.drawImage(image, i * getWidth() / 56, j * getHeight() / 66, null); } } } }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; int i, j, k; System.out.println("Starting painting"); // draw sets if (firstTimeAround) { drawSet(g2); render(); viewer.save("final_product_full.png"); firstTimeAround = false; } // render(); /* for(i=0;i<viewer.getWidth();i++){ for(j=0;j<viewer.getHeight();j++){ viewer.setPixel(i,j,Color3.BLACK); } } */ g2.setBackground(Color.BLACK); // if(newRender){ for (i = minX; i < maxX; i++) { // System.out.println("line "+i); for (j = minY; j < maxY; j++) { g2.setColor( new Color( (float) viewer.getPixel(i, j).getR(), (float) viewer.getPixel(i, j).getG(), (float) viewer.getPixel(i, j).getB())); // g2.drawLine(i,j,1,1); Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1); g2.fill(node_circ); g2.setColor(Color.BLACK); // if(j*scale<viewer.getHeight()){ // j=0;//viewer.getHeight(); // } } // if(i*scale<viewer.getWidth()){ // i=0;//viewer.getWidth(); // } } // g2.drawImage(viewer.1) newRender = false; // } System.out.println("end painting"); }
@Override public void paint(Graphics g) { if (node.isRefNode()) { BufferedImage image = new BufferedImage(1000, HEIGHT_CELL, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = image.createGraphics(); g2.setBackground(new Color(0, 0, 0, 0)); refPainter.draw(g2, OneElementList.buildList(node.getRef()), 0); g.drawImage(image, 0, 0, null); } else { super.paint(g); } }
public void initialize() { // openLevelFile images: try { boxSpriteSheet = ImageIO.read(new File("ItemContainer.png")); coinSpriteSheet = ImageIO.read(new File("Coin.png")); } catch (Exception e) { } if (openLevelFile == false) { try { loadLevel(initLevel); } catch (Exception e) { System.out.println(e); } } else { loadLevel(FileOpenDialog("Open ...")); } // create tile layer: renderTileLayer(); // create bg layer: backgroundLayer = new VolatileImage[backgroundImage.length]; // render layer: for (int i = 0; i < backgroundImage.length; i++) { renderBackgroundLayer(0); renderBackgroundLayer(1); } // create hardware accellerated rendering layer: renderImage = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = renderImage.createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect(0, 0, renderImage.getWidth(), renderImage.getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); }
/** set the height, width, and zoom of this window */ public void setMySize(int w, int h, float zoom) { this.zoom = zoom; this.zoom = 1.0f; // ET hack this.setBounds(getX(), getY(), w, h); w -= reservedWidthRight; h -= reservedHeightBottom; lblCanvas.setBounds(0, 0, w, h); synchronized (imgLock) { img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D gfx = (Graphics2D) img.getGraphics(); gfx.setBackground(Color.WHITE); gfx.setFont(Constants.FONT_DEFAULT); gfx.setComposite(Constants.COMPOSITE_OPAQUE); } }
public void GenerateIcons() { super.GenerateIcons(); if (ports == null) { ports = new Port[1]; ports[0] = new Port(15, 49, Port.TYPE_INPUT, 22, Port.ROT_DOWN, this); } icons = new ImageIcon[1]; icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR)); Graphics g; try { g = icons[0].getImage().getGraphics(); } catch (NullPointerException e) { System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); return; } Graphics2D g2 = (Graphics2D) g; Color transparent = new Color(0, 0, 0, 0); g2.setBackground(transparent); g2.clearRect(0, 0, width, height); g.setColor(Color.white); g.fillRect(16, 0, 4, 2); g.fillRect(4, 2, 4, 2); g.fillRect(12, 4, 4, 2); g.fillRect(20, 4, 4, 2); g.fillRect(4, 8, 4, 2); g.fillRect(12, 8, 4, 2); g.fillRect(24, 8, 4, 2); g.fillRect(0, 10, 4, 2); g.fillRect(8, 10, 4, 2); g.fillRect(16, 10, 4, 2); g.fillRect(24, 12, 4, 2); g.fillRect(8, 14, 4, 2); g.fillRect(16, 14, 4, 2); g.fillRect(0, 18, 4, 2); g.fillRect(12, 18, 4, 2); g.fillRect(24, 18, 4, 2); g.fillRect(16, 20, 4, 2); g.fillRect(4, 22, 4, 2); g.fillRect(20, 22, 4, 2); g.fillRect(8, 24, 4, 2); g.fillRect(16, 24, 4, 2); currentIcon = icons[0].getImage(); }
public void GenerateIcons() { icons = new ImageIcon[1]; icons[0] = new ImageIcon(new BufferedImage(width, height, BufferedImage.TYPE_4BYTE_ABGR)); Graphics g; try { g = icons[0].getImage().getGraphics(); } catch (NullPointerException e) { System.out.println("Could not get Graphics pointer to " + getClass() + " Image"); return; } Graphics2D g2 = (Graphics2D) g; Color transparent = new Color(0, 0, 0, 0); g2.setBackground(transparent); g2.clearRect(0, 0, width, height); g.setColor(Color.blue); g.fillRect(0, 4, 24, 14); g.fillRect(7, 0, 10, 2); g.fillRect(7, 0, 2, 4); g.fillRect(15, 0, 2, 4); currentIcon = icons[0].getImage(); }
@Override public void flip(int x1, int y1, int x2, int y2, BufferCapabilities.FlipContents flipAction) { final BufferedImage buffer = (BufferedImage) getBackBuffer(); if (buffer == null) { throw new IllegalStateException("Buffers have not been created"); } final Graphics g = getGraphics(); try { g.drawImage(buffer, x1, y1, x2, y2, x1, y1, x2, y2, null); } finally { g.dispose(); } if (flipAction == BufferCapabilities.FlipContents.BACKGROUND) { final Graphics2D bg = (Graphics2D) buffer.getGraphics(); try { bg.setBackground(getBackground()); bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight()); } finally { bg.dispose(); } } }
public void paint(Graphics g) { float ffc, flw; int cw, ch; Graphics2D g2 = (Graphics2D) g; Dmax = canvas.getSize(); cw = Dmax.width; ch = Dmax.height; if (bimw != cw || bimh != ch) { if (bimw != cw || bimh != ch) { bim = (BufferedImage) createImage(cw, ch); } Graphics2D bimg2 = bim.createGraphics(); bimg2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); bimg2.setBackground(DatanGraphics.ct[0]); bimg2.clearRect(0, 0, cw, ch); DminInner.width = Dmin.width + 1; DminInner.height = Dmin.height + 1; DmaxInner.width = Dmax.width - 2; DmaxInner.height = Dmax.height - 2; bimg2.setTransform(affTransf(DminInner, DmaxInner, dmin, dmax)); drawPolylines(bimg2); bimw = cw; bimh = ch; bimg2.dispose(); bimg2 = null; } g2.drawImage(bim, 0, 0, this); }
public VolatileImage renderTileLayer() { // create hardware accellerated tile layer (Volatile Image) tileLayer = this.getGraphicsConfiguration() .createCompatibleVolatileImage( loadedLevel.getWidth() * 16, loadedLevel.getHeight() * 16, Transparency.TRANSLUCENT); Graphics2D g2d = tileLayer.createGraphics(); g2d.setComposite(AlphaComposite.Src); // Clear the image. g2d.setColor(new Color(0, 0, 0, 0)); g2d.fillRect(0, 0, tileLayer.getWidth(), tileLayer.getHeight()); g2d.setBackground(new Color(0, 0, 0, 0)); g2d.setColor(new Color(1f, 1f, 1f, 1f)); for (int i = 0; i < numberOfTiles; i++) { tile[i].draw(g2d, this); } return tileLayer; }
public void paintComponent(Graphics g) { Rectangle selection = g.getClipBounds(); // clear out the image Graphics2D g2 = (Graphics2D) g; g2.setBackground(backgroundColor); g2.clearRect( (int) selection.getX(), (int) selection.getY(), (int) selection.getWidth(), (int) selection.getHeight()); // draw the selection if it exists if (selBeginPixel != -1 && selEndPixel != -1) { g2.setBackground(selectionColor); g2.clearRect(selBeginPixel, 0, selEndPixel - selBeginPixel + 1, this.getHeight()); } if (this.points.size() > 0) { g2.setColor(waveColor); // draw the lines if (this.points.size() > stemThresh) { if (points.size() > frameWidth) { // draw contour // g2.setStroke(thickerStroke); for (int i = 0; i < this.points.size() - 1; i += 4) { Point2D.Float pt1 = points.get(i).getDispPoint(); // Point2D.Float pt2 = new Point2D.Float(pt1.x, pt1.y/2); Point2D.Float pt2 = points.get(i + 1).getDispPoint(); Point2D.Float pt3 = points.get(i + 2).getDispPoint(); Point2D.Float pt4 = points.get(i + 3).getDispPoint(); // //Point2D.Float pt4 = new Point2D.Float(pt2.x, pt2.y/2); g2.draw(new Line2D.Float(pt1, pt2)); // g2.setColor(waveLiteColor); g.setColor(waveLiteColor); g2.draw(new Line2D.Float(pt2, pt3)); g2.setColor(waveColor); g2.draw(new Line2D.Float(pt3, pt4)); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); } } else { // draw line g2.setStroke(stroke); for (int i = 0; i < this.points.size() - 1; i++) { g2.draw( new Line2D.Float( this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint())); } } } else { // stem plot for (int i = 0; i < this.points.size(); i++) { // draw the stem SoundSample sample = this.points.get(i); g2.setStroke(thickerStroke); Point2D.Double base = new Point2D.Double( sample.getDispPoint().getX() + 10, Math.floor(this.getHeight()) / 2); Point2D.Double pt = new Point2D.Double(sample.getDispPoint().getX() + 10, sample.getDispPoint().getY()); g2.draw(new Line2D.Float(base, pt)); if (this.points.size() < zoomThresh) { // draw the sample value float sampleValue = (float) sample.getSampleValue(); float y = (float) sample.getDispPoint().getY(); g2.setFont(textFont); if (y < Math.floor(this.getHeight()) / 2) y = y - 10; else y = y + 10; // if (sample.getDispPoint().getX() > 0) g2.drawString(formatter.format(sampleValue), (float) sample.getDispPoint().getX(), y); } // draw the vertical bar in the array // g2.setStroke(thickerStroke); // base = new Point2D.Double(base.getX()-8, this.getHeight() - 10); // pt = new Point2D.Double(base.getX(), this.getHeight() - 50); // g2.draw(new Line2D.Double(base, pt)); // g2.drawString(formatter.format(points.get(i).getSampleIndex()), // (float)base.getX(), (float)base.getY() - 10 ); } // // g2.setStroke(wideStroke); // //draw the array cells // g2.draw(new Line2D.Double(selection.getX(), // Math.floor(this.getHeight() - 30), // selection.getX()+selection.getWidth()-1, // Math.floor(this.getHeight() - 30))); // //draw the array cells // g2.draw(new Line2D.Double(selection.getX(), // Math.floor(this.getHeight() - 10), // selection.getX()+selection.getWidth()-1, // Math.floor(this.getHeight() - 10))); } } // draw the center line g2.setColor(barColor); g2.setStroke(new BasicStroke(1)); g2.draw( new Line2D.Double( selection.getX(), Math.floor(this.getHeight() / 2), selection.getX() + selection.getWidth() - 1, Math.floor(this.getHeight() / 2))); // //draw the current position // if (selection.getX()<currentPixelPosition && // currentPixelPosition<(selection.getX()+selection.getWidth()-1)) // { // g2.setColor(barColor); // g2.setStroke(new BasicStroke(1)); // g2.draw(new Line2D.Double(currentPixelPosition, 0, // currentPixelPosition, frameHeight)); // } }
public void paintComponent(final Graphics g) { final Graphics2D g2 = (Graphics2D) g; g2.setBackground(backgroundColor); g2.clearRect(0, 0, frameWidth, overViewHeight); if (this.points.size() > 0) { g2.setColor(Color.blue); // draw the lines g2.setStroke(stroke); if (points.size() > frameWidth) { // draw contour // g2.setStroke(thickerStroke); for (int i = 0; i < this.points.size() - 1; i += 4) { Point2D.Float pt1 = points.get(i).getDispPoint(); // Point2D.Float pt2 = new Point2D.Float(pt1.x, pt1.y/2); Point2D.Float pt2 = points.get(i + 1).getDispPoint(); Point2D.Float pt3 = points.get(i + 2).getDispPoint(); Point2D.Float pt4 = points.get(i + 3).getDispPoint(); // //Point2D.Float pt4 = new Point2D.Float(pt2.x, pt2.y/2); g2.draw(new Line2D.Float(pt1, pt2)); // g2.setColor(waveLiteColor); g.setColor(waveLiteColor); g2.draw(new Line2D.Float(pt2, pt3)); g2.setColor(waveColor); g2.draw(new Line2D.Float(pt3, pt4)); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); // g2.draw(new Line2D.Float(this.points.get(i).getDispPoint(), // this.points.get(i+1).getDispPoint())); } } else { for (int i = 0; i < this.points.size() - 1; i++) { g2.draw( new Line2D.Float( this.points.get(i).getDispPoint(), this.points.get(i + 1).getDispPoint())); } } } // draw the selection if it exists if (viewBeginX != 0 && viewEndX != 0) { g2.setColor(overViewSelectionColor); g2.fillRect(viewBeginX, 0, viewEndX - viewBeginX + 1, overViewHeight); } final double totalTimeInSec = data.size() / myHelper.getSamplingRate(); final int mainTickDist = (int) Math.floor(frameWidth / totalTimeInSec); final int smallTickDist = (int) Math.floor(mainTickDist / (numOfSmallTicks + 1)); // draw the base line; g2.setColor(Color.black); g2.setStroke(thickerStroke); final Point2D base = new Point2D.Double(0, this.baseLineLocY); Point2D pt = new Point2D.Double(frameWidth, this.baseLineLocY); g2.draw(new Line2D.Double(base, pt)); // draw the ticks pt = new Point2D.Double(0, baseLineLocY - this.mainTickHeight); // show text for main ticks g2.setFont(textFont2); for (int i = 0; i <= totalTimeInSec; i++) { g2.setStroke(thickerStroke); g2.draw(new Line2D.Double(base, pt)); g2.drawString(i + "", (float) base.getX(), (float) base.getY() + textHeightFromBase); for (int j = 0; j < numOfSmallTicks; j++) { g2.setStroke(stroke); base.setLocation(base.getX() + smallTickDist, baseLineLocY); pt.setLocation(pt.getX() + smallTickDist, baseLineLocY - this.smallTickHeight); if (smallTickDist > 100) { g2.drawString( (j + 1) * 0.2 + 1 + "", (float) base.getX(), (float) base.getY() + textHeightFromBase); } if (base.getX() > frameWidth) { break; } g2.draw(new Line2D.Double(base, pt)); } base.setLocation(base.getX() + smallTickDist, baseLineLocY); pt.setLocation(pt.getX() + smallTickDist, baseLineLocY - mainTickHeight); } }
public void initUI(int x, int y) { setVisible(true); loadIcons(); dx = x; dy = y; text_height = getFontMetrics(getFont()).getHeight(); plane_width = icon_size; plane_height = icon_size + text_height + text_gap; radar_area_width = grid_size * dx; radar_area_height = grid_size * dy; getContentPane().setLayout(new BorderLayout()); radarArea = new RadarPane(); radarArea.setMinimumSize(new Dimension(radar_area_width, radar_area_height)); radarArea.setPreferredSize(new Dimension(radar_area_width, radar_area_height)); getContentPane().add(radarArea, BorderLayout.CENTER); radarArea.backImage = new BufferedImage(radar_area_width, radar_area_height, BufferedImage.TYPE_INT_RGB); Graphics2D g = radarArea.backImage.createGraphics(); g.setBackground(back_color); g.setColor(rim_color); g.fillRect(0, 0, radar_area_width, radar_area_height); g.setColor(back_color); g.fillRect(convPos(0), convPos(0), radar_area_width - grid_size, radar_area_height - grid_size); g.setColor(line_color); int i, j; for (i = 0; i < dx; i++) for (j = 0; j < dy; j++) g.draw(new Rectangle(convPos(i) - 1, convPos(j) - 1, 1, 1)); radarArea.backIcon = new ImageIcon(radarArea.backImage); radarArea.back = new JLabel(radarArea.backIcon); radarArea.back.setBounds(0, 0, radar_area_width, radar_area_height); radarArea.add(radarArea.back, new Integer(0)); infoArea = new JPanel(); infoArea.setMinimumSize(new Dimension(info_area_width, radar_area_height)); infoArea.setPreferredSize(new Dimension(info_area_width, radar_area_height)); infoArea.setLayout(new GridLayout(27, 1)); infoTopLine = new Label(" "); infoArea.add(infoTopLine); getContentPane().add(infoArea, BorderLayout.EAST); inputArea = new JLabel(" "); getContentPane().add(inputArea, BorderLayout.SOUTH); controlArea = new JPanel(); newButton = new JButton("New"); newButton.setActionCommand("New"); newButton.addActionListener(this); newButton.setEnabled(false); newButton.setFocusable(false); exitButton = new JButton("Exit"); exitButton.setActionCommand("Exit"); exitButton.addActionListener(this); exitButton.setFocusable(false); controlArea.add(newButton); controlArea.add(exitButton); getContentPane().add(controlArea, BorderLayout.NORTH); pack(); }
public void paint(Graphics g) { if (big == null) { return; } big.setBackground(getBackground()); big.clearRect(0, 0, w, h); float freeMemory = (float) r.freeMemory(); float totalMemory = (float) r.totalMemory(); // .. Draw allocated and used strings .. big.setColor(GREEN); big.drawString( String.valueOf((int) totalMemory / 1024) + "K allocated", 4.0f, (float) ascent + 0.5f); usedStr = String.valueOf(((int) (totalMemory - freeMemory)) / 1024) + "K used"; big.drawString(usedStr, 4, h - descent); // Calculate remaining size float ssH = ascent + descent; float remainingHeight = (float) (h - (ssH * 2) - 0.5f); float blockHeight = remainingHeight / 10; float blockWidth = 20.0f; float remainingWidth = (float) (w - blockWidth - 10); // .. Memory Free .. big.setColor(mfColor); int MemUsage = (int) ((freeMemory / totalMemory) * 10); int i = 0; for (; i < MemUsage; i++) { mfRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1); big.fill(mfRect); } // .. Memory Used .. big.setColor(GREEN); for (; i < 10; i++) { muRect.setRect(5, (float) ssH + i * blockHeight, blockWidth, (float) blockHeight - 1); big.fill(muRect); } // .. Draw History Graph .. big.setColor(graphColor); int graphX = 30; int graphY = (int) ssH; int graphW = w - graphX - 5; int graphH = (int) remainingHeight; graphOutlineRect.setRect(graphX, graphY, graphW, graphH); big.draw(graphOutlineRect); int graphRow = graphH / 10; // .. Draw row .. for (int j = graphY; j <= graphH + graphY; j += graphRow) { graphLine.setLine(graphX, j, graphX + graphW, j); big.draw(graphLine); } // .. Draw animated column movement .. int graphColumn = graphW / 15; if (columnInc == 0) { columnInc = graphColumn; } for (int j = graphX + columnInc; j < graphW + graphX; j += graphColumn) { graphLine.setLine(j, graphY, j, graphY + graphH); big.draw(graphLine); } --columnInc; if (pts == null) { pts = new int[graphW]; ptNum = 0; } else if (pts.length != graphW) { int tmp[] = null; if (ptNum < graphW) { tmp = new int[ptNum]; System.arraycopy(pts, 0, tmp, 0, tmp.length); } else { tmp = new int[graphW]; System.arraycopy(pts, pts.length - tmp.length, tmp, 0, tmp.length); ptNum = tmp.length - 2; } pts = new int[graphW]; System.arraycopy(tmp, 0, pts, 0, tmp.length); } else { big.setColor(YELLOW); pts[ptNum] = (int) (graphY + graphH * (freeMemory / totalMemory)); for (int j = graphX + graphW - ptNum, k = 0; k < ptNum; k++, j++) { if (k != 0) { if (pts[k] != pts[k - 1]) { big.drawLine(j - 1, pts[k - 1], j, pts[k]); } else { big.fillRect(j, pts[k], 1, 1); } } } if (ptNum + 2 == pts.length) { // throw out oldest point for (int j = 1; j < ptNum; j++) { pts[j - 1] = pts[j]; } --ptNum; } else { ptNum++; } } g.drawImage(bimg, 0, 0, this); }
// 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); } }
/** * Sets the background colour of the Canvas. * * @param newColour the new colour for the background of the Canvas */ public void setBackgroundColour(Color newColour) { backgroundColour = newColour; graphic.setBackground(newColour); }
public void run() { Thread me = Thread.currentThread(); while (getSize().width <= 0) { try { anim.sleep(500); } catch (InterruptedException e) { return; } } Graphics2D g2d = null; Graphics2D BufferG2D = null; Graphics2D ScreenG2D = null; BasicStroke solid = new BasicStroke(9.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 9.0f); GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO); int rule = AlphaComposite.SRC_OVER; AlphaComposite opaque = AlphaComposite.SrcOver; AlphaComposite blend = AlphaComposite.getInstance(rule, 0.9f); AlphaComposite set = AlphaComposite.Src; int frame = 0; int frametmp = 0; Dimension oldSize = getSize(); Shape clippath = null; while (anim == me) { Dimension size = getSize(); if (size.width != oldSize.width || size.height != oldSize.height) { img = null; clippath = null; if (BufferG2D != null) { BufferG2D.dispose(); BufferG2D = null; } if (ScreenG2D != null) { ScreenG2D.dispose(); ScreenG2D = null; } } oldSize = size; if (img == null) { img = (BufferedImage) createImage(size.width, size.height); } if (BufferG2D == null) { BufferG2D = img.createGraphics(); BufferG2D.setRenderingHint( RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_DEFAULT); BufferG2D.setClip(clippath); } g2d = BufferG2D; float[] ctrlpts; for (int i = 0; i < animpts.length; i += 2) { animate(animpts, deltas, i + 0, size.width); animate(animpts, deltas, i + 1, size.height); } ctrlpts = animpts; int len = ctrlpts.length; gp.reset(); int dir = 0; float prevx = ctrlpts[len - 2]; float prevy = ctrlpts[len - 1]; float curx = ctrlpts[0]; float cury = ctrlpts[1]; float midx = (curx + prevx) / 2.0f; float midy = (cury + prevy) / 2.0f; gp.moveTo(midx, midy); for (int i = 2; i <= ctrlpts.length; i += 2) { float x1 = (midx + curx) / 2.0f; float y1 = (midy + cury) / 2.0f; prevx = curx; prevy = cury; if (i < ctrlpts.length) { curx = ctrlpts[i + 0]; cury = ctrlpts[i + 1]; } else { curx = ctrlpts[0]; cury = ctrlpts[1]; } midx = (curx + prevx) / 2.0f; midy = (cury + prevy) / 2.0f; float x2 = (prevx + midx) / 2.0f; float y2 = (prevy + midy) / 2.0f; gp.curveTo(x1, y1, x2, y2, midx, midy); } gp.closePath(); g2d.setComposite(set); g2d.setBackground(backgroundColor); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); if (bgChanged || bounds == null) { bounds = new Rectangle(0, 0, getWidth(), getHeight()); bgChanged = false; } // g2d.clearRect(bounds.x-5, bounds.y-5, bounds.x + bounds.width + 5, bounds.y + bounds.height // + 5); g2d.clearRect(0, 0, getWidth(), getHeight()); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setColor(outerColor); g2d.setComposite(opaque); g2d.setStroke(solid); g2d.draw(gp); g2d.setPaint(gradient); if (!bgChanged) { bounds = gp.getBounds(); } else { bounds = new Rectangle(0, 0, getWidth(), getHeight()); bgChanged = false; } gradient = new GradientPaint( bounds.x, bounds.y, gradientColorA, bounds.x + bounds.width, bounds.y + bounds.height, gradientColorB, true); g2d.setComposite(blend); g2d.fill(gp); if (g2d == BufferG2D) { repaint(); } ++frame; Thread.yield(); } if (g2d != null) { g2d.dispose(); } }