01: /*
02: * The contents of this file are subject to the Mozilla Public License
03: * Version 1.1 (the "License"); you may not use this file except in
04: * compliance with the License. You may obtain a copy of the License at
05: * http://www.mozilla.org/MPL/
06: *
07: * Software distributed under the License is distributed on an "AS IS"
08: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
09: * License for the specific language governing rights and limitations
10: * under the License.
11: *
12: * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
13: *
14: * The Initial Developer of the Original Code is iSQL-Viewer, A Mutli-Platform Database Tool.
15: * Portions created by Mark A. Kobold are Copyright (C) 2000-2007. All Rights Reserved.
16: *
17: * Contributor(s):
18: * Mark A. Kobold [mkobold <at> isqlviewer <dot> com].
19: *
20: * If you didn't download this code from the following link, you should check
21: * if you aren't using an obsolete version: http://www.isqlviewer.com
22: */
23: package org.isqlviewer.ui.dnd;
24:
25: import java.awt.Component;
26: import java.awt.HeadlessException;
27: import java.awt.dnd.DropTarget;
28: import java.awt.dnd.DropTargetDragEvent;
29: import java.awt.dnd.DropTargetEvent;
30: import java.awt.dnd.DropTargetListener;
31:
32: import javax.swing.JTabbedPane;
33: import javax.swing.plaf.TabbedPaneUI;
34:
35: import org.isqlviewer.swing.EnhancedTabbedPane;
36:
37: /**
38: * Enhanced Drop target for TabbedPanes.
39: * <p>
40: * Currently this drop target creates that dragOver tab / change selection effect. Not quite a spring loaded effect but
41: * effective for dragging something from one view to abother tabbed view
42: *
43: * @author Mark A. Kobold <mkobold at isqlviewer dot com>
44: * @version 1.0
45: */
46: public class TabbedPaneDropTarget extends DropTarget {
47:
48: private static final long serialVersionUID = 7669524130710371514L;
49: private final EnhancedTabbedPane pane;
50: private int currentDraggingIndex = -1;
51:
52: public TabbedPaneDropTarget(EnhancedTabbedPane pane, Component c,
53: DropTargetListener dtl) throws HeadlessException {
54:
55: super (c, dtl);
56: this .pane = pane;
57: }
58:
59: @Override
60: public synchronized void dragEnter(DropTargetDragEvent dtde) {
61:
62: TabbedPaneUI tabUI = this .pane.getUI();
63: JTabbedPane source = (JTabbedPane) getComponent();
64: int x = dtde.getLocation().x;
65: int y = dtde.getLocation().y;
66: int index = tabUI.tabForCoordinate(source, x, y);
67: if (index >= 0) {
68: source.setSelectedIndex(index);
69: currentDraggingIndex = index;
70: }
71: }
72:
73: @Override
74: public synchronized void dragExit(DropTargetEvent dte) {
75:
76: currentDraggingIndex = -1;
77: }
78:
79: @Override
80: public synchronized void dragOver(DropTargetDragEvent dtde) {
81:
82: TabbedPaneUI tabUI = this .pane.getUI();
83: JTabbedPane source = (JTabbedPane) getComponent();
84: int x = dtde.getLocation().x;
85: int y = dtde.getLocation().y;
86: int index = tabUI.tabForCoordinate(source, x, y);
87: if (index >= 0 && currentDraggingIndex != index) {
88: source.setSelectedIndex(index);
89: currentDraggingIndex = index;
90: }
91: }
92: }
|