Java tutorial
/*********************************************************************** * * Copyright (C) 2014 Avaneesh Rastogi (rastogi.avaneesh (at) gmail (dot) com) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see (http://www.gnu.org/licenses/). * ***********************************************************************/ package GUI; import Miscellaneous.Sound; import Utility.Description; import Utility.Platform; import java.awt.Color; import java.awt.Desktop; import java.awt.Font; import java.awt.FontFormatException; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JColorChooser; import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JScrollBar; import javax.swing.SwingWorker; import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.DefaultExecuteResultHandler; import org.apache.commons.exec.DefaultExecutor; import org.apache.commons.exec.ExecuteWatchdog; import org.apache.commons.exec.Executor; import org.apache.commons.exec.OS; import org.apache.commons.exec.PumpStreamHandler; /** * {@code GraphicalInterface} draws and manages the graphical interface of the * application. * * @author Avaneesh Rastogi * @author Priyanshu Srivastava * @author Nishant Gupta * @version 1.0 */ public class GraphicalInterface extends javax.swing.JFrame { /** * name of command currently selected in interface */ private String m_command; /** * history of commands executed */ private String m_history; /** * text of {@code m_command}'s description */ private final Description m_description; /** * {@code Runtime} instance */ private final Runtime m_runtime; /** * ButtonGroup maintains exclusivity of selection of radio buttons */ private final ButtonGroup bg; /** * Default string value for Terminal Emulator */ private final String m_defaultTerminal; /** * Default string value for Command Description */ private final String m_defaultDescription; /** * Complete string of command to execute */ private String m_completeCommand; /** * Thread object (for executing command) */ Thread t; /** * Whether command should be prefixed with a string */ private boolean m_internalPrefix; /** * Whether execution is manual or not */ private boolean m_isManualExecution; /** * File object containing information about command execution path */ private File m_workingDir; /** * CommandLine object to handle parsing */ CommandLine cmdLine; //----------------------------------------------------------------------- /** * Constructor to initialize GUI components and data members to default * value. */ public GraphicalInterface() { initComponents(); Platform.init(); /* Set variables to null */ m_command = m_history = m_completeCommand = ""; m_internalPrefix = m_isManualExecution = false; m_defaultDescription = "Welcome to Grafcom!\n" + "Select a command from the list to view its description. \n" + "Descriptions help you learn how commands work, what arguments they require\n" + "and what values they return.\n" + "================"; m_defaultTerminal = ">> Welcome to Grafcom!\n" + ">> This is the terminal text area which displays the output \n" + "of all the commands you run along with error messages.\n" + ">> Select command from drop-down list or enter manually, \n" + "click Execute and see the output!\n" + "====================\n"; terminalJTextArea.setText(m_defaultTerminal); descriptionJTextArea.setText(m_defaultDescription); m_runtime = Runtime.getRuntime(); m_description = new Description(); bg = new ButtonGroup(); bg.add(listJRadioButton); bg.add(manualJRadioButton); setFont(); /* set icon in title bar */ ImageIcon icon = new ImageIcon("Resources/icon/utilities-terminal.png"); this.setIconImage(icon.getImage()); /* Set default execution path and update GUI */ m_workingDir = new File(System.getProperty("user.dir")); workdirJFileChooser.setCurrentDirectory(m_workingDir); terminalJTextArea.append("\n" + m_workingDir.getPath() + "> "); /* if windows then disable root access */ rootJCheckBox.setEnabled(OS.isFamilyUnix()); commandJTextField.setEnabled(false); executeManualJButton.setEnabled(false); /* set command list */ commandJComboBox.setModel(new javax.swing.DefaultComboBoxModel(Platform.getCommandList().toArray())); } //----------------------------------------------------------------------- /** * Set scroll bar of {@code scrollPane} to extremum value. * <br> non-zero {@code value} means scroll to bottom. * <br> zero {@code value} means scroll to top. * * @param scrollPane {@code scrollPane} to be modified * @param value whether to scroll to top (zero) or bottom (non-zero) */ private void setScrollBar(final javax.swing.JScrollPane scrollPane, final int value) { /* set the position of scroll bar */ javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (value == 0) { scrollPane.getVerticalScrollBar().setValue(0); } else { JScrollBar sb = scrollPane.getVerticalScrollBar(); sb.setValue(sb.getMaximum()); } } }); } //----------------------------------------------------------------------- /** * Set console (monospace) fonts in Terminal and Command Description. */ private void setFont() { try { InputStream is = GraphicalInterface.class.getResourceAsStream("/Resources/style/fonts/Inconsolata.otf"); Font font = Font.createFont(Font.PLAIN, is); Font sizedFont = font.deriveFont(14f); terminalJTextArea.setFont(sizedFont); descriptionJTextArea.setFont(sizedFont); statusJLabel.setFont(sizedFont); } catch (FontFormatException ex) { Logger.getLogger(GraphicalInterface.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(GraphicalInterface.class.getName()).log(Level.SEVERE, null, ex); } } //----------------------------------------------------------------------- /** * Save terminal text to file on disk. */ private void saveToFile() { savesJFileChooser.setApproveButtonText("Save"); savesJFileChooser.setDialogTitle("Save terminal text to file"); int returnValue = savesJFileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { File file = savesJFileChooser.getSelectedFile(); try { String text = terminalJTextArea.getText(); BufferedWriter op = new BufferedWriter(new FileWriter(file)); /* Save output to file */ op.write(text, 0, text.length()); op.close(); /* if we have to open file after saving */ if (saveJCheckBox.isSelected() == true) { m_runtime.exec(Platform.getTextEditor() + " " + file); } statusJLabel.setText("Terminal text saved to file successfully. File path: " + file); } catch (IOException ex) { statusJLabel.setText("Error occured while saving terminal text to file."); } } else { statusJLabel.setText("Save cancelled."); } } //----------------------------------------------------------------------- /** * Disable GUI components before command execution. */ private void disableExecute() { manualJRadioButton.setEnabled(false); listJRadioButton.setEnabled(false); if (m_isManualExecution) { executeManualJButton.setEnabled(false); commandJTextField.setEnabled(false); } else { executeJButton.setSelected(false); commandJComboBox.setEnabled(false); optionJComboBox.setEnabled(false); argumentJTextField.setEnabled(false); optionJTextField.setEnabled(false); executeJButton.setEnabled(false); } jButton1.setEnabled(false); clearJButton.setEnabled(false); showHistoryJButton.setEnabled(false); clearHistoryJButton.setEnabled(false); saveButton.setEnabled(false); } //----------------------------------------------------------------------- /** * Re-enable GUI components after command execution. */ private void enableExecute() { manualJRadioButton.setEnabled(true); listJRadioButton.setEnabled(true); if (m_isManualExecution) { executeManualJButton.setEnabled(true); commandJTextField.setEnabled(true); manualJRadioButton.setEnabled(true); } else { executeJButton.setSelected(true); commandJComboBox.setEnabled(true); optionJComboBox.setEnabled(true); argumentJTextField.setEnabled(true); optionJTextField.setEnabled(true); executeJButton.setEnabled(true); listJRadioButton.setEnabled(true); } jButton1.setEnabled(true); clearJButton.setEnabled(true); showHistoryJButton.setEnabled(true); clearHistoryJButton.setEnabled(true); saveButton.setEnabled(true); } //----------------------------------------------------------------------- /** * newProcess contains code for command execution thread and consequent GUI * update. */ class newProcess implements Runnable { @Override public void run() { /* set default return value as 1, so that only success sets it to zero */ int returnValue = 1; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { abortJButton.setEnabled(true); disableExecute(); DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); /* Setup watchdog */ ExecuteWatchdog watchdog = new ExecuteWatchdog(maxtimeJSlider.getValue() * 1000); Executor executor = new DefaultExecutor(); executor.setStreamHandler(streamHandler); executor.setWatchdog(watchdog); executor.setWorkingDirectory(m_workingDir); /* Execute the command */ executor.execute(cmdLine, resultHandler); /* wait for specified timeout duration */ resultHandler.waitFor(maxtimeJSlider.getValue() * 1000); /* if process still hasn't exited, then destroy */ if (watchdog.isWatching() || !resultHandler.hasResult() || watchdog.killedProcess()) { watchdog.destroyProcess(); statusJLabel.setText("Command execution time limit exceeded. Execution terminated. " + "Retry with more time limit."); return; } returnValue = resultHandler.getExitValue(); /* Update status bar */ /* if command syntax error */ if (returnValue < 0) { statusJLabel.setText( "Command execution terminated with " + "negative return value: " + returnValue); } else { statusJLabel.setText("Command execution [ " + m_completeCommand + " ] " + "terminated with return value: " + returnValue); } } catch (IOException ex) { statusJLabel.setText("IOException occured."); } catch (InterruptedException ex) { statusJLabel.setText("Command execution aborted by user."); } finally { /* play sound */ if (returnValue != 0) { Sound.playClip("Resources/sound/failure.wav"); } else /* Play success notif. sound */ { Sound.playClip("Resources/sound/success.wav"); } /* Display output in Terminal Area */ if (!outputStream.toString().isEmpty()) { terminalJTextArea.append(outputStream.toString()); } terminalJTextArea.append("\n====================\n"); statusJProgressBar.setIndeterminate(false); terminalJTextArea.append("\n" + m_workingDir.getPath() + "> "); setScrollBar(jScrollPane1, 100); abortJButton.setEnabled(false); enableExecute(); } } } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { savesJFileChooser = new javax.swing.JFileChooser(); workdirJFileChooser = new javax.swing.JFileChooser(); jColorChooser1 = new javax.swing.JColorChooser(); jPanel3 = new javax.swing.JPanel(); clearJCheckBox = new javax.swing.JCheckBox(); saveJCheckBox = new javax.swing.JCheckBox(); historyJCheckBox = new javax.swing.JCheckBox(); maxtimeJSlider = new javax.swing.JSlider(); adminJLabel = new javax.swing.JLabel(); rootJCheckBox = new javax.swing.JCheckBox(); rootPasswordJLabel = new javax.swing.JLabel(); passwordJTextField = new javax.swing.JTextField(); jLabel2 = new javax.swing.JLabel(); clearargJCheckBox = new javax.swing.JCheckBox(); jPanel4 = new javax.swing.JPanel(); manualJRadioButton = new javax.swing.JRadioButton(); commandJTextField = new javax.swing.JTextField(); executeManualJButton = new javax.swing.JButton(); optionJLabel = new javax.swing.JLabel(); optionJTextField = new javax.swing.JTextField(); argumentJLabel = new javax.swing.JLabel(); argumentJTextField = new javax.swing.JTextField(); commandJComboBox = new javax.swing.JComboBox(); listJRadioButton = new javax.swing.JRadioButton(); optionJComboBox = new javax.swing.JComboBox(); executeJButton = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); clearJButton = new javax.swing.JButton(); showHistoryJButton = new javax.swing.JButton(); clearHistoryJButton = new javax.swing.JButton(); saveButton = new javax.swing.JButton(); abortJButton = new javax.swing.JButton(); jPanel1 = new javax.swing.JPanel(); statusJLabel = new javax.swing.JLabel(); statusJProgressBar = new javax.swing.JProgressBar(); jTabbedPane1 = new javax.swing.JTabbedPane(); jScrollPane1 = new javax.swing.JScrollPane(); terminalJTextArea = new javax.swing.JTextArea(); jScrollPane2 = new javax.swing.JScrollPane(); descriptionJTextArea = new javax.swing.JTextArea(); jMenuBar1 = new javax.swing.JMenuBar(); jMenu1 = new javax.swing.JMenu(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem1 = new javax.swing.JMenuItem(); jMenu3 = new javax.swing.JMenu(); jMenuItem7 = new javax.swing.JMenuItem(); jMenuItem6 = new javax.swing.JMenuItem(); jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem(); jMenu2 = new javax.swing.JMenu(); jMenuItem5 = new javax.swing.JMenuItem(); jMenuItem4 = new javax.swing.JMenuItem(); jMenuItem3 = new javax.swing.JMenuItem(); savesJFileChooser.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG); workdirJFileChooser.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG); workdirJFileChooser.setApproveButtonText("Select directory"); workdirJFileChooser.setApproveButtonToolTipText("Choose working directory for command execution"); workdirJFileChooser.setDialogTitle("Choose working directory"); workdirJFileChooser.setFileFilter(null); workdirJFileChooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Grafcom Graphical Commander"); setResizable(false); jPanel3.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204))); clearJCheckBox.setText("Clear terminal before executing command"); clearJCheckBox.setFocusPainted(false); saveJCheckBox.setText("Open file after saving"); saveJCheckBox.setFocusPainted(false); historyJCheckBox.setText("Do not save command history"); historyJCheckBox.setFocusPainted(false); historyJCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { historyJCheckBoxActionPerformed(evt); } }); maxtimeJSlider.setMajorTickSpacing(3); maxtimeJSlider.setMaximum(21); maxtimeJSlider.setMinimum(3); maxtimeJSlider.setPaintLabels(true); maxtimeJSlider.setSnapToTicks(true); maxtimeJSlider.setValue(3); maxtimeJSlider.setFocusable(false); adminJLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N adminJLabel.setText("Superuser privileges (Linux-based systems only)"); rootJCheckBox.setText("Run command as root"); rootJCheckBox.setFocusPainted(false); rootJCheckBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { rootJCheckBoxActionPerformed(evt); } }); rootPasswordJLabel.setText("root password:"); passwordJTextField.setForeground(new java.awt.Color(254, 254, 254)); passwordJTextField .setToolTipText("Enter password here. Password not visible due to security considerations"); passwordJTextField.setEnabled(false); passwordJTextField.setSelectionColor(new java.awt.Color(254, 254, 254)); jLabel2.setText("Set command execution timeout (seconds)"); clearargJCheckBox.setText("Clear command arguments after execution"); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(rootJCheckBox).addComponent(adminJLabel) .addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(clearargJCheckBox).addComponent(saveJCheckBox) .addComponent(historyJCheckBox).addComponent(clearJCheckBox)) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(rootPasswordJLabel).addGap(4, 4, 4).addComponent( passwordJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 166, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addGroup(jPanel3Layout.createSequentialGroup().addGap(37, 37, 37).addComponent( maxtimeJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addGap(76, 76, 76).addComponent(jLabel2))) .addGap(52, 52, 52))); jPanel3Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { clearJCheckBox, historyJCheckBox, saveJCheckBox }); jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup().addContainerGap().addComponent(jLabel2) .addGap(2, 2, 2) .addComponent(maxtimeJSlider, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(clearJCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(clearargJCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(saveJCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(historyJCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE) .addComponent(adminJLabel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(rootJCheckBox) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(rootPasswordJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(passwordJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap())); jPanel4.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204))); manualJRadioButton.setText("Type command manually"); manualJRadioButton.setFocusPainted(false); manualJRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { manualJRadioButtonActionPerformed(evt); } }); commandJTextField.setToolTipText("Enter command to execute"); executeManualJButton.setIcon( new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/utilities-terminal16x16.png"))); // NOI18N executeManualJButton.setText("Execute"); executeManualJButton.setFocusPainted(false); executeManualJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { executeManualJButtonActionPerformed(evt); } }); optionJLabel.setText("option argument:"); optionJTextField.setToolTipText("Specify the argument for the selected option"); optionJTextField.setEnabled(false); argumentJLabel.setText("command argument:"); argumentJTextField.setToolTipText("Specify the argument for the selected command"); argumentJTextField.setEnabled(false); commandJComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "(Select command)" })); commandJComboBox.setToolTipText("Select command to execute"); commandJComboBox.setFocusable(false); commandJComboBox.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { commandJComboBoxActionPerformed(evt); } }); listJRadioButton.setSelected(true); listJRadioButton.setText("Select command from list"); listJRadioButton.setFocusPainted(false); listJRadioButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { listJRadioButtonActionPerformed(evt); } }); optionJComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "(Select option)" })); optionJComboBox.setToolTipText("Choose option for the selected command"); optionJComboBox.setEnabled(false); optionJComboBox.setFocusable(false); executeJButton.setIcon( new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/utilities-terminal16x16.png"))); // NOI18N executeJButton.setText("Execute"); executeJButton.setToolTipText("Click to execute command with the given parameters"); executeJButton.setEnabled(false); executeJButton.setFocusPainted(false); executeJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { executeJButtonActionPerformed(evt); } }); jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/folder.png"))); // NOI18N jButton1.setText("Set command execution path..."); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4); jPanel4.setLayout(jPanel4Layout); jPanel4Layout.setHorizontalGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel4Layout.createSequentialGroup().addContainerGap().addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(argumentJLabel).addComponent(optionJLabel)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(argumentJTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE) .addComponent(optionJTextField)) .addGap(113, 113, 113)) .addGroup(jPanel4Layout.createSequentialGroup().addGroup(jPanel4Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(listJRadioButton) .addGroup(jPanel4Layout.createSequentialGroup() .addComponent(commandJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 135, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(optionJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(executeJButton)) .addComponent(manualJRadioButton) .addGroup(jPanel4Layout.createSequentialGroup() .addComponent(commandJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(executeManualJButton)) .addGroup(jPanel4Layout.createSequentialGroup().addGap(79, 79, 79) .addComponent(jButton1))) .addContainerGap())))); jPanel4Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] { argumentJLabel, optionJLabel }); jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup() .addContainerGap().addComponent(listJRadioButton).addGap(4, 4, 4) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(commandJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(optionJComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(executeJButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(argumentJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(argumentJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 21, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(optionJTextField).addComponent(optionJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(7, 7, 7).addComponent(manualJRadioButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(commandJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(executeManualJButton)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel4Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] { argumentJTextField, optionJTextField }); clearJButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/edit-clear.png"))); // NOI18N clearJButton.setText("Clear Terminal"); clearJButton.setToolTipText("Click to clear terminal output"); clearJButton.setFocusPainted(false); clearJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clearJButtonActionPerformed(evt); } }); showHistoryJButton.setIcon( new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/format-justify-fill.png"))); // NOI18N showHistoryJButton.setText("Show history"); showHistoryJButton.setToolTipText("Click to display the list of commands executed"); showHistoryJButton.setFocusPainted(false); showHistoryJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { showHistoryJButtonActionPerformed(evt); } }); clearHistoryJButton .setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/edit-clear.png"))); // NOI18N clearHistoryJButton.setText("Clear History"); clearHistoryJButton.setFocusPainted(false); clearHistoryJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { clearHistoryJButtonActionPerformed(evt); } }); saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/media-floppy.png"))); // NOI18N saveButton.setText("Save to file..."); saveButton.setFocusPainted(false); saveButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { saveButtonActionPerformed(evt); } }); abortJButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Resources/icon/process-stop.png"))); // NOI18N abortJButton.setText("Abort"); abortJButton.setToolTipText("Abort command execution"); abortJButton.setEnabled(false); abortJButton.setFocusPainted(false); abortJButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { abortJButtonActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup(jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup().addGap(13, 13, 13).addComponent(clearJButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(showHistoryJButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(clearHistoryJButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(saveButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(abortJButton) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(clearJButton).addComponent(showHistoryJButton) .addComponent(clearHistoryJButton).addComponent(saveButton).addComponent(abortJButton))); jPanel1.setBackground(new java.awt.Color(51, 51, 51)); statusJLabel.setForeground(new java.awt.Color(255, 255, 255)); statusJLabel.setText("Select command from drop-down list or type manually to execute."); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup(jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap() .addComponent(statusJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(statusJProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap())); jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(statusJLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE) .addComponent(statusJProgressBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); terminalJTextArea.setEditable(false); terminalJTextArea.setBackground(new java.awt.Color(51, 51, 51)); terminalJTextArea.setColumns(20); terminalJTextArea.setFont(new java.awt.Font("Consolas", 0, 13)); // NOI18N terminalJTextArea.setForeground(new java.awt.Color(204, 204, 204)); terminalJTextArea.setLineWrap(true); terminalJTextArea.setRows(5); terminalJTextArea.setTabSize(3); terminalJTextArea.setToolTipText("Displays output of command executed"); terminalJTextArea.setCaretColor(new java.awt.Color(204, 204, 204)); terminalJTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR)); terminalJTextArea.setMargin(new java.awt.Insets(8, 4, 4, 4)); terminalJTextArea.setSelectionColor(new java.awt.Color(153, 153, 153)); jScrollPane1.setViewportView(terminalJTextArea); jTabbedPane1.addTab("Terminal Emulator", jScrollPane1); jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); descriptionJTextArea.setEditable(false); descriptionJTextArea.setColumns(20); descriptionJTextArea.setFont(new java.awt.Font("Consolas", 0, 13)); // NOI18N descriptionJTextArea.setLineWrap(true); descriptionJTextArea.setRows(5); descriptionJTextArea.setTabSize(3); descriptionJTextArea.setToolTipText("Description of selected command and its options"); descriptionJTextArea.setWrapStyleWord(true); descriptionJTextArea.setCaretColor(new java.awt.Color(255, 255, 255)); descriptionJTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR)); descriptionJTextArea.setFocusable(false); descriptionJTextArea.setMargin(new java.awt.Insets(4, 4, 4, 4)); descriptionJTextArea.setSelectionColor(new java.awt.Color(51, 204, 255)); jScrollPane2.setViewportView(descriptionJTextArea); jTabbedPane1.addTab("Command Description", jScrollPane2); jMenu1.setText("File"); jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK)); jMenuItem2.setText("Save output to file..."); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenuItem1.setText("Exit"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); jMenu1.add(jMenuItem1); jMenuBar1.add(jMenu1); jMenu3.setText("Settings"); jMenuItem7.setText("Terminal background color"); jMenuItem7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem7ActionPerformed(evt); } }); jMenu3.add(jMenuItem7); jMenuItem6.setText("Terminal text color"); jMenuItem6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem6ActionPerformed(evt); } }); jMenu3.add(jMenuItem6); jCheckBoxMenuItem1.setSelected(true); jCheckBoxMenuItem1.setText("Sounds"); jCheckBoxMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jCheckBoxMenuItem1ActionPerformed(evt); } }); jMenu3.add(jCheckBoxMenuItem1); jMenuBar1.add(jMenu3); jMenu2.setText("Help"); jMenuItem5.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0)); jMenuItem5.setText("Grafcom help contents"); jMenuItem5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem5ActionPerformed(evt); } }); jMenu2.add(jMenuItem5); jMenuItem4.setText("Project Homepage"); jMenuItem4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem4ActionPerformed(evt); } }); jMenu2.add(jMenuItem4); jMenuItem3.setText("About"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu2.add(jMenuItem3); jMenuBar1.add(jMenu2); setJMenuBar(jMenuBar1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, 372, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jTabbedPane1)) .addGap(11, 11, 11)) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGap(18, 18, 18).addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(layout.createSequentialGroup().addComponent(jTabbedPane1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); pack(); setLocationRelativeTo(null); }// </editor-fold>//GEN-END:initComponents private void commandJComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_commandJComboBoxActionPerformed /* when no command has been chosen */ if (commandJComboBox.getSelectedIndex() == 0) { argumentJTextField.setEnabled(false); optionJTextField.setEnabled(false); optionJComboBox.setEnabled(false); executeJButton.setEnabled(false); descriptionJTextArea.setText(""); statusJLabel.setText("Select command from drop-down list or type manually to execute."); descriptionJTextArea.setText(m_defaultDescription); return; } argumentJTextField.setEnabled(true); optionJTextField.setEnabled(true); optionJComboBox.setEnabled(true); executeJButton.setEnabled(true); /* get the 'name' of the command chosen */ m_command = commandJComboBox.getSelectedItem().toString(); /* Sets the option list according to command chosen */ optionJComboBox.setModel(new javax.swing.DefaultComboBoxModel(Platform.getOptionList(m_command))); try { descriptionJTextArea.setText(""); descriptionJTextArea .setText(descriptionJTextArea.getText() + m_description.getCommandData(m_command) + "\n"); statusJLabel.setText( "Command description changed. Click on \'Command Description\' tab to view " + "description."); setScrollBar(jScrollPane2, 0); } catch (Exception e) { e.printStackTrace(); } }//GEN-LAST:event_commandJComboBoxActionPerformed private void executeJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_executeJButtonActionPerformed /* Clear terminal area if needed */ if (clearJCheckBox.isSelected() == true) { terminalJTextArea.setText(m_defaultTerminal); } if (OS.isFamilyUnix() && m_command.equals("traceroute")) { /* set Absolute path to traceroute in Linux */ m_command = "/usr/sbin/traceroute"; } m_internalPrefix = OS.isFamilyWindows(); String prefix = (m_internalPrefix) ? "cmd.exe /c " : ""; String option = optionJComboBox.getSelectedItem().toString(); option = option.startsWith("(") ? "" : " " + option; String optionarg = optionJTextField.getText(); optionarg = optionarg.trim().isEmpty() ? "" : " " + optionarg.trim(); String cmdarg = argumentJTextField.getText(); cmdarg = cmdarg.trim().isEmpty() ? "" : " " + cmdarg.trim(); m_completeCommand = m_command + option + optionarg + cmdarg; cmdLine = CommandLine.parse(prefix + m_completeCommand); /* Update status bar */ statusJLabel.setText("Running command... " + m_completeCommand); statusJProgressBar.setIndeterminate(true); terminalJTextArea.append(m_completeCommand + "\n"); setScrollBar(jScrollPane1, 100); m_isManualExecution = false; t = new Thread(new newProcess(), "Process-Thread"); t.start(); /* Add command to history */ if (!historyJCheckBox.isSelected()) { m_history += m_completeCommand + "\n"; } /* Clear states */ if (clearargJCheckBox.isSelected()) { argumentJTextField.setText(""); optionJTextField.setText(""); } passwordJTextField.setText(""); passwordJTextField.setEnabled(false); rootJCheckBox.setSelected(false); }//GEN-LAST:event_executeJButtonActionPerformed private void clearJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearJButtonActionPerformed terminalJTextArea.setText(m_defaultTerminal); terminalJTextArea.append("\n" + m_workingDir.getPath() + "> "); setScrollBar(jScrollPane1, 100); }//GEN-LAST:event_clearJButtonActionPerformed private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed saveToFile(); }//GEN-LAST:event_saveButtonActionPerformed private void showHistoryJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showHistoryJButtonActionPerformed terminalJTextArea.append("\nCommand history:\n" + m_history); terminalJTextArea.append("\n====================\n"); terminalJTextArea.append("\n" + m_workingDir.getPath() + "> "); setScrollBar(jScrollPane1, 100); }//GEN-LAST:event_showHistoryJButtonActionPerformed private void clearHistoryJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearHistoryJButtonActionPerformed m_history = ""; statusJLabel.setText("Command history cleared."); }//GEN-LAST:event_clearHistoryJButtonActionPerformed private void executeManualJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_executeManualJButtonActionPerformed /* get the command from manual-cmd textField */ String manual = commandJTextField.getText().trim(); if (manual.length() == 0) { statusJLabel.setText("Empty command entered."); return; } /* Clear terminal area if needed */ if (clearJCheckBox.isSelected() == true) { terminalJTextArea.setText(""); } m_completeCommand = manual; m_internalPrefix = !manual.startsWith("cmd.exe") && OS.isFamilyWindows(); String prefix = (m_internalPrefix) ? "cmd.exe /c " : ""; cmdLine = CommandLine.parse(prefix + manual); /* Update status bar */ statusJLabel.setText("Running command... " + m_completeCommand); statusJProgressBar.setIndeterminate(true); terminalJTextArea.append(m_completeCommand + "\n"); setScrollBar(jScrollPane1, 100); m_isManualExecution = true; t = new Thread(new newProcess()); t.start(); /* Add command to history */ if (!historyJCheckBox.isSelected()) { m_history += m_completeCommand + "\n"; } /* Clear states after executing command */ /* Set argument box to null after executing command */ if (clearargJCheckBox.isSelected()) { commandJTextField.setText(""); } passwordJTextField.setText(""); passwordJTextField.setEnabled(false); rootJCheckBox.setSelected(false); }//GEN-LAST:event_executeManualJButtonActionPerformed private void historyJCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_historyJCheckBoxActionPerformed m_history = ""; }//GEN-LAST:event_historyJCheckBoxActionPerformed private void rootJCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rootJCheckBoxActionPerformed /* if root-check box is enabled */ if (rootJCheckBox.isSelected() == true) { passwordJTextField.setEnabled(true); /* clear password field */ passwordJTextField.setText(""); } else { /* clearpassword field */ passwordJTextField.setText(""); passwordJTextField.setEnabled(false); } }//GEN-LAST:event_rootJCheckBoxActionPerformed private void listJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_listJRadioButtonActionPerformed commandJTextField.setEnabled(false); executeManualJButton.setEnabled(false); commandJComboBox.setEnabled(true); commandJComboBox.setSelectedIndex(0); descriptionJTextArea.setText(m_defaultDescription); }//GEN-LAST:event_listJRadioButtonActionPerformed private void manualJRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manualJRadioButtonActionPerformed commandJComboBox.setEnabled(false); optionJComboBox.setEnabled(false); argumentJTextField.setEnabled(false); optionJTextField.setEnabled(false); executeJButton.setEnabled(false); commandJTextField.setEnabled(true); executeManualJButton.setEnabled(true); descriptionJTextArea.setText(m_defaultDescription); }//GEN-LAST:event_manualJRadioButtonActionPerformed private void abortJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_abortJButtonActionPerformed if (JOptionPane.showConfirmDialog(null, "Are you sure you want to abort command execution?", "Abort execution", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { t.interrupt(); } }//GEN-LAST:event_abortJButtonActionPerformed private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; String homepage = "https://sourceforge.net/projects/grafcom/"; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { try { desktop.browse(java.net.URI.create(homepage)); } catch (IOException e) { System.out.println("Error occured while opening Project homepage at SourceForge.net"); } } }//GEN-LAST:event_jMenuItem4ActionPerformed private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed if (JOptionPane.showConfirmDialog(null, "Are you sure you want to quit?", "Quit game", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { System.exit(0); } }//GEN-LAST:event_jMenuItem1ActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed int returnValue = workdirJFileChooser.showOpenDialog(this); if (returnValue == JFileChooser.APPROVE_OPTION) { m_workingDir = workdirJFileChooser.getSelectedFile(); terminalJTextArea.append("\n" + m_workingDir.getPath() + "> "); setScrollBar(jScrollPane1, 100); } }//GEN-LAST:event_jButton1ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed saveToFile(); }//GEN-LAST:event_jMenuItem2ActionPerformed private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed HelpDialog HD = new HelpDialog(null, true); }//GEN-LAST:event_jMenuItem5ActionPerformed private void jCheckBoxMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem1ActionPerformed if (!Sound.isMute()) { Sound.setMuteOn(); } else { Sound.setMuteOff(); } }//GEN-LAST:event_jCheckBoxMenuItem1ActionPerformed private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed Color fontColor = JColorChooser.showDialog(terminalJTextArea, "Choose font color", Color.white); if (fontColor != null) { terminalJTextArea.setForeground(fontColor); } }//GEN-LAST:event_jMenuItem6ActionPerformed private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed Color backgroundColor = JColorChooser.showDialog(terminalJTextArea, "Choose background color", Color.white); if (backgroundColor != null) { terminalJTextArea.setBackground(backgroundColor); } }//GEN-LAST:event_jMenuItem7ActionPerformed private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed AboutDialog AD = new AboutDialog(null, true); }//GEN-LAST:event_jMenuItem3ActionPerformed public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(GraphicalInterface.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(GraphicalInterface.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(GraphicalInterface.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(GraphicalInterface.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { new GraphicalInterface().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton abortJButton; private javax.swing.JLabel adminJLabel; private javax.swing.JLabel argumentJLabel; private javax.swing.JTextField argumentJTextField; private javax.swing.JButton clearHistoryJButton; private javax.swing.JButton clearJButton; private javax.swing.JCheckBox clearJCheckBox; private javax.swing.JCheckBox clearargJCheckBox; private javax.swing.JComboBox commandJComboBox; private javax.swing.JTextField commandJTextField; private javax.swing.JTextArea descriptionJTextArea; private javax.swing.JButton executeJButton; private javax.swing.JButton executeManualJButton; private javax.swing.JCheckBox historyJCheckBox; private javax.swing.JButton jButton1; private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1; private javax.swing.JColorChooser jColorChooser1; private javax.swing.JLabel jLabel2; private javax.swing.JMenu jMenu1; private javax.swing.JMenu jMenu2; private javax.swing.JMenu jMenu3; private javax.swing.JMenuBar jMenuBar1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; private javax.swing.JMenuItem jMenuItem4; private javax.swing.JMenuItem jMenuItem5; private javax.swing.JMenuItem jMenuItem6; private javax.swing.JMenuItem jMenuItem7; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JPanel jPanel4; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JRadioButton listJRadioButton; private javax.swing.JRadioButton manualJRadioButton; private javax.swing.JSlider maxtimeJSlider; private javax.swing.JComboBox optionJComboBox; private javax.swing.JLabel optionJLabel; private javax.swing.JTextField optionJTextField; private javax.swing.JTextField passwordJTextField; private javax.swing.JCheckBox rootJCheckBox; private javax.swing.JLabel rootPasswordJLabel; private javax.swing.JButton saveButton; private javax.swing.JCheckBox saveJCheckBox; private javax.swing.JFileChooser savesJFileChooser; private javax.swing.JButton showHistoryJButton; private javax.swing.JLabel statusJLabel; private javax.swing.JProgressBar statusJProgressBar; private javax.swing.JTextArea terminalJTextArea; private javax.swing.JFileChooser workdirJFileChooser; // End of variables declaration//GEN-END:variables } class MyBlankWorker extends SwingWorker<Integer, String> { @Override protected Integer doInBackground() throws Exception { for (int i = 0; i < 1000000; i++) { System.out.println(i); } return 1; } }