├── .gitignore
├── .mvn
└── wrapper
│ ├── maven-wrapper.jar
│ └── maven-wrapper.properties
├── .travis.yml
├── LICENSE
├── README.md
├── mvnw
├── pom.xml
├── readme
├── color-color.png
├── color-context.png
├── color-derive.png
├── color-lineargradient.png
├── font.png
├── highlight.png
├── key.png
├── shape-svg.png
├── suggest-common.png
├── suggest-current-id.png
└── suggest-key.png
└── src
└── main
├── java
└── xdean
│ └── css
│ └── editor
│ ├── FxCssApplication.java
│ ├── FxCssEntrance.java
│ ├── context
│ ├── Config.java
│ ├── Context.java
│ └── setting
│ │ ├── DefaultValue.java
│ │ ├── EditActions.java
│ │ ├── FileActions.java
│ │ ├── HelpActions.java
│ │ ├── OptionBindProcessor.java
│ │ ├── OtherSettings.java
│ │ ├── PreferenceSettings.java
│ │ ├── RawSettingKeys.java
│ │ ├── SettingKeys.java
│ │ └── model
│ │ ├── CssEditorActionKeyOption.java
│ │ ├── CssEditorKeyOption.java
│ │ └── option
│ │ ├── BooleanOption.java
│ │ ├── ConstraintOption.java
│ │ ├── IntegerOption.java
│ │ ├── Option.java
│ │ ├── OptionGroup.java
│ │ ├── RangeOption.java
│ │ ├── SimpleConstraintOption.java
│ │ ├── SimpleOption.java
│ │ ├── StringOption.java
│ │ └── ValueOption.java
│ ├── control
│ ├── CssEditor.java
│ └── CssEditorEvent.java
│ ├── controller
│ ├── CssEditorTab.java
│ ├── MainFrameController.java
│ ├── MainFrameModel.java
│ ├── MenuBarController.java
│ ├── OptionsController.java
│ ├── SearchBarController.java
│ ├── StatusBarController.java
│ └── ToolBarController.java
│ ├── feature
│ ├── CommentFeature.java
│ ├── CssAppFeature.java
│ ├── CssEditorFeature.java
│ ├── HighLightFeature.java
│ ├── LastFileFeature.java
│ ├── PreviewFeature.java
│ ├── SuggestionFeature.java
│ ├── highlight
│ │ ├── CssHighLight.java
│ │ ├── CssHighLightConfig.java
│ │ ├── RegexHighLight.java
│ │ └── SimpleHighLight.java
│ ├── preview
│ │ ├── BorderPreviewer.java
│ │ ├── CssElementPreviewer.java
│ │ ├── PaintPreviewer.java
│ │ └── SvgPreviewer.java
│ └── suggestion
│ │ ├── CssSuggestionConfig.java
│ │ ├── CssSuggestionFilter.java
│ │ ├── CssSuggestionService.java
│ │ ├── CssSuggestionsFilter.java
│ │ ├── RegexSuggestion.java
│ │ └── SimpleSuggestion.java
│ ├── model
│ ├── CssContext.java
│ ├── FileWrapper.java
│ ├── FunctionParsedValue.java
│ └── SimpleParsedValue.java
│ └── service
│ ├── ContextService.java
│ ├── DialogService.java
│ ├── MessageService.java
│ ├── RecentFileService.java
│ └── SkinService.java
└── resources
├── application.properties
├── css
├── css-highlighting.css
├── global.css
└── skin
│ ├── classic.css
│ ├── default.css
│ ├── metal.css
│ └── pink.css
├── fontawesome.ttf
├── fxml
├── MainFrame.fxgraph
├── MainFrame.fxml
├── MenuBar.fxgraph
├── MenuBar.fxml
├── Options.fxgraph
├── Options.fxml
├── SearchBar.fxgraph
├── SearchBar.fxml
├── StatusBar.fxgraph
├── StatusBar.fxml
├── ToolBar.fxgraph
└── ToolBar.fxml
├── image
└── icon.jpg
├── logback.xml
└── message
└── settings.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | hs_err_pid*
4 |
5 | ### Eclipse ###
6 | .settings/
7 | target/
8 | bin/
9 | .classpath
10 | .project
11 | .factorypath
12 | .apt_generated
13 | .springBeans
14 | rebel.xml
15 | /javadoc/
16 |
17 | !.mvn/wrapper/maven-wrapper.jar
18 | !**/src/main/**/target/
19 | !**/src/test/**/target/
20 |
21 | ### IntelliJ IDEA ###
22 | .idea
23 | *.iws
24 | *.iml
25 | *.ipr
26 |
27 | ### NetBeans ###
28 | nbproject/private/
29 | build/
30 | nbbuild/
31 | dist/
32 | nbdist/
33 | .nb-gradle/
34 |
35 | ### other ###
36 | .svn/
37 | .*.md.html
38 | dependency-reduced-pom.xml
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/.mvn/wrapper/maven-wrapper.jar
--------------------------------------------------------------------------------
/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
2 | wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
3 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | sudo: false
2 | language: java
3 | dist: trusty
4 | cache:
5 | directories:
6 | - $HOME/.m2
7 | jdk:
8 | - oraclejdk8
9 | install: true
10 | addons:
11 | sonarcloud:
12 | organization: xdean-github
13 | script:
14 | - mvn clean package sonar:sonar -P jacoco
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CSS Editor FX #
2 |
3 | A CSS editor written in JavaFX 8
4 |
5 | **This is a study project in 2017. Not maintain now.**
6 |
7 | **Hope it inspires you about using Spring Boot + JavaFX together**
8 |
9 | ## Features ##
10 | - [Code Highlight](#code-highlight)
11 | - [Code Assist](#code-assist)
12 | - [JavaFX Context](#javafx-context)
13 | - [Current Context](#current-context)
14 | - *[Specify Context](#specify-context)*
15 | - [Preview](#preview)
16 | - [Color](#color)
17 | - [RGB](#rgb)
18 | - [Color Function](#function)
19 | - [Gradient](#gradient)
20 | - *[Context Color Paser](#context-color-paser)*
21 | - [Shape](#shape)
22 | - [Other Text Editor Common Features](#other)
23 | - *[Code Format](#code-format)*
24 | - [Toggle Comment](#toggle-comment)
25 | - [Custom Font](#custom-font)
26 | - [Custom Shortcut](#custom-shortcut)
27 | - [Known Bugs](#known-bugs)
28 |
29 | ## Code Highlight ##
30 | 
31 |
32 | ## Code Assist ##
33 | ### JavaFX Context ###
34 | 
35 | ### Current Context ###
36 | 
37 | ### Specify Context ###
38 | *Not implement yet*
39 |
40 | ## Preview ##
41 | ### Color ###
42 | #### RGB ####
43 | 
44 | #### Function ####
45 | 
46 | #### Gradient ####
47 | 
48 | #### Context Color Paser ####
49 | 
50 | ### Shape ###
51 | 
52 |
53 | ## Other ##
54 | ### Code Format ###
55 | *Not implement yet*
56 | ### Toggle Comment ###
57 |
58 | ### Custom Font ###
59 | 
60 | ### Custom Shortcut ###
61 | 
62 |
63 | ## Known Bugs ##
64 | - richtextfx codeArea undo leads IllegalArgumentException when merge changes. See [https://github.com/TomasMikula/RichTextFX/pull/402](https://github.com/TomasMikula/RichTextFX/pull/402 "github"), it may resolve soon.
65 | - close tab will not correctly refresh currentTab property. It lead tab color and scrollbars still.
--------------------------------------------------------------------------------
/mvnw:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # ----------------------------------------------------------------------------
3 | # Licensed to the Apache Software Foundation (ASF) under one
4 | # or more contributor license agreements. See the NOTICE file
5 | # distributed with this work for additional information
6 | # regarding copyright ownership. The ASF licenses this file
7 | # to you under the Apache License, Version 2.0 (the
8 | # "License"); you may not use this file except in compliance
9 | # with the License. You may obtain a copy of the License at
10 | #
11 | # https://www.apache.org/licenses/LICENSE-2.0
12 | #
13 | # Unless required by applicable law or agreed to in writing,
14 | # software distributed under the License is distributed on an
15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | # KIND, either express or implied. See the License for the
17 | # specific language governing permissions and limitations
18 | # under the License.
19 | # ----------------------------------------------------------------------------
20 |
21 | # ----------------------------------------------------------------------------
22 | # Maven Start Up Batch script
23 | #
24 | # Required ENV vars:
25 | # ------------------
26 | # JAVA_HOME - location of a JDK home dir
27 | #
28 | # Optional ENV vars
29 | # -----------------
30 | # M2_HOME - location of maven2's installed home dir
31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven
32 | # e.g. to debug Maven itself, use
33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000
34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files
35 | # ----------------------------------------------------------------------------
36 |
37 | if [ -z "$MAVEN_SKIP_RC" ] ; then
38 |
39 | if [ -f /usr/local/etc/mavenrc ] ; then
40 | . /usr/local/etc/mavenrc
41 | fi
42 |
43 | if [ -f /etc/mavenrc ] ; then
44 | . /etc/mavenrc
45 | fi
46 |
47 | if [ -f "$HOME/.mavenrc" ] ; then
48 | . "$HOME/.mavenrc"
49 | fi
50 |
51 | fi
52 |
53 | # OS specific support. $var _must_ be set to either true or false.
54 | cygwin=false;
55 | darwin=false;
56 | mingw=false
57 | case "`uname`" in
58 | CYGWIN*) cygwin=true ;;
59 | MINGW*) mingw=true;;
60 | Darwin*) darwin=true
61 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home
62 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html
63 | if [ -z "$JAVA_HOME" ]; then
64 | if [ -x "/usr/libexec/java_home" ]; then
65 | export JAVA_HOME="`/usr/libexec/java_home`"
66 | else
67 | export JAVA_HOME="/Library/Java/Home"
68 | fi
69 | fi
70 | ;;
71 | esac
72 |
73 | if [ -z "$JAVA_HOME" ] ; then
74 | if [ -r /etc/gentoo-release ] ; then
75 | JAVA_HOME=`java-config --jre-home`
76 | fi
77 | fi
78 |
79 | if [ -z "$M2_HOME" ] ; then
80 | ## resolve links - $0 may be a link to maven's home
81 | PRG="$0"
82 |
83 | # need this for relative symlinks
84 | while [ -h "$PRG" ] ; do
85 | ls=`ls -ld "$PRG"`
86 | link=`expr "$ls" : '.*-> \(.*\)$'`
87 | if expr "$link" : '/.*' > /dev/null; then
88 | PRG="$link"
89 | else
90 | PRG="`dirname "$PRG"`/$link"
91 | fi
92 | done
93 |
94 | saveddir=`pwd`
95 |
96 | M2_HOME=`dirname "$PRG"`/..
97 |
98 | # make it fully qualified
99 | M2_HOME=`cd "$M2_HOME" && pwd`
100 |
101 | cd "$saveddir"
102 | # echo Using m2 at $M2_HOME
103 | fi
104 |
105 | # For Cygwin, ensure paths are in UNIX format before anything is touched
106 | if $cygwin ; then
107 | [ -n "$M2_HOME" ] &&
108 | M2_HOME=`cygpath --unix "$M2_HOME"`
109 | [ -n "$JAVA_HOME" ] &&
110 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
111 | [ -n "$CLASSPATH" ] &&
112 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"`
113 | fi
114 |
115 | # For Mingw, ensure paths are in UNIX format before anything is touched
116 | if $mingw ; then
117 | [ -n "$M2_HOME" ] &&
118 | M2_HOME="`(cd "$M2_HOME"; pwd)`"
119 | [ -n "$JAVA_HOME" ] &&
120 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`"
121 | fi
122 |
123 | if [ -z "$JAVA_HOME" ]; then
124 | javaExecutable="`which javac`"
125 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then
126 | # readlink(1) is not available as standard on Solaris 10.
127 | readLink=`which readlink`
128 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then
129 | if $darwin ; then
130 | javaHome="`dirname \"$javaExecutable\"`"
131 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac"
132 | else
133 | javaExecutable="`readlink -f \"$javaExecutable\"`"
134 | fi
135 | javaHome="`dirname \"$javaExecutable\"`"
136 | javaHome=`expr "$javaHome" : '\(.*\)/bin'`
137 | JAVA_HOME="$javaHome"
138 | export JAVA_HOME
139 | fi
140 | fi
141 | fi
142 |
143 | if [ -z "$JAVACMD" ] ; then
144 | if [ -n "$JAVA_HOME" ] ; then
145 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
146 | # IBM's JDK on AIX uses strange locations for the executables
147 | JAVACMD="$JAVA_HOME/jre/sh/java"
148 | else
149 | JAVACMD="$JAVA_HOME/bin/java"
150 | fi
151 | else
152 | JAVACMD="`\\unset -f command; \\command -v java`"
153 | fi
154 | fi
155 |
156 | if [ ! -x "$JAVACMD" ] ; then
157 | echo "Error: JAVA_HOME is not defined correctly." >&2
158 | echo " We cannot execute $JAVACMD" >&2
159 | exit 1
160 | fi
161 |
162 | if [ -z "$JAVA_HOME" ] ; then
163 | echo "Warning: JAVA_HOME environment variable is not set."
164 | fi
165 |
166 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher
167 |
168 | # traverses directory structure from process work directory to filesystem root
169 | # first directory with .mvn subdirectory is considered project base directory
170 | find_maven_basedir() {
171 |
172 | if [ -z "$1" ]
173 | then
174 | echo "Path not specified to find_maven_basedir"
175 | return 1
176 | fi
177 |
178 | basedir="$1"
179 | wdir="$1"
180 | while [ "$wdir" != '/' ] ; do
181 | if [ -d "$wdir"/.mvn ] ; then
182 | basedir=$wdir
183 | break
184 | fi
185 | # workaround for JBEAP-8937 (on Solaris 10/Sparc)
186 | if [ -d "${wdir}" ]; then
187 | wdir=`cd "$wdir/.."; pwd`
188 | fi
189 | # end of workaround
190 | done
191 | echo "${basedir}"
192 | }
193 |
194 | # concatenates all lines of a file
195 | concat_lines() {
196 | if [ -f "$1" ]; then
197 | echo "$(tr -s '\n' ' ' < "$1")"
198 | fi
199 | }
200 |
201 | BASE_DIR=`find_maven_basedir "$(pwd)"`
202 | if [ -z "$BASE_DIR" ]; then
203 | exit 1;
204 | fi
205 |
206 | ##########################################################################################
207 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central
208 | # This allows using the maven wrapper in projects that prohibit checking in binary data.
209 | ##########################################################################################
210 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then
211 | if [ "$MVNW_VERBOSE" = true ]; then
212 | echo "Found .mvn/wrapper/maven-wrapper.jar"
213 | fi
214 | else
215 | if [ "$MVNW_VERBOSE" = true ]; then
216 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..."
217 | fi
218 | if [ -n "$MVNW_REPOURL" ]; then
219 | jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
220 | else
221 | jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar"
222 | fi
223 | while IFS="=" read key value; do
224 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;;
225 | esac
226 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties"
227 | if [ "$MVNW_VERBOSE" = true ]; then
228 | echo "Downloading from: $jarUrl"
229 | fi
230 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar"
231 | if $cygwin; then
232 | wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"`
233 | fi
234 |
235 | if command -v wget > /dev/null; then
236 | if [ "$MVNW_VERBOSE" = true ]; then
237 | echo "Found wget ... using wget"
238 | fi
239 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
240 | wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
241 | else
242 | wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath"
243 | fi
244 | elif command -v curl > /dev/null; then
245 | if [ "$MVNW_VERBOSE" = true ]; then
246 | echo "Found curl ... using curl"
247 | fi
248 | if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then
249 | curl -o "$wrapperJarPath" "$jarUrl" -f
250 | else
251 | curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f
252 | fi
253 |
254 | else
255 | if [ "$MVNW_VERBOSE" = true ]; then
256 | echo "Falling back to using Java to download"
257 | fi
258 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java"
259 | # For Cygwin, switch paths to Windows format before running javac
260 | if $cygwin; then
261 | javaClass=`cygpath --path --windows "$javaClass"`
262 | fi
263 | if [ -e "$javaClass" ]; then
264 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
265 | if [ "$MVNW_VERBOSE" = true ]; then
266 | echo " - Compiling MavenWrapperDownloader.java ..."
267 | fi
268 | # Compiling the Java class
269 | ("$JAVA_HOME/bin/javac" "$javaClass")
270 | fi
271 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then
272 | # Running the downloader
273 | if [ "$MVNW_VERBOSE" = true ]; then
274 | echo " - Running MavenWrapperDownloader.java ..."
275 | fi
276 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR")
277 | fi
278 | fi
279 | fi
280 | fi
281 | ##########################################################################################
282 | # End of extension
283 | ##########################################################################################
284 |
285 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}
286 | if [ "$MVNW_VERBOSE" = true ]; then
287 | echo $MAVEN_PROJECTBASEDIR
288 | fi
289 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS"
290 |
291 | # For Cygwin, switch paths to Windows format before running java
292 | if $cygwin; then
293 | [ -n "$M2_HOME" ] &&
294 | M2_HOME=`cygpath --path --windows "$M2_HOME"`
295 | [ -n "$JAVA_HOME" ] &&
296 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
297 | [ -n "$CLASSPATH" ] &&
298 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
299 | [ -n "$MAVEN_PROJECTBASEDIR" ] &&
300 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"`
301 | fi
302 |
303 | # Provide a "standardized" way to retrieve the CLI args that will
304 | # work with both Windows and non-Windows executions.
305 | MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@"
306 | export MAVEN_CMD_LINE_ARGS
307 |
308 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain
309 |
310 | exec "$JAVACMD" \
311 | $MAVEN_OPTS \
312 | $MAVEN_DEBUG_OPTS \
313 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \
314 | "-Dmaven.home=${M2_HOME}" \
315 | "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \
316 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@"
317 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 |
5 | com.github.XDean
6 | oss-parent
7 | 1.1
8 |
9 | JavaFX-CSS-Editor
10 | 0.0.1-SNAPSHOT
11 |
12 |
13 |
14 |
15 | io.reactivex.rxjava2
16 | rxjava
17 | 2.1.13
18 |
19 |
20 |
21 |
22 |
23 |
24 | com.github.XDean
25 | auto-message
26 | 0.1.6
27 | provided
28 |
29 |
30 | com.github.XDean
31 | auto-spring-factories
32 | 0.1.2
33 | provided
34 |
35 |
36 | com.github.XDean
37 | javafx-spring-boot
38 | 0.1-SNAPSHOT
39 |
40 |
41 | com.github.XDean
42 | rx2-nullable
43 | 1.0
44 |
45 |
46 | ch.qos.logback
47 | logback-classic
48 | 1.1.3
49 |
50 |
51 | ch.qos.logback
52 | logback-core
53 | 1.1.3
54 |
55 |
56 | org.slf4j
57 | slf4j-api
58 | 1.7.5
59 |
60 |
61 | junit
62 | junit
63 | 4.11
64 |
65 |
66 | io.reactivex.rxjava2
67 | rxjavafx
68 | 2.2.2
69 |
70 |
71 | org.controlsfx
72 | controlsfx
73 | 8.40.12
74 |
75 |
76 | org.fxmisc.richtext
77 | richtextfx
78 | 0.7-M2
79 |
80 |
81 | com.github.XDean
82 | JavaFX-EX
83 | 0.1.0-SNAPSHOT
84 |
85 |
86 |
87 |
88 |
89 |
90 | org.apache.maven.plugins
91 | maven-compiler-plugin
92 | 3.1
93 |
94 |
95 | ${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar
96 |
97 |
98 |
99 |
100 | org.springframework.boot
101 | spring-boot-maven-plugin
102 | 2.2.7.RELEASE
103 |
104 | true
105 |
106 |
107 |
108 |
109 | repackage
110 |
111 |
112 |
113 |
114 |
115 |
116 |
--------------------------------------------------------------------------------
/readme/color-color.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/color-color.png
--------------------------------------------------------------------------------
/readme/color-context.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/color-context.png
--------------------------------------------------------------------------------
/readme/color-derive.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/color-derive.png
--------------------------------------------------------------------------------
/readme/color-lineargradient.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/color-lineargradient.png
--------------------------------------------------------------------------------
/readme/font.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/font.png
--------------------------------------------------------------------------------
/readme/highlight.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/highlight.png
--------------------------------------------------------------------------------
/readme/key.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/key.png
--------------------------------------------------------------------------------
/readme/shape-svg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/shape-svg.png
--------------------------------------------------------------------------------
/readme/suggest-common.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/suggest-common.png
--------------------------------------------------------------------------------
/readme/suggest-current-id.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/suggest-current-id.png
--------------------------------------------------------------------------------
/readme/suggest-key.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/XDean/CSS-Editor-FX/9fb891b71fdfa46b675a4d1d31eb694795d2c586/readme/suggest-key.png
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/FxCssApplication.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor;
2 |
3 | import static xdean.jfxex.bean.BeanUtil.map;
4 | import static xdean.jfxex.event.EventHandlers.consume;
5 |
6 | import java.util.Collections;
7 | import java.util.List;
8 |
9 | import javax.inject.Inject;
10 | import javax.inject.Named;
11 |
12 | import org.springframework.stereotype.Component;
13 |
14 | import javafx.beans.property.ObjectProperty;
15 | import javafx.collections.FXCollections;
16 | import javafx.collections.ObservableList;
17 | import javafx.scene.Parent;
18 | import javafx.scene.Scene;
19 | import javafx.scene.image.Image;
20 | import javafx.stage.Stage;
21 | import xdean.css.editor.context.setting.FileActions;
22 | import xdean.css.editor.control.CssEditor;
23 | import xdean.css.editor.controller.MainFrameController;
24 | import xdean.css.editor.feature.CssAppFeature;
25 | import xdean.css.editor.service.ContextService;
26 | import xdean.css.editor.service.SkinService;
27 | import xdean.jfx.spring.FxApplication;
28 | import xdean.jfx.spring.FxmlResult;
29 | import xdean.jfx.spring.context.FxContext;
30 | import xdean.jfxex.bean.annotation.CheckNull;
31 | import xdean.jfxex.bean.property.ObjectPropertyEX;
32 |
33 | @Component
34 | public class FxCssApplication implements FxApplication, ContextService {
35 |
36 | private @Inject FxmlResult mainFrame;
37 | private @Inject SkinService skinService;
38 | private @Inject FileActions fileActions;
39 | private @Inject List features = Collections.emptyList();
40 |
41 | private final Stage stage;
42 | private final ObservableList editors = FXCollections.observableArrayList();
43 | private final ObjectPropertyEX<@CheckNull CssEditor> activeEditor = new ObjectPropertyEX(this, "editor")
44 | .in(editors, false);
45 |
46 | @Inject
47 | public FxCssApplication(@Named(FxContext.FX_PRIMARY_STAGE) Stage stage) {
48 | this.stage = stage;
49 | activeEditor.addListener((ob, o, n) -> {
50 | if (o != null) {
51 | o.activeProperty().set(false);
52 | }
53 | if (n != null) {
54 | n.activeProperty().set(true);
55 | }
56 | });
57 | }
58 |
59 | @Override
60 | public void start(Stage stage) throws Exception {
61 | Scene scene = skinService.bind(new Scene(mainFrame.getRoot()));
62 | scene.getStylesheets().add("/css/global.css");
63 | stage.setScene(scene);
64 |
65 | features.forEach(f -> f.bind(stage));
66 |
67 | stage.titleProperty()
68 | .bind(map(activeEditorProperty(), e -> (e == null ? "" : e.fileProperty().get().getFileName()) + " - CSS Editor FX"));
69 | stage.setOnCloseRequest(consume(e -> fire(fileActions.exit())));
70 | stage.setMaximized(true);
71 | stage.show();
72 |
73 | stage.getIcons().add(new Image(FxCssApplication.class.getClassLoader().getResourceAsStream("image/icon.jpg")));
74 | }
75 |
76 | @Override
77 | public ObservableList editorList() {
78 | return editors;
79 | }
80 |
81 | @Override
82 | public ObjectProperty<@CheckNull CssEditor> activeEditorProperty() {
83 | return activeEditor;
84 | }
85 |
86 | @Override
87 | public Stage stage() {
88 | return stage;
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/FxCssEntrance.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor;
2 |
3 | import org.springframework.boot.SpringApplication;
4 |
5 | import xdean.jfx.spring.annotation.Splash;
6 | import xdean.jfx.spring.annotation.SpringFxApplication;
7 |
8 | @Splash
9 | @SpringFxApplication
10 | public class FxCssEntrance {
11 | public static void main(String[] args) {
12 | SpringApplication.run(FxCssEntrance.class, args);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/Config.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context;
2 |
3 | import java.io.IOException;
4 | import java.nio.file.Files;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 | import java.util.Optional;
8 | import java.util.Properties;
9 | import java.util.concurrent.TimeUnit;
10 |
11 | import javax.annotation.PostConstruct;
12 | import javax.inject.Inject;
13 |
14 | import org.springframework.stereotype.Service;
15 |
16 | import io.reactivex.subjects.Subject;
17 | import io.reactivex.subjects.UnicastSubject;
18 | import xdean.jex.log.Logable;
19 | import xdean.jfx.spring.splash.PreloadReporter;
20 | import xdean.jfx.spring.splash.PreloadReporter.SubReporter;
21 |
22 | @Service
23 | public class Config implements Logable {
24 | private static final Path CONFIG_FILE = Context.HOME_PATH.resolve("config.properties");
25 | private static final Path DEFAULT_CONFIG_PATH = Paths.get("/default_config.properties");
26 |
27 | private final Properties properties = new Properties();
28 | private final Subject saveSubject = UnicastSubject.create();
29 | private @Inject PreloadReporter preload;
30 |
31 | @PostConstruct
32 | public void init() {
33 | try {
34 | SubReporter sub = preload.load("Loading settings...");
35 | sub.setCount(3);
36 | sub.load("Check user setting");
37 | if (Files.notExists(CONFIG_FILE)) {
38 | if (Files.exists(DEFAULT_CONFIG_PATH)) {
39 | Files.copy(DEFAULT_CONFIG_PATH, CONFIG_FILE);
40 | } else {
41 | Files.createFile(CONFIG_FILE);
42 | }
43 | }
44 | sub.load("Loading settings file");
45 | properties.load(Files.newBufferedReader(CONFIG_FILE));
46 | debug("Load last config: " + properties.toString());
47 | sub.load("Apply settings");
48 | saveSubject
49 | .debounce(1000, TimeUnit.MILLISECONDS)
50 | .subscribe(e -> saveToFile());
51 | } catch (IOException e) {
52 | error("IOException", e);
53 | }
54 | }
55 |
56 | public Optional getProperty(String key) {
57 | return Optional.ofNullable(properties.getProperty(key));
58 | }
59 |
60 | public Optional getProperty(Object key) {
61 | return getProperty(key.toString());
62 | }
63 |
64 | public String getProperty(Object key, String defaultValue) {
65 | return getProperty(key.toString(), defaultValue);
66 | }
67 |
68 | public String getProperty(String key, String defaultValue) {
69 | return getProperty(key).orElse(defaultValue);
70 | }
71 |
72 | public void setProperty(Object key, String value) {
73 | setProperty(key.toString(), value);
74 | }
75 |
76 | public void setProperty(String key, String value) {
77 | properties.setProperty(key, value);
78 | saveSubject.onNext(key);
79 | }
80 |
81 | public void setIfAbsent(Object key, String value) {
82 | setIfAbsent(key.toString(), value);
83 | }
84 |
85 | public void setIfAbsent(String key, String value) {
86 | if (getProperty(key).isPresent() == false) {
87 | setProperty(key, value);
88 | }
89 | }
90 |
91 | public synchronized void saveToFile() {
92 | try {
93 | properties.store(Files.newOutputStream(CONFIG_FILE), "");
94 | } catch (IOException e) {
95 | error(e);
96 | }
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/Context.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context;
2 |
3 | import java.io.IOException;
4 | import java.lang.Thread.UncaughtExceptionHandler;
5 | import java.nio.file.Path;
6 | import java.nio.file.Paths;
7 |
8 | import javax.inject.Inject;
9 |
10 | import org.controlsfx.glyphfont.FontAwesome;
11 | import org.controlsfx.glyphfont.GlyphFontRegistry;
12 | import org.springframework.boot.context.event.ApplicationPreparedEvent;
13 | import org.springframework.context.ApplicationListener;
14 | import org.springframework.context.annotation.Configuration;
15 |
16 | import com.sun.javafx.util.Logging;
17 |
18 | import javafx.application.Platform;
19 | import sun.util.logging.PlatformLogger.Level;
20 | import xdean.css.editor.service.DialogService;
21 | import xdean.jex.log.Logable;
22 | import xdean.jex.util.file.FileUtil;
23 | import xdean.jfx.spring.context.FxContextPostProcessor;
24 | import xdean.spring.auto.AutoSpringFactories;
25 |
26 | @Configuration
27 | @AutoSpringFactories(ApplicationListener.class)
28 | public class Context implements FxContextPostProcessor, ApplicationListener,
29 | UncaughtExceptionHandler, Logable {
30 | public static final Path HOME_PATH = Paths.get(System.getProperty("user.home"), ".xdean", "css");
31 | public static final Path TEMP_PATH = HOME_PATH.resolve("temp");
32 | public static final Path LAST_FILE_PATH = Context.TEMP_PATH.resolve("last");
33 |
34 | private @Inject DialogService messageService;
35 |
36 | @Override
37 | public void onApplicationEvent(ApplicationPreparedEvent event) {
38 | debug("Setup Css Editor Environment");
39 | // create directories
40 | try {
41 | FileUtil.createDirectory(HOME_PATH);
42 | FileUtil.createDirectory(TEMP_PATH);
43 | } catch (IOException e) {
44 | error("Create home path fail.", e);
45 | }
46 | // close CSS logger
47 | Logging.getCSSLogger().setLevel(Level.OFF);
48 |
49 | // To ensure font awesome loaded
50 | GlyphFontRegistry.register(new FontAwesome(getClass().getResourceAsStream("/fontawesome.ttf")));
51 | GlyphFontRegistry.font("FontAwesome");
52 | }
53 |
54 | @Override
55 | public void beforeStart() {
56 | // handle uncaught exception
57 | Thread.setDefaultUncaughtExceptionHandler(this);
58 | Platform.runLater(() -> Thread.currentThread().setUncaughtExceptionHandler(this));
59 | }
60 |
61 | @Override
62 | public void uncaughtException(Thread t, Throwable e) {
63 | error("Uncaught exception", e);
64 | if (e instanceof Error) {
65 | System.exit(1);
66 | }
67 | if (Platform.isFxApplicationThread()) {
68 | handleError(e);
69 | } else {
70 | Platform.runLater(() -> handleError(e));
71 | }
72 | }
73 |
74 | private void handleError(Throwable e) {
75 | messageService.errorDialog(e).show();
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/DefaultValue.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import java.nio.charset.Charset;
4 | import java.util.Locale;
5 |
6 | import xdean.jex.util.string.StringUtil;
7 | import xdean.jfxex.support.skin.SkinStyle;
8 |
9 | public interface DefaultValue {
10 | int DEFAULT_FONT_SIZE = 16;
11 | int MIN_FONT_SIZE = 8;
12 | int MAX_FONT_SIZE = 36;
13 | String DEFAULT_FONT_FAMILY = "Monospaced";
14 | Locale DEFAULT_LOCALE = Locale.ENGLISH;
15 | Charset DEFAULT_CHARSET = Charset.defaultCharset();
16 | String[] DEF_FONT_FAMILIES = {
17 | "Consolas",
18 | "DejaVu Sans Mono",
19 | "Lucida Sans Typewriter",
20 | "Lucida Console",
21 | };
22 |
23 | enum DefaultSkin implements SkinStyle {
24 | CLASSIC("classic"),
25 | DEFAULT("default"),
26 | METAL("metal"),
27 | PINK("pink");
28 |
29 | private static final String CSS_PATH = "/css/skin/";
30 |
31 | private String path;
32 |
33 | private DefaultSkin(String name) {
34 | try {
35 | this.path = DefaultSkin.class.getResource(CSS_PATH + name + ".bss").toExternalForm();
36 | } catch (NullPointerException e) {// If the resource not exist
37 | this.path = DefaultSkin.class.getResource(CSS_PATH + name + ".css").toExternalForm();
38 | }
39 | }
40 |
41 | @Override
42 | public String getURL() {
43 | return path;
44 | }
45 |
46 | @Override
47 | public String getName() {
48 | return StringUtil.upperFirst(toString());
49 | }
50 | }
51 | }
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/EditActions.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import javafx.scene.input.KeyCode;
7 | import javafx.scene.input.KeyCodeCombination;
8 | import javafx.scene.input.KeyCombination;
9 | import xdean.css.editor.context.setting.SettingKeys.Edit;
10 | import xdean.css.editor.context.setting.model.CssEditorActionKeyOption;
11 |
12 | @Configuration
13 | public class EditActions {
14 |
15 | @Bean(Edit.UNDO)
16 | public CssEditorActionKeyOption undo() {
17 | return new CssEditorActionKeyOption(Edit.UNDO, new KeyCodeCombination(KeyCode.Z, KeyCombination.CONTROL_DOWN));
18 | }
19 |
20 | @Bean(Edit.REDO)
21 | public CssEditorActionKeyOption redo() {
22 | return new CssEditorActionKeyOption(Edit.REDO, new KeyCodeCombination(KeyCode.Y, KeyCombination.CONTROL_DOWN));
23 | }
24 |
25 | @Bean(Edit.SUGGEST)
26 | public CssEditorActionKeyOption suggest() {
27 | return new CssEditorActionKeyOption(Edit.SUGGEST, new KeyCodeCombination(KeyCode.SLASH, KeyCombination.ALT_DOWN));
28 | }
29 |
30 | @Bean(Edit.FORMAT)
31 | public CssEditorActionKeyOption format() {
32 | return new CssEditorActionKeyOption(Edit.FORMAT,
33 | new KeyCodeCombination(KeyCode.F, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
34 | }
35 |
36 | @Bean(Edit.COMMENT)
37 | public CssEditorActionKeyOption comment() {
38 | return new CssEditorActionKeyOption(Edit.COMMENT, new KeyCodeCombination(KeyCode.Q, KeyCombination.CONTROL_DOWN));
39 | }
40 |
41 | @Bean(Edit.FIND)
42 | public CssEditorActionKeyOption find() {
43 | return new CssEditorActionKeyOption(Edit.FIND, new KeyCodeCombination(KeyCode.F, KeyCombination.CONTROL_DOWN));
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/FileActions.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import java.nio.file.Path;
4 |
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 |
8 | import javafx.scene.input.KeyCode;
9 | import javafx.scene.input.KeyCodeCombination;
10 | import javafx.scene.input.KeyCombination;
11 | import xdean.css.editor.context.setting.SettingKeys.File;
12 | import xdean.css.editor.context.setting.model.CssEditorActionKeyOption;
13 | import xdean.css.editor.context.setting.model.CssEditorKeyOption;
14 |
15 | @Configuration
16 | public class FileActions {
17 |
18 | @Bean(File.NEW)
19 | public CssEditorActionKeyOption newFile() {
20 | return new CssEditorActionKeyOption(File.NEW, new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN));
21 | }
22 |
23 | @Bean(File.OPEN)
24 | public CssEditorKeyOption open() {
25 | return new CssEditorKeyOption<>(File.OPEN, new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN));
26 | }
27 |
28 | @Bean(File.SAVE)
29 | public CssEditorActionKeyOption save() {
30 | return new CssEditorActionKeyOption(File.SAVE, new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN));
31 | }
32 |
33 | @Bean(File.SAVE_AS)
34 | public CssEditorKeyOption saveAs() {
35 | return new CssEditorKeyOption<>(File.SAVE_AS,
36 | new KeyCodeCombination(KeyCode.S, KeyCombination.ALT_DOWN, KeyCombination.CONTROL_DOWN));
37 | }
38 |
39 | @Bean(File.CLOSE)
40 | public CssEditorActionKeyOption close() {
41 | return new CssEditorActionKeyOption(File.CLOSE, new KeyCodeCombination(KeyCode.W, KeyCombination.CONTROL_DOWN));
42 | }
43 |
44 | @Bean(File.REVERT)
45 | public CssEditorActionKeyOption revert() {
46 | return new CssEditorActionKeyOption(File.REVERT, KeyCodeCombination.NO_MATCH);
47 | }
48 |
49 | @Bean(File.EXIT)
50 | public CssEditorActionKeyOption exit() {
51 | return new CssEditorActionKeyOption(File.EXIT, KeyCodeCombination.NO_MATCH);
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/HelpActions.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import org.springframework.context.annotation.Bean;
4 | import org.springframework.context.annotation.Configuration;
5 |
6 | import javafx.scene.input.KeyCodeCombination;
7 | import xdean.css.editor.context.setting.SettingKeys.Help;
8 | import xdean.css.editor.context.setting.model.CssEditorActionKeyOption;
9 |
10 | @Configuration
11 | public class HelpActions {
12 |
13 | @Bean(Help.SETTINGS)
14 | public CssEditorActionKeyOption settings() {
15 | return new CssEditorActionKeyOption(Help.SETTINGS, KeyCodeCombination.NO_MATCH);
16 | }
17 | @Bean(Help.ABOUT)
18 | public CssEditorActionKeyOption about() {
19 | return new CssEditorActionKeyOption(Help.ABOUT, KeyCodeCombination.NO_MATCH);
20 | }
21 | @Bean(Help.HELP)
22 | public CssEditorActionKeyOption help() {
23 | return new CssEditorActionKeyOption(Help.HELP, KeyCodeCombination.NO_MATCH);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/OptionBindProcessor.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import javax.inject.Inject;
4 |
5 | import org.springframework.beans.BeansException;
6 | import org.springframework.beans.factory.config.BeanPostProcessor;
7 | import org.springframework.stereotype.Component;
8 |
9 | import xdean.css.editor.context.Config;
10 | import xdean.css.editor.context.setting.model.option.Option;
11 |
12 | @Component
13 | public class OptionBindProcessor implements BeanPostProcessor {
14 |
15 | @Inject
16 | Config config;
17 |
18 | @Override
19 | public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
20 | if (bean instanceof Option) {
21 | ((Option>) bean).bind(config);
22 | }
23 | return bean;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/OtherSettings.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import static xdean.css.editor.context.setting.SettingKeys.LANGUAGE;
4 | import static xdean.css.editor.context.setting.SettingKeys.RECENT_LOC;
5 | import static xdean.css.editor.context.setting.SettingKeys.SKIN;
6 |
7 | import java.util.Locale;
8 |
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 |
12 | import xdean.css.editor.context.setting.DefaultValue.DefaultSkin;
13 | import xdean.css.editor.context.setting.SettingKeys.Find;
14 | import xdean.css.editor.context.setting.model.option.BooleanOption;
15 | import xdean.css.editor.context.setting.model.option.Option;
16 | import xdean.css.editor.context.setting.model.option.SimpleOption;
17 | import xdean.css.editor.context.setting.model.option.StringOption;
18 | import xdean.jfxex.util.StringConverters;
19 |
20 | @Configuration
21 | public class OtherSettings {
22 |
23 | @Bean(LANGUAGE)
24 | public Option locale() {
25 | return new SimpleOption<>(LANGUAGE, DefaultValue.DEFAULT_LOCALE, StringConverters.create(Locale::forLanguageTag));
26 | }
27 |
28 | @Bean(SKIN)
29 | public StringOption skin() {
30 | return new StringOption(SKIN, DefaultSkin.CLASSIC.getName());
31 | }
32 |
33 | @Bean(RECENT_LOC)
34 | public StringOption recent() {
35 | return new StringOption(RECENT_LOC, "");
36 | }
37 |
38 | @Bean(Find.WRAP_SEARCH)
39 | public BooleanOption wrapSearch() {
40 | return new BooleanOption(Find.WRAP_SEARCH, true);
41 | }
42 |
43 | @Bean(Find.REGEX)
44 | public BooleanOption regexSearch() {
45 | return new BooleanOption(Find.REGEX, false);
46 | }
47 |
48 | @Bean(Find.CASE_SENSITIVE)
49 | public BooleanOption caseSensitive() {
50 | return new BooleanOption(Find.CASE_SENSITIVE, false);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/PreferenceSettings.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import static xdean.css.editor.context.setting.SettingKeys.GENERAL;
4 |
5 | import java.nio.charset.Charset;
6 | import java.util.Arrays;
7 | import java.util.List;
8 |
9 | import org.springframework.context.annotation.Bean;
10 | import org.springframework.context.annotation.Configuration;
11 |
12 | import com.google.common.collect.BoundType;
13 |
14 | import javafx.scene.text.Font;
15 | import xdean.css.editor.context.setting.SettingKeys.General;
16 | import xdean.css.editor.context.setting.model.option.BooleanOption;
17 | import xdean.css.editor.context.setting.model.option.IntegerOption;
18 | import xdean.css.editor.context.setting.model.option.OptionGroup;
19 | import xdean.css.editor.context.setting.model.option.ValueOption;
20 | import xdean.jfxex.util.StringConverters;
21 |
22 | @Configuration
23 | public class PreferenceSettings {
24 |
25 | @Bean(GENERAL)
26 | public OptionGroup general() {
27 | OptionGroup general = new OptionGroup(GENERAL);
28 | general.add(common());
29 | general.add(text());
30 | return general;
31 | }
32 |
33 | @Bean(General.COMMON)
34 | public OptionGroup common() {
35 | OptionGroup common = new OptionGroup(General.COMMON);
36 | common.add(autoSuggest());
37 | common.add(showLineNo());
38 | common.add(openLast());
39 | common.add(charset());
40 | return common;
41 | }
42 |
43 | @Bean(General.Common.AUTO_SUGGEST)
44 | public BooleanOption autoSuggest() {
45 | return new BooleanOption(General.Common.AUTO_SUGGEST, true);
46 | }
47 |
48 | @Bean(General.Common.SHOW_LINE)
49 | public BooleanOption showLineNo() {
50 | return new BooleanOption(General.Common.SHOW_LINE, true);
51 | }
52 |
53 | @Bean(General.Common.OPEN_LAST)
54 | public BooleanOption openLast() {
55 | return new BooleanOption(General.Common.OPEN_LAST, true);
56 | }
57 |
58 | @Bean(General.Common.CHARSET)
59 | public ValueOption charset() {
60 | ValueOption charset = new ValueOption<>(General.Common.CHARSET, DefaultValue.DEFAULT_CHARSET,
61 | StringConverters.create(this::safeCharSet));
62 | charset.values.setAll(Charset.availableCharsets().values());
63 | return charset;
64 | }
65 |
66 | @Bean(General.TEXT)
67 | public OptionGroup text() {
68 | OptionGroup text = new OptionGroup(General.TEXT);
69 | text.add(fontFamily());
70 | text.add(fontSize());
71 | text.add(wrapText());
72 | return text;
73 | }
74 |
75 | @Bean(General.Text.FONT_FAMILY)
76 | public ValueOption fontFamily() {
77 | ValueOption fontFamily = new ValueOption<>(General.Text.FONT_FAMILY, DefaultValue.DEFAULT_FONT_FAMILY,
78 | StringConverters.create(this::safeFontFamily));
79 | fontFamily.values.setAll(Arrays.asList(DefaultValue.DEF_FONT_FAMILIES));
80 | fontFamily.values.addAll(Font.getFamilies());
81 | return fontFamily;
82 | }
83 |
84 | @Bean(General.Text.FONT_SIZE)
85 | public IntegerOption fontSize() {
86 | IntegerOption fontSize = new IntegerOption(General.Text.FONT_SIZE, DefaultValue.DEFAULT_FONT_SIZE);
87 | fontSize.setRange(DefaultValue.MIN_FONT_SIZE, BoundType.CLOSED, DefaultValue.MAX_FONT_SIZE, BoundType.CLOSED);
88 | return fontSize;
89 | }
90 |
91 | @Bean(General.Text.WRAP_TEXT)
92 | public BooleanOption wrapText() {
93 | return new BooleanOption(General.Text.WRAP_TEXT, true);
94 | }
95 |
96 | /**
97 | * Check whether font family is null or invalid (family not available on system) and search for an
98 | * available family.
99 | */
100 | private String safeFontFamily(String fontFamily) {
101 | List fontFamilies = Font.getFamilies();
102 | if (fontFamily != null && fontFamilies.contains(fontFamily)) {
103 | return fontFamily;
104 | }
105 |
106 | for (String family : DefaultValue.DEF_FONT_FAMILIES) {
107 | if (fontFamilies.contains(family)) {
108 | return family;
109 | }
110 | }
111 | return DefaultValue.DEFAULT_FONT_FAMILY;
112 | }
113 |
114 | private Charset safeCharSet(String charsetName) {
115 | if (Charset.isSupported(charsetName)) {
116 | return Charset.forName(charsetName);
117 | } else {
118 | return Charset.defaultCharset();
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/RawSettingKeys.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import java.lang.String;
4 | import javax.annotation.Generated;
5 |
6 | @Generated("xdean.auto.message.AutoMessageProcessor")
7 | public interface RawSettingKeys {
8 | String OPTION_GENERAL = "option.general";
9 |
10 | String OPTION_GENERAL_COMMON = "option.general.common";
11 |
12 | String OPTION_GENERAL_COMMON_AUTO_SUGGEST = "option.general.common.auto-suggest";
13 |
14 | String OPTION_GENERAL_COMMON_SHOW_LINE = "option.general.common.show-line";
15 |
16 | String OPTION_GENERAL_COMMON_OPEN_LAST = "option.general.common.open-last";
17 |
18 | String OPTION_GENERAL_COMMON_CHARSET = "option.general.common.charset";
19 |
20 | String OPTION_GENERAL_TEXT = "option.general.text";
21 |
22 | String OPTION_GENERAL_TEXT_FONT_FAMILY = "option.general.text.font-family";
23 |
24 | String OPTION_GENERAL_TEXT_FONT_SIZE = "option.general.text.font-size";
25 |
26 | String OPTION_GENERAL_TEXT_WRAP_TEXT = "option.general.text.wrap-text";
27 |
28 | String OPTION_KEY = "option.key";
29 |
30 | String OPTION_FIND_REGEX = "option.find.regex";
31 |
32 | String OPTION_FIND_WRAP_SEARCH = "option.find.wrap-search";
33 |
34 | String OPTION_FIND_CASE_SENSITIVE = "option.find.case-sensitive";
35 |
36 | String OPTION_LANGUAGE = "option.language";
37 |
38 | String OPTION_SKIN = "option.skin";
39 |
40 | String OPTION_RECENT_LOCATION = "option.recent.location";
41 |
42 | String EDIT_UNDO = "edit.undo";
43 |
44 | String EDIT_REDO = "edit.redo";
45 |
46 | String EDIT_SUGGEST = "edit.suggest";
47 |
48 | String EDIT_FORMAT = "edit.format";
49 |
50 | String EDIT_COMMENT = "edit.comment";
51 |
52 | String EDIT_FIND = "edit.find";
53 |
54 | String FILE_NEW = "file.new";
55 |
56 | String FILE_OPEN = "file.open";
57 |
58 | String FILE_SAVE = "file.save";
59 |
60 | String FILE_SAVEAS = "file.saveAs";
61 |
62 | String FILE_CLOSE = "file.close";
63 |
64 | String FILE_REVERT = "file.revert";
65 |
66 | String FILE_EXIT = "file.exit";
67 |
68 | String HELP_SETTINGS = "help.settings";
69 |
70 | String HELP_ABOUT = "help.about";
71 |
72 | String HELP_HELP = "help.help";
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/SettingKeys.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting;
2 |
3 | import static xdean.css.editor.context.setting.RawSettingKeys.*;
4 |
5 | import xdean.auto.message.AutoMessage;
6 |
7 | @AutoMessage(path = "/message/settings.properties", generatedName = "RawSettingKeysStub")
8 | public interface SettingKeys {
9 | String GENERAL = OPTION_GENERAL;
10 |
11 | interface General {
12 |
13 | String COMMON = OPTION_GENERAL_COMMON;
14 |
15 | interface Common {
16 | String AUTO_SUGGEST = OPTION_GENERAL_COMMON_AUTO_SUGGEST;
17 | String SHOW_LINE = OPTION_GENERAL_COMMON_SHOW_LINE;
18 | String OPEN_LAST = OPTION_GENERAL_COMMON_OPEN_LAST;
19 | String CHARSET = OPTION_GENERAL_COMMON_CHARSET;
20 | }
21 |
22 | String TEXT = OPTION_GENERAL_TEXT;
23 |
24 | interface Text {
25 | String FONT_FAMILY = OPTION_GENERAL_TEXT_FONT_FAMILY;
26 | String FONT_SIZE = OPTION_GENERAL_TEXT_FONT_SIZE;
27 | String WRAP_TEXT = OPTION_GENERAL_TEXT_WRAP_TEXT;
28 | }
29 | }
30 |
31 | interface Find {
32 | String REGEX = OPTION_FIND_REGEX;
33 | String WRAP_SEARCH = OPTION_FIND_WRAP_SEARCH;
34 | String CASE_SENSITIVE = OPTION_FIND_CASE_SENSITIVE;
35 | }
36 |
37 | String LANGUAGE = OPTION_LANGUAGE;
38 | String SKIN = OPTION_SKIN;
39 | String RECENT_LOC = OPTION_RECENT_LOCATION;
40 |
41 | interface File {
42 | String NEW = FILE_NEW;
43 | String OPEN = FILE_OPEN;
44 | String SAVE = FILE_SAVE;
45 | String SAVE_AS = FILE_SAVEAS;
46 | String CLOSE = FILE_CLOSE;
47 | String REVERT = FILE_REVERT;
48 | String EXIT = FILE_EXIT;
49 | }
50 |
51 | interface Edit {
52 | String UNDO = EDIT_UNDO;
53 | String REDO = EDIT_REDO;
54 | String SUGGEST = EDIT_SUGGEST;
55 | String FORMAT = EDIT_FORMAT;
56 | String COMMENT = EDIT_COMMENT;
57 | String FIND = EDIT_FIND;
58 | }
59 |
60 | interface Help {
61 | String SETTINGS = HELP_SETTINGS;
62 | String ABOUT = HELP_ABOUT;
63 | String HELP = HELP_HELP;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/model/CssEditorActionKeyOption.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting.model;
2 |
3 | import javafx.scene.input.KeyCombination;
4 |
5 | public class CssEditorActionKeyOption extends CssEditorKeyOption {
6 | public CssEditorActionKeyOption(String key, KeyCombination defaultValue) {
7 | super(key, defaultValue);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/model/CssEditorKeyOption.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting.model;
2 |
3 | import static xdean.jfxex.event.EventHandlers.consumeIf;
4 |
5 | import io.reactivex.rxjavafx.observables.JavaFxObservable;
6 | import javafx.beans.property.BooleanProperty;
7 | import javafx.beans.property.Property;
8 | import javafx.beans.property.SimpleBooleanProperty;
9 | import javafx.event.EventType;
10 | import javafx.scene.input.KeyCombination;
11 | import javafx.scene.input.KeyEvent;
12 | import javafx.util.StringConverter;
13 | import xdean.css.editor.context.setting.model.option.Option;
14 | import xdean.css.editor.control.CssEditor;
15 | import xdean.css.editor.control.CssEditorEvent;
16 | import xdean.jfxex.bean.property.ObjectPropertyEX;
17 | import xdean.jfxex.util.StringConverters;
18 |
19 | public class CssEditorKeyOption implements Option {
20 |
21 | private static final StringConverter CONVERTER = StringConverters.create(KeyCombination::valueOf);
22 |
23 | private final String key;
24 | private final EventType> eventType;
25 | private final ObjectPropertyEX value = new ObjectPropertyEX<>(this, "value");
26 | private final KeyCombination defaultValue;
27 | private final BooleanProperty disable = new SimpleBooleanProperty(this, "disable", false);
28 |
29 | public CssEditorKeyOption(String key, KeyCombination defaultValue) {
30 | this.key = key;
31 | this.defaultValue = defaultValue;
32 | this.eventType = new EventType<>(CssEditorEvent.ANY, key);
33 | this.value.defaultForNull(KeyCombination.NO_MATCH);
34 | }
35 |
36 | @Override
37 | public String getKey() {
38 | return key;
39 | }
40 |
41 | public EventType> getEventType() {
42 | return eventType;
43 | }
44 |
45 | public BooleanProperty disableProperty() {
46 | return disable;
47 | }
48 |
49 | @Override
50 | public Property valueProperty() {
51 | return value;
52 | }
53 |
54 | @Override
55 | public KeyCombination getDefaultValue() {
56 | return defaultValue;
57 | }
58 |
59 | @Override
60 | public StringConverter getConverter() {
61 | return CONVERTER;
62 | }
63 |
64 | public void bind(CssEditor editor) {
65 | editor.addEventFilter(eventType, consumeIf(e -> disable.get()));
66 | JavaFxObservable.eventsOf(editor, KeyEvent.KEY_PRESSED)
67 | .filter(e -> getValue().match(e))
68 | .doOnNext(KeyEvent::consume)
69 | .subscribe(e -> editor.fireEvent(getEvent(editor)));
70 | }
71 |
72 | public CssEditorEvent getEvent(CssEditor editor) {
73 | return new CssEditorEvent<>(editor, getEventType());
74 | }
75 |
76 | public CssEditorEvent getEvent(CssEditor editor, T data) {
77 | return new CssEditorEvent<>(editor, getEventType(), data);
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/model/option/BooleanOption.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting.model.option;
2 |
3 | import static xdean.jex.util.cache.CacheUtil.cache;
4 |
5 | import javafx.beans.property.BooleanProperty;
6 | import xdean.jfxex.bean.BeanConvertUtil;
7 | import xdean.jfxex.util.StringConverters;
8 |
9 | public class BooleanOption extends SimpleOption {
10 | public BooleanOption(String key, boolean defaultValue) {
11 | super(key, defaultValue, StringConverters.create(Boolean::valueOf));
12 | }
13 |
14 | public BooleanProperty booleanProperty() {
15 | return cache(this, () -> BeanConvertUtil.toBoolean(valueProperty()));
16 | }
17 | }
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/model/option/ConstraintOption.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting.model.option;
2 |
3 | public interface ConstraintOption extends Option {
4 | boolean isValid(T t);
5 |
6 | @Override
7 | public default void setValue(T t) {
8 | if (isValid(t)) {
9 | valueProperty().setValue(t);
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/model/option/IntegerOption.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting.model.option;
2 |
3 | import static xdean.jex.util.cache.CacheUtil.cache;
4 | import static xdean.jfxex.bean.BeanConvertUtil.toInteger;
5 |
6 | import javafx.beans.property.IntegerProperty;
7 | import xdean.jfxex.util.StringConverters;
8 |
9 | public class IntegerOption extends RangeOption {
10 |
11 | public IntegerOption(String key, int defaultValue) {
12 | super(key, defaultValue, StringConverters.forInteger(defaultValue));
13 | }
14 |
15 | public IntegerProperty intProperty() {
16 | return cache(this, () -> toInteger(valueProperty()));
17 | }
18 | }
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/model/option/Option.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting.model.option;
2 |
3 | import javafx.beans.property.Property;
4 | import javafx.util.StringConverter;
5 | import xdean.css.editor.context.Config;
6 | import xdean.jex.extra.tryto.Try;
7 |
8 | public interface Option {
9 |
10 | Property valueProperty();
11 |
12 | default T getValue() {
13 | return valueProperty().getValue();
14 | }
15 |
16 | default void setValue(T t) {
17 | valueProperty().setValue(t);
18 | }
19 |
20 | T getDefaultValue();
21 |
22 | String getKey();
23 |
24 | StringConverter getConverter();
25 |
26 | default void bind(Config config) {
27 | StringConverter converter = getConverter();
28 | valueProperty()
29 | .setValue(Try.to(() -> config.getProperty(getKey()).map(converter::fromString).get()).getOrElse(getDefaultValue()));
30 | valueProperty().addListener((ob, o, n) -> config.setProperty(getKey(), converter.toString(n)));
31 | }
32 | }
--------------------------------------------------------------------------------
/src/main/java/xdean/css/editor/context/setting/model/option/OptionGroup.java:
--------------------------------------------------------------------------------
1 | package xdean.css.editor.context.setting.model.option;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collections;
5 | import java.util.List;
6 | import java.util.stream.Collectors;
7 |
8 | import xdean.jex.extra.collection.Either;
9 | import xdean.jex.util.cache.CacheUtil;
10 |
11 | public class OptionGroup {
12 |
13 | List, OptionGroup>> list;
14 | String key;
15 |
16 | public OptionGroup(String key) {
17 | this.key = key;
18 | list = new ArrayList<>();
19 | }
20 |
21 | public > T add(T o) {
22 | list.add(Either.left(o));
23 | return o;
24 | }
25 |
26 | public OptionGroup add(OptionGroup og) {
27 | list.add(Either.right(og));
28 | return og;
29 | }
30 |
31 | public List, OptionGroup>> getChildren() {
32 | return CacheUtil.cache(this, () -> Collections.unmodifiableList(list));
33 | }
34 |
35 | @SuppressWarnings("unchecked")
36 | public List