001 /* 002 Copyright (C) 2001-2003 Renaud Pawlak <renaud@aopsys.com>, 003 Laurent Martelli <laurent@aopsys.com> 004 005 This program is free software; you can redistribute it and/or modify 006 it under the terms of the GNU Lesser General Public License as 007 published by the Free Software Foundation; either version 2 of the 008 License, or (at your option) any later version. 009 010 This program is distributed in the hope that it will be useful, 011 but WITHOUT ANY WARRANTY; without even the implied warranty of 012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 GNU Lesser General Public License for more details. 014 015 You should have received a copy of the GNU Lesser General Public License 016 along with this program; if not, write to the Free Software 017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ 018 019 package org.objectweb.jac.aspects.gui.swing; 020 021 022 import java.util.Arrays; 023 import javax.swing.JLabel; 024 import org.objectweb.jac.aspects.gui.Border; 025 import org.objectweb.jac.aspects.gui.DisplayContext; 026 import org.objectweb.jac.aspects.gui.View; 027 import org.objectweb.jac.aspects.gui.ViewFactory; 028 import org.objectweb.jac.aspects.gui.ViewIdentity; 029 import org.objectweb.jac.core.rtti.FieldItem; 030 import org.objectweb.jac.core.rtti.MethodItem; 031 032 public class SwingLabel extends JLabel implements View { 033 034 ViewFactory factory; 035 DisplayContext context; 036 Object[] parameters; 037 String type; 038 039 public SwingLabel() { 040 } 041 042 Border viewBorder; 043 044 /** 045 * Get the value of viewBorder. 046 * @return value of viewBorder. 047 */ 048 public Border getViewBorder() { 049 return viewBorder; 050 } 051 052 /** 053 * Set the value of viewBorder. 054 * @param v Value to assign to viewBorder. 055 */ 056 public void setViewBorder(Border v) { 057 this.viewBorder = v; 058 } 059 060 061 // style used to change display (css for web) 062 String style; 063 064 public void setStyle(String style) { 065 this.style = style; 066 } 067 068 public String getStyle() { 069 return style; 070 } 071 072 073 MethodItem message; 074 075 /** 076 * Get the value of message. 077 * @return value of message. 078 */ 079 public MethodItem getMessage() { 080 return message; 081 } 082 083 /** 084 * Set the value of message. 085 * @param v Value to assign to message. 086 */ 087 public void setMessage(MethodItem v) { 088 this.message = v; 089 } 090 091 public void setContext(DisplayContext context) { 092 this.context = context; 093 } 094 public DisplayContext getContext() { 095 return context; 096 } 097 098 String description; 099 100 /** 101 * Get the value of description. 102 * @return value of description. 103 */ 104 public String getDescription() { 105 return description; 106 } 107 108 /** 109 * Set the value of description. 110 * @param v Value to assign to description. 111 */ 112 public void setDescription(String v) { 113 this.description = v; 114 } 115 116 View parentView; 117 118 /** 119 * Get the value of parentView. 120 * @return value of parentView. 121 */ 122 public View getParentView() { 123 return parentView; 124 } 125 126 /** 127 * Set the value of parentView. 128 * @param v Value to assign to parentView. 129 */ 130 public void setParentView(View v) { 131 this.parentView = v; 132 } 133 134 public View getRootView() { 135 if (parentView==null) 136 return this; 137 return parentView.getRootView(); 138 } 139 140 public boolean isDescendantOf(View ancestor) { 141 if (this==ancestor) 142 return true; 143 else if (parentView==null) 144 return false; 145 else 146 return parentView.isDescendantOf(ancestor); 147 } 148 149 public void setLabel(String label) { 150 setText(label); 151 } 152 153 public String getLabel() { 154 return getText(); 155 } 156 157 public void setWidth(int width) { 158 } 159 160 public void setHeight(int height) { 161 } 162 163 164 public void close(boolean validate) { 165 closed = true; 166 } 167 168 boolean closed = false; 169 170 public boolean isClosed() { 171 return closed; 172 } 173 174 public void setFactory(ViewFactory factory) { 175 this.factory = factory; 176 } 177 178 public ViewFactory getFactory() { 179 return factory; 180 } 181 182 public void setType(String type) { 183 this.type = type; 184 } 185 186 public String getType() { 187 return type; 188 } 189 190 public void setParameters(Object[] parameters) { 191 this.parameters = parameters; 192 } 193 194 public Object[] getParameters() { 195 return parameters; 196 } 197 198 public boolean equalsView(ViewIdentity view) { 199 return 200 ( ( type!=null && 201 type.equals(view.getType()) ) 202 || (type==null && view.getType()==null ) ) 203 && ( ( parameters!=null && 204 Arrays.equals(parameters,view.getParameters()) ) 205 || (parameters==null && view.getParameters()==null) ); 206 } 207 208 public boolean equalsView(String type, Object[] parameters) { 209 return this.type.equals(type) 210 && Arrays.equals(this.parameters,parameters); 211 } 212 213 public void setFocus(FieldItem field, Object option) { 214 } 215 216 public String toString() { 217 return Integer.toString(hashCode()); 218 } 219 }