mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 22:29:18 +01:00
some cleaning, plus refurb tweak mode code
This commit is contained in:
@@ -2689,49 +2689,32 @@ public class JavaEditor extends Editor {
|
||||
TweakClient tweakClient;
|
||||
|
||||
|
||||
protected void startInteractiveMode() {
|
||||
getJavaTextArea().startInteractiveMode();
|
||||
protected void startTweakMode() {
|
||||
getJavaTextArea().startTweakMode();
|
||||
}
|
||||
|
||||
|
||||
//public void stopInteractiveMode(ArrayList<Handle> handles[]) {
|
||||
protected void stopInteractiveMode(List<List<Handle>> handles) {
|
||||
protected void stopTweakMode(List<List<Handle>> handles) {
|
||||
tweakClient.shutdown();
|
||||
getJavaTextArea().stopInteractiveMode();
|
||||
getJavaTextArea().stopTweakMode();
|
||||
|
||||
// remove space from the code (before and after)
|
||||
//removeSpacesFromCode();
|
||||
|
||||
// check which tabs were modified
|
||||
boolean modified = false;
|
||||
boolean[] modifiedTabs = getModifiedTabs(handles);
|
||||
for (boolean mod : modifiedTabs) {
|
||||
if (mod) {
|
||||
modified = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
boolean[] tweakedTabs = getTweakedTabs(handles);
|
||||
boolean modified = anythingTrue(tweakedTabs);
|
||||
|
||||
if (modified) {
|
||||
// ask to keep the values
|
||||
int ret =
|
||||
Base.showYesNoQuestion(this, Language.text("tweak_mode"),
|
||||
Language.text("tweak_mode.keep_changes.line1"),
|
||||
Language.text("tweak_mode.keep_changes.line2"));
|
||||
if (ret == 1) {
|
||||
// NO! don't keep changes
|
||||
loadSavedCode();
|
||||
// update the painter to draw the saved (old) code
|
||||
textarea.invalidate();
|
||||
|
||||
} else {
|
||||
// YES! keep changes
|
||||
// the new values are already present, just make sure the user can save the modified tabs
|
||||
for (int i=0; i<sketch.getCodeCount(); i++) {
|
||||
if (modifiedTabs[i]) {
|
||||
if (Base.showYesNoQuestion(this, Language.text("tweak_mode"),
|
||||
Language.text("tweak_mode.keep_changes.line1"),
|
||||
Language.text("tweak_mode.keep_changes.line2")) == JOptionPane.YES_OPTION) {
|
||||
for (int i = 0; i < sketch.getCodeCount(); i++) {
|
||||
if (tweakedTabs[i]) {
|
||||
sketch.getCode(i).setModified(true);
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
// load the saved code of tabs that didn't change
|
||||
// (there might be formatting changes that should not be saved)
|
||||
sketch.getCode(i).setProgram(sketch.getCode(i).getSavedProgram());
|
||||
@@ -2756,6 +2739,11 @@ public class JavaEditor extends Editor {
|
||||
// repaint the editor header (show the modified tabs)
|
||||
header.repaint();
|
||||
textarea.invalidate();
|
||||
|
||||
} else { // no or canceled = don't keep changes
|
||||
loadSavedCode();
|
||||
// update the painter to draw the saved (old) code
|
||||
textarea.invalidate();
|
||||
}
|
||||
} else {
|
||||
// number values were not modified but we need to load the saved code
|
||||
@@ -2766,23 +2754,31 @@ public class JavaEditor extends Editor {
|
||||
}
|
||||
|
||||
|
||||
static private boolean anythingTrue(boolean[] list) {
|
||||
for (boolean b : list) {
|
||||
if (b) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected void updateInterface(List<List<Handle>> handles,
|
||||
List<List<ColorControlBox>> colorBoxes) {
|
||||
getJavaTextArea().updateInterface(handles, colorBoxes);
|
||||
}
|
||||
|
||||
|
||||
static private boolean[] getModifiedTabs(List<List<Handle>> handles) {
|
||||
boolean[] modifiedTabs = new boolean[handles.size()];
|
||||
static private boolean[] getTweakedTabs(List<List<Handle>> handles) {
|
||||
boolean[] outgoing = new boolean[handles.size()];
|
||||
|
||||
for (int i = 0; i < handles.size(); i++) {
|
||||
for (Handle h : handles.get(i)) {
|
||||
if (h.valueChanged()) {
|
||||
modifiedTabs[i] = true;
|
||||
outgoing[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return modifiedTabs;
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ public class JavaMode extends Mode {
|
||||
// next lines are executed when the sketch quits
|
||||
if (launchInteractive) {
|
||||
editor.initEditorCode(parser.allHandles, false);
|
||||
editor.stopInteractiveMode(parser.allHandles);
|
||||
editor.stopTweakMode(parser.allHandles);
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
@@ -218,7 +218,7 @@ public class JavaMode extends Mode {
|
||||
// replace editor code with baseCode
|
||||
editor.initEditorCode(parser.allHandles, false);
|
||||
editor.updateInterface(parser.allHandles, parser.colorBoxes);
|
||||
editor.startInteractiveMode();
|
||||
editor.startTweakMode();
|
||||
}
|
||||
return runtime;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ public class JavaTextArea extends JEditTextArea {
|
||||
prevMMotionListeners = painter.getMouseMotionListeners();
|
||||
prevKeyListeners = editor.getKeyListeners();
|
||||
|
||||
interactiveMode = false;
|
||||
tweakMode = false;
|
||||
addPrevListeners();
|
||||
}
|
||||
|
||||
@@ -856,14 +856,18 @@ public class JavaTextArea extends JEditTextArea {
|
||||
}
|
||||
|
||||
|
||||
// TweakMode code
|
||||
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
||||
|
||||
// TWEAK MODE
|
||||
|
||||
|
||||
// save input listeners to stop/start text edit
|
||||
ComponentListener[] prevCompListeners;
|
||||
MouseListener[] prevMouseListeners;
|
||||
MouseMotionListener[] prevMMotionListeners;
|
||||
KeyListener[] prevKeyListeners;
|
||||
boolean interactiveMode;
|
||||
boolean tweakMode;
|
||||
|
||||
|
||||
/* remove all standard interaction listeners */
|
||||
public void removeAllListeners() {
|
||||
@@ -887,33 +891,30 @@ public class JavaTextArea extends JEditTextArea {
|
||||
}
|
||||
|
||||
|
||||
public void startInteractiveMode() {
|
||||
public void startTweakMode() {
|
||||
// ignore if we are already in interactiveMode
|
||||
if (interactiveMode) return;
|
||||
|
||||
removeAllListeners();
|
||||
|
||||
// add our private interaction listeners
|
||||
getCustomPainter().startInterativeMode();
|
||||
this.editable = false;
|
||||
this.caretBlinks = false;
|
||||
this.setCaretVisible(false);
|
||||
interactiveMode = true;
|
||||
if (!tweakMode) {
|
||||
removeAllListeners();
|
||||
getCustomPainter().startTweakMode();
|
||||
this.editable = false;
|
||||
this.caretBlinks = false;
|
||||
this.setCaretVisible(false);
|
||||
tweakMode = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void stopInteractiveMode() {
|
||||
public void stopTweakMode() {
|
||||
// ignore if we are not in interactive mode
|
||||
if (!interactiveMode) return;
|
||||
|
||||
removeAllListeners();
|
||||
addPrevListeners();
|
||||
|
||||
getCustomPainter().stopInteractiveMode();
|
||||
this.editable = true;
|
||||
this.caretBlinks = true;
|
||||
this.setCaretVisible(true);
|
||||
interactiveMode = false;
|
||||
if (tweakMode) {
|
||||
removeAllListeners();
|
||||
addPrevListeners();
|
||||
getCustomPainter().stopTweakMode();
|
||||
editable = true;
|
||||
caretBlinks = true;
|
||||
setCaretVisible(true);
|
||||
tweakMode = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
});
|
||||
|
||||
// TweakMode code
|
||||
interactiveMode = false;
|
||||
tweakMode = false;
|
||||
cursorType = Cursor.DEFAULT_CURSOR;
|
||||
}
|
||||
|
||||
@@ -577,9 +577,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
// TweakMode code
|
||||
protected int horizontalAdjustment = 0;
|
||||
|
||||
public boolean interactiveMode = false;
|
||||
// public ArrayList<Handle> handles[];
|
||||
// public ArrayList<ColorControlBox> colorBoxes[];
|
||||
public boolean tweakMode = false;
|
||||
public List<List<Handle>> handles;
|
||||
public List<List<ColorControlBox>> colorBoxes;
|
||||
|
||||
@@ -588,22 +586,19 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
|
||||
int cursorType;
|
||||
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
|
||||
// Create a new blank cursor.
|
||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
|
||||
cursorImg, new Point(0, 0), "blank cursor");
|
||||
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
|
||||
|
||||
|
||||
@Override
|
||||
synchronized public void paint(Graphics gfx) {
|
||||
super.paint(gfx);
|
||||
|
||||
if (interactiveMode && handles != null) {
|
||||
if (tweakMode && handles != null) {
|
||||
int currentTab = getCurrentCodeIndex();
|
||||
// enable anti-aliasing
|
||||
Graphics2D g2d = (Graphics2D)gfx;
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
for (Handle n : handles.get(currentTab)) {
|
||||
// update n position and width, and draw it
|
||||
@@ -628,22 +623,23 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
}
|
||||
|
||||
|
||||
protected void startInterativeMode() {
|
||||
protected void startTweakMode() {
|
||||
addMouseListener(this);
|
||||
addMouseMotionListener(this);
|
||||
interactiveMode = true;
|
||||
tweakMode = true;
|
||||
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
protected void stopInteractiveMode() {
|
||||
interactiveMode = false;
|
||||
protected void stopTweakMode() {
|
||||
tweakMode = false;
|
||||
|
||||
if (colorSelector != null) {
|
||||
// close color selector
|
||||
colorSelector.hide();
|
||||
colorSelector.frame.dispatchEvent(new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING));
|
||||
WindowEvent windowEvent =
|
||||
new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING);
|
||||
colorSelector.frame.dispatchEvent(windowEvent);
|
||||
}
|
||||
|
||||
setCursor(new Cursor(Cursor.TEXT_CURSOR));
|
||||
@@ -651,9 +647,8 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
}
|
||||
|
||||
|
||||
// Update the interface
|
||||
//public void updateInterface(ArrayList<Handle> handles[], ArrayList<ColorControlBox> colorBoxes[]) {
|
||||
protected void updateInterface(List<List<Handle>> handles, List<List<ColorControlBox>> colorBoxes) {
|
||||
protected void updateInterface(List<List<Handle>> handles,
|
||||
List<List<ColorControlBox>> colorBoxes) {
|
||||
this.handles = handles;
|
||||
this.colorBoxes = colorBoxes;
|
||||
|
||||
@@ -835,13 +830,13 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
|
||||
colorSelector = new ColorSelector(box);
|
||||
colorSelector.frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
colorSelector.frame.setVisible(false);
|
||||
colorSelector = null;
|
||||
}
|
||||
});
|
||||
colorSelector.show(this.getLocationOnScreen().x + e.getX() + 30,
|
||||
this.getLocationOnScreen().y + e.getY() - 130);
|
||||
public void windowClosing(WindowEvent e) {
|
||||
colorSelector.frame.setVisible(false);
|
||||
colorSelector = null;
|
||||
}
|
||||
});
|
||||
colorSelector.show(getLocationOnScreen().x + e.getX() + 30,
|
||||
getLocationOnScreen().y + e.getY() - 130);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -894,33 +889,7 @@ public class JavaTextAreaPainter extends TextAreaPainter
|
||||
}
|
||||
|
||||
|
||||
// private int getGutterMargins() {
|
||||
// return ((JavaTextArea) textArea).getGutterMargins();
|
||||
// }
|
||||
|
||||
|
||||
// private int getGutterWidth() {
|
||||
// return ((JavaTextArea) textArea).getGutterWidth();
|
||||
// }
|
||||
|
||||
|
||||
private JavaTextArea getTextArea() {
|
||||
return (JavaTextArea) textArea;
|
||||
}
|
||||
|
||||
|
||||
// private Color getGutterBgColor() {
|
||||
// return ((JavaTextArea) textArea).gutterBgColor;
|
||||
// }
|
||||
|
||||
|
||||
// private boolean isDebugToolbarEnabled() {
|
||||
// AtomicBoolean enabled = getEditor().debugToolbarEnabled;
|
||||
// return (enabled != null && enabled.get());
|
||||
// }
|
||||
|
||||
|
||||
// private boolean hasJavaTabs() {
|
||||
// return getEditor().hasJavaTabs();
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user