khammond    01/10/07 22:20:49

  Modified:    src/org/apache/jmeter/protocol/http/gui AuthPanel.java
  Log:
  New GUI style.
  
  Revision  Changes    Path
  1.10      +228 -287  
jakarta-jmeter/src/org/apache/jmeter/protocol/http/gui/AuthPanel.java
  
  Index: AuthPanel.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/org/apache/jmeter/protocol/http/gui/AuthPanel.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- AuthPanel.java    2001/07/26 00:34:48     1.9
  +++ AuthPanel.java    2001/10/08 05:20:49     1.10
  @@ -52,7 +52,7 @@
    * information on the Apache Software Foundation, please see
    * <http://www.apache.org/>.
    */
  - package org.apache.jmeter.protocol.http.gui;
  +package org.apache.jmeter.protocol.http.gui;
   import javax.swing.*;
   import javax.swing.border.*;
   import javax.swing.table.*;
  @@ -68,11 +68,11 @@
    *  Sampler. It also understands how to get AuthManagers for the files that the
    *  user selects.
    *
  - *@author     $Author: mstover1 $
  - *@created    $Date: 2001/07/26 00:34:48 $
  - *@version    $Revision: 1.9 $
  + *@author     $Author: khammond $
  + *@created    $Date: 2001/10/08 05:20:49 $
  + *@version    $Revision: 1.10 $
    ***********************************************************/
  -public class AuthPanel extends JPanel implements ModelSupported
  +public class AuthPanel extends JPanel implements ModelSupported, ActionListener
   {
   
        InnerTableModel tableModel;
  @@ -86,6 +86,11 @@
         ***********************************************************/
        JTable authTable;
        private NamePanel namePanel;
  +     JButton addButton;
  +     JButton deleteButton;
  +     JButton loadButton;
  +     JButton saveButton;
  +     JPanel authManagerPanel;
   
        /************************************************************
         *  Default Constructor
  @@ -124,299 +129,206 @@
         ***********************************************************/
        public void init()
        {
  -             this.setLayout(new VerticalLayout());
  +             // set the layout of the control panel
  +             this.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
  +
  +             authManagerPanel = new JPanel();
  +
  +             Border margin = new EmptyBorder(10, 10, 5, 10);
  +             authManagerPanel.setBorder(margin);
  +
  +             authManagerPanel.setLayout(new VerticalLayout(5, VerticalLayout.LEFT));
  +
  +             JLabel panelTitleLabel = new 
JLabel(JMeterUtils.getResString("auth_manager_title"));
  +             Font curFont = panelTitleLabel.getFont();
  +             int curFontSize = curFont.getSize();
  +             curFontSize += 4;
  +             panelTitleLabel.setFont(new Font(curFont.getFontName(), 
curFont.getStyle(), curFontSize));
  +             authManagerPanel.add(panelTitleLabel);
  +
                namePanel = new NamePanel(manager);
  -             this.add(namePanel);
  -             authTable = new JTable(tableModel);
  -             authTable.setCellSelectionEnabled(false);
  -             authTable.setRowSelectionAllowed(true);
  -             authTable.setColumnSelectionAllowed(false);
  -             authTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  +             authManagerPanel.add(namePanel);
   
  -             JPanel main = new JPanel();
  -             main.setLayout(new BorderLayout());
  +             JPanel authTablePanel = createAuthTablePanel();
  +             authManagerPanel.add(authTablePanel);
   
  -             JScrollPane scroller = new JScrollPane(authTable);
  -             JTableHeader tableHeader = authTable.getTableHeader();
  -             scroller.setColumnHeaderView(tableHeader);
  -             main.add(scroller);
  +             this.add(authManagerPanel);
  +     }
   
  -             ButtonPanel buttons = new ButtonPanel();
  -             buttons.addButtonListener(buttons.ADD_BUTTON,
  -                     new ActionListener()
  -                     {
  -                             
/************************************************************
  -                              *  !ToDo (Method description)
  -                              *
  -                              *@param  e  !ToDo (Parameter description)
  -                              
***********************************************************/
  -                             public void actionPerformed(ActionEvent e)
  -                             {
  -                                     final JDialog addDialog = new JDialog();
  -                                     addDialog.setSize(300, 150);
  +     public void actionPerformed(ActionEvent e)
  +     {
  +             String action = e.getActionCommand();
   
  -                                     JPanel _main = new JPanel();
  -                                     GridBagLayout g = new GridBagLayout();
  -                                     _main.setLayout(g);
  -                                     GridBagConstraints c = new 
GridBagConstraints();
  -                                     c.fill = c.BOTH;
  -                                     c.gridwidth = 1;
  -                                     c.gridheight = 1;
  -                                     c.gridx = 1;
  -                                     c.gridy = 1;
  -                                     JLabel urlLabel = new JLabel("Base URL:");
  -                                     g.setConstraints(urlLabel, c);
  -
  -                                     _main.add(urlLabel);
  -                                     final JTextField nameField = new 
JTextField(20);
  -                                     c.gridx = 2;
  -                                     c.gridy = 1;
  -                                     g.setConstraints(nameField, c);
  -                                     _main.add(nameField);
  -                                     JLabel usernameLabel = new 
JLabel(JMeterUtils.getResString("username")+":");
  -                                     c.gridx = 1;
  -                                     c.gridy = 2;
  -                                     g.setConstraints(usernameLabel, c);
  -                                     _main.add(usernameLabel);
  -                                     final JTextField usernameField = new 
JTextField(20);
  -                                     c.gridx = 2;
  -                                     c.gridy = 2;
  -                                     g.setConstraints(usernameField, c);
  -                                     _main.add(usernameField);
  -                                     JLabel passwordLabel = new 
JLabel(JMeterUtils.getResString("password")+":");
  -                                     c.gridx = 1;
  -                                     c.gridy = 3;
  -                                     g.setConstraints(passwordLabel, c);
  -                                     _main.add(passwordLabel);
  -                                     final JPasswordField passwordField = new 
JPasswordField(20);
  -                                     c.gridx = 2;
  -                                     c.gridy = 3;
  -                                     g.setConstraints(passwordField, c);
  -                                     _main.add(passwordField);
  -                                     JButton ok = new JButton("Ok");
  -                                     JButton cancel = new JButton("Cancel");
  -                                     ok.setPreferredSize(cancel.getPreferredSize());
  -                                     ok.addActionListener(
  -                                             new ActionListener()
  -                                             {
  -                                                     
/************************************************************
  -                                                      *  !ToDo (Method description)
  -                                                      *
  -                                                      *@param  ev  !ToDo (Parameter 
description)
  -                                                      
***********************************************************/
  -                                                     public void 
actionPerformed(ActionEvent ev)
  -                                                     {
  -                                                             manager.set(-1, 
nameField.getText(), usernameField.getText(), new String(passwordField.getPassword()));
  -                                                             
tableModel.fireTableDataChanged();
  -                                                             addDialog.dispose();
  -                                                     }
  -                                             });
  -                                     cancel.addActionListener(
  -                                             new ActionListener()
  -                                             {
  -                                                     
/************************************************************
  -                                                      *  !ToDo (Method description)
  -                                                      *
  -                                                      *@param  ev  !ToDo (Parameter 
description)
  -                                                      
***********************************************************/
  -                                                     public void 
actionPerformed(ActionEvent ev)
  -                                                     {
  -                                                             addDialog.dispose();
  -                                                     }
  -                                             });
  -                                     c.fill = c.NONE;
  -                                     c.anchor = c.EAST;
  -                                     c.gridx = 1;
  -                                     c.gridy = 4;
  -                                     g.setConstraints(ok, c);
  -                                     _main.add(ok);
  -                                     c.anchor = c.WEST;
  -                                     c.gridx = 2;
  -                                     c.gridy = 4;
  -                                     g.setConstraints(cancel, c);
  -                                     _main.add(cancel);
  -                                     addDialog.getContentPane().add(_main);
  -                                     addDialog.show();
  -                             }
  -                     });
  -             buttons.addButtonListener(buttons.EDIT_BUTTON,
  -                     new ActionListener()
  -                     {
  -                             
/************************************************************
  -                              *  !ToDo (Method description)
  -                              *
  -                              *@param  e  !ToDo (Parameter description)
  -                              
***********************************************************/
  -                             public void actionPerformed(ActionEvent e)
  +             if (action.equals("Delete"))
  +             {
  +                     if (tableModel.getRowCount() > 0)
  +                     {
  +                             // If a table cell is being edited, we must cancel the 
editing before 
  +                             // deleting the row
  +                             if (authTable.isEditing())
                                {
  -                                     final int row = authTable.getSelectedRow();
  -                                     if (row >= 0)
  -                                     {
  -                                             Authorization auth = manager.get(row);
  -                                             final JDialog addDialog = new 
JDialog();
  -                                             addDialog.setSize(300, 150);
  -
  -                                             JPanel _main = new JPanel();
  -                                             GridBagLayout g = new GridBagLayout();
  -
  -                                             _main.setLayout(g);
  -                                             GridBagConstraints c = new 
GridBagConstraints();
  -                                             c.fill = c.BOTH;
  -                                             c.gridwidth = 1;
  -                                             c.gridheight = 1;
  -                                             c.gridx = 1;
  -                                             c.gridy = 1;
  -                                             JLabel urlLabel = new JLabel("Base 
URL:");
  -                                             g.setConstraints(urlLabel, c);
  -
  -                                             _main.add(urlLabel);
  -                                             final JTextField nameField = new 
JTextField(auth.getURL(), 20);
  -                                             c.gridx = 2;
  -                                             c.gridy = 1;
  -                                             g.setConstraints(nameField, c);
  -                                             _main.add(nameField);
  -                                             JLabel usernameLabel = new 
JLabel(JMeterUtils.getResString("username")+":");
  -                                             c.gridx = 1;
  -                                             c.gridy = 2;
  -                                             g.setConstraints(usernameLabel, c);
  -                                             _main.add(usernameLabel);
  -                                             final JTextField usernameField = new 
JTextField(auth.getUser(), 20);
  -                                             c.gridx = 2;
  -                                             c.gridy = 2;
  -                                             g.setConstraints(usernameField, c);
  -                                             _main.add(usernameField);
  -                                             JLabel passwordLabel = new 
JLabel(JMeterUtils.getResString("password")+":");
  -                                             c.gridx = 1;
  -                                             c.gridy = 3;
  -                                             g.setConstraints(passwordLabel, c);
  -                                             _main.add(passwordLabel);
  -                                             final JPasswordField passwordField = 
new JPasswordField(auth.getPass(), 20);
  -                                             c.gridx = 2;
  -                                             c.gridy = 3;
  -                                             g.setConstraints(passwordField, c);
  -                                             _main.add(passwordField);
  -                                             JButton ok = new JButton("Ok");
  -                                             JButton cancel = new JButton("Cancel");
  -                                             
ok.setPreferredSize(cancel.getPreferredSize());
  -                                             ok.addActionListener(
  -                                                     new ActionListener()
  -                                                     {
  -                                                             
/************************************************************
  -                                                              *  !ToDo (Method 
description)
  -                                                              *
  -                                                              *@param  ev  !ToDo 
(Parameter description)
  -                                                              
***********************************************************/
  -                                                             public void 
actionPerformed(ActionEvent ev)
  -                                                             {
  -                                                                     
manager.set(row, nameField.getText(), usernameField.getText(), new 
String(passwordField.getPassword()));
  -                                                                     
tableModel.fireTableDataChanged();
  -                                                                     
addDialog.dispose();
  -                                                             }
  -                                                     });
  -                                             cancel.addActionListener(
  -                                                     new ActionListener()
  -                                                     {
  -                                                             
/************************************************************
  -                                                              *  !ToDo (Method 
description)
  -                                                              *
  -                                                              *@param  ev  !ToDo 
(Parameter description)
  -                                                              
***********************************************************/
  -                                                             public void 
actionPerformed(ActionEvent ev)
  -                                                             {
  -                                                                     
addDialog.dispose();
  -                                                             }
  -                                                     });
  -                                             c.fill = c.NONE;
  -                                             c.anchor = c.EAST;
  -                                             c.gridx = 1;
  -                                             c.gridy = 4;
  -                                             g.setConstraints(ok, c);
  -                                             _main.add(ok);
  -                                             c.anchor = c.WEST;
  -                                             c.gridx = 2;
  -                                             c.gridy = 4;
  -                                             g.setConstraints(cancel, c);
  -                                             _main.add(cancel);
  -                                             addDialog.getContentPane().add(_main);
  -                                             addDialog.show();
  -                                     }
  +                                     TableCellEditor cellEditor = 
authTable.getCellEditor(authTable.getEditingRow(), authTable.getEditingColumn());
  +                                     cellEditor.cancelCellEditing();
                                }
  -                     });
  -             buttons.addButtonListener(buttons.DELETE_BUTTON,
  -                     new ActionListener()
  -                     {
  -                             
/************************************************************
  -                              *  !ToDo (Method description)
  -                              *
  -                              *@param  e  !ToDo (Parameter description)
  -                              
***********************************************************/
  -                             public void actionPerformed(ActionEvent e)
  +
  +                             int rowSelected = authTable.getSelectedRow();
  +
  +                             if (rowSelected != -1)
                                {
  -                                     int row = authTable.getSelectedRow();
  -                                     if (row >= 0)
  +                                     tableModel.removeRow(rowSelected);
  +                                     tableModel.fireTableDataChanged();
  +
  +                                     // Disable the DELETE and SAVE buttons if no 
rows remaining after delete
  +                                     if (tableModel.getRowCount() == 0)
                                        {
  -                                             manager.remove(row);
  -                                             tableModel.fireTableDataChanged();
  +                                             deleteButton.setEnabled(false);
  +                                             saveButton.setEnabled(false);
                                        }
  -                             }
  -                     });
  -             buttons.addButtonListener(buttons.LOAD_BUTTON,
  -                     new ActionListener()
  -                     {
  -                             
/************************************************************
  -                              *  !ToDo (Method description)
  -                              *
  -                              *@param  e  !ToDo (Parameter description)
  -                              
***********************************************************/
  -                             public void actionPerformed(ActionEvent e)
  -                             {
  -                                     try
  +                             
  +                                     // Table still contains one or more rows, so 
highlight (select)
  +                                     // the appropriate one. 
  +                                     else
                                        {
  -                                             File tmp = 
FileDialoger.promptToOpenFile()
  -                                                             .getSelectedFile();
  -                                             if (tmp != null)
  +                                             int rowToSelect = rowSelected;
  +
  +                                             if (rowSelected >= 
tableModel.getRowCount())
                                                {
  -                                                     
manager.addFile(tmp.getAbsolutePath());
  -                                                     
tableModel.fireTableDataChanged();
  +                                                     rowToSelect = rowSelected - 1;
                                                }
  -                                     }
  -                                     catch (IOException ex)
  -                                     {
  -                                             
JOptionPane.showMessageDialog(null,ex.getMessage(),
  -                                     "Information", 
JOptionPane.INFORMATION_MESSAGE);
  +
  +                                             
authTable.setRowSelectionInterval(rowToSelect, rowToSelect);
                                        }
                                }
  -                     });
  -             buttons.addButtonListener(buttons.SAVE_BUTTON,
  -                     new ActionListener()
  -                     {
  -                             
/************************************************************
  -                              *  !ToDo (Method description)
  -                              *
  -                              *@param  e  !ToDo (Parameter description)
  -                              
***********************************************************/
  -                             public void actionPerformed(ActionEvent e)
  +                     }
  +             }
  +             else if(action.equals("Add"))
  +             {
  +                     // If a table cell is being edited, we should accept the 
current value
  +                     // and stop the editing before adding a new row.
  +                     if (authTable.isEditing())
  +                     {
  +                             TableCellEditor cellEditor = 
authTable.getCellEditor(authTable.getEditingRow(), authTable.getEditingColumn());
  +                             cellEditor.stopCellEditing();
  +                     }
  +
  +                     tableModel.addNewRow();
  +                     tableModel.fireTableDataChanged();
  +
  +                     // Enable the DELETE and SAVE buttons if they are currently 
disabled.
  +                     if (!deleteButton.isEnabled())
  +                     {
  +                             deleteButton.setEnabled(true);
  +                     }
  +                     if (!saveButton.isEnabled())
  +                     {
  +                             saveButton.setEnabled(true);
  +                     }
  +
  +                     // Highlight (select) the appropriate row.
  +                     int rowToSelect = tableModel.getRowCount() - 1;
  +                     authTable.setRowSelectionInterval(rowToSelect, rowToSelect);
  +             }
  +             else if (action.equals("Load"))
  +             {
  +                     try
  +                     {
  +                             File tmp = 
FileDialoger.promptToOpenFile().getSelectedFile();
  +                             if (tmp != null)
                                {
  -                                     try
  -                                     {
  -                                             File tmp = 
FileDialoger.promptToOpenFile()
  -                                                             .getSelectedFile();
  -                                             if (tmp != null)
  -                                             {
  -                                                     
manager.save(tmp.getAbsolutePath());
  -                                             }
  -                                     }
  -                                     catch (IOException ex)
  +                                     manager.addFile(tmp.getAbsolutePath());
  +                                     tableModel.fireTableDataChanged();
  +
  +                                     if (tableModel.getRowCount() > 0)
                                        {
  -                                             
JOptionPane.showMessageDialog(null,ex.getMessage(),
  -                                     "Information", 
JOptionPane.INFORMATION_MESSAGE);
  +                                             deleteButton.setEnabled(true);
  +                                             saveButton.setEnabled(true);
                                        }
  +                             }
  +                     }
  +                     catch (IOException ex)
  +                     {
  +                             ex.printStackTrace();
  +                     }
  +             }
  +             else if (action.equals("Save"))
  +             {
  +                     try
  +                     {
  +                             File tmp = 
FileDialoger.promptToSaveFile(null).getSelectedFile();
  +                             if (tmp != null)
  +                             {
  +                                     manager.save(tmp.getAbsolutePath());
                                }
  -                     });
  -             main.add(buttons, "South");
  -             this.add(main);
  +                     }
  +                     catch (IOException ex)
  +                     {
  +                             ex.printStackTrace();
  +                     }
  +             }
        }
   
  +     public JPanel createAuthTablePanel()
  +     {
  +             Border margin = new EmptyBorder(5, 10, 10, 10);
  +
  +             JPanel tempPanel = new JPanel();
  +             tempPanel.setLayout(new VerticalLayout(0, VerticalLayout.CENTER));
  +             tempPanel.setBorder(new 
CompoundBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), 
JMeterUtils.getResString("auths_stored")), margin));
  +
  +             // create the JTable that holds auth per row
  +             authTable = new JTable(tableModel);
  +             authTable.setCellSelectionEnabled(true);
  +             authTable.setRowSelectionAllowed(true);
  +             authTable.setColumnSelectionAllowed(false);
  +             authTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  +
  +             // create a JScrollPane and place the auth JTable inside it
  +             JScrollPane scroller = new JScrollPane(authTable);
  +             authTable.setPreferredScrollableViewportSize(new Dimension(520, 150));
  +             JTableHeader tableHeader = authTable.getTableHeader();
  +             scroller.setColumnHeaderView(tableHeader);
  +
  +             tempPanel.add(scroller);
  +
  +             // ADD button
  +             addButton = new JButton(JMeterUtils.getResString("add"));
  +             addButton.setMnemonic('A');
  +             addButton.setActionCommand("Add");
  +             addButton.addActionListener(this);
  +
  +             // DELETE button
  +             deleteButton = new JButton(JMeterUtils.getResString("delete"));
  +             deleteButton.setEnabled(false);  // disabled by default
  +             deleteButton.setMnemonic('D');
  +             deleteButton.setActionCommand("Delete");
  +             deleteButton.addActionListener(this);
  +
  +             // LOAD button
  +             loadButton = new JButton(JMeterUtils.getResString("load"));
  +             loadButton.setMnemonic('L');
  +             loadButton.setActionCommand("Load");
  +             loadButton.addActionListener(this);
  +
  +             // SAVE button
  +             saveButton = new JButton(JMeterUtils.getResString("save"));
  +             saveButton.setEnabled(false);  // disabled by default
  +             saveButton.setMnemonic('S');
  +             saveButton.setActionCommand("Save");
  +             saveButton.addActionListener(this);
  +
  +             // Button Panel
  +             JPanel buttonPanel = new JPanel();
  +             buttonPanel.add(addButton);
  +             buttonPanel.add(deleteButton);
  +             buttonPanel.add(loadButton);
  +             buttonPanel.add(saveButton);
  +
  +             tempPanel.add(Box.createRigidArea(new Dimension(0, 10)));
  +             tempPanel.add(buttonPanel);
  +
  +             return tempPanel;
  +     }
  +
        private class InnerTableModel extends AbstractTableModel
        {
                AuthManager manager;
  @@ -426,6 +338,27 @@
                        manager = man;
                }
   
  +             public void removeRow(int row)
  +             {
  +                     manager.remove(row);
  +             }
  +
  +             public void addNewRow()
  +             {
  +                     manager.addAuth();
  +             }
  +
  +             public boolean isCellEditable(int row, int column)
  +             {
  +                     // all table cells are editable
  +                     return true;
  +             }
  +
  +             public Class getColumnClass(int column) 
  +             {
  +                     return getValueAt(0, column).getClass();
  +             }
  +
                /************************************************************
                 *  required by table model interface
                 *
  @@ -460,17 +393,6 @@
                /************************************************************
                 *  required by table model interface
                 *
  -              *@param  column  !ToDo (Parameter description)
  -              *@return         !ToDo (Return description)
  -              ***********************************************************/
  -             public Class getColumnClass(int column)
  -             {
  -                     return manager.getColumnClass(column);
  -             }
  -
  -             /************************************************************
  -              *  required by table model interface
  -              *
                 *@param  row     !ToDo (Parameter description)
                 *@param  column  !ToDo (Parameter description)
                 *@return         !ToDo (Return description)
  @@ -478,6 +400,7 @@
                public Object getValueAt(int row, int column)
                {
                        Authorization auth = manager.getAuthObjectAt(row);
  +
                        if (column == 0)
                        {
                                return auth.getURL();
  @@ -491,6 +414,24 @@
                                return auth.getPass();
                        }
                        return null;
  +             }
  +
  +             public void setValueAt(Object value, int row, int column)
  +             {
  +                     Authorization auth = manager.getAuthObjectAt(row);
  +
  +                     if (column == 0)
  +                     {
  +                             auth.setURL((String)value);
  +                     }
  +                     else if (column == 1)
  +                     {
  +                             auth.setUser((String)value);
  +                     }
  +                     else if (column == 2)
  +                     {
  +                             auth.setPass((String)value);
  +                     }
                }
        }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to