2
2
3
3
import java .awt .BorderLayout ;
4
4
import java .awt .Color ;
5
+ import java .awt .Font ;
5
6
import java .awt .Insets ;
6
7
import java .awt .event .ActionEvent ;
7
8
import java .awt .event .ActionListener ;
8
9
import java .beans .PropertyChangeEvent ;
9
10
import java .beans .PropertyChangeListener ;
10
- import java .io .File ;
11
11
12
12
import javax .swing .BoxLayout ;
13
13
import javax .swing .JButton ;
25
25
import org .cytoscape .application .CyApplicationManager ;
26
26
import org .cytoscape .application .swing .CySwingApplication ;
27
27
import org .cytoscape .io .util .StreamUtil ;
28
- import org .cytoscape .util .swing .FileUtil ;
29
- import org .cytoscape .work .swing .DialogTaskManager ;
28
+ import org .cytoscape .work .SynchronousTaskManager ;
30
29
31
30
@ SuppressWarnings ("serial" )
32
31
public class PostAnalysisKnownSignaturePanel extends JPanel {
@@ -36,8 +35,7 @@ public class PostAnalysisKnownSignaturePanel extends JPanel {
36
35
private final CyApplicationManager cyApplicationManager ;
37
36
private final CySwingApplication application ;
38
37
private final StreamUtil streamUtil ;
39
- private final DialogTaskManager dialog ;
40
- private final FileUtil fileUtil ;
38
+ private final SynchronousTaskManager syncTaskManager ;
41
39
42
40
// 'Known Signature Panel' parameters
43
41
private EnrichmentMap map ;
@@ -46,21 +44,20 @@ public class PostAnalysisKnownSignaturePanel extends JPanel {
46
44
private PostAnalysisWeightPanel weightPanel ;
47
45
48
46
private JFormattedTextField knownSignatureGMTFileNameTextField ;
47
+
49
48
50
49
public PostAnalysisKnownSignaturePanel (
51
50
PostAnalysisInputPanel parentPanel ,
52
51
CyApplicationManager cyApplicationManager ,
53
52
CySwingApplication application ,
54
53
StreamUtil streamUtil ,
55
- DialogTaskManager dialog ,
56
- FileUtil fileUtil ) {
54
+ SynchronousTaskManager syncTaskManager ) {
57
55
58
56
this .parentPanel = parentPanel ;
59
57
this .cyApplicationManager = cyApplicationManager ;
60
58
this .application = application ;
61
59
this .streamUtil = streamUtil ;
62
- this .dialog = dialog ;
63
- this .fileUtil = fileUtil ;
60
+ this .syncTaskManager = syncTaskManager ;
64
61
65
62
createKnownSignatureOptionsPanel ();
66
63
}
@@ -103,20 +100,23 @@ public JToolTip createToolTip() {
103
100
JButton selectSigGMTFileButton = new JButton ();
104
101
knownSignatureGMTFileNameTextField = new JFormattedTextField () ;
105
102
knownSignatureGMTFileNameTextField .setColumns (15 );
103
+ final Color textFieldForeground = knownSignatureGMTFileNameTextField .getForeground ();
106
104
107
-
108
- //components needed for the directory load
109
- knownSignatureGMTFileNameTextField .setFont (new java .awt .Font ("Dialog" ,1 ,10 ));
110
- //GMTFileNameTextField.setText(gmt_instruction);
111
- knownSignatureGMTFileNameTextField .addPropertyChangeListener ("value" ,new FormattedTextFieldAction ());
105
+ knownSignatureGMTFileNameTextField .setFont (new Font ("Dialog" ,1 ,10 ));
106
+ knownSignatureGMTFileNameTextField .addPropertyChangeListener ("value" , new PropertyChangeListener () {
107
+ public void propertyChange (PropertyChangeEvent e ) {
108
+ // if the text is red set it back to black as soon as the user starts typing
109
+ knownSignatureGMTFileNameTextField .setForeground (textFieldForeground );
110
+ }
111
+ });
112
112
113
113
114
114
selectSigGMTFileButton .setText ("..." );
115
115
selectSigGMTFileButton .setMargin (new Insets (0 ,0 ,0 ,0 ));
116
116
selectSigGMTFileButton .setActionCommand ("Known Signature" );
117
117
selectSigGMTFileButton .addActionListener (new ActionListener () {
118
118
public void actionPerformed (ActionEvent evt ) {
119
- selectSignatureGMTFileButtonActionPerformed ( evt );
119
+ parentPanel . chooseGMTFile ( knownSignatureGMTFileNameTextField );
120
120
}
121
121
});
122
122
@@ -136,56 +136,29 @@ public void actionPerformed(ActionEvent evt) {
136
136
}
137
137
138
138
139
- /**
140
- * Event Handler for selectSignatureGMTFileButton.<p>
141
- * Opens a file browser dialog to select the SignatureGMTFile.
142
- */
143
- private void selectSignatureGMTFileButtonActionPerformed (ActionEvent evt ) {
144
- File file = parentPanel .chooseGMTFile (knownSignatureGMTFileNameTextField );
145
- if (file != null ) {
146
- //Load in the GMT file
147
- //Manually fire the same action listener that is used by the signature discovery panel
148
- LoadSignatureSetsActionListener loadAction = new LoadSignatureSetsActionListener (parentPanel , application , cyApplicationManager , dialog , streamUtil );
149
- loadAction .setSelectAll (true );
150
- loadAction .actionPerformed (evt );
139
+ public boolean beforeRun () {
140
+ String filePath = (String )knownSignatureGMTFileNameTextField .getValue ();
141
+
142
+ if (filePath == null || PostAnalysisInputPanel .checkFile (filePath ).equals (Color .RED )){
143
+ String message = "SigGMT file name not valid.\n " ;
144
+ knownSignatureGMTFileNameTextField .setForeground (Color .RED );
145
+ JOptionPane .showMessageDialog (application .getJFrame (), message , "Post Analysis Known Signature" , JOptionPane .WARNING_MESSAGE );
146
+ return false ;
151
147
}
148
+
149
+ paParams .setSignatureGMTFileName (filePath );
150
+
151
+ // Load in the GMT file
152
+ // Manually fire the same action listener that is used by the signature discovery panel.
153
+ // Use the synchronousTaskManager so that this blocks
154
+ LoadSignatureSetsActionListener loadAction = new LoadSignatureSetsActionListener (parentPanel , application , cyApplicationManager , syncTaskManager , streamUtil );
155
+ loadAction .setSelectAll (true );
156
+ loadAction .actionPerformed (null );
157
+
158
+ return true ;
152
159
}
153
160
154
161
155
- /**
156
- * Handles setting for the text field parameters that are numbers.
157
- * Makes sure that the numbers make sense.
158
- */
159
- private class FormattedTextFieldAction implements PropertyChangeListener {
160
- public void propertyChange (PropertyChangeEvent e ) {
161
- JFormattedTextField source = (JFormattedTextField ) e .getSource ();
162
-
163
- String message = "The value you have entered is invalid.\n " ;
164
- boolean invalid = false ;
165
-
166
- if (source == knownSignatureGMTFileNameTextField ) {
167
- String value = knownSignatureGMTFileNameTextField .getText ();
168
- if (value .equalsIgnoreCase ("" ) )
169
- paParams .setSignatureGMTFileName (value );
170
- else if (knownSignatureGMTFileNameTextField .getText ().equalsIgnoreCase ((String )e .getOldValue ())){
171
- //do nothing
172
- }
173
- else if (PostAnalysisInputPanel .checkFile (value ).equals (Color .RED )){
174
- JOptionPane .showMessageDialog (application .getJFrame (),message ,"File name change entered is not a valid file name" ,JOptionPane .WARNING_MESSAGE );
175
- knownSignatureGMTFileNameTextField .setForeground (PostAnalysisInputPanel .checkFile (value ));
176
- }
177
- else {
178
- paParams .setSignatureGMTFileName (value );
179
- paParams .getSignatureSetNames ().clear ();
180
- paParams .getSelectedSignatureSetNames ().clear ();
181
- }
182
- }
183
- if (invalid ) {
184
- JOptionPane .showMessageDialog (application .getJFrame (), message , "Parameter out of bounds" , JOptionPane .WARNING_MESSAGE );
185
- }
186
- }
187
- }
188
-
189
162
void resetPanel () {
190
163
paParams .setSignatureGenesets (new SetOfGeneSets ());
191
164
//Gene-Sets Panel
0 commit comments