001: // @@
002: // @@
003: /*
004: * Wi.Ser Framework
005: *
006: * LGPL Version: 1.8.1, 20-September-2007
007: * Copyright (C) 2005-2006 Dirk von der Weiden <dvdw@imail.de>
008: *
009: * This library is free software; you can redistribute it and/or
010: * modify it under the terms of the GNU Lesser General Public
011: * License as published by the Free Software Foundation; either
012: * version 2 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: * Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library located in LGPL.txt in the
021: * license directory; if not, write to the
022: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
023: * Boston, MA 02111-1307, USA.
024: *
025: * If this agreement does not cover your requirements, please contact us
026: * via email to get detailed information about the commercial license
027: * or our service offerings!
028: *
029: */
030: // @@
031: package de.ug2t.channel.ho.client.swing.enhanced;
032:
033: import java.awt.*;
034: import java.awt.event.*;
035: import java.util.*;
036:
037: import javax.swing.*;
038:
039: import de.ug2t.channel.ho.client.swing.*;
040:
041: public class EnhancedTabbedPane extends JTabbedPane {
042: private TreeMap pem_headers = null;
043:
044: private final MouseMotionListener pem_ml = new MouseMotionListener() {
045: private void pcmf_handle(MouseEvent e, boolean xDragged) {
046: int l_tab = ((EnhancedTabbedPaneUI) EnhancedTabbedPane.this
047: .getUI()).tabForCoordinate(EnhancedTabbedPane.this ,
048: e.getX(), e.getY());
049: Container l_cont = EnhancedTabbedPane.this
050: .pcmf_getTabComponent(l_tab);
051:
052: if (l_cont != null) {
053: JComponent l_comp = (JComponent) e.getSource();
054:
055: Rectangle l_trect = ((EnhancedTabbedPaneUI) EnhancedTabbedPane.this
056: .getUI()).getTabBounds(EnhancedTabbedPane.this ,
057: l_tab);
058: Insets l_ins = ((EnhancedTabbedPaneUI) EnhancedTabbedPane.this
059: .getUI()).pcmf_getTabInsets(l_tab);
060:
061: e.translatePoint(-(l_trect.x + l_ins.left),
062: -(l_trect.y + l_ins.top));
063: e.setSource(l_cont);
064:
065: if (l_cont.contains(e.getPoint())) {
066: MouseMotionListener l_listen[] = l_cont
067: .getMouseMotionListeners();
068: for (int i = 0; i < l_listen.length; i++) {
069: if (xDragged) {
070: l_listen[i].mouseDragged(e);
071: } else
072: l_listen[i].mouseMoved(e);
073: }
074: EnhancedTabbedPane.this .paintImmediately(l_trect);
075: }
076:
077: e.translatePoint((l_trect.x + l_ins.left),
078: (l_trect.y + l_ins.top));
079: e.setSource(l_comp);
080: }
081: return;
082: }
083:
084: public void mouseDragged(MouseEvent e) {
085: this .pcmf_handle(e, true);
086: }
087:
088: public void mouseMoved(MouseEvent e) {
089: this .pcmf_handle(e, false);
090: }
091: };
092:
093: private final MouseListener pem_mm = new HoMouseAdapter() {
094: private void pemf_handle(MouseEvent e, char xType) {
095: int l_tab = ((EnhancedTabbedPaneUI) EnhancedTabbedPane.this
096: .getUI()).tabForCoordinate(EnhancedTabbedPane.this ,
097: e.getX(), e.getY());
098: Container l_cont = EnhancedTabbedPane.this
099: .pcmf_getTabComponent(l_tab);
100:
101: if (l_cont != null) {
102: JComponent l_comp = (JComponent) e.getSource();
103:
104: Rectangle l_trect = ((EnhancedTabbedPaneUI) EnhancedTabbedPane.this
105: .getUI()).getTabBounds(EnhancedTabbedPane.this ,
106: l_tab);
107: Insets l_ins = ((EnhancedTabbedPaneUI) EnhancedTabbedPane.this
108: .getUI()).pcmf_getTabInsets(l_tab);
109:
110: e.translatePoint(-(l_trect.x + l_ins.left),
111: -(l_trect.y + l_ins.top));
112: e.setSource(l_cont);
113:
114: if (xType == HoSwingMouseEventDispatcher.MOUSE_PRESSED
115: || xType == HoSwingMouseEventDispatcher.MOUSE_RELEASED)
116: l_comp.requestFocusInWindow();
117:
118: HoSwingMouseEventDispatcher.pcmf_dispatch(e, xType,
119: l_cont);
120:
121: EnhancedTabbedPane.this .paintImmediately(l_trect);
122: e.translatePoint((l_trect.x + l_ins.left),
123: (l_trect.y + l_ins.top));
124: e.setSource(l_comp);
125: }
126: return;
127: }
128:
129: public void mouseClicked(MouseEvent e) {
130: this .pemf_handle(e,
131: HoSwingMouseEventDispatcher.MOUSE_CLICKED);
132: }
133:
134: public void mousePressed(MouseEvent e) {
135: this .pemf_handle(e,
136: HoSwingMouseEventDispatcher.MOUSE_PRESSED);
137: }
138:
139: public void mouseReleased(MouseEvent e) {
140: this .pemf_handle(e,
141: HoSwingMouseEventDispatcher.MOUSE_RELEASED);
142: }
143:
144: public void mouseEntered(MouseEvent e) {
145: this .pemf_handle(e,
146: HoSwingMouseEventDispatcher.MOUSE_ENTERED);
147: }
148:
149: public void mouseExited(MouseEvent e) {
150: this .pemf_handle(e,
151: HoSwingMouseEventDispatcher.MOUSE_EXITED);
152: }
153: };
154:
155: public void pcmf_reorgTabComponents() {
156: if (this .pem_headers == null)
157: return;
158:
159: TreeMap l_new = new TreeMap();
160: Iterator l_it = this .pem_headers.values().iterator();
161: int i = 0;
162: while (l_it.hasNext())
163: l_new.put(new Integer(i++), l_it.next());
164:
165: this .pem_headers = l_new;
166: }
167:
168: public void pcmf_setTabComponent(int xIdx, Container xCont) {
169: if (xCont instanceof JComponent)
170: ((JComponent) xCont).setDoubleBuffered(false);
171:
172: if (this .pem_headers == null)
173: this .pem_headers = new TreeMap();
174:
175: this .pem_headers.put(new Integer(xIdx), xCont);
176: HoSwingClient.pcm_vPanel.add(xCont);
177: }
178:
179: public Container pcmf_removeTabComponent(int xIdx) {
180: if (this .pem_headers == null)
181: return (null);
182:
183: Container l_ret = (Container) this .pem_headers
184: .remove(new Integer(xIdx));
185: if (this .pem_headers.size() == 0)
186: this .pem_headers = null;
187:
188: HoSwingClient.pcm_vPanel.remove(l_ret);
189:
190: return (l_ret);
191: }
192:
193: public Container pcmf_getTabComponent(int xIdx) {
194: if (this .pem_headers == null)
195: return (null);
196: else
197: return ((Container) this .pem_headers.get(new Integer(xIdx)));
198: }
199:
200: public EnhancedTabbedPane() {
201: super ();
202: this .setUI(new EnhancedTabbedPaneUI());
203: this .addMouseListener(this .pem_mm);
204: this .addMouseMotionListener(this .pem_ml);
205: }
206:
207: public EnhancedTabbedPane(int tabPlacement, int tabLayoutPolicy) {
208: super (tabPlacement, tabLayoutPolicy);
209: this .setUI(new EnhancedTabbedPaneUI());
210: this .addMouseListener(this .pem_mm);
211: this .addMouseMotionListener(this .pem_ml);
212: }
213:
214: public EnhancedTabbedPane(int tabPlacement) {
215: super (tabPlacement);
216: this .setUI(new EnhancedTabbedPaneUI());
217: this .addMouseListener(this .pem_mm);
218: this .addMouseMotionListener(this .pem_ml);
219: }
220:
221: public void pcmf_cleanup() {
222: if (this .pem_headers == null)
223: return;
224:
225: Iterator l_it = this .pem_headers.values().iterator();
226: while (l_it.hasNext())
227: HoSwingClient.pcm_vPanel.remove((Container) l_it.next());
228: }
229: }
|