View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/RegistryObjectsList.java,v 1.8 2002/10/31 01:43:49 farrukh_najmi Exp $ 3 */ 4 package com.sun.xml.registry.client.browser; 5 6 import java.util.*; 7 import javax.xml.registry.*; 8 import javax.xml.registry.infomodel.*; 9 10 import java.awt.*; 11 import java.awt.datatransfer.*; 12 import java.awt.event.*; 13 import javax.swing.*; 14 import javax.swing.event.*; 15 16 /*** 17 * Specialized JList for showing RegistryObjects. 18 * Supports drag&drop of Classification objects. 19 * 20 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 21 */ 22 public class RegistryObjectsList extends JBList { 23 24 public RegistryObjectsList(String interfaceName) { 25 super(interfaceName); 26 } 27 28 /*** 29 * 30 */ 31 public RegistryObjectsList(String interfaceName, RegistryObjectsListModel model) { 32 super(interfaceName, model); 33 34 35 //setDragEnabled(true); 36 //setTransferHandler(new RegistryObjectsListTransferHandler()); 37 38 /* 39 MouseListener ml = new MouseAdapter() { 40 public void mousePressed(MouseEvent e) { 41 JComponent c = (JComponent)e.getSource(); 42 TransferHandler th = c.getTransferHandler(); 43 th.exportAsDrag(c, e, TransferHandler.COPY); 44 } 45 }; 46 addMouseListener(ml); 47 */ 48 } 49 50 /*** 51 * TransferHandler for RegistryObjectsList 52 * 53 */ 54 public class RegistryObjectsListTransferHandler extends TransferHandler { 55 56 boolean isCut = false; 57 58 public boolean canImport(JComponent comp, DataFlavor[] flavors) { 59 return true; 60 } 61 62 protected final Transferable createTransferable(JComponent c) { 63 if (c instanceof RegistryObjectsList) { 64 RegistryObjectsList roList = (RegistryObjectsList) c; 65 try { 66 ArrayList registryObjects = ((RegistryObjectsListModel)roList.getModel()).getModels(); 67 if ((registryObjects != null) && (registryObjects.size() > 0)) { 68 return create(registryObjects); 69 } 70 } 71 catch (JAXRException e) { 72 RegistryBrowser.displayError(e); 73 } 74 } 75 return null; 76 } 77 78 protected RegistryObjectsTransferable create(ArrayList registrObjects) { 79 ArrayList registryObjects = null; 80 81 try { 82 registryObjects = ((RegistryObjectsListModel)RegistryObjectsList.this.getModel()).getModels(); 83 } 84 catch (JAXRException e) { 85 registryObjects = new ArrayList(); 86 RegistryBrowser.displayError(e); 87 } 88 89 return new RegistryObjectsTransferable(registryObjects); 90 } 91 92 protected void exportDone(JComponent comp, Transferable data, int action) { 93 if (comp instanceof RegistryObjectsList && data instanceof RegistryObjectsTransferable) { 94 /* 95 Object[] cells = ((GraphTransferable) data).getCells(); 96 JGraph graph = (JGraph) comp; 97 Point p = insertionLocation; 98 99 if (p == null && action == TransferHandler.MOVE) { 100 removeCells(graph, cells); 101 } 102 else if (p != null && handle != null) { 103 int mod = (action == TransferHandler.COPY) 104 ? InputEvent.CTRL_MASK : 0; 105 106 handle.mouseReleased(new MouseEvent(comp, 0, 0, mod, p.x, p.y, 107 1, false)); 108 } 109 insertionLocation = null; 110 */ 111 } 112 } 113 114 public void exportToClipboard(JComponent compo, Clipboard clip, 115 int action) { 116 isCut = (action == TransferHandler.MOVE); 117 super.exportToClipboard(compo, clip, action); 118 } 119 120 public int getSourceActions(JComponent c) { 121 return COPY_OR_MOVE; 122 } 123 124 public boolean importData(JComponent comp, Transferable t) { 125 try { 126 if (comp instanceof RegistryObjectsList) { 127 RegistryObjectsList list = (RegistryObjectsList) comp; 128 129 if (t.isDataFlavorSupported(RegistryObjectsTransferable.dataFlavor)) { 130 Object obj = 131 t.getTransferData(RegistryObjectsTransferable.dataFlavor); 132 RegistryObjectsTransferable roTransferrable = (RegistryObjectsTransferable) obj; 133 134 ((RegistryObjectsListModel)RegistryObjectsList.this.getModel()).setModels(roTransferrable.getRegistryObjects()); 135 return true; 136 } 137 } 138 } 139 catch (Exception exception) {} 140 finally { 141 isCut = false; 142 } 143 return false; 144 } 145 146 147 148 } 149 150 151 }

This page was automatically generated by Maven