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


Java PCamera类代码示例

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


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

示例1: mapLocation

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Maps the location (upper-left corner) of a PNode on a specified PCanvas to
 * the coordinate system of the parent help pane.
 *
 * @param node
 * @param canvas
 * @return
 */
public Point2D mapLocation( PNode node, PCanvas canvas ) {
    // Determine the node's location in canvas coordinates...
    int x = 0;
    int y = 0;
    {
        // Get the node's full bounds (union of its bounds and all children) in parent node's local coordinates
        Rectangle2D fullBounds = node.getFullBounds();
        // Get the node's global bounds - above the root node's transform, but below the canvas's view transform.
        Rectangle2D globalFullBounds = node.getParent().localToGlobal( fullBounds );

        //TODO: perhaps this code should transform this.globalToLocal(globalFullBounds) to identify the correct location.
        // Apply the canvas' view transform to get bounds in the canvas' coordinate system.
        PCamera camera = canvas.getCamera();
        PAffineTransform transform = camera.getViewTransformReference();
        Rectangle2D bounds = transform.transform( globalFullBounds, null );
        x = (int) bounds.getX();
        y = (int) bounds.getY();
    }

    // Convert the canvas location to a location in the help pane.
    Point2D helpPanePoint = SwingUtilities.convertPoint( canvas, x, y, _helpPane );
    return helpPanePoint;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:32,代码来源:AbstractHelpItem.java

示例2: initialize

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
public void initialize() {
    final PLayer l = new PLayer();
    final PPath n = PPath.createEllipse(0, 0, 100, 80);
    n.setPaint(Color.red);
    n.setStroke(null);
    PBoundsHandle.addBoundsHandlesTo(n);
    l.addChild(n);
    n.translate(200, 200);

    final PCamera c = new PCamera();
    c.setBounds(0, 0, 100, 80);
    c.scaleView(0.1);
    c.addLayer(l);
    PBoundsHandle.addBoundsHandlesTo(c);
    c.setPaint(Color.yellow);

    getCanvas().getLayer().addChild(l);
    getCanvas().getLayer().addChild(c);
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:20,代码来源:CameraExample.java

示例3: initialize

import edu.umd.cs.piccolo.PCamera; //导入依赖的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:mleoking,项目名称:PhET,代码行数:24,代码来源:TwoCanvasExample.java

示例4: setCamera

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Set the camera associated with this canvas. All input events from this
 * canvas go through this camera. And this is the camera that paints this
 * canvas.
 * 
 * @param newCamera camera to attach to this canvas
 */
public void setCamera(final PCamera newCamera) {
    if (camera != null) {
        camera.setComponent(null);
    }

    camera = newCamera;

    if (camera != null) {
        camera.setComponent(this);

        final Rectangle swtRect = getBounds();

        camera.setBounds(new Rectangle2D.Double(swtRect.x, swtRect.y, swtRect.width, swtRect.height));
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:PSWTCanvas.java

示例5: relocateHandle

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Force this handle to relocate itself using its locator.
 */
public void relocateHandle() {
    if (locator != null) {
        final PBounds b = getBoundsReference();
        final Point2D aPoint = locator.locatePoint(null);

        if (locator instanceof PNodeLocator) {
            final PNode located = ((PNodeLocator) locator).getNode();
            final PNode parent = getParent();

            located.localToGlobal(aPoint);
            globalToLocal(aPoint);

            if (parent != located && parent instanceof PCamera) {
                ((PCamera) parent).viewToLocal(aPoint);
            }
        }

        final double newCenterX = aPoint.getX();
        final double newCenterY = aPoint.getY();

        if (newCenterX != b.getCenterX() || newCenterY != b.getCenterY()) {
            centerBoundsOnPoint(newCenterX, newCenterY);
        }
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:29,代码来源:PSWTHandle.java

示例6: updateMarquee

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/** {@inheritDoc} */
protected void updateMarquee(final PInputEvent pie) {
    super.updateMarquee(pie);

    final PBounds b = new PBounds();

    if (marqueeParent instanceof PCamera) {
        b.add(canvasPressPt);
        b.add(pie.getCanvasPosition());
    }
    else {
        b.add(pressPt);
        b.add(pie.getPosition());
    }

    marquee.setPathToRectangle((float) b.x, (float) b.y, (float) b.width, (float) b.height);
    b.reset();
    b.add(pressPt);
    b.add(pie.getPosition());
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:21,代码来源:PSWTSelectionEventHandler.java

示例7: listenForCanvas

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Attaches a listener to the specified node and all its parents to listen
 * for a change in the PSwingCanvas. Only PROPERTY_PARENT listeners are
 * added so this code wouldn't handle if a PLayer were viewed by a different
 * PCamera since that constitutes a child change.
 * 
 * @param node The child node at which to begin a parent-based traversal for
 *            adding listeners.
 */
private void listenForCanvas(final PNode node) {
    // need to get the full tree for this node
    PNode p = node;
    while (p != null) {
        listenToNode(p);

        final PNode parent = p;
        // System.out.println( "parent = " + parent.getClass() );
        if (parent instanceof PLayer) {
            final PLayer player = (PLayer) parent;
            // System.out.println( "Found player: with " +
            // player.getCameraCount() + " cameras" );
            for (int i = 0; i < player.getCameraCount(); i++) {
                final PCamera cam = player.getCamera(i);
                if (cam.getComponent() instanceof PSwingCanvas) {
                    updateCanvas((PSwingCanvas) cam.getComponent());
                    break;
                }
            }
        }
        p = p.getParent();
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:33,代码来源:PSwing.java

示例8: mousePressed

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * A callback that is invoked any time the mouse is pressed on the canvas.
 * If the press occurs directly on the canvas, it create a new PStyledText
 * instance and puts it in editing mode. If the click is on a node, it marks
 * changes it to editing mode.
 * 
 * @param event mouse click event that can be queried
 */
public void mousePressed(final PInputEvent event) {
    final PNode pickedNode = event.getPickedNode();

    stopEditing(event);

    if (event.getButton() != MouseEvent.BUTTON1) {
        return;
    }

    if (pickedNode instanceof PStyledText) {
        startEditing(event, (PStyledText) pickedNode);
    }
    else if (pickedNode instanceof PCamera) {
        final PStyledText newText = createText();
        final Insets pInsets = newText.getInsets();
        newText.translate(event.getPosition().getX() - pInsets.left, event.getPosition().getY() - pInsets.top);
        startEditing(event, newText);
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:28,代码来源:PStyledTextEventHandler.java

示例9: isSelectable

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Determine if the specified node can be selected (i.e., if it is a child
 * of the one the list of nodes that can be selected).
 * 
 * @param node node being tested
 * @return true if node can be selected
 */
protected boolean isSelectable(final PNode node) {
    boolean selectable = false;

    final Iterator parentsIt = selectableParents.iterator();
    while (parentsIt.hasNext()) {
        final PNode parent = (PNode) parentsIt.next();
        if (parent.getChildrenReference().contains(node)) {
            selectable = true;
            break;
        }
        else if (parent instanceof PCamera) {
            for (int i = 0; i < ((PCamera) parent).getLayerCount(); i++) {
                final PLayer layer = ((PCamera) parent).getLayer(i);
                if (layer.getChildrenReference().contains(node)) {
                    selectable = true;
                    break;
                }
            }
        }
    }

    return selectable;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:31,代码来源:PSelectionEventHandler.java

示例10: animateCameraViewTransformTo

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Animates the camera's view transform into the provided one over the
 * duration provided.
 * 
 * @param camera camera being animated
 * @param targetTransform the transform to which the camera's transform will
 *            be animated
 * @param duration the number of milliseconds the animation should last
 * 
 * @return an activity object that represents the animation
 */
protected PActivity animateCameraViewTransformTo(final PCamera camera, final AffineTransform targetTransform,
        final int duration) {
    boolean wasOldAnimation = false;

    // first stop any old animations.
    if (navigationActivity != null) {
        navigationActivity.terminate();
        wasOldAnimation = true;
    }

    if (duration == 0) {
        camera.setViewTransform(targetTransform);
        return null;
    }

    final AffineTransform source = camera.getViewTransformReference();

    if (source.equals(targetTransform)) {
        return null;
    }

    navigationActivity = camera.animateViewToTransform(targetTransform, duration);
    navigationActivity.setSlowInSlowOut(!wasOldAnimation);
    return navigationActivity;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:37,代码来源:PNavigationEventHandler.java

示例11: dragActivityStep

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Updates the current zoom periodically, regardless of whether the mouse
 * has moved recently.
 * 
 * @param event contains information about the current state of the mouse
 */
protected void dragActivityStep(final PInputEvent event) {
    final PCamera camera = event.getCamera();
    final double dx = event.getCanvasPosition().getX() - getMousePressedCanvasPoint().getX();
    double scaleDelta = 1.0 + ZOOM_SENSITIVITY * dx;

    final double currentScale = camera.getViewScale();
    final double newScale = currentScale * scaleDelta;

    if (newScale < minScale) {
        scaleDelta = minScale / currentScale;
    }
    if (maxScale > 0 && newScale > maxScale) {
        scaleDelta = maxScale / currentScale;
    }

    camera.scaleViewAboutPoint(scaleDelta, viewZoomPoint.getX(), viewZoomPoint.getY());
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:PZoomEventHandler.java

示例12: testPick

import edu.umd.cs.piccolo.PCamera; //导入依赖的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:mleoking,项目名称:PhET,代码行数:25,代码来源:PPickPathTest.java

示例13: doZoom

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
protected void doZoom(PInputEvent ref, PInputEvent now)
{
    PCamera camera = ((PCanvas) ref.getComponent()).getCamera();
    Point2D zoomPt = ref.getCanvasPosition();

    double dx = ((MouseEvent) ref.getSourceSwingEvent()).getX()
            - ((MouseEvent) now.getSourceSwingEvent()).getX();
    double scaleDelta = (1.0 + (0.001 * dx));
    double currentScale = camera.getViewScale();
    double newScale = currentScale * scaleDelta;

    if (newScale < getMinScale())
        scaleDelta = getMinScale() / currentScale;

    if ((getMaxScale() > 0) && (newScale > getMaxScale()))
        scaleDelta = getMaxScale() / currentScale;

    camera
            .scaleViewAboutPoint(scaleDelta, zoomPt.getX(), zoomPt
                    .getY());
    original = now;
}
 
开发者ID:hypergraphdb,项目名称:viewer,代码行数:23,代码来源:GraphView.java

示例14: isSelectable

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
 * Determine if the specified node is selectable (i.e., if it is a child of
 * the one the list of selectable parents.
 */
protected boolean isSelectable(PNode node) {
	boolean selectable = false;
	for(PNode parent: selectableParents) {
		if (parent.getChildrenReference().contains(node)) {
			selectable = true;
			break;
		} else if (parent instanceof PCamera) {
			for (int i = 0; i < ((PCamera) parent).getLayerCount(); i++) {
				PLayer layer = ((PCamera) parent).getLayer(i);
				if (layer.getChildrenReference().contains(node)) {
					selectable = true;
					break;
				}
			}
		}
	}
	return selectable;
}
 
开发者ID:hypergraphdb,项目名称:viewer,代码行数:23,代码来源:PNodeSelectionHandler.java

示例15: setViewBounds

import edu.umd.cs.piccolo.PCamera; //导入依赖的package包/类
/**
    * Changes the view bounds of a camera with a smooth animation.
    */
protected void setViewBounds(PCamera camera, PBounds b) {
	if (!smoothPanning) {
		camera.setViewBounds(b);
	} else {
 		// The following allows a camera animation to start while another animation
 		// is already running.
 		if (isAnimatingPan()) {
 			currentCameraAnimation.terminate(PActivity.TERMINATE_WITHOUT_FINISHING);
 		}
			currentCameraAnimation = camera.animateViewToCenterBounds(b, true, 150);
			currentCameraAnimation.setSlowInSlowOut(false);
		// Play one step right now, otherwise nothing will happen while dragging the mouse since animations
 		// won't have time to play.
		currentCameraAnimation.setStartTime(System.currentTimeMillis() - currentCameraAnimation.getStepRate());
		currentCameraAnimation.processStep(System.currentTimeMillis());            		
	}
	}
 
开发者ID:jdfekete,项目名称:geneaquilt,代码行数:21,代码来源:SlidingController.java


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