Statistics
| Revision:

gvsig-geoprocess / org.gvsig.sextante / trunk / org.gvsig.sextante.app / org.gvsig.sextante.app.extension / src / main / java / org / gvsig / sextante / app / extension / ButtonDefinitionDialog.java @ 43

History | View | Annotate | Download (4.29 KB)

1 20 nbrodin
package org.gvsig.sextante.app.extension;
2
import info.clearthought.layout.TableLayout;
3
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6
7
import javax.swing.JButton;
8
import javax.swing.JDialog;
9
import javax.swing.JLabel;
10
import javax.swing.JOptionPane;
11
import javax.swing.JTextField;
12
13
import org.gvsig.andami.PluginServices;
14
15
import es.unex.sextante.core.GeoAlgorithm;
16
import es.unex.sextante.gui.algorithm.FileSelectionPanel;
17
import es.unex.sextante.modeler.ModelAlgorithm;
18
19
public class ButtonDefinitionDialog extends JDialog{
20
        private static final long serialVersionUID = 1L;
21
        private JLabel jLabelName;
22
        private JTextField jTextFieldName;
23
        private JTextField jTextFieldCmd;
24
        private JLabel jLabelCmd;
25
        private AlgorithmsTreePanel jPanelAlgorithms;
26
        private JButton jButtonCancel;
27
        private JButton jButtonOK;
28
        private FileSelectionPanel jTextFieldIcon;
29
        private JLabel jLabelIcon;
30
        private Button m_Button;
31
32
        public ButtonDefinitionDialog(ToolbarConfigDialog toolbarConfigDialog){
33
34
                super(toolbarConfigDialog, "SextanteToolbar", true);
35
36
                initGUI();
37
38
        }
39
40
        private void initGUI() {
41
                {
42
                        TableLayout thisLayout = new TableLayout(new double[][] {{7.0, TableLayout.FILL, TableLayout.FILL, 100.0, 100.0, 7.0}, {TableLayout.FILL, TableLayout.MINIMUM, TableLayout.MINIMUM, TableLayout.MINIMUM, 7.0, 30.0, 7.0}});
43
                        thisLayout.setHGap(5);
44
                        thisLayout.setVGap(5);
45
                        getContentPane().setLayout(thisLayout);
46
                        this.setBounds(0, 0, 365, 496);
47
                        {
48
                                jLabelName = new JLabel();
49
                                getContentPane().add(jLabelName, "1, 2");
50
                                jLabelName.setText(PluginServices.getText(this, "Name"));
51
                        }
52
                        {
53
                                jLabelIcon = new JLabel();
54
                                getContentPane().add(jLabelIcon, "1, 3");
55
                                jLabelIcon.setText(PluginServices.getText(this, "Icon"));
56
                        }
57
                        {
58
                                jTextFieldName = new JTextField();
59
                                getContentPane().add(jTextFieldName, "2, 2, 4, 2");
60
                        }
61
                        {
62
                                jTextFieldIcon = new FileSelectionPanel(false, true, new String[]{"jpg", "gif", "png", "bmp"},
63
                                                                                "*.jpg, *.bmp, *.gif, *.png");
64
                                getContentPane().add(jTextFieldIcon, "2, 3, 4, 3");
65
                        }
66
                        {
67
                                jButtonOK = new JButton();
68
                                getContentPane().add(jButtonOK, "3, 5");
69
                                jButtonOK.setText(PluginServices.getText(this, "OK"));
70
                                jButtonOK.addActionListener(new ActionListener() {
71
                                        public void actionPerformed(ActionEvent evt) {
72
                                                jButtonOKActionPerformed(evt);
73
                                        }
74
                                });
75
                        }
76
                        {
77
                                jButtonCancel = new JButton();
78
                                getContentPane().add(jButtonCancel, "4, 5");
79
                                jButtonCancel.setText(PluginServices.getText(this, "Cancel"));
80
                                jButtonCancel.addActionListener(new ActionListener() {
81
                                        public void actionPerformed(ActionEvent evt) {
82
                                                jButtonCancelActionPerformed(evt);
83
                                        }
84
                                });
85
                        }
86
                        {
87
                                jPanelAlgorithms = new AlgorithmsTreePanel(this);
88
                                getContentPane().add(jPanelAlgorithms, "1, 0, 4, 0");
89
                                {
90
                                        jLabelCmd = new JLabel();
91
                                        getContentPane().add(jLabelCmd, "1, 1");
92
                                        jLabelCmd.setText(PluginServices.getText(this, "Command"));
93
                                }
94
                                {
95
                                        jTextFieldCmd = new JTextField();
96
                                        getContentPane().add(jTextFieldCmd, "2, 1, 4, 1");
97
                                        jTextFieldCmd.setEditable(false);
98
                                        jTextFieldCmd.setEnabled(false);
99
                                }
100
                        }
101
                }
102
103
        }
104
105
        public void setCommand(GeoAlgorithm alg) {
106
107
                String sCmd = alg.getClass().toString();
108
                if (alg instanceof ModelAlgorithm){
109
                        sCmd = sCmd + "," + ((ModelAlgorithm) alg).getFilename();
110
                }
111
                else{
112
                        sCmd = sCmd + "," + " ";
113
                }
114
115
                jTextFieldCmd.setText(sCmd);
116
117
        }
118
119
        public Button getButton() {
120
121
                return m_Button;
122
123
        }
124
125
        private void jButtonOKActionPerformed(ActionEvent evt) {
126
127
                if (createButton()){
128
                        dispose();
129
                        setVisible(false);
130
                }
131
                else{
132
                        JOptionPane.showMessageDialog(null,
133
                                        PluginServices.getText(this, "Wrong_or_missing_parameters_definition"),
134
                                        PluginServices.getText(this, "Warning"),
135
                                        JOptionPane.WARNING_MESSAGE);
136
                }
137
138
        }
139
140
        private boolean createButton() {
141
142
                m_Button = new Button();
143
                m_Button.sIconFilename = jTextFieldIcon.getFilepath() + " ";
144
                m_Button.sCommand = jTextFieldCmd.getText();
145
                m_Button.sName = jTextFieldName.getText() + " ";
146
147
                return !(m_Button.sCommand.trim().equals(""));
148
149
        }
150
151
        private void jButtonCancelActionPerformed(ActionEvent evt) {
152
153
                m_Button = null;
154
                dispose();
155
                setVisible(false);
156
157
        }
158
159
}