Statistics
| Revision:

root / org.gvsig.toolbox / trunk / org.gvsig.toolbox / org.gvsig.toolbox.algorithm / src / main / java / es / unex / sextante / vectorTools / dissolveMultiple / FieldsBox.java @ 59

History | View | Annotate | Download (3.87 KB)

1

    
2

    
3
package es.unex.sextante.vectorTools.dissolveMultiple;
4

    
5
import info.clearthought.layout.TableLayout;
6
import info.clearthought.layout.TableLayoutConstants;
7

    
8
import java.awt.Frame;
9
import java.awt.event.ActionEvent;
10
import java.awt.event.ActionListener;
11
import java.util.ArrayList;
12

    
13
import javax.swing.JButton;
14
import javax.swing.JPanel;
15
import javax.swing.JTextField;
16

    
17
import es.unex.sextante.core.Sextante;
18
import es.unex.sextante.gui.algorithm.MultipleInputSelectionDialog;
19

    
20

    
21
public class FieldsBox
22
         extends
23
            JPanel {
24

    
25
   private Object[]   m_Values;
26
   private ArrayList  m_SelectedIndices = new ArrayList();
27
   private JTextField textField;
28
   private JButton    button;
29

    
30

    
31
   public FieldsBox() {
32

    
33
      super();
34

    
35
      //m_Values = values;
36

    
37
      //initGUI();
38

    
39
   }
40

    
41

    
42
   void initGUI() {
43

    
44
      button = new JButton("...");
45
      textField = new JTextField(Sextante.getText("0_elements_selected"));
46
      textField.setEditable(false);
47

    
48
      button.addActionListener(new ActionListener() {
49
         public void actionPerformed(final ActionEvent evt) {
50
            btnActionPerformed(evt);
51
         }
52
      });
53

    
54
      final TableLayout thisLayout = new TableLayout(new double[][] { { TableLayoutConstants.FILL, 25.0 },
55
               { TableLayoutConstants.FILL } });
56
      this.setLayout(thisLayout);
57
      this.add(textField, "0,  0");
58
      this.add(button, "1,  0");
59
   }
60

    
61

    
62
   /**
63
    * Returns a list of all the objects selected using this panel
64
    * 
65
    * @return a list of selected objects
66
    */
67
   public ArrayList getSelectedObjects() {
68

    
69
      int iIndex;
70
      final ArrayList selected = new ArrayList();
71

    
72
      for (int i = 0; i < m_SelectedIndices.size(); i++) {
73
         iIndex = ((Integer) m_SelectedIndices.get(i)).intValue();
74
         selected.add(this.m_Values[iIndex]);
75
      }
76

    
77
      return selected;
78

    
79
   }
80

    
81

    
82
   private void btnActionPerformed(final ActionEvent e) {
83

    
84
      int iCount;
85
      final StringBuffer sText = new StringBuffer();
86

    
87
      final Frame window = new Frame();
88

    
89
      final MultipleInputSelectionDialog dialog = new MultipleInputSelectionDialog(window, m_Values, m_SelectedIndices);
90

    
91
      dialog.pack();
92
      dialog.setVisible(true);
93

    
94
      iCount = m_SelectedIndices.size();
95
      sText.append(Integer.toString(iCount));
96
      if (iCount == 1) {
97
         sText.append(" " + Sextante.getText("element_selected"));
98
      }
99
      else {
100
         sText.append(" " + Sextante.getText("elements_selected"));
101
      }
102

    
103
      textField.setText(sText.toString());
104

    
105
   }
106

    
107

    
108
   public Object[] getValues() {
109

    
110
      return m_Values;
111

    
112
   }
113

    
114

    
115
   public void setSelectedIndices(final ArrayList selectedIndices) {
116

    
117
      m_SelectedIndices = selectedIndices;
118
      final StringBuffer sText = new StringBuffer();
119
      final int iCount = m_SelectedIndices.size();
120
      sText.append(Integer.toString(iCount));
121
      if (iCount == 1) {
122
         sText.append(" " + Sextante.getText("element_selected"));
123
      }
124
      else {
125
         sText.append(" " + Sextante.getText("elements_selected"));
126
      }
127

    
128
      textField.setText(sText.toString());
129

    
130
   }
131

    
132

    
133
   public String getFieldsAsString() {
134

    
135
      final StringBuffer sb = new StringBuffer();
136
      boolean bFirst = true;
137
      for (int i = 0; i < m_SelectedIndices.size(); i++) {
138
         final int iIndex = ((Integer) m_SelectedIndices.get(i)).intValue();
139
         if (bFirst) {
140
            sb.append(m_Values[iIndex].toString());
141
            bFirst = false;
142
         }
143
         else {
144
            sb.append("," + m_Values[iIndex].toString());
145
         }
146
      }
147

    
148
      return sb.toString();
149

    
150
   }
151

    
152

    
153
   public void setFields(final String[] fields) {
154

    
155
      m_SelectedIndices.clear();
156
      m_Values = fields;
157

    
158
      textField = new JTextField(Sextante.getText("0_elements_selected"));//initGUI();
159

    
160
   }
161

    
162
}