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 @ 168
History | View | Annotate | Download (3.2 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.Color; |
37 |
|
38 |
import javax.swing.Icon; |
39 |
import javax.swing.ImageIcon; |
40 |
import javax.swing.JLabel; |
41 |
|
42 |
import org.gvsig.tools.swing.api.dynobject.ValueChangedListener; |
43 |
import org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent; |
44 |
|
45 |
/**
|
46 |
* @author <a href="mailto:reinhold@uji.es">cmartin</a>
|
47 |
*
|
48 |
*/
|
49 |
public class StatusLabel extends JLabel implements ValueChangedListener{ |
50 |
|
51 |
private static final String NOT_VALIDATED = "unavailable.png"; |
52 |
|
53 |
private static final Color COLOR_MANDATORY = Color.RED; |
54 |
|
55 |
|
56 |
public StatusLabel(String text, boolean isMandatory) { |
57 |
setOpaque(true);
|
58 |
setHorizontalTextPosition(JLabel.LEFT);
|
59 |
setHorizontalAlignment(LEFT); |
60 |
setVerticalAlignment(CENTER); |
61 |
setIconTextGap(10);
|
62 |
if (isMandatory){
|
63 |
this.setForeground(COLOR_MANDATORY);
|
64 |
this.setText("<html><u>" + text + "</u><html>"); |
65 |
}else
|
66 |
setText(text); |
67 |
} |
68 |
|
69 |
|
70 |
/**
|
71 |
* @param notValidated
|
72 |
* @return
|
73 |
*/
|
74 |
private Icon getIcon(String notValidated, String description) { |
75 |
String path = this.getClass().getResource(NOT_VALIDATED).getPath(); |
76 |
if ((path==null)||(path.equals(""))) |
77 |
return null; |
78 |
ImageIcon icon = new ImageIcon(path); |
79 |
icon.setDescription(description); |
80 |
icon.setImageObserver(this);
|
81 |
return icon;
|
82 |
} |
83 |
//
|
84 |
// // Set the font and text when no image was found.
|
85 |
// protected void setText(String text, Font normalFont) {
|
86 |
// if (uhOhFont == null) { // lazily create this font
|
87 |
// uhOhFont = normalFont.deriveFont(Font.ITALIC);
|
88 |
// }
|
89 |
// setFont(uhOhFont);
|
90 |
// setText(uhOhText);
|
91 |
// }
|
92 |
|
93 |
/* (non-Javadoc)
|
94 |
* @see org.gvsig.tools.swing.api.dynobject.ValueChangedListener#handleValueChanged(org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent)
|
95 |
*/
|
96 |
public void handleValueChanged(JDynFieldComponent field) { |
97 |
|
98 |
// Set the icon and text. If icon was null, say so.
|
99 |
if (!field.isValid()){
|
100 |
this.setIcon(getIcon(NOT_VALIDATED, "Not Validated")); |
101 |
}else{
|
102 |
setIcon(null);
|
103 |
} |
104 |
} |
105 |
} |