001: /*
002: * AbstractToolBarPanel.java
003: *
004: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021:
022: package org.underworldlabs.swing.toolbar;
023:
024: import java.awt.Color;
025: import java.awt.FlowLayout;
026: import java.awt.GradientPaint;
027: import java.awt.Graphics;
028: import java.awt.Graphics2D;
029: import java.awt.LayoutManager;
030: import java.awt.Paint;
031: import javax.swing.JPanel;
032: import org.underworldlabs.swing.plaf.UIUtils;
033:
034: /* ----------------------------------------------------------
035: * CVS NOTE: Changes to the CVS repository prior to the
036: * release of version 3.0.0beta1 has meant a
037: * resetting of CVS revision numbers.
038: * ----------------------------------------------------------
039: */
040:
041: /**
042: * Base tool bar panel that paints its own gradient
043: * background where the look and feel is the EQ default.
044: *
045: * @author Takis Diakoumis
046: * @version $Revision: 1.5 $
047: * @date $Date: 2006/07/15 12:51:15 $
048: */
049: public abstract class AbstractToolBarPanel extends JPanel {
050:
051: /** the light gradient colour 1 */
052: private Color colour1;
053:
054: /** the dark gradient colour 2 */
055: private Color colour2;
056:
057: /** whether to fill a gradient background */
058: private boolean fillGradient;
059:
060: /**
061: * Creates a new panel with a double buffer and a flow layout.
062: */
063: public AbstractToolBarPanel() {
064: this (true);
065: }
066:
067: /**
068: * Creates a new panel with <code>FlowLayout</code>
069: * and the specified buffering strategy.
070: * If <code>isDoubleBuffered</code> is true, the <code>JPanel</code>
071: * will use a double buffer.
072: *
073: * @param isDoubleBuffered a boolean, true for double-buffering, which
074: * uses additional memory space to achieve fast, flicker-free
075: * updates
076: */
077: public AbstractToolBarPanel(boolean isDoubleBuffered) {
078: this (new FlowLayout(), isDoubleBuffered);
079: }
080:
081: /**
082: * Create a new buffered panel with the specified layout manager
083: *
084: * @param layout the LayoutManager to use
085: */
086: public AbstractToolBarPanel(LayoutManager layout) {
087: this (layout, true);
088: }
089:
090: /**
091: * Creates a new panel with the specified layout manager and buffering
092: * strategy.
093: *
094: * @param layout the LayoutManager to use
095: * @param isDoubleBuffered a boolean, true for double-buffering, which
096: * uses additional memory space to achieve fast, flicker-free
097: * updates
098: */
099: public AbstractToolBarPanel(LayoutManager layout,
100: boolean isDoubleBuffered) {
101: super (layout, isDoubleBuffered);
102: fillGradient = UIUtils.isDefaultLookAndFeel()
103: || UIUtils.usingOcean();
104: if (fillGradient) {
105: colour1 = getBackground();
106: colour2 = UIUtils.getDarker(colour1, 0.85);
107: }
108: }
109:
110: public boolean isOpaque() {
111: return !fillGradient;
112: }
113:
114: public void paintComponent(Graphics g) {
115: if (fillGradient) {
116: int width = getWidth();
117: int height = getHeight();
118:
119: Graphics2D g2 = (Graphics2D) g;
120: Paint originalPaint = g2.getPaint();
121: GradientPaint fade = new GradientPaint(0, height, colour2,
122: 0, (int) (height * 0.5), colour1);
123:
124: g2.setPaint(fade);
125: g2.fillRect(0, 0, width, height);
126:
127: g2.setPaint(originalPaint);
128: }
129: super.paintComponent(g);
130: }
131:
132: }
|