List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:edu.csudh.goTorosBank.WithdrawServlet.java
public String writeIntoCheck(String filePath, String username, String theAmount, String amountInWords, String dateWrote, String person_payingto, String billType) throws IOException, NullPointerException { File blueCheck = new File("blank-blue-check.jpg"); String pathToOriginal = getServletContext().getRealPath("/" + blueCheck); File file = new File(pathToOriginal); BufferedImage imageToCopy = null; try {//from ww w. j a v a 2 s . c o m imageToCopy = ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); } String amount = theAmount; String person_gettingPayed = person_payingto; String amountinWords = amountInWords; String date = dateWrote; String bill_type = billType; int w = imageToCopy.getWidth(); int h = imageToCopy.getHeight(); BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics2D g2d = img.createGraphics(); g2d.setColor(g2d.getBackground()); g2d.fillRect(0, 0, w, h); g2d.drawImage(imageToCopy, 0, -100, null); g2d.setPaint(Color.black); g2d.setFont(new java.awt.Font("Serif", Font.BOLD, 36)); //g2d.setFont(new Font("Serif", Font.BOLD, 36)); FontMetrics fm = g2d.getFontMetrics(); int x = img.getWidth() - fm.stringWidth(amount) - 100; int y = fm.getHeight(); g2d.drawString(amount, x - 70, y + 335); g2d.drawString(person_gettingPayed, x - 800, y + 329); g2d.drawString(amountinWords, x - 940, y + 390); g2d.drawString(date, x - 340, y + 245); g2d.drawString(bill_type, x - 900, y + 530); String signature = "Use The Force"; g2d.setFont(new java.awt.Font("Monotype Corsiva", Font.BOLD | Font.ITALIC, 36)); g2d.drawString(signature, x - 340, y + 530); g2d.dispose(); /*write check to file*/ String filename = fileNameGenerator(username); String fullname = filePath + "_" + filename + ".jpg"; ImageIO.write(img, "jpg", new File(fullname)); return fullname; }
From source file:dr.app.gui.chart.PDFPlot.java
/** * Paint actual plot//from w w w .j a va 2 s .c om */ @Override public void paintPlot(Graphics2D g2, double xScale, double yScale, double xOffset, double yOffset, int plotNumber, int plotCount) { if (distribution == null) { return; } super.paintPlot(g2, xScale, yScale, xOffset, yOffset, plotNumber, plotCount); g2.setPaint(linePaint); g2.setStroke(lineStroke); double x1 = xMin + offset; double y1 = distribution.pdf(x1 - offset); double step = (xMax - xMin) / stepCount; for (int i = 1; i < stepCount; i++) { double x2 = x1 + step; double y2 = distribution.pdf(x2 - offset); drawLine(g2, x1, y1, x2, y2); x1 = x2; y1 = y2; } }
From source file:com.joliciel.jochre.graphics.VectorizerImpl.java
public BufferedImage drawArrayLists(JochreImage jochreImage) { long startTime = (new Date()).getTime(); BufferedImage vectorizedImage = new BufferedImage(jochreImage.getWidth(), jochreImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D graphics2D = vectorizedImage.createGraphics(); graphics2D.setStroke(new BasicStroke(1)); graphics2D.setPaint(Color.BLACK); for (Paragraph paragraph : jochreImage.getParagraphs()) { for (RowOfShapes row : paragraph.getRows()) { for (GroupOfShapes group : row.getGroups()) { for (Shape shape : group.getShapes()) { List<LineSegment> lines = this.vectorize(shape); for (LineSegment line : lines) graphics2D.drawLine(shape.getLeft() + line.getStartX(), shape.getTop() + line.getStartY(), shape.getLeft() + line.getEndX(), shape.getTop() + line.getEndY()); }/*w w w . java 2 s. c o m*/ } } } if (LOG.isDebugEnabled()) { long endTime = (new Date()).getTime(); long diff = endTime - startTime; LOG.debug("Time elapsed: " + ((double) diff / 1000)); } return vectorizedImage; }
From source file:MainClass.java
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException { Graphics2D g2 = (Graphics2D) g; double w = pf.getImageableWidth(); double h = pf.getImageableHeight(); int xo = (int) pf.getImageableX(); int yo = (int) pf.getImageableY(); Rectangle2D r = new Rectangle2D.Double(xo, yo, w, h); g2.setColor(Color.red);//from www . j a v a 2 s . co m g2.draw(r); PrinterGraphics p = (PrinterGraphics) g2; String s = p.getPrinterJob().getJobName(); g2.setPaint(Color.black); g2.drawString(s, 0, 0); return Printable.PAGE_EXISTS; }
From source file:FieldValidator.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); JLayer jlayer = (JLayer) c; JFormattedTextField ftf = (JFormattedTextField) jlayer.getView(); if (!ftf.isEditValid()) { Graphics2D g2 = (Graphics2D) g.create(); // Paint the red X. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = c.getWidth(); int h = c.getHeight(); int s = 8; int pad = 4; int x = w - pad - s; int y = (h - s) / 2; g2.setPaint(Color.red); g2.fillRect(x, y, s + 1, s + 1); g2.setPaint(Color.white); g2.drawLine(x, y, x + s, y + s); g2.drawLine(x, y + s, x + s, y); g2.dispose();//from w w w . ja va 2 s . com } }
From source file:edu.cuny.cat.ui.ClockPanel.java
@Override public void setup(final ParameterDatabase parameters, final Parameter base) { clock = GameController.getInstance().getClock(); dataset = new DefaultValueDataset(); meterplot = new MyMeterPlot(dataset) { /**/* w w w . j a v a 2 s .c o m*/ * */ private static final long serialVersionUID = 1L; @Override protected void drawValueLabel(final Graphics2D g2, final Rectangle2D area) { g2.setFont(getValueFont()); g2.setPaint(getValuePaint()); String valueStr = "No value"; if (dataset != null) { final Number n = dataset.getValue(); if (n != null) { if (n.intValue() == 0) { valueStr = "to start"; } else if (n.intValue() == clock.getGameLen() * clock.getDayLen()) { valueStr = "done"; } else { valueStr = "day " + (n.intValue() / clock.getDayLen()) + ", round " + (n.intValue() % clock.getDayLen()); } } } final float x = (float) area.getCenterX(); final float y = (float) area.getCenterY() + MeterPlot.DEFAULT_CIRCLE_SIZE; TextUtilities.drawAlignedString(valueStr, g2, x, y, TextAnchor.TOP_CENTER); } }; meterplot.setRange(new Range(0, clock.getDayLen() * clock.getGameLen())); meterplot.setNeedlePaint( parameters.getColorWithDefault(base.push(ClockPanel.P_NEEDLE), null, Color.darkGray)); meterplot.setDialBackgroundPaint(new Color(0, 255, 0, 64)); meterplot.setDialOutlinePaint(Color.gray); meterplot.setDialShape(DialShape.CHORD); meterplot.setMeterAngle(parameters.getIntWithDefault(base.push(ClockPanel.P_ANGLE), null, 260)); meterplot.setTickLabelsVisible(true); meterplot.setTickLabelFont(new Font("Dialog", 1, 10)); meterplot.setTickLabelPaint(Color.darkGray); meterplot.setTickSize(clock.getDayLen()); meterplot.setTickPaint(Color.lightGray); meterplot.setValuePaint(Color.black); meterplot.setValueFont(new Font("Dialog", 1, 14)); meterplot.setUnits(""); meterplot.setTickLabelFormat(new NumberFormat() { /** * */ private static final long serialVersionUID = 1L; @Override public StringBuffer format(final double number, final StringBuffer toAppendTo, final FieldPosition pos) { return format((long) number, toAppendTo, pos); } @Override public StringBuffer format(final long number, final StringBuffer toAppendTo, final FieldPosition pos) { if (number % clock.getDayLen() == 0) { toAppendTo.append(String.valueOf(number / clock.getDayLen())); } return toAppendTo; } @Override public Number parse(final String source, final ParsePosition parsePosition) { return null; } }); final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, meterplot, false); final ChartPanel panel = new ChartPanel(chart); panel.setPreferredSize(new Dimension(parameters.getIntWithDefault(base.push(ClockPanel.P_WIDTH), null, 200), parameters.getIntWithDefault(base.push(ClockPanel.P_HEIGHT), null, 200))); add(panel, BorderLayout.CENTER); initIterationLabel(); initScoreReport(); }
From source file:de.tor.tribes.ui.algo.TimeFrameVisualizer.java
@Override public void paintComponent(Graphics g) { super.paintComponent(g); if (mTimeFrame == null) { renderNoInfoView(g);//from ww w .j a v a 2 s . com } else { updateSize(); LongRange startRange = mTimeFrame.getStartRange(); LongRange arriveRange = mTimeFrame.getArriveRange(); HashMap<LongRange, TimeSpan> startRanges = mTimeFrame .startTimespansToRangesMap(AnyTribe.getSingleton()); HashMap<LongRange, TimeSpan> arriveRanges = mTimeFrame.arriveTimespansToRangesMap(null); long minValue = startRange.getMinimumLong(); long maxValue = arriveRange.getMaximumLong(); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(new TexturePaint(STROKED, new Rectangle(0, 0, 3, 3))); g2d.fillRect(0, 0, getWidth(), getHeight()); //draw frame around the entire range renderRange(new LongRange(startRange.getMinimumLong(), arriveRange.getMaximumLong()), startRange, arriveRange, false, false, g2d, null, popupInfo); g2d.setColor(Constants.DS_BACK); popupInfo.clear(); //fill start range renderRange(startRange, startRange, arriveRange, true, false, g2d, null, popupInfo); //fill arrive range renderRange(arriveRange, startRange, arriveRange, false, true, g2d, null, popupInfo); Paint p = g2d.getPaint(); Iterator<LongRange> rangeKeys = startRanges.keySet().iterator(); while (rangeKeys.hasNext()) { LongRange currentRange = rangeKeys.next(); TimeSpan spanForRange = startRanges.get(currentRange); if (spanForRange != null) { if (spanForRange.isValidAtEveryDay()) { g2d.setPaint(new TexturePaint(DAILY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3))); } else if (spanForRange.isValidAtExactTime()) { g2d.setPaint(new TexturePaint(EXACT_START_FRAME_FILL, new Rectangle(0, 0, 3, 3))); } else { g2d.setPaint(new TexturePaint(ONE_DAY_START_FRAME_FILL, new Rectangle(0, 0, 3, 3))); } } renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo); } Composite c = g2d.getComposite(); rangeKeys = arriveRanges.keySet().iterator(); while (rangeKeys.hasNext()) { LongRange currentRange = rangeKeys.next(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f)); g2d.setPaint(new TexturePaint(ARRIVE_FRAME_FILL, new Rectangle(0, 0, 3, 3))); TimeSpan spanForRange = arriveRanges.get(currentRange); renderRange(currentRange, startRange, arriveRange, false, false, g2d, spanForRange, popupInfo); } g2d.setComposite(c); g2d.setPaint(p); renderDayMarkers(minValue, maxValue, g2d); renderPopup(popupInfo, g2d); } }
From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java
/** * Draws zoom rectangle (if present)./* w w w . j av a 2 s . co m*/ * The drawing is performed in XOR mode, therefore * when this method is called twice in a row, * the second call will completely restore the state * of the canvas. * * @param selectedRegion * @param stroke * @param fillColor */ protected void drawSelectedRegion(Rectangle2D selectedRegion, Stroke stroke, Color fillColor, boolean xorMode, Graphics2D g2) { // Set XOR mode to draw the zoom rectangle if (g2 == null) return; Paint origColor = g2.getPaint(); if (selectedRegion != null) { if (xorMode) { g2.setXORMode(fillColor); } else g2.setPaint(fillColor); g2.fill(selectedRegion); g2.setPaint(Color.black); g2.setStroke(stroke); if (xorMode) g2.setPaint(Color.white); else g2.setPaint(Color.black); g2.draw(selectedRegion); g2.setPaintMode(); g2.setPaint(origColor); } }
From source file:org.jfree.experimental.chart.plot.dial.DialBackground.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//* w w w . j ava 2s. c om*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Paint p = this.paint; if (p instanceof GradientPaint) { p = this.gradientPaintTransformer.transform((GradientPaint) p, view); } g2.setPaint(p); g2.fill(view); }
From source file:TextBouncer.java
protected void setPaint(Graphics2D g2) { if (mGradient) { GradientPaint gp = new GradientPaint(0, 0, Color.blue, 50, 25, Color.green, true); g2.setPaint(gp); } else//ww w. j av a 2 s . c o m g2.setPaint(Color.orange); }