List of usage examples for java.awt GradientPaint GradientPaint
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)
From source file:Main.java
AnimatedImage() { super(60, 60, BufferedImage.TYPE_INT_RGB); frameGradient = new GradientPaint[6]; for (int i = 0; i < frameGradient.length; i++) { frameGradient[i] = new GradientPaint(0f, (float) i, Color.BLUE, 0f, (float) i + 13, Color.RED, true); }/*w w w.ja v a 2 s . c om*/ }
From source file:Charts2D.java
public Charts2D() { super("2D Charts"); setSize(720, 280);/*from w ww.j a v a 2 s . co m*/ getContentPane().setLayout(new GridLayout(1, 3, 10, 0)); getContentPane().setBackground(Color.white); int[] xData = new int[8]; int[] yData = new int[8]; for (int i = 0; i < xData.length; i++) { xData[i] = i; yData[i] = (int) (Math.random() * 100); if (i > 0) yData[i] = (yData[i - 1] + yData[i]) / 2; } JChart2D chart = new JChart2D(JChart2D.LineChart, xData.length, xData, yData, "Line Chart"); chart.setStroke(new BasicStroke(5f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER)); chart.setLineColor(new Color(0, 28, 28)); getContentPane().add(chart); chart = new JChart2D(JChart2D.ColumnChart, xData.length, xData, yData, "Column Chart"); GradientPaint gp = new GradientPaint(0, 100, Color.white, 0, 300, Color.blue, true); chart.setGradient(gp); chart.setEffectIndex(JChart2D.Gradientffect); chart.setDrawShadow(true); getContentPane().add(chart); chart = new JChart2D(JChart2D.PieChart, xData.length, xData, yData, "Pie Chart"); ImageIcon icon = new ImageIcon("largeJava2slogo.GIF"); chart.setForegroundImage(icon.getImage()); chart.setEffectIndex(JChart2D.ImageEffect); chart.setDrawShadow(true); getContentPane().add(chart); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:misc.GradientTranslucentWindowDemo.java
public GradientTranslucentWindowDemo() { super("GradientTranslucentWindow"); setBackground(new Color(0, 0, 0, 0)); setSize(new Dimension(300, 200)); setLocationRelativeTo(null);//from www .jav a 2s . c o m setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel() { @Override protected void paintComponent(Graphics g) { if (g instanceof Graphics2D) { final int R = 240; final int G = 240; final int B = 240; Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0), 0.0f, getHeight(), new Color(R, G, B, 255), true); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(p); g2d.fillRect(0, 0, getWidth(), getHeight()); } } }; setContentPane(panel); setLayout(new GridBagLayout()); add(new JButton("I am a Button")); }
From source file:graficarordenamiento.Graficador.java
public void crearGrafico() { // Creando el Grafico chart = ChartFactory.createBarChart("Grfico de barras", null, null, dataset, PlotOrientation.VERTICAL, false, false, false);//from w w w. j a v a2s .c om chart.setBackgroundPaint(new GradientPaint(0, 0, Color.WHITE, 700, 0, Color.BLACK.brighter(), false)); chart.setBackgroundImageAlpha(0.5f); final CategoryPlot plot = chart.getCategoryPlot(); plot.setNoDataMessage("NO DATA!"); plot.setRangeGridlinePaint(Color.red); plot.setBackgroundPaint(new GradientPaint(0, 0, Color.LIGHT_GRAY, 0, 100, Color.darkGray)); plot.setBackgroundImageAlpha(0.5f); //plot.setDomainGridlinesVisible(true); BarRenderer rend = (BarRenderer) plot.getRenderer(); final ItemLabelPosition e = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0); GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64)); GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0)); GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0)); rend.setSeriesPaint(0, gp0); rend.setSeriesPaint(1, gp1); rend.setSeriesPaint(2, gp2); plot.setRenderer(rend); // change the margin at the top of the range axis... final ValueAxis rangeAxis = plot.getRangeAxis(); rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); rangeAxis.setLowerMargin(0.15); rangeAxis.setUpperMargin(0.15); // set up gradient paints for series... }
From source file:GradientPanel.java
public void paintComponent(Graphics g) { if (isOpaque()) { super.paintComponent(g); return;//from w w w.j av a2 s . co m } int width = getWidth(); int height = getHeight(); // Create the gradient paint GradientPaint paint = null; Color sc = getForeground(); Color ec = getBackground(); switch (direction) { case HORIZONTAL: { paint = new GradientPaint(0, height / 2, sc, width, height / 2, ec, cyclic); break; } case VERTICAL: { paint = new GradientPaint(width / 2, 0, sc, width / 2, maxLength > 0 ? maxLength : height, ec, cyclic); break; } case DIAGONAL_LEFT: { paint = new GradientPaint(0, 0, sc, width, height, ec, cyclic); break; } case DIAGONAL_RIGHT: { paint = new GradientPaint(width, 0, sc, 0, height, ec, cyclic); break; } } if (paint == null) { throw new RuntimeException("Invalid direction specified in GradientPanel"); } // we need to cast to Graphics2D for this operation Graphics2D g2d = (Graphics2D) g; // save the old paint Paint oldPaint = g2d.getPaint(); // set the paint to use for this operation g2d.setPaint(paint); // fill the background using the paint g2d.fillRect(0, 0, width, height); // restore the original paint g2d.setPaint(oldPaint); super.paintComponent(g); }
From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileChartFactory.java
public static JFreeChart createDiveProfileChartPanel(DiveProfile diveProfile, Locale locale, LengthUnit lengthUnit) {//from w w w . j a v a 2 s . c om XYSeries depthSerie = new XYSeries(SERIE_DEPTH); XYSeriesCollection depthCollection = new XYSeriesCollection(); depthCollection.addSeries(depthSerie); JFreeChart chart = ChartFactory.createXYAreaChart(null, getDomainLegend(locale), getRangeLegend(locale, lengthUnit), depthCollection, PlotOrientation.VERTICAL, false, true, false); XYPlot xyp = chart.getXYPlot(); Paint p = new GradientPaint(0f, 0f, UIAgent.getInstance().getColorWaterBottom(), 200f, 200f, UIAgent.getInstance().getColorWaterSurface(), false); xyp.setBackgroundPaint(p); xyp.setDomainGridlinePaint(UIAgent.getInstance().getColorWaterGrid()); xyp.setRangeGridlinePaint(UIAgent.getInstance().getColorWaterGrid()); ((NumberAxis) xyp.getDomainAxis()).setNumberFormatOverride(new MinutesNumberFormat()); XYAreaRenderer renderer0 = new XYAreaRenderer(); renderer0.setOutline(true); renderer0.setBaseOutlinePaint(UIAgent.getInstance().getColorWaterBottom()); Color baseColor = UIAgent.getInstance().getColorBaseBackground(); renderer0.setSeriesPaint(0, new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 50)); xyp.setRenderer(0, renderer0); int i = 1; XYSeriesCollection decoEntriesCollection = new XYSeriesCollection(); XYSeries decoEntriesSerie = new XYSeries(SERIE_DECO_ENTRY); decoEntriesCollection.addSeries(decoEntriesSerie); XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorDecoEntries()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_ENTRY]); xyp.setDataset(i, decoEntriesCollection); xyp.setRenderer(i, renderer2); i++; XYSeriesCollection ascentTooFastCollection = new XYSeriesCollection(); XYSeries ascentTooFastSerie = new XYSeries(SERIE_WARNING_ASCENT_TOO_FAST); ascentTooFastCollection.addSeries(ascentTooFastSerie); renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningAscentTooFast()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_ASCENT_TOO_FAST_WARNING]); xyp.setDataset(i, ascentTooFastCollection); xyp.setRenderer(i, renderer2); i++; XYSeriesCollection decoWarningCollection = new XYSeriesCollection(); XYSeries decoWarningSerie = new XYSeries(SERIE_DECO_STOP); decoWarningCollection.addSeries(decoWarningSerie); renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningDecoCeiling()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_DECO_WARNING]); xyp.setDataset(i, decoWarningCollection); xyp.setRenderer(i, renderer2); i++; XYSeriesCollection remainBottomTimeCollection = new XYSeriesCollection(); XYSeries remainBottomTimeSerie = new XYSeries(SERIE_REMAINING_BOTTOM_TIME); remainBottomTimeCollection.addSeries(remainBottomTimeSerie); renderer2 = new XYLineAndShapeRenderer(); renderer2.setSeriesLinesVisible(0, false); renderer2.setAutoPopulateSeriesShape(false); renderer2.setSeriesPaint(0, UIAgent.getInstance().getColorWarningRemainingBottomTime()); renderer2.setBaseShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[SHAPE_REMAINING_BOTTOM_TIME_WARNING]); xyp.setDataset(i, remainBottomTimeCollection); xyp.setRenderer(i, renderer2); Map<Double, Double> depthEntries = diveProfile.getDepthEntries(); Set<Double> ascentWarning = diveProfile.getAscentWarnings(); Set<Double> decoWarnings = diveProfile.getDecoCeilingWarnings(); Set<Double> remainBottomTime = diveProfile.getRemainingBottomTimeWarnings(); Set<Double> decoEntryTime = diveProfile.getDecoEntries(); if (depthEntries.size() > 0 && depthEntries.get(0d) == null) { depthEntries.put(0d, 0d); } for (Double seconds : depthEntries.keySet()) { double d = UnitsAgent.getInstance().convertLengthFromModel(depthEntries.get(seconds), lengthUnit); depthSerie.add(seconds, Double.valueOf(d)); } if (null != ascentWarning) { for (Double seconds : ascentWarning) { ascentTooFastSerie.add(seconds, depthEntries.get(seconds)); } } if (null != decoWarnings) { for (Double seconds : decoWarnings) { decoWarningSerie.add(seconds, depthEntries.get(seconds)); } } if (null != remainBottomTime) { for (Double seconds : remainBottomTime) { remainBottomTimeSerie.add(seconds, depthEntries.get(seconds)); } } if (null != decoEntryTime) { for (Double seconds : decoEntryTime) { decoEntriesSerie.add(seconds, depthEntries.get(seconds)); } } return chart; }
From source file:edu.uci.ics.jung.visualization.decorators.GradientEdgePaintTransformer.java
public Paint transform(E e) { Layout<V, E> layout = vv.getGraphLayout(); Pair<V> p = layout.getGraph().getEndpoints(e); V b = p.getFirst();/* w w w .j ava 2 s .com*/ V f = p.getSecond(); Point2D pb = transformer.transform(layout.transform(b)); Point2D pf = transformer.transform(layout.transform(f)); float xB = (float) pb.getX(); float yB = (float) pb.getY(); float xF = (float) pf.getX(); float yF = (float) pf.getY(); if ((layout.getGraph().getEdgeType(e)) == EdgeType.UNDIRECTED) { xF = (xF + xB) / 2; yF = (yF + yB) / 2; } if (selfLoop.evaluate(Context.<Graph<V, E>, E>getInstance(layout.getGraph(), e))) { yF += 50; xF += 50; } return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true); }
From source file:uk.ac.ed.epcc.webapp.charts.jfreechart.JFreeChartData.java
private JFreeChart getCustomisedJFreeChart() { JFreeChart chart = getJFreeChart();/*from w ww. j a v a2 s .com*/ chart.getPlot().setBackgroundPaint( new GradientPaint(0.0f, 0.0F, new Color(0.75F, 0.75F, 1.0F), 0.0F, 100.0F, Color.white, false)); if (title != null && title.trim().length() > 0) { chart.setTitle(title); } return chart; }
From source file:Main.java
/** * Reads a <code>Paint</code> object that has been serialised by the * {@link SerialUtilities#writePaint(Paint, ObjectOutputStream)} method. * * @param stream the input stream (<code>null</code> not permitted). * * @return The paint object (possibly <code>null</code>). * * @throws IOException if there is an I/O problem. * @throws ClassNotFoundException if there is a problem loading a class. *///from ww w .j av a 2 s . c om public static Paint readPaint(final ObjectInputStream stream) throws IOException, ClassNotFoundException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } Paint result = null; final boolean isNull = stream.readBoolean(); if (!isNull) { final Class c = (Class) stream.readObject(); if (isSerializable(c)) { result = (Paint) stream.readObject(); } else if (c.equals(GradientPaint.class)) { final float x1 = stream.readFloat(); final float y1 = stream.readFloat(); final Color c1 = (Color) stream.readObject(); final float x2 = stream.readFloat(); final float y2 = stream.readFloat(); final Color c2 = (Color) stream.readObject(); final boolean isCyclic = stream.readBoolean(); result = new GradientPaint(x1, y1, c1, x2, y2, c2, isCyclic); } } return result; }
From source file:com.github.cmisbox.ui.BaseFrame.java
public BaseFrame() { super(AWTUtilitiesWrapper.isTranslucencyCapable(BaseFrame.gc) ? BaseFrame.gc : null); this.log = LogFactory.getLog(this.getClass()); this.gradient = false; this.setUndecorated(true); this.mainPanel = new JPanel(new GridBagLayout()) { private static final long serialVersionUID = 1035974033526970010L; protected void paintComponent(Graphics g) { if ((g instanceof Graphics2D) && BaseFrame.this.gradient) { final int R = 0; final int G = 0; final int B = 0; Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 192), this.getWidth(), this.getHeight(), new Color(R, G, B, 255), true); Graphics2D g2d = (Graphics2D) g; g2d.setPaint(p);//from w w w . ja v a2s . com g2d.fillRect(0, 0, this.getWidth(), this.getHeight()); } else { super.paintComponent(g); } } }; this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); GridBagConstraints gbc = new GridBagConstraints(); this.mainPanel.setDoubleBuffered(false); this.mainPanel.setOpaque(false); this.mainPanel.setBorder(BorderFactory.createLineBorder(Color.white)); JLabel title = new JLabel(this.getWindowTitle(), SwingConstants.CENTER); title.setForeground(Color.white); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 1; gbc.gridy = 0; gbc.weightx = 100; this.mainPanel.add(title, gbc); Image closeImg = this.getImage("images/application-exit.png", 32, 32); JLabel close = new JLabel(new ImageIcon(closeImg), SwingConstants.RIGHT); gbc.fill = GridBagConstraints.NONE; gbc.gridx = 2; gbc.weightx = 0; this.mainPanel.add(close, gbc); close.addMouseListener(this.closeAdapter); this.getContentPane().add(this.mainPanel, BorderLayout.CENTER); this.initComponents(); this.pack(); this.mainPanel.setOpaque(!this.gradient); if (!this.gradient) { this.mainPanel.setBackground(new Color(0, 0, 0, 208)); } this.setLocationRelativeTo(null); AWTUtilitiesWrapper.setWindowOpaque(this, false); this.setVisible(true); this.setAlwaysOnTop(true); }