001: /*
002: * Gruntspud
003: *
004: * Copyright (C) 2002 Brett Smith.
005: *
006: * Written by: Brett Smith <t_magicthize@users.sourceforge.net>
007: *
008: * This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public
009: * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
010: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details.
012: *
013: * You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free
014: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015: */
016: package gruntspud.ui.preferences;
017:
018: import gruntspud.Constants;
019: import gruntspud.GruntspudContext;
020: import gruntspud.actions.AbstractGruntspudAction;
021: import gruntspud.actions.DefaultGruntspudAction;
022: import gruntspud.actions.GruntspudAction;
023: import gruntspud.ui.UIUtil;
024:
025: import java.awt.BorderLayout;
026: import java.awt.Color;
027: import java.awt.Component;
028: import java.awt.Graphics;
029: import java.awt.GridBagConstraints;
030: import java.awt.GridBagLayout;
031: import java.awt.Insets;
032: import java.awt.Rectangle;
033: import java.awt.datatransfer.DataFlavor;
034: import java.awt.datatransfer.StringSelection;
035: import java.awt.datatransfer.Transferable;
036: import java.awt.dnd.DnDConstants;
037: import java.awt.dnd.DragGestureEvent;
038: import java.awt.dnd.DragGestureListener;
039: import java.awt.dnd.DragSource;
040: import java.awt.dnd.DragSourceDragEvent;
041: import java.awt.dnd.DragSourceDropEvent;
042: import java.awt.dnd.DragSourceEvent;
043: import java.awt.dnd.DragSourceListener;
044: import java.awt.dnd.DropTarget;
045: import java.awt.dnd.DropTargetDragEvent;
046: import java.awt.dnd.DropTargetDropEvent;
047: import java.awt.dnd.DropTargetEvent;
048: import java.awt.dnd.DropTargetListener;
049: import java.awt.event.ActionEvent;
050: import java.awt.event.ActionListener;
051: import java.util.StringTokenizer;
052: import java.util.Vector;
053:
054: import javax.swing.AbstractListModel;
055: import javax.swing.Action;
056: import javax.swing.BorderFactory;
057: import javax.swing.DefaultListCellRenderer;
058: import javax.swing.Icon;
059: import javax.swing.JButton;
060: import javax.swing.JCheckBox;
061: import javax.swing.JComboBox;
062: import javax.swing.JLabel;
063: import javax.swing.JList;
064: import javax.swing.JPanel;
065: import javax.swing.JScrollPane;
066: import javax.swing.event.ListSelectionEvent;
067: import javax.swing.event.ListSelectionListener;
068:
069: /**
070: * Description of the Class
071: *
072: * @author magicthize @created 26 May 2002
073: */
074: public class ToolBarOptionsTab extends AbstractOptionsTab implements
075: ListSelectionListener, ActionListener {
076: public final static String[] TOOLBAR_PLACEMENT = { "North", "East",
077: "South", "West" };
078:
079: static DataFlavor[] supportedFlavors = new DataFlavor[1];
080:
081: static {
082: try {
083: supportedFlavors[0] = new DataFlavor(
084: DataFlavor.javaJVMLocalObjectMimeType);
085: } catch (Exception ex) {
086: ex.printStackTrace();
087: }
088: }
089:
090: private JList hiddenTools;
091: private JList shownTools;
092: private ToolListModel hiddenModel;
093: private ToolListModel shownModel;
094: private JButton add;
095: private JButton remove;
096: private JButton addAll;
097: private JButton removeAll;
098: private JButton moveUp;
099: private JButton moveDown;
100: private JCheckBox smallIcons, showSelectiveText;
101: private String oldActions;
102: private JComboBox placement;
103:
104: /**
105: * Constructor for the GlobalOptionsTab object
106: */
107: public ToolBarOptionsTab() {
108: super ("Tool Bar", UIUtil
109: .getCachedIcon(Constants.ICON_TOOL_MAINTAIN));
110: }
111:
112: /**
113: * DOCUMENT ME!
114: *
115: * @param context DOCUMENT ME!
116: */
117: public void init(GruntspudContext context) {
118: super .init(context);
119: setTabToolTipText("Options for the toolbar.");
120: setTabLargeIcon(UIUtil
121: .getCachedIcon(Constants.ICON_TOOL_LARGE_MAINTAIN));
122: setLayout(new GridBagLayout());
123: setTabMnemonic('r');
124: setTabContext("UI");
125: //
126: hiddenTools = new DnDList(hiddenModel = new ToolListModel(),
127: "Actions");
128: hiddenTools.setCellRenderer(new ActionListCellRenderer());
129: hiddenTools.addListSelectionListener(this );
130: hiddenTools.setDragEnabled(true);
131: // hiddenTools.setDropTarget(shownTools);
132: JScrollPane hiddenScroller = new JScrollPane(hiddenTools);
133: hiddenScroller.setAutoscrolls(true);
134: //
135: shownTools = new DnDList(shownModel = new ToolListModel(),
136: "Active");
137: shownTools.setCellRenderer(new ActionListCellRenderer());
138: shownTools.addListSelectionListener(this );
139: shownTools.setDragEnabled(true);
140: JScrollPane shownScroller = new JScrollPane(shownTools);
141: shownScroller.setAutoscrolls(true);
142: //
143: JPanel b = new JPanel(new GridBagLayout());
144: GridBagConstraints gbc = new GridBagConstraints();
145: gbc.anchor = GridBagConstraints.NORTH;
146: gbc.fill = GridBagConstraints.HORIZONTAL;
147: gbc.insets = new Insets(2, 8, 2, 8);
148: gbc.weightx = 1.0;
149: UIUtil.jGridBagAdd(b, add = new JButton(" Add > "), gbc,
150: GridBagConstraints.REMAINDER);
151: add.setMnemonic('a');
152: add.addActionListener(this );
153: UIUtil.jGridBagAdd(b, addAll = new JButton(" Add >> "), gbc,
154: GridBagConstraints.REMAINDER);
155: addAll.setMnemonic('l');
156: addAll.addActionListener(this );
157: UIUtil.jGridBagAdd(b, remove = new JButton(" < Remove "), gbc,
158: GridBagConstraints.REMAINDER);
159: remove.setMnemonic('r');
160: remove.addActionListener(this );
161: UIUtil.jGridBagAdd(b, removeAll = new JButton(" << Remove "),
162: gbc, GridBagConstraints.REMAINDER);
163: removeAll.setMnemonic('v');
164: removeAll.addActionListener(this );
165: UIUtil.jGridBagAdd(b, moveUp = new JButton(" Move Up "), gbc,
166: GridBagConstraints.REMAINDER);
167: moveUp.setMnemonic('u');
168: moveUp.addActionListener(this );
169: gbc.weighty = 1.0;
170: UIUtil.jGridBagAdd(b, moveDown = new JButton(" Move Down "),
171: gbc, GridBagConstraints.REMAINDER);
172: moveDown.setMnemonic('d');
173: moveDown.addActionListener(this );
174: //
175: JPanel m = new JPanel(new GridBagLayout());
176: GridBagConstraints gbc2 = new GridBagConstraints();
177: gbc2.anchor = GridBagConstraints.CENTER;
178: gbc2.fill = GridBagConstraints.BOTH;
179: m.setBorder(BorderFactory.createTitledBorder("Actions"));
180: gbc2.weighty = 1.0;
181: gbc2.weightx = 2.0;
182: UIUtil.jGridBagAdd(m, hiddenScroller, gbc2, 1);
183: gbc2.weightx = 0.0;
184: UIUtil.jGridBagAdd(m, b, gbc2, GridBagConstraints.RELATIVE);
185: gbc2.weightx = 2.0;
186: UIUtil.jGridBagAdd(m, shownScroller, gbc2,
187: GridBagConstraints.REMAINDER);
188: //
189: JPanel o = new JPanel(new GridBagLayout());
190: GridBagConstraints gbco = new GridBagConstraints();
191: gbco.anchor = GridBagConstraints.WEST;
192: gbco.fill = GridBagConstraints.HORIZONTAL;
193: gbco.insets = new Insets(2, 2, 2, 2);
194:
195: o.setBorder(BorderFactory.createTitledBorder("Options"));
196: gbco.weightx = 2.0;
197: UIUtil.jGridBagAdd(o, smallIcons = new JCheckBox(
198: "Use small icons"), gbco, 1);
199: smallIcons.setMnemonic('s');
200: smallIcons.setSelected(context.getHost().getBooleanProperty(
201: Constants.TOOL_BAR_SMALL_ICONS, false));
202: smallIcons.addActionListener(this );
203: UIUtil.jGridBagAdd(o, showSelectiveText = new JCheckBox(
204: "Show selective text"), gbco, 1);
205: showSelectiveText.setMnemonic('s');
206: showSelectiveText.setSelected(context.getHost()
207: .getBooleanProperty(
208: Constants.TOOL_BAR_SHOW_SELECTIVE_TEXT, true));
209: gbco.weightx = 1.0;
210: gbco.anchor = GridBagConstraints.EAST;
211: UIUtil.jGridBagAdd(o, new JLabel("Placement", JLabel.RIGHT),
212: gbco, GridBagConstraints.RELATIVE);
213: gbco.weightx = 1.0;
214: UIUtil.jGridBagAdd(o, placement = new JComboBox(
215: TOOLBAR_PLACEMENT), gbco, GridBagConstraints.REMAINDER);
216: placement.setSelectedItem(context.getHost().getProperty(
217: Constants.TOOL_BAR_POSITION, TOOLBAR_PLACEMENT[0]));
218:
219: //
220: // This panel
221: setLayout(new BorderLayout());
222: add(m, BorderLayout.CENTER);
223: add(o, BorderLayout.SOUTH);
224: //
225: String actions = context.getHost().getProperty(
226: Constants.TOOL_BAR_ACTIONS,
227: Constants.TOOL_BAR_DEFAULT_ACTIONS);
228: StringTokenizer s = new StringTokenizer(actions, ",");
229: while (s.hasMoreTokens()) {
230: String n = s.nextToken();
231: if (n.equals(Constants.TOOL_BAR_SEPARATOR)) {
232: shownModel.add(new SeparatorAction());
233: } else {
234: Action a = context.getViewManager().getAction(n);
235: if (a != null) {
236: shownModel.add(a);
237: }
238: }
239: }
240: Action[] a = context.getViewManager().getActions();
241: hiddenModel.add(new SeparatorAction());
242: for (int i = 0; i < a.length; i++) {
243: if (!shownModel.containsAction((String) a[i]
244: .getValue(GruntspudAction.INTERNAL_NAME))) {
245: hiddenModel.add(a[i]);
246: }
247: }
248: setAvailableActions();
249: }
250:
251: /**
252: * DOCUMENT ME!
253: *
254: * @param evt DOCUMENT ME!
255: */
256: public void actionPerformed(ActionEvent evt) {
257: if (evt.getSource() == add) {
258: int[] z = hiddenTools.getSelectedIndices();
259: for (int i = z.length - 1; i >= 0; i--) {
260: if (z[i] == 0) {
261: shownModel.add(new SeparatorAction());
262: } else {
263: shownModel.add((Action) hiddenModel
264: .getElementAt(z[i]));
265: shownTools.ensureIndexIsVisible(shownModel
266: .getSize() - 1);
267: hiddenModel.removeActionAt(z[i]);
268: }
269: }
270: } else if (evt.getSource() == addAll) {
271: int z = hiddenModel.getSize();
272: for (int i = z - 1; i >= 1; i--) {
273: shownModel.add((Action) hiddenModel.getElementAt(i));
274: hiddenModel.removeActionAt(i);
275: }
276: } else if (evt.getSource() == remove) {
277: int[] z = shownTools.getSelectedIndices();
278: for (int i = z.length - 1; i >= 0; i--) {
279: Action a = (Action) shownModel.getElementAt(z[i]);
280: if (!(a instanceof SeparatorAction)) {
281: hiddenModel.add(a);
282: }
283: shownModel.removeActionAt(z[i]);
284: }
285: } else if (evt.getSource() == removeAll) {
286: int z = shownModel.getSize();
287: for (int i = z - 1; i >= 0; i--) {
288: Action a = (Action) shownModel.getElementAt(i);
289: if (!a.getValue(GruntspudAction.INTERNAL_NAME).equals(
290: Constants.ACTION_ALL_TOOLS)) {
291: if (!(a instanceof SeparatorAction)) {
292: hiddenModel.add((Action) shownModel
293: .getElementAt(i));
294: }
295: shownModel.removeActionAt(i);
296: }
297: }
298: } else if (evt.getSource() == moveUp) {
299: int i = shownTools.getSelectedIndex();
300: shownModel.moveUp(i);
301: shownTools.setSelectedIndex(i - 1);
302: shownTools.ensureIndexIsVisible(i - 1);
303: } else if (evt.getSource() == moveDown) {
304: int i = shownTools.getSelectedIndex();
305: shownModel.moveDown(shownTools.getSelectedIndex());
306: shownTools.setSelectedIndex(i + 1);
307: shownTools.ensureIndexIsVisible(i + 1);
308: } else if (evt.getSource() == smallIcons) {
309: shownModel.reload();
310: hiddenModel.reload();
311: }
312: }
313:
314: /**
315: * DOCUMENT ME!
316: *
317: * @param evt DOCUMENT ME!
318: */
319: public void valueChanged(ListSelectionEvent evt) {
320: setAvailableActions();
321: }
322:
323: /**
324: * Description of the Method
325: *
326: * @return Description of the Return Value
327: */
328: public boolean validateTab() {
329: return true;
330: }
331:
332: /**
333: * Description of the Method
334: */
335: public void tabSelected() {
336: }
337:
338: /**
339: * Description of the Method
340: */
341: public void applyTab() {
342: getContext().getHost()
343: .setBooleanProperty(Constants.TOOL_BAR_SMALL_ICONS,
344: smallIcons.isSelected());
345: getContext().getHost().setProperty(Constants.TOOL_BAR_ACTIONS,
346: shownModel.getActionListString());
347: getContext().getHost().setProperty(Constants.TOOL_BAR_POSITION,
348: (String) placement.getSelectedItem());
349: getContext().getHost().setBooleanProperty(
350: Constants.TOOL_BAR_SHOW_SELECTIVE_TEXT,
351: showSelectiveText.isSelected());
352: }
353:
354: private void setAvailableActions() {
355: add.setEnabled(!hiddenTools.isSelectionEmpty());
356: remove.setEnabled(!shownTools.isSelectionEmpty()
357: && !(((Action) shownTools.getSelectedValue())
358: .getValue(GruntspudAction.INTERNAL_NAME)
359: .equals(Constants.ACTION_ALL_TOOLS)));
360: moveUp.setEnabled((shownTools.getSelectedIndices().length == 1)
361: && (shownTools.getSelectedIndex() > 0));
362: moveDown
363: .setEnabled((shownTools.getSelectedIndices().length == 1)
364: && ((shownTools.getSelectedIndex() + 1) < shownModel
365: .getSize()));
366: }
367:
368: class ToolListModel extends AbstractListModel {
369: private Vector validActions;
370:
371: ToolListModel() {
372: validActions = new Vector();
373: }
374:
375: public boolean containsAction(String n) {
376: for (int i = 0; i < getSize(); i++) {
377: if (((Action) getElementAt(i)).getValue(
378: GruntspudAction.INTERNAL_NAME).equals(n)) {
379: return true;
380: }
381: }
382: return false;
383: }
384:
385: public GruntspudAction getAction(String n) {
386: for (int i = 0; i < getSize(); i++) {
387: GruntspudAction act = (GruntspudAction) getElementAt(i);
388: if (act.getValue(GruntspudAction.INTERNAL_NAME).equals(
389: n)) {
390: return act;
391: }
392: }
393: return null;
394: }
395:
396: public void clear() {
397: validActions.removeAllElements();
398: fireContentsChanged(this , -1, -1);
399: }
400:
401: public void removeActionAt(int i) {
402: validActions.removeElementAt(i);
403: fireIntervalRemoved(this , i, i);
404: }
405:
406: public void moveUp(int i) {
407: Action a = (Action) getElementAt(i);
408: validActions.removeElementAt(i);
409: fireIntervalRemoved(this , i, i);
410: validActions.insertElementAt(a, i - 1);
411: fireIntervalAdded(this , i - 1, i - 1);
412: }
413:
414: public void moveDown(int i) {
415: Action a = (Action) getElementAt(i);
416: validActions.removeElementAt(i);
417: fireIntervalRemoved(this , i, i);
418: validActions.insertElementAt(a, i + 1);
419: fireIntervalAdded(this , i + 1, i + 1);
420: }
421:
422: public void add(Action action) {
423: int i = getSize();
424: validActions.addElement(action);
425: fireIntervalAdded(this , i, i);
426: }
427:
428: public void reload() {
429: fireContentsChanged(this , -1, -1);
430: }
431:
432: public String getActionListString() {
433: StringBuffer buf = new StringBuffer();
434: for (int i = 0; i < getSize(); i++) {
435: if (i > 0) {
436: buf.append(',');
437: }
438: Action a = (Action) getElementAt(i);
439: if (a instanceof SeparatorAction) {
440: buf.append(Constants.TOOL_BAR_SEPARATOR);
441: } else {
442: buf.append((String) a
443: .getValue(GruntspudAction.INTERNAL_NAME));
444: }
445: }
446: return buf.toString();
447: }
448:
449: public void setActions(Action[] actions) {
450: validActions.removeAllElements();
451: for (int i = 0; i < actions.length; i++) {
452: validActions.addElement(actions[i]);
453: }
454: fireContentsChanged(this , -1, -1);
455: }
456:
457: public Object getElementAt(int t) {
458: return validActions.elementAt(t);
459: }
460:
461: public int getSize() {
462: return validActions.size();
463: }
464:
465: /**
466: * @param action
467: */
468: public void removeAction(GruntspudAction action) {
469: int i = validActions.indexOf(action);
470: if (i != -1) {
471: validActions.remove(action);
472: fireIntervalRemoved(this , i, i);
473: }
474: }
475:
476: /**
477: * @param action
478: * @param dropRow
479: */
480: public void insert(GruntspudAction action, int row) {
481: validActions.insertElementAt(action, row);
482: fireIntervalAdded(this , row, row);
483:
484: }
485:
486: /**
487: * @param action
488: * @return
489: */
490: public int indexOf(GruntspudAction action) {
491: return validActions.indexOf(action);
492: }
493: }
494:
495: class SeparatorAction extends AbstractGruntspudAction {
496: SeparatorAction() {
497: putValue(Action.NAME, "Separator");
498: putValue(GruntspudAction.INTERNAL_NAME, "Separator");
499: putValue(GruntspudAction.ICON, UIUtil
500: .getCachedIcon(Constants.ICON_TOOL_NORMAL_REMOVE));
501: putValue(
502: DefaultGruntspudAction.SMALL_ICON,
503: UIUtil
504: .getCachedIcon(Constants.ICON_TOOL_SMALL_NORMAL_REMOVE));
505: putValue(Action.SHORT_DESCRIPTION, "Separator");
506: putValue(Action.LONG_DESCRIPTION, "Separator");
507: }
508:
509: public void actionPerformed(ActionEvent evt) {
510: }
511: }
512:
513: class ActionListCellRenderer extends DefaultListCellRenderer {
514: public Component getListCellRendererComponent(JList list,
515: Object value, int index, boolean isSelected,
516: boolean cellHasFocus) {
517: super .getListCellRendererComponent(list, value, index,
518: isSelected, cellHasFocus);
519: Action n = (Action) value;
520: if (smallIcons.isSelected()) {
521: setIcon((Icon) n.getValue(GruntspudAction.SMALL_ICON));
522: } else {
523: setIcon((Icon) n.getValue(GruntspudAction.ICON));
524: }
525: setText((String) n.getValue(Action.NAME));
526: return this ;
527: }
528: }
529:
530: public class DnDList extends JList implements DropTargetListener,
531: DragSourceListener, DragGestureListener {
532: DropTarget dropTarget = new DropTarget(this , this );
533: DragSource dragSource = DragSource.getDefaultDragSource();
534: int dropRow = -1;
535: Color lineColor;
536: String name;
537:
538: public DnDList(ToolListModel model, String name) {
539: super (model);
540: this .name = name; // this is only really for sussing out dnd
541: dragSource.createDefaultDragGestureRecognizer(this ,
542: DnDConstants.ACTION_MOVE, this );
543: Color c = getForeground();
544: lineColor = new Color(c.getRed(), c.getGreen(),
545: c.getBlue(), 128);
546: setBorder(BorderFactory.createEmptyBorder(2, 2, 12, 2));
547: }
548:
549: /*
550: * (non-Javadoc)
551: *
552: * @see java.awt.dnd.DropTargetListener#dragEnter(java.awt.dnd.DropTargetDragEvent)
553: */
554: public void dragEnter(DropTargetDragEvent dtde) {
555: dtde.acceptDrag(DnDConstants.ACTION_MOVE);
556: }
557:
558: /*
559: * (non-Javadoc)
560: *
561: * @see java.awt.dnd.DropTargetListener#dragOver(java.awt.dnd.DropTargetDragEvent)
562: */
563: public void dragOver(DropTargetDragEvent dtde) {
564: Insets i = getBorder().getBorderInsets(this );
565: if (dtde.getLocation().y > (getSize().height - i.bottom)) {
566: dropRow = getModel().getSize();
567: } else {
568: dropRow = locationToIndex(dtde.getLocation());
569: }
570: repaint();
571:
572: }
573:
574: /*
575: * (non-Javadoc)
576: *
577: * @see java.awt.dnd.DropTargetListener#dropActionChanged(java.awt.dnd.DropTargetDragEvent)
578: */
579: public void dropActionChanged(DropTargetDragEvent dtde) {
580: // TODO Auto-generated method stub
581:
582: }
583:
584: /*
585: * (non-Javadoc)
586: *
587: * @see java.awt.dnd.DropTargetListener#drop(java.awt.dnd.DropTargetDropEvent)
588: */
589: public void drop(DropTargetDropEvent dtde) {
590: try {
591: ActionWrapper wrapper = (ActionWrapper) dtde
592: .getTransferable().getTransferData(
593: supportedFlavors[0]);
594: GruntspudAction action = wrapper.action;
595: if (getModel() == wrapper.model) {
596: int idx = ((ToolListModel) getModel())
597: .indexOf(action);
598: if (idx > dropRow) {
599: wrapper.model.removeAction(wrapper.action);
600: wrapper.model.insert(action, dropRow);
601: } else if (idx < dropRow) {
602: wrapper.model.insert(action, dropRow);
603: wrapper.model.removeAction(wrapper.action);
604: }
605: } else {
606: wrapper.model.removeAction(wrapper.action);
607: ((ToolListModel) getModel())
608: .insert(action, dropRow);
609: }
610: dropRow = -1;
611: repaint();
612: } catch (Exception e) {
613: Constants.UI_LOG.error(e);
614: }
615:
616: }
617:
618: /*
619: * (non-Javadoc)
620: *
621: * @see java.awt.dnd.DropTargetListener#dragExit(java.awt.dnd.DropTargetEvent)
622: */
623: public void dragExit(DropTargetEvent dte) {
624: dropRow = -1;
625: repaint();
626: }
627:
628: /*
629: * (non-Javadoc)
630: *
631: * @see java.awt.dnd.DragSourceListener#dragEnter(java.awt.dnd.DragSourceDragEvent)
632: */
633: public void dragEnter(DragSourceDragEvent dsde) {
634: }
635:
636: /*
637: * (non-Javadoc)
638: *
639: * @see java.awt.dnd.DragSourceListener#dragOver(java.awt.dnd.DragSourceDragEvent)
640: */
641: public void dragOver(DragSourceDragEvent dsde) {
642: }
643:
644: /*
645: * (non-Javadoc)
646: *
647: * @see java.awt.dnd.DragSourceListener#dropActionChanged(java.awt.dnd.DragSourceDragEvent)
648: */
649: public void dropActionChanged(DragSourceDragEvent dsde) {
650: }
651:
652: /*
653: * (non-Javadoc)
654: *
655: * @see java.awt.dnd.DragSourceListener#dragDropEnd(java.awt.dnd.DragSourceDropEvent)
656: */
657: public void dragDropEnd(DragSourceDropEvent dsde) {
658: }
659:
660: /*
661: * (non-Javadoc)
662: *
663: * @see java.awt.dnd.DragSourceListener#dragExit(java.awt.dnd.DragSourceEvent)
664: */
665: public void dragExit(DragSourceEvent dse) {
666: }
667:
668: /*
669: * (non-Javadoc)
670: *
671: * @see java.awt.dnd.DragGestureListener#dragGestureRecognized(java.awt.dnd.DragGestureEvent)
672: */
673: public void dragGestureRecognized(DragGestureEvent dge) {
674: Constants.UI_LOG.debug(dge);
675: GruntspudAction action = (GruntspudAction) getSelectedValue();
676: if (action == null) {
677: getToolkit().beep();
678: } else {
679: ActionTransferable transferable = new ActionTransferable(
680: new ActionWrapper(action, (ToolListModel) this
681: .getModel()));
682: dge.startDrag(DragSource.DefaultMoveDrop, transferable,
683: this );
684: }
685:
686: }
687:
688: public void paintComponent(Graphics g) {
689: super .paintComponent(g);
690: if (dropRow != -1) {
691: g.setColor(lineColor);
692: Rectangle bounds = getCellBounds(dropRow, dropRow);
693: if (bounds == null) {
694: Insets i = getBorder().getBorderInsets(this );
695: g
696: .fillRect(0, getSize().height - i.bottom
697: - 3, 2, 7);
698: g.fillRect(2, getSize().height - i.bottom - 1,
699: getSize().width - 6, 3);
700:
701: } else {
702: g.fillRect(0, bounds.y - 3, 2, 7);
703: g.fillRect(2, bounds.y - 1, bounds.x + bounds.width
704: - 6, 3);
705: }
706: }
707: }
708: }
709:
710: class ActionWrapper {
711: GruntspudAction action;
712: ToolListModel model;
713:
714: ActionWrapper(GruntspudAction action, ToolListModel model) {
715: this .action = action;
716: this .model = model;
717: }
718: }
719:
720: class ActionTransferable implements Transferable {
721:
722: ActionWrapper wrapper;
723:
724: ActionTransferable(ActionWrapper wrapper) {
725: this .wrapper = wrapper;
726: }
727:
728: // Transferable methods.
729: public Object getTransferData(DataFlavor flavor) {
730: if (flavor
731: .isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType))
732: return wrapper;
733: else
734: return null;
735: }
736:
737: public DataFlavor[] getTransferDataFlavors() {
738: return supportedFlavors;
739: }
740:
741: public boolean isDataFlavorSupported(DataFlavor flavor) {
742: return flavor
743: .isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType);
744: }
745: }
746: }
|