001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032: package com.vividsolutions.jump.workbench.ui.plugin.wms;
033:
034: import java.awt.Dimension;
035: import java.awt.GridBagConstraints;
036: import java.awt.GridBagLayout;
037: import java.awt.Insets;
038: import java.util.Iterator;
039: import java.util.List;
040:
041: import javax.swing.BorderFactory;
042: import javax.swing.DefaultComboBoxModel;
043: import javax.swing.JComboBox;
044: import javax.swing.JComponent;
045: import javax.swing.JLabel;
046: import javax.swing.JPanel;
047: import javax.swing.JTextField;
048: import javax.swing.border.Border;
049:
050: import com.vividsolutions.jump.I18N;
051: import com.vividsolutions.jump.workbench.plugin.EnableCheck;
052: import com.vividsolutions.jump.workbench.ui.InputChangedListener;
053: import com.vividsolutions.jump.workbench.ui.TransparencyPanel;
054: import com.vividsolutions.wms.WMService;
055:
056: public class EditWMSQueryPanel extends JPanel {
057: private GridBagLayout gridBagLayout1 = new GridBagLayout();
058: private MapLayerPanel mapLayerPanel = new MapLayerPanel();
059: private JLabel srsLabel = new JLabel();
060: private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
061: private JComboBox srsComboBox = new JComboBox(comboBoxModel);
062: private Border border1;
063: private TransparencyPanel transparencyPanel = new TransparencyPanel();
064: private JLabel transparencyLabel = new JLabel();
065: private JLabel urlLabel = new JLabel();
066: private JTextField urlTextField = new JTextField();
067:
068: private EnableCheck[] enableChecks = new EnableCheck[] {
069: new EnableCheck() {
070: public String check(JComponent component) {
071: return mapLayerPanel.getChosenMapLayers().isEmpty() ? I18N
072: .get("ui.plugin.wms.EditWMSQueryPanel.at-least-one-wms-must-be-chosen")
073: : null;
074: }
075: }, new EnableCheck() {
076: public String check(JComponent component) {
077: return srsComboBox.getSelectedItem() == null ? MapLayerWizardPanel.NO_COMMON_SRS_MESSAGE
078: : null;
079: }
080: } };
081:
082: public EditWMSQueryPanel(WMService service,
083: List initialChosenMapLayers, String initialSRS, int alpha) {
084: try {
085: jbInit();
086: String url = service.getServerUrl();
087: if (url.endsWith("?") || url.endsWith("&")) {
088: url = url.substring(0, url.length() - 1);
089: }
090: urlTextField.setText(url);
091: mapLayerPanel.init(service, initialChosenMapLayers);
092:
093: updateComboBox();
094: String srsName = SRSUtils.getName(initialSRS);
095: srsComboBox.setSelectedItem(srsName);
096:
097: mapLayerPanel.add(new InputChangedListener() {
098: public void inputChanged() {
099: updateComboBox();
100: }
101: });
102: setAlpha(alpha);
103: } catch (Exception ex) {
104: ex.printStackTrace();
105: }
106: }
107:
108: public int getAlpha() {
109: return 255 - transparencyPanel.getSlider().getValue();
110: }
111:
112: private void setAlpha(int alpha) {
113: transparencyPanel.getSlider().setValue(255 - alpha);
114: }
115:
116: public String getSRS() {
117: int index = srsComboBox.getSelectedIndex();
118: String srsCode = (String) mapLayerPanel.commonSRSList().get(
119: index);
120: return srsCode;
121: }
122:
123: /**
124: * Method updateComboBox.
125: */
126: private void updateComboBox() {
127: String selectedSRS = (String) srsComboBox.getSelectedItem();
128:
129: // this method does get called many times when no SRS are available here
130: // this makes sure that the selected SRS stays selected when available
131: if (mapLayerPanel.commonSRSList().size() == 0) {
132: return;
133: }
134:
135: comboBoxModel.removeAllElements();
136:
137: for (Iterator i = mapLayerPanel.commonSRSList().iterator(); i
138: .hasNext();) {
139: String commonSRS = (String) i.next();
140: String srsName = SRSUtils.getName(commonSRS);
141: comboBoxModel.addElement(srsName);
142: }
143:
144: //selectedSRS might no longer be in the combobox, in which case nothing will be selected. [Jon Aquino]
145: srsComboBox.setSelectedItem(selectedSRS);
146: if ((srsComboBox.getSelectedItem() == null)
147: && (srsComboBox.getItemCount() > 0)) {
148: srsComboBox.setSelectedIndex(0);
149: }
150: }
151:
152: void jbInit() throws Exception {
153: border1 = BorderFactory.createEmptyBorder(10, 10, 10, 10);
154: this .setLayout(gridBagLayout1);
155: srsLabel
156: .setText(I18N
157: .get("ui.plugin.wms.EditWMSQueryPanel.coordinate-reference-system"));
158: this .setBorder(border1);
159: this .setToolTipText("");
160: srsComboBox.setMinimumSize(new Dimension(125, 21));
161: srsComboBox.setToolTipText("");
162: transparencyLabel.setText(I18N
163: .get("ui.plugin.wms.EditWMSQueryPanel.transparency"));
164: urlLabel.setText("URL:");
165: urlTextField.setBorder(null);
166: urlTextField.setOpaque(false);
167: urlTextField.setEditable(false);
168: this .add(mapLayerPanel,
169: new GridBagConstraints(1, 2, 3, 1, 1.0, 1.0,
170: GridBagConstraints.CENTER,
171: GridBagConstraints.BOTH, new Insets(10, 0, 10,
172: 0), 0, 0));
173: this .add(srsLabel, new GridBagConstraints(1, 3, 2, 1, 0.0, 0.0,
174: GridBagConstraints.WEST, GridBagConstraints.NONE,
175: new Insets(0, 0, 10, 5), 0, 0));
176: this .add(srsComboBox, new GridBagConstraints(3, 3, 1, 1, 0.0,
177: 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE,
178: new Insets(0, 0, 10, 0), 0, 0));
179: this .add(transparencyPanel, new GridBagConstraints(3, 6, 1, 1,
180: 0.0, 0.0, GridBagConstraints.WEST,
181: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
182: this .add(transparencyLabel, new GridBagConstraints(1, 6, 2, 1,
183: 0.0, 0.0, GridBagConstraints.WEST,
184: GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
185: this .add(urlLabel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
186: GridBagConstraints.WEST, GridBagConstraints.NONE,
187: new Insets(0, 0, 0, 5), 0, 0));
188: this .add(urlTextField, new GridBagConstraints(2, 0, 2, 1, 0.0,
189: 0.0, GridBagConstraints.WEST,
190: GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0),
191: 0, 0));
192: }
193:
194: public List getChosenMapLayers() {
195: return mapLayerPanel.getChosenMapLayers();
196: }
197:
198: public EnableCheck[] getEnableChecks() {
199: return enableChecks;
200: }
201: }
|