Skip to content

Commit

Permalink
add config 🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
madneal committed Oct 31, 2017
1 parent e7e6169 commit 1f5f573
Show file tree
Hide file tree
Showing 16 changed files with 427 additions and 148 deletions.
1 change: 1 addition & 0 deletions .gitnignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*/target
out
352 changes: 223 additions & 129 deletions .idea/workspace.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# F: FULLSEARCH L:LOCALSEARCH
searchMethod: F
excludeFilePathList: [node_modules, $RECYCLE.BIN\\S]
fileList: [docx, doc, xls, xlsx, pdf, txt]
compressFileList: [7z, zip, rar]
# mb
limitFileSize: 500
Binary file added out/production/ui/client/Setting.class
Binary file not shown.
Binary file added out/production/ui/client/Window.class
Binary file not shown.
8 changes: 8 additions & 0 deletions out/production/ui/client/client.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>

<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<GridPane fx:controller="controller.Controller"
xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">
</GridPane>
Binary file added out/production/ui/controller/Controller.class
Binary file not shown.
Binary file added out/production/ui/sample/Controller.class
Binary file not shown.
27 changes: 27 additions & 0 deletions out/production/ui/view/RootLayout.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>

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

<BorderPane prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8">
<top><MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top></BorderPane>
28 changes: 28 additions & 0 deletions out/production/ui/view/Setting.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>

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

<AnchorPane prefHeight="300.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8">
<children><SplitPane focusTraversable="true" layoutX="183.0" layoutY="76.0" prefHeight="300.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<items>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="160.0" prefWidth="100.0" />
</items>
</SplitPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" />
<TabPane prefHeight="200.0" prefWidth="200.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab text="Untitled Tab 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
<Tab text="Untitled Tab 2">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0" />
</content>
</Tab>
</tabs>
</TabPane>
</children></AnchorPane>
32 changes: 18 additions & 14 deletions search/src/main/java/index/IndexUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@

public class IndexUtil {

public static void executeIndex(String searchType) throws Exception {
List<FileBean> fileBeans = new ArrayList<>();
if (searchType == CommonConstants.FULL_SEARCH) {
List<String> driverPaths = FileUtil.getDriver();
for (String driver : driverPaths) {
fileBeans.addAll(FileUtil.getFolderFiles(driver));
public static void executeIndex(String searchType) {
try {
List<FileBean> fileBeans = new ArrayList<>();
if (searchType == CommonConstants.FULL_SEARCH) {
List<String> driverPaths = FileUtil.getDriver();
for (String driver : driverPaths) {
fileBeans.addAll(FileUtil.getFolderFiles(driver));
}
} else {
fileBeans = FileUtil.getFolderFiles(CommonConstants.INPUT_FILE_PATH);
}
} else {
fileBeans = FileUtil.getFolderFiles(CommonConstants.INPUT_FILE_PATH);
int totalCount = fileBeans.size();
CommonConstants.TOTAL_FILE_NUM = String.valueOf(totalCount);
System.out.println(fileBeans.size());
System.out.println("开始创建索引");
BaseIndex.runIndex(fileBeans);
System.out.println("所有线程都创建索引完毕");
} catch (Exception e) {
e.printStackTrace();
}
int totalCount = fileBeans.size();
CommonConstants.TOTAL_FILE_NUM = String.valueOf(totalCount);
System.out.println(fileBeans.size());
System.out.println("开始创建索引");
BaseIndex.runIndex(fileBeans);
System.out.println("所有线程都创建索引完毕");
}

public static IndexWriter getIndexWriter(String indexPath, boolean create) throws IOException {
Expand Down
11 changes: 8 additions & 3 deletions ui/src/main/java/client/Window.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package client;

import index.IndexUtil;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import setting.ConfigController;
import setting.ConfigSetting;

import java.io.IOException;

Expand All @@ -17,10 +20,12 @@ public class Window extends Application {
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("AddressApp");

this.primaryStage.setTitle("Search Everywhere");
ConfigSetting configSetting = ConfigController.readConfig();
if (!configSetting.getHasCreateIndex()) {
IndexUtil.executeIndex(configSetting.getSearchMethod());
}
initRootLayout();

showPersonOverview();
}

Expand Down
5 changes: 5 additions & 0 deletions ui/src/main/java/constants/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package constants;

public class Constants {
public static String CONFIG_FILEPATH = "config.yaml";
}
43 changes: 43 additions & 0 deletions ui/src/main/java/setting/ConfigController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package setting;

import constants.Constants;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

public class ConfigController {

public static ConfigSetting readConfig() {
ConfigSetting configSetting = null;
try {
InputStream configIs = Files.newInputStream(Paths.get(Constants.CONFIG_FILEPATH));
Yaml yaml = new Yaml(new Constructor(ConfigSetting.class));
configSetting = yaml.loadAs(configIs, ConfigSetting.class);
} catch (Exception e) {
e.printStackTrace();
}
return configSetting;
}

public static void writeConfigToYaml(ConfigSetting configSetting) {
try {
Yaml yaml = new Yaml();
String output = yaml.dump(configSetting);
byte[] sourceByte = output.getBytes();
File file = new File(Constants.CONFIG_FILEPATH);
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
fileOutputStream.write(sourceByte);
fileOutputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
56 changes: 56 additions & 0 deletions ui/src/main/java/setting/ConfigSetting.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package setting;

import java.util.List;

public class ConfigSetting {

private String searchMethod;

private List<String> excludeFilePathList;

private List<String> fileList;

private List<String> compressFileList;

private boolean hasCreateIndex;

public String getSearchMethod() {
return searchMethod;
}

public void setSearchMethod(String searchMethod) {
this.searchMethod = searchMethod;
}

public List<String> getExcludeFilePathList() {
return excludeFilePathList;
}

public void setExcludeFilePathList(List<String> excludeFilePathList) {
this.excludeFilePathList = excludeFilePathList;
}

public List<String> getFileList() {
return fileList;
}

public void setFileList(List<String> fileList) {
this.fileList = fileList;
}

public List<String> getCompressFileList() {
return compressFileList;
}

public void setCompressFileList(List<String> compressFileList) {
this.compressFileList = compressFileList;
}

public boolean getHasCreateIndex() {
return hasCreateIndex;
}

public void setHasCreateIndex(boolean hasCreateIndex) {
this.hasCreateIndex = hasCreateIndex;
}
}
5 changes: 3 additions & 2 deletions ui/src/main/java/view/Setting.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
<children>
<Group>
<children>
<Button layoutX="407.0" layoutY="45.0" mnemonicParsing="false" text="Button" />
<Button layoutX="488.0" layoutY="45.0" mnemonicParsing="false" text="search" />
<Label layoutX="19.0" layoutY="50.0" text="Search field" />
<TextField layoutX="145.0" layoutY="45.0" />
<TextField layoutX="159.0" layoutY="47.0" onContextMenuRequested="#getSearchTextChanged" prefHeight="30.0" prefWidth="271.0" />
</children>
</Group>
</children>
Expand All @@ -40,6 +40,7 @@
<CheckBox layoutX="82.0" layoutY="102.0" mnemonicParsing="false" text="txt" />
</children>
</HBox>
<Button layoutX="469.0" layoutY="201.0" mnemonicParsing="false" text="index" />
</children>
</AnchorPane>
</content>
Expand Down

0 comments on commit 1f5f573

Please sign in to comment.