Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Formatting. Fixed definition selection.

Authordjarvis <email>
Date2016-11-08 23:35:36 GMT-0800
Commit0b45052192ad989847bcad78f7acfd6f00450f4c
Parentf7bb968
Delta165 lines added, 140 lines removed, 25-line increase
src/main/java/com/scrivendor/util/StageState.java
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.scrivendor.util;
* @author Karl Tauber
*/
-public class StageState
-{
- private final Stage stage;
- private final Preferences state;
+public class StageState {
- private Rectangle normalBounds;
- private boolean runLaterPending;
+ public static final String K_PANE_SPLIT_DEFINITION = "pane.split.definition";
+ public static final String K_PANE_SPLIT_EDITOR = "pane.split.editor";
- public StageState(Stage stage, Preferences state) {
- this.stage = stage;
- this.state = state;
+ private final Stage stage;
+ private final Preferences state;
- restore();
+ private Rectangle normalBounds;
+ private boolean runLaterPending;
- stage.addEventHandler(WindowEvent.WINDOW_HIDING, e -> save());
+ public StageState( Stage stage, Preferences state ) {
+ this.stage = stage;
+ this.state = state;
- stage.xProperty().addListener((ob, o, n) -> boundsChanged());
- stage.yProperty().addListener((ob, o, n) -> boundsChanged());
- stage.widthProperty().addListener((ob, o, n) -> boundsChanged());
- stage.heightProperty().addListener((ob, o, n) -> boundsChanged());
- }
+ restore();
- private void save() {
- Rectangle bounds = isNormalState() ? getStageBounds() : normalBounds;
- if (bounds != null) {
- state.putDouble("windowX", bounds.getX());
- state.putDouble("windowY", bounds.getY());
- state.putDouble("windowWidth", bounds.getWidth());
- state.putDouble("windowHeight", bounds.getHeight());
- }
- state.putBoolean("windowMaximized", stage.isMaximized());
- state.putBoolean("windowFullScreen", stage.isFullScreen());
- }
+ stage.addEventHandler( WindowEvent.WINDOW_HIDING, e -> save() );
- private void restore() {
- double x = state.getDouble("windowX", Double.NaN);
- double y = state.getDouble("windowY", Double.NaN);
- double w = state.getDouble("windowWidth", Double.NaN);
- double h = state.getDouble("windowHeight", Double.NaN);
- boolean maximized = state.getBoolean("windowMaximized", false);
- boolean fullScreen = state.getBoolean("windowFullScreen", false);
+ stage.xProperty().addListener( (ob, o, n) -> boundsChanged() );
+ stage.yProperty().addListener( (ob, o, n) -> boundsChanged() );
+ stage.widthProperty().addListener( (ob, o, n) -> boundsChanged() );
+ stage.heightProperty().addListener( (ob, o, n) -> boundsChanged() );
+ }
- if (!Double.isNaN(x) && !Double.isNaN(y)) {
- stage.setX(x);
- stage.setY(y);
- } // else: default behavior is center on screen
+ private void save() {
+ Rectangle bounds = isNormalState() ? getStageBounds() : normalBounds;
+ if( bounds != null ) {
+ state.putDouble( "windowX", bounds.getX() );
+ state.putDouble( "windowY", bounds.getY() );
+ state.putDouble( "windowWidth", bounds.getWidth() );
+ state.putDouble( "windowHeight", bounds.getHeight() );
+ }
+ state.putBoolean( "windowMaximized", stage.isMaximized() );
+ state.putBoolean( "windowFullScreen", stage.isFullScreen() );
+ }
- if (!Double.isNaN(w) && !Double.isNaN(h)) {
- stage.setWidth(w);
- stage.setHeight(h);
- } // else: default behavior is use scene size
+ private void restore() {
+ double x = state.getDouble( "windowX", Double.NaN );
+ double y = state.getDouble( "windowY", Double.NaN );
+ double w = state.getDouble( "windowWidth", Double.NaN );
+ double h = state.getDouble( "windowHeight", Double.NaN );
+ boolean maximized = state.getBoolean( "windowMaximized", false );
+ boolean fullScreen = state.getBoolean( "windowFullScreen", false );
- if (fullScreen != stage.isFullScreen())
- stage.setFullScreen(fullScreen);
- if (maximized != stage.isMaximized())
- stage.setMaximized(maximized);
- }
+ if( !Double.isNaN( x ) && !Double.isNaN( y ) ) {
+ stage.setX( x );
+ stage.setY( y );
+ } // else: default behavior is center on screen
- /**
- * Remembers the window bounds when the window
- * is not iconified, maximized or in fullScreen.
- */
- private void boundsChanged() {
- // avoid too many (and useless) runLater() invocations
- if (runLaterPending)
- return;
- runLaterPending = true;
+ if( !Double.isNaN( w ) && !Double.isNaN( h ) ) {
+ stage.setWidth( w );
+ stage.setHeight( h );
+ } // else: default behavior is use scene size
- // must use runLater() to ensure that change of all properties
- // (x, y, width, height, iconified, maximized and fullScreen)
- // has finished
- Platform.runLater(() -> {
- runLaterPending = false;
+ if( fullScreen != stage.isFullScreen() ) {
+ stage.setFullScreen( fullScreen );
+ }
+ if( maximized != stage.isMaximized() ) {
+ stage.setMaximized( maximized );
+ }
+ }
- if (isNormalState())
- normalBounds = getStageBounds();
- });
- }
+ /**
+ * Remembers the window bounds when the window is not iconified, maximized or
+ * in fullScreen.
+ */
+ private void boundsChanged() {
+ // avoid too many (and useless) runLater() invocations
+ if( runLaterPending ) {
+ return;
+ }
+ runLaterPending = true;
- private boolean isNormalState() {
- return !stage.isIconified() && !stage.isMaximized() && !stage.isFullScreen();
- }
+ // must use runLater() to ensure that change of all properties
+ // (x, y, width, height, iconified, maximized and fullScreen)
+ // has finished
+ Platform.runLater( () -> {
+ runLaterPending = false;
- private Rectangle getStageBounds() {
- return new Rectangle(stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight());
- }
+ if( isNormalState() ) {
+ normalBounds = getStageBounds();
+ }
+ } );
+ }
+
+ private boolean isNormalState() {
+ return !stage.isIconified() && !stage.isMaximized() && !stage.isFullScreen();
+ }
+
+ private Rectangle getStageBounds() {
+ return new Rectangle( stage.getX(), stage.getY(), stage.getWidth(), stage.getHeight() );
+ }
}
src/main/java/com/scrivendor/util/Utils.java
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
package com.scrivendor.util;
* @author Karl Tauber
*/
-public class Utils
-{
- public static boolean safeEquals(Object o1, Object o2) {
- if (o1 == o2)
- return true;
- if (o1 == null || o2 == null)
- return false;
- return o1.equals(o2);
- }
+public class Utils {
- public static boolean isNullOrEmpty(String s) {
- return s == null || s.isEmpty();
- }
+ public static boolean safeEquals( Object o1, Object o2 ) {
+ if( o1 == o2 ) {
+ return true;
+ }
+ if( o1 == null || o2 == null ) {
+ return false;
+ }
+ return o1.equals( o2 );
+ }
- public static String ltrim(String s) {
- int i = 0;
- while (i < s.length() && Character.isWhitespace(s.charAt(i)))
- i++;
- return s.substring(i);
- }
+ public static boolean isNullOrEmpty( String s ) {
+ return s == null || s.isEmpty();
+ }
- public static String rtrim(String s) {
- int i = s.length() - 1;
- while (i >= 0 && Character.isWhitespace(s.charAt(i)))
- i--;
- return s.substring(0, i + 1);
- }
+ public static String ltrim( final String s ) {
+ int i = 0;
- public static void putPrefs(Preferences prefs, String key, String value, String def) {
- if (value != def && !value.equals(def))
- prefs.put(key, value);
- else
- prefs.remove(key);
- }
+ while( i < s.length() && Character.isWhitespace( s.charAt( i ) ) ) {
+ i++;
+ }
- public static void putPrefsInt(Preferences prefs, String key, int value, int def) {
- if (value != def)
- prefs.putInt(key, value);
- else
- prefs.remove(key);
- }
+ return s.substring( i );
+ }
- public static void putPrefsBoolean(Preferences prefs, String key, boolean value, boolean def) {
- if (value != def)
- prefs.putBoolean(key, value);
- else
- prefs.remove(key);
- }
+ public static String rtrim( final String s ) {
+ int i = s.length() - 1;
- public static String[] getPrefsStrings(Preferences prefs, String key) {
- ArrayList<String> arr = new ArrayList<>();
- for (int i = 0; i < 10000; i++) {
- String s = prefs.get(key + (i + 1), null);
- if (s == null)
- break;
- arr.add(s);
- }
- return arr.toArray(new String[arr.size()]);
- }
+ while( i >= 0 && Character.isWhitespace( s.charAt( i ) ) ) {
+ i--;
+ }
- public static void putPrefsStrings(Preferences prefs, String key, String[] strings) {
- for (int i = 0; i < strings.length; i++)
- prefs.put(key + (i + 1), strings[i]);
+ return s.substring( 0, i + 1 );
+ }
- for (int i = strings.length; prefs.get(key + (i + 1), null) != null; i++)
- prefs.remove(key + (i + 1));
- }
+ public static void putPrefs( Preferences prefs, String key, String value, String def ) {
+ if( value != def && !value.equals( def ) ) {
+ prefs.put( key, value );
+ } else {
+ prefs.remove( key );
+ }
+ }
- public static ScrollBar findVScrollBar(Node node) {
- Set<Node> scrollBars = node.lookupAll(".scroll-bar");
- for (Node scrollBar : scrollBars) {
- if (scrollBar instanceof ScrollBar &&
- ((ScrollBar)scrollBar).getOrientation() == Orientation.VERTICAL)
- return (ScrollBar) scrollBar;
- }
- return null;
- }
+ public static void putPrefsInt( Preferences prefs, String key, int value, int def ) {
+ if( value != def ) {
+ prefs.putInt( key, value );
+ } else {
+ prefs.remove( key );
+ }
+ }
+
+ public static void putPrefsBoolean( Preferences prefs, String key, boolean value, boolean def ) {
+ if( value != def ) {
+ prefs.putBoolean( key, value );
+ } else {
+ prefs.remove( key );
+ }
+ }
+
+ public static String[] getPrefsStrings( final Preferences prefs, String key ) {
+ final ArrayList<String> arr = new ArrayList<>();
+
+ for( int i = 0; i < 10000; i++ ) {
+ final String s = prefs.get( key + (i + 1), null );
+
+ if( s == null ) {
+ break;
+ }
+ arr.add( s );
+ }
+
+ return arr.toArray( new String[ arr.size() ] );
+ }
+
+ public static void putPrefsStrings( Preferences prefs, String key, String[] strings ) {
+ for( int i = 0; i < strings.length; i++ ) {
+ prefs.put( key + (i + 1), strings[ i ] );
+ }
+
+ for( int i = strings.length; prefs.get( key + (i + 1), null ) != null; i++ ) {
+ prefs.remove( key + (i + 1) );
+ }
+ }
+
+ public static ScrollBar findVScrollBar( Node node ) {
+ final Set<Node> scrollBars = node.lookupAll( ".scroll-bar" );
+
+ for( final Node scrollBar : scrollBars ) {
+ if( scrollBar instanceof ScrollBar
+ && ((ScrollBar)scrollBar).getOrientation() == Orientation.VERTICAL ) {
+ return (ScrollBar)scrollBar;
+ }
+ }
+
+ return null;
+ }
}