diff --git a/pdex/src/galsasson/mode/tweak/TweakEditor.java b/pdex/src/galsasson/mode/tweak/TweakEditor.java deleted file mode 100644 index 0453d165a..000000000 --- a/pdex/src/galsasson/mode/tweak/TweakEditor.java +++ /dev/null @@ -1,472 +0,0 @@ -/* - Part of TweakMode project (https://github.com/galsasson/TweakMode) - - Under Google Summer of Code 2013 - - http://www.google-melange.com/gsoc/homepage/google/gsoc2013 - - Copyright (C) 2013 Gal Sasson - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 - as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package galsasson.mode.tweak; - -import java.awt.BorderLayout; -import java.awt.CardLayout; -import java.awt.Frame; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.regex.Pattern; - -import javax.swing.Box; -import javax.swing.JCheckBoxMenuItem; -import javax.swing.JFileChooser; -import javax.swing.JMenu; -import javax.swing.JMenuItem; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.border.EtchedBorder; -import javax.swing.table.TableModel; -import javax.swing.text.BadLocationException; - -import processing.app.Base; -import processing.app.EditorState; -import processing.app.EditorToolbar; -import processing.app.Mode; -import processing.app.Sketch; -import processing.app.SketchCode; -import processing.app.SketchException; -import processing.app.syntax.JEditTextArea; -import processing.app.syntax.PdeTextAreaDefaults; -import processing.app.syntax.SyntaxDocument; -import processing.mode.java.JavaBuild; -import processing.mode.java.JavaEditor; -import processing.mode.java.JavaToolbar; -import processing.mode.java.runner.Runner; - -/** - * Editor for STMode - * - * @author Gal Sasson <sasgal@gmail.com> - * - */ -public class TweakEditor extends JavaEditor -{ - TweakMode tweakMode; - - String[] baseCode; - - final static int SPACE_AMOUNT = 0; - - int oscPort; - - /** - * Custom TextArea - */ - protected TweakTextArea tweakTextArea; - - protected TweakEditor(Base base, String path, EditorState state, - final Mode mode) { - super(base, path, state, mode); - - tweakMode = (TweakMode)mode; - - // random port for OSC (0xff0 - 0xfff0) - oscPort = (int)(Math.random()*0xf000) + 0xff0; - } - - public EditorToolbar createToolbar() { - return new TweakToolbar(this, base); - } - - /** - * Override creation of the default textarea. - */ - protected JEditTextArea createTextArea() { - tweakTextArea = new TweakTextArea(this, new PdeTextAreaDefaults(mode)); - return tweakTextArea; - } - - public JMenu buildModeMenu() { - JMenu menu = new JMenu("Tweak"); - JCheckBoxMenuItem item; - - item = new JCheckBoxMenuItem("Dump modified code"); - item.setSelected(false); - item.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - tweakMode.dumpModifiedCode = ((JCheckBoxMenuItem)e.getSource()).isSelected(); - } - }); - menu.add(item); - - return menu; - } - - public void startInteractiveMode() - { - tweakTextArea.startInteractiveMode(); - } - - public void stopInteractiveMode(ArrayList handles[]) - { - tweakTextArea.stopInteractiveMode(); - - // 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; - } - } - - if (modified) { - // ask to keep the values - int ret = Base.showYesNoQuestion(this, "Tweak Mode", - "Keep the changes?", - "You changed some values in your sketch. Would you like to keep the changes?"); - if (ret == 1) { - // NO! don't keep changes - loadSavedCode(); - // update the painter to draw the saved (old) code - tweakTextArea.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 handles[], ArrayList colorBoxes[]) - { - // set OSC port of handles - for (int i=0; i handles[]) - { - boolean[] modifiedTabs = new boolean[handles.length]; - - for (int i=0; i handles[], boolean withSpaces) - { - SketchCode[] sketchCode = sketch.getCode(); - for (int tab=0; tab handles[]) - { - SketchCode[] code = sketch.getCode(); - - if (code.length<1) - return false; - - if (handles.length == 0) - return false; - - int setupStartPos = SketchParser.getSetupStart(baseCode[0]); - if (setupStartPos < 0) { - return false; - } - - // Copy current program to interactive program - - /* modify the code below, replace all numbers with their variable names */ - // loop through all tabs in the current sketch - for (int tab=0; tab 0) { - header += "int[] tweakmode_int = new int["+numOfInts+"];\n"; - } - if (numOfFloats > 0) { - header += "float[] tweakmode_float = new float["+numOfFloats+"];\n\n"; - } - - /* add the class for the OSC event handler that will respond to our messages */ - header += "public class TweakMode_OscHandler {\n" + - " public void oscEvent(OscMessage msg) {\n" + - " String type = msg.addrPattern();\n"; - if (numOfInts > 0) { - header += " if (type.contains(\"/tm_change_int\")) {\n" + - " int index = msg.get(0).intValue();\n" + - " int value = msg.get(1).intValue();\n" + - " tweakmode_int[index] = value;\n" + - " }\n"; - if (numOfFloats > 0) { - header += " else "; - } - } - if (numOfFloats > 0) { - header += "if (type.contains(\"/tm_change_float\")) {\n" + - " int index = msg.get(0).intValue();\n" + - " float value = msg.get(1).floatValue();\n" + - " tweakmode_float[index] = value;\n" + - " }\n"; - } - header += " }\n" + - "}\n"; - header += "TweakMode_OscHandler tweakmode_oscHandler = new TweakMode_OscHandler();\n"; - - header += "void tweakmode_initAllVars() {\n"; - for (int i=0; i handles[]) - { - int count = 0; - for (int i=0; i handles[]) - { - int count = 0; - for (int i=0; i Import Library --> Add Library ...\" and choose 'ocsP5'", null); - - return false; - } - - private boolean isSketchModified(Sketch sketch) - { - for (SketchCode sc : sketch.getCode()) { - if (sc.isModified()) { - return true; - } - } - return false; - } -} diff --git a/pdex/src/galsasson/mode/tweak/TweakTextArea.java b/pdex/src/galsasson/mode/tweak/TweakTextArea.java deleted file mode 100644 index c6328cfdf..000000000 --- a/pdex/src/galsasson/mode/tweak/TweakTextArea.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - Part of TweakMode project (https://github.com/galsasson/TweakMode) - - Under Google Summer of Code 2013 - - http://www.google-melange.com/gsoc/homepage/google/gsoc2013 - - Copyright (C) 2013 Gal Sasson - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 - as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package galsasson.mode.tweak; - -import java.awt.Cursor; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.event.ComponentListener; -import java.awt.event.KeyListener; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.util.ArrayList; - -import processing.app.Editor; -import processing.app.syntax.JEditTextArea; -import processing.app.syntax.SyntaxDocument; -import processing.app.syntax.SyntaxStyle; -import processing.app.syntax.TextAreaDefaults; -import processing.app.syntax.Token; -import processing.app.syntax.TokenMarker; - -/** - * Custom TextArea for Tweak Mode - * - * @author Gal Sasson <sasgal@gmail.com> - * - */ -public class TweakTextArea extends JEditTextArea { - public Editor editor; - TweakTextAreaPainter tweakPainter; - - // save input listeners to stop/start text edit - ComponentListener[] prevCompListeners; - MouseListener[] prevMouseListeners; - MouseMotionListener[] prevMMotionListeners; - KeyListener[] prevKeyListeners; - - boolean interactiveMode; - - public TweakTextArea(Editor editor, TextAreaDefaults defaults) { - super(defaults); - this.editor = editor; - prevCompListeners = painter - .getComponentListeners(); - prevMouseListeners = painter.getMouseListeners(); - prevMMotionListeners = painter - .getMouseMotionListeners(); - prevKeyListeners = editor.getKeyListeners(); - - remove(painter); - - tweakPainter = new TweakTextAreaPainter(this, defaults); - painter = tweakPainter; - - interactiveMode = false; - addPrevListeners(); - - add(CENTER, painter); - } - - /** - * Set document with a twist, includes the old caret - * and scroll positions, added for p5. [fry] - * - verify that start and stop fall inside the document [gal] - */ - @Override - public void setDocument(SyntaxDocument document, - int start, int stop, int scroll) { - if (this.document == document) - return; - if (this.document != null) - this.document.removeDocumentListener(documentHandler); - this.document = document; - - document.addDocumentListener(documentHandler); - - if (start > document.getLength()) - start = document.getLength(); - if (stop > document.getLength()) - stop = document.getLength(); - - select(start, stop); - updateScrollBars(); - setScrollPosition(scroll); - painter.repaint(); - } - - - /* remove all standard interaction listeners */ - public void removeAllListeners() - { - ComponentListener[] componentListeners = painter - .getComponentListeners(); - MouseListener[] mouseListeners = painter.getMouseListeners(); - MouseMotionListener[] mouseMotionListeners = painter - .getMouseMotionListeners(); - KeyListener[] keyListeners = editor.getKeyListeners(); - - for (ComponentListener cl : componentListeners) - painter.removeComponentListener(cl); - - for (MouseListener ml : mouseListeners) - painter.removeMouseListener(ml); - - for (MouseMotionListener mml : mouseMotionListeners) - painter.removeMouseMotionListener(mml); - - for (KeyListener kl : keyListeners) { - editor.removeKeyListener(kl); - } - } - - public void startInteractiveMode() - { - // ignore if we are already in interactiveMode - if (interactiveMode) - return; - - removeAllListeners(); - - // add our private interaction listeners - tweakPainter.addMouseListener(tweakPainter); - tweakPainter.addMouseMotionListener(tweakPainter); - tweakPainter.startInterativeMode(); - painter.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - this.editable = false; - this.caretBlinks = false; - this.setCaretVisible(false); - interactiveMode = true; - } - - public void stopInteractiveMode() - { - // ignore if we are not in interactive mode - if (!interactiveMode) - return; - - removeAllListeners(); - addPrevListeners(); - - tweakPainter.stopInteractiveMode(); - painter.setCursor(new Cursor(Cursor.TEXT_CURSOR)); - this.editable = true; - this.caretBlinks = true; - this.setCaretVisible(true); - - interactiveMode = false; - } - - public int getHorizontalScroll() - { - return horizontal.getValue(); - } - - private void addPrevListeners() - { - // add the original text-edit listeners - for (ComponentListener cl : prevCompListeners) { - painter.addComponentListener(cl); - } - for (MouseListener ml : prevMouseListeners) { - painter.addMouseListener(ml); - } - for (MouseMotionListener mml : prevMMotionListeners) { - painter.addMouseMotionListener(mml); - } - for (KeyListener kl : prevKeyListeners) { - editor.addKeyListener(kl); - } - } - - public void updateInterface(ArrayList handles[], ArrayList colorBoxes[]) - { - tweakPainter.updateInterface(handles, colorBoxes); - } - -} diff --git a/pdex/src/galsasson/mode/tweak/TweakTextAreaPainter.java b/pdex/src/galsasson/mode/tweak/TweakTextAreaPainter.java deleted file mode 100644 index 3b49e5d75..000000000 --- a/pdex/src/galsasson/mode/tweak/TweakTextAreaPainter.java +++ /dev/null @@ -1,386 +0,0 @@ -/* - Part of TweakMode project (https://github.com/galsasson/TweakMode) - - Under Google Summer of Code 2013 - - http://www.google-melange.com/gsoc/homepage/google/gsoc2013 - - Copyright (C) 2013 Gal Sasson - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 - as published by the Free Software Foundation. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -package galsasson.mode.tweak; - -import java.awt.Color; -import java.awt.Cursor; -import java.awt.Graphics; -import java.awt.Graphics2D; -import java.awt.Point; -import java.awt.RenderingHints; -import java.awt.Toolkit; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.awt.image.ImageObserver; -import java.util.ArrayList; - -import javax.swing.text.BadLocationException; -import javax.swing.text.DefaultCaret; - -import processing.app.SketchCode; -import processing.app.syntax.JEditTextArea; -import processing.app.syntax.SyntaxDocument; -import processing.app.syntax.TextAreaDefaults; -import processing.app.syntax.TextAreaPainter; -import processing.app.syntax.TokenMarker; - -/** - * Custom painter for XQTextArea. Handles underlining of error lines. - * - * @author Gal Sasson <sasgal@gmail.com> - * - */ -public class TweakTextAreaPainter extends TextAreaPainter - implements MouseListener, MouseMotionListener { - - protected TweakTextArea ta; - protected int horizontalAdjustment = 0; - - public boolean interactiveMode = false; - public ArrayList handles[]; - public ArrayList colorBoxes[]; - - public Handle mouseHandle = null; - public ColorSelector colorSelector; - - 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"); - - private final Object paintMutex = new Object(); - - public TweakTextAreaPainter(TweakTextArea textArea, TextAreaDefaults defaults) - { - super((JEditTextArea)textArea, defaults); - ta = textArea; - interactiveMode = false; - cursorType = Cursor.DEFAULT_CURSOR; - } - - /** - * Repaints the text. - * @param gfx The graphics context - */ - @Override - public synchronized void paint(Graphics gfx) - { - super.paint(gfx); - - if (interactiveMode && handles!=null) - { - int currentTab = ta.editor.getSketch().getCurrentCodeIndex(); - // enable anti-aliasing - Graphics2D g2d = (Graphics2D)gfx; - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, - RenderingHints.VALUE_ANTIALIAS_ON); - - for (Handle n : handles[currentTab]) - { - // update n position and width, and draw it - int lineStartChar = ta.getLineStartOffset(n.line); - int x = ta.offsetToX(n.line, n.newStartChar - lineStartChar); - int y = ta.lineToY(n.line) + fm.getHeight() + 1; - int end = ta.offsetToX(n.line, n.newEndChar - lineStartChar); - n.setPos(x, y); - n.setWidth(end - x); - n.draw(g2d, n==mouseHandle); - } - - // draw color boxes - for (ColorControlBox cBox: colorBoxes[currentTab]) - { - int lineStartChar = ta.getLineStartOffset(cBox.getLine()); - int x = ta.offsetToX(cBox.getLine(), cBox.getCharIndex() - lineStartChar); - int y = ta.lineToY(cBox.getLine()) + fm.getDescent(); - cBox.setPos(x, y+1); - cBox.draw(g2d); - } - } - } - - public void startInterativeMode() - { - interactiveMode = true; - repaint(); - } - - public void stopInteractiveMode() - { - interactiveMode = false; - - if (colorSelector != null) { - // close color selector - colorSelector.hide(); - colorSelector.frame.dispatchEvent(new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING)); - } - - repaint(); - } - - // Update the interface - public void updateInterface(ArrayList handles[], ArrayList colorBoxes[]) - { - this.handles = handles; - this.colorBoxes = colorBoxes; - - initInterfacePositions(); - repaint(); - } - - /** - * Initialize all the number changing interfaces. - * synchronize this method to prevent the execution of 'paint' in the middle. - * (don't paint while we make changes to the text of the editor) - */ - public synchronized void initInterfacePositions() - { - SketchCode[] code = ta.editor.getSketch().getCode(); - int prevScroll = ta.getScrollPosition(); - String prevText = ta.getText(); - - for (int tab=0; tab