private void openCircuit(object sender, RoutedEventArgs e) { Dictionary <String, FileType> fileTypes = FactoryMethod <String, FileType> .getList(); String filter = ""; foreach (var type in fileTypes) { filter += type.Value.getFilter(); } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = filter.Substring(0, filter.LastIndexOf('|')); openFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); if (openFileDialog.ShowDialog() == true) { String fileName = openFileDialog.FileName; int index = fileName.LastIndexOf('.') + 1; String extension = fileName.Substring(index, fileName.Length - index); fileTypes[extension].open(fileName); } updateConnectionList(); }
private void saveCircuit() { Dictionary <String, FileType> fileTypes = FactoryMethod <String, FileType> .getList(); String filter = ""; foreach (var type in fileTypes) { filter += type.Value.getFilter(); } SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = filter.Substring(0, filter.LastIndexOf('|')); saveFileDialog.InitialDirectory = Directory.GetCurrentDirectory(); if (saveFileDialog.ShowDialog() == true) { String fileName = saveFileDialog.FileName; int index = fileName.LastIndexOf('.') + 1; String extension = fileName.Substring(index, fileName.Length - index); fileTypes[extension].save(fileName, Circuit.getList()); circuitSaved_ = true; } }
private static FactoryMethod <TKey, TObject> instance() { if (instance_ == null) { instance_ = new FactoryMethod <TKey, TObject>(); instance_.initialize(); } return(instance_); }
public MainWindow() { InitializeComponent(); Closing += closeWindow; circuitCanvas_ = CircuitCanvas; // Show list of possible nodes Dictionary <String, Node> listNodes = FactoryMethod <String, Node> .getList(); foreach (var node in listNodes) { NodeList.Items.Add(node.Key); } }
/// <summary> /// Adding a new node to the circuit /// </summary> private void addNode(object sender, RoutedEventArgs e) { // Get type and name of node String nodeName = (String)NodeList.SelectedItem; String name = NodeName.Text; // Create new node from factory Node node = FactoryMethod <String, Node> .create(nodeName); node.setName(name); Circuit.addNode(name, node); updateConnectionList(); NodeList.UnselectAll(); circuitSaved_ = false; }
private void createNodes(List <String> lines) { foreach (String line in lines) { int startPosition = 0; int position = line.IndexOf(':'); String name = line.Substring(startPosition, position); int lastSpace = line.LastIndexOf(' '); int lastTab = line.LastIndexOf('\t'); startPosition = Math.Max(lastSpace, lastTab) + 1; position = line.IndexOf(';', startPosition); String type = line.Substring(startPosition, position - startPosition); Node node = FactoryMethod <String, Node> .create(type); node.setName(name); Circuit.addNode(name, node); } }
public static FileType create(String name) { return(FactoryMethod <String, FileType> .create(name)); }
public static Node create(String name) { return(FactoryMethod <String, Node> .create(name)); }