List of usage examples for java.awt Graphics2D fillRect
public abstract void fillRect(int x, int y, int width, int height);
From source file:org.gitools.ui.app.actions.file.ExportHierarchicalTreeImageAction.java
@Override public void actionPerformed(ActionEvent e) { SaveFileWizard saveWiz = SaveFileWizard.createSimple("Export hierarchical tree to image ...", FilenameUtils.getName("Dendrogram " + getSelectedEditor().getName()), Settings.get().getLastExportPath(), new FileFormat[] { FileFormats.PNG }); WizardDialog dlg = new WizardDialog(Application.get(), saveWiz); dlg.open();/*from w ww. ja va 2s . com*/ if (dlg.isCancelled()) { return; } Settings.get().setLastExportPath(saveWiz.getFolder()); final File file = saveWiz.getPathAsFile(); final String formatExtension = saveWiz.getFormat().getExtension(); JobThread.execute(Application.get(), new JobRunnable() { @Override public void run(IProgressMonitor monitor) { try { monitor.begin("Exporting hierarchical tree to image ...", 1); monitor.info("File: " + file.getName()); HierarchicalCluster model = getHierarchicalCluster(); final int width = getSelectedEditor().getWidth(); final int height = model.getIdentifiers().size() * 12; DendrogramPanel panel = new DendrogramPanel() { @Override public int getWidth() { return width; } @Override public int getHeight() { return height; } }; panel.setModel(model); panel.setBackground(Color.WHITE); final BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D g = bi.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, width, height); panel.paintTree(g); ImageIO.write(bi, formatExtension, file); } catch (Exception ex) { monitor.exception(ex); } } }); Application.get().showNotification("Image created.", 2000); }
From source file:org.n52.server.io.DiagramGenerator.java
public void createLegend(DesignOptions options, OutputStream out) throws OXFException, IOException { int topMargin = 10; int leftMargin = 30; int iconWidth = 15; int iconHeight = 15; int verticalSpaceBetweenEntries = 20; int horizontalSpaceBetweenIconAndText = 15; DesignDescriptionList ddList = buildUpDesignDescriptionList(options); int width = 800; int height = topMargin + (ddList.size() * (iconHeight + verticalSpaceBetweenEntries)); BufferedImage legendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D legendGraphics = legendImage.createGraphics(); legendGraphics.setColor(Color.white); legendGraphics.fillRect(0, 0, width, height); int offset = 0; for (RenderingDesign dd : ddList.getAllDesigns()) { int yPos = topMargin + offset * iconHeight + offset * verticalSpaceBetweenEntries; // icon:/* w w w. ja va2s. c o m*/ legendGraphics.setColor(dd.getColor()); legendGraphics.fillRect(leftMargin, yPos, iconWidth, iconHeight); // text: legendGraphics.setColor(Color.black); legendGraphics.drawString(dd.getFeature().getLabel() + " - " + dd.getLabel(), leftMargin + iconWidth + horizontalSpaceBetweenIconAndText, yPos + iconHeight); offset++; } JPEGImageWriteParam p = new JPEGImageWriteParam(null); p.setCompressionMode(JPEGImageWriteParam.MODE_DEFAULT); write(legendImage, FORMAT, out); }
From source file:org.jcurl.core.swing.SumDisplayBase.java
@Override protected void paintComponent(final Graphics g) { super.paintComponent(g); final Graphics2D g2 = (Graphics2D) g; g2.setRenderingHints(hints);/*from w w w.j ava2s . co m*/ // background g2.setPaint(backGround); g2.fillRect(0, 0, getWidth(), getHeight()); for (int i = RockSet.ROCKS_PER_COLOR - 1; i >= 0; i--) { if (RockSet.isSet(recentMask, i, true)) paintRock(g2, i, true); if (RockSet.isSet(recentMask, i, false)) paintRock(g2, i, false); } }
From source file:com.ikon.module.common.CommonWorkflowModule.java
/** * Get Process Definition Image/*from w w w . j a v a2s .c o m*/ */ public static byte[] getProcessDefinitionImage(long processDefinitionId, String node) throws WorkflowException { log.debug("getProcessDefinitionImage({}, {})", new Object[] { processDefinitionId, node }); JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext(); byte[] image = null; try { GraphSession graphSession = jbpmContext.getGraphSession(); org.jbpm.graph.def.ProcessDefinition pd = graphSession.getProcessDefinition(processDefinitionId); FileDefinition fileDef = pd.getFileDefinition(); WorkflowUtils.DiagramInfo dInfo = WorkflowUtils.getDiagramInfo(fileDef.getInputStream("gpd.xml")); WorkflowUtils.DiagramNodeInfo dNodeInfo = dInfo.getNodeMap().get(node); BufferedImage img = ImageIO.read(fileDef.getInputStream("processimage.jpg")); // Obtain all nodes Y and X List<Integer> ordenadas = new ArrayList<Integer>(); List<Integer> abcisas = new ArrayList<Integer>(); for (WorkflowUtils.DiagramNodeInfo nodeInfo : dInfo.getNodeMap().values()) { ordenadas.add(nodeInfo.getY()); abcisas.add(nodeInfo.getX()); } // Calculate minimal Y Collections.sort(ordenadas); int fixOrd = ordenadas.get(0) < 0 ? ordenadas.get(0) : 0; // Calculate minimal X Collections.sort(abcisas); int fixAbs = abcisas.get(0) < 0 ? abcisas.get(0) : 0; if (dNodeInfo != null) { // Select node log.debug("DiagramNodeInfo: {}", dNodeInfo); Graphics g = img.getGraphics(); Graphics2D g2d = (Graphics2D) g; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25F)); g2d.setColor(Color.blue); g2d.fillRect(dNodeInfo.getX() - fixAbs, dNodeInfo.getY() - fixOrd, dNodeInfo.getWidth(), dNodeInfo.getHeight()); g.dispose(); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(img, "jpg", baos); image = baos.toByteArray(); baos.flush(); baos.close(); } catch (JbpmException e) { throw new WorkflowException(e.getMessage(), e); } catch (IOException e) { throw new WorkflowException(e.getMessage(), e); } finally { jbpmContext.close(); } log.debug("getProcessDefinitionImage: {}", image); return image; }
From source file:com.anrisoftware.prefdialog.miscswing.validatingfields.ValidatingComponent.java
private void paintInvalidOverlay(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setComposite(ALPHA);/*from w w w.j a v a2 s. c om*/ g2.setPaint(invalidBackground); Rectangle bounds = g.getClipBounds(); g2.fillRect(bounds.x, bounds.y, bounds.width, bounds.height); }
From source file:Wallpaper.java
@Override public void paint(Graphics g, JComponent c) { super.paint(g, c); Graphics2D g2 = (Graphics2D) g.create(); int w = c.getWidth(); int h = c.getHeight(); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .5f)); g2.setPaint(new GradientPaint(0, 0, Color.yellow, 0, h, Color.red)); g2.fillRect(0, 0, w, h); g2.dispose();//from ww w . j av a 2 s .c o m }
From source file:org.fhcrc.cpl.viewer.quant.gui.LogRatioHistMouseListener.java
/** * Draw the box to contain the ratio/*w w w .ja v a 2 s . com*/ */ protected void drawBoxForRatio(Graphics2D g) { g.setPaint(Color.LIGHT_GRAY); g.fillRect(15, 15, 75, 12); }
From source file:org.n52.server.sos.generator.DiagramGenerator.java
/** * Creates a time series chart diagram and writes it to the OutputStream. * /*from w w w. java2 s .c om*/ * @param entireCollMap * @param options * @param out * @throws OXFException * @throws IOException */ public void producePresentation(Map<String, OXFFeatureCollection> entireCollMap, DesignOptions options, FileOutputStream out, boolean compress) throws OXFException, IOException { // render features: int width = options.getWidth(); int height = options.getHeight(); Calendar begin = Calendar.getInstance(); begin.setTimeInMillis(options.getBegin()); Calendar end = Calendar.getInstance(); end.setTimeInMillis(options.getEnd()); DiagramRenderer renderer = new DiagramRenderer(false); JFreeChart diagramChart = renderer.renderChart(entireCollMap, options, begin, end, compress); diagramChart.removeLegend(); // draw chart into image: BufferedImage diagramImage = new BufferedImage(width, height, TYPE_INT_RGB); Graphics2D chartGraphics = diagramImage.createGraphics(); chartGraphics.setColor(Color.white); chartGraphics.fillRect(0, 0, width, height); diagramChart.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height)); JPEGEncodeParam p = new JPEGEncodeParam(); p.setQuality(1f); ImageEncoder encoder = ImageCodec.createImageEncoder("jpeg", out, p); encoder.encode(diagramImage); }
From source file:org.n52.oxf.render.sos.TimeSeriesChartRenderer4xPhenomenons.java
/** * The resulting IVisualization shows a chart which consists a TimeSeries for each FeatureOfInterest * contained in the observationCollection. *//*from ww w .j a v a 2 s . c o m*/ public IVisualization renderChart(OXFFeatureCollection observationCollection, ParameterContainer paramCon, int width, int height) { JFreeChart chart = renderChart(observationCollection, paramCon); // draw plot into image: Plot plot = chart.getPlot(); BufferedImage chartImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D chartGraphics = chartImage.createGraphics(); chartGraphics.setColor(Color.white); chartGraphics.fillRect(0, 0, width, height); plot.draw(chartGraphics, new Rectangle2D.Float(0, 0, width, height), null, null, null); // draw legend into image: LegendTitle legend = chart.getLegend(); BufferedImage legendImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D legendGraphics = legendImage.createGraphics(); legendGraphics.setColor(Color.white); legendGraphics.fillRect(0, 0, (int) legend.getWidth(), (int) legend.getHeight()); legend.draw(legendGraphics, new Rectangle2D.Float(0, 0, width, height)); return new StaticVisualization(chartImage, legendImage); }
From source file:TwoStopsGradient.java
@Override protected void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; GradientPaint p;/*from w w w .jav a2 s. c om*/ p = new GradientPaint(0, 0, new Color(0xFFFFFF), 0, getHeight(), new Color(0xC8D2DE)); Paint oldPaint = g2.getPaint(); g2.setPaint(p); g2.fillRect(0, 0, getWidth(), getHeight()); g2.setPaint(oldPaint); super.paintComponent(g); }