Example usage for javax.swing.event UndoableEditEvent getEdit

List of usage examples for javax.swing.event UndoableEditEvent getEdit

Introduction

In this page you can find the example usage for javax.swing.event UndoableEditEvent getEdit.

Prototype

public UndoableEdit getEdit() 

Source Link

Document

Returns the edit value.

Usage

From source file:com.projity.undo.DataFactoryUndoController.java

public void undoableEditHappened(UndoableEditEvent e) {
    super.undoableEditHappened(e);
    if (hook == null || hook.evaluate(e))
        dataFactory.setGroupDirty(true);
    else//from  ww w . ja  v  a2  s . c  o m
        e.getEdit().undo();
}

From source file:ca.sqlpower.enterprise.DataSourceCollectionUpdater.java

public void undoableEditHappened(UndoableEditEvent e) {
    if (e.getEdit() instanceof PlDotIni.AddDSTypeUndoableEdit) {
        JDBCDataSourceType jdst = ((PlDotIni.AddDSTypeUndoableEdit) e.getEdit()).getType();
        jdst.addPropertyChangeListener(this);

        List<NameValuePair> properties = new ArrayList<NameValuePair>();
        for (String name : jdst.getPropertyNames()) {
            properties.add(new BasicNameValuePair(name, jdst.getProperty(name)));
        }/*  ww  w  .  j  av  a  2  s  .  c  o m*/

        postJDBCDataSourceTypeProperties(jdst, properties);
    }

    if (e.getEdit() instanceof PlDotIni.RemoveDSTypeUndoableEdit) {
        JDBCDataSourceType jdst = ((PlDotIni.RemoveDSTypeUndoableEdit) e.getEdit()).getType();
        jdst.removePropertyChangeListener(this);

        removeJDBCDataSourceType(jdst);
    }
}

From source file:com.mindcognition.mindraider.ui.swing.concept.annotation.renderer.AbstractTextAnnotationRenderer.java

public void undoableEditHappened(UndoableEditEvent e) {
    undoManager.addEdit(e.getEdit());
    toolbar.refreshButtons();
}

From source file:net.pandoragames.far.ui.swing.component.UndoHistory.java

/**
 * Method from interface <code>UndoableEditListener</code>.
 * Interfaces with the text component (pecisely: its Document object)
 * to record text modifications.//from www  .  ja v a  2 s.  c  o  m
 * @param event containing an UndoableEdit obejct
 */
public void undoableEditHappened(UndoableEditEvent event) {
    this.addEdit(event.getEdit());
}

From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java

private void initTextField(String pathToEditingFile) {
    textField.addMouseListener(new ClickListener() {
        @Override//from   ww w . j  ava  2 s  . c o m
        public void doubleClick(MouseEvent e) {
            textField.selectAll();
        }
    });

    textField.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void changedUpdate(DocumentEvent e) {
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateTextFont();
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            updateTextFont();
        }

        private void updateTextFont() {
            UrlValidator urlValidator = new UrlValidator();
            if (urlValidator.isValid(textField.getText())) {
                if (textField != null) {
                    setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
                    textField.setForeground(Color.BLUE);
                }
            } else {
                if (textField != null) {
                    setTextFieldFont(textField.getFont(), TextAttribute.UNDERLINE, -1);
                    textField.setForeground(Color.BLACK);
                }
            }
        }

    });

    UndoManager undoManager = new UndoManager();
    textField.getDocument().addUndoableEditListener(new UndoableEditListener() {

        public void undoableEditHappened(UndoableEditEvent evt) {
            undoManager.addEdit(evt.getEdit());
        }

    });

    textField.getActionMap().put("Undo", new AbstractAction("Undo") {
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canUndo()) {
                    undoManager.undo();
                }
            } catch (CannotUndoException e) {
            }
        }
    });

    textField.getInputMap().put(KeyStroke.getKeyStroke("control Z"), "Undo");

    textField.getActionMap().put("Redo", new AbstractAction("Redo") {
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canRedo()) {
                    undoManager.redo();
                }
            } catch (CannotRedoException e) {
            }
        }
    });

    textField.getInputMap().put(KeyStroke.getKeyStroke("control shift Z"), "Redo");

    fillTextField(pathToEditingFile);
}

From source file:com.prodigy4440.view.MainJFrame.java

public final void initComponents() {

    List<Image> icons = new LinkedList<>();
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited16x16.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited32x32.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited48x48.png")).getImage());
    icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited72x72.png")).getImage());

    this.setIconImages(icons);

    ActionHandler actionHandler = new ActionHandler(this);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setSize(620, 520);
    this.setLocationRelativeTo(null);
    this.setTitle("Untitled Document- IgboTextEditor");
    southJPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED);
    southJPanel.setBorder(sbb);//from www  . ja  v a2 s  .  c  om
    menuBar = new JMenuBar();

    fileJMenu = new JMenu("File");
    fileJMenu.setMnemonic('F');
    editJMenu = new JMenu("Edit");
    editJMenu.setMnemonic('E');
    formatJMenu = new JMenu("Format");
    formatJMenu.setMnemonic('A');
    viewJMenu = new JMenu("View");
    viewJMenu.setMnemonic('V');
    helpJMenu = new JMenu("Help");
    helpJMenu.setMnemonic('H');

    newDocumentJMenuItem = new JMenuItem("New");
    newDocumentJMenuItem.addActionListener(actionHandler);
    newDocumentJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
    openJMenuItem = new JMenuItem("Open");
    openJMenuItem.addActionListener(actionHandler);
    openJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
    saveJMenuItem = new JMenuItem("Save");
    saveJMenuItem.addActionListener(actionHandler);
    saveJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
    printJMenuItem = new JMenuItem("Print");
    printJMenuItem.addActionListener(actionHandler);
    printJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));
    exitJMenuItem = new JMenuItem("Exit");
    exitJMenuItem.addActionListener(actionHandler);

    undoJMenuItem = new JMenuItem("Undo");
    undoJMenuItem.addActionListener(actionHandler);
    undoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK));
    redoJMenuItem = new JMenuItem("Redo");
    redoJMenuItem.addActionListener(actionHandler);
    redoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK));
    copyJMenuItem = new JMenuItem("Copy");
    copyJMenuItem.addActionListener(actionHandler);
    copyJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK));
    cutJMenuItem = new JMenuItem("Cut");
    cutJMenuItem.addActionListener(actionHandler);
    cutJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK));
    pasteJMenuItem = new JMenuItem("Paste");
    pasteJMenuItem.addActionListener(actionHandler);
    pasteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK));
    deleteJMenuItem = new JMenuItem("Delete");
    deleteJMenuItem.addActionListener(actionHandler);
    deleteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
    selectAllJMenuItem = new JMenuItem("Select All");
    selectAllJMenuItem.addActionListener(actionHandler);
    selectAllJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK));
    findJMenuItem = new JMenuItem("Find");
    findJMenuItem.addActionListener(actionHandler);
    findJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK));
    replaceJMenuItem = new JMenuItem("Replace");
    replaceJMenuItem.addActionListener(actionHandler);
    replaceJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));

    wordWrapJCheckBoxMenuItem = new JCheckBoxMenuItem("Word Wrap");
    wordWrapJCheckBoxMenuItem.addActionListener(actionHandler);
    wordWrapJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));
    fontJMenuItem = new JMenuItem("Font");
    fontJMenuItem.addActionListener(actionHandler);
    colorJMenuItem = new JMenuItem("Color");
    colorJMenuItem.addActionListener(actionHandler);

    statusBarJCheckBoxMenuItem = new JCheckBoxMenuItem("Status Bar");
    statusBarJCheckBoxMenuItem.addActionListener(actionHandler);
    statusBarJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.ALT_MASK));

    helpJMenuItem = new JMenuItem("Help");
    helpJMenuItem.addActionListener(actionHandler);
    helpJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK));
    aboutJMenuItem = new JMenuItem("About");
    aboutJMenuItem.addActionListener(actionHandler);

    statusJLabel = new JLabel("Status:");

    //Main text area setup
    textArea = new JTextArea();
    undoManager = new UndoManager();
    wordSearcher = new WordSearcher(textArea);
    textArea.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE));
    document = textArea.getDocument();
    document.addUndoableEditListener(new UndoableEditListener() {
        @Override
        public void undoableEditHappened(UndoableEditEvent e) {
            undoManager.addEdit(e.getEdit());
        }
    });

    font = new Font("Tahoma", Font.PLAIN, 16);
    textArea.setFont(font);
    color = Color.BLUE;
    textArea.setForeground(color);

    undoManager = new UndoManager();

    fileJMenu.add(newDocumentJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(openJMenuItem);
    fileJMenu.add(saveJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(printJMenuItem);
    fileJMenu.addSeparator();
    fileJMenu.add(exitJMenuItem);

    editJMenu.add(undoJMenuItem);
    editJMenu.add(redoJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(copyJMenuItem);
    editJMenu.add(cutJMenuItem);
    editJMenu.add(pasteJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(deleteJMenuItem);
    editJMenu.add(selectAllJMenuItem);
    editJMenu.addSeparator();
    editJMenu.add(findJMenuItem);
    editJMenu.add(replaceJMenuItem);

    formatJMenu.add(wordWrapJCheckBoxMenuItem);
    formatJMenu.add(fontJMenuItem);
    formatJMenu.add(colorJMenuItem);

    viewJMenu.add(statusBarJCheckBoxMenuItem);

    helpJMenu.add(helpJMenuItem);
    helpJMenu.add(aboutJMenuItem);

    menuBar.add(fileJMenu);
    menuBar.add(editJMenu);
    menuBar.add(formatJMenu);
    menuBar.add(viewJMenu);
    menuBar.add(helpJMenu);

    southJPanel.setVisible(false);
    southJPanel.add(statusJLabel);
    //JScrollPane setup
    JScrollPane scrollPane = new JScrollPane(textArea);
    scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    //setting uo the Jframe
    this.setJMenuBar(menuBar);
    this.add(scrollPane, BorderLayout.CENTER);
    this.add(southJPanel, BorderLayout.SOUTH);
    textArea.addMouseListener(new MouseInputListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            Highlighter h = textArea.getHighlighter();
            h.removeAllHighlights();
        }

        @Override
        public void mousePressed(MouseEvent e) {
            Highlighter h = textArea.getHighlighter();
            h.removeAllHighlights();
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseDragged(MouseEvent e) {
        }

        @Override
        public void mouseMoved(MouseEvent e) {
        }
    });

    textArea.addKeyListener(new IgboKeyListener(textArea));

}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatWritePanel.java

/**
 * Handles the <tt>UndoableEditEvent</tt>, by adding the content edit to
 * the <tt>UndoManager</tt>.
 *
 * @param e The <tt>UndoableEditEvent</tt>.
 *///from ww  w .  j a v a 2s  . com
public void undoableEditHappened(UndoableEditEvent e) {
    this.undo.addEdit(e.getEdit());
}

From source file:net.sourceforge.pmd.util.designer.Designer.java

private static void makeTextComponentUndoable(JTextComponent textConponent) {
    final UndoManager undoManager = new UndoManager();
    textConponent.getDocument().addUndoableEditListener(new UndoableEditListener() {
        @Override//from  ww  w.j  a v  a 2 s.  c o  m
        public void undoableEditHappened(UndoableEditEvent evt) {
            undoManager.addEdit(evt.getEdit());
        }
    });
    ActionMap actionMap = textConponent.getActionMap();
    InputMap inputMap = textConponent.getInputMap();
    actionMap.put("Undo", new AbstractAction("Undo") {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canUndo()) {
                    undoManager.undo();
                }
            } catch (CannotUndoException e) {
                throw new RuntimeException(e);
            }
        }
    });
    inputMap.put(KeyStroke.getKeyStroke("control Z"), "Undo");

    actionMap.put("Redo", new AbstractAction("Redo") {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canRedo()) {
                    undoManager.redo();
                }
            } catch (CannotRedoException e) {
                throw new RuntimeException(e);
            }
        }
    });
    inputMap.put(KeyStroke.getKeyStroke("control Y"), "Redo");
}

From source file:org.executequery.gui.text.TextUndoManager.java

public void undoableEditHappened(UndoableEditEvent undoableEditEvent) {

    UndoableEdit edit = undoableEditEvent.getEdit();
    AbstractDocument.DefaultDocumentEvent event = (AbstractDocument.DefaultDocumentEvent) edit;
    EventType eventType = event.getType();

    if (eventType == EventType.INSERT) {

        try {/*w  w w  . java 2 s. co  m*/

            if (addNextInsert) {

                add();
            }

            compoundEdit.addEdit(edit);

            int start = event.getOffset();
            int length = event.getLength();

            String text = event.getDocument().getText(start, length);
            if (StringUtils.endsWithAny(text, WHITESPACE)) {

                addNextInsert = true;
            }

        } catch (BadLocationException e) {

            Log.debug(e);
        }

    } else if (eventType == EventType.REMOVE) {

        add();
        compoundEdit.addEdit(edit);
        add();

    } else if (eventType == EventType.CHANGE) {

        compoundEdit.addEdit(edit);
    }

    redoCommand.setEnabled(false);
    undoCommand.setEnabled(true);
}

From source file:org.fife.ui.rsyntaxtextarea.EOLPreservingRSyntaxDocument.java

@Override
protected void fireUndoableEditUpdate(UndoableEditEvent evt) {
    if (lastEdit != null) {
        CompoundEdit edit = new CompoundEdit();
        edit.addEdit(evt.getEdit());
        edit.addEdit(lastEdit);//from  w w w  .j  av a  2s.  co m
        edit.end();
        super.fireUndoableEditUpdate(new UndoableEditEvent(evt.getSource(), edit));
        lastEdit = null;
    } else {
        super.fireUndoableEditUpdate(evt);
    }
}