Ignore:
Timestamp:
2003-05-27T15:40:47+12:00 (21 years ago)
Author:
mdewsnip
Message:

Fixed tabbing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/util/DragGroup.java

    r4293 r4364  
    6161/** 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. */
    6262public class DragGroup
    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();
     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();
    7979
    80     /** Register a DragComponent as begin part of this group.
     80    /** Register a DragComponent as begin part of this group.
    8181      * @param component The DragComponent to add.
    8282      */
    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     }
     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    }
    9090
    91     /** Invoked when a component gains the keyboard focus. */
    92     public void focusGained(FocusEvent event) {
    93           ((DragComponent)event.getComponent()).gainFocus();
    94     }
     91    /** Invoked when a component gains the keyboard focus. */
     92    public void focusGained(FocusEvent event) {
     93    ((DragComponent)event.getComponent()).gainFocus();
     94    }
    9595         
    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.
     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.
    101101      * @return The DragComponent which is currently responsible for drawing the ghost, and thus is active.
    102102      */
    103     public DragComponent getActive() {
    104           return ghost_owner;
    105     }
    106     /** Retrieve the nodes selected at the beginning of this drag operation.
     103    public DragComponent getActive() {
     104    return ghost_owner;
     105    }
     106    /** Retrieve the nodes selected at the beginning of this drag operation.
    107107      * @return A TreePath[].
    108108      */
    109     public TreePath[] getSelection() {
    110           return selection;
    111     }
    112     /** Retrieve the component which served as the source of this drag action.
     109    public TreePath[] getSelection() {
     110    return selection;
     111    }
     112    /** Retrieve the component which served as the source of this drag action.
    113113      * @return The DragComponent in question.
    114114      */
    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.
     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.
    119119      * @param new_owner The DragComponent that has gained focus during a drag action.
    120120      */
    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.
     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.
    140140      * @param selection The new value for selected_nodes as a TreePath[].
    141141      */
    142     public void setSelection(TreePath[] selection) {
    143           this.selection = selection;
    144     }
    145     /** Sets the value of drag_source.
     142    public void setSelection(TreePath[] selection) {
     143    this.selection = selection;
     144    }
     145    /** Sets the value of drag_source.
    146146      * @param drag_source The new value for drag_source as a DragTree.
    147147      */
    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     }
     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    }
    152152}
    153 
    154 
    155 
Note: See TracChangeset for help on using the changeset viewer.