- Timestamp:
- 2003-05-27T15:40:47+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/DragGroup.java
r4293 r4364 61 61 /** This class acts as a linker between all the various drag and drop enabled DragComponent. It provides methods for ensuring only one component is the drop target, showing extra user feedback, and maintains a single point of focus. Moreover it provides a storage space for necessary shared variables such as mouse_offset of initial drag etc. */ 62 62 public class DragGroup 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 63 implements FocusListener { 64 /** The image used for the ghost icon when dragging. */ 65 public BufferedImage image_ghost = null; 66 /** The initial offset of the mouse from the selection within a DragComponent. Then as you drag the mouse, the ghost appears in a visually consistant place, and remains at the same offset throughout the dragging process. */ 67 public Point mouse_offset = null; 68 /** The component currently in charge of drawing the ghost icon. Note that this isn't necessarily the only component that needs to repaint 'spoilt' screen real-estate as a side effect of the ghost. */ 69 private DragComponent ghost_owner = null; 70 /** The component where the drag began, so that extra information necessary for the drag can be garnered by the drop target, or so that focus can return to the source component if the drop is rejected. 71 * @see org.greenstone.gatherer.tree.DragComponent#gainFocus 72 * @see org.greenstone.gatherer.tree.DragComponent#loseFocus 73 */ 74 private DragTree drag_source = null; 75 /** The selected nodes, as determined when the drag begun. */ 76 private TreePath[] selection = null; 77 /** A list of DragComponents registered as being part of this group. */ 78 private Vector registered = new Vector(); 79 79 80 80 /** Register a DragComponent as begin part of this group. 81 81 * @param component The DragComponent to add. 82 82 */ 83 84 85 86 87 88 89 83 public void add(DragComponent component) { 84 if(!registered.contains(component)) { 85 registered.add(component); 86 component.addFocusListener(this); 87 component.setGroup(this); 88 } 89 } 90 90 91 92 93 94 91 /** Invoked when a component gains the keyboard focus. */ 92 public void focusGained(FocusEvent event) { 93 ((DragComponent)event.getComponent()).gainFocus(); 94 } 95 95 96 97 98 99 100 96 /** Invoked when a component loses the keyboard focus. */ 97 public void focusLost(FocusEvent event) { 98 ((DragComponent)event.getComponent()).loseFocus(); 99 } 100 /** Determines the current 'active' component, ie that component with focus. 101 101 * @return The DragComponent which is currently responsible for drawing the ghost, and thus is active. 102 102 */ 103 104 105 106 103 public DragComponent getActive() { 104 return ghost_owner; 105 } 106 /** Retrieve the nodes selected at the beginning of this drag operation. 107 107 * @return A TreePath[]. 108 108 */ 109 110 111 112 109 public TreePath[] getSelection() { 110 return selection; 111 } 112 /** Retrieve the component which served as the source of this drag action. 113 113 * @return The DragComponent in question. 114 114 */ 115 116 117 118 115 public DragTree getSource() { 116 return drag_source; 117 } 118 /** When called this method asserts that one of the registered GComponents just became the proud owner of focus, and is henceforth responsible for drawing the ghost, and acting like a component thats in focus. 119 119 * @param new_owner The DragComponent that has gained focus during a drag action. 120 120 */ 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 121 public void grabFocus(DragComponent new_owner) { 122 // Tell the previous owner of ghost to clear itself. 123 if(ghost_owner != null) { 124 ghost_owner.clearGhost(); 125 } 126 // Assign new owner 127 ghost_owner = new_owner; 128 // Then tell all other GComponents to indicate they aren't in focus in whatever way they do that (ie selected items of a GTree go gray). Of course the new owners told it is in focus. 129 for(int i = 0; i < registered.size(); i++) { 130 DragComponent comp = (DragComponent)registered.get(i); 131 if(comp == new_owner) { 132 comp.gainFocus(); 133 } 134 else { 135 comp.loseFocus(); 136 } 137 } 138 } 139 /** Sets the value of selected_nodes. 140 140 * @param selection The new value for selected_nodes as a TreePath[]. 141 141 */ 142 143 144 145 142 public void setSelection(TreePath[] selection) { 143 this.selection = selection; 144 } 145 /** Sets the value of drag_source. 146 146 * @param drag_source The new value for drag_source as a DragTree. 147 147 */ 148 149 150 151 148 public void setSource(DragTree drag_source) { 149 this.drag_source = drag_source; 150 System.err.println("The drag source is now " + drag_source); 151 } 152 152 } 153 154 155
Note:
See TracChangeset
for help on using the changeset viewer.