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