List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:lcmc.common.ui.ResourceGraph.java
protected final void drawInsideVertex(final Graphics2D g2d, final Vertex v, final Color[] colors, final double x, final double y, final float height, final float width) { final int number = colors.length; if (number > 1) { for (int i = 1; i < number; i++) { final Paint p = new GradientPaint((float) x + width / number, (float) y, getVertexFillSecondaryColor(v), (float) x + width / number, (float) y + height, colors[i], false);/* www . ja va2 s. co m*/ g2d.setPaint(p); final Shape s = new Rectangle2D.Double(x + width / 2 + (width / number / 2) * i, y, width / number / 2, height - 2); g2d.fill(s); } } }
From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.renderer.FormattedScatterRenderer.java
/** * This function is taken directly from JFreeChart with adjustments to draw differently colored * items.//from ww w . ja v a 2 s . c om * * When updating JFreeChart this function must probably be adapted. * */ @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { // do nothing if item is not visible if (!getItemVisible(row, column)) { return; } int visibleRow = state.getVisibleSeriesIndex(row); if (visibleRow < 0) { return; } int visibleRowCount = state.getVisibleSeriesCount(); PlotOrientation orientation = plot.getOrientation(); ValueSourceToMultiValueCategoryDatasetAdapter dataSet = (ValueSourceToMultiValueCategoryDatasetAdapter) dataset; List values = dataSet.getValues(row, column); if (values == null) { return; } int valueCount = values.size(); for (int i = 0; i < valueCount; i++) { // current data point... double x1; if (getUseSeriesOffset()) { x1 = domainAxis.getCategorySeriesMiddle(column, dataset.getColumnCount(), visibleRow, visibleRowCount, getItemMargin(), dataArea, plot.getDomainAxisEdge()); } else { x1 = domainAxis.getCategoryMiddle(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); } Number n = (Number) values.get(i); int idx = dataSet.getValueIndex(row, column, i); double value = n.doubleValue(); double y1 = rangeAxis.valueToJava2D(value, dataArea, plot.getRangeAxisEdge()); Shape shape = getItemShape(row, idx); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, y1, x1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, x1, y1); } if (getItemShapeFilled(row, column)) { if (getUseFillPaint()) { g2.setPaint(getItemFillPaint(row, column)); } else { g2.setPaint(getItemPaint(row, idx)); } g2.fill(shape); } if (getDrawOutlines()) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(row, column)); } else { g2.setPaint(getItemPaint(row, idx)); } g2.setStroke(getItemOutlineStroke(row, column)); g2.draw(shape); } } }
From source file:org.gumtree.vis.awt.JChartPanel.java
/** * Draws a vertical line used to trace the mouse position to the horizontal * axis.// ww w.j av a2 s. c o m * * @param g2 the graphics device. * @param x the x-coordinate of the trace line. */ private void drawHorizontalAxisTrace(Graphics2D g2, int x) { Rectangle2D dataArea = getScreenDataArea(); if (((int) dataArea.getMinX() < x) && (x < (int) dataArea.getMaxX())) { g2.setPaint(getAxisTraceColor()); g2.setStroke(new BasicStroke(0.25f)); g2.draw(new Line2D.Float(x, (int) dataArea.getMinY(), x, (int) dataArea.getMaxY())); } }
From source file:org.gumtree.vis.awt.JChartPanel.java
/** * Draws a horizontal line used to trace the mouse position to the vertical * axis./*from ww w . j ava 2 s .c o m*/ * * @param g2 the graphics device. * @param y the y-coordinate of the trace line. */ private void drawVerticalAxisTrace(Graphics2D g2, int y) { Rectangle2D dataArea = getScreenDataArea(); if (((int) dataArea.getMinY() < y) && (y < (int) dataArea.getMaxY())) { g2.setPaint(getAxisTraceColor()); g2.setStroke(new BasicStroke(0.25f)); g2.draw(new Line2D.Float((int) dataArea.getMinX(), y, (int) dataArea.getMaxX(), y)); } }
From source file:dk.sdu.mmmi.featureous.views.featurecharacterization.FeatureViewChart.java
public FeatureViewChart(List<TraceModel> ftms, final boolean pkg) { this.pkg = pkg; data = new DefaultCategoryDataset(); chart = ChartFactory.createStackedBarChart("Feature characterization", "Feature", "Scattering", data, PlotOrientation.VERTICAL, true, false, false); plot = (CategoryPlot) chart.getPlot(); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_45); xAxis.setMaximumCategoryLabelLines(2); // chart.getLegend().setPosition(RectangleEdge.RIGHT); // chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP); // chart.getLegend().setHorizontalAlignment(HorizontalAlignment.LEFT); LegendItemCollection lic = new LegendItemCollection(); // lic.add(new LegendItem("Infrastructural unit", "", "", "", new Rectangle(10, 10), Color.GREEN)); // lic.add(new LegendItem("Group-feature unit", "", "", "", new Rectangle(10, 10), Color.BLUE)); // lic.add(new LegendItem("Single-feature unit", "", "", "", new Rectangle(10, 10), Color.RED)); plot.setFixedLegendItems(lic);/*from w w w .j av a 2 s.c o m*/ // chart.removeLegend(); panel = new ChartPanel(chart); chart.setBackgroundPaint(Color.white); this.ftms = ftms; scattering = new ArrayList<Result>( new StaticScattering(pkg).calculateAndReturnAll(new HashSet<TraceModel>(ftms), null)); Result.sortByName(scattering); for (Result r : scattering) { // OutputUtil.log(r.name + ";" +r.value); } panel.getPopupMenu().setEnabled(false);//add(SVGExporter.createExportAction(chart, panel)); StackedBarRenderer r2 = new StackedBarRenderer() { @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); double start = plot.getDomainAxis().getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double end = plot.getDomainAxis().getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); String compUnit = data.getRowKey(row).toString(); // Calculate y coeffs double posBase = getBase(); for (int i = 0; i < row; i++) { Number val = dataset.getValue(i, column); if (val != null) { posBase = posBase + val.doubleValue(); } } Number value = dataset.getValue(row, column); if (value == null) { return; } double val = value.doubleValue(); double translatedBase = plot.getRangeAxis().valueToJava2D(posBase, dataArea, plot.getRangeAxisEdge()); double translatedValue = plot.getRangeAxis().valueToJava2D(posBase + val, dataArea, plot.getRangeAxisEdge()); if (Controller.getInstance().getTraceSet().getSelectionManager().getSelectedClasses() .contains(compUnit) || Controller.getInstance().getTraceSet().getSelectionManager().getSelectedPkgs() .contains(compUnit)) { g2.setPaint(UIUtils.SELECTION_COLOR); g2.setStroke(new BasicStroke(3f)); Line2D l2d = new Line2D.Double(start, translatedBase, start, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(end, translatedBase, end, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(start, translatedBase, end, translatedBase); g2.draw(l2d); l2d = new Line2D.Double(start, translatedValue, end, translatedValue); g2.draw(l2d); } } }; plot.setRenderer(r2, true); StackedBarRenderer r = (StackedBarRenderer) plot.getRenderer(); r.setDrawBarOutline(true); plot.getRenderer().setOutlineStroke(new BasicStroke(0.1f)); Controller.getInstance().getTraceSet().getSelectionManager().addSelectionListener(this); }
From source file:forseti.JUtil.java
public static synchronized Image generarImagenMensaje(String mensaje, String nombreFuente, int tamanioFuente) { Frame f = new Frame(); f.addNotify();//w w w . j av a2s.co m GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); env.getAvailableFontFamilyNames(); Font fuente = new Font(nombreFuente, Font.PLAIN, tamanioFuente); FontMetrics medidas = f.getFontMetrics(fuente); int anchoMensaje = medidas.stringWidth(mensaje); int lineaBaseX = anchoMensaje / 10; int ancho = anchoMensaje + 2 * (lineaBaseX + tamanioFuente); int alto = tamanioFuente * 7 / 2; int lineaBaseY = alto * 8 / 10; Image imagenMensaje = f.createImage(ancho, alto); Graphics2D g2d = (Graphics2D) imagenMensaje.getGraphics(); g2d.setFont(fuente); g2d.translate(lineaBaseX, lineaBaseY); g2d.setPaint(Color.lightGray); AffineTransform origTransform = g2d.getTransform(); g2d.shear(-0.95, 0); g2d.scale(1, 3); g2d.drawString(mensaje, 0, 0); g2d.setTransform(origTransform); g2d.setPaint(Color.black); g2d.drawString(mensaje, 0, 0); return (imagenMensaje); }
From source file:com.fluidops.iwb.deepzoom.ImageLoader.java
private void generateIDCard(URI uri, Map<URI, Set<Value>> facets, String url, File file) { int width = 200; int height = 200; BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D ig2 = bi.createGraphics(); ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ig2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); /* Special ID card handling for certain entity types */ /* TODO: special images based on type if(facets.containsKey(RDF.TYPE)) {/*w w w .j a v a 2s. c o m*/ Set<Value> facet = facets.get(RDF.TYPE); for(Value v : facet) { if(v.equals(Vocabulary.DCAT_DATASET)) { Image img = null; try { img = ImageIO.read( new File( "webapps/ROOT/images/rdf.jpg" ) ); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } catch (IOException e) { logger.error("Could not get image"); } ig2.drawImage( img, 0, 0, null ); break; } } } */ String label = EndpointImpl.api().getDataManager().getLabel(uri); Font font = new Font(Font.SANS_SERIF, Font.BOLD, 20); ig2.setFont(font); FontMetrics fontMetrics = ig2.getFontMetrics(); int labelwidth = fontMetrics.stringWidth(label); if (labelwidth >= width) { int fontsize = 20 * width / labelwidth; font = new Font(Font.SANS_SERIF, Font.BOLD, fontsize); ig2.setFont(font); fontMetrics = ig2.getFontMetrics(); } int x = (width - fontMetrics.stringWidth(label)) / 2; int y = (fontMetrics.getAscent() + (height - (fontMetrics.getAscent() + fontMetrics.getDescent())) / 2); ig2.setPaint(Color.black); ig2.drawString(label, x, y); BufferedOutputStream out; try { out = new BufferedOutputStream(new FileOutputStream(file)); ImageIO.write(bi, "PNG", out); out.flush(); out.close(); } catch (IOException e) { logger.error(e.getMessage(), e); } }
From source file:dk.sdu.mmmi.featureous.views.codecharacterization.TanglingViewChart.java
public TanglingViewChart(boolean pkg, boolean sortByValue) { this.sortByValue = sortByValue; this.pkg = pkg; data = new DefaultKeyedValues2DDataset(); String title = "Computational unit characterization"; jchart = ChartFactory.createStackedBarChart(title, (pkg) ? "Package" : "Class", "Tangling", data, PlotOrientation.VERTICAL, true, false, false); CategoryPlot plot = (CategoryPlot) jchart.getPlot(); // chart.getLegend().setPosition(RectangleEdge.RIGHT); // chart.getLegend().setVerticalAlignment(VerticalAlignment.TOP); // chart.getLegend().setHorizontalAlignment(HorizontalAlignment.LEFT); LegendItemCollection lic = new LegendItemCollection(); // lic.add(new LegendItem("Infrastructural unit", "", "", "", new Rectangle(10, 10), Color.GREEN)); // lic.add(new LegendItem("Group-feature unit", "", "", "", new Rectangle(10, 10), Color.BLUE)); // lic.add(new LegendItem("Single-feature unit", "", "", "", new Rectangle(10, 10), Color.RED)); plot.setFixedLegendItems(lic);/*from ww w. j a v a 2s . c o m*/ // chart.removeLegend(); plot.setDomainAxis(new SparselyLabeledCategoryAxis(20)); CategoryAxis xAxis = (CategoryAxis) plot.getDomainAxis(); xAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90); xAxis.setLabel((pkg) ? "Package" : "Class"); // xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 5, 5)); // xAxis.setMaximumCategoryLabelLines(1); xAxis.setLowerMargin(0); xAxis.setCategoryMargin(0); xAxis.setUpperMargin(0); // xAxis.setMaximumCategoryLabelWidthRatio(20f); jchart.setBackgroundPaint(Color.white); StackedBarRenderer renderer = new StackedBarRenderer() { @Override public void drawItem(Graphics2D g2, CategoryItemRendererState state, Rectangle2D dataArea, CategoryPlot plot, CategoryAxis domainAxis, ValueAxis rangeAxis, CategoryDataset dataset, int row, int column, int pass) { super.drawItem(g2, state, dataArea, plot, domainAxis, rangeAxis, dataset, row, column, pass); double start = plot.getDomainAxis().getCategoryStart(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); double end = plot.getDomainAxis().getCategoryEnd(column, getColumnCount(), dataArea, plot.getDomainAxisEdge()); String compUnit = data.getRowKey(row).toString(); // Calculate y coeffs double posBase = getBase(); // for(int i = 0; i<row; i++){ // Number val = dataset.getValue(i, column); // if(val!=null){ // posBase = posBase + val.doubleValue(); // } // } Number value = dataset.getValue(row, column); if (value == null) { return; } double val = value.doubleValue(); double translatedBase = plot.getRangeAxis().valueToJava2D(posBase, dataArea, plot.getRangeAxisEdge()); double translatedValue = plot.getRangeAxis().valueToJava2D(posBase + val, dataArea, plot.getRangeAxisEdge()); if (Controller.getInstance().getTraceSet().getSelectionManager().getSelectedClasses() .contains(compUnit) || Controller.getInstance().getTraceSet().getSelectionManager().getSelectedPkgs() .contains(compUnit)) { g2.setPaint(UIUtils.SELECTION_COLOR); g2.setStroke(new BasicStroke(3f)); Line2D l2d = new Line2D.Double(start, translatedBase, start, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(end, translatedBase, end, translatedValue); g2.draw(l2d); l2d = new Line2D.Double(start, translatedBase, end, translatedBase); g2.draw(l2d); l2d = new Line2D.Double(start, translatedValue, end, translatedValue); g2.draw(l2d); } } }; renderer.setToolTipGenerator(new CategoryToolTipGenerator() { public String generateToolTip(CategoryDataset cd, int i, int i1) { String key = data.getRowKey(i).toString(); // key = key.substring(0, key.length()-1); return "<html>" + i + " - " + key + "<br>" + Double.toString(cd.getValue(i, i1).doubleValue()) + "</hmtl>"; } }); plot.setRenderer(renderer); panel = new ChartPanel(jchart); panel.getPopupMenu().setEnabled(false);//add(SVGExporter.createExportAction(chart, panel)); createView(); Controller.getInstance().getTraceSet().getSelectionManager().addSelectionListener(this); }
From source file:com.moviejukebox.plugin.DefaultImagePlugin.java
/** * Draw a frame around the image; color depends on resolution if wanted * * @param movie//from ww w. ja va 2 s . com * @param bi * @return */ private BufferedImage drawFrame(Movie movie, BufferedImage bi) { BufferedImage newImg = new BufferedImage(bi.getWidth(), bi.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D newGraphics = newImg.createGraphics(); newGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cornerRadius2 = 0; if (!movie.isHD()) { String[] colorSD = frameColorSD.split("/"); int[] lengthSD = new int[colorSD.length]; for (int i = 0; i < colorSD.length; i++) { lengthSD[i] = Integer.parseInt(colorSD[i]); } newGraphics.setPaint(new Color(lengthSD[0], lengthSD[1], lengthSD[2])); } else if (highdefDiff) { if (movie.isHD()) { // Otherwise use the 720p String[] color720 = frameColor720.split("/"); int[] length720 = new int[color720.length]; for (int i = 0; i < color720.length; i++) { length720[i] = Integer.parseInt(color720[i]); } newGraphics.setPaint(new Color(length720[0], length720[1], length720[2])); } if (movie.isHD1080()) { String[] color1080 = frameColor1080.split("/"); int[] length1080 = new int[color1080.length]; for (int i = 0; i < color1080.length; i++) { length1080[i] = Integer.parseInt(color1080[i]); } newGraphics.setPaint(new Color(length1080[0], length1080[1], length1080[2])); } } else { // We don't care, so use the default HD logo. String[] colorHD = frameColorHD.split("/"); int[] lengthHD = new int[colorHD.length]; for (int i = 0; i < colorHD.length; i++) { lengthHD[i] = Integer.parseInt(colorHD[i]); } newGraphics.setPaint(new Color(lengthHD[0], lengthHD[1], lengthHD[2])); } if (roundCorners) { cornerRadius2 = cornerRadius; } RoundRectangle2D.Double rect = new RoundRectangle2D.Double(0, 0, bi.getWidth(), bi.getHeight(), rcqFactor * cornerRadius2, rcqFactor * cornerRadius2); newGraphics.setClip(rect); // image fitted into border newGraphics.drawImage(bi, (int) (rcqFactor * frameSize - 1), (int) (rcqFactor * frameSize - 1), (int) (bi.getWidth() - (rcqFactor * frameSize * 2) + 2), (int) (bi.getHeight() - (rcqFactor * frameSize * 2) + 2), null); BasicStroke s4 = new BasicStroke(rcqFactor * frameSize * 2); newGraphics.setStroke(s4); newGraphics.draw(rect); newGraphics.dispose(); return newImg; }
From source file:io.github.dsheirer.spectrum.SpectrumPanel.java
/** * Draws the current fft spectrum with a line and a gradient fill. *//* w w w. j av a2s . c o m*/ private void drawSpectrum(Graphics2D graphics) { Dimension size = getSize(); //Draw the background Rectangle background = new Rectangle(0, 0, size.width, size.height); graphics.setColor(mColorSpectrumBackground); graphics.draw(background); graphics.fill(background); //Define the gradient GradientPaint gradient = new GradientPaint(0, (getSize().height - mSpectrumInset) / 2, mColorSpectrumGradientTop, 0, getSize().height, mColorSpectrumGradientBottom); graphics.setBackground(mColorSpectrumBackground); GeneralPath spectrumShape = new GeneralPath(); //Start at the lower right inset point spectrumShape.moveTo(size.getWidth(), size.getHeight() - mSpectrumInset); //Draw to the lower left spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset); float[] bins = getBins(); //If we have FFT data to display ... if (bins != null) { float insideHeight = size.height - mSpectrumInset; float scalor = insideHeight / -mDBScale; /* Calculate based on bin size - 1, since bin 0 is rendered at zero * and the last bin is rendered at the width */ float binSize = (float) size.width / ((float) (bins.length)); for (int x = 0; x < bins.length; x++) { float height; height = bins[x] * scalor; if (height > insideHeight) { height = insideHeight; } if (height < 0) { height = 0; } float xAxis = (float) x * binSize; spectrumShape.lineTo(xAxis, height); } } //Otherwise show an empty spectrum else { //Draw Left Size graphics.setPaint(gradient); spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset); //Draw Middle spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset); } //Draw Right Side spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset); graphics.setPaint(gradient); graphics.draw(spectrumShape); graphics.fill(spectrumShape); graphics.setPaint(mColorSpectrumLine); //Draw the bottom line under the spectrum graphics.draw(new Line2D.Float(0, size.height - mSpectrumInset, size.width, size.height - mSpectrumInset)); }