├── .gitignore
├── .idea
├── .gitignore
├── codeStyles
│ └── codeStyleConfig.xml
├── compiler.xml
├── gradle.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── jarRepositories.xml
├── kotlinc.xml
├── markdown.xml
├── misc.xml
├── modules
│ ├── sierra-test
│ │ ├── Sierra.sierra-test.iml
│ │ ├── Sierra.sierra-test.main.iml
│ │ └── Sierra.sierra-test.test.iml
│ └── sierra
│ │ ├── Sierra.sierra.iml
│ │ ├── Sierra.sierra.main.iml
│ │ └── Sierra.sierra.test.iml
├── uiDesigner.xml
└── vcs.xml
├── LICENSE
├── README.md
├── README
├── action.png
├── activity-indicator.png
├── alignment-x.png
├── alignment-y.png
├── border.png
├── box.png
├── button-group.png
├── cell-renderer.png
├── date-picker.png
├── form.png
├── greeting.png
├── grid.png
├── menu-button.png
├── orientation.png
├── suggestion-picker.png
├── task-executor.png
├── text-fields.png
├── tiingo.png
└── time-picker.png
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── publish.gradle
├── settings.gradle
├── sierra-test
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── httprpc
│ │ └── sierra
│ │ └── test
│ │ ├── ActionTest.java
│ │ ├── ActivityIndicatorTest.java
│ │ ├── AlignmentXTest.java
│ │ ├── AlignmentYTest.java
│ │ ├── Asset.java
│ │ ├── AssetPricing.java
│ │ ├── BaselineTest.java
│ │ ├── BorderTest.java
│ │ ├── BoxTest.java
│ │ ├── ButtonGroupTest.java
│ │ ├── CellRendererTest.java
│ │ ├── DateTimePickerTest.java
│ │ ├── FlowTest.java
│ │ ├── FormTest.java
│ │ ├── GreetingTest.java
│ │ ├── ImagePaneTest.java
│ │ ├── MenuButtonTest.java
│ │ ├── OrientationTest.java
│ │ ├── StackTest.java
│ │ ├── SuggestionPickerTest.java
│ │ ├── TaskExecutorTest.java
│ │ ├── TextFieldTest.java
│ │ ├── TextPaneTest.java
│ │ ├── TiingoServiceProxy.java
│ │ └── TiingoTest.java
│ └── resources
│ └── org
│ └── httprpc
│ └── sierra
│ └── test
│ ├── ActionTest.properties
│ ├── ActivityIndicatorTest.properties
│ ├── BorderTest.properties
│ ├── ButtonGroupTest.properties
│ ├── DateTimePickerTest.properties
│ ├── FormTest.properties
│ ├── MenuButtonTest.properties
│ ├── OrientationTest.properties
│ ├── TaskExecutorTest.properties
│ ├── TextFieldTest.properties
│ ├── TiingoTest.properties
│ ├── action-test.xml
│ ├── activity-indicator-test.xml
│ ├── alignment-x-test.xml
│ ├── alignment-y-test.xml
│ ├── baseline-test.xml
│ ├── border-test.xml
│ ├── box-test.xml
│ ├── button-group-test.xml
│ ├── date-time-picker-test.xml
│ ├── flag-cell-renderer.xml
│ ├── flags
│ ├── alpha.png
│ ├── bravo.png
│ ├── charlie.png
│ ├── delta.png
│ ├── echo.png
│ ├── foxtrot.png
│ ├── golf.png
│ ├── hotel.png
│ ├── india.png
│ ├── juliet.png
│ ├── kilo.png
│ ├── lima.png
│ ├── mike.png
│ ├── november.png
│ ├── oscar.png
│ ├── papa.png
│ ├── quebec.png
│ ├── romeo.png
│ ├── sierra.png
│ ├── tango.png
│ ├── uniform.png
│ ├── victor.png
│ ├── whisky.png
│ ├── xray.png
│ ├── yankee.png
│ └── zulu.png
│ ├── flow-test.xml
│ ├── form-test.xml
│ ├── format_align_center_black_18dp.svg
│ ├── format_align_justify_black_18dp.svg
│ ├── format_align_left_black_18dp.svg
│ ├── format_align_right_black_18dp.svg
│ ├── greeting-test.xml
│ ├── menu-button-test.xml
│ ├── orientation-test.xml
│ ├── people_18dp.svg
│ ├── search_18dp.svg
│ ├── stack-test.xml
│ ├── suggestion-picker-test.xml
│ ├── task-executor-test.xml
│ ├── text-field-test.xml
│ ├── tiingo-test.xml
│ └── world.png
├── sierra.dtd
├── sierra.png
└── sierra
├── build.gradle
└── src
└── main
└── java
└── org
└── httprpc
└── sierra
├── ActivityIndicator.java
├── BoxPanel.java
├── ColumnPanel.java
├── DatePicker.java
├── HorizontalAlignment.java
├── ImagePane.java
├── LayoutPanel.java
├── MenuButton.java
├── Picker.java
├── RowPanel.java
├── ScrollingKeyboardFocusManager.java
├── Spacer.java
├── StackPanel.java
├── SuggestionPicker.java
├── TaskExecutor.java
├── TextPane.java
├── TimePicker.java
├── UILoader.java
├── VerticalAlignment.java
└── package-info.java
/.gitignore:
--------------------------------------------------------------------------------
1 | .gradle
2 | .idea/sonarlint
3 | **/build
4 | **/out
5 | **/.DS_Store
6 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/markdown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules/sierra-test/Sierra.sierra-test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules/sierra-test/Sierra.sierra-test.main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules/sierra-test/Sierra.sierra-test.test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules/sierra/Sierra.sierra.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules/sierra/Sierra.sierra.main.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/modules/sierra/Sierra.sierra.test.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README/action.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/action.png
--------------------------------------------------------------------------------
/README/activity-indicator.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/activity-indicator.png
--------------------------------------------------------------------------------
/README/alignment-x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/alignment-x.png
--------------------------------------------------------------------------------
/README/alignment-y.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/alignment-y.png
--------------------------------------------------------------------------------
/README/border.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/border.png
--------------------------------------------------------------------------------
/README/box.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/box.png
--------------------------------------------------------------------------------
/README/button-group.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/button-group.png
--------------------------------------------------------------------------------
/README/cell-renderer.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/cell-renderer.png
--------------------------------------------------------------------------------
/README/date-picker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/date-picker.png
--------------------------------------------------------------------------------
/README/form.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/form.png
--------------------------------------------------------------------------------
/README/greeting.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/greeting.png
--------------------------------------------------------------------------------
/README/grid.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/grid.png
--------------------------------------------------------------------------------
/README/menu-button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/menu-button.png
--------------------------------------------------------------------------------
/README/orientation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/orientation.png
--------------------------------------------------------------------------------
/README/suggestion-picker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/suggestion-picker.png
--------------------------------------------------------------------------------
/README/task-executor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/task-executor.png
--------------------------------------------------------------------------------
/README/text-fields.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/text-fields.png
--------------------------------------------------------------------------------
/README/tiingo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/tiingo.png
--------------------------------------------------------------------------------
/README/time-picker.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/README/time-picker.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | subprojects {
16 | group = 'org.httprpc'
17 | version = '2.8'
18 |
19 | apply plugin: 'java-library'
20 |
21 | repositories {
22 | mavenCentral()
23 | mavenLocal()
24 | }
25 |
26 | java {
27 | sourceCompatibility = JavaVersion.VERSION_17
28 | targetCompatibility = JavaVersion.VERSION_17
29 | }
30 |
31 | javadoc {
32 | options.addStringOption('Xdoclint:none', '-quiet')
33 | }
34 |
35 | jar {
36 | manifest {
37 | attributes (
38 | 'Implementation-Title': project.name,
39 | 'Implementation-Version': project.version
40 | )
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | kiloVersion = 4.10
2 | flatLafVersion = 3.6
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH="\\\"\\\""
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | if ! command -v java >/dev/null 2>&1
137 | then
138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
139 |
140 | Please set the JAVA_HOME variable in your environment to match the
141 | location of your Java installation."
142 | fi
143 | fi
144 |
145 | # Increase the maximum file descriptors if we can.
146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
147 | case $MAX_FD in #(
148 | max*)
149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
150 | # shellcheck disable=SC2039,SC3045
151 | MAX_FD=$( ulimit -H -n ) ||
152 | warn "Could not query maximum file descriptor limit"
153 | esac
154 | case $MAX_FD in #(
155 | '' | soft) :;; #(
156 | *)
157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
158 | # shellcheck disable=SC2039,SC3045
159 | ulimit -n "$MAX_FD" ||
160 | warn "Could not set maximum file descriptor limit to $MAX_FD"
161 | esac
162 | fi
163 |
164 | # Collect all arguments for the java command, stacking in reverse order:
165 | # * args from the command line
166 | # * the main class name
167 | # * -classpath
168 | # * -D...appname settings
169 | # * --module-path (only if needed)
170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
171 |
172 | # For Cygwin or MSYS, switch paths to Windows format before running java
173 | if "$cygwin" || "$msys" ; then
174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176 |
177 | JAVACMD=$( cygpath --unix "$JAVACMD" )
178 |
179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
180 | for arg do
181 | if
182 | case $arg in #(
183 | -*) false ;; # don't mess with options #(
184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
185 | [ -e "$t" ] ;; #(
186 | *) false ;;
187 | esac
188 | then
189 | arg=$( cygpath --path --ignore --mixed "$arg" )
190 | fi
191 | # Roll the args list around exactly as many times as the number of
192 | # args, so each arg winds up back in the position where it started, but
193 | # possibly modified.
194 | #
195 | # NB: a `for` loop captures its iteration list before it begins, so
196 | # changing the positional parameters here affects neither the number of
197 | # iterations, nor the values presented in `arg`.
198 | shift # remove old arg
199 | set -- "$@" "$arg" # push replacement arg
200 | done
201 | fi
202 |
203 |
204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206 |
207 | # Collect all arguments for the java command:
208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209 | # and any embedded shellness will be escaped.
210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211 | # treated as '${Hostname}' itself on the command line.
212 |
213 | set -- \
214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
215 | -classpath "$CLASSPATH" \
216 | -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
217 | "$@"
218 |
219 | # Stop when "xargs" is not available.
220 | if ! command -v xargs >/dev/null 2>&1
221 | then
222 | die "xargs is not available"
223 | fi
224 |
225 | # Use "xargs" to parse quoted args.
226 | #
227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
228 | #
229 | # In Bash we could simply go:
230 | #
231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
232 | # set -- "${ARGS[@]}" "$@"
233 | #
234 | # but POSIX shell has neither arrays nor command substitution, so instead we
235 | # post-process each arg (as a line of input to sed) to backslash-escape any
236 | # character that might be a shell metacharacter, then use eval to reverse
237 | # that process (while maintaining the separation between arguments), and wrap
238 | # the whole thing up as a single "set" statement.
239 | #
240 | # This will of course break if any of these variables contains a newline or
241 | # an unmatched quote.
242 | #
243 |
244 | eval "set -- $(
245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
246 | xargs -n1 |
247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
248 | tr '\n' ' '
249 | )" '"$@"'
250 |
251 | exec "$JAVACMD" "$@"
252 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/publish.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | apply plugin: 'maven-publish'
16 | apply plugin: 'signing'
17 |
18 | tasks.register("sourcesJar", Jar) {
19 | from sourceSets.main.allJava
20 | archiveClassifier = 'sources'
21 | }
22 |
23 | tasks.register("javadocJar", Jar) {
24 | from javadoc
25 | archiveClassifier = 'javadoc'
26 | }
27 |
28 | publishing {
29 | repositories {
30 | maven {
31 | url = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
32 |
33 | credentials {
34 | username = project.properties['nexusUsername'] ?: ''
35 | password = project.properties['nexusPassword'] ?: ''
36 | }
37 | }
38 | }
39 |
40 | publications {
41 | mavenJava(MavenPublication) {
42 | artifactId = project.name
43 | from components.java
44 | artifact sourcesJar
45 | artifact javadocJar
46 | pom {
47 | name = project.name
48 | description = 'Declarative UI for Java'
49 | url = 'https://github.com/HTTP-RPC/Sierra'
50 | licenses {
51 | license {
52 | name = 'The Apache License, Version 2.0'
53 | url = 'https://www.apache.org/licenses/LICENSE-2.0.txt'
54 | }
55 | }
56 | developers {
57 | developer {
58 | name = 'Greg Brown'
59 | email = 'gk_brown@icloud.com'
60 | }
61 | }
62 | scm {
63 | connection = 'scm:git:git://github.com/HTTP-RPC/Sierra.git'
64 | url = 'https://github.com/HTTP-RPC/Sierra'
65 | }
66 | }
67 | }
68 | }
69 | }
70 |
71 | signing {
72 | sign publishing.publications.mavenJava
73 | }
74 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'Sierra'
2 |
3 | include 'sierra', 'sierra-test'
4 |
--------------------------------------------------------------------------------
/sierra-test/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | dependencies {
16 | implementation project(':sierra')
17 |
18 | implementation "com.formdev:flatlaf:${flatLafVersion}:no-natives"
19 | implementation "com.formdev:flatlaf-extras:${flatLafVersion}"
20 | }
21 |
22 | compileJava {
23 | options.compilerArgs = [
24 | '-parameters'
25 | ]
26 | }
27 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/ActionTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JButton;
21 | import javax.swing.JFrame;
22 | import javax.swing.JLabel;
23 | import javax.swing.SwingUtilities;
24 | import java.util.ResourceBundle;
25 |
26 | public class ActionTest extends JFrame implements Runnable {
27 | private JButton greetingButton = null;
28 | private JLabel greetingLabel = null;
29 |
30 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(ActionTest.class.getName());
31 |
32 | private ActionTest() {
33 | super(resourceBundle.getString("title"));
34 |
35 | setDefaultCloseOperation(EXIT_ON_CLOSE);
36 | }
37 |
38 | @Override
39 | public void run() {
40 | setContentPane(UILoader.load(this, "action-test.xml", resourceBundle));
41 |
42 | greetingButton.addActionListener(event -> sayHello());
43 |
44 | setSize(240, 180);
45 | setVisible(true);
46 | }
47 |
48 | private void sayHello() {
49 | greetingLabel.setText(resourceBundle.getString("greeting"));
50 | }
51 |
52 | public static void main(String[] args) {
53 | FlatLightLaf.setup();
54 |
55 | SwingUtilities.invokeLater(new ActionTest());
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/ActivityIndicatorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.ActivityIndicator;
19 | import org.httprpc.sierra.UILoader;
20 |
21 | import javax.swing.JFrame;
22 | import javax.swing.JToggleButton;
23 | import javax.swing.SwingUtilities;
24 | import java.util.ResourceBundle;
25 |
26 | public class ActivityIndicatorTest extends JFrame implements Runnable {
27 | private ActivityIndicator activityIndicator1 = null;
28 | private ActivityIndicator activityIndicator2 = null;
29 | private ActivityIndicator activityIndicator3 = null;
30 |
31 | private JToggleButton toggleButton = null;
32 |
33 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(ActivityIndicatorTest.class.getName());
34 |
35 | private ActivityIndicatorTest() {
36 | super(resourceBundle.getString("title"));
37 |
38 | setDefaultCloseOperation(EXIT_ON_CLOSE);
39 | }
40 |
41 | @Override
42 | public void run() {
43 | setContentPane(UILoader.load(this, "activity-indicator-test.xml", resourceBundle));
44 |
45 | toggleButton.addActionListener(event -> toggleActivityIndicators(toggleButton.isSelected()));
46 |
47 | setSize(360, 240);
48 | setVisible(true);
49 | }
50 |
51 | private void toggleActivityIndicators(boolean active) {
52 | if (active) {
53 | activityIndicator1.start();
54 | activityIndicator2.start();
55 | activityIndicator3.start();
56 | } else {
57 | activityIndicator1.stop();
58 | activityIndicator2.stop();
59 | activityIndicator3.stop();
60 | }
61 | }
62 |
63 | public static void main(String[] args) {
64 | FlatLightLaf.setup();
65 |
66 | SwingUtilities.invokeLater(new ActivityIndicatorTest());
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/AlignmentXTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 |
23 | public class AlignmentXTest extends JFrame implements Runnable {
24 | private AlignmentXTest() {
25 | super("X-Alignment Test");
26 |
27 | setDefaultCloseOperation(EXIT_ON_CLOSE);
28 | }
29 |
30 | @Override
31 | public void run() {
32 | setContentPane(UILoader.load(this, "alignment-x-test.xml"));
33 |
34 | pack();
35 | setVisible(true);
36 | }
37 |
38 | public static void main(String[] args) {
39 | FlatLightLaf.setup();
40 |
41 | SwingUtilities.invokeLater(new AlignmentXTest());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/AlignmentYTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 |
23 | public class AlignmentYTest extends JFrame implements Runnable {
24 | private AlignmentYTest() {
25 | super("Y-Alignment Test");
26 |
27 | setDefaultCloseOperation(EXIT_ON_CLOSE);
28 | }
29 |
30 | @Override
31 | public void run() {
32 | setContentPane(UILoader.load(this, "alignment-y-test.xml"));
33 |
34 | pack();
35 | setVisible(true);
36 | }
37 |
38 | public static void main(String[] args) {
39 | FlatLightLaf.setup();
40 |
41 | SwingUtilities.invokeLater(new AlignmentYTest());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/Asset.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import java.time.LocalDate;
18 |
19 | public interface Asset {
20 | String getTicker();
21 | String getName();
22 | String getExchangeCode();
23 | String getDescription();
24 | LocalDate getStartDate();
25 | LocalDate getEndDate();
26 | }
27 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/AssetPricing.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import java.time.Instant;
18 |
19 | public interface AssetPricing {
20 | Instant getDate();
21 | Double getOpen();
22 | Double getHigh();
23 | Double getLow();
24 | Double getClose();
25 | Long getVolume();
26 | }
27 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/BaselineTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 | import java.awt.Font;
23 |
24 | public class BaselineTest extends JFrame implements Runnable {
25 | private BaselineTest() {
26 | super("Baseline Test");
27 |
28 | setDefaultCloseOperation(EXIT_ON_CLOSE);
29 | }
30 |
31 | @Override
32 | public void run() {
33 | setContentPane(UILoader.load(this, "baseline-test.xml"));
34 |
35 | pack();
36 | setVisible(true);
37 | }
38 |
39 | public static void main(String[] args) {
40 | UILoader.define("small", new Font("Arial", Font.PLAIN, 12));
41 | UILoader.define("medium", new Font("Arial", Font.PLAIN, 24));
42 | UILoader.define("large", new Font("Arial", Font.BOLD, 48));
43 |
44 | FlatLightLaf.setup();
45 |
46 | SwingUtilities.invokeLater(new BaselineTest());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/BorderTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 | import java.awt.Font;
23 | import java.util.ResourceBundle;
24 |
25 | public class BorderTest extends JFrame implements Runnable {
26 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(BorderTest.class.getName());
27 |
28 | private BorderTest() {
29 | super(resourceBundle.getString("title"));
30 |
31 | setDefaultCloseOperation(EXIT_ON_CLOSE);
32 | }
33 |
34 | @Override
35 | public void run() {
36 | setContentPane(UILoader.load(this, "border-test.xml", resourceBundle));
37 |
38 | setSize(480, 320);
39 | setVisible(true);
40 | }
41 |
42 | public static void main(String[] args) {
43 | UILoader.define("h1", new Font("Arial", Font.BOLD, 24));
44 | UILoader.define("h2", new Font("Arial", Font.PLAIN, 18));
45 |
46 | FlatLightLaf.setup();
47 |
48 | SwingUtilities.invokeLater(new BorderTest());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/BoxTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 |
23 | public class BoxTest extends JFrame implements Runnable {
24 | private BoxTest() {
25 | super("Box Test");
26 |
27 | setDefaultCloseOperation(EXIT_ON_CLOSE);
28 | }
29 |
30 | @Override
31 | public void run() {
32 | setContentPane(UILoader.load(this, "box-test.xml"));
33 |
34 | pack();
35 | setVisible(true);
36 | }
37 |
38 | public static void main(String[] args) {
39 | FlatLightLaf.setup();
40 |
41 | SwingUtilities.invokeLater(new BoxTest());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/ButtonGroupTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.ButtonGroup;
21 | import javax.swing.JFrame;
22 | import javax.swing.JLabel;
23 | import javax.swing.JToggleButton;
24 | import javax.swing.SwingUtilities;
25 | import java.util.ResourceBundle;
26 |
27 | public class ButtonGroupTest extends JFrame implements Runnable {
28 | private JToggleButton alignLeftButton = null;
29 | private JToggleButton alignCenterButton = null;
30 | private JToggleButton alignRightButton = null;
31 | private JToggleButton alignJustifyButton = null;
32 |
33 | private JLabel selectionLabel = null;
34 |
35 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(ButtonGroupTest.class.getName());
36 |
37 | private ButtonGroupTest() {
38 | super(resourceBundle.getString("title"));
39 |
40 | setDefaultCloseOperation(EXIT_ON_CLOSE);
41 | }
42 |
43 | @Override
44 | public void run() {
45 | setContentPane(UILoader.load(this, "button-group-test.xml"));
46 |
47 | var buttonGroup = new ButtonGroup();
48 |
49 | buttonGroup.add(alignLeftButton);
50 | buttonGroup.add(alignCenterButton);
51 | buttonGroup.add(alignRightButton);
52 | buttonGroup.add(alignJustifyButton);
53 |
54 | alignLeftButton.addActionListener(event -> updateSelection());
55 | alignCenterButton.addActionListener(event -> updateSelection());
56 | alignRightButton.addActionListener(event -> updateSelection());
57 | alignJustifyButton.addActionListener(event -> updateSelection());
58 |
59 | alignLeftButton.setSelected(true);
60 |
61 | updateSelection();
62 |
63 | setSize(320, 120);
64 | setVisible(true);
65 | }
66 |
67 | private void updateSelection() {
68 | String text;
69 | if (alignLeftButton.isSelected()) {
70 | text = resourceBundle.getString("alignLeft");
71 | } else if (alignCenterButton.isSelected()) {
72 | text = resourceBundle.getString("alignCenter");
73 | } else if (alignRightButton.isSelected()) {
74 | text = resourceBundle.getString("alignRight");
75 | } else if (alignJustifyButton.isSelected()) {
76 | text = resourceBundle.getString("alignJustify");
77 | } else {
78 | throw new UnsupportedOperationException();
79 | }
80 |
81 | selectionLabel.setText(text);
82 | }
83 |
84 | public static void main(String[] args) {
85 | FlatLightLaf.setup();
86 |
87 | SwingUtilities.invokeLater(new ButtonGroupTest());
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/CellRendererTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS"BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.ImagePane;
19 | import org.httprpc.sierra.UILoader;
20 |
21 | import javax.imageio.ImageIO;
22 | import javax.swing.DefaultListModel;
23 | import javax.swing.JComponent;
24 | import javax.swing.JFrame;
25 | import javax.swing.JLabel;
26 | import javax.swing.JList;
27 | import javax.swing.JScrollPane;
28 | import javax.swing.ListCellRenderer;
29 | import javax.swing.SwingUtilities;
30 | import java.awt.Color;
31 | import java.awt.Component;
32 | import java.awt.Image;
33 | import java.io.IOException;
34 |
35 | public class CellRendererTest extends JFrame implements Runnable {
36 | private static class Flag {
37 | final Image image;
38 | final String name;
39 | final String description;
40 |
41 | Flag(String imageName, String name, String description) throws IOException {
42 | image = ImageIO.read(CellRendererTest.class.getResource(String.format("flags/%s", imageName)));
43 |
44 | this.name = name;
45 | this.description = description;
46 | }
47 | }
48 |
49 | private static class FlagCellRenderer implements ListCellRenderer {
50 | JComponent component;
51 |
52 | ImagePane imagePane = null;
53 | JLabel nameLabel = null;
54 | JLabel descriptionLabel = null;
55 |
56 | FlagCellRenderer() {
57 | component = UILoader.load(this, "flag-cell-renderer.xml");
58 | }
59 |
60 | @Override
61 | public Component getListCellRendererComponent(JList extends Flag> list, Flag value, int index, boolean selected, boolean cellHasFocus) {
62 | imagePane.setImage(value.image);
63 | nameLabel.setText(value.name);
64 | descriptionLabel.setText(value.description);
65 |
66 | Color background;
67 | Color foreground;
68 | if (selected) {
69 | background = list.getSelectionBackground();
70 | foreground = list.getSelectionForeground();
71 | } else {
72 | background = list.getBackground();
73 | foreground = list.getForeground();
74 | }
75 |
76 | component.setBackground(background);
77 |
78 | nameLabel.setForeground(foreground);
79 | descriptionLabel.setForeground(foreground);
80 |
81 | return component;
82 | }
83 | }
84 |
85 | private CellRendererTest() {
86 | super("Cell Renderer Test");
87 |
88 | setDefaultCloseOperation(EXIT_ON_CLOSE);
89 | }
90 |
91 | @Override
92 | public void run() {
93 | var list = new JList();
94 |
95 | var model = new DefaultListModel();
96 |
97 | try {
98 | model.addElement(new Flag("alpha.png", "Alpha", "I have a diver down; keep well clear at slow speed."));
99 | model.addElement(new Flag("bravo.png", "Bravo", "I am taking in or discharging or carrying dangerous goods."));
100 | model.addElement(new Flag("charlie.png", "Charlie", "Affirmative."));
101 | model.addElement(new Flag("delta.png", "Delta", "Keep clear of me; I am maneuvering with difficulty."));
102 | model.addElement(new Flag("echo.png", "Echo", "I am altering my course to starboard."));
103 | model.addElement(new Flag("foxtrot.png", "Foxtrot", "I am disabled; communicate with me."));
104 | model.addElement(new Flag("golf.png", "Golf", "I require a pilot."));
105 | model.addElement(new Flag("hotel.png", "Hotel", "I have a pilot on board."));
106 | model.addElement(new Flag("india.png", "India", "I am altering my course to port."));
107 | model.addElement(new Flag("juliet.png", "Juliet", "I am leaking dangerous cargo."));
108 | model.addElement(new Flag("kilo.png", "Kilo", "I wish to communicate with you."));
109 | model.addElement(new Flag("lima.png", "Lima", "You should stop your vessel instantly."));
110 | model.addElement(new Flag("mike.png", "Mike", "My vessel is stopped and making no way through the water."));
111 | model.addElement(new Flag("november.png", "November", "Negative."));
112 | model.addElement(new Flag("oscar.png", "Oscar", "Man overboard."));
113 | model.addElement(new Flag("papa.png", "Papa", "My nets have come fast upon an obstruction."));
114 | model.addElement(new Flag("quebec.png", "Quebec", "My vessel is \"healthy\" and I request free pratique."));
115 | model.addElement(new Flag("romeo.png", "Romeo", "No ICS meaning as single flag."));
116 | model.addElement(new Flag("sierra.png", "Sierra", "I am operating astern propulsion."));
117 | model.addElement(new Flag("tango.png", "Tango", "Keep clear of me."));
118 | model.addElement(new Flag("uniform.png", "Uniform", "You are running into danger."));
119 | model.addElement(new Flag("victor.png", "Victor", "I require assistance."));
120 | model.addElement(new Flag("whisky.png", "Whiskey", "I require medical assistance."));
121 | model.addElement(new Flag("xray.png", "Xray", "Stop carrying out your intentions and watch for my signals."));
122 | model.addElement(new Flag("yankee.png", "Yankee", "I am dragging my anchor."));
123 | model.addElement(new Flag("zulu.png", "Zulu", "I require a tug."));
124 | } catch (IOException exception) {
125 | throw new RuntimeException(exception);
126 | }
127 |
128 | list.setModel(model);
129 | list.setCellRenderer(new FlagCellRenderer());
130 |
131 | var scrollPane = new JScrollPane(list);
132 |
133 | scrollPane.setBorder(null);
134 |
135 | setContentPane(scrollPane);
136 |
137 | setSize(420, 560);
138 | setVisible(true);
139 | }
140 |
141 | public static void main(String[] args) {
142 | FlatLightLaf.setup();
143 |
144 | SwingUtilities.invokeLater(new CellRendererTest());
145 | }
146 | }
147 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/DateTimePickerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.DatePicker;
19 | import org.httprpc.sierra.TimePicker;
20 | import org.httprpc.sierra.UILoader;
21 |
22 | import javax.swing.DefaultComboBoxModel;
23 | import javax.swing.JCheckBox;
24 | import javax.swing.JComboBox;
25 | import javax.swing.JFrame;
26 | import javax.swing.JLabel;
27 | import javax.swing.SwingUtilities;
28 | import java.awt.ComponentOrientation;
29 | import java.time.LocalDate;
30 | import java.time.LocalTime;
31 | import java.time.format.DateTimeFormatter;
32 | import java.time.format.FormatStyle;
33 | import java.time.temporal.TemporalAccessor;
34 | import java.util.Locale;
35 | import java.util.ResourceBundle;
36 |
37 | public class DateTimePickerTest extends JFrame implements Runnable {
38 | private DatePicker datePicker = null;
39 |
40 | private TimePicker timePicker = null;
41 | private JComboBox minuteIntervalComboBox = null;
42 | private JCheckBox strictCheckBox = null;
43 |
44 | private JLabel selectionLabel = null;
45 |
46 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(DateTimePickerTest.class.getName());
47 |
48 | private DateTimePickerTest() {
49 | super(resourceBundle.getString("title"));
50 |
51 | setDefaultCloseOperation(EXIT_ON_CLOSE);
52 | }
53 |
54 | @Override
55 | public void run() {
56 | setContentPane(UILoader.load(this, "date-time-picker-test.xml", resourceBundle));
57 |
58 | var dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
59 |
60 | var now = LocalDate.now();
61 |
62 | datePicker.setMinimumDate(now.minusMonths(3));
63 | datePicker.setMaximumDate(now.plusMonths(3));
64 |
65 | datePicker.addActionListener(event -> showSelection(dateFormatter, datePicker.getDate()));
66 |
67 | var minimumTime = LocalTime.of(6, 0);
68 | var maximumTime = LocalTime.of(18, 0);
69 |
70 | var timeFormatter = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
71 |
72 | timePicker.setMinimumTime(minimumTime);
73 | timePicker.setMaximumTime(maximumTime);
74 |
75 | timePicker.addActionListener(event -> showSelection(timeFormatter, timePicker.getTime()));
76 |
77 | minuteIntervalComboBox.setModel(new DefaultComboBoxModel<>(new Integer[] {1, 2, 3, 4, 5, 6, 10, 15, 20, 30}));
78 | minuteIntervalComboBox.addActionListener(event -> timePicker.setMinuteInterval((Integer)minuteIntervalComboBox.getSelectedItem()));
79 |
80 | strictCheckBox.addActionListener(event -> timePicker.setStrict(strictCheckBox.isSelected()));
81 |
82 | applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault()));
83 |
84 | setSize(480, 320);
85 | setVisible(true);
86 | }
87 |
88 | private void showSelection(DateTimeFormatter formatter, TemporalAccessor value) {
89 | var message = String.format(resourceBundle.getString("selectionFormat"), formatter.format(value));
90 |
91 | selectionLabel.setText(message);
92 | }
93 |
94 | public static void main(String[] args) {
95 | FlatLightLaf.setup();
96 |
97 | SwingUtilities.invokeLater(new DateTimePickerTest());
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/FlowTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 |
23 | public class FlowTest extends JFrame implements Runnable {
24 | private FlowTest() {
25 | super("Flow Test");
26 |
27 | setDefaultCloseOperation(EXIT_ON_CLOSE);
28 | }
29 |
30 | @Override
31 | public void run() {
32 | setContentPane(UILoader.load(this, "flow-test.xml"));
33 |
34 | setSize(800, 240);
35 | setVisible(true);
36 | }
37 |
38 | public static void main(String[] args) {
39 | FlatLightLaf.setup();
40 |
41 | SwingUtilities.invokeLater(new FlowTest());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/FormTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.ScrollingKeyboardFocusManager;
19 | import org.httprpc.sierra.UILoader;
20 |
21 | import javax.swing.JFrame;
22 | import javax.swing.JScrollPane;
23 | import javax.swing.SwingUtilities;
24 | import java.awt.KeyboardFocusManager;
25 | import java.util.ResourceBundle;
26 |
27 | public class FormTest extends JFrame implements Runnable {
28 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(FormTest.class.getName());
29 |
30 | private FormTest() {
31 | super(resourceBundle.getString("title"));
32 |
33 | setDefaultCloseOperation(EXIT_ON_CLOSE);
34 | }
35 |
36 | @Override
37 | public void run() {
38 | var scrollPane = new JScrollPane(UILoader.load(this, "form-test.xml", resourceBundle));
39 |
40 | scrollPane.setBorder(null);
41 |
42 | setContentPane(scrollPane);
43 |
44 | setSize(480, 360);
45 | setVisible(true);
46 | }
47 |
48 | public static void main(String[] args) {
49 | FlatLightLaf.setup();
50 |
51 | KeyboardFocusManager.setCurrentKeyboardFocusManager(new ScrollingKeyboardFocusManager());
52 |
53 | SwingUtilities.invokeLater(new FormTest());
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/GreetingTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 |
23 | public class GreetingTest extends JFrame implements Runnable {
24 | private GreetingTest() {
25 | super("Greeting Test");
26 |
27 | setDefaultCloseOperation(EXIT_ON_CLOSE);
28 | }
29 |
30 | @Override
31 | public void run() {
32 | setContentPane(UILoader.load(this, "greeting-test.xml"));
33 |
34 | setSize(320, 480);
35 | setVisible(true);
36 | }
37 |
38 | public static void main(String[] args) {
39 | FlatLightLaf.setup();
40 |
41 | SwingUtilities.invokeLater(new GreetingTest());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/ImagePaneTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.ImagePane;
19 |
20 | import javax.imageio.ImageIO;
21 | import javax.swing.JFrame;
22 | import javax.swing.SwingUtilities;
23 | import javax.swing.border.LineBorder;
24 | import java.awt.Color;
25 | import java.awt.Image;
26 | import java.io.IOException;
27 |
28 | public class ImagePaneTest extends JFrame implements Runnable {
29 | private ImagePaneTest() {
30 | super("Image Pane Test");
31 |
32 | setDefaultCloseOperation(EXIT_ON_CLOSE);
33 | }
34 |
35 | @Override
36 | public void run() {
37 | Image image;
38 | try {
39 | image = ImageIO.read(getClass().getResource("world.png"));
40 | } catch (IOException exception) {
41 | image = null;
42 | }
43 |
44 | var imagePane = new ImagePane(image);
45 |
46 | imagePane.setBackground(Color.WHITE);
47 | imagePane.setOpaque(true);
48 | imagePane.setScaleMode(ImagePane.ScaleMode.FILL_HEIGHT);
49 | imagePane.setBorder(new LineBorder(Color.LIGHT_GRAY, 16));
50 |
51 | setContentPane(imagePane);
52 |
53 | pack();
54 | setVisible(true);
55 | }
56 |
57 | public static void main(String[] args) {
58 | FlatLightLaf.setup();
59 |
60 | SwingUtilities.invokeLater(new ImagePaneTest());
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/MenuButtonTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.MenuButton;
19 | import org.httprpc.sierra.UILoader;
20 |
21 | import javax.swing.JCheckBox;
22 | import javax.swing.JFrame;
23 | import javax.swing.JMenuItem;
24 | import javax.swing.JPopupMenu;
25 | import javax.swing.SwingUtilities;
26 | import java.util.ResourceBundle;
27 |
28 | public class MenuButtonTest extends JFrame implements Runnable {
29 | private MenuButton menuButton = null;
30 |
31 | private JCheckBox focusableCheckBox = null;
32 |
33 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(MenuButtonTest.class.getName());
34 |
35 | private MenuButtonTest() {
36 | super(resourceBundle.getString("title"));
37 |
38 | setDefaultCloseOperation(EXIT_ON_CLOSE);
39 | }
40 |
41 | @Override
42 | public void run() {
43 | setContentPane(UILoader.load(this, "menu-button-test.xml", resourceBundle));
44 |
45 | var popupMenu = new JPopupMenu();
46 |
47 | popupMenu.add(new JMenuItem(resourceBundle.getString("item1")));
48 | popupMenu.add(new JMenuItem(resourceBundle.getString("item2")));
49 | popupMenu.add(new JMenuItem(resourceBundle.getString("item3")));
50 |
51 | menuButton.setPopupMenu(popupMenu);
52 |
53 | focusableCheckBox.addActionListener(event -> toggleFocusable());
54 | focusableCheckBox.setSelected(true);
55 |
56 | setSize(480, 360);
57 | setVisible(true);
58 | }
59 |
60 | private void toggleFocusable() {
61 | menuButton.setFocusable(focusableCheckBox.isSelected());
62 | }
63 |
64 | public static void main(String[] args) {
65 | FlatLightLaf.setup();
66 |
67 | SwingUtilities.invokeLater(new MenuButtonTest());
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/OrientationTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.RowPanel;
19 | import org.httprpc.sierra.UILoader;
20 |
21 | import javax.swing.JButton;
22 | import javax.swing.JFrame;
23 | import javax.swing.JRadioButton;
24 | import javax.swing.SwingUtilities;
25 | import java.awt.ComponentOrientation;
26 | import java.util.ResourceBundle;
27 |
28 | public class OrientationTest extends JFrame implements Runnable {
29 | private RowPanel rowPanel = null;
30 |
31 | private JRadioButton leftToRightButton = null;
32 | private JRadioButton rightToLeftButton = null;
33 |
34 | private JButton applyOrientationButton = null;
35 |
36 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(OrientationTest.class.getName());
37 |
38 | private OrientationTest() {
39 | super(resourceBundle.getString("title"));
40 |
41 | setDefaultCloseOperation(EXIT_ON_CLOSE);
42 | }
43 |
44 | @Override
45 | public void run() {
46 | setContentPane(UILoader.load(this, "orientation-test.xml", resourceBundle));
47 |
48 | leftToRightButton.setSelected(true);
49 |
50 | applyOrientationButton.addActionListener(event -> applyOrientation());
51 |
52 | pack();
53 | setVisible(true);
54 | }
55 |
56 | private void applyOrientation() {
57 | if (leftToRightButton.isSelected()) {
58 | rowPanel.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
59 | } else if (rightToLeftButton.isSelected()) {
60 | rowPanel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
61 | } else {
62 | throw new UnsupportedOperationException();
63 | }
64 |
65 | rowPanel.revalidate();
66 | }
67 |
68 | public static void main(String[] args) {
69 | FlatLightLaf.setup();
70 |
71 | SwingUtilities.invokeLater(new OrientationTest());
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/StackTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 |
23 | public class StackTest extends JFrame implements Runnable {
24 | private StackTest() {
25 | super("Stack Test");
26 |
27 | setDefaultCloseOperation(EXIT_ON_CLOSE);
28 | }
29 |
30 | @Override
31 | public void run() {
32 | setContentPane(UILoader.load(this, "stack-test.xml"));
33 |
34 | pack();
35 | setVisible(true);
36 | }
37 |
38 | public static void main(String[] args) {
39 | FlatLightLaf.setup();
40 |
41 | SwingUtilities.invokeLater(new StackTest());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/SuggestionPickerTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.SuggestionPicker;
19 | import org.httprpc.sierra.UILoader;
20 |
21 | import javax.swing.JFrame;
22 | import javax.swing.SwingUtilities;
23 |
24 | import static org.httprpc.kilo.util.Collections.*;
25 |
26 | public class SuggestionPickerTest extends JFrame implements Runnable {
27 | private SuggestionPicker sizeSuggestionPicker = null;
28 | private SuggestionPicker colorSuggestionPicker = null;
29 |
30 | private SuggestionPickerTest() {
31 | super("Suggestion Picker Test");
32 |
33 | setDefaultCloseOperation(EXIT_ON_CLOSE);
34 | }
35 |
36 | @Override
37 | public void run() {
38 | setContentPane(UILoader.load(this, "suggestion-picker-test.xml"));
39 |
40 | sizeSuggestionPicker.setSuggestions(listOf(
41 | "small",
42 | "medium",
43 | "large"
44 | ));
45 |
46 | sizeSuggestionPicker.addActionListener(event -> System.out.println(sizeSuggestionPicker.getText()));
47 |
48 | colorSuggestionPicker.setSuggestions(listOf(
49 | "red",
50 | "orange",
51 | "yellow",
52 | "green",
53 | "blue",
54 | "purple",
55 | "brown",
56 | "black"
57 | ));
58 |
59 | colorSuggestionPicker.addActionListener(event -> System.out.println(colorSuggestionPicker.getText()));
60 |
61 | setSize(320, 240);
62 | setVisible(true);
63 | }
64 |
65 | public static void main(String[] args) {
66 | FlatLightLaf.setup();
67 |
68 | SwingUtilities.invokeLater(new SuggestionPickerTest());
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/TaskExecutorTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.ActivityIndicator;
19 | import org.httprpc.sierra.TaskExecutor;
20 | import org.httprpc.sierra.UILoader;
21 |
22 | import javax.swing.JButton;
23 | import javax.swing.JFrame;
24 | import javax.swing.JLabel;
25 | import javax.swing.SwingUtilities;
26 | import java.util.ResourceBundle;
27 | import java.util.concurrent.Executors;
28 |
29 | public class TaskExecutorTest extends JFrame implements Runnable {
30 | private JButton button = null;
31 | private JLabel label = null;
32 | private ActivityIndicator activityIndicator = null;
33 |
34 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(TaskExecutorTest.class.getName());
35 |
36 | private static final TaskExecutor taskExecutor = new TaskExecutor(Executors.newCachedThreadPool(runnable -> {
37 | var thread = new Thread(runnable);
38 |
39 | thread.setDaemon(true);
40 |
41 | return thread;
42 | }));
43 |
44 | private TaskExecutorTest() {
45 | super(resourceBundle.getString("title"));
46 |
47 | setDefaultCloseOperation(EXIT_ON_CLOSE);
48 | }
49 |
50 | @Override
51 | public void run() {
52 | setContentPane(UILoader.load(this, "task-executor-test.xml", resourceBundle));
53 |
54 | button.addActionListener(event -> executeTask());
55 |
56 | setSize(320, 180);
57 | setVisible(true);
58 | }
59 |
60 | private void executeTask() {
61 | button.setEnabled(false);
62 |
63 | label.setText(resourceBundle.getString("executingTask"));
64 |
65 | activityIndicator.start();
66 |
67 | taskExecutor.execute(() -> {
68 | var value = Math.random();
69 |
70 | Thread.sleep((long)(5000 * value));
71 |
72 | if (value < 0.5) {
73 | throw new Exception();
74 | }
75 |
76 | return 100.0;
77 | }, (result, exception) -> {
78 | button.setEnabled(true);
79 |
80 | if (exception == null) {
81 | label.setText(String.format(resourceBundle.getString("taskCompleteFormat"), result));
82 | } else {
83 | label.setText(resourceBundle.getString("taskFailed"));
84 | }
85 |
86 | activityIndicator.stop();
87 | });
88 | }
89 |
90 | public static void main(String[] args) {
91 | FlatLightLaf.setup();
92 |
93 | SwingUtilities.invokeLater(new TaskExecutorTest());
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/TextFieldTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.UILoader;
19 |
20 | import javax.swing.JFrame;
21 | import javax.swing.SwingUtilities;
22 | import java.util.ResourceBundle;
23 |
24 | public class TextFieldTest extends JFrame implements Runnable {
25 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(TextFieldTest.class.getName());
26 |
27 | private TextFieldTest() {
28 | super(resourceBundle.getString("title"));
29 |
30 | setDefaultCloseOperation(EXIT_ON_CLOSE);
31 | }
32 |
33 | @Override
34 | public void run() {
35 | setContentPane(UILoader.load(this, "text-field-test.xml", resourceBundle));
36 |
37 | pack();
38 | setVisible(true);
39 | }
40 |
41 | public static void main(String[] args) {
42 | FlatLightLaf.setup();
43 |
44 | SwingUtilities.invokeLater(new TextFieldTest());
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/TextPaneTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.sierra.HorizontalAlignment;
19 | import org.httprpc.sierra.TextPane;
20 | import org.httprpc.sierra.VerticalAlignment;
21 |
22 | import javax.swing.JFrame;
23 | import javax.swing.SwingUtilities;
24 | import javax.swing.border.LineBorder;
25 | import java.awt.Color;
26 |
27 | public class TextPaneTest extends JFrame implements Runnable {
28 | private TextPaneTest() {
29 | super("Text Pane Test");
30 |
31 | setDefaultCloseOperation(EXIT_ON_CLOSE);
32 | }
33 |
34 | @Override
35 | public void run() {
36 | var textPane = new TextPane("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.");
37 |
38 | textPane.setBackground(Color.WHITE);
39 | textPane.setOpaque(true);
40 | textPane.setWrapText(true);
41 | textPane.setHorizontalAlignment(HorizontalAlignment.CENTER);
42 | textPane.setVerticalAlignment(VerticalAlignment.CENTER);
43 | textPane.setBorder(new LineBorder(Color.LIGHT_GRAY, 16));
44 |
45 | setContentPane(textPane);
46 |
47 | pack();
48 | setVisible(true);
49 | }
50 |
51 | public static void main(String[] args) {
52 | FlatLightLaf.setup();
53 |
54 | SwingUtilities.invokeLater(new TextPaneTest());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/TiingoServiceProxy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import org.httprpc.kilo.RequestMethod;
18 | import org.httprpc.kilo.ResourcePath;
19 | import org.httprpc.kilo.ServicePath;
20 |
21 | import java.io.IOException;
22 | import java.time.LocalDate;
23 | import java.util.List;
24 |
25 | @ServicePath("tiingo")
26 | public interface TiingoServiceProxy {
27 | @RequestMethod("GET")
28 | @ResourcePath("daily/?")
29 | Asset getAsset(String ticker) throws IOException;
30 |
31 | @RequestMethod("GET")
32 | @ResourcePath("daily/?/prices")
33 | List getHistoricalPricing(String ticker, LocalDate startDate, LocalDate endDate) throws IOException;
34 | }
35 |
--------------------------------------------------------------------------------
/sierra-test/src/main/java/org/httprpc/sierra/test/TiingoTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra.test;
16 |
17 | import com.formdev.flatlaf.FlatLightLaf;
18 | import org.httprpc.kilo.WebServiceProxy;
19 | import org.httprpc.kilo.beans.BeanAdapter;
20 | import org.httprpc.sierra.ActivityIndicator;
21 | import org.httprpc.sierra.TaskExecutor;
22 | import org.httprpc.sierra.TextPane;
23 | import org.httprpc.sierra.UILoader;
24 |
25 | import javax.swing.JButton;
26 | import javax.swing.JComponent;
27 | import javax.swing.JFrame;
28 | import javax.swing.JOptionPane;
29 | import javax.swing.JTable;
30 | import javax.swing.JTextField;
31 | import javax.swing.ListSelectionModel;
32 | import javax.swing.SwingConstants;
33 | import javax.swing.SwingUtilities;
34 | import javax.swing.event.TableModelListener;
35 | import javax.swing.table.DefaultTableCellRenderer;
36 | import javax.swing.table.TableModel;
37 | import java.net.URI;
38 | import java.text.NumberFormat;
39 | import java.time.Instant;
40 | import java.time.LocalDate;
41 | import java.time.ZoneId;
42 | import java.time.format.DateTimeFormatter;
43 | import java.time.format.FormatStyle;
44 | import java.util.Comparator;
45 | import java.util.List;
46 | import java.util.Locale;
47 | import java.util.ResourceBundle;
48 | import java.util.concurrent.Executors;
49 |
50 | import static org.httprpc.kilo.util.Collections.*;
51 | import static org.httprpc.kilo.util.Optionals.*;
52 |
53 | public class TiingoTest extends JFrame implements Runnable {
54 | private static class HistoricalPricingTableModel implements TableModel {
55 | private List values;
56 |
57 | private List columns = listOf("date", "open", "high", "low", "close", "volume");
58 |
59 | public HistoricalPricingTableModel(List rows) {
60 | values = rows.stream().map(BeanAdapter::new).toList();
61 | }
62 |
63 | @Override
64 | public int getRowCount() {
65 | return values.size();
66 | }
67 |
68 | @Override
69 | public int getColumnCount() {
70 | return columns.size();
71 | }
72 |
73 | @Override
74 | public String getColumnName(int columnIndex) {
75 | return resourceBundle.getString(columns.get(columnIndex));
76 | }
77 |
78 | @Override
79 | public Class> getColumnClass(int columnIndex) {
80 | return Object.class;
81 | }
82 |
83 | @Override
84 | public boolean isCellEditable(int rowIndex, int columnIndex) {
85 | return false;
86 | }
87 |
88 | @Override
89 | public Object getValueAt(int rowIndex, int columnIndex) {
90 | return values.get(rowIndex).get(columns.get(columnIndex));
91 | }
92 |
93 | @Override
94 | public void setValueAt(Object value, int rowIndex, int columnIndex) {
95 | throw new UnsupportedOperationException();
96 | }
97 |
98 | @Override
99 | public void addTableModelListener(TableModelListener listener) {
100 | // No-op
101 | }
102 |
103 | @Override
104 | public void removeTableModelListener(TableModelListener listener) {
105 | // No-op
106 | }
107 | }
108 |
109 | private static class DateCellRenderer extends DefaultTableCellRenderer {
110 | static DateTimeFormatter dateFormatter;
111 | static {
112 | dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).withZone(ZoneId.of("America/New_York"));
113 | }
114 |
115 | @Override
116 | public void setValue(Object value) {
117 | setText(map((Instant)value, dateFormatter::format));
118 | }
119 | }
120 |
121 | private static class PriceCellRenderer extends DefaultTableCellRenderer {
122 | static NumberFormat priceFormat;
123 | static {
124 | priceFormat = NumberFormat.getCurrencyInstance(Locale.US);
125 | }
126 |
127 | PriceCellRenderer() {
128 | setHorizontalAlignment(SwingConstants.TRAILING);
129 | }
130 |
131 | @Override
132 | public void setValue(Object value) {
133 | setText(map((Number)value, priceFormat::format));
134 | }
135 | }
136 |
137 | private static class VolumeCellRenderer extends DefaultTableCellRenderer {
138 | static NumberFormat volumeFormat;
139 | static {
140 | volumeFormat = NumberFormat.getNumberInstance();
141 |
142 | volumeFormat.setGroupingUsed(true);
143 | }
144 |
145 | VolumeCellRenderer() {
146 | setHorizontalAlignment(SwingConstants.TRAILING);
147 | }
148 |
149 | @Override
150 | public void setValue(Object value) {
151 | setText(map((Number)value, volumeFormat::format));
152 | }
153 | }
154 |
155 | private JTextField tickerTextField = null;
156 | private JTextField countTextField = null;
157 |
158 | private ActivityIndicator activityIndicator = null;
159 |
160 | private JButton submitButton = null;
161 |
162 | private JTextField nameTextField = null;
163 | private JTextField exchangeCodeTextField = null;
164 | private JTextField startDateTextField = null;
165 | private JTextField endDateTextField = null;
166 |
167 | private TextPane descriptionTextPane = null;
168 |
169 | private JTable historicalPricingTable = null;
170 |
171 | private static final ResourceBundle resourceBundle = ResourceBundle.getBundle(TiingoTest.class.getName());
172 |
173 | private static final TaskExecutor taskExecutor = new TaskExecutor(Executors.newCachedThreadPool(runnable -> {
174 | var thread = new Thread(runnable);
175 |
176 | thread.setDaemon(true);
177 |
178 | return thread;
179 | }));
180 |
181 | private static final URI baseURI = URI.create("https://api.tiingo.com/");
182 |
183 | private TiingoTest() {
184 | super(resourceBundle.getString("title"));
185 |
186 | setDefaultCloseOperation(EXIT_ON_CLOSE);
187 | }
188 |
189 | @Override
190 | public void run() {
191 | setContentPane(UILoader.load(this, "tiingo-test.xml", resourceBundle));
192 |
193 | countTextField.setText(Integer.toString(30));
194 |
195 | submitButton.addActionListener(event -> submit());
196 |
197 | rootPane.setDefaultButton(submitButton);
198 |
199 | setSize(960, 540);
200 | setVisible(true);
201 | }
202 |
203 | private void submit() {
204 | var token = System.getProperty("token");
205 |
206 | if (token == null) {
207 | showErrorMessage("apiTokenRequired", null);
208 | return;
209 | }
210 |
211 | var ticker = tickerTextField.getText().trim();
212 |
213 | if (ticker.isEmpty()) {
214 | showErrorMessage("tickerRequired", tickerTextField);
215 | return;
216 | }
217 |
218 | var countText = countTextField.getText().trim();
219 |
220 | if (countText.isEmpty()) {
221 | showErrorMessage("countRequired", countTextField);
222 | return;
223 | }
224 |
225 | int count;
226 | try {
227 | count = Integer.parseInt(countText);
228 | } catch (NumberFormatException exception) {
229 | showErrorMessage("invalidCount", countTextField);
230 | return;
231 | }
232 |
233 | var endDate = LocalDate.now();
234 | var startDate = endDate.minusDays(count);
235 |
236 | submitButton.setEnabled(false);
237 |
238 | activityIndicator.start();
239 |
240 | var tiingoServiceProxy = WebServiceProxy.of(TiingoServiceProxy.class, baseURI, mapOf(
241 | entry("Authorization", String.format("Token %s", token))
242 | ));
243 |
244 | taskExecutor.execute(() -> tiingoServiceProxy.getAsset(ticker), (result, exception) -> {
245 | if (exception == null) {
246 | updateAsset(result);
247 | } else {
248 | exception.printStackTrace(System.out);
249 | }
250 | });
251 |
252 | taskExecutor.execute(() -> tiingoServiceProxy.getHistoricalPricing(ticker, startDate, endDate), (result, exception) -> {
253 | if (exception == null) {
254 | updateHistoricalPricing(result);
255 | } else {
256 | exception.printStackTrace(System.out);
257 | }
258 | });
259 |
260 | taskExecutor.notify(() -> {
261 | submitButton.setEnabled(true);
262 |
263 | activityIndicator.stop();
264 | });
265 | }
266 |
267 | private void showErrorMessage(String messageKey, JComponent component) {
268 | JOptionPane.showMessageDialog(this,
269 | resourceBundle.getString(messageKey),
270 | resourceBundle.getString("error"),
271 | JOptionPane.ERROR_MESSAGE);
272 |
273 | if (component != null) {
274 | component.requestFocus();
275 | }
276 | }
277 |
278 | private void updateAsset(Asset asset) {
279 | nameTextField.setText(asset.getName());
280 | nameTextField.setCaretPosition(0);
281 |
282 | exchangeCodeTextField.setText(asset.getExchangeCode());
283 |
284 | var dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
285 |
286 | startDateTextField.setText(dateFormatter.format(asset.getStartDate()));
287 | endDateTextField.setText(dateFormatter.format(asset.getEndDate()));
288 |
289 | descriptionTextPane.setText(asset.getDescription());
290 | }
291 |
292 | private void updateHistoricalPricing(List historicalPricing) {
293 | historicalPricing.sort(Comparator.comparing(AssetPricing::getDate).reversed());
294 |
295 | historicalPricingTable.setModel(new HistoricalPricingTableModel(historicalPricing));
296 |
297 | var columnModel = historicalPricingTable.getColumnModel();
298 |
299 | columnModel.getColumn(0).setCellRenderer(new DateCellRenderer());
300 |
301 | var priceRenderer = new PriceCellRenderer();
302 |
303 | columnModel.getColumn(1).setCellRenderer(priceRenderer);
304 | columnModel.getColumn(2).setCellRenderer(priceRenderer);
305 | columnModel.getColumn(3).setCellRenderer(priceRenderer);
306 | columnModel.getColumn(4).setCellRenderer(priceRenderer);
307 |
308 | columnModel.getColumn(5).setCellRenderer(new VolumeCellRenderer());
309 |
310 | historicalPricingTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
311 | }
312 |
313 | public static void main(String[] args) {
314 | FlatLightLaf.setup();
315 |
316 | SwingUtilities.invokeLater(new TiingoTest());
317 | }
318 | }
319 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/ActionTest.properties:
--------------------------------------------------------------------------------
1 | title = Action Test
2 |
3 | prompt = Say Hello
4 | greeting = Hello, World!
5 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/ActivityIndicatorTest.properties:
--------------------------------------------------------------------------------
1 | title = Activity Indicator Test
2 |
3 | active = Active
4 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/BorderTest.properties:
--------------------------------------------------------------------------------
1 | title = Border Test
2 |
3 | pageStart = Page Start
4 | lineStart = Line Start
5 | center = Center
6 | lineEnd = Line End
7 | pageEnd = Page End
8 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/ButtonGroupTest.properties:
--------------------------------------------------------------------------------
1 | title = Button Group Test
2 |
3 | alignLeft = Align left
4 | alignCenter = Align center
5 | alignRight = Align right
6 | alignJustify = Align justify
7 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/DateTimePickerTest.properties:
--------------------------------------------------------------------------------
1 | title = Date/Time Picker Test
2 |
3 | date = Date
4 | time = Time
5 | minuteInterval = Minute Interval
6 | strict = Strict
7 |
8 | selectionFormat = You selected %s.
9 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/FormTest.properties:
--------------------------------------------------------------------------------
1 | title = Form Test
2 |
3 | firstName = First Name
4 | lastName = Last Name
5 | streetAddress = Street Address
6 | city = City
7 | state = State
8 | postalCode = Postal Code
9 |
10 | emailAddress = Email Address
11 | homePhone = Home Phone
12 | mobilePhone = Mobile Phone
13 | fax = Fax
14 |
15 | field1 = Field 1
16 | field2 = Field 2
17 | field3 = Field 3
18 | field4 = Field 4
19 |
20 | notes = Notes
21 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/MenuButtonTest.properties:
--------------------------------------------------------------------------------
1 | title = Menu Button Test
2 |
3 | showMenu = Show Menu
4 |
5 | item1 = Item 1
6 | item2 = Item 2
7 | item3 = Item 3
8 |
9 | focusable = Focusable
10 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/OrientationTest.properties:
--------------------------------------------------------------------------------
1 | title = Orientation Test
2 |
3 | button1Text = 1
4 | button2Text = 2
5 | button3Text = 3
6 | button4Text = 4
7 | button5Text = 5
8 |
9 | leftToRight = Left to right
10 | rightToLeft = Right to left
11 |
12 | applyOrientation = Apply Orientation
13 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/TaskExecutorTest.properties:
--------------------------------------------------------------------------------
1 | title = Task Executor Test
2 |
3 | checkBox1 = Check box 1
4 | checkBox2 = Check box 2
5 |
6 | executeTask = Execute Task
7 |
8 | executingTask = Executing task...
9 | taskCompleteFormat = Task %.1f%% complete
10 | taskFailed = Task failed
11 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/TextFieldTest.properties:
--------------------------------------------------------------------------------
1 | title = Text Field Test
2 |
3 | firstName = First Name
4 | lastName = Last Name
5 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/TiingoTest.properties:
--------------------------------------------------------------------------------
1 | title = Tiingo Test
2 |
3 | ticker = Ticker
4 | count = Count
5 | submit = Submit
6 |
7 | name = Name
8 | exchangeCode = Exchange Code
9 | description = Description
10 | startDate = Start Date
11 | endDate = End Date
12 |
13 | date = Date
14 | open = Open
15 | high = High
16 | low = Low
17 | close = Close
18 | volume = Volume
19 |
20 | error = Error
21 | apiTokenRequired = API token is required.
22 | tickerRequired = Ticker is required.
23 | countRequired = Count is required.
24 | invalidCount = Invalid count.
25 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/action-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/activity-indicator-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/alignment-x-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/alignment-y-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/baseline-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/border-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/box-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/button-group-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/date-time-picker-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flag-cell-renderer.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/alpha.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/alpha.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/bravo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/bravo.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/charlie.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/charlie.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/delta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/delta.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/echo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/echo.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/foxtrot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/foxtrot.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/golf.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/golf.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/hotel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/hotel.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/india.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/india.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/juliet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/juliet.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/kilo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/kilo.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/lima.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/lima.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/mike.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/mike.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/november.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/november.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/oscar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/oscar.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/papa.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/papa.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/quebec.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/quebec.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/romeo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/romeo.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/sierra.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/sierra.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/tango.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/tango.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/uniform.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/uniform.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/victor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/victor.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/whisky.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/whisky.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/xray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/xray.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/yankee.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/yankee.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/zulu.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/flags/zulu.png
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/flow-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/form-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/format_align_center_black_18dp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/format_align_justify_black_18dp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/format_align_left_black_18dp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/format_align_right_black_18dp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/greeting-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/menu-button-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/orientation-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/people_18dp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/search_18dp.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/stack-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
25 |
26 |
31 |
32 |
37 |
38 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/suggestion-picker-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/task-executor-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/text-field-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/tiingo-test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/sierra-test/src/main/resources/org/httprpc/sierra/test/world.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra-test/src/main/resources/org/httprpc/sierra/test/world.png
--------------------------------------------------------------------------------
/sierra.dtd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/sierra.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HTTP-RPC/Sierra/5065bad4e0745a0f11b3f6e618598f2fb9e75425/sierra.png
--------------------------------------------------------------------------------
/sierra/build.gradle:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | apply from: rootProject.file('publish.gradle')
16 |
17 | dependencies {
18 | api "org.httprpc:kilo-client:${kiloVersion}"
19 |
20 | compileOnly "com.formdev:flatlaf-extras:${flatLafVersion}"
21 | }
22 |
--------------------------------------------------------------------------------
/sierra/src/main/java/org/httprpc/sierra/ActivityIndicator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra;
16 |
17 | import javax.swing.JComponent;
18 | import javax.swing.Timer;
19 | import javax.swing.UIManager;
20 | import javax.swing.plaf.ComponentUI;
21 | import java.awt.Color;
22 | import java.awt.Dimension;
23 | import java.awt.Graphics;
24 | import java.awt.Graphics2D;
25 | import java.awt.RenderingHints;
26 | import java.awt.Shape;
27 | import java.awt.geom.RoundRectangle2D;
28 | import java.util.LinkedList;
29 | import java.util.List;
30 |
31 | /**
32 | * Shows indeterminate progress.
33 | */
34 | public class ActivityIndicator extends JComponent {
35 | private class ActivityIndicatorUI extends ComponentUI {
36 | @Override
37 | public Dimension getMinimumSize(JComponent component) {
38 | return new Dimension(0, 0);
39 | }
40 |
41 | @Override
42 | public Dimension getMaximumSize(JComponent component) {
43 | return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
44 | }
45 |
46 | @Override
47 | public Dimension getPreferredSize(JComponent component) {
48 | var insets = getInsets();
49 |
50 | return new Dimension(indicatorSize + insets.left + insets.right, indicatorSize + insets.top + insets.bottom);
51 | }
52 |
53 | @Override
54 | public int getBaseline(JComponent component, int width, int height) {
55 | return -1;
56 | }
57 |
58 | @Override
59 | public void paint(Graphics graphics, JComponent component) {
60 | paint((Graphics2D)graphics);
61 | }
62 |
63 | private void paint(Graphics2D graphics) {
64 | if (!active) {
65 | return;
66 | }
67 |
68 | var size = getSize();
69 | var insets = getInsets();
70 |
71 | var width = Math.max(size.width - (insets.left + insets.right), 0);
72 | var height = Math.max(size.height - (insets.top + insets.bottom), 0);
73 |
74 | graphics = (Graphics2D)graphics.create();
75 |
76 | graphics.setClip(insets.left, insets.top, width, height);
77 |
78 | graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
79 |
80 | var radius = indicatorSize / 2;
81 |
82 | var x = (width - indicatorSize) / 2 + insets.left + radius;
83 | var y = (height - indicatorSize) / 2 + insets.top + radius;
84 |
85 | graphics.translate(x, y);
86 |
87 | graphics.rotate((angle % 360) * Math.PI / 180);
88 |
89 | var foreground = getForeground();
90 |
91 | for (var i = 0; i < SPOKE_COUNT; i++) {
92 | var alpha = (int)Math.round((i * (1.0 / SPOKE_COUNT)) * 255);
93 |
94 | var color = new Color(foreground.getRed(), foreground.getGreen(), foreground.getBlue(), alpha);
95 |
96 | graphics.setColor(color);
97 | graphics.fill(spokeShape);
98 |
99 | graphics.rotate(INCREMENT);
100 | }
101 |
102 | graphics.dispose();
103 | }
104 | }
105 |
106 | private int indicatorSize;
107 |
108 | private Shape spokeShape;
109 |
110 | private boolean active = false;
111 |
112 | private static int angle = 0;
113 |
114 | private static List activeInstances = new LinkedList<>();
115 |
116 | private static final int SPOKE_COUNT = 8;
117 |
118 | private static final double INCREMENT = (2 * Math.PI) / SPOKE_COUNT;
119 |
120 | private static Timer timer = new Timer(100, event -> {
121 | angle = (angle + 360 / SPOKE_COUNT) % 360;
122 |
123 | for (var instance : activeInstances) {
124 | instance.repaint();
125 | }
126 | });
127 |
128 | /**
129 | * Constructs a new activity indicator.
130 | */
131 | public ActivityIndicator() {
132 | this(24);
133 | }
134 |
135 | /**
136 | * Constructs a new activity indicator.
137 | *
138 | * @param indicatorSize
139 | * The indicator size.
140 | */
141 | public ActivityIndicator(int indicatorSize) {
142 | setIndicatorSize(indicatorSize);
143 |
144 | setUI(new ActivityIndicatorUI());
145 |
146 | if (UIManager.getLookAndFeelDefaults().get("Label.disabledForeground") instanceof Color foreground) {
147 | setForeground(foreground);
148 | }
149 | }
150 |
151 | /**
152 | * Returns the indicator size.
153 | *
154 | * @return
155 | * The indicator size.
156 | */
157 | public int getIndicatorSize() {
158 | return indicatorSize;
159 | }
160 |
161 | /**
162 | * Sets the indicator size.
163 | *
164 | * @param indicatorSize
165 | * The indicator size.
166 | */
167 | public void setIndicatorSize(int indicatorSize) {
168 | if (indicatorSize < 12) {
169 | throw new IllegalArgumentException();
170 | }
171 |
172 | this.indicatorSize = indicatorSize;
173 |
174 | var spokeWidth = indicatorSize / 3.0;
175 | var spokeHeight = indicatorSize / 8.0;
176 |
177 | spokeShape = new RoundRectangle2D.Double(spokeWidth / 2, -spokeHeight / 2, spokeWidth, spokeHeight, spokeHeight, spokeHeight);
178 |
179 | revalidate();
180 | }
181 |
182 | /**
183 | * Indicates that the activity indicator is active.
184 | *
185 | * @return
186 | * {@code true} if the indicator is active; {@code false}, otherwise.
187 | */
188 | public boolean isActive() {
189 | return active;
190 | }
191 |
192 | /**
193 | * Starts the activity indicator.
194 | */
195 | public void start() {
196 | repaint();
197 |
198 | if (activeInstances.isEmpty()) {
199 | timer.start();
200 | }
201 |
202 | activeInstances.add(this);
203 |
204 | active = true;
205 | }
206 |
207 | /**
208 | * Stops the activity indicator.
209 | */
210 | public void stop() {
211 | active = false;
212 |
213 | activeInstances.remove(this);
214 |
215 | if (activeInstances.isEmpty()) {
216 | timer.stop();
217 | }
218 |
219 | repaint();
220 | }
221 | }
222 |
--------------------------------------------------------------------------------
/sierra/src/main/java/org/httprpc/sierra/BoxPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra;
16 |
17 | /**
18 | * Abstract base class for box panels.
19 | */
20 | public abstract class BoxPanel extends LayoutPanel {
21 | private int spacing = 0;
22 |
23 | /**
24 | * Returns the amount of space between successive sub-components. The
25 | * default value is 0.
26 | *
27 | * @return
28 | * The sub-component spacing.
29 | */
30 | public int getSpacing() {
31 | return spacing;
32 | }
33 |
34 | /**
35 | * Sets the amount of space between successive sub-components.
36 | *
37 | * @param spacing
38 | * The sub-component spacing.
39 | */
40 | public void setSpacing(int spacing) {
41 | if (spacing < 0) {
42 | throw new IllegalArgumentException();
43 | }
44 |
45 | this.spacing = spacing;
46 |
47 | revalidate();
48 | }
49 |
50 | /**
51 | * Returns the weight associated with the component at a given index.
52 | *
53 | * @param index
54 | * The component index.
55 | *
56 | * @return
57 | * The component's weight, or {@link Double#NaN} if no weight is associated
58 | * with the component.
59 | */
60 | protected double getWeight(int index) {
61 | var constraints = getConstraints(index);
62 |
63 | if (constraints instanceof Double weight) {
64 | if (weight <= 0.0) {
65 | throw new IllegalStateException();
66 | }
67 |
68 | return weight;
69 | } else {
70 | return Double.NaN;
71 | }
72 | }
73 |
74 | /**
75 | * Calculates the panel's baseline, as determined by the first component
76 | * that reports a valid baseline.
77 | * {@inheritDoc}
78 | */
79 | @Override
80 | public int getBaseline(int width, int height) {
81 | setSize(width, height);
82 | validate();
83 |
84 | var n = getComponentCount();
85 |
86 | for (var i = 0; i < n; i++) {
87 | var component = getComponent(i);
88 |
89 | var baseline = component.getBaseline(component.getWidth(), component.getHeight());
90 |
91 | if (baseline >= 0) {
92 | return component.getY() + baseline;
93 | }
94 | }
95 |
96 | return -1;
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/sierra/src/main/java/org/httprpc/sierra/ColumnPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra;
16 |
17 | import java.awt.Dimension;
18 | import java.awt.LayoutManager;
19 | import java.util.LinkedList;
20 | import java.util.List;
21 |
22 | /**
23 | * Arranges sub-components in a vertical line. The panel's preferred width is
24 | * the maximum preferred width of its sub-components plus horizontal insets.
25 | * Preferred height is the total preferred height of all unweighted
26 | * sub-components plus vertical insets.
27 | */
28 | public class ColumnPanel extends BoxPanel {
29 | // Column layout manager
30 | private class ColumnLayoutManager extends AbstractLayoutManager {
31 | @Override
32 | public Dimension preferredLayoutSize() {
33 | columnWidths.clear();
34 |
35 | var size = getSize();
36 | var insets = getInsets();
37 |
38 | var width = Math.max(size.width - (insets.left + insets.right), 0);
39 |
40 | var preferredWidth = 0;
41 | var preferredHeight = 0;
42 |
43 | var n = getComponentCount();
44 |
45 | for (var i = 0; i < n; i++) {
46 | var component = getComponent(i);
47 |
48 | component.setSize(width, Integer.MAX_VALUE);
49 |
50 | if (alignToGrid && component instanceof RowPanel) {
51 | component.doLayout();
52 | } else {
53 | var preferredSize = component.getPreferredSize();
54 |
55 | preferredWidth = Math.max(preferredWidth, preferredSize.width);
56 |
57 | if (Double.isNaN(getWeight(i))) {
58 | preferredHeight += preferredSize.height;
59 | }
60 | }
61 | }
62 |
63 | var spacing = getSpacing();
64 |
65 | if (alignToGrid) {
66 | preferredWidth = columnWidths.stream().reduce(0, Integer::sum) + (columnWidths.size() - 1) * spacing;
67 |
68 | for (var i = 0; i < n; i++) {
69 | var component = getComponent(i);
70 |
71 | if (Double.isNaN(getWeight(i)) && component instanceof RowPanel) {
72 | preferredHeight += component.getPreferredSize().height;
73 | }
74 | }
75 | }
76 |
77 | preferredHeight += spacing * (n - 1);
78 |
79 | return new Dimension(preferredWidth + insets.left + insets.right, preferredHeight + insets.top + insets.bottom);
80 | }
81 |
82 | @Override
83 | public void layoutContainer() {
84 | columnWidths.clear();
85 |
86 | var size = getSize();
87 | var insets = getInsets();
88 |
89 | var width = Math.max(size.width - (insets.left + insets.right), 0);
90 |
91 | var totalWeight = 0.0;
92 | var excessHeight = Math.max(size.height - (insets.top + insets.bottom), 0);
93 |
94 | var n = getComponentCount();
95 |
96 | for (var i = 0; i < n; i++) {
97 | var component = getComponent(i);
98 |
99 | var weight = getWeight(i);
100 |
101 | if (Double.isNaN(weight)) {
102 | component.setSize(width, Integer.MAX_VALUE);
103 |
104 | if (alignToGrid && component instanceof RowPanel) {
105 | component.doLayout();
106 | } else {
107 | component.setSize(width, component.getPreferredSize().height);
108 |
109 | excessHeight -= component.getHeight();
110 | }
111 | } else {
112 | totalWeight += weight;
113 | }
114 | }
115 |
116 | if (alignToGrid) {
117 | for (var i = 0; i < n; i++) {
118 | var component = getComponent(i);
119 |
120 | if (Double.isNaN(getWeight(i)) && component instanceof RowPanel) {
121 | component.setSize(component.getWidth(), component.getPreferredSize().height);
122 |
123 | excessHeight -= component.getHeight();
124 | }
125 | }
126 | }
127 |
128 | var spacing = getSpacing();
129 |
130 | excessHeight = Math.max(0, excessHeight - spacing * (n - 1));
131 |
132 | var remainingHeight = excessHeight;
133 |
134 | var y = insets.top;
135 |
136 | for (var i = 0; i < n; i++) {
137 | var component = getComponent(i);
138 |
139 | component.setLocation(insets.left, y);
140 |
141 | var weight = getWeight(i);
142 |
143 | if (!Double.isNaN(weight)) {
144 | if (i < n - 1) {
145 | var height = (int)Math.round(excessHeight * (weight / totalWeight));
146 |
147 | component.setSize(width, height);
148 |
149 | remainingHeight -= height;
150 | } else {
151 | component.setSize(width, remainingHeight);
152 | }
153 | }
154 |
155 | y += component.getHeight() + spacing;
156 | }
157 | }
158 | }
159 |
160 | private boolean alignToGrid = false;
161 |
162 | private List columnWidths = new LinkedList<>();
163 |
164 | /**
165 | * Constructs a new column panel.
166 | */
167 | public ColumnPanel() {
168 | setLayout(new ColumnLayoutManager());
169 | }
170 |
171 | /**
172 | * Sets the layout manager.
173 | * {@inheritDoc}
174 | */
175 | @Override
176 | public void setLayout(LayoutManager layoutManager) {
177 | if (layoutManager != null && !(layoutManager instanceof ColumnLayoutManager)) {
178 | throw new IllegalArgumentException();
179 | }
180 |
181 | super.setLayout(layoutManager);
182 | }
183 |
184 | /**
185 | * Indicates that nested elements will be vertically aligned in a grid. The
186 | * default value is {@code false}.
187 | *
188 | * @return
189 | * {@code true} if nested elements will be aligned to grid; {@code false},
190 | * otherwise.
191 | */
192 | public boolean getAlignToGrid() {
193 | return alignToGrid;
194 | }
195 |
196 | /**
197 | * Toggles grid alignment.
198 | *
199 | * @param alignToGrid
200 | * {@code true} to enable grid alignment; {@code false} to disable it.
201 | */
202 | public void setAlignToGrid(boolean alignToGrid) {
203 | this.alignToGrid = alignToGrid;
204 |
205 | revalidate();
206 | }
207 |
208 | /**
209 | * Returns the calculated column widths.
210 | *
211 | * @return
212 | * The calculated column widths.
213 | */
214 | protected List getColumnWidths() {
215 | return columnWidths;
216 | }
217 | }
218 |
--------------------------------------------------------------------------------
/sierra/src/main/java/org/httprpc/sierra/HorizontalAlignment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra;
16 |
17 | /**
18 | * Horizontal alignment options.
19 | */
20 | public enum HorizontalAlignment {
21 | /**
22 | * Leading alignment.
23 | */
24 | LEADING,
25 |
26 | /**
27 | * Trailing alignment.
28 | */
29 | TRAILING,
30 |
31 | /**
32 | * Center alignment.
33 | */
34 | CENTER
35 | }
36 |
--------------------------------------------------------------------------------
/sierra/src/main/java/org/httprpc/sierra/ImagePane.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra;
16 |
17 | import javax.swing.JComponent;
18 | import javax.swing.plaf.ComponentUI;
19 | import java.awt.Dimension;
20 | import java.awt.Graphics;
21 | import java.awt.Graphics2D;
22 | import java.awt.Image;
23 |
24 | /**
25 | * Displays an image.
26 | */
27 | public class ImagePane extends JComponent {
28 | /**
29 | * Image scaling options.
30 | */
31 | public enum ScaleMode {
32 | /**
33 | * No scaling.
34 | */
35 | NONE,
36 |
37 | /**
38 | * Image will be scaled to match the width of the image pane.
39 | */
40 | FILL_WIDTH,
41 |
42 | /**
43 | * Image will be scaled to match the height of the image pane.
44 | */
45 | FILL_HEIGHT
46 | }
47 |
48 | // Image pane UI
49 | private class ImagePaneUI extends ComponentUI {
50 | @Override
51 | public Dimension getMinimumSize(JComponent component) {
52 | return new Dimension(0, 0);
53 | }
54 |
55 | @Override
56 | public Dimension getMaximumSize(JComponent component) {
57 | return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
58 | }
59 |
60 | @Override
61 | public Dimension getPreferredSize(JComponent component) {
62 | if (image == null) {
63 | return new Dimension(0, 0);
64 | }
65 |
66 | var insets = getInsets();
67 |
68 | var width = Math.max(getWidth() - (insets.left + insets.right), 0);
69 | var height = Math.max(getHeight() - (insets.top + insets.bottom), 0);
70 |
71 | var imageWidth = image.getWidth(null);
72 | var imageHeight = image.getHeight(null);
73 |
74 | double scale;
75 | if (width > 0 && height > 0) {
76 | scale = getScale(width, height, imageWidth, imageHeight);
77 | } else {
78 | scale = 1.0;
79 | }
80 |
81 | var preferredWidth = (int)Math.round(imageWidth * scale) + insets.left + insets.right;
82 | var preferredHeight = (int)Math.round(imageHeight * scale) + insets.top + insets.bottom;
83 |
84 | return new Dimension(preferredWidth, preferredHeight);
85 | }
86 |
87 | @Override
88 | public int getBaseline(JComponent component, int width, int height) {
89 | return -1;
90 | }
91 |
92 | @Override
93 | public void paint(Graphics graphics, JComponent component) {
94 | paint((Graphics2D)graphics);
95 | }
96 |
97 | private void paint(Graphics2D graphics) {
98 | if (image == null) {
99 | return;
100 | }
101 |
102 | var size = getSize();
103 | var insets = getInsets();
104 |
105 | var width = Math.max(size.width - (insets.left + insets.right), 0);
106 | var height = Math.max(size.height - (insets.top + insets.bottom), 0);
107 |
108 | var imageWidth = image.getWidth(null);
109 | var imageHeight = image.getHeight(null);
110 |
111 | var scale = getScale(width, height, imageWidth, imageHeight);
112 |
113 | var scaledImageWidth = scale * imageWidth;
114 | var scaledImageHeight = scale * imageHeight;
115 |
116 | var x = switch (horizontalAlignment) {
117 | case LEADING, TRAILING -> {
118 | if (getComponentOrientation().isLeftToRight() ^ horizontalAlignment == HorizontalAlignment.TRAILING) {
119 | yield 0;
120 | } else {
121 | yield width - scaledImageWidth;
122 | }
123 |
124 | }
125 | case CENTER -> (width - scaledImageWidth) / 2;
126 | };
127 |
128 | var y = switch (verticalAlignment) {
129 | case TOP -> 0;
130 | case BOTTOM -> height - scaledImageHeight;
131 | case CENTER -> (height - scaledImageHeight) / 2;
132 | };
133 |
134 | graphics = (Graphics2D)graphics.create();
135 |
136 | graphics.setClip(insets.left, insets.top, width, height);
137 |
138 | graphics.translate(x + insets.left, y + insets.top);
139 | graphics.scale(scale, scale);
140 |
141 | graphics.drawImage(image, 0, 0, null);
142 |
143 | graphics.dispose();
144 | }
145 |
146 | private double getScale(int width, int height, int imageWidth, int imageHeight) {
147 | return switch (scaleMode) {
148 | case NONE -> 1.0;
149 | case FILL_WIDTH -> (double)width / imageWidth;
150 | case FILL_HEIGHT -> (double)height / imageHeight;
151 | };
152 | }
153 | }
154 |
155 | private Image image;
156 |
157 | private ScaleMode scaleMode = ScaleMode.NONE;
158 |
159 | private HorizontalAlignment horizontalAlignment = HorizontalAlignment.CENTER;
160 | private VerticalAlignment verticalAlignment = VerticalAlignment.CENTER;
161 |
162 | /**
163 | * Constructs an image pane.
164 | */
165 | public ImagePane() {
166 | this(null);
167 | }
168 |
169 | /**
170 | * Constructs an image pane.
171 | *
172 | * @param image
173 | * The image to display, or {@code null} for no image.
174 | */
175 | public ImagePane(Image image) {
176 | this.image = image;
177 |
178 | setUI(new ImagePaneUI());
179 | }
180 |
181 | /**
182 | * Returns the image displayed by the component.
183 | *
184 | * @return
185 | * The image displayed by the component.
186 | */
187 | public Image getImage() {
188 | return image;
189 | }
190 |
191 | /**
192 | * Sets the image displayed by the component.
193 | *
194 | * @param image
195 | * The image to display, or {@code null} for no image.
196 | */
197 | public void setImage(Image image) {
198 | this.image = image;
199 |
200 | revalidate();
201 | }
202 |
203 | /**
204 | * Returns the scale mode. The default value is {@link ScaleMode#NONE}.
205 | *
206 | * @return
207 | * The scale mode.
208 | */
209 | public ScaleMode getScaleMode() {
210 | return scaleMode;
211 | }
212 |
213 | /**
214 | * Sets the scale mode.
215 | *
216 | * @param scaleMode
217 | * The scale mode.
218 | */
219 | public void setScaleMode(ScaleMode scaleMode) {
220 | if (scaleMode == null) {
221 | throw new IllegalArgumentException();
222 | }
223 |
224 | this.scaleMode = scaleMode;
225 |
226 | revalidate();
227 | }
228 |
229 | /**
230 | * Returns the horizontal alignment. The default value is
231 | * {@link HorizontalAlignment#CENTER}.
232 | *
233 | * @return
234 | * The horizontal alignment.
235 | */
236 | public HorizontalAlignment getHorizontalAlignment() {
237 | return horizontalAlignment;
238 | }
239 |
240 | /**
241 | * Sets the horizontal alignment.
242 | *
243 | * @param horizontalAlignment
244 | * The horizontal alignment.
245 | */
246 | public void setHorizontalAlignment(HorizontalAlignment horizontalAlignment) {
247 | if (horizontalAlignment == null) {
248 | throw new IllegalArgumentException();
249 | }
250 |
251 | this.horizontalAlignment = horizontalAlignment;
252 |
253 | repaint();
254 | }
255 |
256 | /**
257 | * Returns the vertical alignment. The default value is
258 | * {@link VerticalAlignment#CENTER}.
259 | *
260 | * @return
261 | * The vertical alignment.
262 | */
263 | public VerticalAlignment getVerticalAlignment() {
264 | return verticalAlignment;
265 | }
266 |
267 | /**
268 | * Sets the vertical alignment.
269 | *
270 | * @param verticalAlignment
271 | * The vertical alignment.
272 | */
273 | public void setVerticalAlignment(VerticalAlignment verticalAlignment) {
274 | if (verticalAlignment == null) {
275 | throw new IllegalArgumentException();
276 | }
277 |
278 | this.verticalAlignment = verticalAlignment;
279 |
280 | repaint();
281 | }
282 | }
283 |
--------------------------------------------------------------------------------
/sierra/src/main/java/org/httprpc/sierra/LayoutPanel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed under the Apache License, Version 2.0 (the "License");
3 | * you may not use this file except in compliance with the License.
4 | * You may obtain a copy of the License at
5 | *
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * Unless required by applicable law or agreed to in writing, software
9 | * distributed under the License is distributed on an "AS IS" BASIS,
10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 | * See the License for the specific language governing permissions and
12 | * limitations under the License.
13 | */
14 |
15 | package org.httprpc.sierra;
16 |
17 | import javax.swing.JPanel;
18 | import javax.swing.Scrollable;
19 | import javax.swing.SwingConstants;
20 | import java.awt.Component;
21 | import java.awt.Container;
22 | import java.awt.Dimension;
23 | import java.awt.LayoutManager2;
24 | import java.awt.Rectangle;
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | /**
29 | * Abstract base class for layout panels.
30 | */
31 | public abstract class LayoutPanel extends JPanel implements Scrollable {
32 | abstract static class AbstractLayoutManager implements LayoutManager2 {
33 | @Override
34 | public void addLayoutComponent(String name, Component component) {
35 | // No-op
36 | }
37 |
38 | @Override
39 | public void addLayoutComponent(Component component, Object constraints) {
40 | // No-op
41 | }
42 |
43 | @Override
44 | public void removeLayoutComponent(Component component) {
45 | // No-op
46 | }
47 |
48 | @Override
49 | public void invalidateLayout(Container container) {
50 | // No-op
51 | }
52 |
53 | @Override
54 | public float getLayoutAlignmentX(Container container) {
55 | return 0;
56 | }
57 |
58 | @Override
59 | public float getLayoutAlignmentY(Container container) {
60 | return 0;
61 | }
62 |
63 | @Override
64 | public Dimension minimumLayoutSize(Container container) {
65 | return new Dimension(0, 0);
66 | }
67 |
68 | @Override
69 | public Dimension maximumLayoutSize(Container container) {
70 | return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
71 | }
72 |
73 | @Override
74 | public Dimension preferredLayoutSize(Container container) {
75 | return preferredLayoutSize();
76 | }
77 |
78 | protected abstract Dimension preferredLayoutSize();
79 |
80 | @Override
81 | public void layoutContainer(Container container) {
82 | layoutContainer();
83 | }
84 |
85 | protected abstract void layoutContainer();
86 | }
87 |
88 | private List