Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.app.wmsclient / src / main / java / org / gvsig / raster / wms / app / wmsclient / gui / panel / WebMapContextFileChooserAccessory.java @ 2484

History | View | Annotate | Download (5.36 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
 
23
package org.gvsig.raster.wms.app.wmsclient.gui.panel;
24

    
25
import java.awt.Dimension;
26
import java.util.List;
27

    
28
import javax.swing.JComboBox;
29
import javax.swing.JLabel;
30
import javax.swing.JPanel;
31

    
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.app.project.ProjectManager;
34
import org.gvsig.app.project.documents.Document;
35
import org.gvsig.app.project.documents.view.DefaultViewDocument;
36
import org.gvsig.app.project.documents.view.ViewManager;
37
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel;
38

    
39

    
40
public class WebMapContextFileChooserAccessory extends JPanel {
41
        public static int NEW_VIEW = -1;
42
        public static int CURRENT_VIEW = -1;
43
        public static int USERS_VIEW_SELECTION = -1;
44

    
45
        private JComboBox cmbMode = null;
46
        private JComboBox cmbViews = null;
47
        private JLabel lblExplain = null;
48
        private String currentView = null;
49

    
50
        public WebMapContextFileChooserAccessory(String currentViewName) {
51
                super();
52
                currentView = currentViewName;
53
                initialize();
54
        }
55

    
56
        private void initialize() {
57
                lblExplain = new JLabel();
58
                lblExplain.setBounds(25, 52, 268, 55);
59
                lblExplain.setText(PluginServices.getText(this, "html_in_a_new_view"));
60
                setLayout(null);
61
                setSize(315, 240);
62
                setPreferredSize(new Dimension(315, 72));
63
                this.add(getCmbViews(), null);
64
                this.add(lblExplain, null);
65
                setBorder(javax.swing.BorderFactory.createTitledBorder(
66
                                  null, PluginServices.getText(this, "open_layers_as"),
67
                                  javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
68
                                  javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
69
                this.add(getCmbMode(), null);
70
        }
71

    
72
        /**
73
         * This method initializes cmbBoxMode
74
         *
75
         * @return javax.swing.JComboBox
76
         */
77
        private JComboBox getCmbMode() {
78
                if (cmbMode == null) {
79
                        cmbMode = new JComboBox();
80
                        cmbMode.setBounds(25, 26, 268, 20);
81
                        cmbMode.removeAllItems();
82
                        cmbMode.addItemListener(new java.awt.event.ItemListener() {
83
                                public void itemStateChanged(java.awt.event.ItemEvent e) {
84
                                        cmbViews.setVisible(false);
85

    
86
                                        if (cmbMode.getSelectedIndex() == NEW_VIEW) {
87
                                                lblExplain.setText(PluginServices.getText(this, "html_in_a_new_view"));
88
                                        } else if (cmbMode.getSelectedIndex() == CURRENT_VIEW) {
89
                                                lblExplain.setText(PluginServices.getText(this, "html_in_the_current_view"));
90
                                        } else if (cmbMode.getSelectedIndex() == USERS_VIEW_SELECTION) {
91
                                                lblExplain.setText(PluginServices.getText(this, "html_in_other_view"));
92
                                                cmbViews.setVisible(true);
93
                                        }
94
                                }
95
                        });
96
                        cmbMode.addItem(PluginServices.getText(this, "a_new_view"));
97
                        if (currentView!=null) {
98
                                cmbMode.addItem(PluginServices.getText(this, "layers_in_the_current_view")+": "+currentView);
99
                                CURRENT_VIEW = cmbMode.getItemCount()-1;
100
                                cmbMode.setSelectedIndex(CURRENT_VIEW);
101
                        }
102
                        if (getCmbViews().getItemCount()>0) {
103
                                cmbMode.addItem(PluginServices.getText(this, "layers_in_other_view"));
104
                                USERS_VIEW_SELECTION = cmbMode.getItemCount() -1;
105
                        }
106
                }
107

    
108
                return cmbMode;
109
        }
110

    
111
        public void setCurrentView(AbstractViewPanel v) {
112
                currentView = v.getName();
113
        }
114

    
115
        public DefaultViewDocument getSelectedView() {
116
                String viewName = null;
117
                if (getCmbMode().getSelectedIndex() == NEW_VIEW)
118
                        return null;
119
                else if (getCmbMode().getSelectedIndex() == CURRENT_VIEW)
120
                        viewName = currentView;
121
                else if (getCmbMode().getSelectedIndex() == USERS_VIEW_SELECTION)
122
                        viewName = (String) getCmbViews().getSelectedItem();
123
                return (DefaultViewDocument) ProjectManager.getInstance().getCurrentProject().getDocument(viewName, ViewManager.TYPENAME);
124
//                ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
125
//                return (ProjectView) pe.getProject().getProjectDocumentByName(viewName, ProjectViewFactory.registerName);
126
        }
127

    
128
        public int getOption() {
129
                return cmbMode.getSelectedIndex();
130
        }
131

    
132
        /**
133
         * This method initializes cmbViews
134
         *
135
         * @return javax.swing.JComboBox
136
         */
137
        private JComboBox getCmbViews() {
138
                if (cmbViews == null) {
139
                        cmbViews = new JComboBox();
140
                        cmbViews.setBounds(25, 114, 266, 20);
141
                        List<Document> views = ProjectManager.getInstance().getCurrentProject().getDocuments( ViewManager.TYPENAME);
142
                        for (Document v : views) {
143
                                cmbViews.addItem(v.getName());
144
                        }
145
                        
146
//                        ProjectExtension pe = (ProjectExtension) PluginServices.getExtension(ProjectExtension.class);
147
//                        ArrayList views = pe.getProject().getDocumentsByType(ProjectViewFactory.registerName);
148
//                        for (int i = 0; i < views.size(); i++) {
149
//                                ProjectView v = (ProjectView)views.get(i);
150
//                                cmbViews.addItem(v.getName());
151
//                        }
152
                }
153
                return cmbViews;
154
        }
155
}  //  @jve:decl-index=0:visual-constraint="10,0"