diff --git a/cyclist/src/edu/utexas/cycic/Cycic.java b/cyclist/src/edu/utexas/cycic/Cycic.java index f023e55b..8fe867d4 100644 --- a/cyclist/src/edu/utexas/cycic/Cycic.java +++ b/cyclist/src/edu/utexas/cycic/Cycic.java @@ -597,7 +597,7 @@ public void changed(ObservableValue observable, String oldValu } HashMap months = new HashMap(); - ArrayList monthList = new ArrayList(); + static ArrayList monthList = new ArrayList(); /** * Quick hack to convert months into their integer values. * i.e. January = 0, Feb = 1, etc... diff --git a/cyclist/src/edu/utexas/cycic/CycicCircles.java b/cyclist/src/edu/utexas/cycic/CycicCircles.java index 4e1beebf..23de8cdb 100644 --- a/cyclist/src/edu/utexas/cycic/CycicCircles.java +++ b/cyclist/src/edu/utexas/cycic/CycicCircles.java @@ -112,6 +112,7 @@ public void handle(ActionEvent e){ public void handle(ActionEvent e){ /** TODO CHANGE NICHE OF CIRCLE */ TextInputDialog dg = new TextInputDialog(parent.niche); + dg.setResizable(true); dg.setContentText("New Niche: "); Optional result = dg.showAndWait(); if (result.isPresent()){ diff --git a/cyclist/src/edu/utexas/cycic/DataArrays.java b/cyclist/src/edu/utexas/cycic/DataArrays.java index 88da07e9..9cc8604b 100644 --- a/cyclist/src/edu/utexas/cycic/DataArrays.java +++ b/cyclist/src/edu/utexas/cycic/DataArrays.java @@ -390,6 +390,7 @@ class facilityNode{ String facilityType = ""; Integer facTypeIndex = 0; String facLifetime = ""; + Integer userLevel = 0; ArrayList facilityData = new ArrayList(); ArrayList facilityStructure = new ArrayList(); ArrayList facilityClones = new ArrayList(); diff --git a/cyclist/src/edu/utexas/cycic/FormBuilder.java b/cyclist/src/edu/utexas/cycic/FormBuilder.java index d1148e14..03b60109 100644 --- a/cyclist/src/edu/utexas/cycic/FormBuilder.java +++ b/cyclist/src/edu/utexas/cycic/FormBuilder.java @@ -37,9 +37,7 @@ public FormBuilder(){ super(); formNode = Cycic.workingNode; TITLE = (String) Cycic.workingNode.name; - System.out.println(formNode.facilityStructure); - formBuilder(grid, formNode.facilityStructure, formNode.facilityData); - + userLevel = formNode.userLevel; Button button = new Button(); button.setText(formNode.facilityType); @@ -54,6 +52,7 @@ public FormBuilder(){ public void changed(ObservableValue observable, String oldValue, String newValue){ userLevelBox.setValue(newValue); userLevel = Integer.parseInt(newValue); + formNode.userLevel = Integer.parseInt(newValue); grid.getChildren().clear(); if (userLevel > 0) { grid.add(lifetimeLabel,0,0); @@ -93,6 +92,7 @@ public void handle(MouseEvent e){ Cycic.workingNode = formNode; } }); + formBuilder(grid, formNode.facilityStructure, formNode.facilityData); setTitle(TITLE); setContent(formGrid); } @@ -163,6 +163,7 @@ public void handle(ActionEvent e) { public static void showHelpDialog(String help) { Dialog dg = new Dialog(); + dg.setResizable(true); ButtonType loginButtonType = new ButtonType("Ok", ButtonData.OK_DONE); dg.setContentText(help); dg.getDialogPane().getButtonTypes().addAll(loginButtonType, ButtonType.CANCEL); @@ -294,8 +295,12 @@ public void formBuilder(GridPane grid, ArrayList facArray, ArrayList) facArray, (ArrayList) dataArray), columnNumber+1, rowNumber); // Indenting a sub structure + rowNumber += 1; columnNumber += 1; for(int ii = 0; ii < dataArray.size(); ii ++){ grid.add(arrayListRemove(grid, dataArray, ii, facArray), columnNumber+2, rowNumber); @@ -304,7 +309,6 @@ public void formBuilder(GridPane grid, ArrayList facArray, ArrayList) facArray, (ArrayList) dataArray), columnNumber, rowNumber); rowNumber += 1; } } else if (facArray.get(1) instanceof ArrayList) { diff --git a/cyclist/src/edu/utexas/cycic/FormBuilderFunctions.java b/cyclist/src/edu/utexas/cycic/FormBuilderFunctions.java index fa55a6ee..2c832ba4 100644 --- a/cyclist/src/edu/utexas/cycic/FormBuilderFunctions.java +++ b/cyclist/src/edu/utexas/cycic/FormBuilderFunctions.java @@ -3,7 +3,6 @@ import java.io.File; import java.util.ArrayList; -import edu.utah.sci.cyclist.core.presenter.SelectionModel; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.event.ActionEvent; @@ -11,14 +10,10 @@ import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; -import javafx.scene.control.SelectionMode; import javafx.scene.control.Slider; import javafx.scene.control.TextField; import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; -import javafx.scene.paint.Color; -import javafx.scene.shape.Shape; -import javafx.scene.text.Text; import javafx.stage.FileChooser; import javafx.stage.Window; @@ -312,7 +307,9 @@ public void handle(MouseEvent e){ cb.getItems().clear(); for(CommodityNode label: DataArrays.CommoditiesList){ - cb.getItems().add(label.name.getText()); + if(!label.name.getText().equalsIgnoreCase("")){ + cb.getItems().add(label.name.getText()); + } } cb.getItems().add("New Commodity"); @@ -327,11 +324,10 @@ public void handle(MouseEvent e){ cb.setPromptText("Select a commodity"); cb.valueProperty().addListener(new ChangeListener(){ public void changed(ObservableValue observable, String oldValue, String newValue){ - if(newValue == null){ + if(newValue == null || newValue.equalsIgnoreCase("")){ for (int i = 0; i < facNode.cycicCircle.incommods.size(); i++) { if (facNode.cycicCircle.incommods.get(i) == (String) oldValue){ - String string = facNode.cycicCircle.incommods.remove(i); - System.out.println(string); + facNode.cycicCircle.incommods.remove(i); break; } } @@ -378,7 +374,9 @@ public void handle(MouseEvent e){ }*/ cb.getItems().clear(); for (CommodityNode label: DataArrays.CommoditiesList){ - cb.getItems().add(label.name.getText()); + if(!label.name.getText().equalsIgnoreCase("")){ + cb.getItems().add(label.name.getText()); + } } cb.getItems().add("New Commodity"); @@ -393,7 +391,7 @@ public void handle(MouseEvent e){ cb.setPromptText("Select a commodity"); cb.valueProperty().addListener(new ChangeListener(){ public void changed(ObservableValue observable, String oldValue, String newValue){ - if(newValue == null){ + if(newValue == null || newValue.equalsIgnoreCase("")){ for (int i = 0; i < facNode.cycicCircle.outcommods.size(); i++) { if (facNode.cycicCircle.outcommods.get(i) == (String) oldValue){ facNode.cycicCircle.outcommods.remove(i); @@ -469,17 +467,24 @@ static ComboBox comboBoxCommod(ArrayList facArray, final ArrayLi public void handle(MouseEvent e){ cb.getItems().clear(); for (CommodityNode label: DataArrays.CommoditiesList){ - cb.getItems().add(label.name.getText()); + if(!label.name.getText().equalsIgnoreCase("")){ + cb.getItems().add(label.name.getText()); + } } - //cb.getItems().add("New Commodity"); + cb.getItems().add("New Commodity"); } }); cb.valueProperty().addListener(new ChangeListener(){ public void changed(ObservableValue observable, String oldValue, String newValue){ - defaultValue.set(0, newValue); - if((Boolean) facArray.get(10) == false){ - facArray.set(10, true); + if(newValue == null || newValue.equalsIgnoreCase("")){ + } else if (newValue == "New Commodity"){ + Cycic.addNewCommodity(); + } else { + defaultValue.set(0, newValue); + if((Boolean) facArray.get(10) == false){ + facArray.set(10, true); + } } } }); diff --git a/cyclist/src/edu/utexas/cycic/InstitutionView.java b/cyclist/src/edu/utexas/cycic/InstitutionView.java index 1544e992..5f533fff 100644 --- a/cyclist/src/edu/utexas/cycic/InstitutionView.java +++ b/cyclist/src/edu/utexas/cycic/InstitutionView.java @@ -49,7 +49,8 @@ public InstitutionView() { ListView facilityList = new ListView(); facilityList.setOrientation(Orientation.VERTICAL); - facilityList.setMinHeight(25); + facilityList.autosize(); + facilityList.setMaxWidth(100); ContextMenu listCtxtMenu = new ContextMenu(); MenuItem removeFac = new MenuItem("Remove Initial Facility"); @@ -74,14 +75,14 @@ public void handle(MouseEvent event){ facilityList.getItems().add(fac.getKey() + " - " + fac.getValue()); } - topGrid.add(new Label(InstitutionCorralView.workingInstitution.type), 2, 0); + topGrid.add(new Label(InstitutionCorralView.workingInstitution.type), 4, 0); // Setting up the view visuals. topGrid.setHgap(10); topGrid.setVgap(2); topGrid.add(new Label("Name"), 0, 0); - topGrid.add(FormBuilderFunctions.institNameBuilder(InstitutionCorralView.workingInstitution), 1, 0); + topGrid.add(FormBuilderFunctions.institNameBuilder(InstitutionCorralView.workingInstitution), 1, 0, 2, 1); topGrid.add(new Label("Prototype"), 0, 2); ComboBox protoName = new ComboBox(); @@ -108,6 +109,7 @@ public void replaceSelection(String text) { } } }; + protoNumber.setMaxWidth(20); topGrid.add(protoNumber, 3, 2); Button protoButton = new Button("Add"); protoButton.setOnAction(new EventHandler(){ @@ -134,8 +136,6 @@ public void handle(ActionEvent e){ VBox regionGridBox = new VBox(); regionGridBox.getChildren().addAll(topGrid, grid); - - VBox listBox = new VBox(); listBox.getChildren().addAll(new Label("Initial Facilities"), facilityList); HBox overView = new HBox(); @@ -143,7 +143,7 @@ public void handle(ActionEvent e){ setTitle(TITLE); setContent(overView); - setPrefSize(600,400); + //setPrefSize(600,400); formBuilder(InstitutionCorralView.workingInstitution.institStruct, InstitutionCorralView.workingInstitution.institData); } @@ -194,34 +194,56 @@ public void formBuilder(ArrayList facArray, ArrayList dataArray) // resetting the indent columnNumber -= 1; } - } else if (facArray.get(2) == "zeroOrMore") { + } else if (facArray.get(2) == "oneOrMoreMap"){ + //facArray = (ArrayList) facArray.get(1); + //dataArray = (ArrayList) dataArray.get(0); if ((int)facArray.get(6) <= userLevel && i == 0){ Label name = new Label((String) facArray.get(0)); + if(facArray.get(9) != null && !facArray.get(9).toString().equalsIgnoreCase("")){ + name.setText((String) facArray.get(9)); + } else { + name.setText((String) facArray.get(0)); + } + name.setTooltip(new Tooltip((String)facArray.get(7))); + name.setOnMouseClicked(FormBuilder.helpDialogHandler( (String) facArray.get(8))); grid.add(name, columnNumber, rowNumber); - grid.add(orMoreAddButton(grid, (ArrayList) facArray, (ArrayList) dataArray), 1+columnNumber, rowNumber); + grid.add(orMoreAddButton(grid, (ArrayList) facArray, (ArrayList) dataArray), columnNumber+1, rowNumber); rowNumber += 1; // Indenting a sub structure columnNumber += 1; for(int ii = 0; ii < dataArray.size(); ii ++){ - grid.add(arrayListRemove(dataArray, ii), columnNumber-1, rowNumber); + if ( ii > 0 ) { + grid.add(arrayListRemove(dataArray, ii), columnNumber+2, rowNumber); + } formBuilder((ArrayList)facArray.get(1), (ArrayList) dataArray.get(ii)); rowNumber += 1; } // resetting the indent columnNumber -= 1; } - } else if (facArray.get(2) == "input" || facArray.get(2) == "output") { - if ((int)facArray.get(6) <= userLevel){ + } else if (facArray.get(2) == "zeroOrMore") { + if ((int)facArray.get(6) <= userLevel && i == 0){ Label name = new Label((String) facArray.get(0)); + if(facArray.get(9) != null && !facArray.get(9).toString().equalsIgnoreCase("")){ + name.setText((String) facArray.get(9)); + } else { + name.setText((String) facArray.get(0)); + } + name.setTooltip(new Tooltip((String)facArray.get(7))); + name.setOnMouseClicked(FormBuilder.helpDialogHandler( (String) facArray.get(8))); grid.add(name, columnNumber, rowNumber); - rowNumber += 1; + grid.add(orMoreAddButton(grid, (ArrayList) facArray, (ArrayList) dataArray), columnNumber+1, rowNumber); // Indenting a sub structure + rowNumber += 1; columnNumber += 1; for(int ii = 0; ii < dataArray.size(); ii ++){ - formBuilder((ArrayList)facArray.get(1), (ArrayList) dataArray.get(ii)); + grid.add(arrayListRemove(dataArray, ii), columnNumber+2, rowNumber); + formBuilder((ArrayList)facArray.get(1), (ArrayList) dataArray.get(ii)); + rowNumber += 1; } // resetting the indent columnNumber -= 1; + rowNumber += 1; } } else { // Adding the label diff --git a/cyclist/src/edu/utexas/cycic/OutPut.java b/cyclist/src/edu/utexas/cycic/OutPut.java index 446aa6b0..f53a7766 100644 --- a/cyclist/src/edu/utexas/cycic/OutPut.java +++ b/cyclist/src/edu/utexas/cycic/OutPut.java @@ -5,18 +5,11 @@ import java.util.Base64; import java.util.Map; import java.util.Optional; -import java.util.Set; import javafx.scene.control.ButtonType; import javafx.scene.control.Dialog; import javafx.scene.control.Label; -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonObject; -import javax.json.JsonReader; -import javax.json.JsonString; -import javax.json.JsonValue; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; @@ -328,7 +321,6 @@ public static void facilityBuilder(Document doc, Element rootElement, facilityNo Element configType = doc.createElement(facType.replace(" ", "").toString()); config.appendChild(configType); - for(int i = 0; i < dataArray.size(); i++){ if (dataArray.get(i) instanceof ArrayList){ facilityDataElement(doc, configType, (ArrayList) facArray.get(i), (ArrayList) dataArray.get(i)); @@ -410,7 +402,7 @@ public static void facilityDataElement(Document doc, Element rootElement, ArrayL * @return Boolean to indicate whether a indent is required. */ public static boolean indentCheck(String string){ - if(string == "oneOrMore" || string == "zeroOrMore"||string == "oneOrMoreMap" || string == "pair" || string == "item"){ + if(string.equalsIgnoreCase("oneOrMore") || string.equalsIgnoreCase("zeroOrMore")||string.equalsIgnoreCase("oneOrMoreMap") || string.equalsIgnoreCase("pair") || string.equalsIgnoreCase("item")){ return true; } else { return false; @@ -490,6 +482,7 @@ public static void loadFile(File file){ loadSimControl(doc); loadCommodities(doc); + loadRecipes(doc); Cycic.buildCommodPane(); NodeList uiItem = doc.getElementsByTagName("ui"); String uiString = uiItem.item(0).getTextContent().replaceAll("\\\\\"", "\""); @@ -660,7 +653,7 @@ static public void loadSimControl(Document doc){ // Start Month String startMonth = doc.getElementsByTagName("startmonth").item(0).getTextContent(); Cycic.workingScenario.simulationData.startMonth = startMonth; - Cycic.startMonth.setValue(startMonth); + Cycic.startMonth.setValue(Cycic.monthList.get(Integer.parseInt(Cycic.workingScenario.simulationData.startMonth)-1)); // Start Year String startYear = doc.getElementsByTagName("startyear").item(0).getTextContent(); @@ -668,6 +661,29 @@ static public void loadSimControl(Document doc){ Cycic.startYear.setText(startYear); } + + + static public void loadRecipes(Document doc){ + NodeList recipeList = doc.getElementsByTagName("recipe"); + for (int i = 0; i < recipeList.getLength(); i++){ + Node tempRecipe = recipeList.item(i); + Nrecipe recipe = new Nrecipe(); + recipe.Name = tempRecipe.getChildNodes().item(1).getTextContent(); + recipe.Basis = tempRecipe.getChildNodes().item(3).getTextContent(); + for(int j = 5; j < tempRecipe.getChildNodes().getLength(); j+=2){ + Node comp = tempRecipe.getChildNodes().item(j); + isotopeData composition = new isotopeData(); + composition.Name = comp.getChildNodes().item(1).getTextContent(); + if(recipe.Basis.equalsIgnoreCase("mass")){ + composition.mass = Double.parseDouble(comp.getChildNodes().item(3).getTextContent()); + } else { + composition.atom = Double.parseDouble(comp.getChildNodes().item(3).getTextContent()); + } + recipe.Composition.add(composition); + } + Cycic.workingScenario.Recipes.add(recipe); + } + } static public void loadFacilities(Map object){ Object[] keys = object.keySet().toArray(); @@ -679,6 +695,7 @@ static public void loadFacilities(Map object){ facNode.archetype = (String) fac.get("archetype"); facNode.facilityType = (String) fac.get("type"); facNode.cycicCircle = CycicCircles.addNode((String) facNode.name, facNode); + facNode.niche = (String) fac.get("niche"); facNode.cycicCircle.niche = (String) fac.get("niche"); facNode.cycicCircle.setCenterX(Double.parseDouble((String) fac.get("X"))); facNode.cycicCircle.setCenterY(Double.parseDouble((String) fac.get("Y"))); @@ -834,6 +851,20 @@ public static String xmlStringGen(){ for(Nrecipe recipe : CycicScenarios.workingCycicScenario.Recipes){ recipeBuilder(doc, rootElement, recipe); } + + for(instituteNode inst : CycicScenarios.workingCycicScenario.institNodes){ + if(inst.name.equalsIgnoreCase("__inst__")){ + CycicScenarios.workingCycicScenario.institNodes.remove(inst); + break; + } + } + + for(regionNode region : CycicScenarios.workingCycicScenario.regionNodes){ + if(region.name.equalsIgnoreCase("__region__")){ + CycicScenarios.workingCycicScenario.regionNodes.remove(region); + break; + } + } // Writing out the xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); diff --git a/cyclist/src/edu/utexas/cycic/RegionShape.java b/cyclist/src/edu/utexas/cycic/RegionShape.java index 6bdd9557..8e61ced7 100644 --- a/cyclist/src/edu/utexas/cycic/RegionShape.java +++ b/cyclist/src/edu/utexas/cycic/RegionShape.java @@ -5,14 +5,11 @@ import edu.utah.sci.cyclist.core.controller.CyclistController; import edu.utah.sci.cyclist.core.event.dnd.DnD; import edu.utah.sci.cyclist.core.tools.Tool; -import edu.utexas.cycic.tools.FormBuilderTool; import edu.utexas.cycic.tools.RegionViewTool; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.control.Label; -import javafx.scene.control.ListView; import javafx.scene.control.ContextMenu; -import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; import javafx.scene.input.ClipboardContent; import javafx.scene.input.Dragboard; @@ -20,11 +17,8 @@ import javafx.scene.input.MouseEvent; import javafx.scene.input.TransferMode; import javafx.scene.paint.Color; -import javafx.scene.shape.Circle; import javafx.scene.shape.Rectangle; import javafx.scene.shape.Shape; -import javafx.scene.text.Font; -import javafx.scene.text.Text; /** * This class extends the Java Circle class. Used to represent a region diff --git a/cyclist/src/edu/utexas/cycic/RegionView.java b/cyclist/src/edu/utexas/cycic/RegionView.java index 0b9f4214..dd9c85ed 100644 --- a/cyclist/src/edu/utexas/cycic/RegionView.java +++ b/cyclist/src/edu/utexas/cycic/RegionView.java @@ -1,6 +1,7 @@ package edu.utexas.cycic; import java.util.ArrayList; + import edu.utah.sci.cyclist.core.ui.components.ViewBase; import javafx.event.ActionEvent; import javafx.event.EventHandler; @@ -8,17 +9,14 @@ import javafx.geometry.Orientation; import javafx.geometry.Pos; import javafx.scene.control.Button; -import javafx.scene.control.ButtonType; import javafx.scene.control.ComboBox; import javafx.scene.control.ContextMenu; -import javafx.scene.control.Dialog; import javafx.scene.control.Label; import javafx.scene.control.ListView; import javafx.scene.control.MenuItem; import javafx.scene.control.Slider; import javafx.scene.control.TextField; import javafx.scene.control.Tooltip; -import javafx.scene.control.ButtonBar.ButtonData; import javafx.scene.input.MouseEvent; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; @@ -42,6 +40,7 @@ public RegionView(){ final ListView institList = new ListView(); institList.setOrientation(Orientation.VERTICAL); institList.setMinHeight(25); + institList.setMaxWidth(120); ContextMenu listCtxtMenu = new ContextMenu(); MenuItem removeInst = new MenuItem("Remove Institution"); @@ -112,8 +111,6 @@ public void handle(ActionEvent event){ VBox institBox = new VBox(); institBox.getChildren().addAll(new Label("Institutions"), institList); regionSideBar.setPadding(new Insets(0, 5, 0, 0)); - regionSideBar.setMinWidth(200); - regionSideBar.setPrefWidth(200); regionSideBar.getChildren().addAll(institBox); VBox regionGridBox = new VBox(); @@ -124,7 +121,6 @@ public void handle(ActionEvent event){ setTitle(TITLE); setContent(regionBox); - setPrefSize(600,400); formBuilder(RegionCorralView.workingRegion.regionStruct, RegionCorralView.workingRegion.regionData); } @@ -213,18 +209,26 @@ public void formBuilder(ArrayList facArray, ArrayList dataArray) } else if (facArray.get(2) == "zeroOrMore") { if ((int)facArray.get(6) <= userLevel && i == 0){ Label name = new Label((String) facArray.get(0)); + if(facArray.get(9) != null && !facArray.get(9).toString().equalsIgnoreCase("")){ + name.setText((String) facArray.get(9)); + } else { + name.setText((String) facArray.get(0)); + } + name.setTooltip(new Tooltip((String)facArray.get(7))); + name.setOnMouseClicked(FormBuilder.helpDialogHandler( (String) facArray.get(8))); grid.add(name, columnNumber, rowNumber); - grid.add(orMoreAddButton(grid, (ArrayList) facArray, (ArrayList) dataArray), 1+columnNumber, rowNumber); - rowNumber += 1; + grid.add(orMoreAddButton(grid, (ArrayList) facArray, (ArrayList) dataArray), columnNumber+1, rowNumber); // Indenting a sub structure + rowNumber += 1; columnNumber += 1; for(int ii = 0; ii < dataArray.size(); ii ++){ - grid.add(arrayListRemove(dataArray, ii), columnNumber-1, rowNumber); + grid.add(arrayListRemove(dataArray, ii), columnNumber+2, rowNumber); formBuilder((ArrayList)facArray.get(1), (ArrayList) dataArray.get(ii)); rowNumber += 1; } // resetting the indent columnNumber -= 1; + rowNumber += 1; } } else if (facArray.get(1) instanceof ArrayList) { if ((int)facArray.get(6) <= userLevel){