private void SaveGraphAsImage() { //TODO: ENSURE THAT DATA IS EVEN PRESENT ON THE GRAPH //TODO: THIS SHOULD BE DECOUPLED ImageTools.IO.Encoders.AddEncoder <ImageTools.IO.Jpeg.JpegEncoder>(); ImageTools.IO.Encoders.AddEncoder <ImageTools.IO.Png.PngEncoder>(); UI.GraphViewModel graphVM = UI.ViewModelLocator.GraphDataStatic; ImageTools.ExtendedImage myImage = graphVM.GraphToImage(); System.Windows.Controls.SaveFileDialog saveFileDialog = new System.Windows.Controls.SaveFileDialog(); saveFileDialog.Filter = "JPEG Files (*.jpg)|*.jpg|PNG Files (*.png)|*.png"; saveFileDialog.FilterIndex = 1; bool?dialogResult = saveFileDialog.ShowDialog(); if (dialogResult == true) { using (Stream fs = (Stream)saveFileDialog.OpenFile()) { myImage.WriteToStream(fs, saveFileDialog.SafeFileName); } } }
/// <summary> /// Handles the DataLoaded event /// </summary> /// <param name="args">The arguments for the event</param> public void DataLoadedEventHandler(DataLoadedEventArgs args) { if (args.SourceMechanism == CreationType.Live) { LayoutGraph(LayoutManager.Instance.ActiveLayout, false, args.Scope); } else if (AllNodesHaveSamePosition(args.Scope)) { // Layout the graph LayoutGraph(LayoutManager.Instance.DefaultLayout, true, args.Scope); } else { // Just resize the graph to fit UI.GraphViewModel graphVM = UI.ViewModelLocator.GraphDataStatic; graphVM.ResizeToFit(); } }
/// <summary> /// Handles the ToolbarItemClicked event /// </summary> /// <param name="args">The arguments for the event</param> public void ToolbarItemClickedEventHandler(ToolBarItemEventArgs args) { NodeViewModelBase rootNode = GetGraphComponents(args.Scope).NodeSelector.SelectedNode; // TODO: USE CONSTANT FOR ITEM NAME // TODO: Controls should control their own behavior if (args.ToolBarItem.Name == "GENERATOR") { CreateRandomGraph(args.Scope); } else if (args.ToolBarItem.Name.EndsWith("_LAYOUT")) { LayoutBase layout = InitializeLayout(args.ToolBarItem.Name, args.Scope); // Perform the layout LayoutGraph(layout, false, args.Scope, rootNode); } else if (args.ToolBarItem.Name == "IMPORT") { PerformImport(args.Scope, new GraphMLGraphDataFormat()); // TODO: Determine which type at runtime } else if (args.ToolBarItem.Name == "EXPORT") { PerformExport(args.Scope); } else if (args.ToolBarItem.Name == "GRAPH_TO_IMAGE") { SaveGraphAsImage(); } else if (args.ToolBarItem.Name == "PRINT_GRAPH") { PrintGraph(); } else if (args.ToolBarItem.Name == "RESIZE") { UI.GraphViewModel graphVM = UI.ViewModelLocator.GraphDataStatic; graphVM.ResizeToFit(); //TODO: THIS SHOULD BE DECOUPLED } }