List of usage examples for java.awt LinearGradientPaint LinearGradientPaint
public LinearGradientPaint(Point2D start, Point2D end, float[] fractions, Color[] colors)
From source file:Main.java
private static int[] makeGradientPallet() { BufferedImage image = new BufferedImage(100, 1, BufferedImage.TYPE_INT_RGB); Graphics2D g2 = image.createGraphics(); Point2D start = new Point2D.Float(0f, 0f); Point2D end = new Point2D.Float(99f, 0f); float[] dist = { 0.0f, 0.5f, 1.0f }; Color[] colors = { Color.RED, Color.YELLOW, Color.GREEN }; g2.setPaint(new LinearGradientPaint(start, end, dist, colors)); g2.fillRect(0, 0, 100, 1);//from w w w.j a v a2 s. c o m g2.dispose(); int width = image.getWidth(null); int[] pallet = new int[width]; PixelGrabber pg = new PixelGrabber(image, 0, 0, width, 1, pallet, 0, width); try { pg.grabPixels(); } catch (Exception e) { e.printStackTrace(); } return pallet; }
From source file:org.adempiere.webui.apps.graph.jfreegraph.PerformanceGraphBuilder.java
public JFreeChart createIndicatorChart(IndicatorModel model) { JFreeChart chart = null;//from w ww. j a v a 2 s . co m DefaultValueDataset data = new DefaultValueDataset((float) model.goalModel.getPercent()); MeterPlot plot = new MeterPlot(data); MColorSchema colorSchema = model.goalModel.getColorSchema(); int rangeLo = 0; int rangeHi = 0; Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float(50, 50); float[] dist = { 0.0f, 0.2f, 0.45f, 0.75f, 1.0f }; for (int i = 1; i <= 4; i++) { switch (i) { case 1: rangeHi = colorSchema.getMark1Percent(); break; case 2: rangeHi = colorSchema.getMark2Percent(); break; case 3: rangeHi = colorSchema.getMark3Percent(); break; case 4: rangeHi = colorSchema.getMark4Percent(); break; } if (rangeHi == 9999) rangeHi = (int) Math.floor(rangeLo * 1.5); if (rangeLo < rangeHi) { Color[] colors = { colorSchema.getColor(rangeHi).brighter().brighter(), colorSchema.getColor(rangeHi).brighter(), colorSchema.getColor(rangeHi), colorSchema.getColor(rangeHi).darker(), colorSchema.getColor(rangeHi).darker().darker() }; LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors); plot.addInterval(new MeterInterval("Normal", //label new Range(rangeLo, rangeHi), //range p, new BasicStroke(7.0f), model.dialBackground)); rangeLo = rangeHi; } } plot.setRange(new Range(0, rangeLo)); plot.setDialBackgroundPaint(model.dialBackground); plot.setUnits(""); plot.setDialShape(DialShape.CHORD); plot.setNeedlePaint(model.needleColor); plot.setTickSize(2000); plot.setTickLabelFont(new Font("SansSerif", Font.BOLD, 8)); plot.setValueFont(new Font("SansSerif", Font.BOLD, 8)); plot.setNoDataMessageFont(new Font("SansSerif", Font.BOLD, 8)); plot.setTickLabelPaint(model.tickColor); plot.setValuePaint(new Color(0.0f, 0.0f, 0.0f, 0.0f)); plot.setTickPaint(model.tickColor); // chart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 9), plot, false); return chart; }
From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java
/** * @param g2 graphics2D object//from ww w. j a v a 2 s . c om */ private static void plotColorScaleBar(Graphics2D g2) { // calculate color scale bar dimensions & location Point csBarTL = new Point(heatmapWidth + colorScaleHorizontalMargin, colorScaleVerticalMargin); Point csBarBL = new Point(heatmapWidth + colorScaleHorizontalMargin, fullHeight - colorScaleVerticalMargin); Rectangle csBar = new Rectangle(csBarTL.x, csBarTL.y, colorScaleWidth - 2 * colorScaleHorizontalMargin, fullHeight - 2 * colorScaleVerticalMargin); // plot the color scale linear gradient LinearGradientPaint gradient = new LinearGradientPaint(csBarTL, csBarBL, gradientFractions, gradientColors); g2.setPaint(gradient); g2.fill(csBar); // plot a border around color scale g2.setColor(Color.black); g2.drawRect(csBar.x, csBar.y, csBar.width, csBar.height); }
From source file:org.ietr.preesm.mapper.ui.GanttPlotter.java
public static LinearGradientPaint getBackgroundColorGradient() { Point2D start = new Point2D.Float(0, 0); Point2D end = new Point2D.Float(500, 500); float[] dist = { 0.0f, 0.8f }; Color[] colors = { new Color(170, 160, 190), Color.WHITE }; LinearGradientPaint p = new LinearGradientPaint(start, end, dist, colors); return p;//from w w w. j a v a 2 s. com }
From source file:be.ac.ua.comp.scarletnebula.gui.ServerCellRenderer.java
private JPanel createServerPanel(final Server server, final JList list, final int index, final boolean isSelected) { final JXPanel p = new JXPanel(); p.setLayout(new GridBagLayout()); final Color background = Colors.alpha(getBackgroundColor(list, index, isSelected), 0.4f); p.setBackground(background);//from ww w. ja va 2s .c o m Color color1 = Colors.White.color(0.5f); Color color2 = Colors.Gray.color(0.95f); final Point2D start = new Point2D.Float(0, 0); Point2D stop = new Point2D.Float(150, 500); if (server != null && !server.sshWillFail() && server.getServerStatistics() != null) { final ServerStatisticsManager manager = server.getServerStatistics(); final Datastream.WarnLevel warnlevel = manager.getHighestWarnLevel(); if (warnlevel == Datastream.WarnLevel.HIGH) { color1 = Colors.Red.alpha(0.2f); color2 = Colors.Red.alpha(0.8f); stop = new Point2D.Float(500, 2); } else if (warnlevel == Datastream.WarnLevel.MEDIUM) { color1 = Colors.Orange.alpha(0.3f); color2 = Colors.Orange.alpha(0.8f); stop = new Point2D.Float(500, 2); } else if (warnlevel == Datastream.WarnLevel.LOW) { color1 = Colors.Orange.alpha(0.2f); color2 = Colors.Orange.alpha(0.4f); stop = new Point2D.Float(500, 2); } } final LinearGradientPaint gradientPaint = new LinearGradientPaint(start, stop, new float[] { 0.0f, 1.0f }, new Color[] { color1, color2 }); final MattePainter mattePainter = new MattePainter(gradientPaint, true); p.setBackgroundPainter(mattePainter); if (isSelected) { p.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(UIManager.getColor("List.background"), 2), BorderFactory.createBevelBorder(BevelBorder.LOWERED))); } else { p.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder(UIManager.getColor("List.background"), 2), BorderFactory.createEtchedBorder())); } return p; }