1 19 20 package org.netbeans.spi.looks; 21 22 import java.awt.Image ; 23 import java.awt.image.BufferedImage ; 24 import java.awt.datatransfer.Transferable ; 25 import java.awt.datatransfer.StringSelection ; 26 import java.beans.*; 27 import java.util.*; 28 import javax.swing.JPanel ; 29 30 31 import org.openide.nodes.*; 32 import org.openide.util.actions.SystemAction; 33 import org.openide.util.actions.CallableSystemAction; 34 import org.openide.util.HelpCtx; 35 import org.openide.util.datatransfer.NewType; 36 import org.openide.util.datatransfer.PasteType; 37 38 40 public class GoldenEvent { 41 42 private String name; 43 private Object oldValue, newValue; 44 private Node source; 45 private boolean isAdd; 46 private Node[] delta; 47 private int[] indices; 48 private int[] permutation; 49 50 51 53 public GoldenEvent( Node source, String name, Object oldValue, Object newValue ) { 54 this.source = source; 55 this.name = name; 56 this.oldValue = oldValue; 57 this.newValue = newValue; 58 } 59 60 62 public GoldenEvent( Node source, boolean isAdd, Node[] delta, int[] indices ) { 63 this.source = source; 64 this.isAdd = isAdd; 65 this.delta = delta; 66 this.indices = indices; 67 } 68 69 71 public GoldenEvent( Node source, int[] permutation ) { 72 this.source = source; 73 this.permutation = permutation; 74 } 75 76 public Class getRepresentedClass() { 77 if ( name == null ) { 78 if ( permutation == null ) { 79 return NodeMemberEvent.class; 80 } 81 else { 82 return NodeReorderEvent.class; 83 } 84 } 85 else { 86 return PropertyChangeEvent.class; 87 } 88 } 89 90 92 93 public boolean compareTo( Object ev ) { 94 if ( getRepresentedClass() != ev.getClass() ) { 95 return false; 96 } 97 98 if ( getRepresentedClass() == PropertyChangeEvent.class ) { 99 PropertyChangeEvent pe = (PropertyChangeEvent)ev; 100 return source.equals( pe.getSource() ) && 101 name.equals( pe.getPropertyName() ) && 102 oldValue == null ? pe.getOldValue() == null : oldValue.equals( pe.getOldValue() ) && 103 newValue == null ? pe.getNewValue() == null : newValue.equals( pe.getNewValue() ); 104 } 105 106 else if ( getRepresentedClass() == NodeMemberEvent.class ) { 107 NodeMemberEvent nme = (NodeMemberEvent) ev; 108 109 return source.equals( nme.getNode() ) && 110 isAdd == nme.isAddEvent() && 111 Arrays.equals( delta, nme.getDelta() ) && 112 Arrays.equals( indices, nme.getDeltaIndices() ); 113 } 114 115 else if ( getRepresentedClass() == NodeReorderEvent.class ) { 116 NodeReorderEvent nre = (NodeReorderEvent) ev; 117 118 return source.equals( nre.getNode() ) && 119 Arrays.equals( permutation, nre.getPermutation() ); 120 } 121 122 else { 123 return false; 124 } 125 } 126 127 131 public static boolean compare( List events, GoldenEvent[] goldenEvents, Class eventClass ) { 132 133 List filteredEvents = new ArrayList(); 134 if ( eventClass != null ) { 135 for ( Iterator it = events.iterator(); it.hasNext(); ) { 136 Object e = it.next(); 137 if ( e.getClass() == eventClass ) { 138 filteredEvents.add( e ); 139 } 140 } 141 } 142 else { 143 filteredEvents = events; 144 } 145 146 if ( filteredEvents.size() != goldenEvents.length ) { 147 return false; 148 } 149 150 for ( int i = 0; i < filteredEvents.size(); i++ ) { 151 if ( !goldenEvents[i].compareTo( filteredEvents.get( i ) ) ) { 152 return false; 153 } 154 } 155 156 return true; 157 } 158 159 public static void printEvents( List events ) { 160 161 for ( Iterator it = events.iterator(); it.hasNext(); ) { 162 Object e = it.next(); 163 164 if ( e instanceof PropertyChangeEvent ) { 165 System.out.println("PCHG : " + ((PropertyChangeEvent)e).getPropertyName() + " : " + ((PropertyChangeEvent)e).getSource() ); 166 System.out.println(" new : " + ((PropertyChangeEvent)e).getOldValue() ); 167 System.out.println(" old : " + ((PropertyChangeEvent)e).getNewValue() ); 168 } 169 170 if ( e instanceof NodeMemberEvent ) { 171 NodeMemberEvent ne = (NodeMemberEvent) e; 172 System.out.println( ( ne.isAddEvent() ? "cADD : " : "cRMV : " ) + ne.getNode().getName() ); 173 174 Node[] delta = ne.getDelta(); 175 if ( delta == null ) { 176 System.out.println("d : " + null ); 177 } 178 else { 179 System.out.println("d : " ); 180 for( int i = 0; i < delta.length; i++ ) { 181 System.out.println(" " + delta[i].getName() ); 182 } 183 } 184 185 int[] deltaIdx = ne.getDeltaIndices(); 186 if ( deltaIdx == null ) { 187 System.out.println("di : " + null ); 188 } 189 else { 190 System.out.println("di : " ); 191 for( int i = 0; i < deltaIdx.length; i++ ) { 192 System.out.println(" " + deltaIdx[i] ); 193 } 194 } 195 196 } 197 198 if ( e instanceof NodeReorderEvent ) { 199 NodeReorderEvent ne = (NodeReorderEvent) e; 200 System.out.println( ( "RORD: " ) + ne.getNode().getName() ); 201 202 int[] perm = ne.getPermutation(); 203 if ( perm == null ) { 204 System.out.println("d : " + null ); 205 } 206 else { 207 System.out.println("d : " ); 208 for( int i = 0; i < perm.length; i++ ) { 209 System.out.println(" " + perm[i] ); 210 } 211 } 212 213 } 214 215 } 216 } 217 218 219 public static class Listener implements NodeListener { 220 221 private List events = new ArrayList(); 222 223 224 public void propertyChange(PropertyChangeEvent evt) { 225 events.add( evt ); 226 } 227 228 public void nodeDestroyed(NodeEvent evt) { 229 events.add( evt ); 230 } 231 232 public void childrenReordered(NodeReorderEvent evt) { 233 events.add( evt ); 234 } 235 236 public void childrenRemoved(NodeMemberEvent evt) { 237 events.add( evt ); 238 } 239 240 public void childrenAdded(NodeMemberEvent evt) { 241 events.add( evt ); 242 } 243 244 public List getEvents() { 245 return events; 246 } 247 248 } 249 250 } 251 252 | Popular Tags |