aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/itmill/toolkit/ui/Button.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/itmill/toolkit/ui/Button.java')
-rw-r--r--src/com/itmill/toolkit/ui/Button.java282
1 files changed, 155 insertions, 127 deletions
diff --git a/src/com/itmill/toolkit/ui/Button.java b/src/com/itmill/toolkit/ui/Button.java
index 2b278caa86..b15d3b2da3 100644
--- a/src/com/itmill/toolkit/ui/Button.java
+++ b/src/com/itmill/toolkit/ui/Button.java
@@ -1,30 +1,30 @@
/* *************************************************************************
- IT Mill Toolkit
+ IT Mill Toolkit
- Development of Browser User Interfaces Made Easy
+ Development of Browser User Interfaces Made Easy
- Copyright (C) 2000-2006 IT Mill Ltd
-
- *************************************************************************
+ Copyright (C) 2000-2006 IT Mill Ltd
+
+ *************************************************************************
- This product is distributed under commercial license that can be found
- from the product package on license.pdf. Use of this product might
- require purchasing a commercial license from IT Mill Ltd. For guidelines
- on usage, see licensing-guidelines.html
+ This product is distributed under commercial license that can be found
+ from the product package on license.pdf. Use of this product might
+ require purchasing a commercial license from IT Mill Ltd. For guidelines
+ on usage, see licensing-guidelines.html
- *************************************************************************
-
- For more information, contact:
-
- IT Mill Ltd phone: +358 2 4802 7180
- Ruukinkatu 2-4 fax: +358 2 4802 7181
- 20540, Turku email: info@itmill.com
- Finland company www: www.itmill.com
-
- Primary source for information and releases: www.itmill.com
+ *************************************************************************
+
+ For more information, contact:
+
+ IT Mill Ltd phone: +358 2 4802 7180
+ Ruukinkatu 2-4 fax: +358 2 4802 7181
+ 20540, Turku email: info@itmill.com
+ Finland company www: www.itmill.com
+
+ Primary source for information and releases: www.itmill.com
- ********************************************************************** */
+ ********************************************************************** */
package com.itmill.toolkit.ui;
@@ -44,11 +44,12 @@ import com.itmill.toolkit.terminal.KeyMapper;
import com.itmill.toolkit.terminal.PaintException;
import com.itmill.toolkit.terminal.PaintTarget;
-/**
+/**
* A generic button component.
- *
+ *
* @author IT Mill Ltd.
- * @version @VERSION@
+ * @version
+ * @VERSION@
* @since 3.0
*/
public class Button extends AbstractField implements Action.Container {
@@ -56,63 +57,72 @@ public class Button extends AbstractField implements Action.Container {
/* Private members ************************************************* */
boolean switchMode = false;
-
+
/** List of action handlers */
private LinkedList actionHandlers = null;
/** Action mapper */
private KeyMapper actionMapper = null;
- /**
- * Creates a new push button.
- * The value of the push button is allways false and they are
- * immediate by default.
- *
+ /**
+ * Creates a new push button. The value of the push button is allways false
+ * and they are immediate by default.
+ *
*/
public Button() {
setSwitchMode(false);
}
- /**
+ /**
* Creates a new push button.
*
- * The value of the push button is allways false and they are
- * immediate by default.
+ * The value of the push button is allways false and they are immediate by
+ * default.
*
- * @param caption the Button caption.
+ * @param caption
+ * the Button caption.
*/
public Button(String caption) {
setCaption(caption);
setSwitchMode(false);
}
- /**
+ /**
* Creates a new push button with click listener.
- * @param caption the Button caption.
- * @param listener the Button click listener.
+ *
+ * @param caption
+ * the Button caption.
+ * @param listener
+ * the Button click listener.
*/
public Button(String caption, ClickListener listener) {
this(caption);
addListener(listener);
}
- /**
- * Creates a new push button with a method listening button clicks.
- * The method must have either no parameters, or only one parameter of
+ /**
+ * Creates a new push button with a method listening button clicks. The
+ * method must have either no parameters, or only one parameter of
* Button.ClickEvent type.
- * @param caption the Button caption.
- * @param target the Object having the method for listening button clicks.
- * @param methodName the name of the method in target object, that
- * receives button click events.
+ *
+ * @param caption
+ * the Button caption.
+ * @param target
+ * the Object having the method for listening button clicks.
+ * @param methodName
+ * the name of the method in target object, that receives button
+ * click events.
*/
public Button(String caption, Object target, String methodName) {
this(caption);
addListener(ClickEvent.class, target, methodName);
}
- /**
+ /**
* Creates a new switch button with initial value.
- * @param state the Initial state of the switch-button.
+ *
+ * @param state
+ * the Initial state of the switch-button.
* @param initialState
*/
public Button(String caption, boolean initialState) {
@@ -121,9 +131,11 @@ public class Button extends AbstractField implements Action.Container {
setSwitchMode(true);
}
- /**
+ /**
* Creates a new switch button that is connected to a boolean property.
- * @param state the Initial state of the switch-button.
+ *
+ * @param state
+ * the Initial state of the switch-button.
* @param dataSource
*/
public Button(String caption, Property dataSource) {
@@ -132,19 +144,24 @@ public class Button extends AbstractField implements Action.Container {
setPropertyDataSource(dataSource);
}
- /**
+ /**
* Gets component UIDL tag.
+ *
* @return the Component UIDL tag as string.
*/
public String getTag() {
return "button";
}
- /**
+ /**
* Paints the content of this component.
- * @param event the PaintEvent.
- * @throws IOException if the writing failed due to input/output error.
- * @throws PaintException if the paint operation failed.
+ *
+ * @param event
+ * the PaintEvent.
+ * @throws IOException
+ * if the writing failed due to input/output error.
+ * @throws PaintException
+ * if the paint operation failed.
*/
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
@@ -158,23 +175,19 @@ public class Button extends AbstractField implements Action.Container {
state = false;
}
target.addVariable(this, "state", state);
-
+
// Actions
if (actionHandlers != null) {
Set actionSet = new LinkedHashSet();
- for (Iterator ahi = actionHandlers.iterator();
- ahi.hasNext();
- ) {
- Action[] aa =
- ((Action.Handler) ahi.next()).getActions(
- this,
+ for (Iterator ahi = actionHandlers.iterator(); ahi.hasNext();) {
+ Action[] aa = ((Action.Handler) ahi.next()).getActions(this,
this);
if (aa != null)
for (int ai = 0; ai < aa.length; ai++) {
actionSet.add(aa[ai]);
}
}
-
+
target.startTag("actions");
target.addVariable(this, "action", "");
for (Iterator i = actionSet.iterator(); i.hasNext();) {
@@ -187,15 +200,15 @@ public class Button extends AbstractField implements Action.Container {
target.addAttribute("icon", a.getIcon());
target.addAttribute("key", actionMapper.key(a));
target.addAttribute("keycode", a.getKeyCode());
- if(a.getModifiers() != null) {
+ if (a.getModifiers() != null) {
int[] modifiers = a.getModifiers();
target.addAttribute("modifiers", modifiers.length);
- for(int j = 0; j < modifiers.length; j++) {
+ for (int j = 0; j < modifiers.length; j++) {
target.addAttribute("modifier" + j, modifiers[j]);
}
}
target.endTag("action");
- } catch( Exception e ){
+ } catch (Exception e) {
// ignore non-shorcut actions for button
}
}
@@ -203,10 +216,11 @@ public class Button extends AbstractField implements Action.Container {
}
}
- /**
- * Invoked when the value of a variable has changed. Button
- * listeners are notified if the button is clicked.
- * @param source
+ /**
+ * Invoked when the value of a variable has changed. Button listeners are
+ * notified if the button is clicked.
+ *
+ * @param source
* @param variables
*/
public void changeVariables(Object source, Map variables) {
@@ -217,11 +231,10 @@ public class Button extends AbstractField implements Action.Container {
if (isSwitchMode()) {
- // For switch button, the event is only sent if the
+ // For switch button, the event is only sent if the
// switch state is changed
- if (newValue != null
- && !newValue.equals(oldValue)
- && !isReadOnly()) {
+ if (newValue != null && !newValue.equals(oldValue)
+ && !isReadOnly()) {
setValue(newValue);
fireClick();
}
@@ -240,19 +253,14 @@ public class Button extends AbstractField implements Action.Container {
// TODO this is pretty much copy-pasted from tree, may be simplified
if (variables.containsKey("action")) {
- StringTokenizer st =
- new StringTokenizer((String) variables.get("action"), ",");
+ StringTokenizer st = new StringTokenizer((String) variables
+ .get("action"), ",");
if (st.countTokens() == 2) {
Action action = (Action) actionMapper.get(st.nextToken());
- if (action != null
- && actionHandlers != null)
- for (Iterator i = actionHandlers.iterator();
- i.hasNext();
- )
- ((Action.Handler) i.next()).handleAction(
- action,
- this,
- this);
+ if (action != null && actionHandlers != null)
+ for (Iterator i = actionHandlers.iterator(); i.hasNext();)
+ ((Action.Handler) i.next()).handleAction(action, this,
+ this);
}
}
@@ -260,7 +268,9 @@ public class Button extends AbstractField implements Action.Container {
/**
* Checks if it is switchMode.
- * @return <code>true</code> if it is in Switch Mode, otherwise <code>false</code>.
+ *
+ * @return <code>true</code> if it is in Switch Mode, otherwise
+ * <code>false</code>.
*/
public boolean isSwitchMode() {
return switchMode;
@@ -268,7 +278,9 @@ public class Button extends AbstractField implements Action.Container {
/**
* Sets the switchMode.
- * @param switchMode The switchMode to set.
+ *
+ * @param switchMode
+ * The switchMode to set.
*/
public void setSwitchMode(boolean switchMode) {
this.switchMode = switchMode;
@@ -278,9 +290,9 @@ public class Button extends AbstractField implements Action.Container {
}
}
- /**
- * Sets immediate mode.
- * Push buttons can not be set in non-immediate mode.
+ /**
+ * Sets immediate mode. Push buttons can not be set in non-immediate mode.
+ *
* @see com.itmill.toolkit.ui.AbstractComponent#setImmediate(boolean)
*/
public void setImmediate(boolean immediate) {
@@ -288,8 +300,9 @@ public class Button extends AbstractField implements Action.Container {
super.setImmediate(!isSwitchMode() || immediate);
}
- /**
+ /**
* The type of the button as a property.
+ *
* @see com.itmill.toolkit.data.Property#getType()
*/
public Class getType() {
@@ -301,39 +314,42 @@ public class Button extends AbstractField implements Action.Container {
private static final Method BUTTON_CLICK_METHOD;
static {
try {
- BUTTON_CLICK_METHOD =
- ClickListener.class.getDeclaredMethod(
- "buttonClick",
- new Class[] { ClickEvent.class });
+ BUTTON_CLICK_METHOD = ClickListener.class.getDeclaredMethod(
+ "buttonClick", new Class[] { ClickEvent.class });
} catch (java.lang.NoSuchMethodException e) {
// This should never happen
throw new java.lang.RuntimeException();
}
}
- /**
- * Click event. This event is thrown, when the button is clicked.
+ /**
+ * Click event. This event is thrown, when the button is clicked.
+ *
* @author IT Mill Ltd.
- * @version @VERSION@
+ * @version
+ * @VERSION@
* @since 3.0
*/
public class ClickEvent extends Component.Event {
/**
- * Serial generated by eclipse.
- */
- private static final long serialVersionUID = 3546647602931118393L;
+ * Serial generated by eclipse.
+ */
+ private static final long serialVersionUID = 3546647602931118393L;
- /**
- * New instance of text change event.
- * @param source the Source of the event.
+ /**
+ * New instance of text change event.
+ *
+ * @param source
+ * the Source of the event.
*/
public ClickEvent(Component source) {
super(source);
}
- /**
+ /**
* Gets the Button where the event occurred.
+ *
* @return the Source of the event.
*/
public Button getButton() {
@@ -341,45 +357,55 @@ public class Button extends AbstractField implements Action.Container {
}
}
- /**
+ /**
* Button click listener
+ *
* @author IT Mill Ltd.
- * @version @VERSION@
+ * @version
+ * @VERSION@
* @since 3.0
*/
public interface ClickListener {
- /**
+ /**
* Button has been pressed.
- * @param event Button click event.
+ *
+ * @param event
+ * Button click event.
*/
public void buttonClick(ClickEvent event);
}
- /**
+ /**
* Adds the button click listener.
- * @param listener the Listener to be added.
+ *
+ * @param listener
+ * the Listener to be added.
*/
public void addListener(ClickListener listener) {
addListener(ClickEvent.class, listener, BUTTON_CLICK_METHOD);
}
- /**
+ /**
* Removes the button click listener.
- * @param listener the Listener to be removed.
+ *
+ * @param listener
+ * the Listener to be removed.
*/
public void removeListener(ClickListener listener) {
removeListener(ClickEvent.class, listener, BUTTON_CLICK_METHOD);
}
- /**
- * Emits the options change event.
+ /**
+ * Emits the options change event.
*/
protected void fireClick() {
fireEvent(new Button.ClickEvent(this));
}
- /** Adds an action handler.
+ /**
+ * Adds an action handler.
+ *
* @see com.itmill.toolkit.event.Action.Container#addActionHandler(Action.Handler)
*/
public void addActionHandler(Action.Handler actionHandler) {
@@ -391,28 +417,30 @@ public class Button extends AbstractField implements Action.Container {
actionMapper = new KeyMapper();
}
- if(!actionHandlers.contains(actionHandler)){
- actionHandlers.add(actionHandler);
- requestRepaint();
- }
+ if (!actionHandlers.contains(actionHandler)) {
+ actionHandlers.add(actionHandler);
+ requestRepaint();
+ }
}
}
- /** Removes an action handler.
+ /**
+ * Removes an action handler.
+ *
* @see com.itmill.toolkit.event.Action.Container#removeActionHandler(Action.Handler)
*/
public void removeActionHandler(Action.Handler actionHandler) {
if (actionHandlers != null && actionHandlers.contains(actionHandler)) {
-
- actionHandlers.remove(actionHandler);
-
- if (actionHandlers.isEmpty()) {
- actionHandlers = null;
- actionMapper = null;
- }
-
- requestRepaint();
+
+ actionHandlers.remove(actionHandler);
+
+ if (actionHandlers.isEmpty()) {
+ actionHandlers = null;
+ actionMapper = null;
+ }
+
+ requestRepaint();
}
}
}