当前位置: 首页>>代码示例>>Java>>正文


Java PCanvas类代码示例

本文整理汇总了Java中org.piccolo2d.PCanvas的典型用法代码示例。如果您正苦于以下问题:Java PCanvas类的具体用法?Java PCanvas怎么用?Java PCanvas使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PCanvas类属于org.piccolo2d包,在下文中一共展示了PCanvas类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initialize

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void initialize() {
    final PRoot root = getCanvas().getRoot();
    final PLayer layer = getCanvas().getLayer();

    final PNode n = PPath.createRectangle(0, 0, 100, 80);
    final PNode sticky = PPath.createRectangle(0, 0, 50, 50);
    PBoundsHandle.addBoundsHandlesTo(n);
    sticky.setPaint(Color.YELLOW);
    PBoundsHandle.addBoundsHandlesTo(sticky);

    layer.addChild(n);
    getCanvas().getCamera().addChild(sticky);

    final PCamera otherCamera = new PCamera();
    otherCamera.addLayer(layer);
    root.addChild(otherCamera);

    final PCanvas other = new PCanvas();
    other.setCamera(otherCamera);
    final PFrame result = new PFrame("TwoCanvasExample", false, other);
    result.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    result.setLocation(500, 100);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:24,代码来源:TwoCanvasExample.java

示例2: initialize

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void initialize() {
    final PCanvas canvas = getCanvas();

    final PPath circle = PPath.createEllipse(0, 0, 100, 100);
    circle.setStroke(new BasicStroke(10));
    circle.setPaint(Color.YELLOW);

    final PPath rectangle = PPath.createRectangle(-100, -50, 100, 100);
    rectangle.setStroke(new BasicStroke(15));
    rectangle.setPaint(Color.ORANGE);

    final PNodeCache cache = new PNodeCache();
    cache.addChild(circle);
    cache.addChild(rectangle);

    cache.invalidateCache();

    canvas.getLayer().addChild(cache);
    canvas.removeInputEventListener(canvas.getPanEventHandler());
    canvas.addInputEventListener(new PDragEventHandler());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:22,代码来源:NodeCacheExample.java

示例3: install

import org.piccolo2d.PCanvas; //导入依赖的package包/类
/**
 * Installs the scroll director and adds the appropriate listeners.
 * 
 * @param targetViewPort viewport on which this director directs
 * @param targetView PCanvas that the viewport looks at
 */
public void install(final PViewport targetViewPort, final PCanvas targetView) {
    scrollPane = (PScrollPane) targetViewPort.getParent();
    this.viewPort = targetViewPort;
    this.view = targetView;

    if (targetView != null) {
        camera = targetView.getCamera();
        root = targetView.getRoot();
    }

    if (camera != null) {
        camera.addPropertyChangeListener(this);
    }
    if (root != null) {
        root.addPropertyChangeListener(this);
    }

    if (scrollPane != null) {
        scrollPane.revalidate();
    }
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:28,代码来源:PDefaultScrollDirector.java

示例4: testSelectionChange

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testSelectionChange()
{
    PCanvas canvas = new PCanvas();
    PLayer layer = canvas.getLayer();
    PNode node = new PNode();
    layer.addChild(node);

    PSelectionEventHandler selectionHandler = new PSelectionEventHandler(layer, layer);
    assertTrue(selectionHandler.getSelectionReference().isEmpty());

    PNotificationCenter notificationCenter = PNotificationCenter.defaultCenter();
    notificationCenter.addListener(this, "selectionChanged", PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, null);

    selectionHandler.select(node);
    assertTrue(selectionHandler.getSelectionReference().contains(node));
    assertTrue(selectionChanged);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:18,代码来源:PSelectionEventHandlerTest.java

示例5: testKeyboardDeleteFiresSelectionChange

import org.piccolo2d.PCanvas; //导入依赖的package包/类
/**
 * {@link http://code.google.com/p/piccolo2d/issues/detail?id=177}
 */
public void testKeyboardDeleteFiresSelectionChange()
{
    PCanvas canvas = new PCanvas();
    PLayer layer = canvas.getLayer();
    PNode node = new PNode();
    layer.addChild(node);

    PSelectionEventHandler selectionHandler = new PSelectionEventHandler(layer, layer);
    selectionHandler.setDeleteKeyActive(true);
    selectionHandler.select(node);
    assertTrue(selectionHandler.getSelectionReference().contains(node));

    PNotificationCenter notificationCenter = PNotificationCenter.defaultCenter();
    notificationCenter.addListener(this, "selectionChanged", PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, null);

    KeyEvent keyEvent = new KeyEvent(canvas, -1, System.currentTimeMillis(), 0, KeyEvent.VK_DELETE);
    PInputEvent event = new PInputEvent(null, keyEvent);
    selectionHandler.keyPressed(event);
    assertTrue(selectionHandler.getSelectionReference().isEmpty());
    assertTrue(selectionChanged);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:25,代码来源:PSelectionEventHandlerTest.java

示例6: testKeyboardDeleteInactive

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testKeyboardDeleteInactive()
{
    PCanvas canvas = new PCanvas();
    PLayer layer = canvas.getLayer();
    PNode node = new PNode();
    layer.addChild(node);

    PSelectionEventHandler selectionHandler = new PSelectionEventHandler(layer, layer);
    selectionHandler.setDeleteKeyActive(false);
    selectionHandler.select(node);
    assertTrue(selectionHandler.getSelectionReference().contains(node));

    PNotificationCenter notificationCenter = PNotificationCenter.defaultCenter();
    notificationCenter.addListener(this, "selectionChanged", PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, null);

    KeyEvent keyEvent = new KeyEvent(canvas, -1, System.currentTimeMillis(), 0, KeyEvent.VK_DELETE);
    PInputEvent event = new PInputEvent(null, keyEvent);
    selectionHandler.keyPressed(event);
    assertTrue(selectionHandler.getSelectionReference().contains(node));
    assertFalse(selectionChanged);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:22,代码来源:PSelectionEventHandlerTest.java

示例7: testKeyboardDeleteEmptySelection

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testKeyboardDeleteEmptySelection()
{
    PCanvas canvas = new PCanvas();
    PLayer layer = canvas.getLayer();

    PSelectionEventHandler selectionHandler = new PSelectionEventHandler(layer, layer);
    selectionHandler.setDeleteKeyActive(true);
    assertTrue(selectionHandler.getSelectionReference().isEmpty());

    PNotificationCenter notificationCenter = PNotificationCenter.defaultCenter();
    notificationCenter.addListener(this, "selectionChanged", PSelectionEventHandler.SELECTION_CHANGED_NOTIFICATION, null);

    KeyEvent keyEvent = new KeyEvent(canvas, -1, System.currentTimeMillis(), 0, KeyEvent.VK_DELETE);
    PInputEvent event = new PInputEvent(null, keyEvent);
    selectionHandler.keyPressed(event);
    assertTrue(selectionHandler.getSelectionReference().isEmpty());
    assertFalse(selectionChanged);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:19,代码来源:PSelectionEventHandlerTest.java

示例8: testAnimateToRelativePositionResultsInProperTransform

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testAnimateToRelativePositionResultsInProperTransform() {
    final PCanvas canvas = new PCanvas();
    final PNode A = new PNode();
    A.setBounds(0, 0, 50, 50);
    canvas.getLayer().addChild(A);
    final PNode B = new PNode();
    B.setBounds(0, 0, 100, 100);
    B.setOffset(100, 100);
    canvas.getLayer().addChild(B);

    final Point2D srcPt = new Point2D.Double(1.0, 0.0);
    final Point2D destPt = new Point2D.Double(0.0, 0.0);
    A.animateToRelativePosition(srcPt, destPt, B.getGlobalBounds(), 0);

    final PAffineTransform expectedTransform = new PAffineTransform();
    expectedTransform.translate(50, 100);

    assertEquals(expectedTransform, A.getTransform());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:20,代码来源:PNodeTest.java

示例9: testSetTransparency1MeansInvisible

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testSetTransparency1MeansInvisible() {
    final PNode node = new PNode();
    node.setBounds(0, 0, 100, 100);
    node.setVisible(true);
    node.setPaint(Color.RED);

    final PCanvas canvas = buildCanvasContainingNode(node);

    final BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
    final Graphics g = GraphicsEnvironment.getLocalGraphicsEnvironment().createGraphics(img);

    canvas.paintComponent(g);
    node.setTransparency(1f);
    assertEquals(Color.RED.getRGB(), img.getRGB(10, 10));

    node.setTransparency(0f);
    canvas.paintComponent(g);
    assertEquals(Color.WHITE.getRGB(), img.getRGB(10, 10));

}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:21,代码来源:PNodeTest.java

示例10: testHiddenNodesAreNotPickable

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testHiddenNodesAreNotPickable() {
    final PCanvas canvas = new PCanvas();
    canvas.setBounds(0, 0, 400, 400);
    canvas.setPreferredSize(new Dimension(400, 400));
    final PNode node1 = new PNode();
    node1.setBounds(0, 0, 100, 100);
    node1.setPaint(Color.RED);
    canvas.getLayer().addChild(node1);

    final PNode node2 = (PNode) node1.clone();
    node2.setPaint(Color.BLUE);

    final PLayer layer2 = new PLayer();
    layer2.addChild(node2);
    layer2.setVisible(false);
    canvas.getCamera().addLayer(layer2);

    final PPickPath path = canvas.getCamera().pick(5, 5, 5);
    assertSame(node1, path.getPickedNode());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:21,代码来源:PNodeTest.java

示例11: testPaintFillsBounds

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testPaintFillsBounds() {
    PHtmlView html = new PHtmlView(LOREM_IPSUM);
    html.setPaint(Color.RED);
    
    PCanvas canvas = new PCanvas();
    canvas.setBackground(Color.WHITE);
    canvas.setBounds(0, 0, 500, 30);
    canvas.getLayer().addChild(html);
    
    BufferedImage image = new BufferedImage(600, 30, BufferedImage.TYPE_INT_RGB);        
    Graphics2D g2 = image.createGraphics();
    canvas.paint(g2);
          
    assertEquals(Color.red.getRGB(), image.getRGB(0, 0));
    assertEquals(Color.red.getRGB(), image.getRGB(0, (int)(html.getHeight()-1)));        
    assertEquals(Color.red.getRGB(), image.getRGB(300, 0));
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:18,代码来源:PHtmlViewTest.java

示例12: testPick

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void testPick() {
    final PCanvas canvas = new PCanvas();
    final PCamera camera = canvas.getCamera();
    final PLayer layer = canvas.getLayer();

    camera.setBounds(0, 0, 100, 100);

    final PNode a = PPath.createRectangle(0, 0, 100, 100);
    final PNode b = PPath.createRectangle(0, 0, 100, 100);
    final PNode c = PPath.createRectangle(0, 0, 100, 100);

    layer.addChild(a);
    layer.addChild(b);
    layer.addChild(c);

    final PPickPath pickPath = camera.pick(50, 50, 2);

    assertTrue(pickPath.getPickedNode() == c);
    assertTrue(pickPath.nextPickedNode() == b);
    assertTrue(pickPath.nextPickedNode() == a);
    assertTrue(pickPath.nextPickedNode() == camera);
    assertTrue(pickPath.nextPickedNode() == null);
    assertTrue(pickPath.nextPickedNode() == null);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:25,代码来源:PPickPathTest.java

示例13: initialize

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void initialize() {
    final PCanvas c = getCanvas();
    final PLayer l = c.getLayer();
    final PCamera cam = c.getCamera();

    cam.scaleView(2.0);
    final PPath path = PPath.createRectangle(0, 0, 100, 100);

    l.addChild(path);
    path.translate(100, 10);
    path.scale(0.2);
    cam.animateViewToCenterBounds(path.getGlobalFullBounds(), true, 1000);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:14,代码来源:CenterExample.java

示例14: initialize

import org.piccolo2d.PCanvas; //导入依赖的package包/类
public void initialize() {
    final PCanvas c = getCanvas();

    final PActivity updateHandles = new PActivity(-1, 0) {
        protected void activityStep(final long elapsedTime) {
            super.activityStep(elapsedTime);

            final PRoot root = getActivityScheduler().getRoot();

            if (root.getPaintInvalid() || root.getChildPaintInvalid()) {
                final Iterator i = getCanvas().getCamera().getChildrenIterator();
                while (i.hasNext()) {
                    final PNode each = (PNode) i.next();
                    if (each instanceof PHandle) {
                        final PHandle handle = (PHandle) each;
                        handle.relocateHandle();
                    }
                }
            }
        }
    };

    final PPath rect = PPath.createRectangle(0, 0, 100, 100);
    rect.setPaint(Color.RED);
    c.getLayer().addChild(rect);

    c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthEastLocator(rect)));
    c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createNorthWestLocator(rect)));
    c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthEastLocator(rect)));
    c.getCamera().addChild(new PBoundsHandle(PBoundsLocator.createSouthWestLocator(rect)));

    c.getRoot().getActivityScheduler().addActivity(updateHandles, true);
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:34,代码来源:StickyHandleLayerExample.java

示例15: PStyledTextEventHandler

import org.piccolo2d.PCanvas; //导入依赖的package包/类
/**
 * Basic constructor for PStyledTextEventHandler.
 * 
 * @param canvas canvas to which this handler will be attached
 */
public PStyledTextEventHandler(final PCanvas canvas) {
    final PInputEventFilter filter = new PInputEventFilter();
    filter.setOrMask(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK);
    setEventFilter(filter);
    this.canvas = canvas;
    initEditor(createDefaultEditor());
}
 
开发者ID:piccolo2d,项目名称:piccolo2d.java,代码行数:13,代码来源:PStyledTextEventHandler.java


注:本文中的org.piccolo2d.PCanvas类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。