package com.scrivenvar.options;
import com.scrivenvar.Messages;
import com.scrivenvar.ui.AbstractPane;
import com.scrivenvar.util.Item;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
import java.util.SortedMap;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
public class GeneralOptionsPane extends AbstractPane {
@SuppressWarnings( "unchecked" )
public GeneralOptionsPane() {
initComponents();
String defaultLineSeparator = System.getProperty( "line.separator", "\n" );
String defaultLineSeparatorStr = defaultLineSeparator.replace( "\r", "CR" ).replace( "\n", "LF" );
lineSeparatorField.getItems().addAll(
new Item<>( Messages.get( "GeneralOptionsPane.platformDefault", defaultLineSeparatorStr ), null ),
new Item<>( Messages.get( "GeneralOptionsPane.sepWindows" ), "\r\n" ),
new Item<>( Messages.get( "GeneralOptionsPane.sepUnix" ), "\n" ) );
encodingField.getItems().addAll( getAvailableEncodings() );
}
private Collection<Item<String>> getAvailableEncodings() {
SortedMap<String, Charset> availableCharsets = Charset.availableCharsets();
ArrayList<Item<String>> values = new ArrayList<>( 1 + availableCharsets.size() );
values.add( new Item<>( Messages.get( "GeneralOptionsPane.platformDefault", Charset.defaultCharset().name() ), null ) );
for( String name : availableCharsets.keySet() ) {
values.add( new Item<>( name, name ) );
}
return values;
}
void load() {
lineSeparatorField.setValue( new Item<>( getOptions().getLineSeparator(), getOptions().getLineSeparator() ) );
encodingField.setValue( new Item<>( getOptions().getEncoding(), getOptions().getEncoding() ) );
}
void save() {
getOptions().setLineSeparator( lineSeparatorField.getValue().value );
getOptions().setEncoding( encodingField.getValue().value );
}
private void initComponents() {
Label lineSeparatorLabel = new Label();
lineSeparatorField = new ComboBox<>();
Label lineSeparatorLabel2 = new Label();
Label encodingLabel = new Label();
encodingField = new ComboBox<>();
setCols( "[fill][fill][fill]" );
setRows( "[][]para[]" );
lineSeparatorLabel.setText( Messages.get( "GeneralOptionsPane.lineSeparatorLabel.text" ) );
lineSeparatorLabel.setMnemonicParsing( true );
add( lineSeparatorLabel, "cell 0 0" );
add( lineSeparatorField, "cell 1 0" );
lineSeparatorLabel2.setText( Messages.get( "GeneralOptionsPane.lineSeparatorLabel2.text" ) );
add( lineSeparatorLabel2, "cell 2 0" );
encodingLabel.setText( Messages.get( "GeneralOptionsPane.encodingLabel.text" ) );
encodingLabel.setMnemonicParsing( true );
add( encodingLabel, "cell 0 1" );
encodingField.setVisibleRowCount( 20 );
add( encodingField, "cell 1 1" );
lineSeparatorLabel.setLabelFor( lineSeparatorField );
encodingLabel.setLabelFor( encodingField );
}
private ComboBox<Item<String>> lineSeparatorField;
private ComboBox<Item<String>> encodingField;
}