Skip to content

Commit

Permalink
#20 Optimize Preferences dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkosertic committed Oct 9, 2017
1 parent fdedc08 commit f622923
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,31 @@

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ListView;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import org.controlsfx.control.PropertySheet;

import java.util.*;
import java.io.File;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;

public class ConfigurationController {

private static String CATEGORY_COMMON = "Common";
private static String CATEGORY_SUGGEST = "Suggestion";
private static String CATEGORY_LANGUAGE = "Language analyzers";
private static String CATEGORY_FILEFORMATS = "File formats";

@FXML
ListView indexedDirectories;

@FXML
Button buttonAdd;

@FXML
Button buttonRemove;

@FXML
PropertySheet propertySheet;
Expand All @@ -34,21 +49,19 @@ public class ConfigurationController {
private ConfigurationManager configurationManager;
private Stage stage;


private final Set<Configuration.CrawlLocation> removedLocations = new HashSet<>();
private final Set<Configuration.CrawlLocation> addedLocations = new HashSet<>();
private final Map<SupportedDocumentType, CheckBox> supportedDocuments = new HashMap<>();
private final Map<SupportedLanguage, CheckBox> supportedLanguages = new HashMap<>();

public void initialize(ConfigurationManager aConfigurationManager, Stage aStage) {
Objects.requireNonNull(propertySheet);
Objects.requireNonNull(buttonOk);

buttonRemove.setOnAction(actionEvent -> removeSelectedLocation());
buttonAdd.setOnAction(actionEvent -> addNewLocation());
buttonOk.setOnAction(actionEvent -> ok());

stage = aStage;
configurationManager = aConfigurationManager;

indexedDirectories.getItems().addAll(configurationManager.getConfiguration().getCrawlLocations());

propertySheet.getItems().add(new PropertyEditorItem(Integer.class, CATEGORY_COMMON, "Max number of documents in search result", SpinnerPropertyEditor.class) {

@Override
Expand Down Expand Up @@ -133,10 +146,62 @@ public void setValue(Object o) {
configurationManager.updateConfiguration(configurationManager.getConfiguration().updateSuggestionsInOrder((Boolean) o));
}
});

for (SupportedLanguage theLanguage : SupportedLanguage.values()) {

propertySheet.getItems().add(new PropertyEditorItem(boolean.class, CATEGORY_LANGUAGE, theLanguage.toLocale().getDisplayName(), BooleanPropertyEditor.class) {

@Override
public Object getValue() {
return configurationManager.getConfiguration().getEnabledLanguages().contains(theLanguage);
}

@Override
public void setValue(Object o) {
configurationManager.updateConfiguration(configurationManager.getConfiguration().enableLanguage(theLanguage));
}
});
}

for (SupportedDocumentType theDocumentType : SupportedDocumentType.values()) {

propertySheet.getItems().add(new PropertyEditorItem(boolean.class, CATEGORY_FILEFORMATS, theDocumentType.getDisplayName(Locale.getDefault()), BooleanPropertyEditor.class) {

@Override
public Object getValue() {
return configurationManager.getConfiguration().getEnabledDocumentTypes().contains(theDocumentType);
}

@Override
public void setValue(Object o) {
configurationManager.updateConfiguration(configurationManager.getConfiguration().enableDocumentType(theDocumentType));
}
});
}

}

private void ok() {
private void removeSelectedLocation() {

Configuration.CrawlLocation theLocation = (Configuration.CrawlLocation) indexedDirectories.getSelectionModel().getSelectedItem();
indexedDirectories.getItems().remove(theLocation);

configurationManager.updateConfiguration(configurationManager.getConfiguration().removeLocation(theLocation));
}

private void addNewLocation() {
DirectoryChooser theChooser = new DirectoryChooser();
theChooser.setTitle("Add new crawl location");
File theFile = theChooser.showDialog(stage.getOwner());
if (theFile != null) {
Configuration.CrawlLocation theNewLocation = new Configuration.CrawlLocation(UUID.randomUUID().toString(), theFile);
indexedDirectories.getItems().add(theNewLocation);

configurationManager.updateConfiguration(configurationManager.getConfiguration().addLocation(theNewLocation));
}
}

private void ok() {
stage.hide();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Modality;
Expand Down Expand Up @@ -223,7 +223,7 @@ void configure() {
stage.initStyle(StageStyle.UTILITY);

FXMLLoader theLoader = new FXMLLoader(getClass().getResource("/scenes/configuration.fxml"));
AnchorPane theConfigurationRoot = theLoader.load();
Parent theConfigurationRoot = theLoader.load();
stage.setScene(new Scene(theConfigurationRoot));
stage.setTitle("Configuration");
stage.initModality(Modality.APPLICATION_MODAL);
Expand Down
86 changes: 54 additions & 32 deletions src/main/resources/scenes/configuration.fxml
Original file line number Diff line number Diff line change
@@ -1,37 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import java.net.URL?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import org.controlsfx.control.PropertySheet?>
<?import java.net.URL?>
<AnchorPane id="AnchorPane" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.mirkosertic.desktopsearch.ConfigurationController">
<children>
<VBox>
<children>
<PropertySheet fx:id="propertySheet" minHeight="400.0" mode="CATEGORY" />
<HBox alignment="TOP_RIGHT" styleClass="dialogButtonArea" VBox.vgrow="NEVER">
<children>
<Button fx:id="buttonOk" alignment="CENTER" contentDisplay="CENTER" maxWidth="120.0" minWidth="120.0" mnemonicParsing="false" prefWidth="120.0" text="Ok" textAlignment="CENTER" />
</children>
<padding>
<Insets bottom="10.0" right="10.0" top="10.0" />
</padding>
<VBox.margin>
<Insets top="10.0" />
</VBox.margin>
</HBox>
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
</children>
<stylesheets>
<URL value="@JMetroLightTheme.css" />
<URL value="@userinterface.css" />
</stylesheets>
<opaqueInsets>
<Insets />
</opaqueInsets>
</AnchorPane>

<BorderPane minHeight="500.0" minWidth="400.0" xmlns="http://javafx.com/javafx/9" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.mirkosertic.desktopsearch.ConfigurationController">
<bottom>
<HBox alignment="TOP_RIGHT" styleClass="dialogButtonArea" BorderPane.alignment="CENTER">
<children>
<Button fx:id="buttonOk" alignment="CENTER" contentDisplay="CENTER" maxWidth="120.0" minWidth="120.0" mnemonicParsing="false" prefWidth="120.0" text="Ok" textAlignment="CENTER" />
</children>
<padding>
<Insets bottom="10.0" right="10.0" top="10.0" />
</padding>
</HBox>
</bottom>
<center>
<PropertySheet fx:id="propertySheet" mode="CATEGORY" modeSwitcherVisible="false" searchBoxVisible="false" BorderPane.alignment="CENTER" />
</center>
<stylesheets>
<URL value="@JMetroLightTheme.css" />
<URL value="@userinterface.css" />
</stylesheets>
<top>
<BorderPane BorderPane.alignment="CENTER">
<right>
<VBox BorderPane.alignment="CENTER">
<children>
<Button fx:id="buttonAdd" maxHeight="25.0" maxWidth="25.0" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="25.0" styleClass="buttonAdd" text="+" />
<Button fx:id="buttonRemove" maxHeight="25.0" maxWidth="25.0" minHeight="25.0" minWidth="25.0" mnemonicParsing="false" prefHeight="25.0" prefWidth="25.0" styleClass="buttonRemove" text="-">
<VBox.margin>
<Insets top="5.0" />
</VBox.margin>
</Button>
</children>
<padding>
<Insets left="5.0" />
</padding>
</VBox>
</right>
<center>
<ListView fx:id="indexedDirectories" prefHeight="100.0" BorderPane.alignment="CENTER" />
</center>
<top>
<Label text="Configured crawl locations:" BorderPane.alignment="TOP_LEFT" />
</top>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" />
</padding>
</BorderPane>
</top>
</BorderPane>

0 comments on commit f622923

Please sign in to comment.