{
Desktop desktop;
- private static boolean headless;
+ private boolean headless;
- private static ArgParser argParser;
+ private ArgParser argParser;
private Map<String, AlignFrame> afMap;
- private static boolean commandArgsProvided = false;
+ private boolean commandArgsProvided = false;
- public static boolean commandArgsProvided()
+ private boolean argsWereParsed = false;
+
+ public Commands(ArgParser argparser, boolean headless)
{
- return commandArgsProvided;
+ this(Desktop.instance, argparser, headless);
}
- public static boolean processArgs(ArgParser ap, boolean h)
+ public Commands(Desktop d, ArgParser argparser, boolean h)
{
- argParser = ap;
+ argParser = argparser;
headless = h;
- boolean argsWereParsed = true;
- if (headless)
+ desktop = d;
+ afMap = new HashMap<String, AlignFrame>();
+ if (argparser != null)
{
- System.setProperty("java.awt.headless", "true");
+ processArgs(argparser, headless);
}
+ }
+
+ private boolean processArgs(ArgParser argparser, boolean h)
+ {
+ argParser = argparser;
+ headless = h;
+ boolean theseArgsWereParsed = false;
if (argParser != null && argParser.linkedIds() != null)
{
for (String id : argParser.linkedIds())
{
ArgValuesMap avm = argParser.linkedArgs(id);
- Commands cmds = new Commands();
+ theseArgsWereParsed = true;
if (id == null)
{
- cmds.processUnlinked(id);
- argsWereParsed &= cmds.wereParsed();
+ theseArgsWereParsed &= processUnlinked(id);
}
else
{
- cmds.processLinked(id);
- argsWereParsed &= cmds.wereParsed();
+ theseArgsWereParsed &= processLinked(id);
}
- cmds.processImages(id);
- argsWereParsed &= cmds.wereParsed();
+ theseArgsWereParsed &= processImages(id);
// close ap
if (avm.getBoolean(Arg.CLOSE))
{
- AlignFrame af = cmds.afMap.get(id);
+ AlignFrame af = afMap.get(id);
if (af != null)
{
af.closeMenuItem_actionPerformed(true);
return true;
}
// carry on with jalview.bin.Jalview
+ argsWereParsed = theseArgsWereParsed;
return argsWereParsed;
}
- boolean argsWereParsed = true; // set false as soon as an arg is found
-
- private boolean wereParsed()
+ public boolean commandArgsProvided()
{
- return argsWereParsed;
- }
-
- public Commands()
- {
- this(Desktop.instance);
+ return commandArgsProvided;
}
- public Commands(Desktop d)
+ public boolean argsWereParsed()
{
- this.desktop = d;
- afMap = new HashMap<String, AlignFrame>();
+ return argsWereParsed;
}
- protected void processUnlinked(String id)
+ protected boolean processUnlinked(String id)
{
- processLinked(id);
+ return processLinked(id);
}
- protected void processLinked(String id)
+ protected boolean processLinked(String id)
{
+ boolean theseArgsWereParsed = false;
ArgValuesMap avm = argParser.linkedArgs(id);
if (avm == null)
- return;
- else
- argsWereParsed = false;
+ return true;
/*
// script to execute after all loading is completed one way or another
if (openFile == null)
continue;
- argsWereParsed = true;
+ theseArgsWereParsed = true;
if (first)
{
first = false;
{
Console.debug(
"Opening '" + openFile + "' in existing alignment frame");
- af.getCurrentView().addFile(new File(openFile), format);
+ af.getCurrentView().addFile(new File(openFile), format, false);
}
Console.debug("Command " + Arg.OPEN + " executed successfully!");
Console.info("Changed colour " + acg.toString());
}
}
+
+ return theseArgsWereParsed;
}
- protected void processImages(String id)
+ protected boolean processImages(String id)
{
ArgValuesMap avm = argParser.linkedArgs(id);
AlignFrame af = afMap.get(id);
if (af == null)
{
Console.warn("Did not have an alignment window for id=" + id);
- return;
+ return false;
}
if (avm.containsArg(Arg.IMAGE))
}
}
}
+ return true;
}
private SequenceI getSpecifiedSequence(AlignFrame af, SubVals subId)
private Desktop desktop;
+ protected Commands cmds;
+
public static AlignFrame currentAlignFrame;
static
}
}
// Run Commands from cli
- boolean commandsSuccess = Commands.processArgs(argparser, headlessArg);
+ cmds = new Commands(argparser, headlessArg);
+ boolean commandsSuccess = cmds.argsWereParsed();
if (commandsSuccess)
{
Console.info("Successfully completed commands");
if (headlessArg)
+ {
+ System.out.println("#### EXITING");
System.exit(0);
+ }
}
else
{
if (!Platform.isJS() && !headless && file == null
&& Cache.getDefault("SHOW_STARTUP_FILE", true)
- && !Commands.commandArgsProvided())
+ && !cmds.commandArgsProvided())
// don't open the startup file if command line args have been processed
// (&& !Commands.commandArgsProvided())
/**
public void quit()
{
// System.exit will run the shutdownHook first
+ System.out.println("Quitting now. Bye!");
System.exit(0);
}
{
Jalview.currentAlignFrame = currentAlignFrame;
}
+
+ protected Commands getCommands()
+ {
+ return cmds;
+ }
}
if (Boolean.parseBoolean(System.getProperty("launcherstop", "false")))
{
+ System.out.println(
+ "System property 'launcherstop' is set and not 'false'. Exiting.");
System.exit(0);
}
try
viewStyle.setFontName(font.getName());
viewStyle.setFontStyle(font.getStyle());
viewStyle.setFontSize(font.getSize());
-
+
validCharWidth = true;
}
*/
public void addFile(File file, FileFormatI format)
{
+ addFile(file, format, true);
+ }
+
+ public void addFile(File file, FileFormatI format, boolean async)
+ {
DataSourceType protocol = AppletFormatAdapter.checkProtocol(file);
if (format == null)
}
}
- new FileLoader().LoadFile(this, file, DataSourceType.FILE, format);
+ new FileLoader().LoadFile(this, file, DataSourceType.FILE, format,
+ async);
}
public void addFile(File file)
// this will run the shutdownHook but QuitHandler.getQuitResponse() should
// not run a second time if gotQuitResponse flag has been set (i.e. user
// confirmed quit of some kind).
+ System.out.println("Desktop exiting.");
System.exit(0);
}
public void LoadFile(AlignViewport viewport, Object file,
DataSourceType protocol, FileFormatI format)
{
+ LoadFile(viewport, file, protocol, format, true);
+ }
+
+ public void LoadFile(AlignViewport viewport, Object file,
+ DataSourceType protocol, FileFormatI format, boolean async)
+ {
this.viewport = viewport;
if (file instanceof File)
{
this.selectedFile = (File) file;
file = selectedFile.getPath();
}
- LoadFile(file.toString(), protocol, format);
+ LoadFile(file.toString(), protocol, format, async);
}
public void LoadFile(String file, DataSourceType protocol,
FileFormatI format)
{
+ LoadFile(file, protocol, format, true);
+ }
+
+ public void LoadFile(String file, DataSourceType protocol,
+ FileFormatI format, boolean async)
+ {
this.file = file;
this.protocol = protocol;
this.format = format;
- final Thread loader = new Thread(this);
-
- SwingUtilities.invokeLater(new Runnable()
+ if (async)
{
- @Override
- public void run()
+ final Thread loader = new Thread(this);
+
+ SwingUtilities.invokeLater(new Runnable()
{
- loader.start();
- }
- });
+ @Override
+ public void run()
+ {
+ loader.start();
+ }
+ });
+ }
+ else
+ {
+ this.run();
+ }
}
/**
} catch (Exception e)
{
}
+ System.out.println("Window closing. Bye!");
System.exit(0);
}
import java.util.Date;
import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
}
+ @AfterMethod(alwaysRun = true)
+ public void tearDown()
+ {
+ Desktop.instance.closeAll_actionPerformed(null);
+ }
+
@Test(groups = "Functional", dataProvider = "cmdLines")
public void commandsOpenTest(String cmdLine, String sequence)
{
String[] args = cmdLine.split("\\s+");
Jalview.main(args);
- ArgParser argparser = new ArgParser(args);
- boolean commandsSuccess = Commands.processArgs(argparser, false);
- Assert.assertTrue(commandsSuccess, "Overall commandsSuccess is false");
+ Commands cmds = Jalview.getInstance().getCommands();
+ Assert.assertNotNull(cmds);
+ Assert.assertTrue(cmds.commandArgsProvided(),
+ "Commands were not provided in the args");
+ Assert.assertTrue(cmds.argsWereParsed(),
+ "Overall command parse and operation is false");
if (sequence != null)
{
- AlignFrame[] afs = Desktop.getAlignFrames();
- boolean found = false;
- ALIGNFRAME: for (AlignFrame af : afs)
+ Assert.assertTrue(lookForSequenceName(sequence),
+ "Sequence '" + sequence
+ + "' was not found in opened alignment files: "
+ + cmdLine);
+ }
+
+ System.out.println("##### GOT TO END");
+ }
+
+ public static boolean lookForSequenceName(String sequenceName)
+ {
+ AlignFrame[] afs = Desktop.getAlignFrames();
+ for (AlignFrame af : afs)
+ {
+ for (String name : af.getViewport().getAlignment().getSequenceNames())
{
- for (String name : af.getViewport().getAlignment()
- .getSequenceNames())
+ if (sequenceName.equals(name))
{
- if (sequence.equals(name))
- {
- found = true;
- break ALIGNFRAME;
- }
+ return true;
}
}
- Assert.assertTrue(found, "Sequence '" + sequence
- + "' was not found in opened alignment files: " + cmdLine);
}
+ return false;
}
@DataProvider(name = "cmdLines")
--open=test/jalview/bin/argparser/test1.fa
---open=test/jalview/bin/argparser/test2.fa
+--open=test/jalview/bin/argparser/test3.fa
--- /dev/null
+>TEST2
+AAARG