gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster / org.gvsig.fmap.mapcontext.raster.swing / org.gvsig.fmap.mapcontext.raster.swing.impl / src / main / java / org / gvsig / fmap / mapcontext / raster / swing / impl / operations / OperationSelectorPanelController.java @ 8799
History | View | Annotate | Download (3.89 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2017 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.mapcontext.raster.swing.impl.operations; |
24 |
|
25 |
import java.util.Iterator; |
26 |
import java.util.List; |
27 |
import java.util.Locale; |
28 |
|
29 |
import javax.swing.DefaultListModel; |
30 |
import javax.swing.JComponent; |
31 |
import javax.swing.ListSelectionModel; |
32 |
import javax.swing.event.ListSelectionEvent; |
33 |
import javax.swing.event.ListSelectionListener; |
34 |
|
35 |
import org.slf4j.Logger; |
36 |
import org.slf4j.LoggerFactory; |
37 |
|
38 |
import org.gvsig.fmap.mapcontext.raster.swing.operations.OperationSelectorPanel; |
39 |
import org.gvsig.raster.lib.buffer.api.BufferLocator; |
40 |
import org.gvsig.raster.lib.buffer.api.operations.OperationFactory; |
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
import org.gvsig.tools.i18n.I18nManager; |
43 |
|
44 |
/**
|
45 |
* @author fdiaz
|
46 |
*
|
47 |
*/
|
48 |
public class OperationSelectorPanelController extends OperationSelectorPanelView implements OperationSelectorPanel, |
49 |
ListSelectionListener {
|
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = -419078249858416625L; |
55 |
@SuppressWarnings("unused") |
56 |
private static final Logger LOG = LoggerFactory.getLogger(OperationSelectorPanelController.class); |
57 |
// private List<OperationFactory> factories;
|
58 |
|
59 |
/**
|
60 |
*
|
61 |
*/
|
62 |
@SuppressWarnings("unchecked") |
63 |
public OperationSelectorPanelController() {
|
64 |
translate(); |
65 |
initializeComponents(); |
66 |
} |
67 |
|
68 |
private void initializeComponents() { |
69 |
lstOperations.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
70 |
|
71 |
lstOperations.getSelectionModel().addListSelectionListener(this);
|
72 |
|
73 |
DefaultListModel<OperationFactory> model = new DefaultListModel<OperationFactory>(); |
74 |
List<OperationFactory> factories = BufferLocator.getOperationManager().getOperationFactories();
|
75 |
for (Iterator iterator = factories.iterator(); iterator.hasNext();) { |
76 |
OperationFactory operationFactory = (OperationFactory) iterator.next(); |
77 |
model.addElement(operationFactory); |
78 |
} |
79 |
lstOperations.setModel(model); |
80 |
lstOperations.setCellRenderer(new OperationFactoryCellRenderer());
|
81 |
} |
82 |
|
83 |
private void translate() { |
84 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
85 |
lstOperations.setToolTipText(i18nManager.getTranslation(lstOperations.getToolTipText())); |
86 |
} |
87 |
|
88 |
/**
|
89 |
* @param locale
|
90 |
*
|
91 |
*/
|
92 |
public void setLocate(Locale locale) { |
93 |
Locale l = super.getLocale(); |
94 |
if (!l.equals(locale)) {
|
95 |
translate(); |
96 |
} |
97 |
super.setLocale(locale);
|
98 |
} |
99 |
|
100 |
@Override
|
101 |
public JComponent asJComponent() { |
102 |
return this; |
103 |
} |
104 |
|
105 |
@Override
|
106 |
public void valueChanged(ListSelectionEvent e) { |
107 |
|
108 |
} |
109 |
|
110 |
@Override
|
111 |
public OperationFactory getSelected() {
|
112 |
return (OperationFactory) lstOperations.getSelectedValue();
|
113 |
} |
114 |
|
115 |
@Override
|
116 |
public void addListSelectionListener(ListSelectionListener listener) { |
117 |
lstOperations.getSelectionModel().addListSelectionListener(listener); |
118 |
} |
119 |
|
120 |
@Override
|
121 |
public void clearSelection() { |
122 |
lstOperations.clearSelection(); |
123 |
} |
124 |
} |