Changeset 5720
- Timestamp:
- 2003-10-23T11:06:23+13:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/cdm/FormatManager.java
r5651 r5720 48 48 import org.greenstone.gatherer.cdm.Format; 49 49 import org.greenstone.gatherer.msm.ElementWrapper; 50 import org.greenstone.gatherer.util.StaticStrings; 50 51 import org.greenstone.gatherer.util.Utility; 51 52 import org.w3c.dom.*; … … 78 79 for(int i = 0; i < size; i++) { 79 80 getElementAt(i); 81 } 82 83 // Ensure the default formats for DateList, HList and VList are assigned 84 if(getFormat("DateList") == null) { 85 addFormat(new Format("","DateList","<td>[link][icon][/link]</td><td>[highlight]{Or}{[Title],Untitled}[/highlight]</td><td>[Date]</td>")); 86 } 87 88 if(getFormat("HList") == null) { 89 addFormat(new Format("","HList","[link][highlight][Title][/highlight][/link]")); 90 } 91 92 if(getFormat("VList") == null) { 93 addFormat(new Format("","VList","<td valign=top>[link][icon][/link]</td><td valign=top>[srclink]{Or}{[thumbicon],[srcicon]}[/srclink]</td><td valign=top>[highlight]{Or}{[Title],[dc.Title],[dls.Title],Untitled}[/highlight]{If}{[Source],<br><i>([Source])</i>}</td>")); 80 94 } 81 95 } … … 156 170 157 171 private HashMap buildDefaultMappings(ArrayList features_model, ArrayList parts_model) { 158 172 System.err.println("buildDefaultMappings(): replace me with something that reads in a data xml file."); 159 173 return new HashMap(); 160 174 } … … 178 192 System.err.println("buildPartModel(): replace me with something that reads in a data xml file."); 179 193 ArrayList part_model = new ArrayList(); 180 part_model.add( "");181 part_model.add( "DateList");182 part_model.add( "HList");183 part_model.add( "Invisible");184 part_model.add( "VList");194 part_model.add(new Part("", "")); 195 part_model.add(new Part("DateList", "<td>[link][icon][/link]</td><td>[highlight]{Or}{[Title],Untitled}[/highlight]</td><td>[Date]</td>")); 196 part_model.add(new Part("HList", "[link][highlight][Title][/highlight][/link]")); 197 part_model.add(new Part("Invisible", "")); 198 part_model.add(new Part("VList", "<td valign=top>[link][icon][/link]</td><td valign=top>[srclink]{Or}{[thumbicon],[srcicon]}[/srclink]</td><td valign=top>[highlight]{Or}{[Title],[dc.Title],[dls.Title],Untitled}[/highlight]{If}{[Source],<br><i>([Source])</i>}</td>")); 185 199 return part_model; 186 200 } … … 217 231 private HashMap default_mappings; 218 232 private JButton add_button; 219 private JButton insert_button; 233 //private JButton default_button; 234 private JButton insert_button; 220 235 private JButton remove_button; 221 236 private JButton replace_button; … … 227 242 private JTextArea instructions_textarea; 228 243 private JTextArea editor_textarea; 229 private JPanel control_pane; 244 private JPanel blank_pane; 245 private JPanel control_pane; 230 246 private JPanel part_pane; 231 247 private JPanel selection_pane; … … 275 291 Dictionary.registerTooltip(part_combobox, "CDM.FormatManager.Part_Tooltip"); 276 292 293 blank_pane = new JPanel(); 294 277 295 JPanel center_pane = new JPanel(); 278 296 … … 287 305 Dictionary.registerText(editor_label, "CDM.FormatManager.Editor"); 288 306 307 //default_button = new JButton(); 308 //default_button.setEnabled(false); 309 //default_button.setMnemonic(KeyEvent.VK_D); 310 //Dictionary.registerBoth(default_button, "CDM.FormatManager.Default_Format", "CDM.FormatManager.Default_Format_Tooltip"); 311 289 312 editor_textarea = new JTextArea(); 290 313 editor_textarea.setBackground(Gatherer.config.getColor("coloring.editable_background", false)); … … 325 348 // Connect 326 349 add_button.addActionListener(new AddListener()); 350 //default_button.addActionListener(new DefaultFormatListener()); 327 351 insert_button.addActionListener(new InsertListener()); 328 352 remove_button.addActionListener(new RemoveListener()); … … 357 381 editor_header_pane.setLayout(new GridLayout(1,3)); 358 382 editor_header_pane.add(editor_label); 359 editor_header_pane.add(new JPanel()); 383 //editor_header_pane.add(new JPanel()); 384 //editor_header_pane.add(default_button); 360 385 361 386 variable_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0)); … … 434 459 Entry entry = (Entry)feature_combobox.getSelectedItem(); 435 460 Object f = entry.getFeature(); 436 String p = (String)part_combobox.getSelectedItem();461 String p = part_combobox.getSelectedItem().toString(); 437 462 Format format = null; 438 463 if(view_type.equals(FLAG)) { … … 455 480 } 456 481 } 457 482 458 483 private class EditorListener 459 484 implements DocumentListener { … … 502 527 ignore_event = true; 503 528 // Step one: reset part 504 part_combobox.setSelectedIndex( 0);529 part_combobox.setSelectedIndex(4); 505 530 // Step two: the rest 506 531 Entry entry = (Entry) feature_combobox.getSelectedItem(); … … 508 533 if(Format.isParamType(name)) { 509 534 // Flags first. 510 selection_pane.remove(part_pane); 535 selection_pane.remove(part_pane); 536 //selection_pane.add(blank_pane); 511 537 card_layout.show(control_pane, FLAG); 512 538 view_type = FLAG; 513 539 } 514 540 else { 515 selection_pane.add(part_pane); 541 //selection_pane.remove(blank_pane); 542 selection_pane.add(part_pane); 516 543 card_layout.show(control_pane, VALUE); 517 544 view_type = VALUE; … … 520 547 // Add is only enabled if there isn't already a format for the choosen feature and part. Create a dummy format and test if itsa already in the model 521 548 Object f = entry.getFeature(); 522 String p = (String)part_combobox.getSelectedItem(); 549 Part part = (Part)part_combobox.getSelectedItem(); 550 String pname = part.getName(); 523 551 // You can never add anything to blank-blank 524 if(f.toString().length() == 0 && p .length() == 0) {552 if(f.toString().length() == 0 && pname.length() == 0) { 525 553 add_button.setEnabled(false); 526 554 replace_button.setEnabled(false); … … 528 556 } 529 557 else { 530 name = Format.generateName(f, p); 531 Format format = getFormat(name); 532 // If there is an existing feature, select it. 533 if(format != null) { 534 format_list.setSelectedValue(format, true); 535 // Now use type to determine what controls are visible, and what have initial values. 536 if(format.isParamType()) { 537 // Flags first. 538 selection_pane.remove(part_pane); 539 card_layout.show(control_pane, FLAG); 540 view_type = FLAG; 541 // Initial value 542 enabled_checkbox.setSelected(format.getState()); 543 } 544 else { 545 selection_pane.add(part_pane); 546 card_layout.show(control_pane, VALUE); 547 view_type = VALUE; 548 // Initial value 549 editor_textarea.setText(format.getValue()); 550 } 551 control_pane.updateUI(); 552 remove_button.setEnabled(true); 553 } 554 else { 555 format_list.clearSelection(); 556 if(Format.isParamType(name)) { 557 // Flags first. 558 selection_pane.remove(part_pane); 559 card_layout.show(control_pane, FLAG); 560 view_type = FLAG; 561 // Initial value 562 enabled_checkbox.setSelected(false); 563 } 564 else { 565 selection_pane.add(part_pane); 566 card_layout.show(control_pane, VALUE); 567 view_type = VALUE; 568 // Initial value 569 editor_textarea.setText(""); 570 } 571 add_button.setEnabled(true); 572 } 573 format = null; 574 name = null; 575 } 576 p = null; 577 f = null; 578 replace_button.setEnabled(false); 579 name = null; 580 entry = null; 581 ignore_event = false; 582 } 583 } 584 } 585 586 private class FormatListListener 587 implements ListSelectionListener { 588 public void valueChanged(ListSelectionEvent event) { 589 if(!ignore_event) { 590 if(!format_list.isSelectionEmpty()) { 591 ignore_event = true; 592 Format format = (Format)format_list.getSelectedValue(); 593 // Try to match the target, remembering the entries within are Entry's 594 Entry an_entry = new Entry(format.getFeature()); 595 feature_combobox.setSelectedItem(an_entry); 596 // If we didn't match anything, add it and select it again 597 Entry result_entry = (Entry) feature_combobox.getSelectedItem(); 598 if(!an_entry.equals(result_entry)) { 599 feature_combobox.insertItemAt(an_entry, feature_combobox.getItemCount()); 600 feature_combobox.setSelectedItem(an_entry); 601 } 602 603 if(format.canHavePart()) { 604 part_combobox.setEnabled(true); 605 // Try to match the part. 606 String part_entry = format.getPart(); 607 part_combobox.setSelectedItem(part_entry); 608 // If we didn't match anything, add it and select it again 609 String selected_part = (String)part_combobox.getSelectedItem(); 610 if(!part_entry.equals(selected_part)) { 611 part_combobox.insertItemAt(part_entry, part_combobox.getItemCount()); 612 part_combobox.setSelectedItem(part_entry); 613 } 614 } 615 else { 616 part_combobox.setEnabled(false); 617 } 618 // Now use type to determine what controls are visible, and what have initial values. 619 if(format.isParamType()) { 620 // Flags first. 621 selection_pane.remove(part_pane); 622 card_layout.show(control_pane, FLAG); 623 view_type = FLAG; 624 // Initial value 625 enabled_checkbox.setSelected(format.getState()); 626 } 627 else { 628 selection_pane.add(part_pane); 629 card_layout.show(control_pane, VALUE); 630 view_type = VALUE; 631 // Initial value 632 editor_textarea.setText(format.getValue()); 633 } 634 control_pane.updateUI(); 635 remove_button.setEnabled(true); 636 ignore_event = false; 637 } 638 else { 639 remove_button.setEnabled(false); 640 } 641 add_button.setEnabled(false); 642 replace_button.setEnabled(false); 643 } 644 } 645 } 646 647 private class InsertListener 648 implements ActionListener { 649 public void actionPerformed(ActionEvent event) { 650 editor_textarea.insert((String)variable_combobox.getSelectedItem(), editor_textarea.getCaretPosition()); 651 } 652 } 653 654 private class PartListener 655 implements ActionListener { 656 public void actionPerformed(ActionEvent event) { 657 if(!ignore_event) { 658 // Add is only enabled if there isn't already a format for the choosen feature and part. Create a dummy format and test if itsa already in the model 659 Entry entry = (Entry) feature_combobox.getSelectedItem(); 660 Object f = entry.getFeature(); 661 String p = (String)part_combobox.getSelectedItem(); 662 // You can never add anything to blank-blank 663 if(f.toString().length() == 0 && p.length() == 0) { 664 add_button.setEnabled(false); 665 replace_button.setEnabled(false); 666 remove_button.setEnabled(false); 667 } 668 else { 669 String name = Format.generateName(f, p); 558 name = Format.generateName(f, pname); 670 559 Format format = getFormat(name); 671 560 // If there is an existing feature, select it. … … 706 595 view_type = VALUE; 707 596 // Initial value 708 editor_textarea.setText( "");597 editor_textarea.setText(part.getDefaultFormat()); 709 598 } 710 599 add_button.setEnabled(true); … … 713 602 name = null; 714 603 } 715 p = null; 604 part = null; 605 pname = null; 606 f = null; 607 replace_button.setEnabled(false); 608 name = null; 609 entry = null; 610 ignore_event = false; 611 } 612 } 613 } 614 615 private class FormatListListener 616 implements ListSelectionListener { 617 public void valueChanged(ListSelectionEvent event) { 618 if(!ignore_event && !event.getValueIsAdjusting()) { 619 if(!format_list.isSelectionEmpty()) { 620 ignore_event = true; 621 Format format = (Format)format_list.getSelectedValue(); 622 // Try to match the target, remembering the entries within are Entry's 623 Entry an_entry = new Entry(format.getFeature()); 624 feature_combobox.setSelectedItem(an_entry); 625 // If we didn't match anything, add it and select it again 626 Entry result_entry = (Entry) feature_combobox.getSelectedItem(); 627 if(!an_entry.equals(result_entry)) { 628 feature_combobox.insertItemAt(an_entry, feature_combobox.getItemCount()); 629 feature_combobox.setSelectedItem(an_entry); 630 } 631 632 // Now use type to determine what controls are visible, and what have initial values. 633 ///ystem.err.println("Determine the correct type."); 634 if(format.isParamType()) { 635 ///ystem.err.println("Flag type - remove part"); 636 // Flags first. 637 SwingUtilities.invokeLater(new GUIChangeTask(selection_pane, part_pane, blank_pane, false)); 638 card_layout.show(control_pane, FLAG); 639 view_type = FLAG; 640 // Initial value 641 enabled_checkbox.setSelected(format.getState()); 642 } 643 else { 644 ///ystem.err.println("Value type - show part"); 645 SwingUtilities.invokeLater(new GUIChangeTask(selection_pane, part_pane, blank_pane, true)); 646 card_layout.show(control_pane, VALUE); 647 view_type = VALUE; 648 // Initial values 649 650 // Try to match the part. 651 String part_entry = format.getPart(); 652 // Set Selected Item doesn't work so I'll do this manually 653 boolean found = false; 654 for(int i=0; i < part_combobox.getItemCount(); i++) { 655 Part a_part = (Part) part_combobox.getItemAt(i); 656 if(a_part.equals(part_entry)) { 657 part_combobox.setSelectedItem(a_part); 658 found = true; 659 } 660 a_part = null; 661 } 662 // If we didn't match anything, add it and select it again 663 if(!found) { 664 Part a_part = new Part(part_entry, ""); 665 part_combobox.insertItemAt(a_part, part_combobox.getItemCount()); 666 part_combobox.setSelectedItem(a_part); 667 } 668 669 editor_textarea.setText(format.getValue()); 670 } 671 //control_pane.updateUI(); 672 remove_button.setEnabled(true); 673 ignore_event = false; 674 } 675 else { 676 remove_button.setEnabled(false); 677 } 678 add_button.setEnabled(false); 679 replace_button.setEnabled(false); 680 } 681 } 682 } 683 684 private class InsertListener 685 implements ActionListener { 686 public void actionPerformed(ActionEvent event) { 687 editor_textarea.insert((String)variable_combobox.getSelectedItem(), editor_textarea.getCaretPosition()); 688 } 689 } 690 691 private class PartListener 692 implements ActionListener { 693 public void actionPerformed(ActionEvent event) { 694 if(!ignore_event) { 695 // Add is only enabled if there isn't already a format for the choosen feature and part. Create a dummy format and test if its already in the model 696 Entry entry = (Entry) feature_combobox.getSelectedItem(); 697 Object f = entry.getFeature(); 698 Part part = (Part) part_combobox.getSelectedItem(); 699 String pname = part.getName(); 700 // You can never add anything to blank-blank 701 if(f.toString().length() == 0 && pname.length() == 0) { 702 add_button.setEnabled(false); 703 replace_button.setEnabled(false); 704 remove_button.setEnabled(false); 705 } 706 else { 707 String name = Format.generateName(f, pname); 708 Format format = getFormat(name); 709 // If there is an existing feature, select it. 710 if(format != null) { 711 format_list.setSelectedValue(format, true); 712 // Now use type to determine what controls are visible, and what have initial values. 713 if(format.isParamType()) { 714 // Flags first. 715 selection_pane.remove(part_pane); 716 card_layout.show(control_pane, FLAG); 717 view_type = FLAG; 718 // Initial value 719 enabled_checkbox.setSelected(format.getState()); 720 } 721 else { 722 selection_pane.add(part_pane); 723 card_layout.show(control_pane, VALUE); 724 view_type = VALUE; 725 // Initial value 726 editor_textarea.setText(format.getValue()); 727 } 728 control_pane.updateUI(); 729 remove_button.setEnabled(true); 730 } 731 else { 732 format_list.clearSelection(); 733 if(Format.isParamType(name)) { 734 // Flags first. 735 selection_pane.remove(part_pane); 736 card_layout.show(control_pane, FLAG); 737 view_type = FLAG; 738 // Initial value 739 enabled_checkbox.setSelected(false); 740 } 741 else { 742 selection_pane.add(part_pane); 743 card_layout.show(control_pane, VALUE); 744 view_type = VALUE; 745 // Initial value 746 editor_textarea.setText(part.getDefaultFormat()); 747 } 748 add_button.setEnabled(true); 749 } 750 format = null; 751 name = null; 752 } 753 754 pname = null; 755 part = null; 716 756 f = null; 717 757 entry = null; … … 747 787 Entry entry = (Entry)feature_combobox.getSelectedItem(); 748 788 Object f = entry.getFeature(); 749 String p = (String)part_combobox.getSelectedItem();789 String p = part_combobox.getSelectedItem().toString(); 750 790 Format format = null; 751 791 if(view_type.equals(FLAG)) { … … 829 869 public String toString() { 830 870 if(classifier != null) { 831 // Return the classifier - less the 'classify ' prefix 832 return classifier. toString().substring(9);871 // Return the classifier - less the 'classify ' prefix and with its CL index shown 872 return classifier.getPositionString() + StaticStrings.COLON_CHARACTER + StaticStrings.SPACE_CHARACTER + classifier.toString().substring(9); 833 873 } 834 874 return text; 835 875 } 836 876 } 877 878 private class GUIChangeTask 879 implements Runnable { 880 private boolean to_add; 881 private JPanel child; 882 private JPanel parent; 883 private JPanel replacement; 884 885 public GUIChangeTask(JPanel parent, JPanel child, JPanel replacement, boolean to_add) { 886 this.child = child; 887 this.parent = parent; 888 this.replacement = replacement; 889 this.to_add = to_add; 890 } 891 892 public void run() { 893 if(to_add) { 894 parent.remove(replacement); 895 parent.add(child); 896 parent.updateUI(); 897 } 898 else { 899 parent.remove(child); 900 parent.add(replacement); 901 parent.updateUI(); 902 } 903 } 904 } 905 906 /** This class encapsulates all of the information associated with a certain component part of a feature within a html page returned from the receptioninst. */ 907 private class Part 908 implements Comparable { 909 /** The default format string for this part */ 910 private String default_format = null; 911 /** The name of this part */ 912 private String name = null; 913 /** Constructor - must be provided with all of the details of a part as there are no other setter methods. 914 * @param name the name of this part 915 * @param default_format the default format string for this part 916 */ 917 public Part(String name, String default_format) { 918 this.default_format = default_format; 919 this.name = name; 920 } 921 /** Compare this part to another object in terms of ordering 922 * @param obj the other Object 923 * @return <0 if the object is before, 0 if equal to, and >0 if the object is after this part 924 */ 925 public int compareTo(Object obj) { 926 return name.compareTo(obj.toString()); 927 } 928 929 /** Determine if the part is equivelent to some other object 930 * @param obj the other Object 931 * @return true is the two objects are equal 932 */ 933 public boolean equals(Object obj) { 934 return name.equals(obj.toString()); 935 } 936 937 /** Retrieve the default format string for this part 938 * @return the default format String 939 */ 940 public String getDefaultFormat() { 941 // Retrieve the format for the super format - either VList or HList 942 Format default_format_object = getFormat(name); 943 if(default_format_object != null) { 944 return default_format_object.getValue(); 945 } 946 else { 947 return this.default_format; 948 } 949 } 950 /** Retrieve the name of this part 951 * @return the name as a String 952 */ 953 public String getName() { 954 return name; 955 } 956 /** Produce a string representation of this part, which in this case is simply the name again 957 * @return the name as a String 958 */ 959 public String toString() { 960 return name; 961 } 962 } 837 963 }
Note:
See TracChangeset
for help on using the changeset viewer.