Skip to content

Commit

Permalink
Added progressStatus displaying #3
Browse files Browse the repository at this point in the history
  • Loading branch information
REDNBLACK committed Apr 11, 2016
1 parent 0a83155 commit a0fd5d4
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 45 deletions.
2 changes: 1 addition & 1 deletion gui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

mainClassName = 'org.f0w.k2i.gui.Main'
version = '0.9.0'
version = '0.9.5'

dependencies {
compile project(':k2i-core')
Expand Down
55 changes: 24 additions & 31 deletions gui/src/main/java/org/f0w/k2i/gui/Controller.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class Controller {
@FXML
private Button startBtn;

@FXML
private Label progressStatus;

@FXML
private javafx.scene.control.ProgressBar progressBar;

Expand All @@ -102,7 +105,7 @@ public class Controller {
@FXML
private TextField logLevelField;

void init(Stage stage) {
void setStage(Stage stage) {
this.stage = stage;
}

Expand All @@ -128,14 +131,10 @@ void initialize() {
});
modeComboBox.getSelectionModel().select(new Choice<>(MovieHandler.Type.valueOf(config.getString("mode"))));

authId.focusedProperty().addListener((observable, oldValue, newValue) -> {
configMap.put("auth", authId.getText());
});
authId.focusedProperty().addListener(o -> configMap.put("auth", authId.getText()));
authId.setText(config.getString("auth"));

listId.focusedProperty().addListener((arg0, oldValue, newValue) -> {
configMap.put("list", listId.getText());
});
listId.focusedProperty().addListener(o -> configMap.put("list", listId.getText()));
listId.setText(config.getString("list"));


Expand Down Expand Up @@ -181,37 +180,29 @@ void initialize() {


// Для экспертов
userAgentField.focusedProperty().addListener((arg0, oldValue, newValue) -> {
configMap.put("user_agent", userAgentField.getText());
});
userAgentField.focusedProperty().addListener(o -> configMap.put("user_agent", userAgentField.getText()));
userAgentField.setText(config.getString("user_agent"));

yearDeviationField.focusedProperty().addListener((arg0, oldValue, newValue) -> {
configMap.put("year_deviation", yearDeviationField.getText());
});
yearDeviationField.focusedProperty()
.addListener(o -> configMap.put("year_deviation", yearDeviationField.getText()));
yearDeviationField.setText(config.getString("year_deviation"));

timeoutField.focusedProperty().addListener((arg0, oldValue, newValue) -> {
configMap.put("timeout", timeoutField.getText());
});
timeoutField.focusedProperty().addListener(o -> configMap.put("timeout", timeoutField.getText()));
timeoutField.setText(config.getString("timeout"));

logLevelField.focusedProperty().addListener((arg0, oldValue, newValue) -> {
configMap.put("log_level", logLevelField.getText());
});
logLevelField.focusedProperty().addListener(o -> configMap.put("log_level", logLevelField.getText()));
logLevelField.setText(config.getString("log_level"));
}

void destroy() {
byte[] configuration = ConfigFactory.parseMap(configMap)
.withFallback(config)
.root()
.render(ConfigRenderOptions.concise())
.getBytes();

try {
Files.write(
configFile.toPath(),
ConfigFactory.parseMap(configMap)
.withFallback(config)
.root()
.render(ConfigRenderOptions.concise())
.getBytes()
);
Files.write(configFile.toPath(), configuration);
} catch (IOException ignore) {
// Do nothing
}
Expand Down Expand Up @@ -260,7 +251,7 @@ protected void handleStartAction(ActionEvent event) {
private class ProgressListener {
private final AtomicInteger max = new AtomicInteger(0);
private final AtomicInteger current = new AtomicInteger(0);
private final AtomicInteger successfulCount = new AtomicInteger(0);
private final AtomicInteger successful = new AtomicInteger(0);

@Subscribe
public void handleStart(ImportStartedEvent event) {
Expand All @@ -269,6 +260,7 @@ public void handleStart(ImportStartedEvent event) {
Platform.runLater(() -> {
startBtn.setText("В процессе...");
startBtn.setDisable(true);
progressStatus.setText("0/" + max.get());
});
}

Expand All @@ -277,10 +269,11 @@ public void handleAdvance(ImportProgressAdvancedEvent event) {
int maximum = max.get();
int cur = current.incrementAndGet();
if (event.successful) {
successfulCount.incrementAndGet();
successful.incrementAndGet();
}

progressBar.setProgress((cur * 100 / maximum) * 0.01);
Platform.runLater(() -> progressStatus.setText(cur + "/" + maximum));
}

@Subscribe
Expand All @@ -302,7 +295,7 @@ public void handleEnd(ImportFinishedEvent event) {
alert.setHeaderText("Обработка фильмов была завершена с ошибками.");

alert.setContentText(
"Было обработаны " + successfulCount.get() + " из " + max.get() + " фильмов, без ошибок"
"Было обработаны " + successful.get() + " из " + max.get() + " фильмов, без ошибок"
);

// Create expandable Exception.
Expand All @@ -328,7 +321,7 @@ public void handleEnd(ImportFinishedEvent event) {

String exceptionText = sw.toString();

Label label = new Label("Произошли ошибки с " + (max.get() - successfulCount.get()) + " фильмами:");
Label label = new Label("Произошли ошибки с " + (max.get() - successful.get()) + " фильмами:");

TextArea textArea = new TextArea(exceptionText);
textArea.setEditable(false);
Expand Down
6 changes: 3 additions & 3 deletions gui/src/main/java/org/f0w/k2i/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import javafx.stage.Stage;

public class Main extends Application {
public static final int WIDTH = 600;
public static final int HEIGHT = 361;
private static final int WIDTH = 600;
private static final int HEIGHT = 361;

public static void main(String[] args) {
Application.launch(Main.class, args);
Expand All @@ -22,7 +22,7 @@ public void start(Stage stage) throws Exception {
Parent root = loader.load();

Controller controller = loader.getController();
controller.init(stage);
controller.setStage(stage);

stage.setTitle("Kinopoisk2IMDB");
stage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("icon.png")));
Expand Down
8 changes: 4 additions & 4 deletions gui/src/main/resources/fxml/main.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
root {
display: block;
}

.text-field.error {
-fx-text-box-border: red;
-fx-focus-color: red;
Expand All @@ -16,4 +12,8 @@ root {
derive(-fx-accent, 30%) 50%,
derive(-fx-accent, 30%) 99%
);
}

#progressStatus {
-fx-text-fill: crimson;
}
14 changes: 8 additions & 6 deletions gui/src/main/resources/fxml/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,15 @@
<!--End Accordion row-->

<!--Start HBox row-->
<HBox alignment="BOTTOM_RIGHT" prefWidth="600" prefHeight="50.0" spacing="40.0" layoutY="311.0">
<HBox alignment="BOTTOM_RIGHT" layoutY="311.0" prefHeight="50.0" prefWidth="600" spacing="40.0">
<children>
<ProgressBar fx:id="progressBar" maxHeight="30.0" prefWidth="435.0" progress="0.0" />
<Button maxHeight="30.0" mnemonicParsing="false"
fx:id="startBtn"
text="Запустить"
onAction="#handleStartAction" />
<AnchorPane>
<children>
<ProgressBar fx:id="progressBar" prefHeight="30.0" prefWidth="437.0" progress="0.0" />
<Label fx:id="progressStatus" layoutX="198.0" layoutY="-1.0" prefHeight="30.0" text="0/0" />
</children>
</AnchorPane>
<Button fx:id="startBtn" maxHeight="30.0" mnemonicParsing="false" onAction="#handleStartAction" text="Запустить" />
</children>
<padding>
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
Expand Down

0 comments on commit a0fd5d4

Please sign in to comment.