List of usage examples for java.awt Color Color
public Color(ColorSpace cspace, float[] components, float alpha)
From source file:Main.java
/** * Make the color brighter by the specified factor. * <p/>//from w ww . j a va2s .c o m * This code is adapted from java.awt.Color to take in a factor. * Therefore, it inherits its quirks. Most importantly, * a smaller factor makes the color more bright. * * @param c a color * @param factor the smaller the factor, the brighter. * @return a brighter color */ private static Color brighter(Color c, double factor) { int r = c.getRed(); int g = c.getGreen(); int b = c.getBlue(); /* From 2D group: * 1. black.brighter() should return grey * 2. applying brighter to blue will always return blue, brighter * 3. non pure color (non zero rgb) will eventually return white */ int i = (int) (1.0 / (1.0 - factor)); if (r == 0 && g == 0 && b == 0) { return new Color(i, i, i); } if (r > 0 && r < i) r = i; if (g > 0 && g < i) g = i; if (b > 0 && b < i) b = i; return new Color(Math.min((int) (r / factor), 255), Math.min((int) (g / factor), 255), Math.min((int) (b / factor), 255)); }
From source file:Main.java
/** * Converts a hexadecimal color to Color object * e.g. ff0000 will be converted to Color 255 0 0 * @param hex the hexadecimal color/*from w w w .j a va 2 s . c o m*/ * @return Color object of the hexadecimal value */ static Color hexToColor(final String hex) { final int hexColorDigitSize = 6; final int hexRadix = 16; final int hexRgbDigitSize = 2; final int redStartIndex = 0; final int greenStartIndex = 2; final int blueStartIndex = 4; if (hex == null || hex.length() != hexColorDigitSize) { throw new IllegalArgumentException("Invalid hex color value."); } int red = Integer.parseInt(hex.substring(redStartIndex, redStartIndex + hexRgbDigitSize), hexRadix); int green = Integer.parseInt(hex.substring(greenStartIndex, greenStartIndex + hexRgbDigitSize), hexRadix); int blue = Integer.parseInt(hex.substring(blueStartIndex, blueStartIndex + hexRgbDigitSize), hexRadix); return new Color(red, green, blue); }
From source file:Main.java
private static List<Color> buildPalette(int[] raw) { Preconditions.checkArgument(raw.length == 256 * 3); Color[] pal = new Color[256]; for (int i = 0; i < pal.length; i++) { pal[i] = new Color(raw[i * 3], raw[i * 3 + 1], raw[i * 3 + 2]); }/*w w w . j a v a 2s .c o m*/ return Collections.unmodifiableList(Arrays.asList(pal)); }
From source file:Main.java
public Main() { super(""); setSize(570, 400);//from w ww . jav a 2 s . co m getContentPane().setBackground(new Color(244, 232, 152)); getLayeredPane().setOpaque(true); JButton[] frames = new JButton[5]; for (int i = 0; i < 5; i++) { frames[i] = new JButton("InnerFrame " + i); frames[i].setBounds(50 + i * 20, 50 + i * 20, 200, 200); getLayeredPane().add(frames[i]); } super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); }
From source file:Main.java
public static Color getGradientRgbColor(float ratio, Color minColor, Color maxColor) { if (ratio < 0) ratio = 0.0F;// w w w . j ava2 s .c om if (ratio > 1.0) ratio = 1.0F; int red = (int) (maxColor.getRed() * ratio + minColor.getRed() * (1.0 - ratio)); int green = (int) (maxColor.getGreen() * ratio + minColor.getGreen() * (1 - ratio)); int blue = (int) (maxColor.getBlue() * ratio + minColor.getBlue() * (1 - ratio)); Color gradient = new Color(red, green, blue); return gradient; }
From source file:org.gumtree.vis.awt.DefaultChartTheme.java
public static Paint[] createDefaultPaintArray() { return new Paint[] { ChartColor.DARK_BLUE, ChartColor.DARK_GREEN, ChartColor.DARK_MAGENTA, ChartColor.DARK_CYAN, ChartColor.DARK_RED, ChartColor.DARK_YELLOW, Color.darkGray, new Color(0xFF, 0x55, 0x55), new Color(0x55, 0x55, 0xFF), new Color(0x00, 0x77, 0x00), new Color(0x77, 0x77, 0x00), new Color(0xCA, 0x00, 0xCA), new Color(0x00, 0x88, 0x88), // Color.pink, Color.gray,//w w w. jav a 2 s . c o m // ChartColor.LIGHT_RED, // ChartColor.LIGHT_BLUE, // ChartColor.LIGHT_GREEN, // ChartColor.LIGHT_YELLOW, // ChartColor.LIGHT_MAGENTA, // ChartColor.LIGHT_CYAN, // Color.lightGray, ChartColor.VERY_DARK_RED, ChartColor.VERY_DARK_BLUE, ChartColor.VERY_DARK_GREEN, ChartColor.VERY_DARK_YELLOW, ChartColor.VERY_DARK_MAGENTA, ChartColor.VERY_DARK_CYAN, ChartColor.VERY_LIGHT_RED, ChartColor.VERY_LIGHT_BLUE, ChartColor.VERY_LIGHT_GREEN, ChartColor.VERY_LIGHT_YELLOW, ChartColor.VERY_LIGHT_MAGENTA, ChartColor.VERY_LIGHT_CYAN }; }
From source file:Main.java
/** * Get the foreground color for the current UI. * @return The desired foreground color. *//*w ww. ja v a 2 s . c o m*/ public static Color getSelectionForegroundColor() { if (selectionForegroundColor != null) { return selectionForegroundColor; } //for windows selectionForegroundColor = (Color) Toolkit.getDefaultToolkit() .getDesktopProperty("win.item.highlightTextColor"); if (selectionForegroundColor == null) { selectionForegroundColor = UIManager.getColor("Table.selectionForeground"); if (selectionForegroundColor == null) { selectionForegroundColor = UIManager.getColor("Table[Enabled+Selected].textForeground"); if (selectionForegroundColor == null) { selectionForegroundColor = new JList().getSelectionForeground(); } } //sometimes the UIManager color won't work selectionForegroundColor = new Color(selectionForegroundColor.getRed(), selectionForegroundColor.getGreen(), selectionForegroundColor.getBlue()); } return selectionForegroundColor; }
From source file:st.jigasoft.dbutil.util.ReportTheme.java
public static void circularTheme(JFreeChart chart, String... colunsName) { chart.setBackgroundPaint(/*from w w w . ja v a2s . co m*/ new GradientPaint(new Point(0, 0), new Color(20, 20, 20), new Point(400, 200), Color.DARK_GRAY)); TextTitle t = chart.getTitle(); t.setHorizontalAlignment(HorizontalAlignment.LEFT); t.setPaint(new Color(240, 240, 240)); t.setFont(new Font("Arial", Font.BOLD, 26)); PiePlot plot = (PiePlot) chart.getPlot(); plot.setBackgroundPaint(null); plot.setInteriorGap(0.04); plot.setOutlineVisible(false); int iCount = 0; // use gradients and white borders for the section colours for (Object s : colunsName) { plot.setSectionPaint(s.toString(), createGradientPaint(new Color(200, 200, 255), colorItems(iCount++))); if (iCount == MAX_COLUNS_COLOR) iCount = 0; } plot.setBaseSectionOutlinePaint(Color.WHITE); plot.setSectionOutlinesVisible(true); plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f)); plot.setLabelFont(new Font("Courier New", Font.BOLD, 20)); plot.setLabelLinkPaint(Color.WHITE); plot.setLabelLinkStroke(new BasicStroke(2.0f)); plot.setLabelOutlineStroke(null); plot.setLabelPaint(Color.WHITE); plot.setLabelBackgroundPaint(null); // // add a subtitle giving the data source TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523", new Font("Courier New", Font.PLAIN, 12)); source.setPaint(Color.WHITE); source.setPosition(RectangleEdge.BOTTOM); source.setHorizontalAlignment(HorizontalAlignment.RIGHT); chart.addSubtitle(source); }
From source file:Rotate.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(150, 150, 150)); g2d.fillRect(20, 20, 80, 50);//from ww w. j a v a 2 s . com g2d.translate(180, -150); g2d.rotate(Math.PI / 4); g2d.fillRect(20, 20, 80, 50); }
From source file:Translation.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(150, 150, 150)); g2d.fillRect(20, 20, 80, 50);//from ww w. j a v a2 s .c o m g2d.translate(150, 50); g2d.fillRect(20, 20, 80, 50); }