Changeset 7280


Ignore:
Timestamp:
2004-05-05T13:44:48+12:00 (20 years ago)
Author:
kjdon
Message:

removed a heap of unnecessary crap - filename, email etc fields that are not used, BrowseListener for the old browse button (for base this coll on)

File:
1 edited

Legend:

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

    r7275 r7280  
    4747
    4848    static public boolean titleClashes(String title, File current_config_file) {
    49     // An empty collection title never clashes with anything. I may look ugly in the final collection but there is nothing wrong with having no title for a particular language.
     49    // An empty collection title never clashes with anything. It may look ugly in the final collection but there is nothing wrong with having no title for a particular language.
    5050    if(title == null || title.length() == 0) {
    5151        return false;
     
    7575    private JDialog self;
    7676    private JTextArea description;
    77     /* Suppress email
    78     private JTextField address;
    79     private JTextField host;
    80     */
    8177    private JTextField title;
    82     //private RestrictedTextField file;
    8378    private String description_final;
    84     // private String email_final; no more email
    85     // private String name_final;
    8679    private String title_final;
    8780    static private Dimension COMPONENT_SIZE = new Dimension(230, 25);
     
    142135    JLabel name_label = new JLabel();
    143136    Dictionary.setText(name_label, "NewCollectionPrompt.Collection_Name");
    144     //JPanel file_pane = new JPanel();
    145     //file = new RestrictedTextField(new RestrictedTextDocument(FILENAME_SIZE), "", FILENAME_SIZE);
    146     //Dictionary.setTooltip(file, "NewCollectionPrompt.Collection_Name_Tooltip");
    147     //JLabel file_label = new JLabel(".col");
    148         /* Suppress Email
    149     JPanel email_pane = new JPanel();
    150     JLabel email_label = new JLabel();
    151         Dictionary.setText(email_label, "NewCollectionPrompt.Collection_Email");
    152     JPanel host_pane = new JPanel();
    153     JPanel address_pane = new JPanel();
    154     address = new JTextField();
    155     Dictionary.setTooltip(address, "CDM.General.Email.Creator_Tooltip");
    156     JLabel at_label = new JLabel("@");
    157     host = new JTextField();
    158     Dictionary.setTooltip(host, "CDM.General.Email.Creator_Tooltip");
    159     */
    160137
    161138    JPanel center_pane = new JPanel();
     
    184161    cancel_button.setMnemonic(KeyEvent.VK_C);
    185162    Dictionary.setBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip");
    186 
    187     //ColorListener email_color_listener = new ColorListener(address, host); No more email
    188 
    189163    // Connection
    190164    cancel_button.addActionListener(new CancelListener());
    191165    create_button.addActionListener(new CreateListener());
    192     //address.addKeyListener(email_color_listener); suppress email
    193166    description.addKeyListener(new ColorListener(description));
    194167    description.addKeyListener(new DescriptionListener());
    195     //file.addKeyListener(new ColorListener(file));
    196     //host.addKeyListener(email_color_listener); suppress email
    197168    title.addKeyListener(new ColorListener(title));
    198     //title.getDocument().addDocumentListener(new TitleListener());
     169
    199170    // Layout
    200 
    201171    title_pane.setLayout(new BorderLayout(5,0));
    202172    title_pane.add(title_label, BorderLayout.WEST);
    203173    title_pane.add(title, BorderLayout.CENTER);
    204174
    205     /* suppress filename
    206     file_pane.setLayout(new BorderLayout());
    207     file_pane.add(file, BorderLayout.WEST);
    208     file_pane.add(file_label, BorderLayout.CENTER);
    209 
    210     name_pane.setLayout(new BorderLayout());
    211     name_pane.add(name_label, BorderLayout.WEST);
    212     name_pane.add(file_pane, BorderLayout.CENTER);
    213     */
    214 
    215     /* suppress email
    216 
    217     address_pane.setLayout(new BorderLayout());
    218     address_pane.add(address, BorderLayout.CENTER);
    219     address_pane.add(at_label, BorderLayout.EAST);
    220 
    221     host_pane.setLayout(new GridLayout(1,2));
    222     host_pane.add(address_pane);
    223     host_pane.add(host);
    224 
    225     email_pane.setLayout(new BorderLayout());
    226     email_pane.add(email_label, BorderLayout.WEST);
    227     email_pane.add(host_pane, BorderLayout.CENTER);
    228     */
    229 
    230175    upper_pane.setLayout(new GridLayout(2,1));
    231176    upper_pane.add(instructions_label);
    232177    upper_pane.add(title_pane);
    233     //upper_pane.add(name_pane);
    234     //upper_pane.add(email_pane); no email anymore
    235178
    236179    description_pane.setLayout(new BorderLayout());
     
    241184    base_collection_pane.add(base_collection_label, BorderLayout.WEST);
    242185    base_collection_pane.add(base_collection, BorderLayout.CENTER);
    243     // base_collection_pane.add(base_collection_browse, BorderLayout.EAST);
    244186
    245187    center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0));
     
    278220    return description_final;
    279221    }
    280 
    281     /* No more email
    282     public String getEmail() {
    283     return email_final;
    284     }
    285     */
    286 
     222 
    287223    /** 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.
    288224     * @return the filename as a String
    289225     */
    290     public String getName() {
    291         // Retrieve the first 8 non-whitespace characters of title_final.
    292         StringBuffer name_buffer = new StringBuffer("");
    293         int i = 0;
    294         while(i < title_final.length() && name_buffer.length() < 8) {
    295             char c = title_final.charAt(i);
    296             // Arg. We need a few more tests than just whitespace
    297             if(Character.isLetterOrDigit(c)) {
    298                 name_buffer.append(Character.toLowerCase(c));
    299             }
    300             i++;
    301         }
    302         // We need to ensure the filename is unique
    303         int counter = 0;
    304         StringBuffer new_name_buffer = new StringBuffer(name_buffer.toString());
    305         while(filenameClashes(new_name_buffer.toString())) {
    306             new_name_buffer = new StringBuffer(name_buffer.toString());
    307             counter++;
    308             String suffix = String.valueOf(counter);
    309             // If we have to truncate the namestring so as to fit the suffix
    310             if(suffix.length() + new_name_buffer.length() > 8) {
    311                 new_name_buffer.replace(new_name_buffer.length() - suffix.length(), new_name_buffer.length(), suffix);
    312             }
    313             // Or just append it if that isn't necessary
    314             else {
    315                 new_name_buffer.append(suffix);
    316             }
    317 
    318         }
    319         // All done
    320         return new_name_buffer.toString();
    321     }
    322 
     226    public String getName() {
     227    // Retrieve the first 8 non-whitespace characters of title_final.
     228    StringBuffer name_buffer = new StringBuffer("");
     229    int i = 0;
     230    while(i < title_final.length() && name_buffer.length() < 8) {
     231        char c = title_final.charAt(i);
     232        // Arg. We need a few more tests than just whitespace
     233        if(Character.isLetterOrDigit(c)) {
     234        name_buffer.append(Character.toLowerCase(c));
     235        }
     236        i++;
     237    }
     238    // We need to ensure the filename is unique
     239    int counter = 0;
     240    StringBuffer new_name_buffer = new StringBuffer(name_buffer.toString());
     241    while(filenameClashes(new_name_buffer.toString())) {
     242        new_name_buffer = new StringBuffer(name_buffer.toString());
     243        counter++;
     244        String suffix = String.valueOf(counter);
     245        // If we have to truncate the namestring so as to fit the suffix
     246        if(suffix.length() + new_name_buffer.length() > 8) {
     247        new_name_buffer.replace(new_name_buffer.length() - suffix.length(), new_name_buffer.length(), suffix);
     248        }
     249        // Or just append it if that isn't necessary
     250        else {
     251        new_name_buffer.append(suffix);
     252        }
     253       
     254    }
     255    // All done
     256    return new_name_buffer.toString();
     257    }
     258   
    323259    private boolean filenameClashes(String filename) {
    324260    File collection_directory = new File(Utility.getCollectDir(Gatherer.config.gsdl_path));
     
    335271    return title_final;
    336272    }
    337 
    338 
    339     private class BrowseListener
    340     implements ActionListener {
    341     public void actionPerformed(ActionEvent event) {
    342         File file;
    343         if(Gatherer.config.gsdl_path != null) {
    344         file = new File(Utility.getCollectDir(Gatherer.config.gsdl_path));
    345         }
    346         else {
    347         file = new File(Utility.BASE_DIR);
    348         }
    349         // Show OpenCollectionPrompt.
    350         OpenCollectionDialog chooser = new OpenCollectionDialog(file);
    351         file = chooser.getSelectedFile();
    352         if(file != null) {
    353         file = file.getParentFile();
    354         BasicCollectionConfiguration collect_cfg = new BasicCollectionConfiguration(new File(file, Utility.META_DIR));
    355         Item item = new Item(file, collect_cfg);
    356         base_collection.addItem(item);
    357         base_collection.setSelectedItem(item);
    358         collect_cfg = null;
    359         }
    360     }
    361     }
    362 
     273 
    363274    private class CancelListener
    364275    implements ActionListener {
     
    390301    }
    391302    }
    392 
     303   
    393304    private class CreateListener
    394305    implements ActionListener {
     
    413324        }
    414325        }
    415         /* Suppress filename
    416            name_final = file.getText();
    417            if(name_final.length() > 0) {
    418            // Determine if this filename is already in use.
    419            File collection_directory = new File(Utility.getCollectDir(Gatherer.config.gsdl_path));
    420            File children[] = collection_directory.listFiles();
    421            for(int i = 0; children != null && i < children.length; i++) {
    422            if(children[i].getName().equals(name_final)) {
    423            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
    424            file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    425            file.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    426            return;
    427            }
    428            }
    429            }
    430            else {
    431            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Name_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
    432            file.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    433            file.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    434            return;
    435            }
    436         */
    437         /* Suppress email
    438            email_final = address.getText() + "@" + host.getText();
    439            if(email_final.length() == 0 || email_final.startsWith("@") || email_final.endsWith("@")) {
    440            JOptionPane.showMessageDialog(Gatherer.g_man, Dictionary.get("NewCollectionPrompt.Email_Error"), Dictionary.get("NewCollectionPrompt.Error"), JOptionPane.ERROR_MESSAGE);
    441            address.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    442            address.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    443            host.setForeground(Gatherer.config.getColor("coloring.error_foreground", false));
    444            host.setBackground(Gatherer.config.getColor("coloring.error_background", false));
    445            return;
    446            }
    447         */
     326       
    448327        description_final = description.getText();
    449328        if(description_final.length() == 0) {
     
    499378    public String toString() {
    500379        if(name == null && config != null) {
    501         StringBuffer title_buffer = new StringBuffer(config.getName());
    502         title_buffer.append(StaticStrings.SPACE_CHARACTER);
    503         title_buffer.append(StaticStrings.OPEN_PARENTHESIS_CHARACTER);
    504         title_buffer.append(config.getShortName());
    505         title_buffer.append(StaticStrings.CLOSE_PARENTHESIS_CHARACTER);
    506         name = title_buffer.toString();
    507         title_buffer = null;
     380        name = config.toString();
    508381        }
    509382        return name;
    510383    }
    511384    }
    512 
    513     /*
    514     private class RestrictedTextField
    515     extends JTextField {
    516     public RestrictedTextField(RestrictedTextDocument document, String value, int cols) {
    517         super(document, "", cols);
    518     }
    519     protected Document createDefaultModel() {
    520         return new RestrictedTextDocument(11);
    521     }
    522     }
    523 
    524     private class RestrictedTextDocument
    525     extends PlainDocument {
    526     private char block[];
    527     private int cols;
    528     private int current;
    529     public RestrictedTextDocument(int cols) {
    530         super();
    531         this.cols = cols;
    532         this.current = 0;
    533     }
    534     public void blockChar(char c) {
    535         if(block == null) {
    536         block = new char[1];
    537         block[0] = c;
    538         }
    539         else {
    540         char temp[] = block;
    541         block = new char[temp.length + 1];
    542         System.arraycopy(temp, 0, block, 0, temp.length);
    543         block[temp.length] = c;
    544         temp = null;
    545         }
    546     }
    547     public void insertString(int offs, String str, AttributeSet a)
    548         throws BadLocationException {
    549         // Remove any blocked characters.
    550         StringBuffer temp = new StringBuffer(str);
    551         for(int i = 0; block != null && i < block.length; i++) {
    552         for(int j = temp.length() - 1; j >= 0; j--) {
    553             if(temp.charAt(j) == block[i]) {
    554             temp.deleteCharAt(j);
    555             }
    556         }
    557         }
    558         str = temp.toString();
    559         if(cols == -1 || str.length() + current <= cols) {
    560         super.insertString(offs, str, a);
    561         current = current + str.length();
    562         }
    563     }
    564     public void remove(int offs, int len)
    565         throws BadLocationException {
    566         super.remove(offs, len);
    567         current = current - len;
    568     }
    569     }
    570     */
    571 
    572     /* Suppress filename
    573     private class TitleListener
    574     implements DocumentListener {
    575     ** Gives notification that an attribute or set of attributes changed. *
    576     public void changedUpdate(DocumentEvent e) {
    577         updateFilename();
    578     }
    579 
    580     ** Gives notification that there was an insert into the document. *
    581     public void insertUpdate(DocumentEvent e) {
    582         updateFilename();
    583     }
    584 
    585     ** Gives notification that a portion of the document has been removed. *
    586     public void removeUpdate(DocumentEvent e) {
    587         updateFilename();
    588     }
    589 
    590     private void updateFilename() {
    591         String current_name = file.getText();
    592         String current_title = title.getText();
    593         StringBuffer temp = new StringBuffer("");
    594         int i = 0;
    595         while(i < current_title.length() && temp.length() < 8) {
    596         if(current_title.charAt(i) != ' ') {
    597             temp.append(Character.toLowerCase(current_title.charAt(i)));
    598         }
    599         i++;
    600         }
    601         String result = temp.toString();
    602         if(current_name.startsWith(result) || result.startsWith(current_name)) {
    603         file.setText(result);
    604         }
    605     }
    606     }
    607     */
    608385}
    609386
Note: See TracChangeset for help on using the changeset viewer.