/** * Creates the simplest possible scene graph. 1 Camera, 1 Layer, 1 Root * * @return a basic scene with 1 camera, layer and root */ public static PCamera createBasicScenegraph() { final PRoot root = new PRoot(); final PLayer layer = new PLayer(); final PCamera camera = new PCamera(); root.addChild(camera); root.addChild(layer); camera.addLayer(layer); return camera; }
/** * Add an activity to the activity scheduler associated with this root. * Activities are given a chance to run during each call to the roots * <code>processInputs</code> method. When the activity has finished running * it will automatically get removed. * * @param activity Activity that should be scheduled * @return whether it has been scheduled (always true) */ public boolean addActivity(final PActivity activity) { getActivityScheduler().addActivity(activity); return true; }
/** * Schedule the given activity with the root, note that only scheduled * activities will be stepped. If the activity is successfully added true is * returned, else false. * * @param activity new activity to schedule * @return true if the activity is successfully scheduled. */ public boolean addActivity(final PActivity activity) { final PRoot r = getRoot(); if (r != null) { return r.addActivity(activity); } return false; }
final boolean wasInteracting = getInteracting(); if (!isInteracting && !getInteracting()) { for (int i = 0; i < getChildrenCount(); i++) { final PNode child = getChild(i); if (child instanceof PCamera) { child.repaint(); firePropertyChange(PROPERTY_CODE_INTERACTING_CHANGED, PROPERTY_INTERACTING_CHANGED, Boolean .valueOf(wasInteracting), Boolean.valueOf(isInteracting));
/** * Dispatches the given event to the default input manager for the root of * this canvas. * * @param awtEvent awt event needing dispatching * @param type type of the event */ protected void sendInputEventToInputManager(final InputEvent awtEvent, final int type) { getRoot().getDefaultInputManager().processEventFromCamera(awtEvent, type, getCamera()); }
/** * Wait for all scheduled activities to finish before returning from this * method. This will freeze out user input, and so it is generally * recommended that you use PActivities.setTriggerTime() to offset * activities instead of using this method. */ public void waitForActivities() { final PNodeFilter cameraWithCanvas = new CameraWithCanvasFilter(); while (activityScheduler.getActivitiesReference().size() > 0) { processInputs(); final Iterator i = getAllNodes(cameraWithCanvas, null).iterator(); while (i.hasNext()) { final PCamera each = (PCamera) i.next(); each.getComponent().paintImmediately(); } } }
/** * Builds the basic scene graph associated with this canvas. Developers may * override this method to install their own layers, and cameras. * * @return PCamera viewing the freshly created scene */ public PCamera createBasicSceneGraph() { final PRoot r = new PSWTRoot(this); final PLayer l = new PLayer(); final PCamera c = new PCamera(); r.addChild(c); r.addChild(l); c.addLayer(l); return c; }
/** * Advanced. If you want to add additional input sources to the roots UI * process you can do that here. You will seldom do this unless you are * making additions to the Piccolo2D framework. * * @param inputSource An input source that should be added */ public void addInputSource(final InputSource inputSource) { inputSources.add(inputSource); firePropertyChange(PROPERTY_CODE_INPUT_SOURCES, PROPERTY_INPUT_SOURCES, null, inputSources); }
/** * Returns the activity timer. Creating it if necessary. * * @return a Timer instance. */ protected Timer getActivityTimer() { if (activityTimer == null) { activityTimer = root.createTimer(PUtil.ACTIVITY_SCHEDULER_FRAME_DELAY, new ActionListener() { public void actionPerformed(final ActionEvent e) { root.processInputs(); } }); } return activityTimer; } }
/** * Get the default input manager to be used when processing input events. * PCanvas's use this method when they forward new swing input events to the * PInputManager. * * @return a singleton instance of PInputManager */ public PInputManager getDefaultInputManager() { if (defaultInputManager == null) { defaultInputManager = new PInputManager(); addInputSource(defaultInputManager); } return defaultInputManager; }
/** * Sends the given input event with the given type to the current * InputManager. * * @param event event to dispatch * @param type type of event being dispatched */ protected void sendInputEventToInputManager(final InputEvent event, final int type) { getRoot().getDefaultInputManager().processEventFromCamera(event, type, getCamera()); }
/** * Advanced. If you want to remove the default input source from the roots * UI process you can do that here. You will seldom do this unless you are * making additions to the Piccolo2D framework. * * @param inputSource input source that should no longer be asked about * input events */ public void removeInputSource(final InputSource inputSource) { if (inputSources.remove(inputSource)) { firePropertyChange(PROPERTY_CODE_INPUT_SOURCES, PROPERTY_INPUT_SOURCES, null, inputSources); } }
/** * Return true if any activities that respond with true to the method * isAnimating were run in the last PRoot.processInputs() loop. This values * is used by this canvas to determine the render quality to use for the * next paint. * * @return whether the PCanvas is currently being animated */ public boolean getAnimating() { return getRoot().getActivityScheduler().getAnimating(); }
/** * Schedules the "infinite" drag activity so that auto-panning and zooming * will continue to update the scene even if there are no further drag * events fired. For example, if the mouse is dragged to the right while * pressing the right mouse button and then paused for a while, the scene * should continue to zoom in. * * @param event the event that's responsible for the start of the activity */ protected void startDragActivity(final PInputEvent event) { dragActivity = new PActivity(-1, PUtil.DEFAULT_ACTIVITY_STEP_RATE); dragActivity.setDelegate(new PActivity.PActivityDelegate() { public void activityStarted(final PActivity activity) { dragActivityFirstStep(dragEvent); } public void activityStepped(final PActivity activity) { dragActivityStep(dragEvent); } public void activityFinished(final PActivity activity) { dragActivityFinalStep(dragEvent); } }); event.getCamera().getRoot().addActivity(dragActivity); }
/** * Return true if any activities that respond with true to the method * isAnimating were run in the last PRoot.processInputs() loop. This values * is used by this canvas to determine the render quality to use for the * next paint. * * @return true if there is an animating activity that is currently active */ public boolean getAnimating() { return getRoot().getActivityScheduler().getAnimating(); }
public void widgetDisposed(final DisposeEvent de) { getRoot().getActivityScheduler().removeAllActivities(); SWTGraphics2D.decrementGCCount(); } });
r.getActivityScheduler().addActivity(transformActivity);