|
24 | 24 |
|
25 | 25 | //import com.itextpdf.xmp.impl.Utils; |
26 | 26 |
|
27 | | - |
28 | 27 | import apple.awt.CButton; |
| 28 | +import edu.iastate.metnet.metaomgraph.AnimatedSwingWorker; |
29 | 29 | import edu.iastate.metnet.metaomgraph.MetaOmProject; |
30 | 30 |
|
31 | | - |
32 | 31 | import javax.swing.JScrollPane; |
33 | 32 | import javax.swing.JTable; |
34 | 33 | import java.awt.event.ActionListener; |
@@ -164,69 +163,23 @@ public void actionPerformed(ActionEvent arg0) { |
164 | 163 | btnGo = new JButton("Go"); |
165 | 164 | btnGo.addActionListener(new ActionListener() { |
166 | 165 | public void actionPerformed(ActionEvent arg0) { |
167 | | - double minVal = 0; |
168 | | - double maxVal = 0; |
169 | | - List<String> colNames = new ArrayList<>(); |
170 | | - try { |
171 | | - minVal = Double.parseDouble(textField.getText()); |
172 | | - maxVal = Double.parseDouble(textField_1.getText()); |
173 | | - } catch (NumberFormatException nfe) { |
174 | | - JOptionPane.showMessageDialog(null, "Please check min and max values", "Values error", |
175 | | - JOptionPane.ERROR_MESSAGE); |
176 | | - return; |
177 | | - } |
178 | | - // get results for selected rows |
179 | | - int[] selected = table.getSelectedRows(); |
180 | | - if(selected ==null || selected.length<1) { |
181 | | - return; |
182 | | - } |
183 | | - List<List<String>> res = new ArrayList<>(); |
184 | | - if (searchDC) { |
185 | | - try { |
186 | | - for (int s = 0; s < selected.length; s++) { |
187 | | - int thisIndex=table.convertRowIndexToModel( selected[s]); |
188 | | - List<String> temp = new ArrayList<>(); |
189 | | - colNames.add(myProject.getDefaultRowNames(thisIndex)); |
190 | | - double[] values = myProject.getAllData(thisIndex); |
191 | | - for (int i = 0; i < values.length; i++) { |
| 166 | + new AnimatedSwingWorker("Working...", true) { |
| 167 | + @Override |
| 168 | + public Object construct() { |
| 169 | + EventQueue.invokeLater(new Runnable() { |
| 170 | + public void run() { |
192 | 171 | try { |
193 | | - if (values[i] >= minVal && values[i] <= maxVal) |
194 | | - temp.add(myProject.getDataColumnHeader(i)); |
195 | | - } catch (NumberFormatException nfe) { |
196 | | - System.err.println("value at " + i + " is not a number"); |
| 172 | + startSearch(); |
| 173 | + } catch (Exception e) { |
| 174 | + e.printStackTrace(); |
197 | 175 | } |
198 | 176 | } |
199 | | - res.add(temp); |
200 | | - } |
201 | | - |
202 | | - } catch (IOException e) { |
203 | | - e.printStackTrace(); |
| 177 | + }); |
| 178 | + return null; |
204 | 179 | } |
205 | 180 |
|
206 | | - // JOptionPane.showMessageDialog(null, "cn:" + colNames.toString()); |
207 | | - // JOptionPane.showMessageDialog(null, "res:" + res.toString()); |
208 | | - } else { |
209 | | - try { |
210 | | - for (int s = 0; s < selected.length; s++) { |
211 | | - int thisIndex=table.convertRowIndexToModel(selected[s]); |
212 | | - List<String> temp = new ArrayList<>(); |
213 | | - colNames.add(myProject.getDataColumnHeader(thisIndex)); |
214 | | - double[] values = myProject.getDataForColumn(thisIndex); |
215 | | - for (int i = 0; i < values.length; i++) { |
216 | | - try { |
217 | | - if (values[i] >= minVal && values[i] <= maxVal) |
218 | | - temp.add(myProject.getDefaultRowNames(i)); |
219 | | - } catch (NumberFormatException nfe) { |
220 | | - System.err.println("value at " + i + " is not a number"); |
221 | | - } |
222 | | - } |
223 | | - res.add(temp); |
224 | | - } |
225 | | - } catch (IOException e) { |
226 | | - e.printStackTrace(); |
227 | | - } |
228 | | - } |
229 | | - initRightTable(colNames, res); |
| 181 | + }.start(); |
| 182 | + |
230 | 183 | } |
231 | 184 | }); |
232 | 185 | panel.add(btnGo); |
@@ -529,4 +482,75 @@ public void toggleSortOrder(int column) { |
529 | 482 |
|
530 | 483 | } |
531 | 484 |
|
| 485 | + /** |
| 486 | + * function to perform search by expression values |
| 487 | + */ |
| 488 | + public void startSearch() { |
| 489 | + double minVal = 0; |
| 490 | + double maxVal = 0; |
| 491 | + List<String> colNames = new ArrayList<>(); |
| 492 | + try { |
| 493 | + minVal = Double.parseDouble(textField.getText()); |
| 494 | + maxVal = Double.parseDouble(textField_1.getText()); |
| 495 | + } catch (NumberFormatException nfe) { |
| 496 | + JOptionPane.showMessageDialog(null, "Please check min and max values", "Values error", |
| 497 | + JOptionPane.ERROR_MESSAGE); |
| 498 | + return; |
| 499 | + } |
| 500 | + // get results for selected rows |
| 501 | + int[] selected = table.getSelectedRows(); |
| 502 | + if (selected == null || selected.length < 1) { |
| 503 | + JOptionPane.showMessageDialog(null, "Please select rows to search.", "Please select rows", |
| 504 | + JOptionPane.ERROR_MESSAGE); |
| 505 | + return; |
| 506 | + } |
| 507 | + List<List<String>> res = new ArrayList<>(); |
| 508 | + // search datacolumns |
| 509 | + if (searchDC) { |
| 510 | + try { |
| 511 | + for (int s = 0; s < selected.length; s++) { |
| 512 | + int thisIndex = table.convertRowIndexToModel(selected[s]); |
| 513 | + List<String> temp = new ArrayList<>(); |
| 514 | + colNames.add(myProject.getDefaultRowNames(thisIndex)); |
| 515 | + double[] values = myProject.getAllData(thisIndex); |
| 516 | + for (int i = 0; i < values.length; i++) { |
| 517 | + try { |
| 518 | + if (values[i] >= minVal && values[i] <= maxVal) |
| 519 | + temp.add(myProject.getDataColumnHeader(i)); |
| 520 | + } catch (NumberFormatException nfe) { |
| 521 | + System.err.println("value at " + i + " is not a number"); |
| 522 | + } |
| 523 | + } |
| 524 | + res.add(temp); |
| 525 | + } |
| 526 | + |
| 527 | + } catch (IOException e) { |
| 528 | + e.printStackTrace(); |
| 529 | + } |
| 530 | + |
| 531 | + } else {// search features |
| 532 | + try { |
| 533 | + for (int s = 0; s < selected.length; s++) { |
| 534 | + int thisIndex = table.convertRowIndexToModel(selected[s]); |
| 535 | + List<String> temp = new ArrayList<>(); |
| 536 | + colNames.add(myProject.getDataColumnHeader(thisIndex)); |
| 537 | + double[] values = myProject.getDataForColumn(thisIndex); |
| 538 | + for (int i = 0; i < values.length; i++) { |
| 539 | + try { |
| 540 | + if (values[i] >= minVal && values[i] <= maxVal) |
| 541 | + temp.add(myProject.getDefaultRowNames(i)); |
| 542 | + } catch (NumberFormatException nfe) { |
| 543 | + System.err.println("value at " + i + " is not a number"); |
| 544 | + } |
| 545 | + } |
| 546 | + res.add(temp); |
| 547 | + } |
| 548 | + } catch (IOException e) { |
| 549 | + e.printStackTrace(); |
| 550 | + } |
| 551 | + } |
| 552 | + initRightTable(colNames, res); |
| 553 | + |
| 554 | + } |
| 555 | + |
532 | 556 | } |
0 commit comments