1 19 20 21 package org.netbeans.modules.form.editors2; 22 23 import org.openide.awt.Mnemonics; 24 import org.openide.explorer.propertysheet.editors.*; 25 26 import java.beans.*; 27 import java.awt.*; 28 import java.util.HashMap ; 29 import javax.swing.*; 30 import java.util.ResourceBundle ; 31 32 36 37 public class CursorEditor extends PropertyEditorSupport implements 38 EnhancedPropertyEditor, 39 org.openide.explorer.propertysheet.editors.XMLPropertyEditor, 40 org.netbeans.modules.form.NamedPropertyEditor { 41 42 private static HashMap CURSOR_TYPES = new HashMap (); 43 private static HashMap CURSOR_CONSTANTS = new HashMap (); 44 static { 45 CURSOR_TYPES.put(new Cursor(Cursor.CROSSHAIR_CURSOR).getName(), new Integer (Cursor.CROSSHAIR_CURSOR)); 46 CURSOR_TYPES.put(new Cursor(Cursor.DEFAULT_CURSOR).getName(), new Integer (Cursor.DEFAULT_CURSOR)); 47 CURSOR_TYPES.put(new Cursor(Cursor.E_RESIZE_CURSOR).getName(), new Integer (Cursor.E_RESIZE_CURSOR)); 48 CURSOR_TYPES.put(new Cursor(Cursor.HAND_CURSOR).getName(), new Integer (Cursor.HAND_CURSOR)); 49 CURSOR_TYPES.put(new Cursor(Cursor.MOVE_CURSOR).getName(), new Integer (Cursor.MOVE_CURSOR)); 50 CURSOR_TYPES.put(new Cursor(Cursor.N_RESIZE_CURSOR).getName(), new Integer (Cursor.N_RESIZE_CURSOR)); 51 CURSOR_TYPES.put(new Cursor(Cursor.NE_RESIZE_CURSOR).getName(), new Integer (Cursor.NE_RESIZE_CURSOR)); 52 CURSOR_TYPES.put(new Cursor(Cursor.NW_RESIZE_CURSOR).getName(), new Integer (Cursor.NW_RESIZE_CURSOR)); 53 CURSOR_TYPES.put(new Cursor(Cursor.S_RESIZE_CURSOR).getName(), new Integer (Cursor.S_RESIZE_CURSOR)); 54 CURSOR_TYPES.put(new Cursor(Cursor.SE_RESIZE_CURSOR).getName(), new Integer (Cursor.SE_RESIZE_CURSOR)); 55 CURSOR_TYPES.put(new Cursor(Cursor.SW_RESIZE_CURSOR).getName(), new Integer (Cursor.SW_RESIZE_CURSOR)); 56 CURSOR_TYPES.put(new Cursor(Cursor.TEXT_CURSOR).getName(), new Integer (Cursor.TEXT_CURSOR)); 57 CURSOR_TYPES.put(new Cursor(Cursor.W_RESIZE_CURSOR).getName(), new Integer (Cursor.W_RESIZE_CURSOR)); 58 CURSOR_TYPES.put(new Cursor(Cursor.WAIT_CURSOR).getName(), new Integer (Cursor.WAIT_CURSOR)); 59 60 CURSOR_CONSTANTS.put(new Integer (Cursor.CROSSHAIR_CURSOR), "java.awt.Cursor.CROSSHAIR_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.DEFAULT_CURSOR), "java.awt.Cursor.DEFAULT_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.E_RESIZE_CURSOR), "java.awt.Cursor.E_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.HAND_CURSOR), "java.awt.Cursor.HAND_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.MOVE_CURSOR), "java.awt.Cursor.MOVE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.N_RESIZE_CURSOR), "java.awt.Cursor.N_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.NE_RESIZE_CURSOR), "java.awt.Cursor.NE_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.NW_RESIZE_CURSOR), "java.awt.Cursor.NW_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.S_RESIZE_CURSOR), "java.awt.Cursor.S_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.SE_RESIZE_CURSOR), "java.awt.Cursor.SE_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.SW_RESIZE_CURSOR), "java.awt.Cursor.SW_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.TEXT_CURSOR), "java.awt.Cursor.TEXT_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.W_RESIZE_CURSOR), "java.awt.Cursor.W_RESIZE_CURSOR"); CURSOR_CONSTANTS.put(new Integer (Cursor.WAIT_CURSOR), "java.awt.Cursor.WAIT_CURSOR"); } 75 76 Cursor current; 77 78 79 public CursorEditor() { 80 current = new Cursor(Cursor.DEFAULT_CURSOR); 81 } 82 83 public Object getValue() { 84 return current; 85 } 86 87 public void setValue(Object value) { 88 if (value == null) return; 89 if (value instanceof Cursor) { 90 current =(Cursor) value; 91 firePropertyChange(); 92 } else { 93 throw new IllegalArgumentException (); 94 } 95 } 96 97 public String getAsText() { 98 if (current == null) 99 return "null"; else 101 return current.getName(); 102 } 103 104 public void setAsText(String string) { 105 Object o = CURSOR_TYPES.get(string); 106 if (o != null) { 107 int type =((Integer ) o).intValue(); 108 setValue(new Cursor(type)); 109 } 110 } 111 112 public boolean supportsEditingTaggedValues() { 113 return true; 114 } 115 116 public String [] getTags() { 117 String [] tags = new String [CURSOR_TYPES.size()]; 118 int i=0; 119 for (java.util.Iterator iter = CURSOR_TYPES.keySet().iterator(); iter.hasNext(); i++) 120 tags [i] =(String ) iter.next(); 121 return tags; 122 } 123 124 public boolean hasInPlaceCustomEditor() { 125 return false; 126 } 127 128 public Component getInPlaceCustomEditor() { 129 return null; 130 } 131 132 public boolean supportsCustomEditor() { 133 return true; 134 } 135 136 public Component getCustomEditor() { 137 return new CursorPanel(current); 138 } 139 140 public String getJavaInitializationString() { 141 if (current == null) return null; String cursorName =(String ) CURSOR_CONSTANTS.get(new Integer (current.getType())); 143 if (cursorName != null) 144 return "new java.awt.Cursor("+cursorName+")"; return "new java.awt.Cursor("+current.getType()+")"; } 147 148 static class CursorPanel extends JPanel implements EnhancedCustomPropertyEditor { 149 CursorPanel(Cursor value) { 150 setLayout(new java.awt.GridBagLayout ()); 151 java.awt.GridBagConstraints gridBagConstraints1; 152 list = new JList(new java.util.Vector (CURSOR_TYPES.keySet())); 153 list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 154 if (value != null) 155 list.setSelectedValue(value.getName(), true); 156 157 ResourceBundle bundle = org.openide.util.NbBundle.getBundle(CursorEditor.class); 158 JLabel cursorListLabel = new JLabel(); 159 Mnemonics.setLocalizedText(cursorListLabel, bundle.getString("CTL_SelectCursorName")); cursorListLabel.setLabelFor(list); 161 162 gridBagConstraints1 = new java.awt.GridBagConstraints (); 163 gridBagConstraints1.gridx = 0; 164 gridBagConstraints1.gridy = 1; 165 gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; 166 gridBagConstraints1.insets = new java.awt.Insets (8, 8, 8, 8); 167 gridBagConstraints1.weightx = 1.0; 168 gridBagConstraints1.weighty = 1.0; 169 JScrollPane scrollPane = new JScrollPane(list); 170 add(scrollPane, gridBagConstraints1); 171 172 gridBagConstraints1 = new java.awt.GridBagConstraints (); 173 gridBagConstraints1.gridx = 0; 174 gridBagConstraints1.gridy = 0; 175 gridBagConstraints1.insets = new java.awt.Insets (8, 8, 0, 8); 176 gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; 177 178 add(cursorListLabel, gridBagConstraints1); 179 180 list.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_SelectCursorName")); 181 scrollPane.getVerticalScrollBar().getAccessibleContext().setAccessibleName(bundle.getString("ACSD_CTL_SelectCursorName")); scrollPane.getVerticalScrollBar().getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_SelectCursorName")); getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CursorCustomEditor")); 184 } 185 186 public Object getPropertyValue() throws IllegalStateException { 187 if (list.getSelectedValue()==null) return null; 188 int type =((Integer ) CURSOR_TYPES.get(list.getSelectedValue())).intValue(); 189 return new Cursor(type); 190 } 191 192 private JList list; 193 } 194 195 198 public static final String XML_CURSOR = "Color"; 200 public static final String ATTR_ID = "id"; 202 208 public void readFromXML(org.w3c.dom.Node element) throws java.io.IOException { 209 if (!XML_CURSOR.equals(element.getNodeName())) { 210 throw new java.io.IOException (); 211 } 212 org.w3c.dom.NamedNodeMap attributes = element.getAttributes(); 213 try { 214 String id = attributes.getNamedItem(ATTR_ID).getNodeValue(); 215 setAsText(id); 216 } catch (NullPointerException e) { 217 throw new java.io.IOException (); 218 } 219 } 220 221 226 public org.w3c.dom.Node storeToXML(org.w3c.dom.Document doc) { 227 org.w3c.dom.Element el = doc.createElement(XML_CURSOR); 228 el.setAttribute(ATTR_ID, getAsText()); 229 return el; 230 } 231 232 233 236 237 public String getDisplayName() { 238 return org.openide.util.NbBundle.getBundle(CursorEditor.class).getString("CTL_CursorEditor_DisplayName"); 239 } 240 241 } 242 | Popular Tags |