Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.ui / src / main / java / org / gvsig / gui / beans / panelGroup / panels / AbstractPanel.java @ 40561

History | View | Annotate | Download (7.24 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.gui.beans.panelGroup.panels;
25

    
26
import java.awt.Dimension;
27

    
28
import javax.swing.JPanel;
29

    
30
import org.gvsig.gui.beans.panelGroup.AbstractPanelGroup;
31

    
32
/**
33
 * <p>Represents a {@link JPanel JPanel} adapted to work as a panel of an {@link AbstractPanelGroup  AbstractPanelGroup}.</p>
34
 *  
35
 * @see JPanel
36
 * @see IPanel
37
 * 
38
 * @see AbstractPanelGroup
39
 * 
40
 * @version 16/10/2007
41
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es) 
42
 */
43
public abstract class AbstractPanel extends JPanel implements IPanel {
44
        /**
45
         * <p>If this panel remains with its initial preferred size of it has been changed.</p>
46
         * 
47
         * @see #remainsWithItsDefaultPreferredSize()
48
         */
49
        protected boolean remainsWithDefaultPreferredSize;
50

    
51
        /**
52
         * <p>Optional attribute that identifies this panel.</p>
53
         * 
54
         * @see #getID()
55
         * @see #setID(String)
56
         */
57
        private String id;
58

    
59
        /**
60
         * <p>Identifier used by a {@link AbstractPanelGroup AbstractPanelGroup} to identify this panel.</p>
61
         * 
62
         * @see #getLabel()
63
         * @see #setLabel(String)
64
         */
65
        private String label;
66

    
67
        /**
68
         * <p>Identifier used to group together different <code>IPanel</code> panels
69
     *      in a {@link AbstractPanelGroup AbstractPanelGroup}</p>
70
     *
71
     * @see #getLabelGroup()
72
     * @see #setLabelGroup(String)
73
         */
74
        private String labelGroup;
75

    
76
        /**
77
         * <p>Reference to an object that is related this panel</p>
78
         * 
79
         * @see #getReference()
80
         * @see #setReference(Object)
81
         */
82
        private Object reference;
83

    
84
        /**
85
         * <p>Reference to the container of the group which this panel is a member.</p>
86
         * 
87
         * @see #getPanelGroup()
88
         * @see #setPanelGroup(AbstractPanelGroup)
89
         */
90
        private AbstractPanelGroup panelGroup;
91
        
92
        /**
93
         * <p>Determines if this component has changed since it was created, or applied (or accepted).</p>
94
         */
95
        protected boolean hasChanged;
96

    
97
        /**
98
         * <p>Determines if this panel will always be applied and accepted, or only when has changed.</p>
99
         */
100
        private boolean alwaysApplicable;
101
        
102
        /**
103
         * <p>Initializes this panel.</p>
104
         */
105
        public AbstractPanel() {
106
                super();
107
                
108
                id = null;
109
                label = null;
110
                labelGroup = null;
111
                remainsWithDefaultPreferredSize = true;
112
                hasChanged = false;
113
                alwaysApplicable = true;
114
        }
115

    
116
        /**
117
         * <p>Initializes this panel using three parameters.</p>
118
         * 
119
         * @param id optional attribute that identifies this panel
120
         * @param label identifier used by a {@link AbstractPanelGroup AbstractPanelGroup} to identify this panel
121
         * @param labelGroup identifier used to group together different <code>IPanel</code> panels
122
     *      in a {@link AbstractPanelGroup AbstractPanelGroup}
123
         */
124
        public AbstractPanel(String id, String label, String labelGroup) {
125
                super();
126
                
127
                this.id = id;
128
                this.label = label;
129
                this.labelGroup = labelGroup;
130
                remainsWithDefaultPreferredSize = true;
131
                hasChanged = false;
132
                alwaysApplicable = true;
133
        }
134

    
135
        /**
136
         * <p>This method is used by each concrete implementation of <code>AbstractPanel</code> to
137
         *  execute its particular initialization tasks.</p>
138
         */
139
        protected abstract void initialize();
140

    
141
        /*
142
         * (non-Javadoc)
143
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#getID()
144
         */
145
        public String getID() {
146
                return id;
147
        }
148

    
149
        /*
150
         * (non-Javadoc)
151
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#getLabel()
152
         */
153
        public String getLabel() {
154
                return label;
155
        }
156

    
157
        /*
158
         * (non-Javadoc)
159
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#getLabelGroup()
160
         */
161
        public String getLabelGroup() {
162
                return labelGroup;
163
        }
164

    
165
        /*
166
         * (non-Javadoc)
167
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#setID(java.lang.String)
168
         */
169
        public void setID(String id) {
170
                this.id = id;
171
        }
172

    
173
        /*
174
         * (non-Javadoc)
175
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#setLabel(java.lang.String)
176
         */
177
        public void setLabel(String label) {
178
                this.label = label;
179
        }
180

    
181
        /*
182
         * (non-Javadoc)
183
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#setLabelGroup(java.lang.String)
184
         */
185
        public void setLabelGroup(String labelGroup) {
186
                this.labelGroup = labelGroup;
187
        }
188

    
189
        /*
190
         * (non-Javadoc)
191
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#getReference()
192
         */
193
        public Object getReference() {
194
                return reference; 
195
        }
196

    
197
        /*
198
         * (non-Javadoc)
199
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#setReference(java.lang.Object)
200
         */
201
        public void setReference(Object ref) {
202
                reference = ref;
203
        }
204

    
205
        /*
206
         * (non-Javadoc)
207
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#getPanelGroup()
208
         */
209
        public AbstractPanelGroup getPanelGroup() {
210
                return panelGroup;
211
        }
212

    
213
        /*
214
         * (non-Javadoc)
215
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#setPanelGroup(org.gvsig.gui.beans.panelGroup.AbstractPanelGroup)
216
         */
217
        public void setPanelGroup(AbstractPanelGroup panelGroup) {
218
                this.panelGroup = panelGroup;
219
        }
220

    
221
        /*
222
         * (non-Javadoc)
223
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#setInGroupGUI(boolean)
224
         */
225
        public synchronized void setInGroupGUI(boolean visible) {
226
                if (panelGroup != null)
227
                        panelGroup.setPanelInGUI(this, visible);
228
        }
229

    
230
        /*
231
         * (non-Javadoc)
232
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#isInGroupGUI()
233
         */
234
        public synchronized boolean isInGroupGUI() {
235
                if (panelGroup == null)
236
                        return false;
237

    
238
                return panelGroup.isPanelInGUI(this);
239
        }
240

    
241
        /*
242
         * (non-Javadoc)
243
         * @see java.awt.Component#toString()
244
         */
245
        public String toString() {
246
                return (label == null)? "": label;
247
        }
248

    
249
        /*
250
         * (non-Javadoc)
251
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#remainsWithItsDefaultPreferredSize()
252
         */
253
        public boolean remainsWithItsDefaultPreferredSize() {
254
                return remainsWithDefaultPreferredSize;
255
        }
256

    
257
        /*
258
         * (non-Javadoc)
259
         * @see javax.swing.JComponent#setPreferredSize(java.awt.Dimension)
260
         */
261
        public void setPreferredSize(Dimension preferredSize) {
262
                super.setPreferredSize(preferredSize);
263
                remainsWithDefaultPreferredSize = false;
264
        }
265
        
266
        /*
267
         * (non-Javadoc)
268
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#hasChanged()
269
         */
270
        public boolean hasChanged() {
271
                return hasChanged;
272
        }
273

    
274
        /*
275
         * (non-Javadoc)
276
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#resetChangedStatus()
277
         */
278
        public void resetChangedStatus() {
279
                hasChanged = false;
280
        }
281

    
282
        /*
283
         * (non-Javadoc)
284
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#setAlwaysApplicable(boolean)
285
         */
286
        public void setAlwaysApplicable(boolean b) {
287
                alwaysApplicable = b;
288
        }
289
        
290
        /*
291
         * (non-Javadoc)
292
         * @see org.gvsig.gui.beans.panelGroup.panels.IPanel#isAlwaysApplicable()
293
         */
294
        public boolean isAlwaysApplicable() {
295
                return alwaysApplicable;
296
        }
297
}