001: /*
002: * Copyright (C) 2005 - 2008 JasperSoft Corporation. All rights reserved.
003: * http://www.jaspersoft.com.
004: *
005: * Unless you have purchased a commercial license agreement from JasperSoft,
006: * the following license terms apply:
007: *
008: * This program is free software; you can redistribute it and/or modify
009: * it under the terms of the GNU General Public License version 2 as published by
010: * the Free Software Foundation.
011: *
012: * This program is distributed WITHOUT ANY WARRANTY; and without the
013: * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
014: * See the 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, see http://www.gnu.org/licenses/gpl.txt
018: * or write to:
019: *
020: * Free Software Foundation, Inc.,
021: * 59 Temple Place - Suite 330,
022: * Boston, MA USA 02111-1307
023: *
024: *
025: *
026: *
027: * JDragTable.java
028: *
029: * Created on 14 novembre 2003, 0.43
030: *
031: */
032:
033: package it.businesslogic.ireport.gui.table;
034:
035: import java.awt.dnd.*;
036: import it.businesslogic.ireport.*;
037: import it.businesslogic.ireport.gui.dnd.*;
038: import java.awt.datatransfer.*;
039: import org.jdesktop.swingx.decorator.SortController;
040: import org.jdesktop.swingx.decorator.SortOrder;
041: import org.jdesktop.swingx.table.TableColumnExt;
042:
043: /**
044: *
045: * @author Administrator
046: */
047: public class JDragTable extends org.jdesktop.swingx.JXTable implements
048: DragGestureListener, DragSourceListener {
049:
050: public JDragTable() {
051:
052: super ();
053:
054: DragSource dragSource = DragSource.getDefaultDragSource();
055:
056: // creating the recognizer is all that's necessary - it
057: // does not need to be manipulated after creation
058: dragSource.createDefaultDragGestureRecognizer(this , // component where drag originates
059: DnDConstants.ACTION_COPY, // actions
060: this ); // drag gesture listener
061:
062: setColumnControlVisible(true);
063:
064: }
065:
066: public void dragGestureRecognized(DragGestureEvent e) {
067: // drag anything ...
068:
069: TransferableObject to = new TransferableObject(this .getValueAt(
070: this .getSelectedRow(), this .getSelectedColumn()));
071:
072: try {
073: if (to != null)
074: e.startDrag(DragSource.DefaultCopyDrop, // cursor
075: to); //, // transferable
076: //this); // drag source listener
077: } catch (Exception ex) {
078:
079: ex.printStackTrace();
080:
081: }
082:
083: }
084:
085: public void dragDropEnd(DragSourceDropEvent e) {
086: }
087:
088: public void dragEnter(DragSourceDragEvent e) {
089: }
090:
091: public void dragExit(DragSourceEvent e) {
092: }
093:
094: public void dragOver(DragSourceDragEvent e) {
095: }
096:
097: public void dropActionChanged(DragSourceDragEvent e) {
098: }
099:
100: public void toggleSortOrder(int columnIndex) {
101: super .toggleSortOrder(columnIndex);
102:
103: int index = convertColumnIndexToModel(columnIndex);
104: SortOrder so = SortOrder.UNSORTED;
105: SortController sortController = getSortController();
106: if (sortController != null) {
107: so = sortController.getSortOrder(index);
108: }
109:
110: fireSortChangedListenerSortChanged(new SortChangedEvent(this ,
111: index, so));
112: }
113:
114: public void toggleSortOrder(Object identifier) {
115: super .toggleSortOrder(identifier);
116:
117: TableColumnExt columnExt = getColumnExt(identifier);
118: int index = columnExt.getModelIndex();
119:
120: SortOrder so = SortOrder.UNSORTED;
121: SortController sortController = getSortController();
122: if (sortController != null) {
123: so = sortController.getSortOrder(index);
124: }
125:
126: fireSortChangedListenerSortChanged(new SortChangedEvent(this ,
127: index, so));
128: }
129:
130: public void setSortOrder(Object identifier, SortOrder arg1) {
131: super .setSortOrder(identifier, arg1);
132:
133: TableColumnExt columnExt = getColumnExt(identifier);
134: int index = columnExt.getModelIndex();
135:
136: SortOrder so = SortOrder.UNSORTED;
137: SortController sortController = getSortController();
138: if (sortController != null) {
139: so = sortController.getSortOrder(index);
140: }
141:
142: fireSortChangedListenerSortChanged(new SortChangedEvent(this ,
143: index, so));
144: }
145:
146: public void resetSortOrder() {
147: super .resetSortOrder();
148:
149: fireSortChangedListenerSortChanged(new SortChangedEvent(this ,
150: -1, SortOrder.UNSORTED));
151: }
152:
153: /**
154: * Utility field used by event firing mechanism.
155: */
156: private javax.swing.event.EventListenerList listenerList = null;
157:
158: /**
159: * Registers TabPaneChangedListener to receive events.
160: * @param listener The listener to register.
161: */
162: public synchronized void addSortChangedListener(
163: SortChangedListener listener) {
164:
165: if (listenerList == null) {
166: listenerList = new javax.swing.event.EventListenerList();
167: }
168: listenerList.add(SortChangedListener.class, listener);
169: }
170:
171: /**
172: * Removes TabPaneChangedListener from the list of listeners.
173: * @param listener The listener to remove.
174: */
175: public synchronized void removeSortChangedListener(
176: SortChangedListener listener) {
177:
178: listenerList.remove(SortChangedListener.class, listener);
179: }
180:
181: /**
182: * Notifies all registered listeners about the event.
183: *
184: * @param event The event to be fired
185: */
186: private void fireSortChangedListenerSortChanged(
187: SortChangedEvent event) {
188:
189: if (listenerList == null)
190: return;
191: Object[] listeners = listenerList.getListenerList();
192: for (int i = listeners.length - 2; i >= 0; i -= 2) {
193: if (listeners[i] == SortChangedListener.class) {
194: ((SortChangedListener) listeners[i + 1])
195: .sortChanged(event);
196: }
197: }
198: }
199: }
|