1919import org .uffr .rbmksim .simulation .ColumnType ;
2020import org .uffr .rbmksim .simulation .GridLocation ;
2121import org .uffr .rbmksim .simulation .RBMKColumnBase ;
22- import org .uffr .rbmksim .simulation .bcolumns .RBMKBlueprintColumn ;
2322import org .uffr .rbmksim .util .I18n ;
2423import org .uffr .rbmksim .util .InfoProviderNT ;
2524import org .uffr .rbmksim .util .RBMKRenderHelper ;
3231import javafx .fxml .Initializable ;
3332import javafx .scene .canvas .Canvas ;
3433import javafx .scene .control .Alert .AlertType ;
34+ import javafx .scene .control .Button ;
3535import javafx .scene .control .ChoiceBox ;
3636import javafx .scene .control .DatePicker ;
3737import javafx .scene .control .Label ;
@@ -74,6 +74,10 @@ public class MainController implements Initializable
7474 @ FXML
7575 private ChoiceBox <GraphType > graphSelectionBox ;
7676 @ FXML
77+ private ChoiceBox <ColumnType > columnTypeBox ;
78+ @ FXML
79+ private Button setColumnButton , resetColumnButton ;
80+ @ FXML
7781 private Pane canvasPane ;
7882 @ FXML
7983 private AnchorPane canvasAnchor ;
@@ -82,28 +86,7 @@ public class MainController implements Initializable
8286 @ FXML
8387 private Label nameLabel , creatorLabel , versionLabel , dateLabel , zoomLabel ;
8488 @ FXML
85- private Tooltip nameTooltip , creatorNameTooltip , versionTooltip , dateTooltip ;
86-
87- private enum GraphType
88- {
89- HEAT ("heat" ),
90- FLUX ("flux" ),
91- STEAM ("steam" ),
92- POWER ("power" ),
93- COOLANT ("coolant" );
94-
95- public final String key ;
96- private GraphType (String key )
97- {
98- this .key = key ;
99- }
100-
101- @ Override
102- public String toString ()
103- {
104- return I18n .resolve ("app.graphType." + key );
105- }
106- }
89+ private Tooltip nameTooltip , creatorNameTooltip , versionTooltip , dateTooltip , setColumnButtonTooltip ;
10790
10891 @ Override
10992 public void initialize (URL url , ResourceBundle bundle )
@@ -166,7 +149,8 @@ public void initialize(URL url, ResourceBundle bundle)
166149 method .invoke (item , I18n .resolve (unlocalized ));
167150 } catch (IllegalArgumentException | InvocationTargetException | SecurityException e )
168151 {
169- LOGGER .warn ("Either assumed property controlled by setter method [" + method .getName () + "] has entry in lang file but does not have associated assumed getter method or method is not a string" , e );
152+ LOGGER .warn ("Either assumed property controlled by setter method [{}] has entry in lang file but does not have associated assumed getter method or method is not a string" , method .getName ());
153+ LOGGER .warn ("Got exception:" , e );
170154 }
171155 }
172156 }
@@ -176,20 +160,20 @@ public void initialize(URL url, ResourceBundle bundle)
176160 LOGGER .error ("Unable to retrieve field!" , e );
177161 }
178162 }
179- LOGGER .trace ("I18n complete" );
163+ LOGGER .trace ("I18n complete. Setting up miscellaneous fields... " );
180164
181- LOGGER .trace ("Setting up miscellaneous fields..." );
182-
183165 mainCanvas .heightProperty ().bind (canvasPane .heightProperty ());
184166 mainCanvas .widthProperty ().bind (canvasPane .widthProperty ());
185167
186- for (GraphType type : GraphType .values ())
187- graphSelectionBox .getItems ().add (type );
168+ graphSelectionBox .getItems ().addAll (GraphType .values ());
188169 graphSelectionBox .selectionModelProperty ().get ().selectFirst ();
170+ columnTypeBox .getItems ().addAll (ColumnType .values ());
171+ columnTypeBox .selectionModelProperty ().get ().selectFirst ();
189172
173+ // The "-fx-text-fill" thing doesn't do anything, doesn't seem to work
190174 infoTextArea .setStyle ("-fx-font-family: monospace; -fx-background-color: DIMGRAY; -fx-text-fill: WHITE;" );
191175
192- versionTextField .setTextFormatter (new TextFormatter <>(new StringConverter <Version >()
176+ versionTextField .setTextFormatter (new TextFormatter <Version >(new StringConverter <Version >()
193177 {
194178 @ Override
195179 public Version fromString (String arg0 )
@@ -238,7 +222,7 @@ private void onFrameChanged()
238222 {
239223 nameTextField .setText (currentFrame .getName ());
240224 creatorTextField .setText (currentFrame .getCreatorName ());
241- versionTextField .setText (currentFrame .getVersion ());
225+ versionTextField .setText (currentFrame .getVersion (). toString () );
242226 dateInput .setValue (currentFrame .getDate ());
243227 canvasAnchor .setPrefWidth (currentFrame .columns * RBMKRenderHelper .CELL_SIZE );
244228 canvasAnchor .setPrefHeight (currentFrame .rows * RBMKRenderHelper .CELL_SIZE );
@@ -255,12 +239,12 @@ private void onClickNewBlueprint()
255239 Main .setFrame (new RBMKBlueprint (mainCanvas ));
256240
257241 // TODO Remove
258- final ColumnType testType = ColumnType .BLANK ;
242+ /* final ColumnType testType = ColumnType.BLANK;
259243 final RBMKFrame frame = Main.getFrame().get();
260- frame .addColumn (new RBMKBlueprintColumn (new GridLocation (0 , 0 ), frame , testType , false ));
261- frame .addColumn (new RBMKBlueprintColumn (new GridLocation (0 , 10 ), frame , testType , false ));
262- frame .addColumn (new RBMKBlueprintColumn (new GridLocation (10 , 0 ), frame , testType , false ));
263- frame .addColumn (new RBMKBlueprintColumn (new GridLocation (10 , 10 ), frame , testType , false ));
244+ frame.addColumn(new RBMKBlueprintColumn(new GridLocation(0, 0), testType, false));
245+ frame.addColumn(new RBMKBlueprintColumn(new GridLocation(0, 10), testType, false));
246+ frame.addColumn(new RBMKBlueprintColumn(new GridLocation(10, 0), testType, false));
247+ frame.addColumn(new RBMKBlueprintColumn(new GridLocation(10, 10), testType, false));*/
264248
265249 onFrameChanged ();
266250 }
@@ -407,10 +391,7 @@ private void onCanvasClicked(MouseEvent event)
407391 final GridLocation loc = new GridLocation (x , y );
408392 final RBMKColumnBase column = currentFrame .getColumnAtCoords (loc );
409393 currentFrame .setSelectedLocation (Optional .of (loc ));
410- if (column != null && currentFrame .getSelectedLocation ().isPresent ())
411- setInfoArea (column );
412- else
413- infoTextArea .getChildren ().clear ();
394+ setInfoArea (column != null && currentFrame .getSelectedLocation ().isPresent () ? column : null );
414395 currentFrame .render ();
415396 }
416397 }
@@ -453,7 +434,7 @@ private void onVersionTextChanged(KeyEvent event)
453434 {
454435 LOGGER .trace ("onVersionTextChanged() triggered" );
455436 if (currentFrame != null && event .getCode () == KeyCode .ENTER )
456- currentFrame .setVersion (versionTextField .getText ());
437+ currentFrame .setVersion (( Version ) versionTextField .getTextFormatter (). getValue ());
457438 }
458439
459440 @ FXML
@@ -484,15 +465,38 @@ private void onZoomLevelTextChanged(KeyEvent event)
484465 }
485466 }
486467
468+ @ FXML
469+ private void onClickSetColumn ()
470+ {
471+ LOGGER .debug ("onClickSetColumn() triggered" );
472+ if (currentFrame != null && currentFrame .selectedLocation .isPresent ())
473+ {
474+ currentFrame .setColumn (currentFrame .selectedLocation .get (), columnTypeBox .getValue ());
475+ setInfoArea (currentFrame .getColumnAtCoords (currentFrame .selectedLocation .get ()));
476+ currentFrame .render ();
477+ }
478+ }
479+
480+ @ FXML
481+ private void onClickResetColumn ()
482+ {
483+ LOGGER .debug ("onClickResetColumn() triggered" );
484+ if (currentFrame != null && currentFrame .selectedLocation .isPresent ())
485+ {
486+ currentFrame .setColumn (currentFrame .selectedLocation .get (), null );
487+ setInfoArea (null );
488+ // Better performance?
489+ RBMKRenderHelper .eraseColumn (currentFrame .selectedLocation .get (), mainCanvas .getGraphicsContext2D (), currentFrame .getRenderer ().zoom );
490+ RBMKRenderHelper .drawSelectionRect (currentFrame .selectedLocation .get (), mainCanvas .getGraphicsContext2D (), currentFrame .getRenderer ().zoom );
491+ }
492+ }
493+
487494 public void setInfoArea (@ Nullable InfoProviderNT infoProvider )
488495 {
489496 LOGGER .debug ("Set infoTextArea with data provided by InfoProvider instance" );
490497 infoTextArea .getChildren ().clear ();
491498 if (infoProvider != null )
492499 infoTextArea .getChildren ().addAll (infoProvider .getText ());
493-
494- // infoTextArea.getChildren().add(new Text(infoProvider.asProperString()));
495- // infoTextArea.setText(infoProvider.asProperString());
496500 }
497501
498502 private static double clampZoom (double amount )
0 commit comments