001: /*
002: * WbTabbedPane.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.components;
013:
014: import java.awt.Cursor;
015: import java.awt.Font;
016: import java.awt.FontMetrics;
017: import java.awt.Insets;
018: import java.awt.Insets;
019: import java.awt.dnd.DragSource;
020: import java.awt.event.MouseEvent;
021: import java.awt.event.MouseListener;
022: import java.awt.event.MouseMotionListener;
023: import javax.swing.JTabbedPane;
024: import javax.swing.JToolTip;
025: import javax.swing.UIManager;
026: import javax.swing.plaf.TabbedPaneUI;
027: import workbench.gui.WbSwingUtilities;
028: import workbench.interfaces.Moveable;
029: import workbench.log.LogMgr;
030:
031: /**
032: *
033: * @author support@sql-workbench.net
034: */
035: public class WbTabbedPane extends JTabbedPane implements MouseListener,
036: MouseMotionListener {
037: private Moveable tabMover;
038: private int draggedTabIndex;
039:
040: public WbTabbedPane() {
041: super ();
042: init();
043: }
044:
045: public int getTabHeight() {
046: Font font = getFont();
047: if (font == null)
048: return 0;
049: FontMetrics metrics = getFontMetrics(font);
050: if (metrics == null)
051: return 0;
052: int fontHeight = metrics.getHeight();
053: Insets tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
054: if (tabInsets != null) {
055: fontHeight += tabInsets.top + tabInsets.bottom + 2;
056: }
057: return fontHeight + 5;
058: }
059:
060: public WbTabbedPane(int placement) {
061: super (placement);
062: init();
063: }
064:
065: public JToolTip createToolTip() {
066: JToolTip tip = new MultiLineToolTip();
067: tip.setComponent(this );
068: return tip;
069: }
070:
071: private void init() {
072: // For use with the jGoodies Plastic look & feel
073: this
074: .putClientProperty("jgoodies.noContentBorder",
075: Boolean.TRUE);
076: try {
077: TabbedPaneUI tui = TabbedPaneUIFactory.getBorderLessUI();
078: if (tui != null)
079: this .setUI(tui);
080: } catch (Exception e) {
081: LogMgr.logError("WbTabbedPane.init()", "Error during init",
082: e);
083: }
084: this .setBorder(WbSwingUtilities.EMPTY_BORDER);
085: }
086:
087: public Insets getInsets() {
088: return new Insets(0, 0, 0, 0);
089: }
090:
091: public void fireStateChanged() {
092: super .fireStateChanged();
093: }
094:
095: @Override
096: @SuppressWarnings("deprecation")
097: public boolean isManagingFocus() {
098: return false;
099: }
100:
101: @Override
102: public boolean isRequestFocusEnabled() {
103: return false;
104: }
105:
106: @Override
107: @SuppressWarnings("deprecation")
108: public boolean isFocusTraversable() {
109: return false;
110: }
111:
112: @Override
113: public boolean isFocusable() {
114: return false;
115: }
116:
117: public void disableDragDropReordering() {
118: this .removeMouseListener(this );
119: this .removeMouseMotionListener(this );
120: this .tabMover = null;
121: draggedTabIndex = -1;
122: }
123:
124: public void enableDragDropReordering(Moveable mover) {
125: this .addMouseListener(this );
126: this .addMouseMotionListener(this );
127: this .tabMover = mover;
128: draggedTabIndex = -1;
129: }
130:
131: public void mouseClicked(MouseEvent e) {
132: }
133:
134: public void mousePressed(MouseEvent e) {
135: draggedTabIndex = getUI().tabForCoordinate(this , e.getX(),
136: e.getY());
137: }
138:
139: public void mouseReleased(MouseEvent e) {
140: draggedTabIndex = -1;
141: setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
142: }
143:
144: public void mouseEntered(MouseEvent e) {
145: }
146:
147: public void mouseExited(MouseEvent e) {
148: }
149:
150: public void mouseDragged(MouseEvent e) {
151: if (tabMover == null)
152: return;
153: if (draggedTabIndex == -1)
154: return;
155:
156: int newIndex = getUI().tabForCoordinate(this , e.getX(),
157: e.getY());
158:
159: if (newIndex != -1 && newIndex != draggedTabIndex) {
160: setCursor(DragSource.DefaultMoveDrop);
161: tabMover.moveTab(draggedTabIndex, newIndex);
162: draggedTabIndex = newIndex;
163: }
164: }
165:
166: public void mouseMoved(MouseEvent e) {
167: }
168:
169: }
|