svn-gvsig-desktop / 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 @ 43925
History | View | Annotate | Download (4.28 KB)
1 |
/*
|
---|---|
2 |
* To change this license header, choose License Headers in Project Properties.
|
3 |
* To change this template file, choose Tools | Templates
|
4 |
* and open the template in the editor.
|
5 |
*/
|
6 |
package org.gvsig.export.swing.impl.panels; |
7 |
|
8 |
import java.awt.event.ActionEvent; |
9 |
import java.awt.event.ActionListener; |
10 |
import java.util.List; |
11 |
import javax.swing.DefaultListModel; |
12 |
import javax.swing.JComponent; |
13 |
import javax.swing.JScrollPane; |
14 |
import javax.swing.event.ListSelectionEvent; |
15 |
import javax.swing.event.ListSelectionListener; |
16 |
import org.gvsig.export.ExportLocator; |
17 |
import org.gvsig.export.ExportParameters; |
18 |
import org.gvsig.export.Filter; |
19 |
import org.gvsig.export.spi.ExportServiceFactory; |
20 |
import org.gvsig.export.swing.JExportProcessPanel; |
21 |
import org.gvsig.export.swing.spi.ExportPanel; |
22 |
import org.gvsig.export.swing.spi.ExportPanelValidationException; |
23 |
import org.gvsig.tools.ToolsLocator; |
24 |
import org.gvsig.tools.i18n.I18nManager; |
25 |
import org.gvsig.tools.swing.api.ListElement; |
26 |
|
27 |
/**
|
28 |
*
|
29 |
* @author jjdelcerro
|
30 |
*/
|
31 |
public class SelectFormatPanel |
32 |
extends SelectFormatPanelView
|
33 |
implements ExportPanel
|
34 |
{ |
35 |
|
36 |
private final JExportProcessPanel processPanel; |
37 |
private final ExportParameters parameters; |
38 |
private final Filter<ExportServiceFactory> serviceFilter; |
39 |
private final ActionListener onExitPanel; |
40 |
|
41 |
public SelectFormatPanel(
|
42 |
JExportProcessPanel processPanel, |
43 |
ExportParameters parameters, |
44 |
Filter<ExportServiceFactory> serviceFilter,
|
45 |
ActionListener onExitPanel
|
46 |
) { |
47 |
this.processPanel = processPanel;
|
48 |
this.parameters = parameters;
|
49 |
this.serviceFilter = serviceFilter;
|
50 |
this.onExitPanel = onExitPanel;
|
51 |
initComponents(); |
52 |
} |
53 |
|
54 |
private void initComponents() { |
55 |
this.txtDescription.setBackground(this.lblEmpty.getBackground()); |
56 |
this.txtDescription.setForeground(this.lblEmpty.getForeground()); |
57 |
if( this.txtDescription.getParent().getParent() instanceof JScrollPane ) { |
58 |
JScrollPane scrollPanel = (JScrollPane) this.txtDescription.getParent().getParent(); |
59 |
scrollPanel.setBorder(null);
|
60 |
} |
61 |
|
62 |
List<ExportServiceFactory> factories = ExportLocator.getServiceManager()
|
63 |
.getServiceFactories(serviceFilter); |
64 |
DefaultListModel model = new DefaultListModel(); |
65 |
for (ExportServiceFactory factory : factories) {
|
66 |
model.addElement(new ListElement(factory.getLabel(),factory));
|
67 |
} |
68 |
this.lstServices.setModel(model);
|
69 |
this.lstServices.addListSelectionListener(new ListSelectionListener() { |
70 |
@Override
|
71 |
public void valueChanged(ListSelectionEvent e) { |
72 |
if( e.getValueIsAdjusting() ) {
|
73 |
return;
|
74 |
} |
75 |
doUpdateDescription(); |
76 |
} |
77 |
}); |
78 |
} |
79 |
|
80 |
private void doUpdateDescription() { |
81 |
ExportServiceFactory factory = this.getSelectedService();
|
82 |
if( factory == null ) { |
83 |
return;
|
84 |
} |
85 |
this.txtDescription.setText(factory.getDescription());
|
86 |
this.processPanel.setButtonEnabled(JExportProcessPanel.BUTTON_NEXT, true); |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public String getIdPanel() { |
91 |
return "SelectFormatPanel"; |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public String getTitlePanel() { |
96 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
97 |
return i18n.getTranslation("select_format_to_export"); |
98 |
} |
99 |
|
100 |
@Override
|
101 |
public boolean validatePanel() throws ExportPanelValidationException { |
102 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
103 |
ExportServiceFactory factory = this.getSelectedService();
|
104 |
if( factory == null ) { |
105 |
throw new ExportPanelValidationException( |
106 |
i18n.getTranslation("_You_must_select_an_item_from_the_list_of-formats")
|
107 |
); |
108 |
} |
109 |
return true; |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public void enterPanel() { |
114 |
|
115 |
} |
116 |
|
117 |
@Override
|
118 |
public void exitPanel() { |
119 |
this.onExitPanel.actionPerformed(new ActionEvent(this, 0, "exitPanel")); |
120 |
} |
121 |
|
122 |
@Override
|
123 |
public JComponent asJComponent() { |
124 |
return this; |
125 |
} |
126 |
|
127 |
public ExportServiceFactory getSelectedService() {
|
128 |
ExportServiceFactory factory = (ExportServiceFactory) ListElement.getSelected(lstServices); |
129 |
return factory;
|
130 |
} |
131 |
|
132 |
} |