001 /* 002 Copyright (C) 2002-2003 Laurent Martelli <laurent@aopsys.com> 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, 010 but WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 GNU Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public License 015 along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 017 018 package org.objectweb.jac.aspects.gui.web; 019 020 import java.io.PrintWriter; 021 import org.objectweb.jac.aspects.gui.*; 022 import org.objectweb.jac.aspects.gui.web.html.Element; 023 import org.objectweb.jac.aspects.gui.InvokeEvent; 024 import org.objectweb.jac.aspects.gui.MethodView; 025 import org.objectweb.jac.core.rtti.AbstractMethodItem; 026 import org.objectweb.jac.core.rtti.MethodItem; 027 028 public class Method extends AbstractView 029 implements MethodView, HTMLViewer, MethodListener 030 { 031 protected Object substance; 032 protected AbstractMethodItem method; 033 protected String icon; 034 protected boolean onlyIcon = false; // If true, only show the icon 035 036 public Method(Object substance, AbstractMethodItem method) { 037 this.substance = substance; 038 this.method = method; 039 } 040 041 // MethodView interface 042 043 public void setMethod(AbstractMethodItem method) { 044 this.method = method; 045 } 046 047 public void setIcon(String icon) { 048 this.icon = icon; 049 } 050 051 public void setOnlyIcon(boolean onlyIcon) { 052 this.onlyIcon = onlyIcon; 053 } 054 055 /** 056 * Returns the text of the button 057 */ 058 protected String getText() { 059 if (method instanceof MethodItem && 060 ((MethodItem)method).isSetter() && icon!=null) 061 return ""; 062 else 063 return label; 064 } 065 066 // HTMLViewer interface 067 068 public void genHTML(PrintWriter out) { 069 JacRequest request = WebDisplay.getRequest(); 070 Element iconElt = iconElement(icon,label,false).addCssClass("first"); 071 if (onlyIcon) { 072 iconElt.addCssClass("last"); 073 } 074 String button = 075 eventURL(iconElt+(onlyIcon?"":getText()), 076 "onInvoke","").toString(); 077 if (request.isIEUserAgent()) { 078 out.print("<table class=\"method\"><tr><td>"+ 079 button+"</td></tr></table>"); 080 } else { 081 out.print(button); 082 } 083 } 084 085 // MethodListener interface 086 087 public void onInvoke() { 088 EventHandler.get().onInvoke( 089 context, 090 new InvokeEvent(this,substance,method)); 091 } 092 093 public String toString() { 094 return super.toString()+":"+method.getLongName(); 095 } 096 097 } 098