|
From: fredrik <fre...@us...> - 2005-04-28 11:51:44
|
Update of /cvsroot/test-manager/main/src/testmanager/gui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14164/src/testmanager/gui Modified Files: MainWindow.java MainWindowLogHandler.java Added Files: AdminAccountDialog.java Log Message: Reorganizing servlets & adding bug tracking Index: MainWindowLogHandler.java =================================================================== RCS file: /cvsroot/test-manager/main/src/testmanager/gui/MainWindowLogHandler.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** MainWindowLogHandler.java 20 Apr 2005 00:50:07 -0000 1.2 --- MainWindowLogHandler.java 28 Apr 2005 11:51:04 -0000 1.3 *************** *** 2,5 **** --- 2,6 ---- import java.util.logging.Handler; + import java.util.logging.Level; import java.util.logging.LogRecord; *************** *** 30,34 **** */ public void publish(LogRecord record) { ! mainWindow.log(record.getMessage()); } --- 31,39 ---- */ public void publish(LogRecord record) { ! if (record.getLevel() == Level.SEVERE) { ! mainWindow.log("SEVERE " + record.getMessage()); ! } else { ! mainWindow.log(record.getMessage()); ! } } --- NEW FILE: AdminAccountDialog.java --- package testmanager.gui; import java.awt.Frame; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; /** * @author Fredrik Fornwall */ public class AdminAccountDialog extends JDialog { protected JTextField fullNameField = new JTextField(20); protected JTextField userNameField = new JTextField(20); protected JTextField mailField = new JTextField(20); protected JPasswordField passwordField = new JPasswordField(20); protected JButton okButton = new JButton("Ok"); protected JButton cancelButton = new JButton("Cancel"); protected JLabel userNameLabel = new JLabel("User Name:"); protected JLabel fullNameLabel = new JLabel("Full Name:"); protected JLabel passLabel = new JLabel("Pasword:"); protected JLabel mailLabel = new JLabel("Mail:"); public String getFullName() { return fullNameField.getText(); } public String getPass() { return new String(passwordField.getPassword()); } public String getUserName() { return userNameField.getText(); } public String getMail() { return mailField.getText(); } public boolean okPressed() { return pressed_OK; } private boolean pressed_OK = false; public AdminAccountDialog(Frame parent, String title) { super(parent, title, true); if (parent != null) { setLocationRelativeTo(parent); } } protected void dialogInit() { super.dialogInit(); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent e) { // other actions close the dialog. pressed_OK = (e.getSource() == okButton); setVisible(false); } }; GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); c.insets.top = c.insets.bottom = c.insets.right = c.insets.left = 5; JPanel pane = new JPanel(gridbag); pane.setBorder(BorderFactory.createEmptyBorder(10, 20, 5, 20)); c.anchor = GridBagConstraints.EAST; if (gridbag == null) System.out.println("GRIDBAG IS NULL!"); if (fullNameLabel == null) System.out.println("FULLNAMELABEL IS NULL!"); if (c == null) System.out.println("C IS NULL"); gridbag.setConstraints(fullNameLabel, c); pane.add(fullNameLabel); gridbag.setConstraints(fullNameField, c); pane.add(fullNameField); c.gridy = 1; gridbag.setConstraints(passLabel, c); pane.add(passLabel); gridbag.setConstraints(passwordField, c); pane.add(passwordField); c.gridy = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.anchor = GridBagConstraints.CENTER; JPanel panel = new JPanel(); okButton.addActionListener(actionListener); panel.add(okButton); cancelButton.addActionListener(actionListener); panel.add(cancelButton); gridbag.setConstraints(panel, c); pane.add(panel); getContentPane().add(pane); pack(); } } Index: MainWindow.java =================================================================== RCS file: /cvsroot/test-manager/main/src/testmanager/gui/MainWindow.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** MainWindow.java 24 Apr 2005 02:10:38 -0000 1.20 --- MainWindow.java 28 Apr 2005 11:51:04 -0000 1.21 *************** *** 34,213 **** public class MainWindow extends JFrame { ! /** ! * Try to set the system look and feel. ! */ ! static { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } catch (Exception e) { ! // If the system look and feel cannot be found, the default look ! // and feel will be used automatically. ! } ! } ! private JMenuBar menuBar = new JMenuBar(); ! private JTextArea logArea = new JTextArea(); ! private JTextField statusField = new JTextField("Starting"); ! private static MainWindow instance; ! private static SimpleDateFormat dateFormat = new SimpleDateFormat("y-MM-dd HH:mm:ss"); ! /** ! * Set the message show in the status label. ! * ! * @param statusText ! * The status text to display. ! */ ! public void setStatusLabel(final String statusText) { ! SwingUtilities.invokeLater(new Runnable() { ! public void run() { ! statusField.setText(statusText); ! } ! }); ! } ! /** ! * Add a log message to the main window. ! * ! * @param logMessage ! * The log message which will be writtin in the log area. ! */ ! public void log(final String logMessage) { ! // As JTextArea#append is thread-safe it could be called in this thread. ! // However, if we want the scroll pane to be updated to show the last ! // inserted line, this method must be called in the event dispatch ! // thread. ! SwingUtilities.invokeLater(new Runnable() { ! public void run() { ! instance.logArea.append(dateFormat.format(new Date()) + " " + logMessage + "\n"); ! } ! }); ! } ! /** ! * Show a confirmation dialog asking the user if he really wants to close down the application. ! * The intent is to prevent a user from accidentally closing the Open Test Manager server by ! * closing the main window. ! */ ! public static void confirmShutdown() { ! switch (Application.getInstance().getState()) { ! case Application.STATE_RUNNING: ! // Continue with asking the user if he wants to shut down ! break; ! case Application.STATE_ERROR: ! // Cannot shut down correctly, just exit the application ! System.exit(0); ! break; ! case Application.STATE_SHUTTING_DOWN: ! // We are already shutting down, ignore another request ! return; ! case Application.STATE_STARTING: ! // Don't interrupt while starting application, ignore request ! return; ! default: ! break; ! } ! int response = JOptionPane.showConfirmDialog(instance, new String[] { ! "Do you want to shut down the Open Test Manager server?", ! "No clients will be able to access the application." }, "Really shut down?", ! JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); ! if (response == JOptionPane.YES_OPTION) { ! // Shut down in a separate thread as it may take some time ! Thread shutDownThread = new Thread() { ! public void run() { ! Application.getInstance().shutDown(); ! } ! }; ! shutDownThread.start(); ! } ! } ! /** ! * Create a new main window. ! */ ! public MainWindow() { ! // Set the window title showing application name and version number ! super("Open Test Manager v" + Application.VERSION); ! setupMenu(); ! instance = this; ! getContentPane().setLayout(new GridBagLayout()); ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.fill = GridBagConstraints.BOTH; ! constraints.weightx = 1.0; ! logArea.setEditable(false); ! constraints.gridx = 0; ! constraints.gridy = 1; ! JPanel statusPanel = new JPanel(); ! statusPanel.setLayout(new BorderLayout()); ! statusPanel.setBorder(BorderFactory.createTitledBorder("Status")); ! statusPanel.add(statusField); ! statusField.setEditable(false); ! statusField.setText("Starting"); ! getContentPane().add(statusPanel, constraints); ! constraints.gridy = 0; ! constraints.gridx = 0; ! constraints.weighty = 1.0; ! constraints.weightx = 1.0; ! constraints.fill = GridBagConstraints.BOTH; ! JPanel logPanel = new JPanel(); ! logPanel.setLayout(new BorderLayout()); ! logArea.setLineWrap(true); ! logArea.setWrapStyleWord(true); ! logPanel.add(new JScrollPane(logArea)); ! logPanel.setBorder(BorderFactory.createTitledBorder("Log")); ! getContentPane().add(logPanel, constraints); ! addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent arg0) { ! confirmShutdown(); ! } ! }); ! } ! /** ! * Setup the menu for the main window. ! */ ! private void setupMenu() { ! JMenu menu = new JMenu("File"); ! menu.setMnemonic(KeyEvent.VK_F); ! menuBar.add(menu); ! JMenuItem menuItem = new JMenuItem("Exit"); ! menuItem.setMnemonic(KeyEvent.VK_X); ! menuItem.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent event) { ! confirmShutdown(); ! } ! }); ! menu.add(menuItem); ! menu = new JMenu("Help"); ! menu.setMnemonic(KeyEvent.VK_H); ! menuItem = new JMenuItem("About Open Test Manager"); ! menuItem.setMnemonic(KeyEvent.VK_A); ! menuItem.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent event) { ! JOptionPane.showMessageDialog(instance, ! "Open Test Manager - a test management tool\n\n" ! + "http://test-manager.sf.net/"); ! } ! }); ! menu.add(menuItem); ! menuBar.add(menu); ! setJMenuBar(menuBar); ! } } \ No newline at end of file --- 34,227 ---- public class MainWindow extends JFrame { ! /** ! * Try to set the system look and feel. ! */ ! static { ! try { ! UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); ! } catch (Exception e) { ! // If the system look and feel cannot be found, the default look ! // and feel will be used automatically. ! } ! } ! private JMenuBar menuBar = new JMenuBar(); ! private JTextArea logArea = new JTextArea(); ! private JTextField statusField = new JTextField("Starting"); ! private static MainWindow instance; ! private static SimpleDateFormat dateFormat = new SimpleDateFormat( ! "y-MM-dd HH:mm:ss"); ! /** ! * Set the message show in the status label. ! * ! * @param statusText ! * The status text to display. ! */ ! public void setStatusLabel(final String statusText) { ! SwingUtilities.invokeLater(new Runnable() { ! public void run() { ! statusField.setText(statusText); ! } ! }); ! } ! /** ! * Prompt the user for an initial admin password. ! * ! * @return The password entered by the user. ! */ ! public String getInitialAdminPassword() { ! AdminAccountDialog d = new AdminAccountDialog(this, "Enter admin account information"); ! d.setVisible(true); ! return d.getName(); ! } ! /** ! * Add a log message to the main window. ! * ! * @param logMessage ! * The log message which will be writtin in the log area. ! */ ! public void log(final String logMessage) { ! // As JTextArea#append is thread-safe it could be called in this thread. ! // However, if we want the scroll pane to be updated to show the last ! // inserted line, this method must be called in the event dispatch ! // thread. ! SwingUtilities.invokeLater(new Runnable() { ! public void run() { ! instance.logArea.append(dateFormat.format(new Date()) + " " ! + logMessage + "\n"); ! } ! }); ! } ! /** ! * Show a confirmation dialog asking the user if he really wants to close ! * down the application. The intent is to prevent a user from accidentally ! * closing the Open Test Manager server by closing the main window. ! */ ! public static void confirmShutdown() { ! switch (Application.getInstance().getState()) { ! case Application.STATE_RUNNING: ! // Continue with asking the user if he wants to shut down ! break; ! case Application.STATE_ERROR: ! // Cannot shut down correctly, just exit the application ! System.exit(0); ! break; ! case Application.STATE_SHUTTING_DOWN: ! // We are already shutting down, ignore another request ! return; ! case Application.STATE_STARTING: ! // Don't interrupt while starting application, ignore request ! return; ! default: ! break; ! } ! int response = JOptionPane.showConfirmDialog(instance, new String[] { ! "Do you want to shut down the Open Test Manager server?", ! "No clients will be able to access the application." }, ! "Really shut down?", JOptionPane.YES_NO_OPTION, ! JOptionPane.WARNING_MESSAGE); ! if (response == JOptionPane.YES_OPTION) { ! // Shut down in a separate thread as it may take some time ! Thread shutDownThread = new Thread() { ! public void run() { ! Application.getInstance().shutDown(); ! } ! }; ! shutDownThread.start(); ! } ! } ! /** ! * Create a new main window. ! */ ! public MainWindow() { ! // Set the window title showing application name and version number ! super("Open Test Manager " + Application.VERSION); ! setupMenu(); ! instance = this; ! getContentPane().setLayout(new GridBagLayout()); ! GridBagConstraints constraints = new GridBagConstraints(); ! constraints.fill = GridBagConstraints.BOTH; ! constraints.weightx = 1.0; ! logArea.setEditable(false); ! constraints.gridx = 0; ! constraints.gridy = 1; ! JPanel statusPanel = new JPanel(); ! statusPanel.setLayout(new BorderLayout()); ! statusPanel.setBorder(BorderFactory.createTitledBorder("Status")); ! statusPanel.add(statusField); ! statusField.setEditable(false); ! statusField.setText("Starting"); ! getContentPane().add(statusPanel, constraints); ! constraints.gridy = 0; ! constraints.gridx = 0; ! constraints.weighty = 1.0; ! constraints.weightx = 1.0; ! constraints.fill = GridBagConstraints.BOTH; ! JPanel logPanel = new JPanel(); ! logPanel.setLayout(new BorderLayout()); ! logArea.setLineWrap(true); ! logArea.setWrapStyleWord(true); ! logPanel.add(new JScrollPane(logArea)); ! logPanel.setBorder(BorderFactory.createTitledBorder("Log")); ! getContentPane().add(logPanel, constraints); ! addWindowListener(new WindowAdapter() { ! public void windowClosing(WindowEvent arg0) { ! confirmShutdown(); ! } ! }); ! } ! /** ! * Setup the menu for the main window. ! */ ! private void setupMenu() { ! JMenu menu = new JMenu("File"); ! menu.setMnemonic(KeyEvent.VK_F); ! menuBar.add(menu); ! JMenuItem menuItem = new JMenuItem("Exit"); ! menuItem.setMnemonic(KeyEvent.VK_X); ! menuItem.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent event) { ! confirmShutdown(); ! } ! }); ! menu.add(menuItem); ! menu = new JMenu("Help"); ! menu.setMnemonic(KeyEvent.VK_H); ! menuItem = new JMenuItem("About Open Test Manager"); ! menuItem.setMnemonic(KeyEvent.VK_A); ! menuItem.addActionListener(new ActionListener() { ! public void actionPerformed(ActionEvent event) { ! JOptionPane.showMessageDialog(instance, ! "Open Test Manager - a test management tool\n\n" ! + "http://test-manager.sf.net/"); ! } ! }); ! menu.add(menuItem); ! menuBar.add(menu); ! ! setJMenuBar(menuBar); ! } } \ No newline at end of file |