5656import java .awt .FontMetrics ;
5757import java .io .File ;
5858import java .io .IOException ;
59+ import java .util .*;
5960import java .util .Iterator ;
6061import java .util .List ;
6162import java .util .StringTokenizer ;
6263import java .util .NoSuchElementException ;
63- import java .util .HashMap ;
64+ import java .util .TreeMap ;
6465import java .util .Map ;
6566import java .util .Enumeration ;
6667import java .util .ArrayList ;
6768import java .util .Hashtable ;
6869import java .util .Properties ;
70+ import java .util .Vector ;
6971import edu .rice .cs .plt .tuple .Pair ;
7072
7173public class ExecuteExternalDialog extends JFrame implements OptionConstants {
@@ -1110,23 +1112,50 @@ private void _cancel() {
11101112
11111113 public static edu .rice .cs .util .Log LOG = new edu .rice .cs .util .Log ("process.txt" , false );
11121114
1115+ /** Run a command and return an external process panel. */
1116+ public ExternalProcessPanel runCommand (String name , String cmdline , String workdir ) {
1117+ updateProperties ();
1118+ ProcessCreator pc = new ProcessCreator (cmdline , workdir .trim (), _props );
1119+ String label = "External" ;
1120+ if (!name .equals ("" )) { label += ": " +name ; }
1121+ final ExternalProcessPanel panel = new ExternalProcessPanel (_mainFrame , label , pc );
1122+ _mainFrame ._tabs .addLast (panel );
1123+ panel .getMainPanel ().addFocusListener (new FocusAdapter () {
1124+ public void focusGained (FocusEvent e ) { _mainFrame ._lastFocusOwner = panel ; }
1125+ });
1126+ panel .setVisible (true );
1127+ _mainFrame .showTab (panel );
1128+ _mainFrame ._tabbedPane .setSelectedComponent (panel );
1129+ // Use SwingUtilties.invokeLater to ensure that focus is set AFTER the findResultsPanel has been selected
1130+ EventQueue .invokeLater (new Runnable () { public void run () { panel .requestFocusInWindow (); } });
1131+ return panel ;
1132+ }
1133+
1134+ public ExternalProcessPanel runJava (String name , String jvmargs , String cmdline , String workdir ) {
1135+ ProcessCreator pc = new JVMProcessCreator (jvmargs , cmdline , workdir , _props );
1136+
1137+ String label = "External Java" ;
1138+ if (!name .equals ("" )) { label += ": " +name ; }
1139+ final ExternalProcessPanel panel = new ExternalProcessPanel (_mainFrame , label , pc );
1140+ _mainFrame ._tabs .addLast (panel );
1141+ panel .getMainPanel ().addFocusListener (new FocusAdapter () {
1142+ public void focusGained (FocusEvent e ) { _mainFrame ._lastFocusOwner = panel ; }
1143+ });
1144+ panel .setVisible (true );
1145+ _mainFrame .showTab (panel );
1146+ _mainFrame ._tabbedPane .setSelectedComponent (panel );
1147+ // Use SwingUtilties.invokeLater to ensure that focus is set AFTER the findResultsPanel has been selected
1148+ EventQueue .invokeLater (new Runnable () { public void run () { panel .requestFocusInWindow (); } });
1149+
1150+ return panel ;
1151+ }
1152+
11131153 /** Execute the command line. */
11141154 private void _runCommand () {
11151155 _mainFrame .updateStatusField ("Executing external process..." );
11161156
11171157 if (_commandLinePreview .getText ().length ()>0 ) {
1118- ProcessCreator pc = new ProcessCreator (_commandLine .getText (), _commandWorkDirLine .getText ().trim (), _props );
1119- String name = "External" ;
1120- final ExternalProcessPanel panel = new ExternalProcessPanel (_mainFrame , name , pc );
1121- _mainFrame ._tabs .addLast (panel );
1122- panel .getMainPanel ().addFocusListener (new FocusAdapter () {
1123- public void focusGained (FocusEvent e ) { _mainFrame ._lastFocusOwner = panel ; }
1124- });
1125- panel .setVisible (true );
1126- _mainFrame .showTab (panel );
1127- _mainFrame ._tabbedPane .setSelectedComponent (panel );
1128- // Use SwingUtilties.invokeLater to ensure that focus is set AFTER the findResultsPanel has been selected
1129- EventQueue .invokeLater (new Runnable () { public void run () { panel .requestFocusInWindow (); } });
1158+ runCommand ("" , _commandLine .getText (), _commandWorkDirLine .getText ());
11301159 }
11311160 else {
11321161 JOptionPane .showMessageDialog (this ,
@@ -1145,20 +1174,8 @@ private void _runJava() {
11451174 _mainFrame .updateStatusField ("Executing external Java class..." );
11461175
11471176 if (_javaCommandLinePreview .getText ().length ()>0 ) {
1148- ProcessCreator pc = new JVMProcessCreator (_jvmLine .getText (), _javaCommandLine .getText (),
1149- _javaCommandWorkDirLine .getText ().trim (), _props );
1150-
1151- String name = "External Java" ;
1152- final ExternalProcessPanel panel = new ExternalProcessPanel (_mainFrame , name , pc );
1153- _mainFrame ._tabs .addLast (panel );
1154- panel .getMainPanel ().addFocusListener (new FocusAdapter () {
1155- public void focusGained (FocusEvent e ) { _mainFrame ._lastFocusOwner = panel ; }
1156- });
1157- panel .setVisible (true );
1158- _mainFrame .showTab (panel );
1159- _mainFrame ._tabbedPane .setSelectedComponent (panel );
1160- // Use SwingUtilties.invokeLater to ensure that focus is set AFTER the findResultsPanel has been selected
1161- EventQueue .invokeLater (new Runnable () { public void run () { panel .requestFocusInWindow (); } });
1177+ runJava ("" , _jvmLine .getText (), _javaCommandLine .getText (),
1178+ _javaCommandWorkDirLine .getText ());
11621179 }
11631180 else {
11641181 JOptionPane .showMessageDialog (this ,
@@ -1176,25 +1193,36 @@ private void _runJava() {
11761193 private void _saveCommand () {
11771194 int count = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_COUNT ) + 1 ;
11781195
1179- String name = "External " +count ;
1180- StringOption nameOption = new StringOption (OptionConstants .EXTERNAL_SAVED_PREFIX +count +".name" ,name );
1181- DrJava .getConfig ().getOptionMap ().setString (nameOption , name );
1196+ final Vector <String > names = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_NAMES );
1197+ final Vector <String > types = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_TYPES );
1198+ final Vector <String > cmdlines = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_CMDLINES );
1199+ final Vector <String > jvmargs = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_JVMARGS );
1200+ final Vector <String > workdirs = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_WORKDIRS );
1201+
1202+ String name = JOptionPane .showInputDialog (this , "Name for saved process:" , "External Java " +count );
1203+ if (name ==null ) {
1204+ // Always apply and save settings
1205+ _saveSettings ();
1206+ this .setVisible (false );
1207+ return ;
1208+ }
1209+
1210+ names .add (name );
1211+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_NAMES ,names );
11821212
1183- String type = "cmdline" ;
1184- StringOption typeOption = new StringOption (OptionConstants .EXTERNAL_SAVED_PREFIX +count +".type" ,type );
1185- DrJava .getConfig ().getOptionMap ().setString (typeOption , type );
1213+ types .add ("cmdline" );
1214+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_TYPES ,types );
11861215
11871216 String cmdline = _commandLine .getText ();
1188- StringOption cmdlineOption = new StringOption ( OptionConstants . EXTERNAL_SAVED_PREFIX + count + ".cmdline" , cmdline );
1189- DrJava .getConfig ().getOptionMap (). setString ( cmdlineOption , cmdline );
1217+ cmdlines . add ( cmdline );
1218+ DrJava .getConfig ().setSetting ( OptionConstants . EXTERNAL_SAVED_CMDLINES , cmdlines );
11901219
1191- String jvmargs = "" ;
1192- StringOption jvmargsOption = new StringOption (OptionConstants .EXTERNAL_SAVED_PREFIX +count +".jvmargs" ,jvmargs );
1193- DrJava .getConfig ().getOptionMap ().setString (jvmargsOption , jvmargs );
1220+ jvmargs .add ("" );
1221+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_JVMARGS ,jvmargs );
11941222
11951223 String workdir = _commandWorkDirLine .getText ();
1196- StringOption workdirOption = new StringOption ( OptionConstants . EXTERNAL_SAVED_PREFIX + count + ".workdir" , workdir );
1197- DrJava .getConfig ().getOptionMap (). setString ( workdirOption , workdir );
1224+ workdirs . add ( workdir );
1225+ DrJava .getConfig ().setSetting ( OptionConstants . EXTERNAL_SAVED_WORKDIRS , workdirs );
11981226
11991227 // Always apply and save settings
12001228 _saveSettings ();
@@ -1205,11 +1233,44 @@ private void _saveCommand() {
12051233
12061234 /** Save the Java class to the menu. */
12071235 private void _saveJava () {
1208- // TODO
1236+ int count = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_COUNT ) + 1 ;
1237+
1238+ final Vector <String > names = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_NAMES );
1239+ final Vector <String > types = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_TYPES );
1240+ final Vector <String > cmdlines = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_CMDLINES );
1241+ final Vector <String > jvmargs = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_JVMARGS );
1242+ final Vector <String > workdirs = DrJava .getConfig ().getSetting (OptionConstants .EXTERNAL_SAVED_WORKDIRS );
1243+
1244+ String name = JOptionPane .showInputDialog (this , "Name for saved process:" , "External Java " +count );
1245+ if (name ==null ) {
1246+ // Always apply and save settings
1247+ _saveSettings ();
1248+ this .setVisible (false );
1249+ return ;
1250+ }
1251+
1252+ names .add (name );
1253+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_NAMES ,names );
12091254
1255+ types .add ("java" );
1256+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_TYPES ,types );
1257+
1258+ String cmdline = _javaCommandLine .getText ();
1259+ cmdlines .add (cmdline );
1260+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_CMDLINES ,cmdlines );
1261+
1262+ jvmargs .add (_jvmLine .getText ());
1263+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_JVMARGS ,jvmargs );
1264+
1265+ String workdir = _javaCommandWorkDirLine .getText ();
1266+ workdirs .add (workdir );
1267+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_WORKDIRS ,workdirs );
1268+
12101269 // Always apply and save settings
12111270 _saveSettings ();
12121271 this .setVisible (false );
1272+
1273+ DrJava .getConfig ().setSetting (OptionConstants .EXTERNAL_SAVED_COUNT , count );
12131274 }
12141275
12151276 /** Save the settings for this dialog. */
@@ -1298,7 +1359,7 @@ public void run() {
12981359
12991360 /** Update the properties. */
13001361 public void updateProperties () {
1301- _props = new HashMap <String , Properties >();
1362+ _props = new TreeMap <String , Properties >();
13021363 _props .put ("Java" , System .getProperties ());
13031364
13041365 Properties drJavaProps = new Properties ();
0 commit comments