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();
}
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));
}
}
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();
}
}
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);
}
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);
}
}
}
Aggregations