1 19 20 package org.netbeans.modules.mdrxml.looks; 21 22 import java.lang.ref.WeakReference ; 23 import java.io.IOException ; 24 import java.awt.datatransfer.Transferable ; 25 import org.openide.actions.PropertiesAction; 26 import org.openide.nodes.*; 27 import org.openide.util.NbBundle; 28 import org.openide.util.actions.SystemAction; 29 import org.netbeans.api.looks.*; 30 import org.netbeans.spi.looks.*; 31 import org.netbeans.modules.mdrxml.looks.actions.DeleteAction; 32 import org.netbeans.modules.mdrxml.looks.actions.GenerateTextAction; 33 37 public class NodeLook extends DefaultLook { 38 39 private static class NameProperty extends PropertySupport.ReadWrite { 40 41 private WeakReference ref; 42 43 public NameProperty(Look.NodeSubstitute substitute) { 44 super(NbBundle.getMessage(NodeLook.class,"TXT_Name"),String .class,NbBundle.getMessage(NodeLook.class,"TXT_Name"),NbBundle.getMessage(NodeLook.class,"TIP_Name")); 45 this.ref = new WeakReference (substitute); 46 } 47 48 public Object getValue() { 49 Look.NodeSubstitute val = (Look.NodeSubstitute) this.ref.get (); 50 if (val != null && (val.getRepresentedObject() instanceof xmlmodel.Node)) { 51 return ((xmlmodel.Node)val.getRepresentedObject()).getName(); 52 } 53 else { 54 return null; 55 } 56 } 57 58 public void setValue(Object value) { 59 Look.NodeSubstitute val = (Look.NodeSubstitute) this.ref.get (); 60 if (value instanceof String && val != null && val.getRepresentedObject() instanceof xmlmodel.Node) { 61 ((xmlmodel.Node)val.getRepresentedObject()).setName((String )value); 62 val.fireNameChange(null,(String )value); 63 val.fireDisplayNameChange(null,(String )value); 64 } 65 } 66 67 } 68 69 70 public NodeLook(String name) { 71 super(name); 72 } 73 74 public String getName(Look.NodeSubstitute substitute) { 75 try { 76 xmlmodel.Node en = (xmlmodel.Node) substitute.getRepresentedObject(); 77 return en.getName(); 78 }catch (javax.jmi.reflect.InvalidObjectException ioe) { 79 return new String (); 80 } 81 } 82 83 public String getDisplayName(Look.NodeSubstitute substitute) { 84 return this.getName(substitute); 85 } 86 87 public Node.PropertySet[] getPropertySets(Look.NodeSubstitute substitute) { 88 Sheet.Set set = new Sheet.Set(); 89 String name = NbBundle.getMessage(NodeLook.class,"TXT_Properties"); 90 set.setName(name); 91 set.setDisplayName(name); 92 set.put(new NameProperty(substitute)); 93 return new Node.PropertySet[] {set}; 94 } 95 96 public javax.swing.Action [] getActions(Look.NodeSubstitute substitute) { 97 return new javax.swing.Action [] { 98 SystemAction.get(DeleteAction.class), 99 SystemAction.get(PropertiesAction.class), 100 SystemAction.get(GenerateTextAction.class) 101 }; 102 } 103 104 public boolean canCopy (Look.NodeSubstitute substitute) { 105 return true; 106 } 107 108 public Transferable drag (Look.NodeSubstitute substitute) throws IOException { 109 return this.clipboardCopy (substitute); 110 } 111 112 } 113 | Popular Tags |