View Javadoc
1 package com.tirsen.angkor.widget; 2 3 import com.tirsen.angkor.Controller; 4 import com.tirsen.angkor.Debug; 5 import com.tirsen.angkor.RenderContext; 6 import com.tirsen.angkor.ViewLink; 7 import com.tirsen.angkor.Component; 8 import com.tirsen.angkor.event.AbstractAction; 9 import com.tirsen.angkor.event.Action; 10 import com.tirsen.angkor.event.ActionEvent; 11 import com.tirsen.angkor.event.ActionListener; 12 import com.tirsen.angkor.event.ActionSource; 13 import com.tirsen.angkor.event.ActionSourceHelper; 14 import org.apache.log4j.Category; 15 16 import java.io.IOException; 17 18 /*** 19 * This has essentially been refactored into something almost exactly similar to {@link Link}. 20 * TODO refactor this into Link and remove this class and all its uses. 21 * 22 * <!-- $Id: MenuItem.java,v 1.6 2002/10/13 19:59:23 tirsen Exp $ --> 23 * <!-- $Author: tirsen $ --> 24 * 25 * @author Jon Tirsén (tirsen@users.sourceforge.net) 26 * @version $Revision: 1.6 $ 27 */ 28 public class MenuItem extends Component implements ActionSource 29 { 30 private static final Category logger = Category.getInstance(Debug.LOGGER_NAME); 31 32 private String text; 33 private ActionSourceHelper actionSourceHelper = new ActionSourceHelper(this); 34 35 public MenuItem(Action action) 36 { 37 setAction(action); 38 } 39 40 /*** 41 * The specified text or if specified text is <code>null</code> the name of the action. 42 */ 43 public String getText() 44 { 45 String ret = text; 46 if (ret == null && getAction() != null) ret = (String) getAction().getValue(Action.NAME); 47 return ret; 48 } 49 50 public void setText(String text) 51 { 52 this.text = text; 53 } 54 55 public boolean isParsing() 56 { 57 return true; 58 } 59 60 public void parse(RenderContext context) 61 { 62 super.parse(context); 63 if ("clicked".equals(context.getRequestParameter(getId()))) 64 { 65 click(context); 66 } 67 } 68 69 public static class GotoAction extends AbstractAction 70 { 71 private ViewLink link; 72 private String linkName; 73 private Controller target; 74 75 public GotoAction(String linkName, Controller target) 76 { 77 super(target.getDisplayName()); 78 this.linkName = linkName; 79 this.target = target; 80 } 81 82 public GotoAction(ViewLink link, Controller target) 83 { 84 super(target.getDisplayName()); 85 this.link = link; 86 this.target = target; 87 } 88 89 public void actionPerformed(ActionEvent evt) 90 { 91 logger.debug("going to " + target); 92 if (linkName != null) target.getApplication().relink(linkName, target); 93 if (link != null) link.relink(target); 94 } 95 96 public boolean isViewShown() 97 { 98 boolean result = false; 99 if (target == null) 100 result = false; 101 else if (linkName != null) 102 result = (target == target.getApplication().getComponent(linkName)); 103 else if (link != null) result = target == link.getTarget(); 104 return result; 105 } 106 107 public boolean isEnabled() 108 { 109 return super.isEnabled() && !isViewShown(); 110 } 111 } 112 113 public void click(RenderContext context) 114 { 115 logger.info("" + this + " was clicked."); 116 actionSourceHelper.signalActionEvent(context); 117 } 118 119 public void render(RenderContext context) throws IOException 120 { 121 if (isVisible()) 122 { 123 if (!isEnabled()) 124 { 125 // render as disabled 126 context.startTag("SPAN id=\"" + uniqueId(context) + "\""); 127 context.println(getText()); 128 context.endTag("SPAN"); 129 } 130 else 131 { 132 String url = context.requestURL(uniqueId(context) + "=clicked"); 133 context.startTag("A id=\"" + uniqueId(context) + "\" href=\"" + url + "\""); 134 context.println(getText()); 135 context.endTag("A"); 136 context.registerParsingComponent(this); 137 } 138 context.println(" "); 139 } 140 } 141 142 public boolean isEnabled() 143 { 144 return getAction().isEnabled(); 145 } 146 147 public Action getAction() 148 { 149 return actionSourceHelper.getAction(); 150 } 151 152 public void setAction(Action action) 153 { 154 actionSourceHelper.setAction(action); 155 } 156 157 public void addActionListener(ActionListener listener) 158 { 159 actionSourceHelper.addActionListener(listener); 160 } 161 162 public void removeActionListener(ActionListener listener) 163 { 164 actionSourceHelper.removeActionListener(listener); 165 } 166 167 public void signalActionEvent() 168 { 169 actionSourceHelper.signalActionEvent(); 170 } 171 }

This page was automatically generated by Maven