use of javafx.scene.paint.Color in project FXyzLib by Birdasaur.
the class ScatterPlotMesh method setXYZData.
public void setXYZData(ArrayList<Double> xData, ArrayList<Double> yData, ArrayList<Double> zData) {
xAxisData = xData;
yAxisData = yData;
zAxisData = zData;
getChildren().clear();
//for now we will always default to x axis
//later we could maybe dynamically determine the smallest axis and then
//uses 0's for the other axes that are larger.
ArrayList<Point3D> point3DList = new ArrayList<>();
for (int i = 0; i < xAxisData.size(); i++) {
//some safety checks for array sizes
double translateY = 0.0;
double translateZ = 0.0;
if (!yAxisData.isEmpty() && yAxisData.size() > i)
translateY = yAxisData.get(i);
if (!zAxisData.isEmpty() && zAxisData.size() > i)
translateZ = zAxisData.get(i);
setTranslateX(xAxisData.get(i));
//Convert to Floats and build list of adjusted points
point3DList.add(new Point3D(new Float(xAxisData.get(i)), new Float(translateY), new Float(translateZ)));
float width = 1;
final TriangleMesh mesh = new TriangleMesh();
//This extra point allows us to build triangles later
for (Point3D point : point3DList) {
//Rear points
//top right rear point
mesh.getPoints().addAll(point.x + width, point.y + width, point.z + width);
//top left rear point
mesh.getPoints().addAll(point.x - width, point.y + width, point.z + width);
//bottom right rear point
mesh.getPoints().addAll(point.x + width, point.y - width, point.z + width);
//bottom left rear point
mesh.getPoints().addAll(point.x - width, point.y - width, point.z + width);
//Front points
//top right front point
mesh.getPoints().addAll(point.x + width, point.y + width, point.z - width);
//top left front point
mesh.getPoints().addAll(point.x - width, point.y + width, point.z - width);
//bottom right front point
mesh.getPoints().addAll(point.x + width, point.y - width, point.z - width);
//bottom left front point
mesh.getPoints().addAll(point.x - width, point.y - width, point.z - width);
}
//add dummy Texture Coordinate
mesh.getTexCoords().addAll(0, 0);
//Now generate nodes for each point
for (int p = 8; p < point3DList.size() * 7; p += 8) {
//add each segment
//Wind the next 8 vertices as a cube. The cube itself will represent the data
//Vertices wound counter-clockwise which is the default front face of any Triangle
//Rear triangle faces should be wound clockwise to face away from center
//TRR,BLR,BRR
mesh.getFaces().addAll(p, 0, p + 3, 0, p + 2, 0);
//BLR,TRR,TLR
mesh.getFaces().addAll(p + 3, 0, p, 0, p + 1, 0);
//left side faces
//TLR,TLF,BLR
mesh.getFaces().addAll(p + 1, 0, p + 5, 0, p + 3, 0);
//TLF,BLR,BLF
mesh.getFaces().addAll(p + 5, 0, p + 7, 0, p + 3, 0);
//front side faces
//TLF,BLF,TLR
mesh.getFaces().addAll(p + 5, 0, p + 7, 0, p + 4, 0);
//TRF,BLF,BRF
mesh.getFaces().addAll(p + 4, 0, p + 7, 0, p + 6, 0);
//front side faces
//TRF,BRF,BRR
mesh.getFaces().addAll(p + 4, 0, p + 6, 0, p + 2, 0);
//TRF,BRR,TRR
mesh.getFaces().addAll(p + 4, 0, p + 2, 0, p, 0);
//Top faces
//TRR,TLR,TRF
mesh.getFaces().addAll(p, 0, p + 1, 0, p + 3, 0);
//TLR,TLF,TRF
mesh.getFaces().addAll(p + 1, 0, p + 5, 0, p + 3, 0);
//bottom faces
//BLR,BLF,BRF
mesh.getFaces().addAll(p + 3, 0, p + 7, 0, p + 6, 0);
//BLR,BRF,BRR
mesh.getFaces().addAll(p + 3, 0, p + 6, 0, p + 2, 0);
}
//Need to add the mesh to a MeshView before adding to our 3D scene
MeshView meshView = new MeshView(mesh);
//Fill so that the line shows width
meshView.setDrawMode(DrawMode.FILL);
Color hsb = Color.hsb((new Double(i) / 12) * 360, 1.0, 1.0, 0.5);
PhongMaterial material = new PhongMaterial(hsb);
material.setDiffuseColor(hsb);
material.setSpecularColor(hsb);
meshView.setMaterial(material);
//Make sure you Cull the Back so that no black shows through
meshView.setCullFace(CullFace.BACK);
// //Add some ambient light so folks can see it
// Group line = new Group();
// AmbientLight light = new AmbientLight(Color.WHITE);
// light.getScope().add(meshView);
// line.getChildren().add(light);
// line.getChildren().add(meshView);
getChildren().addAll(meshView);
}
}
use of javafx.scene.paint.Color in project FXyzLib by Birdasaur.
the class CapsuleTest method start.
@Override
public void start(Stage stage) {
Group capsuleGroup = new Group();
for (int i = 0; i < 50; i++) {
Random r = new Random();
//A lot of magic numbers in here that just artificially constrain the math
float randomRadius = (float) ((r.nextFloat() * 100) + 25);
float randomHeight = (float) ((r.nextFloat() * 300) + 75);
Color randomColor = new Color(r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble());
Capsule cap = new Capsule(randomRadius, randomHeight, randomColor);
cap.setEmissiveLightingColor(randomColor);
cap.setEmissiveLightingOn(r.nextBoolean());
cap.setDrawMode(r.nextBoolean() ? DrawMode.FILL : DrawMode.LINE);
double translationX = Math.random() * 1024 * 1.95;
if (Math.random() >= 0.5) {
translationX *= -1;
}
double translationY = Math.random() * 1024 * 1.95;
if (Math.random() >= 0.5) {
translationY *= -1;
}
double translationZ = Math.random() * 1024 * 1.95;
if (Math.random() >= 0.5) {
translationZ *= -1;
}
Translate translate = new Translate(translationX, translationY, translationZ);
Rotate rotateX = new Rotate(Math.random() * 360, Rotate.X_AXIS);
Rotate rotateY = new Rotate(Math.random() * 360, Rotate.Y_AXIS);
Rotate rotateZ = new Rotate(Math.random() * 360, Rotate.Z_AXIS);
cap.getTransforms().addAll(translate, rotateX, rotateY, rotateZ);
capsuleGroup.getChildren().add(cap);
}
root.getChildren().add(capsuleGroup);
camera = new AdvancedCamera();
controller = new FPSController();
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.setFieldOfView(42);
camera.setController(controller);
Scene scene = new Scene(new StackPane(root), 1024, 668, true, SceneAntialiasing.BALANCED);
scene.setCamera(camera);
scene.setFill(Color.BLACK);
controller.setScene(scene);
stage.setTitle("Hello World!");
stage.setScene(scene);
stage.show();
stage.setFullScreen(true);
stage.setFullScreenExitHint("");
}
use of javafx.scene.paint.Color in project Minesweeper3D by SethDamiani.
the class Main method start.
@Override
public void start(Stage primaryStage) throws Exception {
// Main JavaFX method
// Add all sides into the cube group
cube.getChildren().addAll(sideA, sideB, sideC, sideD, sideE, sideF);
// Set proper layout
cube.setLayoutX(150);
cube.setLayoutY(190);
// Create the main cube object
createCube(cube, gX, gY, game, primaryStage);
// Properly nest cube rotation control groups
gameRoot.getChildren().add(gY);
// ||
gY.getChildren().add(gX);
// ||
gX.getChildren().add(cube);
stopwatch.setFont(new Font(45));
bombs.setFont(new Font(45));
gameRoot.getChildren().addAll(stopwatch, bombs);
timeTask = new Timeline(new // Task to keep track of time
KeyFrame(// Task to keep track of time
Duration.seconds(1), // Task to keep track of time
event -> {
time++;
stopwatch.setText("Time: " + String.valueOf(time));
}));
// Make timeTask run forever and ever
timeTask.setCycleCount(Timeline.INDEFINITE);
for (int x = 0; x < Grid.length; x++) {
// Add the cells to their proper side groups
for (int y = 0; y < Grid[x].length; y++) {
for (int z = 0; z < Grid[x][y].length; z++) {
Grid[x][y][z] = new Cell(cube, 40, 40 * y, 40 * z, x);
switch(x) {
case 0:
sideA.getChildren().add(Grid[x][y][z].cell);
break;
case 1:
sideB.getChildren().add(Grid[x][y][z].cell);
break;
case 2:
sideC.getChildren().add(Grid[x][y][z].cell);
break;
case 3:
sideD.getChildren().add(Grid[x][y][z].cell);
break;
case 4:
sideE.getChildren().add(Grid[x][y][z].cell);
break;
case 5:
sideF.getChildren().add(Grid[x][y][z].cell);
break;
}
}
}
}
// Place bombs randomly
placeBombs(100);
// Place the correct numbers according to the new bomb positions
placeNumbers();
// -------------------------------------------------------------------------------
// Confirm Exit screen setup
// new Color(1,1,1,.5)
Text confirmExitText = new Text("Quit");
confirmExitText.setFill(Color.WHITE);
confirmExitText.setFont(Font.font(80));
confirmExitText.setX(400 - confirmExitText.getLayoutBounds().getWidth() / 2);
confirmExitText.setY(200);
Text confirmExitSubText = new Text("Are you sure you would like to quit to the main menu?\nAll progress will be lost.");
confirmExitSubText.setFill(Color.WHITE);
confirmExitSubText.setFont(Font.font(20));
confirmExitSubText.setTextAlignment(TextAlignment.CENTER);
confirmExitSubText.setX(400 - confirmExitSubText.getLayoutBounds().getWidth() / 2);
confirmExitSubText.setY(300);
Text confirmExitYesText = new Text("Yes");
confirmExitYesText.setFont(Font.font(30));
confirmExitYesText.setFill(Color.WHITE);
confirmExitYesText.setX(300 - confirmExitYesText.getLayoutBounds().getWidth() / 2);
confirmExitYesText.setY(500);
Rectangle confirmExitYesButton = new Rectangle(confirmExitYesText.getBoundsInLocal().getMinX() - 20, confirmExitYesText.getBoundsInLocal().getMinY() - 20, confirmExitYesText.getLayoutBounds().getWidth() + 40, confirmExitYesText.getLayoutBounds().getHeight() + 40);
confirmExitYesButton.setFill(Color.TRANSPARENT);
confirmExitYesButton.setStroke(Color.WHITE);
confirmExitYesButton.setStrokeWidth(10);
confirmExitYesButton.setOnMouseEntered(event -> confirmExitYesButton.setFill(new Color(1, 1, 1, .5)));
confirmExitYesButton.setOnMouseExited(event -> confirmExitYesButton.setFill(Color.TRANSPARENT));
confirmExitYesText.setOnMouseEntered(event -> confirmExitYesButton.setFill(new Color(1, 1, 1, .5)));
confirmExitYesText.setOnMouseExited(event -> confirmExitYesButton.setFill(Color.TRANSPARENT));
confirmExitYesButton.setOnMouseClicked(event -> primaryStage.setScene(menu));
confirmExitYesText.setOnMouseClicked(event -> primaryStage.setScene(menu));
Text confirmExitNoText = new Text("No");
confirmExitNoText.setFont(Font.font(30));
confirmExitNoText.setFill(Color.WHITE);
confirmExitNoText.setX(500 - confirmExitYesText.getLayoutBounds().getWidth() / 2);
confirmExitNoText.setY(500);
Rectangle confirmExitNoButton = new Rectangle(confirmExitNoText.getBoundsInLocal().getMinX() - 20, confirmExitNoText.getBoundsInLocal().getMinY() - 20, confirmExitNoText.getLayoutBounds().getWidth() + 40, confirmExitNoText.getLayoutBounds().getHeight() + 40);
confirmExitNoButton.setFill(Color.TRANSPARENT);
confirmExitNoButton.setStroke(Color.WHITE);
confirmExitNoButton.setStrokeWidth(10);
confirmExitNoButton.setOnMouseEntered(event -> confirmExitNoButton.setFill(new Color(1, 1, 1, .5)));
confirmExitNoButton.setOnMouseExited(event -> confirmExitNoButton.setFill(Color.TRANSPARENT));
confirmExitNoText.setOnMouseEntered(event -> confirmExitNoButton.setFill(new Color(1, 1, 1, .5)));
confirmExitNoText.setOnMouseExited(event -> confirmExitNoButton.setFill(Color.TRANSPARENT));
confirmExitNoButton.setOnMouseClicked(event -> {
timeTask.play();
primaryStage.setScene(game);
});
confirmExitNoText.setOnMouseClicked(event -> {
timeTask.play();
primaryStage.setScene(game);
});
confirmExitRoot.getChildren().addAll(confirmExitText, confirmExitSubText, confirmExitYesText, confirmExitNoText, confirmExitYesButton, confirmExitNoButton);
// Quit screen UI setup
// Initialize and configure background
Rectangle quitBox = new Rectangle(800, 700, Color.INDIANRED);
// Initialize and configure the title
Text quitText = new Text(260, 200, "Game Over");
quitText.setFont(new Font(80));
quitText.setStroke(Color.WHITE);
quitText.setFill(Color.WHITE);
quitText.setTextAlignment(TextAlignment.CENTER);
quitText.setX(400 - quitText.getLayoutBounds().getWidth() / 2);
// Initialize and configure the time text
Text endScoreText = new Text(260, 320, "Time: ");
endScoreText.setFont(new Font(40));
endScoreText.setTextAlignment(TextAlignment.CENTER);
endScoreText.setFill(Color.WHITE);
endScoreText.setStroke(Color.WHITE);
// Center the text within the button
endScoreText.setX(350 - endScoreText.getLayoutBounds().getWidth() / 2);
// Initialize and configure first name input field
TextField firstNameInput = new TextField();
firstNameInput.setFont(new Font(24));
// Initialize and configure first name input label
Text firstNameLabel = new Text("First name: ");
firstNameLabel.setFont(new Font(28));
firstNameLabel.setFill(Color.WHITE);
// Initialize and configure horizontal box for first name input
HBox firstNameBox = new HBox(5, firstNameLabel, firstNameInput);
firstNameBox.setLayoutX(180);
firstNameBox.setLayoutY(395);
// Initialize and configure last name input field
TextField lastNameInput = new TextField();
lastNameInput.setFont(new Font(24));
// Initialize and configure last name input label
Text lastNameLabel = new Text("Last name: ");
lastNameLabel.setFont(new Font(28));
lastNameLabel.setFill(Color.WHITE);
// Initialize and configure horizontal box for last name input
HBox lastNameBox = new HBox(5, lastNameLabel, lastNameInput);
lastNameBox.setLayoutX(182);
lastNameBox.setLayoutY(450);
// Initialize and configure continue button border
Rectangle continueRect = new Rectangle(300, 550, 500, 70);
continueRect.setStroke(Color.WHITE);
continueRect.setFill(Color.TRANSPARENT);
continueRect.setStrokeWidth(5);
// Initialize and configure continue button text
Text continueText = new Text("Submit and Continue");
continueText.setFont(new Font(50));
continueText.setFill(Color.WHITE);
continueText.setY(600);
continueText.setX(400 - continueText.getLayoutBounds().getWidth() / 2);
continueRect.setWidth(continueText.getLayoutBounds().getWidth() + 40);
continueRect.setX(400 - continueRect.getLayoutBounds().getWidth() / 2);
// Advance to next field on enter press
firstNameInput.setOnAction(event -> lastNameInput.requestFocus());
// Manual game-win override
game.addEventHandler(// Manual game-win override
KeyEvent.KEY_PRESSED, // Manual game-win override
event -> {
if (event.getCode() == KeyCode.BACK_SLASH && event.isAltDown()) {
gameWon = true;
endScoreText.setText("Time: " + time);
endScoreText.setX(400 - endScoreText.getLayoutBounds().getWidth() / 2);
game.getOnMouseClicked().handle(mouseEvent);
}
});
// Submit score when enter is pressed in last name entry
lastNameInput.setOnAction(// Submit score when enter is pressed in last name entry
event -> {
if (gameWon) {
String firstName = firstNameInput.getText();
String lastName = lastNameInput.getText();
Long date = System.currentTimeMillis() / 1000;
highScoresMap.put(date, new HighScore(date, difficulty, firstName, lastName, time));
refreshTableData();
try {
writeHighScores();
} catch (IOException e) {
System.out.println("ERROR: couldn't save high scores to file.");
}
}
primaryStage.setScene(menu);
});
quitRoot.getChildren().addAll(quitBox, quitText, endScoreText, firstNameBox, lastNameBox, continueRect, continueText);
// Process new high score data into table and .csv
EventHandler<MouseEvent> submitScores = // Process new high score data into table and .csv
event -> {
if (gameWon) {
String firstName = firstNameInput.getText();
String lastName = lastNameInput.getText();
Long date = System.currentTimeMillis() / 1000;
highScoresMap.put(date, new HighScore(date, difficulty, firstName, lastName, time));
refreshTableData();
try {
writeHighScores();
} catch (IOException e) {
System.out.println("ERROR: couldn't save high scores to file.");
}
}
primaryStage.setScene(menu);
};
continueRect.addEventHandler(MouseEvent.MOUSE_CLICKED, submitScores);
continueText.addEventHandler(MouseEvent.MOUSE_CLICKED, submitScores);
// Pause screen UI setup
Rectangle pauseBox = new Rectangle(800, 700, Color.BLACK);
Text pauseText = new Text(260, 350, "Paused");
pauseText.setFont(new Font(80));
pauseText.setStroke(Color.WHITE);
pauseText.setFill(Color.WHITE);
pauseText.setTextAlignment(TextAlignment.CENTER);
Text timeText = new Text(260, 430, "Time: ");
timeText.setFont(new Font(40));
timeText.setTextAlignment(TextAlignment.CENTER);
timeText.setFill(Color.WHITE);
timeText.setStroke(Color.WHITE);
timeText.setX(250 - timeText.getLayoutBounds().getWidth() / 2);
Text bombsText = new Text(550, 430, bombs.getText());
bombsText.setFont(new Font(40));
bombsText.setTextAlignment(TextAlignment.CENTER);
bombsText.setFill(Color.WHITE);
bombsText.setStroke(Color.WHITE);
bombsText.setX(500 - bombsText.getLayoutBounds().getWidth() / 2);
Text infoText = new Text("Loading");
infoText.setFont(new Font(40));
infoText.setTextAlignment(TextAlignment.CENTER);
infoText.setFill(Color.WHITE);
infoText.setStroke(Color.WHITE);
infoText.setX(400 - infoText.getLayoutBounds().getWidth() / 2);
infoText.setY(430);
Rectangle resume = new Rectangle(300, 500, 200, 70);
resume.setFill(Color.TRANSPARENT);
resume.setStroke(Color.WHITE);
resume.setStrokeWidth(5);
Text resumeText = new Text("Resume");
resumeText.setFont(new Font(50));
resumeText.setFill(Color.WHITE);
resumeText.setY(550);
resumeText.setX(400 - resumeText.getLayoutBounds().getWidth() / 2);
pauseRoot.getChildren().addAll(pauseBox, pauseText, resume, resumeText, infoText);
EventHandler<MouseEvent> resumeButton = event -> {
timeTask.play();
primaryStage.setScene(game);
};
resume.addEventHandler(MouseEvent.MOUSE_CLICKED, resumeButton);
resumeText.addEventHandler(MouseEvent.MOUSE_CLICKED, resumeButton);
pause.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.SPACE) {
primaryStage.setScene(game);
timeTask.play();
} else if (event.getCode() == KeyCode.ESCAPE) {
primaryStage.setScene(confirmExit);
}
});
game.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.SPACE) {
timeTask.pause();
infoText.setText("Time: " + time + "s Bombs: " + flaggedCells + "/" + totalBombs);
infoText.setX(400 - infoText.getLayoutBounds().getWidth() / 2);
primaryStage.setScene(pause);
}
});
// High scores UI setup
scores.setFill(new ImagePattern(bg));
Text scoresTitle = new Text(120, 120, "High Scores");
scoresRoot.getChildren().add(scoresTitle);
scoresTitle.setFont(new Font(70));
scoresTitle.setStroke(Color.BLACK);
scoresTitle.setStrokeWidth(5);
scoresTitle.setTextAlignment(TextAlignment.CENTER);
scoresTitle.setX(400 - scoresTitle.getLayoutBounds().getWidth() / 2);
Rectangle back = new Rectangle(100, 550, 200, 70);
back.setFill(Color.TRANSPARENT);
back.setStroke(Color.BLACK);
back.setStrokeWidth(5);
back.setFill(new Color(1, 1, 1, .5));
back.setOnMouseEntered(event -> back.setFill(new Color(1, 1, 1, .8)));
back.setOnMouseExited(event -> back.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(back);
Text backText = new Text("Back");
backText.setFont(new Font(50));
backText.setFill(Color.BLACK);
backText.setY(600);
backText.setX(200 - backText.getLayoutBounds().getWidth() / 2);
backText.setStroke(Color.BLACK);
backText.setStrokeWidth(3);
backText.setOnMouseEntered(event -> back.setFill(new Color(1, 1, 1, .8)));
backText.setOnMouseExited(event -> back.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(backText);
EventHandler<MouseEvent> backButton = event -> primaryStage.setScene(menu);
back.addEventHandler(MouseEvent.MOUSE_CLICKED, backButton);
backText.addEventHandler(MouseEvent.MOUSE_CLICKED, backButton);
Rectangle deleteScore = new Rectangle(500, 550, 200, 70);
deleteScore.setFill(Color.TRANSPARENT);
deleteScore.setStroke(Color.BLACK);
deleteScore.setStrokeWidth(5);
deleteScore.setFill(new Color(1, 1, 1, .5));
deleteScore.setOnMouseEntered(event -> deleteScore.setFill(new Color(1, 1, 1, .8)));
deleteScore.setOnMouseExited(event -> deleteScore.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(deleteScore);
Text deleteScoresText = new Text("Delete");
deleteScoresText.setFont(new Font(50));
deleteScoresText.setFill(Color.BLACK);
deleteScoresText.setY(600);
deleteScoresText.setX(600 - deleteScoresText.getLayoutBounds().getWidth() / 2);
deleteScoresText.setStroke(Color.BLACK);
deleteScoresText.setStrokeWidth(3);
deleteScoresText.setOnMouseEntered(event -> deleteScore.setFill(new Color(1, 1, 1, .8)));
deleteScoresText.setOnMouseExited(event -> deleteScore.setFill(new Color(1, 1, 1, .5)));
scoresRoot.getChildren().add(deleteScoresText);
// Delete selected high score from table and .csv
EventHandler<MouseEvent> deleteScoreButton = // Delete selected high score from table and .csv
event -> {
if (table.getSelectionModel().getSelectedIndex() == -1)
return;
HighScore current = (HighScore) table.getSelectionModel().getSelectedItem();
highScoresMap.remove(Long.parseLong(current.getRawID()));
refreshTableData();
try {
writeHighScores();
} catch (IOException e) {
System.out.println("ERROR: couldn't save high scores to file.");
}
};
deleteScore.addEventHandler(MouseEvent.MOUSE_CLICKED, deleteScoreButton);
deleteScoresText.addEventHandler(MouseEvent.MOUSE_CLICKED, deleteScoreButton);
CheckBox editable = new CheckBox("Edit mode");
editable.setSelected(true);
editable.setLayoutX(630);
editable.setLayoutY(30);
editable.setFont(Font.font("Tahoma", FontWeight.BLACK, 18));
scoresRoot.getChildren().add(editable);
// High scores table setup
table = new TableView();
table.setLayoutX(100);
table.setLayoutY(200);
table.setPrefWidth(600);
table.setPrefHeight(300);
table.setEditable(true);
EventHandler<TableColumn.CellEditEvent> fieldEditCommit = event -> {
if (table.getSelectionModel().getSelectedIndex() == -1)
return;
HighScore current = (HighScore) table.getSelectionModel().getSelectedItem();
switch(event.getTableColumn().getId()) {
case "Difficulty":
highScoresMap.get(Long.parseLong(current.getRawID())).setDifficulty((String) event.getNewValue());
break;
case "First Name":
highScoresMap.get(Long.parseLong(current.getRawID())).setFirstName((String) event.getNewValue());
break;
case "Last Name":
highScoresMap.get(Long.parseLong(current.getRawID())).setLastName((String) event.getNewValue());
break;
}
try {
writeHighScores();
} catch (IOException e) {
System.out.println("Error saving scores");
}
refreshTableData();
};
table.setStyle(".list-view .scroll-bar:horizontal .increment-arrow,.list-view .scroll-bar:horizontal .decrement-arrow,.list-view .scroll-bar:horizontal .increment-button,.list-view .scroll-bar:horizontal .decrement-button {-fx-padding:0;}");
IDCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("ID"));
IDCol.prefWidthProperty().bind(table.widthProperty().multiply(0.3));
IDCol.setId("ID");
IDCol.setSortable(false);
IDCol.setResizable(false);
difficultyCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("difficulty"));
difficultyCol.setCellFactory(TextFieldTableCell.forTableColumn());
difficultyCol.setOnEditCommit(fieldEditCommit);
difficultyCol.prefWidthProperty().bind(table.widthProperty().multiply(0.175));
difficultyCol.setId("Difficulty");
difficultyCol.setSortable(false);
difficultyCol.setResizable(false);
firstNameCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("firstName"));
firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
firstNameCol.setOnEditCommit(fieldEditCommit);
firstNameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.175));
firstNameCol.setId("First Name");
firstNameCol.setSortable(false);
firstNameCol.setResizable(false);
lastNameCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("lastName"));
lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
lastNameCol.setOnEditCommit(fieldEditCommit);
lastNameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.175));
lastNameCol.setId("Last Name");
lastNameCol.setSortable(false);
lastNameCol.setResizable(false);
timeCol.setCellValueFactory(new PropertyValueFactory<HighScore, String>("time"));
timeCol.prefWidthProperty().bind(table.widthProperty().multiply(0.172));
timeCol.setId("Time");
timeCol.setSortable(true);
timeCol.setResizable(false);
table.getSortOrder().setAll(timeCol);
timeCol.setSortType(TableColumn.SortType.ASCENDING);
table.getColumns().addAll(IDCol, difficultyCol, firstNameCol, lastNameCol, timeCol);
table.setOnMousePressed(event -> table.getSortOrder().setAll(timeCol));
MenuItem tableDelete = new MenuItem("Delete");
tableDelete.setOnAction(event -> {
if (table.getSelectionModel().getSelectedIndex() == -1)
return;
HighScore current = (HighScore) table.getSelectionModel().getSelectedItem();
highScoresMap.remove(Long.parseLong(current.getRawID()));
refreshTableData();
});
editable.setOnAction(event -> {
if (event.getSource() instanceof CheckBox) {
CheckBox checkBox = (CheckBox) event.getSource();
if (checkBox.isSelected()) {
difficultyCol.setEditable(true);
firstNameCol.setEditable(true);
lastNameCol.setEditable(true);
} else {
difficultyCol.setEditable(false);
firstNameCol.setEditable(false);
lastNameCol.setEditable(false);
}
}
});
// Search abilities setup
table.setPlaceholder(new Label("Search did not return any results."));
ObservableList<String> searchOptions = FXCollections.observableArrayList("Date", "Difficulty", "First Name", "Last Name", "Time");
ComboBox searchSelector = new ComboBox(searchOptions);
searchSelector.getSelectionModel().select(2);
searchSelector.setLayoutX(585 - searchSelector.getLayoutBounds().getWidth() / 2);
searchSelector.setLayoutY(160);
TextField search = new TextField();
search.setPromptText("Search");
search.setPrefWidth(480);
search.setPrefHeight(searchSelector.getHeight());
search.setLayoutX(100);
search.setLayoutY(160);
// Execute search on selection mode change
searchSelector.setOnAction(event -> refreshTableData(search.getText(), (String) searchSelector.getSelectionModel().getSelectedItem()));
// Execute search on any keystroke
search.setOnKeyReleased(event -> {
String query = search.getText();
refreshTableData(query, (String) searchSelector.getSelectionModel().getSelectedItem());
});
scoresRoot.getChildren().addAll(table, searchSelector, search);
// Menu setup
menu.setFill(new ImagePattern(bg));
Text title = new Text(120, 120, "3D Minesweeper");
menuRoot.getChildren().add(title);
title.setFont(new Font(70));
title.setStroke(Color.BLACK);
title.setStrokeWidth(5);
title.setTextAlignment(TextAlignment.CENTER);
title.setX(400 - title.getLayoutBounds().getWidth() / 2);
Text name = new Text(150, 200, "Computer Science (ICS3U-01) FST\nBy Seth Damiani");
menuRoot.getChildren().add(name);
name.setFont(new Font(30));
name.setTextAlignment(TextAlignment.CENTER);
name.setStroke(Color.BLACK);
name.setStrokeWidth(2);
name.setX(400 - name.getLayoutBounds().getWidth() / 2);
Rectangle easy = new Rectangle(250, 300, 300, 75);
menuRoot.getChildren().add(easy);
easy.setStroke(Color.BLACK);
easy.setStrokeWidth(5);
easy.setFill(new Color(1, 1, 1, .5));
easy.setOnMouseEntered(event -> easy.setFill(new Color(1, 1, 1, .8)));
easy.setOnMouseExited(event -> easy.setFill(new Color(1, 1, 1, .5)));
Text easyText = new Text(400, 337.5, "Easy");
menuRoot.getChildren().add(easyText);
easyText.setFont(new Font(50));
easyText.setTextAlignment(TextAlignment.CENTER);
easyText.setStroke(Color.BLACK);
easyText.setStrokeWidth(3);
easyText.setX(400 - easyText.getLayoutBounds().getWidth() / 2);
easyText.setY(350);
easyText.setOnMouseEntered(event -> easy.setFill(new Color(1, 1, 1, .8)));
easyText.setOnMouseExited(event -> easy.setFill(new Color(1, 1, 1, .5)));
Rectangle medium = new Rectangle(250, 400, 300, 75);
menuRoot.getChildren().add(medium);
medium.setStroke(Color.BLACK);
medium.setStrokeWidth(5);
medium.setFill(Color.TRANSPARENT);
medium.setFill(new Color(1, 1, 1, .5));
medium.setOnMouseEntered(event -> medium.setFill(new Color(1, 1, 1, .8)));
medium.setOnMouseExited(event -> medium.setFill(new Color(1, 1, 1, .5)));
Text mediumText = new Text(400, 337.5, "Medium");
menuRoot.getChildren().add(mediumText);
mediumText.setFont(new Font(50));
mediumText.setTextAlignment(TextAlignment.CENTER);
mediumText.setStroke(Color.BLACK);
mediumText.setStrokeWidth(3);
mediumText.setX(400 - mediumText.getLayoutBounds().getWidth() / 2);
mediumText.setY(450);
mediumText.setOnMouseEntered(event -> medium.setFill(new Color(1, 1, 1, .8)));
mediumText.setOnMouseExited(event -> medium.setFill(new Color(1, 1, 1, .5)));
Rectangle hard = new Rectangle(250, 500, 300, 75);
menuRoot.getChildren().add(hard);
hard.setStroke(Color.BLACK);
hard.setStrokeWidth(5);
hard.setFill(Color.TRANSPARENT);
hard.setFill(new Color(1, 1, 1, .5));
hard.setOnMouseEntered(event -> hard.setFill(new Color(1, 1, 1, .8)));
hard.setOnMouseExited(event -> hard.setFill(new Color(1, 1, 1, .5)));
Text hardText = new Text(400, 337.5, "Hard");
menuRoot.getChildren().add(hardText);
hardText.setFont(new Font(50));
hardText.setTextAlignment(TextAlignment.CENTER);
hardText.setStroke(Color.BLACK);
hardText.setStrokeWidth(3);
hardText.setX(400 - hardText.getLayoutBounds().getWidth() / 2);
hardText.setY(550);
hardText.setOnMouseEntered(event -> hard.setFill(new Color(1, 1, 1, .8)));
hardText.setOnMouseExited(event -> hard.setFill(new Color(1, 1, 1, .5)));
Rectangle highscores = new Rectangle(600, 550, 150, 100);
menuRoot.getChildren().add(highscores);
highscores.setStroke(Color.BLACK);
highscores.setStrokeWidth(5);
highscores.setFill(Color.TRANSPARENT);
highscores.setFill(new Color(1, 1, 1, .5));
highscores.setOnMouseEntered(event -> highscores.setFill(new Color(1, 1, 1, .8)));
highscores.setOnMouseExited(event -> highscores.setFill(new Color(1, 1, 1, .5)));
Text highscoresText = new Text("High\nScores");
menuRoot.getChildren().add(highscoresText);
highscoresText.setFont(new Font(40));
highscoresText.setTextAlignment(TextAlignment.CENTER);
highscoresText.setStroke(Color.BLACK);
highscoresText.setStrokeWidth(3);
highscoresText.setX(675 - highscoresText.getLayoutBounds().getWidth() / 2);
highscoresText.setY(590);
highscoresText.setOnMouseEntered(event -> highscores.setFill(new Color(1, 1, 1, .8)));
highscoresText.setOnMouseExited(event -> highscores.setFill(new Color(1, 1, 1, .5)));
Rectangle exit = new Rectangle(50, 550, 150, 100);
menuRoot.getChildren().add(exit);
exit.setStroke(Color.BLACK);
exit.setStrokeWidth(5);
exit.setFill(Color.TRANSPARENT);
exit.setFill(new Color(1, 1, 1, .5));
exit.setOnMouseEntered(event -> exit.setFill(new Color(1, 1, 1, .8)));
exit.setOnMouseExited(event -> exit.setFill(new Color(1, 1, 1, .5)));
Text exitText = new Text("Exit");
menuRoot.getChildren().add(exitText);
exitText.setFont(new Font(40));
exitText.setTextAlignment(TextAlignment.CENTER);
exitText.setStroke(Color.BLACK);
exitText.setStrokeWidth(3);
exitText.setX(125 - exitText.getLayoutBounds().getWidth() / 2);
exitText.setY(610);
exitText.setOnMouseEntered(event -> exit.setFill(new Color(1, 1, 1, .8)));
exitText.setOnMouseExited(event -> exit.setFill(new Color(1, 1, 1, .5)));
// Handle click on easy button
EventHandler<MouseEvent> easyButton = event -> {
resetGame();
placeBombs(50);
totalBombs = 50;
flaggedCells = 0;
placeNumbers();
bombs.setText("Bombs: " + flaggedCells + "/" + totalBombs);
difficulty = "Easy";
primaryStage.setScene(game);
time = 0;
timeTask.play();
};
easy.addEventHandler(MouseEvent.MOUSE_CLICKED, easyButton);
easyText.addEventHandler(MouseEvent.MOUSE_CLICKED, easyButton);
// Handle click on medium button
EventHandler<MouseEvent> mediumButton = event -> {
resetGame();
placeBombs(100);
totalBombs = 100;
flaggedCells = 0;
placeNumbers();
bombs.setText("Bombs: " + flaggedCells + "/" + totalBombs);
difficulty = "Medium";
primaryStage.setScene(game);
time = 0;
timeTask.play();
};
medium.addEventHandler(MouseEvent.MOUSE_CLICKED, mediumButton);
mediumText.addEventHandler(MouseEvent.MOUSE_CLICKED, mediumButton);
// Handle click on hard button
EventHandler<MouseEvent> hardButton = event -> {
resetGame();
placeBombs(150);
totalBombs = 150;
flaggedCells = 0;
placeNumbers();
bombs.setText("Bombs: " + flaggedCells + "/" + totalBombs);
difficulty = "Hard";
primaryStage.setScene(game);
time = 0;
timeTask.play();
};
hard.addEventHandler(MouseEvent.MOUSE_CLICKED, hardButton);
hardText.addEventHandler(MouseEvent.MOUSE_CLICKED, hardButton);
EventHandler<MouseEvent> exitButton = event -> System.exit(0);
exit.addEventHandler(MouseEvent.MOUSE_CLICKED, exitButton);
exitText.addEventHandler(MouseEvent.MOUSE_CLICKED, exitButton);
EventHandler<MouseEvent> highScoresButton = event -> primaryStage.setScene(scores);
highscoresText.addEventHandler(MouseEvent.MOUSE_CLICKED, highScoresButton);
highscores.addEventHandler(MouseEvent.MOUSE_CLICKED, highScoresButton);
readHighScores();
refreshTableData();
// Continuously check if game has been won or lost
game.setOnMouseClicked(event -> {
if (gameLost) {
timeTask.stop();
endScoreText.setText("Time: " + time);
endScoreText.setX(400 - endScoreText.getLayoutBounds().getWidth() / 2);
quitBox.setFill(Color.INDIANRED);
quitText.setText("You Lost");
quitText.setX(400 - quitText.getLayoutBounds().getWidth() / 2);
firstNameBox.setVisible(false);
lastNameBox.setVisible(false);
endScoreText.setVisible(false);
continueText.setText("Menu");
continueText.setX(400 - continueText.getLayoutBounds().getWidth() / 2);
continueRect.setWidth(continueText.getLayoutBounds().getWidth() + 40);
continueRect.setX(400 - continueRect.getLayoutBounds().getWidth() / 2);
primaryStage.setScene(quit);
}
if (gameWon) {
timeTask.stop();
quitBox.setFill(Color.FORESTGREEN);
quitText.setText("You Won!");
quitText.setX(400 - quitText.getLayoutBounds().getWidth() / 2);
firstNameBox.setVisible(true);
lastNameBox.setVisible(true);
endScoreText.setVisible(true);
endScoreText.setText("Time: " + time);
continueText.setText("Submit & Continue");
continueText.setX(400 - continueText.getLayoutBounds().getWidth() / 2);
continueRect.setWidth(continueText.getLayoutBounds().getWidth() + 40);
continueRect.setX(400 - continueRect.getLayoutBounds().getWidth() / 2);
primaryStage.setScene(quit);
}
});
primaryStage.setTitle("Minesweeper 3D - Seth Damiani");
primaryStage.setResizable(false);
primaryStage.setScene(menu);
primaryStage.show();
}
use of javafx.scene.paint.Color in project fxexperience2 by EricCanull.
the class ColorPickerControl method updateUI.
private Color updateUI(double hue, double saturation, double brightness, double alpha) {
updating = true;
// update the HSB values so they are within range
hue = PaintPickerController.clamp(0, hue, 360);
saturation = PaintPickerController.clamp(0, saturation, 1);
brightness = PaintPickerController.clamp(0, brightness, 1);
alpha = PaintPickerController.clamp(0, alpha, 1);
// make an rgb color from the hsb
final Color color = Color.hsb(hue, saturation, brightness, alpha);
int red = (int) (color.getRed() * 255);
int green = (int) (color.getGreen() * 255);
int blue = (int) (color.getBlue() * 255);
// final String hexa = String.format("#%02x%02x%02x", red, green, blue); //NOI18N
final String hexa = "#" + color.toString().toUpperCase().substring(2, color.toString().length());
// Set TextFields value
hue_textfield.setText(String.valueOf((int) hue));
saturation_textfield.setText(String.valueOf((int) (saturation * 100)));
brightness_textfield.setText(String.valueOf((int) (brightness * 100)));
// 2 decimals rounding
double alpha_rounded = round(alpha, 100);
alpha_textfield.setText(Double.toString(alpha_rounded));
red_textfield.setText(Integer.toString(red));
green_textfield.setText(Integer.toString(green));
blue_textfield.setText(Integer.toString(blue));
hexa_textfield.setText(hexa);
// Set the background color of the chips
final StringBuilder sb = new StringBuilder();
//NOI18N
sb.append("hsb(");
sb.append(hue);
//NOI18N
sb.append(", ");
sb.append(saturation * 100);
//NOI18N
sb.append("%, ");
sb.append(brightness * 100);
//NOI18N
sb.append("%, ");
sb.append(alpha);
//NOI18N
sb.append(")");
final String hsbCssValue = sb.toString();
//NOI18N
final String chipStyle = "-fx-background-color: " + hsbCssValue;
chip_region.setStyle(chipStyle);
picker_handle_chip_circle.setFill(Color.rgb(red, green, blue));
final String alphaChipStyle = //NOI18N
"-fx-background-color: " + "linear-gradient(to right, transparent, " + hsbCssValue + //NOI18N
")";
alpha_region.setStyle(alphaChipStyle);
// Set the background color of the picker region
// (force saturation and brightness to 100% - don't add opacity)
final String pickerRegionStyle = //NOI18N
"-fx-background-color: hsb(" + hue + //NOI18N
", 100%, 100%, 1.0);";
picker_region.setStyle(pickerRegionStyle);
// Position the picker dot
// Saturation is on x axis
double xSat = picker_region.getWidth() * saturation;
// Brightness is on y axis (reversed as white is top)
double yBri = picker_region.getHeight() * (1.0 - brightness);
double xPos = (picker_region.getBoundsInParent().getMinX() + xSat) - picker_handle_stackpane.getWidth() / 2;
double yPos = (picker_region.getBoundsInParent().getMinY() + yBri) - picker_handle_stackpane.getHeight() / 2;
picker_handle_stackpane.setLayoutX(xPos);
picker_handle_stackpane.setLayoutY(yPos);
// Set the Sliders value
hue_slider.adjustValue(hue);
alpha_slider.adjustValue(alpha);
updating = false;
return color;
}
use of javafx.scene.paint.Color in project fxexperience2 by EricCanull.
the class ColorPickerControl method onHexaChange.
private void onHexaChange(ActionEvent event) {
try {
// Update UI
final Color color = updateUI_OnHexaChange();
final Object source = event.getSource();
assert source instanceof TextField;
((TextField) source).selectAll();
// Update model
setPaintProperty(color);
} catch (IllegalArgumentException iae) {
handleHexaException();
}
}
Aggregations