Skip to content

Commit

Permalink
Implemented handling/saving of options for expert
Browse files Browse the repository at this point in the history
  • Loading branch information
REDNBLACK committed Apr 8, 2016
1 parent 9070982 commit 1795e3e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 40 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ subprojects {
repositories {
mavenCentral()
}

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
13 changes: 11 additions & 2 deletions 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.8.0'
version = '0.9.0'

dependencies {
compile project(':core')
Expand All @@ -15,14 +15,23 @@ dependencies {

copyL4jLib.dependsOn shadowJar

task copyIcon(type: Copy) {
from 'src/main/resources/icon.ico'
into 'build/launch4j'
}

afterEvaluate {
copyL4jLib.dependsOn copyIcon
}

launch4j {
mainClassName
productName = 'Kinopoisk2IMDB GUI'
internalName = 'k2i-gui'
copyright = 'REDNBLACK'
companyName = 'f0w.org'
productVersion = version
outfile = 'Kinopoisk2IMDB.exe'
icon = 'icon.ico'
copyConfigurable = project.tasks.shadowJar.outputs.files
jar = "lib/${project.tasks.shadowJar.archiveName}"
}
93 changes: 65 additions & 28 deletions gui/src/main/java/org/f0w/k2i/gui/Controller.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.f0w.k2i.gui;

import com.google.common.eventbus.Subscribe;

import com.typesafe.config.Config;
import com.typesafe.config.ConfigException;
import com.typesafe.config.ConfigFactory;
import com.typesafe.config.ConfigRenderOptions;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
Expand All @@ -15,16 +17,14 @@
import javafx.scene.layout.Priority;
import javafx.stage.FileChooser;
import javafx.stage.Stage;

import org.controlsfx.control.CheckComboBox;
import org.controlsfx.control.ToggleSwitch;

import org.f0w.k2i.core.Client;
import org.f0w.k2i.core.comparator.MovieComparator;
import org.f0w.k2i.core.comparator.title.*;
import org.f0w.k2i.core.comparator.year.DeviationYearComparator;
import org.f0w.k2i.core.comparator.year.EqualsYearComparator;
import org.f0w.k2i.core.event.ImportFinishedEvent;
import org.f0w.k2i.core.event.ImportStartedEvent;
import org.f0w.k2i.core.event.ImportProgressAdvancedEvent;
import org.f0w.k2i.core.comparator.year.*;
import org.f0w.k2i.core.event.*;
import org.f0w.k2i.core.exchange.finder.MovieFinder;
import org.f0w.k2i.core.handler.MovieHandler;
import org.f0w.k2i.core.model.entity.Movie;
Expand Down Expand Up @@ -63,10 +63,10 @@ public class Controller {
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().unwrapped()));

@FXML
private ChoiceBox<Choice<MovieHandler.Type, String>> modeChoiceBox;
private ComboBox<Choice<MovieHandler.Type, String>> modeComboBox;

@FXML
private ChoiceBox<Choice<MovieFinder.Type, String>> queryFormatChoiceBox;
private ComboBox<Choice<MovieFinder.Type, String>> queryFormatComboBox;

@FXML
private Label selectedFile;
Expand All @@ -81,7 +81,7 @@ public class Controller {
private Button selectFileBtn;

@FXML
private ToggleSwitch cleanRunSwitch;
private CheckBox cleanRunCheckbox;

@FXML
private Button startBtn;
Expand All @@ -92,18 +92,31 @@ public class Controller {
@FXML
private CheckComboBox<Choice<Class<? extends MovieComparator>, String>> comparatorsBox;

@FXML
private TextField userAgentField;

@FXML
private TextField yearDeviationField;

@FXML
private TextField timeoutField;

@FXML
private TextField logLevelField;

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

@FXML
void initialize() {
modeChoiceBox.setItems(FXCollections.observableArrayList(
// Основные
modeComboBox.setItems(FXCollections.observableArrayList(
new Choice<>(MovieHandler.Type.SET_RATING, "Выставить рейтинг"),
new Choice<>(ADD_TO_WATCHLIST, "Добавить в список"),
new Choice<>(COMBINED, "Добавить в список и выставить рейтинг")
));
modeChoiceBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
modeComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue.value.equals(ADD_TO_WATCHLIST) || newValue.value.equals(COMBINED)) {
listId.setEditable(true);
listId.setDisable(false);
Expand All @@ -115,33 +128,34 @@ void initialize() {

configMap.put("mode", newValue.value.toString());
});
modeChoiceBox.getSelectionModel().select(new Choice<>(MovieHandler.Type.valueOf(config.getString("mode"))));
modeComboBox.getSelectionModel().select(new Choice<>(MovieHandler.Type.valueOf(config.getString("mode"))));

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

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


queryFormatChoiceBox.setItems(FXCollections.observableArrayList(

// Дополнительные
queryFormatComboBox.setItems(FXCollections.observableArrayList(
new Choice<>(XML, "XML"),
new Choice<>(JSON, "JSON"),
new Choice<>(HTML, "HTML"),
new Choice<>(MIXED, "Смешанный")
));
queryFormatChoiceBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
queryFormatComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
configMap.put("query_format", newValue.value.toString());
});
queryFormatChoiceBox.getSelectionModel().select(
queryFormatComboBox.getSelectionModel().select(
new Choice<>(MovieFinder.Type.valueOf(config.getString("query_format")))
);

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

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

progressBar.setMaxWidth(Double.MAX_VALUE);

comparatorsBox.getItems().addAll(FXCollections.observableArrayList(
new Choice<>(DeviationYearComparator.class, "Год с отклонением"),
new Choice<>(EqualsYearComparator.class, "Год с полным совпадением"),
Expand All @@ -162,9 +176,32 @@ void initialize() {
new Choice<>(ReflectionUtils.stringToClass(c, MovieComparator.class))
));

cleanRunSwitch.selectedProperty().addListener((observable, oldValue, newValue) -> {
cleanRunCheckbox.selectedProperty().addListener((observable, oldValue, newValue) -> {
cleanRun = newValue;
});



// Для экспертов
userAgentField.focusedProperty().addListener((arg0, oldValue, newValue) -> {
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.setText(config.getString("year_deviation"));

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

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

void destroy() {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main/java/org/f0w/k2i/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void start(Stage stage) throws Exception {
Controller controller = loader.getController();
controller.init(stage);

stage.setTitle("Kinopoisk2IMDB GUI");
stage.setTitle("Kinopoisk2IMDB");
stage.getIcons().add(new Image(getClass().getClassLoader().getResourceAsStream("icon.png")));
stage.setScene(new Scene(root, WIDTH, HEIGHT));
stage.setResizable(false);
Expand Down
16 changes: 7 additions & 9 deletions gui/src/main/resources/fxml/main.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<?import org.controlsfx.control.CheckComboBox?>
<?import org.controlsfx.control.ToggleSwitch?>

<?import java.net.URL?>
<FlowPane fx:controller="org.f0w.k2i.gui.Controller"
Expand Down Expand Up @@ -56,7 +54,7 @@
<Label text="Режим работы" GridPane.rowIndex="2" />
<Label text="Строка авторизации IMDB" GridPane.rowIndex="3" />
<Label text="ID списка IMDB" GridPane.rowIndex="4" />
<ChoiceBox fx:id="modeChoiceBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<ComboBox fx:id="modeComboBox" maxWidth="1.7976931348623157E308" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="authId" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="listId" GridPane.columnIndex="1" GridPane.rowIndex="4" />
</children>
Expand Down Expand Up @@ -86,9 +84,9 @@
<Label text="Тип запроса" />
<Label text="Сравнение" GridPane.rowIndex="1" />
<Label text="Чистый запуск" GridPane.rowIndex="2" />
<ChoiceBox fx:id="queryFormatChoiceBox" GridPane.columnIndex="1" />
<ComboBox fx:id="queryFormatComboBox" GridPane.columnIndex="1" />
<CheckComboBox fx:id="comparatorsBox" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<ToggleSwitch fx:id="cleanRunSwitch" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<CheckBox fx:id="cleanRunCheckbox" GridPane.columnIndex="1" GridPane.rowIndex="2" />
</children>
</GridPane>
</children>
Expand All @@ -108,10 +106,10 @@
<Label text="year_deviation" GridPane.rowIndex="1" />
<Label text="timeout" GridPane.rowIndex="2" />
<Label text="log_level" GridPane.rowIndex="3" />
<TextField GridPane.columnIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField GridPane.columnIndex="1" GridPane.rowIndex="3" />
<TextField fx:id="userAgentField" GridPane.columnIndex="1" />
<TextField fx:id="yearDeviationField" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<TextField fx:id="timeoutField" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<TextField fx:id="logLevelField" GridPane.columnIndex="1" GridPane.rowIndex="3" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="261.0" minWidth="10.0" prefWidth="193.0" />
Expand Down

0 comments on commit 1795e3e

Please sign in to comment.