├── .editorconfig
├── .github
└── workflows
│ ├── codeql-analysis.yml
│ └── gradle.yml
├── .gitignore
├── AutoComplete
├── README.md
├── build.gradle
├── gradlew
├── gradlew.bat
└── src
│ ├── main
│ ├── dist
│ │ └── translators.txt
│ ├── java
│ │ └── org
│ │ │ └── fife
│ │ │ └── ui
│ │ │ └── autocomplete
│ │ │ ├── AbstractCompletion.java
│ │ │ ├── AbstractCompletionProvider.java
│ │ │ ├── AutoCompleteDescWindow.java
│ │ │ ├── AutoCompletePopupWindow.java
│ │ │ ├── AutoCompletion.java
│ │ │ ├── AutoCompletionEvent.java
│ │ │ ├── AutoCompletionListener.java
│ │ │ ├── AutoCompletionStyleContext.java
│ │ │ ├── BasicCompletion.java
│ │ │ ├── Completion.java
│ │ │ ├── CompletionCellRenderer.java
│ │ │ ├── CompletionListModel.java
│ │ │ ├── CompletionProvider.java
│ │ │ ├── CompletionProviderBase.java
│ │ │ ├── CompletionXMLParser.java
│ │ │ ├── DefaultCompletionProvider.java
│ │ │ ├── DelegatingCellRenderer.java
│ │ │ ├── DescWindowCallback.java
│ │ │ ├── EmptyIcon.java
│ │ │ ├── ExternalURLHandler.java
│ │ │ ├── FastListUI.java
│ │ │ ├── FunctionCompletion.java
│ │ │ ├── LanguageAwareCompletionProvider.java
│ │ │ ├── LinkRedirector.java
│ │ │ ├── MarkupTagCompletion.java
│ │ │ ├── OutlineHighlightPainter.java
│ │ │ ├── ParameterChoicesProvider.java
│ │ │ ├── ParameterizedCompletion.java
│ │ │ ├── ParameterizedCompletionChoicesWindow.java
│ │ │ ├── ParameterizedCompletionContext.java
│ │ │ ├── ParameterizedCompletionDescriptionToolTip.java
│ │ │ ├── ParameterizedCompletionInsertionInfo.java
│ │ │ ├── RoundRobinAutoCompletion.java
│ │ │ ├── ShorthandCompletion.java
│ │ │ ├── SizeGrip.java
│ │ │ ├── SortByRelevanceComparator.java
│ │ │ ├── SuppressFBWarnings.java
│ │ │ ├── TemplateCompletion.java
│ │ │ ├── TemplatePiece.java
│ │ │ ├── TipUtil.java
│ │ │ ├── Util.java
│ │ │ ├── VariableCompletion.java
│ │ │ └── package-info.java
│ └── resources
│ │ └── org
│ │ └── fife
│ │ └── ui
│ │ └── autocomplete
│ │ ├── AutoCompleteDescWindow.properties
│ │ ├── AutoCompleteDescWindow_ar.properties
│ │ ├── AutoCompleteDescWindow_de.properties
│ │ ├── AutoCompleteDescWindow_es.properties
│ │ ├── AutoCompleteDescWindow_fr.properties
│ │ ├── AutoCompleteDescWindow_hu.properties
│ │ ├── AutoCompleteDescWindow_in.properties
│ │ ├── AutoCompleteDescWindow_it.properties
│ │ ├── AutoCompleteDescWindow_ja.properties
│ │ ├── AutoCompleteDescWindow_ko.properties
│ │ ├── AutoCompleteDescWindow_nl.properties
│ │ ├── AutoCompleteDescWindow_pl.properties
│ │ ├── AutoCompleteDescWindow_pt_BR.properties
│ │ ├── AutoCompleteDescWindow_ru.properties
│ │ ├── AutoCompleteDescWindow_tr.properties
│ │ ├── AutoCompleteDescWindow_zh_CN.properties
│ │ ├── AutoCompleteDescWindow_zh_TW.properties
│ │ ├── CompletionXml.dtd
│ │ ├── arrow_left.png
│ │ ├── arrow_right.png
│ │ ├── bullet_black.png
│ │ └── osx_sizegrip.png
│ └── test
│ └── java
│ └── org
│ └── fife
│ └── ui
│ └── autocomplete
│ └── UtilTest.java
├── AutoCompleteDemo
├── README.md
├── build.gradle
└── src
│ └── main
│ ├── java
│ └── org
│ │ └── fife
│ │ └── ui
│ │ └── autocomplete
│ │ └── demo
│ │ ├── AutoCompleteDemoApp.java
│ │ ├── CCellRenderer.java
│ │ ├── DemoRootPane.java
│ │ └── package-info.java
│ └── resources
│ ├── c.xml
│ ├── img
│ ├── function.png
│ ├── macro.png
│ └── var.png
│ └── lang
│ └── c
│ ├── c.txt
│ └── create_c_xml.pl
├── LICENSE.md
├── README.md
├── build.gradle
├── config
├── checkstyle
│ ├── acSuppressions.xml
│ ├── checkstyle.xml
│ └── javaHeader.txt
└── spotbugs-exclude.xml
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.editorconfig:
--------------------------------------------------------------------------------
1 | [*.java]
2 | indent_style = tab
3 | indent_size = 4
4 | trim_trailing_whitespace = true
5 | end_of_line = lf
6 | max_line_length = 120
7 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master ]
20 | schedule:
21 | - cron: '28 6 * * 4'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 |
28 | strategy:
29 | fail-fast: false
30 | matrix:
31 | language: [ 'java' ]
32 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
33 | # Learn more:
34 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
35 |
36 | steps:
37 | - name: Checkout repository
38 | uses: actions/checkout@v4
39 |
40 | - name: Set up JDK 17
41 | uses: actions/setup-java@v4
42 | with:
43 | java-version: '17'
44 | distribution: 'temurin'
45 |
46 | # Initializes the CodeQL tools for scanning.
47 | - name: Initialize CodeQL
48 | uses: github/codeql-action/init@v3
49 | with:
50 | languages: ${{ matrix.language }}
51 | # If you wish to specify custom queries, you can do so here or in a config file.
52 | # By default, queries listed here will override any specified in a config file.
53 | # Prefix the list here with "+" to use these queries and those in the config file.
54 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
55 |
56 | ## Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
57 | ## If this step fails, then you should remove it and run the build manually (see below)
58 | #- name: Autobuild
59 | # uses: github/codeql-action/autobuild@v1
60 |
61 | # ℹ️ Command-line programs to run using the OS shell.
62 | # 📚 https://git.io/JvXDl
63 |
64 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
65 | # and modify them (or add more) to build your code if your project
66 | # uses a compiled language
67 |
68 | # Note: Assumes we're running on Ubuntu
69 | # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
70 | - name: Build
71 | run: xvfb-run ./gradlew build -xsign -xpublish --warning-mode all
72 |
73 | - name: Perform CodeQL Analysis
74 | uses: github/codeql-action/analyze@v3
75 |
--------------------------------------------------------------------------------
/.github/workflows/gradle.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Gradle
2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
3 |
4 | name: Gradle Build
5 |
6 | on:
7 | push:
8 | branches: [ master ]
9 | pull_request:
10 | branches: [ master ]
11 |
12 | jobs:
13 | build:
14 |
15 | runs-on: ubuntu-latest
16 |
17 | strategy:
18 | matrix:
19 | java: [ '17', '21', '23' ]
20 |
21 | steps:
22 | - uses: actions/checkout@v4
23 |
24 | - name: Verify gradle wrapper
25 | uses: gradle/actions/wrapper-validation@v4
26 | if: matrix.java == '17'
27 |
28 | - name: Set up JDK ${{ matrix.java }}
29 | uses: actions/setup-java@v4
30 | with:
31 | java-version: ${{ matrix.java }}
32 | distribution: 'temurin'
33 |
34 | - name: Grant execute permission for gradlew
35 | run: chmod +x gradlew
36 |
37 | # Note: Assumes we're running on Ubuntu
38 | # https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2404-Readme.md
39 | - name: Build with Gradle
40 | run: xvfb-run ./gradlew build -xsign -xpublish --warning-mode all
41 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | autocomplete_*.zip
3 | build
4 | .gradle
5 | out/
6 |
--------------------------------------------------------------------------------
/AutoComplete/README.md:
--------------------------------------------------------------------------------
1 | # AutoComplete
2 | This is the source code for the library.
3 |
--------------------------------------------------------------------------------
/AutoComplete/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java-library'
3 | }
4 |
5 | ['base', 'distribution', 'maven-publish', 'signing'].each { apply plugin: it }
6 |
7 | base {
8 | archivesName = 'autocomplete'
9 | }
10 |
11 | dependencies {
12 | api 'com.fifesoft:rsyntaxtextarea:3.5.4'
13 | }
14 |
15 | ext.isReleaseVersion = !project.version.endsWith('SNAPSHOT')
16 |
17 | java {
18 | withSourcesJar()
19 | withJavadocJar()
20 | }
21 | jar {
22 | manifest {
23 | attributes('Class-Path': 'rsyntaxtextarea.jar',
24 | 'Specification-Title': 'AutoComplete',
25 | 'Specification-Version': version,
26 | 'Implementation-Title': 'org.fife.ui',
27 | 'Implementation-Version': version)
28 | }
29 | }
30 |
31 | publishing {
32 | repositories {
33 | maven {
34 | def releasesRepoUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
35 | def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
36 | url = isReleaseVersion ? releasesRepoUrl : snapshotsRepoUrl
37 | credentials { // Credentials usually kept in user's .gradle/gradle.properties
38 | // We must defensively check for these properties so CI builds work
39 | username = project.hasProperty('ossrhToken') ? ossrhToken : 'unknown'
40 | password = project.hasProperty('ossrhTokenPassword') ? ossrhTokenPassword : 'unknown'
41 | }
42 | }
43 | }
44 | publications {
45 | maven(MavenPublication) {
46 |
47 | groupId = 'com.fifesoft'
48 | artifactId = 'autocomplete'
49 | version = version
50 |
51 | from components.java
52 |
53 | pom {
54 | name = 'autocomplete'
55 | description = 'AutoComplete is a library allowing you to add IDE-like auto-completion ' +
56 | '(aka "code completion" or "Intellisense") to any Swing JTextComponent. Special integration ' +
57 | 'is added for RSyntaxTextArea, since this feature is commonly needed when editing source code. ' +
58 | 'Features include: Drop-down completion choice list. Optional companion "description" window, ' +
59 | 'complete with full HTML support and navigable with hyperlinks. Optional parameter completion ' +
60 | 'assistance for functions and methods, ala Eclipse and NetBeans. Completion information is ' +
61 | 'typically specified in an XML file, but can even be dynamic.'
62 | url = 'https://github.com/bobbylight/AutoComplete'
63 | inceptionYear = '2003'
64 | packaging = 'jar'
65 | licenses {
66 | license {
67 | name = 'BSD-3-Clause'
68 | url = 'https://github.com/bobbylight/AutoComplete/blob/master/LICENSE.md'
69 | }
70 | }
71 | developers {
72 | developer {
73 | name = 'Robert Futrell'
74 | }
75 | }
76 | scm {
77 | url = 'https://github.com/bobbylight/AutoComplete'
78 | connection = 'scm:git:git://github.com/bobbylight/AutoComplete'
79 | developerConnection = 'scm:git:git@github.com:bobbylight/AutoComplete'
80 | if (isReleaseVersion) {
81 | tag = project.version
82 | }
83 | }
84 | }
85 | }
86 | }
87 | }
88 |
89 | signing {
90 | // Don't require signing for e.g. ./gradlew install
91 | required = gradle.taskGraph.hasTask('publish') && isReleaseVersion
92 | sign publishing.publications.maven
93 | }
94 | tasks.withType(Sign) {
95 | onlyIf { isReleaseVersion }
96 | }
97 |
--------------------------------------------------------------------------------
/AutoComplete/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/AutoComplete/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/dist/translators.txt:
--------------------------------------------------------------------------------
1 | Translators
2 | -----------
3 |
4 | Arabic: Mawaheb, Linostar
5 | Chinese: Terrance, peter_barnes, Sunquan, sonyichi, zvest
6 | Chinese (Traditional): kin Por Fok, liou xiao
7 | Dutch: Roel, Sebastiaan, lovepuppy
8 | French: Pat, PivWan
9 | German: Domenic, bikerpete
10 | Hungarian: Zityi, flatron
11 | Indonesian: azis, Sonny
12 | Italian: Luca, stepagweb
13 | Japanese: Josh, izumi, tomoM
14 | Korean: Changkyoon, sbrownii
15 | Polish: Chris, Maciej Mrug
16 | Portuguese (Brazil): Pat, Marcos Parmeggiani, Leandro
17 | Russian: Nadiya, Vladimir
18 | Spanish: Leonardo, phrodo, daloporhecho
19 | Turkish: Cahit, Burak
20 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/AbstractCompletion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * AbstractCompletion.java - Base class for possible completions.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import javax.swing.Icon;
12 | import javax.swing.text.JTextComponent;
13 |
14 |
15 | /**
16 | * Base class for possible completions. Most, if not all, {@link Completion}
17 | * implementations can extend this class. It remembers the
18 | * {@code CompletionProvider} that returns this completion, and also implements
19 | * {@code Comparable}, allowing such completions to be compared
20 | * lexicographically (ignoring case).
21 | *
22 | * This implementation assumes the input text and replacement text are the
23 | * same value. It also returns the input text from its {@link #toString()}
24 | * method (which is what DefaultListCellRenderer
uses to render
25 | * objects). Subclasses that wish to override any of this behavior can simply
26 | * override the corresponding method(s) needed to do so.
27 | *
28 | * @author Robert Futrell
29 | * @version 1.0
30 | */
31 | public abstract class AbstractCompletion implements Completion {
32 |
33 | /**
34 | * The provider that created this completion.
35 | */
36 | private final CompletionProvider provider;
37 |
38 | /**
39 | * The icon to use for this completion.
40 | */
41 | private Icon icon;
42 |
43 | /**
44 | * The relevance of this completion. Completion instances with higher
45 | * "relevance" values are inserted higher into the list of possible
46 | * completions than those with lower values. Completion instances with
47 | * equal relevance values are sorted alphabetically.
48 | */
49 | private int relevance;
50 |
51 |
52 | /**
53 | * Constructor.
54 | *
55 | * @param provider The provider that created this completion.
56 | */
57 | protected AbstractCompletion(CompletionProvider provider) {
58 | this.provider = provider;
59 | }
60 |
61 |
62 | /**
63 | * Constructor.
64 | *
65 | * @param provider The provider that created this completion.
66 | * @param icon The icon for this completion.
67 | */
68 | protected AbstractCompletion(CompletionProvider provider, Icon icon) {
69 | this(provider);
70 | setIcon(icon);
71 | }
72 |
73 |
74 | @Override
75 | public int compareTo(Completion c2) {
76 | if (c2==this) {
77 | return 0;
78 | }
79 | else if (c2!=null) {
80 | return toString().compareToIgnoreCase(c2.toString());
81 | }
82 | return -1;
83 | }
84 |
85 |
86 | @Override
87 | public String getAlreadyEntered(JTextComponent comp) {
88 | return provider.getAlreadyEnteredText(comp);
89 | }
90 |
91 |
92 | @Override
93 | public Icon getIcon() {
94 | return icon;
95 | }
96 |
97 |
98 | /**
99 | * Returns the text the user has to (start) typing for this completion
100 | * to be offered. The default implementation simply returns
101 | * {@link #getReplacementText()}.
102 | *
103 | * @return The text the user has to (start) typing for this completion.
104 | * @see #getReplacementText()
105 | */
106 | @Override
107 | public String getInputText() {
108 | return getReplacementText();
109 | }
110 |
111 |
112 | @Override
113 | public CompletionProvider getProvider() {
114 | return provider;
115 | }
116 |
117 |
118 | @Override
119 | public int getRelevance() {
120 | return relevance;
121 | }
122 |
123 |
124 | /**
125 | * The default implementation returns null
. Subclasses
126 | * can override this method.
127 | *
128 | * @return The tool tip text.
129 | */
130 | @Override
131 | public String getToolTipText() {
132 | return null;
133 | }
134 |
135 |
136 | /**
137 | * Sets the icon to use for this completion.
138 | *
139 | * @param icon The icon to use.
140 | * @see #getIcon()
141 | */
142 | public void setIcon(Icon icon) {
143 | this.icon = icon;
144 | }
145 |
146 |
147 | /**
148 | * Sets the relevance of this completion.
149 | *
150 | * @param relevance The new relevance of this completion.
151 | * @see #getRelevance()
152 | */
153 | public void setRelevance(int relevance) {
154 | this.relevance = relevance;
155 | }
156 |
157 |
158 | /**
159 | * Returns a string representation of this completion. The default
160 | * implementation returns {@link #getInputText()}.
161 | *
162 | * @return A string representation of this completion.
163 | */
164 | @Override
165 | public String toString() {
166 | return getInputText();
167 | }
168 |
169 |
170 | }
171 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/AbstractCompletionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * AbstractCompletionProvider.java - Base class for completion providers.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import java.io.Serializable;
12 | import java.util.ArrayList;
13 | import java.util.Collections;
14 | import java.util.Comparator;
15 | import java.util.List;
16 |
17 | import javax.swing.text.JTextComponent;
18 |
19 |
20 | /**
21 | * A base class for completion providers. {@link Completion}s are kept in
22 | * a sorted list. To get the list of completions that match a given input,
23 | * a binary search is done to find the first matching completion, then all
24 | * succeeding completions that also match are also returned.
25 | *
26 | * @author Robert Futrell
27 | * @version 1.0
28 | */
29 | public abstract class AbstractCompletionProvider
30 | extends CompletionProviderBase {
31 |
32 | /**
33 | * The completions this provider is aware of. Subclasses should ensure
34 | * that this list is sorted alphabetically (case-insensitively).
35 | */
36 | protected List completions;
37 |
38 | /**
39 | * Compares a {@link Completion} against a String.
40 | */
41 | protected CaseInsensitiveComparator comparator;
42 |
43 |
44 | /**
45 | * Constructor.
46 | */
47 | public AbstractCompletionProvider() {
48 | comparator = new CaseInsensitiveComparator();
49 | clearParameterizedCompletionParams();
50 | completions = new ArrayList<>();
51 | }
52 |
53 |
54 | /**
55 | * Adds a single completion to this provider. If you are adding multiple
56 | * completions to this provider, for efficiency reasons please consider
57 | * using {@link #addCompletions(List)} instead.
58 | *
59 | * @param c The completion to add.
60 | * @throws IllegalArgumentException If the completion's provider isn't
61 | * this {@code CompletionProvider}.
62 | * @see #addCompletions(List)
63 | * @see #removeCompletion(Completion)
64 | * @see #clear()
65 | */
66 | public void addCompletion(Completion c) {
67 | checkProviderAndAdd(c);
68 | Collections.sort(completions);
69 | }
70 |
71 |
72 | /**
73 | * Adds {@link Completion}s to this provider.
74 | *
75 | * @param completions The completions to add. This cannot be
76 | * null
.
77 | * @throws IllegalArgumentException If a completion's provider isn't
78 | * this {@code CompletionProvider}.
79 | * @see #addCompletion(Completion)
80 | * @see #removeCompletion(Completion)
81 | * @see #clear()
82 | */
83 | public void addCompletions(List completions) {
84 | //this.completions.addAll(completions);
85 | for (Completion c : completions) {
86 | checkProviderAndAdd(c);
87 | }
88 | Collections.sort(this.completions);
89 | }
90 |
91 |
92 | /**
93 | * Adds simple completions for a list of words.
94 | *
95 | * @param words The words.
96 | * @see BasicCompletion
97 | */
98 | protected void addWordCompletions(String[] words) {
99 | int count = words==null ? 0 : words.length;
100 | for (int i=0; inull if there
139 | * are no matching {@code Completion}s.
140 | */
141 | @SuppressWarnings("unchecked")
142 | public List getCompletionByInputText(String inputText) {
143 |
144 | // Find any entry that matches this input text (there may be > 1).
145 | int end = Collections.binarySearch(completions, inputText, comparator);
146 | if (end<0) {
147 | return null;
148 | }
149 |
150 | // There might be multiple entries with the same input text.
151 | int start = end;
152 | while (start>0 &&
153 | comparator.compare(completions.get(start-1), inputText)==0) {
154 | start--;
155 | }
156 | int count = completions.size();
157 | while (++end getCompletionsImpl(JTextComponent comp) {
168 |
169 | List retVal = new ArrayList<>();
170 | String text = getAlreadyEnteredText(comp);
171 |
172 | if (text!=null) {
173 |
174 | int index = Collections.binarySearch(completions, text, comparator);
175 | if (index<0) { // No exact match
176 | index = -index - 1;
177 | }
178 | else {
179 | // If there are several overloads for the function being
180 | // completed, Collections.binarySearch() will return the index
181 | // of one of those overloads, but we must return all of them,
182 | // so search backward until we find the first one.
183 | int pos = index - 1;
184 | while (pos>0 &&
185 | comparator.compare(completions.get(pos), text)==0) {
186 | retVal.add(completions.get(pos));
187 | pos--;
188 | }
189 | }
190 |
191 | while (indextrue if this provider contained the specified
215 | * completion.
216 | * @see #clear()
217 | * @see #addCompletion(Completion)
218 | * @see #addCompletions(List)
219 | */
220 | public boolean removeCompletion(Completion c) {
221 | // Don't just call completions.remove(c) as it'll be a linear search.
222 | int index = Collections.binarySearch(completions, c);
223 | if (index<0) {
224 | return false;
225 | }
226 | completions.remove(index);
227 | return true;
228 | }
229 |
230 |
231 | /**
232 | * A comparator that compares the input text of a {@link Completion}
233 | * against a String lexicographically, ignoring case.
234 | */
235 | @SuppressWarnings("rawtypes")
236 | public static class CaseInsensitiveComparator implements Comparator,
237 | Serializable {
238 |
239 | @Override
240 | public int compare(Object o1, Object o2) {
241 | String s1 = o1 instanceof String ? (String)o1 :
242 | ((Completion)o1).getInputText();
243 | String s2 = o2 instanceof String ? (String)o2 :
244 | ((Completion)o2).getInputText();
245 | return String.CASE_INSENSITIVE_ORDER.compare(s1, s2);
246 | }
247 |
248 | }
249 |
250 |
251 | }
252 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/AutoCompletionEvent.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 02/08/2014
3 | *
4 | * This library is distributed under a modified BSD license. See the included
5 | * LICENSE.md file for details.
6 | */
7 | package org.fife.ui.autocomplete;
8 |
9 | import java.util.EventObject;
10 |
11 |
12 | /**
13 | * An event fired by an instance of {@link AutoCompletion}. This can be
14 | * used by applications that wish to be notified of the auto-complete popup
15 | * window showing and hiding.
16 | *
17 | * @author Robert Futrell
18 | * @version 1.0
19 | */
20 | public class AutoCompletionEvent extends EventObject {
21 |
22 | /**
23 | * The type of this event.
24 | */
25 | private final Type type;
26 |
27 |
28 | /**
29 | * Constructor.
30 | *
31 | * @param source The AutoCompletion
instance that fired
32 | * this event.
33 | * @param type The event type.
34 | */
35 | public AutoCompletionEvent(AutoCompletion source, Type type) {
36 | super(source);
37 | this.type = type;
38 | }
39 |
40 |
41 | /**
42 | * Returns the source AutoCompletion
instance. This is just
43 | * shorthand for return (AutoCompletion)getSource();
.
44 | *
45 | * @return The source AutoCompletion
instance.
46 | */
47 | public AutoCompletion getAutoCompletion() {
48 | return (AutoCompletion)getSource();
49 | }
50 |
51 |
52 | /**
53 | * Returns the type of this event.
54 | *
55 | * @return The type of this event.
56 | */
57 | public Type getEventType() {
58 | return type;
59 | }
60 |
61 |
62 | /**
63 | * Enumeration of the various types of this event.
64 | */
65 | public enum Type {
66 |
67 | /**
68 | * Denotes that the auto-completion window was shown.
69 | */
70 | POPUP_SHOWN,
71 |
72 | /**
73 | * Denotes that the auto-completion window was hidden.
74 | */
75 | POPUP_HIDDEN
76 | }
77 |
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/AutoCompletionListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 02/08/2014
3 | *
4 | * This library is distributed under a modified BSD license. See the included
5 | * LICENSE.md file for details.
6 | */
7 | package org.fife.ui.autocomplete;
8 |
9 | import java.util.EventListener;
10 |
11 |
12 | /**
13 | * An interface that allows listening for interesting events from an
14 | * {@link AutoCompletion}.
15 | *
16 | * @author Robert Futrell
17 | * @version 1.0
18 | */
19 | public interface AutoCompletionListener extends EventListener {
20 |
21 |
22 | /**
23 | * Callback notified when a change to the AutoCompletion
's
24 | * status occurs.
25 | *
26 | * @param e The event.
27 | */
28 | void autoCompleteUpdate(AutoCompletionEvent e);
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/AutoCompletionStyleContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 06/24/2012
3 | *
4 | * AutoCompletionStyleContext.java - Manages styles related to auto-completion.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import java.awt.Color;
12 |
13 |
14 | /**
15 | * Manages the colors shared across the library.
16 | *
17 | * @author Robert Futrell
18 | * @version 1.0
19 | */
20 | public class AutoCompletionStyleContext {
21 |
22 | /**
23 | * The color used to denote the ending caret position for parameterized
24 | * completions.
25 | */
26 | private Color parameterizedCompletionCursorPositionColor;
27 |
28 | /**
29 | * The color used to highlight copies of editable parameters in
30 | * parameterized completions.
31 | */
32 | private Color parameterCopyColor;
33 |
34 | /**
35 | * The color of the outline highlight used to denote editable parameters
36 | * in parameterized completions.
37 | */
38 | private Color parameterOutlineColor;
39 |
40 |
41 | /**
42 | * Constructor.
43 | */
44 | public AutoCompletionStyleContext() {
45 | setParameterOutlineColor(Color.gray);
46 | setParameterCopyColor(new Color(0xb4d7ff));
47 | setParameterizedCompletionCursorPositionColor(new Color(0x00b400));
48 | }
49 |
50 |
51 | /**
52 | * Returns the color of the highlight painted on copies of editable
53 | * parameters in parameterized completions.
54 | *
55 | * @return The color used.
56 | * @see #setParameterCopyColor(Color)
57 | */
58 | public Color getParameterCopyColor() {
59 | return parameterCopyColor;
60 | }
61 |
62 |
63 | /**
64 | * Returns the color used to denote the ending caret position for
65 | * parameterized completions.
66 | *
67 | * @return The color used.
68 | * @see #setParameterizedCompletionCursorPositionColor(Color)
69 | */
70 | public Color getParameterizedCompletionCursorPositionColor() {
71 | return parameterizedCompletionCursorPositionColor;
72 | }
73 |
74 |
75 | /**
76 | * Returns the color of the outline highlight used to denote editable
77 | * parameters in parameterized completions.
78 | *
79 | * @return The color used.
80 | * @see #setParameterOutlineColor(Color)
81 | */
82 | public Color getParameterOutlineColor() {
83 | return parameterOutlineColor;
84 | }
85 |
86 |
87 | /**
88 | * Sets the color of the highlight painted on copies of editable
89 | * parameters in parameterized completions.
90 | *
91 | * @param color The color to use.
92 | * @see #setParameterCopyColor(Color)
93 | */
94 | public void setParameterCopyColor(Color color) {
95 | this.parameterCopyColor = color;
96 | }
97 |
98 |
99 | /**
100 | * Sets the color used to denote the ending caret position for
101 | * parameterized completions.
102 | *
103 | * @param color The color to use.
104 | * @see #getParameterizedCompletionCursorPositionColor()
105 | */
106 | public void setParameterizedCompletionCursorPositionColor(Color color) {
107 | this.parameterizedCompletionCursorPositionColor = color;
108 | }
109 |
110 |
111 | /**
112 | * Sets the color of the outline highlight used to denote editable
113 | * parameters in parameterized completions.
114 | *
115 | * @param color The color to use.
116 | * @see #getParameterOutlineColor()
117 | */
118 | public void setParameterOutlineColor(Color color) {
119 | this.parameterOutlineColor = color;
120 | }
121 |
122 |
123 | }
124 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/BasicCompletion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 01/03/2009
3 | *
4 | * BasicCompletion.java - A straightforward Completion implementation.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 |
12 | /**
13 | * A straightforward {@link Completion} implementation. This implementation
14 | * can be used if you have a relatively short number of static completions
15 | * with no (or short) summaries.
16 | *
17 | * This implementation uses the replacement text as the input text. It also
18 | * includes a "short description" field, which (if non-null
), is
19 | * used in the completion choices list.
20 | *
21 | * @author Robert Futrell
22 | * @version 1.0
23 | */
24 | public class BasicCompletion extends AbstractCompletion {
25 |
26 | private final String replacementText;
27 | private String shortDesc;
28 | private String summary;
29 |
30 |
31 | /**
32 | * Constructor.
33 | *
34 | * @param provider The parent completion provider.
35 | * @param replacementText The text to replace.
36 | */
37 | public BasicCompletion(CompletionProvider provider, String replacementText){
38 | this(provider, replacementText, null);
39 | }
40 |
41 |
42 | /**
43 | * Constructor.
44 | *
45 | * @param provider The parent completion provider.
46 | * @param replacementText The text to replace.
47 | * @param shortDesc A short description of the completion. This will be
48 | * displayed in the completion list. This may be null
.
49 | */
50 | public BasicCompletion(CompletionProvider provider, String replacementText,
51 | String shortDesc) {
52 | this(provider, replacementText, shortDesc, null);
53 | }
54 |
55 |
56 | /**
57 | * Constructor.
58 | *
59 | * @param provider The parent completion provider.
60 | * @param replacementText The text to replace.
61 | * @param shortDesc A short description of the completion. This will be
62 | * displayed in the completion list. This may be null
.
63 | * @param summary The summary of this completion. This should be HTML.
64 | * This may be null
.
65 | */
66 | public BasicCompletion(CompletionProvider provider, String replacementText,
67 | String shortDesc, String summary) {
68 | super(provider);
69 | this.replacementText = replacementText;
70 | this.shortDesc = shortDesc;
71 | this.summary = summary;
72 | }
73 |
74 |
75 | @Override
76 | public String getReplacementText() {
77 | return replacementText;
78 | }
79 |
80 |
81 | /**
82 | * Returns the short description of this completion, usually used in
83 | * the completion choices list.
84 | *
85 | * @return The short description, or null
if there is none.
86 | * @see #setShortDescription(String)
87 | */
88 | public String getShortDescription() {
89 | return shortDesc;
90 | }
91 |
92 |
93 | @Override
94 | public String getSummary() {
95 | return summary;
96 | }
97 |
98 |
99 | /**
100 | * Sets the short description of this completion.
101 | *
102 | * @param shortDesc The short description of this completion.
103 | * @see #getShortDescription()
104 | */
105 | public void setShortDescription(String shortDesc) {
106 | this.shortDesc = shortDesc;
107 | }
108 |
109 |
110 | /**
111 | * Sets the summary for this completion.
112 | *
113 | * @param summary The summary for this completion.
114 | * @see #getSummary()
115 | */
116 | public void setSummary(String summary) {
117 | this.summary = summary;
118 | }
119 |
120 |
121 | /**
122 | * Returns a string representation of this completion. If the short
123 | * description is not null
, this method will return:
124 | *
125 | * getInputText() + " - " + shortDesc
126 | *
127 | * otherwise, it will return {@code getInputText()}.
128 | *
129 | * @return A string representation of this completion.
130 | */
131 | @Override
132 | public String toString() {
133 | if (shortDesc==null) {
134 | return getInputText();
135 | }
136 | return getInputText() + " - " + shortDesc;
137 | }
138 |
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/Completion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * Completion.java - Represents a single completion choice.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import javax.swing.Icon;
12 | import javax.swing.text.JTextComponent;
13 |
14 |
15 | /**
16 | * Represents a completion choice. A {@link CompletionProvider} returns lists
17 | * of objects implementing this interface. A {@code Completion} contains the
18 | * following information:
19 | *
20 | *
21 | * The text the user must (begin to) input for this to be a completion
22 | * choice.
23 | * The text that will be filled in if the user chooses this completion.
24 | * Note that often, this is the same as the text the user must (begin to)
25 | * enter, but this doesn't have to be the case.
26 | * Summary HTML that describes this completion. This is information that
27 | * can be displayed in a helper "tooltip"-style window beside the
28 | * completion list. This may be null
. It may also be
29 | * lazily generated to cut down on memory usage.
30 | * The {@code CompletionProvider} that returned this completion.
31 | * Tool tip text that can be displayed when a mouse hovers over this
32 | * completion in a text component.
33 | *
34 | *
35 | * @author Robert Futrell
36 | * @version 1.0
37 | * @see AbstractCompletion
38 | */
39 | public interface Completion extends Comparable {
40 |
41 |
42 | /**
43 | * Compares this completion to another one lexicographically, ignoring
44 | * case.
45 | *
46 | * @param other Another completion instance.
47 | * @return How this completion compares to the other one.
48 | */
49 | @Override
50 | int compareTo(Completion other);
51 |
52 |
53 | /**
54 | * Returns the portion of this completion that has already been entered
55 | * into the text component. The match is case-insensitive.
56 | *
57 | * This is a convenience method for:
58 | * getProvider().getAlreadyEnteredText(comp)
.
59 | *
60 | * @param comp The text component.
61 | * @return The already-entered portion of this completion.
62 | */
63 | String getAlreadyEntered(JTextComponent comp);
64 |
65 |
66 | /**
67 | * Returns the icon to use for this completion.
68 | *
69 | * @return The icon, or null
for none.
70 | */
71 | Icon getIcon();
72 |
73 |
74 | /**
75 | * Returns the text that the user has to (start) typing for this completion
76 | * to be offered. Note that this will usually be the same value as
77 | * {@link #getReplacementText()}, but not always (a completion could be
78 | * a way to implement shorthand, for example, "sysout
" mapping
79 | * to "System.out.println(
").
80 | *
81 | * @return The text the user has to (start) typing for this completion to
82 | * be offered.
83 | * @see #getReplacementText()
84 | */
85 | String getInputText();
86 |
87 |
88 | /**
89 | * Returns the provider that returned this completion.
90 | *
91 | * @return The provider.
92 | */
93 | CompletionProvider getProvider();
94 |
95 |
96 | /**
97 | * Returns the "relevance" of this completion. This is used when sorting
98 | * completions by their relevance. It is an abstract concept that may
99 | * mean different things to different languages, and may depend on the
100 | * context of the completion.
101 | *
102 | * By default, all completions have a relevance of 0
. The
103 | * higher the value returned by this method, the higher up in the list
104 | * this completion will be; the lower the value returned, the lower it will
105 | * be. Completion
s with equal relevance values will be
106 | * sorted alphabetically.
107 | *
108 | * @return The relevance of this completion.
109 | */
110 | int getRelevance();
111 |
112 |
113 | /**
114 | * Returns the text to insert as the result of this auto-completion. This
115 | * is the "complete" text, including any text that replaces what the user
116 | * has already typed.
117 | *
118 | * @return The replacement text.
119 | * @see #getInputText()
120 | */
121 | String getReplacementText();
122 |
123 |
124 | /**
125 | * Returns the description of this auto-complete choice. This can be
126 | * used in a popup "description window."
127 | *
128 | * @return This item's description. This should be HTML. It may be
129 | * null
if there is no description for this
130 | * completion.
131 | */
132 | String getSummary();
133 |
134 |
135 | /**
136 | * Returns the tool tip text to display for mouse hovers over this
137 | * completion.
138 | *
139 | * Note that for this functionality to be enabled, a
140 | * {@code JTextComponent} must be registered with the
141 | * {@code ToolTipManager}, and the text component must know to search
142 | * for this value. In the case of an
143 | * RSyntaxTextArea , this
144 | * can be done with a {@code org.fife.ui.rtextarea.ToolTipSupplier} that
145 | * calls into
146 | * {@link CompletionProvider#getCompletionsAt(JTextComponent, java.awt.Point)}.
147 | *
148 | * @return The tool tip text for this completion, or null
if
149 | * none.
150 | */
151 | String getToolTipText();
152 |
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/CompletionListModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/22/2008
3 | *
4 | * CompletionListModel.java - A model that allows bulk addition of elements.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import java.util.ArrayList;
12 | import java.util.Collection;
13 | import java.util.List;
14 |
15 | import javax.swing.AbstractListModel;
16 |
17 |
18 | /**
19 | * A list model implementation that allows the bulk addition of elements.
20 | * This is the only feature missing from DefaultListModel
that
21 | * we need.
22 | *
23 | * @author Robert Futrell
24 | * @version 1.0
25 | */
26 | class CompletionListModel extends AbstractListModel {
27 |
28 | /**
29 | * Container for items in this model.
30 | */
31 | private final List delegate;
32 |
33 |
34 | /**
35 | * Constructor.
36 | */
37 | CompletionListModel() {
38 | delegate = new ArrayList<>();
39 | }
40 |
41 |
42 | /**
43 | * Removes all the elements from this list. The list will
44 | * be empty after this call returns (unless it throws an exception).
45 | *
46 | * @see #setContents(Collection)
47 | */
48 | public void clear() {
49 | int end = delegate.size()-1;
50 | delegate.clear();
51 | if (end >= 0) {
52 | fireIntervalRemoved(this, 0, end);
53 | }
54 | }
55 |
56 |
57 | @Override
58 | public Completion getElementAt(int index) {
59 | return delegate.get(index);
60 | }
61 |
62 |
63 | @Override
64 | public int getSize() {
65 | return delegate.size();
66 | }
67 |
68 |
69 | /**
70 | * Sets the contents of this model. All previous contents are removed.
71 | *
72 | * @param contents The new contents of this model.
73 | */
74 | public void setContents(Collection contents) {
75 | clear();
76 | int count = contents.size();
77 | if (count>0) {
78 | delegate.addAll(contents);
79 | fireIntervalAdded(this, 0, count-1); // endpoints included (!)
80 | }
81 | }
82 |
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/CompletionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * CompletionProvider.java - Provides autocompletion values based on the
5 | * text currently in a text component.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.awt.Point;
13 | import java.util.List;
14 |
15 | import javax.swing.ListCellRenderer;
16 | import javax.swing.text.JTextComponent;
17 |
18 |
19 | /**
20 | * Provides autocompletion values to an {@link AutoCompletion}.
21 | *
22 | * Completion providers can have an optional parent. Parents are searched for
23 | * completions when their children are. This allows for chaining of completion
24 | * providers.
25 | *
26 | * @author Robert Futrell
27 | * @version 1.0
28 | */
29 | public interface CompletionProvider {
30 |
31 |
32 | /**
33 | * Clears the values used to identify and insert "parameterized completions"
34 | * (e.g. functions or methods). After this method is called, functions and
35 | * methods will not have their parameters auto-completed.
36 | *
37 | * @see #setParameterizedCompletionParams(char, String, char)
38 | */
39 | void clearParameterizedCompletionParams();
40 |
41 |
42 | /**
43 | * Returns the text just before the current caret position that could be
44 | * the start of something auto-completable.
45 | *
46 | * @param comp The text component.
47 | * @return The text. A return value of null
means nothing
48 | * should be auto-completed; a value of an empty string
49 | * (""
) means auto-completion should still be
50 | * considered (i.e., all possible choices are valid).
51 | */
52 | String getAlreadyEnteredText(JTextComponent comp);
53 |
54 |
55 | /**
56 | * Gets the possible completions for the text component at the current
57 | * caret position.
58 | *
59 | * @param comp The text component.
60 | * @return The list of {@link Completion}s. If no completions are
61 | * available, this method should return an empty list.
62 | */
63 | List getCompletions(JTextComponent comp);
64 |
65 |
66 | /**
67 | * Returns the completions that have been entered at the specified visual
68 | * location. This can be used for tool tips when the user hovers the
69 | * mouse over completed text.
70 | *
71 | * @param comp The text component.
72 | * @param p The position, usually from a {@code MouseEvent}.
73 | * @return The completions, or an empty list if there are none.
74 | */
75 | List getCompletionsAt(JTextComponent comp, Point p);
76 |
77 |
78 | /**
79 | * Returns the cell renderer for completions returned from this provider.
80 | *
81 | * @return The cell renderer, or null
if the default should
82 | * be used.
83 | * @see #setListCellRenderer(ListCellRenderer)
84 | */
85 | ListCellRenderer getListCellRenderer();
86 |
87 |
88 | /**
89 | * Returns an object that can return a list of completion choices for
90 | * parameters. This is used when a user code-completes a parameterized
91 | * completion, such as a function or method. For any parameter to the
92 | * function/method, this object can return possible completions.
93 | *
94 | * @return The parameter choices provider, or null
if
95 | * none is installed.
96 | */
97 | ParameterChoicesProvider getParameterChoicesProvider();
98 |
99 |
100 | /**
101 | * Returns a list of parameterized completions that have been entered
102 | * at the current caret position of a text component (and thus can have
103 | * their completion choices displayed).
104 | *
105 | * @param tc The text component.
106 | * @return The list of {@link ParameterizedCompletion}s. If no completions
107 | * are available, this may be null
.
108 | */
109 | List getParameterizedCompletions(JTextComponent tc);
110 |
111 |
112 | /**
113 | * Returns the text that marks the end of a list of parameters to a
114 | * function or method.
115 | *
116 | * @return The text for a parameter list end, for example,
117 | * ')
', or {@code 0} if none.
118 | * @see #getParameterListStart()
119 | * @see #getParameterListSeparator()
120 | * @see #setParameterizedCompletionParams(char, String, char)
121 | */
122 | char getParameterListEnd();
123 |
124 |
125 | /**
126 | * Returns the text that separates parameters to a function or method.
127 | *
128 | * @return The text that separates parameters, for example,
129 | * ",
".
130 | * @see #getParameterListStart()
131 | * @see #getParameterListEnd()
132 | * @see #setParameterizedCompletionParams(char, String, char)
133 | */
134 | String getParameterListSeparator();
135 |
136 |
137 | /**
138 | * Returns the text that marks the start of a list of parameters to a
139 | * function or method.
140 | *
141 | * @return The text for a parameter list start, for example,
142 | * "(
".
143 | * @see #getParameterListEnd()
144 | * @see #getParameterListSeparator()
145 | * @see #setParameterizedCompletionParams(char, String, char)
146 | */
147 | char getParameterListStart();
148 |
149 |
150 | /**
151 | * Returns the parent completion provider.
152 | *
153 | * @return The parent completion provider.
154 | * @see #setParent(CompletionProvider)
155 | */
156 | CompletionProvider getParent();
157 |
158 |
159 | /**
160 | * This method is called if auto-activation is enabled in the parent
161 | * {@link AutoCompletion} after the user types a single character. This
162 | * provider should check the text at the current caret position of the
163 | * text component, and decide whether auto-activation would be appropriate
164 | * here. For example, a CompletionProvider
for Java might
165 | * want to return true
for this method only if the last
166 | * character typed was a '.
'.
167 | *
168 | * @param tc The text component.
169 | * @return Whether auto-activation would be appropriate.
170 | */
171 | boolean isAutoActivateOkay(JTextComponent tc);
172 |
173 |
174 | /**
175 | * Sets the renderer to use when displaying completion choices.
176 | *
177 | * @param r The renderer to use.
178 | * @see #getListCellRenderer()
179 | */
180 | void setListCellRenderer(ListCellRenderer r);
181 |
182 |
183 | /**
184 | * Sets the values used to identify and insert "parameterized completions"
185 | * (e.g. functions or methods). If this method isn't called, functions
186 | * and methods will not have their parameters auto-completed.
187 | *
188 | * @param listStart The character that marks the beginning of a list of
189 | * parameters, such as '{@code (}' in C or Java.
190 | * @param separator Text that should separate parameters in a parameter
191 | * list when one is inserted. For example, "{@code , }".
192 | * @param listEnd The character that marks the end of a list of parameters,
193 | * such as '{@code )}' in C or Java.
194 | * @throws IllegalArgumentException If either {@code listStart} or
195 | * {@code listEnd} is not printable ASCII, or if
196 | * {@code separator} is null
or an empty string.
197 | * @see #clearParameterizedCompletionParams()
198 | */
199 | void setParameterizedCompletionParams(char listStart,
200 | String separator, char listEnd);
201 |
202 |
203 | /**
204 | * Sets the parent completion provider.
205 | *
206 | * @param parent The parent provider. null
means there will
207 | * be no parent provider.
208 | * @see #getParent()
209 | */
210 | void setParent(CompletionProvider parent);
211 |
212 |
213 | }
214 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/CompletionProviderBase.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 02/06/2010
3 | *
4 | * CompletionProviderBase.java - Base completion provider implementation.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import java.util.Collections;
12 | import java.util.Comparator;
13 | import java.util.List;
14 | import javax.swing.ListCellRenderer;
15 | import javax.swing.text.BadLocationException;
16 | import javax.swing.text.Document;
17 | import javax.swing.text.JTextComponent;
18 | import javax.swing.text.Segment;
19 |
20 |
21 | /**
22 | * A base class for all standard completion providers. This class implements
23 | * functionality that should be sharable across all {@code CompletionProvider}
24 | * implementations.
25 | *
26 | * @author Robert Futrell
27 | * @version 1.0
28 | * @see AbstractCompletionProvider
29 | */
30 | public abstract class CompletionProviderBase implements CompletionProvider {
31 |
32 | /**
33 | * The parent completion provider.
34 | */
35 | private CompletionProvider parent;
36 |
37 | /**
38 | * The renderer to use for completions from this provider. If this is
39 | * null
, a default renderer is used.
40 | */
41 | private ListCellRenderer listCellRenderer;
42 |
43 | /**
44 | * Text that marks the beginning of a parameter list, for example, '('.
45 | */
46 | private char paramListStart;
47 |
48 | /**
49 | * Text that marks the end of a parameter list, for example, ')'.
50 | */
51 | private char paramListEnd;
52 |
53 | /**
54 | * Text that separates items in a parameter list, for example, ", ".
55 | */
56 | private String paramListSeparator;
57 |
58 | /**
59 | * Whether auto-activation should occur after letters.
60 | */
61 | private boolean autoActivateAfterLetters;
62 |
63 | /**
64 | * Non-letter chars that should cause auto-activation to occur.
65 | */
66 | private String autoActivateChars;
67 |
68 | /**
69 | * Provides completion choices for a parameterized completion's parameters.
70 | */
71 | private ParameterChoicesProvider paramChoicesProvider;
72 |
73 | /**
74 | * A segment to use for fast char access.
75 | */
76 | private final Segment s = new Segment();
77 |
78 | /**
79 | * An empty string, defined as a constant.
80 | */
81 | protected static final String EMPTY_STRING = "";
82 |
83 | /**
84 | * Comparator used to sort completions by their relevance before sorting
85 | * them lexicographically.
86 | */
87 | private static final Comparator SORT_BY_RELEVANCE_COMPARATOR =
88 | new SortByRelevanceComparator();
89 |
90 |
91 | @Override
92 | public void clearParameterizedCompletionParams() {
93 | paramListEnd = paramListStart = 0;
94 | paramListSeparator = null;
95 | }
96 |
97 |
98 | @Override
99 | public List getCompletions(JTextComponent comp) {
100 |
101 | List completions = getCompletionsImpl(comp);
102 | if (parent!=null) {
103 | List parentCompletions = parent.getCompletions(comp);
104 | if (parentCompletions!=null) {
105 | completions.addAll(parentCompletions);
106 | Collections.sort(completions);
107 | }
108 | }
109 |
110 | // NOTE: We can't sort by relevance prior to this; we need to have
111 | // things alphabetical, so we can easily narrow down completions to
112 | // those starting with what was already typed.
113 | if (/*sortByRelevance*/true) {
114 | completions.sort(SORT_BY_RELEVANCE_COMPARATOR);
115 | }
116 |
117 | return completions;
118 |
119 | }
120 |
121 |
122 | /**
123 | * Does the dirty work of creating a list of completions.
124 | *
125 | * @param comp The text component to look in.
126 | * @return The list of possible completions, or an empty list if there
127 | * are none.
128 | */
129 | protected abstract List getCompletionsImpl(JTextComponent comp);
130 |
131 |
132 | @Override
133 | public ListCellRenderer getListCellRenderer() {
134 | return listCellRenderer;
135 | }
136 |
137 |
138 | @Override
139 | public ParameterChoicesProvider getParameterChoicesProvider() {
140 | return paramChoicesProvider;
141 | }
142 |
143 |
144 | @Override
145 | public char getParameterListEnd() {
146 | return paramListEnd;
147 | }
148 |
149 |
150 | @Override
151 | public String getParameterListSeparator() {
152 | return paramListSeparator;
153 | }
154 |
155 |
156 | @Override
157 | public char getParameterListStart() {
158 | return paramListStart;
159 | }
160 |
161 |
162 | @Override
163 | public CompletionProvider getParent() {
164 | return parent;
165 | }
166 |
167 |
168 | @Override
169 | public boolean isAutoActivateOkay(JTextComponent tc) {
170 | Document doc = tc.getDocument();
171 | char ch = 0;
172 | try {
173 | doc.getText(tc.getCaretPosition(), 1, s);
174 | ch = s.first();
175 | } catch (BadLocationException ble) { // Never happens
176 | ble.printStackTrace();
177 | }
178 | return (autoActivateAfterLetters && Character.isLetter(ch)) ||
179 | (autoActivateChars!=null && autoActivateChars.indexOf(ch)>-1);
180 | }
181 |
182 |
183 | /**
184 | * Sets the characters that auto-activation should occur after. A Java
185 | * completion provider, for example, might want to set others
186 | * to ".
", to allow auto-activation for members of an object.
187 | *
188 | * @param letters Whether auto-activation should occur after any letter.
189 | * @param others A string of (non-letter) chars that auto-activation should
190 | * occur after. This may be null
.
191 | */
192 | public void setAutoActivationRules(boolean letters, String others) {
193 | autoActivateAfterLetters = letters;
194 | autoActivateChars = others;
195 | }
196 |
197 |
198 | /**
199 | * Sets the param choices provider. This is used when a user
200 | * code-completes a parameterized completion, such as a function or method.
201 | * For any parameter to the function/method, this object can return
202 | * possible completions.
203 | *
204 | * @param pcp The parameter choices provider, or null
for
205 | * none.
206 | * @see #getParameterChoicesProvider()
207 | */
208 | public void setParameterChoicesProvider(ParameterChoicesProvider pcp) {
209 | paramChoicesProvider = pcp;
210 | }
211 |
212 |
213 | @Override
214 | public void setListCellRenderer(ListCellRenderer r) {
215 | listCellRenderer = r;
216 | }
217 |
218 |
219 | @Override
220 | public void setParameterizedCompletionParams(char listStart,
221 | String separator, char listEnd) {
222 | if (listStart<0x20 || listStart==0x7F) {
223 | throw new IllegalArgumentException("Invalid listStart");
224 | }
225 | if (listEnd<0x20 || listEnd==0x7F) {
226 | throw new IllegalArgumentException("Invalid listEnd");
227 | }
228 | if (separator==null || separator.isEmpty()) {
229 | throw new IllegalArgumentException("Invalid separator");
230 | }
231 | paramListStart = listStart;
232 | paramListSeparator = separator;
233 | paramListEnd = listEnd;
234 | }
235 |
236 |
237 | @Override
238 | public void setParent(CompletionProvider parent) {
239 | this.parent = parent;
240 | }
241 |
242 |
243 | }
244 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/DefaultCompletionProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * DefaultCompletionProvider.java - A basic completion provider implementation.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import java.awt.Point;
12 | import java.io.BufferedInputStream;
13 | import java.io.File;
14 | import java.io.IOException;
15 | import java.io.InputStream;
16 | import java.nio.file.Files;
17 | import java.util.ArrayList;
18 | import java.util.List;
19 | import javax.swing.text.BadLocationException;
20 | import javax.swing.text.Document;
21 | import javax.swing.text.Element;
22 | import javax.swing.text.JTextComponent;
23 | import javax.swing.text.Segment;
24 | import javax.xml.parsers.ParserConfigurationException;
25 | import javax.xml.parsers.SAXParser;
26 | import javax.xml.parsers.SAXParserFactory;
27 | import org.xml.sax.SAXException;
28 |
29 |
30 | /**
31 | * A basic completion provider implementation. This provider has no
32 | * understanding of language semantics. It simply checks the text entered up
33 | * to the caret position for a match against known completions. This is all
34 | * that is needed in the majority of cases.
35 | *
36 | * @author Robert Futrell
37 | * @version 1.0
38 | */
39 | public class DefaultCompletionProvider extends AbstractCompletionProvider {
40 |
41 | /**
42 | * A buffer used when generating completion results.
43 | */
44 | protected Segment seg;
45 |
46 | /**
47 | * Used to speed up {@link #getCompletionsAt(JTextComponent, Point)}.
48 | */
49 | private String lastCompletionsAtText;
50 |
51 | /**
52 | * Used to speed up {@link #getCompletionsAt(JTextComponent, Point)},
53 | * since this may be called multiple times in succession (this is usually
54 | * called by {@code JTextComponent.getToolTipText()}, and if the user
55 | * wiggles the mouse while a tool tip is displayed, this method gets
56 | * repeatedly called. It can be costly, so we try to speed it up a tad).
57 | */
58 | private List lastParameterizedCompletionsAt;
59 |
60 | /**
61 | * Constructor. The returned provider will not be aware of any completions.
62 | *
63 | * @see #addCompletion(Completion)
64 | */
65 | public DefaultCompletionProvider() {
66 | init();
67 | }
68 |
69 |
70 | /**
71 | * Creates a completion provider that provides completion for a simple
72 | * list of words.
73 | *
74 | * @param words The words to offer as completion suggestions. If this is
75 | * null
, no completions will be known.
76 | * @see BasicCompletion
77 | */
78 | public DefaultCompletionProvider(String[] words) {
79 | init();
80 | addWordCompletions(words);
81 | }
82 |
83 |
84 | /**
85 | * Returns the text just before the current caret position that could be
86 | * the start of something auto-completable.
87 | *
88 | * This method returns all characters before the caret that are matched
89 | * by {@link #isValidChar(char)}.
90 | *
91 | * {@inheritDoc}
92 | */
93 | @Override
94 | public String getAlreadyEnteredText(JTextComponent comp) {
95 |
96 | Document doc = comp.getDocument();
97 |
98 | int dot = comp.getCaretPosition();
99 | Element root = doc.getDefaultRootElement();
100 | int index = root.getElementIndex(dot);
101 | Element elem = root.getElement(index);
102 | int start = elem.getStartOffset();
103 | int len = dot-start;
104 | try {
105 | doc.getText(start, len, seg);
106 | } catch (BadLocationException ble) {
107 | ble.printStackTrace();
108 | return EMPTY_STRING;
109 | }
110 |
111 | int segEnd = seg.offset + len;
112 | start = segEnd - 1;
113 | while (start>=seg.offset && isValidChar(seg.array[start])) {
114 | start--;
115 | }
116 | start++;
117 |
118 | len = segEnd - start;
119 | return len==0 ? EMPTY_STRING : new String(seg.array, start, len);
120 |
121 | }
122 |
123 |
124 | @Override
125 | public List getCompletionsAt(JTextComponent tc, Point p) {
126 |
127 | int offset = tc.viewToModel(p);
128 | if (offset<0 || offset>=tc.getDocument().getLength()) {
129 | lastCompletionsAtText = null;
130 | return lastParameterizedCompletionsAt = null;
131 | }
132 |
133 | Segment s = new Segment();
134 | Document doc = tc.getDocument();
135 | Element root = doc.getDefaultRootElement();
136 | int line = root.getElementIndex(offset);
137 | Element elem = root.getElement(line);
138 | int start = elem.getStartOffset();
139 | int end = elem.getEndOffset() - 1;
140 |
141 | try {
142 |
143 | doc.getText(start, end-start, s);
144 |
145 | // Get the valid chars before the specified offset.
146 | int startOffs = s.offset + (offset-start) - 1;
147 | while (startOffs>=s.offset && isValidChar(s.array[startOffs])) {
148 | startOffs--;
149 | }
150 |
151 | // Get the valid chars at and after the specified offset.
152 | int endOffs = s.offset + (offset-start);
153 | while (endOffs list = getCompletionByInputText(text);
169 | lastCompletionsAtText = text;
170 | return lastParameterizedCompletionsAt = list;
171 |
172 | } catch (BadLocationException ble) {
173 | ble.printStackTrace(); // Never happens
174 | }
175 |
176 | lastCompletionsAtText = null;
177 | return lastParameterizedCompletionsAt = null;
178 |
179 | }
180 |
181 |
182 | @Override
183 | public List getParameterizedCompletions(
184 | JTextComponent tc) {
185 |
186 | List list = null;
187 |
188 | // If this provider doesn't support parameterized completions,
189 | // bail out now.
190 | char paramListStart = getParameterListStart();
191 | if (paramListStart==0) {
192 | return list; // null
193 | }
194 |
195 | int dot = tc.getCaretPosition();
196 | Segment s = new Segment();
197 | Document doc = tc.getDocument();
198 | Element root = doc.getDefaultRootElement();
199 | int line = root.getElementIndex(dot);
200 | Element elem = root.getElement(line);
201 | int offs = elem.getStartOffset();
202 | int len = dot - offs - 1/*paramListStart.length()*/;
203 | if (len<=0) { // Not enough chars on the line for a method.
204 | return list; // null
205 | }
206 |
207 | try {
208 |
209 | doc.getText(offs, len, s);
210 |
211 | // Get the identifier preceding the '(', ignoring any whitespace
212 | // between them.
213 | offs = s.offset + len - 1;
214 | while (offs>=s.offset && Character.isWhitespace(s.array[offs])) {
215 | offs--;
216 | }
217 | int end = offs;
218 | while (offs>=s.offset && isValidChar(s.array[offs])) {
219 | offs--;
220 | }
221 |
222 | String text = new String(s.array, offs+1, end-offs);
223 |
224 | // Get a list of all Completions matching the text, but then
225 | // narrow it down to just the ParameterizedCompletions.
226 | List l = getCompletionByInputText(text);
227 | if (l!=null && !l.isEmpty()) {
228 | for (Object o : l) {
229 | if (o instanceof ParameterizedCompletion) {
230 | if (list == null) {
231 | list = new ArrayList<>(1);
232 | }
233 | list.add((ParameterizedCompletion) o);
234 | }
235 | }
236 | }
237 |
238 | } catch (BadLocationException ble) {
239 | ble.printStackTrace(); // Never happens
240 | }
241 |
242 | return list;
243 |
244 | }
245 |
246 |
247 | /**
248 | * Initializes this completion provider.
249 | */
250 | protected void init() {
251 | seg = new Segment();
252 | }
253 |
254 |
255 | /**
256 | * Returns whether the specified character is valid in an auto-completion.
257 | * The default implementation is equivalent to
258 | * "Character.isLetterOrDigit(ch) || ch=='_'
". Subclasses
259 | * can override this method to change what characters are matched.
260 | *
261 | * @param ch The character.
262 | * @return Whether the character is valid.
263 | */
264 | protected boolean isValidChar(char ch) {
265 | return Character.isLetterOrDigit(ch) || ch=='_';
266 | }
267 |
268 |
269 | /**
270 | * Loads completions from an XML file. The XML should validate against
271 | * CompletionXml.dtd
.
272 | *
273 | * @param file An XML file to load from.
274 | * @throws IOException If an IO error occurs.
275 | */
276 | public void loadFromXML(File file) throws IOException {
277 | try (BufferedInputStream bin = new BufferedInputStream(
278 | Files.newInputStream(file.toPath()))) {
279 | loadFromXML(bin);
280 | }
281 | }
282 |
283 |
284 | /**
285 | * Loads completions from an XML input stream. The XML should validate
286 | * against CompletionXml.dtd
.
287 | *
288 | * @param in The input stream to read from.
289 | * @throws IOException If an IO error occurs.
290 | */
291 | public void loadFromXML(InputStream in) throws IOException {
292 | loadFromXML(in, null);
293 | }
294 |
295 |
296 | /**
297 | * Loads completions from an XML input stream. The XML should validate
298 | * against CompletionXml.dtd
.
299 | *
300 | * @param in The input stream to read from.
301 | * @param cl The class loader to use when loading any extra classes defined
302 | * in the XML, such as custom {@link FunctionCompletion}s. This
303 | * may be null
if the default is to be used, or if no
304 | * custom completions are defined in the XML.
305 | * @throws IOException If an IO error occurs.
306 | */
307 | public void loadFromXML(InputStream in, ClassLoader cl) throws IOException {
308 |
309 | SAXParserFactory factory = SAXParserFactory.newInstance();
310 | factory.setValidating(true);
311 | CompletionXMLParser handler = new CompletionXMLParser(this, cl);
312 | try (BufferedInputStream bin = new BufferedInputStream(in)) {
313 | SAXParser saxParser = factory.newSAXParser();
314 | saxParser.parse(bin, handler);
315 | List completions = handler.getCompletions();
316 | addCompletions(completions);
317 | char startChar = handler.getParamStartChar();
318 | if (startChar != 0) {
319 | char endChar = handler.getParamEndChar();
320 | String sep = handler.getParamSeparator();
321 | // Sanity check. Note endChar can be null
322 | if (sep != null && sep.length() > 0) {
323 | setParameterizedCompletionParams(startChar, sep, endChar);
324 | }
325 | }
326 | } catch (SAXException | ParserConfigurationException e) {
327 | throw new IOException(e.toString());
328 | }
329 |
330 | }
331 |
332 |
333 | /**
334 | * Loads completions from an XML file. The XML should validate against
335 | * CompletionXml.dtd
.
336 | *
337 | * @param resource A resource the current ClassLoader can get to.
338 | * @throws IOException If an IO error occurs.
339 | */
340 | public void loadFromXML(String resource) throws IOException {
341 | ClassLoader cl = getClass().getClassLoader();
342 | InputStream in = cl.getResourceAsStream(resource);
343 | if (in==null) {
344 | File file = new File(resource);
345 | if (file.isFile()) {
346 | in = Files.newInputStream(file.toPath());
347 | }
348 | else {
349 | throw new IOException("No such resource: " + resource);
350 | }
351 | }
352 | try (BufferedInputStream bin = new BufferedInputStream(in)) {
353 | loadFromXML(bin);
354 | }
355 | }
356 |
357 |
358 | }
359 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/DelegatingCellRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/22/2008
3 | *
4 | * DelegatingCellRenderer.java - A renderer for Completions that will delegate
5 | * to the Completion's provider's renderer, if there is one.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.awt.Component;
13 | import javax.swing.DefaultListCellRenderer;
14 | import javax.swing.JComponent;
15 | import javax.swing.JList;
16 | import javax.swing.ListCellRenderer;
17 |
18 |
19 | /**
20 | * List cell renderer that delegates to a {@link CompletionProvider}'s
21 | * renderer, if it has one. If it doesn't, it calls into a fallback renderer.
22 | * If a fallback renderer isn't specified, it simply renders
23 | * (({@link Completion})value).toString()
.
24 | *
25 | * @author Robert Futrell
26 | * @version 1.0
27 | */
28 | class DelegatingCellRenderer extends DefaultListCellRenderer {
29 |
30 | /**
31 | * The renderer to fall back on if one isn't specified by a provider.
32 | * This is usually {@code this}.
33 | */
34 | private ListCellRenderer fallback;
35 |
36 |
37 | /**
38 | * Returns the fallback cell renderer.
39 | *
40 | * @return The fallback cell renderer.
41 | * @see #setFallbackCellRenderer(ListCellRenderer)
42 | */
43 | public ListCellRenderer getFallbackCellRenderer() {
44 | return fallback;
45 | }
46 |
47 |
48 | @Override
49 | public Component getListCellRendererComponent(JList> list, Object value,
50 | int index, boolean selected, boolean hasFocus) {
51 | Completion c = (Completion)value;
52 | CompletionProvider p = c.getProvider();
53 | ListCellRenderer r = p.getListCellRenderer();
54 | if (r!=null) {
55 | return r.getListCellRendererComponent(list, value, index, selected,
56 | hasFocus);
57 | }
58 | if (fallback==null) {
59 | return super.getListCellRendererComponent(list, value, index,
60 | selected, hasFocus);
61 | }
62 | return fallback.getListCellRendererComponent(list, value, index,
63 | selected, hasFocus);
64 | }
65 |
66 |
67 | /**
68 | * Sets the fallback cell renderer.
69 | *
70 | * @param fallback The fallback cell renderer. If this is
71 | * null
, {@code this} will be used.
72 | * @see #getFallbackCellRenderer()
73 | */
74 | public void setFallbackCellRenderer(ListCellRenderer fallback) {
75 | this.fallback = fallback;
76 | }
77 |
78 |
79 | @Override
80 | public void updateUI() {
81 | super.updateUI();
82 | if ((fallback instanceof JComponent) && fallback!=this) {
83 | ((JComponent)fallback).updateUI();
84 | }
85 | }
86 |
87 |
88 | }
89 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/DescWindowCallback.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 05/11/2012
3 | *
4 | * This library is distributed under a modified BSD license. See the included
5 | * LICENSE.md file for details.
6 | */
7 | package org.fife.ui.autocomplete;
8 |
9 |
10 | /**
11 | * Passed to {@link ExternalURLHandler}s as a way for them to display a summary
12 | * for a new completion in response to a link event.
13 | *
14 | * @author Robert Futrell
15 | * @version 1.0
16 | * @see ExternalURLHandler
17 | */
18 | public interface DescWindowCallback {
19 |
20 |
21 | /**
22 | * Callback allowing a new code completion's description to be displayed
23 | * in the description window.
24 | *
25 | * @param completion The new completion.
26 | * @param anchor The anchor to scroll to, or null
if none.
27 | */
28 | void showSummaryFor(Completion completion, String anchor);
29 |
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/EmptyIcon.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 04/29/2010
3 | *
4 | * EmptyIcon.java - The canonical icon that paints nothing.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import java.awt.Component;
12 | import java.awt.Graphics;
13 | import java.io.Serializable;
14 | import javax.swing.Icon;
15 |
16 |
17 | /**
18 | * A standard icon that doesn't paint anything. This can be used when some
19 | * Completion
s have icons and others don't, to visually align the
20 | * text of all completions.
21 | *
22 | * @author Robert Futrell
23 | * @version 1.0
24 | */
25 | public class EmptyIcon implements Icon, Serializable {
26 |
27 | /**
28 | * The size of the icon.
29 | */
30 | private int size;
31 |
32 |
33 | /**
34 | * Constructor.
35 | *
36 | * @param size The size of this icon.
37 | */
38 | public EmptyIcon(int size) {
39 | this.size = size;
40 | }
41 |
42 |
43 | @Override
44 | public int getIconHeight() {
45 | return size;
46 | }
47 |
48 |
49 | @Override
50 | public int getIconWidth() {
51 | return size;
52 | }
53 |
54 |
55 | @Override
56 | public void paintIcon(Component c, Graphics g, int x, int y) {
57 | }
58 |
59 |
60 | /**
61 | * Sets the size of this icon. The parent container will likely need
62 | * to be revalidated if this is called after the UI is displayed.
63 | *
64 | * @param size The new icon size.
65 | */
66 | public void setSize(int size) {
67 | this.size = size;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/ExternalURLHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/23/2008
3 | *
4 | * ExternalURLHandler.java - Implementations can be registered as a callback
5 | * to handle the user clicking on external URLs.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import javax.swing.event.HyperlinkEvent;
13 |
14 |
15 | /**
16 | * A callback for when an external URL is clicked in the description window.
17 | * If no handler is installed, the system default web browser is used to open
18 | * the URL.
19 | *
20 | * Alternatively, folks implementing robust code completion support for a
21 | * language might install an ExternalURLHandler
to handle
22 | * navigating through linked documentation of objects, functions, etc.
23 | *
24 | * @author Robert Futrell
25 | * @version 1.0
26 | * @see AutoCompletion#setExternalURLHandler(ExternalURLHandler)
27 | */
28 | public interface ExternalURLHandler {
29 |
30 |
31 | /**
32 | * Called when an external URL is clicked in the description window.
33 | *
34 | * @param e The event containing the hyperlink clicked.
35 | * @param c The completion currently being displayed.
36 | * @param callback Allows you to display new content in the description
37 | * window.
38 | */
39 | void urlClicked(HyperlinkEvent e, Completion c,
40 | DescWindowCallback callback);
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/FastListUI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 04/26/2010
3 | *
4 | * FastListUI.java - A JList UI implementation that computes the preferred size
5 | * of all cells really fast, to facilitate lists of possibly thousands of items
6 | * rendered with HTML, which is slow with BasicListUI extensions.
7 | *
8 | * This library is distributed under a modified BSD license. See the included
9 | * LICENSE.md file for details.
10 | */
11 | package org.fife.ui.autocomplete;
12 |
13 | import java.awt.*;
14 | import javax.swing.JViewport;
15 | import javax.swing.ListCellRenderer;
16 | import javax.swing.ListModel;
17 | import javax.swing.UIManager;
18 | import javax.swing.plaf.basic.BasicListUI;
19 |
20 |
21 | /**
22 | * A custom list UI, used by the completion choices list. If the number of
23 | * completion choices is "large," it does a fast estimate of the preferred
24 | * width and height of list items. This allows HTML renderers to be used (such
25 | * as {@link CompletionCellRenderer}), with thousands of completion choices,
26 | * with no performance penalty. With standard BasicListUI subclasses, this can
27 | * cause very poor performance each time the list is displayed, which
28 | * is bad for lists that are repeatedly hidden and re-displayed, such as
29 | * completion choices. This is all because the calculation to get the
30 | * preferred size of each list item, when it is displayed with HTML, is slow.
31 | *
32 | * @author Robert Futrell
33 | * @version 1.0
34 | */
35 | class FastListUI extends BasicListUI {
36 |
37 | /**
38 | * Whether the selection background was overridden (usually because of
39 | * Nimbus) so we know to manually uninstall the color we installed.
40 | */
41 | private boolean overriddenBackground;
42 |
43 | /**
44 | * Whether the selection foreground was overridden (usually because of
45 | * Nimbus) so we know to manually uninstall the color we installed.
46 | */
47 | private boolean overriddenForeground;
48 |
49 | /**
50 | * If there are more than this many completions in a single list, this
51 | * UI will estimate the cell width and height needed for each item instead
52 | * of computing it, for performance reasons.
53 | */
54 | private static final int ESTIMATION_THRESHOLD = 200;
55 |
56 |
57 | private Color determineSelectionBackground() {
58 | Color c = UIManager.getColor("List.selectionBackground");
59 | if (c==null) {
60 | c = UIManager.getColor("nimbusSelectionBackground");
61 | if (c==null) { // Not Nimbus, but still need a value - fallback
62 | c = UIManager.getColor("textHighlight");
63 | if (c==null) {
64 | c = SystemColor.textHighlight;
65 | }
66 | }
67 | }
68 |
69 | // Nimbus unfortunately requires a Color, not a ColorUIResource, for
70 | // the background override to work. This causes this color to "stick"
71 | // even if the LAF is changed to something else later. "c" here may
72 | // actually be a ColorUIResource
73 | return new Color(c.getRGB());//new ColorUIResource(c);
74 |
75 | }
76 |
77 |
78 | private Color determineSelectionForeground() {
79 | Color c = UIManager.getColor("List.selectionForeground");
80 | if (c==null) {
81 | c = UIManager.getColor("nimbusSelectedText");
82 | if (c==null) { // Not Nimbus, but still need a value - fallback
83 | c = UIManager.getColor("textHighlightText");
84 | if (c==null) {
85 | c = SystemColor.textHighlightText;
86 | }
87 | }
88 | }
89 | // Nimbus unfortunately requires Color, not ColorUIResource, and "c"
90 | // may actually be a ColorUIResource
91 | return new Color(c.getRGB());
92 | }
93 |
94 |
95 | /**
96 | * Overridden to ensure we have selection background/foreground colors
97 | * defined, even if we're in some weirdo LAF such as Nimbus which doesn't
98 | * define them. Since FastListUI extends BasicListUI, we need these values
99 | * to be defined.
100 | */
101 | @Override
102 | protected void installDefaults() {
103 |
104 | super.installDefaults();
105 |
106 | if (list.getSelectionBackground()==null) {
107 | list.setSelectionBackground(determineSelectionBackground());
108 | overriddenBackground = true;
109 | }
110 |
111 | if (list.getSelectionForeground()==null) {
112 | list.setSelectionForeground(determineSelectionForeground());
113 | overriddenForeground = true;
114 | }
115 | }
116 |
117 |
118 | /**
119 | * Overridden to work around a Nimbus issue.
120 | */
121 | @Override
122 | protected void uninstallDefaults() {
123 |
124 | super.uninstallDefaults();
125 |
126 | if (overriddenBackground) {
127 | list.setSelectionBackground(null);
128 | }
129 |
130 | if (overriddenForeground) {
131 | list.setSelectionForeground(null);
132 | }
133 |
134 | }
135 |
136 |
137 | /**
138 | * Recalculates the cell width and height of each cell in the list. This
139 | * method is overridden to do a fast estimation if the completion list is
140 | * too long, to improve performance for lists with huge amounts of
141 | * completions.
142 | */
143 | @Override
144 | @SuppressWarnings("unchecked") // BasicListUI has unparameterized JList
145 | protected void updateLayoutState() {
146 |
147 | ListModel> model = list.getModel();
148 | int itemCount = model.getSize();
149 |
150 | // If the item count is small enough to run fast on practically all
151 | // machines, go ahead and use the super implementation to determine
152 | // the optimal cell sizes.
153 | if (itemCount renderer = (ListCellRenderer)list.getCellRenderer();
161 |
162 | cellWidth = list.getWidth();
163 | if (list.getParent() instanceof JViewport) { // Always true for us
164 | cellWidth = list.getParent().getWidth();
165 | }
166 | //System.out.println(cellWidth);
167 |
168 | // We're getting a fixed cell height for all cells
169 | cellHeights = null;
170 |
171 | if (renderer != null) { // Definitely true that itemCount > 0 due to check above
172 | Object value = model.getElementAt(0);
173 | Component c = renderer.getListCellRendererComponent(list,
174 | value, 0, false, false);
175 | rendererPane.add(c);
176 | Dimension cellSize = c.getPreferredSize();
177 | cellHeight = cellSize.height;
178 | cellWidth = Math.max(cellWidth, cellSize.width);
179 | }
180 | else {
181 | cellHeight = 20;
182 | }
183 |
184 | }
185 |
186 |
187 | }
188 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/LinkRedirector.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 05/16/2012
3 | *
4 | * This library is distributed under a modified BSD license. See the included
5 | * LICENSE.md file for details.
6 | */
7 | package org.fife.ui.autocomplete;
8 |
9 | import java.net.URL;
10 |
11 |
12 | /**
13 | * Possibly redirects one URL to another. Useful if you want "external" URLs
14 | * in code completion documentation to point to a local copy instead, for
15 | * example.
16 | *
17 | * @author Robert Futrell
18 | * @version 1.0
19 | */
20 | public interface LinkRedirector {
21 |
22 |
23 | /**
24 | * Hook to return an alternate URL to navigate to when a URL is clicked in
25 | * an {@code RSyntaxTextArea} instance.
26 | *
27 | * @param original The original URL, e.g. from a {@code HyperlinkEvent}.
28 | * @return The link to redirect to, or {@code null} if the original URL
29 | * should still be used.
30 | */
31 | URL possiblyRedirect(URL original);
32 |
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/MarkupTagCompletion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 01/06/2009
3 | *
4 | * MarkupTagCompletion.java - A completion representing a tag in markup, such
5 | * as HTML or XML.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 |
15 | import org.fife.ui.autocomplete.ParameterizedCompletion.Parameter;
16 |
17 |
18 | /**
19 | * A completion representing a tag in markup, such as HTML or XML.
20 | *
21 | * @author Robert Futrell
22 | * @version 1.0
23 | */
24 | public class MarkupTagCompletion extends AbstractCompletion {
25 |
26 | private String name;
27 | private String desc;
28 | private String definedIn;
29 |
30 | /**
31 | * Attributes of the tag.
32 | */
33 | private List attrs;
34 |
35 |
36 | /**
37 | * Constructor.
38 | *
39 | * @param provider The parent provider instance.
40 | * @param name The name of the tag.
41 | */
42 | public MarkupTagCompletion(CompletionProvider provider, String name) {
43 | super(provider);
44 | this.name = name;
45 | }
46 |
47 |
48 | /**
49 | * Adds HTML describing the attributes of this tag to a buffer.
50 | *
51 | * @param sb The buffer to append to.
52 | */
53 | protected void addAttributes(StringBuilder sb) {
54 |
55 | // TODO: Localize me.
56 |
57 | int attrCount = getAttributeCount();
58 | if (attrCount>0) {
59 | sb.append("Attributes: ");
60 | sb.append("");
61 | for (int i=0; i");
64 | sb.append(attr.getName()!=null ? attr.getName() :
65 | attr.getType());
66 | sb.append(" ");
67 | String desc = attr.getDescription();
68 | if (desc!=null) {
69 | sb.append(desc);
70 | }
71 | sb.append(" ");
72 | }
73 | sb.append("
");
74 | }
75 |
76 | }
77 |
78 |
79 | /**
80 | * Adds the definition string for this completion to a buffer.
81 | *
82 | * @param sb The buffer to add to.
83 | */
84 | protected void addDefinitionString(StringBuilder sb) {
85 | sb.append("").append(name).append(" ");
86 | }
87 |
88 |
89 | /**
90 | * Returns all attributes of this tag.
91 | *
92 | * @return A list of {@link ParameterizedCompletion.Parameter}s.
93 | * @see #getAttribute(int)
94 | * @see #getAttributeCount()
95 | */
96 | public List getAttributes() {
97 | return attrs;
98 | }
99 |
100 |
101 | /**
102 | * Returns the specified {@link ParameterizedCompletion.Parameter}.
103 | *
104 | * @param index The index of the attribute to retrieve.
105 | * @return The attribute.
106 | * @see #getAttributeCount()
107 | */
108 | public Parameter getAttribute(int index) {
109 | return attrs.get(index);
110 | }
111 |
112 |
113 | /**
114 | * Returns the number of attributes of this tag.
115 | *
116 | * @return The number of attributes of this tag.
117 | * @see #getAttribute(int)
118 | */
119 | public int getAttributeCount() {
120 | return attrs==null ? 0 : attrs.size();
121 | }
122 |
123 |
124 | /**
125 | * Returns where this variable is defined.
126 | *
127 | * @return Where this variable is defined.
128 | * @see #setDefinedIn(String)
129 | */
130 | public String getDefinedIn() {
131 | return definedIn;
132 | }
133 |
134 |
135 | /**
136 | * Returns a short description of this variable. This should be an
137 | * HTML snippet.
138 | *
139 | * @return A short description of this variable. This may be
140 | * null
.
141 | * @see #setDescription(String)
142 | */
143 | public String getDescription() {
144 | return desc;
145 | }
146 |
147 |
148 | /**
149 | * Returns the name of this tag.
150 | *
151 | * @return The name of this tag.
152 | */
153 | public String getName() {
154 | return name;
155 | }
156 |
157 |
158 | @Override
159 | public String getReplacementText() {
160 | return getName();
161 | }
162 |
163 |
164 | @Override
165 | public String getSummary() {
166 | StringBuilder sb = new StringBuilder();
167 | addDefinitionString(sb);
168 | possiblyAddDescription(sb);
169 | addAttributes(sb);
170 | possiblyAddDefinedIn(sb);
171 | return sb.toString();
172 | }
173 |
174 |
175 | /**
176 | * Adds some HTML describing where this variable is defined, if this
177 | * information is known.
178 | *
179 | * @param sb The buffer to append to.
180 | */
181 | protected void possiblyAddDefinedIn(StringBuilder sb) {
182 | if (definedIn!=null) {
183 | sb.append(" Defined in:"); // TODO: Localize me
184 | sb.append(" ").append(definedIn).append(" ");
185 | }
186 | }
187 |
188 |
189 | /**
190 | * Adds the description text as HTML to a buffer, if a description is
191 | * defined.
192 | *
193 | * @param sb The buffer to append to.
194 | */
195 | protected void possiblyAddDescription(StringBuilder sb) {
196 | if (desc!=null) {
197 | sb.append(" ");
198 | sb.append(desc);
199 | sb.append(" ");
200 | }
201 | }
202 |
203 |
204 | /**
205 | * Sets where this variable is defined.
206 | *
207 | * @param definedIn Where this variable is defined.
208 | * @see #getDefinedIn()
209 | */
210 | public void setDefinedIn(String definedIn) {
211 | this.definedIn = definedIn;
212 | }
213 |
214 |
215 | /**
216 | * Sets the short description of this tag. This should be an
217 | * HTML snippet.
218 | *
219 | * @param desc A short description of this tag. This may be
220 | * null
.
221 | * @see #getDescription()
222 | */
223 | public void setDescription(String desc) {
224 | this.desc = desc;
225 | }
226 |
227 |
228 | /**
229 | * Sets the attributes of this tag.
230 | *
231 | * @param attrs The attributes.
232 | * @see #getAttribute(int)
233 | * @see #getAttributeCount()
234 | */
235 | public void setAttributes(List extends Parameter> attrs) {
236 | // Deep copy so parsing can re-use its array.
237 | this.attrs = new ArrayList<>(attrs);
238 | }
239 |
240 |
241 | }
242 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/OutlineHighlightPainter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 04/26/2009
3 | *
4 | * OutlineHighlightPainter.java - Highlight painter that draws an outline
5 | * around its text.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.awt.Color;
13 | import java.awt.Graphics;
14 | import java.awt.Rectangle;
15 | import java.awt.Shape;
16 | import javax.swing.text.BadLocationException;
17 | import javax.swing.text.DefaultHighlighter;
18 | import javax.swing.text.JTextComponent;
19 | import javax.swing.text.Position;
20 | import javax.swing.text.View;
21 |
22 |
23 | /*
24 | * NOTE: Whenever you see text like "Workaround for Java Highlight issues",
25 | * this is because highlighted text in a JTextComponent gets "pushed" forward
26 | * when the caret is at the Highlight's start, when we need it to instead get
27 | * prepended to. For this reason, the auto-complete package adds its Highlights
28 | * 1 char too long (1 char earlier than where it should really start), but only
29 | * paint the Highlight from the 2nd char on.
30 | */
31 | /**
32 | * Highlight painter that draws an outline around the text. This is used to
33 | * draw bounds around function/method parameters.
34 | *
35 | * @author Robert Futrell
36 | * @version 1.0
37 | */
38 | class OutlineHighlightPainter extends
39 | DefaultHighlighter.DefaultHighlightPainter {
40 |
41 | /**
42 | * DefaultHighlightPainter doesn't allow changing color, so we must cache
43 | * ours here.
44 | */
45 | private Color color;
46 |
47 |
48 | /**
49 | * Constructor.
50 | *
51 | * @param color The color to draw the bounding boxes with. This cannot
52 | * be null
.
53 | */
54 | OutlineHighlightPainter(Color color) {
55 | super(color);
56 | this.color = color != null? color : Color.BLACK; // SpotBugs
57 | }
58 |
59 |
60 | /**
61 | * Returns the color to paint bounding boxes with.
62 | *
63 | * @return The color.
64 | * @see #setColor(Color)
65 | */
66 | @Override
67 | public Color getColor() {
68 | return color;
69 | }
70 |
71 |
72 | @Override
73 | public Shape paintLayer(Graphics g, int p0, int p1, Shape viewBounds,
74 | JTextComponent c, View view) {
75 |
76 | g.setColor(getColor());
77 | p0++; // Workaround for Java Highlight issues.
78 |
79 | // This special case isn't needed for most standard Swing Views (which
80 | // always return a width of 1 for modelToView() calls), but it is
81 | // needed for RSTA views, which actually return the width of chars for
82 | // modelToView calls. But this should be faster anyway, as we
83 | // short-circuit and do only one modelToView() for one offset.
84 | if (p0==p1) {
85 | try {
86 | Shape s = view.modelToView(p0, viewBounds,
87 | Position.Bias.Forward);
88 | Rectangle r = s.getBounds();
89 | g.drawLine(r.x, r.y, r.x, r.y+r.height);
90 | return r;
91 | } catch (BadLocationException ble) {
92 | ble.printStackTrace(); // Never happens
93 | return null;
94 | }
95 | }
96 |
97 | if (p0 == view.getStartOffset() && p1 == view.getEndOffset()) {
98 | // Contained in view, can just use bounds.
99 | Rectangle alloc;
100 | if (viewBounds instanceof Rectangle) {
101 | alloc = (Rectangle) viewBounds;
102 | } else {
103 | alloc = viewBounds.getBounds();
104 | }
105 | g.drawRect(alloc.x, alloc.y, alloc.width - 1, alloc.height - 1);
106 | return alloc;
107 | }
108 |
109 | // Should only render part of View.
110 | try {
111 | // --- determine locations ---
112 | Shape shape = view.modelToView(p0, Position.Bias.Forward, p1,
113 | Position.Bias.Backward, viewBounds);
114 | Rectangle r = (shape instanceof Rectangle) ? (Rectangle) shape :
115 | shape.getBounds();
116 | g.drawRect(r.x, r.y, r.width - 1, r.height - 1);
117 | return r;
118 | } catch (BadLocationException e) { // Never happens
119 | e.printStackTrace();
120 | return null;
121 | }
122 |
123 | }
124 |
125 |
126 | /**
127 | * Sets the color to paint the bounding boxes with.
128 | *
129 | * @param color The new color. This cannot be null
.
130 | * @see #getColor()
131 | */
132 | public void setColor(Color color) {
133 | if (color==null) {
134 | throw new IllegalArgumentException("color cannot be null");
135 | }
136 | this.color = color;
137 | }
138 |
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/ParameterChoicesProvider.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/14/2010
3 | *
4 | * ParameterChoicesProvider.java - Provides completions for a
5 | * ParameterizedCompletion's parameters.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.util.List;
13 | import javax.swing.text.JTextComponent;
14 |
15 |
16 | /**
17 | * Provides completions for a {@link ParameterizedCompletion}'s parameters.
18 | * So, for example, if the user code-completes a function or method, if
19 | * a ParameterChoicesProvider
is installed, it can return possible
20 | * completions for the parameters to that function or method.
21 | *
22 | * @author Robert Futrell
23 | * @version 1.0
24 | */
25 | public interface ParameterChoicesProvider {
26 |
27 |
28 | /**
29 | * Returns a list of choices for a specific parameter.
30 | *
31 | * @param tc The text component.
32 | * @param param The currently focused parameter.
33 | * @return The list of parameters. This may be null
for
34 | * "no parameters," but might also be an empty list.
35 | */
36 | List getParameterChoices(JTextComponent tc,
37 | ParameterizedCompletion.Parameter param);
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/ParameterizedCompletion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/11/2010
3 | *
4 | * ParameterizedCompletion.java - A completion option.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import javax.swing.text.JTextComponent;
12 |
13 |
14 | /**
15 | * A completion option that takes parameters, such as a function or method.
16 | *
17 | * In order to use any instance of a {@code ParameterizedCompletion}, you need
18 | * to call {@link AutoCompletion#setParameterAssistanceEnabled(boolean)} with
19 | * a value of {@code true} first. Otherwise, any completion choices will be
20 | * visible in the completion list, but won't insert anything when selected.
21 | *
22 | * @author Robert Futrell
23 | * @version 1.0
24 | */
25 | public interface ParameterizedCompletion extends Completion {
26 |
27 |
28 | /**
29 | * Returns the "definition string" for this completion. For example,
30 | * for the C "printf
" function, this would return
31 | * "int printf(const char *, ...)
".
32 | *
33 | * @return The definition string.
34 | */
35 | String getDefinitionString();
36 |
37 |
38 | /**
39 | * Returns the specified {@link Parameter}.
40 | *
41 | * @param index The index of the parameter to retrieve.
42 | * @return The parameter.
43 | * @see #getParamCount()
44 | */
45 | Parameter getParam(int index);
46 |
47 |
48 | /**
49 | * Returns the number of parameters this completion takes.
50 | *
51 | * @return The number of parameters this completion takes.
52 | * @see #getParam(int)
53 | */
54 | int getParamCount();
55 |
56 |
57 | /**
58 | * Returns completion information for this parameterized completion,
59 | * given the specified text component.
60 | *
61 | * @param tc The text component.
62 | * @param replaceTabsWithSpaces Whether to replace tabs with spaces.
63 | * @return The completion info.
64 | */
65 | ParameterizedCompletionInsertionInfo getInsertionInfo(
66 | JTextComponent tc, boolean replaceTabsWithSpaces);
67 |
68 |
69 | /**
70 | * Returns whether a tool tip displaying assistance for each parameter
71 | * while it is being edited is appropriate for this completion.
72 | *
73 | * @return Whether the tool tip is appropriate to display.
74 | */
75 | boolean getShowParameterToolTip();
76 |
77 |
78 | /**
79 | * A parameter passed to a parameterized {@link Completion}.
80 | */
81 | class Parameter {
82 |
83 | private String name;
84 | private Object type;
85 | private String desc;
86 | private boolean isEndParam;
87 |
88 | /**
89 | * Constructor.
90 | *
91 | * @param type The type of this parameter. This may be
92 | * null
for languages without specific types,
93 | * dynamic typing, etc. Usually you'll pass a String for this
94 | * value, but you may pass any object representing a type in
95 | * your language, as long as its toString()
method
96 | * returns a string representation of the type.
97 | * @param name The name of the parameter.
98 | */
99 | public Parameter(Object type, String name) {
100 | this(type, name, false);
101 | }
102 |
103 | /**
104 | * Constructor.
105 | *
106 | * @param type The type of this parameter. This may be
107 | * null
for languages without specific types,
108 | * dynamic typing, etc. Usually you'll pass a String for this
109 | * value, but you may pass any object representing a type in
110 | * your language, as long as its toString()
method
111 | * returns a string representation of the type.
112 | * @param name The name of the parameter.
113 | * @param endParam Whether this parameter is an "ending parameter;"
114 | * that is, whether this parameter is at a logical "ending
115 | * point" in the completion text. If the user types in a
116 | * parameter that is an ending point, parameter completion mode
117 | * terminates. Set this to true
for a trailing
118 | * parameter after a function call's closing ')', for example.
119 | */
120 | public Parameter(Object type, String name, boolean endParam) {
121 | this.name = name;
122 | this.type = type;
123 | this.isEndParam = endParam;
124 | }
125 |
126 | /**
127 | * Returns the description of this completion.
128 | *
129 | * @return The description of this completion.
130 | */
131 | public String getDescription() {
132 | return desc;
133 | }
134 |
135 | /**
136 | * Returns the name of this completion.
137 | *
138 | * @return The name of this completion.
139 | */
140 | public String getName() {
141 | return name;
142 | }
143 |
144 | /**
145 | * Returns the type of this parameter, as a string.
146 | *
147 | * @return The type of the parameter, or null
for none.
148 | */
149 | public String getType() {
150 | return type==null ? null : type.toString();
151 | }
152 |
153 | /**
154 | * Returns the object used to describe the type of this parameter.
155 | *
156 | * @return The type object, or null
for none.
157 | */
158 | public Object getTypeObject() {
159 | return type;
160 | }
161 |
162 | /**
163 | * @return Whether this parameter is an "ending parameter;"
164 | * that is, whether this parameter is at a logical "ending
165 | * point" in the completion text. If the user types in a
166 | * parameter that is an ending point, parameter completion mode
167 | * terminates.
168 | */
169 | public boolean isEndParam() {
170 | return isEndParam;
171 | }
172 |
173 | /**
174 | * Sets the description of this completion.
175 | *
176 | * @param desc The description.
177 | * @see #getDescription()
178 | */
179 | public void setDescription(String desc) {
180 | this.desc = desc;
181 | }
182 |
183 | @Override
184 | public String toString() {
185 | StringBuilder sb = new StringBuilder();
186 | if (getType()!=null) {
187 | sb.append(getType());
188 | }
189 | if (getName()!=null) {
190 | if (getType()!=null) {
191 | sb.append(' ');
192 | }
193 | sb.append(getName());
194 | }
195 | return sb.toString();
196 | }
197 |
198 | }
199 |
200 |
201 | }
202 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/11/2010
3 | *
4 | * ParameterizedCompletionChoicesWindow.java - A list of likely choices for a
5 | * parameter.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.awt.ComponentOrientation;
13 | import java.awt.Dimension;
14 | import java.awt.Rectangle;
15 | import java.awt.Window;
16 | import java.awt.event.MouseAdapter;
17 | import java.awt.event.MouseEvent;
18 | import java.util.ArrayList;
19 | import java.util.Comparator;
20 | import java.util.List;
21 | import javax.swing.DefaultListModel;
22 | import javax.swing.JList;
23 | import javax.swing.JScrollPane;
24 | import javax.swing.JWindow;
25 | import javax.swing.SwingUtilities;
26 | import javax.swing.text.JTextComponent;
27 |
28 | import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
29 |
30 |
31 | /**
32 | * A small popup window offering a list of likely choices for a parameter
33 | * when the user has code-completed a parameterized completion. For example,
34 | * if they have just code-completed the C function "fprintf
",
35 | * when entering the file name, this popup might display all local variables
36 | * of type "char *
".
37 | *
38 | * @author Robert Futrell
39 | * @version 1.0
40 | */
41 | public class ParameterizedCompletionChoicesWindow extends JWindow {
42 |
43 | /**
44 | * The parent AutoCompletion instance.
45 | */
46 | private AutoCompletion ac;
47 |
48 | /**
49 | * The list of completion choices.
50 | */
51 | private JList list;
52 |
53 | /**
54 | * The currently displayed completion choices.
55 | */
56 | private DefaultListModel model;
57 |
58 | /**
59 | * A list of lists of choices for each parameter.
60 | */
61 | private List> choicesListList;
62 |
63 | /**
64 | * The scroll pane containing the list.
65 | */
66 | private JScrollPane sp;
67 |
68 | /**
69 | * Comparator used to sort completions by their relevance before sorting
70 | * them lexicographically.
71 | */
72 | private static final Comparator SORT_BY_RELEVANCE_COMPARATOR =
73 | new SortByRelevanceComparator();
74 |
75 |
76 | /**
77 | * Constructor.
78 | *
79 | * @param parent The parent window (hosting the text component).
80 | * @param ac The auto-completion instance.
81 | * @param context The completion context.
82 | */
83 | public ParameterizedCompletionChoicesWindow(Window parent,
84 | AutoCompletion ac,
85 | final ParameterizedCompletionContext context) {
86 |
87 | super(parent);
88 | this.ac = ac;
89 | ComponentOrientation o = ac.getTextComponentOrientation();
90 |
91 | model = new DefaultListModel<>();
92 | list = new JList<>(model);
93 | if (ac.getParamChoicesRenderer()!=null) {
94 | list.setCellRenderer(ac.getParamChoicesRenderer());
95 | }
96 | list.addMouseListener(new MouseAdapter() {
97 | @Override
98 | public void mouseClicked(MouseEvent e) {
99 | if (e.getClickCount()==2) {
100 | context.insertSelectedChoice();
101 | }
102 | }
103 | });
104 | sp = new JScrollPane(list);
105 |
106 | setContentPane(sp);
107 | applyComponentOrientation(o);
108 | setFocusableWindowState(false);
109 |
110 | // Give apps a chance to decorate us with drop shadows, etc.
111 | PopupWindowDecorator decorator = PopupWindowDecorator.get();
112 | if (decorator!=null) {
113 | decorator.decorate(this);
114 | }
115 |
116 | }
117 |
118 |
119 | /**
120 | * Returns the selected value.
121 | *
122 | * @return The selected value, or null
if nothing is
123 | * selected.
124 | */
125 | public String getSelectedChoice() {
126 | Completion c = list.getSelectedValue();
127 | return c==null ? null : c.toString();
128 | }
129 |
130 |
131 | /**
132 | * Changes the selected index.
133 | *
134 | * @param amount The amount by which to change the selected index.
135 | */
136 | public void incSelection(int amount) {
137 | int selection = list.getSelectedIndex();
138 | selection += amount;
139 | if (selection<0) {
140 | // Account for nothing selected yet
141 | selection = model.getSize()-1;//+= model.getSize();
142 | }
143 | else {
144 | selection %= model.getSize();
145 | }
146 | list.setSelectedIndex(selection);
147 | list.ensureIndexIsVisible(selection);
148 | }
149 |
150 |
151 | /**
152 | * Initializes this window to offer suggestions for the parameters of
153 | * a specific completion.
154 | *
155 | * @param pc The completion whose parameters we should offer suggestions
156 | * for.
157 | */
158 | public void initialize(ParameterizedCompletion pc) {
159 |
160 | CompletionProvider provider = pc.getProvider();
161 | ParameterChoicesProvider pcp = provider.getParameterChoicesProvider();
162 | if (pcp==null) {
163 | choicesListList = null;
164 | return;
165 | }
166 |
167 | int paramCount = pc.getParamCount();
168 | choicesListList = new ArrayList<>(paramCount);
169 | JTextComponent tc = ac.getTextComponent();
170 |
171 | for (int i=0; i choices = pcp.getParameterChoices(tc, param);
174 | choicesListList.add(choices);
175 | }
176 |
177 | }
178 |
179 |
180 | /**
181 | * Sets the location of this window relative to the given rectangle.
182 | *
183 | * @param r The visual position of the caret (in screen coordinates).
184 | */
185 | public void setLocationRelativeTo(Rectangle r) {
186 |
187 | // Multi-monitor support - make sure the completion window (and
188 | // description window, if applicable) both fit in the same window in
189 | // a multi-monitor environment. To do this, we decide which monitor
190 | // the rectangle "r" is in, and use that one (just pick top-left corner
191 | // as the defining point).
192 | Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y);
193 | //Dimension screenSize = tooltip.getToolkit().getScreenSize();
194 |
195 | // Try putting our stuff "below" the caret first.
196 | int y = r.y + r.height + 5;
197 |
198 | // Get x-coordinate of completions. Try to align left edge with the
199 | // caret first.
200 | int x = r.x;
201 | if (xscreenBounds.x+screenBounds.width) { // completions don't fit
205 | x = screenBounds.x + screenBounds.width - getWidth();
206 | }
207 |
208 | setLocation(x, y);
209 |
210 | }
211 |
212 |
213 | /**
214 | * Displays the choices for the specified parameter matching the given
215 | * text. This will display or hide this popup window as necessary.
216 | *
217 | * @param param The index of the parameter the caret is currently in.
218 | * This may be -1
if not in a parameter (i.e., on
219 | * the comma between parameters).
220 | * @param prefix Text in the parameter before the dot. This may
221 | * be null
to represent the empty string.
222 | */
223 | public void setParameter(int param, String prefix) {
224 |
225 | model.clear();
226 | List temp = new ArrayList<>();
227 |
228 | if (choicesListList!=null && param>=0 && param choices = choicesListList.get(param);
231 | if (choices!=null) {
232 | for (Completion c : choices) {
233 | String choice = c.getReplacementText();
234 | if (prefix==null || Util.startsWithIgnoreCase(choice, prefix)) {
235 | temp.add(c);
236 | }
237 | }
238 | }
239 |
240 | // Sort completions appropriately.
241 | Comparator c = null;
242 | if (/*sortByRelevance*/true) {
243 | c = SORT_BY_RELEVANCE_COMPARATOR;
244 | }
245 | temp.sort(c);
246 | for (Completion completion : temp) {
247 | model.addElement(completion);
248 | }
249 |
250 | int visibleRowCount = Math.min(model.size(), 10);
251 | list.setVisibleRowCount(visibleRowCount);
252 |
253 | // Toggle visibility, if necessary.
254 | if (visibleRowCount==0 && isVisible()) {
255 | setVisible(false);
256 | }
257 | else if (visibleRowCount>0) {
258 | Dimension size = getPreferredSize();
259 | if (size.width<150) {
260 | setSize(150, size.height);
261 | }
262 | else {
263 | pack();
264 | }
265 | // Make sure nothing is ever obscured by vertical scroll bar.
266 | if (sp.getVerticalScrollBar()!=null &&
267 | sp.getVerticalScrollBar().isVisible()) {
268 | size = getSize();
269 | int w = size.width + sp.getVerticalScrollBar().getWidth()+5;
270 | setSize(w, size.height);
271 | }
272 | list.setSelectedIndex(0);
273 | list.ensureIndexIsVisible(0);
274 | if (!isVisible()) {
275 | setVisible(true);
276 | }
277 | }
278 |
279 | }
280 |
281 | else {
282 | setVisible(false);
283 | }
284 |
285 | }
286 |
287 |
288 | /**
289 | * Toggles the visibility of this popup window.
290 | *
291 | * @param visible Whether this window should be visible.
292 | */
293 | @Override
294 | public void setVisible(boolean visible) {
295 | if (visible!=isVisible()) {
296 | // i.e. if no possibilities matched what's been typed
297 | if (visible && model.size()==0) {//list.getVisibleRowCount()==0) {
298 | return;
299 | }
300 | super.setVisible(visible);
301 | }
302 | }
303 |
304 |
305 | /**
306 | * Updates the {@code LookAndFeel} of this window.
307 | */
308 | public void updateUI() {
309 | SwingUtilities.updateComponentTreeUI(this);
310 | }
311 |
312 |
313 | }
314 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * ParameterizedCompletionDescriptionToolTip.java - A "tool tip" displaying
5 | * information on the function or method currently being entered.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.awt.BorderLayout;
13 | import java.awt.EventQueue;
14 | import java.awt.Rectangle;
15 | import java.awt.Window;
16 | import javax.swing.BorderFactory;
17 | import javax.swing.JLabel;
18 | import javax.swing.JPanel;
19 | import javax.swing.JWindow;
20 | import javax.swing.SwingUtilities;
21 |
22 | import org.fife.ui.rsyntaxtextarea.HtmlUtil;
23 | import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
24 |
25 |
26 | /**
27 | * A "tool tip" that displays information on the function or method currently
28 | * being entered.
29 | *
30 | * @author Robert Futrell
31 | * @version 1.0
32 | */
33 | class ParameterizedCompletionDescriptionToolTip {
34 |
35 | /**
36 | * The backing AutoCompletion.
37 | */
38 | private AutoCompletion ac;
39 |
40 | /**
41 | * The actual tool tip.
42 | */
43 | private JWindow tooltip;
44 |
45 | /**
46 | * The label that holds the description.
47 | */
48 | private JLabel descLabel;
49 |
50 | /**
51 | * The completion being described.
52 | */
53 | private ParameterizedCompletion pc;
54 |
55 | private boolean overflow;
56 |
57 | /**
58 | * Constructor.
59 | *
60 | * @param owner The parent window.
61 | * @param ac The parent auto-completion.
62 | * @param pc The completion being described.
63 | */
64 | ParameterizedCompletionDescriptionToolTip(Window owner,
65 | ParameterizedCompletionContext context,
66 | AutoCompletion ac, ParameterizedCompletion pc) {
67 |
68 | tooltip = new JWindow(owner);
69 |
70 | this.ac = ac;
71 | this.pc = pc;
72 |
73 | descLabel = new JLabel();
74 | descLabel.setBorder(BorderFactory.createCompoundBorder(
75 | TipUtil.getToolTipBorder(),
76 | BorderFactory.createEmptyBorder(2, 5, 2, 5)));
77 | descLabel.setOpaque(true);
78 | descLabel.setBackground(TipUtil.getToolTipBackground());
79 | // It appears that if a JLabel is set as a content pane directly, when
80 | // using the JDK's opacity APIs, it won't paint its background, even
81 | // if label.setOpaque(true) is called. You have to have a container
82 | // underneath it for it to paint its background. Thus, we embed our
83 | // label in a parent JPanel to handle this case.
84 | //tooltip.setContentPane(descLabel);
85 | JPanel panel = new JPanel(new BorderLayout());
86 | panel.add(descLabel);
87 | tooltip.setContentPane(panel);
88 |
89 | // Give apps a chance to decorate us with drop shadows, etc.
90 | PopupWindowDecorator decorator = PopupWindowDecorator.get();
91 | if (decorator!=null) {
92 | decorator.decorate(tooltip);
93 | }
94 |
95 | updateText(0);
96 |
97 | tooltip.setFocusableWindowState(false);
98 |
99 | }
100 |
101 |
102 | /**
103 | * Returns whether this tool tip is visible.
104 | *
105 | * @return Whether this tool tip is visible.
106 | * @see #setVisible(boolean)
107 | */
108 | public boolean isVisible() {
109 | return tooltip.isVisible();
110 | }
111 |
112 |
113 | /**
114 | * Sets the location of this tool tip relative to the given rectangle.
115 | *
116 | * @param r The visual position of the caret (in screen coordinates).
117 | */
118 | public void setLocationRelativeTo(Rectangle r) {
119 |
120 | // Multi-monitor support - make sure the completion window (and
121 | // description window, if applicable) both fit in the same window in
122 | // a multi-monitor environment. To do this, we decide which monitor
123 | // the rectangle "r" is in, and use that one (just pick top-left corner
124 | // as the defining point).
125 | Rectangle screenBounds = Util.getScreenBoundsForPoint(r.x, r.y);
126 | //Dimension screenSize = tooltip.getToolkit().getScreenSize();
127 |
128 | // Try putting our stuff "above" the caret first.
129 | int y = r.y - 5 - tooltip.getHeight();
130 | if (y<0) {
131 | y = r.y + r.height + 5;
132 | }
133 |
134 | // Get x-coordinate of completions. Try to align left edge with the
135 | // caret first.
136 | int x = r.x;
137 | if (xscreenBounds.x+screenBounds.width) { // completions don't fit
141 | x = screenBounds.x + screenBounds.width - tooltip.getWidth();
142 | }
143 |
144 | tooltip.setLocation(x, y);
145 | EventQueue.invokeLater(tooltip::pack);
146 | }
147 |
148 |
149 | /**
150 | * Toggles the visibility of this tool tip.
151 | *
152 | * @param visible Whether this tool tip should be visible.
153 | * @see #isVisible()
154 | */
155 | public void setVisible(boolean visible) {
156 | tooltip.setVisible(visible);
157 | }
158 |
159 |
160 | /**
161 | * Updates the text in the tool tip to have the current parameter
162 | * displayed in bold.
163 | *
164 | * @param selectedParam The index of the selected parameter.
165 | * @return Whether the text needed to be updated.
166 | */
167 | public boolean updateText(int selectedParam) {
168 |
169 | StringBuilder sb = new StringBuilder("");
170 | int paramCount = pc.getParamCount();
171 |
172 | if (overflow) {
173 | if (selectedParam < paramCount) { // Not end-of-function parameter
174 | String temp = pc.getParam(Math.min(paramCount - 1, selectedParam)).toString();
175 | sb.append("...")
176 | .append(HtmlUtil.escapeForHtml(temp, " ", false))
177 | .append(" ...");
178 | // Hacky calls to hide tool tip if "trailing" parameter is focused, and we are displaying only
179 | // one argument at a time, then re-show it if they tab back into a parameter. Otherwise, we
180 | // end up showing an empty tool tip here
181 | if (!isVisible()) {
182 | setVisible(true);
183 | }
184 | }
185 | else {
186 | setVisible(false);
187 | }
188 | }
189 | else {
190 |
191 | for (int i=0; i");
195 | }
196 |
197 | // Some parameter types may have chars in them unfriendly to HTML
198 | // (such as type parameters in Java). We need to take care to
199 | // escape these.
200 | String temp = pc.getParam(i).toString();
201 | sb.append(HtmlUtil.escapeForHtml(temp, " ", false));
202 |
203 | if (i==selectedParam) {
204 | sb.append("");
205 | }
206 | if (i=0 && selectedParam");
219 | sb.append(desc);
220 | }
221 | }
222 |
223 | descLabel.setText(sb.toString());
224 | if (!overflow && sb.length() > ac.getParameterDescriptionTruncateThreshold()) {
225 | overflow = true;
226 | updateText(selectedParam);
227 | }
228 | else {
229 | overflow = false;
230 | tooltip.pack();
231 | }
232 |
233 | return true;
234 |
235 | }
236 |
237 |
238 | /**
239 | * Updates the {@code LookAndFeel} of this window and the description
240 | * window.
241 | */
242 | public void updateUI() {
243 | SwingUtilities.updateComponentTreeUI(tooltip);
244 | }
245 |
246 |
247 | }
248 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/ParameterizedCompletionInsertionInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 05/26/2012
3 | *
4 | * ParameterizedCompletionInsertionInfo.java - Used internally to track the
5 | * changes required for a specific parameterized completion.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.util.ArrayList;
13 | import java.util.List;
14 | import javax.swing.text.Position;
15 |
16 | import org.fife.ui.rsyntaxtextarea.DocumentRange;
17 |
18 |
19 | /**
20 | * Describes a parameterized completion - what's being inserted, where the
21 | * parameters are in the inserted text, etc.
22 | *
23 | * @author Robert Futrell
24 | * @version 1.0
25 | */
26 | public class ParameterizedCompletionInsertionInfo {
27 |
28 | private int minOffs;
29 | private Position maxOffs;
30 | private int defaultEnd;
31 | private int selStart;
32 | private int selEnd;
33 | private String textToInsert;
34 | private List replacementLocations;
35 | private List replacementCopies;
36 |
37 |
38 | /**
39 | * Constructor.
40 | */
41 | public ParameterizedCompletionInsertionInfo() {
42 | defaultEnd = -1;
43 | }
44 |
45 |
46 | /**
47 | * Adds a copy of a replacement.
48 | *
49 | * @param id The ID of the replacement copy, e.g. the text itself.
50 | * @param start The start offset.
51 | * @param end The end offset.
52 | */
53 | public void addReplacementCopy(String id, int start, int end) {
54 | if (replacementCopies==null) {
55 | replacementCopies = new ArrayList<>(1);
56 | }
57 | replacementCopies.add(new ReplacementCopy(id, start, end));
58 | }
59 |
60 |
61 | /**
62 | * Marks a region of the replacement text as representing a variable name
63 | * or some other construct that the user should replace.
64 | *
65 | * @param start The start offset.
66 | * @param end The end offset.
67 | * @see #getReplacementCount()
68 | * @see #getReplacementLocation(int)
69 | */
70 | public void addReplacementLocation(int start, int end) {
71 | if (replacementLocations==null) {
72 | replacementLocations = new ArrayList<>(1);
73 | }
74 | replacementLocations.add(new DocumentRange(start, end));
75 | }
76 |
77 |
78 | /**
79 | * Returns the default end offset.
80 | *
81 | * @return The default end offset.
82 | * @see #setDefaultEndOffs(int)
83 | */
84 | public int getDefaultEndOffs() {
85 | return defaultEnd>-1 ? defaultEnd : getMaxOffset().getOffset();
86 | }
87 |
88 |
89 | /**
90 | * Returns the maximum offset the caret can move to before being outside
91 | * the text inserted for this completion.
92 | *
93 | * @return The maximum offset.
94 | * @see #getMinOffset()
95 | */
96 | public Position getMaxOffset() {
97 | return maxOffs;
98 | }
99 |
100 |
101 | /**
102 | * Returns the minimum offset the caret can move to before being outside
103 | * the text inserted for this completion.
104 | *
105 | * @return The minimum offset.
106 | * @see #getMaxOffset()
107 | */
108 | public int getMinOffset() {
109 | return minOffs;
110 | }
111 |
112 |
113 | /**
114 | * Returns the number of replacements.
115 | *
116 | * @return The number of replacements.
117 | */
118 | public int getReplacementCopyCount() {
119 | return replacementCopies==null ? 0 : replacementCopies.size();
120 | }
121 |
122 |
123 | /**
124 | * Returns the number of replacements in the completion.
125 | *
126 | * @return The number of replacements in the completion.
127 | */
128 | public int getReplacementCount() {
129 | return replacementLocations==null ? 0 : replacementLocations.size();
130 | }
131 |
132 |
133 | /**
134 | * Returns the specified replacement copy.
135 | *
136 | * @param index The index of the replacement to retrieve.
137 | * @return The replacement.
138 | * @see #getReplacementCopyCount()
139 | * @see #addReplacementCopy(String, int, int)
140 | */
141 | public ReplacementCopy getReplacementCopy(int index) {
142 | return replacementCopies.get(index);
143 | }
144 |
145 |
146 | /**
147 | * Returns the starting- and ending-offsets of the replacement regions
148 | * in the completion.
149 | *
150 | * @param index The replacement region.
151 | * @return The range in the document of that replacement region.
152 | * @see #getReplacementCount()
153 | */
154 | public DocumentRange getReplacementLocation(int index) {
155 | return replacementLocations.get(index);
156 | }
157 |
158 |
159 | /**
160 | * Returns the offset that should be the end of the initially selected
161 | * text when the completion is inserted (i.e., the end offset of the first
162 | * replacement region).
163 | *
164 | * @return The end offset for the initial selection.
165 | * @see #getSelectionStart()
166 | */
167 | public int getSelectionEnd() {
168 | return selEnd;
169 | }
170 |
171 |
172 | /**
173 | * Returns the offset that should be the start of the initially selected
174 | * text when the completion is inserted (i.e., the start offset of the
175 | * first replacement region).
176 | *
177 | * @return The start offset for the initial selection.
178 | * @see #getSelectionEnd()
179 | */
180 | public int getSelectionStart() {
181 | return selStart;
182 | }
183 |
184 |
185 | /**
186 | * Returns the actual text to insert when the completion is selected.
187 | *
188 | * @return The text to insert.
189 | * @see #setTextToInsert(String)
190 | */
191 | public String getTextToInsert() {
192 | return textToInsert;
193 | }
194 |
195 |
196 | /**
197 | * Returns whether there is an initial selected region for the
198 | * completion (i.e., whether the completion actually has any parameters).
199 | *
200 | * @return Whether there is a region to initially select for the completion.
201 | */
202 | public boolean hasSelection() {
203 | return selEnd!=selStart;
204 | }
205 |
206 |
207 | /**
208 | * Sets the initially selected region for the completion.
209 | *
210 | * @param selStart The selection start.
211 | * @param selEnd The selection end.
212 | * @see #getSelectionEnd()
213 | * @see #getSelectionStart()
214 | */
215 | public void setInitialSelection(int selStart, int selEnd) {
216 | this.selStart = selStart;
217 | this.selEnd = selEnd;
218 | }
219 |
220 |
221 | /**
222 | * Sets the document range the caret can move around in before being
223 | * outside the text inserted for the completion.
224 | *
225 | * @param minOffs The minimum offset.
226 | * @param maxOffs The maximum offset, that will track its location as the
227 | * document is modified.
228 | * @see #getMinOffset()
229 | * @see #getMaxOffset()
230 | */
231 | public void setCaretRange(int minOffs, Position maxOffs) {
232 | this.minOffs = minOffs;
233 | this.maxOffs = maxOffs;
234 | }
235 |
236 |
237 | /**
238 | * Sets the default end offset.
239 | *
240 | * @param end The new default end offset.
241 | * @see #getDefaultEndOffs()
242 | */
243 | public void setDefaultEndOffs(int end) {
244 | defaultEnd = end;
245 | }
246 |
247 |
248 | /**
249 | * Sets the text to insert for the completion.
250 | *
251 | * @param text The text to insert.
252 | * @see #getTextToInsert()
253 | */
254 | public void setTextToInsert(String text) {
255 | this.textToInsert = text;
256 | }
257 |
258 |
259 | /**
260 | * Information about a replacement.
261 | */
262 | public static class ReplacementCopy {
263 |
264 | private String id;
265 | private int start;
266 | private int end;
267 |
268 | ReplacementCopy(String id, int start, int end) {
269 | this.id = id;
270 | this.start = start;
271 | this.end = end;
272 | }
273 |
274 | /**
275 | * Returns the end of the replacement.
276 | *
277 | * @return The end of the replacement.
278 | */
279 | public int getEnd() {
280 | return end;
281 | }
282 |
283 | /**
284 | * Returns the ID of the replacement.
285 | *
286 | * @return The ID of the replacement.
287 | */
288 | public String getId() {
289 | return id;
290 | }
291 |
292 | /**
293 | * Returns the start of the replacement.
294 | *
295 | * @return The start of the replacement.
296 | */
297 | public int getStart() {
298 | return start;
299 | }
300 |
301 | }
302 |
303 |
304 | }
305 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/RoundRobinAutoCompletion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/02/2013
3 | *
4 | * This library is distributed under a modified BSD license. See the included
5 | * AutoComplete.License.txt file for details.
6 | */
7 | package org.fife.ui.autocomplete;
8 |
9 | import java.awt.event.ActionEvent;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 |
13 | import javax.swing.Action;
14 |
15 |
16 | /**
17 | * An AutoCompletion
that adds the ability to cycle through a set
18 | * of CompletionProvider
s via the trigger key. This allows the
19 | * application to logically "group together" completions of similar kinds;
20 | * for example, Java code completions vs. template completions.
21 | *
22 | * Usage:
23 | *
24 | * XPathDynamicCompletionProvider dynamicProvider = new XPathDynamicCompletionProvider();
25 | * RoundRobinAutoCompletion ac = new RoundRobinAutoCompletion(dynamicProvider);
26 | * XPathCompletionProvider staticProvider = new XPathCompletionProvider();
27 | * ac.addCompletionProvider(staticProvider);
28 | * ac.setXXX(..);
29 | * ...
30 | * ac.install(textArea);
31 | *
32 | *
33 | * @author mschlegel
34 | */
35 | public class RoundRobinAutoCompletion extends AutoCompletion {
36 |
37 | /** The List of CompletionProviders to use. */
38 | private List cycle = new ArrayList<>();
39 |
40 |
41 | /**
42 | * Constructor.
43 | *
44 | * @param provider A single completion provider.
45 | * @see #addCompletionProvider(CompletionProvider)
46 | */
47 | public RoundRobinAutoCompletion(CompletionProvider provider) {
48 |
49 | super(provider);
50 | cycle.add(provider);
51 |
52 | // principal requirement for round-robin
53 | setHideOnCompletionProviderChange(false);
54 | // this is required since otherwise, on empty list of completions for
55 | // one of the CompletionProviders, round-robin completion would not
56 | // work
57 | setHideOnNoText(false);
58 | // this is required to prevent single choice of 1st provider to choose
59 | // the completion since the user may want the second provider to be
60 | // chosen.
61 | setAutoCompleteSingleChoices(false);
62 |
63 | }
64 |
65 |
66 | /**
67 | * Adds an additional CompletionProvider
to the list to
68 | * cycle through.
69 | *
70 | * @param provider The new completion provider.
71 | */
72 | public void addCompletionProvider(CompletionProvider provider) {
73 | cycle.add(provider);
74 | }
75 |
76 |
77 | /**
78 | * Moves to the next Provider internally. Needs refresh of the popup window
79 | * to display the changes.
80 | *
81 | * @return true if the next provider was the default one (thus returned to
82 | * the default view). May be used in case you like to hide the
83 | * popup in this case.
84 | */
85 | public boolean advanceProvider() {
86 | CompletionProvider currentProvider = getCompletionProvider();
87 | int i = (cycle.indexOf(currentProvider)+1) % cycle.size();
88 | setCompletionProvider(cycle.get(i));
89 | return i==0;
90 | }
91 |
92 |
93 | /**
94 | * Overridden to provide our own implementation of the action.
95 | */
96 | @Override
97 | protected Action createAutoCompleteAction() {
98 | return new CycleAutoCompleteAction();
99 | }
100 |
101 |
102 | /**
103 | * Resets the cycle to use the default provider on next refresh.
104 | */
105 | public void resetProvider() {
106 | CompletionProvider currentProvider = getCompletionProvider();
107 | CompletionProvider defaultProvider = cycle.get(0);
108 | if (currentProvider != defaultProvider) {
109 | setCompletionProvider(defaultProvider);
110 | }
111 | }
112 |
113 |
114 | /**
115 | * An implementation of the auto-complete action that ensures the proper
116 | * CompletionProvider
is displayed based on the context in
117 | * which the user presses the trigger key.
118 | */
119 | private final class CycleAutoCompleteAction extends AutoCompleteAction {
120 |
121 | @Override
122 | public void actionPerformed(ActionEvent e) {
123 | if (isAutoCompleteEnabled()) {
124 | if (isPopupVisible()) {
125 | // The popup is already visible, and user pressed the
126 | // trigger-key. In this case, move to next provider.
127 | advanceProvider();
128 | }
129 | else {
130 | // Be sure to start with the default provider
131 | resetProvider();
132 | }
133 | // Check if there are completions from the current provider. If not, advance to the next provider and
134 | // display that one.
135 | // A completion provider can force displaying "his" empty completion pop-up by returning an empty
136 | // BasicCompletion. This is useful when the user is typing backspace, and you like to display the first
137 | // provider always first.
138 | for (int i=1; i completions = getCompletionProvider().getCompletions(getTextComponent());
140 | if (!completions.isEmpty()) {
141 | //nothing to do, just let the current provider display
142 | break;
143 | }
144 | else {
145 | //search for non-empty completions
146 | advanceProvider();
147 | }
148 | }
149 | }
150 | super.actionPerformed(e);
151 | }
152 |
153 | }
154 |
155 |
156 | // TODO add label "Ctrl-Space for " to the popup window
157 | }
158 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/ShorthandCompletion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/22/2008
3 | *
4 | * ShorthandCompletion.java - A completion that is shorthand for some other
5 | * text.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 |
13 | /**
14 | * A completion where the input text is shorthand for (really, just different
15 | * from) the actual text to be inserted. For example, the input text
16 | * "sysout
" could be associated with the completion
17 | * "System.out.println(
" in Java.
18 | *
19 | * @author Robert Futrell
20 | * @version 1.0
21 | */
22 | public class ShorthandCompletion extends BasicCompletion {
23 |
24 | /**
25 | * The text the user can start typing that will match this completion.
26 | */
27 | private String inputText;
28 |
29 |
30 | /**
31 | * Constructor.
32 | *
33 | * @param provider The provider that returns this completion.
34 | * @param inputText The text the user inputs to get this completion.
35 | * @param replacementText The replacement text of the completion.
36 | */
37 | public ShorthandCompletion(CompletionProvider provider, String inputText,
38 | String replacementText) {
39 | super(provider, replacementText);
40 | this.inputText = inputText;
41 | }
42 |
43 |
44 | /**
45 | * Constructor.
46 | *
47 | * @param provider The provider that returns this completion.
48 | * @param inputText The text the user inputs to get this completion.
49 | * @param replacementText The replacement text of the completion.
50 | * @param shortDesc A short description of the completion. This will be
51 | * displayed in the completion list. This may be null
.
52 | */
53 | public ShorthandCompletion(CompletionProvider provider, String inputText,
54 | String replacementText, String shortDesc) {
55 | super(provider, replacementText, shortDesc);
56 | this.inputText = inputText;
57 | }
58 |
59 |
60 | /**
61 | * Constructor.
62 | *
63 | * @param provider The provider that returns this completion.
64 | * @param inputText The text the user inputs to get this completion.
65 | * @param replacementText The replacement text of the completion.
66 | * @param shortDesc A short description of the completion. This will be
67 | * displayed in the completion list. This may be null
.
68 | * @param summary The summary of this completion. This should be HTML.
69 | * This may be null
.
70 | */
71 | public ShorthandCompletion(CompletionProvider provider, String inputText,
72 | String replacementText, String shortDesc, String summary) {
73 | super(provider, replacementText, shortDesc, summary);
74 | this.inputText = inputText;
75 | }
76 |
77 |
78 | /**
79 | * Returns the text the user must start typing to get this completion.
80 | *
81 | * @return The text the user must start to input.
82 | */
83 | @Override
84 | public String getInputText() {
85 | return inputText;
86 | }
87 |
88 |
89 | /**
90 | * If a summary has been set, that summary is returned. Otherwise, the
91 | * replacement text is returned.
92 | *
93 | * @return A description of this completion (the text that will be
94 | * inserted).
95 | * @see #getReplacementText()
96 | */
97 | @Override
98 | public String getSummary() {
99 | String summary = super.getSummary();
100 | return summary!=null ? summary : ("" + getSummaryBody());
101 | }
102 |
103 |
104 | /**
105 | * Returns the "body" of the HTML returned by {@link #getSummary()} when
106 | * no summary text has been set. This is defined to return the replacement
107 | * text in a monospaced font.
108 | *
109 | * @return The summary text's body, if no other summary has been defined.
110 | * @see #getReplacementText()
111 | */
112 | protected String getSummaryBody() {
113 | return "" + getReplacementText();
114 | }
115 |
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/SizeGrip.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/23/2008
3 | *
4 | * SizeGrip.java - A size grip component that sits at the bottom of the window,
5 | * allowing the user to easily resize that window.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.awt.Color;
13 | import java.awt.ComponentOrientation;
14 | import java.awt.Cursor;
15 | import java.awt.Dimension;
16 | import java.awt.Graphics;
17 | import java.awt.Image;
18 | import java.awt.Point;
19 | import java.awt.Window;
20 | import java.awt.event.MouseEvent;
21 | import java.io.File;
22 | import java.io.IOException;
23 | import java.net.MalformedURLException;
24 | import java.net.URL;
25 | import javax.imageio.ImageIO;
26 | import javax.swing.JPanel;
27 | import javax.swing.SwingUtilities;
28 | import javax.swing.UIManager;
29 | import javax.swing.event.MouseInputAdapter;
30 |
31 |
32 | /**
33 | * A component that allows its parent window to be resizable, similar to the
34 | * size grip seen on status bars. This is essentially a copy of the class with
35 | * the same name in RSyntaxTextArea, but is duplicated to prevent a dependency
36 | * on that library.
37 | *
38 | * @author Robert Futrell
39 | * @version 1.0
40 | */
41 | class SizeGrip extends JPanel {
42 |
43 | /**
44 | * The size grip to use if we're on OS X.
45 | */
46 | private Image osxSizeGrip;
47 |
48 |
49 | SizeGrip() {
50 | MouseHandler adapter = new MouseHandler();
51 | addMouseListener(adapter);
52 | addMouseMotionListener(adapter);
53 | setPreferredSize(new Dimension(16, 16));
54 | }
55 |
56 |
57 | /**
58 | * Overridden to ensure that the cursor for this component is appropriate
59 | * for the orientation.
60 | *
61 | * @param o The new orientation.
62 | */
63 | @Override
64 | public void applyComponentOrientation(ComponentOrientation o) {
65 | possiblyFixCursor(o.isLeftToRight());
66 | super.applyComponentOrientation(o);
67 | }
68 |
69 |
70 | /**
71 | * Creates and returns the OS X size grip image.
72 | *
73 | * @return The OS X size grip.
74 | */
75 | private Image createOSXSizeGrip() {
76 | ClassLoader cl = getClass().getClassLoader();
77 | URL url = cl.getResource("org/fife/ui/autocomplete/osx_sizegrip.png");
78 | if (url==null) {
79 | // We're not running in a jar - we may be debugging in Eclipse,
80 | // for example
81 | File f = new File("../AutoComplete/src/org/fife/ui/autocomplete/osx_sizegrip.png");
82 | if (f.isFile()) {
83 | try {
84 | url = f.toURI().toURL();
85 | } catch (MalformedURLException mue) { // Never happens
86 | mue.printStackTrace();
87 | return null;
88 | }
89 | }
90 | else {
91 | return null; // Can't find resource or image file
92 | }
93 | }
94 | Image image = null;
95 | try {
96 | image = ImageIO.read(url);
97 | } catch (IOException ioe) { // Never happens
98 | ioe.printStackTrace();
99 | }
100 | return image;
101 | }
102 |
103 |
104 | /**
105 | * Paints this panel.
106 | *
107 | * @param g The graphics context.
108 | */
109 | @Override
110 | protected void paintComponent(Graphics g) {
111 |
112 | super.paintComponent(g);
113 |
114 | Dimension dim = getSize();
115 |
116 | if (osxSizeGrip!=null) {
117 | g.drawImage(osxSizeGrip, dim.width-16, dim.height-16, null);
118 | return;
119 | }
120 |
121 | Color c1 = UIManager.getColor("Label.disabledShadow");
122 | Color c2 = UIManager.getColor("Label.disabledForeground");
123 | ComponentOrientation orientation = getComponentOrientation();
124 |
125 | if (orientation.isLeftToRight()) {
126 | int width = dim.width -= 3;
127 | int height = dim.height -= 3;
128 | g.setColor(c1);
129 | g.fillRect(width-9,height-1, 3,3);
130 | g.fillRect(width-5,height-1, 3,3);
131 | g.fillRect(width-1,height-1, 3,3);
132 | g.fillRect(width-5,height-5, 3,3);
133 | g.fillRect(width-1,height-5, 3,3);
134 | g.fillRect(width-1,height-9, 3,3);
135 | g.setColor(c2);
136 | g.fillRect(width-9,height-1, 2,2);
137 | g.fillRect(width-5,height-1, 2,2);
138 | g.fillRect(width-1,height-1, 2,2);
139 | g.fillRect(width-5,height-5, 2,2);
140 | g.fillRect(width-1,height-5, 2,2);
141 | g.fillRect(width-1,height-9, 2,2);
142 | }
143 | else {
144 | int height = dim.height -= 3;
145 | g.setColor(c1);
146 | g.fillRect(10,height-1, 3,3);
147 | g.fillRect(6,height-1, 3,3);
148 | g.fillRect(2,height-1, 3,3);
149 | g.fillRect(6,height-5, 3,3);
150 | g.fillRect(2,height-5, 3,3);
151 | g.fillRect(2,height-9, 3,3);
152 | g.setColor(c2);
153 | g.fillRect(10,height-1, 2,2);
154 | g.fillRect(6,height-1, 2,2);
155 | g.fillRect(2,height-1, 2,2);
156 | g.fillRect(6,height-5, 2,2);
157 | g.fillRect(2,height-5, 2,2);
158 | g.fillRect(2,height-9, 2,2);
159 | }
160 |
161 | }
162 |
163 |
164 | /**
165 | * Ensures that the cursor for this component is appropriate for the
166 | * orientation.
167 | *
168 | * @param ltr Whether the current component orientation is LTR.
169 | */
170 | protected void possiblyFixCursor(boolean ltr) {
171 | int cursor = Cursor.NE_RESIZE_CURSOR;
172 | if (ltr) {
173 | cursor = Cursor.NW_RESIZE_CURSOR;
174 | }
175 | if (cursor!=getCursor().getType()) {
176 | setCursor(Cursor.getPredefinedCursor(cursor));
177 | }
178 | }
179 |
180 |
181 | @Override
182 | public void updateUI() {
183 | super.updateUI();
184 | // TODO: Key off of Aqua LaF, not just OS X, as this size grip looks
185 | // bad on other LaFs on Mac such as Nimbus.
186 | if (System.getProperty("os.name").contains("OS X")) {
187 | if (osxSizeGrip==null) {
188 | osxSizeGrip = createOSXSizeGrip();
189 | }
190 | }
191 | else { // Clear memory in case of runtime LaF change.
192 | osxSizeGrip = null;
193 | }
194 |
195 | }
196 |
197 |
198 | /*
199 | * NOTE: We use SwingUtilities.convertPointToScreen() instead of just using
200 | * the locations relative to the corner component because the latter proved
201 | * buggy - stretch the window too wide and some kind of arithmetic error
202 | * started happening somewhere - our window would grow way too large.
203 | */
204 | /**
205 | * Listens for mouse events on this panel and resizes the parent window
206 | * appropriately.
207 | */
208 | private final class MouseHandler extends MouseInputAdapter {
209 |
210 | private Point origPos;
211 |
212 | @Override
213 | public void mouseDragged(MouseEvent e) {
214 | Point newPos = e.getPoint();
215 | SwingUtilities.convertPointToScreen(newPos, SizeGrip.this);
216 | int xDelta = newPos.x - origPos.x;
217 | int yDelta = newPos.y - origPos.y;
218 | Window wind = SwingUtilities.getWindowAncestor(SizeGrip.this);
219 | if (wind!=null) { // Should always be true
220 | if (getComponentOrientation().isLeftToRight()) {
221 | int w = wind.getWidth();
222 | if (newPos.x>=wind.getX()) {
223 | w += xDelta;
224 | }
225 | int h = wind.getHeight();
226 | if (newPos.y>=wind.getY()) {
227 | h += yDelta;
228 | }
229 | wind.setSize(w,h);
230 | }
231 | else { // RTL
232 | int newW = Math.max(1, wind.getWidth()-xDelta);
233 | int newH = Math.max(1, wind.getHeight()+yDelta);
234 | wind.setBounds(newPos.x, wind.getY(), newW, newH);
235 | }
236 | // invalidate()/validate() needed pre-1.6.
237 | wind.invalidate();
238 | wind.validate();
239 | }
240 | origPos.setLocation(newPos);
241 | }
242 |
243 | @Override
244 | public void mousePressed(MouseEvent e) {
245 | origPos = e.getPoint();
246 | SwingUtilities.convertPointToScreen(origPos, SizeGrip.this);
247 | }
248 |
249 | @Override
250 | public void mouseReleased(MouseEvent e) {
251 | origPos = null;
252 | }
253 |
254 | }
255 |
256 |
257 | }
258 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/SortByRelevanceComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/17/2010
3 | *
4 | * SortByRelevanceComparator.java - Sorts two Completions by relevance before
5 | * sorting them lexicographically.
6 | *
7 | * This library is distributed under a modified BSD license. See the included
8 | * LICENSE.md file for details.
9 | */
10 | package org.fife.ui.autocomplete;
11 |
12 | import java.io.Serializable;
13 | import java.util.Comparator;
14 |
15 |
16 | /**
17 | * Compares two Completion
s by their relevance before
18 | * sorting them lexicographically.
19 | *
20 | * @author Robert Futrell
21 | * @version 1.0
22 | */
23 | public class SortByRelevanceComparator implements Comparator, Serializable {
24 |
25 |
26 | @Override
27 | public int compare(Completion c1, Completion c2) {
28 | int rel1 = c1.getRelevance();
29 | int rel2 = c2.getRelevance();
30 | int diff = rel2 - rel1;//rel1 - rel2;
31 | return diff==0 ? c1.compareTo(c2) : diff;
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/SuppressFBWarnings.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This library is distributed under a modified BSD license. See the included
3 | * LICENSE.md file for details.
4 | */
5 | package org.fife.ui.autocomplete;
6 |
7 | import java.lang.annotation.Retention;
8 |
9 | import static java.lang.annotation.RetentionPolicy.CLASS;
10 |
11 | /**
12 | * Used to suppress FindBugs warnings. It should be used instead of SuppressWarnings to
13 | * avoid conflicts with SuppressWarnings.
14 | */
15 | @Retention(value = CLASS)
16 | public @interface SuppressFBWarnings {
17 |
18 | /**
19 | * The set of FindBugs warnings that are to be suppressed in annotated element.
20 | * The value can be a bug category, kind or pattern.
21 | *
22 | * @return The FindBugs warnings to ignore.
23 | */
24 | String[] value() default {};
25 |
26 | /**
27 | * Optional documentation of the reason why the warning is suppressed.
28 | *
29 | * @return The reason the FindBugs warnings were ignored.
30 | */
31 | String justification() default "";
32 | }
33 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/TemplatePiece.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 06/17/2012
3 | *
4 | * TemplatePiece.java - A logical piece of a template completion.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 |
12 | /**
13 | * A piece of a TemplateCompletion
. You add instances of this
14 | * class to template completions to define them.
15 | *
16 | * @author Robert Futrell
17 | * @version 1.0
18 | * @see TemplateCompletion
19 | */
20 | interface TemplatePiece {
21 |
22 |
23 | String getText();
24 |
25 |
26 | /**
27 | * A plain text template piece.
28 | */
29 | class Text implements TemplatePiece {
30 |
31 | private String text;
32 |
33 | Text(String text) {
34 | this.text = text;
35 | }
36 |
37 | @Override
38 | public String getText() {
39 | return text;
40 | }
41 |
42 | @Override
43 | public String toString() {
44 | return "[TemplatePiece.Text: text=" + text + "]";
45 | }
46 |
47 | }
48 |
49 |
50 | /**
51 | * A parameter template piece.
52 | */
53 | class Param implements TemplatePiece {
54 |
55 | String text;
56 |
57 | Param(String text) {
58 | this.text = text;
59 | }
60 |
61 | @Override
62 | public String getText() {
63 | return text;
64 | }
65 |
66 | @Override
67 | public String toString() {
68 | return "[TemplatePiece.Param: param=" + text + "]";
69 | }
70 |
71 | }
72 |
73 |
74 | /**
75 | * A copy of a parameter template piece.
76 | */
77 | class ParamCopy implements TemplatePiece {
78 |
79 | private String text;
80 |
81 | ParamCopy(String text) {
82 | this.text = text;
83 | }
84 |
85 | @Override
86 | public String getText() {
87 | return text;
88 | }
89 |
90 | @Override
91 | public String toString() {
92 | return "[TemplatePiece.ParamCopy: param=" + text + "]";
93 | }
94 |
95 | }
96 |
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/TipUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 08/13/2009
3 | *
4 | * TipUtil.java - Utility methods for homemade tool tips.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import org.fife.ui.rsyntaxtextarea.HtmlUtil;
12 |
13 | import java.awt.Color;
14 | import java.awt.Font;
15 | import java.awt.SystemColor;
16 | import java.net.URL;
17 | import javax.swing.*;
18 | import javax.swing.border.Border;
19 | import javax.swing.plaf.ColorUIResource;
20 | import javax.swing.text.html.HTMLDocument;
21 |
22 |
23 | /**
24 | * Static utility methods for homemade tool tips.
25 | *
26 | * This is blatantly ripped off from RSyntaxTextArea's "FocusableTips" class
27 | * of the same name, but isn't re-used to prevent a hard dependency on the
28 | * RSTA library.
29 | *
30 | * @author Robert Futrell
31 | * @version 1.0
32 | */
33 | final class TipUtil {
34 |
35 |
36 | private TipUtil() {
37 | }
38 |
39 |
40 | /**
41 | * Returns the default background color to use for tool tip windows.
42 | *
43 | * @return The default background color.
44 | */
45 | public static Color getToolTipBackground() {
46 |
47 | Color c = UIManager.getColor("ToolTip.background");
48 |
49 | // Tooltip.background is wrong color on Nimbus (!)
50 | boolean isNimbus = isNimbusLookAndFeel();
51 | if (c==null || isNimbus) {
52 | c = UIManager.getColor("info"); // Used by Nimbus (and others)
53 | if (c==null || (isNimbus && isDerivedColor(c))) {
54 | c = SystemColor.info; // System default
55 | }
56 | }
57 |
58 | // Workaround for a bug (?) with Nimbus - calling JLabel.setBackground()
59 | // with a ColorUIResource does nothing, must be a normal Color
60 | if (c instanceof ColorUIResource) {
61 | c = new Color(c.getRGB());
62 | }
63 |
64 | return c;
65 |
66 | }
67 |
68 |
69 | /**
70 | * Returns the border used by tool tips in this look and feel.
71 | *
72 | * @return The border.
73 | */
74 | public static Border getToolTipBorder() {
75 |
76 | Border border = UIManager.getBorder("ToolTip.border");
77 |
78 | if (border==null || isNimbusLookAndFeel()) {
79 | border = UIManager.getBorder("nimbusBorder");
80 | if (border==null) {
81 | border = BorderFactory.createLineBorder(SystemColor.controlDkShadow);
82 | }
83 | }
84 |
85 | return border;
86 |
87 | }
88 |
89 |
90 | /**
91 | * Returns the color to use for hyperlink-style components in tool tips.
92 | * This method will return Color.blue
unless it appears
93 | * that the current LookAndFeel uses light text on a dark background,
94 | * in which case a brighter alternative is returned.
95 | *
96 | * @return The color to use for hyperlinks in tool tips.
97 | * @see Util#getHyperlinkForeground()
98 | */
99 | static Color getToolTipHyperlinkForeground() {
100 |
101 | // This property is defined by all standard LaFs, even Nimbus (!),
102 | // but you never know what crazy LaFs there are...
103 | Color fg = UIManager.getColor("ToolTip.foreground");
104 | if (fg == null || TipUtil.isNimbusLookAndFeel()) {
105 | fg = new JToolTip().getForeground();
106 | }
107 |
108 | return Util.isLightForeground(fg) ? Util.LIGHT_HYPERLINK_FG : Color.blue;
109 |
110 | }
111 |
112 |
113 | /**
114 | * Returns whether a color is a Nimbus DerivedColor, which is troublesome
115 | * in that it doesn't use its RGB values (uses HSB instead?) and so
116 | * querying them is useless.
117 | *
118 | * @param c The color to check.
119 | * @return Whether it is a DerivedColor
120 | */
121 | private static boolean isDerivedColor(Color c) {
122 | return c!=null && (c.getClass().getName().endsWith(".DerivedColor") ||
123 | c.getClass().getName().endsWith(".DerivedColor$UIResource"));
124 | }
125 |
126 |
127 | /**
128 | * Returns whether the Nimbus Look and Feel is installed.
129 | *
130 | * @return Whether the current LAF is Nimbus.
131 | */
132 | private static boolean isNimbusLookAndFeel() {
133 | return UIManager.getLookAndFeel().getName().equals("Nimbus");
134 | }
135 |
136 |
137 | /**
138 | * Tweaks a JEditorPane
so it can be used to render the
139 | * content in a focusable pseudo-tool tip. It is assumed that the editor
140 | * pane is using an HTMLDocument
.
141 | *
142 | * @param textArea The editor pane to tweak.
143 | */
144 | public static void tweakTipEditorPane(JEditorPane textArea) {
145 |
146 | // Jump through a few hoops to get things looking nice in Nimbus
147 | boolean isNimbus = isNimbusLookAndFeel();
148 | if (isNimbus) {
149 | Color selBG = textArea.getSelectionColor();
150 | Color selFG = textArea.getSelectedTextColor();
151 | textArea.setUI(new javax.swing.plaf.basic.BasicEditorPaneUI());
152 | textArea.setSelectedTextColor(selFG);
153 | textArea.setSelectionColor(selBG);
154 | }
155 |
156 | textArea.setEditable(false); // Required for links to work!
157 | textArea.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
158 |
159 | // Make selection visible even though we are not (initially) focusable.
160 | textArea.getCaret().setSelectionVisible(true);
161 |
162 | // Set the foreground color. Important because when rendering HTML,
163 | // default foreground becomes black, which may not match all Look and
164 | // Feels (e.g. Substance).
165 | Color fg = UIManager.getColor("ToolTip.foreground");
166 | if (fg == null) {
167 | fg = UIManager.getColor("Label.foreground");
168 | }
169 | if (fg==null || (isNimbus && isDerivedColor(fg))) {
170 | fg = SystemColor.textText;
171 | }
172 | textArea.setForeground(fg);
173 |
174 | // Make it use the "tool tip" background color.
175 | textArea.setBackground(TipUtil.getToolTipBackground());
176 |
177 | // Force JEditorPane to use a certain font even in HTML.
178 | // All standard LookAndFeels, even Nimbus (!), define Label.font.
179 | Font font = UIManager.getFont("Label.font");
180 | if (font == null) { // Try to make a sensible default
181 | font = new Font("SansSerif", Font.PLAIN, 12);
182 | }
183 | HTMLDocument doc = (HTMLDocument) textArea.getDocument();
184 | doc.getStyleSheet().addRule(
185 | "body { font-family: " + font.getFamily() +
186 | "; font-size: " + font.getSize() + "pt" +
187 | "; color: " + HtmlUtil.getHexString(fg) + "; }");
188 |
189 | // Always add link foreground rule. Unfortunately these CSS rules
190 | // stack each time the LaF is changed (how can we overwrite them
191 | // without clearing out the important "standard" ones?).
192 | Color linkFG = TipUtil.getToolTipHyperlinkForeground();
193 | doc.getStyleSheet().addRule(
194 | "a { color: " + HtmlUtil.getHexString(linkFG) + "; }");
195 |
196 | URL url = TipUtil.class.getResource("bullet_black.png");
197 | if (url!=null) {
198 | doc.getStyleSheet().addRule(
199 | "ul { list-style-image: '" + url + "'; }");
200 | }
201 |
202 | }
203 |
204 |
205 | }
206 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * Util.java - Utility methods for the autocompletion package.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import java.awt.*;
12 | import java.net.URI;
13 | import java.security.AccessControlException;
14 | import java.util.regex.Pattern;
15 |
16 | import javax.swing.*;
17 |
18 | import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
19 |
20 |
21 | /**
22 | * Utility methods for the auto-complete framework.
23 | *
24 | * @author Robert Futrell
25 | * @version 1.0
26 | */
27 | public final class Util {
28 |
29 | /**
30 | * If a system property is defined with this name and set, ignoring case,
31 | * to true
, this library will not attempt to use Substance
32 | * renderers. Otherwise, if a Substance Look and Feel is installed, we
33 | * will attempt to use Substance cell renderers in all of our dropdowns.
34 | *
35 | * Note that we do not have a build dependency on Substance, so all access
36 | * to Substance stuff is done via reflection. We will fall back onto
37 | * default renderers if something goes horribly wrong.
38 | */
39 | public static final String PROPERTY_DONT_USE_SUBSTANCE_RENDERERS =
40 | "org.fife.ui.autocomplete.DontUseSubstanceRenderers";
41 |
42 | /**
43 | * If this system property is true
, then even the "main" two
44 | * auto-complete windows will allow window decorations via
45 | * {@link PopupWindowDecorator}. If this property is undefined or
46 | * false
, they won't honor such decorations. This is due to
47 | * certain performance issues with translucent windows (used for drop
48 | * shadows), even as of Java 7u2.
49 | */
50 | public static final String PROPERTY_ALLOW_DECORATED_AUTOCOMPLETE_WINDOWS =
51 | "org.fife.ui.autocomplete.allowDecoratedAutoCompleteWindows";
52 |
53 | /**
54 | * Used for the color of hyperlinks when a LookAndFeel uses light text
55 | * against a dark background.
56 | */
57 | public static final Color LIGHT_HYPERLINK_FG = new Color(0xd8ffff);
58 |
59 | private static final Pattern TAG_PATTERN = Pattern.compile("<[^>]*>");
60 |
61 | private static final boolean USE_SUBSTANCE_RENDERERS;
62 | private static boolean desktopCreationAttempted;
63 | private static Desktop desktop;
64 | private static final Object LOCK_DESKTOP_CREATION = new Object();
65 |
66 |
67 | private Util() {
68 | }
69 |
70 | /**
71 | * Attempts to open a web browser to the specified URI.
72 | *
73 | * @param uri The URI to open. If this is null
, nothing
74 | * happens and this method returns false
.
75 | * @return Whether the operation was successful.
76 | */
77 | public static boolean browse(URI uri) {
78 |
79 | boolean success = false;
80 |
81 | if (uri!=null) {
82 | Desktop desktop = getDesktop();
83 | if (desktop!=null) {
84 | try {
85 | desktop.browse(uri);
86 | success = true;
87 | } catch (RuntimeException re) {
88 | throw re; // Keep FindBugs happy
89 | } catch (Exception e) {
90 | // Ignore, just return "false" below.
91 | }
92 | }
93 | }
94 |
95 | return success;
96 |
97 | }
98 |
99 |
100 | /**
101 | * Returns the singleton java.awt.Desktop
instance, or
102 | * null
if it is unsupported on this platform.
103 | *
104 | * @return The desktop, as an {@link Object}, or {@code null}
105 | * if desktop operations are unsupported.
106 | */
107 | private static Desktop getDesktop() {
108 |
109 | synchronized (LOCK_DESKTOP_CREATION) {
110 | if (!desktopCreationAttempted) {
111 | desktopCreationAttempted = true;
112 | if (Desktop.isDesktopSupported()) {
113 | desktop = Desktop.getDesktop();
114 | }
115 | }
116 | }
117 |
118 | return desktop;
119 |
120 | }
121 |
122 |
123 | /**
124 | * Returns the color to use for hyperlink-style components. This method
125 | * will return Color.blue
unless it appears that the current
126 | * LookAndFeel uses light text on a dark background, in which case a
127 | * brighter alternative is returned.
128 | *
129 | * @return The color to use for hyperlinks.
130 | * @see TipUtil#getToolTipHyperlinkForeground()
131 | */
132 | static Color getHyperlinkForeground() {
133 |
134 | // This property is defined by all standard LaFs, even Nimbus (!),
135 | // but you never know what crazy LaFs there are...
136 | Color fg = UIManager.getColor("Label.foreground");
137 | if (fg==null) {
138 | fg = new JLabel().getForeground();
139 | }
140 |
141 | return isLightForeground(fg) ? LIGHT_HYPERLINK_FG : Color.blue;
142 |
143 | }
144 |
145 |
146 | /**
147 | * Returns the screen coordinates for the monitor that contains the
148 | * specified point. This is useful for setups with multiple monitors,
149 | * to ensure that popup windows are positioned properly.
150 | *
151 | * @param x The x-coordinate, in screen coordinates.
152 | * @param y The y-coordinate, in screen coordinates.
153 | * @return The bounds of the monitor that contains the specified point.
154 | */
155 | public static Rectangle getScreenBoundsForPoint(int x, int y) {
156 | GraphicsEnvironment env = GraphicsEnvironment.
157 | getLocalGraphicsEnvironment();
158 | GraphicsDevice[] devices = env.getScreenDevices();
159 | for (GraphicsDevice device : devices) {
160 | GraphicsConfiguration config = device.getDefaultConfiguration();
161 | Rectangle gcBounds = config.getBounds();
162 | if (gcBounds.contains(x, y)) {
163 | return gcBounds;
164 | }
165 | }
166 | // If point is outside all monitors, default to default monitor (?)
167 | return env.getMaximumWindowBounds();
168 | }
169 |
170 |
171 | /**
172 | * Give apps a chance to decorate us with drop shadows, etc. Since very
173 | * scrollable things such as lists (of e.g. completions) are *very* slow
174 | * when in per-pixel translucent windows, even as of Java 7u2, we force the
175 | * user to specify an extra option for the two "main" auto-complete windows.
176 | *
177 | * @return Whether to allow decorating the main auto-complete windows.
178 | * @see #PROPERTY_ALLOW_DECORATED_AUTOCOMPLETE_WINDOWS
179 | */
180 | public static boolean getShouldAllowDecoratingMainAutoCompleteWindows() {
181 | try {
182 | return Boolean.getBoolean(
183 | PROPERTY_ALLOW_DECORATED_AUTOCOMPLETE_WINDOWS);
184 | } catch (AccessControlException ace) { // We're in an applet.
185 | return false;
186 | }
187 | }
188 |
189 |
190 | /**
191 | * Returns whether we should attempt to use Substance cell renderers and
192 | * styles for things such as completion choices, if a Substance Look and
193 | * Feel is installed. If this is false
, we'll use our
194 | * standard rendering for completions, even when Substance is being used.
195 | *
196 | * @return Whether to use Substance renderers if Substance is installed.
197 | */
198 | public static boolean getUseSubstanceRenderers() {
199 | return USE_SUBSTANCE_RENDERERS;
200 | }
201 |
202 |
203 | /**
204 | * Returns whether the specified color is "light" to use as a foreground.
205 | * Colors that return true
indicate that the current Look and
206 | * Feel probably uses light text colors on a dark background.
207 | *
208 | * @param fg The foreground color.
209 | * @return Whether it is a "light" foreground color.
210 | */
211 | public static boolean isLightForeground(Color fg) {
212 | return fg.getRed()>0xa0 && fg.getGreen()>0xa0 && fg.getBlue()>0xa0;
213 | }
214 |
215 |
216 | /**
217 | * Returns whether a string starts with a specified prefix, ignoring case.
218 | * This method does not support characters outside the BMP.
219 | *
220 | * @param str The string to check. This cannot be {@code null}.
221 | * @param prefix The prefix to check for. This cannot be {@code null}.
222 | * @return Whether {@code str} starts with {@code prefix}, ignoring case.
223 | */
224 | public static boolean startsWithIgnoreCase(String str, String prefix) {
225 | int prefixLength = prefix.length();
226 | if (str.length() >= prefixLength) {
227 | return str.regionMatches(true, 0, prefix, 0, prefixLength);
228 | }
229 | return false;
230 | }
231 |
232 |
233 | /**
234 | * Strips any HTML from a string. The string must start with
235 | * "<html>
" for markup tags to be stripped.
236 | *
237 | * @param text The string.
238 | * @return The string, with any HTML stripped.
239 | */
240 | public static String stripHtml(String text) {
241 | if (text==null || !text.startsWith("")) {
242 | return text;
243 | }
244 | // TODO: Micro-optimize me, might be called in renderers and loops
245 | return TAG_PATTERN.matcher(text).replaceAll("");
246 | }
247 |
248 |
249 | static {
250 |
251 | boolean use;
252 | try {
253 | use = !Boolean.getBoolean(PROPERTY_DONT_USE_SUBSTANCE_RENDERERS);
254 | } catch (AccessControlException ace) { // We're in an applet.
255 | use = true;
256 | }
257 | USE_SUBSTANCE_RENDERERS = use;
258 |
259 | }
260 |
261 |
262 | }
263 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/VariableCompletion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/22/2008
3 | *
4 | * VariableCompletion.java - A completion for a variable.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete;
10 |
11 | import javax.swing.text.JTextComponent;
12 |
13 |
14 | /**
15 | * A completion for a variable (or constant) in a programming language.
16 | *
17 | * This completion type uses its {@code shortDescription} property as part of
18 | * its summary returned by {@link #getSummary()}; for this reason, it may be
19 | * a little longer (even much longer), if desired, than what is recommended
20 | * for {@code BasicCompletion}s (where the {@code shortDescription} is used
21 | * in {@link #toString()} for {@code ListCellRenderers}).
22 | *
23 | * @author Robert Futrell
24 | * @version 1.0
25 | */
26 | public class VariableCompletion extends BasicCompletion {
27 |
28 | /**
29 | * The variable's type.
30 | */
31 | private String type;
32 |
33 | /**
34 | * What library (for example) this variable is defined in.
35 | */
36 | private String definedIn;
37 |
38 |
39 | /**
40 | * Constructor.
41 | *
42 | * @param provider The parent provider.
43 | * @param name The name of this variable.
44 | * @param type The type of this variable (e.g. "int
",
45 | * "String
", etc.).
46 | */
47 | public VariableCompletion(CompletionProvider provider, String name,
48 | String type) {
49 | super(provider, name);
50 | this.type = type;
51 | }
52 |
53 |
54 | /**
55 | * Adds the definition string for this completion to a buffer.
56 | *
57 | * @param sb The buffer to add to.
58 | */
59 | protected void addDefinitionString(StringBuilder sb) {
60 | sb.append("").append(getDefinitionString()).append(" ");
61 | }
62 |
63 |
64 | /**
65 | * Return the definition of this variable completion.
66 | *
67 | * @return The definition string.
68 | */
69 | public String getDefinitionString() {
70 |
71 | StringBuilder sb = new StringBuilder();
72 |
73 | // Add the return type if applicable (C macros like NULL have no type).
74 | if (type!=null) {
75 | sb.append(type).append(' ');
76 | }
77 |
78 | // Add the name of the item being described
79 | sb.append(getName());
80 |
81 | return sb.toString();
82 |
83 | }
84 |
85 |
86 | /**
87 | * Returns where this variable is defined.
88 | *
89 | * @return Where this variable is defined.
90 | * @see #setDefinedIn(String)
91 | */
92 | public String getDefinedIn() {
93 | return definedIn;
94 | }
95 |
96 |
97 | /**
98 | * Returns the name of this variable.
99 | *
100 | * @return The name.
101 | */
102 | public String getName() {
103 | return getReplacementText();
104 | }
105 |
106 |
107 | @Override
108 | public String getSummary() {
109 | StringBuilder sb = new StringBuilder();
110 | addDefinitionString(sb);
111 | possiblyAddDescription(sb);
112 | possiblyAddDefinedIn(sb);
113 | return sb.toString();
114 | }
115 |
116 |
117 | /**
118 | * Returns the tool tip text to display for mouse hovers over this
119 | * completion.
120 | *
121 | * Note that for this functionality to be enabled, a
122 | * {@code JTextComponent} must be registered with the
123 | * {@code ToolTipManager}, and the text component must know to search
124 | * for this value. In the case of an
125 | * RSyntaxTextArea , this
126 | * can be done with a {@code org.fife.ui.rtextarea.ToolTipSupplier} that
127 | * calls into
128 | * {@link CompletionProvider#getCompletionsAt(JTextComponent, java.awt.Point)}.
129 | *
130 | * @return The tool tip text for this completion, or null
if
131 | * none.
132 | */
133 | @Override
134 | public String getToolTipText() {
135 | return getDefinitionString();
136 | }
137 |
138 |
139 | /**
140 | * Returns the type of this variable.
141 | *
142 | * @return The type.
143 | */
144 | public String getType() {
145 | return type;
146 | }
147 |
148 |
149 | /**
150 | * Adds some HTML describing where this variable is defined, if this
151 | * information is known.
152 | *
153 | * @param sb The buffer to append to.
154 | */
155 | protected void possiblyAddDefinedIn(StringBuilder sb) {
156 | if (definedIn!=null) {
157 | sb.append("
Defined in:"); // TODO: Localize me
158 | sb.append(" ").append(definedIn).append(" ");
159 | }
160 | }
161 |
162 |
163 | /**
164 | * Adds the description text as HTML to a buffer, if a description is
165 | * defined.
166 | *
167 | * @param sb The buffer to append to.
168 | * @return Whether there was a description to add.
169 | */
170 | protected boolean possiblyAddDescription(StringBuilder sb) {
171 | if (getShortDescription()!=null) {
172 | sb.append(" ");
173 | sb.append(getShortDescription());
174 | sb.append(" ");
175 | return true;
176 | }
177 | return false;
178 | }
179 |
180 |
181 | /**
182 | * Sets where this variable is defined.
183 | *
184 | * @param definedIn Where this variable is defined.
185 | * @see #getDefinedIn()
186 | */
187 | public void setDefinedIn(String definedIn) {
188 | this.definedIn = definedIn;
189 | }
190 |
191 |
192 | /**
193 | * Overridden to return the name of the variable being completed.
194 | *
195 | * @return A string representation of this completion.
196 | */
197 | @Override
198 | public String toString() {
199 | return getName();
200 | }
201 |
202 |
203 | }
204 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/java/org/fife/ui/autocomplete/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This library is distributed under a modified BSD license. See the included
3 | * LICENSE.md file for details.
4 | */
5 | /**
6 | * The auto-completion library.
7 | */
8 | package org.fife.ui.autocomplete;
9 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=No description available
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_ar.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=\u0644\u0627 \u064a\u0648\u062c\u062f \u0634\u0631\u062d \u0645\u062a\u0627\u062d
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_de.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=Keine Beschreibung verf\u00fcgbar
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_es.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=No hay descripci\u00f3n disponible
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_fr.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=Aucune description disponible
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_hu.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=Nincs el\u00e9rhet\u0151 le\u00edr\u00e1s
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_in.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=No description available
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_it.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=Nessuna descrizione disponibile
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_ja.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=\u8a18\u8ff0\u306f\u4e0d\u660e\u3067\u3059
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_ko.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=\ud574\ub2f9 \uc124\uba85 \uc5c6\uc74c
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_nl.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=No description available
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_pl.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=Opis nie jest dost\u0119pny
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_pt_BR.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=Nenhuma descri\u00e7\u00e3o dispon\u00edvel
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_ru.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=\u041d\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_tr.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=A\u00e7\u0131klama mevcut de\u011fil
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_zh_CN.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=\u6ca1\u6709\u63cf\u8ff0
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/AutoCompleteDescWindow_zh_TW.properties:
--------------------------------------------------------------------------------
1 | NoDescAvailable=No description available
2 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/CompletionXml.dtd:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
20 |
22 |
27 |
28 |
32 |
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/arrow_left.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/AutoComplete/src/main/resources/org/fife/ui/autocomplete/arrow_left.png
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/arrow_right.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/AutoComplete/src/main/resources/org/fife/ui/autocomplete/arrow_right.png
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/bullet_black.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/AutoComplete/src/main/resources/org/fife/ui/autocomplete/bullet_black.png
--------------------------------------------------------------------------------
/AutoComplete/src/main/resources/org/fife/ui/autocomplete/osx_sizegrip.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/AutoComplete/src/main/resources/org/fife/ui/autocomplete/osx_sizegrip.png
--------------------------------------------------------------------------------
/AutoComplete/src/test/java/org/fife/ui/autocomplete/UtilTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This library is distributed under a modified BSD license. See the included
3 | * LICENSE.md file for details.
4 | */
5 | package org.fife.ui.autocomplete;
6 |
7 | import org.junit.jupiter.api.Assertions;
8 | import org.junit.jupiter.api.Test;
9 |
10 |
11 | class UtilTest {
12 |
13 | @Test
14 | void startsWithIgnoreCase_happyPath() {
15 |
16 | Assertions.assertTrue(Util.startsWithIgnoreCase("a", "a"));
17 | Assertions.assertTrue(Util.startsWithIgnoreCase("a", "A"));
18 |
19 | Assertions.assertTrue(Util.startsWithIgnoreCase("Hello world", "Hello"));
20 | Assertions.assertTrue(Util.startsWithIgnoreCase("Hello world", "hello"));
21 | Assertions.assertTrue(Util.startsWithIgnoreCase("Hello world", "HELLO"));
22 |
23 | }
24 |
25 |
26 | @Test
27 | void startsWithIgnoreCase_tricky_iWithoutDot() {
28 | Assertions.assertTrue(Util.startsWithIgnoreCase("\u0131", "i"));
29 | Assertions.assertTrue(Util.startsWithIgnoreCase("\u0131", "I"));
30 | Assertions.assertTrue(Util.startsWithIgnoreCase("i", "\u0131"));
31 | Assertions.assertTrue(Util.startsWithIgnoreCase("I", "\u0131"));
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/AutoCompleteDemo/README.md:
--------------------------------------------------------------------------------
1 | # AutoCompleteDemo
2 | A demo application showing off some features of the AutoComplete library.
3 |
--------------------------------------------------------------------------------
/AutoCompleteDemo/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | implementation project(path: ':AutoComplete')
3 | }
4 |
--------------------------------------------------------------------------------
/AutoCompleteDemo/src/main/java/org/fife/ui/autocomplete/demo/AutoCompleteDemoApp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 12/21/2008
3 | *
4 | * AutoCompleteDemoApp.java - A demo program for the auto-completion library.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete.demo;
10 |
11 | import java.awt.*;
12 | import javax.swing.*;
13 |
14 | import org.fife.ui.autocomplete.*;
15 |
16 |
17 | /**
18 | * A program that demonstrates use of auto-completion. It creates a simple
19 | * C source editor with context-sensitive auto-completion.
20 | *
21 | * @author Robert Futrell
22 | * @version 1.0
23 | */
24 | public class AutoCompleteDemoApp extends JFrame {
25 |
26 |
27 | /**
28 | * Constructor.
29 | */
30 | AutoCompleteDemoApp() {
31 | this(null);
32 | }
33 |
34 |
35 | /**
36 | * Constructor.
37 | *
38 | * @param provider The completion provider for the editor to use.
39 | */
40 | public AutoCompleteDemoApp(CompletionProvider provider) {
41 | setRootPane(new DemoRootPane(provider));
42 | setTitle("AutoCompletion Demo");
43 | setSize(new Dimension(500,600));//pack();
44 | setLocationRelativeTo(null);
45 | setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
46 | }
47 |
48 |
49 | /**
50 | * Program entry point.
51 | *
52 | * @param args Command line arguments.
53 | */
54 | public static void main(String[] args) {
55 |
56 | SwingUtilities.invokeLater(() -> {
57 | String laf = UIManager.getSystemLookAndFeelClassName();
58 | //laf = "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
59 | try {
60 | UIManager.setLookAndFeel(laf);
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | }
64 | AutoCompleteDemoApp frame = new AutoCompleteDemoApp();
65 | frame.getToolkit().setDynamicLayout(true);
66 | frame.setVisible(true);
67 | });
68 |
69 | }
70 |
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/AutoCompleteDemo/src/main/java/org/fife/ui/autocomplete/demo/CCellRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * 01/07/2009
3 | *
4 | * CCellRenderer.java - A cell renderer for C completions.
5 | *
6 | * This library is distributed under a modified BSD license. See the included
7 | * LICENSE.md file for details.
8 | */
9 | package org.fife.ui.autocomplete.demo;
10 |
11 | import javax.swing.Icon;
12 | import javax.swing.JList;
13 |
14 | import org.fife.ui.autocomplete.Completion;
15 | import org.fife.ui.autocomplete.CompletionCellRenderer;
16 | import org.fife.ui.autocomplete.FunctionCompletion;
17 | import org.fife.ui.autocomplete.VariableCompletion;
18 |
19 |
20 | /**
21 | * The cell renderer used for the C programming language.
22 | *
23 | * @author Robert Futrell
24 | * @version 1.0
25 | */
26 | class CCellRenderer extends CompletionCellRenderer {
27 |
28 | private final Icon variableIcon;
29 | private final Icon functionIcon;
30 |
31 |
32 | /**
33 | * Constructor.
34 | */
35 | CCellRenderer() {
36 | variableIcon = getIcon("img/var.png");
37 | functionIcon = getIcon("img/function.png");
38 | }
39 |
40 |
41 | @Override
42 | protected void prepareForOtherCompletion(JList> list,
43 | Completion c, int index, boolean selected, boolean hasFocus) {
44 | super.prepareForOtherCompletion(list, c, index, selected, hasFocus);
45 | setIcon(getEmptyIcon());
46 | }
47 |
48 |
49 | @Override
50 | protected void prepareForVariableCompletion(JList> list,
51 | VariableCompletion vc, int index, boolean selected,
52 | boolean hasFocus) {
53 | super.prepareForVariableCompletion(list, vc, index, selected,
54 | hasFocus);
55 | setIcon(variableIcon);
56 | }
57 |
58 |
59 | @Override
60 | protected void prepareForFunctionCompletion(JList> list,
61 | FunctionCompletion fc, int index, boolean selected,
62 | boolean hasFocus) {
63 | super.prepareForFunctionCompletion(list, fc, index, selected,
64 | hasFocus);
65 | setIcon(functionIcon);
66 | }
67 |
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/AutoCompleteDemo/src/main/java/org/fife/ui/autocomplete/demo/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * This library is distributed under a modified BSD license. See the included
3 | * LICENSE.md file for details.
4 | */
5 | /**
6 | * A package that demonstrates features of the AutoComplete library.
7 | */
8 | package org.fife.ui.autocomplete.demo;
9 |
--------------------------------------------------------------------------------
/AutoCompleteDemo/src/main/resources/img/function.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/AutoCompleteDemo/src/main/resources/img/function.png
--------------------------------------------------------------------------------
/AutoCompleteDemo/src/main/resources/img/macro.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/AutoCompleteDemo/src/main/resources/img/macro.png
--------------------------------------------------------------------------------
/AutoCompleteDemo/src/main/resources/img/var.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/AutoCompleteDemo/src/main/resources/img/var.png
--------------------------------------------------------------------------------
/AutoCompleteDemo/src/main/resources/lang/c/create_c_xml.pl:
--------------------------------------------------------------------------------
1 | #!/usr/local/bin/perl
2 | #
3 | # create_c_xml.pl - Generates the XML API file for RSyntaxTextArea from c.txt
4 | #
5 | # Usage:
6 | # perl create_c_xml.pl
7 | #
8 | use strict;
9 | use Cwd qw(abs_path);
10 | use File::Basename;
11 |
12 |
13 | sub fixDesc {
14 |
15 | my $temp = $_[0];
16 |
17 | $temp =~ s/^\s+//; # Leading whitespace
18 | $temp =~ s/\n[\n]?$//; # Final (one or two) newlines
19 | $temp =~ s!([^>])\n!$1 \n!g; # Newlines (for lines not ending in a tag)
20 |
21 | if ($temp =~ m/[\<\>\&]/) {
22 | $temp = "";
23 | }
24 | return $temp;
25 |
26 | }
27 |
28 |
29 | my $this_script = abs_path($0);
30 | my $dir = dirname($this_script);
31 | my $infile = "$dir/c.txt";
32 | my $outfile = "$dir/../c.xml";
33 |
34 | my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
35 | my $datestamp = sprintf("%4d-%02d-%02d %02d:%02d:%02d\n",
36 | $year+1900,$mon+1,$mday,$hour,$min,$sec);
37 |
38 | open(OUT, ">$outfile") || die("Cannot open outfile: $!\n");
39 |
40 | # Header information
41 | print OUT <
43 |
44 |
45 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 | EOT
63 |
64 | open(IN, $infile) || die("Cannot open infile: $!\n");
65 |
66 | my @elems;
67 | my $item;
68 | my $definedIn;
69 | my @names;
70 | my $line = ;
71 | while (length($line)>0) {
72 |
73 | # Skip header lines and empty lines between items.
74 | if ($line =~ m/^#+\s+([^ ]+)\s+#+$/) {
75 | $definedIn = $1;
76 | $line = ;
77 | next;
78 | }
79 | elsif ($line =~ m/^#.+|^$/) {
80 | $line = ;
81 | next;
82 | }
83 |
84 | if ($line =~ m/^([\w\s]+) (function|constant)/) { # An item to add
85 | my $name = $1;
86 | my $returnValDesc;
87 | push(@names, $name);
88 | $item = ");
91 | if ($line !~ m/^([^\|]+)\|(.*)$/) {
92 | print("ERROR: Bad format for function return type line: '$line'\n");
93 | exit(1);
94 | }
95 | $item .= " returnType=\"";
96 | $item .= $1 . "\"";
97 | $returnValDesc = $2;
98 | }
99 | $item .= " definedIn=\"" . $definedIn . "\">\n";
100 | my $params = "";
101 | while (chomp($line=) && ($line =~ m/^[^ ]/)) {
102 | if ($line =~ m/^(\w+) (\([^\)]+\)\([^\)]+\))\|(.*)$/) { # bsearch - tricky function argument
103 | $params .= "\t\t 0) {
105 | # Try to only put param descs in CDATA if necessary, to keep XML size down.
106 | my $desc = $3;
107 | if ($desc =~ m/[<>]/) {
108 | $desc = fixDesc($desc);
109 | }
110 | $params .= ">\n\t\t\t$desc \n\t\t\n";
111 | }
112 | else {
113 | $params .= "/>\n";
114 | }
115 | }
116 | elsif ($line =~ m/^(.+)? ([\w_\(\)\*]+(:?\[[\w_]+\])?)\|(.*)$/) {
117 | $params .= "\t\t 0) {
119 | # Try to only put param descs in CDATA if necessary, to keep XML size down.
120 | my $desc = $4;
121 | if ($desc =~ m/[<>]/) {
122 | $desc = fixDesc($desc);
123 | }
124 | $params .= ">\n\t\t\t$desc \n\t\t\n";
125 | }
126 | else {
127 | $params .= "/>\n";
128 | }
129 | }
130 | elsif ($line =~ m/^\.\.\.\|(.*)$/) {
131 | $params .= "\t\t 0) {
133 | # Try to only put param descs in CDATA if necessary, to keep XML size down.
134 | my $desc = $1;
135 | if ($desc =~ m/[<>]/) {
136 | $desc = fixDesc($desc);
137 | }
138 | $params .= ">\n\t\t\t$desc \n\t\t\n";
139 | }
140 | else {
141 | $params .= "/>\n";
142 | }
143 | }
144 | elsif ($line =~ m/^([\w_])+\|(.*)?$/) {
145 | $params .= "\t\t 0) {
147 | # Try to only put param descs in CDATA if necessary, to keep XML size down.
148 | my $desc = $2;
149 | if ($desc =~ m/[<>]/) {
150 | $desc = fixDesc($desc);
151 | }
152 | $params .= ">\n\t\t\t$desc \n\t\t\n";
153 | }
154 | else {
155 | $params .= "/>\n";
156 | }
157 | }
158 | else {
159 | print("WARNING: Param line didn't match regex:\n");
160 | print("\"$line\"\n");
161 | }
162 | }
163 | if (length($params)>0) {
164 | $item .= "\t\n";
165 | $item .= $params;
166 | $item .= "\t \n";
167 | }
168 | $item .= "\t";
169 | my $desc = "";
170 | while (defined($line) && ($line =~ m/^$|^ /)) {
171 | $desc .= substr($line, 1) . "\n";
172 | chomp($line = );
173 | }
174 | $desc = fixDesc($desc);
175 | $item .= "$desc \n";
176 | if (length($returnValDesc)>0) {
177 | $item .= "\t" . fixDesc($returnValDesc) . " \n";
178 | }
179 | $item .= " ";
180 | #print($item);
181 | push(@elems, $item);
182 | }
183 |
184 | else {
185 | print(STDERR "ERROR: Unexpected line format: \"$line\"\n");
186 | exit(1);
187 | }
188 |
189 | }
190 |
191 | # Get items for the last header.
192 | if (length($item)>0) {
193 | push(@elems, $item);
194 | }
195 |
196 | if (@elems>0) {
197 | foreach (sort {lc $a cmp lc $b} @elems) {
198 | my $elem = $_;
199 | print(OUT "$elem\n");
200 | }
201 | }
202 |
203 | close(IN);
204 |
205 | # Print footer of XML definition file
206 | print OUT <
208 |
209 |
210 | EOT
211 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright (c) 2021, Robert Futrell
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above copyright
10 | notice, this list of conditions and the following disclaimer in the
11 | documentation and/or other materials provided with the distribution.
12 | * Neither the name of the author nor the names of its contributors may
13 | be used to endorse or promote products derived from this software
14 | without specific prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AutoComplete
2 | 
3 | 
4 | 
5 |
6 | AutoComplete is a code completion library for Swing JTextComponents, with enhanced functionality available
7 | for instances of [RSyntaxTextArea](https://github.com/bobbylight/RSyntaxTextArea).
8 |
9 | AutoComplete is available under a [modified BSD license](https://github.com/bobbylight/AutoComplete/blob/master/LICENSE.md).
10 |
11 | # Features
12 | * A completion choices list that updates as the user types
13 | * A "documentation" companion window for displaying documentation about the currently selected completion choice
14 | * Parameter assistance (e.g. tabbing through function/method parameters, with tool tip assistance for each argument
15 | and a possible list of valid variable completions for each)
16 |
17 | # Adding to Your Project
18 | This library is available in the
19 | [Maven Central repository](http://search.maven.org/#search%7Cga%7C1%7Cautocomplete%20jar) (`com.fifesoft:autocomplete:XXX`).
20 | SNAPSHOT builds of the in-development, unreleased version are hosted on
21 | [Sonatype](https://oss.sonatype.org/content/repositories/snapshots/com/fifesoft/autocomplete/).
22 |
23 | # Compiling
24 | AutoComplete is built using Gradle. It requires Java 17 to buil but runs on
25 | Java 8 or later.
26 | To compile the source, run all tests, and build the distribution jar,
27 | simply run the following gradle command:
28 |
29 | ```bash
30 | gradlew clean build --warning-mode all
31 | ```
32 |
33 | # Example Usage
34 | The example below shows how to add code completion for simple keywords to
35 | RSyntaxTextArea. For more examples, see the `AutoCompleteDemo`
36 | submodule in this project.
37 |
38 | ```java
39 | import java.awt.*;
40 | import javax.swing.*;
41 | import org.fife.ui.autocomplete.*;
42 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
43 | import org.fife.ui.rsyntaxtextarea.SyntaxConstants;
44 | import org.fife.ui.rtextarea.RTextScrollPane;
45 |
46 | public class AutoCompleteDemo extends JFrame {
47 |
48 | public AutoCompleteDemo() {
49 |
50 | JPanel contentPane = new JPanel(new BorderLayout());
51 | RSyntaxTextArea textArea = new RSyntaxTextArea(20, 60);
52 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
53 | textArea.setCodeFoldingEnabled(true);
54 | contentPane.add(new RTextScrollPane(textArea));
55 |
56 | // A CompletionProvider is what knows of all possible completions, and
57 | // analyzes the contents of the text area at the caret position to
58 | // determine what completion choices should be presented. Most instances
59 | // of CompletionProvider (such as DefaultCompletionProvider) are designed
60 | // so that they can be shared among multiple text components.
61 | CompletionProvider provider = createCompletionProvider();
62 |
63 | // An AutoCompletion acts as a "middle-man" between a text component
64 | // and a CompletionProvider. It manages any options associated with
65 | // the auto-completion (the popup trigger key, whether to display a
66 | // documentation window along with completion choices, etc.). Unlike
67 | // CompletionProviders, instances of AutoCompletion cannot be shared
68 | // among multiple text components.
69 | AutoCompletion ac = new AutoCompletion(provider);
70 | ac.install(textArea);
71 |
72 | setContentPane(contentPane);
73 | setTitle("AutoComplete Demo");
74 | setDefaultCloseOperation(EXIT_ON_CLOSE);
75 | pack();
76 | setLocationRelativeTo(null);
77 |
78 | }
79 |
80 | /**
81 | * Create a simple provider that adds some Java-related completions.
82 | */
83 | private CompletionProvider createCompletionProvider() {
84 |
85 | // A DefaultCompletionProvider is the simplest concrete implementation
86 | // of CompletionProvider. This provider has no understanding of
87 | // language semantics. It simply checks the text entered up to the
88 | // caret position for a match against known completions. This is all
89 | // that is needed in the majority of cases.
90 | DefaultCompletionProvider provider = new DefaultCompletionProvider();
91 |
92 | // Add completions for all Java keywords. A BasicCompletion is just
93 | // a straightforward word completion.
94 | provider.addCompletion(new BasicCompletion(provider, "abstract"));
95 | provider.addCompletion(new BasicCompletion(provider, "assert"));
96 | provider.addCompletion(new BasicCompletion(provider, "break"));
97 | provider.addCompletion(new BasicCompletion(provider, "case"));
98 | // ... etc ...
99 | provider.addCompletion(new BasicCompletion(provider, "transient"));
100 | provider.addCompletion(new BasicCompletion(provider, "try"));
101 | provider.addCompletion(new BasicCompletion(provider, "void"));
102 | provider.addCompletion(new BasicCompletion(provider, "volatile"));
103 | provider.addCompletion(new BasicCompletion(provider, "while"));
104 |
105 | // Add a couple of "shorthand" completions. These completions don't
106 | // require the input text to be the same thing as the replacement text.
107 | provider.addCompletion(new ShorthandCompletion(provider, "sysout",
108 | "System.out.println(", "System.out.println("));
109 | provider.addCompletion(new ShorthandCompletion(provider, "syserr",
110 | "System.err.println(", "System.err.println("));
111 |
112 | return provider;
113 |
114 | }
115 |
116 | public static void main(String[] args) {
117 | // Instantiate GUI on the EDT.
118 | SwingUtilities.invokeLater(() -> {
119 | try {
120 | String laf = UIManager.getSystemLookAndFeelClassName();
121 | UIManager.setLookAndFeel(laf);
122 | } catch (Exception e) { /* Never happens */ }
123 | new AutoCompleteDemo().setVisible(true);
124 | });
125 | }
126 |
127 | }
128 | ```
129 | # Sister Projects
130 | * [RSyntaxTextArea](https://github.com/bobbylight/RSyntaxTextArea) provides syntax highlighting, code folding, and many other features out-of-the-box.
131 | * [RSTALanguageSupport](https://github.com/bobbylight/RSTALanguageSupport) - Code completion for RSTA for the following languages: Java, JavaScript, HTML, PHP, JSP, Perl, C, Unix Shell. Built on both RSTA and AutoComplete.
132 | * [SpellChecker](https://github.com/bobbylight/SpellChecker) - Adds squiggle-underline spell checking to RSyntaxTextArea.
133 | * [RSTAUI](https://github.com/bobbylight/RSTAUI) - Common dialogs needed by text editing applications: Find, Replace, Go to Line, File Properties.
134 |
135 | # Getting Help
136 | * Add an [issue on GitHub](https://github.com/bobbylight/AutoComplete/issues)
137 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | mavenCentral()
4 | }
5 | dependencies {
6 | classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:7.1.0'
7 | }
8 | }
9 |
10 | plugins {
11 | id 'com.github.spotbugs' version '6.1.3'
12 | }
13 |
14 | // We require building with JDK 17 or later. Built artifact compatibility
15 | // is controlled by javaLanguageVersion
16 | assert JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)
17 |
18 | group = 'com.fifesoft'
19 | // NOTE: Local Java 17: /Library/Java/JavaVirtualMachines/jdk-17.0.13+11/Contents/Home
20 |
21 | allprojects {
22 |
23 | repositories {
24 | mavenCentral()
25 | maven {
26 | url = 'https://oss.sonatype.org/content/repositories/snapshots'
27 | }
28 | }
29 |
30 | wrapper {
31 | gradleVersion = '8.12.1'
32 | }
33 | }
34 |
35 | subprojects {
36 |
37 | apply plugin: 'java'
38 | apply plugin: 'checkstyle'
39 | apply plugin: 'com.github.spotbugs'
40 |
41 | tasks.withType(JavaCompile).configureEach {
42 | options.encoding = 'UTF-8'
43 | }
44 |
45 | test {
46 | useJUnitPlatform()
47 | }
48 |
49 | checkstyle {
50 | toolVersion = '10.21.2'
51 | configDirectory = file("$rootProject.projectDir/config/checkstyle")
52 | }
53 |
54 | spotbugs {
55 | // Relative to subprojects
56 | includeFilter = file('../config/spotbugs-exclude.xml')
57 | }
58 |
59 | spotbugsMain {
60 | reports {
61 | html {
62 | required = true
63 | }
64 | xml {
65 | required = false
66 | }
67 | }
68 | }
69 | spotbugsTest {
70 | reports {
71 | html {
72 | required = true
73 | }
74 | xml {
75 | required = false
76 | }
77 | }
78 | }
79 |
80 | dependencies {
81 | testImplementation platform('org.junit:junit-bom:5.11.4')
82 | testImplementation 'org.junit.jupiter:junit-jupiter'
83 | testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
84 | }
85 |
86 | compileJava {
87 | options.release = Integer.parseInt(javaLanguageVersion)
88 | options.debug = true
89 | options.debugOptions.debugLevel = 'source,vars,lines'
90 | options.compilerArgs << "-Xlint:deprecation" << '-Xlint:unchecked'
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/config/checkstyle/acSuppressions.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/config/checkstyle/javaHeader.txt:
--------------------------------------------------------------------------------
1 | /*
2 |
--------------------------------------------------------------------------------
/config/spotbugs-exclude.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Note that Maven- and signing-related properties are in /gradle.properties
2 | javaLanguageVersion=8
3 | version=3.3.3-SNAPSHOT
4 |
5 | # Ugh, see https://github.com/gradle/gradle/issues/11308
6 | systemProp.org.gradle.internal.publish.checksums.insecure=true
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bobbylight/AutoComplete/72408f54b302f53f053d0fbda7266fe78855920b/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.12.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=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
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, 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 | org.gradle.wrapper.GradleWrapperMain \
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=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
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 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'AutoComplete'
2 |
3 | include 'AutoComplete', 'AutoCompleteDemo'
4 |
--------------------------------------------------------------------------------