1 package org.apache.cocoon.forms.formmodel; 16 17 import org.apache.cocoon.environment.Request; 18 import org.apache.cocoon.forms.FormContext; 19 import org.apache.cocoon.forms.event.*; 20 import org.apache.cocoon.xml.AttributesImpl; 21 22 34 public class ImageMap extends AbstractWidget implements ActionListenerEnabled { 35 36 private final ImageMapDefinition definition; 37 private ActionListener listener; 38 private String imgURI; private int x; private int y; 42 public static final String COMMAND_AT = "command"; 44 public static final String VALUE_EL = "imageuri"; 45 public static final String ONACTION_EL = "on-action"; 46 public static final String IMAGEMAP_EL = "imagemap"; 47 48 public ImageMap(ImageMapDefinition definition) { 49 super(definition); 50 this.definition = definition; 51 this.imgURI= definition.getImageURI(); 52 this.x= 0; 53 this.y= 0; 54 } 55 56 public WidgetDefinition getDefinition() { 57 return this.definition; 58 } 59 60 public int getX() { 62 return this.x; 63 } 64 65 public int getY() { 66 return this.y; 67 } 68 69 public String getImageURI() { 71 if ( this.imgURI != null ) { 72 return this.imgURI; 73 } else { 74 return ""; 75 } 76 } 77 78 public void setImageURI(String newImgURI) { 79 this.imgURI= newImgURI; 80 } 81 82 public void setValue(Object newImgURI) { 84 this.setImageURI(newImgURI.toString()); 85 } 86 87 public Object getValue() { 88 return this.getImageURI(); 89 } 90 91 public void readFromRequest(final FormContext formContext) { 92 if (!getCombinedState().isAcceptingInputs()) 93 return; 94 95 Form form = getForm(); 96 97 String fullId = getRequestParameterName(); 99 Request request = formContext.getRequest(); 100 101 try { 103 this.x= (new Integer (formContext.getRequest().getParameter(fullId + ".x"))).intValue(); 104 this.y= (new Integer (formContext.getRequest().getParameter(fullId + ".y"))).intValue(); 105 } catch (java.lang.NumberFormatException e) { 106 this.x= 0; 107 this.y= 0; 108 } 109 110 String value = request.getParameter(fullId); 111 if (value != null && value.length() > 0) { 112 form.setSubmitWidget(this); 113 114 } else { 115 value = request.getParameter(fullId + ".x"); 122 if ((value != null) && value.length() > 0) { 123 form.setSubmitWidget(this); 124 } 125 } 126 127 if (form.getSubmitWidget() == this) { 128 form.addWidgetEvent(new ImageMapEvent(this, definition.getActionCommand())); 129 130 handleActivate(); 131 } 132 } 133 134 137 public AttributesImpl getXMLElementAttributes() { 138 AttributesImpl attrs = super.getXMLElementAttributes(); 139 attrs.addCDATAAttribute("imageuri", this.imgURI); 140 return attrs; 141 } 142 143 148 protected void handleActivate() { 149 getForm().endProcessing(true); 150 } 151 152 155 public boolean validate() { 156 return true; 157 } 158 159 public String getXMLElementName() { 160 return IMAGEMAP_EL; 161 } 162 163 168 public void addActionListener(ActionListener listener) { 169 this.listener = WidgetEventMulticaster.add(this.listener, listener); 170 } 171 172 public void removeActionListener(ActionListener listener) { 173 this.listener = WidgetEventMulticaster.remove(this.listener, listener); 174 } 175 176 private void fireActionEvent(ActionEvent event) { 177 if (this.listener != null) { 178 this.listener.actionPerformed(event); 179 } 180 } 181 182 public void broadcastEvent(WidgetEvent event) { 183 if (event instanceof ActionEvent) { 184 this.definition.fireActionEvent((ActionEvent)event); 185 fireActionEvent((ActionEvent)event); 186 } else { 187 super.broadcastEvent(event); 189 } 190 } 191 192 } 193 | Popular Tags |