package dasherJava.core.settings; import java.util.ArrayList; import java.util.List; public class Settings { public static final Settings DEFAULT_SETTINGS = new Settings(); private final int frameRate; private final String antialiasing; //"on", "default" or "off" private final String textAntialiasing; //"on", "gasp", "default" or "off" private volatile int windowX; private volatile int windowY; private volatile int windowWidth; private volatile int windowHeight; private final int spaceBehindNodes; private final String windowAlwaysOnTop; //"always", "whenExternalText" or "never" private final String windowUnfocusable; //"always", "whenExternalText" or "never" private final boolean rememberWindowPosition; private final boolean rememberWindowSize; private final boolean showStatusBar; private final String confirmExit; //"always", "whenTextEntered" or "never" private final List alphabetHistory; //first entry is the name of the currently selected alphabet private final int maxAlphabetHistoryLength; private volatile String colorPaletteNameOverride; private final String orientationOverride; private final int ppmMaxOrder; private final int ppmAlpha; private final int ppmBeta; private final int ppmUniform; private final String textOutputTarget; //"internal" or "external" private final String inputProvider; //"mouse", "globalMouse", "joystick" or "socket" private final boolean startStopOnLeftClick; private volatile float movementSpeed; private final boolean onlineLearning; private final int onlineLearningDelay; private final int maxNumberOfNodes; private final int maxNumberOfOldRootNodes; private final float minGainForNodeTrade; private final float minNodeSizeForExpansion; //unused for now private final float maxNodeSizeForCollapse; //unused for now private final float minNodeSizeForRendering; private final float minGroupSizeForRendering; private final float dropRootNodeMarginTop; private final float dropRootNodeMarginBottom; private final float dropRootNodeMarginSize; private final float zoomOutMarginTop; private final float zoomOutMarginBottom; private final float zoomOutMarginSize; private final int normalFontSize; private final int mediumFontSize; private final int highlightFontSize; private final float mediumFontSizeMarginBefore; private final float mediumFontSizeMarginAfter; private final float nodeOutlineThickness; private final float inputLineThickness; private final float crosshairThickness; private final float crosshairWidth; private final String startStopHandler; //"none", "circle" or "twoBoxes" private final float circleSize; private final float circleOutlineThickness; private final float circleOutlineThicknessHold; private final int circleHoldStartTime; private final int circleHoldStopTime; private final float firstBoxSize; private final float firstBoxLeftInset; private final float firstBoxRightInset; private final float firstBoxOutlineThickness; private final float firstBoxOutlineThicknessHold; private final int firstBoxHoldTime; private final int firstBoxResetTime; private final float secondBoxSize; private final float secondBoxLeftInset; private final float secondBoxRightInset; private final float secondBoxOutlineThickness; private final float secondBoxOutlineThicknessHold; private final int secondBoxHoldTime; private final int socketOutputPort; private final String joystickInputName; private final String joystickInputComponentNameX; private final float joystickInputSensitivityX; private final float joystickInputOffsetX; private final String joystickInputComponentNameY; private final float joystickInputSensitivityY; private final float joystickInputOffsetY; private final String joystickInputComponentNameStartStop; private final int socketInputPort; private final String socketInputLabelX; private final float socketInputMinX; private final float socketInputMaxX; private final String socketInputLabelY; private final float socketInputMinY; private final float socketInputMaxY; private final String socketInputLabelStartStop; private Settings() { //default settings frameRate=60; antialiasing="on"; textAntialiasing="on"; windowX=Integer.MIN_VALUE; windowY=Integer.MIN_VALUE; windowWidth=400; windowHeight=550; spaceBehindNodes=50; windowAlwaysOnTop="whenExternalText"; windowUnfocusable="whenExternalText"; rememberWindowPosition=true; rememberWindowSize=true; showStatusBar=true; confirmExit="whenTextEntered"; alphabetHistory=new ArrayList<>(5); maxAlphabetHistoryLength=5; colorPaletteNameOverride=""; orientationOverride=""; ppmMaxOrder=5; //PPM parameters copied from original Dasher ppmAlpha=49; ppmBeta=77; ppmUniform=50; textOutputTarget="internal"; inputProvider="mouse"; startStopOnLeftClick=true; movementSpeed=0.03f; onlineLearning=true; onlineLearningDelay=5; maxNumberOfNodes=3000; maxNumberOfOldRootNodes=100; minGainForNodeTrade=10.0f; minNodeSizeForExpansion=0.0f; //unused for now maxNodeSizeForCollapse=0.0f; //unused for now minNodeSizeForRendering=3.0f; minGroupSizeForRendering=3.0f; dropRootNodeMarginTop=10.0f; dropRootNodeMarginBottom=10.0f; dropRootNodeMarginSize=10.0f; zoomOutMarginTop=1.0f; zoomOutMarginBottom=1.0f; zoomOutMarginSize=1.0f; normalFontSize=20; mediumFontSize=26; highlightFontSize=32; mediumFontSizeMarginBefore=10.0f; mediumFontSizeMarginAfter=10.0f; nodeOutlineThickness=1.0f; inputLineThickness=1.0f; crosshairThickness=1.0f; crosshairWidth=0.12f; startStopHandler="none"; circleSize=0.14f; circleOutlineThickness=1.0f; circleOutlineThicknessHold=4.0f; circleHoldStartTime=1000; circleHoldStopTime=1000; firstBoxSize=0.5f; firstBoxLeftInset=0.1f; firstBoxRightInset=0.1f; firstBoxOutlineThickness=2.0f; firstBoxOutlineThicknessHold=5.0f; firstBoxHoldTime=1000; firstBoxResetTime=1000; secondBoxSize=0.5f; secondBoxLeftInset=0.1f; secondBoxRightInset=0.1f; secondBoxOutlineThickness=2.0f; secondBoxOutlineThicknessHold=5.0f; secondBoxHoldTime=1000; socketOutputPort=20322; joystickInputName=""; joystickInputComponentNameX="x"; joystickInputSensitivityX=1.0f; joystickInputOffsetX=0.0f; joystickInputComponentNameY="y"; joystickInputSensitivityY=1.0f; joystickInputOffsetY=0.0f; joystickInputComponentNameStartStop=""; socketInputPort=20321; //original Dasher uses port 20320 for input (but UDP instead of TCP) socketInputLabelX="x"; socketInputMinX=-32767.0f; socketInputMaxX=32767.0f; socketInputLabelY="y"; socketInputMinY=-32767.0f; socketInputMaxY=32767.0f; socketInputLabelStartStop="s"; } public Settings(int frameRate, String antialiasing, String textAntialiasing, int windowX, int windowY, int windowWidth, int windowHeight, int spaceBehindNodes, String windowAlwaysOnTop, String windowUnfocusable, boolean rememberWindowPosition, boolean rememberWindowSize, boolean showStatusBar, String confirmExit, List alphabetHistory, int maxAlphabetHistoryLength, String colorPaletteNameOverride, String orientationOverride, int ppmMaxOrder, int ppmAlpha, int ppmBeta, int ppmUniform, String textOutputTarget, String inputProvider, boolean startStopOnLeftClick, float movementSpeed, boolean onlineLearning, int onlineLearningDelay, int maxNumberOfNodes, int maxNumberOfOldRootNodes, float minGainForNodeTrade, float minNodeSizeForExpansion, float maxNodeSizeForCollapse, float minNodeSizeForRendering, float minGroupSizeForRendering, float dropRootNodeMarginTop, float dropRootNodeMarginBottom, float dropRootNodeMarginSize, float zoomOutMarginTop, float zoomOutMarginBottom, float zoomOutMarginSize, int normalFontSize, int mediumFontSize, int highlightFontSize, float mediumFontSizeMarginBefore, float mediumFontSizeMarginAfter, float nodeOutlineThickness, float inputLineThickness, float crosshairThickness, float crosshairWidth, String startStopHandler, float circleSize, float circleOutlineThickness, float circleOutlineThicknessHold, int circleHoldStartTime, int circleHoldStopTime, float firstBoxSize, float firstBoxLeftInset, float firstBoxRightInset, float firstBoxOutlineThickness, float firstBoxOutlineThicknessHold, int firstBoxHoldTime, int firstBoxResetTime, float secondBoxSize, float secondBoxLeftInset, float secondBoxRightInset, float secondBoxOutlineThickness, float secondBoxOutlineThicknessHold, int secondBoxHoldTime, int socketOutputPort, String joystickInputName, String joystickInputComponentNameX, float joystickInputSensitivityX, float joystickInputOffsetX, String joystickInputComponentNameY, float joystickInputSensitivityY, float joystickInputOffsetY, String joystickInputComponentNameStartStop, int socketInputPort, String socketInputLabelX, float socketInputMinX, float socketInputMaxX, String socketInputLabelY, float socketInputMinY, float socketInputMaxY, String socketInputLabelStartStop) { this.frameRate=frameRate; this.antialiasing=antialiasing; this.textAntialiasing=textAntialiasing; this.windowX=windowX; this.windowY=windowY; this.windowWidth=windowWidth; this.windowHeight=windowHeight; this.spaceBehindNodes=spaceBehindNodes; this.windowAlwaysOnTop=windowAlwaysOnTop; this.windowUnfocusable=windowUnfocusable; this.rememberWindowPosition=rememberWindowPosition; this.rememberWindowSize=rememberWindowSize; this.showStatusBar=showStatusBar; this.confirmExit=confirmExit; this.alphabetHistory=alphabetHistory; this.maxAlphabetHistoryLength=maxAlphabetHistoryLength; this.colorPaletteNameOverride=colorPaletteNameOverride; this.orientationOverride=orientationOverride; this.ppmMaxOrder=ppmMaxOrder; this.ppmAlpha=ppmAlpha; this.ppmBeta=ppmBeta; this.ppmUniform=ppmUniform; this.textOutputTarget=textOutputTarget; this.inputProvider=inputProvider; this.startStopOnLeftClick=startStopOnLeftClick; this.movementSpeed=movementSpeed; this.onlineLearning=onlineLearning; this.onlineLearningDelay=onlineLearningDelay; this.maxNumberOfNodes=maxNumberOfNodes; this.maxNumberOfOldRootNodes=maxNumberOfOldRootNodes; this.minGainForNodeTrade=minGainForNodeTrade; this.minNodeSizeForExpansion=minNodeSizeForExpansion; this.maxNodeSizeForCollapse=maxNodeSizeForCollapse; this.minNodeSizeForRendering=minNodeSizeForRendering; this.minGroupSizeForRendering=minGroupSizeForRendering; this.dropRootNodeMarginTop=dropRootNodeMarginTop; this.dropRootNodeMarginBottom=dropRootNodeMarginBottom; this.dropRootNodeMarginSize=dropRootNodeMarginSize; this.zoomOutMarginTop=zoomOutMarginTop; this.zoomOutMarginBottom=zoomOutMarginBottom; this.zoomOutMarginSize=zoomOutMarginSize; this.normalFontSize=normalFontSize; this.mediumFontSize=mediumFontSize; this.highlightFontSize=highlightFontSize; this.mediumFontSizeMarginBefore=mediumFontSizeMarginBefore; this.mediumFontSizeMarginAfter=mediumFontSizeMarginAfter; this.nodeOutlineThickness=nodeOutlineThickness; this.inputLineThickness=inputLineThickness; this.crosshairThickness=crosshairThickness; this.crosshairWidth=crosshairWidth; this.startStopHandler=startStopHandler; this.circleSize=circleSize; this.circleOutlineThickness=circleOutlineThickness; this.circleOutlineThicknessHold=circleOutlineThicknessHold; this.circleHoldStartTime=circleHoldStartTime; this.circleHoldStopTime=circleHoldStopTime; this.firstBoxSize=firstBoxSize; this.firstBoxLeftInset=firstBoxLeftInset; this.firstBoxRightInset=firstBoxRightInset; this.firstBoxOutlineThickness=firstBoxOutlineThickness; this.firstBoxOutlineThicknessHold=firstBoxOutlineThicknessHold; this.firstBoxHoldTime=firstBoxHoldTime; this.firstBoxResetTime=firstBoxResetTime; this.secondBoxSize=secondBoxSize; this.secondBoxLeftInset=secondBoxLeftInset; this.secondBoxRightInset=secondBoxRightInset; this.secondBoxOutlineThickness=secondBoxOutlineThickness; this.secondBoxOutlineThicknessHold=secondBoxOutlineThicknessHold; this.secondBoxHoldTime=secondBoxHoldTime; this.socketOutputPort=socketOutputPort; this.joystickInputName=joystickInputName; this.joystickInputComponentNameX=joystickInputComponentNameX; this.joystickInputSensitivityX=joystickInputSensitivityX; this.joystickInputOffsetX=joystickInputOffsetX; this.joystickInputComponentNameY=joystickInputComponentNameY; this.joystickInputSensitivityY=joystickInputSensitivityY; this.joystickInputOffsetY=joystickInputOffsetY; this.joystickInputComponentNameStartStop=joystickInputComponentNameStartStop; this.socketInputPort=socketInputPort; this.socketInputLabelX=socketInputLabelX; this.socketInputMinX=socketInputMinX; this.socketInputMaxX=socketInputMaxX; this.socketInputLabelY=socketInputLabelY; this.socketInputMinY=socketInputMinY; this.socketInputMaxY=socketInputMaxY; this.socketInputLabelStartStop=socketInputLabelStartStop; } public int getFrameRate() { return frameRate; } public String getAntialiasing() { return antialiasing; } public String getTextAntialiasing() { return textAntialiasing; } public int getWindowX() { return windowX; } public void setWindowX(int windowX) { this.windowX=windowX; } public int getWindowY() { return windowY; } public void setWindowY(int windowY) { this.windowY=windowY; } public int getWindowWidth() { return windowWidth; } public void setWindowWidth(int windowWidth) { this.windowWidth=windowWidth; } public int getWindowHeight() { return windowHeight; } public void setWindowHeight(int windowHeight) { this.windowHeight=windowHeight; } public int getSpaceBehindNodes() { return spaceBehindNodes; } public String getWindowAlwaysOnTop() { return windowAlwaysOnTop; } public String getWindowUnfocusable() { return windowUnfocusable; } public boolean getRememberWindowPosition() { return rememberWindowPosition; } public boolean getRememberWindowSize() { return rememberWindowSize; } public boolean getShowStatusBar() { return showStatusBar; } public String getConfirmExit() { return confirmExit; } public String getAlphabetName() { return alphabetHistory.isEmpty() ? "" : alphabetHistory.get(0); } public List getAlphabetHistory() { return alphabetHistory; } public int getMaxAlphabetHistoryLength() { return maxAlphabetHistoryLength; } public String getColorPaletteNameOverride() { return colorPaletteNameOverride; } public void setColorPaletteNameOverride(String colorPaletteNameOverride) { this.colorPaletteNameOverride=colorPaletteNameOverride; } public String getOrientationOverride() { return orientationOverride; } public int getPPMMaxOrder() { return ppmMaxOrder; } public int getPPMAlpha() { return ppmAlpha; } public int getPPMBeta() { return ppmBeta; } public int getPPMUniform() { return ppmUniform; } public String getTextOutputTarget() { return textOutputTarget; } public String getInputProvider() { return inputProvider; } public boolean getStartStopOnLeftClick() { return startStopOnLeftClick; } public float getMovementSpeed() { return movementSpeed; } public void setMovementSpeed(float movementSpeed) { this.movementSpeed=movementSpeed; } public boolean getOnlineLearning() { return onlineLearning; } public int getOnlineLearningDelay() { return onlineLearningDelay; } public int getMaxNumberOfNodes() { return maxNumberOfNodes; } public int getMaxNumberOfOldRootNodes() { return maxNumberOfOldRootNodes; } public float getMinGainForNodeTrade() { return minGainForNodeTrade; } public float getMinNodeSizeForExpansion() { return minNodeSizeForExpansion; } public float getMaxNodeSizeForCollapse() { return maxNodeSizeForCollapse; } public float getMinNodeSizeForRendering() { return minNodeSizeForRendering; } public float getMinGroupSizeForRendering() { return minGroupSizeForRendering; } public float getDropRootNodeMarginTop() { return dropRootNodeMarginTop; } public float getDropRootNodeMarginBottom() { return dropRootNodeMarginBottom; } public float getDropRootNodeMarginSize() { return dropRootNodeMarginSize; } public float getZoomOutMarginTop() { return zoomOutMarginTop; } public float getZoomOutMarginBottom() { return zoomOutMarginBottom; } public float getZoomOutMarginSize() { return zoomOutMarginSize; } public int getNormalFontSize() { return normalFontSize; } public int getMediumFontSize() { return mediumFontSize; } public int getHighlightFontSize() { return highlightFontSize; } public float getMediumFontSizeMarginBefore() { return mediumFontSizeMarginBefore; } public float getMediumFontSizeMarginAfter() { return mediumFontSizeMarginAfter; } public float getNodeOutlineThickness() { return nodeOutlineThickness; } public float getInputLineThickness() { return inputLineThickness; } public float getCrosshairThickness() { return crosshairThickness; } public float getCrosshairWidth() { return crosshairWidth; } public String getStartStopHandler() { return startStopHandler; } public float getCircleSize() { return circleSize; } public float getCircleOutlineThickness() { return circleOutlineThickness; } public float getCircleOutlineThicknessHold() { return circleOutlineThicknessHold; } public int getCircleHoldStartTime() { return circleHoldStartTime; } public int getCircleHoldStopTime() { return circleHoldStopTime; } public float getFirstBoxSize() { return firstBoxSize; } public float getFirstBoxLeftInset() { return firstBoxLeftInset; } public float getFirstBoxRightInset() { return firstBoxRightInset; } public float getFirstBoxOutlineThickness() { return firstBoxOutlineThickness; } public float getFirstBoxOutlineThicknessHold() { return firstBoxOutlineThicknessHold; } public int getFirstBoxHoldTime() { return firstBoxHoldTime; } public int getFirstBoxResetTime() { return firstBoxResetTime; } public float getSecondBoxSize() { return secondBoxSize; } public float getSecondBoxLeftInset() { return secondBoxLeftInset; } public float getSecondBoxRightInset() { return secondBoxRightInset; } public float getSecondBoxOutlineThickness() { return secondBoxOutlineThickness; } public float getSecondBoxOutlineThicknessHold() { return secondBoxOutlineThicknessHold; } public int getSecondBoxHoldTime() { return secondBoxHoldTime; } public int getSocketOutputPort() { return socketOutputPort; } public String getJoystickInputName() { return joystickInputName; } public String getJoystickInputComponentNameX() { return joystickInputComponentNameX; } public float getJoystickInputSensitivityX() { return joystickInputSensitivityX; } public float getJoystickInputOffsetX() { return joystickInputOffsetX; } public String getJoystickInputComponentNameY() { return joystickInputComponentNameY; } public float getJoystickInputSensitivityY() { return joystickInputSensitivityY; } public float getJoystickInputOffsetY() { return joystickInputOffsetY; } public String getJoystickInputComponentNameStartStop() { return joystickInputComponentNameStartStop; } public int getSocketInputPort() { return socketInputPort; } public String getSocketInputLabelX() { return socketInputLabelX; } public float getSocketInputMinX() { return socketInputMinX; } public float getSocketInputMaxX() { return socketInputMaxX; } public String getSocketInputLabelY() { return socketInputLabelY; } public float getSocketInputMinY() { return socketInputMinY; } public float getSocketInputMaxY() { return socketInputMaxY; } public String getSocketInputLabelStartStop() { return socketInputLabelStartStop; } public void insertIntoAlphabetHistory(String newAlphabetName) { if (!alphabetHistory.isEmpty() && alphabetHistory.get(0).isEmpty()) alphabetHistory.remove(0); //if the first //entry of the list is empty (no alphabet selected), remove that empty entry alphabetHistory.remove(newAlphabetName); while (alphabetHistory.size()>=maxAlphabetHistoryLength) alphabetHistory.remove(alphabetHistory.size()-1); alphabetHistory.add(0, newAlphabetName); } public int getWindowXResult() { return rememberWindowPosition ? windowX : DEFAULT_SETTINGS.windowX; } public int getWindowYResult() { return rememberWindowPosition ? windowY : DEFAULT_SETTINGS.windowY; } public int getWindowWidthResult() { return rememberWindowSize ? windowWidth : DEFAULT_SETTINGS.windowWidth; } public int getWindowHeightResult() { return rememberWindowSize ? windowHeight : DEFAULT_SETTINGS.windowHeight; } public boolean getWindowAlwaysOnTopResult() { return windowAlwaysOnTop.equals("always") || windowAlwaysOnTop.equals("whenExternalText") && textOutputTarget.equals("external"); } public boolean getWindowUnfocusableResult() { return windowUnfocusable.equals("always") || windowUnfocusable.equals("whenExternalText") && textOutputTarget.equals("external"); } }