gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.algorithm / org.gvsig.raster.tools.algorithm.swing / org.gvsig.raster.tools.algorithm.swing.impl / src / main / java / org / gvsig / raster / tools / algorithm / swing / impl / bean / inputlayer / InputLayerImpl.java @ 2818
History | View | Annotate | Download (4.8 KB)
1 | 2480 | nbrodin | /* 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.raster.tools.algorithm.swing.impl.bean.inputlayer; |
||
23 | |||
24 | import java.awt.GridBagConstraints; |
||
25 | import java.awt.GridBagLayout; |
||
26 | import java.awt.event.ActionEvent; |
||
27 | import java.awt.event.ActionListener; |
||
28 | |||
29 | import javax.swing.BorderFactory; |
||
30 | import javax.swing.JComboBox; |
||
31 | import javax.swing.JLabel; |
||
32 | import javax.swing.JPanel; |
||
33 | |||
34 | import org.gvsig.i18n.Messages; |
||
35 | import org.gvsig.raster.swing.listener.PanelChangeEvent; |
||
36 | import org.gvsig.raster.swing.listener.PanelChangeListener; |
||
37 | import org.gvsig.raster.tools.algorithm.swing.bean.LayerComboElement; |
||
38 | |||
39 | /**
|
||
40 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
41 | */
|
||
42 | public class InputLayerImpl extends JPanel implements ActionListener { |
||
43 | private static final long serialVersionUID = 1L; |
||
44 | private JComboBox inputLayerCombo = null; |
||
45 | private JComboBox bandsSelectorCombo = null; |
||
46 | private JLabel layerLabel = null; |
||
47 | private JLabel bandsLabel = null; |
||
48 | private String boxLabel = null; |
||
49 | private boolean borderEnabled = false; |
||
50 | private boolean labelsEnabled = false; |
||
51 | private PanelChangeListener listener = null; |
||
52 | |||
53 | public InputLayerImpl(String[] labels, boolean border, boolean labelEnabled) { |
||
54 | if(labels != null) { |
||
55 | layerLabel = new JLabel(labels[0]); |
||
56 | bandsLabel = new JLabel(labels[1]); |
||
57 | boxLabel = labels[2];
|
||
58 | } else {
|
||
59 | boxLabel = Messages.getText("input");
|
||
60 | } |
||
61 | this.borderEnabled = border;
|
||
62 | this.labelsEnabled = labelEnabled;
|
||
63 | init(); |
||
64 | } |
||
65 | |||
66 | private void init() { |
||
67 | this.setLayout(new GridBagLayout()); |
||
68 | if(borderEnabled)
|
||
69 | setBorder(BorderFactory.createTitledBorder(boxLabel));
|
||
70 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
||
71 | gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; |
||
72 | gridBagConstraints1.weightx = 1;
|
||
73 | gridBagConstraints1.insets = new java.awt.Insets(0, 2, 0, 0); |
||
74 | |||
75 | if(labelsEnabled) {
|
||
76 | gridBagConstraints1.gridx = 0;
|
||
77 | gridBagConstraints1.gridy = 0;
|
||
78 | this.add(getLayerLabel(), gridBagConstraints1);
|
||
79 | } |
||
80 | |||
81 | gridBagConstraints1.gridx = 0;
|
||
82 | gridBagConstraints1.gridy = 1;
|
||
83 | this.add(getInputLayerCombo(), gridBagConstraints1);
|
||
84 | |||
85 | gridBagConstraints1.fill = java.awt.GridBagConstraints.NONE; |
||
86 | gridBagConstraints1.weightx = 0;
|
||
87 | |||
88 | if(labelsEnabled) {
|
||
89 | gridBagConstraints1.gridx = 1;
|
||
90 | gridBagConstraints1.gridy = 0;
|
||
91 | this.add(getBandsLabel(), gridBagConstraints1);
|
||
92 | } |
||
93 | |||
94 | gridBagConstraints1.gridx = 1;
|
||
95 | gridBagConstraints1.gridy = 1;
|
||
96 | this.add(getBandsSelectorCombo(), gridBagConstraints1);
|
||
97 | } |
||
98 | |||
99 | public JComboBox getInputLayerCombo() { |
||
100 | if(inputLayerCombo == null) { |
||
101 | inputLayerCombo = new JComboBox(); |
||
102 | inputLayerCombo.addActionListener(this);
|
||
103 | } |
||
104 | return inputLayerCombo;
|
||
105 | } |
||
106 | |||
107 | public JComboBox getBandsSelectorCombo() { |
||
108 | if(bandsSelectorCombo == null) { |
||
109 | bandsSelectorCombo = new JComboBox(); |
||
110 | bandsSelectorCombo.addActionListener(this);
|
||
111 | } |
||
112 | return bandsSelectorCombo;
|
||
113 | } |
||
114 | |||
115 | public JLabel getLayerLabel() { |
||
116 | if(layerLabel == null) |
||
117 | layerLabel = new JLabel(Messages.getText("layers")); |
||
118 | return layerLabel;
|
||
119 | } |
||
120 | |||
121 | public JLabel getBandsLabel() { |
||
122 | if(bandsLabel == null) |
||
123 | bandsLabel = new JLabel(Messages.getText("bands")); |
||
124 | return bandsLabel;
|
||
125 | } |
||
126 | |||
127 | public void setEnabled(boolean enable) { |
||
128 | getBandsSelectorCombo().setEnabled(enable); |
||
129 | getInputLayerCombo().setEnabled(enable); |
||
130 | } |
||
131 | |||
132 | public void actionPerformed(ActionEvent e) { |
||
133 | if(listener != null) |
||
134 | listener.panelHasChanged(new PanelChangeEvent(e));
|
||
135 | if(e.getSource() == getInputLayerCombo()) {
|
||
136 | if(getInputLayerCombo().getSelectedItem() instanceof LayerComboElement) { |
||
137 | int nElements = ((LayerComboElement)getInputLayerCombo().getSelectedItem()).getNumOfElements();
|
||
138 | getBandsSelectorCombo().removeAllItems(); |
||
139 | getBandsSelectorCombo().addItem(Messages.getText("all"));
|
||
140 | for (int i = 0; i < nElements; i++) { |
||
141 | getBandsSelectorCombo().addItem(i); |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 | } |
||
146 | |||
147 | public void addPanelChangeEvent(PanelChangeListener listener) { |
||
148 | this.listener = listener;
|
||
149 | } |
||
150 | } |