/** * Add a camera to this layer's camera list. This method it called * automatically when a layer is added to a camera. * * @param camera the camera to add to this layer */ public void addCamera(final PCamera camera) { addCamera(cameras.size(), camera); }
/** * Add a camera to this layer's camera list at the specified index. This * method it called automatically when a layer is added to a camera. * * @param index index at which the camera should be inserted * @param camera Camera to add to layer */ public void addCamera(final int index, final PCamera camera) { cameras.add(index, camera); invalidatePaint(); firePropertyChange(PROPERTY_CODE_CAMERAS, PROPERTY_CAMERAS, null, cameras); }
/** * Paint all the layers in the list of layers viewed by this camera. This method * is called after the view transform and clip have been applied to the * specified paint context. * * @param paintContext context in which painting occurs */ protected void paintCameraView(final PPaintContext paintContext) { final int size = layers.size(); for (int i = 0; i < size; i++) { final PLayer each = (PLayer) layers.get(i); each.fullPaint(paintContext); } }
/** * Override repaints and forward them to the cameras that are viewing this * layer. * * @param localBounds bounds flagged as needing repainting * @param repaintSource the source of the repaint notification */ public void repaintFrom(final PBounds localBounds, final PNode repaintSource) { if (repaintSource != this) { localToParent(localBounds); } notifyCameras(localBounds); if (getParent() != null) { getParent().repaintFrom(localBounds, repaintSource); } }
/** * 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; }
/** * Dispatches repaint notification to all registered cameras. * * @param parentBounds bounds needing repainting in parent coordinate system */ protected void notifyCameras(final PBounds parentBounds) { final int count = getCameraCount(); for (int i = 0; i < count; i++) { final PCamera each = (PCamera) cameras.get(i); each.repaintFromLayer(parentBounds, this); } }
/** * Try to pick all of the layers in the list of layers viewed by this * camera. This method is called after the view transform has been applied * to the specified pick path. * * @param pickPath pick path * @return true if any of the layers in the list of layers viewed by this * camera were picked */ protected boolean pickCameraView(final PPickPath pickPath) { final int size = layers.size(); for (int i = size - 1; i >= 0; i--) { final PLayer each = (PLayer) layers.get(i); if (each.fullPick(pickPath)) { return true; } } return false; }
/** * Return the union of the full bounds of each layer in the list of layers * viewed by this camera, or empty bounds if the list of layers viewed by * this camera is empty. * * @return the union of the full bounds of each layer in the list of layers * viewed by this camera, or empty bounds if the list of layers viewed * by this camera is empty */ public PBounds getUnionOfLayerFullBounds() { final PBounds result = new PBounds(); final int size = layers.size(); for (int i = 0; i < size; i++) { final PLayer each = (PLayer) layers.get(i); result.add(each.getFullBoundsReference()); } return result; }
((PLayer) layers.get(i)).getAllNodes(null, nodes);
/** * 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; }
/** * Write this layer and all its children out to the given stream. Note that * the layer writes out any cameras that are viewing it conditionally, so * they will only get written out if someone else writes them * unconditionally. * * @param out object to which the layer should be streamed * @throws IOException may occur while serializing to stream */ private void writeObject(final ObjectOutputStream out) throws IOException { if (!(out instanceof PObjectOutputStream)) { throw new RuntimeException("May not serialize PLayer to a non PObjectOutputStream"); } out.defaultWriteObject(); final int count = getCameraCount(); for (int i = 0; i < count; i++) { ((PObjectOutputStream) out).writeConditionalObject(cameras.get(i)); } out.writeObject(Boolean.FALSE); }
/** * Remove the camera at the given index from this layer's camera list. * * @param index the index of the camera we wish to remove * * @return camera that was removed */ public PCamera removeCamera(final int index) { final PCamera result = (PCamera) cameras.remove(index); invalidatePaint(); firePropertyChange(PROPERTY_CODE_CAMERAS, PROPERTY_CAMERAS, null, cameras); return result; }
/** * Inserts the specified layer at the specified position in the list of layers viewed by this camera. * Layers may be viewed by multiple cameras at once. * * @param index index at which the specified layer is to be inserted * @param layer layer to add * @throws IndexOutOfBoundsException if the specified index is out of range * (<code>index < 0 || index >= getLayerCount()</code>) */ public void addLayer(final int index, final PLayer layer) { layers.add(index, layer); layer.addCamera(this); invalidatePaint(); firePropertyChange(PROPERTY_CODE_LAYERS, PROPERTY_LAYERS, null, layers); }
/** * Remove the camera from this layer's camera list. * * @param camera the camera to remove from the layer, does nothing if not * found * @return camera that was passed in */ public PCamera removeCamera(final PCamera camera) { if (cameras.remove(camera)) { invalidatePaint(); firePropertyChange(PROPERTY_CODE_CAMERAS, PROPERTY_CAMERAS, null, cameras); } return camera; }