import jalview.api.AlignmentViewPanel;
import jalview.bin.Cache;
import jalview.bin.Jalview;
+import jalview.io.DataSourceType;
+import jalview.io.FileFormat;
+import jalview.io.FileFormatException;
+import jalview.io.FileFormatI;
import jalview.io.FileLoader;
-import jalview.io.FormatAdapter;
import jalview.io.IdentifyFile;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
+import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
+import javax.swing.AbstractAction;
import javax.swing.DefaultDesktopManager;
import javax.swing.DesktopManager;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JProgressBar;
+import javax.swing.KeyStroke;
import javax.swing.SwingUtilities;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkEvent.EventType;
public void run()
{
Cache.log.debug("Filechooser init thread started.");
- new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
- jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
- jalview.io.AppletFormatAdapter.READABLE_FNAMES,
- jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
+ FileFormat fileFormat = FileFormat.valueOf(Cache
+ .getProperty("DEFAULT_FILE_FORMAT"));
+ new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
+ // jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
+ // jalview.io.AppletFormatAdapter.READABLE_FNAMES,
+ fileFormat);
Cache.log.debug("Filechooser init thread finished.");
}
}).start();
String file = (String) contents
.getTransferData(DataFlavor.stringFlavor);
- String format = new IdentifyFile().identify(file,
- FormatAdapter.PASTE);
+ FileFormatI format = new IdentifyFile().identify(file,
+ DataSourceType.PASTE);
- new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
+ new FileLoader().LoadFile(file, DataSourceType.PASTE, format);
}
} catch (Exception ex)
{
boolean success = true;
Transferable t = evt.getTransferable();
- java.util.List<String> files = new ArrayList<String>();
- java.util.List<String> protocols = new ArrayList<String>();
+ List<String> files = new ArrayList<String>();
+ List<DataSourceType> protocols = new ArrayList<DataSourceType>();
try
{
for (int i = 0; i < files.size(); i++)
{
String file = files.get(i).toString();
- String protocol = (protocols == null) ? FormatAdapter.FILE
- : (String) protocols.get(i);
- String format = null;
+ DataSourceType protocol = (protocols == null) ? DataSourceType.FILE
+ : protocols.get(i);
+ FileFormatI format = null;
if (file.endsWith(".jar"))
{
- format = "Jalview";
+ format = FileFormat.Jalview;
}
else
@Override
public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
{
+ FileFormat fileFormat = FileFormat.valueOf(Cache
+ .getProperty("DEFAULT_FILE_FORMAT"));
JalviewFileChooser chooser = new JalviewFileChooser(
- jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
- jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
- jalview.io.AppletFormatAdapter.READABLE_FNAMES,
- jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
+ Cache.getProperty("LAST_DIRECTORY"),
+ // AppletFormatAdapter.READABLE_EXTENSIONS,
+ // AppletFormatAdapter.READABLE_FNAMES,
+ fileFormat);
chooser.setFileView(new JalviewFileView());
chooser.setDialogTitle(MessageManager
if (value == JalviewFileChooser.APPROVE_OPTION)
{
String choice = chooser.getSelectedFile().getPath();
- jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
+ Cache.setProperty("LAST_DIRECTORY", chooser
.getSelectedFile().getParent());
- String format = null;
+ FileFormatI format = null;
if (chooser.getSelectedFormat() != null
- && chooser.getSelectedFormat().equals("Jalview"))
+ && chooser.getSelectedFormat() == FileFormat.Jalview)
{
- format = "Jalview";
+ format = FileFormat.Jalview;
}
else
{
- format = new IdentifyFile().identify(choice, FormatAdapter.FILE);
+ try
+ {
+ format = new IdentifyFile().identify(choice, DataSourceType.FILE);
+ } catch (FileFormatException e)
+ {
+ // format is null
+ }
}
if (viewport != null)
{
- new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
+ new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE,
format);
}
else
{
- new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
+ new FileLoader().LoadFile(choice, DataSourceType.FILE, format);
}
}
}
*
* @param e
* DOCUMENT ME!
+ * @throws FileFormatException
*/
@Override
public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
+ throws FileFormatException
{
// This construct allows us to have a wider textfield
// for viewing
{
if (viewport != null)
{
- new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
- "Jalview");
+ new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
+ FileFormat.Jalview);
}
else
{
- new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
+ new FileLoader().LoadFile(url, DataSourceType.URL,
+ FileFormat.Jalview);
}
}
else
{
- String format = new IdentifyFile().identify(url, FormatAdapter.URL);
+ FileFormatI format = new IdentifyFile().identify(url,
+ DataSourceType.URL);
if (format.equals("URL NOT FOUND"))
{
if (viewport != null)
{
- new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
+ new FileLoader()
+ .LoadFile(viewport, url, DataSourceType.URL, format);
}
else
{
- new FileLoader().LoadFile(url, FormatAdapter.URL, format);
+ new FileLoader().LoadFile(url, DataSourceType.URL, format);
}
}
}
dialogExecutor.shutdownNow();
}
closeAll_actionPerformed(null);
+
+ if (groovyConsole != null)
+ {
+ // suppress a possible repeat prompt to save script
+ groovyConsole.setDirty(false);
+ groovyConsole.exit();
+ }
System.exit(0);
}
*/
void openGroovyConsole()
{
- groovyConsole = new groovy.ui.Console();
+ if (groovyConsole == null)
+ {
+ groovyConsole = new groovy.ui.Console();
+ groovyConsole.setVariable("Jalview", this);
+ groovyConsole.run();
- /*
- * bind groovy variable 'Jalview' to the Desktop object
- */
- groovyConsole.setVariable("Jalview", this);
+ /*
+ * We allow only one console at a time, so that AlignFrame menu option
+ * 'Calculate | Run Groovy script' is unambiguous.
+ * Disable 'Groovy Console', and enable 'Run script', when the console is
+ * opened, and the reverse when it is closed
+ */
+ Window window = (Window) groovyConsole.getFrame();
+ window.addWindowListener(new WindowAdapter()
+ {
+ @Override
+ public void windowClosed(WindowEvent e)
+ {
+ /*
+ * rebind CMD-Q from Groovy Console to Jalview Quit
+ */
+ addQuitHandler();
+ enableExecuteGroovy(false);
+ }
+ });
+ }
/*
- * start the console
+ * show Groovy console window (after close and reopen)
*/
- groovyConsole.run();
+ ((Window) groovyConsole.getFrame()).setVisible(true);
/*
- * Allow only one console at a time, so that the AlignFrame menu option
- * 'Calculate | Run Groovy script' is unambiguous.
- * Disable 'new console', and enable 'Run script', when the console is
- * opened, and the reverse when it is closed
+ * if we got this far, enable 'Run Groovy' in AlignFrame menus
+ * and disable opening a second console
*/
- Window window = (Window) groovyConsole.getFrame();
- window.addWindowListener(new WindowAdapter()
+ enableExecuteGroovy(true);
+ }
+
+ /**
+ * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this
+ * binding when opened
+ */
+ protected void addQuitHandler()
+ {
+ getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
+ KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit
+ .getDefaultToolkit().getMenuShortcutKeyMask()),
+ "Quit");
+ getRootPane().getActionMap().put("Quit", new AbstractAction()
{
@Override
- public void windowClosed(WindowEvent e)
+ public void actionPerformed(ActionEvent e)
{
- enableExecuteGroovy(false);
+ quit();
}
});
-
- /*
- * if we got this far, enable 'Run Groovy' in AlignFrame menus
- * and disable opening a second console
- */
- enableExecuteGroovy(true);
}
/**
}
public static void transferFromDropTarget(List<String> files,
- List<String> protocols, DropTargetDropEvent evt, Transferable t)
+ List<DataSourceType> protocols, DropTargetDropEvent evt,
+ Transferable t)
throws Exception
{
.getTransferData(DataFlavor.javaFileListFlavor))
{
files.add(((File)file).toString());
- protocols.add(FormatAdapter.FILE);
+ protocols.add(DataSourceType.FILE);
}
}
else
{
Cache.log.debug("Adding missing FILE protocol for "
+ files.get(protocols.size()));
- protocols.add(FormatAdapter.FILE);
+ protocols.add(DataSourceType.FILE);
}
for (java.util.StringTokenizer st = new java.util.StringTokenizer(
data, "\r\n"); st.hasMoreTokens();)
java.net.URI uri = new java.net.URI(s);
if (uri.getScheme().toLowerCase().startsWith("http"))
{
- protocols.add(FormatAdapter.URL);
+ protocols.add(DataSourceType.URL);
files.add(uri.toString());
}
else
{
// otherwise preserve old behaviour: catch all for file objects
java.io.File file = new java.io.File(uri);
- protocols.add(FormatAdapter.FILE);
+ protocols.add(DataSourceType.FILE);
files.add(file.toString());
}
}