1 19 20 package org.netbeans.spi.looks; 21 22 import org.netbeans.spi.looks.GoldenValue; 23 24 import java.beans.*; 25 import java.util.Hashtable ; 26 27 30 public class SampleRepObject { 31 32 private int attachCalled; 33 private int detachCalled; 34 private int setNameCalled; 35 private int destroyCalled; 36 37 private Hashtable properties = new Hashtable (); 38 39 public static final String DESTROY = "Destroy"; 42 43 private GoldenValue[] goldenValues; 44 45 private PropertyChangeSupport propertyChangeSupport; 46 47 public SampleRepObject() {} 48 49 public SampleRepObject( GoldenValue[] goldenValues ) { 50 this.goldenValues = goldenValues; 51 } 52 53 55 public void attach() { 56 attachCalled++; 57 } 58 59 public void detach() { 60 detachCalled++; 61 } 62 63 public void setName() { 64 setNameCalled++; 65 } 66 67 public void destroy() { 68 destroyCalled++; 69 } 70 71 public int getAttachCalled() { 72 int r = attachCalled; 73 attachCalled = 0; 74 return r; 75 } 76 77 public int getDetachCalled() { 78 int r = detachCalled; 79 detachCalled = 0; 80 return r; 81 } 82 83 public int getSetNameCalled() { 84 int r = setNameCalled; 85 setNameCalled = 0; 86 return r; 87 } 88 89 public int getDestroyCalled() { 90 int r = destroyCalled; 91 destroyCalled = 0; 92 return r; 93 } 94 95 97 public Object getProperty( String key ) { 98 return properties.get( key ); 99 } 100 101 public void setProperty( String key, Object o ) { 102 Object oldValue = getProperty( key ); 103 properties.put( key, o ); 104 105 if ( propertyChangeSupport != null ) { 106 propertyChangeSupport.firePropertyChange( key, oldValue, o ); 107 } 108 } 109 110 112 public Object getValue( long key ) { 113 114 if ( goldenValues == null ) { 115 return null; 116 } 117 118 for( int i = 0; i < goldenValues.length; i++ ) { 119 if ( key == goldenValues[i].key ) { 120 return goldenValues[i].result; 121 } 122 } 123 return null; 124 } 125 126 public void setValue( long key, Object value ) { 127 128 if ( goldenValues == null ) { 129 goldenValues = new GoldenValue[] { 130 new GoldenValue( key, value ) 131 }; 132 return; 133 } 134 135 int index = -1; 137 138 for( int i = 0; i < goldenValues.length; i++ ) { 139 if ( key == goldenValues[i].key ) { 140 index = i; 141 } 142 } 143 144 Object oldValue = null; 145 146 if ( index == -1 ) { 148 GoldenValue[] newGvs = new GoldenValue[ goldenValues.length + 1 ]; 149 index = goldenValues.length; 150 System.arraycopy( goldenValues, 0, newGvs, 0, goldenValues.length ); 151 goldenValues = newGvs; 152 } 153 else { 154 oldValue = goldenValues[index].result; 155 } 156 157 goldenValues[index] = new GoldenValue( key, value ); 158 159 if ( propertyChangeSupport != null ) { 160 propertyChangeSupport.firePropertyChange( 161 Long.toString( goldenValues[index].key ), 162 oldValue, 163 value ); 164 165 166 } 167 168 169 } 170 171 173 public void addPropertyChangeListener( PropertyChangeListener listener ) { 174 if ( propertyChangeSupport == null ) { 175 propertyChangeSupport = new PropertyChangeSupport( this ); 176 } 177 178 propertyChangeSupport.addPropertyChangeListener( listener ); 179 } 180 181 182 public void removePropertyChangeListener( PropertyChangeListener listener ) { 183 if ( propertyChangeSupport == null ) { 184 return; 185 } 186 187 propertyChangeSupport.removePropertyChangeListener( listener ); 188 } 189 190 } 191 192 | Popular Tags |