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: PanePainter.java,v 1.11 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel.theme.internal.laftheme;
024:
025: import net.infonode.util.Direction;
026:
027: import javax.swing.*;
028: import java.awt.*;
029: import java.awt.event.FocusEvent;
030: import java.awt.event.MouseEvent;
031: import java.awt.event.MouseWheelEvent;
032:
033: class PanePainter extends JTabbedPane {
034: private boolean mouseEntered = false;
035:
036: private boolean focusActive = false;
037:
038: private boolean useMouseEnterExit = false;
039:
040: private Direction direction;
041:
042: PanePainter(Direction d) {
043: setTabPlacement(d);
044: setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
045:
046: useMouseEnterExit = UIManager.getLookAndFeel().getClass()
047: .getName().indexOf(".LiquidLookAndFeel") > -1;
048:
049: if (!useMouseEnterExit)
050: super .processMouseEvent(new MouseEvent(this ,
051: MouseEvent.MOUSE_ENTERED, System
052: .currentTimeMillis(), 0, 0, 0, 0, false));
053: }
054:
055: void setTabAreaEntered(boolean entered) {
056: if (entered)
057: super .processMouseEvent(new MouseEvent(this ,
058: MouseEvent.MOUSE_ENTERED, System
059: .currentTimeMillis(), 0, 0, 0, 0, false));
060: else
061: super .processMouseEvent(new MouseEvent(this ,
062: MouseEvent.MOUSE_EXITED,
063: System.currentTimeMillis(), 0, -1, -1, 0, false));
064: }
065:
066: private void setTabPlacement(Direction d) {
067: this .direction = d;
068:
069: if (d == Direction.UP)
070: setTabPlacement(JTabbedPane.TOP);
071: else if (d == Direction.LEFT)
072: setTabPlacement(JTabbedPane.LEFT);
073: else if (d == Direction.RIGHT)
074: setTabPlacement(JTabbedPane.RIGHT);
075: else
076: setTabPlacement(JTabbedPane.BOTTOM);
077: }
078:
079: void setMouseEntered(boolean entered) {
080: if (useMouseEnterExit) {
081: if (entered && !mouseEntered) {
082: super
083: .processMouseEvent(new MouseEvent(this ,
084: MouseEvent.MOUSE_ENTERED, System
085: .currentTimeMillis(), 0, 0, 0,
086: 0, false));
087: } else if (!entered && mouseEntered) {
088: super .processMouseEvent(new MouseEvent(this ,
089: MouseEvent.MOUSE_EXITED, System
090: .currentTimeMillis(), 0, -1, -1, 0,
091: false));
092: }
093: } else {
094: if (!entered && mouseEntered) {
095: super .processMouseMotionEvent(new MouseEvent(this ,
096: MouseEvent.MOUSE_MOVED, System
097: .currentTimeMillis(), 0, -1, -1, 0,
098: false));
099: }
100: }
101:
102: mouseEntered = entered;
103: }
104:
105: void setHoveredTab(int index) {
106: if (index > -1 && index < getTabCount()) {
107: Rectangle hoverBounds = getBoundsAt(index);
108: int xPos = hoverBounds.x + hoverBounds.width / 2;
109: int yPos = hoverBounds.y + hoverBounds.height / 2;
110:
111: super .processMouseMotionEvent(new MouseEvent(this ,
112: MouseEvent.MOUSE_MOVED, System.currentTimeMillis(),
113: 0, xPos, yPos, 0, false));
114: }
115: }
116:
117: void setFocusActive(boolean active) {
118: if (active && !focusActive)
119: super .processFocusEvent(new FocusEvent(this ,
120: FocusEvent.FOCUS_GAINED));
121: else if (!active && focusActive)
122: super .processFocusEvent(new FocusEvent(this ,
123: FocusEvent.FOCUS_LOST));
124:
125: focusActive = active;
126: }
127:
128: Direction getDirection() {
129: return direction;
130: }
131:
132: void doValidation() {
133: Component c = this ;
134: while (c != null) {
135: c.invalidate();
136: c = c.getParent();
137: }
138: validate();
139: }
140:
141: void removeAllTabs() {
142: removeAll();
143: doValidation();
144: }
145:
146: public Font getFont() {
147: Font font = UIManager.getFont("TabbedPane.font");
148: return font == null ? super .getFont() : font;
149: }
150:
151: public void updateUI() {
152: setBorder(null);
153: setBackground(null);
154: setForeground(null);
155: setOpaque(false);
156:
157: super .updateUI();
158:
159: setTabLayoutPolicy(WRAP_TAB_LAYOUT);
160:
161: useMouseEnterExit = UIManager.getLookAndFeel().getClass()
162: .getName().indexOf(".LiquidLookAndFeel") > -1;
163:
164: if (!useMouseEnterExit)
165: super .processMouseEvent(new MouseEvent(this ,
166: MouseEvent.MOUSE_ENTERED, System
167: .currentTimeMillis(), 0, 0, 0, 0, false));
168: }
169:
170: public boolean hasFocus() {
171: return focusActive;
172: }
173:
174: public void repaint() {
175: }
176:
177: public void repaint(long tm, int x, int y, int width, int height) {
178: }
179:
180: void paint(Graphics g, int tx, int ty) {
181: Rectangle clip = g.getClipBounds();
182:
183: if (clip != null && clip.x == 0 && clip.y == 0
184: && clip.width == 0 && clip.height == 0) {
185: return;
186: }
187:
188: g.translate(tx, ty);
189: update(g);
190: g.translate(-tx, -ty);
191: }
192:
193: protected void processMouseEvent(MouseEvent e) {
194: }
195:
196: protected void processMouseMotionEvent(MouseEvent e) {
197: }
198:
199: protected void processFocusEvent(FocusEvent e) {
200: }
201:
202: protected void processMouseWheelEvent(MouseWheelEvent e) {
203: }
204: }
|