List of usage examples for java.awt GradientPaint GradientPaint
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)
From source file:ReportGen.java
private void monthlyPreview(String year, String table) throws NumberFormatException { try {/*from w ww.ja v a2 s. c om*/ exportcounttableexcel.setEnabled(true); exportcounttablepdf.setEnabled(true); // exportgraphtoimage.setEnabled(true); tableModel = (DefaultTableModel) dataTable.getModel(); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged(); String str[] = { "Months", "Values" }; tableModel.setColumnIdentifiers(str); ChartPanel chartPanel; displaypane.removeAll(); displaypane.revalidate(); displaypane.repaint(); displaypane.setLayout(new BorderLayout()); //row String series1 = "Results"; //column, String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; String yr = year; int value[] = new int[12]; int c = 0; switch (table) { case "Reservation": for (String month : months) { value[c] = client.getCountMonthlyReportReservation("0" + (c + 1), yr); c++; } break; case "Registration": for (String month : months) { value[c] = client.getCountMonthlyReportRegistration("0" + (c + 1), yr); c++; } break; case "Bill": for (String month : months) { String result = client.getMonthlyBillingReport("0" + (c + 1), yr); if (result != null) { String[] dates = result.split("-"); if (Integer.parseInt(dates[2]) > 5) { value[c] += 1; } } c++; } break; } for (int i = 0; i < months.length; i++) { tableModel.addRow(new Object[] { months[i], value[i] }); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(value[0], series1, months[0]); dataset.addValue(value[1], series1, months[1]); dataset.addValue(value[2], series1, months[2]); dataset.addValue(value[3], series1, months[3]); dataset.addValue(value[4], series1, months[4]); dataset.addValue(value[5], series1, months[5]); dataset.addValue(value[6], series1, months[6]); dataset.addValue(value[7], series1, months[7]); dataset.addValue(value[8], series1, months[8]); dataset.addValue(value[9], series1, months[9]); dataset.addValue(value[10], series1, months[10]); dataset.addValue(value[11], series1, months[11]); chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title "Months of the Year 2014", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chartPanel = new ChartPanel(chart); displaypane.add(chartPanel, BorderLayout.CENTER); } catch (RemoteException ex) { // Logger.getLogger(ReportGen.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:ReportGen.java
private void yearlyPreview(String table) throws NumberFormatException { try {/*from w w w. j av a2s.com*/ exportcounttableexcel.setEnabled(true); exportcounttablepdf.setEnabled(true); // exportgraphtoimage.setEnabled(true); tableModel = (DefaultTableModel) dataTable.getModel(); tableModel.getDataVector().removeAllElements(); tableModel.fireTableDataChanged(); String str[] = { "Months", "Values" }; tableModel.setColumnIdentifiers(str); ChartPanel chartPanel; displaypane.removeAll(); displaypane.revalidate(); displaypane.repaint(); displaypane.setLayout(new BorderLayout()); //row String series1 = "Results"; //column, String years[] = { "2014", "2015", "2016", "2017", "2018", "2019", "2020" }; int value[] = new int[7]; int c = 0; switch (table) { case "Reservation": for (String year : years) { value[c] = client.getCountYearlyReportReservation(year); c++; } break; case "Registration": for (String year : years) { value[c] = client.getCountYearlyReportRegistration(year); c++; } break; } for (int i = 0; i < years.length; i++) { tableModel.addRow(new Object[] { years[i], value[i] }); } DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(value[0], series1, years[0]); dataset.addValue(value[1], series1, years[1]); dataset.addValue(value[2], series1, years[2]); dataset.addValue(value[3], series1, years[3]); dataset.addValue(value[4], series1, years[4]); dataset.addValue(value[5], series1, years[5]); dataset.addValue(value[6], series1, years[6]); chart = ChartFactory.createBarChart("181 North Place Residences Graph", // chart title "Months of the Year 2014", // domain axis label "Value", // range axis label dataset, // data PlotOrientation.VERTICAL, // orientation true, // include legend true, // tooltips false // urls ); // set the background color for the chart... chart.setBackgroundPaint(Color.white); // get a reference to the plot for further customisation... final CategoryPlot plot = chart.getCategoryPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); // set the range axis to display integers only... final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // disable bar outlines... final BarRenderer renderer = (BarRenderer) plot.getRenderer(); renderer.setDrawBarOutline(false); // set up gradient paints for series... final GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, Color.lightGray); final GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, Color.lightGray); renderer.setSeriesPaint(0, gp0); renderer.setSeriesPaint(1, gp1); renderer.setSeriesPaint(2, gp2); final org.jfree.chart.axis.CategoryAxis domainAxis = plot.getDomainAxis(); domainAxis.setCategoryLabelPositions( CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0)); chartPanel = new ChartPanel(chart); displaypane.add(chartPanel, BorderLayout.CENTER); } catch (RemoteException ex) { // Logger.getLogger(ReportGen.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart// ww w . jav a2 s.c om */ public JFreeChart createWaferMapChart() { final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(5); final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo", // title dataset, // wafermapdataset PlotOrientation.VERTICAL, // vertical = notchdown true, // legend false, // tooltips false); // final Legend legend = chart.getLegend(); // legend.setAnchor(Legend.EAST); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9)); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); return chart; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart//from ww w. j a v a2 s . c o m */ public JFreeChart createWaferMapChartValueIndexed() { final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(500); final JFreeChart chart = ChartFactory.createWaferMapChart("Wafer Map Demo - Value Indexed", // title dataset, // wafermapdataset PlotOrientation.VERTICAL, // vertical = notchdown true, // legend false, // tooltips false); // final Legend legend = chart.getLegend(); // legend.setAnchor(Legend.EAST); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9)); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); return chart; }
From source file:org.jfree.chart.demo.JFreeChartDemoBase.java
/** * Creates a basic wafermap chart with a random dataset * * @return a wafermap chart/*from w w w . j a va 2 s .c om*/ */ public JFreeChart createWaferMapChartPositionIndexed() { final WaferMapDataset dataset = DemoDatasetFactory.createRandomWaferMapDataset(500); final WaferMapPlot plot = new WaferMapPlot(dataset); final WaferMapRenderer renderer = new WaferMapRenderer(35, WaferMapRenderer.POSITION_INDEX); plot.setRenderer(renderer); final JFreeChart chart = new JFreeChart("Wafer Map Demo - Position Indexed", JFreeChart.DEFAULT_TITLE_FONT, plot, true); // final Legend legend = chart.getLegend(); // legend.setAnchor(Legend.EAST); chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.blue)); final TextTitle copyright = new TextTitle("JFreeChart WaferMapPlot", new Font("SansSerif", Font.PLAIN, 9)); copyright.setPosition(RectangleEdge.BOTTOM); copyright.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(copyright); return chart; }
From source file:paintbasico2d.VentanaPrincipal.java
private void jRadioButtonDegradadoHorizontalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonDegradadoHorizontalActionPerformed // TODO add your handling code here: VentanaInterna vi;//from w w w . j ava 2 s . c o m if (escritorio.getSelectedFrame() instanceof VentanaInterna) { vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi.getLienzo().getEditar()) { UserShape s = vi.getLienzo().getSelectedShape(); if (s != null) { s.setRelleno(false); s.setisGradiente(true); s.setGradiente(new GradientPaint((float) s.getBounds2D().getX(), 0, this.jButtonDegradado1.getBackground(), (float) s.getBounds2D().getX() + (float) s.getBounds2D().getWidth(), 0, this.jButtonDegradado2.getBackground())); vi.repaint(); } } else { vi.getLienzo().SetRelleno(false); vi.getLienzo().setIsGradiente(true); GradientPaint g = new GradientPaint(0, 0, jButtonDegradado1.getBackground(), vi.getLienzo().getWidth(), 0, jButtonDegradado2.getBackground()); //vi.getLienzo().setGradiente(new GradientPaint(0,0, this.jButtonDegradado1.getBackground(), vi.getLienzo().getWidth(),0,this.jButtonDegradado2.getBackground())); vi.getLienzo().setGradiente(g); } } }
From source file:paintbasico2d.VentanaPrincipal.java
private void jRadioButtonDegradadoVerticalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonDegradadoVerticalActionPerformed // TODO add your handling code here: VentanaInterna vi;/*ww w .jav a 2 s . c om*/ if (escritorio.getSelectedFrame() instanceof VentanaInterna) { vi = (VentanaInterna) escritorio.getSelectedFrame(); if (vi.getLienzo().getEditar()) { UserShape s = vi.getLienzo().getSelectedShape(); if (s != null) { s.setRelleno(false); s.setisGradiente(true); s.setGradiente(new GradientPaint(0, 0, jButtonDegradado1.getBackground(), 0, vi.getLienzo().getHeight(), jButtonDegradado2.getBackground())); vi.repaint(); } } else { vi.getLienzo().SetRelleno(false); vi.getLienzo().setIsGradiente(true); GradientPaint g = new GradientPaint(0, 0, jButtonDegradado1.getBackground(), 0, vi.getLienzo().getHeight(), jButtonDegradado2.getBackground()); //vi.getLienzo().setGradiente(new GradientPaint(0,0, this.jButtonDegradado1.getBackground(), vi.getLienzo().getWidth(),0,this.jButtonDegradado2.getBackground())); vi.getLienzo().setGradiente(g); } } }
From source file:edu.ku.brc.ui.UIHelper.java
/** * @param g2/*from www . j a va 2 s.c om*/ * @param shape * @param glowWidth */ public static void paintBorderGlow(final Graphics2D g2, final Shape shape, final int glowWidth) { int gw = glowWidth * 2; for (int i = gw; i >= 2; i -= 2) { float pct = (float) (gw - i) / (gw - 1); Color mixHi = getMixedColor(clrGlowInnerHi, pct, clrGlowOuterHi, 1.0f - pct); Color mixLo = getMixedColor(clrGlowInnerLo, pct, clrGlowOuterLo, 1.0f - pct); g2.setPaint(new GradientPaint(0.0f, 40 * 0.25f, mixHi, 0.0f, 40, mixLo)); g2.setColor(Color.WHITE); // See my "Java 2D Trickery: Soft Clipping" entry for more // on why we use SRC_ATOP here g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, pct)); g2.setStroke(new BasicStroke(i)); g2.draw(shape); } }
From source file:org.forester.archaeopteryx.TreePanel.java
final void paintPhylogeny(final Graphics2D g, final boolean to_pdf, final boolean to_graphics_file, final int graphics_file_width, final int graphics_file_height, final int graphics_file_x, final int graphics_file_y) { /* GUILHEM_BEG */ _query_sequence = _control_panel.getSelectedQuerySequence(); /* GUILHEM_END */ // Color the background if (!to_pdf) { final Rectangle r = getVisibleRect(); if (!getOptions().isBackgroundColorGradient() || getOptions().isPrintBlackAndWhite()) { g.setColor(getTreeColorSet().getBackgroundColor()); if (!to_graphics_file) { g.fill(r);//from ww w .j a va 2s.c o m } else { if (getOptions().isPrintBlackAndWhite()) { g.setColor(Color.WHITE); } g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height); } } else { if (!to_graphics_file) { g.setPaint(new GradientPaint(r.x, r.y, getTreeColorSet().getBackgroundColor(), r.x, r.y + r.height, getTreeColorSet().getBackgroundColorGradientBottom())); g.fill(r); } else { g.setPaint(new GradientPaint(graphics_file_x, graphics_file_y, getTreeColorSet().getBackgroundColor(), graphics_file_x, graphics_file_y + graphics_file_height, getTreeColorSet().getBackgroundColorGradientBottom())); g.fillRect(graphics_file_x, graphics_file_y, graphics_file_width, graphics_file_height); } } g.setStroke(new BasicStroke(1)); } else { g.setStroke(new BasicStroke(getOptions().getPrintLineWidth())); } if ((getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED) && (getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.CIRCULAR)) { _external_node_index = 0; // Position starting X of tree if (!_phylogeny.isRooted()) { _phylogeny.getRoot().setXcoord(TreePanel.MOVE); } else if ((_phylogeny.getRoot().getDistanceToParent() > 0.0) && getControlPanel().isDrawPhylogram()) { _phylogeny.getRoot().setXcoord((float) (TreePanel.MOVE + (_phylogeny.getRoot().getDistanceToParent() * getXcorrectionFactor()))); } else { _phylogeny.getRoot().setXcoord(TreePanel.MOVE + getXdistance()); } // Position starting Y of tree _phylogeny.getRoot().setYcoord( (getYdistance() * _phylogeny.getRoot().getNumberOfExternalNodes()) + (TreePanel.MOVE / 2.0f)); final int dynamic_hiding_factor = (int) (getTreeFontSet()._fm_large.getHeight() / (1.5 * getYdistance())); if (getControlPanel().isDynamicallyHideData()) { if (dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } final PhylogenyNodeIterator it; for (it = _phylogeny.iteratorPreorder(); it.hasNext();) { paintNodeRectangular(g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData() && (dynamic_hiding_factor > 1), dynamic_hiding_factor, to_graphics_file); } if (getOptions().isShowScale()) { if (!(to_graphics_file || to_pdf)) { paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf, to_graphics_file); } else { paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file); } } if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { paintPhylogenyLite(g); } } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.UNROOTED) { if (getControlPanel().getDynamicallyHideData() != null) { getControlPanel().setDynamicHidingIsOn(false); } final double angle = getStartingAngle(); final boolean radial_labels = getOptions().getNodeLabelDirection() == NODE_LABEL_DIRECTION.RADIAL; _dynamic_hiding_factor = 0; if (getControlPanel().isDynamicallyHideData()) { _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * 10)); } if (getControlPanel().getDynamicallyHideData() != null) { if (_dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } paintUnrooted(_phylogeny.getRoot(), angle, (float) (angle + 2 * Math.PI), radial_labels, g, to_pdf, to_graphics_file); if (getOptions().isShowScale()) { if (!(to_graphics_file || to_pdf)) { paintScale(g, getVisibleRect().x, getVisibleRect().y + getVisibleRect().height, to_pdf, to_graphics_file); } else { paintScale(g, graphics_file_x, graphics_file_y + graphics_file_height, to_pdf, to_graphics_file); } } if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { g.setColor(getTreeColorSet().getOvColor()); paintUnrootedLite(_phylogeny.getRoot(), angle, angle + 2 * Math.PI, g, (getUrtFactorOv() / (getVisibleRect().width / getOvMaxWidth()))); paintOvRectangle(g); } } else if (getPhylogenyGraphicsType() == PHYLOGENY_GRAPHICS_TYPE.CIRCULAR) { final int radius = (int) ((Math.min(getPreferredSize().getWidth(), getPreferredSize().getHeight()) / 2) - (MOVE + getLongestExtNodeInfo())); final int d = radius + MOVE + getLongestExtNodeInfo(); _dynamic_hiding_factor = 0; if (getControlPanel().isDynamicallyHideData() && (radius > 0)) { _dynamic_hiding_factor = (int) ((getTreeFontSet()._fm_large.getHeight() * 1.5 * getPhylogeny().getNumberOfExternalNodes()) / (TWO_PI * radius)); } if (getControlPanel().getDynamicallyHideData() != null) { if (_dynamic_hiding_factor > 1) { getControlPanel().setDynamicHidingIsOn(true); } else { getControlPanel().setDynamicHidingIsOn(false); } } paintCircular(_phylogeny, getStartingAngle(), d, d, radius > 0 ? radius : 0, g, to_pdf, to_graphics_file); if (getOptions().isShowOverview() && isOvOn() && !to_graphics_file && !to_pdf) { final int radius_ov = (int) (getOvMaxHeight() < getOvMaxWidth() ? getOvMaxHeight() / 2 : getOvMaxWidth() / 2); double x_scale = 1.0; double y_scale = 1.0; int x_pos = getVisibleRect().x + getOvXPosition(); int y_pos = getVisibleRect().y + getOvYPosition(); if (getWidth() > getHeight()) { x_scale = (double) getHeight() / getWidth(); x_pos = ForesterUtil.roundToInt(x_pos / x_scale); } else { y_scale = (double) getWidth() / getHeight(); y_pos = ForesterUtil.roundToInt(y_pos / y_scale); } _at = g.getTransform(); g.scale(x_scale, y_scale); paintCircularLite(_phylogeny, getStartingAngle(), x_pos + radius_ov, y_pos + radius_ov, (int) (radius_ov - (getLongestExtNodeInfo() / (getVisibleRect().width / getOvRectangle().getWidth()))), g); g.setTransform(_at); paintOvRectangle(g); } } }