Articles/Window/OpenWindowNearButton: Button.diff
| File Button.diff, 3.6 kB (added by Mauno Haukila, 4 months ago) |
|---|
-
Button.java
131 131 public void paintContent(PaintTarget target) throws PaintException { 132 132 super.paintContent(target); 133 133 134 if (isSwitchMode()) {135 target.addAttribute("type", "switch");136 }137 134 boolean state; 138 135 try { 139 136 state = ((Boolean) getValue()).booleanValue(); 140 137 } catch (final NullPointerException e) { 141 138 state = false; 142 139 } 143 target.addVariable(this, "state", state); 140 if (isSwitchMode()) { 141 target.addAttribute("type", "switch"); 142 target.addVariable(this, "state", state); 143 } else { 144 target.addVariable(this, "clientX",-1); 145 target.addVariable(this, "clientY",-1); 146 } 144 147 145 148 } 146 149 … … 159 162 final Boolean newValue = (Boolean) variables.get("state"); 160 163 final Boolean oldValue = (Boolean) getValue(); 161 164 162 if (isSwitchMode()) { 165 // For switch button, the event is only sent if the 166 // switch state is changed 167 if (newValue != null && !newValue.equals(oldValue) && !isReadOnly()) { 168 setValue(newValue); 169 fireClick(); 170 } 163 171 164 // For switch button, the event is only sent if the 165 // switch state is changed 166 if (newValue != null && !newValue.equals(oldValue) 167 && !isReadOnly()) { 168 setValue(newValue); 169 fireClick(); 170 } 171 } else { 172 } else if (!isReadOnly() && variables.containsKey("clientX")) { 173 // Only send click event if the button is pushed 174 final Integer clientX = (Integer) variables.get("clientX"); 175 final Integer clientY = (Integer) variables.get("clientY"); 176 final Boolean oldValue = (Boolean) getValue(); 177 fireClick(clientX, clientY); 172 178 173 // Only send click event if the button is pushed 174 if (newValue.booleanValue()) { 175 fireClick(); 176 } 177 178 // If the button is true for some reason, release it 179 if (oldValue.booleanValue()) { 180 setValue(new Boolean(false)); 181 } 179 // If the button is true for some reason, release it 180 if (oldValue.booleanValue()) { 181 setValue(new Boolean(false)); 182 182 } 183 183 } 184 184 } … … 262 262 * @since 3.0 263 263 */ 264 264 public class ClickEvent extends Component.Event { 265 265 private int clientX = -1; 266 private int clientY = -1; 266 267 /** 267 268 * Serial generated by eclipse. 268 269 */ … … 278 279 super(source); 279 280 } 280 281 282 public ClickEvent(Component source, int positionX, int positionY) { 283 this(source); 284 clientX = positionX; 285 clientY = positionY; 286 } 287 281 288 /** 282 289 * Gets the Button where the event occurred. 283 290 * … … 286 293 public Button getButton() { 287 294 return (Button) getSource(); 288 295 } 296 297 public int getClientX() { 298 return clientX; 299 } 300 301 public int getClientY() { 302 return clientY; 303 } 289 304 } 290 305 291 306 /** … … 333 348 protected void fireClick() { 334 349 fireEvent(new Button.ClickEvent(this)); 335 350 } 336 351 protected void fireClick(int clientX, int clientY) { 352 fireEvent(new Button.ClickEvent(this,clientX,clientY)); 353 } 337 354 }
