@Override public void hideComponents(boolean hide) { this.hideComponents = hide; if (componentsInHiearchy == null) return; for (Renderable r : componentsInHiearchy) { Node node = (Node) r; node.setIsVisible(!hide); if (r instanceof RenderableComplex) { ((RenderableComplex) r).hideComponents = hide; } } // The following statements are related to bounds. if (bounds == null) return; if (hide) { saveOldBounds(); copyBoundsToComponents(); } else { recoverOldBounds(); // Make sure a complex container has enough size Renderable container = this.container; Rectangle childBounds = this.bounds; while (container instanceof RenderableComplex) { Rectangle cBounds = container.getBounds(); if (!cBounds.contains(childBounds)) { ((RenderableComplex) container).layout(); } childBounds = container.getBounds(); container = container.getContainer(); } } }
public void render(Renderer renderer) { // Find renderables and sort them by depth List<Renderable> renderables = new ArrayList<>(); for (GameObject actor : actors) { if (actor instanceof Renderable) { renderables.add((Renderable) actor); } } renderables.sort((o1, o2) -> (int) (Integer.MAX_VALUE * (o2.getDepth() - o1.getDepth()))); // Apply camera renderer.pushMatrix(); if (camera != null) { camera.applyTransforms(renderer); } // render objects for (Renderable renderable : renderables) { renderable.render(renderer); } renderer.popMatrix(); }
@Override public void render(EntityPlayer player, Graphics g, double x, double y) { final float pitch = player.pitch; final int attackTime = player.getAttackTime(); final boolean flip = pitch >= 90 && pitch <= 270; final Renderable sprite = this.getSprite(player, attackTime); final float width = 12; final float height = 24; GL11.glPushMatrix(); GL11.glTranslated(x, y, 0); if (flip) { GL11.glScalef(-1, 1, 1); } GL11.glTranslatef(-width / 2, -height, 0); sprite.draw(0, 0); this.drawHeldItem(player, attackTime); GL11.glPopMatrix(); }
private boolean isNormalObject(Renderable r, Set<Long> normalIds) { if (r instanceof HyperEdge) { if (r instanceof FlowLine) return isFlowLineRelatedToSet((FlowLine) r, normalIds); // Most likely the following statements should not be reached. But place // here just in case. if (r.getReactomeId() == null) return true; if (normalIds.contains(r.getReactomeId())) return true; } else if (r instanceof Node) { if (r instanceof ProcessNode) return true; // Should be used only for normal pathway. if (r.getReactomeId() == null) return true; // Check if it is linked to another disease entities Node node = (Node) r; List<HyperEdge> edges = node.getConnectedReactions(); boolean isNormal = false; for (HyperEdge edge : edges) { if (edge instanceof FlowLine) isNormal = isFlowLineRelatedToSet((FlowLine) edge, normalIds); if (isNormal) return true; if (edge.getReactomeId() != null && normalIds.contains(edge.getReactomeId())) return true; // Some special cases that use links if (!(edge instanceof EntitySetAndEntitySetLink) && !(edge instanceof EntitySetAndMemberLink) && edge.getReactomeId() == null) return true; } } return false; }
/** * Some of disease reactions may not be drawn in the pathway diagram (e.g. LoF or GoF reactions). * These reactions should be overlaid onto their normalReaction counterparts, which are encoded by * their normalReaction attributes. * * @param diseaseIds */ private void overlayDiseaseReactions(Set<Long> diseaseIds) { // Get the list of all drawing objects for checking Map<Long, Renderable> idToObject = new HashMap<Long, Renderable>(); List<Renderable> components = displayedObject.getComponents(); if (components == null || components.size() == 0) return; for (Renderable r : components) { if (r.getReactomeId() == null) continue; idToObject.put(r.getReactomeId(), r); } try { normalToDiseaseNode = new HashMap<Node, Node>(); for (Long diseaseId : diseaseIds) { if (idToObject.containsKey(diseaseId)) continue; // Have to copy the normal reactions to draw GKInstance inst = adaptor.fetchInstance(diseaseId); if (inst.getSchemClass().isa(ReactomeJavaConstants.ReactionlikeEvent)) { List<GKInstance> normalReactions = inst.getAttributeValuesList(ReactomeJavaConstants.normalReaction); if (normalReactions != null && normalReactions.size() > 0) { for (GKInstance normalRxt : normalReactions) { Renderable r = idToObject.get(normalRxt.getDBID()); if (r instanceof HyperEdge) overlayDiseaseReaction((HyperEdge) r, inst); } } } } return; } catch (Exception e) { e.printStackTrace(); } }
private boolean isDiseaseObject(Renderable r, Set<Long> diseaseIds) { if (r instanceof FlowLine) { FlowLine fl = (FlowLine) r; return isFlowLineRelatedToSet(fl, diseaseIds); } // Assume normal objects only: this is a very strong assumption if (r.getReactomeId() == null) return false; // A PE may be represented multiple times in a pathway diagram. Some of them // are linked to normal reactions, and some linked to disease reactions. // Have to check these cases. if (r instanceof HyperEdge) return diseaseIds.contains(r.getReactomeId()); if (r instanceof Node) { Node node = (Node) r; List<HyperEdge> edges = node.getConnectedReactions(); boolean isDisease = false; for (HyperEdge edge : edges) { if (edge instanceof FlowLine) { isDisease = isFlowLineRelatedToSet((FlowLine) edge, diseaseIds); } else if (edge.getReactomeId() != null && diseaseIds.contains(edge.getReactomeId())) { isDisease = true; } if (isDisease) return true; } } return false; }
public Renderable getComponentByName(String name) { Renderable renderable = null; for (Iterator it = components.iterator(); it.hasNext(); ) { renderable = (Renderable) it.next(); if (renderable.getDisplayName().equals(name)) return renderable; } return null; }
@Override public Renderable obtain() { Renderable renderable = super.obtain(); renderable.lights = null; renderable.material = null; renderable.mesh = null; renderable.shader = null; return renderable; }
public static Sampleable sampleable(Renderable base) { BoundingBox bb = base.getBoundingBox(); OverlayRaster or = new OverlayRaster(bb.intRight() + 1, bb.intBottom() + 1); base.render(or); return new AbstractSampleable(bb) { @Override public Color getColorAt(Point<Double> point) { return or.getColor(point.toIntegerPoint()); } }; }
public static void renderScene() { for (int ID : renderables.keySet()) { List<Renderable> batch = renderables.get(ID); GL11.glBindTexture(GL11.GL_TEXTURE_2D, ID); for (Renderable renderable : batch) { renderable.masterRender(); } GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); } renderables.clear(); }
/** * Calls {@link RenderableProvider#getRenderables(Array, Pool)} and adds all returned {@link * Renderable} instances to the current batch to be rendered. Any lights set on the returned * renderables will be replaced with the given lights. Any shaders set on the returned renderables * will be replaced by the given {@link Shader}. * * @param renderableProvider the renderable provider * @param lights the lights to use for the renderables * @param shader the shader to use for the renderables */ public void render( final RenderableProvider renderableProvider, final Lights lights, final Shader shader) { int offset = renderables.size; renderableProvider.getRenderables(renderables, renderablesPool); for (int i = offset; i < renderables.size; i++) { Renderable renderable = renderables.get(i); renderable.lights = lights; renderable.shader = shader; renderable.shader = shaderProvider.getShader(renderable); reuseableRenderables.add(renderable); } }
/** * Check if a passed Renderable object can be a Complex's component. * * @param r * @return */ @Override public boolean isAssignable(Renderable r) { if (bounds == null || r == this) // Don't point it to itself return false; // This container has not be materialized if (r instanceof Node) { if (r instanceof RenderableCompartment || r instanceof RenderablePathway || r instanceof Note) return false; // Need to check based on bounds. Should have a full containing if (r.getBounds() == null) return bounds.contains(r.getPosition()); else return bounds.contains(r.getBounds()); } return false; }
private void saveOldBounds() { if (oldIdToBounds == null) oldIdToBounds = new HashMap<Integer, Rectangle>(); else oldIdToBounds.clear(); // Save the bounds for this RenderableComplex. This bounds // will be used as the reference for future recovering oldIdToBounds.put(getID(), new Rectangle(bounds)); for (Renderable r : componentsInHiearchy) { Rectangle rBounds = r.getBounds(); if (rBounds != null) { // Just in case oldIdToBounds.put(r.getID(), new Rectangle(rBounds)); } } }
protected void doRender(DrawContext dc, Iterable<? extends Renderable> renderables) { for (Renderable renderable : renderables) { try { // If the caller has specified their own Iterable, // then we cannot make any guarantees about its contents. if (renderable != null) renderable.render(dc); } catch (Exception e) { String msg = Logging.getMessage("generic.ExceptionWhileRenderingRenderable"); Logging.logger().log(java.util.logging.Level.SEVERE, msg, e); // continue to next renderable } } }
@Override public void onDrawFrame(GL10 gl) { gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT); camera.update(gl); camera.focusOnObjects(gl); for (Renderable r : renderScheduler.getRenderList(gl)) { gl.glPushMatrix(); r.draw(gl); gl.glPopMatrix(); } }
public Renderable removeComponent(Renderable renderable) { Renderable target = getTarget(renderable); stoichiometries.remove(target); if (componentsInHiearchy != null) componentsInHiearchy.remove(renderable); if (oldIdToBounds != null) oldIdToBounds.remove(renderable.getID()); return super.removeComponent(renderable); }
/** This method is used to copy the bounds of this complex to all it contained components. */ public void copyBoundsToComponents() { if (componentsInHiearchy == null || componentsInHiearchy.size() == 0) return; for (Renderable r : componentsInHiearchy) { if (r.bounds == null) { r.bounds = new Rectangle(bounds); if (r.getPosition() == null) r.setPosition(new Point()); ((Node) r).validatePositionFromBounds(); } else { r.bounds.x = bounds.x; r.bounds.y = bounds.y; r.bounds.width = bounds.width; r.bounds.height = bounds.height; } ((Node) r).invalidateTextBounds(); } }
public void addComponent(Renderable renderable) { // as of Jan 22, stoichiometry is disabled. // // Check stoichiometries first // Renderable target = getTarget(renderable); // // Have to make stoichiometries consistent // Integer value = (Integer) stoichiometries.get(target); // if (value == null) // stoichiometries.put(target, new Integer(1)); // else // stoichiometries.put(target, new Integer(value.intValue() + 1)); // // Check if renderable has been added to components // for (Iterator it = components.iterator(); it.hasNext();) { // Renderable r = (Renderable) it.next(); // if (r instanceof Shortcut) // r = ((Shortcut)r).getTarget(); // if (r == target) // return; // } components.add(renderable); rebuildHierarchy(); if (hideComponents) { renderable.setIsVisible(false); if (renderable instanceof ContainerNode) ((ContainerNode) renderable).hideComponents(true); } }
public void render() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); Collections.sort(Handler.renderables); for (Renderable renderable : Handler.renderables) { renderable.render(); } /* * EntityHandler.render(); SpellHandler.render(); */ Display.update(); Display.sync(60); }
private Node replaceNormalNode( Node normalNode, GKInstance diseaseEntity, Boolean needDashedBorder) { Node diseaseNode = normalToDiseaseNode.get(normalNode); if (diseaseNode != null) return diseaseNode; try { // If a node exists already, it should use for (Renderable r : diseaseComps) { if (diseaseEntity.getDBID().equals(r.getReactomeId()) && r instanceof Node) { // This is rather arbitrary: if two nodes are very close, // use the existing one. int dx = Math.abs(r.getPosition().x - normalNode.getPosition().x); int dy = Math.abs(r.getPosition().y - normalNode.getPosition().y); if (dx < 10 && dy < 10) { // We don't need to create a new Node if it exists already normalToDiseaseNode.put(normalNode, (Node) r); overlaidObjects.add(r); // Add it to overlaid object to cover edges return (Node) r; } } } diseaseNode = normalNode.getClass().newInstance(); RenderUtility.copyRenderInfo(normalNode, diseaseNode); // The following should NOT be called since NodeAttachment is // related to disease entity only. // TODO: Need to support this. Currently it is not supported!!! See example // in PI3/AKT cancer pathway. // diseaseNode.setNodeAttachmentsLocally(node.getNodeAttachments()); diseaseNode.setDisplayName(diseaseEntity.getDisplayName()); diseaseNode.setReactomeId(diseaseEntity.getDBID()); diseaseNode.invalidateBounds(); diseaseNode.setRenderer(normalNode.getRenderer()); diseaseNode.setLineColor(DefaultRenderConstants.DEFAULT_DISEASE_BACKGROUND); diseaseNode.setNeedDashedBorder(needDashedBorder); RenderUtility.hideCompartmentInNodeName(diseaseNode); overlaidObjects.add(diseaseNode); displayedObject.addComponent(diseaseNode); normalToDiseaseNode.put(normalNode, diseaseNode); return diseaseNode; } catch (Exception e) { e.printStackTrace(); } return null; }
public boolean isPicked(Point p) { // reset selectionPosition = SelectionPosition.NONE; if (!isVisible || bounds == null) return false; // Check contained components first // Need to check contained components in an order if (componentsInHiearchy != null && componentsInHiearchy.size() > 0) { for (Renderable r : componentsInHiearchy) { if (r.isPicked(p)) return false; } } if (isResizeWidgetPicked(p)) return true; // // Check if text label is picked // if (isTextPicked(p)) { // selectionPosition = SelectionPosition.TEXT; // return true; // } if (isNodeAttachmentPicked(p)) return true; return bounds.contains(p); }
public void testIsRenderable() { Renderable ui = new Renderable(); try { RootPanel.get().add(ui); assertEquals(values.anUnsafeUri(), ui.jsAnchorFromSafeUri.getHref()); AnchorElement anchor = expectedEscapedAnchor(); assertEquals(anchor.getHref(), ui.jsAnchorFromString.getHref()); assertEquals("http://www.google.com/images/logo_sm.gif", ui.inlineHttpAnchor.getHref()); assertEquals("javascript:void(0)", ui.inlineJavascriptAnchor.getHref()); assertEquals( values.aSelector() + values.aGifPath(), ui.httpAnchorFromConstructedString.getHref()); assertEquals(values.anUnsafeUri(), ui.jsAnchorFromSafeUriObj.uri.asString()); assertEquals( "http://www.google.com/images/logo_sm.gif", ui.inlineHttpAnchorObj.uri.asString()); assertEquals("javascript:void(0)", ui.inlineJavascriptAnchorObj.uri.asString()); } finally { ui.removeFromParent(); } }
@Override public void render(GL2 gl, GLU glu, GLUT glut) { // camera.prepare(gl, glu, glut); // preRendering(gl, glu, glut); gl.glLoadIdentity(); camera.prepare(gl, glu, glut); setupWorld(gl, glu, glut); for (Renderable r : this) { gl.glPushMatrix(); r.render(gl, glu, glut); gl.glPopMatrix(); } }
protected void doPick( DrawContext dc, Iterable<? extends Renderable> renderables, java.awt.Point pickPoint) { this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); try { for (Renderable renderable : renderables) { // If the caller has specified their own Iterable, // then we cannot make any guarantees about its contents. if (renderable != null) { float[] inColor = new float[4]; dc.getGL().glGetFloatv(GL.GL_CURRENT_COLOR, inColor, 0); java.awt.Color color = dc.getUniquePickColor(); dc.getGL() .glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); try { renderable.render(dc); } catch (Exception e) { String msg = Logging.getMessage("generic.ExceptionWhilePickingRenderable"); Logging.logger().severe(msg); continue; // go on to next renderable } dc.getGL().glColor4fv(inColor, 0); if (renderable instanceof Locatable) { this.pickSupport.addPickableObject( color.getRGB(), renderable, ((Locatable) renderable).getPosition(), false); } else { this.pickSupport.addPickableObject(color.getRGB(), renderable); } } } this.pickSupport.resolvePick(dc, pickPoint, this); } finally { this.pickSupport.endPicking(dc); } }
private void checkLossOfFunctionNodes() { try { lofNodes = new ArrayList<Node>(); List<Renderable> components = displayedObject.getComponents(); if (components == null || components.size() == 0) return; for (Renderable r : components) { if (r instanceof Node || r.getReactomeId() == null) continue; if (!diseaseIds.contains(r.getReactomeId())) continue; GKInstance inst = adaptor.fetchInstance(r.getReactomeId()); if (!inst.getSchemClass().isa(ReactomeJavaConstants.ReactionlikeEvent) || !inst.getSchemClass().isValidAttribute(ReactomeJavaConstants.entityFunctionalStatus)) continue; List<GKInstance> efs = inst.getAttributeValuesList(ReactomeJavaConstants.entityFunctionalStatus); Set<GKInstance> lofPEs = new HashSet<GKInstance>(); for (GKInstance ef : efs) { GKInstance pe = (GKInstance) ef.getAttributeValue(ReactomeJavaConstants.physicalEntity); if (isLOFEntity(ef)) lofPEs.add(pe); } List<Node> nodes = ((HyperEdge) r).getConnectedNodes(); for (Node node : nodes) { if (node.getReactomeId() == null) continue; GKInstance nodeInst = adaptor.fetchInstance(node.getReactomeId()); Set<GKInstance> nodeRefEntities = getReferenceEntity(nodeInst); for (GKInstance lofPE : lofPEs) { Set<GKInstance> lofRefEntities = getReferenceEntity(lofPE); lofRefEntities.retainAll(nodeRefEntities); if (lofRefEntities.size() > 0) { // A LOF node lofNodes.add(node); break; } } } } } catch (Exception e) { e.printStackTrace(); } }
/** * We override the equals method of Object so that we can compare RunnableRender instances against * each other. Since the important pieces are "wrapped" up, we need to unwrap them to compare them * correctly. For our purposes, we are really interested in whether the associated {@link * com.icesoft.faces.webapp.xmlhttp.PersistentFacesState PersistentFacesState}s are equal so we * "unwrap" each RunnableRender and compare the internal PersistentFacesStates. * * @param obj The RunnableRender to compare to. * @return True if the internal PersistentFacesStates of each RunnableRender are equal. False * otherwise. */ public boolean equals(Object obj) { if (obj == null || !(obj instanceof RunnableRender) || renderable == null) { return false; } Renderable comparedRenderable = ((RunnableRender) obj).getRenderable(); if (comparedRenderable == null) { return false; } PersistentFacesState comparedState = comparedRenderable.getState(); if (comparedState == null) { return false; } PersistentFacesState myState = renderable.getState(); if (myState == null) { return false; } return myState.equals(comparedState); }
private void getSubunits(Renderable node, Set subunits) { List comps = node.getComponents(); if (comps == null || comps.size() == 0) { // Treat an empty complex as a subunit. This might not be good. if (node instanceof Shortcut) subunits.add(((Shortcut) node).getTarget()); else subunits.add(node); } else { Node tmp = null; for (Iterator it = comps.iterator(); it.hasNext(); ) { tmp = (Node) it.next(); getSubunits(tmp, subunits); } } }
private boolean isOldBoundsRecoverable() { if (oldIdToBounds == null || oldIdToBounds.size() == 0) return false; // Make sure all nodes have been registered if (componentsInHiearchy == null || componentsInHiearchy.size() == 0) return false; for (Renderable r : componentsInHiearchy) { if (!oldIdToBounds.containsKey(r.getID())) return false; } // Check if a complex component has the same size as its container. // This may occur when a hidecomponent complex forms a complex with // another Node. for (Renderable r : componentsInHiearchy) { if (!(r instanceof RenderableComplex)) continue; RenderableComplex complex = (RenderableComplex) r; Rectangle complexBounds = oldIdToBounds.get(complex.getID()); List<Renderable> list = RenderUtility.getComponentsInHierarchy(complex); for (Renderable tmp : list) { Rectangle tmpBounds = oldIdToBounds.get(tmp.getID()); if (tmpBounds.width == complexBounds.width && tmpBounds.height == complexBounds.height) return false; } } return true; }
public void paintComponent(Graphics g) { super.paintComponent(g); ((Graphics2D) g).setBackground(Color.BLACK); for (Renderable e : RenderableHolder.getInstance().getRenderableList()) { if (e.isVisible() && e.getZ() < -1) e.draw((Graphics2D) g); } for (Monster m : Cage.getInstance().getCage()) { if (m.isVisible()) { m.draw((Graphics2D) g); } } for (Renderable e : RenderableHolder.getInstance().getRenderableList()) { if (e.isVisible() && e.getZ() >= -1) e.draw((Graphics2D) g); } }
/** * See note above in run method. Just fiddle with the session to try to cause * IllegalStateExceptions before Seam takes over. * * @param state PersistentFacesState used in rendering * @throws IllegalStateException If logged out. */ private void testSession(PersistentFacesState state) throws IllegalStateException { FacesContext fc = state.getFacesContext(); Object o = fc.getExternalContext().getSession(false); if (o == null) { renderable.renderingException( new FatalRenderingException("Session has ended (User Logout?)")); } else { if (o instanceof HttpSession) { HttpSession session = (HttpSession) o; session.getAttributeNames(); } else if (o instanceof PortletSession) { PortletSession ps = (PortletSession) o; ps.getAttributeNames(); } } }