more cleanup of internal accessors

This commit is contained in:
benfry
2008-08-17 21:32:47 +00:00
parent 6435506850
commit bd87e82876
7 changed files with 81 additions and 76 deletions
+4 -4
View File
@@ -279,7 +279,7 @@ public class Base {
Preferences.setInteger("last.sketch.count", editorCount);
//System.out.println("saving sketch count " + editorCount);
for (int i = 0; i < editorCount; i++) {
String path = editors[i].sketch.getMainFilePath();
String path = editors[i].getSketch().getMainFilePath();
if (path.startsWith(untitledPath)) {
path = ""; // this will prevent it from opening
}
@@ -295,7 +295,7 @@ public class Base {
// If a sketch is untitled on quit, may need to store the new name
// rather than the location from the temp folder.
protected void storeSketchPath(Editor editor, int index) {
String path = editor.sketch.getMainFilePath();
String path = editor.getSketch().getMainFilePath();
String untitledPath = untitledFolder.getAbsolutePath();
if (path.startsWith(untitledPath)) {
path = "";
@@ -527,7 +527,7 @@ public class Base {
Editor editor = new Editor(this, path, location);
// Make sure that the sketch actually loaded
if (editor.sketch == null) {
if (editor.getSketch() == null) {
return null; // Just walk away quietly
}
@@ -856,7 +856,7 @@ public class Base {
ActionListener listener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO ohmigod that's nassssteee!
activeEditor.sketch.importLibrary(e.getActionCommand());
activeEditor.getSketch().importLibrary(e.getActionCommand());
}
};
+42 -40
View File
@@ -98,25 +98,21 @@ public class Editor extends JFrame {
JLabel lineNumberComponent;
// currently opened program
protected Sketch sketch;
Sketch sketch;
EditorLineStatus lineStatus;
protected JEditTextArea textarea;
JEditTextArea textarea;
EditorListener listener;
// runtime information and window placement
Point sketchWindowLocation;
//RunButtonWatcher watcher;
Runner runtime;
JMenuItem exportAppItem;
JMenuItem saveMenuItem;
JMenuItem saveAsMenuItem;
// True if the sketchbook has changed since this Editor was last active.
// boolean sketchbookUpdated;
boolean running;
boolean presenting;
@@ -128,8 +124,6 @@ public class Editor extends JFrame {
// used internally, and only briefly
CompoundEdit compoundEdit;
//SketchHistory history; // TODO re-enable history
//Sketchbook sketchbook;
FindReplace find;
@@ -359,7 +353,7 @@ public class Editor extends JFrame {
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
@@ -409,7 +403,7 @@ public class Editor extends JFrame {
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
protected void buildMenuBar() {
@@ -949,7 +943,7 @@ public class Editor extends JFrame {
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
class UndoAction extends AbstractAction {
@@ -1023,7 +1017,7 @@ public class Editor extends JFrame {
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
@@ -1032,8 +1026,8 @@ public class Editor extends JFrame {
public Sketch getSketch() {
return sketch;
}
/**
* Get the JEditTextArea object for use (not recommended). This should only
* be used in obscure cases that really need to hack the internals of the
@@ -1187,11 +1181,40 @@ public class Editor extends JFrame {
}
/**
* Use before a manipulating text to group editing operations together as a
* single undo. Use stopCompoundEdit() once finished.
*/
public void startCompoundEdit() {
compoundEdit = new CompoundEdit();
}
/**
* Use with startCompoundEdit() to group edit operations in a single undo.
*/
public void stopCompoundEdit() {
compoundEdit.end();
undo.addEdit(compoundEdit);
undoAction.updateUndoState();
redoAction.updateRedoState();
compoundEdit = null;
}
public int getScrollPosition() {
return textarea.getScrollPosition();
}
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
* Switch between tabs, this swaps out the Document object
* that's currently being manipulated.
*/
public void setCode(SketchCode code) {
protected void setCode(SketchCode code) {
if (code.document == null) { // this document not yet inited
code.document = new SyntaxDocument();
@@ -1236,28 +1259,7 @@ public class Editor extends JFrame {
}
/**
* Use before a manipulating text to group editing operations together as a
* single undo. Use stopCompoundEdit() once finished.
*/
public void startCompoundEdit() {
compoundEdit = new CompoundEdit();
}
/**
* Use with startCompoundEdit() to group edit operations in a single undo.
*/
public void stopCompoundEdit() {
compoundEdit.end();
undo.addEdit(compoundEdit);
undoAction.updateUndoState();
redoAction.updateRedoState();
compoundEdit = null;
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
@@ -1416,7 +1418,7 @@ public class Editor extends JFrame {
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
@@ -1969,7 +1971,7 @@ public class Editor extends JFrame {
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
@@ -2041,7 +2043,7 @@ public class Editor extends JFrame {
}
// ...................................................................
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
/**
+11 -10
View File
@@ -107,9 +107,10 @@ public class EditorHeader extends JComponent {
popup.show(EditorHeader.this, x, y);
} else {
for (int i = 0; i < editor.sketch.codeCount; i++) {
Sketch sketch = editor.getSketch();
for (int i = 0; i < sketch.codeCount; i++) {
if ((x > tabLeft[i]) && (x < tabRight[i])) {
editor.sketch.setCurrent(i);
sketch.setCurrent(i);
repaint();
}
}
@@ -122,7 +123,7 @@ public class EditorHeader extends JComponent {
public void paintComponent(Graphics screen) {
if (screen == null) return;
Sketch sketch = editor.sketch;
Sketch sketch = editor.getSketch();
if (sketch == null) return; // ??
Dimension size = getSize();
@@ -299,7 +300,7 @@ public class EditorHeader extends JComponent {
item = Editor.newJMenuItemShift("New Tab", 'N');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.sketch.handleNewCode();
editor.getSketch().handleNewCode();
}
});
menu.add(item);
@@ -307,7 +308,7 @@ public class EditorHeader extends JComponent {
item = new JMenuItem("Rename");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.sketch.handleRenameCode();
editor.getSketch().handleRenameCode();
/*
// this is already being called by nameCode(), the second stage of rename
if (editor.sketch.current == editor.sketch.code[0]) {
@@ -321,7 +322,7 @@ public class EditorHeader extends JComponent {
item = new JMenuItem("Delete");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.sketch.handleDeleteCode();
editor.getSketch().handleDeleteCode();
}
});
menu.add(item);
@@ -329,7 +330,7 @@ public class EditorHeader extends JComponent {
item = new JMenuItem("Hide");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.sketch.handleHideCode();
editor.getSketch().handleHideCode();
}
});
menu.add(item);
@@ -339,11 +340,11 @@ public class EditorHeader extends JComponent {
ActionListener unhideListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String which = (String) e.getActionCommand();
editor.sketch.handleUnhideCode(which);
editor.getSketch().handleUnhideCode(which);
rebuildMenu();
}
};
Sketch sketch = editor.sketch;
Sketch sketch = editor.getSketch();
if (sketch != null) {
for (int i = 0; i < sketch.hiddenCount; i++) {
item = new JMenuItem(sketch.hidden[i].getPrettyName());
@@ -399,7 +400,7 @@ public class EditorHeader extends JComponent {
ActionListener jumpListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.sketch.setCurrent(e.getActionCommand());
editor.getSketch().setCurrent(e.getActionCommand());
}
};
for (int i = 0; i < sketch.codeCount; i++) {
+5 -3
View File
@@ -106,12 +106,14 @@ public class EditorListener {
//System.out.println((int)c + " " + code + " " + event);
//System.out.println();
Sketch sketch = editor.getSketch();
if ((event.getModifiers() & CTRL_ALT) == CTRL_ALT) {
if (code == KeyEvent.VK_LEFT) {
editor.sketch.handlePrevCode();
sketch.handlePrevCode();
return true;
} else if (code == KeyEvent.VK_RIGHT) {
editor.sketch.handleNextCode();
sketch.handleNextCode();
return true;
}
}
@@ -125,7 +127,7 @@ public class EditorListener {
if (!editor.getSketch().isModified()) {
if ((code == KeyEvent.VK_BACK_SPACE) || (code == KeyEvent.VK_TAB) ||
(code == KeyEvent.VK_ENTER) || ((c >= 32) && (c < 128))) {
editor.sketch.setModified(true);
sketch.setModified(true);
}
}
+3 -3
View File
@@ -253,7 +253,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
// answering to rename/new code question
if (mode == EDIT) { // this if() isn't (shouldn't be?) necessary
String answer = editField.getText();
editor.sketch.nameCode(answer);
editor.getSketch().nameCode(answer);
unedit();
}
}
@@ -313,7 +313,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
if (c == KeyEvent.VK_ENTER) { // accept the input
String answer = editField.getText();
editor.sketch.nameCode(answer);
editor.getSketch().nameCode(answer);
unedit();
event.consume();
@@ -425,7 +425,7 @@ public class EditorStatus extends JPanel /*implements ActionListener*/ {
// answering to rename/new code question
if (mode == EDIT) { // this if() isn't (shouldn't be?) necessary
String answer = editField.getText();
editor.sketch.nameCode(answer);
editor.getSketch().nameCode(answer);
unedit();
}
}
+7 -7
View File
@@ -274,7 +274,7 @@ public class FindReplace extends JFrame implements ActionListener {
// this will catch "find next" being called when no search yet
if (search.length() == 0) return;
String text = editor.textarea.getText();
String text = editor.getText();
if (ignoreCase) {
search = search.toLowerCase();
@@ -282,7 +282,7 @@ public class FindReplace extends JFrame implements ActionListener {
}
//int selectionStart = editor.textarea.getSelectionStart();
int selectionEnd = editor.textarea.getSelectionStop();
int selectionEnd = editor.getSelectionStop();
int nextIndex = text.indexOf(search, selectionEnd);
if (nextIndex == -1) {
@@ -302,7 +302,7 @@ public class FindReplace extends JFrame implements ActionListener {
found = true;
replaceButton.setEnabled(true);
replaceFindButton.setEnabled(true);
editor.textarea.select(nextIndex, nextIndex + search.length());
editor.setSelection(nextIndex, nextIndex + search.length());
}
@@ -315,7 +315,7 @@ public class FindReplace extends JFrame implements ActionListener {
// check to see if the document has wrapped around
// otherwise this will cause an infinite loop
String sel = editor.textarea.getSelectedText();
String sel = editor.getSelectedText();
if (sel.equals(replaceField.getText())) {
found = false;
replaceButton.setEnabled(false);
@@ -323,10 +323,10 @@ public class FindReplace extends JFrame implements ActionListener {
return;
}
editor.textarea.setSelectedText(replaceField.getText());
editor.setSelectedText(replaceField.getText());
//editor.setSketchModified(true);
//editor.sketch.setCurrentModified(true);
editor.sketch.setModified(true);
editor.getSketch().setModified(true); // TODO is this necessary?
// don't allow a double replace
replaceButton.setEnabled(false);
@@ -340,7 +340,7 @@ public class FindReplace extends JFrame implements ActionListener {
*/
public void replaceAll() {
// move to the beginning
editor.textarea.select(0, 0);
editor.setSelection(0, 0);
do {
find(false);
+9 -9
View File
@@ -526,9 +526,9 @@ public class Sketch {
// (unfortunately this will kill positions for carets etc)
editor.handleOpenUnchecked(newMainFilePath,
currentIndex,
editor.textarea.getSelectionStart(),
editor.textarea.getSelectionStop(),
editor.textarea.getScrollPosition());
editor.getSelectionStart(),
editor.getSelectionStop(),
editor.getScrollPosition());
// get the changes into the sketchbook menu
// (re-enabled in 0115 to fix bug #332)
@@ -999,9 +999,9 @@ public class Sketch {
editor.handleOpenUnchecked(newFile.getPath(),
currentIndex,
editor.textarea.getSelectionStart(),
editor.textarea.getSelectionStop(),
editor.textarea.getScrollPosition());
editor.getSelectionStart(),
editor.getSelectionStop(),
editor.getScrollPosition());
// Name changed, rebuild the sketch menus
//editor.sketchbook.rebuildMenusAsync();
@@ -1234,9 +1234,9 @@ public class Sketch {
// get the text currently being edited
if (current != null) {
current.program = editor.getText();
current.selectionStart = editor.textarea.getSelectionStart();
current.selectionStop = editor.textarea.getSelectionStop();
current.scrollPosition = editor.textarea.getScrollPosition();
current.selectionStart = editor.getSelectionStart();
current.selectionStop = editor.getSelectionStop();
current.scrollPosition = editor.getScrollPosition();
}
current = code[which];