KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > gui > SectionFieldPanel


1 package jimm.datavision.gui;
2 import jimm.datavision.ErrorHandler;
3 import jimm.datavision.gui.cmd.NewDraggedFieldCommand;
4 import java.awt.Color JavaDoc;
5 import java.awt.Component JavaDoc;
6 import java.awt.dnd.*;
7 import java.awt.datatransfer.*;
8 import javax.swing.JPanel JavaDoc;
9
10 /**
11  * This is the panel that holds {@link FieldWidget}s within a {@link
12  * SectionWidget}. It can handle dragged fields.
13  *
14  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
15  */

16 public class SectionFieldPanel extends JPanel JavaDoc implements DropTargetListener {
17
18 protected SectionWidget sectionWidget;
19
20 /**
21  * Constructor.
22  *
23  * @param sw the section widget
24  */

25 public SectionFieldPanel(SectionWidget sw) {
26     super();
27     sectionWidget = sw;
28     new DropTarget(this, // component
29
DnDConstants.ACTION_COPY_OR_MOVE, // actions
30
this); // DropTargetListener
31
}
32
33 /**
34  * Accepts fields dragged from the field picker window.
35  */

36 public void drop(DropTargetDropEvent e) {
37     try {
38     DataFlavor stringFlavor = DataFlavor.stringFlavor;
39     Transferable tr = e.getTransferable();
40     if (e.isDataFlavorSupported(stringFlavor)) {
41         addField(e, (String JavaDoc)tr.getTransferData(stringFlavor));
42         e.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
43         e.dropComplete(true);
44     }
45     else {
46         e.rejectDrop();
47     }
48     }
49     catch(Exception JavaDoc ex) {
50     ErrorHandler.error(ex);
51     }
52 }
53
54 public void dragEnter(DropTargetDragEvent e) { }
55 public void dragExit(DropTargetEvent e) { }
56 public void dragOver(DropTargetDragEvent e) { }
57 public void dropActionChanged(DropTargetDragEvent e) { }
58
59 /**
60  * Creates and adds a new field. The type and contents of the field are
61  * determined by the string that was dropped. If the field is a
62  * <code>ColumnField</code> and this is a detail section, add a text title
63  * field as well.
64  *
65  * @param e the drop event
66  * @param dropString the string received from the field picker window
67  */

68 protected void addField(DropTargetDropEvent e, String JavaDoc dropString) {
69     sectionWidget.performCommand(new NewDraggedFieldCommand(sectionWidget,
70                                 dropString, e));
71 }
72
73 /**
74  * Performs visual changes that reflect the "hidden" state of the section.
75  * Called by the command that edits the suppression proc of a section.
76  *
77  * @param isHidden new suppressed state
78  */

79 public void setHidden(boolean isHidden) {
80     Color JavaDoc c = isHidden ? SectionWidget.SUPPRESSED_COLOR
81     : SectionWidget.NORMAL_COLOR;
82     setBackground(c);
83     Component JavaDoc[] kids = getComponents();
84     for (int i = 0; i < kids.length; ++i)
85     kids[i].setBackground(c);
86 }
87
88 }
89
Popular Tags