@Override public void dragGestureRecognized(DragGestureEvent event) { TreePath path = tree.getSelectionPath(); if (path != null) { // Dragged node is a DefaultMutableTreeNode if (path.getLastPathComponent() instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) path.getLastPathComponent(); // This is an ObjectType node if (treeNode.getUserObject() instanceof ObjectType) { ObjectType type = (ObjectType) treeNode.getUserObject(); Cursor cursor = null; if (event.getDragAction() == DnDConstants.ACTION_COPY) { cursor = DragSource.DefaultCopyDrop; } if (RenderManager.isGood()) { // The new renderer is initialized RenderManager.inst().startDragAndDrop(type); event.startDrag(cursor, new TransferableObjectType(type), RenderManager.inst()); } else { event.startDrag(cursor, new TransferableObjectType(type)); } } } } }
@Override public Component getTreeCellRendererComponent( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); // If not a leaf, just return if (!leaf) return this; // If we don't find an ObjectType (likely we will) just return Object userObj = ((DefaultMutableTreeNode) value).getUserObject(); if (!(userObj instanceof ObjectType)) return this; ObjectType type = (ObjectType) userObj; this.setText(type.getName()); if (!RenderManager.isGood()) return this; if (type.getIconImage() == null) return this; icon.setImage(type.getIconImage()); this.setIcon(icon); return this; }
@Override public void collectProxies(double simTime, ArrayList<RenderProxy> out) { if (labelObservee == null || !labelObservee.getShow()) { return; } String text = labelObservee.getCachedText(); double height = labelObservee.getTextHeight(); Color4d color = fontColor.getValue(); TessFontKey fk = new TessFontKey(fontName.getChoice(), style); Vec3d textSize = RenderManager.inst().getRenderedStringSize(fk, height, text); Transform trans = labelObservee.getGlobalTransForSize(textSize, simTime); boolean ds = dropShadow.getValue(); Color4d dsColor = dropShadowColor.getValue(); Vec3d dsOffset = dropShadowOffset.getValue(); VisibilityInfo vi = getVisibilityInfo(); boolean dirty = false; dirty = dirty || !compare(textCache, text); dirty = dirty || !compare(transCache, trans); dirty = dirty || dirty_col4d(colorCache, color); dirty = dirty || heightCache != height; dirty = dirty || !compare(fkCache, fk); dirty = dirty || dropShadowCache != ds; dirty = dirty || dirty_col4d(dsColorCache, dsColor); dirty = dirty || dirty_vec3d(dsOffsetCache, dsOffset); dirty = dirty || !compare(viCache, vi); textCache = text; transCache = trans; colorCache = color; heightCache = height; fkCache = fk; dropShadowCache = ds; dsColorCache = dsColor; dsOffsetCache = dsOffset; viCache = vi; if (cachedProxies != null && !dirty) { // Nothing changed out.addAll(cachedProxies); registerCacheHit("TextLabel"); return; } registerCacheMiss("TextLabel"); if (trans == null) { return; } cachedProxies = new ArrayList<RenderProxy>(); cachedProxies.add( new StringProxy(text, fk, color, trans, height, vi, labelObservee.getEntityNumber())); if (ds) { Transform dsTrans = new Transform(trans); Vec3d shadowTrans = new Vec3d(dsOffset); shadowTrans.scale3(height); shadowTrans.add3(dsTrans.getTransRef()); dsTrans.setTrans(shadowTrans); cachedProxies.add( new StringProxy( text, fk, dsColor, dsTrans, height, vi, labelObservee.getEntityNumber())); } out.addAll(cachedProxies); }