Changeset 6041


Ignore:
Timestamp:
2003-11-28T17:48:22+13:00 (20 years ago)
Author:
jmt12
Message:

Email field is gone, as is short filename. Sais filename is now automatically created

File:
1 edited

Legend:

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

    r5716 r6041  
    2323    private JDialog self;
    2424    private JTextArea description;
     25    /* Suppress email
    2526    private JTextField address;
    2627    private JTextField host;
     28    */
    2729    private JTextField title;
    28     private RestrictedTextField file;
     30    //private RestrictedTextField file;
    2931    private String description_final;
    30     private String email_final;
    31     private String name_final;
     32    // private String email_final; no more email
     33    // private String name_final;
    3234    private String title_final;
    3335    static private Dimension label_size = new Dimension(230, 25);
    3436    /** The size of this new collection dialog box. */
    35     static private Dimension size = new Dimension(700, 375);
     37    static private Dimension size = new Dimension(600, 280);
    3638    static private int FILENAME_SIZE = 8;
    3739
     
    9193    JLabel name_label = new JLabel();
    9294    Dictionary.setText(name_label, "NewCollectionPrompt.Collection_Name");
    93     JPanel file_pane = new JPanel();
    94     file = new RestrictedTextField(new RestrictedTextDocument(FILENAME_SIZE), "", FILENAME_SIZE);
    95     Dictionary.setTooltip(file, "NewCollectionPrompt.Collection_Name_Tooltip");
    96     JLabel file_label = new JLabel(".col");
     95    //JPanel file_pane = new JPanel();
     96    //file = new RestrictedTextField(new RestrictedTextDocument(FILENAME_SIZE), "", FILENAME_SIZE);
     97    //Dictionary.setTooltip(file, "NewCollectionPrompt.Collection_Name_Tooltip");
     98    //JLabel file_label = new JLabel(".col");
     99        /* Suppress Email
    97100    JPanel email_pane = new JPanel();
    98101    JLabel email_label = new JLabel();
    99     Dictionary.setText(email_label, "NewCollectionPrompt.Collection_Email");
     102        Dictionary.setText(email_label, "NewCollectionPrompt.Collection_Email");
    100103    JPanel host_pane = new JPanel();
    101104    JPanel address_pane = new JPanel();
     
    105108    host = new JTextField();
    106109    Dictionary.setTooltip(host, "CDM.General.Email.Creator_Tooltip");
     110    */
    107111
    108112    JPanel center_pane = new JPanel();
     
    131135    cancel_button.setMnemonic(KeyEvent.VK_C);
    132136    Dictionary.setBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
    133     ColorListener email_color_listener = new ColorListener(address, host);
     137   
     138    //ColorListener email_color_listener = new ColorListener(address, host); No more email
    134139
    135140    // Connection
    136141    cancel_button.addActionListener(new CancelListener());
    137142    create_button.addActionListener(new CreateListener());
    138     address.addKeyListener(email_color_listener);
     143    //address.addKeyListener(email_color_listener); suppress email
    139144    description.addKeyListener(new ColorListener(description));
    140145    description.addKeyListener(new DescriptionListener());
    141     file.addKeyListener(new ColorListener(file));
    142     host.addKeyListener(email_color_listener);
     146    //file.addKeyListener(new ColorListener(file));
     147    //host.addKeyListener(email_color_listener); suppress email
    143148    title.addKeyListener(new ColorListener(title));
    144     title.getDocument().addDocumentListener(new TitleListener());
     149    //title.getDocument().addDocumentListener(new TitleListener());
    145150    // Layout
    146151    title_label.setPreferredSize(label_size);
     
    150155    title_pane.add(title, BorderLayout.CENTER);
    151156
     157    /* suppress filename
    152158    file_pane.setLayout(new BorderLayout());
    153159    file_pane.add(file, BorderLayout.WEST);
     
    159165    name_pane.add(name_label, BorderLayout.WEST);
    160166    name_pane.add(file_pane, BorderLayout.CENTER);
    161 
     167    */
     168
     169    /* suppress email
    162170    email_label.setPreferredSize(label_size);
    163171
     
    173181    email_pane.add(email_label, BorderLayout.WEST);
    174182    email_pane.add(host_pane, BorderLayout.CENTER);
    175 
    176     upper_pane.setLayout(new GridLayout(4,1));
     183    */
     184
     185    upper_pane.setLayout(new GridLayout(2,1));
    177186    upper_pane.add(instructions_label);
    178187    upper_pane.add(title_pane);
    179     upper_pane.add(name_pane);
    180     upper_pane.add(email_pane);
     188    //upper_pane.add(name_pane);
     189    //upper_pane.add(email_pane); no email anymore
    181190
    182191    description_pane.setLayout(new BorderLayout());
     
    227236    }
    228237
     238    /* No more email
    229239    public String getEmail() {
    230240    return email_final;
    231241    }
    232 
     242    */
     243
     244    /** Generates the collection short filename by taking the first eight characters of the title (spaces removed) and then adjusting by further truncating and then adding an unique suffix as necessary.
     245     * @return the filename as a String
     246     */
    233247    public String getName() {
    234     return name_final;
     248    // Retrieve the first 8 non-whitespace characters of title_final.
     249    StringBuffer name_buffer = new StringBuffer("");
     250    int i = 0;
     251    while(i < title_final.length() && name_buffer.length() < 8) {
     252        char c = title_final.charAt(i);
     253        if(!Character.isWhitespace(c)) {
     254        name_buffer.append(Character.toLowerCase(c));
     255        }
     256        i++;
     257    }
     258    // We need to ensure the filename is unique
     259    int counter = 0;
     260    while(filenameClashes(name_buffer.toString())) {
     261        counter++;
     262        String suffix = String.valueOf(counter);
     263        name_buffer.replace(name_buffer.length() - suffix.length(), name_buffer.length(), suffix);
     264    }
     265    // All done
     266    return name_buffer.toString();
     267    }
     268
     269    private boolean filenameClashes(String filename) {
     270    File collection_directory = new File(Utility.getCollectionDir(Gatherer.config.gsdl_path));
     271    File children[] = collection_directory.listFiles();
     272    for(int i = 0; children != null && i < children.length; i++) {
     273        if(children[i].getName().equals(filename)) {
     274        return true;
     275        }
     276    }
     277    return false;
    235278    }
    236279
     
    304347        return;
    305348        }
     349        // We must ensure that the collection title is unique. This is a pain in the nether regions as we are forced to load the collect.cfg of each other collection in turn looking for a conflicting title
     350        else {
     351
     352
     353        }
     354        /* Suppress filename
    306355        name_final = file.getText();
    307356        if(name_final.length() > 0) {
     
    324373        return;
    325374        }
     375        */
     376        /* Suppress email
    326377        email_final = address.getText() + "@" + host.getText();
    327378        if(email_final.length() == 0 || email_final.startsWith("@") || email_final.endsWith("@")) {
     
    333384        return;
    334385        }
     386        */
    335387        description_final = description.getText();
    336388        if(description_final.length() == 0) {
     
    382434    }
    383435
     436    /*
    384437    private class RestrictedTextField
    385438    extends JTextField {
     
    438491    }
    439492    }
    440 
     493    */
     494
     495    /* Suppress filename
    441496    private class TitleListener
    442497    implements DocumentListener {
    443     /** Gives notification that an attribute or set of attributes changed. */
     498    ** Gives notification that an attribute or set of attributes changed. *
    444499    public void changedUpdate(DocumentEvent e) {
    445500        updateFilename();
    446501    }
    447502
    448     /** Gives notification that there was an insert into the document. */
     503    ** Gives notification that there was an insert into the document. *
    449504    public void insertUpdate(DocumentEvent e) {
    450505        updateFilename();
    451506    }
    452507         
    453     /** Gives notification that a portion of the document has been removed. */
     508    ** Gives notification that a portion of the document has been removed. *
    454509    public void removeUpdate(DocumentEvent e) {
    455510        updateFilename();
     
    473528    }
    474529    }
     530    */
    475531}
     532
     533
     534
Note: See TracChangeset for help on using the changeset viewer.