Ignore:
Timestamp:
2003-05-27T15:34:50+12:00 (21 years ago)
Author:
kjdon
Message:

re-tabbed the code for java

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/GAuthenticator.java

    r4293 r4363  
    5555import javax.swing.JPasswordField;
    5656/** Provides a graphic authenticator for network password requests.
    57 * @author John Thompson, Greenstone Digital Library, University of Waikato
    58 * @version 2.3
    59 */
     57 * @author John Thompson, Greenstone Digital Library, University of Waikato
     58 * @version 2.3
     59 */
    6060public class GAuthenticator
    61     extends Authenticator {
    62     /** Indicates if this authentication prompt been cancelled, and if so rolls-back authentication. */
    63     private boolean authentication_cancelled = false;
    64     /** The button used to cancel a prompt. */
    65     private JButton cancel_button = null;
    66     /** The button used to submit the login/password. */
    67     private JButton ok_button = null;
    68     /** A reference to the dialog prompt created so inner classes can dispose of it. */
    69     private JDialog dialog = null;
    70     /** The password is a special starred out password field. */
    71     private JPasswordField password = null;
    72     /** The default size of this dialog. */
    73     static final private Dimension SIZE = new Dimension(410,130);
    74     /** Constructor. */
    75     public GAuthenticator() {
    76     }
    77     /** Prompt the user for authentication using a pretty dialog box.
     61    extends Authenticator {
     62    /** Indicates if this authentication prompt been cancelled, and if so rolls-back authentication. */
     63    private boolean authentication_cancelled = false;
     64    /** The button used to cancel a prompt. */
     65    private JButton cancel_button = null;
     66    /** The button used to submit the login/password. */
     67    private JButton ok_button = null;
     68    /** A reference to the dialog prompt created so inner classes can dispose of it. */
     69    private JDialog dialog = null;
     70    /** The password is a special starred out password field. */
     71    private JPasswordField password = null;
     72    /** The default size of this dialog. */
     73    static final private Dimension SIZE = new Dimension(410,130);
     74    /** Constructor. */
     75    public GAuthenticator() {
     76    }
     77    /** Prompt the user for authentication using a pretty dialog box.
    7878      * @return A <strong>PasswordAuthentication</strong> object containing the login and password valuees the user has submitted.
    7979      * @see org.greenstone.gatherer.GAuthenticator.AuthenticationActionListener
    8080      * @see org.greenstone.gatherer.GAuthenticator.RequestFocusListener
    8181      */
    82     protected PasswordAuthentication getPasswordAuthentication() {
    83           // Component definition.
    84           dialog = new JDialog (Gatherer.g_man, get("Title"), true);
    85           dialog.setModal(true);
    86           dialog.setSize(SIZE);
    87           JPanel content_pane = (JPanel)dialog.getContentPane();
    88           JLabel title_label = new JLabel(getRequestingPrompt());
    89           JPanel user_panel = new JPanel();
    90           JLabel username_label = new JLabel(get("Username"));
    91           JTextField username = new JTextField();
    92           JPanel password_panel = new JPanel();
    93           JLabel password_label = new JLabel(get("Password"));
    94           password = new JPasswordField();
    95           password.setEchoChar ('*');
    96           JPanel button_panel = new JPanel();
    97           ok_button = new JButton(get("General.OK"));
    98           cancel_button = new JButton(get("General.Cancel"));
    99           // Connect listeners.
    100           cancel_button.addActionListener(new AuthenticationActionListener(true));
    101           ok_button.addActionListener(new AuthenticationActionListener(false));
    102           password.addActionListener(new AuthenticationActionListener(false));
    103           username.addActionListener(new RequestFocusListener(password));
    104           // Layout the components.
    105           user_panel.setLayout(new GridLayout(1,2));
    106           user_panel.add(username_label);
    107           user_panel.add(username);
     82    protected PasswordAuthentication getPasswordAuthentication() {
     83    // Component definition.
     84    dialog = new JDialog (Gatherer.g_man, get("Title"), true);
     85    dialog.setModal(true);
     86    dialog.setSize(SIZE);
     87    JPanel content_pane = (JPanel)dialog.getContentPane();
     88    JLabel title_label = new JLabel(getRequestingPrompt());
     89    JPanel user_panel = new JPanel();
     90    JLabel username_label = new JLabel(get("Username"));
     91    JTextField username = new JTextField();
     92    JPanel password_panel = new JPanel();
     93    JLabel password_label = new JLabel(get("Password"));
     94    password = new JPasswordField();
     95    password.setEchoChar ('*');
     96    JPanel button_panel = new JPanel();
     97    ok_button = new JButton(get("General.OK"));
     98    cancel_button = new JButton(get("General.Cancel"));
     99    // Connect listeners.
     100    cancel_button.addActionListener(new AuthenticationActionListener(true));
     101    ok_button.addActionListener(new AuthenticationActionListener(false));
     102    password.addActionListener(new AuthenticationActionListener(false));
     103    username.addActionListener(new RequestFocusListener(password));
     104    // Layout the components.
     105    user_panel.setLayout(new GridLayout(1,2));
     106    user_panel.add(username_label);
     107    user_panel.add(username);
    108108
    109           password_panel.setLayout(new GridLayout(1,2));
    110           password_panel.add(password_label);
    111           password_panel.add(password);
     109    password_panel.setLayout(new GridLayout(1,2));
     110    password_panel.add(password_label);
     111    password_panel.add(password);
    112112
    113           button_panel.setLayout(new GridLayout(1,2));
    114           button_panel.add(ok_button);
    115           button_panel.add(cancel_button);
     113    button_panel.setLayout(new GridLayout(1,2));
     114    button_panel.add(ok_button);
     115    button_panel.add(cancel_button);
    116116
    117           content_pane.setLayout(new GridLayout(4,1));
    118           content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    119           content_pane.add(title_label);
    120           content_pane.add(user_panel);
    121           content_pane.add(password_panel);
    122           content_pane.add(button_panel);
    123           // Position the window.
    124           Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
    125           dialog.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
    126           dialog.show();
    127           if(!authentication_cancelled) {
    128                 return new PasswordAuthentication(username.getText(), password.getPassword());
    129           } else {
    130                 return null;
    131           }
    132     }
     117    content_pane.setLayout(new GridLayout(4,1));
     118    content_pane.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     119    content_pane.add(title_label);
     120    content_pane.add(user_panel);
     121    content_pane.add(password_panel);
     122    content_pane.add(button_panel);
     123    // Position the window.
     124    Dimension screen_size = Toolkit.getDefaultToolkit().getScreenSize();
     125    dialog.setLocation((screen_size.width - SIZE.width) / 2, (screen_size.height - SIZE.height) / 2);
     126    dialog.show();
     127    if(!authentication_cancelled) {
     128        return new PasswordAuthentication(username.getText(), password.getPassword());
     129    } else {
     130        return null;
     131    }
     132    }
    133133
    134     /** Retrieve a phrase from the dictionary.
     134    /** Retrieve a phrase from the dictionary.
    135135      * @param key A <strong>String</strong> used to determine what phrase to retrieve.
    136136      * @return The required phrase as a <strong>String</strong>, or at least some meaningful error message.
     
    138138      * @see org.greenstone.gatherer.Gatherer
    139139      */
    140     private String get(String key) {
    141           if(key.indexOf(".") == -1) {
    142                 key = "GAuthenticator." + key;
    143           }
    144           return Gatherer.dictionary.get(key);
    145     }
    146     /** Detects actions upon any control that attempt to submit the current details for authentication. */
    147     private class AuthenticationActionListener
    148           implements ActionListener {
    149           /** <i>true</i> if this authentication action cancels the authentication, <i>false</i> otherwise. */
    150           private boolean cancel_action = false;
    151           /** Constructor.
    152             * @param cancel_action <i>true</i> if this authentication action cancels the authentication, <i>false</i> otherwise.
     140    private String get(String key) {
     141    if(key.indexOf(".") == -1) {
     142        key = "GAuthenticator." + key;
     143    }
     144    return Gatherer.dictionary.get(key);
     145    }
     146    /** Detects actions upon any control that attempt to submit the current details for authentication. */
     147    private class AuthenticationActionListener
     148    implements ActionListener {
     149    /** <i>true</i> if this authentication action cancels the authentication, <i>false</i> otherwise. */
     150    private boolean cancel_action = false;
     151    /** Constructor.
     152     * @param cancel_action <i>true</i> if this authentication action cancels the authentication, <i>false</i> otherwise.
    153153            */
    154           public AuthenticationActionListener(boolean cancel_action) {
    155                 this.cancel_action = cancel_action;
    156           }
    157           /** Any implementation of an ActionListener must include this method so that we can be informed when an action has been performed on our registered controls, allowing us to dispose of the authentication dialog after determining if this is a submit action or a cancel one.
     154    public AuthenticationActionListener(boolean cancel_action) {
     155        this.cancel_action = cancel_action;
     156    }
     157    /** Any implementation of an ActionListener must include this method so that we can be informed when an action has been performed on our registered controls, allowing us to dispose of the authentication dialog after determining if this is a submit action or a cancel one.
    158158            * @param event An <strong>ActionEvent</strong> with information about the event that fired this method.
    159159            */
    160           public void actionPerformed(ActionEvent event) {
    161                 authentication_cancelled = cancel_action;
    162                 dialog.dispose();
    163           }
    164     }
    165     /** This listener detects actions on registered controls, and when they occur ensures the focus is moved to some targetted component. */
    166     private class RequestFocusListener
    167           implements ActionListener {
    168           /*The <strong>Component</strong> you wish to gain focus when an action is performed on a registered control. */
    169           private Component target = null;
    170           /** Constructor.
    171             * @param target The <strong>Component</strong> you wish to gain focus when an action is performed on a registered control.
     160    public void actionPerformed(ActionEvent event) {
     161        authentication_cancelled = cancel_action;
     162        dialog.dispose();
     163    }
     164    }
     165    /** This listener detects actions on registered controls, and when they occur ensures the focus is moved to some targetted component. */
     166    private class RequestFocusListener
     167    implements ActionListener {
     168    /*The <strong>Component</strong> you wish to gain focus when an action is performed on a registered control. */
     169    private Component target = null;
     170    /** Constructor.
     171     * @param target The <strong>Component</strong> you wish to gain focus when an action is performed on a registered control.
    172172            */
    173           public RequestFocusListener(Component target) {
    174                 this.target = target;
    175           }
    176           /** Any implementation of an ActionListener must include this method so that we can be informed when an action has been performed on our registered controls, allowing us to request focus in the target control.
     173    public RequestFocusListener(Component target) {
     174        this.target = target;
     175    }
     176    /** Any implementation of an ActionListener must include this method so that we can be informed when an action has been performed on our registered controls, allowing us to request focus in the target control.
    177177            * @param event An <strong>ActionEvent</strong> with information about the event that fired this method.
    178178            */
    179           public void actionPerformed(ActionEvent event) {
    180                 target.requestFocus();
    181           }
    182     }
     179    public void actionPerformed(ActionEvent event) {
     180        target.requestFocus();
     181    }
     182    }
    183183}
    184184
Note: See TracChangeset for help on using the changeset viewer.