Search in sources :

Example 1 with ColorSelector

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

Aggregations

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