Statistics
| Revision:

root / org.gvsig.educa.portableview.app / org.gvsig.educa.portableview.app.viewer / src / main / java / org / gvsig / educa / portableview / app / viewer / ui / PortableViewDocumentProperties.java @ 254

History | View | Annotate | Download (8.17 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.portableview.app.viewer.ui;
23

    
24
import java.awt.FlowLayout;
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27
import java.awt.GridLayout;
28
import java.awt.Insets;
29
import java.awt.event.ActionEvent;
30

    
31
import javax.swing.AbstractAction;
32
import javax.swing.BorderFactory;
33
import javax.swing.JButton;
34
import javax.swing.JPanel;
35
import javax.swing.JScrollPane;
36
import javax.swing.JTextArea;
37
import javax.swing.JTextField;
38

    
39
import org.apache.commons.lang3.StringUtils;
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
42
import org.gvsig.andami.ui.mdiManager.WindowInfo;
43
import org.gvsig.educa.portableview.app.viewer.PortableViewDocument;
44
import org.gvsig.educa.portableview.swing.PortableViewSwingLocator;
45
import org.gvsig.educa.portableview.swing.PortableViewSwingManager;
46
import org.gvsig.educa.portableview.swing.PortableViewWindowManager.MESSAGE_DIALOG_TYPE;
47
import org.gvsig.educa.portableview.swing.viewer.PortableViewInforamtionViewer;
48
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
49
import org.gvsig.tools.swing.api.ToolsSwingLocator;
50
import org.gvsig.tools.swing.api.usability.UsabilitySwingManager;
51

    
52
/**
53
 * @author gvSIG Team
54
 * @version $Id$
55
 *
56
 */
57
public class PortableViewDocumentProperties extends JPanel implements
58
    SingletonWindow {
59

    
60
    /**
61
     *
62
     */
63
    private static final long serialVersionUID = 8865766314251281948L;
64

    
65
    private static final int DEFAULT_HEIGHT = 450;
66

    
67
    private static final int DEFAULT_WIDTH = 700;
68

    
69
    private final PortableViewDocument model;
70
    private final PortableViewSwingManager tmSwingManager;
71
    private final UsabilitySwingManager usabManager;
72
    private WindowInfo windowInfo;
73

    
74
    private JTextField name;
75

    
76
    private PortableViewInforamtionViewer info;
77

    
78
    private JTextArea comments;
79

    
80
    private JButton acceptButton;
81

    
82
    private JButton cancelButton;
83

    
84
    private JTextField sourceViewName;
85

    
86
    /**
87
     * @param doc
88
     */
89
    public PortableViewDocumentProperties(PortableViewDocument doc) {
90
        super();
91
        model = doc;
92
        tmSwingManager = PortableViewSwingLocator.getSwingManager();
93
        usabManager = ToolsSwingLocator.getUsabilitySwingManager();
94
        initializeUI();
95
    }
96

    
97
    /**
98
     *
99
     */
100
    private void initializeUI() {
101
        setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
102
        setLayout(new GridBagLayout());
103

    
104
        GridBagConstraints gbcBase = createBaseGridBagContraints();
105

    
106
        // add name
107
        JPanel namePanel = createNamePanel();
108
        add(namePanel, gbcBase.clone());
109

    
110
        // add ThMap info
111
        JPanel infoPanel = createInfoPanel();
112
        GridBagConstraints gbc = (GridBagConstraints) gbcBase.clone();
113
        gbc.fill = GridBagConstraints.BOTH;
114
        gbc.weighty = 1;
115
        add(infoPanel, gbc);
116

    
117
        // add comments
118
        JPanel commentPanel = createCommentsPanel();
119
        add(commentPanel, gbcBase.clone());
120

    
121
        // add command panel
122
        JPanel commandsPanel = createCommandPanel();
123
        add(commandsPanel, gbcBase.clone());
124

    
125
    }
126

    
127
    /**
128
     * @return
129
     */
130
    private GridBagConstraints createBaseGridBagContraints() {
131
        GridBagConstraints gbcBase = new GridBagConstraints();
132

    
133
        gbcBase.gridx = GridBagConstraints.RELATIVE;
134
        gbcBase.gridy = GridBagConstraints.RELATIVE;
135
        gbcBase.gridheight = 1;
136
        gbcBase.gridwidth = GridBagConstraints.REMAINDER;
137
        gbcBase.insets = new Insets(5, 5, 5, 5);
138
        gbcBase.fill = GridBagConstraints.HORIZONTAL;
139
        gbcBase.weightx = 1;
140
        gbcBase.weighty = 0;
141
        return gbcBase;
142
    }
143

    
144
    /**
145
     * @return
146
     */
147
    private JPanel createCommandPanel() {
148
        JPanel commandsPanel =
149
            new JPanel(new FlowLayout(FlowLayout.TRAILING, 10, 10));
150
        acceptButton =
151
            usabManager.createJButton(new AbstractAction(tmSwingManager
152
                .getTranslation("accept")) {
153

    
154
                /**
155
                     *
156
                     */
157
                private static final long serialVersionUID =
158
                    -1782481065769162438L;
159

    
160
                public void actionPerformed(ActionEvent e) {
161
                    accept();
162

    
163
                }
164

    
165
            });
166
        commandsPanel.add(acceptButton);
167
        cancelButton =
168
            usabManager.createJButton(new AbstractAction(tmSwingManager
169
                .getTranslation("cancel")) {
170

    
171
                /**
172
                     *
173
                     */
174
                private static final long serialVersionUID =
175
                    2955490218831066658L;
176

    
177
                public void actionPerformed(ActionEvent e) {
178
                    close();
179

    
180
                }
181

    
182
            });
183
        commandsPanel.add(cancelButton);
184
        return commandsPanel;
185
    }
186

    
187
    /**
188
     * @return
189
     */
190
    private JPanel createNamePanel() {
191
        GridBagLayoutPanel namePanel = new GridBagLayoutPanel();
192
        name = new JTextField(model.getName());
193
        namePanel.addComponent(tmSwingManager.getTranslation("name"), name);
194
        sourceViewName = new JTextField();
195
        sourceViewName.setEditable(false);
196
        if (model.getSourceView() != null) {
197
            sourceViewName.setText(model.getSourceView().getName());
198
            namePanel.addComponent(
199
                tmSwingManager.getTranslation("source_view"), sourceViewName);
200
        }
201
        return namePanel;
202
    }
203

    
204
    /**
205
     * @return
206
     */
207
    private JPanel createInfoPanel() {
208
        JPanel infoPanel = new JPanel(new GridLayout());
209
        info = tmSwingManager.newInformationViewer();
210
        info.loadMapInfromation(model.getPortableView());
211
        infoPanel.add(new JScrollPane(info.getSwingComponent()));
212
        infoPanel.setBorder(BorderFactory.createTitledBorder(tmSwingManager
213
            .getTranslation("portable_view_information")));
214
        return infoPanel;
215
    }
216

    
217
    /**
218
     * @return
219
     */
220
    private JPanel createCommentsPanel() {
221
        GridBagLayoutPanel commentPanel = new GridBagLayoutPanel();
222
        comments = new JTextArea(model.getComment());
223
        JScrollPane commentsScroll = new JScrollPane(comments);
224
        commentPanel.addComponent(tmSwingManager.getTranslation("comments"),
225
            commentsScroll);
226
        return commentPanel;
227
    }
228

    
229
    private void accept() {
230
        if (StringUtils.isBlank(name.getText())) {
231
            tmSwingManager.getWindowManager().showMessageDialog(this,
232
                tmSwingManager.getTranslation("portable_view_properties"),
233
                tmSwingManager.getTranslation("name_is_required"),
234
                MESSAGE_DIALOG_TYPE.ERROR);
235
            return;
236
        }
237
        model.setName(name.getText());
238
        model.setComment(comments.getText());
239
        close();
240
    }
241

    
242
    public void close() {
243
        PluginServices.getMDIManager().closeWindow(this);
244
    }
245

    
246
    public WindowInfo getWindowInfo() {
247
        if (windowInfo == null) {
248
            windowInfo =
249
                new WindowInfo(WindowInfo.MAXIMIZABLE | WindowInfo.RESIZABLE);
250

    
251
            windowInfo.setTitle(tmSwingManager
252
                .getTranslation("portable_view_properties"));
253

    
254
            windowInfo.setWidth(DEFAULT_WIDTH);
255
            windowInfo.setHeight(DEFAULT_HEIGHT);
256
        }
257
        return windowInfo;
258
    }
259

    
260
    public Object getWindowProfile() {
261
        return WindowInfo.PROPERTIES_PROFILE;
262
    }
263

    
264
    public Object getWindowModel() {
265
        return model;
266
    }
267

    
268
}