Statistics
| Revision:

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 @ 2537

History | View | Annotate | Download (3.91 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.tools.dynform.impl;
25

    
26
import java.awt.Cursor;
27
import java.awt.event.MouseAdapter;
28
import java.awt.event.MouseEvent;
29
import java.net.URL;
30

    
31
import javax.swing.ImageIcon;
32
import javax.swing.JComponent;
33
import javax.swing.JLabel;
34
import javax.swing.JOptionPane;
35

    
36
import org.gvsig.tools.dynform.JDynFormField;
37
import org.gvsig.tools.dynform.spi.dynformfield.JProblemIndicator;
38
import org.gvsig.tools.swing.api.Component;
39
import org.gvsig.tools.swing.api.ToolsSwingLocator;
40
import org.gvsig.tools.swing.icontheme.IconTheme;
41

    
42
public class DefaultJProblemIndicator implements Component, JProblemIndicator {
43

    
44
    private String message = null;
45
    private JLabel indicator = null;
46
    private ImageIcon okIcon = null;
47
    private ImageIcon errorIcon = null;
48
    private Cursor defaultCursor = null;
49
    private Cursor handCursor = null;
50
    private JDynFormField field = null;
51

    
52
    public DefaultJProblemIndicator(JDynFormField field) {
53
        this.field = field;
54
    }
55

    
56
    private void initComponentIfNeed() {
57
        if (this.indicator == null) {
58
            this.indicator = new JLabel();
59
            URL resource;
60
            IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
61
            this.errorIcon = theme.get("form-problem-indicator");
62
            resource = this.getClass().getClassLoader().getResource("org/gvsig/tools/dynform/impl/images/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

    
117
}