id 'application'
id 'eclipse'
id "com.diffplug.gradle.spotless" version "3.28.0"
- id 'com.github.johnrengelman.shadow' version '4.0.3'
+ id 'com.github.johnrengelman.shadow' version '7.1.2'
id 'com.install4j.gradle' version '10.0.3'
id 'com.dorongold.task-tree' version '2.1.1' // only needed to display task dependency tree with gradle task1 [task2 ...] taskTree
id 'com.palantir.git-version' version '0.13.0' apply false
showExceptions true
showCauses true
showStackTraces true
-
+ if (test_output) {
+ showStandardStreams true
+ }
info.events = [ TestLogEvent.FAILED ]
}
if (buildDist) {
dependsOn makeDist
}
- from ("${jalviewDir}/${libDistDir}") {
- include("*.jar")
- }
- manifest {
- attributes "Implementation-Version": JALVIEW_VERSION,
- "Application-Name": applicationName
+
+ def jarFiles = fileTree(dir: "${jalviewDir}/${libDistDir}", include: "*.jar", exclude: "regex.jar").getFiles()
+ def groovyJars = jarFiles.findAll {it1 -> file(it1).getName().startsWith("groovy-swing")}
+ def otherJars = jarFiles.findAll {it2 -> !file(it2).getName().startsWith("groovy-swing")}
+ from groovyJars
+ from otherJars
+
+ // we need to include the groovy-swing Include-Package for it to run in the shadowJar
+ doFirst {
+ def jarFileManifests = []
+ groovyJars.each { jarFile ->
+ def mf = zipTree(jarFile).getFiles().find { it.getName().equals("MANIFEST.MF") }
+ if (mf != null) {
+ jarFileManifests += mf
+ }
+ }
+
+ manifest {
+ attributes "Implementation-Version": JALVIEW_VERSION, "Application-Name": applicationName
+ from (jarFileManifests) {
+ eachEntry { details ->
+ if (!details.key.equals("Import-Package")) {
+ details.exclude()
+ }
+ }
+ }
+ }
}
duplicatesStrategy "INCLUDE"
You can run different defined groups of tests with
```bash
-gradle test -PtestngGroups=Network
+gradle test -Ptestng_groups=Network
```
Available groups include Functional (default), Network, External.
To exclude one or more groups of tests, add them as a comma separated list in testngExcludedGroups.
```bash
-gradle test -PtestngExcludedGroups=Not-bamboo
+gradle test -Ptestng_excluded_groups=Not-bamboo
```
+#### Viewing stdout and stderr for tests
+By default, gradle doesn't report any of the output or error streams produced by tests. You can enable output by setting the following:
+
+```bash
+gradle test -Ptest_output=1
+```
### Installer packaging with *install4j*
import jalview.datamodel.SequenceFeature
import jalview.gui.Desktop
-def af = jalview.bin.Jalview.currentAlignFrame
+def af = Jalview.getCurrentAlignFrame()
def av = af.viewport
def fr = Desktop.getAlignFrameFor(av.codingComplement).getFeatureRenderer()
def counts = 0
}
af.getFeatureRenderer().featuresAdded()
af.alignPanel.paintAlignment(true, true)
-println "Added " + countm + " missense and " + counts + " synonymous variants"
\ No newline at end of file
+println "Added " + countm + " missense and " + counts + " synonymous variants"
import jalview.gui.*;
import jalview.io.*;
-def class JvLoadTest {
+class JvLoadTest {
FileLoader fl = null;
def String safename = null;
JvLoadTest(String sname) {
System.gc();
jalview.gui.Desktop.instance.desktop.showMemoryUsage(true);
return new JvLoadTest(tempFile)
-}
\ No newline at end of file
+}
void printSimilarityMatrix(boolean selview=false, boolean includeids=true, SimilarityParams pidMethod) {
- def currentAlignFrame = jalview.bin.Jalview.getCurrentAlignFrame()
+ def currentAlignFrame = Jalview.getCurrentAlignFrame()
jalview.gui.AlignViewport av = currentAlignFrame.getCurrentView()
print "\n"
}
-}
\ No newline at end of file
+}
*/
// run an alignment on the current alignFrame
import jalview.ws.jws2.*;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
import jalview.datamodel.*;
// First get the JABA service discoverer and see if there are any services.
disc.run();
}
-for (jalview.ws.jws2.Jws2Discoverer.Jws2Instance service: disc.getServices()) {
+for (jalview.ws.jws2.jabaws2.Jws2Instance service: disc.getServices()) {
if (service.serviceType.indexOf("uscle")>-1) {
// now - go through the services if any, and find a Muscle service
import static java.awt.Toolkit.*
-def curviewport = Jalview.getAlignFrames()[Jalview.getAlignFrames().length-1].getViewport();
+def curviewport = Jalview.getCurrentAlignFrame().getViewport();
// TSV output by default.
// change "\t" to "," to output CSV file
/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
+ *
* This file is part of Jalview.
- *
+ *
* Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
+ * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see <http://www.gnu.org/licenses/>.
* The Jalview Authors are detailed in the 'AUTHORS' file.
import jalview.gui.AlignFrame;
import jalview.gui.AlignViewport;
-def af = Jalview.getAlignFrames();
-def al = af[0].viewport.alignment;
+def al = Jalview.getCurrentAlignFrame().viewport.alignment;
ParseProperties pp = new ParseProperties(al);
-pp.getScoresFromDescription("Score", "ScanPS Raw Score", "([-0-9.+]+)");
+pp.getScoresFromDescription("Score", "ScanPS Raw Score", "([-0-9.+]+)", true);
def sqs = al.getSequenceAt(0);
def annots = sqs.getAnnotation();
/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
+ *
* This file is part of Jalview.
- *
+ *
* Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
+ * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see <http://www.gnu.org/licenses/>.
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
// do something groovy in jalview
println "Hello World.\n"
-println "First sequence is " + currentAlFrame.viewport.alignment.getSequenceAt(0).getDisplayId(true)
+println "First sequence is " + Jalview.getCurrentAlignFrame().viewport.alignment.getSequenceAt(0).getDisplayId(true)
def alf = Jalview.getAlignFrames()
for (ala in alf)
{
- // ala is an jalview.gui.AlignFrame object
+ // ala is an jalview.gui.AlignFrame object
println ala.getTitle()
// get the parent jalview.datamodel.Alignment from the alignment viewport
def alignment = ala.viewport.alignment
// get the first sequence from the jalview.datamodel.Alignment object
- def seq = alignment.getSequenceAt(0)
+ def seq = alignment.getSequenceAt(0)
}
Jalview.quit()
import jalview.gui.AlignFrame;
import jalview.gui.AlignViewport;
import java.util.BitSet;
-import javax.swing.JOptionPane;
+import jalview.gui.JvOptionPane;
import groovy.swing.SwingBuilder;
def toselect = getFeatureInput(); // change this to select the desired feature type
cs.addElement(i);
}
ala.viewport.setColumnSelection(cs);
- ala.alignPanel.paintAlignment(true);
+ ala.alignPanel.paintAlignment(true, true);
ala.statusBar.setText("Marked "+bs.cardinality()+" columns containing features of type "+toselect)
} else {
ala.statusBar.setText("No features of type "+toselect+" found.");
null, 'Select columns by feature by type','Enter type of feature', JvOptionPane.OK_OPTION)
return response
- }
\ No newline at end of file
+ }
import java.awt.datatransfer.StringSelection
import static java.awt.Toolkit.*
-def curviewport = Jalview.getAlignFrames()[Jalview.getAlignFrames().length-1].getViewport()
+def curviewport = Jalview.getCurrentAlignFrame().getViewport()
def debug = false
for (ala in af)
{
- def al = ala.viewport.alignment;
+ def al = ala.getViewport().getAlignment();
if (al!=null)
{
SequenceI[] seqs = al.getSequencesArray();
}
}
}
+ ala.repaint();
}
-
\ No newline at end of file
+
/*
* Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
* Copyright (C) $$Year-Rel$$ The Jalview Authors
- *
+ *
* This file is part of Jalview.
- *
+ *
* Jalview is free software: you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
+ * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
- *
- * Jalview is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty
- * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with Jalview. If not, see <http://www.gnu.org/licenses/>.
* The Jalview Authors are detailed in the 'AUTHORS' file.
*/
-import jalview.bin.Jalview
import jalview.workers.FeatureSetCounterI
import jalview.workers.AlignmentAnnotationFactory
/*
* Demonstration of FeatureSetCounterI
- * compute annotation tracks counting number of displayed
+ * compute annotation tracks counting number of displayed
* features of each type in each column
*/
/*
* discover features on the current view
*/
-
-def featuresDisp=Jalview.currentAlignFrame.currentView.featuresDisplayed
+
+def featuresDisp=Jalview.getCurrentAlignFrame().currentView.featuresDisplayed
if (featuresDisp == null) {
print 'Need at least one feature visible on alignment'
}
assert 'java.util.ArrayList' == visibleFeatures.class.name
/*
- * A closure that returns an array of features present
+ * A closure that returns an array of features present
* for each feature type in visibleFeatures
- * Argument 'features' will be a list of SequenceFeature
+ * Argument 'features' will be a list of SequenceFeature
*/
-def getCounts =
- { features ->
+def getCounts =
+ { features ->
int[] obs = new int[visibleFeatures.size]
for (sf in features)
{
* or sf.getValue(attributeName) for GFF 'column 9' properties
*/
int pos = 0
- for (type in visibleFeatures)
+ for (type in visibleFeatures)
{
- if (type.equals(sf.type))
+ if (type.equals(sf.type))
{
obs[pos]++
}
}
obs
}
-
+
/*
* Define something that counts each visible feature type
*/
def columnSetCounter =
[
- getNames: { visibleFeatures as String[] },
+ getNames: { visibleFeatures as String[] },
getDescriptions: { visibleFeatures as String[] },
getMinColour: { [0, 255, 255] as int[] }, // cyan
getMaxColour: { [0, 0, 255] as int[] }, // blue
- count:
- { res, feats ->
- getCounts.call(feats)
+ count:
+ { res, feats ->
+ getCounts.call(feats)
}
] as FeatureSetCounterI
-1.8.3-1.3.0_FJVL
+1.8.3-1.3.1_FJVL
-1.8.3-1.3.0_JVL
+1.8.3-1.3.1_JVL
<parent>
<groupId>com.threerings.getdown</groupId>
<artifactId>getdown</artifactId>
- <version>1.8.3-1.3.0_FJVL</version>
+ <version>1.8.3-1.3.1_FJVL</version>
</parent>
<artifactId>getdown-ant</artifactId>
<parent>
<groupId>com.threerings.getdown</groupId>
<artifactId>getdown</artifactId>
- <version>1.8.3-1.3.0_FJVL</version>
+ <version>1.8.3-1.3.1_FJVL</version>
</parent>
<artifactId>getdown-core</artifactId>
String query = jalviewUri.getQuery();
_appargs.clear();
- _appargs.add("-open");
if (host != null && host.length() > 0) {
URL newUrl = new URL(
(https?"https":"http")
}
if (ext != null && LOCATOR_FILE_EXTENSION.equals(ext.toLowerCase(Locale.ROOT))) {
// this file extension should have been dealt with in Getdown class
- } else {
- _appargs.add(0, "-open");
}
}
<parent>
<groupId>com.threerings.getdown</groupId>
<artifactId>getdown</artifactId>
- <version>1.8.3-1.3.0_FJVL</version>
+ <version>1.8.3-1.3.1_FJVL</version>
</parent>
<artifactId>getdown-launcher</artifactId>
if [ x$JVLVERSION != x ]; then
export VERSION=$JVLVERSION
else
- export VERSION=1.8.3-1.3.0_JVL
+ export VERSION=1.8.3-1.3.1_JVL
fi
if [ x${VERSION%_JVL} = x$VERSION ]; then
<groupId>com.threerings.getdown</groupId>
<artifactId>getdown</artifactId>
<packaging>pom</packaging>
- <version>1.8.3-1.3.0_FJVL</version>
+ <version>1.8.3-1.3.1_FJVL</version>
<name>getdown</name>
<description>An application installer and updater.</description>
testng_groups = Functional
testng_excluded_groups =
+test_output =
+
j8libDir = j8lib
j11libDir = j11lib
</tr>
<tr valign="top">
+ <td><code>‑‑javaconsole / ‑‑nojavaconsole</code></td>
+ <td>Show (/ or don't show) the Java Console. Using one of these overrides any saved Preference.</td>
+ </tr>
+
+ <tr valign="top">
<td><code>‑‑questionnaire / ‑‑noquestionnaire</code></td>
<td>Show (/ or don't show) the questionnaire if one is available.</td>
</tr>
* The Jalview Authors are detailed in the 'AUTHORS' file.
-->
<head>
-<title>Groovy Shell</title>
+<title>Groovy Console</title>
</head>
<body>
<p>
- <strong>The Groovy Shell</strong>
+ <strong>The Groovy Console</strong>
</p>
<p>
Groovy (<a href="http://www.groovy-lang.org/">www.groovy-lang.org</a>)
short pause, you should then see the <a
href="https://groovy-lang.org/groovyconsole.html">Groovy
Console</a> appear. This allows you to interactively execute Groovy
- scripts whilst Jalview is running. We've also provided a <strong>Calculations→Execute
- Groovy Script</strong> button so you can execute the currently loaded
+ scripts whilst Jalview is running. We've also provided a <strong>Calculations→Run
+ Groovy Console Script</strong> button so you can execute the currently loaded
groovy script whilst viewing an alignment.
</p>
<p>
we recommend you also take a look at Jalview's source, since all the
public methods of the jalview class hierarchy can be called from
Groovy scripts. In addition, the following objects are also defined:
+ </p>
-
-
<ul>
- <li><strong>Jalview</strong> - this is bound to <code>jalview.bin.Jalview</code>.<br />Useful
- methods include:
+ <li><strong>Jalview</strong> - this is bound to <code>jalview.bin.groovy.JalviewObject</code> providing access to the following useful
+ methods:
<ul>
<li>Jalview.getAlignFrames() - returns a list of
jalview.gui.AlignFrame objects</li>
<li>Jalview.getCurrentAlignFrame() - returns the alignment
- window which is currently being looked at by the user</li>
+ window which has most recently been in focus. If you change focus to another alignment window then re-running <code>Jalview.getCurrentAlignFrame()</code> will return the new <code>AlignFrame</code>.</li>
</ul></li>
- <li><strong>currentAlFrame</strong> - this is only defined when
- running a Groovy script via the --groovy command line argument. It
- returns the first alignment window created after acting on the
- other arguments passed on the command line.</li>
+ <li><strong>currentAlFrame</strong> When used on the command line this refers to the current opened alignment.
+ <br/>
+ When used from the Groovy Console, it refers to the alignment that was in focus when the Groovy Console was opened.
+ <br/>
+ When a Groovy Console script is run from <em>Calculate</em>-><em>Run Groovy Console Script</em>, <code>currentAlFrame</code> us updated to that alignment.</li>
</ul>
<p>
+ If you specify a <code>--groovy</code> argument before an <code>--open</code> argument
+ then you should ensure your script doesn't refer to <code>currentAlFrame</code>.
+ <p>
+
+ <p>
<em>A simple script</em><br />
<ul>
<li>Getting the title, alignment and first sequence from the
current alignFrame<br> <pre>
-def alf = Jalview.getAlignFrames();
-print alf[0].getTitle();
-def alignment = alf[0].viewport.alignment;
+def al = Jalview.getCurrentAlignFrame();
+print al.getTitle();
+def alignment = al.viewport.alignment;
def seq = alignment.getSequenceAt(0);
</pre>
</li>
<li>Copy and paste it into the groovy script console</li>
<li>Load the example Feredoxin project (the one that opens by
default when you first launched Jalview)</li>
- <li>Select <strong>Calculations→Execute Groovy
+ <li>Select <strong>Calculations→Run Groovy Console
Script</strong> from the alignment window's menu bar to run the script on
the current view.
</li>
status.cancelled_image_export_operation = Cancelled {0} export operation
info.error_creating_file = Error creating {0} file
exception.outofmemory_loading_mmcif_file = Out of memory loading mmCIF File
-label.run_groovy = Run Groovy console script
-label.run_groovy_tip = Run the script in the Groovy console over this alignment
+label.run_groovy = Run Groovy Console Script
+label.run_groovy_tip = Run the script in the Groovy Console over this alignment
label.couldnt_run_groovy_script = Failed to run Groovy script
label.uniprot_sequence_fetcher = UniProt Sequence Fetcher
action.next_page= >>
import javax.swing.UIManager;
import jalview.analytics.Plausible;
+import jalview.bin.argparser.Arg;
+import jalview.bin.argparser.ArgParser;
import jalview.datamodel.PDBEntry;
import jalview.gui.Preferences;
import jalview.gui.UserDefinedColours;
}
if (file == null || !file.exists())
{
+ if (file != null)
+ {
+ jalview.bin.Console
+ .errPrintln("Could not load bootstrap preferences file '"
+ + file.getPath() + "'");
+ }
String channelPrefsFilename = ChannelProperties
.getProperty("preferences.filename");
String propertiesFilename = System.getProperty("user.home")
+ File.separatorChar + channelPrefsFilename;
+ jalview.bin.Console.errPrintln(
+ "Using default properties file '" + propertiesFilename + "'");
file = new File(propertiesFilename);
}
if (file == null || !file.exists())
+
{
String releasePrefsFilename = fallbackPropertiesFile;
String releasePropertiesFilename = System.getProperty("user.home")
+ File.separatorChar + releasePrefsFilename;
+ jalview.bin.Console.errPrintln("Falling back to properties file '"
+ + releasePropertiesFilename + "'");
file = new File(releasePropertiesFilename);
}
- if (filename == null)
- return null;
if (!file.exists())
{
jalview.bin.Console
.errPrintln("Could not load bootstrap preferences file '"
- + filename + "'");
+ + file.getPath() + "'");
return null;
}
{
return key == null ? null : sessionProperties.get(key);
}
+
+ public static boolean getArgCacheDefault(Arg a, String pref, boolean def)
+ {
+ ArgParser ap = Jalview.getInstance().getArgParser();
+ return ap.isSet(a) ? ap.getBoolean(a) : getDefault(pref, def);
+ }
}
// RESTORE SESSION AFTER EXPORT IF NEED BE
if (sessionToRestore != null)
{
- Console.debug("Restoring session from "
- + sessionToRestore);
-
- sview.getBinding().restoreSession(sessionToRestore.getAbsolutePath());
+ Console.debug(
+ "Restoring session from " + sessionToRestore);
+
+ sview.getBinding().restoreSession(
+ sessionToRestore.getAbsolutePath());
}
} catch (ImageOutputException ioexec)
continue;
} finally
{
- try {
+ try
+ {
this.colourAlignFrame(af, originalColourScheme);
} catch (Exception t)
{
- addError("Unexpected error when restoring colourscheme to alignment after temporary change for export.",t);
+ addError(
+ "Unexpected error when restoring colourscheme to alignment after temporary change for export.",
+ t);
}
}
}
ArgValuesMap avm = argParser.getLinkedArgs(id);
AlignFrame af = afMap.get(id);
- if (af == null)
+ if (avm != null && !avm.containsArg(Arg.GROOVY))
{
- addWarn("Did not have an alignment window for id=" + id);
+ // nothing to do
return;
}
+ if (af == null)
+ {
+ addWarn("Groovy script does not have an alignment window. Proceeding with caution!");
+ }
+
if (avm.containsArg(Arg.GROOVY))
{
- String groovyscript = avm.getValue(Arg.GROOVY);
- if (groovyscript != null)
+ for (ArgValue groovyAv : avm.getArgValueList(Arg.GROOVY))
{
- // Execute the groovy script after we've done all the rendering stuff
- // and before any images or figures are generated.
- Console.info("Executing script " + groovyscript);
- Jalview.getInstance().executeGroovyScript(groovyscript, af);
+ String groovyscript = groovyAv.getValue();
+ if (groovyscript != null)
+ {
+ // Execute the groovy script after we've done all the rendering stuff
+ // and before any images or figures are generated.
+ Console.info("Executing script " + groovyscript);
+ Jalview.getInstance().executeGroovyScript(groovyscript, af);
+ }
}
}
}
ArgValuesMap avm = argParser.getLinkedArgs(id);
AlignFrame af = afMap.get(id);
+ if (avm != null && !avm.containsArg(Arg.IMAGE))
+ {
+ // nothing to do
+ return true;
+ }
+
if (af == null)
{
- addWarn("Did not have an alignment window for id=" + id);
+ addWarn("Do not have an alignment window to create image from (id="
+ + id + "). Not proceeding.");
return false;
}
ArgValuesMap avm = argParser.getLinkedArgs(id);
AlignFrame af = afMap.get(id);
+ if (avm != null && !avm.containsArg(Arg.OUTPUT))
+ {
+ // nothing to do
+ return true;
+ }
+
if (af == null)
{
- addWarn("Did not have an alignment window for id=" + id);
+ addWarn("Do not have an alignment window (id=" + id
+ + "). Not proceeding.");
return false;
}
package jalview.bin;
import java.io.PrintStream;
-import java.util.Locale;
import jalview.log.JLogger;
-import jalview.log.JLoggerI;
import jalview.log.JLoggerI.LogLevel;
import jalview.log.JLoggerLog4j;
import jalview.util.ChannelProperties;
{
JLogger.LogLevel logLevel = JLogger.LogLevel.INFO;
- if (JLogger.isLevel(providedLogLevel))
+ if (providedLogLevel != null && JLogger.isLevel(providedLogLevel))
{
logLevel = Console.getLogLevel(providedLogLevel);
}
public static void setLogLevel(String logLevelString)
{
- for (LogLevel logLevel : JLoggerI.LogLevel.values())
+ LogLevel l = null;
+ try
+ {
+ l = LogLevel.valueOf(logLevelString);
+ } catch (IllegalArgumentException | NullPointerException e1)
+ {
+ Console.debug("Invalid log level '" + logLevelString + "'");
+ return;
+ }
+ if (l != null)
{
- if (logLevel.toString().toLowerCase(Locale.ROOT)
- .equals(logLevelString.toLowerCase(Locale.ROOT)))
+ log.setLevel(l);
+ if (!Platform.isJS())
{
- log.setLevel(logLevel);
- if (!Platform.isJS())
- {
- Log4j.init(logLevel);
- }
- JLoggerLog4j.getLogger("org.apache.axis", logLevel);
- break;
+ Log4j.init(l);
}
+ JLoggerLog4j.getLogger("org.apache.axis", l);
}
}
import jalview.bin.argparser.Arg.Type;
import jalview.bin.argparser.ArgParser;
import jalview.bin.argparser.BootstrapArgs;
+import jalview.bin.groovy.JalviewObject;
+import jalview.bin.groovy.JalviewObjectI;
import jalview.ext.so.SequenceOntology;
import jalview.gui.AlignFrame;
import jalview.gui.Desktop;
* @author $author$
* @version $Revision$
*/
-public class Jalview
+public class Jalview implements JalviewObjectI
{
static
{
protected Commands cmds;
- public static AlignFrame currentAlignFrame;
+ public AlignFrame currentAlignFrame = null;
private ArgParser argparser = null;
}
else if (bootstrapArgs.contains(Arg.DEBUG))
{
- logLevel = "DEBUG";
+ logLevel = bootstrapArgs.getBoolean(Arg.DEBUG) ? "DEBUG" : "INFO";
}
if (logLevel == null && !(bootstrapProperties == null))
{
try
{
Console.initLogger();
- } catch (
-
- NoClassDefFoundError error)
+ } catch (NoClassDefFoundError error)
{
error.printStackTrace();
String message = "\nEssential logging libraries not found."
+ "\nUse: java -classpath \"$PATH_TO_LIB$/*:$PATH_TO_CLASSES$\" jalview.bin.Jalview";
- Jalview.exit(message, ExitCode.OK);
+ Jalview.exit(message, ExitCode.NO_LOGGING);
}
desktop = null;
PromptUserConfig prompter = new PromptUserConfig(Desktop.desktop,
"USAGESTATS",
MessageManager.getString("prompt.analytics_title"),
- MessageManager.getString("prompt.analytics"),
- new Runnable()
+ MessageManager.getString("prompt.analytics"), new Runnable()
{
@Override
public void run()
}
try
{
+ JalviewObjectI j = new JalviewObject(this);
Map<String, java.lang.Object> vbinding = new HashMap<>();
- vbinding.put("Jalview", this);
- if (af != null)
- {
- vbinding.put("currentAlFrame", af);
- }
+ vbinding.put(JalviewObjectI.jalviewObjectName, j);
+ vbinding.put(JalviewObjectI.currentAlFrameName,
+ af != null ? af : getCurrentAlignFrame());
Binding gbinding = new Binding(vbinding);
GroovyScriptEngine gse = new GroovyScriptEngine(new URL[] { sfile });
gse.run(sfile.toString(), gbinding);
.errPrintln("Exception Whilst trying to execute file " + sfile
+ " as a groovy script.");
e.printStackTrace(System.err);
-
}
}
return false;
}
+ @Override
public AlignFrame[] getAlignFrames()
{
return desktop == null ? new AlignFrame[] { getCurrentAlignFrame() }
- : Desktop.getAlignFrames();
-
+ : Desktop.getDesktopAlignFrames();
}
/**
* jalview.bin.Jalview.quit() will just run the non-GUI shutdownHook and exit
*/
+ @Override
public void quit()
{
// System.exit will run the shutdownHook first
Jalview.exit("Quitting now. Bye!", ExitCode.OK);
}
- public static AlignFrame getCurrentAlignFrame()
+ @Override
+ public AlignFrame getCurrentAlignFrame()
{
- return Jalview.currentAlignFrame;
+ return currentAlignFrame;
}
- public static void setCurrentAlignFrame(AlignFrame currentAlignFrame)
+ public void setCurrentAlignFrame(AlignFrame af)
{
- Jalview.currentAlignFrame = currentAlignFrame;
+ this.currentAlignFrame = af;
}
public Commands getCommands()
// only add new ones to the end of the list (to preserve ordinal values)
OK, FILE_NOT_FOUND, FILE_NOT_READABLE, NO_FILES, INVALID_FORMAT,
INVALID_ARGUMENT, INVALID_VALUE, MIXED_CLI_ARGUMENTS,
- ERROR_RUNNING_COMMANDS;
+ ERROR_RUNNING_COMMANDS, NO_LOGGING, GROOVY_ERROR;
}
/******************************
j.getArgParser().getMixedExamples());
String quit = MessageManager.getString("action.quit");
- Desktop.instance.nonBlockingDialog(title, warning, quit,
- JvOptionPane.WARNING_MESSAGE, false, true);
+ Desktop.instance.nonBlockingDialog(title, warning, null, quit,
+ JvOptionPane.WARNING_MESSAGE, false, false, true, 30000);
Jalview.exit(
"Exiting due to mixed old and new command line arguments.",
{
String cont = MessageManager.getString("label.continue");
- Desktop.instance.nonBlockingDialog(32, 2, title, warning, url, cont,
- JvOptionPane.WARNING_MESSAGE, false, true, true);
+ Desktop.instance.nonBlockingDialog(title, warning, url, cont,
+ JvOptionPane.WARNING_MESSAGE, false, true, true, 30000);
}
}
if (j.getCommands() != null && j.getCommands().getErrors().size() > 0)
Math.max(message.length(), Math.min(60, shortest)),
Math.min(errors.size(), 20), title, message,
j.getCommands().errorsToString(), ok,
- JvOptionPane.WARNING_MESSAGE, true, false, true);
+ JvOptionPane.WARNING_MESSAGE, true, false, true, -1);
}
}
}
QUESTIONNAIRE(Type.CONFIG,
"Show (or don't show) the questionnaire if one is available.",
true, Opt.BOOLEAN, Opt.BOOTSTRAP),
+ JAVACONSOLE(Type.CONFIG, "Show (or don't show) the Java Console.", false,
+ Opt.BOOLEAN, Opt.BOOTSTRAP),
NOUSAGESTATS(Type.CONFIG, "Don't send initial launch usage stats.",
Opt.UNARY, Opt.BOOTSTRAP),
NOSTARTUPFILE(Type.CONFIG, "Don't show the default startup file.",
}
if (bsa != null)
+ {
this.bootstrapArgs = bsa;
+ }
else
+ {
this.bootstrapArgs = BootstrapArgs.getBootstrapArgs(args);
+ }
parse(args, initsubstitutions, allowPrivate);
}
}
}
}
+
+ // if in an argfile, remove it from the hashset so it can be re-used in
+ // another argfile
+ if (inArgFile != null)
+ {
+ argFiles.remove(inArgFile);
+ }
}
public boolean contains(Arg a)
--- /dev/null
+package jalview.bin.groovy;
+
+import jalview.bin.Jalview.ExitCode;
+import jalview.gui.AlignFrame;
+
+public class JalviewObject implements JalviewObjectI
+{
+ private JalviewObjectI object = null;
+
+ public JalviewObject(JalviewObjectI j)
+ {
+ this.object = j;
+ }
+
+ @Override
+ public AlignFrame[] getAlignFrames()
+ {
+ return object == null ? null : object.getAlignFrames();
+ }
+
+ @Override
+ public AlignFrame getCurrentAlignFrame()
+ {
+ return object == null ? null : object.getCurrentAlignFrame();
+ }
+
+ @Override
+ public void quit()
+ {
+ if (object != null)
+ {
+ object.quit();
+ }
+ else
+ {
+ jalview.bin.Jalview.exit(
+ "Groovy console quit without Jalview object.",
+ ExitCode.GROOVY_ERROR);
+ }
+ }
+
+}
--- /dev/null
+package jalview.bin.groovy;
+
+import jalview.gui.AlignFrame;
+
+public interface JalviewObjectI
+{
+ public AlignFrame[] getAlignFrames();
+
+ public AlignFrame getCurrentAlignFrame();
+
+ public final static String currentAlFrameName = "currentAlFrame";
+
+ public final static String jalviewObjectName = "Jalview";
+
+ public void quit();
+}
import jalview.bin.Cache;
import jalview.bin.Console;
import jalview.bin.Jalview;
+import jalview.bin.groovy.JalviewObjectI;
import jalview.commands.CommandI;
import jalview.commands.EditCommand;
import jalview.commands.EditCommand.Action;
@Override
public void focusGained(FocusEvent e)
{
- Jalview.setCurrentAlignFrame(AlignFrame.this);
+ Jalview.getInstance().setCurrentAlignFrame(AlignFrame.this);
}
});
@Override
protected void runGroovy_actionPerformed()
{
- Jalview.setCurrentAlignFrame(this);
- groovy.ui.Console console = Desktop.getGroovyConsole();
+ Jalview.getInstance().setCurrentAlignFrame(this);
+ groovy.console.ui.Console console = Desktop.getGroovyConsole();
if (console != null)
{
try
{
+ console.setVariable(JalviewObjectI.currentAlFrameName, this);
console.runScript();
} catch (Exception ex)
{
*/
protected boolean noReferencesTo(AlignedCodonFrame acf)
{
- AlignFrame[] frames = Desktop.getAlignFrames();
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
if (frames == null)
{
return true;
private JComboBox<LogLevel> logLevelCombo = new JComboBox<LogLevel>();
- protected LogLevel startingLogLevel = LogLevel.INFO;
+ protected LogLevel startingLogLevel = null;
public Console()
{
scrollPane.setBorder(noBorder);
textArea.addMouseListener(new MouseAdapter()
{
+ @Override
public void mouseClicked(MouseEvent e)
{
if (e.getButton() == MouseEvent.BUTTON1)
MessageManager.getString("label.copy_to_clipboard"));
copyToClipboardButton.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
copyConsoleTextToClipboard();
private Color fg = textArea.getForeground();
+ @Override
public void mousePressed(MouseEvent e)
{
textArea.setBackground(textArea.getSelectionColor());
textArea.setForeground(textArea.getSelectedTextColor());
}
+ @Override
public void mouseReleased(MouseEvent e)
{
textArea.setBackground(bg);
// logLevelCombo.addItem(LogLevel.ERROR);
// logLevelCombo.addItem(LogLevel.OFF);
// set startingLogLevel
- startingLogLevel = jalview.bin.Console.log == null ? LogLevel.INFO
- : jalview.bin.Console.log.getLevel();
+
+ if (jalview.bin.Console.getLogger() == null)
+ {
+ startingLogLevel = jalview.bin.Console.getCachedLogLevel();
+ }
+ else
+ {
+ startingLogLevel = jalview.bin.Console.getLogger().getLevel();
+ }
setChosenLogLevelCombo();
logLevelCombo.addActionListener(new ActionListener()
{
+ @Override
public void actionPerformed(ActionEvent e)
{
if (jalview.bin.Console.log != null)
boolean added = false;
for (int i = 0; i < logLevelCombo.getItemCount(); i++)
{
- LogLevel l = (LogLevel) logLevelCombo.getItemAt(i);
+ LogLevel l = logLevelCombo.getItemAt(i);
if (l.compareTo(setLogLevel) >= 0)
{
logLevelCombo.insertItemAt(setLogLevel, i);
*/
public Console(Desktop desktop)
{
- this(desktop, true);
- }
-
- /**
- * attach a console to the desktop - the desktop will open it if requested.
- *
- * @param desktop
- * @param showjconsole
- * - if true, then redirect stdout immediately
- */
- public Console(Desktop desktop, boolean showjconsole)
- {
parent = desktop;
// window name - get x,y,width, height possibly scaled
- Rectangle bounds = desktop.getLastKnownDimensions("JAVA_CONSOLE_");
- if (bounds == null)
+ Rectangle bounds = parent == null ? null
+ : parent.getLastKnownDimensions("JAVA_CONSOLE_");
+ if (bounds != null)
{
frame = initFrame(
ChannelProperties.getProperty("app_name") + " Java Console",
- desktop.getWidth() / 2, desktop.getHeight() / 4,
- desktop.getX(), desktop.getY());
+ bounds.width, bounds.height, bounds.x, bounds.y);
+ }
+ else if (parent != null && parent.getWidth() > 0
+ && parent.getHeight() > 0)
+ {
+ frame = initFrame(
+ ChannelProperties.getProperty("app_name") + " Java Console",
+ parent.getWidth() / 2, parent.getHeight() / 4, parent.getX(),
+ parent.getY());
}
else
{
frame = initFrame(
ChannelProperties.getProperty("app_name") + " Java Console",
- bounds.width, bounds.height, bounds.x, bounds.y);
+ MIN_WIDTH, MIN_HEIGHT, 10, 10);
}
frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
- // desktop.add(frame);
+ // parent.add(frame);
initConsole(false);
LogLevel level = (LogLevel) logLevelCombo.getSelectedItem();
if (!Platform.isJS())
pin.close();
} catch (Exception e)
{
+ jalview.bin.Console.debug("pin.close() error", e);
}
try
{
pin2.close();
} catch (Exception e)
{
+ jalview.bin.Console.debug("pin2.close() error", e);
}
try
{
textAppender.join(10);
} catch (Exception e)
{
+ jalview.bin.Console.debug("textAppender.join(10) error", e);
}
}
/*
try
{
this.wait(100);
-// if (pin.available() == 0)
-// {
-// trimBuffer(false);
-// }
} catch (InterruptedException ie)
{
+ jalview.bin.Console.debug("pin.available() error", ie);
}
}
{
try
{
- this.wait(100);
+ this.wait(100); // ##### implicated BLOCKED
if (pin2.available() == 0)
{
trimBuffer(false);
}
} catch (InterruptedException ie)
{
+ jalview.bin.Console.debug("pin.available() error", ie);
}
}
while (pin2.available() != 0)
textArea.append(replace.toString());
trimBuffer(false);
}
- });
+ });
}
if (displayPipe.length() == 0)
{
}
} catch (InterruptedException e)
{
+ jalview.bin.Console.debug("displayPipe.length() error", e);
}
}
}
this.wait(100);
} catch (InterruptedException e)
{
-
+ jalview.bin.Console.debug("this.wait(100) error", e);
}
}
if (quit)
this.wait(1000);
} catch (InterruptedException ie)
{
+ jalview.bin.Console.debug("this.wait(1000) error", ie);
}
throw new NullPointerException(
MessageManager.getString("exception.application_test_npe"));
+ "\nTruncated...\n";
} catch (Exception e)
{
- e.printStackTrace();
+ jalview.bin.Console.warn("textArea Exception", e);
}
}
// trim the buffer
}
} catch (Exception e)
{
- e.printStackTrace();
+ jalview.bin.Console.warn("textArea Exception", e);
}
// lines = textArea.getLineCount();
}
import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.bin.Jalview.ExitCode;
+import jalview.bin.argparser.Arg;
+import jalview.bin.groovy.JalviewObject;
+import jalview.bin.groovy.JalviewObjectI;
import jalview.datamodel.Alignment;
import jalview.datamodel.HiddenColumns;
import jalview.datamodel.Sequence;
*/
public class Desktop extends jalview.jbgui.GDesktop
implements DropTargetListener, ClipboardOwner, IProgressIndicator,
- jalview.api.StructureSelectionManagerProvider
+ jalview.api.StructureSelectionManagerProvider, JalviewObjectI
{
private static final String CITATION;
static
boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false);
- boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false);
+ boolean showjconsole = Cache.getArgCacheDefault(Arg.JAVACONSOLE,
+ "SHOW_JAVA_CONSOLE", false);
+
+ // start dialogue queue for single dialogues
+ startDialogQueue();
+
+ if (!Platform.isJS())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
+ {
+ Desktop.instance.acquireDialogQueue();
+
+ jconsole = new Console(this);
+ jconsole.setHeader(Cache.getVersionDetailsForConsole());
+ showConsole(showjconsole);
+
+ Desktop.instance.releaseDialogQueue();
+ }
+
desktop = new MyDesktopPane(selmemusage);
showMemusage.setSelected(selmemusage);
setBounds(xPos, yPos, 900, 650);
}
- // start dialogue queue for single dialogues
- startDialogQueue();
-
if (!Platform.isJS())
/**
* Java only
* @j2sIgnore
*/
{
- jconsole = new Console(this, showjconsole);
- jconsole.setHeader(Cache.getVersionDetailsForConsole());
- showConsole(showjconsole);
-
showNews.setVisible(false);
experimentalFeatures.setSelected(showExperimental());
iw = (int) (iw * sw);
iy = (int) (iy * sh);
ih = (int) (ih * sh);
- while (ix >= screenSize.width)
+ if (ix >= screenSize.width)
{
jalview.bin.Console.debug(
"Window geometry location recall error: shifting horizontal to within screenbounds.");
- ix -= screenSize.width;
+ ix = ix % screenSize.width;
}
- while (iy >= screenSize.height)
+ if (iy >= screenSize.height)
{
jalview.bin.Console.debug(
"Window geometry location recall error: shifting vertical to within screenbounds.");
- iy -= screenSize.height;
+ iy = iy % screenSize.height;
}
jalview.bin.Console.debug(
"Got last known dimensions for " + windowName + ": x:" + ix
{
if (itf instanceof AlignFrame)
{
- Jalview.setCurrentAlignFrame((AlignFrame) itf);
+ Jalview.getInstance().setCurrentAlignFrame((AlignFrame) itf);
}
itf.requestFocus();
}
desktopQuit(true, false);
}
- public QuitHandler.QResponse desktopQuit(boolean ui, boolean disposeFlag)
- {
- final Runnable doDesktopQuit = () -> {
- Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
- Cache.setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
- Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height + "");
- storeLastKnownDimensions("", new Rectangle(getBounds().x,
- getBounds().y, getWidth(), getHeight()));
+ /**
+ * close everything, stash window geometries, and shut down all associated threads/workers
+ * @param dispose - sets the dispose on close flag - JVM may terminate when set
+ * @param terminateJvm - quit with prejudice - stops the JVM.
+ */
+ public void quitTheDesktop(boolean dispose, boolean terminateJvm) {
+ Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
+ Cache.setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
+ Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height + "");
+ storeLastKnownDimensions("", new Rectangle(getBounds().x,
+ getBounds().y, getWidth(), getHeight()));
- if (jconsole != null)
- {
- storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
- jconsole.stopConsole();
- }
+ if (jconsole != null)
+ {
+ storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
+ jconsole.stopConsole();
+ }
- if (jvnews != null)
- {
- storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
- }
+ if (jvnews != null)
+ {
+ storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
+ }
- // Frames should all close automatically. Keeping external
- // viewers open should already be decided by user.
- closeAll_actionPerformed(null);
+ // Frames should all close automatically. Keeping external
+ // viewers open should already be decided by user.
+ closeAll_actionPerformed(null);
- // check for aborted quit
- if (QuitHandler.quitCancelled())
- {
- jalview.bin.Console.debug("Desktop aborting quit");
- return;
- }
+ if (dialogExecutor != null)
+ {
+ dialogExecutor.shutdownNow();
+ }
- if (dialogExecutor != null)
- {
- dialogExecutor.shutdownNow();
- }
+ if (groovyConsole != null)
+ {
+ // suppress a possible repeat prompt to save script
+ groovyConsole.setDirty(false);
+ groovyConsole.exit();
+ }
- if (groovyConsole != null)
- {
- // suppress a possible repeat prompt to save script
- groovyConsole.setDirty(false);
- groovyConsole.exit();
- }
+ if (terminateJvm)
+ {
+ // note that shutdown hook will not be run
+ jalview.bin.Console.debug("Force Quit selected by user");
+ Runtime.getRuntime().halt(0);
+ }
- if (QuitHandler.gotQuitResponse() == QResponse.FORCE_QUIT)
- {
- // note that shutdown hook will not be run
- jalview.bin.Console.debug("Force Quit selected by user");
- Runtime.getRuntime().halt(0);
- }
+ jalview.bin.Console.debug("Quit selected by user");
+ if (dispose)
+ {
+ instance.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
+ // instance.dispose();
+ }
+ }
+ public QuitHandler.QResponse desktopQuit(boolean ui, boolean disposeFlag)
+ {
+ final Runnable doDesktopQuit = () -> {
- jalview.bin.Console.debug("Quit selected by user");
- if (disposeFlag)
+ // FIRST !! check for aborted quit
+ if (QuitHandler.quitCancelled())
{
- instance.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
- // instance.dispose();
+ jalview.bin.Console.debug("Quit was cancelled - Desktop aborting quit");
+ return;
}
+
+ // Proceed with quitting
+ quitTheDesktop(disposeFlag, QuitHandler.gotQuitResponse() == QResponse.FORCE_QUIT);
+ // and exit the JVM
instance.quit();
};
}
/**
- * Don't call this directly, use desktopQuit() above. Exits the program.
+ * Exits the program and the JVM.
+ *
+ * Don't call this directly
+ *
+ * - use desktopQuit() above to tidy up first.
+ *
+ * - use closeDesktop() to shutdown Jalview without shutting down the JVM
+ *
*/
@Override
public void quit()
{
}
}
- Jalview.setCurrentAlignFrame(null);
+ Jalview.getInstance().setCurrentAlignFrame(null);
jalview.bin.Console.info("ALL CLOSED");
/*
return null;
}
List<AlignmentPanel> aps = new ArrayList<>();
- AlignFrame[] frames = getAlignFrames();
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
if (frames == null)
{
return null;
List<AlignmentViewport> viewp = new ArrayList<>();
if (desktop != null)
{
- AlignFrame[] frames = Desktop.getAlignFrames();
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
for (AlignFrame afr : frames)
{
*
* @return an array of AlignFrame, or null if none found
*/
- public static AlignFrame[] getAlignFrames()
+ @Override
+ public AlignFrame[] getAlignFrames()
{
- if (Jalview.isHeadlessMode())
+ if (desktop == null)
{
- // Desktop.desktop is null in headless mode
- return new AlignFrame[] { Jalview.currentAlignFrame };
+ return null;
}
JInternalFrame[] frames = Desktop.desktop.getAllFrames();
}
/**
+ * static version
+ */
+ public static AlignFrame[] getDesktopAlignFrames()
+ {
+ if (Jalview.isHeadlessMode())
+ {
+ // Desktop.desktop is null in headless mode
+ return Jalview.getInstance().getAlignFrames();
+ }
+
+ if (instance != null && desktop != null)
+ {
+ return instance.getAlignFrames();
+ }
+
+ return null;
+ }
+
+ /**
* Returns an array of any AppJmol frames in the Desktop (or null if none).
*
* @return
openGroovyConsole();
} catch (Exception ex)
{
- jalview.bin.Console.error("Groovy Shell Creation failed.", ex);
+ jalview.bin.Console.error("Groovy Console creation failed.", ex);
JvOptionPane.showInternalMessageDialog(Desktop.desktop,
MessageManager.getString("label.couldnt_create_groovy_shell"),
{
if (groovyConsole == null)
{
- groovyConsole = new groovy.ui.Console();
- groovyConsole.setVariable("Jalview", this);
+ JalviewObjectI j = new JalviewObject(this);
+ groovyConsole = new groovy.console.ui.Console();
+ groovyConsole.setVariable(JalviewObjectI.jalviewObjectName, j);
+ groovyConsole.setVariable(JalviewObjectI.currentAlFrameName,
+ getCurrentAlignFrame());
groovyConsole.run();
/*
*/
groovyShell.setEnabled(!enabled);
- AlignFrame[] alignFrames = getAlignFrames();
+ AlignFrame[] alignFrames = getDesktopAlignFrames();
if (alignFrames != null)
{
for (AlignFrame af : alignFrames)
*/
private Semaphore block = new Semaphore(0);
- private static groovy.ui.Console groovyConsole;
+ private static groovy.console.ui.Console groovyConsole;
/**
* add another dialog thread to the queue
myTopFrame.setDisplayedView(myTopFrame.alignPanel);
}
- public static groovy.ui.Console getGroovyConsole()
+ public static groovy.console.ui.Console getGroovyConsole()
{
return groovyConsole;
}
}
/**
- * closes the current instance window, disposes and forgets about it.
+ * closes the current instance window, but leaves the JVM running.
+ * Bypasses any shutdown prompts, but does not set window dispose on close in case JVM terminates.
*/
public static void closeDesktop()
{
if (Desktop.instance != null)
{
- Desktop.instance.closeAll_actionPerformed(null);
- Desktop.instance.setVisible(false);
Desktop us = Desktop.instance;
- Desktop.instance = null;
+ Desktop.instance.quitTheDesktop(false, false);
// call dispose in a separate thread - try to avoid indirect deadlocks
- new Thread(new Runnable()
+ if (us != null)
{
- @Override
- public void run()
+ new Thread(new Runnable()
{
- ExecutorService dex = us.dialogExecutor;
- if (dex != null)
+ @Override
+ public void run()
{
- dex.shutdownNow();
- us.dialogExecutor = null;
- us.block.drainPermits();
+ ExecutorService dex = us.dialogExecutor;
+ if (dex != null)
+ {
+ dex.shutdownNow();
+ us.dialogExecutor = null;
+ us.block.drainPermits();
+ }
+ us.dispose();
}
- us.dispose();
- }
- }).start();
+ }).start();
+ }
}
}
public void nonBlockingDialog(String title, String message, String button,
int type, boolean scrollable, boolean modal)
{
- nonBlockingDialog(32, 2, title, message, null, button, type, scrollable,
- false, modal);
+ nonBlockingDialog(title, message, null, button, type, scrollable, false,
+ modal, -1);
+ }
+
+ public void nonBlockingDialog(String title, String message,
+ String boxtext, String button, int type, boolean scrollable,
+ boolean html, boolean modal, int timeout)
+ {
+ nonBlockingDialog(32, 2, title, message, boxtext, button, type,
+ scrollable, html, modal, timeout);
}
public void nonBlockingDialog(int width, int height, String title,
String message, String boxtext, String button, int type,
- boolean scrollable, boolean html, boolean modal)
+ boolean scrollable, boolean html, boolean modal, int timeout)
{
if (type < 0)
{
jvp.setResponseHandler(JOptionPane.YES_OPTION, () -> {
});
+ jvp.setTimeout(timeout);
+ JButton jb = new JButton(button);
jvp.showDialogOnTopAsync(this, jp, title, JOptionPane.YES_OPTION, type,
null, new Object[]
- { button }, button, modal, null, false);
+ { button }, button, modal, new JButton[] { jb }, false);
}
+ @Override
+ public AlignFrame getCurrentAlignFrame()
+ {
+ return Jalview.getInstance().getCurrentAlignFrame();
+ }
}
{
FeatureMatcherSetI theFilter = (FeatureMatcherSetI) filter;
setOpaque(true);
- String asText = theFilter.toString();
setBackground(tbl.getBackground());
- this.setText(asText);
this.setIcon(null);
+ if (theFilter != null)
+ {
+ String asText = theFilter.toString();
+ this.setText(asText);
+ }
+
if (isSelected)
{
if (selectedBorder == null)
private Map<Object, Runnable> callbacks = new HashMap<>();
+ private int timeout = -1;
+
+ public void setTimeout(int i)
+ {
+ timeout = i;
+ }
+
/*
* JalviewJS reports user choice in the dialog as the selected option (text);
* this list allows conversion to index (int)
"Supplied buttons array not the same length as supplied options array.");
break NOTNULL;
}
+
+ // run through buttons for initialValue first so we can set (and start)
+ // a final timeoutThreadF to include (and interrupt) in the button
+ // actions
+ Thread timeoutThread = null;
+ for (int i = 0; i < options.length; i++)
+ {
+ Object o = options[i];
+ JButton jb = buttons[i];
+ if (o.equals(initialValue))
+ {
+ if (timeout > 0 && jb != null && jb instanceof JButton)
+ {
+ // after timeout ms click the default button
+ timeoutThread = new Thread(() -> {
+ try
+ {
+ Thread.sleep(timeout);
+ } catch (InterruptedException e)
+ {
+ Console.debug(
+ "Dialog timeout interrupted. Probably a button pressed.");
+ }
+ jb.doClick();
+ });
+ }
+ initialValueButton = jb;
+ break;
+ }
+ }
+ final Thread timeoutThreadF = timeoutThread;
+ if (timeoutThreadF != null)
+ {
+ timeoutThreadF.start();
+ }
+
int[] buttonActions = { JOptionPane.YES_OPTION,
JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION };
for (int i = 0; i < options.length; i++)
"Setting button " + i + " to '" + o.toString() + "'");
JButton jb = buttons[i];
- if (o.equals(initialValue))
- initialValueButton = jb;
-
int buttonAction = buttonActions[i];
Runnable action = callbacks.get(buttonAction);
jb.setText((String) o);
@Override
public void actionPerformed(ActionEvent e)
{
+ if (timeoutThreadF != null)
+ {
+ timeoutThreadF.interrupt();
+ }
Object obj = e.getSource();
if (obj == null || !(obj instanceof Component))
// A better hack which works is to create a new JFrame parent with
// setAlwaysOnTop(true)
+ boolean parentOnTop = dialogParent.isAlwaysOnTop();
dialogParent.setAlwaysOnTop(true);
parentComponent = dialogParent;
JOPTIONPANE_MESSAGETYPE, icon, options, initialValue, modal,
buttons);
+ dialogParent.setAlwaysOnTop(parentOnTop);
+
if (dispose)
{
dialogParent.setAlwaysOnTop(false);
return QResponse.QUIT;
int size = 0;
- AlignFrame[] afArray = Desktop.getAlignFrames();
+ AlignFrame[] afArray = Desktop.getDesktopAlignFrames();
if (!(afArray == null || afArray.length == 0))
{
for (int i = 0; i < afArray.length; i++)
try
{
- iframe.setClosed(true);
+ iframe.setClosed(true); // ##### implicated BLOCKED
} catch (Exception ex)
{
}
*/
protected void updateWebServiceMenus()
{
- for (AlignFrame alignFrame : Desktop.getAlignFrames())
+ for (AlignFrame alignFrame : Desktop.getDesktopAlignFrames())
{
alignFrame.BuildWebServiceMenu();
}
{
return this != FILE;
}
+
+ public boolean isUrl()
+ {
+ return this == URL || this == RELATIVE_URL;
+ }
}
// We read the data anyway - it might make sense.
}
// BH 2018 switch to File object here instead of filename
- alignFrame = new Jalview2XML(raiseGUI && !Jalview.isBatchMode()).loadJalviewAlign(
- selectedFile == null ? file : selectedFile);
+ alignFrame = new Jalview2XML(raiseGUI && !Jalview.isBatchMode())
+ .loadJalviewAlign(
+ selectedFile == null ? file : selectedFile);
}
else
{
} catch (Exception er)
{
- jalview.bin.Console.errPrintln("Exception whilst opening file '" + file);
+ jalview.bin.Console
+ .errPrintln("Exception whilst opening file '" + file);
er.printStackTrace();
if (raiseGUI && !Jalview.isBatchMode())
{
}
});
}
- jalview.bin.Console.errPrintln("Out of memory loading file " + file + "!!");
+ jalview.bin.Console
+ .errPrintln("Out of memory loading file " + file + "!!");
}
loadtime += System.currentTimeMillis();
AlignViewport avp = af.getViewport();
if (avp == null)
return;
- avp.setSavedUpToDate(!protocol.isDynamic(),
- QuitHandler.Message.UNSAVED_ALIGNMENTS);
+ boolean upToDate = !protocol.isDynamic();
+ if (protocol.isUrl() && !Cache
+ .getDefault(PROMPT_SAVE_UNCHANGED_URL_ALIGNMENTS, true))
+ {
+ upToDate = true;
+ }
+ avp.setSavedUpToDate(upToDate,
+ upToDate ? null : QuitHandler.Message.UNSAVED_ALIGNMENTS);
}
+ public static final String PROMPT_SAVE_UNCHANGED_URL_ALIGNMENTS = "PROMPT_SAVE_UNCHANGED_URL_ALIGNMENTS";
+
public static boolean getUseDefaultFileFormat()
{
return useDefaultFileFormat;
private static final int MAX_REFS_PER_SOURCE = 4;
- private static final int MAX_SOURCES = 40;
+ private static final int MAX_SOURCES = 5;
private static String linkImageURL;
{
return 1;
}
+
String s1 = ref1.getSource();
String s2 = ref2.getSource();
boolean s1Primary = DBRefSource.isPrimarySource(s1);
boolean s2Primary = DBRefSource.isPrimarySource(s2);
+ if (ref1.isCanonical() && !ref2.isCanonical())
+ {
+ return -1;
+ }
+ if (!ref1.isCanonical() && ref2.isCanonical())
+ {
+ return 1;
+ }
if (s1Primary && !s2Primary)
{
return -1;
private void buildSkipList()
{
skipList = new Hashtable();
- AlignFrame[] al = Desktop.getAlignFrames();
+ AlignFrame[] al = Desktop.getDesktopAlignFrames();
for (int f = 0; al != null && f < al.length; f++)
{
skipList.put(al[f].getViewport().getSequenceSetId(), al[f]);
*/
public void saveState(JarOutputStream jout)
{
- AlignFrame[] frames = Desktop.getAlignFrames();
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
setStateSavedUpToDate(true);
if (stateSavedUpToDate()) // nothing happened since last project save
return true;
- AlignFrame[] frames = Desktop.getAlignFrames();
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
if (frames != null)
{
for (int i = 0; i < frames.length; i++)
*/
package jalview.workers;
+import java.awt.Color;
+
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
import jalview.bin.Jalview;
import jalview.datamodel.Annotation;
import jalview.gui.AlignFrame;
-import java.awt.Color;
-
/**
* Factory class with methods which allow clients (including external scripts
* such as Groovy) to 'register and forget' an alignment annotation calculator.
*/
public static void newCalculator(FeatureSetCounterI counter)
{
- AlignmentViewPanel currentAlignFrame = Jalview
+ AlignmentViewPanel currentAlignFrame = Jalview.getInstance()
.getCurrentAlignFrame().alignPanel;
if (currentAlignFrame == null)
{
{
// TODO need an interface for AlignFrame by which to access
// its AlignViewportI and AlignmentViewPanel
- AlignFrame currentAlignFrame = Jalview.getCurrentAlignFrame();
+ AlignFrame currentAlignFrame = Jalview.getInstance()
+ .getCurrentAlignFrame();
if (currentAlignFrame != null)
{
new AnnotationWorker(currentAlignFrame.getViewport(),
Assert.assertEquals(cmds.argsWereParsed(), cmdArgs,
"Overall command parse and operation is false");
- Assert.assertEquals(Desktop.getAlignFrames().length, numFrames,
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length, numFrames,
"Wrong number of AlignFrames");
if (sequences != null)
{
Set<String> openedSequenceNames = new HashSet<>();
- AlignFrame[] afs = Desktop.getAlignFrames();
+ AlignFrame[] afs = Desktop.getDesktopAlignFrames();
for (AlignFrame af : afs)
{
openedSequenceNames.addAll(
public static boolean lookForSequenceName(String sequenceName)
{
- AlignFrame[] afs = Desktop.getAlignFrames();
+ AlignFrame[] afs = Desktop.getDesktopAlignFrames();
for (AlignFrame af : afs)
{
for (String name : af.getViewport().getAlignment().getSequenceNames())
}
;
- AlignFrame[] afs = Desktop.getAlignFrames();
+ AlignFrame[] afs = Desktop.getDesktopAlignFrames();
Assert.assertNotNull(afs);
Assert.assertTrue(afs.length > 0);
{
Assert.fail("Unexpected exception " + x);
}
- AlignFrame[] alfs = Desktop.getAlignFrames();
+ AlignFrame[] alfs = Desktop.getDesktopAlignFrames();
Assert.assertEquals("Expect just 2 alignment frames", 2, alfs.length);
// internal paste should yield a new alignment window with shared dataset
AlignmentI dataset = internalSource.getViewport().getAlignment()
SequenceFetcher sf = new SequenceFetcher(Desktop.instance,
forSource, forAccession);
sf.run();
- AlignFrame[] afs = Desktop.getAlignFrames();
+ AlignFrame[] afs = Desktop.getDesktopAlignFrames();
if (afs.length == 0)
{
failedDBRetr.add("Didn't retrieve " + first);
assertTrue(report.startsWith("<i>\n" + "<br/>\n" + "UNIPROT P30410,\n"
+ " P30411,\n" + " P30412,\n" + " P30413,...<br/>\n"
+ "PDB0 3iu1<br/>\n" + "PDB1 3iu1<br/>"));
- assertTrue(report.endsWith("PDB5 3iu1<br/>\n" + "PDB6 3iu1<br/>\n"
- + "PDB7 3iu1<br/>\n" + "PDB8,...<br/>\n"
+ assertTrue(report.endsWith("PDB3 3iu1<br/>\n"+"PDB4,...<br/>\n"
+ "(Output Sequence Details to list all database references)\n"
+ "</i>"));
}
cacheBox.addItem(testInput);
cacheBox.setSelectedItem(testInput);
cacheBox.updateCache();
-
- try
+ boolean done[]=new boolean[] { false };
+ // this event gets processed after updateCache's update event on the swing
+ // thread
+ SwingUtilities.invokeLater(() -> {
+ done[0]=true;
+ });
+ long t=0;
+ while (!done[0] && t<200)
{
- // fix for JAL-4153
- // This delay is to let cacheBox.updateCache() finish updating the cache
- SwingUtilities.invokeAndWait(() -> {
- try
- {
- Thread.sleep(1);
+ try {
+ Thread.sleep(7);
+ t++;
} catch (InterruptedException e)
{
e.printStackTrace();
}
- });
- } catch (InvocationTargetException | InterruptedException e)
+ }
+ if (!done[0])
{
- e.printStackTrace();
+ Assert.fail("Giving up after 1.4s waiting for cache to be updated.");
}
+
LinkedHashSet<String> foundCache = appCache
.getAllCachedItemsFor(TEST_CACHE_KEY);
Assert.assertTrue(foundCache.contains(testInput));
@Test(groups = { "Functional" })
public void gatherViewsHere() throws Exception
{
- int origCount = Desktop.getAlignFrames() == null ? 0
- : Desktop.getAlignFrames().length;
+ int origCount = Desktop.getDesktopAlignFrames() == null ? 0
+ : Desktop.getDesktopAlignFrames().length;
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/exampleFile_2_7.jar", DataSourceType.FILE);
assertNotNull(af, "Didn't read in the example file correctly.");
- assertTrue(Desktop.getAlignFrames().length == 1 + origCount,
+ assertTrue(Desktop.getDesktopAlignFrames().length == 1 + origCount,
"Didn't gather the views in the example file.");
}
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
"examples/exampleFile_2_7.jar", DataSourceType.FILE);
- Assert.assertEquals(Desktop.getAlignFrames().length, 1);
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 1);
String afid = af.getViewport().getSequenceSetId();
// check FileLoader returned a reference to the one alignFrame that is
Desktop.explodeViews(af);
- int oldviews = Desktop.getAlignFrames().length;
- Assert.assertEquals(Desktop.getAlignFrames().length,
+ int oldviews = Desktop.getDesktopAlignFrames().length;
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length,
Desktop.getAlignmentPanels(afid).length);
File tfile = File.createTempFile("testStoreAndRecoverExpanded", ".jvp");
try
Assert.fail("Didn't save the expanded view state", e);
}
Desktop.instance.closeAll_actionPerformed(null);
- if (Desktop.getAlignFrames() != null)
+ if (Desktop.getDesktopAlignFrames() != null)
{
- Assert.assertEquals(Desktop.getAlignFrames().length, 0);
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
}
af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
DataSourceType.FILE);
Assert.assertNotNull(af);
- Assert.assertEquals(Desktop.getAlignFrames().length,
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length,
Desktop.getAlignmentPanels(
af.getViewport().getSequenceSetId()).length);
Assert.assertEquals(Desktop
Assert.fail("Didn't save the expanded view state", e);
}
Desktop.instance.closeAll_actionPerformed(null);
- if (Desktop.getAlignFrames() != null)
+ if (Desktop.getDesktopAlignFrames() != null)
{
- Assert.assertEquals(Desktop.getAlignFrames().length, 0);
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
}
af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
Assert.fail("Didn't save the expanded view state", e);
}
Desktop.instance.closeAll_actionPerformed(null);
- if (Desktop.getAlignFrames() != null)
+ if (Desktop.getDesktopAlignFrames() != null)
{
- Assert.assertEquals(Desktop.getAlignFrames().length, 0);
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
}
af = new FileLoader().LoadFileWaitTillLoaded(tfile.getAbsolutePath(),
Assert.fail("Didn't save the state", e);
}
Desktop.instance.closeAll_actionPerformed(null);
- if (Desktop.getAlignFrames() != null)
+ if (Desktop.getDesktopAlignFrames() != null)
{
- Assert.assertEquals(Desktop.getAlignFrames().length, 0);
+ Assert.assertEquals(Desktop.getDesktopAlignFrames().length, 0);
}
AlignFrame restoredFrame = new FileLoader().LoadFileWaitTillLoaded(
assertNotNull(af);
AlignmentI ds = null;
- for (AlignFrame alignFrame : Desktop.getAlignFrames())
+ for (AlignFrame alignFrame : Desktop.getDesktopAlignFrames())
{
if (ds == null)
{
/*
* find the complement frames (ugly)
*/
- AlignFrame[] frames = Desktop.getAlignFrames();
+ AlignFrame[] frames = Desktop.getDesktopAlignFrames();
assertEquals(frames.length, 2);
AlignViewport av1 = frames[0].getViewport();
AlignViewport av2 = frames[1].getViewport();