Skip to content

Commit

Permalink
Improve JavaFX
Browse files Browse the repository at this point in the history
  • Loading branch information
LimZiJia committed Feb 25, 2024
1 parent 97d286a commit ceb7198
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
8 changes: 3 additions & 5 deletions data/duke.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
T,0,1
T,0,2
T,0,3
T,0,4
T,0,5
T,0,2106_lab_2
E,0,mid_terms,2024-03-01,2024-03-14
D,0,2102_assignment_1,2024-03-07
14 changes: 11 additions & 3 deletions src/main/duke/ui/DialogBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;

/**
* An example of a custom control using FXML.
Expand All @@ -41,9 +42,16 @@ private DialogBox(String text, Image img, Color c) {
e.printStackTrace();
}

Circle clip = new Circle();
clip.setCenterX(90);
clip.setCenterY(90);
clip.setRadius(82);
dialog.setText(text);
displayPicture.setImage(img);
setBackground(new Background(new BackgroundFill(c, CornerRadii.EMPTY, Insets.EMPTY)));
displayPicture.setClip(clip);
setBackground(new Background(new BackgroundFill(c,
new CornerRadii(30),
new Insets(5, 5, 10, 10))));
}

/**
Expand All @@ -57,11 +65,11 @@ private void flip() {
}

public static DialogBox getUserDialog(String text, Image img) {
return new DialogBox(text, img, Color.AQUA);
return new DialogBox(text, img, Color.LIGHTSTEELBLUE);
}

public static DialogBox getDukeDialog(String text, Image img) {
var db = new DialogBox(text, img, Color.AQUAMARINE);
var db = new DialogBox(text, img, Color.LIGHTGRAY);
db.flip();
return db;
}
Expand Down
41 changes: 18 additions & 23 deletions src/main/resources/view/DialogBox.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,30 @@

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.text.Font?>

<fx:root alignment="TOP_RIGHT" fillHeight="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<fx:root alignment="CENTER" fillHeight="false" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" nodeOrientation="LEFT_TO_RIGHT" prefHeight="240.0" prefWidth="498.0" type="javafx.scene.layout.HBox" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<SplitPane dividerPositions="0.7108" prefWidth="500.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="198.0" prefWidth="307.0">
<children>
<Label fx:id="dialog" prefHeight="198.0" prefWidth="296.0" text="Label" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="0.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<font>
<Font name="Consolas" size="12.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0">
<children>
<ImageView fx:id="displayPicture" fitHeight="209.0" fitWidth="148.0" layoutX="-7.0" layoutY="-8.0" pickOnBounds="true" />
</children>
</AnchorPane>
</items>
</SplitPane>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="240.0" prefWidth="300.0">
<children>
<Label fx:id="dialog" layoutX="6.0" prefHeight="240.0" prefWidth="300.0" text="Label" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="6.0" AnchorPane.rightAnchor="-20.0" AnchorPane.topAnchor="0.0">
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
</padding>
<font>
<Font name="Consolas" size="9.0" />
</font>
</Label>
</children>
</AnchorPane>
<AnchorPane minHeight="0.0" minWidth="0.0" nodeOrientation="LEFT_TO_RIGHT" prefHeight="240.0" prefWidth="188.0">
<children>
<ImageView fx:id="displayPicture" fitHeight="171.0" fitWidth="170.0" layoutX="9.0" layoutY="35.0" pickOnBounds="true" />
</children>
</AnchorPane>
</children>
<opaqueInsets>
<Insets />
Expand Down

0 comments on commit ceb7198

Please sign in to comment.