1 19 20 package org.openide.explorer.propertysheet; 21 22 import java.awt.BorderLayout ; 23 import java.awt.Color ; 24 import java.awt.Component ; 25 import java.awt.Dialog ; 26 import java.awt.Graphics ; 27 import java.awt.KeyboardFocusManager ; 28 import java.awt.Rectangle ; 29 import java.awt.event.KeyEvent ; 30 import java.awt.event.MouseEvent ; 31 import org.openide.nodes.AbstractNode; 32 import org.openide.util.HelpCtx; 33 import org.openide.nodes.Children; 34 import org.openide.nodes.Sheet; 35 import org.openide.nodes.PropertySupport; 36 import java.lang.reflect.InvocationTargetException ; 37 import java.beans.PropertyEditor ; 38 import java.beans.PropertyChangeListener ; 39 import javax.swing.JComponent ; 40 import javax.swing.JFrame ; 41 import javax.swing.JTextArea ; 42 import javax.swing.SwingUtilities ; 43 import org.openide.explorer.propertysheet.ExtTestCase.WaitWindow; 44 import org.openide.nodes.Node; 45 46 50 public class NonEditabilityTest extends ExtTestCase { 51 52 public NonEditabilityTest(String name) { 53 super(name); 54 } 55 56 protected boolean runInEQ() { 57 return false; 58 } 59 60 private PropertySheet sheet = null; 61 private JFrame frame = null; 62 protected void setUp() throws Exception { 63 PropUtils.putSortOrder(PropertySheet.UNSORTED); 65 66 JFrame jf = new JFrame (); 67 jf.getContentPane().setLayout(new BorderLayout ()); 68 sheet = new PropertySheet(); 69 jf.getContentPane().add (sheet); 70 71 jf.setBounds (20, 20, 200, 400); 72 frame = jf; 73 new WaitWindow(jf); 74 } 75 76 public void testClickInvokesCustomEditor() throws Exception { 77 if( !ExtTestCase.canSafelyRunFocusTests() ) 78 return; 79 80 Node n = new ANode(); 81 setCurrentNode (n, sheet); 82 83 sleep(); 84 85 requestFocus (sheet.table); 86 sleep(); 87 88 Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); 89 if (owner == sheet.table) { 91 System.out.println ("About to click cell"); 92 93 Rectangle r = sheet.table.getCellRect(1, 1, false); 94 final MouseEvent me = new MouseEvent (sheet.table, MouseEvent.MOUSE_PRESSED, 95 System.currentTimeMillis(), MouseEvent.BUTTON1_MASK, r.x + 3, 96 r.y + 3, 2, false); 97 98 SwingUtilities.invokeLater(new Runnable () { 99 public void run() { 100 sheet.table.dispatchEvent(me); 101 } 102 }); 103 104 sleep(); 105 sleep(); 106 107 System.out.println ("Now checking focus"); 108 109 owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); 110 assertTrue ("Focus owner should be custom editor, not " + owner, owner instanceof JTextArea ); 111 112 JComponent jc = (JComponent ) owner; 113 assertTrue ("Custom editor should have been invoked, but focus owner's top level ancestor is not a dialog", jc.getTopLevelAncestor() instanceof Dialog ); 114 115 Dialog d = (Dialog ) jc.getTopLevelAncestor(); 116 117 d.setVisible(false); 118 } 119 120 requestFocus (sheet.table); 121 sleep(); 122 123 owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); 124 if (owner == sheet.table) { pressKey(sheet.table, KeyEvent.VK_SPACE); 126 sleep(); 127 128 owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); 129 assertTrue ("After pressing a key, focus owner should still be the table, not " + owner, sheet.table == owner); 130 } 131 132 } 133 134 private static final class ANode extends AbstractNode { 135 public ANode() { 136 super(Children.LEAF); 137 } 138 public HelpCtx getHelpCtx() { 139 return new HelpCtx("node-help"); 140 } 141 protected Sheet createSheet() { 142 Sheet s = super.createSheet(); 143 Sheet.Set ss = Sheet.createPropertiesSet(); 144 ss.put (new AProperty()); 145 ss.put (new AProperty()); 146 s.put(ss); 147 return s; 148 } 149 } 150 151 private static final String name = "foo"; 152 private static final class AProperty extends PropertySupport.ReadOnly { 153 public AProperty() { 154 super(name, String .class, name, name); 155 } 156 public Object getValue() throws IllegalAccessException , InvocationTargetException { 157 return "value-" + getName(); 158 } 159 160 public PropertyEditor getPropertyEditor() { 161 return new APropertyEditor(); 162 } 163 } 164 165 private static final class APropertyEditor implements PropertyEditor { 166 public void setValue(Object value) { 167 168 } 169 170 public Object getValue() { 171 return null; 172 } 173 174 public boolean isPaintable() { 175 return true; 176 } 177 178 public void paintValue(Graphics gfx, Rectangle box) { 179 gfx.setColor (Color.ORANGE); 180 gfx.fillRect (box.x, box.y, box.width, box.height); 181 } 182 183 public String getJavaInitializationString() { 184 return null; 185 } 186 187 public String getAsText() { 188 return null; 189 } 190 191 public void setAsText(String text) throws IllegalArgumentException { 192 193 } 194 195 public String [] getTags() { 196 return null; 197 } 198 199 public Component getCustomEditor() { 200 return new JTextArea (); 201 } 202 203 public boolean supportsCustomEditor() { 204 return true; 205 } 206 207 public void addPropertyChangeListener(PropertyChangeListener listener) { 208 209 } 210 211 public void removePropertyChangeListener(PropertyChangeListener listener) { 212 213 } 214 } 215 } 216 | Popular Tags |