Skip to content

Commit

Permalink
Merge pull request #2 from gekoramy/shuffle-ability
Browse files Browse the repository at this point in the history
Add the ability to shuffle
  • Loading branch information
gekoramy authored Aug 28, 2018
2 parents 0959e22 + 97f5346 commit 41ca1e1
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 92 deletions.
4 changes: 2 additions & 2 deletions src/main/java/me/gekoramy/github/quiz/app/AppDownload.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public void start(Stage stage) {
Injector.setConfigurationSource(customProperties::get);
DownloadView appView = new DownloadView();
Scene scene = new Scene(appView.getView());
stage.setHeight(150.0);
stage.setMinHeight(150.0);
stage.setMaxHeight(150.0);
stage.setTitle("Download");
stage.setResizable(false);
stage.setScene(scene);
stage.show();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/me/gekoramy/github/quiz/app/AppPreview.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ public void start(Stage stage) {
PreviewView appView = new PreviewView();
Scene scene = new Scene(appView.getView());
((PreviewPresenter) appView.getPresenter()).setAccelerators(scene);
stage.setHeight(150.0);
stage.setMinHeight(150.0);
stage.setMaxHeight(150.0);
stage.setTitle("Preview");
stage.setScene(scene);
stage.setResizable(false);
stage.show();
}

Expand Down
26 changes: 9 additions & 17 deletions src/main/java/me/gekoramy/github/quiz/app/download/download.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<StackPane prefHeight="150.0" stylesheets="@download.css" xmlns="http://javafx.com/javafx/8.0.121"
xmlns:fx="http://javafx.com/fxml/1" fx:controller="me.gekoramy.github.quiz.app.download.DownloadPresenter"
fx:id="root" style="-fx-background-color: #EE6A5F;">
<StackPane fx:id="root" prefHeight="150.0" style="-fx-background-color: #EE6A5F;" stylesheets="@download.css"
xmlns="http://javafx.com/javafx/8.0.121" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="me.gekoramy.github.quiz.app.download.DownloadPresenter">
<VBox>
<ProgressBar fx:id="progress" minHeight="150.0" maxWidth="999999.0"/>
<ProgressBar fx:id="progress" maxWidth="999999.0" minHeight="150.0"/>
</VBox>

<GridPane>
<rowConstraints>
<RowConstraints valignment="CENTER" vgrow="SOMETIMES"/>
</rowConstraints>

<columnConstraints>
<ColumnConstraints halignment="LEFT" hgrow="SOMETIMES"/>
</columnConstraints>

<VBox alignment="CENTER_LEFT">
<Label fx:id="lblRepo" text="lblRepo" GridPane.columnIndex="0">
<font>
<Font size="35.0"/>
</font>
<VBox.margin>
<Insets left="15.0" right="15.0"/>
</VBox.margin>
</Label>
<StackPane.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</StackPane.margin>
</GridPane>
</VBox>

</StackPane>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class PreviewPresenter implements Initializable {
@FXML
private Hyperlink btnRefresh;
@FXML
private Hyperlink btnShuffle;
@FXML
private Hyperlink btnDownload;
@FXML
private Hyperlink btnStart;
Expand Down Expand Up @@ -92,6 +94,9 @@ public void initialize(URL location, ResourceBundle resources) {

progress.progressProperty().bind(examStarter.getQuestionPool().progressProperty());

btnRefresh.managedProperty().bindBidirectional(btnRefresh.visibleProperty());
btnDownload.managedProperty().bindBidirectional(btnDownload.visibleProperty());

updateAvailable.valueProperty().addListener((value, oldValue, newValue) -> {
if (newValue != null && newValue) {
btnDownload.visibleProperty().set(true);
Expand All @@ -108,6 +113,7 @@ public void initialize(URL location, ResourceBundle resources) {
btnStore.setOnAction(e -> onStore());
btnDownload.setOnAction(e -> onDownload());
btnRefresh.setOnAction(e -> onRefresh());
btnShuffle.setOnAction(e -> onShuffle());
btnStart.setOnAction(e -> onStart());
}

Expand Down Expand Up @@ -180,4 +186,8 @@ private void onRefresh() {
}
}
}

private void onShuffle() {
examStarter.shuffle();
}
}
138 changes: 68 additions & 70 deletions src/main/java/me/gekoramy/github/quiz/app/preview/preview.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -13,76 +13,74 @@
progress="1"/>
</VBox>

<GridPane hgap="40.0">
<rowConstraints>
<RowConstraints valignment="CENTER" vgrow="SOMETIMES"/>
<RowConstraints valignment="CENTER" vgrow="NEVER"/>
</rowConstraints>
<VBox alignment="CENTER" spacing="15.0">
<HBox alignment="CENTER" spacing="15.0">
<Hyperlink fx:id="lblRepo" style="-fx-text-fill: #424242;" text="lblRepo">
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Region HBox.hgrow="ALWAYS"/>
<Hyperlink fx:id="btnStore">
<graphic>
<SVGPath
content="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"
scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Hyperlink fx:id="btnRefresh">
<graphic>
<SVGPath
content="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"
scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Hyperlink fx:id="btnDownload" visible="false" managed="false">
<graphic>
<SVGPath
content="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z"
scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Hyperlink fx:id="btnShuffle">
<graphic>
<SVGPath
content="M10.59 9.17L5.41 4 4 5.41l5.17 5.17 1.42-1.41zM14.5 4l2.04 2.04L4 18.59 5.41 20 17.96 7.46 20 9.5V4h-5.5zm.33 9.41l-1.41 1.41 3.13 3.13L14.5 20H20v-5.5l-2.04 2.04-3.13-3.13z"
scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Hyperlink fx:id="btnStart">
<graphic>
<SVGPath content="M8 5v14l11-7z" scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Label fx:id="lblQuestions" minWidth="50">
<font>
<Font size="35.0"/>
</font>
</Label>
</HBox>

<columnConstraints>
<ColumnConstraints halignment="LEFT" hgrow="SOMETIMES"/>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES"/>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES"/>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES"/>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES"/>
</columnConstraints>

<Hyperlink fx:id="lblRepo" style="-fx-text-fill: #424242;" text="lblRepo" GridPane.columnIndex="0">
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Hyperlink fx:id="btnStore" GridPane.columnIndex="1">
<graphic>
<SVGPath
content="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm-5 16c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-10H5V5h10v4z"
scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>

<Hyperlink fx:id="btnRefresh" GridPane.columnIndex="2">
<graphic>
<SVGPath
content="M17.65 6.35C16.2 4.9 14.21 4 12 4c-4.42 0-7.99 3.58-7.99 8s3.57 8 7.99 8c3.73 0 6.84-2.55 7.73-6h-2.08c-.82 2.33-3.04 4-5.65 4-3.31 0-6-2.69-6-6s2.69-6 6-6c1.66 0 3.14.69 4.22 1.78L13 11h7V4l-2.35 2.35z"
scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Hyperlink fx:id="btnDownload" visible="false" GridPane.columnIndex="2">
<graphic>
<SVGPath
content="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM17 13l-5 5-5-5h3V9h4v4h3z"
scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Hyperlink fx:id="btnStart" GridPane.columnIndex="3">
<graphic>
<SVGPath content="M8 5v14l11-7z" scaleX="1.5" scaleY="1.5" style="-fx-fill: #424242;"/>
</graphic>
<font>
<Font size="35.0"/>
</font>
</Hyperlink>
<Label fx:id="lblQuestions" GridPane.columnIndex="4" minWidth="50">
<font>
<Font size="35.0"/>
</font>
</Label>

<Slider fx:id="sldQuestions" min="1" GridPane.rowIndex="1" GridPane.columnSpan="5" blockIncrement="1" snapToTicks="true"
majorTickUnit="1" minorTickCount="0"/>

<StackPane.margin>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
</StackPane.margin>
</GridPane>
<Slider fx:id="sldQuestions" blockIncrement="1" majorTickUnit="1" min="1" minorTickCount="0" snapToTicks="true">
<VBox.margin>
<Insets left="15.0" right="15.0"/>
</VBox.margin>
</Slider>
</VBox>

</StackPane>
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@ protected Void call() {
}
};
}

public void shuffle() {
questionPool.shuffle();
}
}
5 changes: 4 additions & 1 deletion src/main/java/me/gekoramy/github/quiz/util/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public DoubleProperty progressProperty() {
public void revert() {
toDoList.clear();
toDoList.addAll(totalList);
Collections.shuffle(toDoList);
this.progress.set(1);
}

Expand All @@ -76,4 +75,8 @@ public List<T> retrieve(int many) {
public boolean isDone() {
return toDoList.size() == 0;
}

public void shuffle() {
Collections.shuffle(toDoList);
}
}

0 comments on commit 41ca1e1

Please sign in to comment.