/** * Launch an automatic layout process that will position nodes in the * background. * * @param layoutAlgorithm * The algorithm to use (see Layouts.newLayoutAlgorithm() for the * default algorithm). */ public void enableAutoLayout(Layout layoutAlgorithm) { synchronized (views) { if (optLayout == null) { // optLayout = new LayoutRunner(graph, layoutAlgorithm, true, // true); optLayout = new LayoutRunner(graph, layoutAlgorithm, true, false); graph.replay(); layoutPipeIn = optLayout.newLayoutPipe(); layoutPipeIn.addAttributeSink(graph); } } }
/** * Release any link to the source of events and stop the layout proces. The * thread will end after this method has been called. */ public void release() { pumpPipe.unregisterFromSource(); pumpPipe.removeSink(layout); pumpPipe = null; loop = false; if (Thread.currentThread() != this) { try { this.join(); } catch (Exception e) { logger.log(Level.WARNING, "Unable to stop/release layout.", e); } } layout = null; }
@Override public void run() { String layoutName = layout.getLayoutAlgorithmName(); while (loop) { double limit = layout.getStabilizationLimit(); pumpPipe.pump(); if (limit > 0) { if (layout.getStabilization() > limit) { nap(longNap); } else { layout.compute(); nap(shortNap); } } else { layout.compute(); nap(shortNap); } } logger.info(String.format("Layout '%s' process stopped.", layoutName)); }
/** * Disable the running automatic layout process, if any. */ public void disableAutoLayout() { synchronized (views) { if (optLayout != null) { ((ThreadProxyPipe) layoutPipeIn).unregisterFromSource(); layoutPipeIn.removeSink(graph); layoutPipeIn = null; optLayout.release(); optLayout = null; } } }
/** * New layout runner that listen at the given source and compute a layout on * its graph structure in a distinct thread. * * @param source * The source of graph events. * @param layout * The layout algorithm to use. * @param start * Start the layout thread immediately ? Else the start() method * must be called later. */ public LayoutRunner(Source source, Layout layout, boolean start) { this.layout = layout; this.pumpPipe = new ThreadProxyPipe(); this.pumpPipe.addSink(layout); if (start) start(); this.pumpPipe.init(source); }
/** * Disable the running automatic layout process, if any. */ public void disableAutoLayout() { synchronized (views) { if (optLayout != null) { ((ThreadProxyPipe) layoutPipeIn).unregisterFromSource(); layoutPipeIn.removeSink(graph); layoutPipeIn = null; optLayout.release(); optLayout = null; } } }
/** * New layout runner that listen at the given source and compute a layout on * its graph structure in a distinct thread. * * @param source * The source of graph events. * @param layout * The layout algorithm to use. * @param start * Start the layout thread immediately ? Else the start() method * must be called later. */ public LayoutRunner(Source source, Layout layout, boolean start) { this.layout = layout; this.pumpPipe = new ThreadProxyPipe(); this.pumpPipe.addSink(layout); if (start) start(); this.pumpPipe.init(source); }
/** * Launch an automatic layout process that will position nodes in the * background. * * @param layoutAlgorithm * The algorithm to use (see Layouts.newLayoutAlgorithm() for the * default algorithm). */ public void enableAutoLayout(Layout layoutAlgorithm) { synchronized (views) { if (optLayout == null) { // optLayout = new LayoutRunner(graph, layoutAlgorithm, true, // true); optLayout = new LayoutRunner(graph, layoutAlgorithm, true, false); graph.replay(); layoutPipeIn = optLayout.newLayoutPipe(); layoutPipeIn.addAttributeSink(graph); } } }
case COMPUTED_IN_LAYOUT_RUNNER: optLayout.release(); optLayout = null; layoutPipeIn.removeAttributeSink(gg);
/** * New layout runner that listen at the given graph and compute a layout on * its graph structure in a distinct thread. A pipe is still created to * listen at the graph. This means that the graph is never directly used. * * @param graph * The source of graph events. * @param layout * The layout algorithm to use. * @param start * Start the layout thread immediately ? Else the start() method * must be called later. * @param replay * If the graph already contains some data, replay events to * create the data, this is mostly always needed. */ public LayoutRunner(Graph graph, Layout layout, boolean start, boolean replay) { this.layout = layout; this.pumpPipe = new ThreadProxyPipe(); this.pumpPipe.addSink(layout); if (start) start(); this.pumpPipe.init(graph, replay); }
/** * Release any link to the source of events and stop the layout proces. The * thread will end after this method has been called. */ public void release() { pumpPipe.unregisterFromSource(); pumpPipe.removeSink(layout); pumpPipe = null; loop = false; if (Thread.currentThread() != this) { try { this.join(); } catch (Exception e) { logger.log(Level.WARNING, "Unable to stop/release layout.", e); } } layout = null; }
@Override public void run() { String layoutName = layout.getLayoutAlgorithmName(); while (loop) { double limit = layout.getStabilizationLimit(); pumpPipe.pump(); if (limit > 0) { if (layout.getStabilization() > limit) { nap(longNap); } else { layout.compute(); nap(shortNap); } } else { layout.compute(); nap(shortNap); } } logger.info(String.format("Layout '%s' process stopped.", layoutName)); }
case COMPUTED_IN_LAYOUT_RUNNER: optLayout.release(); optLayout = null; layoutPipeIn.removeAttributeSink(gg);
/** * New layout runner that listen at the given graph and compute a layout on * its graph structure in a distinct thread. A pipe is still created to * listen at the graph. This means that the graph is never directly used. * * @param graph * The source of graph events. * @param layout * The layout algorithm to use. * @param start * Start the layout thread immediately ? Else the start() method * must be called later. * @param replay * If the graph already contains some data, replay events to * create the data, this is mostly always needed. */ public LayoutRunner(Graph graph, Layout layout, boolean start, boolean replay) { this.layout = layout; this.pumpPipe = new ThreadProxyPipe(); this.pumpPipe.addSink(layout); if (start) start(); this.pumpPipe.init(graph, replay); }