📄 convertorpanel.java
字号:
proc_err_task.start(); proc_out_task.start(); // Block THIS thread till process returns! int proc_istatus = proc.waitFor(); // Clean up InputStreamThread's when the proces is done. proc_err_task.stopRunning(); proc_err_task = null; proc_out_task.stopRunning(); proc_out_task = null; cmd_textarea.append( "\n> Ending with exit status " + proc_istatus + "\n" ); } catch ( Throwable err ) { err.printStackTrace(); } } private SwingProcessWorker convertSelectedLogFile() { String convertor; String path2jardir, path2tracelib; String infile_name, outfile_name, jar_path; String option4jar; File infile, outfile, jar_file; InputLog slog_ins; RuntimeExecCommand exec_cmd; SwingProcessWorker conv_worker; ProgressAction conv_progress; // Check the validity of the Input File infile_name = cmd_infile.getText(); infile = new File( infile_name ); if ( ! infile.exists() ) { Dialogs.error( top_window, infile_name + " does not exist!\n" + "No conversion will take place." ); return null; } if ( infile.isDirectory() ) { Dialogs.error( top_window, infile_name + " is a directory!\n" + "No conversion will take place." ); return null; } if ( ! infile.canRead() ) { Dialogs.error( top_window, "File " + infile_name + " is NOT readable!\n" + "No conversion will take place." ); return null; } slog_ins = null; try { slog_ins = new InputLog( infile_name ); } catch ( NullPointerException nperr ) { slog_ins = null; } catch ( Exception err ) { slog_ins = null; } if ( slog_ins != null && slog_ins.isSLOG2() ) { Dialogs.error( top_window, infile_name + " is already a SLOG-2 file!\n" + "No conversion will take place." ); cmd_outfile.setText( infile_name ); return null; } // Check the validity of the Output File outfile_name = cmd_outfile.getText(); outfile = new File( outfile_name ); if ( outfile.exists() ) { if ( outfile.isDirectory() ) { Dialogs.error( top_window, outfile_name + " is a directory!\n" + "No conversion will take place." ); return null; } if ( ! outfile.canWrite() ) { Dialogs.error( top_window, "File " + outfile_name + " cannot be written!\n" + "No conversion will take place." ); return null; } if ( ! Dialogs.confirm( top_window, outfile_name + " already exists! " + "Do you want to overwrite it ?" ) ) { Dialogs.info( top_window, "Please change the output filename " + "and restart the conversion again.", null ); return null; } outfile.delete(); } convertor = (String) cmd_pulldown.getSelectedItem(); // Set the path to the jar file path2jardir = cmd_path2jardir.getText(); jar_path = ConvertorConst.getDefaultJarPath( path2jardir, convertor ); jar_file = new File( jar_path ); if ( ! jar_file.exists() ) { Dialogs.error( top_window, jar_path + " does not exist!" ); return null; } exec_cmd = new RuntimeExecCommand(); exec_cmd.addWholeString( cmd_path2jvm.getText() ); exec_cmd.addTokenizedString( cmd_option4jvm.getText() ); path2tracelib = cmd_path2tracelib.getText(); if ( path2tracelib != null && path2tracelib.length() > 0 ) exec_cmd.addWholeString( "-Djava.library.path=" + path2tracelib ); exec_cmd.addWholeString( "-jar" ); exec_cmd.addWholeString( jar_path ); option4jar = cmd_option4jar.getText(); if ( option4jar != null && option4jar.length() > 0 ) exec_cmd.addTokenizedString( option4jar ); exec_cmd.addWholeString( "-o" ); exec_cmd.addWholeString( outfile_name ); exec_cmd.addWholeString( infile_name ); /* Start a SwingWorker thread to execute the process: Prepare a progress action for the JProgressBar for the SwingWorker */ conv_progress = new ProgressAction( cmd_outfile_size, cmd_progress ); conv_progress.initialize( infile, outfile ); conv_worker = new SwingProcessWorker( this, cmd_textarea ); conv_worker.initialize( exec_cmd.toStringArray(), conv_progress ); conv_worker.start(); return conv_worker; } private void resetAllButtons( boolean isConvertingLogfile ) { cmd_start_btn.setEnabled( !isConvertingLogfile ); cmd_stop_btn.setEnabled( isConvertingLogfile ); cmd_help_btn.setEnabled( !isConvertingLogfile ); if ( cmd_close4cancel_btn != null ) cmd_close4cancel_btn.setEnabled( !isConvertingLogfile ); if ( cmd_close4ok_btn != null ) { // The scenarios that logconv_worker == null are either the // process has not been started or it has been stopped by user. if ( logconv_worker != null && logconv_worker.isEndedNormally() ) cmd_close4ok_btn.setEnabled( !isConvertingLogfile ); else cmd_close4ok_btn.setEnabled( false ); } } // Interface for WaitingContainer (used by SwingProcessWorker) public void initializeWaiting() { Routines.setComponentAndChildrenCursors( cmd_splitter, CustomCursor.Wait ); this.resetAllButtons( true ); } // Interface for WaitingContainer (used by SwingProcessWorker) public void finalizeWaiting() { this.resetAllButtons( false ); Routines.setComponentAndChildrenCursors( cmd_splitter, CustomCursor.Normal ); } public void addActionListenerForOkayButton( ActionListener action ) { if ( action != null && cmd_close4ok_btn != null ) cmd_close4ok_btn.addActionListener( action ); } public void addActionListenerForCancelButton( ActionListener action ) { if ( action != null && cmd_close4cancel_btn != null ) cmd_close4cancel_btn.addActionListener( action ); } public String getOutputSLOG2Name() { return cmd_outfile.getText(); } private class LogNameListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { String infile_name, outfile_name; infile_name = cmd_infile.getText(); outfile_name = ConvertorConst.getDefaultSLOG2Name( infile_name ); cmd_outfile.setText( outfile_name ); } } private class InputFileSelectorListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { String filename = selectLogFile(); if ( filename != null && filename.length() > 0 ) { cmd_infile.setText( filename ); printSelectedConvertorHelp(); } } } private class OutputFileSelectorListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { String filename = selectLogFile(); if ( filename != null && filename.length() > 0 ) { cmd_outfile.setText( filename ); } } } private class PulldownListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { String convertor, path2jardir; convertor = (String) cmd_pulldown.getSelectedItem(); path2jardir = ConvertorConst.getDefaultPathToJarDir(); cmd_path2tracelib.setText( ConvertorConst.getDefaultTraceLibPath( convertor, path2jardir ) ); printSelectedConvertorHelp(); } } private class JarDirectoryListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { String convertor, path2jardir; String def_path2tracelib, cur_path2tracelib, new_path2tracelib; convertor = (String) cmd_pulldown.getSelectedItem(); cur_path2tracelib = cmd_path2tracelib.getText(); if ( cur_path2tracelib == null ) cur_path2tracelib = ""; // Check if the TraceLibrary Path has been updated, // i.e. already synchronized with JAR Directory. path2jardir = cmd_path2jardir.getText(); new_path2tracelib = ConvertorConst.getDefaultTraceLibPath( convertor, path2jardir ); if ( new_path2tracelib == null ) new_path2tracelib = ""; if ( cur_path2tracelib.equals( new_path2tracelib ) ) return; // Check if path2tracelib is differnt from the default path2jardir = ConvertorConst.getDefaultPathToJarDir(); def_path2tracelib = ConvertorConst.getDefaultTraceLibPath( convertor, path2jardir ); if ( def_path2tracelib == null ) def_path2tracelib = ""; if ( ! cur_path2tracelib.equals( def_path2tracelib ) ) { if ( ! Dialogs.confirm( top_window, "TraceLibrary Path has been modified " + "from the original default value.\n" + "Should it be updated by the new " + "default value based on your modified " + "JAR Directory ?" ) ) { return; } } // Update the default TraceLibPaths with the modified cmd_path2jar. cmd_path2tracelib.setText( new_path2tracelib ); } } private class StartConvertorListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { logconv_worker = convertSelectedLogFile(); } } private class StopConvertorListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { // Set logconv_worker = null when the conversion is stopped manually // so resetAllButtons() can set close4ok button accordingly. if ( logconv_worker != null ) { logconv_worker.finished(); logconv_worker = null; } } } private class HelpConvertorListener implements ActionListener { public void actionPerformed( ActionEvent evt ) { cmd_path2jardir.fireActionPerformed(); // call JarDirectoryListener printSelectedConvertorHelp(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -