Changeset 11993


Ignore:
Timestamp:
2006-07-04T09:34:05+12:00 (18 years ago)
Author:
shaoqun
Message:

added redo, undo and reset default functionality, removed the replace button

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/cdm/FormatManager.java

    r11890 r11993  
    3333import javax.swing.*;
    3434import javax.swing.event.*;
     35import javax.swing.undo.*;
    3536import org.greenstone.gatherer.Configuration;
    3637import org.greenstone.gatherer.DebugStream;
     
    7273    static final private String DOCUMENTBUTTONS = "DocumentButtons";
    7374    static final private String DOCUMENTBUTTONS_DEFAULT_FORMAT = "Detach|Highlight";
    74    
     75    static private  HashMap format_map = null ;     
     76
    7577    /** The controls used to edit the format commands. */
    7678    private Control controls = null;
    7779    /** A reference to ourselves so inner classes can get at the model. */
    7880    private DOMProxyListModel model = null;
    79 
     81   
     82   
    8083    /** Constructor. */
    8184    public FormatManager() {
    8285    super(CollectionDesignManager.collect_config.getDocumentElement(), CollectionConfiguration.FORMAT_ELEMENT, new Format());
    8386    this.model = this;
     87
     88        format_map = new HashMap();
     89    format_map.put(DATELIST,"<td>[link][icon][/link]</td>\n<td>[highlight]{Or}{[dls.Title],[dc.Title],[ex.Title],Untitled}[/highlight]</td>\n<td>[ex.Date]</td>");
     90    format_map.put(HLIST,"[link][highlight][ex.Title][/highlight][/link]");
     91    format_map.put(VLIST,"<td valign=\"top\">[link][icon][/link]</td>\n<td valign=\"top\">[ex.srclink]{Or}{[ex.thumbicon],[ex.srcicon]}[ex./srclink]</td>\n<td valign=\"top\">[highlight]\n{Or}{[dls.Title],[dc.Title],[ex.Title],Untitled}\n[/highlight]{If}{[ex.Source],<br><i>([ex.Source])</i>}</td>");   
     92    format_map.put(DOCUMENTHEADING,"{Or}{[parent(Top):Title],[Title],untitled}<br>");   
     93    format_map.put(DOCUMENTTEXT,"[Text]");     
     94    format_map.put( DOCUMENTBUTTONS,"Detach|Highlight");
     95    format_map.put( "","");
     96       
    8497    DebugStream.println("FormatManager: parsed " + getSize() + " format statements.");
    8598    // Establish all of the format objects, so that classifier indexes are initially correct (subsequent refreshes of the model will be sufficient to keep these up to date, as long as we start with a live reference to a classifier.
    8699    int size = getSize();
    87     for(int i = 0; i < size; i++) {
     100        for(int i = 0; i < size; i++) {
    88101        getElementAt(i);
    89102    }
    90 
    91     // Ensure the default formats for DateList, HList and VList are assigned
     103         
     104        // Ensure the default formats for DateList, HList and VList are assigned
    92105    if (getFormat(DATELIST) == null) {
    93         addFormat(new Format("",DATELIST,DATELIST_DEFAULT_FORMAT));
    94     }
    95 
     106            addFormat(new Format("",DATELIST,DATELIST_DEFAULT_FORMAT));       
     107    }
     108
     109   
    96110    if (getFormat(HLIST) == null) {
    97         addFormat(new Format("",HLIST,HLIST_DEFAULT_FORMAT));
    98     }
    99 
     111        addFormat(new Format("",HLIST,HLIST_DEFAULT_FORMAT));               
     112    }
     113
     114     
    100115    if (getFormat(VLIST) == null) {
    101         addFormat(new Format("",VLIST,VLIST_DEFAULT_FORMAT));
    102     }
     116        addFormat(new Format("",VLIST,VLIST_DEFAULT_FORMAT));           
     117    }
     118   
    103119
    104120    if (getFormat(DOCUMENTHEADING) == null) {
    105121        addFormat(new Format(DOCUMENTHEADING, "", DOCUMENTHEADING_DEFAULT_FORMAT));
    106     }
    107     if (getFormat(DOCUMENTTEXT) == null) {
     122        }
     123
     124 
     125    if (getFormat(DOCUMENTTEXT)== null) {
    108126        addFormat(new Format(DOCUMENTTEXT,"",DOCUMENTTEXT_DEFAULT_FORMAT));
    109     }
    110     if (getFormat(DOCUMENTBUTTONS) == null) {
     127    }
     128   
     129   
     130
     131      if (getFormat(DOCUMENTBUTTONS) == null) {
    111132        addFormat(new Format(DOCUMENTBUTTONS,"",DOCUMENTBUTTONS_DEFAULT_FORMAT));
    112     }
    113    
     133    }
     134     
    114135    }
    115136
     
    118139     */
    119140    private void addFormat(Format format) {
    120     if(!contains(format)) {
     141        if(!contains(format)) {
    121142        Element element = format.getElement();
    122143        // Locate where we should insert this new classifier.
     
    126147    }
    127148    }
     149
    128150
    129151    public void destroy() {
     
    181203    remove(format);
    182204    Gatherer.c_man.configurationChanged();
     205       
    183206    }
    184207
     
    212235    {
    213236    ArrayList variable_model = new ArrayList();
     237        variable_model.add("");
    214238    variable_model.add("[Text]");
    215239    ArrayList every_metadata_set_element = MetadataSetManager.getEveryMetadataSetElement();
     
    235259    private class FormatControl
    236260    extends JPanel
    237     implements Control {
     261    implements Control{
    238262   
    239263    private ArrayList feature_model;
     
    246270    private JButton insert_button;
    247271    private JButton remove_button;
    248     private JButton replace_button;
    249     private JCheckBox enabled_checkbox;
     272    private JButton default_button;
     273        private JButton undo_button;   
     274    private JButton redo_button;
     275    private JCheckBox enabled_checkbox;
    250276    private JComboBox feature_combobox;
    251277    private JComboBox part_combobox;
     
    258284    private JPanel selection_pane;
    259285    private String view_type;
    260 
    261     private final Dimension FIELD_SIZE = new Dimension(200, 30);
    262     public FormatControl() {
     286    private final Dimension FIELD_SIZE = new Dimension(200, 30);
     287        private final UndoManager undo = new UndoManager();
     288        private boolean newtext = true;
     289        private Format previousFormat = null;
     290        private Format currentFormat = null;       
     291        private boolean fresh = true;
     292       
     293        public FormatControl() {
    263294        feature_model = buildFeatureModel();
    264295        part_model = buildPartModel();
    265296        variable_model = buildVariableModel();
    266 
     297     
    267298        // Create
    268299        JPanel header_pane = new DesignPaneHeader("CDM.GUI.Formats", "formatstatements");
     
    310341        editor_textarea.setRows(6);
    311342        editor_textarea.setWrapStyleWord(false);
    312         Dictionary.registerTooltip(editor_textarea, "CDM.FormatManager.Editor_Tooltip");
     343        Dictionary.registerTooltip(editor_textarea, "CDM.FormatManager.Add_Tooltip");
    313344
    314345        JPanel variable_pane = new JPanel();
     
    321352        insert_button.setMnemonic(KeyEvent.VK_I);
    322353        Dictionary.registerBoth(insert_button, "CDM.FormatManager.Insert", "CDM.FormatManager.Insert_Tooltip");
    323 
     354     
     355            default_button = new GLIButton();
     356        default_button.setMnemonic(KeyEvent.VK_D);
     357        Dictionary.registerBoth(default_button, "CDM.FormatManager.Default", "CDM.FormatManager.Default_Tooltip");
     358     
    324359        JPanel flag_pane = new JPanel();
    325360        enabled_checkbox = new JCheckBox();
     
    331366        add_button.setMnemonic(KeyEvent.VK_A);
    332367        Dictionary.registerBoth(add_button, "CDM.FormatManager.Add", "CDM.FormatManager.Add_Tooltip");
    333         replace_button = new GLIButton();
    334         replace_button.setEnabled(false);
    335         replace_button.setMnemonic(KeyEvent.VK_C);
    336         Dictionary.registerBoth(replace_button, "CDM.FormatManager.Replace", "CDM.FormatManager.Replace_Tooltip");
     368
     369       
    337370        remove_button = new GLIButton();
    338371        remove_button.setEnabled(false);
     
    340373        Dictionary.registerBoth(remove_button, "CDM.FormatManager.Remove", "CDM.FormatManager.Remove_Tooltip");
    341374
     375            undo_button = new GLIButton();
     376        undo_button.setEnabled(false);
     377        undo_button.setMnemonic(KeyEvent.VK_U);
     378        Dictionary.registerBoth(undo_button, "CDM.FormatManager.Undo", "CDM.FormatManager.Undo_Tooltip");
     379
     380            redo_button = new GLIButton();
     381        redo_button.setEnabled(false);
     382        redo_button.setMnemonic(KeyEvent.VK_O);
     383        Dictionary.registerBoth(redo_button, "CDM.FormatManager.Redo", "CDM.FormatManager.Redo_Tooltip");
     384
     385
    342386        // Connect
    343387        add_button.addActionListener(new AddListener());
    344388        add_button.addActionListener(CollectionDesignManager.collect_cfg_change_listener);
    345         insert_button.addActionListener(new InsertListener());
    346         insert_button.addActionListener(CollectionDesignManager.collect_cfg_change_listener);
     389     
    347390        remove_button.addActionListener(new RemoveListener());
    348391        remove_button.addActionListener(CollectionDesignManager.collect_cfg_change_listener);
    349         replace_button.addActionListener(new ReplaceListener());
    350         replace_button.addActionListener(CollectionDesignManager.collect_cfg_change_listener);
     392            default_button.addActionListener(new DefaultListener());
     393        default_button.addActionListener(CollectionDesignManager.collect_cfg_change_listener);
     394            undo_button.addActionListener(new UndoListener());
     395            redo_button.addActionListener(new RedoListener());
    351396        enabled_checkbox.addActionListener(new EnabledListener());
    352397        enabled_checkbox.addActionListener(CollectionDesignManager.collect_cfg_change_listener);
    353398        feature_combobox.addActionListener(new FeatureListener());
    354399        part_combobox.addActionListener(new PartListener());
    355         editor_textarea.getDocument().addDocumentListener(new EditorListener());
    356         format_list.addListSelectionListener(new FormatListListener());
     400       
     401            editor_textarea.getDocument().addDocumentListener(new EditorListener());
     402        // Listen for undo and redo events
     403        editor_textarea.getDocument().addUndoableEditListener(new UndoableEditListener() {
     404            public void undoableEditHappened(UndoableEditEvent evt) {
     405            undo.addEdit(evt.getEdit());
     406            }
     407        });
     408
     409
     410            format_list.addListSelectionListener(new FormatListListener());
     411            variable_combobox.addActionListener(new VariableListener());
    357412
    358413        // Layout
     
    361416        format_list_pane.setLayout(new BorderLayout());
    362417        format_list_pane.add(new JScrollPane(format_list), BorderLayout.CENTER);
     418           
    363419
    364420        feature_pane.setBorder(BorderFactory.createEmptyBorder(5,0,0,0));
     
    372428        part_pane.add(part_combobox, BorderLayout.CENTER);
    373429
    374         //selection_pane.setLayout(new GridLayout(2,1,0,2));
    375         //selection_pane.add(feature_pane);
    376         //selection_pane.add(part_pane);
    377430
    378431        flag_pane.add(enabled_checkbox);
     
    381434        editor_header_pane.setLayout(new GridLayout(1,3));
    382435        editor_header_pane.add(editor_label);
    383 
     436       
     437        JPanel rupanel = new JPanel();
     438            rupanel.setLayout(new GridLayout(1,2));
     439        rupanel.add(undo_button);     
     440        rupanel.add(redo_button);
     441     
    384442        variable_pane.setBorder(BorderFactory.createEmptyBorder(2,0,2,0));
    385443        variable_pane.setLayout(new GridLayout(1,3));
    386444        variable_pane.add(variable_label);
    387445        variable_pane.add(variable_combobox);
    388         variable_pane.add(insert_button);
     446        variable_pane.add(rupanel);
    389447
    390448        editor_pane.setLayout(new BorderLayout());
    391449        editor_pane.add(editor_header_pane, BorderLayout.NORTH);
    392         editor_pane.add(new JScrollPane(editor_textarea), BorderLayout.CENTER);
    393         //editor_pane.add(variable_pane, BorderLayout.SOUTH);
     450            editor_pane.add(new JScrollPane(editor_textarea), BorderLayout.CENTER);
    394451
    395452        selection_pane.setLayout(new BorderLayout());
     
    402459        control_pane.add(selection_pane, VALUE);
    403460        control_pane.add(blank_pane, BLANK);
    404 
     461           
     462           
    405463        button_pane.setLayout(new GridLayout(1,3));
    406464        button_pane.add(add_button);
    407         button_pane.add(replace_button);
    408465        button_pane.add(remove_button);
     466            button_pane.add(default_button);     
     467           
    409468
    410469        center_pane.setLayout(new BorderLayout());
     
    424483    }
    425484       
     485
     486
    426487    /** Overriden to ensure that the instructions pane is scrolled to the top.
    427488     */
     
    442503        variable_combobox.setModel(new DefaultComboBoxModel(variable_model.toArray()));
    443504        variable_combobox.setSelectedItem(selected_variable);
    444         }   
     505        }   
    445506    }
    446507
     
    451512    }
    452513
     514
     515   
    453516    /** Listens for clicks on the add button, and if the relevant details are provided adds a new format. Note that formats are responsible for codecing the values into something that can be a) stored in a DOM and b) written to file */
    454517    private class AddListener
     
    457520        public void actionPerformed(ActionEvent event)
    458521        {
     522   
    459523        ignore_event = true; // Prevent format_list excetera propagating events
    460524
     
    470534        if (view_type.equals(FLAG)) {
    471535            format = new Format(f, p, enabled_checkbox.isSelected());
    472         }
     536            }
    473537        else {
    474538            format = new Format(f, p, editor_textarea.getText());
     539           
    475540        }
     541
     542   
    476543        addFormat(format);
    477 
     544        existingFormat();
    478545        // Save the collection configuration file immediately
    479         Gatherer.g_man.design_pane.saveConfiguration();
    480 
    481         add_button.setEnabled(false);
    482         replace_button.setEnabled(false);
    483         remove_button.setEnabled(true);
    484 
    485         // Update list selection
     546   
     547        Gatherer.c_man.configurationChanged();
     548
     549            // Update list selection
    486550        format_list.setSelectedValue(format, true);
    487551        format = null;
     
    497561 
    498562        public void changedUpdate(DocumentEvent e) {
     563             
    499564        update();
    500565        }
    501566         
    502567        public void insertUpdate(DocumentEvent e) {
    503         update();
     568        update();   
     569        updateUndo("insert");                   
     570       
    504571        }
    505572         
    506573        public void removeUpdate(DocumentEvent e) {
    507574        update();
     575        updateUndo("remove");         
     576       
     577        }
     578
     579            private void updateUndo(String from){
     580
     581        if (!newtext){
     582            undo_button.setEnabled(true);
     583        }                   
     584
     585        if (editor_textarea.getText().length()!=0 && newtext){
     586            newtext = false;                                                                   
     587        }               
    508588        }
    509589
    510590        public void update() {
     591                                 
    511592        // Determine if replace should be enabled
    512593        if(!format_list.isSelectionEmpty()) {
    513594            Format format = (Format)format_list.getSelectedValue();
    514             replace_button.setEnabled(!format.isParamType() && editor_textarea.getText() != format.getValue());
     595            boolean shouldSave = !format.isParamType();
     596           
     597                    if (shouldSave){
     598            format.setValue(editor_textarea.getText());
     599                        Gatherer.c_man.configurationChanged();
     600                        model.refresh((DOMProxyListEntry)format);
     601            }
     602                                                                         
    515603        }
    516604        else {
    517             replace_button.setEnabled(false);
     605            add_button.setEnabled(false);
     606           
    518607        }
     608           
    519609        }
    520610    }
     
    527617        if(!format_list.isSelectionEmpty()) {
    528618            Format format = (Format)format_list.getSelectedValue();
    529             replace_button.setEnabled(format.isParamType() && enabled_checkbox.isSelected() != format.getState());
     619            boolean shouldSave = format.isParamType();
     620            if (shouldSave){
     621            format.setState(enabled_checkbox.isSelected());
     622                        Gatherer.c_man.configurationChanged();
     623                        model.refresh((DOMProxyListEntry)format);
     624            }
    530625        }
     626
    531627        // Thats it. Add would have been enabled upon feature/part selection depending if no existing format, um, existed.
    532628        }
     
    536632        implements ActionListener {
    537633        public void actionPerformed(ActionEvent event) {
     634                undo_button.setEnabled(false);
     635                redo_button.setEnabled(false);
     636                default_button.setEnabled(true);
     637        newtext = true;
     638   
    538639        if(!ignore_event) {
    539640            ignore_event = true;
     
    549650            }
    550651            // Step two: the rest
    551             
     652           
    552653            String name = entry.toString();
    553654            // 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
     
    558659            if(f.toString().length() == 0 && pname.length() == 0) {
    559660                        add_button.setEnabled(false);
    560             replace_button.setEnabled(false);
    561661            remove_button.setEnabled(false);
    562662            }
     
    565665               Format format = getFormat(Format.generateName(f, pname));
    566666               // If there is an existing feature, select it, and use it to determine what controls are visible
     667             
    567668               if(format != null) {
    568669              ///ystem.err.println("There is an existing format!");
     
    584685                view_type = VALUE;
    585686                // Initial value
    586                 editor_textarea.setText(format.getValue());
     687
     688                                editor_textarea.setText(format.getValue());
     689                                editor_textarea.setCaretPosition(0);
     690                                                                         
    587691                }
     692                            existingFormat();
    588693                control_pane.updateUI();
    589                 remove_button.setEnabled(true);
    590                             add_button.setEnabled(false);
    591694               }
    592695               // Otherwise there is no existing format, so we proceed by checking against the feature name
    593696            else {
    594697                 ///ystem.err.println("No existing format");
    595                 format_list.clearSelection();
     698                            format_list.clearSelection();
    596699                if(Format.isParamType(name)) {
    597700                   ///ystem.err.println("Flag type");
     
    602705                // Initial value
    603706                enabled_checkbox.setSelected(false);
     707                enabled_checkbox.setEnabled(false);
    604708                }
    605709                else {
     
    609713                view_type = VALUE;
    610714                // Initial value
     715
    611716                editor_textarea.setText(part.getDefaultFormat());
     717                                editor_textarea.setCaretPosition(0);
     718                       
    612719                }
    613                 add_button.setEnabled(true);
     720                newFormat();
    614721            }
    615722            format = null;
     
    619726            pname = null;
    620727            f = null;
    621             replace_button.setEnabled(false);
    622728            name = null;
    623729            entry = null;
    624730            ignore_event = false;
    625731        }
     732                undo.discardAllEdits();
    626733        }
    627734    }
     
    630737        implements ListSelectionListener {
    631738        public void valueChanged(ListSelectionEvent event) {
     739                undo_button.setEnabled(false);
     740                redo_button.setEnabled(false);
     741                default_button.setEnabled(true);
     742        newtext = true;
     743       
    632744        if(!ignore_event && !event.getValueIsAdjusting()) {
     745       
    633746            if(!format_list.isSelectionEmpty()) {
    634             ignore_event = true;
     747                        existingFormat();
     748                        ignore_event = true;
    635749            Format format = (Format)format_list.getSelectedValue();
    636750            // Try to match the target, remembering the entries within are Entry's
     
    679793                  part_combobox.insertItemAt(a_part, part_combobox.getItemCount());
    680794                  part_combobox.setSelectedItem(a_part);
    681                }
    682795               
     796                           }
     797             
    683798               editor_textarea.setText(format.getValue());
    684             }
     799               editor_textarea.setCaretPosition(0);
     800                                     
     801                        }
     802                           
    685803            //control_pane.updateUI();
    686             remove_button.setEnabled(true);
    687804            ignore_event = false;
    688805            }
    689             else {
    690             remove_button.setEnabled(false);
    691             }
    692             add_button.setEnabled(false);
    693             replace_button.setEnabled(false);
     806         
    694807        }
    695         }
    696     }
    697 
    698     private class InsertListener
     808        undo.discardAllEdits();
     809            }
     810         
     811    }
     812
     813        private void newFormat(){
     814        editor_textarea.setEditable(false);
     815        editor_textarea.setBackground(Color.lightGray);
     816        Dictionary.registerTooltip(editor_textarea, "CDM.FormatManager.Add_Tooltip");
     817
     818        enabled_checkbox.setEnabled(false);
     819            undo_button.setEnabled(false);
     820        redo_button.setEnabled(false);
     821            variable_combobox.setEnabled(false); 
     822        add_button.setEnabled(true);
     823        remove_button.setEnabled(false);
     824            default_button.setEnabled(false);
     825                 
     826    }
     827
     828          private void existingFormat(){
     829        editor_textarea.setEditable(true);
     830        editor_textarea.setBackground(Color.white);
     831        Dictionary.registerTooltip(editor_textarea, "CDM.FormatManager.Edit_Tooltip");
     832        enabled_checkbox.setEnabled(true);
     833            variable_combobox.setEnabled(true); 
     834        add_button.setEnabled(false);
     835        remove_button.setEnabled(true);
     836            default_button.setEnabled(true);
     837                 
     838    }
     839             
     840    private class VariableListener
    699841        implements ActionListener {
    700842        public void actionPerformed(ActionEvent event) {
    701         editor_textarea.insert((String)variable_combobox.getSelectedItem(), editor_textarea.getCaretPosition());
    702         }
    703     }
    704        
     843                String selected_value = (String)variable_combobox.getSelectedItem();
     844             
     845        if (!selected_value.equals("")){
     846            editor_textarea.insert(selected_value, editor_textarea.getCaretPosition());   
     847            undo_button.setEnabled(true);
     848
     849        }
     850        }
     851       
     852    }
     853
    705854    private class PartListener
    706855        implements ActionListener {
    707856        public void actionPerformed(ActionEvent event) {
    708         if(!ignore_event) {
     857        undo_button.setEnabled(false);
     858                redo_button.setEnabled(false);
     859                default_button.setEnabled(true);
     860            newtext = true;
     861            if(!ignore_event) {
    709862            // 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
    710863            Entry entry = (Entry) feature_combobox.getSelectedItem();
     
    715868            if(f.toString().length() == 0 && pname.length() == 0) {
    716869            add_button.setEnabled(false);
    717             replace_button.setEnabled(false);
    718870            remove_button.setEnabled(false);
    719871            }
     
    738890                view_type = VALUE;
    739891                // Initial value
     892                             
    740893                editor_textarea.setText(format.getValue());
     894                    editor_textarea.setCaretPosition(0);
     895                               
    741896                }
    742897                control_pane.updateUI();
    743                 remove_button.setEnabled(true);
     898                existingFormat();
    744899            }
    745900            else {
     
    752907                // Initial value
    753908                enabled_checkbox.setSelected(false);
     909                enabled_checkbox.setEnabled(false);
    754910                }
    755911                else {
     
    758914                view_type = VALUE;
    759915                // Initial value
    760                 editor_textarea.setText(part.getDefaultFormat());
     916                               
     917                                editor_textarea.setText(part.getDefaultFormat());
     918                editor_textarea.setCaretPosition(0);
     919                   
    761920                }
    762                 add_button.setEnabled(true);
     921                            newFormat();
    763922            }
    764923            format = null;
     
    770929            f = null;
    771930            entry = null;
    772             replace_button.setEnabled(false);
    773931        }
     932        undo.discardAllEdits();
    774933        }
    775934    }
     
    785944
    786945            // Save the collection configuration file immediately
    787             Gatherer.g_man.design_pane.saveConfiguration();
    788 
     946            Gatherer.c_man.configurationChanged();
    789947            // Change buttons
    790948            add_button.setEnabled(true);
    791             replace_button.setEnabled(false);
     949            newFormat();
     950                   
    792951        }
    793 
    794         remove_button.setEnabled(false);
    795         }
    796     }
    797 
    798     private class ReplaceListener
     952        }
     953    }
     954
     955
     956
     957 private class DefaultListener
    799958        implements ActionListener {
    800959
    801960        public void actionPerformed(ActionEvent event)
    802961        {
    803         ignore_event = true; // Prevent format_list excetera propagating events
    804 
    805         if (!format_list.isSelectionEmpty()) {
    806             // Remove the current format
    807             removeFormat((Format) format_list.getSelectedValue());
    808 
     962        newtext = false;
     963        if(!ignore_event) { 
    809964            Entry entry = (Entry) feature_combobox.getSelectedItem();
    810965            Object f = entry.getFeature();
    811             String p = "";
    812             if (entry.canHavePart()) {
    813             p = part_combobox.getSelectedItem().toString();
    814             }
    815 
    816             // Add a new format string of the appropriate type
    817             Format format = null;
    818             if (view_type.equals(FLAG)) {
    819             format = new Format(f, p, enabled_checkbox.isSelected());
     966            String name ="";
     967            String pname="";
     968                    Part part = null;
     969
     970            if (entry.canHavePart()){
     971            part = (Part) part_combobox.getSelectedItem();
     972            pname = part.getName();
     973            name = Format.generateName(f, pname);       
     974            }
     975            else{
     976            name = entry.toString();
     977            }
     978
     979            Format format = getFormat(name);
     980            // If there is an existing feature, select it.
     981            if(format != null) {
     982            remove_button.setEnabled(true);
    820983            }
    821984            else {
    822             format = new Format(f, p, editor_textarea.getText());
    823             }
    824             addFormat(format);
    825 
    826             // Save the collection configuration file immediately
    827             Gatherer.g_man.design_pane.saveConfiguration();
    828 
    829             add_button.setEnabled(false);
    830             remove_button.setEnabled(true);
    831             // Update list selection
    832             format_list.setSelectedValue(format, true);
    833             format = null;
    834             p = null;
    835             f = null;
    836             entry = null;
     985                       
     986            add_button.setEnabled(true);
     987            }//endif (format !=null)
     988   
     989            if(Format.isParamType(name)) {
     990            // Flags first.
     991            card_layout.show(control_pane, FLAG);
     992            view_type = FLAG;
     993                // Initial value
     994            enabled_checkbox.setSelected(false);
     995            }
     996            else {
     997            card_layout.show(control_pane, VALUE);
     998            view_type = VALUE;
     999            // Initial value
     1000            if (pname !=null && pname.length()!=0 ){
     1001                editor_textarea.setText((String)format_map.get(pname));
     1002                editor_textarea.setCaretPosition(0);
     1003            }
     1004            else{
     1005                editor_textarea.setText((String)format_map.get(name));
     1006                editor_textarea.setCaretPosition(0);
     1007            }
     1008            }
     1009           
    8371010        }
    838 
    839         replace_button.setEnabled(false);
    840         ignore_event = false;
    841         }
    842     }
     1011        }
     1012
     1013 }
     1014
     1015        private class UndoListener
     1016        implements ActionListener {
     1017
     1018        public void actionPerformed(ActionEvent event)
     1019        {
     1020                try {
     1021                    if (undo.canUndo()) {
     1022                        int pos = editor_textarea.getCaretPosition();
     1023                        undo.undo();
     1024            editor_textarea.setCaretPosition(pos);
     1025                        redo_button.setEnabled(true);
     1026
     1027                    }
     1028                    if (!undo.canUndo()){
     1029            undo_button.setEnabled(false);
     1030            }
     1031            else{
     1032                        undo_button.setEnabled(true);
     1033            }   
     1034
     1035                } catch (Exception e) {
     1036                }           
     1037        }
     1038    }
     1039   
     1040       private class RedoListener
     1041        implements ActionListener {
     1042         public void actionPerformed(ActionEvent evt) {
     1043                try {
     1044                    if (undo.canRedo()) {
     1045            int pos = editor_textarea.getCaretPosition();
     1046                        undo.redo();
     1047                        editor_textarea.setCaretPosition(pos);
     1048                    }
     1049                    if (!undo.canRedo()){
     1050            redo_button.setEnabled(false);
     1051            }
     1052            else{
     1053                        redo_button.setEnabled(true);
     1054            }                     
     1055
     1056                } catch (Exception e) {}
     1057     }
     1058       }
     1059
    8431060    }
    8441061
Note: See TracChangeset for help on using the changeset viewer.