Search in sources :

Example 1 with MITextEditorPane

use of org.meteoinfo.console.editor.MITextEditorPane in project MeteoInfo by meteoinfo.

the class FrmTextEditor method addNewTextEditor.

private TextEditor addNewTextEditor(String title) {
    final TextEditor tab = new TextEditor(this.jTabbedPane1, title);
    this.jTabbedPane1.add(tab, title);
    this.jTabbedPane1.setSelectedComponent(tab);
    tab.setTextFont(_font);
    final MITextEditorPane textArea = (MITextEditorPane) tab.getTextArea();
    if (this._scriptLanguage.equals("Groovy")) {
        tab.getTextArea().setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY);
    } else {
        tab.getTextArea().setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON);
    }
    tab.getTextArea().discardAllEdits();
    tab.getTextArea().setDirty(false);
    tab.setTitle(title);
    // Set name completion
    JIntrospect nameComplete = new JIntrospect(this.interp);
    textArea.setNameCompletion(nameComplete);
    ButtonTabComponent btc = new ButtonTabComponent(this.jTabbedPane1);
    JButton button = btc.getTabButton();
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            FrmTextEditor.this.closeFile(tab);
        }
    });
    this.jTabbedPane1.setTabComponentAt(this.jTabbedPane1.indexOfComponent(tab), btc);
    return tab;
}
Also used : JIntrospect(org.meteoinfo.console.jython.JIntrospect) ButtonTabComponent(org.meteoinfo.ui.ButtonTabComponent) TextEditor(org.meteoinfo.console.editor.TextEditor) MITextEditorPane(org.meteoinfo.console.editor.MITextEditorPane) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent)

Example 2 with MITextEditorPane

use of org.meteoinfo.console.editor.MITextEditorPane in project MeteoInfo by meteoinfo.

the class EditorDockable method addNewTextEditor.

/**
 * Add a new text editor
 *
 * @param title Title
 * @return Text editor
 */
public final TextEditor addNewTextEditor(String title) {
    final TextEditor tab = new TextEditor(tabbedPanel, title);
    tabbedPanel.add(tab, title);
    tabbedPanel.setSelectedComponent(tab);
    final MITextEditorPane textArea = (MITextEditorPane) tab.getTextArea();
    textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON);
    textArea.discardAllEdits();
    this.theme.apply(textArea);
    tab.setTextFont(this.textFont);
    // Evaluate menu
    JPopupMenu popup = textArea.getPopupMenu();
    JMenuItem evaluate = new JMenuItem("Evaluate Selection");
    evaluate.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCodeLines(textArea);
            } catch (InterruptedException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadLocationException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    popup.insert(evaluate, 0);
    popup.insert(new Separator(), 1);
    // Comment menu
    JMenuItem comment = new JMenuItem("Comment or Uncomment");
    comment.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                comment(textArea);
            } catch (InterruptedException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadLocationException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    popup.insert(comment, 2);
    // Insert Tab menu
    JMenuItem insertTab = new JMenuItem("Insert Tab");
    insertTab.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                insertTab(textArea);
            } catch (InterruptedException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            } catch (AWTException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    popup.insert(insertTab, 3);
    // Delete Tab menu
    JMenuItem delTab = new JMenuItem("Delete Tab");
    delTab.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                delTab(textArea);
            } catch (InterruptedException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            } catch (BadLocationException ex) {
                Logger.getLogger(EditorDockable.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    popup.insert(delTab, 4);
    tab.getTextArea().setDirty(false);
    tab.setTitle(title);
    // Set name completion
    JIntrospect nameComplete = new JIntrospect(this.interp);
    textArea.setNameCompletion(nameComplete);
    // //Set language support - code auto completion
    // JythonLanguageSupport ac = new JythonLanguageSupport();
    // ac.install(textArea);
    // JythonCompletionProvider cp = ac.getProvider();
    // if (this.interp != null)
    // ((JythonSourceCompletionProvider)cp.getDefaultCompletionProvider()).setInterp(interp);
    ButtonTabComponent btc = new ButtonTabComponent(tabbedPanel);
    JButton button = btc.getTabButton();
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            closeFile(tab);
        }
    });
    tabbedPanel.setTabComponentAt(tabbedPanel.indexOfComponent(tab), btc);
    return tab;
}
Also used : JIntrospect(org.meteoinfo.console.jython.JIntrospect) MITextEditorPane(org.meteoinfo.console.editor.MITextEditorPane) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JPopupMenu(javax.swing.JPopupMenu) ButtonTabComponent(org.meteoinfo.ui.ButtonTabComponent) TextEditor(org.meteoinfo.console.editor.TextEditor) ActionListener(java.awt.event.ActionListener) JMenuItem(javax.swing.JMenuItem) BadLocationException(javax.swing.text.BadLocationException) Separator(javax.swing.JPopupMenu.Separator) AWTException(java.awt.AWTException)

Aggregations

ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 MITextEditorPane (org.meteoinfo.console.editor.MITextEditorPane)2 TextEditor (org.meteoinfo.console.editor.TextEditor)2 JIntrospect (org.meteoinfo.console.jython.JIntrospect)2 ButtonTabComponent (org.meteoinfo.ui.ButtonTabComponent)2 AWTException (java.awt.AWTException)1 JButton (javax.swing.JButton)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1 Separator (javax.swing.JPopupMenu.Separator)1 BadLocationException (javax.swing.text.BadLocationException)1