KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > swing > SwingLabel


1 /*
2   Copyright (C) 2001-2003 Renaud Pawlak <renaud@aopsys.com>,
3                           Laurent Martelli <laurent@aopsys.com>
4   
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU Lesser General Public License as
7   published by the Free Software Foundation; either version 2 of the
8   License, or (at your option) any later version.
9
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   GNU Lesser General Public License for more details.
14
15   You should have received a copy of the GNU Lesser General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */

18
19 package org.objectweb.jac.aspects.gui.swing;
20
21
22 import java.util.Arrays JavaDoc;
23 import javax.swing.JLabel JavaDoc;
24 import org.objectweb.jac.aspects.gui.Border;
25 import org.objectweb.jac.aspects.gui.DisplayContext;
26 import org.objectweb.jac.aspects.gui.Length;
27 import org.objectweb.jac.aspects.gui.View;
28 import org.objectweb.jac.aspects.gui.ViewFactory;
29 import org.objectweb.jac.aspects.gui.ViewIdentity;
30 import org.objectweb.jac.core.rtti.FieldItem;
31 import org.objectweb.jac.core.rtti.MethodItem;
32
33 public class SwingLabel extends JLabel JavaDoc implements View {
34
35     ViewFactory factory;
36     DisplayContext context;
37     Object JavaDoc[] parameters;
38     String JavaDoc type;
39    
40     public SwingLabel() {
41     }
42
43     Border viewBorder;
44    
45     /**
46      * Get the value of viewBorder.
47      * @return value of viewBorder.
48      */

49     public Border getViewBorder() {
50         return viewBorder;
51     }
52    
53     /**
54      * Set the value of viewBorder.
55      * @param v Value to assign to viewBorder.
56      */

57     public void setViewBorder(Border v) {
58         this.viewBorder = v;
59     }
60    
61
62     // style used to change display (css for web)
63
String JavaDoc style;
64
65     public void setStyle(String JavaDoc style) {
66         this.style = style;
67     }
68
69     public String JavaDoc getStyle() {
70         return style;
71     }
72
73
74     MethodItem message;
75    
76     /**
77      * Get the value of message.
78      * @return value of message.
79      */

80     public MethodItem getMessage() {
81         return message;
82     }
83    
84     /**
85      * Set the value of message.
86      * @param v Value to assign to message.
87      */

88     public void setMessage(MethodItem v) {
89         this.message = v;
90     }
91
92     public void setContext(DisplayContext context) {
93         this.context = context;
94     }
95     public DisplayContext getContext() {
96         return context;
97     }
98
99     String JavaDoc description;
100    
101     /**
102      * Get the value of description.
103      * @return value of description.
104      */

105     public String JavaDoc getDescription() {
106         return description;
107     }
108    
109     /**
110      * Set the value of description.
111      * @param v Value to assign to description.
112      */

113     public void setDescription(String JavaDoc v) {
114         this.description = v;
115     }
116    
117     View parentView;
118    
119     /**
120      * Get the value of parentView.
121      * @return value of parentView.
122      */

123     public View getParentView() {
124         return parentView;
125     }
126    
127     /**
128      * Set the value of parentView.
129      * @param v Value to assign to parentView.
130      */

131     public void setParentView(View v) {
132         this.parentView = v;
133     }
134
135     public View getRootView() {
136         if (parentView==null)
137             return this;
138         return parentView.getRootView();
139     }
140
141     public boolean isDescendantOf(View ancestor) {
142         if (this==ancestor)
143             return true;
144         else if (parentView==null)
145             return false;
146         else
147             return parentView.isDescendantOf(ancestor);
148     }
149
150     public void setLabel(String JavaDoc label) {
151         setText(label);
152     }
153
154     public String JavaDoc getLabel() {
155         return getText();
156     }
157
158     public void setSize(Length width, Length height) {
159         SwingUtils.setSize(this,width,height);
160     }
161
162     public void close(boolean validate) {
163         closed = true;
164     }
165
166     boolean closed = false;
167
168     public boolean isClosed() {
169         return closed;
170     }
171
172     public void setFactory(ViewFactory factory) {
173         this.factory = factory;
174     }
175
176     public ViewFactory getFactory() {
177         return factory;
178     }
179
180     public void setType(String JavaDoc type) {
181         this.type = type;
182     }
183
184     public String JavaDoc getType() {
185         return type;
186     }
187
188     public void setParameters(Object JavaDoc[] parameters) {
189         this.parameters = parameters;
190     }
191    
192     public Object JavaDoc[] getParameters() {
193         return parameters;
194     }
195
196     public boolean equalsView(ViewIdentity view) {
197         return
198             ( ( type!=null &&
199                 type.equals(view.getType()) )
200               || (type==null && view.getType()==null ) )
201             && ( ( parameters!=null &&
202                    Arrays.equals(parameters,view.getParameters()) )
203                  || (parameters==null && view.getParameters()==null) );
204     }
205
206     public boolean equalsView(String JavaDoc type, Object JavaDoc[] parameters) {
207         return this.type.equals(type)
208             && Arrays.equals(this.parameters,parameters);
209     }
210
211     public void setFocus(FieldItem field, Object JavaDoc option) {
212     }
213  
214     public String JavaDoc toString() {
215         return Integer.toString(hashCode());
216     }
217 }
218
Popular Tags