Statistics
| Revision:

root / org.gvsig.educa.thematicmap / trunk / org.gvsig.educa.thematicmap / org.gvsig.educa.thematicmap.swing / org.gvsig.educa.thematicmap.swing.impl / src / main / java / org / gvsig / educa / thematicmap / swing / impl / DefaultThematicMapWindowManager.java @ 16

History | View | Annotate | Download (6.26 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
package org.gvsig.educa.thematicmap.swing.impl;
23

    
24
import java.awt.Component;
25

    
26
import javax.swing.JComponent;
27
import javax.swing.JOptionPane;
28

    
29
import org.gvsig.educa.thematicmap.swing.ThematicMapSwingComponent;
30
import org.gvsig.educa.thematicmap.swing.ThematicMapWindowManager;
31
import org.gvsig.educa.thematicmap.swing.editor.ThematicMapCompilationEditor;
32
import org.gvsig.educa.thematicmap.swing.viewer.ThematicMapViewer;
33
import org.gvsig.tools.swing.api.ToolsSwingLocator;
34

    
35
/**
36
 * Default implementation for the {@link ThematicMapWindowManager}.
37
 * 
38
 * @author gvSIG Team
39
 * @version $Id$
40
 */
41
public class DefaultThematicMapWindowManager implements
42
    ThematicMapWindowManager {
43

    
44
    private final DefaultThematicMapSwingManager manager;
45

    
46
    public DefaultThematicMapWindowManager(
47
        DefaultThematicMapSwingManager manager) {
48
        this.manager = manager;
49
        ;
50
    }
51

    
52
    /** {@inheridDoc} */
53
    public void showWindow(JComponent panel, String tittle, MODE mode) {
54
        ToolsSwingLocator.getWindowManager().showWindow(panel, tittle, mode);
55
    }
56

    
57
    /** {@inheridDoc} */
58
    public void showInWindow(ThematicMapSwingComponent swingComponent,
59
        String title, MODE mode) {
60
        showWindow(swingComponent.getSwingComponent(), title, mode);
61

    
62
    }
63

    
64
    /** {@inheridDoc} */
65
    public void showViewer(ThematicMapViewer mapViewer, MODE mode) {
66
        String title =
67
            String.format("%1s [%2s]", mapViewer.getThematicMap()
68
                .getInformation().getName(),
69
                manager.getTranslation("Thematic_Map"));
70
        showInWindow(mapViewer, title, MODE.WINDOW);
71
    }
72

    
73
    /** {@inheridDoc} */
74
    public void showCompilationEditor(
75
        ThematicMapCompilationEditor mapCompilationEditor, MODE mode) {
76
        String name = "{".concat(manager.getTranslation("new")).concat("}");
77
        String title =
78
            String.format("%1s [%2s]", name,
79
                manager.getTranslation("Thematic_Map_Compilation"));
80
        showInWindow(mapCompilationEditor, title, MODE.WINDOW);
81

    
82
    }
83

    
84
    /** {@inheridDoc} */
85
    public void showMessageDialog(Component component, String title,
86
        String text, MESSAGE_DIALOG_TYPE type) {
87
        showAMessageDialog(component, title, text, type);
88
    }
89

    
90
    /** {@inheridDoc} */
91
    public void showMessageDialog(String title, String text,
92
        MESSAGE_DIALOG_TYPE type) {
93
        showAMessageDialog(null, title, text, type);
94
    }
95

    
96
    /** {@inheridDoc} */
97
    public void showMessageDialog(ThematicMapSwingComponent component,
98
        String title, String text, MESSAGE_DIALOG_TYPE type) {
99
        showAMessageDialog(component.getSwingComponent(), title, text, type);
100
    }
101

    
102
    private int getJOptionPaneMessageType(MESSAGE_DIALOG_TYPE type) {
103
        switch (type) {
104
        case ERROR:
105
            return JOptionPane.ERROR_MESSAGE;
106

    
107
        case INFO:
108
            return JOptionPane.INFORMATION_MESSAGE;
109

    
110
        case WARNING:
111
            return JOptionPane.WARNING_MESSAGE;
112

    
113
        case QUESTION:
114
            return JOptionPane.QUESTION_MESSAGE;
115

    
116
        default:
117
            return JOptionPane.PLAIN_MESSAGE;
118
        }
119
    }
120

    
121
    private void showAMessageDialog(Component component, String title,
122
        String text, MESSAGE_DIALOG_TYPE type) {
123
        int messageType = getJOptionPaneMessageType(type);
124
        JOptionPane.showMessageDialog(component, text, title, messageType);
125
    }
126

    
127
    /** {@inheridDoc} */
128
    public CONFIRM_DIALOG_OPTION showConfirmDialog(Component parent,
129
        String message, String title, CONFIRM_DIALOG_TYPE type,
130
        MESSAGE_DIALOG_TYPE messageType) {
131
        int optType;
132
        switch (type) {
133
        case YES_NO:
134
            optType = JOptionPane.YES_NO_OPTION;
135
            break;
136
        case YES_NO_CANCEL:
137
            optType = JOptionPane.YES_NO_CANCEL_OPTION;
138
            break;
139
        case OK_CANCEL:
140
            optType = JOptionPane.OK_CANCEL_OPTION;
141
            break;
142
        default:
143
            throw new IllegalArgumentException();
144
        }
145
        int msgType = getJOptionPaneMessageType(messageType);
146
        int ret =
147
            JOptionPane.showConfirmDialog(parent, message, title, optType,
148
                msgType);
149
        switch (ret) {
150
        case JOptionPane.CANCEL_OPTION:
151
            return CONFIRM_DIALOG_OPTION.CANCEL;
152
        case JOptionPane.OK_OPTION:
153
            return CONFIRM_DIALOG_OPTION.OK_YES;
154
        case JOptionPane.NO_OPTION:
155
            return CONFIRM_DIALOG_OPTION.NO;
156
        case JOptionPane.CLOSED_OPTION:
157
            return CONFIRM_DIALOG_OPTION.CLOSED_PANEL;
158
        default:
159
            throw new IllegalStateException();
160
        }
161
    }
162

    
163
    /** {@inheridDoc} */
164
    public CONFIRM_DIALOG_OPTION showConfirmDialog(String translation,
165
        String title, CONFIRM_DIALOG_TYPE type, MESSAGE_DIALOG_TYPE messageType) {
166
        return showConfirmDialog(null, translation, title, type, messageType);
167
    }
168

    
169
    public String showInputStringDialog(String translation, String title,
170
        String defautValue, MESSAGE_DIALOG_TYPE messageType) {
171

    
172
        return showInputStringDialog(null, translation, title, defautValue,
173
            messageType);
174

    
175
    }
176

    
177
    public String showInputStringDialog(Component parent, String translation,
178
        String title, String defautValue, MESSAGE_DIALOG_TYPE messageType) {
179
        int msgType = getJOptionPaneMessageType(messageType);
180
        return (String) JOptionPane.showInputDialog(parent, translation, title,
181
            msgType, null, null, defautValue);
182
    }
183

    
184
}