Search in sources :

Example 1 with ColorControlBox

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

the class JavaTextAreaPainter method startTweakMode.

protected void startTweakMode() {
    addMouseListener(new MouseListener() {

        @Override
        public void mouseReleased(MouseEvent e) {
            if (mouseHandle != null) {
                mouseHandle.resetProgress();
                mouseHandle = null;
                updateCursor(e.getX(), e.getY());
                repaint();
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            int currentTab = getCurrentCodeIndex();
            // check for clicks on number handles
            for (Handle n : handles.get(currentTab)) {
                if (n.pick(e.getX(), e.getY())) {
                    cursorType = -1;
                    JavaTextAreaPainter.this.setCursor(blankCursor);
                    mouseHandle = n;
                    mouseHandle.setCenterX(e.getX());
                    repaint();
                    return;
                }
            }
            // check for clicks on color boxes
            for (ColorControlBox box : colorBoxes.get(currentTab)) {
                if (box.pick(e.getX(), e.getY())) {
                    if (colorSelector != null) {
                        // we already show a color selector, close it
                        colorSelector.frame.dispatchEvent(new WindowEvent(colorSelector.frame, WindowEvent.WINDOW_CLOSING));
                    }
                    colorSelector = new ColorSelector(box);
                    colorSelector.frame.addWindowListener(new WindowAdapter() {

                        public void windowClosing(WindowEvent e) {
                            colorSelector.frame.setVisible(false);
                            colorSelector = null;
                        }
                    });
                    colorSelector.show(getLocationOnScreen().x + e.getX() + 30, getLocationOnScreen().y + e.getY() - 130);
                }
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    });
    addMouseMotionListener(new MouseMotionListener() {

        @Override
        public void mouseMoved(MouseEvent e) {
            updateCursor(e.getX(), e.getY());
            if (!Settings.alwaysShowColorBoxes) {
                showHideColorBoxes(e.getY());
            }
        }

        @Override
        public void mouseDragged(MouseEvent e) {
            if (mouseHandle != null) {
                // set the current drag amount of the arrows
                mouseHandle.setCurrentX(e.getX());
                // update code text with the new value
                updateCodeText();
                if (colorSelector != null) {
                    colorSelector.refreshColor();
                }
                repaint();
            }
        }
    });
    tweakMode = true;
    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    repaint();
}
Also used : MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) ColorControlBox(processing.mode.java.tweak.ColorControlBox) ColorSelector(processing.mode.java.tweak.ColorSelector) MouseMotionListener(java.awt.event.MouseMotionListener) Cursor(java.awt.Cursor) Handle(processing.mode.java.tweak.Handle)

Example 2 with ColorControlBox

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

the class JavaTextAreaPainter method updateCursor.

private void updateCursor(int mouseX, int mouseY) {
    int currentTab = getCurrentCodeIndex();
    for (Handle n : handles.get(currentTab)) {
        if (n.pick(mouseX, mouseY)) {
            cursorType = Cursor.W_RESIZE_CURSOR;
            setCursor(new Cursor(cursorType));
            return;
        }
    }
    for (ColorControlBox colorBox : colorBoxes.get(currentTab)) {
        if (colorBox.pick(mouseX, mouseY)) {
            cursorType = Cursor.HAND_CURSOR;
            setCursor(new Cursor(cursorType));
            return;
        }
    }
    if (cursorType == Cursor.W_RESIZE_CURSOR || cursorType == Cursor.HAND_CURSOR || cursorType == -1) {
        cursorType = Cursor.DEFAULT_CURSOR;
        setCursor(new Cursor(cursorType));
    }
}
Also used : ColorControlBox(processing.mode.java.tweak.ColorControlBox) Cursor(java.awt.Cursor) Point(java.awt.Point) Handle(processing.mode.java.tweak.Handle)

Example 3 with ColorControlBox

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

the class JavaTextAreaPainter method showHideColorBoxes.

private void showHideColorBoxes(int y) {
    // display the box if the mouse if in the same line.
    // always keep the color box of the color selector.
    int currentTab = getCurrentCodeIndex();
    boolean change = false;
    for (ColorControlBox box : colorBoxes.get(currentTab)) {
        if (box.setMouseY(y)) {
            change = true;
        }
    }
    if (colorSelector != null) {
        colorSelector.colorBox.visible = true;
    }
    if (change) {
        repaint();
    }
}
Also used : ColorControlBox(processing.mode.java.tweak.ColorControlBox) Point(java.awt.Point)

Example 4 with ColorControlBox

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

the class JavaTextAreaPainter method updateTweakInterfacePositions.

/**
	* 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)
	*/
private synchronized void updateTweakInterfacePositions() {
    SketchCode[] code = getEditor().getSketch().getCode();
    int prevScroll = textArea.getVerticalScrollPosition();
    String prevText = textArea.getText();
    for (int tab = 0; tab < code.length; tab++) {
        String tabCode = getJavaEditor().baseCode[tab];
        textArea.setText(tabCode);
        for (Handle n : handles.get(tab)) {
            int lineStartChar = textArea.getLineStartOffset(n.line);
            int x = textArea.offsetToX(n.line, n.newStartChar - lineStartChar);
            int end = textArea.offsetToX(n.line, n.newEndChar - lineStartChar);
            int y = textArea.lineToY(n.line) + fm.getHeight() + 1;
            n.initInterface(x, y, end - x, fm.getHeight());
        }
        for (ColorControlBox cBox : colorBoxes.get(tab)) {
            int lineStartChar = textArea.getLineStartOffset(cBox.getLine());
            int x = textArea.offsetToX(cBox.getLine(), cBox.getCharIndex() - lineStartChar);
            int y = textArea.lineToY(cBox.getLine()) + fm.getDescent();
            cBox.initInterface(this, x, y + 1, fm.getHeight() - 2, fm.getHeight() - 2);
        }
    }
    textArea.setText(prevText);
    textArea.scrollTo(prevScroll, 0);
}
Also used : SketchCode(processing.app.SketchCode) ColorControlBox(processing.mode.java.tweak.ColorControlBox) Point(java.awt.Point) Handle(processing.mode.java.tweak.Handle)

Example 5 with ColorControlBox

use of processing.mode.java.tweak.ColorControlBox 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)

Aggregations

ColorControlBox (processing.mode.java.tweak.ColorControlBox)5 Point (java.awt.Point)4 Handle (processing.mode.java.tweak.Handle)4 Cursor (java.awt.Cursor)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 SketchCode (processing.app.SketchCode)1 ColorSelector (processing.mode.java.tweak.ColorSelector)1