Skip to content

Commit e2409ac

Browse files
committed
some cleaning, plus refurb tweak mode code
1 parent 9388477 commit e2409ac

File tree

5 files changed

+80
-114
lines changed

5 files changed

+80
-114
lines changed

app/src/processing/app/Base.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ static public int showYesNoQuestion(Frame editor, String title,
21292129
JOptionPane.QUESTION_MESSAGE);
21302130

21312131
String[] options = new String[] {
2132-
"Yes", "No"
2132+
"Yes", "No"
21332133
};
21342134
pane.setOptions(options);
21352135

java/src/processing/mode/java/JavaEditor.java

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2689,49 +2689,32 @@ protected void applyPreferences() {
26892689
TweakClient tweakClient;
26902690

26912691

2692-
protected void startInteractiveMode() {
2693-
getJavaTextArea().startInteractiveMode();
2692+
protected void startTweakMode() {
2693+
getJavaTextArea().startTweakMode();
26942694
}
26952695

26962696

2697-
//public void stopInteractiveMode(ArrayList<Handle> handles[]) {
2698-
protected void stopInteractiveMode(List<List<Handle>> handles) {
2697+
protected void stopTweakMode(List<List<Handle>> handles) {
26992698
tweakClient.shutdown();
2700-
getJavaTextArea().stopInteractiveMode();
2699+
getJavaTextArea().stopTweakMode();
27012700

27022701
// remove space from the code (before and after)
27032702
//removeSpacesFromCode();
27042703

27052704
// check which tabs were modified
2706-
boolean modified = false;
2707-
boolean[] modifiedTabs = getModifiedTabs(handles);
2708-
for (boolean mod : modifiedTabs) {
2709-
if (mod) {
2710-
modified = true;
2711-
break;
2712-
}
2713-
}
2705+
boolean[] tweakedTabs = getTweakedTabs(handles);
2706+
boolean modified = anythingTrue(tweakedTabs);
27142707

27152708
if (modified) {
27162709
// ask to keep the values
2717-
int ret =
2718-
Base.showYesNoQuestion(this, Language.text("tweak_mode"),
2719-
Language.text("tweak_mode.keep_changes.line1"),
2720-
Language.text("tweak_mode.keep_changes.line2"));
2721-
if (ret == 1) {
2722-
// NO! don't keep changes
2723-
loadSavedCode();
2724-
// update the painter to draw the saved (old) code
2725-
textarea.invalidate();
2726-
2727-
} else {
2728-
// YES! keep changes
2729-
// the new values are already present, just make sure the user can save the modified tabs
2730-
for (int i=0; i<sketch.getCodeCount(); i++) {
2731-
if (modifiedTabs[i]) {
2710+
if (Base.showYesNoQuestion(this, Language.text("tweak_mode"),
2711+
Language.text("tweak_mode.keep_changes.line1"),
2712+
Language.text("tweak_mode.keep_changes.line2")) == JOptionPane.YES_OPTION) {
2713+
for (int i = 0; i < sketch.getCodeCount(); i++) {
2714+
if (tweakedTabs[i]) {
27322715
sketch.getCode(i).setModified(true);
2733-
}
2734-
else {
2716+
2717+
} else {
27352718
// load the saved code of tabs that didn't change
27362719
// (there might be formatting changes that should not be saved)
27372720
sketch.getCode(i).setProgram(sketch.getCode(i).getSavedProgram());
@@ -2756,6 +2739,11 @@ protected void stopInteractiveMode(List<List<Handle>> handles) {
27562739
// repaint the editor header (show the modified tabs)
27572740
header.repaint();
27582741
textarea.invalidate();
2742+
2743+
} else { // no or canceled = don't keep changes
2744+
loadSavedCode();
2745+
// update the painter to draw the saved (old) code
2746+
textarea.invalidate();
27592747
}
27602748
} else {
27612749
// number values were not modified but we need to load the saved code
@@ -2766,23 +2754,31 @@ protected void stopInteractiveMode(List<List<Handle>> handles) {
27662754
}
27672755

27682756

2757+
static private boolean anythingTrue(boolean[] list) {
2758+
for (boolean b : list) {
2759+
if (b) return true;
2760+
}
2761+
return false;
2762+
}
2763+
2764+
27692765
protected void updateInterface(List<List<Handle>> handles,
27702766
List<List<ColorControlBox>> colorBoxes) {
27712767
getJavaTextArea().updateInterface(handles, colorBoxes);
27722768
}
27732769

27742770

2775-
static private boolean[] getModifiedTabs(List<List<Handle>> handles) {
2776-
boolean[] modifiedTabs = new boolean[handles.size()];
2771+
static private boolean[] getTweakedTabs(List<List<Handle>> handles) {
2772+
boolean[] outgoing = new boolean[handles.size()];
27772773

27782774
for (int i = 0; i < handles.size(); i++) {
27792775
for (Handle h : handles.get(i)) {
27802776
if (h.valueChanged()) {
2781-
modifiedTabs[i] = true;
2777+
outgoing[i] = true;
27822778
}
27832779
}
27842780
}
2785-
return modifiedTabs;
2781+
return outgoing;
27862782
}
27872783

27882784

java/src/processing/mode/java/JavaMode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public void run() {
209209
// next lines are executed when the sketch quits
210210
if (launchInteractive) {
211211
editor.initEditorCode(parser.allHandles, false);
212-
editor.stopInteractiveMode(parser.allHandles);
212+
editor.stopTweakMode(parser.allHandles);
213213
}
214214
}
215215
}).start();
@@ -218,7 +218,7 @@ public void run() {
218218
// replace editor code with baseCode
219219
editor.initEditorCode(parser.allHandles, false);
220220
editor.updateInterface(parser.allHandles, parser.colorBoxes);
221-
editor.startInteractiveMode();
221+
editor.startTweakMode();
222222
}
223223
return runtime;
224224
}

java/src/processing/mode/java/pdex/JavaTextArea.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public JavaTextArea(TextAreaDefaults defaults, JavaEditor editor) {
143143
prevMMotionListeners = painter.getMouseMotionListeners();
144144
prevKeyListeners = editor.getKeyListeners();
145145

146-
interactiveMode = false;
146+
tweakMode = false;
147147
addPrevListeners();
148148
}
149149

@@ -856,14 +856,18 @@ public void hideSuggestion() {
856856
}
857857

858858

859-
// TweakMode code
859+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
860+
861+
// TWEAK MODE
862+
860863

861864
// save input listeners to stop/start text edit
862865
ComponentListener[] prevCompListeners;
863866
MouseListener[] prevMouseListeners;
864867
MouseMotionListener[] prevMMotionListeners;
865868
KeyListener[] prevKeyListeners;
866-
boolean interactiveMode;
869+
boolean tweakMode;
870+
867871

868872
/* remove all standard interaction listeners */
869873
public void removeAllListeners() {
@@ -887,33 +891,30 @@ public void removeAllListeners() {
887891
}
888892

889893

890-
public void startInteractiveMode() {
894+
public void startTweakMode() {
891895
// ignore if we are already in interactiveMode
892-
if (interactiveMode) return;
893-
894-
removeAllListeners();
895-
896-
// add our private interaction listeners
897-
getCustomPainter().startInterativeMode();
898-
this.editable = false;
899-
this.caretBlinks = false;
900-
this.setCaretVisible(false);
901-
interactiveMode = true;
896+
if (!tweakMode) {
897+
removeAllListeners();
898+
getCustomPainter().startTweakMode();
899+
this.editable = false;
900+
this.caretBlinks = false;
901+
this.setCaretVisible(false);
902+
tweakMode = true;
903+
}
902904
}
903905

904906

905-
public void stopInteractiveMode() {
907+
public void stopTweakMode() {
906908
// ignore if we are not in interactive mode
907-
if (!interactiveMode) return;
908-
909-
removeAllListeners();
910-
addPrevListeners();
911-
912-
getCustomPainter().stopInteractiveMode();
913-
this.editable = true;
914-
this.caretBlinks = true;
915-
this.setCaretVisible(true);
916-
interactiveMode = false;
909+
if (tweakMode) {
910+
removeAllListeners();
911+
addPrevListeners();
912+
getCustomPainter().stopTweakMode();
913+
editable = true;
914+
caretBlinks = true;
915+
setCaretVisible(true);
916+
tweakMode = false;
917+
}
917918
}
918919

919920

java/src/processing/mode/java/pdex/JavaTextAreaPainter.java

Lines changed: 21 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void mouseMoved(final MouseEvent evt) {
143143
});
144144

145145
// TweakMode code
146-
interactiveMode = false;
146+
tweakMode = false;
147147
cursorType = Cursor.DEFAULT_CURSOR;
148148
}
149149

@@ -577,9 +577,7 @@ public String getToolTipText(MouseEvent event) {
577577
// TweakMode code
578578
protected int horizontalAdjustment = 0;
579579

580-
public boolean interactiveMode = false;
581-
// public ArrayList<Handle> handles[];
582-
// public ArrayList<ColorControlBox> colorBoxes[];
580+
public boolean tweakMode = false;
583581
public List<List<Handle>> handles;
584582
public List<List<ColorControlBox>> colorBoxes;
585583

@@ -588,22 +586,19 @@ public String getToolTipText(MouseEvent event) {
588586

589587
int cursorType;
590588
BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
591-
592-
// Create a new blank cursor.
593-
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(
594-
cursorImg, new Point(0, 0), "blank cursor");
589+
Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "blank cursor");
595590

596591

597592
@Override
598593
synchronized public void paint(Graphics gfx) {
599594
super.paint(gfx);
600595

601-
if (interactiveMode && handles != null) {
596+
if (tweakMode && handles != null) {
602597
int currentTab = getCurrentCodeIndex();
603598
// enable anti-aliasing
604599
Graphics2D g2d = (Graphics2D)gfx;
605600
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
606-
RenderingHints.VALUE_ANTIALIAS_ON);
601+
RenderingHints.VALUE_ANTIALIAS_ON);
607602

608603
for (Handle n : handles.get(currentTab)) {
609604
// update n position and width, and draw it
@@ -628,32 +623,32 @@ synchronized public void paint(Graphics gfx) {
628623
}
629624

630625

631-
protected void startInterativeMode() {
626+
protected void startTweakMode() {
632627
addMouseListener(this);
633628
addMouseMotionListener(this);
634-
interactiveMode = true;
629+
tweakMode = true;
635630
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
636631
repaint();
637632
}
638633

639634

640-
protected void stopInteractiveMode() {
641-
interactiveMode = false;
635+
protected void stopTweakMode() {
636+
tweakMode = false;
642637

643638
if (colorSelector != null) {
644-
// close color selector
645639
colorSelector.hide();
646-
colorSelector.frame.dispatchEvent(new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING));
640+
WindowEvent windowEvent =
641+
new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING);
642+
colorSelector.frame.dispatchEvent(windowEvent);
647643
}
648644

649645
setCursor(new Cursor(Cursor.TEXT_CURSOR));
650646
repaint();
651647
}
652648

653649

654-
// Update the interface
655-
//public void updateInterface(ArrayList<Handle> handles[], ArrayList<ColorControlBox> colorBoxes[]) {
656-
protected void updateInterface(List<List<Handle>> handles, List<List<ColorControlBox>> colorBoxes) {
650+
protected void updateInterface(List<List<Handle>> handles,
651+
List<List<ColorControlBox>> colorBoxes) {
657652
this.handles = handles;
658653
this.colorBoxes = colorBoxes;
659654

@@ -835,13 +830,13 @@ public void mousePressed(MouseEvent e) {
835830

836831
colorSelector = new ColorSelector(box);
837832
colorSelector.frame.addWindowListener(new WindowAdapter() {
838-
public void windowClosing(WindowEvent e) {
839-
colorSelector.frame.setVisible(false);
840-
colorSelector = null;
841-
}
842-
});
843-
colorSelector.show(this.getLocationOnScreen().x + e.getX() + 30,
844-
this.getLocationOnScreen().y + e.getY() - 130);
833+
public void windowClosing(WindowEvent e) {
834+
colorSelector.frame.setVisible(false);
835+
colorSelector = null;
836+
}
837+
});
838+
colorSelector.show(getLocationOnScreen().x + e.getX() + 30,
839+
getLocationOnScreen().y + e.getY() - 130);
845840
}
846841
}
847842
}
@@ -894,33 +889,7 @@ private int getCurrentCodeIndex() {
894889
}
895890

896891

897-
// private int getGutterMargins() {
898-
// return ((JavaTextArea) textArea).getGutterMargins();
899-
// }
900-
901-
902-
// private int getGutterWidth() {
903-
// return ((JavaTextArea) textArea).getGutterWidth();
904-
// }
905-
906-
907892
private JavaTextArea getTextArea() {
908893
return (JavaTextArea) textArea;
909894
}
910-
911-
912-
// private Color getGutterBgColor() {
913-
// return ((JavaTextArea) textArea).gutterBgColor;
914-
// }
915-
916-
917-
// private boolean isDebugToolbarEnabled() {
918-
// AtomicBoolean enabled = getEditor().debugToolbarEnabled;
919-
// return (enabled != null && enabled.get());
920-
// }
921-
922-
923-
// private boolean hasJavaTabs() {
924-
// return getEditor().hasJavaTabs();
925-
// }
926895
}

0 commit comments

Comments
 (0)