gvsig-tools / 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 @ 931
History | View | Annotate | Download (2.39 KB)
1 |
package org.gvsig.tools.dynform.impl; |
---|---|
2 |
|
3 |
import java.awt.Cursor; |
4 |
import java.awt.event.MouseAdapter; |
5 |
import java.awt.event.MouseEvent; |
6 |
import java.net.URL; |
7 |
|
8 |
import javax.swing.ImageIcon; |
9 |
import javax.swing.JComponent; |
10 |
import javax.swing.JLabel; |
11 |
import javax.swing.JOptionPane; |
12 |
|
13 |
import org.gvsig.tools.dynform.spi.dynformfield.JProblemIndicator; |
14 |
import org.gvsig.tools.dynforms.JDynFormField; |
15 |
import org.gvsig.tools.swing.api.Component; |
16 |
|
17 |
public class DefaultJProblemIndicator implements Component, JProblemIndicator { |
18 |
private String message = null; |
19 |
private JLabel indicator = null; |
20 |
private ImageIcon okIcon = null; |
21 |
private ImageIcon errorIcon = null; |
22 |
private Cursor defaultCursor = null; |
23 |
private Cursor handCursor = null; |
24 |
private JDynFormField field = null; |
25 |
|
26 |
public DefaultJProblemIndicator(JDynFormField field) {
|
27 |
this.field = field;
|
28 |
} |
29 |
|
30 |
public JComponent asJComponent() { |
31 |
if( this.indicator == null ) { |
32 |
this.indicator = new JLabel(); |
33 |
URL resource = null; |
34 |
resource = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/problem.png"); |
35 |
if( resource!=null ) { |
36 |
this.errorIcon = new ImageIcon(resource); |
37 |
} |
38 |
resource = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/transparent.png"); |
39 |
if( resource!=null ) { |
40 |
this.okIcon = new ImageIcon(resource); |
41 |
} |
42 |
this.indicator.setIcon(this.okIcon); |
43 |
|
44 |
this.indicator.addMouseListener(new MouseAdapter() { |
45 |
public void mouseClicked(MouseEvent evt) { |
46 |
if( message == null ) { |
47 |
return;
|
48 |
} |
49 |
int count = evt.getClickCount();
|
50 |
if (count == 1) { |
51 |
JOptionPane.showMessageDialog(field.asJComponent() ,message,"Status",JOptionPane.INFORMATION_MESSAGE); |
52 |
} |
53 |
} |
54 |
}); |
55 |
this.defaultCursor = this.indicator.getCursor(); |
56 |
this.handCursor = new Cursor(Cursor.HAND_CURSOR); |
57 |
} |
58 |
return this.indicator; |
59 |
} |
60 |
|
61 |
public void clear() { |
62 |
this.message = null; |
63 |
this.indicator.setToolTipText(""); |
64 |
this.indicator.setIcon(this.okIcon); |
65 |
this.indicator.setCursor(this.defaultCursor); |
66 |
} |
67 |
public void set(String message) { |
68 |
this.message = message;
|
69 |
this.indicator.setToolTipText(message);
|
70 |
this.indicator.setIcon(this.errorIcon); |
71 |
this.indicator.setCursor(this.handCursor); |
72 |
field.fireMessageEvent(this.message);
|
73 |
} |
74 |
public void restore() { |
75 |
if( message != null ) { |
76 |
set(message); |
77 |
} |
78 |
} |
79 |
|
80 |
} |