001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
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 (at your option) 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,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: BaseContainer.java,v 1.13 2005/12/04 13:46:03 jesper Exp $
023: package net.infonode.gui.panel;
024:
025: import javax.swing.*;
026: import javax.swing.plaf.PanelUI;
027: import java.awt.*;
028:
029: public class BaseContainer extends JPanel {
030: private Color foreground;
031:
032: private Color background;
033:
034: private Font font;
035:
036: private Color overridedBackground;
037:
038: private Color overridedForeground;
039:
040: private Font overridedFont;
041:
042: private boolean forcedOpaque = true;
043:
044: private boolean opaque = true;
045:
046: private static PanelUI UI = new PanelUI() {
047: };
048:
049: public BaseContainer() {
050: this (true);
051: }
052:
053: public BaseContainer(boolean opaque) {
054: this (opaque, new BorderLayout());
055: }
056:
057: public BaseContainer(LayoutManager l) {
058: this (true, l);
059: }
060:
061: public BaseContainer(final boolean opaque, LayoutManager l) {
062: super (l);
063:
064: this .forcedOpaque = opaque;
065:
066: updateOpaque();
067: }
068:
069: public void setUI(PanelUI ui) {
070: Color oBackground = overridedBackground;
071: Color oForeground = overridedForeground;
072: Font oFont = overridedFont;
073:
074: oBackground = null;
075: oForeground = null;
076: oFont = null;
077:
078: setBackground(null);
079: setForeground(null);
080: setFont(null);
081:
082: super .setUI(ui);
083:
084: background = getBackground();
085: foreground = getForeground();
086: font = getFont();
087:
088: overridedBackground = oBackground;
089: overridedForeground = oForeground;
090: overridedFont = oFont;
091:
092: if (!forcedOpaque)
093: super .setUI(UI);
094:
095: updateBackground();
096: updateForeground();
097: updateFont();
098: }
099:
100: void setForcedOpaque(final boolean forcedOpaque) {
101: if (this .forcedOpaque != forcedOpaque) {
102: this .forcedOpaque = forcedOpaque;
103:
104: updateUI();
105: updateOpaque();
106: }
107: }
108:
109: // Overrided
110:
111: public void setOpaque(boolean opaque) {
112: this .opaque = opaque;
113:
114: updateOpaque();
115: }
116:
117: protected void paintComponent(Graphics g) {
118: if (forcedOpaque)
119: super .paintComponent(g);
120: }
121:
122: public void setForeground(Color fg) {
123: this .foreground = fg;
124:
125: updateForeground();
126: }
127:
128: public void setBackground(Color bg) {
129: this .background = bg;
130:
131: updateBackground();
132: }
133:
134: public void setFont(Font font) {
135: this .font = font;
136:
137: updateFont();
138: }
139:
140: void setOverridedForeround(Color fg) {
141: this .overridedForeground = fg;
142:
143: updateForeground();
144: }
145:
146: void setOverridedBackground(Color bg) {
147: this .overridedBackground = bg;
148:
149: updateBackground();
150: }
151:
152: void setOverrideFont(Font font) {
153: this .overridedFont = font;
154:
155: updateFont();
156: }
157:
158: private void updateBackground() {
159: super .setBackground(overridedBackground == null ? background
160: : overridedBackground);
161: }
162:
163: private void updateForeground() {
164: super .setForeground(overridedForeground == null ? foreground
165: : overridedForeground);
166: }
167:
168: private void updateFont() {
169: super .setFont(overridedFont == null ? font : overridedFont);
170: }
171:
172: private void updateOpaque() {
173: super.setOpaque(forcedOpaque ? opaque : forcedOpaque);
174: }
175: }
|