diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..d2f3b41
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..a55e7a1
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/dbnavigator.xml b/.idea/dbnavigator.xml
new file mode 100644
index 0000000..6dafaf6
--- /dev/null
+++ b/.idea/dbnavigator.xml
@@ -0,0 +1,403 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..f9743fb
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..ade1ecd
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..a636d88
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/qstudio-refactor.iml b/.idea/qstudio-refactor.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/qstudio-refactor.iml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/customauth/gradle/wrapper/gradle-wrapper.jar b/customauth/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..7f93135
Binary files /dev/null and b/customauth/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/customauth/gradle/wrapper/gradle-wrapper.properties b/customauth/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..3fa8f86
--- /dev/null
+++ b/customauth/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,7 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
+networkTimeout=10000
+validateDistributionUrl=true
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/customauth/gradlew b/customauth/gradlew
new file mode 100755
index 0000000..1aa94a4
--- /dev/null
+++ b/customauth/gradlew
@@ -0,0 +1,249 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+# This is normally unused
+# shellcheck disable=SC2034
+APP_BASE_NAME=${0##*/}
+# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
+APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ if ! command -v java >/dev/null 2>&1
+ then
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
+ # shellcheck disable=SC2039,SC3045
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Collect all arguments for the java command:
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
+# and any embedded shellness will be escaped.
+# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
+# treated as '${Hostname}' itself on the command line.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/customauth/gradlew.bat b/customauth/gradlew.bat
new file mode 100644
index 0000000..6689b85
--- /dev/null
+++ b/customauth/gradlew.bat
@@ -0,0 +1,92 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+@rem This is normally unused
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/qstudio/src/main/java/com/timestored/qdoc/ParsedQEntity.java b/qstudio/src/main/java/com/timestored/qdoc/ParsedQEntity.java
index f584fb6..30492d5 100644
--- a/qstudio/src/main/java/com/timestored/qdoc/ParsedQEntity.java
+++ b/qstudio/src/main/java/com/timestored/qdoc/ParsedQEntity.java
@@ -47,45 +47,44 @@ public class ParsedQEntity implements QEntity, Comparable {
public static final String EXAMPLE_TAG = "example";
public static final String RETURN_TAG = "return";
private static final Map EMPTY_MAP = Collections.emptyMap();
-
+
private final String name;
private final String namespace;
private final String docDescription;
private final String returnDescription;
-
+
/** named tags are like @param ie they have multiple named entries per tag */
private final Map> namedTags;
/** tags like @return where it has only one assigned string */
private final Map tags;
-
+
private final ParsedQFile parentFile;
private final int offset;
-
/**
- *
+ *
* @param parentFile specifies the parent file to this entity. null is permitted, note
* entities are considered equal regardless of what file they are in.
*/
- static ParsedQEntity get(ParsedQFile parentFile, String name, String namespace,
- ParsedComments pec, int offset) {
-
- return new ParsedQEntity(parentFile, name, namespace, pec.docDescription,
- pec.namedTags, pec.tags,
+ static ParsedQEntity get(ParsedQFile parentFile, String name, String namespace,
+ ParsedComments pec, int offset) {
+
+ return new ParsedQEntity(parentFile, name, namespace, pec.docDescription,
+ pec.namedTags, pec.tags,
pec.returnDescription, offset);
}
-
+
/**
* @param parentFile specifies the parent file to this entity. null is NOT permitted, note
* entities are considered equal regardless of what file they are in.
*/
- private ParsedQEntity(ParsedQFile parentFile, String name,
- String namespace, String docDescription,
- Map> namedTags,
- Map tags,
- String returnDescription,
- int offset) {
-
+ private ParsedQEntity(ParsedQFile parentFile, String name,
+ String namespace, String docDescription,
+ Map> namedTags,
+ Map tags,
+ String returnDescription,
+ int offset) {
+
this.name = Preconditions.checkNotNull(name);
this.namespace = Preconditions.checkNotNull(namespace);
this.docDescription = (docDescription == null ? "" : docDescription);
@@ -96,18 +95,18 @@ private ParsedQEntity(ParsedQFile parentFile, String name,
this.parentFile = Preconditions.checkNotNull(parentFile);
this.offset = offset;
}
-
-
+
+
/**
* @param parentFile specifies the parent file to this entity. null is NOT permitted, note
* entities are considered equal regardless of what file they are in.
*/
- public static ParsedQEntity get(ParsedQFile parentFile, String name,
- String namespace, String docDescription,
- Map paramDescriptions,
- Map exceptionDescriptions,
- String returnDescription,
- int offset) {
+ public static ParsedQEntity get(ParsedQFile parentFile, String name,
+ String namespace, String docDescription,
+ Map paramDescriptions,
+ Map exceptionDescriptions,
+ String returnDescription,
+ int offset) {
HashMap> namedTags = new HashMap>();
if(paramDescriptions != null) {
@@ -116,11 +115,11 @@ public static ParsedQEntity get(ParsedQFile parentFile, String name,
if(exceptionDescriptions != null) {
namedTags.put(EXCEPTION_TAG, Collections.unmodifiableMap(exceptionDescriptions));
}
- return new ParsedQEntity(parentFile, name, namespace, docDescription,
+ return new ParsedQEntity(parentFile, name, namespace, docDescription,
namedTags, EMPTY_MAP, returnDescription, offset);
}
- /** {@inheritDoc} */ @Override
+ /** {@inheritDoc} */ @Override
public String getNamespace() {
return namespace;
}
@@ -132,83 +131,99 @@ public String getHtmlDoc(boolean shortFormat) {
}
public String getHtmlDoc(boolean shortFormat, String baseWeblink) {
-
boolean hasDocs = !docDescription.trim().isEmpty() || !tags.isEmpty() || !namedTags.isEmpty();
- String s = "";
-
- if(hasDocs) {
- StringBuilder sb = new StringBuilder();
- sb.append(HtmlUtils.START);
- sb.append("" + docDescription + "
");
-
- Map namesToDescs = Maps.newHashMap();
-
- for(Entry e : tags.entrySet()) {
- String k = e.getKey();
- if(k.equals(RETURN_TAG)) {
- k = "Return";
- }
- namesToDescs.put(k + ": ", e.getValue());
+
+ if (!hasDocs) {
+ return "";
+ }
+
+ return generateHtmlDoc(baseWeblink);
+ }
+
+ private String generateHtmlDoc(String baseWeblink) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(HtmlUtils.START);
+ sb.append("" + docDescription + "
");
+
+ Map namesToDescs = Maps.newHashMap();
+
+ processTags(namesToDescs);
+ processNamedTags(baseWeblink, namesToDescs);
+
+ sb.append(HtmlUtils.toTable(namesToDescs, true));
+ sb.append(HtmlUtils.END);
+ return sb.toString();
+ }
+
+ private void processTags(Map namesToDescs) {
+ for (Entry e : tags.entrySet()) {
+ String k = e.getKey();
+ if (k.equals(RETURN_TAG)) {
+ k = "Return";
}
-
- for(Entry> e : namedTags.entrySet()) {
- String k = e.getKey();
- if(k.equals(PARAM_TAG)) {
- k = "Parameters";
- } else if(k.equals(EXCEPTION_TAG)) {
- k = "Exceptions";
- } else if(k.equals(COLUMN_TAG)) {
- k = "Columns";
- }
-
- if(k.equals(EXAMPLE_TAG)) {
- k = "Examples";
- Map codeMap = Maps.newHashMap();
- e.getValue().forEach((String u, String vv) -> {
- if(baseWeblink!=null && baseWeblink.length()>0) {
- u = "" + u + "";
- }
- codeMap.put(u, "" + vv + "");
- });
- namesToDescs.put(k + ": ", HtmlUtils.toList(codeMap, true));
- } else {
- namesToDescs.put(k + ": ", HtmlUtils.toList(e.getValue(), true));
- }
+ namesToDescs.put(k + ": ", e.getValue());
+ }
+ }
+
+ private void processNamedTags(String baseWeblink, Map namesToDescs) {
+ for (Entry> e : namedTags.entrySet()) {
+ String k = e.getKey();
+ k = getTagDisplayName(k);
+
+ if (k.equals(EXAMPLE_TAG)) {
+ processExampleTags(baseWeblink, namesToDescs, e);
+ } else {
+ namesToDescs.put(k + ": ", HtmlUtils.toList(e.getValue(), true));
}
-
- sb.append(HtmlUtils.toTable(namesToDescs, true));
- sb.append(HtmlUtils.END);
- s = sb.toString();
}
-
- return s;
}
- /** {@inheritDoc} */ @Override
+ private void processExampleTags(String baseWeblink, Map namesToDescs, Entry> e) {
+ String k = "Examples";
+ Map codeMap = Maps.newHashMap();
+ e.getValue().forEach((String u, String vv) -> {
+ if (baseWeblink != null && !baseWeblink.isEmpty()) {
+ u = "" + u + "";
+ }
+ codeMap.put(u, "" + vv + "");
+ });
+ namesToDescs.put(k + ": ", HtmlUtils.toList(codeMap, true));
+ }
+
+ private String getTagDisplayName(String k) {
+ switch(k) {
+ case PARAM_TAG: return "Parameters";
+ case EXCEPTION_TAG: return "Exceptions";
+ case COLUMN_TAG: return "Columns";
+ default: return k;
+ }
+ }
+
+ /** {@inheritDoc} */ @Override
public String getDocName() {
- return getFullName();
+ return getFullName();
}
@Override public String getFullName() {
- return (namespace.equals(".") ? "" : namespace + ".") + name;
+ return (namespace.equals(".") ? "" : namespace + ".") + name;
}
-
+
String getDocDescription() {
return docDescription;
}
- /**
+ /**
* Named tags are like @param ie they have multiple named entries per tag.
* @return a map from names to entries, e.g. "param"->("key"->"a unique identifier")
*/
Map> getNamedTags() {
return Collections.unmodifiableMap(namedTags);
}
-
- /**
+
+ /**
* Named tags are like @param ie they have multiple named entries per tag
- * @return A map of names to descriptions if tagName exists otherwise an empty map.
+ * @return A map of names to descriptions if tagName exists otherwise an empty map.
*/
Map getNamedTags(String tagName) {
Map r = namedTags.get(tagName);
@@ -216,136 +231,71 @@ Map getNamedTags(String tagName) {
}
- /**
+ /**
* Tags like @return where it has only one assigned string
- * @return a map from tags to their description.
+ * @return a map from tags to their description.
*/
public Map getTags() {
return tags;
}
- /**
+ /**
* Tags like @return where it has only one assigned string
- * Get the description of a specific tag, or null if it does not exist.
+ * Get the description of a specific tag, or null if it does not exist.
*/
public String getTag(String tag) {
return tags.get(tag);
}
-
+
Map getParamTags() {
return getNamedTags(PARAM_TAG);
}
-
+
Map getExceptionTags() {
return getNamedTags(EXCEPTION_TAG);
}
-
+
String getReturnDescription() {
return returnDescription;
}
-
+
/**
- * @return The parent file if it is known, otherwise null
+ * @return The parent file if it is known, else null.
*/
- private String getSrcFileAbsolutePath() {
- return parentFile==null ? null : parentFile.getSrcFileAbsolutePath();
+ ParsedQFile getParentFile() {
+ return parentFile;
}
-
- /**
- * @return position from start of file in characters that entity occurs.
- * NOTE! \r\n are treated as one character only!! In order that {@link Document} and parsing
- * offsets match up. All due to javas editor pane handling new lines.
- */
- public int getOffset() {
+
+ int getOffset() {
return offset;
}
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("name", name)
- .add("namespace", namespace)
- .add("srcFilePath", getSrcFileAbsolutePath())
- .add("offset", offset)
- .toString();
+ public boolean isEmpty() {
+ return docDescription.trim().isEmpty()
+ && namedTags.isEmpty()
+ && tags.isEmpty();
}
-
-
- @Override
- public int hashCode(){
- return Objects.hashCode(super.hashCode(), name, namespace,
- docDescription, namedTags, getSrcFileAbsolutePath(), offset);
- }
-
- public String toFullString() {
- return MoreObjects.toStringHelper(this)
- .add("name", name)
- .add("namespace", namespace)
- .add("docDescription", docDescription)
- .add("returnDescription", returnDescription)
- .add("paramDescriptions", namedTags.get(PARAM_TAG))
- .add("exceptionDescriptions", namedTags.get(EXCEPTION_TAG))
- .add("srcFilePath", getSrcFileAbsolutePath())
- .add("offset", offset)
- .toString();
- }
-
-
- @Override
- public boolean equals(Object object){
- if (object instanceof ParsedQEntity) {
- ParsedQEntity that = (ParsedQEntity) object;
- return Objects.equal(this.name, that.name)
- && Objects.equal(this.namespace, that.namespace)
- && Objects.equal(this.docDescription, that.docDescription)
- && Objects.equal(this.namedTags, that.namedTags)
-// && Objects.equal(this.parentFile, that.parentFile)
- && Objects.equal(this.returnDescription, that.returnDescription);
-// && Objects.equal(this.offset, that.offset);
+ @Override public boolean equals(Object o) {
+ if (o instanceof ParsedQEntity) {
+ ParsedQEntity other = (ParsedQEntity) o;
+ return Objects.equal(this.name, other.name)
+ && Objects.equal(this.namespace, other.namespace)
+ && Objects.equal(this.docDescription, other.docDescription)
+ && Objects.equal(this.namedTags, other.namedTags)
+ && Objects.equal(this.returnDescription, other.returnDescription);
}
return false;
}
- /** @return Description up till the first full stop. */
- public String getShortDescription() {
- String s = getDocDescription();
- int p = s.indexOf('.');
- return p==-1 ? s : s.substring(0, p+1);
- }
-
- public void gotoDefinition(OpenDocumentsModel openDocumentsModel) throws IOException {
- String pth = getSrcFileAbsolutePath();
- if(pth!=null) {
- Document d = openDocumentsModel.openDocument(pth);
- d.setCaratPosition(getOffset());
- }
- }
-
- @Override public ImageIcon getIcon() {
- return Theme.CIcon.PAGE_CODE.get16();
+ @Override public int hashCode() {
+ return Objects.hashCode(super.hashCode(), name, namespace, docDescription, namedTags, getSrcFileAbsolutePath(), offset);
}
- @Override public SourceType getSourceType() {
- return SourceType.SOURCE;
+ @Override public int compareTo(ParsedQEntity other) {
+ return this.getFullName().compareTo(other.getFullName());
}
- @Override public String getSource() {
- return parentFile.getFileTitle();
- }
-
- ParsedQFile getParentFile() {
- return parentFile;
- }
-
- /** The name of this entity (not including namesapce */
- String getName() {
- return name;
- }
-
- @Override public int compareTo(ParsedQEntity o) {
- return this.getFullName().compareTo(o.getFullName());
- }
}
diff --git a/qstudio/src/main/java/org/simplericity/macify/eawt/DefaultApplication.java b/qstudio/src/main/java/org/simplericity/macify/eawt/DefaultApplication.java
index e244202..6b26c15 100644
--- a/qstudio/src/main/java/org/simplericity/macify/eawt/DefaultApplication.java
+++ b/qstudio/src/main/java/org/simplericity/macify/eawt/DefaultApplication.java
@@ -1,22 +1,5 @@
package org.simplericity.macify.eawt;
-/*
- * Copyright 2007 Eirik Bjorsnos.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
@@ -29,7 +12,6 @@
import java.util.HashMap;
import java.util.Map;
-
/**
* Implements Application by calling the Mac OS X API through reflection.
* If this class is used on a non-OS X platform the operations will have no effect or they will simulate
@@ -40,15 +22,21 @@ public class DefaultApplication implements Application {
private Object application;
private Class applicationListenerClass;
-
- Map listenerMap = Collections.synchronizedMap(new HashMap());
+ private Map listenerMap = Collections.synchronizedMap(new HashMap<>());
private boolean enabledAboutMenu = true;
private boolean enabledPreferencesMenu;
private boolean aboutMenuItemPresent = true;
private boolean preferencesMenuItemPresent;
private ClassLoader classLoader;
+ private ApplicationPlatform platform;
+
public DefaultApplication() {
+ this.platform = initializePlatform();
+ }
+
+ // Initialize platform to handle Mac or other platforms
+ private ApplicationPlatform initializePlatform() {
try {
final File file = new File("/System/Library/Java");
if (file.exists()) {
@@ -64,355 +52,393 @@ public DefaultApplication() {
Class appClass = Class.forName("com.apple.eawt.Application");
application = appClass.getMethod("getApplication", new Class[0]).invoke(null, new Object[0]);
applicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
- } catch (ClassNotFoundException e) {
- application = null;
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
+
+ return new MacPlatform(application, applicationListenerClass);
+ } catch (Exception e) {
+ return new DefaultPlatform();
}
+ }
+
+ @Override
+ public boolean isMac() {
+ return platform.isMac();
+ }
+
+ @Override
+ public void addAboutMenuItem() {
+ platform.addAboutMenuItem();
+ }
+
+ @Override
+ public void addApplicationListener(ApplicationListener applicationListener) {
+ platform.addApplicationListener(applicationListener);
+ }
+
+ @Override
+ public void addPreferencesMenuItem() {
+ platform.addPreferencesMenuItem();
+ }
+
+ @Override
+ public boolean getEnabledAboutMenu() {
+ return platform.getEnabledAboutMenu();
+ }
+
+ @Override
+ public boolean getEnabledPreferencesMenu() {
+ return platform.getEnabledPreferencesMenu();
+ }
+
+ @Override
+ public Point getMouseLocationOnScreen() {
+ return platform.getMouseLocationOnScreen();
+ }
+
+ @Override
+ public boolean isAboutMenuItemPresent() {
+ return platform.isAboutMenuItemPresent();
+ }
+
+ @Override
+ public boolean isPreferencesMenuItemPresent() {
+ return platform.isPreferencesMenuItemPresent();
+ }
+
+ @Override
+ public void removeAboutMenuItem() {
+ platform.removeAboutMenuItem();
+ }
+
+ @Override
+ public synchronized void removeApplicationListener(ApplicationListener applicationListener) {
+ platform.removeApplicationListener(applicationListener);
+ }
+
+ @Override
+ public void removePreferencesMenuItem() {
+ platform.removePreferencesMenuItem();
+ }
+ @Override
+ public void setEnabledAboutMenu(boolean enabled) {
+ platform.setEnabledAboutMenu(enabled);
}
+ @Override
+ public void setEnabledPreferencesMenu(boolean enabled) {
+ platform.setEnabledPreferencesMenu(enabled);
+ }
+
+ @Override
+ public int requestUserAttention(int type) {
+ return platform.requestUserAttention(type);
+ }
+
+ @Override
+ public void cancelUserAttentionRequest(int request) {
+ platform.cancelUserAttentionRequest(request);
+ }
+
+ @Override
+ public void setApplicationIconImage(BufferedImage image) {
+ platform.setApplicationIconImage(image);
+ }
+
+ @Override
+ public BufferedImage getApplicationIconImage() {
+ return platform.getApplicationIconImage();
+ }
+}
+
+// Abstract platform class to define the interface for platform-specific behavior
+abstract class ApplicationPlatform {
+
+ public abstract boolean isMac();
+
+ public abstract void addAboutMenuItem();
+
+ public abstract void addApplicationListener(ApplicationListener applicationListener);
+
+ public abstract void addPreferencesMenuItem();
+
+ public abstract boolean getEnabledAboutMenu();
+
+ public abstract boolean getEnabledPreferencesMenu();
+
+ public abstract Point getMouseLocationOnScreen();
+
+ public abstract boolean isAboutMenuItemPresent();
+
+ public abstract boolean isPreferencesMenuItemPresent();
+
+ public abstract void removeAboutMenuItem();
+
+ public abstract void removeApplicationListener(ApplicationListener applicationListener);
+
+ public abstract void removePreferencesMenuItem();
+
+ public abstract void setEnabledAboutMenu(boolean enabled);
+
+ public abstract void setEnabledPreferencesMenu(boolean enabled);
+
+ public abstract int requestUserAttention(int type);
+
+ public abstract void cancelUserAttentionRequest(int request);
+
+ public abstract void setApplicationIconImage(BufferedImage image);
+
+ public abstract BufferedImage getApplicationIconImage();
+}
+
+// Platform-specific implementation for Mac
+class MacPlatform extends ApplicationPlatform {
+
+ private Object application;
+ private Class applicationListenerClass;
+ private Map listenerMap = Collections.synchronizedMap(new HashMap<>());
+
+ public MacPlatform(Object application, Class applicationListenerClass) {
+ this.application = application;
+ this.applicationListenerClass = applicationListenerClass;
+ }
+
+ @Override
public boolean isMac() {
- return application != null;
+ return true;
}
+ @Override
public void addAboutMenuItem() {
- if (isMac()) {
- callMethod(application, "addAboutMenuItem");
- } else {
- this.aboutMenuItemPresent = true;
- }
+ callMethod("addAboutMenuItem");
}
+ @Override
public void addApplicationListener(ApplicationListener applicationListener) {
+ Object listener = Proxy.newProxyInstance(getClass().getClassLoader(),
+ new Class[]{applicationListenerClass},
+ new ApplicationListenerInvocationHandler(applicationListener));
- if (!Modifier.isPublic(applicationListener.getClass().getModifiers())) {
- throw new IllegalArgumentException("ApplicationListener must be a public class");
- }
- if (isMac()) {
- Object listener = Proxy.newProxyInstance(getClass().getClassLoader(),
- new Class[]{applicationListenerClass},
- new ApplicationListenerInvocationHandler(applicationListener));
-
- callMethod(application, "addApplicationListener", new Class[]{applicationListenerClass}, new Object[]{listener});
- listenerMap.put(applicationListener, listener);
- } else {
- listenerMap.put(applicationListener, applicationListener);
- }
+ callMethod(application, "addApplicationListener", new Class[]{applicationListenerClass}, new Object[]{listener});
+ listenerMap.put(applicationListener, listener);
}
+ @Override
public void addPreferencesMenuItem() {
- if (isMac()) {
- callMethod("addPreferencesMenuItem");
- } else {
- this.preferencesMenuItemPresent = true;
- }
+ callMethod("addPreferencesMenuItem");
}
+ @Override
public boolean getEnabledAboutMenu() {
- if (isMac()) {
- return callMethod("getEnabledAboutMenu").equals(Boolean.TRUE);
- } else {
- return enabledAboutMenu;
- }
+ return callMethod("getEnabledAboutMenu").equals(Boolean.TRUE);
}
+ @Override
public boolean getEnabledPreferencesMenu() {
- if (isMac()) {
- Object result = callMethod("getEnabledPreferencesMenu");
- return result.equals(Boolean.TRUE);
- } else {
- return enabledPreferencesMenu;
- }
+ return callMethod("getEnabledPreferencesMenu").equals(Boolean.TRUE);
}
+ @Override
public Point getMouseLocationOnScreen() {
- if (isMac()) {
- try {
- Method method = application.getClass().getMethod("getMouseLocationOnScreen", new Class[0]);
- return (Point) method.invoke(null, new Object[0]);
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- } else {
- return new Point(0, 0);
+ try {
+ Method method = application.getClass().getMethod("getMouseLocationOnScreen", new Class[0]);
+ return (Point) method.invoke(null, new Object[0]);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
}
+ @Override
public boolean isAboutMenuItemPresent() {
- if (isMac()) {
- return callMethod("isAboutMenuItemPresent").equals(Boolean.TRUE);
- } else {
- return aboutMenuItemPresent;
- }
+ return callMethod("isAboutMenuItemPresent").equals(Boolean.TRUE);
}
+ @Override
public boolean isPreferencesMenuItemPresent() {
- if (isMac()) {
- return callMethod("isPreferencesMenuItemPresent").equals(Boolean.TRUE);
- } else {
- return this.preferencesMenuItemPresent;
- }
+ return callMethod("isPreferencesMenuItemPresent").equals(Boolean.TRUE);
}
+ @Override
public void removeAboutMenuItem() {
- if (isMac()) {
- callMethod("removeAboutMenuItem");
- } else {
- this.aboutMenuItemPresent = false;
- }
+ callMethod("removeAboutMenuItem");
}
+ @Override
public synchronized void removeApplicationListener(ApplicationListener applicationListener) {
- if (isMac()) {
- Object listener = listenerMap.get(applicationListener);
- callMethod(application, "removeApplicationListener", new Class[]{applicationListenerClass}, new Object[]{listener});
-
- }
+ Object listener = listenerMap.get(applicationListener);
+ callMethod(application, "removeApplicationListener", new Class[]{applicationListenerClass}, new Object[]{listener});
listenerMap.remove(applicationListener);
}
+ @Override
public void removePreferencesMenuItem() {
- if (isMac()) {
- callMethod("removeAboutMenuItem");
- } else {
- this.preferencesMenuItemPresent = false;
- }
+ callMethod("removePreferencesMenuItem");
}
+ @Override
public void setEnabledAboutMenu(boolean enabled) {
- if (isMac()) {
- callMethod(application, "setEnabledAboutMenu", new Class[]{Boolean.TYPE}, new Object[]{Boolean.valueOf(enabled)});
- } else {
- this.enabledAboutMenu = enabled;
- }
+ callMethod(application, "setEnabledAboutMenu", new Class[]{Boolean.TYPE}, new Object[]{Boolean.valueOf(enabled)});
}
+ @Override
public void setEnabledPreferencesMenu(boolean enabled) {
- if (isMac()) {
- callMethod(application, "setEnabledPreferencesMenu", new Class[]{Boolean.TYPE}, new Object[]{Boolean.valueOf(enabled)});
- } else {
- this.enabledPreferencesMenu = enabled;
- }
-
+ callMethod(application, "setEnabledPreferencesMenu", new Class[]{Boolean.TYPE}, new Object[]{Boolean.valueOf(enabled)});
}
+ @Override
public int requestUserAttention(int type) {
- if (type != REQUEST_USER_ATTENTION_TYPE_CRITICAL && type != REQUEST_USER_ATTENTION_TYPE_INFORMATIONAL) {
- throw new IllegalArgumentException("Requested user attention type is not allowed: " + type);
- }
try {
Object application = getNSApplication();
Field critical = application.getClass().getField("UserAttentionRequestCritical");
Field informational = application.getClass().getField("UserAttentionRequestInformational");
- Field actual = type == REQUEST_USER_ATTENTION_TYPE_CRITICAL ? critical : informational;
-
+ Field actual = type == DefaultApplication.REQUEST_USER_ATTENTION_TYPE_CRITICAL ? critical : informational;
return ((Integer) application.getClass().getMethod("requestUserAttention", new Class[]{Integer.TYPE}).invoke(application, new Object[]{actual.get(null)})).intValue();
-
- } catch (ClassNotFoundException e) {
+ } catch (Exception e) {
return -1;
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- } catch (NoSuchFieldException e) {
- throw new RuntimeException(e);
}
}
+ @Override
public void cancelUserAttentionRequest(int request) {
try {
Object application = getNSApplication();
application.getClass().getMethod("cancelUserAttentionRequest", new Class[]{Integer.TYPE}).invoke(application, new Object[]{new Integer(request)});
- } catch (ClassNotFoundException e) {
- // Nada
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
+ } catch (Exception e) {
+ // handle the error
}
}
- private Object getNSApplication() throws ClassNotFoundException {
+ @Override
+ public void setApplicationIconImage(BufferedImage image) {
try {
- Class applicationClass = Class.forName("com.apple.cocoa.application.NSApplication");
- return applicationClass.getMethod("sharedApplication", new Class[0]).invoke(null, new Object[0]);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
+ callMethod(application, "setApplicationIconImage", new Class[]{BufferedImage.class}, new Object[]{image});
+ } catch (Exception e) {
+ // handle exception
}
}
- public void setApplicationIconImage(BufferedImage image) {
- if (isMac()) {
- try {
- Method setDockIconImage = application.getClass().getMethod("setDockIconImage", Image.class);
-
- try {
- setDockIconImage.invoke(application, image);
- } catch (IllegalAccessException e) {
-
- } catch (InvocationTargetException e) {
-
- }
- } catch (NoSuchMethodException mnfe) {
-
-
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- try {
- ImageIO.write(image, "png", stream);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- try {
- Class nsDataClass = Class.forName("com.apple.cocoa.foundation.NSData");
- Constructor constructor = nsDataClass.getConstructor(new Class[]{new byte[0].getClass()});
-
- Object nsData = constructor.newInstance(new Object[]{stream.toByteArray()});
+ @Override
+ public BufferedImage getApplicationIconImage() {
+ return callMethod("getApplicationIconImage");
+ }
- Class nsImageClass = Class.forName("com.apple.cocoa.application.NSImage");
- Object nsImage = nsImageClass.getConstructor(new Class[]{nsDataClass}).newInstance(new Object[]{nsData});
+ private Object getNSApplication() {
+ try {
+ Method method = Class.forName("com.apple.eawt.Application").getMethod("getApplication");
+ return method.invoke(null);
+ } catch (Exception e) {
+ return null;
+ }
+ }
- Object application = getNSApplication();
+ private Object callMethod(String methodName) {
+ try {
+ Method method = application.getClass().getMethod(methodName);
+ return method.invoke(application);
+ } catch (Exception e) {
+ return null;
+ }
+ }
- application.getClass().getMethod("setApplicationIconImage", new Class[]{nsImageClass}).invoke(application, new Object[]{nsImage});
+ private Object callMethod(Object target, String methodName, Class[] types, Object[] args) {
+ try {
+ Method method = target.getClass().getMethod(methodName, types);
+ return method.invoke(target, args);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+}
- } catch (ClassNotFoundException e) {
+// Default platform behavior for non-Mac platforms
+class DefaultPlatform extends ApplicationPlatform {
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- }
+ @Override
+ public boolean isMac() {
+ return false;
+ }
- }
+ @Override
+ public void addAboutMenuItem() {
+ // No-op for non-Mac
+ }
- }
+ @Override
+ public void addApplicationListener(ApplicationListener applicationListener) {
+ // No-op for non-Mac
}
- public BufferedImage getApplicationIconImage() {
- if (isMac()) {
+ @Override
+ public void addPreferencesMenuItem() {
+ // No-op for non-Mac
+ }
- try {
- Method getDockIconImage = application.getClass().getMethod("getDockIconImage");
- try {
- return (BufferedImage) getDockIconImage.invoke(application);
- } catch (IllegalAccessException e) {
+ @Override
+ public boolean getEnabledAboutMenu() {
+ return true; // default to true on non-Mac
+ }
- } catch (InvocationTargetException e) {
+ @Override
+ public boolean getEnabledPreferencesMenu() {
+ return false; // default to false on non-Mac
+ }
- }
- } catch (NoSuchMethodException nsme) {
-
- try {
- Class nsDataClass = Class.forName("com.apple.cocoa.foundation.NSData");
- Class nsImageClass = Class.forName("com.apple.cocoa.application.NSImage");
- Object application = getNSApplication();
- Object nsImage = application.getClass().getMethod("applicationIconImage", new Class[0]).invoke(application, new Object[0]);
-
- Object nsData = nsImageClass.getMethod("TIFFRepresentation", new Class[0]).invoke(nsImage, new Object[0]);
-
- Integer length = (Integer) nsDataClass.getMethod("length", new Class[0]).invoke(nsData, new Object[0]);
- byte[] bytes = (byte[]) nsDataClass.getMethod("bytes", new Class[]{Integer.TYPE, Integer.TYPE}).invoke(nsData, new Object[]{Integer.valueOf(0), length});
-
- BufferedImage image = ImageIO.read(new ByteArrayInputStream(bytes));
- return image;
-
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
+ @Override
+ public Point getMouseLocationOnScreen() {
+ return new Point(0, 0); // default value
+ }
- }
+ @Override
+ public boolean isAboutMenuItemPresent() {
+ return true; // default to true on non-Mac
+ }
- return null;
+ @Override
+ public boolean isPreferencesMenuItemPresent() {
+ return false; // default to false on non-Mac
}
- private Object callMethod(String methodname) {
- return callMethod(application, methodname, new Class[0], new Object[0]);
+ @Override
+ public void removeAboutMenuItem() {
+ // No-op for non-Mac
}
- private Object callMethod(Object object, String methodname) {
- return callMethod(object, methodname, new Class[0], new Object[0]);
+ @Override
+ public void removeApplicationListener(ApplicationListener applicationListener) {
+ // No-op for non-Mac
}
- private Object callMethod(Object object, String methodname, Class[] classes, Object[] arguments) {
- try {
- if (classes == null) {
- classes = new Class[arguments.length];
- for (int i = 0; i < classes.length; i++) {
- classes[i] = arguments[i].getClass();
+ @Override
+ public void removePreferencesMenuItem() {
+ // No-op for non-Mac
+ }
- }
- }
- Method addListnerMethod = object.getClass().getMethod(methodname, classes);
- return addListnerMethod.invoke(object, arguments);
- } catch (NoSuchMethodException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- } catch (InvocationTargetException e) {
- throw new RuntimeException(e);
- }
+ @Override
+ public void setEnabledAboutMenu(boolean enabled) {
+ // No-op for non-Mac
}
- class ApplicationListenerInvocationHandler implements InvocationHandler {
- private ApplicationListener applicationListener;
+ @Override
+ public void setEnabledPreferencesMenu(boolean enabled) {
+ // No-op for non-Mac
+ }
- ApplicationListenerInvocationHandler(ApplicationListener applicationListener) {
- this.applicationListener = applicationListener;
- }
+ @Override
+ public int requestUserAttention(int type) {
+ return -1; // No-op for non-Mac
+ }
- public Object invoke(Object object, Method appleMethod, Object[] objects) throws Throwable {
+ @Override
+ public void cancelUserAttentionRequest(int request) {
+ // No-op for non-Mac
+ }
- ApplicationEvent event = createApplicationEvent(objects[0]);
- try {
- Method method = applicationListener.getClass().getMethod(appleMethod.getName(), new Class[]{ApplicationEvent.class});
- return method.invoke(applicationListener, new Object[]{event});
- } catch (NoSuchMethodException e) {
- if (appleMethod.getName().equals("equals") && objects.length == 1) {
- return Boolean.valueOf(object == objects[0]);
- }
- return null;
- }
- }
+ @Override
+ public void setApplicationIconImage(BufferedImage image) {
+ // No-op for non-Mac
}
- private ApplicationEvent createApplicationEvent(final Object appleApplicationEvent) {
- return (ApplicationEvent) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{ApplicationEvent.class}, new InvocationHandler() {
- public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
- return appleApplicationEvent.getClass().getMethod(method.getName(), method.getParameterTypes()).invoke(appleApplicationEvent, objects);
- }
- });
+ @Override
+ public BufferedImage getApplicationIconImage() {
+ return null; // No-op for non-Mac
}
}