From: <sh...@us...> - 2010-08-16 04:11:55
|
Revision: 18348 http://jedit.svn.sourceforge.net/jedit/?rev=18348&view=rev Author: shlomy Date: 2010-08-16 04:11:48 +0000 (Mon, 16 Aug 2010) Log Message: ----------- Allow dragging a separator from the separator button. Unfortunately, this prevents the button from functioning as a button, only dragging is supported. Need to fix this. Modified Paths: -------------- plugins/MenuEditor/trunk/src/menuEditor/MenuEditor.java Modified: plugins/MenuEditor/trunk/src/menuEditor/MenuEditor.java =================================================================== --- plugins/MenuEditor/trunk/src/menuEditor/MenuEditor.java 2010-08-15 06:31:12 UTC (rev 18347) +++ plugins/MenuEditor/trunk/src/menuEditor/MenuEditor.java 2010-08-16 04:11:48 UTC (rev 18348) @@ -8,6 +8,8 @@ import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; @@ -23,6 +25,7 @@ import java.util.HashMap; import javax.swing.*; +import javax.swing.TransferHandler.TransferSupport; import jdiff.util.Diff; import jdiff.util.DiffNormalOutput; @@ -59,6 +62,8 @@ new HashMap<String, ArrayList<MenuElement>>(); private boolean itemListInitialized = false; private static File home; + private DataFlavor flavor = new DataFlavor( + this.getClass(), "MenuElementFlavor"); public static void start() { @@ -459,6 +464,8 @@ appendSeparator(); } }); + separator.setTransferHandler(new SeparatorTransferHandler()); + separator.addMouseListener(new SeparatorMouseListener()); movePanel.add(add); movePanel.add(remove); movePanel.add(up); @@ -620,31 +627,30 @@ return copy; } } - public class ListTransferHandler extends TransferHandler + public class MenuElementTransferable implements Transferable { - public class MenuElementTransferable implements Transferable + ArrayList<MenuElement> elements = new ArrayList<MenuElement>(); + public DataFlavor[] getTransferDataFlavors() { - ArrayList<MenuElement> elements = new ArrayList<MenuElement>(); - public DataFlavor[] getTransferDataFlavors() - { - return new DataFlavor[]{ flavor }; - } - public boolean isDataFlavorSupported(DataFlavor flavor) - { - return (ListTransferHandler.this.flavor == flavor); - } - public Object getTransferData(DataFlavor flavor) - throws UnsupportedFlavorException, IOException - { - return elements; - } - public void add(Object elem) - { - elements.add((MenuElement) elem); - } + return new DataFlavor[]{ flavor }; } + public boolean isDataFlavorSupported(DataFlavor flavor) + { + return (MenuEditor.this.flavor == flavor); + } + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException + { + return elements; + } + public void add(Object elem) + { + elements.add((MenuElement) elem); + } + } - DataFlavor flavor = new DataFlavor(this.getClass(), "MenuElementFlavor"); + public class ListTransferHandler extends TransferHandler + { int [] indices; @Override @@ -712,4 +718,37 @@ itemModel.remove(indices[i]); } } + private class SeparatorTransferHandler extends TransferHandler + { + @Override + public boolean canImport(TransferSupport support) + { + return false; + } + + @Override + public int getSourceActions(JComponent c) + { + return TransferHandler.COPY; + } + + @Override + protected Transferable createTransferable(JComponent c) + { + MenuElementTransferable t = new MenuElementTransferable(); + t.add(new MenuElement(menuSeparator)); + return t; + } + + } + private class SeparatorMouseListener extends MouseAdapter + { + @Override + public void mousePressed(MouseEvent e) + { + JComponent c = (JComponent) e.getSource(); + TransferHandler handler = c.getTransferHandler(); + handler.exportAsDrag(c, e, TransferHandler.COPY); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |