001: /*
002: * @(#)${NAME}
003: *
004: * Copyright 2002 - 2004 JIDE Software Inc. All rights reserved.
005: */
006: package com.jidesoft.plaf.aqua;
007:
008: import apple.laf.AquaImageFactory;
009: import com.jidesoft.icons.IconsFactory;
010: import com.jidesoft.plaf.UIDefaultsLookup;
011: import com.jidesoft.plaf.basic.BasicPainter;
012: import com.jidesoft.plaf.basic.ThemePainter;
013: import com.jidesoft.swing.JideSwingUtilities;
014: import sun.java2d.SunGraphics2D;
015:
016: import javax.swing.*;
017: import java.awt.*;
018: import java.util.logging.Logger;
019:
020: /**
021: * Painter for Aqua style L&F.
022: * <p/>
023: * Please note, this class is an internal class which is meant to be used by other JIDE classes only.
024: * Future version might break your build if you use it.
025: */
026: public class AquaPainter extends BasicPainter {
027: private static final Logger LOGGER = Logger
028: .getLogger(AquaPainter.class.getName());
029:
030: private static AquaPainter _instance;
031: private final static ImageIcon SELECTED = IconsFactory
032: .getImageIcon(AquaPainter.class, "icons/selected.gif");
033: private final static ImageIcon ROLLOVER = IconsFactory
034: .getImageIcon(AquaPainter.class, "icons/rollover.gif");
035: private final static ImageIcon PRESSED = IconsFactory.getImageIcon(
036: AquaPainter.class, "icons/pressed.gif");
037: private final static Color ROLLOVER_BACKGROUND = new Color(238,
038: 238, 238);
039: private final static Color SELECTED_BACKGROUND = new Color(153,
040: 153, 153);
041: private final static Color PRESSED_BACKGROUND = new Color(195, 195,
042: 195);
043:
044: public static ThemePainter getInstance() {
045: if (_instance == null) {
046: _instance = new AquaPainter();
047: }
048: return _instance;
049: }
050:
051: public AquaPainter() {
052: }
053:
054: @Override
055: public Color getCommandBarTitleBarBackground() {
056: return UIDefaultsLookup.getColor("JideButton.background");
057: }
058:
059: @Override
060: public void paintButtonBackground(JComponent c, Graphics g,
061: Rectangle rect, int orientation, int state) {
062: if (state == STATE_DEFAULT) {
063: super .paintButtonBackground(c, g, rect, orientation, state);
064: } else if (state == STATE_ROLLOVER) {
065: paintImageBorder(g, rect, ROLLOVER, ROLLOVER_BACKGROUND);
066: } else if (state == STATE_SELECTED) {
067: paintImageBorder(g, rect, SELECTED, SELECTED_BACKGROUND);
068: } else if (state == STATE_PRESSED) {
069: paintImageBorder(g, rect, PRESSED, PRESSED_BACKGROUND);
070: }
071: }
072:
073: private void paintImageBorder(Graphics g, Rectangle rect,
074: ImageIcon icon, Color background) {
075: JideSwingUtilities.drawImageBorder(g, icon, rect, new Insets(3,
076: 3, 3, 3), false);
077:
078: if (background != null) {
079: Color oldColor = g.getColor();
080: g.setColor(background);
081: g.fillRect(rect.x + 3, rect.y + 3, rect.width - 6,
082: rect.height - 6);
083: g.setColor(oldColor);
084: }
085: }
086:
087: @Override
088: public void paintCollapsiblePaneTitlePaneBackgroundEmphasized(
089: JComponent c, Graphics g, Rectangle rect, int orientation,
090: int state) {
091: try {
092: AquaImageFactory.drawFrameTitleBackground(
093: (SunGraphics2D) g, rect.x, rect.y, rect.width,
094: rect.height, true, false, false);
095: } catch (Exception e) {
096: LOGGER.warning(e.getLocalizedMessage());
097: }
098: }
099:
100: @Override
101: public void paintCollapsiblePaneTitlePaneBackground(JComponent c,
102: Graphics g, Rectangle rect, int orientation, int state) {
103: try {
104: AquaImageFactory.drawFrameTitleBackground(
105: (SunGraphics2D) g, rect.x, rect.y, rect.width,
106: rect.height, false, false, false);
107: } catch (Exception e) {
108: LOGGER.warning(e.getLocalizedMessage());
109: }
110: }
111:
112: @Override
113: public void paintDockableFrameTitlePane(JComponent c, Graphics g,
114: Rectangle rect, int orientation, int state) {
115: try {
116: AquaImageFactory.drawFrameTitleBackground(
117: (SunGraphics2D) g, rect.x, rect.y, rect.width,
118: rect.height, state == STATE_SELECTED, false, false);
119: } catch (Exception e) {
120: LOGGER.warning(e.getLocalizedMessage());
121: }
122: }
123:
124: @Override
125: public void paintCommandBarTitlePane(JComponent c, Graphics g,
126: Rectangle rect, int orientation, int state) {
127: try {
128: AquaImageFactory.drawFrameTitleBackground(
129: (SunGraphics2D) g, rect.x, rect.y, rect.width,
130: rect.height, true, false, false);
131: } catch (Exception e) {
132: LOGGER.warning(e.getLocalizedMessage());
133: }
134: }
135: }
|