Changeset 639 in tmcsimulator for trunk/src/tmcsim/client/cadclientgui/screens


Ignore:
Timestamp:
03/13/2021 01:06:51 PM (5 years ago)
Author:
jdalbey
Message:

Login.java modified to fix defect #254. LoginTest?.java unit test added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/tmcsim/client/cadclientgui/screens/Login.java

    r532 r639  
    5353    public Login(String studentNamesFile) 
    5454    { 
    55         readNamesFile(studentNamesFile); 
     55        students = readNamesFile(studentNamesFile); 
    5656        initView(); 
    5757    } 
     
    6262     * with the names of participants in that training.  
    6363     * @param studentNamesFile the full path to a text file of student names 
    64      * @author jdalbey  ticket #206 
     64     * @author jdalbey  ticket #206, #254 
    6565     */ 
    66     private void readNamesFile(String studentNamesFile) 
    67     { 
     66    public static Vector<String> readNamesFile(String studentNamesFile) 
     67    { 
     68        // Initialize the student name list 
     69        Vector<String> lines = new Vector<String>(); 
    6870        FileInputStream fis = null; 
    6971        try { 
     
    7577            // split string into an array 
    7678            String[] results = out.split("\\n"); 
    77             // Initialize the student name list 
    78             students = new Vector(); 
    79             // Make sure to truncate names before putting in list 
     79            // Put the names into a list (so it can be displayed in comboBox) 
    8080            for (String name: results) 
    8181            { 
    82                 String truncName = name.trim(); 
    83                 // Limit name length so it fits in the combo box 
    84                 if (truncName.length() > 26) 
     82                // Make sure to reverse name order before putting in list 
     83                String displayName = name.trim(); 
     84                // Ignore blank lines 
     85                if (displayName.length() > 0) 
    8586                { 
    86                     truncName = truncName.substring(0,25); 
     87                    // Limit name length so it fits in the combo box 
     88                    if (displayName.length() > 26) 
     89                    { 
     90                        displayName = displayName.substring(0,25); 
     91                    } 
     92                    // Add the validated name to the list of students 
     93                    lines.add(displayName); 
    8794                } 
    88                 // Add the validated name to the list of students 
    89                 students.add(truncName); 
    9095            } 
    91             // Append the default name  
    92             students.add("Anonymous Trainee"); 
    9396        } catch (FileNotFoundException ex) { 
    9497            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex); 
     
    100103            } 
    101104        } 
    102     } 
     105        return lines; 
     106    } 
     107     
     108    /** Reverse order of lastname, firstname to firstname lastname  
     109     * @param formattedname fullname with lastname first, separated by comma 
     110     * @return fullname with firstname first and no comma 
     111     *  Note, the result is what is desired for the CAD comment log entries. 
     112     *  If formattedname lacks a comma, just return it unchanged. 
     113     */ 
     114    public static String reverseLastFirst(String formattedname) 
     115    { 
     116        int commapos = formattedname.indexOf(","); 
     117        // Handle input name without comma - just return it 
     118        if (commapos < 0) return formattedname; 
     119        // switch the name order 
     120        String firstname = formattedname.substring(commapos+1).trim(); 
     121        String lastname = formattedname.substring(0,commapos).trim(); 
     122        return firstname + ' ' + lastname; 
     123    } 
     124     
    103125    private ActionListener newEnterActionListener() 
    104126    { 
     
    110132                // Extract the selected student name from the combo box 
    111133                String userEntry = (String) userNameCombo.getSelectedItem(); 
     134                userEntry = reverseLastFirst(userEntry); // switch name order 
    112135                ScreenManager.setUserName(userEntry); 
    113136                ScreenManager.openCADMenu(); 
     
    216239        JLabel passwordLabel = new JLabel("Password  "); 
    217240        passwordLabel.setForeground(Color.WHITE); 
    218         passwordField = new JTextField("Not required"); 
    219         passwordField.setEnabled(false); 
     241        passwordField = new JTextField(""); 
     242        passwordField.setEnabled(true); 
    220243        Box passwordBox = new Box(BoxLayout.X_AXIS); 
    221244        passwordBox.setAlignmentX(LEFT_ALIGNMENT); 
Note: See TracChangeset for help on using the changeset viewer.