use of au.gov.asd.tac.constellation.utilities.visual.VisualManager in project constellation by constellation-app.
the class RecentGraphScreenshotUtilities method takeScreenshot.
/**
* Take a screenshot of the graph and save it to the screenshots directory
* so that it can be used by the Welcome View.
*
* @param filename The filename of the graph
*/
public static void takeScreenshot(final String filename) {
final String imageFile = getScreenshotsDir() + File.separator + filename + FileExtensionConstants.PNG;
final Path source = Paths.get(imageFile);
final GraphNode graphNode = GraphNode.getGraphNode(GraphManager.getDefault().getActiveGraph());
final VisualManager visualManager = graphNode.getVisualManager();
final BufferedImage[] originalImage = new BufferedImage[1];
originalImage[0] = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_ARGB);
if (visualManager != null) {
final Semaphore waiter = new Semaphore(0);
visualManager.exportToBufferedImage(originalImage, waiter);
waiter.acquireUninterruptibly();
}
try {
// resizeAndSave the buffered image in memory and write the image to disk
resizeAndSave(originalImage[0], source, IMAGE_SIZE, IMAGE_SIZE);
refreshScreenshotsDir();
} catch (final IOException ex) {
LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
}
}
use of au.gov.asd.tac.constellation.utilities.visual.VisualManager in project constellation by constellation-app.
the class GetGraphImage method callService.
@Override
public void callService(final PluginParameters parameters, final InputStream in, final OutputStream out) throws IOException {
final Graph graph = GraphManager.getDefault().getActiveGraph();
if (graph == null) {
throw new RestServiceException(HTTP_UNPROCESSABLE_ENTITY, "No graph is opened in Constellation");
}
// This is asynchronous, so we need a Semaphore.
//
final GraphNode graphNode = GraphNode.getGraphNode(graph);
final VisualManager visualManager = graphNode.getVisualManager();
final BufferedImage[] img1 = new BufferedImage[1];
if (visualManager != null) {
final Semaphore waiter = new Semaphore(0);
visualManager.exportToBufferedImage(img1, waiter);
waiter.acquireUninterruptibly();
ImageIO.write(img1[0], "png", out);
} else {
throw new IOException("Graph image unavailable");
}
}
use of au.gov.asd.tac.constellation.utilities.visual.VisualManager in project constellation by constellation-app.
the class GLInteractiveVisualManagerFactory method constructVisualManager.
@Override
public VisualManager constructVisualManager(Graph graph) {
final GraphVisualAccess access = new GraphVisualAccess(graph);
try (final ReadableGraph rg = graph.getReadableGraph()) {
access.updateModCounts(rg);
}
final Preferences prefs = NbPreferences.forModule(DeveloperPreferenceKeys.class);
final InteractiveGLVisualProcessor processor = new InteractiveGLVisualProcessor(prefs.getBoolean(DeveloperPreferenceKeys.DEBUG_GL, DeveloperPreferenceKeys.DEBUG_GL_DEFAULT), prefs.getBoolean(DeveloperPreferenceKeys.PRINT_GL_CAPABILITIES, DeveloperPreferenceKeys.PRINT_GL_CAPABILITIES_DEFAULT));
final VisualManager manager = new VisualManager(access, processor);
final GraphChangeListener changeDetector = event -> manager.updateFromIndigenousChanges();
final DefaultInteractionEventHandler eventHandler = new DefaultInteractionEventHandler(graph, manager, processor, processor);
processor.addDropTargetToCanvas(new GraphRendererDropTarget(graph, manager, processor));
graph.addGraphChangeListener(changeDetector);
changeDetector.graphChanged(null);
processor.startVisualising(manager);
processor.setEventHandler(eventHandler);
return manager;
}
use of au.gov.asd.tac.constellation.utilities.visual.VisualManager in project constellation by constellation-app.
the class GLVisualProcessorGraphTester method main.
public static void main(String[] args) {
final GLVisualProcessorDemo demo = new GLVisualProcessorDemo();
final StoreGraph graph = createGraph();
final Graph dualGraph = new DualGraph(graph, false);
final GraphVisualAccess access = new GraphVisualAccess(dualGraph);
final GLVisualProcessor processor = new GLVisualProcessor();
final VisualManager visualManager = new VisualManager(access, processor);
processor.startVisualising(visualManager);
demo.runDemo(processor, visualManager);
final GraphChangeListener gct = (event) -> visualManager.updateFromIndigenousChanges();
gct.graphChanged(null);
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
}
try {
WritableGraph wg = dualGraph.getWritableGraph("linkmode", false);
try {
final int connectionModeAttr = VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(wg);
wg.setObjectValue(connectionModeAttr, 0, ConnectionMode.LINK);
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
}
gct.graphChanged(null);
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
}
try {
WritableGraph wg = dualGraph.getWritableGraph("transmode", false);
try {
final int connectionModeAttr = VisualConcept.GraphAttribute.CONNECTION_MODE.ensure(wg);
wg.setObjectValue(connectionModeAttr, 0, ConnectionMode.TRANSACTION);
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
}
gct.graphChanged(null);
try {
Thread.sleep(2000);
} catch (InterruptedException ex) {
}
final int[] changed = new int[] { 0, 1 };
try {
WritableGraph wg = dualGraph.getWritableGraph("blazin", false);
try {
final int blazeAttr = VisualConcept.VertexAttribute.BLAZE.ensure(wg);
for (int i = 0; i < 10000; i++) {
try {
Thread.sleep(1);
} catch (InterruptedException ex) {
}
wg.setObjectValue(blazeAttr, 0, new Blaze(((Blaze) wg.getObjectValue(blazeAttr, 0)).getAngle() + 1, ConstellationColor.BLUE));
wg = wg.flush(false);
visualManager.addSingleChangeOperation(new VisualChangeBuilder(VisualProperty.VERTEX_BLAZE_ANGLE).forItems(changed).build());
}
} finally {
wg.commit();
}
} catch (InterruptedException ex) {
}
}
use of au.gov.asd.tac.constellation.utilities.visual.VisualManager in project constellation by constellation-app.
the class ExportToImagePlugin method execute.
@Override
protected void execute(final PluginGraphs graphs, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
final String fnam = parameters.getParameters().get(FILE_NAME_PARAMETER_ID).getStringValue();
final File imageFile = new File(fnam);
final GraphNode graphNode = GraphNode.getGraphNode(graphs.getGraph());
final VisualManager visualManager = graphNode.getVisualManager();
if (visualManager != null) {
visualManager.exportToImage(imageFile);
final ReadableGraph rg = graphs.getGraph().getReadableGraph();
try {
ConstellationLoggerHelper.exportPropertyBuilder(this, GraphRecordStoreUtilities.getVertices(rg, false, false, false).getAll(GraphRecordStoreUtilities.SOURCE + VisualConcept.VertexAttribute.LABEL), new File(fnam), ConstellationLoggerHelper.SUCCESS);
} finally {
rg.release();
}
}
}
Aggregations