Search in sources :

Example 6 with Handle

use of processing.mode.java.tweak.Handle in project processing by processing.

the class JavaTextAreaPainter method paint.

@Override
public synchronized void paint(Graphics gfx) {
    super.paint(gfx);
    if (tweakMode && handles != null) {
        int currentTab = getCurrentCodeIndex();
        // enable anti-aliasing
        Graphics2D g2d = (Graphics2D) gfx;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        for (Handle n : handles.get(currentTab)) {
            // update n position and width, and draw it
            int lineStartChar = textArea.getLineStartOffset(n.line);
            int x = textArea.offsetToX(n.line, n.newStartChar - lineStartChar);
            int y = textArea.lineToY(n.line) + fm.getHeight() + 1;
            int end = textArea.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.get(currentTab)) {
            int lineStartChar = textArea.getLineStartOffset(cBox.getLine());
            int x = textArea.offsetToX(cBox.getLine(), cBox.getCharIndex() - lineStartChar);
            int y = textArea.lineToY(cBox.getLine()) + fm.getDescent();
            cBox.setPos(x, y + 1);
            cBox.draw(g2d);
        }
    }
}
Also used : ColorControlBox(processing.mode.java.tweak.ColorControlBox) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D) Handle(processing.mode.java.tweak.Handle)

Example 7 with Handle

use of processing.mode.java.tweak.Handle in project processing by processing.

the class JavaTextAreaPainter method updateCodeText.

/**
	 * Take the saved code of the current tab and replace
	 * all numbers with their current values.
	 * Update TextArea with the new code.
	 */
public void updateCodeText() {
    int charInc = 0;
    int currentTab = getCurrentCodeIndex();
    SketchCode sc = getEditor().getSketch().getCode(currentTab);
    String code = getJavaEditor().baseCode[currentTab];
    for (Handle n : handles.get(currentTab)) {
        int s = n.startChar + charInc;
        int e = n.endChar + charInc;
        code = replaceString(code, s, e, n.strNewValue);
        n.newStartChar = n.startChar + charInc;
        charInc += n.strNewValue.length() - n.strValue.length();
        n.newEndChar = n.endChar + charInc;
    }
    replaceTextAreaCode(code);
    // update also the sketch code for later
    sc.setProgram(code);
}
Also used : SketchCode(processing.app.SketchCode) Point(java.awt.Point) Handle(processing.mode.java.tweak.Handle)

Aggregations

Handle (processing.mode.java.tweak.Handle)7 Point (java.awt.Point)4 ColorControlBox (processing.mode.java.tweak.ColorControlBox)4 Cursor (java.awt.Cursor)2 SketchCode (processing.app.SketchCode)2 LineBreakpoint (processing.mode.java.debug.LineBreakpoint)2 Graphics2D (java.awt.Graphics2D)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 MouseMotionListener (java.awt.event.MouseMotionListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringList (processing.data.StringList)1 ColorSelector (processing.mode.java.tweak.ColorSelector)1 TweakClient (processing.mode.java.tweak.TweakClient)1