List of usage examples for java.awt Graphics setColor
public abstract void setColor(Color c);
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFTZTimeColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*w w w . ja v a 2 s . co m*/ } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Calendar) { Calendar cal = (Calendar) value; str = CFLibXmlUtil.formatTZTime(cal); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, 4, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFTZTimestampColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from w ww . j a v a 2 s. c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Calendar) { Calendar cal = (Calendar) value; str = CFLibXmlUtil.formatTZTimestamp(cal); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, 4, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFUuidColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;// ww w.j a v a 2 s .co m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof UUID) { UUID uuid = (UUID) value; str = uuid.toString(); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, 4, leading + ascent + 4); } }
From source file:Sketch.java
public void actionPerformed(ActionEvent e) { // The button must have been pressed. Insets insets = board.getInsets(); Graphics g = board.getGraphics(); g.setColor(board.getBackground()); g.fillRect(insets.left, insets.top, board.getWidth() - insets.left - insets.right, board.getHeight() - insets.top - insets.bottom); }
From source file:Sketch.java
public void propertyChange(PropertyChangeEvent e) { if (e.getPropertyName() == "value") { Graphics g = board.getGraphics(); g.setColor(getForeground()); g.drawLine(lastX, lastY, shuttle1.getValue(), shuttle2.getValue()); lastX = shuttle1.getValue();// w w w .java2 s .co m lastY = shuttle2.getValue(); } }
From source file:RedBlueBox.java
public void paintComponent(Graphics g) { Insets insets = getInsets();/*from ww w . java 2s .co m*/ int endX = getWidth() - insets.right; int endY = getHeight() - insets.bottom; // get the top-left corner int x = insets.left; int y = insets.top; g.setColor(Color.RED); Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(endX, y); p.addPoint(x, endY); g.fillPolygon(p); g.setColor(Color.BLUE); p.reset(); p.addPoint(endX, y); p.addPoint(x, endY); p.addPoint(endX, endY); g.fillPolygon(p); }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFDateColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;//from www. ja va2 s .c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Calendar) { Calendar cal = (Calendar) value; Format fmt = getDefaultFormat(); str = fmt.format(cal.getTime()); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); g.drawString(firstLine, 4, leading + ascent + 4); } }
From source file:DiamondAbstractButtonStateIcon.java
public void paintIcon(Component component, Graphics g, int x, int y) { if (component instanceof AbstractButton) { AbstractButton abstractButton = (AbstractButton) component; boolean selected = abstractButton.isSelected(); if (selected) { g.setColor(Color.RED); } else {// ww w.ja v a2 s. c o m g.setColor(Color.BLUE); } g.drawRect(0, 0, 20, 20); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFInt16ColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;/*w w w . ja va2 s . co m*/ } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Short) { Short val = (Short) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }
From source file:net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.CFInt32ColumnCellRenderer.java
public void paint(Graphics g) { if (g == null) { return;// w w w. ja v a2 s .c o m } Rectangle bounds = getBounds(); g.setColor(getBackground()); g.fill3DRect(0, 0, bounds.width, bounds.height, true); g.setColor(getForeground()); String str; if (value instanceof Integer) { Integer val = (Integer) value; Format fmt = getDefaultFormat(); str = fmt.format(val); } else if (value instanceof String) { str = (String) value; } else { str = null; } if (str != null) { int firstNewline = str.indexOf('\n'); if (firstNewline < 0) { firstNewline = str.indexOf('\r'); if (firstNewline < 0) { firstNewline = str.indexOf('\f'); if (firstNewline < 0) { firstNewline = str.length(); } } } String firstLine = str.substring(0, firstNewline); FontMetrics fm = g.getFontMetrics(); int ascent = fm.getAscent(); int leading = fm.getLeading(); int width = fm.stringWidth(firstLine); int x = (bounds.width - 8) - width; g.drawString(firstLine, x, leading + ascent + 4); } }