KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > web > Method


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 org.objectweb.jac.aspects.gui.web;
19
20 import java.io.PrintWriter JavaDoc;
21 import org.objectweb.jac.aspects.gui.*;
22 import org.objectweb.jac.aspects.gui.web.html.Element;
23 import org.objectweb.jac.aspects.gui.InvokeEvent;
24 import org.objectweb.jac.aspects.gui.MethodView;
25 import org.objectweb.jac.core.rtti.AbstractMethodItem;
26 import org.objectweb.jac.core.rtti.MethodItem;
27
28 public class Method extends AbstractView
29     implements MethodView, HTMLViewer, MethodListener
30 {
31     protected Object JavaDoc substance;
32     protected AbstractMethodItem method;
33     protected String JavaDoc icon;
34     protected boolean onlyIcon = false; // If true, only show the icon
35

36     public Method(Object JavaDoc substance, AbstractMethodItem method) {
37         this.substance = substance;
38         this.method = method;
39     }
40
41     // MethodView interface
42

43     public void setMethod(AbstractMethodItem method) {
44         this.method = method;
45     }
46
47     public void setIcon(String JavaDoc icon) {
48         this.icon = icon;
49     }
50
51     public void setOnlyIcon(boolean onlyIcon) {
52         this.onlyIcon = onlyIcon;
53     }
54
55     /**
56      * Returns the text of the button
57      */

58     protected String JavaDoc getText() {
59         if (method instanceof MethodItem &&
60             ((MethodItem)method).isSetter() && icon!=null)
61             return "";
62         else
63             return label;
64     }
65
66     // HTMLViewer interface
67

68     public void genHTML(PrintWriter JavaDoc out) {
69         JacRequest request = WebDisplay.getRequest();
70         Element iconElt = iconElement(icon,label,false).addCssClass("first");
71         if (onlyIcon) {
72             iconElt.addCssClass("last");
73         }
74         String JavaDoc button =
75             eventURL(iconElt+(onlyIcon?"":getText()),
76                      "onInvoke","").toString();
77         if (request.isIEUserAgent()) {
78             out.print("<table class=\"method\"><tr><td>"+
79                       button+"</td></tr></table>");
80         } else {
81             out.print(button);
82         }
83     }
84
85     // MethodListener interface
86

87     public void onInvoke() {
88         EventHandler.get().onInvoke(
89             context,
90             new InvokeEvent(this,substance,method));
91     }
92
93     public String JavaDoc toString() {
94         return super.toString()+":"+method.getLongName();
95     }
96     
97 }
98
99
Popular Tags