1 19 20 package org.netbeans.spi.looks; 21 22 import java.beans.*; 23 import java.util.List ; 24 import java.awt.datatransfer.Transferable ; 25 import java.io.IOException ; 26 import java.util.Collection ; 27 import javax.swing.Action ; 28 import java.awt.Component ; 29 30 import org.openide.nodes.*; 31 import org.openide.util.HelpCtx; 32 import org.openide.util.datatransfer.NewType; 33 import org.openide.util.datatransfer.PasteType; 34 import org.openide.util.Lookup; 35 import org.netbeans.spi.looks.*; 36 37 42 public class SampleLook extends Look { 43 44 45 private SampleListener listener = new SampleListener(); 46 47 private GoldenValue goldenValues[] = null; 48 49 public SampleLook( String name ) { 50 super( name ); 51 } 52 53 public SampleLook( String name, GoldenValue[] goldenValues ) { 54 this( name ); 55 this.goldenValues = goldenValues; 56 } 57 58 60 63 public String getDisplayName() { 64 return getName() + " - DisplayName"; 65 } 66 67 public void attachTo(Object representedObject) { 68 69 Lookup lookup = null; 70 71 if ( representedObject instanceof SampleRepObject ) { 72 ((SampleRepObject)representedObject).attach(); 74 75 76 ((SampleRepObject)representedObject).addPropertyChangeListener( listener ); 77 } 78 else if ( goldenValues != null ) { 79 lookup = (Lookup)GoldenValue.get( ProxyLook.GET_LOOKUP_ITEMS, goldenValues ); 80 } 81 82 } 83 84 public void detachFrom( Object representedObject ) { 85 if ( representedObject instanceof SampleRepObject ) { 86 ((SampleRepObject)representedObject).detach(); ((SampleRepObject)representedObject).removePropertyChangeListener( listener ); } 90 } 91 92 94 public Collection getLookupItems(Object representedObject, Lookup oldEnv ) { 95 if ( goldenValues != null ) { 96 return (Collection )GoldenValue.get( ProxyLook.GET_LOOKUP_ITEMS, goldenValues ); 97 } 98 else { 99 return (Collection )((SampleRepObject)representedObject).getValue( ProxyLook.GET_LOOKUP_ITEMS ); 100 } 101 } 102 103 104 106 public String getDisplayName(Object representedObject, Lookup env ) { 107 return (String )get( ProxyLook.GET_DISPLAY_NAME, representedObject ); 108 } 109 110 public String getName(Object representedObject, Lookup env ) { 111 return (String )get( ProxyLook.GET_NAME, representedObject ); 112 } 113 114 115 public void rename(Object representedObject, String newName, Lookup env ) { 116 if ( representedObject instanceof SampleRepObject ) { 117 ((SampleRepObject)representedObject).setName(); 118 } 119 } 120 121 public String getShortDescription(Object representedObject, Lookup env ) { 122 return (String )get( ProxyLook.GET_SHORT_DESCRIPTION, representedObject ); 123 } 124 125 public java.awt.Image getIcon(Object representedObject, int type, Lookup env ) { 126 return (java.awt.Image )get( ProxyLook.GET_ICON, representedObject ); 127 } 128 129 public java.awt.Image getOpenedIcon(Object representedObject, int type, Lookup env ) { 130 return (java.awt.Image )get( ProxyLook.GET_OPENED_ICON, representedObject ); 131 } 132 133 public HelpCtx getHelpCtx(Object representedObject, Lookup env ) { 134 return (HelpCtx)get( ProxyLook.GET_HELP_CTX, representedObject ); 135 } 136 137 139 public List getChildObjects(Object representedObject, Lookup env ) { 140 return (List )get( ProxyLook.GET_CHILD_OBJECTS, representedObject ); 141 } 142 143 public boolean isLeaf(Object representedObject, Lookup env ) { 144 return get( ProxyLook.GET_CHILD_OBJECTS, representedObject ) == null; 145 } 146 147 149 public NewType[] getNewTypes(Object representedObject, Lookup env ) { 150 return (NewType[])get( ProxyLook.GET_NEW_TYPES, representedObject ); 151 } 152 153 public Action [] getActions(Object representedObject, Lookup env ) { 154 return (Action [])get( ProxyLook.GET_ACTIONS, representedObject ); 155 } 156 157 public Action [] getContextActions(Object representedObject, Lookup env ) { 158 return (Action [])get( ProxyLook.GET_CONTEXT_ACTIONS, representedObject ); 159 } 160 161 public Action getDefaultAction(Object representedObject, Lookup env ) { 162 return (Action )get( ProxyLook.GET_DEFAULT_ACTION, representedObject ); 163 } 164 165 167 public Node.PropertySet[] getPropertySets(Object representedObject, Lookup env ) { 168 return (Node.PropertySet[])get( ProxyLook.GET_PROPERTY_SETS, representedObject ); 169 } 170 171 public Component getCustomizer(Object representedObject, Lookup env ) { 172 return (java.awt.Component )get( ProxyLook.GET_CUSTOMIZER, representedObject ); 173 } 174 175 public boolean hasCustomizer(Object representedObject, Lookup env ) { 176 return ((Boolean )get( ProxyLook.HAS_CUSTOMIZER, representedObject )).booleanValue(); 177 } 178 179 181 public boolean canRename(Object representedObject, Lookup env ) { 182 return ((Boolean )get( ProxyLook.CAN_RENAME, representedObject )).booleanValue(); 183 } 184 185 public boolean canDestroy(Object representedObject, Lookup env ) { 186 return ((Boolean )get( ProxyLook.CAN_DESTROY, representedObject )).booleanValue(); 187 } 188 189 public boolean canCopy(Object representedObject, Lookup env ) { 190 return ((Boolean )get( ProxyLook.CAN_COPY, representedObject )).booleanValue(); 191 } 192 193 public boolean canCut(Object representedObject, Lookup env ) { 194 return ((Boolean )get( ProxyLook.CAN_CUT, representedObject )).booleanValue(); 195 } 196 197 public PasteType[] getPasteTypes(Object representedObject, Transferable t, Lookup env ) { 198 return (PasteType[])get( ProxyLook.GET_PASTE_TYPES, representedObject ); 199 } 200 201 public PasteType getDropType(Object representedObject, Transferable t, int action, int index, Lookup env ) { 202 return (PasteType)get( ProxyLook.GET_DROP_TYPE, representedObject ); 203 } 204 205 public Transferable clipboardCopy(Object representedObject, Lookup env ) throws IOException { 206 return (Transferable )get( ProxyLook.CLIPBOARD_COPY, representedObject ); 207 } 208 209 public Transferable clipboardCut(Object representedObject, Lookup env ) throws IOException { 210 return (Transferable )get( ProxyLook.CLIPBOARD_CUT, representedObject ); 211 } 212 213 public Transferable drag(Object representedObject, Lookup env ) throws IOException { 214 return (Transferable )get( ProxyLook.DRAG, representedObject ); 215 } 216 217 public void destroy(Object representedObject, Lookup env ) throws IOException { 218 if ( representedObject instanceof SampleRepObject ) { 219 ((SampleRepObject)representedObject).destroy(); 220 } 221 } 222 223 225 229 protected Object get( long key, Object representedObject ) { 230 231 if ( goldenValues != null ) { 232 return GoldenValue.get( key, goldenValues ); 233 } 234 235 240 if ( representedObject instanceof SampleRepObject ) { 241 return ((SampleRepObject)representedObject).getValue( key ); 242 } 243 else { 244 return null; 245 } 246 } 247 248 250 public class SampleListener implements PropertyChangeListener { 251 252 254 public void propertyChange(PropertyChangeEvent evt) { 255 256 try { 257 long ev = Long.parseLong( evt.getPropertyName() ); 258 259 fireChange( evt.getSource(), ev ); 260 } 261 catch ( NumberFormatException e ) { 262 if ( SampleRepObject.DESTROY.equals( evt.getPropertyName() ) ) { 263 fireChange( evt.getSource(), Look.DESTROY ); 264 } 265 else { 266 firePropertyChange( evt.getSource(), evt.getPropertyName() ); 267 } 268 } 269 } 270 271 } 272 273 274 } 275 | Popular Tags |