Skip to content

Commit 81929a1

Browse files
committed
added progress bar to search by expression
1 parent bff3f1e commit 81929a1

1 file changed

Lines changed: 84 additions & 60 deletions

File tree

src/edu/iastate/metnet/metaomgraph/ui/SearchByExpressionFrame.java

Lines changed: 84 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@
2424

2525
//import com.itextpdf.xmp.impl.Utils;
2626

27-
2827
import apple.awt.CButton;
28+
import edu.iastate.metnet.metaomgraph.AnimatedSwingWorker;
2929
import edu.iastate.metnet.metaomgraph.MetaOmProject;
3030

31-
3231
import javax.swing.JScrollPane;
3332
import javax.swing.JTable;
3433
import java.awt.event.ActionListener;
@@ -164,69 +163,23 @@ public void actionPerformed(ActionEvent arg0) {
164163
btnGo = new JButton("Go");
165164
btnGo.addActionListener(new ActionListener() {
166165
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() {
192171
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();
197175
}
198176
}
199-
res.add(temp);
200-
}
201-
202-
} catch (IOException e) {
203-
e.printStackTrace();
177+
});
178+
return null;
204179
}
205180

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+
230183
}
231184
});
232185
panel.add(btnGo);
@@ -529,4 +482,75 @@ public void toggleSortOrder(int column) {
529482

530483
}
531484

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+
532556
}

0 commit comments

Comments
 (0)