我正在尝试一些 Piccolo 来创建一个可缩放的界面。
我正在画布上创建一个矩形,上面有一些 PText。现在缩放时,我想将文本更改为不同的内容。
我在我的初始化中做到了这一点:
//
//specify the current Piccolo PCanvas
//
m_canvas = getCanvas();
m_canvas.removeInputEventListener(m_canvas.getPanEventHandler());
//m_canvas.addInputEventListener(new ClickAndDragHandler(m_canvas));
//
//add nodes to the collection -> adding to the collection = adding to the canvas
//
m_nodecollection = new NodeCollection(m_canvas);
RectangleNode node_links = new RectangleNode();
node_links.setBounds(10, 10, 500, 500);
m_nodecollection.addNode(node_links);
RectangleNode node_rechts = new RectangleNode();
node_rechts.setBounds(600,10,500,500);
m_nodecollection.addNode(node_rechts);
PImage node_arrowLeft = new PImage("left.gif");
node_arrowLeft.setBounds(600, 550, node_arrowLeft.getWidth(), node_arrowLeft.getHeight());
m_nodecollection.addNode(node_arrowLeft);
PImage node_arrowRight = new PImage("right.gif");
node_arrowRight.setBounds(680, 550, node_arrowRight.getWidth(), node_arrowRight.getHeight());
m_nodecollection.addNode(node_arrowRight);
m_nodecollection.connectNodesWithLine(node_rechts, node_arrowRight, true);
m_nodecollection.connectNodesWithLine(node_rechts, node_arrowLeft, true);
PText node_text = new PText("Zoomlevel Not Supported");
node_text.setBounds(180,150, node_text.getWidth(), node_text.getHeight());
m_nodecollection.connectNodesWithLine(node_links, node_text, true);
m_nodecollection.addNode(node_text);
node_links.addChild(node_text);
node_links.setCollection(m_nodecollection);
用整个 nodecollection 和 PText 作为成员变量创建了我自己的矩形类。
public class RectangleNode extends PNode{
private Rectangle2D m_rectangle;
private NodeCollection collection;
private PText text;
public RectangleNode()
{
m_rectangle = new Rectangle2D.Double();
}
public Rectangle2D getRectangle()
{
if(m_rectangle == null)
m_rectangle = new Rectangle2D.Double();
return m_rectangle;
}
public boolean setBounds(double x, double y, double w, double h)
{
if(super.setBounds(x, y, w, h))
{
m_rectangle.setFrame(x, y, w, h);
return true;
}
return false;
}
public void setCollection(NodeCollection collection)
{
this.collection = collection;
}
public void setText(PText text)
{
this.text = text;
}
public void paint(PPaintContext paintcontext)
{
Graphics2D g2 = paintcontext.getGraphics();
//niet ingezoomd
if(paintcontext.getScale() <= 0.2)
g2.setPaint(Color.BLACK);
//half ingezoomd
if(paintcontext.getScale() > 0.2 && paintcontext.getScale() < 0.7)
{
g2.setPaint(Color.BLACK);
}
//volledig ingezoomd
if(paintcontext.getScale() > 0.7)
{
g2.setPaint(Color.RED);
g2.fill(getRectangle());
g2.setPaint(Color.BLACK);
g2.draw(getRectangle());
}
}
}
现在,我想我可以像这样更改文本: text.setText("Tester"); 但它不起作用,例如 settext 然后将节点添加到集合中,然后它显示在当前文本上并出现巨大错误......
有人能帮助我吗?
亲切的问候,