Revision 1881 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.dynform/org.gvsig.tools.dynform.impl/src/main/java/org/gvsig/tools/dynform/impl/DefaultJProblemIndicator.java
DefaultJProblemIndicator.java | ||
---|---|---|
38 | 38 |
import org.gvsig.tools.swing.api.Component; |
39 | 39 |
|
40 | 40 |
public class DefaultJProblemIndicator implements Component, JProblemIndicator { |
41 |
private String message = null; |
|
42 |
private JLabel indicator = null; |
|
43 |
private ImageIcon okIcon = null; |
|
44 |
private ImageIcon errorIcon = null; |
|
45 |
private Cursor defaultCursor = null; |
|
46 |
private Cursor handCursor = null; |
|
47 |
private JDynFormField field = null; |
|
48 |
|
|
49 |
public DefaultJProblemIndicator(JDynFormField field) { |
|
50 |
this.field = field; |
|
51 |
} |
|
52 |
|
|
53 |
public JComponent asJComponent() { |
|
54 |
if( this.indicator == null ) { |
|
55 |
this.indicator = new JLabel(); |
|
56 |
URL resource = null; |
|
57 |
resource = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/problem.png"); |
|
58 |
if( resource!=null ) { |
|
59 |
this.errorIcon = new ImageIcon(resource); |
|
60 |
} |
|
61 |
resource = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/transparent.png"); |
|
62 |
if( resource!=null ) { |
|
63 |
this.okIcon = new ImageIcon(resource); |
|
64 |
} |
|
65 |
this.indicator.setIcon(this.okIcon); |
|
66 |
|
|
67 |
this.indicator.addMouseListener(new MouseAdapter() { |
|
68 |
public void mouseClicked(MouseEvent evt) { |
|
69 |
if( message == null ) { |
|
70 |
return; |
|
71 |
} |
|
72 |
int count = evt.getClickCount(); |
|
73 |
if (count == 1) { |
|
74 |
JOptionPane.showMessageDialog(field.asJComponent() ,message,"Status",JOptionPane.INFORMATION_MESSAGE); |
|
75 |
} |
|
76 |
} |
|
77 |
}); |
|
78 |
this.defaultCursor = this.indicator.getCursor(); |
|
79 |
this.handCursor = new Cursor(Cursor.HAND_CURSOR); |
|
80 |
} |
|
81 |
return this.indicator; |
|
82 |
} |
|
83 | 41 |
|
84 |
public void clear() { |
|
85 |
this.message = null; |
|
86 |
this.indicator.setToolTipText(""); |
|
87 |
this.indicator.setIcon(this.okIcon); |
|
88 |
this.indicator.setCursor(this.defaultCursor); |
|
89 |
} |
|
90 |
public void set(String message) { |
|
91 |
this.message = message; |
|
92 |
this.indicator.setToolTipText(message); |
|
93 |
this.indicator.setIcon(this.errorIcon); |
|
94 |
this.indicator.setCursor(this.handCursor); |
|
95 |
field.fireMessageEvent(this.message); |
|
96 |
} |
|
97 |
public void restore() { |
|
98 |
if( message != null ) { |
|
99 |
set(message); |
|
100 |
} |
|
101 |
} |
|
42 |
private String message = null; |
|
43 |
private JLabel indicator = null; |
|
44 |
private ImageIcon okIcon = null; |
|
45 |
private ImageIcon errorIcon = null; |
|
46 |
private Cursor defaultCursor = null; |
|
47 |
private Cursor handCursor = null; |
|
48 |
private JDynFormField field = null; |
|
102 | 49 |
|
50 |
public DefaultJProblemIndicator(JDynFormField field) { |
|
51 |
this.field = field; |
|
52 |
} |
|
53 |
|
|
54 |
private void initComponentIfNeed() { |
|
55 |
if (this.indicator == null) { |
|
56 |
this.indicator = new JLabel(); |
|
57 |
URL resource = null; |
|
58 |
resource = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/problem.png"); |
|
59 |
if (resource != null) { |
|
60 |
this.errorIcon = new ImageIcon(resource); |
|
61 |
} |
|
62 |
resource = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/transparent.png"); |
|
63 |
if (resource != null) { |
|
64 |
this.okIcon = new ImageIcon(resource); |
|
65 |
} |
|
66 |
this.indicator.setIcon(this.okIcon); |
|
67 |
|
|
68 |
this.indicator.addMouseListener(new MouseAdapter() { |
|
69 |
@Override |
|
70 |
public void mouseClicked(MouseEvent evt) { |
|
71 |
if (message == null) { |
|
72 |
return; |
|
73 |
} |
|
74 |
int count = evt.getClickCount(); |
|
75 |
if (count == 1) { |
|
76 |
JOptionPane.showMessageDialog(field.asJComponent(), message, "Status", JOptionPane.INFORMATION_MESSAGE); |
|
77 |
} |
|
78 |
} |
|
79 |
}); |
|
80 |
this.defaultCursor = this.indicator.getCursor(); |
|
81 |
this.handCursor = new Cursor(Cursor.HAND_CURSOR); |
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 |
@Override |
|
86 |
public JComponent asJComponent() { |
|
87 |
this.initComponentIfNeed(); |
|
88 |
return this.indicator; |
|
89 |
} |
|
90 |
|
|
91 |
@Override |
|
92 |
public void clear() { |
|
93 |
this.initComponentIfNeed(); |
|
94 |
this.message = null; |
|
95 |
this.indicator.setToolTipText(""); |
|
96 |
this.indicator.setIcon(this.okIcon); |
|
97 |
this.indicator.setCursor(this.defaultCursor); |
|
98 |
} |
|
99 |
|
|
100 |
@Override |
|
101 |
public void set(String message) { |
|
102 |
this.initComponentIfNeed(); |
|
103 |
this.message = message; |
|
104 |
this.indicator.setToolTipText(message); |
|
105 |
this.indicator.setIcon(this.errorIcon); |
|
106 |
this.indicator.setCursor(this.handCursor); |
|
107 |
field.fireMessageEvent(this.message); |
|
108 |
} |
|
109 |
|
|
110 |
@Override |
|
111 |
public void restore() { |
|
112 |
if (message != null) { |
|
113 |
set(message); |
|
114 |
} |
|
115 |
} |
|
116 |
|
|
103 | 117 |
} |
Also available in: Unified diff