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;
}
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;
}
Aggregations