Revision 44386 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.impl/src/main/java/org/gvsig/export/swing/impl/panels/SelectFormatPanel.java
SelectFormatPanel.java | ||
---|---|---|
5 | 5 |
*/ |
6 | 6 |
package org.gvsig.export.swing.impl.panels; |
7 | 7 |
|
8 |
import java.awt.BorderLayout; |
|
8 | 9 |
import java.awt.event.ActionEvent; |
9 | 10 |
import java.awt.event.ActionListener; |
11 |
import java.nio.charset.Charset; |
|
10 | 12 |
import java.util.List; |
13 |
import java.util.Random; |
|
14 |
import java.util.function.Predicate; |
|
15 |
import java.util.logging.Level; |
|
16 |
import java.util.logging.Logger; |
|
11 | 17 |
import javax.swing.DefaultListModel; |
18 |
import javax.swing.JButton; |
|
12 | 19 |
import javax.swing.JComponent; |
20 |
import javax.swing.JPanel; |
|
13 | 21 |
import javax.swing.JScrollPane; |
22 |
import javax.swing.border.EmptyBorder; |
|
14 | 23 |
import javax.swing.event.ListSelectionEvent; |
15 | 24 |
import javax.swing.event.ListSelectionListener; |
16 | 25 |
import org.gvsig.export.ExportLocator; |
... | ... | |
21 | 30 |
import org.gvsig.export.swing.spi.ExportPanel; |
22 | 31 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
23 | 32 |
import org.gvsig.tools.ToolsLocator; |
33 |
import org.gvsig.tools.bookmarksandhistory.Bookmark; |
|
34 |
import org.gvsig.tools.bookmarksandhistory.Bookmarks; |
|
35 |
import org.gvsig.tools.bookmarksandhistory.History; |
|
24 | 36 |
import org.gvsig.tools.i18n.I18nManager; |
25 | 37 |
import org.gvsig.tools.swing.api.ListElement; |
38 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
39 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController; |
|
40 |
import org.gvsig.tools.swing.api.bookmarkshistory.BookmarksController.BookmarkEvent; |
|
41 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController; |
|
42 |
import org.gvsig.tools.swing.api.bookmarkshistory.HistoryController.HistoryEvent; |
|
43 |
import org.slf4j.LoggerFactory; |
|
26 | 44 |
|
27 | 45 |
/** |
28 | 46 |
* |
29 | 47 |
* @author jjdelcerro |
30 | 48 |
*/ |
31 |
public class SelectFormatPanel
|
|
49 |
public class SelectFormatPanel |
|
32 | 50 |
extends SelectFormatPanelView |
33 |
implements ExportPanel |
|
34 |
{ |
|
51 |
implements ExportPanel { |
|
35 | 52 |
|
36 | 53 |
private final JExportProcessPanel processPanel; |
37 |
private final ExportParameters parameters;
|
|
54 |
private ExportParameters parameters; |
|
38 | 55 |
private final Filter<ExportServiceFactory> serviceFilter; |
39 | 56 |
private final ActionListener onExitPanel; |
57 |
private BookmarksController<ExportParameters> bookmarksController; |
|
58 |
private HistoryController historyController; |
|
59 |
private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(SelectFormatPanel.class); |
|
40 | 60 |
|
41 | 61 |
public SelectFormatPanel( |
42 | 62 |
JExportProcessPanel processPanel, |
43 | 63 |
ExportParameters parameters, |
44 | 64 |
Filter<ExportServiceFactory> serviceFilter, |
45 | 65 |
ActionListener onExitPanel |
46 |
) {
|
|
66 |
) { |
|
47 | 67 |
this.processPanel = processPanel; |
48 | 68 |
this.parameters = parameters; |
49 | 69 |
this.serviceFilter = serviceFilter; |
... | ... | |
54 | 74 |
private void initComponents() { |
55 | 75 |
this.txtDescription.setBackground(this.lblEmpty.getBackground()); |
56 | 76 |
this.txtDescription.setForeground(this.lblEmpty.getForeground()); |
57 |
if( this.txtDescription.getParent().getParent() instanceof JScrollPane ) {
|
|
77 |
if (this.txtDescription.getParent().getParent() instanceof JScrollPane) {
|
|
58 | 78 |
JScrollPane scrollPanel = (JScrollPane) this.txtDescription.getParent().getParent(); |
59 | 79 |
scrollPanel.setBorder(null); |
60 | 80 |
} |
61 |
|
|
81 |
|
|
62 | 82 |
List<ExportServiceFactory> factories = ExportLocator.getServiceManager() |
63 | 83 |
.getServiceFactories(serviceFilter); |
64 | 84 |
DefaultListModel model = new DefaultListModel(); |
65 | 85 |
for (ExportServiceFactory factory : factories) { |
66 |
model.addElement(new ListElement(factory.getLabel(),factory)); |
|
86 |
model.addElement(new ListElement(factory.getLabel(), factory));
|
|
67 | 87 |
} |
68 | 88 |
this.lstServices.setModel(model); |
69 | 89 |
this.lstServices.addListSelectionListener(new ListSelectionListener() { |
70 | 90 |
@Override |
71 | 91 |
public void valueChanged(ListSelectionEvent e) { |
72 |
if( e.getValueIsAdjusting() ) {
|
|
92 |
if (e.getValueIsAdjusting()) {
|
|
73 | 93 |
return; |
74 | 94 |
} |
75 | 95 |
doUpdateDescription(); |
96 |
// doUpdateFilter(); |
|
76 | 97 |
} |
77 | 98 |
}); |
99 |
|
|
100 |
Bookmarks<ExportParameters> bookmarks = ExportLocator.getServiceManager().getBookmarks(); |
|
101 |
this.bookmarksController = ToolsSwingLocator.getToolsSwingManager().createBookmarksController(bookmarks, this.btnBookmark); |
|
102 |
this.bookmarksController.setAllowAddBookmarks(false); |
|
103 |
this.bookmarksController.setFilter(new Predicate<Bookmark<ExportParameters>>() { |
|
104 |
@Override |
|
105 |
public boolean test(Bookmark<ExportParameters> bookmark) { |
|
106 |
ExportParameters params = bookmark.getValue(); |
|
107 |
if (params == null) { |
|
108 |
return false; |
|
109 |
} |
|
110 |
ExportServiceFactory selectedService = SelectFormatPanel.this.getSelectedService(); |
|
111 |
if (selectedService == null) { |
|
112 |
return true; |
|
113 |
} |
|
114 |
String currentFactory = selectedService.getName(); |
|
115 |
String paramsServiceName = params.getServiceName(); |
|
116 |
return (paramsServiceName == null ? currentFactory == null : paramsServiceName.equals(currentFactory)); |
|
117 |
} |
|
118 |
}); |
|
119 |
this.bookmarksController.addActionListener(new ActionListener() { |
|
120 |
@Override |
|
121 |
public void actionPerformed(ActionEvent e) { |
|
122 |
BookmarkEvent<ExportParameters> b = (BookmarkEvent<ExportParameters>) e; |
|
123 |
if (b.getID() == BookmarksController.ID_GETVALUE) { //e.getActionCommand()) { |
|
124 |
// b.setCurrentValue(SelectFormatPanel.this.parameters.clone()) |
|
125 |
} else if (b.getID() == BookmarksController.ID_SETVALUE) { |
|
126 |
if (b.getCurrentValue() == null) { |
|
127 |
return; |
|
128 |
} |
|
129 |
ExportParameters exportParams = null; |
|
130 |
try { |
|
131 |
exportParams = b.getCurrentValue().clone(); |
|
132 |
} catch (CloneNotSupportedException ex) { |
|
133 |
LOG.error("Not been able to clone export parameters"); |
|
134 |
return; |
|
135 |
} |
|
136 |
setSelectedService(exportParams.getFactory()); |
|
137 |
|
|
138 |
SelectFormatPanel.this.processPanel.getProcess().setParameters(exportParams); |
|
139 |
SelectFormatPanel.this.parameters = exportParams; |
|
140 |
} |
|
141 |
|
|
142 |
} |
|
143 |
}); |
|
144 |
History<ExportParameters> history = ExportLocator.getServiceManager().getHistory(); |
|
145 |
this.historyController = ToolsSwingLocator.getToolsSwingManager().createHistoryController(history, this.btnHistory); |
|
146 |
this.historyController.setFilter(new Predicate<ExportParameters>() { |
|
147 |
@Override |
|
148 |
public boolean test(ExportParameters params) { |
|
149 |
if (params == null) { |
|
150 |
return false; |
|
151 |
} |
|
152 |
ExportServiceFactory selectedService = SelectFormatPanel.this.getSelectedService(); |
|
153 |
if (selectedService == null) { |
|
154 |
return false; |
|
155 |
} |
|
156 |
String currentFactory = selectedService.getName(); |
|
157 |
String paramsServiceName = params.getServiceName(); |
|
158 |
return (paramsServiceName == null ? currentFactory == null : paramsServiceName.equals(currentFactory)); |
|
159 |
} |
|
160 |
}); |
|
161 |
this.historyController.addActionListener(new ActionListener() { |
|
162 |
@Override |
|
163 |
public void actionPerformed(ActionEvent e) { |
|
164 |
HistoryEvent<ExportParameters> he = (HistoryEvent<ExportParameters>) e; |
|
165 |
ExportParameters exportParams = null; |
|
166 |
if (he.getCurrentValue() == null) { |
|
167 |
return; |
|
168 |
} |
|
169 |
try { |
|
170 |
exportParams = he.getCurrentValue().clone(); |
|
171 |
} catch (CloneNotSupportedException ex) { |
|
172 |
LOG.error("Not been able to clone export parameters"); |
|
173 |
return; |
|
174 |
} |
|
175 |
setSelectedService(exportParams.getFactory()); |
|
176 |
|
|
177 |
SelectFormatPanel.this.processPanel.getProcess().setParameters(exportParams); |
|
178 |
SelectFormatPanel.this.parameters = exportParams; |
|
179 |
|
|
180 |
} |
|
181 |
} |
|
182 |
); |
|
183 |
|
|
184 |
// this.jpnTabs.setLayout(new BorderLayout()); |
|
185 |
// |
|
186 |
// EmptyBorder emptyborder2x2 = new EmptyBorder(2, 2, 2, 2); |
|
187 |
// bookmarksButton.setBorder(emptyborder2x2); |
|
188 |
// historyButton.setBorder(emptyborder2x2); |
|
189 |
// JPanel subPanel = new JPanel(); |
|
190 |
// subPanel.add(historyButton); |
|
191 |
// subPanel.add(bookmarksButton); |
|
192 |
// this.jpnTabs.add(subPanel, BorderLayout.EAST); |
|
193 |
|
|
78 | 194 |
} |
79 |
|
|
195 |
|
|
80 | 196 |
private void doUpdateDescription() { |
81 | 197 |
ExportServiceFactory factory = this.getSelectedService(); |
82 |
if( factory == null ) {
|
|
198 |
if (factory == null) {
|
|
83 | 199 |
return; |
84 | 200 |
} |
85 | 201 |
this.txtDescription.setText(factory.getDescription()); |
... | ... | |
90 | 206 |
public String getIdPanel() { |
91 | 207 |
return "SelectFormatPanel"; |
92 | 208 |
} |
93 |
|
|
209 |
|
|
94 | 210 |
@Override |
95 | 211 |
public String getTitlePanel() { |
96 | 212 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
... | ... | |
101 | 217 |
public boolean validatePanel() throws ExportPanelValidationException { |
102 | 218 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
103 | 219 |
ExportServiceFactory factory = this.getSelectedService(); |
104 |
if( factory == null ) {
|
|
220 |
if (factory == null) {
|
|
105 | 221 |
throw new ExportPanelValidationException( |
106 |
i18n.getTranslation("_You_must_select_an_item_from_the_list_of-formats") |
|
222 |
i18n.getTranslation("_You_must_select_an_item_from_the_list_of-formats")
|
|
107 | 223 |
); |
108 | 224 |
} |
109 | 225 |
return true; |
... | ... | |
122 | 238 |
@Override |
123 | 239 |
public void nextPanel() { |
124 | 240 |
this.onExitPanel.actionPerformed(new ActionEvent(this, 0, "exitPanel")); |
241 |
// ExportEntry currentEntry = this.exportationPanelParameters.getCurrentEntry(); |
|
242 |
// if (currentEntry != null) { |
|
243 |
// ExportParameters exportParams = currentEntry.getParameters(); |
|
244 |
// if (exportParams != null) { |
|
245 |
// this.processPanel.getProcess().setParameters(exportParams); |
|
246 |
// } |
|
247 |
// } |
|
125 | 248 |
} |
126 | 249 |
|
127 | 250 |
@Override |
128 | 251 |
public JComponent asJComponent() { |
129 | 252 |
return this; |
130 | 253 |
} |
131 |
|
|
254 |
|
|
132 | 255 |
public ExportServiceFactory getSelectedService() { |
133 | 256 |
ExportServiceFactory factory = (ExportServiceFactory) ListElement.getSelected(lstServices); |
134 | 257 |
return factory; |
135 | 258 |
} |
136 |
|
|
259 |
|
|
260 |
public void setSelectedService(ExportServiceFactory factory) { |
|
261 |
ListElement.setSelected(lstServices, factory); |
|
262 |
} |
|
263 |
|
|
137 | 264 |
} |
Also available in: Unified diff