KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > businesslogic > ireport > gui > JTableFrame


1 /*
2  * Copyright (C) 2005 - 2006 JasperSoft Corporation. All rights reserved.
3  * http://www.jaspersoft.com.
4  *
5  * Unless you have purchased a commercial license agreement from JasperSoft,
6  * the following license terms apply:
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as published by
10  * the Free Software Foundation.
11  *
12  * This program is distributed WITHOUT ANY WARRANTY; and without the
13  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
18  * or write to:
19  *
20  * Free Software Foundation, Inc.,
21  * 59 Temple Place - Suite 330,
22  * Boston, MA USA 02111-1307
23  *
24  *
25  *
26  *
27  * JTableFrame.java
28  *
29  * Created on 20 maggio 2003, 20.20
30  *
31  */

32
33 package it.businesslogic.ireport.gui;
34 import javax.swing.*;
35 import java.util.*;
36 import java.awt.dnd.*;
37 import java.awt.event.*;
38 import javax.swing.table.*;
39 /**
40  *
41  * @author Administrator
42  */

43 public class JTableFrame extends javax.swing.JInternalFrame JavaDoc {
44     
45     /** Creates new form JTableFrame */
46     java.awt.Point JavaDoc origin = null;
47     public JTableFrame() {
48         initComponents();
49         ((javax.swing.plaf.basic.BasicInternalFrameUI JavaDoc)getUI()).getNorthPane().setPreferredSize( new java.awt.Dimension JavaDoc(0,15) );
50     
51
52         this.jList1.setModel(new DefaultListModel());
53         ((DefaultListModel)this.jList1.getModel()).addElement("Field1");
54         ((DefaultListModel)this.jList1.getModel()).addElement("Field2");
55         ((DefaultListModel)this.jList1.getModel()).addElement("Field3");
56         ((DefaultListModel)this.jList1.getModel()).addElement("Field4");
57         ((DefaultListModel)this.jList1.getModel()).addElement("Field5");
58         ((DefaultListModel)this.jList1.getModel()).addElement("Field6");
59         ((DefaultListModel)this.jList1.getModel()).addElement("Field7");
60         ((DefaultListModel)this.jList1.getModel()).addElement("Field8");
61         ((DefaultListModel)this.jList1.getModel()).addElement("Field9");
62         ((DefaultListModel)this.jList1.getModel()).addElement("Field10");
63         this.dragSource = DragSource.getDefaultDragSource();
64         this.dgListener = new java.awt.dnd.DragGestureListener JavaDoc(){
65             public void dragGestureRecognized(DragGestureEvent dge)
66             {
67                 jList1dragGestureRecognized(dge);
68             }
69         };
70         this.dsListener = new DSListener();
71         /*
72         new DragSourceListener(){
73             public void dragDropEnd(DragSourceDropEvent dsde) {}
74             public void dragEnter(DragSourceDragEvent dsde) {}
75             public void dragExit(DragSourceEvent dse) {}
76             public void dragOver(DragSourceDragEvent dsde) {}
77             public void dropActionChanged(DragSourceDragEvent dsde){}
78         };
79          **/

80         
81         this.dragSource.createDefaultDragGestureRecognizer(
82         this, DnDConstants.ACTION_COPY_OR_MOVE, this.dgListener );
83         
84         jList1.setDragEnabled(true);
85         jList1.setTransferHandler(new it.businesslogic.ireport.gui.dnd.ListColumnTransferableHandler());
86     }
87     
88     private DragSource dragSource;
89     private DragGestureListener dgListener;
90     private DragSourceListener dsListener;
91
92     public void jList1dragGestureRecognized(DragGestureEvent dge)
93     {
94         
95     }
96     
97     /** This method is called from within the constructor to
98      * initialize the form.
99      * WARNING: Do NOT modify this code. The content of this method is
100      * always regenerated by the Form Editor.
101      */

102     private void initComponents() {//GEN-BEGIN:initComponents
103
jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
104         jList1 = new javax.swing.JList JavaDoc();
105
106         setBackground(new java.awt.Color JavaDoc(255, 255, 255));
107         setResizable(true);
108         setTitle("My Table");
109         setFrameIcon(null);
110         addMouseMotionListener(new java.awt.event.MouseMotionAdapter JavaDoc() {
111             public void mouseDragged(java.awt.event.MouseEvent JavaDoc evt) {
112                 formMouseDragged(evt);
113             }
114         });
115
116         jList1.setDragEnabled(true);
117         jList1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter JavaDoc() {
118             public void mouseDragged(java.awt.event.MouseEvent JavaDoc evt) {
119                 jList1MouseDragged(evt);
120             }
121         });
122
123         jScrollPane1.setViewportView(jList1);
124
125         getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
126
127         pack();
128     }//GEN-END:initComponents
129

130     private void jList1MouseDragged(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_jList1MouseDragged
131
JComponent c = (JComponent)evt.getSource();
132         TransferHandler handler = c.getTransferHandler();
133         handler.exportAsDrag(c, evt, TransferHandler.COPY);
134     }//GEN-LAST:event_jList1MouseDragged
135

136     private void formMouseDragged(java.awt.event.MouseEvent JavaDoc evt) {//GEN-FIRST:event_formMouseDragged
137

138     }//GEN-LAST:event_formMouseDragged
139

140     
141     // Variables declaration - do not modify//GEN-BEGIN:variables
142
private javax.swing.JScrollPane JavaDoc jScrollPane1;
143     private javax.swing.JList JavaDoc jList1;
144     // End of variables declaration//GEN-END:variables
145

146     
147     class DSListener implements DragSourceListener {
148     
149     /**
150      * @param e the event
151      */

152     public void dragDropEnd(DragSourceDropEvent e) {
153       if( e.getDropSuccess() == false ) {
154     System.out.println( "not successful");
155     return;
156       }
157
158       /*
159        * the dropAction should be what the drop target specified
160        * in acceptDrop
161        */

162       //System.out.println( "dragdropend action " + e.getDropAction() );
163

164       // this is the action selected by the drop target
165
//if(e.getDropAction() == DnDConstants.ACTION_MOVE)
166
//DragLabel.this.setText("");
167
}
168
169     /**
170      * @param e the event
171      */

172     public void dragEnter(DragSourceDragEvent e) {
173       //System.out.println( "draglabel enter " + e);
174
DragSourceContext context = e.getDragSourceContext();
175       //intersection of the users selected action, and the source and target actions
176
int myaction = e.getDropAction();
177       //if( (myaction & 1) != 0) {
178
context.setCursor(DragSource.DefaultCopyDrop);
179       //} else {
180
//context.setCursor(DragSource.DefaultCopyNoDrop);
181
//}
182
}
183     /**
184      * @param e the event
185      */

186     public void dragOver(DragSourceDragEvent e) {
187       DragSourceContext context = e.getDragSourceContext();
188       int sa = context.getSourceActions();
189       int ua = e.getUserAction();
190       int da = e.getDropAction();
191       int ta = e.getTargetActions();
192       //System.out.println("dl dragOver source actions" + sa);
193
//System.out.println("user action" + ua);
194
//System.out.println("drop actions" + da);
195
//System.out.println("target actions" + ta);
196
}
197     /**
198      * @param e the event
199      */

200     public void dragExit(DragSourceEvent e) {
201       //System.out.println( "draglabel exit " + e);
202
DragSourceContext context = e.getDragSourceContext();
203     }
204
205     /**
206      * for example, press shift during drag to change to
207      * a link action
208      * @param e the event
209      */

210     public void dropActionChanged (DragSourceDragEvent e) {
211       DragSourceContext context = e.getDragSourceContext();
212       context.setCursor(DragSource.DefaultCopyNoDrop);
213     }
214   }
215 }
216
217
Popular Tags