Revision 270 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
StatusLabel.java | ||
---|---|---|
47 | 47 |
* @author <a href="mailto:reinhold@uji.es">cmartin</a> |
48 | 48 |
* |
49 | 49 |
*/ |
50 |
public class StatusLabel extends JLabel implements ValueChangedListener{ |
|
50 |
public class StatusLabel extends JLabel implements ValueChangedListener {
|
|
51 | 51 |
|
52 | 52 |
private static final String NOT_VALIDATED = "unavailable.png"; |
53 |
|
|
53 |
|
|
54 | 54 |
private static final Color COLOR_MANDATORY = Color.RED; |
55 | 55 |
private JLabel validationLabel; |
56 | 56 |
|
57 | 57 |
public StatusLabel(String text, boolean isMandatory) { |
58 |
validationLabel = new JLabel();
|
|
59 |
validationLabel.setOpaque(true);
|
|
60 |
validationLabel.setHorizontalAlignment(RIGHT);
|
|
61 |
validationLabel.setIconTextGap(10);
|
|
62 |
validationLabel.setVerticalAlignment(TOP);
|
|
63 |
setOpaque(true);
|
|
64 |
setHorizontalTextPosition(JLabel.LEFT);
|
|
65 |
setHorizontalAlignment(LEFT);
|
|
66 |
setVerticalAlignment(TOP);
|
|
67 |
if (isMandatory){
|
|
68 |
// this.setForeground(COLOR_MANDATORY);
|
|
69 |
this.setText("<html><u>" + text + "</u><html>");
|
|
70 |
}else
|
|
71 |
setText(text);
|
|
58 |
validationLabel = new JLabel();
|
|
59 |
validationLabel.setOpaque(true);
|
|
60 |
validationLabel.setHorizontalAlignment(RIGHT);
|
|
61 |
validationLabel.setIconTextGap(10);
|
|
62 |
validationLabel.setVerticalAlignment(TOP);
|
|
63 |
setOpaque(true);
|
|
64 |
setHorizontalTextPosition(JLabel.LEFT);
|
|
65 |
setHorizontalAlignment(LEFT);
|
|
66 |
setVerticalAlignment(TOP);
|
|
67 |
if (isMandatory) {
|
|
68 |
// this.setForeground(COLOR_MANDATORY);
|
|
69 |
this.setText("<html><u>" + text + "</u><html>");
|
|
70 |
} else
|
|
71 |
setText(text);
|
|
72 | 72 |
} |
73 | 73 |
|
74 |
|
|
75 | 74 |
/** |
76 | 75 |
* @param notValidated |
77 | 76 |
* @return |
78 | 77 |
*/ |
79 | 78 |
private Icon getIcon(String notValidated, String description) { |
80 |
String path = this.getClass().getResource(NOT_VALIDATED).getPath();
|
|
81 |
if ((path==null)||(path.equals("")))
|
|
82 |
return null;
|
|
83 |
ImageIcon icon = new ImageIcon(path);
|
|
84 |
icon.setDescription(description);
|
|
85 |
icon.setImageObserver(this);
|
|
86 |
return icon;
|
|
79 |
String path = this.getClass().getResource(NOT_VALIDATED).getPath();
|
|
80 |
if ((path == null) || (path.equals("")))
|
|
81 |
return null;
|
|
82 |
ImageIcon icon = new ImageIcon(path);
|
|
83 |
icon.setDescription(description);
|
|
84 |
icon.setImageObserver(this);
|
|
85 |
return icon;
|
|
87 | 86 |
} |
88 |
// |
|
89 |
// // Set the font and text when no image was found. |
|
90 |
// protected void setText(String text, Font normalFont) { |
|
91 |
// if (uhOhFont == null) { // lazily create this font |
|
92 |
// uhOhFont = normalFont.deriveFont(Font.ITALIC); |
|
93 |
// } |
|
94 |
// setFont(uhOhFont); |
|
95 |
// setText(uhOhText); |
|
96 |
// } |
|
97 | 87 |
|
98 |
/* (non-Javadoc) |
|
99 |
* @see org.gvsig.tools.swing.api.dynobject.ValueChangedListener#handleValueChanged(org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent) |
|
88 |
// |
|
89 |
// // Set the font and text when no image was found. |
|
90 |
// protected void setText(String text, Font normalFont) { |
|
91 |
// if (uhOhFont == null) { // lazily create this font |
|
92 |
// uhOhFont = normalFont.deriveFont(Font.ITALIC); |
|
93 |
// } |
|
94 |
// setFont(uhOhFont); |
|
95 |
// setText(uhOhText); |
|
96 |
// } |
|
97 |
|
|
98 |
/* |
|
99 |
* (non-Javadoc) |
|
100 |
* |
|
101 |
* @see |
|
102 |
* org.gvsig.tools.swing.api.dynobject.ValueChangedListener#handleValueChanged |
|
103 |
* (org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent) |
|
100 | 104 |
*/ |
101 | 105 |
public void handleValueChanged(JDynFieldComponent field) { |
102 | 106 |
|
103 |
// Set the icon and text. If icon was null, say so.
|
|
104 |
if (!field.isValid()){
|
|
105 |
validationLabel.setIcon(getIcon(NOT_VALIDATED, "Not Validated"));
|
|
106 |
}else{
|
|
107 |
setIcon(null);
|
|
108 |
}
|
|
107 |
// Set the icon and text. If icon was null, say so.
|
|
108 |
if (!field.isValid()) {
|
|
109 |
validationLabel.setIcon(getIcon(NOT_VALIDATED, "Not Validated"));
|
|
110 |
} else {
|
|
111 |
setIcon(null);
|
|
112 |
}
|
|
109 | 113 |
} |
110 | 114 |
|
111 |
|
|
112 | 115 |
/** |
113 | 116 |
* @return |
114 | 117 |
*/ |
115 | 118 |
public Component getValidationLabel() { |
116 |
return this.validationLabel;
|
|
119 |
return this.validationLabel;
|
|
117 | 120 |
} |
118 | 121 |
} |
Also available in: Unified diff