Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jac/aspects/gui/web/Method.java


1   /*
2     Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com>
3     
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU Lesser General Public License as
6     published by the Free Software Foundation; either version 2 of the
7     License, or (at your option) any later version.
8   
9     This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU Lesser General Public License for more details.
13  
14    You should have received a copy of the GNU Lesser General Public License
15    along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
17  
18  package jac.aspects.gui.web;
19  
20  import jac.aspects.gui.*;
21  import jac.aspects.gui.MethodView;
22  import jac.core.rtti.AbstractMethodItem;
23  import jac.core.rtti.MethodItem;
24  import jac.util.Log;
25  import java.io.PrintWriter;
26  import javax.swing.ImageIcon;
27  
28  public class Method extends AbstractView 
29     implements MethodView, HTMLViewer, MethodListener
30  {
31     Object substance;
32     AbstractMethodItem method;
33     String icon;
34  
35     public Method(Object substance, AbstractMethodItem method) {
36        this.substance = substance;
37        this.method = method;
38     }
39  
40     // MethodView interface
41  
42     public void setMethod(AbstractMethodItem method) {
43        this.method = method;
44     }
45  
46     public void setIcon(String icon) {
47        this.icon = icon;
48     }
49  
50     /**
51      * Returns the text of the button
52      */
53     protected String getText() {
54        if (method instanceof MethodItem && 
55            ((MethodItem)method).isSetter() && icon!=null)
56           return "";
57        else
58           return label;
59     }
60  
61     // HTMLViewer interface
62  
63     public void genHTML(PrintWriter out) {
64        JacRequest request = ((WebDisplay)context.getDisplay()).getRequest();
65        if (request.isIEUserAgent()) {
66           out.println("<table class=\"method\"><tr><td>"+
67                       eventURL(iconElement(icon,label,false)+getText(),"onInvoke","")+
68                       "</td></tr></table>");
69        } else {
70           out.println("<span class=\"method\">"+
71                       eventURL(iconElement(icon,label,false)+getText(),"onInvoke","")+
72                       "</span>");
73        }
74     }
75  
76     // MethodListener interface
77  
78     public void onInvoke() {
79        Log.trace("gui.events",
80                  "action performed on MethodView "+method.getName());
81        EventHandler.get().onInvoke(context,substance,method);
82     }
83  }
84