Ignore:
Timestamp:
2003-05-27T15:40:47+12:00 (21 years ago)
Author:
mdewsnip
Message:

Fixed tabbing.

File:
1 edited

Legend:

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

    r4293 r4364  
    6666 */
    6767public class EmailAddress {
    68     /** The controls for editing this email. */
    69     private Control controls = null;
    70     /** A reference to the Gatherer. */
    71     private Gatherer gatherer = null;
    72     /** The type of this email, in collection configuration terms. */
    73     private int type = -1;
    74     /** The host part of the email (after @). */
    75     public String host = null;
    76     /** The user part of the email (before @). */
    77     public String user = null;
    78     /** The name given to or associated with this particular email (maybe the persons name, or it this email belongs to a certain variable i.e Collection Author). */
    79     public String name = null;
    80     /** Enumeration of important email address types - in this case the creator of a collection. */
    81     static final public int CREATOR = 0;
    82     /** Enumeration of important email address types - in this case the maintainer of a collection. */
    83     static final public int MAINTAINER = 1;
    84     /** Enumeration of important email address types - in this case any other email address other than the two noted above. */
    85     static final public int OTHER = 2;
    86     /** Constructor.
    87       * @param gatherer A reference to the <strong>Gatherer</strong> for messaging purposes.
    88       */
    89     public EmailAddress(Gatherer gatherer) {
    90           this.gatherer = gatherer;
    91     }
    92     /** Constructor.
    93       * @param gatherer A reference to the <strong>Gatherer</strong> for messaging purposes.
    94       * @param raw A <strong>String</strong> containing both the name and email separated by whitespace.
    95       */
    96     public EmailAddress(Gatherer gatherer, String raw) {
    97           this(gatherer);
    98           StringTokenizer tokenizer = new StringTokenizer(raw);
    99           if(tokenizer.countTokens() >= 2) {
    100                 this.name = tokenizer.nextToken();
    101                 if(name.equals("creator")) {
    102                      type = CREATOR;
    103                 }
    104                 else if(name.equals("maintainer")) {
    105                      type = MAINTAINER;
    106                 }
    107                 else {
    108                      type = OTHER;
    109                 }
    110                 String email = tokenizer.nextToken();
    111                 if(email.indexOf("@") != -1) {
    112                      this.user = email.substring(0, email.indexOf("@"));
    113                      this.host = email.substring(email.indexOf("@") + 1);
    114                 }
    115           }
    116           else {
    117                 this.name = "Invalid Email";
    118                 this.user = "";
    119                 this.host = "";
    120           }
    121     }
    122     /** Retrieve the controls associated with editing this email address.
    123       * @return A <strong>JPanel</strong> containing those controls.
    124       */
    125     public JPanel getControls() {
    126           if(controls == null) {
    127                 controls = new Control(name);
    128           }
    129           return controls;
    130     }
    131     /** Retrieve the controls associated with editing this email address, but ensure they have a certain title label.
    132       * @param label The <strong>String</strong> to use as the label.
    133       * @return A <strong>JPanel</strong> containing those controls.
    134       */
    135     public JPanel getControls(String label) {
    136           if(controls == null) {
    137                 controls = new Control(label);
    138           }
    139           return controls;
    140     }
    141     /** Method to produce this email as a string.
    142       * @return A <strong>String</string> representing this email.
    143       */
    144     public String toString() {
    145           return name + " " + user + "@" + host;
    146     }
    147     /** Determines if this is a valid email.
    148       * @return <i>true</i> if it is current valid, <i>false</i> otherwise.
    149       */
    150     public boolean isValid() {
    151           return (user != null && user.length() > 0) && (host != null && host.length() > 0);
    152     }
    153     /** Overloaded to call get with both a key and an empty argument array.
    154       * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
    155       * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
    156       */
    157     private String get(String key) {
    158           return get(key, null);
    159     }
    160     /** Used to retrieve a property value from the Locale specific ResourceBundle, based upon the key and arguments supplied. If the key cannot be found or if some other part of the call fails a default (English) error message is returned. <BR>
    161       * Here the get recieves a second argument which is an array of Strings used to populate argument fields, denoted {<I>n</I>}, within the value String returned. Note that argument numbers greater than or equal to 32 are automatically mapped to the formatting String named Farg<I>n</I>.
    162       * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
    163       * @param args A <strong>String[]</strong> used to populate argument fields within the complete String.
    164       * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatically populated with formatting Strings of with argument String provided in the get call.
    165       * @see org.greenstone.gatherer.Dictionary
    166       * @see org.greenstone.gatherer.Gatherer
    167       */
    168     private String get(String key, String args[]) {
    169           if(key.indexOf('.') == -1) {
    170                 key = "CDM.General.Email." + key;
    171           }
    172           return gatherer.dictionary.get(key, args);
    173     }
    174     /** The controls used for editing an email address. Basically two text fields with an '@' label in the middle. You also have a title label for this control, which is known for the major email address types, or can be supplied for any other purpose. */
    175     private class Control
    176           extends JPanel {
    177           /** The at symbol label. */
    178           private JLabel at = null;
    179           /** The title label. */
    180           private JLabel label = null;
    181           /** The first text field for the user part of an address. */
    182           private JTextField field1 = null;
    183           /** The second text field for the host part of an address. */
    184           private JTextField field2 = null;
    185           /** The panel on to which the text fields and the at label are placed. */
    186           private JPanel middle = null;
    187           /** Constructor.
    188             * @param name The <strong>String</strong> to use for the title label.
    189             * @see org.greenstone.gatherer.util.EmailAddress.Control.HostListener
    190             * @see org.greenstone.gatherer.util.EmailAddress.Control.UserListener
    191             */
    192           public Control(String name) {
    193                 super();
    194                 switch(type) {
    195                 case CREATOR:
    196                      label = new JLabel(get("Creator"));
    197                      break;
    198                 case MAINTAINER:
    199                      label = new JLabel(get("Maintainer"));
    200                      break;                 
    201                 default:
    202                      label = new JLabel(name);
    203                 }
    204                 middle = new JPanel();
    205                 field1 = new JTextField(user);
    206                 at = new JLabel("@");
    207                 field2 = new JTextField(host);
     68    /** The controls for editing this email. */
     69    private Control controls = null;
     70    /** A reference to the Gatherer. */
     71    private Gatherer gatherer = null;
     72    /** The type of this email, in collection configuration terms. */
     73    private int type = -1;
     74    /** The host part of the email (after @). */
     75    public String host = null;
     76    /** The user part of the email (before @). */
     77    public String user = null;
     78    /** The name given to or associated with this particular email (maybe the persons name, or it this email belongs to a certain variable i.e Collection Author). */
     79    public String name = null;
     80    /** Enumeration of important email address types - in this case the creator of a collection. */
     81    static final public int CREATOR = 0;
     82    /** Enumeration of important email address types - in this case the maintainer of a collection. */
     83    static final public int MAINTAINER = 1;
     84    /** Enumeration of important email address types - in this case any other email address other than the two noted above. */
     85    static final public int OTHER = 2;
     86    /** Constructor.
     87     * @param gatherer A reference to the <strong>Gatherer</strong> for messaging purposes.
     88     */
     89    public EmailAddress(Gatherer gatherer) {
     90    this.gatherer = gatherer;
     91    }
     92    /** Constructor.
     93     * @param gatherer A reference to the <strong>Gatherer</strong> for messaging purposes.
     94     * @param raw A <strong>String</strong> containing both the name and email separated by whitespace.
     95     */
     96    public EmailAddress(Gatherer gatherer, String raw) {
     97    this(gatherer);
     98    StringTokenizer tokenizer = new StringTokenizer(raw);
     99    if(tokenizer.countTokens() >= 2) {
     100        this.name = tokenizer.nextToken();
     101        if(name.equals("creator")) {
     102        type = CREATOR;
     103        }
     104        else if(name.equals("maintainer")) {
     105        type = MAINTAINER;
     106        }
     107        else {
     108        type = OTHER;
     109        }
     110        String email = tokenizer.nextToken();
     111        if(email.indexOf("@") != -1) {
     112        this.user = email.substring(0, email.indexOf("@"));
     113        this.host = email.substring(email.indexOf("@") + 1);
     114        }
     115    }
     116    else {
     117        this.name = "Invalid Email";
     118        this.user = "";
     119        this.host = "";
     120    }
     121    }
     122    /** Retrieve the controls associated with editing this email address.
     123     * @return A <strong>JPanel</strong> containing those controls.
     124     */
     125    public JPanel getControls() {
     126    if(controls == null) {
     127        controls = new Control(name);
     128    }
     129    return controls;
     130    }
     131    /** Retrieve the controls associated with editing this email address, but ensure they have a certain title label.
     132     * @param label The <strong>String</strong> to use as the label.
     133     * @return A <strong>JPanel</strong> containing those controls.
     134     */
     135    public JPanel getControls(String label) {
     136    if(controls == null) {
     137        controls = new Control(label);
     138    }
     139    return controls;
     140    }
     141    /** Method to produce this email as a string.
     142     * @return A <strong>String</string> representing this email.
     143     */
     144    public String toString() {
     145    return name + " " + user + "@" + host;
     146    }
     147    /** Determines if this is a valid email.
     148     * @return <i>true</i> if it is current valid, <i>false</i> otherwise.
     149     */
     150    public boolean isValid() {
     151    return (user != null && user.length() > 0) && (host != null && host.length() > 0);
     152    }
     153    /** Overloaded to call get with both a key and an empty argument array.
     154     * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
     155     * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatiically populated with formatting Strings of with argument String provided in the get call.
     156     */
     157    private String get(String key) {
     158    return get(key, null);
     159    }
     160    /** Used to retrieve a property value from the Locale specific ResourceBundle, based upon the key and arguments supplied. If the key cannot be found or if some other part of the call fails a default (English) error message is returned. <BR>
     161     * Here the get recieves a second argument which is an array of Strings used to populate argument fields, denoted {<I>n</I>}, within the value String returned. Note that argument numbers greater than or equal to 32 are automatically mapped to the formatting String named Farg<I>n</I>.
     162     * @param key A <strong>String</strong> which is mapped to a initial String within the ResourceBundle.
     163     * @param args A <strong>String[]</strong> used to populate argument fields within the complete String.
     164     * @return A <strong>String</strong> which has been referenced by the key String and that either contains no argument fields, or has had the argument fields automatically populated with formatting Strings of with argument String provided in the get call.
     165     * @see org.greenstone.gatherer.Dictionary
     166     * @see org.greenstone.gatherer.Gatherer
     167     */
     168    private String get(String key, String args[]) {
     169    if(key.indexOf('.') == -1) {
     170        key = "CDM.General.Email." + key;
     171    }
     172    return gatherer.dictionary.get(key, args);
     173    }
     174    /** The controls used for editing an email address. Basically two text fields with an '@' label in the middle. You also have a title label for this control, which is known for the major email address types, or can be supplied for any other purpose. */
     175    private class Control
     176    extends JPanel {
     177    /** The at symbol label. */
     178    private JLabel at = null;
     179    /** The title label. */
     180    private JLabel label = null;
     181    /** The first text field for the user part of an address. */
     182    private JTextField field1 = null;
     183    /** The second text field for the host part of an address. */
     184    private JTextField field2 = null;
     185    /** The panel on to which the text fields and the at label are placed. */
     186    private JPanel middle = null;
     187    /** Constructor.
     188     * @param name The <strong>String</strong> to use for the title label.
     189     * @see org.greenstone.gatherer.util.EmailAddress.Control.HostListener
     190     * @see org.greenstone.gatherer.util.EmailAddress.Control.UserListener
     191     */
     192    public Control(String name) {
     193        super();
     194        switch(type) {
     195        case CREATOR:
     196        label = new JLabel(get("Creator"));
     197        break;
     198        case MAINTAINER:
     199        label = new JLabel(get("Maintainer"));
     200        break;                   
     201        default:
     202        label = new JLabel(name);
     203        }
     204        middle = new JPanel();
     205        field1 = new JTextField(user);
     206        at = new JLabel("@");
     207        field2 = new JTextField(host);
    208208                // Add listeners
    209                 field1.addKeyListener(new UserListener());
    210                 field2.addKeyListener(new HostListener());
     209        field1.addKeyListener(new UserListener());
     210        field2.addKeyListener(new HostListener());
    211211                // Layout
    212                 label.setBorder(BorderFactory.createEmptyBorder(2,5,2,10));
    213 
    214                 at.setBorder(BorderFactory.createEmptyBorder(2,5,2,5));
    215 
    216                 middle.setLayout(new BorderLayout());
    217                 middle.add(field1, BorderLayout.CENTER);
    218                 middle.add(at, BorderLayout.EAST);
    219 
    220                 setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    221                 setLayout(new GridLayout(1,3));
    222                 add(label);
    223                 add(middle);
    224                 add(field2);
    225           }
    226           /** Listens for changes of the host part of the email address and updates the email object accordingly. */     
    227           private class HostListener
    228                 extends KeyAdapter {
     212        label.setBorder(BorderFactory.createEmptyBorder(2,5,2,10));
     213
     214        at.setBorder(BorderFactory.createEmptyBorder(2,5,2,5));
     215
     216        middle.setLayout(new BorderLayout());
     217        middle.add(field1, BorderLayout.CENTER);
     218        middle.add(at, BorderLayout.EAST);
     219
     220        setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
     221        setLayout(new GridLayout(1,3));
     222        add(label);
     223        add(middle);
     224        add(field2);
     225    }
     226    /** Listens for changes of the host part of the email address and updates the email object accordingly. */   
     227    private class HostListener
     228        extends KeyAdapter {
    229229                /** Whenever a key is released (ie after a key typed event has been fired) when typing in the host field, this method updates the host field of the email object.
    230230                 * @param event A <strong>KeyEvent</strong> containing extra information about the key release performed.
    231231                 */
    232                 public void keyReleased(KeyEvent event) {
    233                      host = field2.getText();
    234                 }
    235           }
    236           /** Listens for changes of the user part of the email address and updates the email object accordingly. */
    237           private class UserListener
    238                 extends KeyAdapter {
     232        public void keyReleased(KeyEvent event) {
     233        host = field2.getText();
     234        }
     235    }
     236    /** Listens for changes of the user part of the email address and updates the email object accordingly. */
     237    private class UserListener
     238        extends KeyAdapter {
    239239                /** Whenever a key is released (ie after a key typed event has been fired) when typing in the user field, this method updates the user field of the email object.
    240240                 * @param event A <strong>KeyEvent</strong> containing extra information about the key release performed.
    241241                 */
    242                 public void keyReleased(KeyEvent event) {
    243                      user = field1.getText();
    244                 }
    245           }
     242        public void keyReleased(KeyEvent event) {
     243        user = field1.getText();
     244        }
     245    }
    246246         
    247     }
     247    }
    248248}
    249 
    250 
    251 
    252 
    253 
Note: See TracChangeset for help on using the changeset viewer.