 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.textedit.scripteditor;
22 import java.awt.Frame;
23 import java.awt.Rectangle;
24 import java.awt.geom.RectangularShape;
25 import java.io.BufferedReader;
27 import java.io.FileInputStream;
28 import java.io.FileNotFoundException;
29 import java.io.IOException;
30 import java.io.InputStreamReader;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.prefs.Preferences;
34 import javax.swing.JDialog;
35 import javax.swing.JOptionPane;
36 import javax.swing.JTabbedPane;
37 import javax.swing.SwingConstants;
38 import javax.swing.event.ChangeEvent;
39 import javax.swing.event.ChangeListener;
40 import javax.swing.text.BadLocationException;
47 import net.
sf.japi.swing.action.ActionBuilder;
48 import net.
sf.japi.swing.action.ActionBuilderFactory;
49 import org.apache.log4j.Category;
50 import org.apache.log4j.Logger;
51 import org.jetbrains.annotations.NotNull;
52 import org.jetbrains.annotations.Nullable;
71 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
89 private static final String
WINDOW_X =
"ScriptEditWindow.x";
96 private static final String
WINDOW_Y =
"ScriptEditWindow.y";
136 super(owner,
"Script Pad");
137 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
142 setJMenuBar(
ACTION_BUILDER.createMenuBar(
true,
"scriptEditMenu"));
144 tabPane =
new JTabbedPane(SwingConstants.TOP);
151 final RectangularShape screen = getGraphicsConfiguration().getBounds();
152 final int width = preferences.getInt(
WINDOW_WIDTH, (
int) (0.8 * screen.getWidth()));
153 final int height = preferences.getInt(
WINDOW_HEIGHT, (
int) (0.8 * screen.getHeight()));
154 final int x = preferences.getInt(
WINDOW_X, (
int) (screen.getX() + (screen.getWidth() - width) / 2.0));
155 final int y = preferences.getInt(
WINDOW_Y, (
int) (screen.getY() + (screen.getHeight() - height) / 2.0));
156 setBounds(x, y, width, height);
161 public void preExitNotify() {
166 public void appExitNotify() {
167 final Rectangle bounds = getBounds();
168 preferences.putInt(
WINDOW_X, bounds.x);
169 preferences.putInt(
WINDOW_Y, bounds.y);
175 public void waitExitNotify() {
180 exiter.addExiterListener(exiterListener);
193 public void addTab(@NotNull
final String title, @Nullable
final File file) {
212 update(getGraphics());
215 if (file !=
null && file.exists()) {
218 try (FileInputStream fis =
new FileInputStream(file)) {
219 try (InputStreamReader isr =
new InputStreamReader(fis)) {
220 try (BufferedReader in =
new BufferedReader(isr)) {
221 boolean firstLine =
true;
222 final StringBuilder buff =
new StringBuilder();
224 final String line = in.readLine();
235 syntaxDocument.insertString(0, buff.toString(),
null);
240 }
catch (
final FileNotFoundException e) {
241 if (
LOG.isInfoEnabled()) {
242 LOG.info(
"addTab(): File '" + file.getName() +
"' not found.");
244 }
catch (
final IOException e) {
245 if (
LOG.isInfoEnabled()) {
246 LOG.info(
"addTab(): I/O-Error while reading '" + file.getName() +
"'.");
248 }
catch (
final BadLocationException e) {
249 if (
LOG.isInfoEnabled()) {
250 LOG.info(
"addTab(): Bad Location in Document!");
271 final int oldIndex =
tabPane.getSelectedIndex();
272 final int newIndex = oldIndex >=
tabPane.getTabCount() - 1 ? oldIndex - 1 : oldIndex;
273 tabPane.setSelectedIndex(newIndex);
294 return tabPane.getSelectedIndex();
309 public void setTitleAt(
final int index, @NotNull
final String title) {
310 tabPane.setTitleAt(index, title);
330 public boolean askConfirm(@NotNull
final String title, @NotNull
final String message) {
331 return JOptionPane.showConfirmDialog(
this, message, title, JOptionPane.YES_NO_OPTION, JOptionPane.INFORMATION_MESSAGE) == JOptionPane.YES_OPTION;
341 public void showMessage(@NotNull
final String title, @NotNull
final String message,
final int messageType) {
342 JOptionPane.showMessageDialog(
this, message, title, messageType);
345 public void showMessage(@NotNull
final String title, @NotNull
final String message) {
346 JOptionPane.showMessageDialog(
this, message, title, JOptionPane.INFORMATION_MESSAGE);
static final ActionBuilder ACTION_BUILDER
Action Builder.
Encapsulates default settings for a text area.
final JTabbedPane tabPane
jEdit's text area component.
void showMessage(@NotNull final String title, @NotNull final String message, final int messageType)
Shows the given message in the UI.
This package contains the other part of the script editor.
void setEditingFocus()
Sets the focus to this TextArea, so this component is instantly registered for key press events.
Base package of all Gridarta classes.
Listener for close box on the window.
void refresh()
Refreshes the enable/disable state of all menus.
String getActiveTitle()
Returns the title of the active tab.
void setTitleAt(final int index, @NotNull final String title)
Sets the title of the tab at specified index.
void removeDocument(@NotNull final Document document)
Removes a document.
JEditTextArea getActiveTextArea()
void resetUndo(@NotNull final Document document)
Forget all undo-able operations for a document.
TextAreaDefaults textAreaDefaults
The TextAreaDefaults for tabs.
void resetModified()
Reset the "modified" state.
final ScriptEditUndoActions scriptEditUndoActions
The undo related actions for the script editor.
void setTextAreaDefaults(@NotNull final TextAreaDefaults textAreaDefaults)
A document implementation that can be tokenized by the syntax highlighting system.
static final Category LOG
The Logger for printing log messages.
void setCurrentDocument(@Nullable final Document currentDocument)
Sets the current document.
Actions used by the script editor.
final ScriptEditView view
boolean getPaintInvalid()
static TokenMarker createTokenMarker(@Nullable final File file)
Creates a suitable TokenMarker for a given file.
void addTab(@NotNull final String title, @Nullable final File file)
Adds a new TextArea Panel to the TabbedPane.
ScriptEditView(@NotNull final ScriptEditControl control, @NotNull final Frame owner, @NotNull final Preferences preferences, @NotNull final Exiter exiter)
Builds a frame but keep it hidden (it is shown when first file is opened).
final Actions actions
The actions for the script editor.
void showMessage(@NotNull final String title, @NotNull final String message)
final List< JEditTextArea > textAreas
void addDocument(@NotNull final Document document)
Adds a document.
ScriptEditControl - Manages events and data flow for the script editor entity.
EditTabListener(@NotNull final ScriptEditView view)
boolean askConfirm(@NotNull final String title, @NotNull final String message)
Shows the given confirmation message as popup frame.
Inner class: Listener for ChangeEvents in the tabPane.
void stateChanged(@NotNull final ChangeEvent e)
static final long serialVersionUID
Serial Version UID.
void setTokenMarker(@Nullable final TokenMarker tokenMarker)
Sets the token marker that is to be used to split lines of this document up into tokens.
static final String WINDOW_Y
The key used to store the editor window y-coordinate in preferences file.
A factory for creatingTokenMarker instances for Files.
static final String WINDOW_X
The key used to store the editor window x-coordinate in preferences file.
void closeActiveTab()
Closes the active script-tab.
Interface for listeners interested in Exiter related events.
static final String WINDOW_HEIGHT
The key used to store the editor window height in preferences file.
static final String WINDOW_WIDTH
The key used to store the editor window width in preferences file.
Implements undo and redo actions.