src/com/caucho/ria/examples/words/WordNode.fx
/*
* Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
*
* This file is part of Resin(R) Open Source
*
* Each copy or derived work must preserve the copyright notice and this
* notice unmodified.
*
* Resin Open Source is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Resin Open Source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
* of NON-INFRINGEMENT. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with Resin Open Source; if not, write to the
*
* Free Software Foundation, Inc.
* 59 Temple Place, Suite 330
* Boston, MA 02111-1307 USA
*
* @author Emil Ong
*/
package com.caucho.ria.examples.words;
import javafx.ui.*;
import javafx.ui.canvas.*;
class WordNode extends CompositeNode {
attribute x: Number;
attribute y: Number;
attribute value: String;
attribute text: Text;
attribute word: Word;
attribute readOnly: Boolean;
}
operation WordNode.updatePosition(e:CanvasMouseEvent) {
if (not readOnly) {
x += e.localDragTranslation.x;
y += e.localDragTranslation.y;
if (x < 0) {
x = 0;
}
if (y < 0) {
y = 0;
}
if (x + text.currentWidth + 8 > 403) {
x = 403 - text.currentWidth - 8;
}
if (y + text.currentHeight + 8 > 199) {
y = 199 - text.currentHeight - 8;
}
if (x > 202) {
word.setUsed(true);
}
else {
word.setUsed(false);
}
}
}
attribute WordNode.text = Text {
x: bind x
y: bind y
content: bind value
onMouseDragged: operation(e:CanvasMouseEvent) {
updatePosition(e);
}
};
function WordNode.composeNode() = Group {
cursor: HAND
content: [
Rect {
x: bind x - 4
y: bind y - 5
width: bind text.currentWidth + 8
height: bind text.currentHeight + 8
arcHeight: 5
arcWidth: 5
stroke: black
fill: yellow
opacity: 1
onMouseDragged: operation(e:CanvasMouseEvent) {
updatePosition(e);
}
},
text
]
};
// Poor man's binding of JavaFX class to our Java class
trigger on WordNode.x[oldValue] = newValue {
word.setX(newValue);
}
trigger on WordNode.y[oldValue] = newValue {
word.setY(newValue);
}