Skip to content

Commit 55a41e4

Browse files
committed
Minor improvements added.
1 parent fb0de40 commit 55a41e4

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

aima-gui/src/main/java/aima/gui/fx/demo/IntegratedAimaApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package aima.gui.fx.demo;
22

3-
import aima.gui.fx.demo.search.MapColoringApp;
3+
import aima.gui.fx.demo.search.CspMapColoringApp;
44
import aima.gui.fx.demo.search.games.EightPuzzleApp;
55
import aima.gui.fx.demo.search.games.TicTacToeApp;
66
import aima.gui.prog.agent.NondeterministicVacuumEnvironmentProg;
@@ -57,7 +57,7 @@ protected void defineContent(IntegratedAppPaneBuilder builder) {
5757
builder.registerApp(VacuumAgentApp.class);
5858
builder.registerApp(RouteFindingAgentApp.class);
5959

60-
builder.registerApp(MapColoringApp.class);
60+
builder.registerApp(CspMapColoringApp.class);
6161
builder.registerApp(NQueensSearchApp.class);
6262

6363
builder.registerApp(EightPuzzleApp.class);

aima-gui/src/main/java/aima/gui/fx/demo/search/MapColoringApp.java renamed to aima-gui/src/main/java/aima/gui/fx/demo/search/CspMapColoringApp.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import aima.gui.fx.framework.Parameter;
66
import aima.gui.fx.framework.SimulationPaneBuilder;
77
import aima.gui.fx.framework.SimulationPaneCtrl;
8-
import aima.gui.fx.views.BinaryCspViewCtrl;
8+
import aima.gui.fx.views.CspViewCtrl;
99
import javafx.application.Platform;
1010
import javafx.scene.layout.BorderPane;
1111
import javafx.scene.layout.Pane;
@@ -19,7 +19,7 @@
1919
*
2020
* @author Ruediger Lunde
2121
*/
22-
public class MapColoringApp extends IntegrableApplication {
22+
public class CspMapColoringApp extends IntegrableApplication {
2323

2424
public static void main(String[] args) {
2525
launch(args);
@@ -28,19 +28,19 @@ public static void main(String[] args) {
2828
public final static String PARAM_MAP = "map";
2929
public final static String PARAM_STRATEGY = "strategy";
3030

31-
private BinaryCspViewCtrl stateViewCtrl;
31+
private CspViewCtrl stateViewCtrl;
3232
private SimulationPaneCtrl simPaneCtrl;
3333

3434
private CSP csp;
3535
private SolutionStrategy strategy;
3636
private int stepCounter;
3737

38-
public MapColoringApp() {
38+
public CspMapColoringApp() {
3939
}
4040

4141
@Override
4242
public String getTitle() {
43-
return "Map Coloring App";
43+
return "CSP Map Coloring App";
4444
}
4545

4646
/**
@@ -52,7 +52,7 @@ public Pane createRootPane() {
5252
BorderPane root = new BorderPane();
5353

5454
StackPane stateView = new StackPane();
55-
stateViewCtrl = new BinaryCspViewCtrl(stateView);
55+
stateViewCtrl = new CspViewCtrl(stateView);
5656

5757
Parameter[] params = createParameters();
5858

@@ -203,7 +203,9 @@ private void updateStateView(CSP csp, Assignment assignment) {
203203
private void updateStateViewLater(CSP csp, Assignment assignment) {
204204
stateViewCtrl.update(csp, assignment);
205205
String txt1 = "Step " + stepCounter + ": ";
206-
String txt2 = assignment != null ? assignment.toString() : "Domain reduced";
206+
String txt2 = "Domain reduced";
207+
if (assignment != null)
208+
txt2 = assignment.toString() + (assignment.isSolution(csp) ? " (Solution)" : "");
207209
simPaneCtrl.setStatus(txt1 + txt2);
208210
}
209211
}

aima-gui/src/main/java/aima/gui/fx/views/BinaryCspViewCtrl.java renamed to aima-gui/src/main/java/aima/gui/fx/views/CspViewCtrl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @author Ruediger Lunde
2323
*/
24-
public class BinaryCspViewCtrl {
24+
public class CspViewCtrl {
2525
protected Pane pane;
2626
protected CSP csp;
2727
protected Assignment assignment;
@@ -35,7 +35,7 @@ public class BinaryCspViewCtrl {
3535
*/
3636
protected Hashtable<Object, Color> colorMapping = new Hashtable<Object, Color>();
3737

38-
public BinaryCspViewCtrl(StackPane viewRoot) {
38+
public CspViewCtrl(StackPane viewRoot) {
3939
pane = new Pane();
4040
viewRoot.getChildren().add(pane);
4141
viewRoot.setStyle("-fx-background-color: white");
@@ -106,12 +106,12 @@ protected void visualize(Variable var) {
106106
label += " = " + value;
107107
fillColor = colorMapping.get(value);
108108
}
109-
Circle circle = new Circle(pos.getX(), pos.getY(), 30);
109+
Circle circle = new Circle(pos.getX(), pos.getY(), 20);
110110
circle.setStroke(Color.BLACK);
111111
circle.setFill(fillColor != null ? fillColor : Color.WHITE);
112-
Text t1 = new Text(pos.getX(), pos.getY(), label);
112+
Text t1 = new Text(pos.getX() + 25, pos.getY(), label);
113113
t1.setTextOrigin(VPos.CENTER);
114-
Text t2 = new Text(pos.getX(), pos.getY() + 50, csp.getDomain(var).toString());
114+
Text t2 = new Text(pos.getX(), pos.getY() + 40, csp.getDomain(var).toString());
115115
pane.getChildren().addAll(circle, t1, t2);
116116
}
117117

0 commit comments

Comments
 (0)