/** * Set the layout policy. * * @param policy policy defining how the layout is computed */ public synchronized void setLayoutPolicy(LayoutPolicy policy) { if (policy != layoutPolicy) { switch (layoutPolicy) { case ComputedInLayoutRunner: optLayout.release(); optLayout = null; layoutPipeIn.removeAttributeSink(gg); layoutPipeIn = null; layout = null; break; case ComputedAtNewImage: gg.removeSink(layout); layout.removeAttributeSink(gg); layout = null; break; } switch (policy) { case ComputedInLayoutRunner: layout = Layouts.newLayoutAlgorithm(); optLayout = new LayoutRunner(gg, layout); layoutPipeIn = optLayout.newLayoutPipe(); layoutPipeIn.addAttributeSink(gg); break; case ComputedAtNewImage: layout = Layouts.newLayoutAlgorithm(); gg.addSink(layout); layout.addAttributeSink(gg); break; } layoutPolicy = policy; } }
public synchronized void outputNewImage(String filename) { switch (layoutPolicy) { case COMPUTED_IN_LAYOUT_RUNNER: layoutPipeIn.pump(); break; case COMPUTED_ONCE_AT_NEW_IMAGE: if (layout != null) layout.compute(); break; case COMPUTED_FULLY_AT_NEW_IMAGE: stabilizeLayout(layout.getStabilizationLimit()); break; default: break; } if (resolution.getWidth() != image.getWidth() || resolution.getHeight() != image.getHeight()) initImage(); if (clearImageBeforeOutput) { for (int x = 0; x < resolution.getWidth(); x++) for (int y = 0; y < resolution.getHeight(); y++) image.setRGB(x, y, 0x00000000); } if (gg.getNodeCount() > 0) { if (autofit) { gg.computeBounds(); Point3 lo = gg.getMinPos(); Point3 hi = gg.getMaxPos(); renderer.getCamera().setBounds(lo.x, lo.y, lo.z, hi.x, hi.y, hi.z); } renderer.render(g2d, 0, 0, resolution.getWidth(), resolution.getHeight()); } for (PostRenderer action : postRenderers) action.render(g2d); image.flush(); try { File out = new File(filename); if (out.getParent() != null && !out.getParentFile().exists()) out.getParentFile().mkdirs(); ImageIO.write(image, outputType.name(), out); printProgress(); } catch (IOException e) { // ? } }
protected void clearGG() { gg.clear(); if (styleSheet != null) gg.setAttribute("ui.stylesheet", styleSheet); if (layout != null) layout.clear(); }
public void disableAutoLayout() { if (layout != null) { layoutAlgorithm.removeListener(ctx.getRenderer().getLayoutListener()); layout.release(); layout = null; } }
/** * Set the layout policy. * * @param policy policy defining how the layout is computed */ public synchronized void setLayoutPolicy(LayoutPolicy policy) { if (policy != layoutPolicy) { switch (layoutPolicy) { case COMPUTED_IN_LAYOUT_RUNNER: // layout.removeListener(this); optLayout.release(); optLayout = null; layoutPipeIn.removeAttributeSink(gg); layoutPipeIn = null; layout = null; break; case COMPUTED_ONCE_AT_NEW_IMAGE: // layout.removeListener(this); gg.removeSink(layout); layout.removeAttributeSink(gg); layout = null; break; default: break; } switch (policy) { case COMPUTED_IN_LAYOUT_RUNNER: layout = Layouts.newLayoutAlgorithm(); optLayout = new InnerLayoutRunner(); break; case COMPUTED_FULLY_AT_NEW_IMAGE: case COMPUTED_ONCE_AT_NEW_IMAGE: layout = Layouts.newLayoutAlgorithm(); gg.addSink(layout); layout.addAttributeSink(gg); break; default: break; } // layout.addListener(this); layoutPolicy = policy; } }
/** Produce a new image. */ protected synchronized void outputNewImage() { switch (layoutPolicy) { case ComputedAtNewImage: if (layout != null) layout.compute(); break; } if (resolution.getWidth() != image.getWidth() || resolution.getHeight() != image.getHeight()) initImage(); if (gg.getNodeCount() > 0) { gg.computeBounds(); Point3 lo = gg.getMinPos(); Point3 hi = gg.getMaxPos(); renderer.setBounds(lo.x, lo.y, lo.z, hi.x, hi.y, hi.z); renderer.render(g2d, resolution.getWidth(), resolution.getHeight()); } for (PostRenderer action : postRenderers) action.render(g2d); image.flush(); try { File out = new File(String.format("%s%06d.png", filePrefix, counter++)); if (!out.getParentFile().exists()) out.getParentFile().mkdirs(); ImageIO.write(image, outputType.name(), out); printProgress(); } catch (IOException e) { // ? } }
public void stabilizeLayout(double limit) { if (layout != null) { while (layout.getStabilization() < limit) layout.compute(); } }
/** * Set the stabilization limit of the layout used to compute coordinates of nodes. See {@link * org.graphstream.ui.layout.Layout#setStabilizationLimit(double)} for more informations about * this limit. * * @param limit */ public void setLayoutStabilizationLimit(double limit) { if (layout == null) throw new NullPointerException("did you enable layout ?"); layout.setStabilizationLimit(limit); }
public void enableAutoLayout(Layout layoutAlgorithm) { disableAutoLayout(); layout = new LayoutRunner(source, layoutAlgorithm, true); layoutAlgorithm.addListener(ctx.getRenderer().getLayoutListener()); this.layoutAlgorithm = layoutAlgorithm; }