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: * JTableFrame.java
028: *
029: * Created on 20 maggio 2003, 20.20
030: *
031: */
032:
033: package it.businesslogic.ireport.gui;
034:
035: import javax.swing.*;
036: import java.util.*;
037: import java.awt.dnd.*;
038: import java.awt.event.*;
039: import javax.swing.table.*;
040:
041: /**
042: *
043: * @author Administrator
044: */
045: public class JTableFrame extends javax.swing.JInternalFrame {
046:
047: /** Creates new form JTableFrame */
048: java.awt.Point origin = null;
049:
050: public JTableFrame() {
051: initComponents();
052: ((javax.swing.plaf.basic.BasicInternalFrameUI) getUI())
053: .getNorthPane().setPreferredSize(
054: new java.awt.Dimension(0, 15));
055:
056: this .jList1.setModel(new DefaultListModel());
057: ((DefaultListModel) this .jList1.getModel())
058: .addElement("Field1");
059: ((DefaultListModel) this .jList1.getModel())
060: .addElement("Field2");
061: ((DefaultListModel) this .jList1.getModel())
062: .addElement("Field3");
063: ((DefaultListModel) this .jList1.getModel())
064: .addElement("Field4");
065: ((DefaultListModel) this .jList1.getModel())
066: .addElement("Field5");
067: ((DefaultListModel) this .jList1.getModel())
068: .addElement("Field6");
069: ((DefaultListModel) this .jList1.getModel())
070: .addElement("Field7");
071: ((DefaultListModel) this .jList1.getModel())
072: .addElement("Field8");
073: ((DefaultListModel) this .jList1.getModel())
074: .addElement("Field9");
075: ((DefaultListModel) this .jList1.getModel())
076: .addElement("Field10");
077: this .dragSource = DragSource.getDefaultDragSource();
078: this .dgListener = new java.awt.dnd.DragGestureListener() {
079: public void dragGestureRecognized(DragGestureEvent dge) {
080: jList1dragGestureRecognized(dge);
081: }
082: };
083: this .dsListener = new DSListener();
084: /*
085: new DragSourceListener(){
086: public void dragDropEnd(DragSourceDropEvent dsde) {}
087: public void dragEnter(DragSourceDragEvent dsde) {}
088: public void dragExit(DragSourceEvent dse) {}
089: public void dragOver(DragSourceDragEvent dsde) {}
090: public void dropActionChanged(DragSourceDragEvent dsde){}
091: };
092: **/
093:
094: this .dragSource.createDefaultDragGestureRecognizer(this ,
095: DnDConstants.ACTION_COPY_OR_MOVE, this .dgListener);
096:
097: jList1.setDragEnabled(true);
098: jList1
099: .setTransferHandler(new it.businesslogic.ireport.gui.dnd.ListColumnTransferableHandler());
100: }
101:
102: private DragSource dragSource;
103: private DragGestureListener dgListener;
104: private DragSourceListener dsListener;
105:
106: public void jList1dragGestureRecognized(DragGestureEvent dge) {
107:
108: }
109:
110: /** This method is called from within the constructor to
111: * initialize the form.
112: * WARNING: Do NOT modify this code. The content of this method is
113: * always regenerated by the Form Editor.
114: */
115: private void initComponents() {//GEN-BEGIN:initComponents
116: jScrollPane1 = new javax.swing.JScrollPane();
117: jList1 = new javax.swing.JList();
118:
119: setBackground(new java.awt.Color(255, 255, 255));
120: setResizable(true);
121: setTitle("My Table");
122: setFrameIcon(null);
123: addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
124: public void mouseDragged(java.awt.event.MouseEvent evt) {
125: formMouseDragged(evt);
126: }
127: });
128:
129: jList1.setDragEnabled(true);
130: jList1
131: .addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
132: public void mouseDragged(
133: java.awt.event.MouseEvent evt) {
134: jList1MouseDragged(evt);
135: }
136: });
137:
138: jScrollPane1.setViewportView(jList1);
139:
140: getContentPane()
141: .add(jScrollPane1, java.awt.BorderLayout.CENTER);
142:
143: pack();
144: }//GEN-END:initComponents
145:
146: private void jList1MouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseDragged
147: JComponent c = (JComponent) evt.getSource();
148: TransferHandler handler = c.getTransferHandler();
149: handler.exportAsDrag(c, evt, TransferHandler.COPY);
150: }//GEN-LAST:event_jList1MouseDragged
151:
152: private void formMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseDragged
153:
154: }//GEN-LAST:event_formMouseDragged
155:
156: // Variables declaration - do not modify//GEN-BEGIN:variables
157: private javax.swing.JScrollPane jScrollPane1;
158: private javax.swing.JList jList1;
159:
160: // End of variables declaration//GEN-END:variables
161:
162: class DSListener implements DragSourceListener {
163:
164: /**
165: * @param e the event
166: */
167: public void dragDropEnd(DragSourceDropEvent e) {
168: if (e.getDropSuccess() == false) {
169: System.out.println("not successful");
170: return;
171: }
172:
173: /*
174: * the dropAction should be what the drop target specified
175: * in acceptDrop
176: */
177: //System.out.println( "dragdropend action " + e.getDropAction() );
178: // this is the action selected by the drop target
179: //if(e.getDropAction() == DnDConstants.ACTION_MOVE)
180: //DragLabel.this.setText("");
181: }
182:
183: /**
184: * @param e the event
185: */
186: public void dragEnter(DragSourceDragEvent e) {
187: //System.out.println( "draglabel enter " + e);
188: DragSourceContext context = e.getDragSourceContext();
189: //intersection of the users selected action, and the source and target actions
190: int myaction = e.getDropAction();
191: //if( (myaction & 1) != 0) {
192: context.setCursor(DragSource.DefaultCopyDrop);
193: //} else {
194: //context.setCursor(DragSource.DefaultCopyNoDrop);
195: //}
196: }
197:
198: /**
199: * @param e the event
200: */
201: public void dragOver(DragSourceDragEvent e) {
202: DragSourceContext context = e.getDragSourceContext();
203: int sa = context.getSourceActions();
204: int ua = e.getUserAction();
205: int da = e.getDropAction();
206: int ta = e.getTargetActions();
207: //System.out.println("dl dragOver source actions" + sa);
208: //System.out.println("user action" + ua);
209: //System.out.println("drop actions" + da);
210: //System.out.println("target actions" + ta);
211: }
212:
213: /**
214: * @param e the event
215: */
216: public void dragExit(DragSourceEvent e) {
217: //System.out.println( "draglabel exit " + e);
218: DragSourceContext context = e.getDragSourceContext();
219: }
220:
221: /**
222: * for example, press shift during drag to change to
223: * a link action
224: * @param e the event
225: */
226: public void dropActionChanged(DragSourceDragEvent e) {
227: DragSourceContext context = e.getDragSourceContext();
228: context.setCursor(DragSource.DefaultCopyNoDrop);
229: }
230: }
231: }
|