mirror of
https://github.com/frosch95/SmartCSV.fx.git
synced 2026-04-11 13:38:23 +02:00
read and edit csv preferences
This commit is contained in:
45
src/main/java/ninja/javafx/smartcsv/csv/CSVConfigurable.java
Normal file
45
src/main/java/ninja/javafx/smartcsv/csv/CSVConfigurable.java
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ninja.javafx.smartcsv.csv;
|
||||||
|
|
||||||
|
import org.supercsv.prefs.CsvPreference;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class CSVConfigurable {
|
||||||
|
|
||||||
|
protected CsvPreference csvPreference;
|
||||||
|
|
||||||
|
public CSVConfigurable() {
|
||||||
|
csvPreference = CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCsvPreference(CsvPreference csvPreference) {
|
||||||
|
this.csvPreference = csvPreference;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,6 @@ import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.supercsv.io.CsvMapReader;
|
import org.supercsv.io.CsvMapReader;
|
||||||
import org.supercsv.io.ICsvMapReader;
|
import org.supercsv.io.ICsvMapReader;
|
||||||
import org.supercsv.prefs.CsvPreference;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -42,7 +41,7 @@ import java.util.Map;
|
|||||||
* reads the csv file and stores the values in csv model
|
* reads the csv file and stores the values in csv model
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CSVFileReader implements FileReader {
|
public class CSVFileReader extends CSVConfigurable implements FileReader {
|
||||||
|
|
||||||
private CSVModel model;
|
private CSVModel model;
|
||||||
|
|
||||||
@@ -51,7 +50,7 @@ public class CSVFileReader implements FileReader {
|
|||||||
|
|
||||||
ICsvMapReader mapReader = null;
|
ICsvMapReader mapReader = null;
|
||||||
try {
|
try {
|
||||||
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile()), CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
|
mapReader = new CsvMapReader(new java.io.FileReader(file.getAbsoluteFile()), csvPreference);
|
||||||
model = new CSVModel(file.getAbsolutePath());
|
model = new CSVModel(file.getAbsolutePath());
|
||||||
|
|
||||||
// the header columns are used as the keys to the Map
|
// the header columns are used as the keys to the Map
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.supercsv.io.CsvMapWriter;
|
import org.supercsv.io.CsvMapWriter;
|
||||||
import org.supercsv.io.ICsvMapWriter;
|
import org.supercsv.io.ICsvMapWriter;
|
||||||
import org.supercsv.prefs.CsvPreference;
|
|
||||||
import org.supercsv.quote.AlwaysQuoteMode;
|
|
||||||
|
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -44,16 +42,12 @@ import static java.util.stream.Collectors.toMap;
|
|||||||
* filewriter for the csv
|
* filewriter for the csv
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class CSVFileWriter {
|
public class CSVFileWriter extends CSVConfigurable {
|
||||||
|
|
||||||
public void saveFile(CSVModel model) throws IOException {
|
public void saveFile(CSVModel model) throws IOException {
|
||||||
ICsvMapWriter mapWriter = null;
|
ICsvMapWriter mapWriter = null;
|
||||||
try {
|
try {
|
||||||
CsvPreference preference = new CsvPreference.
|
mapWriter = new CsvMapWriter(new FileWriter(model.getFilepath()), csvPreference);
|
||||||
Builder(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE).
|
|
||||||
useQuoteMode(new AlwaysQuoteMode())
|
|
||||||
.build();
|
|
||||||
mapWriter = new CsvMapWriter(new FileWriter(model.getFilepath()), preference);
|
|
||||||
mapWriter.writeHeader(model.getHeader());
|
mapWriter.writeHeader(model.getHeader());
|
||||||
|
|
||||||
for(CSVRow row: model.getRows()) {
|
for(CSVRow row: model.getRows()) {
|
||||||
|
|||||||
@@ -42,18 +42,23 @@ import ninja.javafx.smartcsv.csv.CSVFileReader;
|
|||||||
import ninja.javafx.smartcsv.csv.CSVFileWriter;
|
import ninja.javafx.smartcsv.csv.CSVFileWriter;
|
||||||
import ninja.javafx.smartcsv.fx.about.AboutController;
|
import ninja.javafx.smartcsv.fx.about.AboutController;
|
||||||
import ninja.javafx.smartcsv.fx.list.ValidationErrorListCell;
|
import ninja.javafx.smartcsv.fx.list.ValidationErrorListCell;
|
||||||
|
import ninja.javafx.smartcsv.fx.preferences.PreferencesController;
|
||||||
import ninja.javafx.smartcsv.fx.table.ObservableMapValueFactory;
|
import ninja.javafx.smartcsv.fx.table.ObservableMapValueFactory;
|
||||||
import ninja.javafx.smartcsv.fx.table.ValidationCellFactory;
|
import ninja.javafx.smartcsv.fx.table.ValidationCellFactory;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
import ninja.javafx.smartcsv.fx.table.model.CSVModel;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
import ninja.javafx.smartcsv.fx.table.model.CSVRow;
|
||||||
import ninja.javafx.smartcsv.fx.table.model.CSVValue;
|
import ninja.javafx.smartcsv.fx.table.model.CSVValue;
|
||||||
|
import ninja.javafx.smartcsv.preferences.PreferencesFileReader;
|
||||||
import ninja.javafx.smartcsv.validation.ValidationError;
|
import ninja.javafx.smartcsv.validation.ValidationError;
|
||||||
import ninja.javafx.smartcsv.validation.ValidationFileReader;
|
import ninja.javafx.smartcsv.validation.ValidationFileReader;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.supercsv.prefs.CsvPreference;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@@ -72,6 +77,9 @@ public class SmartCSVController extends FXMLController {
|
|||||||
// injections
|
// injections
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PreferencesFileReader preferencesLoader;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CSVFileReader csvLoader;
|
private CSVFileReader csvLoader;
|
||||||
|
|
||||||
@@ -84,6 +92,9 @@ public class SmartCSVController extends FXMLController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AboutController aboutController;
|
private AboutController aboutController;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PreferencesController preferencesController;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private BorderPane applicationPane;
|
private BorderPane applicationPane;
|
||||||
|
|
||||||
@@ -130,9 +141,12 @@ public class SmartCSVController extends FXMLController {
|
|||||||
errorList.getSelectionModel().selectedItemProperty().addListener(observable -> scrollToError());
|
errorList.getSelectionModel().selectedItemProperty().addListener(observable -> scrollToError());
|
||||||
fileChanged.addListener(observable -> setStateName());
|
fileChanged.addListener(observable -> setStateName());
|
||||||
setStateName();
|
setStateName();
|
||||||
|
initCsvPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// setter
|
// setter
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -184,6 +198,19 @@ public class SmartCSVController extends FXMLController {
|
|||||||
alert.showAndWait();
|
alert.showAndWait();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void preferences(ActionEvent actionEvent) {
|
||||||
|
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
||||||
|
alert.setTitle("Preferences");
|
||||||
|
alert.setHeaderText("Preferences");
|
||||||
|
alert.getDialogPane().setContent(preferencesController.getView());
|
||||||
|
Optional<ButtonType> result = alert.showAndWait();
|
||||||
|
|
||||||
|
if (result.get() == ButtonType.OK){
|
||||||
|
setCsvPreference(preferencesController.getCsvPreference());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canExit() {
|
public boolean canExit() {
|
||||||
boolean canExit = true;
|
boolean canExit = true;
|
||||||
if (model != null && fileChanged.get()) {
|
if (model != null && fileChanged.get()) {
|
||||||
@@ -205,6 +232,24 @@ public class SmartCSVController extends FXMLController {
|
|||||||
// private methods
|
// private methods
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private void initCsvPreferences() {
|
||||||
|
try {
|
||||||
|
File preferencesFile = new File(
|
||||||
|
getClass().getResource("/ninja/javafx/smartcsv/fx/preferences/preferences.json").toURI());
|
||||||
|
preferencesLoader.read(preferencesFile);
|
||||||
|
CsvPreference csvPreference = preferencesLoader.getCSVpreference();
|
||||||
|
setCsvPreference(csvPreference);
|
||||||
|
} catch (IOException | URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCsvPreference(CsvPreference csvPreference) {
|
||||||
|
csvLoader.setCsvPreference(csvPreference);
|
||||||
|
csvFileWriter.setCsvPreference(csvPreference);
|
||||||
|
preferencesController.setCsvPreference(csvPreference);
|
||||||
|
}
|
||||||
|
|
||||||
private void loadFile(FileReader fileReader, String filterText, String filter, String title, Label fileLabel) {
|
private void loadFile(FileReader fileReader, String filterText, String filter, String title, Label fileLabel) {
|
||||||
final FileChooser fileChooser = new FileChooser();
|
final FileChooser fileChooser = new FileChooser();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ninja.javafx.smartcsv.fx.preferences;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.CheckBox;
|
||||||
|
import javafx.scene.control.ComboBox;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import ninja.javafx.smartcsv.fx.FXMLController;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.supercsv.prefs.CsvPreference;
|
||||||
|
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import static ninja.javafx.smartcsv.preferences.QuoteModeHelper.getQuoteMode;
|
||||||
|
import static ninja.javafx.smartcsv.preferences.QuoteModeHelper.getQuoteModeName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* controller for preferences
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class PreferencesController extends FXMLController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField quoteChar;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField delimiterChar;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private CheckBox surroundingSpacesNeedQuotes;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private CheckBox ignoreEmptyLines;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private ComboBox<String> quoteMode;
|
||||||
|
|
||||||
|
private String endOfLineSymbols;
|
||||||
|
|
||||||
|
|
||||||
|
@Value("${fxml.smartcvs.preferences.view}")
|
||||||
|
@Override
|
||||||
|
public void setFxmlFilePath(String filePath) {
|
||||||
|
this.fxmlFilePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
|
quoteMode.getItems().addAll("normal", "always", "column");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCsvPreference(CsvPreference csvPreference) {
|
||||||
|
quoteChar.setText(Character.toString(csvPreference.getQuoteChar()));
|
||||||
|
delimiterChar.setText(Character.toString((char)csvPreference.getDelimiterChar()));
|
||||||
|
surroundingSpacesNeedQuotes.setSelected(csvPreference.isSurroundingSpacesNeedQuotes());
|
||||||
|
ignoreEmptyLines.setSelected(csvPreference.isIgnoreEmptyLines());
|
||||||
|
quoteMode.getSelectionModel().select(getQuoteModeName(csvPreference.getQuoteMode()));
|
||||||
|
endOfLineSymbols = csvPreference.getEndOfLineSymbols();
|
||||||
|
}
|
||||||
|
|
||||||
|
public CsvPreference getCsvPreference() {
|
||||||
|
return new CsvPreference.Builder(quoteChar.getText().charAt(0), delimiterChar.getText().charAt(0), endOfLineSymbols)
|
||||||
|
.useQuoteMode(getQuoteMode(quoteMode.getSelectionModel().getSelectedItem()))
|
||||||
|
.surroundingSpacesNeedQuotes(surroundingSpacesNeedQuotes.isSelected())
|
||||||
|
.ignoreEmptyLines(ignoreEmptyLines.isSelected())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ninja.javafx.smartcsv.preferences;
|
||||||
|
|
||||||
|
import com.typesafe.config.Config;
|
||||||
|
import com.typesafe.config.ConfigFactory;
|
||||||
|
import ninja.javafx.smartcsv.FileReader;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.supercsv.prefs.CsvPreference;
|
||||||
|
import org.supercsv.quote.AlwaysQuoteMode;
|
||||||
|
import org.supercsv.quote.ColumnQuoteMode;
|
||||||
|
import org.supercsv.quote.NormalQuoteMode;
|
||||||
|
import org.supercsv.quote.QuoteMode;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static ninja.javafx.smartcsv.preferences.QuoteModeHelper.getQuoteMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* file reader for the preferences
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class PreferencesFileReader implements FileReader {
|
||||||
|
|
||||||
|
private Config config;
|
||||||
|
private CsvPreference csvPreference;
|
||||||
|
|
||||||
|
public PreferencesFileReader() {
|
||||||
|
csvPreference = new CsvPreference.
|
||||||
|
Builder(CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE).
|
||||||
|
useQuoteMode(new AlwaysQuoteMode()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void read(File filename) throws IOException {
|
||||||
|
config = ConfigFactory.parseFile(filename);
|
||||||
|
|
||||||
|
if (config != null) {
|
||||||
|
char quoteChar = config.getString("quoteChar").charAt(0);
|
||||||
|
char delimiterChar = config.getString("delimiterChar").charAt(0);
|
||||||
|
String endOfLineSymbols = config.getString("endOfLineSymbols");
|
||||||
|
boolean surroundingSpacesNeedQuotes = config.getBoolean("surroundingSpacesNeedQuotes");
|
||||||
|
boolean ignoreEmptyLines = config.getBoolean("ignoreEmptyLines");
|
||||||
|
String quoteMode = config.getString("quoteMode");
|
||||||
|
|
||||||
|
csvPreference = new CsvPreference.Builder(quoteChar, delimiterChar, endOfLineSymbols)
|
||||||
|
.useQuoteMode(getQuoteMode(quoteMode))
|
||||||
|
.surroundingSpacesNeedQuotes(surroundingSpacesNeedQuotes)
|
||||||
|
.ignoreEmptyLines(ignoreEmptyLines)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CsvPreference getCSVpreference() {
|
||||||
|
return csvPreference;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
The MIT License (MIT)
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2015 javafx.ninja <info@javafx.ninja>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ninja.javafx.smartcsv.preferences;
|
||||||
|
|
||||||
|
import org.supercsv.quote.AlwaysQuoteMode;
|
||||||
|
import org.supercsv.quote.ColumnQuoteMode;
|
||||||
|
import org.supercsv.quote.NormalQuoteMode;
|
||||||
|
import org.supercsv.quote.QuoteMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for mapping quote quoteModeName
|
||||||
|
*/
|
||||||
|
public class QuoteModeHelper {
|
||||||
|
|
||||||
|
public static QuoteMode getQuoteMode(String quoteModeName) {
|
||||||
|
switch (quoteModeName) {
|
||||||
|
case "always": return new AlwaysQuoteMode();
|
||||||
|
case "column": return new ColumnQuoteMode();
|
||||||
|
default: return new NormalQuoteMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getQuoteModeName(QuoteMode quoteMode) {
|
||||||
|
if (quoteMode instanceof AlwaysQuoteMode) {
|
||||||
|
return "always";
|
||||||
|
} else if (quoteMode instanceof ColumnQuoteMode) {
|
||||||
|
return "column";
|
||||||
|
} else {
|
||||||
|
return "normal";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ application.version = 0.2
|
|||||||
# fxml views
|
# fxml views
|
||||||
fxml.smartcvs.view = /ninja/javafx/smartcsv/fx/smartcsv.fxml
|
fxml.smartcvs.view = /ninja/javafx/smartcsv/fx/smartcsv.fxml
|
||||||
fxml.smartcvs.about.view = /ninja/javafx/smartcsv/fx/about/about.fxml
|
fxml.smartcvs.about.view = /ninja/javafx/smartcsv/fx/about/about.fxml
|
||||||
|
fxml.smartcvs.preferences.view = /ninja/javafx/smartcsv/fx/preferences/preferences.fxml
|
||||||
|
|
||||||
# resources
|
# resources
|
||||||
resource.main = ninja.javafx.smartcsv.fx.smartcsv
|
resource.main = ninja.javafx.smartcsv.fx.smartcsv
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.*?>
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import java.lang.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
|
<GridPane hgap="8.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" vgap="8.0" xmlns="http://javafx.com/javafx/8.0.66" xmlns:fx="http://javafx.com/fxml/1">
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
|
||||||
|
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="NEVER" />
|
||||||
|
</rowConstraints>
|
||||||
|
<children>
|
||||||
|
<Label text="%preferences.quoteChar" />
|
||||||
|
<TextField fx:id="quoteChar" GridPane.columnIndex="1" />
|
||||||
|
<Label text="%preferences.delimiterChar" GridPane.rowIndex="1" />
|
||||||
|
<TextField fx:id="delimiterChar" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
|
<Label text="%preferences.surroundingSpacesNeedQuotes" GridPane.rowIndex="2" />
|
||||||
|
<CheckBox fx:id="surroundingSpacesNeedQuotes" mnemonicParsing="false" text="" GridPane.columnIndex="1" GridPane.rowIndex="2" />
|
||||||
|
<Label text="%preferences.ignoreEmptyLines" GridPane.rowIndex="3" />
|
||||||
|
<CheckBox fx:id="ignoreEmptyLines" mnemonicParsing="false" text="" GridPane.columnIndex="1" GridPane.rowIndex="3" />
|
||||||
|
<Label text="%preferences.quoteMode" GridPane.rowIndex="4" />
|
||||||
|
<ComboBox fx:id="quoteMode" prefWidth="150.0" GridPane.columnIndex="1" GridPane.rowIndex="4" />
|
||||||
|
</children>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
|
||||||
|
</padding>
|
||||||
|
</GridPane>
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"quoteChar" : "\"",
|
||||||
|
"delimiterChar" : ";",
|
||||||
|
"endOfLineSymbols" : "\n",
|
||||||
|
"surroundingSpacesNeedQuotes" : true,
|
||||||
|
"ignoreEmptyLines" : true,
|
||||||
|
"quoteMode" : "always"
|
||||||
|
}
|
||||||
@@ -44,4 +44,7 @@
|
|||||||
-glyph-size: 14px;
|
-glyph-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.preferences-icon {
|
||||||
|
-glyph-name: "COG";
|
||||||
|
-glyph-size: 14px;
|
||||||
|
}
|
||||||
|
|||||||
@@ -40,6 +40,12 @@
|
|||||||
</graphic>
|
</graphic>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<SeparatorMenuItem mnemonicParsing="false"/>
|
<SeparatorMenuItem mnemonicParsing="false"/>
|
||||||
|
<MenuItem mnemonicParsing="false" onAction="#preferences" text="%menu.preferences">
|
||||||
|
<graphic>
|
||||||
|
<FontAwesomeIconView styleClass="preferences-icon"/>
|
||||||
|
</graphic>
|
||||||
|
</MenuItem>
|
||||||
|
<SeparatorMenuItem mnemonicParsing="false"/>
|
||||||
<MenuItem mnemonicParsing="false" onAction="#close" text="%menu.close">
|
<MenuItem mnemonicParsing="false" onAction="#close" text="%menu.close">
|
||||||
<graphic>
|
<graphic>
|
||||||
<FontAwesomeIconView styleClass="exit-icon"/>
|
<FontAwesomeIconView styleClass="exit-icon"/>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ menu.about = About
|
|||||||
menu.file = File
|
menu.file = File
|
||||||
menu.edit = Edit
|
menu.edit = Edit
|
||||||
menu.help = Help
|
menu.help = Help
|
||||||
|
menu.preferences = Preferences
|
||||||
title.validation.errors = Validation Errors:
|
title.validation.errors = Validation Errors:
|
||||||
|
|
||||||
stateline.csv = CSV:
|
stateline.csv = CSV:
|
||||||
@@ -20,6 +21,12 @@ dialog.exit.title = Close Application
|
|||||||
dialog.exit.header.text = Do you want to close application?
|
dialog.exit.header.text = Do you want to close application?
|
||||||
dialog.exit.text = There are changes made to the csv file. If you close now, the changes are lost!
|
dialog.exit.text = There are changes made to the csv file. If you close now, the changes are lost!
|
||||||
|
|
||||||
|
preferences.quoteChar = Quote character:
|
||||||
|
preferences.delimiterChar = Delimiter character:
|
||||||
|
preferences.ignoreEmptyLines = Ignore empty lines:
|
||||||
|
preferences.surroundingSpacesNeedQuotes = Surrounding spaces need quotes:
|
||||||
|
preferences.quoteMode = Quote mode:
|
||||||
|
|
||||||
# validaton messages
|
# validaton messages
|
||||||
validation.message.not.empty = should not be empty
|
validation.message.not.empty = should not be empty
|
||||||
validation.message.integer = should be an integer
|
validation.message.integer = should be an integer
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ menu.about = \u00dcber ...
|
|||||||
menu.file = Datei
|
menu.file = Datei
|
||||||
menu.edit = Bearbeiten
|
menu.edit = Bearbeiten
|
||||||
menu.help = Hilfe
|
menu.help = Hilfe
|
||||||
|
menu.preferences = Einstellungen
|
||||||
title.validation.errors = Fehler in der Datei:
|
title.validation.errors = Fehler in der Datei:
|
||||||
|
|
||||||
stateline.csv = CSV:
|
stateline.csv = CSV:
|
||||||
|
|||||||
Reference in New Issue
Block a user