gvsig-tools / org.gvsig.tools / library / trunk / org.gvsig.tools / org.gvsig.tools.swing / org.gvsig.tools.swing.impl / src / main / java / org / gvsig / tools / swing / impl / dynobject / StatusLabel.java @ 281
History | View | Annotate | Download (4.55 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
/*
|
23 |
* AUTHORS (In addition to CIT):
|
24 |
* 2010 Institute of New Imaging Technologies (INIT):
|
25 |
* http://www.init.uji.es
|
26 |
* Geographic Information research group:
|
27 |
* http://www.geoinfo.uji.es
|
28 |
* Universitat Jaume I, Spain
|
29 |
*/
|
30 |
|
31 |
/**
|
32 |
*
|
33 |
*/
|
34 |
package org.gvsig.tools.swing.impl.dynobject; |
35 |
|
36 |
import java.awt.BorderLayout; |
37 |
import java.awt.Color; |
38 |
import java.awt.Component; |
39 |
import java.awt.Dimension; |
40 |
|
41 |
import javax.swing.Icon; |
42 |
import javax.swing.ImageIcon; |
43 |
import javax.swing.JLabel; |
44 |
import javax.swing.JPanel; |
45 |
|
46 |
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener; |
47 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
48 |
|
49 |
/**
|
50 |
*
|
51 |
* JLabel with a "not validated" image, whose validation is validated and shown
|
52 |
* whenever the listener is triggered.
|
53 |
*
|
54 |
* @author 2010 - <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG Team
|
55 |
* @author 2010 - <a href="mailto:reinhold@uji.es">Cristian Mart?n </a> - gvSIG Team
|
56 |
* @version $Id$
|
57 |
*
|
58 |
*/
|
59 |
public class StatusLabel extends JLabel implements ValueChangedListener { |
60 |
|
61 |
private static final String NOT_VALIDATED = "unavailable.png"; |
62 |
|
63 |
private static final Color COLOR_MANDATORY = Color.RED; |
64 |
private JLabel validationLabel; |
65 |
|
66 |
private JPanel validationPanel; |
67 |
|
68 |
public StatusLabel(String text, boolean isMandatory) { |
69 |
validationLabel = new JLabel(); |
70 |
validationLabel.setOpaque(true);
|
71 |
validationLabel.setHorizontalAlignment(RIGHT); |
72 |
validationLabel.setIconTextGap(10);
|
73 |
validationLabel.setVerticalAlignment(TOP); |
74 |
setOpaque(true);
|
75 |
setHorizontalTextPosition(JLabel.LEFT);
|
76 |
setHorizontalAlignment(LEFT); |
77 |
setVerticalAlignment(TOP); |
78 |
if (isMandatory) {
|
79 |
// this.setForeground(COLOR_MANDATORY);
|
80 |
this.setText("<html><u>" + text + "</u><html>"); |
81 |
} else
|
82 |
setText(text); |
83 |
} |
84 |
|
85 |
/**
|
86 |
* @param notValidated
|
87 |
* @return
|
88 |
*/
|
89 |
private Icon getIcon(String notValidated, String description) { |
90 |
String path = this.getClass().getResource(NOT_VALIDATED).getPath(); |
91 |
if ((path == null) || (path.equals(""))) |
92 |
return null; |
93 |
ImageIcon icon = new ImageIcon(path); |
94 |
icon.setDescription(description); |
95 |
icon.setImageObserver(this);
|
96 |
return icon;
|
97 |
} |
98 |
|
99 |
//
|
100 |
// // Set the font and text when no image was found.
|
101 |
// protected void setText(String text, Font normalFont) {
|
102 |
// if (uhOhFont == null) { // lazily create this font
|
103 |
// uhOhFont = normalFont.deriveFont(Font.ITALIC);
|
104 |
// }
|
105 |
// setFont(uhOhFont);
|
106 |
// setText(uhOhText);
|
107 |
// }
|
108 |
|
109 |
/*
|
110 |
* (non-Javadoc)
|
111 |
*
|
112 |
* @see
|
113 |
* org.gvsig.tools.swing.api.dynobject.ValueChangedListener#handleValueChanged
|
114 |
* (org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent)
|
115 |
*/
|
116 |
public void handleValueChanged(JDynFieldComponent field) { |
117 |
|
118 |
// Set the icon and text. If icon was null, say so.
|
119 |
if (!field.isValid()) {
|
120 |
validationLabel.setIcon(getIcon(NOT_VALIDATED, "Not Validated"));
|
121 |
} else {
|
122 |
validationLabel.setIcon(null);
|
123 |
} |
124 |
} |
125 |
|
126 |
public Component getValidationLabel(){ |
127 |
return this.validationLabel; |
128 |
} |
129 |
|
130 |
/**
|
131 |
* @return
|
132 |
*/
|
133 |
public Component getValidationPanel() { |
134 |
if (validationPanel==null){ |
135 |
validationPanel = new JPanel(new BorderLayout()); |
136 |
validationPanel.setSize(new Dimension(15,15)); |
137 |
validationPanel.setOpaque(true);
|
138 |
validationPanel.add(validationLabel,BorderLayout.LINE_START);
|
139 |
} |
140 |
return this.validationPanel; |
141 |
} |
142 |
} |