- Timestamp:
- 2004-05-05T13:44:48+12:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/gui/NewCollectionDetailsPrompt.java
r7275 r7280 47 47 48 48 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. 50 50 if(title == null || title.length() == 0) { 51 51 return false; … … 75 75 private JDialog self; 76 76 private JTextArea description; 77 /* Suppress email78 private JTextField address;79 private JTextField host;80 */81 77 private JTextField title; 82 //private RestrictedTextField file;83 78 private String description_final; 84 // private String email_final; no more email85 // private String name_final;86 79 private String title_final; 87 80 static private Dimension COMPONENT_SIZE = new Dimension(230, 25); … … 142 135 JLabel name_label = new JLabel(); 143 136 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 Email149 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 */160 137 161 138 JPanel center_pane = new JPanel(); … … 184 161 cancel_button.setMnemonic(KeyEvent.VK_C); 185 162 Dictionary.setBoth(cancel_button, "General.Cancel", "General.Cancel_Tooltip"); 186 187 //ColorListener email_color_listener = new ColorListener(address, host); No more email188 189 163 // Connection 190 164 cancel_button.addActionListener(new CancelListener()); 191 165 create_button.addActionListener(new CreateListener()); 192 //address.addKeyListener(email_color_listener); suppress email193 166 description.addKeyListener(new ColorListener(description)); 194 167 description.addKeyListener(new DescriptionListener()); 195 //file.addKeyListener(new ColorListener(file));196 //host.addKeyListener(email_color_listener); suppress email197 168 title.addKeyListener(new ColorListener(title)); 198 //title.getDocument().addDocumentListener(new TitleListener()); 169 199 170 // Layout 200 201 171 title_pane.setLayout(new BorderLayout(5,0)); 202 172 title_pane.add(title_label, BorderLayout.WEST); 203 173 title_pane.add(title, BorderLayout.CENTER); 204 174 205 /* suppress filename206 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 email216 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 230 175 upper_pane.setLayout(new GridLayout(2,1)); 231 176 upper_pane.add(instructions_label); 232 177 upper_pane.add(title_pane); 233 //upper_pane.add(name_pane);234 //upper_pane.add(email_pane); no email anymore235 178 236 179 description_pane.setLayout(new BorderLayout()); … … 241 184 base_collection_pane.add(base_collection_label, BorderLayout.WEST); 242 185 base_collection_pane.add(base_collection, BorderLayout.CENTER); 243 // base_collection_pane.add(base_collection_browse, BorderLayout.EAST);244 186 245 187 center_pane.setBorder(BorderFactory.createEmptyBorder(5,0,5,0)); … … 278 220 return description_final; 279 221 } 280 281 /* No more email 282 public String getEmail() { 283 return email_final; 284 } 285 */ 286 222 287 223 /** 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. 288 224 * @return the filename as a String 289 225 */ 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 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 323 259 private boolean filenameClashes(String filename) { 324 260 File collection_directory = new File(Utility.getCollectDir(Gatherer.config.gsdl_path)); … … 335 271 return title_final; 336 272 } 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 363 274 private class CancelListener 364 275 implements ActionListener { … … 390 301 } 391 302 } 392 303 393 304 private class CreateListener 394 305 implements ActionListener { … … 413 324 } 414 325 } 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 448 327 description_final = description.getText(); 449 328 if(description_final.length() == 0) { … … 499 378 public String toString() { 500 379 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(); 508 381 } 509 382 return name; 510 383 } 511 384 } 512 513 /*514 private class RestrictedTextField515 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 RestrictedTextDocument525 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 filename573 private class TitleListener574 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 */608 385 } 609 386
Note:
See TracChangeset
for help on using the changeset viewer.