Changeset 29030


Ignore:
Timestamp:
2014-05-02T18:59:15+12:00 (10 years ago)
Author:
ak19
Message:

Now there are 2 sets of undo and redo buttons, one for each format statement textarea. These work just like the ctrl-z and ctrl-y shortcuts and menu options for the individual text areas, instead of undoing or redoing one character at a time. I think this is how undo and redo buttons should be added to an RSyntaxTextarea and will move the changes into their own class after this and will look at fixing up Format4gs3Manager.java similarly

File:
1 edited

Legend:

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

    r29017 r29030  
    8080    private GLIButton next_button = null;
    8181    private GLIButton accept_all_button = null;
    82     private GLIButton undo_button = null;
    83     private GLIButton redo_button = null;
     82    private GLIButton gs2_undo_button = null;
     83    private GLIButton gs2_redo_button = null;
     84    private GLIButton gs3_undo_button = null;
     85    private GLIButton gs3_redo_button = null;
    8486    private GLIButton htmltidy_button = null;
    8587    private GLIButton xmltidy_button = null;
     
    8890    private JLabel count_label = null;
    8991    private JLabel statusbar = null;
    90     private UndoManager undoManager;
    9192
    9293    public FormatConversionDialog (File collect_cfg_file, Document xml_file_doc, NodeList gsf_format_gs2_list) {
     
    104105   
    105106
     107    gs2_textarea = new NumberedJTextArea();
     108    gs3_textarea = new NumberedJTextArea();
     109
     110
    106111    JPanel midbutton_panel = new JPanel(); // FlowLayout by default in a JPanel
    107112    midbutton_panel.setComponentOrientation(Dictionary.getOrientation());
     113
     114    gs2_undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip"));
     115    gs2_undo_button.setEnabled(false);
     116
     117    gs2_redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip"));
     118    gs2_redo_button.setEnabled(false);
     119
     120    gs2_undo_button.addActionListener(new UndoListener(gs2_textarea, gs2_undo_button, gs2_redo_button));
     121    gs2_redo_button.addActionListener(new RedoListener(gs2_textarea, gs2_undo_button, gs2_redo_button));
     122
    108123    JButton reconvert_button = new GLIButton(Dictionary.get("FormatConversionDialog.Reconvert"), Dictionary.get("FormatConversionDialog.Reconvert_Tooltip"));
     124
     125    midbutton_panel.add(gs2_undo_button);
     126    midbutton_panel.add(gs2_redo_button);
    109127    midbutton_panel.add(reconvert_button);
    110128    reconvert_button.addActionListener(new ReconvertListener());
     
    117135    JPanel button1_panel = new JPanel();
    118136    button1_panel.setComponentOrientation(Dictionary.getOrientation());
    119     undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip"));
    120     undo_button.addActionListener(new UndoListener());
    121     undo_button.setEnabled(false);
    122 
    123     redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip"));
    124     redo_button.addActionListener(new RedoListener());
    125     redo_button.setEnabled(false);
     137    gs3_undo_button = new GLIButton(Dictionary.get("General.Undo"), Dictionary.get("General.Undo_Tooltip"));
     138    gs3_undo_button.setEnabled(false);
     139
     140    gs3_redo_button = new GLIButton(Dictionary.get("General.Redo"), Dictionary.get("General.Redo_Tooltip"));
     141    gs3_redo_button.setEnabled(false);
     142
     143    gs3_undo_button.addActionListener(new UndoListener(gs3_textarea, gs3_undo_button, gs3_redo_button));
     144    gs3_redo_button.addActionListener(new RedoListener(gs3_textarea, gs3_undo_button, gs3_redo_button));
     145   
    126146
    127147    xmltidy_button = new GLIButton(Dictionary.get("FormatConversionDialog.XHTML_Tidy"), Dictionary.get("FormatConversionDialog.XHTML_Tidy_Tooltip"));
    128148    xmltidy_button.addActionListener(new XMLTidyButtonListener());
    129149
    130     button1_panel.add(undo_button);
    131     button1_panel.add(redo_button);
     150    button1_panel.add(gs3_undo_button);
     151    button1_panel.add(gs3_redo_button);
    132152    button1_panel.add(xmltidy_button);
    133153
     
    149169    // The undoable text areas. Adding the UndoableEditListener has to come after instantiation
    150170    // of the undo and redo buttons, since the listener expects these buttons to already exist
    151     undoManager = new UndoManager();
    152 
    153     gs2_textarea = new NumberedJTextArea();
    154     gs3_textarea = new NumberedJTextArea();
    155 
    156     CustomUndoableEditListener customUndoableEditListener = new CustomUndoableEditListener();
    157     gs2_textarea.getDocument().addUndoableEditListener(customUndoableEditListener);
    158     gs3_textarea.getDocument().addUndoableEditListener(customUndoableEditListener);
     171
     172    gs2_textarea.getDocument().addUndoableEditListener(new CustomUndoableEditListener(gs2_undo_button, gs2_redo_button));
     173    gs3_textarea.getDocument().addUndoableEditListener(new CustomUndoableEditListener(gs3_undo_button, gs3_redo_button));
    159174
    160175    initTextArea(gs2_textarea);
     
    639654
    640655    // as we're on a new screen of dialog, need to clear all undo/redo history
    641     undoManager.discardAllEdits();
    642     undo_button.setEnabled(false);
    643     redo_button.setEnabled(false);
     656    gs2_undo_button.setEnabled(false);
     657    gs2_redo_button.setEnabled(false);
     658    gs3_undo_button.setEnabled(false);
     659    gs3_redo_button.setEnabled(false);
     660    gs2_textarea.discardAllEdits();
     661    gs3_textarea.discardAllEdits();
    644662
    645663    int len = gsf_format_gs2_list.getLength();
     
    935953    private class UndoListener implements ActionListener
    936954    {   
     955    NumberedJTextArea textarea = null;
     956    GLIButton undobutton, redobutton;
     957
     958    public UndoListener(NumberedJTextArea textarea, GLIButton undobutton, GLIButton redobutton) {
     959       
     960        this.textarea = textarea;
     961        this.undobutton = undobutton;
     962        this.redobutton = redobutton;       
     963       
     964    }
     965   
    937966    public void actionPerformed(ActionEvent event)
    938967    {
    939968        try {
    940         if (undoManager.canUndo()) {                       
    941             redo_button.setEnabled(true);
    942             undoManager.undo();                 
    943         }
    944        
    945         if (!undoManager.canUndo()) {
    946             undo_button.setEnabled(false);
     969        if (textarea.canUndo()) {                       
     970            redobutton.setEnabled(true);
     971            textarea.undoLastAction();                 
     972        }
     973       
     974        if (!textarea.canUndo()) {
     975            undobutton.setEnabled(false);
    947976        } else {
    948             undo_button.setEnabled(true);
     977            undobutton.setEnabled(true);
    949978        }
    950979       
    951980        } catch (Exception e) {
    952981        System.err.println("Exception trying to undo: " + e.getMessage());
     982        e.printStackTrace();
    953983        }
    954984    }
     
    957987    private class RedoListener implements ActionListener
    958988    {
     989    NumberedJTextArea textarea = null;
     990    GLIButton undobutton, redobutton;
     991
     992    public RedoListener(NumberedJTextArea textarea, GLIButton undobutton, GLIButton redobutton) {
     993
     994        this.textarea = textarea;
     995        this.undobutton = undobutton;
     996        this.redobutton = redobutton;
     997    }
     998
    959999    public void actionPerformed(ActionEvent evt)
    9601000    {
    9611001        try {
    962         if (undoManager.canRedo()) {
    963             undo_button.setEnabled(true); // the difference with Format4gs3Manager, and no DocumentListener
    964             undoManager.redo();
    965         }
    966        
    967         if (!undoManager.canRedo()) {
    968             redo_button.setEnabled(false);
     1002        if (textarea.canRedo()) {
     1003            undobutton.setEnabled(true); // the difference with Format4gs3Manager, and no DocumentListener
     1004            textarea.redoLastAction();
     1005        }
     1006       
     1007        if (!textarea.canRedo()) {
     1008            redobutton.setEnabled(false);
    9691009        } else {
    970             redo_button.setEnabled(true);
     1010            redobutton.setEnabled(true);
    9711011        }
    9721012       
    9731013        } catch (Exception e) {
    9741014        System.err.println("Exception trying to redo: " + e.getMessage());
     1015        e.printStackTrace();
    9751016        }
    9761017    }
     
    9781019
    9791020    private class CustomUndoableEditListener implements UndoableEditListener {
     1021    GLIButton undobutton = null;
     1022    GLIButton redobutton = null;
     1023
     1024    public CustomUndoableEditListener(GLIButton undo_button, GLIButton redo_button) {
     1025        undobutton = undo_button;
     1026        redobutton = redo_button;
     1027    }
     1028
    9801029    public void undoableEditHappened(UndoableEditEvent evt)
    981     {
    982        
    983         undoManager.addEdit(evt.getEdit());
    984         redo_button.setEnabled(false);
    985         undo_button.setEnabled(true);
    986     }
    987     }
    988 
     1030    {       
     1031        undobutton.setEnabled(true);
     1032        redobutton.setEnabled(false);       
     1033    }
     1034    }
    9891035}
Note: See TracChangeset for help on using the changeset viewer.