public void paint(Graphics g) { gRef = (Graphics2D) g; // change size of font gRef.setFont(gRef.getFont().deriveFont(9.0f)); fmRef = g.getFontMetrics(); // Clear background if (Preferences.monochrome) { gRef.setColor(Preferences.whiteColor); } else { gRef.setColor(Preferences.backgroundColor); } gRef.fillRect(0, 0, getWidth(), getHeight()); // set colour to correct drawing colour if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { gRef.setColor(Preferences.penColor); } gRef.translate(0, margin); // Call c code to draw tree gRef.scale(scale, scale); nativeDrawTree(); }
/** [Internal] */ private void paintBackground(Graphics2D g2, Color theBackground) { Color color1 = g2.getColor(); if (theBackground == null) theBackground = Color.white; g2.setColor(theBackground); g2.fillRect(0, 0, 30000, 30000); g2.setColor(color1); }
/* (non-Javadoc) * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int) */ public int print(Graphics g, PageFormat pf, int page) throws PrinterException { int ret = PAGE_EXISTS; String line = null; try { if (fph.knownPage(page)) { in.seek(fph.getFileOffset(page)); line = in.readLine(); } else { long offset = in.getFilePointer(); line = in.readLine(); if (line == null) { ret = NO_SUCH_PAGE; } else { fph.createPage(page); fph.setFileOffset(page, offset); } } if (ret == PAGE_EXISTS) { // Seite ausgeben, Grafikkontext vorbereiten Graphics2D g2 = (Graphics2D) g; g2.scale(1.0 / RESMUL, 1.0 / RESMUL); int ypos = (int) pf.getImageableY() * RESMUL; int xpos = ((int) pf.getImageableX() + 2) * RESMUL; int yd = 12 * RESMUL; int ymax = ypos + (int) pf.getImageableHeight() * RESMUL - yd; // Seitentitel ausgeben ypos += yd; g2.setColor(Color.black); g2.setFont(new Font("Monospaced", Font.BOLD, 10 * RESMUL)); g.drawString(fbname + " Seite " + (page + 1), xpos, ypos); g.drawLine( xpos, ypos + 6 * RESMUL, xpos + (int) pf.getImageableWidth() * RESMUL, ypos + 6 * RESMUL); ypos += 2 * yd; // Zeilen ausgeben g2.setColor(new Color(0, 0, 127)); g2.setFont(new Font("Monospaced", Font.PLAIN, 10 * RESMUL)); while (line != null) { g.drawString(line, xpos, ypos); ypos += yd; if (ypos >= ymax) { break; } line = in.readLine(); } } } catch (IOException e) { throw new PrinterException(e.toString()); } return ret; }
public void setPenColour(int colour) { if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { if (colour == 0) { gRef.setColor(Preferences.penColor); } if (colour == 1) { gRef.setColor(Preferences.highlightColor); } } }
@Override public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { System.out.println("PageFormat: width=" + pf.getWidth() + ", height=" + pf.getHeight()); Logger.getGlobal().log(Level.INFO, "PageFormat {0}", pf); System.out.println("pageIndex " + pageIndex); Logger.getGlobal().log(Level.INFO, "pageIndex {0}", pageIndex); if (pageIndex == 0) { Graphics2D g2d = (Graphics2D) g; Font font = g2d.getFont(); g2d.setFont(font.deriveFont((float) fontSize)); g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.setColor(Color.black); int step = g2d.getFont().getSize(); step += step / 4; double y = paddingTop + g2d.getFont().getSize(); for (String s : printStringList) { Logger.getGlobal().log(Level.INFO, "printStringList: {0}", s); g2d.drawString(s, (float) paddingLeft, (float) y); y += step; } // g2d.fillRect(0, 0, 200, 200); return Printable.PAGE_EXISTS; } else { return Printable.NO_SUCH_PAGE; } }
public int print(Graphics g,PageFormat pf,int pageIndex) { if (pageIndex == 0) { Graphics2D g2d= (Graphics2D)g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.setColor(Color.black); g2d.drawString("example string", 250, 250); g2d.fillRect(0, 0, 200, 200); return Printable.PAGE_EXISTS; } else { return Printable.NO_SUCH_PAGE; } }
public void doPaint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.black); BufferedImage bimg = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); Graphics ig = bimg.getGraphics(); Color alphared = new Color(255, 0, 0, 128); Color alphagreen = new Color(0, 255, 0, 128); Color alphablue = new Color(0, 0, 255, 128); ig.setColor(alphared); ig.fillRect(0, 0, 200, 200); ig.setColor(alphagreen); ig.fillRect(25, 25, 150, 150); ig.setColor(alphablue); ig.fillRect(75, 75, 125, 125); g.drawImage(bimg, 10, 25, this); GradientPaint gp = new GradientPaint(10.0f, 10.0f, alphablue, 210.0f, 210.0f, alphared, true); g2.setPaint(gp); g2.fillRect(10, 240, 200, 200); }
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { // Component printMe = getPrintComponent(); Graphics2D g2 = (Graphics2D) g; g2.setColor(Color.black); // set default foreground color to black // for faster printing, turn off double buffering // RepaintManager.currentManager(this).setDoubleBufferingEnabled(false); Dimension d = printComponent.getSize(); // get size of document double panelWidth = d.width; // width in pixels double panelHeight = d.height; // height in pixels double pageHeight = pf.getImageableHeight(); // height of printer page double pageWidth = pf.getImageableWidth(); // width of printer page double scale = pageWidth / panelWidth; int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight); // make sure we don't print empty pages if (pageIndex >= totalNumPages) { return Printable.NO_SUCH_PAGE; } // shift Graphic to line up with beginning of print-imageable region g2.translate(pf.getImageableX(), pf.getImageableY()); // shift Graphic to line up with beginning of next page to print g2.translate(0f, -pageIndex * pageHeight); // scale the page so the width fits... g2.scale(scale, scale); // PRINT IT! printComponent.paint(g2); return Printable.PAGE_EXISTS; }
private void clearArc(int x, int y, int width, int height, int startAngle, int arcAngle) { penColor = gRef.getColor(); gRef.setColor(Preferences.backgroundColor); gRef.fillArc(x, y, width, height, startAngle, arcAngle); gRef.setColor(penColor); }
private void restoreColor() { gRef.setColor(penColor); }
private void setFillColor(int symbolType) { penColor = gRef.getColor(); switch (symbolType) { case FTAConstants.SYMB_BASIC: gRef.setColor(Preferences.basicInitiatingEventColor); break; case FTAConstants.SYMB_UNDEV: gRef.setColor(Preferences.undevelopedEventColor); break; case FTAConstants.SYMB_EXTERN: gRef.setColor(Preferences.externalEventColor); break; case FTAConstants.SYMB_INTERMEDIATE: gRef.setColor(Preferences.intermediateEventColor); break; case FTAConstants.SYMB_AND: gRef.setColor(Preferences.andGateColor); break; case FTAConstants.SYMB_OR: gRef.setColor(Preferences.orGateColor); break; case FTAConstants.SYMB_PRIORITY_AND: gRef.setColor(Preferences.priorityAndGateColor); break; case FTAConstants.SYMB_EXCL_OR: gRef.setColor(Preferences.exclusiveOrGateColor); break; case FTAConstants.SYMB_INHIBIT: gRef.setColor(Preferences.inhibitGateColor); break; case FTAConstants.SYMB_CONDITION: gRef.setColor(Preferences.conditioningEventColor); break; case FTAConstants.SYMB_TRANS_IN: gRef.setColor(Preferences.transferInColor); break; case FTAConstants.SYMB_TRANS_OUT: gRef.setColor(Preferences.transferOutColor); break; default: gRef.setColor(Preferences.backgroundColor); break; } }
private void drawPlot(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setColor(Color.white); g2d.fillRect(0, 0, getWidth(), getHeight()); double activeWidth = getWidth() - leftMargin - rightMargin; double activeHeight = getHeight() - topMargin - bottomMargin; int bottomY = getHeight() - bottomMargin; int rightX = getWidth() - rightMargin; // draw data line int x1, x2, y1, y2; g2d.setColor(Color.red); for (int i = 1; i < numComponents; i++) { x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth); y1 = (int) (bottomY - (plotData[i - 1][plotIndex] * 10.0) / 1000 * activeHeight); x2 = (int) (leftMargin + ((double) (i) / (numComponents - 1)) * activeWidth); y2 = (int) (bottomY - (plotData[i][plotIndex] * 10) / 1000 * activeHeight); g2d.drawLine(x1, y1, x2, y2); } // draw data points int radius = 2; for (int i = 0; i < numComponents; i++) { x1 = (int) (leftMargin + ((double) (i) / (numComponents - 1)) * activeWidth); y1 = (int) (bottomY - (plotData[i][plotIndex] * 10.0) / 1000 * activeHeight); g2d.drawOval(x1 - radius - 1, y1 - radius - 1, 2 * radius + 2, 2 * radius + 2); } // draw axes g2d.setColor(Color.black); g2d.drawLine(leftMargin, bottomY, rightX, bottomY); g2d.drawLine(leftMargin, bottomY, leftMargin, topMargin); g2d.drawLine(leftMargin, topMargin, rightX, topMargin); g2d.drawLine(rightX, bottomY, rightX, topMargin); // draw ticks int tickSize = 4; for (int i = 1; i <= numComponents; i++) { x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth); g2d.drawLine(x1, bottomY, x1, bottomY + tickSize); } for (int i = 0; i <= 1000; i += 100) { y1 = (int) (bottomY - i / 1000.0 * activeHeight); g2d.drawLine(leftMargin, y1, leftMargin - tickSize, y1); } // labels DecimalFormat df = new DecimalFormat("#,###,###.###"); Font font = new Font("SanSerif", Font.PLAIN, 11); FontMetrics metrics = g.getFontMetrics(font); int hgt, adv; hgt = metrics.getHeight(); // x-axis labels String label; for (int i = 1; i <= numComponents; i++) { label = String.valueOf(i); x1 = (int) (leftMargin + ((double) (i - 1) / (numComponents - 1)) * activeWidth); adv = metrics.stringWidth(label) / 2; g2d.drawString(label, x1 - adv, bottomY + hgt + 4); } label = "Component"; adv = metrics.stringWidth(label); int xAxisMidPoint = (int) (leftMargin + activeWidth / 2); g2d.drawString(label, xAxisMidPoint - adv / 2, bottomY + 2 * hgt + 6); // y-axis labels // rotate the font Font oldFont = g.getFont(); Font f = oldFont.deriveFont(AffineTransform.getRotateInstance(-Math.PI / 2.0)); g2d.setFont(f); int yAxisMidPoint = (int) (topMargin + activeHeight / 2); int offset; label = "Explained Variance (%)"; offset = metrics.stringWidth("100.0") + 12 + hgt; adv = metrics.stringWidth(label); g2d.drawString(label, leftMargin - offset, yAxisMidPoint + adv / 2); // replace the rotated font. g2d.setFont(oldFont); df = new DecimalFormat("0.0"); for (int i = 0; i <= 1000; i += 100) { label = df.format(i / 10); y1 = (int) (bottomY - i / 1000.0 * activeHeight); adv = metrics.stringWidth(label); g2d.drawString(label, leftMargin - adv - 12, y1 + hgt / 2); } // title // bold font oldFont = g.getFont(); font = font = new Font("SanSerif", Font.BOLD, 12); g2d.setFont(font); label = "PCA Scree Plot"; adv = metrics.stringWidth(label); g2d.drawString(label, getWidth() / 2 - adv / 2, topMargin - hgt - 5); g2d.setFont(oldFont); }
public int print(Graphics gc, PageFormat format, int pageIndex) throws java.awt.print.PrinterException { if (pageIndex > 0) { out("page " + pageIndex + " requested, ending print job."); return Printable.NO_SUCH_PAGE; } Dimension page = new Dimension( (int) format.getImageableWidth() - 1, (int) format.getImageableHeight() - 1); Graphics2D g = (Graphics2D) gc; out( "asked to render page " + pageIndex + " in " + outpf(format) + " w/transform " + g.getTransform()); // note: supposedly, perhaps on Windows with JVM's 1.5 and newer, the // transform scale provided can actually allow us to derive the DPI of the // print device, which we could use for image rendering optimization's // during prints. Mac OS X Snow Leopard w/JVM 1.6 always reports a 1.0 // scale though. And operations like "print preview" or "print to PDF" // wouldn't have a fixed DPI anyway. if (DEBUG.CONTAINMENT) { g.setColor(Color.lightGray); g.fillRect(0, 0, 9999, 9999); } g.translate(format.getImageableX(), format.getImageableY()); // Don't need to clip if printing whole map, as computed zoom // should have made sure everything is within page size // if (!isPrintingView()) // g.clipRect(0, 0, page.width, page.height); if (DEBUG.CONTAINMENT) { // g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); // draw border outline of page g.setColor(Color.gray); g.setStroke(VueConstants.STROKE_TWO); g.drawRect(0, 0, page.width, page.height); // g.setComposite(AlphaComposite.Src); } // compute zoom & offset for visible map components Point2D.Float offset = new Point2D.Float(); // center vertically only if landscape mode // if (format.getOrientation() == PageFormat.LANDSCAPE) // TODO: allow horizontal centering, but not vertical centering (handle in computeZoomFit) double scale = ZoomTool.computeZoomFit(page, 5, bounds, offset, true); out("rendering at scale " + scale); // set up the DrawContext DrawContext dc = new DrawContext( g, scale, -offset.x, -offset.y, null, // frame would be the PageFormat offset & size rectangle focal, false); // todo: absolute links shouldn't be spec'd here dc.setMapDrawing(); dc.setPrintQuality(); if (isPrintingView() && map == focal) g.clipRect( (int) Math.floor(bounds.getX()), (int) Math.floor(bounds.getY()), (int) Math.ceil(bounds.getWidth()), (int) Math.ceil(bounds.getHeight())); if (DEBUG.CONTAINMENT) { g.setColor(Color.red); g.setStroke(VueConstants.STROKE_TWO); g.draw(bounds); } // render the map if (map == focal) map.draw(dc); else focal.draw(dc); out("page " + pageIndex + " rendered."); return Printable.PAGE_EXISTS; }
// 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); } }