2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
23 import jalview.api.AlignViewportI;
24 import jalview.api.AlignmentViewPanel;
25 import jalview.bin.Cache;
26 import jalview.bin.Jalview;
27 import jalview.io.FileLoader;
28 import jalview.io.FormatAdapter;
29 import jalview.io.IdentifyFile;
30 import jalview.io.JalviewFileChooser;
31 import jalview.io.JalviewFileView;
32 import jalview.jbgui.GSplitFrame;
33 import jalview.jbgui.GStructureViewer;
34 import jalview.structure.StructureSelectionManager;
35 import jalview.util.ImageMaker;
36 import jalview.util.MessageManager;
37 import jalview.util.Platform;
38 import jalview.viewmodel.AlignmentViewport;
39 import jalview.ws.params.ParamManager;
41 import java.awt.BorderLayout;
42 import java.awt.Color;
43 import java.awt.Dimension;
44 import java.awt.FontMetrics;
45 import java.awt.Graphics;
46 import java.awt.GridLayout;
47 import java.awt.Point;
48 import java.awt.Rectangle;
49 import java.awt.Toolkit;
50 import java.awt.Window;
51 import java.awt.datatransfer.Clipboard;
52 import java.awt.datatransfer.ClipboardOwner;
53 import java.awt.datatransfer.DataFlavor;
54 import java.awt.datatransfer.Transferable;
55 import java.awt.dnd.DnDConstants;
56 import java.awt.dnd.DropTargetDragEvent;
57 import java.awt.dnd.DropTargetDropEvent;
58 import java.awt.dnd.DropTargetEvent;
59 import java.awt.dnd.DropTargetListener;
60 import java.awt.event.ActionEvent;
61 import java.awt.event.ActionListener;
62 import java.awt.event.FocusEvent;
63 import java.awt.event.FocusListener;
64 import java.awt.event.MouseAdapter;
65 import java.awt.event.MouseEvent;
66 import java.awt.event.MouseListener;
67 import java.awt.event.WindowAdapter;
68 import java.awt.event.WindowEvent;
69 import java.beans.PropertyChangeEvent;
70 import java.beans.PropertyChangeListener;
71 import java.beans.PropertyVetoException;
72 import java.io.BufferedInputStream;
74 import java.io.FileOutputStream;
76 import java.util.ArrayList;
77 import java.util.Hashtable;
78 import java.util.List;
79 import java.util.StringTokenizer;
80 import java.util.Vector;
81 import java.util.concurrent.ExecutorService;
82 import java.util.concurrent.Executors;
83 import java.util.concurrent.Semaphore;
85 import javax.swing.DefaultDesktopManager;
86 import javax.swing.DesktopManager;
87 import javax.swing.JButton;
88 import javax.swing.JComboBox;
89 import javax.swing.JComponent;
90 import javax.swing.JDesktopPane;
91 import javax.swing.JFrame;
92 import javax.swing.JInternalFrame;
93 import javax.swing.JLabel;
94 import javax.swing.JMenuItem;
95 import javax.swing.JOptionPane;
96 import javax.swing.JPanel;
97 import javax.swing.JPopupMenu;
98 import javax.swing.JProgressBar;
99 import javax.swing.SwingUtilities;
100 import javax.swing.event.HyperlinkEvent;
101 import javax.swing.event.HyperlinkEvent.EventType;
102 import javax.swing.event.MenuEvent;
103 import javax.swing.event.MenuListener;
110 * @version $Revision: 1.155 $
112 public class Desktop extends jalview.jbgui.GDesktop implements
113 DropTargetListener, ClipboardOwner, IProgressIndicator,
114 jalview.api.StructureSelectionManagerProvider
117 private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
120 * news reader - null if it was never started.
122 private BlogReader jvnews = null;
124 private File projectFile;
128 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
130 public void addJalviewPropertyChangeListener(
131 PropertyChangeListener listener)
133 changeSupport.addJalviewPropertyChangeListener(listener);
137 * @param propertyName
139 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
140 * java.beans.PropertyChangeListener)
142 public void addJalviewPropertyChangeListener(String propertyName,
143 PropertyChangeListener listener)
145 changeSupport.addJalviewPropertyChangeListener(propertyName, listener);
149 * @param propertyName
151 * @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
152 * java.beans.PropertyChangeListener)
154 public void removeJalviewPropertyChangeListener(String propertyName,
155 PropertyChangeListener listener)
157 changeSupport.removeJalviewPropertyChangeListener(propertyName,
161 /** Singleton Desktop instance */
162 public static Desktop instance;
164 public static MyDesktopPane desktop;
166 static int openFrameCount = 0;
168 static final int xOffset = 30;
170 static final int yOffset = 30;
172 public static jalview.ws.jws1.Discoverer discoverer;
174 public static Object[] jalviewClipboard;
176 public static boolean internalCopy = false;
178 static int fileLoadingCount = 0;
180 class MyDesktopManager implements DesktopManager
183 private DesktopManager delegate;
185 public MyDesktopManager(DesktopManager delegate)
187 this.delegate = delegate;
191 public void activateFrame(JInternalFrame f)
195 delegate.activateFrame(f);
196 } catch (NullPointerException npe)
198 Point p = getMousePosition();
199 instance.showPasteMenu(p.x, p.y);
204 public void beginDraggingFrame(JComponent f)
206 delegate.beginDraggingFrame(f);
210 public void beginResizingFrame(JComponent f, int direction)
212 delegate.beginResizingFrame(f, direction);
216 public void closeFrame(JInternalFrame f)
218 delegate.closeFrame(f);
222 public void deactivateFrame(JInternalFrame f)
224 delegate.deactivateFrame(f);
228 public void deiconifyFrame(JInternalFrame f)
230 delegate.deiconifyFrame(f);
234 public void dragFrame(JComponent f, int newX, int newY)
240 delegate.dragFrame(f, newX, newY);
244 public void endDraggingFrame(JComponent f)
246 delegate.endDraggingFrame(f);
250 public void endResizingFrame(JComponent f)
252 delegate.endResizingFrame(f);
256 public void iconifyFrame(JInternalFrame f)
258 delegate.iconifyFrame(f);
262 public void maximizeFrame(JInternalFrame f)
264 delegate.maximizeFrame(f);
268 public void minimizeFrame(JInternalFrame f)
270 delegate.minimizeFrame(f);
274 public void openFrame(JInternalFrame f)
276 delegate.openFrame(f);
280 public void resizeFrame(JComponent f, int newX, int newY, int newWidth,
287 delegate.resizeFrame(f, newX, newY, newWidth, newHeight);
291 public void setBoundsForFrame(JComponent f, int newX, int newY,
292 int newWidth, int newHeight)
294 delegate.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
297 // All other methods, simply delegate
302 * Creates a new Desktop object.
307 * A note to implementors. It is ESSENTIAL that any activities that might
308 * block are spawned off as threads rather than waited for during this
312 doVamsasClientCheck();
314 groovyShell = new JMenuItem();
315 groovyShell.setText(MessageManager.getString("label.groovy_console"));
316 groovyShell.addActionListener(new ActionListener()
319 public void actionPerformed(ActionEvent e)
321 groovyShell_actionPerformed();
324 toolsMenu.add(groovyShell);
325 groovyShell.setVisible(true);
327 doConfigureStructurePrefs();
328 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
329 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
330 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",
332 boolean showjconsole = jalview.bin.Cache.getDefault(
333 "SHOW_JAVA_CONSOLE", false);
334 desktop = new MyDesktopPane(selmemusage);
335 if (Platform.isAMac())
337 desktop.setDoubleBuffered(false);
339 showMemusage.setSelected(selmemusage);
340 desktop.setBackground(Color.white);
341 getContentPane().setLayout(new BorderLayout());
342 // alternate config - have scrollbars - see notes in JAL-153
343 // JScrollPane sp = new JScrollPane();
344 // sp.getViewport().setView(desktop);
345 // getContentPane().add(sp, BorderLayout.CENTER);
346 getContentPane().add(desktop, BorderLayout.CENTER);
347 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
349 // This line prevents Windows Look&Feel resizing all new windows to maximum
350 // if previous window was maximised
351 desktop.setDesktopManager(new MyDesktopManager(
352 new DefaultDesktopManager()));
354 Rectangle dims = getLastKnownDimensions("");
361 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
362 setBounds((screenSize.width - 900) / 2,
363 (screenSize.height - 650) / 2, 900, 650);
365 jconsole = new Console(this, showjconsole);
366 // add essential build information
367 jconsole.setHeader("Jalview Version: "
368 + jalview.bin.Cache.getProperty("VERSION") + "\n"
369 + "Jalview Installation: "
370 + jalview.bin.Cache.getDefault("INSTALLATION", "unknown")
371 + "\n" + "Build Date: "
372 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
373 + "Java version: " + System.getProperty("java.version") + "\n"
374 + System.getProperty("os.arch") + " "
375 + System.getProperty("os.name") + " "
376 + System.getProperty("os.version"));
378 showConsole(showjconsole);
380 showNews.setVisible(false);
382 this.addWindowListener(new WindowAdapter()
385 public void windowClosing(WindowEvent evt)
392 this.addMouseListener(ma = new MouseAdapter()
395 public void mousePressed(MouseEvent evt)
397 if (evt.isPopupTrigger())
399 showPasteMenu(evt.getX(), evt.getY());
403 desktop.addMouseListener(ma);
405 this.addFocusListener(new FocusListener()
409 public void focusLost(FocusEvent e)
411 // TODO Auto-generated method stub
416 public void focusGained(FocusEvent e)
418 Cache.log.debug("Relaying windows after focus gain");
419 // make sure that we sort windows properly after we gain focus
420 instance.relayerWindows();
423 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
424 // Spawn a thread that shows the splashscreen
425 SwingUtilities.invokeLater(new Runnable()
435 // Thread off a new instance of the file chooser - this reduces the time it
436 // takes to open it later on.
437 new Thread(new Runnable()
442 Cache.log.debug("Filechooser init thread started.");
443 new JalviewFileChooser(
444 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
445 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
446 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
447 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
448 Cache.log.debug("Filechooser init thread finished.");
451 // Add the service change listener
452 changeSupport.addJalviewPropertyChangeListener("services",
453 new PropertyChangeListener()
457 public void propertyChange(PropertyChangeEvent evt)
459 Cache.log.debug("Firing service changed event for "
460 + evt.getNewValue());
461 JalviewServicesChanged(evt);
467 public void doConfigureStructurePrefs()
469 // configure services
470 StructureSelectionManager ssm = StructureSelectionManager
471 .getStructureSelectionManager(this);
472 if (jalview.bin.Cache.getDefault(Preferences.ADD_SS_ANN, true))
474 ssm.setAddTempFacAnnot(jalview.bin.Cache.getDefault(
475 Preferences.ADD_TEMPFACT_ANN, true));
476 ssm.setProcessSecondaryStructure(jalview.bin.Cache.getDefault(
477 Preferences.STRUCT_FROM_PDB, true));
478 ssm.setSecStructServices(jalview.bin.Cache.getDefault(
479 Preferences.USE_RNAVIEW, true));
483 ssm.setAddTempFacAnnot(false);
484 ssm.setProcessSecondaryStructure(false);
485 ssm.setSecStructServices(false);
489 public void checkForNews()
491 final Desktop me = this;
492 // Thread off the news reader, in case there are connection problems.
493 addDialogThread(new Runnable()
498 Cache.log.debug("Starting news thread.");
500 jvnews = new BlogReader(me);
501 showNews.setVisible(true);
502 Cache.log.debug("Completed news thread.");
508 protected void showNews_actionPerformed(ActionEvent e)
510 showNews(showNews.isSelected());
513 void showNews(boolean visible)
516 Cache.log.debug((visible ? "Showing" : "Hiding") + " news.");
517 showNews.setSelected(visible);
518 if (visible && !jvnews.isVisible())
520 new Thread(new Runnable()
525 long now = System.currentTimeMillis();
526 Desktop.instance.setProgressBar(
527 MessageManager.getString("status.refreshing_news"), now);
528 jvnews.refreshNews();
529 Desktop.instance.setProgressBar(null, now);
538 * recover the last known dimensions for a jalview window
541 * - empty string is desktop, all other windows have unique prefix
542 * @return null or last known dimensions scaled to current geometry (if last
543 * window geom was known)
545 Rectangle getLastKnownDimensions(String windowName)
547 // TODO: lock aspect ratio for scaling desktop Bug #0058199
548 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
549 String x = jalview.bin.Cache.getProperty(windowName + "SCREEN_X");
550 String y = jalview.bin.Cache.getProperty(windowName + "SCREEN_Y");
551 String width = jalview.bin.Cache.getProperty(windowName
553 String height = jalview.bin.Cache.getProperty(windowName
555 if ((x != null) && (y != null) && (width != null) && (height != null))
557 int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer
558 .parseInt(width), ih = Integer.parseInt(height);
559 if (jalview.bin.Cache.getProperty("SCREENGEOMETRY_WIDTH") != null)
561 // attempt #1 - try to cope with change in screen geometry - this
562 // version doesn't preserve original jv aspect ratio.
563 // take ratio of current screen size vs original screen size.
564 double sw = ((1f * screenSize.width) / (1f * Integer
565 .parseInt(jalview.bin.Cache
566 .getProperty("SCREENGEOMETRY_WIDTH"))));
567 double sh = ((1f * screenSize.height) / (1f * Integer
568 .parseInt(jalview.bin.Cache
569 .getProperty("SCREENGEOMETRY_HEIGHT"))));
570 // rescale the bounds depending upon the current screen geometry.
571 ix = (int) (ix * sw);
572 iw = (int) (iw * sw);
573 iy = (int) (iy * sh);
574 ih = (int) (ih * sh);
575 while (ix >= screenSize.width)
577 jalview.bin.Cache.log
578 .debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
579 ix -= screenSize.width;
581 while (iy >= screenSize.height)
583 jalview.bin.Cache.log
584 .debug("Window geometry location recall error: shifting vertical to within screenbounds.");
585 iy -= screenSize.height;
587 jalview.bin.Cache.log.debug("Got last known dimensions for "
588 + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
591 // return dimensions for new instance
592 return new Rectangle(ix, iy, iw, ih);
597 private void doVamsasClientCheck()
599 if (jalview.bin.Cache.vamsasJarsPresent())
601 setupVamsasDisconnectedGui();
602 VamsasMenu.setVisible(true);
603 final Desktop us = this;
604 VamsasMenu.addMenuListener(new MenuListener()
606 // this listener remembers when the menu was first selected, and
607 // doesn't rebuild the session list until it has been cleared and
609 boolean refresh = true;
612 public void menuCanceled(MenuEvent e)
618 public void menuDeselected(MenuEvent e)
624 public void menuSelected(MenuEvent e)
628 us.buildVamsasStMenu();
633 vamsasStart.setVisible(true);
637 void showPasteMenu(int x, int y)
639 JPopupMenu popup = new JPopupMenu();
640 JMenuItem item = new JMenuItem(
641 MessageManager.getString("label.paste_new_window"));
642 item.addActionListener(new ActionListener()
645 public void actionPerformed(ActionEvent evt)
652 popup.show(this, x, y);
659 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
660 Transferable contents = c.getContents(this);
662 if (contents != null)
664 String file = (String) contents
665 .getTransferData(DataFlavor.stringFlavor);
667 String format = new IdentifyFile().identify(file,
668 FormatAdapter.PASTE);
670 new FileLoader().LoadFile(file, FormatAdapter.PASTE, format);
673 } catch (Exception ex)
676 .println("Unable to paste alignment from system clipboard:\n"
682 * Adds and opens the given frame to the desktop
693 public static synchronized void addInternalFrame(
694 final JInternalFrame frame, String title, int w, int h)
696 addInternalFrame(frame, title, true, w, h, true);
700 * Add an internal frame to the Jalview desktop
707 * When true, display frame immediately, otherwise, caller must call
708 * setVisible themselves.
714 public static synchronized void addInternalFrame(
715 final JInternalFrame frame, String title, boolean makeVisible,
718 addInternalFrame(frame, title, makeVisible, w, h, true);
722 * Add an internal frame to the Jalview desktop and make it visible
735 public static synchronized void addInternalFrame(
736 final JInternalFrame frame, String title, int w, int h,
739 addInternalFrame(frame, title, true, w, h, resizable);
743 * Add an internal frame to the Jalview desktop
750 * When true, display frame immediately, otherwise, caller must call
751 * setVisible themselves.
759 public static synchronized void addInternalFrame(
760 final JInternalFrame frame, String title, boolean makeVisible,
761 int w, int h, boolean resizable)
764 // TODO: allow callers to determine X and Y position of frame (eg. via
766 // TODO: consider fixing method to update entries in the window submenu with
767 // the current window title
769 frame.setTitle(title);
770 if (frame.getWidth() < 1 || frame.getHeight() < 1)
774 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
775 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
776 // IF JALVIEW IS RUNNING HEADLESS
777 // ///////////////////////////////////////////////
779 || (System.getProperty("java.awt.headless") != null && System
780 .getProperty("java.awt.headless").equals("true")))
787 frame.setVisible(makeVisible);
788 frame.setClosable(true);
789 frame.setResizable(resizable);
790 frame.setMaximizable(resizable);
791 frame.setIconifiable(resizable);
792 if (Platform.isAMac())
794 frame.setIconifiable(false);
795 frame.setFrameIcon(null);
796 // frame.setDesktopIcon(null);
797 frame.setDoubleBuffered(false);
799 if (frame.getX() < 1 && frame.getY() < 1)
801 frame.setLocation(xOffset * openFrameCount, yOffset
802 * ((openFrameCount - 1) % 10) + yOffset);
805 final JMenuItem menuItem = new JMenuItem(title);
806 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
809 public void internalFrameActivated(
810 javax.swing.event.InternalFrameEvent evt)
812 JInternalFrame itf = desktop.getSelectedFrame();
821 public void internalFrameClosed(
822 javax.swing.event.InternalFrameEvent evt)
824 PaintRefresher.RemoveComponent(frame);
826 windowMenu.remove(menuItem);
827 JInternalFrame itf = desktop.getSelectedFrame();
836 menuItem.addActionListener(new ActionListener()
839 public void actionPerformed(ActionEvent e)
843 frame.setSelected(true);
844 frame.setIcon(false);
845 } catch (java.beans.PropertyVetoException ex)
851 menuItem.addMouseListener(new MouseListener()
855 public void mouseReleased(MouseEvent e)
860 public void mousePressed(MouseEvent e)
865 public void mouseExited(MouseEvent e)
869 frame.setSelected(false);
870 } catch (PropertyVetoException e1)
876 public void mouseEntered(MouseEvent e)
880 frame.setSelected(true);
881 } catch (PropertyVetoException e1)
887 public void mouseClicked(MouseEvent e)
893 windowMenu.add(menuItem);
899 frame.setSelected(true);
900 frame.requestFocus();
901 } catch (java.beans.PropertyVetoException ve)
903 } catch (java.lang.ClassCastException cex)
906 .warn("Squashed a possible GUI implementation error. If you can recreate this, please look at http://issues.jalview.org/browse/JAL-869",
912 public void lostOwnership(Clipboard clipboard, Transferable contents)
916 Desktop.jalviewClipboard = null;
919 internalCopy = false;
923 public void dragEnter(DropTargetDragEvent evt)
928 public void dragExit(DropTargetEvent evt)
933 public void dragOver(DropTargetDragEvent evt)
938 public void dropActionChanged(DropTargetDragEvent evt)
949 public void drop(DropTargetDropEvent evt)
951 boolean success = true;
952 Transferable t = evt.getTransferable();
953 java.util.List<String> files = new ArrayList<String>();
954 java.util.List<String> protocols = new ArrayList<String>();
958 Desktop.transferFromDropTarget(files, protocols, evt, t);
959 } catch (Exception e)
969 for (int i = 0; i < files.size(); i++)
971 String file = files.get(i).toString();
972 String protocol = (protocols == null) ? FormatAdapter.FILE
973 : (String) protocols.get(i);
974 String format = null;
976 if (file.endsWith(".jar"))
983 format = new IdentifyFile().identify(file, protocol);
986 new FileLoader().LoadFile(file, protocol, format);
989 } catch (Exception ex)
994 evt.dropComplete(success); // need this to ensure input focus is properly
995 // transfered to any new windows created
1005 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
1007 JalviewFileChooser chooser = new JalviewFileChooser(
1008 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1009 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
1010 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
1011 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
1013 chooser.setFileView(new JalviewFileView());
1014 chooser.setDialogTitle(MessageManager
1015 .getString("label.open_local_file"));
1016 chooser.setToolTipText(MessageManager.getString("action.open"));
1018 int value = chooser.showOpenDialog(this);
1020 if (value == JalviewFileChooser.APPROVE_OPTION)
1022 String choice = chooser.getSelectedFile().getPath();
1023 jalview.bin.Cache.setProperty("LAST_DIRECTORY", chooser
1024 .getSelectedFile().getParent());
1026 String format = null;
1027 if (chooser.getSelectedFormat() != null
1028 && chooser.getSelectedFormat().equals("Jalview"))
1034 format = new IdentifyFile().identify(choice, FormatAdapter.FILE);
1037 if (viewport != null)
1039 new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE,
1044 new FileLoader().LoadFile(choice, FormatAdapter.FILE, format);
1056 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
1058 // This construct allows us to have a wider textfield
1060 JLabel label = new JLabel(
1061 MessageManager.getString("label.input_file_url"));
1062 final JComboBox history = new JComboBox();
1064 JPanel panel = new JPanel(new GridLayout(2, 1));
1067 history.setPreferredSize(new Dimension(400, 20));
1068 history.setEditable(true);
1069 history.addItem("http://www.");
1071 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
1075 if (historyItems != null)
1077 st = new StringTokenizer(historyItems, "\t");
1079 while (st.hasMoreTokens())
1081 history.addItem(st.nextElement());
1085 int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
1086 MessageManager.getString("label.input_alignment_from_url"),
1087 JOptionPane.OK_CANCEL_OPTION);
1089 if (reply != JOptionPane.OK_OPTION)
1094 String url = history.getSelectedItem().toString();
1096 if (url.toLowerCase().endsWith(".jar"))
1098 if (viewport != null)
1100 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL,
1105 new FileLoader().LoadFile(url, FormatAdapter.URL, "Jalview");
1110 String format = new IdentifyFile().identify(url, FormatAdapter.URL);
1112 if (format.equals("URL NOT FOUND"))
1114 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1115 MessageManager.formatMessage("label.couldnt_locate",
1116 new Object[] { url }), MessageManager
1117 .getString("label.url_not_found"),
1118 JOptionPane.WARNING_MESSAGE);
1123 if (viewport != null)
1125 new FileLoader().LoadFile(viewport, url, FormatAdapter.URL, format);
1129 new FileLoader().LoadFile(url, FormatAdapter.URL, format);
1135 * Opens the CutAndPaste window for the user to paste an alignment in to
1138 * - if not null, the pasted alignment is added to the current
1139 * alignment; if null, to a new alignment window
1142 public void inputTextboxMenuItem_actionPerformed(
1143 AlignmentViewPanel viewPanel)
1145 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1146 cap.setForInput(viewPanel);
1147 Desktop.addInternalFrame(cap,
1148 MessageManager.getString("label.cut_paste_alignmen_file"),
1158 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
1160 .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
1161 jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
1163 storeLastKnownDimensions("", new Rectangle(getBounds().x,
1164 getBounds().y, getWidth(), getHeight()));
1166 if (jconsole != null)
1168 storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
1169 jconsole.stopConsole();
1173 storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
1176 if (dialogExecutor != null)
1178 dialogExecutor.shutdownNow();
1180 closeAll_actionPerformed(null);
1184 private void storeLastKnownDimensions(String string, Rectangle jc)
1186 jalview.bin.Cache.log.debug("Storing last known dimensions for "
1187 + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
1188 + " height:" + jc.height);
1190 jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
1191 jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
1192 jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
1193 jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
1203 public void aboutMenuItem_actionPerformed(ActionEvent e)
1205 // StringBuffer message = getAboutMessage(false);
1206 // JOptionPane.showInternalMessageDialog(Desktop.desktop,
1208 // message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
1209 new Thread(new Runnable()
1214 new SplashScreen(true);
1219 public StringBuffer getAboutMessage(boolean shortv)
1221 StringBuffer message = new StringBuffer();
1222 message.append("<html>");
1225 message.append("<h1><strong>Version: "
1226 + jalview.bin.Cache.getProperty("VERSION") + "</strong></h1>");
1227 message.append("<strong>Last Updated: <em>"
1228 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")
1229 + "</em></strong>");
1235 message.append("<strong>Version "
1236 + jalview.bin.Cache.getProperty("VERSION")
1237 + "; last updated: "
1238 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
1241 if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
1244 message.append("<br>...Checking latest version...</br>");
1246 else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
1247 .equals(jalview.bin.Cache.getProperty("VERSION")))
1249 boolean red = false;
1250 if (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
1251 .indexOf("automated build") == -1)
1254 // Displayed when code version and jnlp version do not match and code
1255 // version is not a development build
1256 message.append("<div style=\"color: #FF0000;font-style: bold;\">");
1259 message.append("<br>!! Version "
1260 + jalview.bin.Cache.getDefault("LATEST_VERSION",
1262 + " is available for download from "
1263 + jalview.bin.Cache.getDefault("www.jalview.org",
1264 "http://www.jalview.org") + " !!");
1267 message.append("</div>");
1270 message.append("<br>Authors: "
1272 .getDefault("AUTHORFNAMES",
1273 "The Jalview Authors (See AUTHORS file for current list)")
1274 + "<br><br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
1275 + "<br><br>For help, see the FAQ at <a href=\"http://www.jalview.org/faq\">www.jalview.org/faq</a> and/or join the jalview-discuss@jalview.org mailing list"
1276 + "<br><br>If you use Jalview, please cite:"
1277 + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
1278 + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
1279 + "<br>Bioinformatics doi: 10.1093/bioinformatics/btp033"
1291 public void documentationMenuItem_actionPerformed(ActionEvent e)
1295 Help.showHelpWindow();
1296 } catch (Exception ex)
1302 public void closeAll_actionPerformed(ActionEvent e)
1304 JInternalFrame[] frames = desktop.getAllFrames();
1305 for (int i = 0; i < frames.length; i++)
1309 frames[i].setClosed(true);
1310 } catch (java.beans.PropertyVetoException ex)
1314 System.out.println("ALL CLOSED");
1315 if (v_client != null)
1317 // TODO clear binding to vamsas document objects on close_all
1321 * reset state of singleton objects as appropriate (clear down session state
1322 * when all windows are closed)
1324 StructureSelectionManager ssm = StructureSelectionManager
1325 .getStructureSelectionManager(this);
1333 public void raiseRelated_actionPerformed(ActionEvent e)
1335 reorderAssociatedWindows(false, false);
1339 public void minimizeAssociated_actionPerformed(ActionEvent e)
1341 reorderAssociatedWindows(true, false);
1344 void closeAssociatedWindows()
1346 reorderAssociatedWindows(false, true);
1352 * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
1356 protected void garbageCollect_actionPerformed(ActionEvent e)
1358 // We simply collect the garbage
1359 jalview.bin.Cache.log.debug("Collecting garbage...");
1361 jalview.bin.Cache.log.debug("Finished garbage collection.");
1368 * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
1372 protected void showMemusage_actionPerformed(ActionEvent e)
1374 desktop.showMemoryUsage(showMemusage.isSelected());
1381 * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
1385 protected void showConsole_actionPerformed(ActionEvent e)
1387 showConsole(showConsole.isSelected());
1390 Console jconsole = null;
1393 * control whether the java console is visible or not
1397 void showConsole(boolean selected)
1399 showConsole.setSelected(selected);
1400 // TODO: decide if we should update properties file
1401 Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected)
1403 jconsole.setVisible(selected);
1406 void reorderAssociatedWindows(boolean minimize, boolean close)
1408 JInternalFrame[] frames = desktop.getAllFrames();
1409 if (frames == null || frames.length < 1)
1414 AlignmentViewport source = null, target = null;
1415 if (frames[0] instanceof AlignFrame)
1417 source = ((AlignFrame) frames[0]).getCurrentView();
1419 else if (frames[0] instanceof TreePanel)
1421 source = ((TreePanel) frames[0]).getViewPort();
1423 else if (frames[0] instanceof PCAPanel)
1425 source = ((PCAPanel) frames[0]).av;
1427 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
1429 source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
1434 for (int i = 0; i < frames.length; i++)
1437 if (frames[i] == null)
1441 if (frames[i] instanceof AlignFrame)
1443 target = ((AlignFrame) frames[i]).getCurrentView();
1445 else if (frames[i] instanceof TreePanel)
1447 target = ((TreePanel) frames[i]).getViewPort();
1449 else if (frames[i] instanceof PCAPanel)
1451 target = ((PCAPanel) frames[i]).av;
1453 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
1455 target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
1458 if (source == target)
1464 frames[i].setClosed(true);
1468 frames[i].setIcon(minimize);
1471 frames[i].toFront();
1475 } catch (java.beans.PropertyVetoException ex)
1490 protected void preferences_actionPerformed(ActionEvent e)
1502 public void saveState_actionPerformed(ActionEvent e)
1504 JalviewFileChooser chooser = new JalviewFileChooser(
1505 jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
1506 new String[] { "jvp" }, new String[] { "Jalview Project" },
1509 chooser.setFileView(new JalviewFileView());
1510 chooser.setDialogTitle(MessageManager.getString("label.save_state"));
1512 int value = chooser.showSaveDialog(this);
1514 if (value == JalviewFileChooser.APPROVE_OPTION)
1516 final Desktop me = this;
1517 final java.io.File choice = chooser.getSelectedFile();
1518 setProjectFile(choice);
1520 new Thread(new Runnable()
1525 // TODO: refactor to Jalview desktop session controller action.
1526 setProgressBar(MessageManager.formatMessage(
1527 "label.saving_jalview_project",
1528 new Object[] { choice.getName() }), choice.hashCode());
1529 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
1530 choice.getParent());
1531 // TODO catch and handle errors for savestate
1532 // TODO prevent user from messing with the Desktop whilst we're saving
1535 new Jalview2XML().saveState(choice);
1536 } catch (OutOfMemoryError oom)
1538 new OOMWarning("Whilst saving current state to "
1539 + choice.getName(), oom);
1540 } catch (Exception ex)
1543 "Problems whilst trying to save to " + choice.getName(),
1545 JOptionPane.showMessageDialog(me, MessageManager.formatMessage(
1546 "label.error_whilst_saving_current_state_to",
1547 new Object[] { choice.getName() }), MessageManager
1548 .getString("label.couldnt_save_project"),
1549 JOptionPane.WARNING_MESSAGE);
1551 setProgressBar(null, choice.hashCode());
1557 private void setProjectFile(File choice)
1559 this.projectFile = choice;
1562 public File getProjectFile()
1564 return this.projectFile;
1574 public void loadState_actionPerformed(ActionEvent e)
1576 JalviewFileChooser chooser = new JalviewFileChooser(
1577 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[] {
1578 "jvp", "jar" }, new String[] { "Jalview Project",
1579 "Jalview Project (old)" }, "Jalview Project");
1580 chooser.setFileView(new JalviewFileView());
1581 chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
1583 int value = chooser.showOpenDialog(this);
1585 if (value == JalviewFileChooser.APPROVE_OPTION)
1587 final File selectedFile = chooser.getSelectedFile();
1588 setProjectFile(selectedFile);
1589 final String choice = selectedFile.getAbsolutePath();
1590 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
1591 selectedFile.getParent());
1592 new Thread(new Runnable()
1598 MessageManager.formatMessage(
1599 "label.loading_jalview_project",
1600 new Object[] { choice }), choice.hashCode());
1603 new Jalview2XML().loadJalviewAlign(choice);
1604 } catch (OutOfMemoryError oom)
1606 new OOMWarning("Whilst loading project from " + choice, oom);
1607 } catch (Exception ex)
1609 Cache.log.error("Problems whilst loading project from "
1611 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
1613 "label.error_whilst_loading_project_from",
1614 new Object[] { choice }), MessageManager
1615 .getString("label.couldnt_load_project"),
1616 JOptionPane.WARNING_MESSAGE);
1618 setProgressBar(null, choice.hashCode());
1625 public void inputSequence_actionPerformed(ActionEvent e)
1627 new SequenceFetcher(this);
1630 JPanel progressPanel;
1632 ArrayList<JPanel> fileLoadingPanels = new ArrayList<JPanel>();
1634 public void startLoading(final String fileName)
1636 if (fileLoadingCount == 0)
1638 fileLoadingPanels.add(addProgressPanel(MessageManager.formatMessage(
1639 "label.loading_file", new Object[] { fileName })));
1644 private JPanel addProgressPanel(String string)
1646 if (progressPanel == null)
1648 progressPanel = new JPanel(new GridLayout(1, 1));
1649 totalProgressCount = 0;
1650 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
1652 JPanel thisprogress = new JPanel(new BorderLayout(10, 5));
1653 JProgressBar progressBar = new JProgressBar();
1654 progressBar.setIndeterminate(true);
1656 thisprogress.add(new JLabel(string), BorderLayout.WEST);
1658 thisprogress.add(progressBar, BorderLayout.CENTER);
1659 progressPanel.add(thisprogress);
1660 ((GridLayout) progressPanel.getLayout())
1661 .setRows(((GridLayout) progressPanel.getLayout()).getRows() + 1);
1662 ++totalProgressCount;
1663 instance.validate();
1664 return thisprogress;
1667 int totalProgressCount = 0;
1669 private void removeProgressPanel(JPanel progbar)
1671 if (progressPanel != null)
1673 synchronized (progressPanel)
1675 progressPanel.remove(progbar);
1676 GridLayout gl = (GridLayout) progressPanel.getLayout();
1677 gl.setRows(gl.getRows() - 1);
1678 if (--totalProgressCount < 1)
1680 this.getContentPane().remove(progressPanel);
1681 progressPanel = null;
1688 public void stopLoading()
1691 if (fileLoadingCount < 1)
1693 while (fileLoadingPanels.size() > 0)
1695 removeProgressPanel(fileLoadingPanels.remove(0));
1697 fileLoadingPanels.clear();
1698 fileLoadingCount = 0;
1703 public static int getViewCount(String alignmentId)
1705 AlignmentViewport[] aps = getViewports(alignmentId);
1706 return (aps == null) ? 0 : aps.length;
1711 * @param alignmentId
1712 * - if null, all sets are returned
1713 * @return all AlignmentPanels concerning the alignmentId sequence set
1715 public static AlignmentPanel[] getAlignmentPanels(String alignmentId)
1717 if (Desktop.desktop == null)
1719 // no frames created and in headless mode
1720 // TODO: verify that frames are recoverable when in headless mode
1723 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>();
1724 AlignFrame[] frames = getAlignFrames();
1729 for (AlignFrame af : frames)
1731 for (AlignmentPanel ap : af.alignPanels)
1733 if (alignmentId == null
1734 || alignmentId.equals(ap.av.getSequenceSetId()))
1740 if (aps.size() == 0)
1744 AlignmentPanel[] vap = aps.toArray(new AlignmentPanel[aps.size()]);
1749 * get all the viewports on an alignment.
1751 * @param sequenceSetId
1752 * unique alignment id (may be null - all viewports returned in that
1754 * @return all viewports on the alignment bound to sequenceSetId
1756 public static AlignmentViewport[] getViewports(String sequenceSetId)
1758 List<AlignmentViewport> viewp = new ArrayList<AlignmentViewport>();
1759 if (desktop != null)
1761 AlignFrame[] frames = Desktop.getAlignFrames();
1763 for (AlignFrame afr : frames)
1765 if (sequenceSetId == null
1766 || afr.getViewport().getSequenceSetId()
1767 .equals(sequenceSetId))
1769 if (afr.alignPanels != null)
1771 for (AlignmentPanel ap : afr.alignPanels)
1773 if (sequenceSetId == null
1774 || sequenceSetId.equals(ap.av.getSequenceSetId()))
1782 viewp.add(afr.getViewport());
1786 if (viewp.size() > 0)
1788 return viewp.toArray(new AlignmentViewport[viewp.size()]);
1795 * Explode the views in the given frame into separate AlignFrame
1799 public void explodeViews(AlignFrame af)
1801 int size = af.alignPanels.size();
1807 for (int i = 0; i < size; i++)
1809 AlignmentPanel ap = af.alignPanels.get(i);
1810 AlignFrame newaf = new AlignFrame(ap);
1813 * Restore the view's last exploded frame geometry if known. Multiple
1814 * views from one exploded frame share and restore the same (frame)
1815 * position and size.
1817 Rectangle geometry = ap.av.getExplodedGeometry();
1818 if (geometry != null)
1820 newaf.setBounds(geometry);
1823 ap.av.setGatherViewsHere(false);
1825 addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1826 AlignFrame.DEFAULT_HEIGHT);
1829 af.alignPanels.clear();
1830 af.closeMenuItem_actionPerformed(true);
1835 * Gather expanded views (separate AlignFrame's) with the same sequence set
1836 * identifier back in to this frame as additional views, and close the
1837 * expanded views. Note the expanded frames may themselves have multiple
1838 * views. We take the lot.
1842 public void gatherViews(AlignFrame source)
1844 source.viewport.setGatherViewsHere(true);
1845 source.viewport.setExplodedGeometry(source.getBounds());
1846 JInternalFrame[] frames = desktop.getAllFrames();
1847 String viewId = source.viewport.getSequenceSetId();
1849 for (int t = 0; t < frames.length; t++)
1851 if (frames[t] instanceof AlignFrame && frames[t] != source)
1853 AlignFrame af = (AlignFrame) frames[t];
1854 boolean gatherThis = false;
1855 for (int a = 0; a < af.alignPanels.size(); a++)
1857 AlignmentPanel ap = af.alignPanels.get(a);
1858 if (viewId.equals(ap.av.getSequenceSetId()))
1861 ap.av.setGatherViewsHere(false);
1862 ap.av.setExplodedGeometry(af.getBounds());
1863 source.addAlignmentPanel(ap, false);
1869 af.alignPanels.clear();
1870 af.closeMenuItem_actionPerformed(true);
1877 jalview.gui.VamsasApplication v_client = null;
1880 public void vamsasImport_actionPerformed(ActionEvent e)
1882 if (v_client == null)
1884 // Load and try to start a session.
1885 JalviewFileChooser chooser = new JalviewFileChooser(
1886 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1888 chooser.setFileView(new JalviewFileView());
1889 chooser.setDialogTitle(MessageManager
1890 .getString("label.open_saved_vamsas_session"));
1891 chooser.setToolTipText(MessageManager
1892 .getString("label.select_vamsas_session_opened_as_new_vamsas_session"));
1894 int value = chooser.showOpenDialog(this);
1896 if (value == JalviewFileChooser.APPROVE_OPTION)
1898 String fle = chooser.getSelectedFile().toString();
1899 if (!vamsasImport(chooser.getSelectedFile()))
1902 .showInternalMessageDialog(
1904 MessageManager.formatMessage(
1905 "label.couldnt_import_as_vamsas_session",
1906 new Object[] { fle }),
1908 .getString("label.vamsas_document_import_failed"),
1909 JOptionPane.ERROR_MESSAGE);
1915 jalview.bin.Cache.log
1916 .error("Implementation error - load session from a running session is not supported.");
1921 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1924 * @return true if import was a success and a session was started.
1926 public boolean vamsasImport(URL url)
1928 // TODO: create progress bar
1929 if (v_client != null)
1932 jalview.bin.Cache.log
1933 .error("Implementation error - load session from a running session is not supported.");
1939 // copy the URL content to a temporary local file
1940 // TODO: be a bit cleverer here with nio (?!)
1941 File file = File.createTempFile("vdocfromurl", ".vdj");
1942 FileOutputStream fos = new FileOutputStream(file);
1943 BufferedInputStream bis = new BufferedInputStream(url.openStream());
1944 byte[] buffer = new byte[2048];
1946 while ((ln = bis.read(buffer)) > -1)
1948 fos.write(buffer, 0, ln);
1952 v_client = new jalview.gui.VamsasApplication(this, file,
1953 url.toExternalForm());
1954 } catch (Exception ex)
1956 jalview.bin.Cache.log.error(
1957 "Failed to create new vamsas session from contents of URL "
1961 setupVamsasConnectedGui();
1962 v_client.initial_update(); // TODO: thread ?
1963 return v_client.inSession();
1967 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1970 * @return true if import was a success and a session was started.
1972 public boolean vamsasImport(File file)
1974 if (v_client != null)
1977 jalview.bin.Cache.log
1978 .error("Implementation error - load session from a running session is not supported.");
1982 setProgressBar(MessageManager.formatMessage(
1983 "status.importing_vamsas_session_from",
1984 new Object[] { file.getName() }), file.hashCode());
1987 v_client = new jalview.gui.VamsasApplication(this, file, null);
1988 } catch (Exception ex)
1990 setProgressBar(MessageManager.formatMessage(
1991 "status.importing_vamsas_session_from",
1992 new Object[] { file.getName() }), file.hashCode());
1993 jalview.bin.Cache.log.error(
1994 "New vamsas session from existing session file failed:", ex);
1997 setupVamsasConnectedGui();
1998 v_client.initial_update(); // TODO: thread ?
1999 setProgressBar(MessageManager.formatMessage(
2000 "status.importing_vamsas_session_from",
2001 new Object[] { file.getName() }), file.hashCode());
2002 return v_client.inSession();
2005 public boolean joinVamsasSession(String mysesid)
2007 if (v_client != null)
2011 .getString("error.try_join_vamsas_session_another"));
2013 if (mysesid == null)
2016 MessageManager.getString("error.invalid_vamsas_session_id"));
2018 v_client = new VamsasApplication(this, mysesid);
2019 setupVamsasConnectedGui();
2020 v_client.initial_update();
2021 return (v_client.inSession());
2025 public void vamsasStart_actionPerformed(ActionEvent e)
2027 if (v_client == null)
2030 // we just start a default session for moment.
2032 * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2033 * getProperty("LAST_DIRECTORY"));
2035 * chooser.setFileView(new JalviewFileView());
2036 * chooser.setDialogTitle("Load Vamsas file");
2037 * chooser.setToolTipText("Import");
2039 * int value = chooser.showOpenDialog(this);
2041 * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
2042 * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
2044 v_client = new VamsasApplication(this);
2045 setupVamsasConnectedGui();
2046 v_client.initial_update(); // TODO: thread ?
2050 // store current data in session.
2051 v_client.push_update(); // TODO: thread
2055 protected void setupVamsasConnectedGui()
2057 vamsasStart.setText(MessageManager.getString("label.session_update"));
2058 vamsasSave.setVisible(true);
2059 vamsasStop.setVisible(true);
2060 vamsasImport.setVisible(false); // Document import to existing session is
2061 // not possible for vamsas-client-1.0.
2064 protected void setupVamsasDisconnectedGui()
2066 vamsasSave.setVisible(false);
2067 vamsasStop.setVisible(false);
2068 vamsasImport.setVisible(true);
2069 vamsasStart.setText(MessageManager
2070 .getString("label.new_vamsas_session"));
2074 public void vamsasStop_actionPerformed(ActionEvent e)
2076 if (v_client != null)
2078 v_client.end_session();
2080 setupVamsasDisconnectedGui();
2084 protected void buildVamsasStMenu()
2086 if (v_client == null)
2088 String[] sess = null;
2091 sess = VamsasApplication.getSessionList();
2092 } catch (Exception e)
2094 jalview.bin.Cache.log.warn(
2095 "Problem getting current sessions list.", e);
2100 jalview.bin.Cache.log.debug("Got current sessions list: "
2101 + sess.length + " entries.");
2102 VamsasStMenu.removeAll();
2103 for (int i = 0; i < sess.length; i++)
2105 JMenuItem sessit = new JMenuItem();
2106 sessit.setText(sess[i]);
2107 sessit.setToolTipText(MessageManager.formatMessage(
2108 "label.connect_to_session", new Object[] { sess[i] }));
2109 final Desktop dsktp = this;
2110 final String mysesid = sess[i];
2111 sessit.addActionListener(new ActionListener()
2115 public void actionPerformed(ActionEvent e)
2117 if (dsktp.v_client == null)
2119 Thread rthr = new Thread(new Runnable()
2125 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
2126 dsktp.setupVamsasConnectedGui();
2127 dsktp.v_client.initial_update();
2135 VamsasStMenu.add(sessit);
2137 // don't show an empty menu.
2138 VamsasStMenu.setVisible(sess.length > 0);
2143 jalview.bin.Cache.log.debug("No current vamsas sessions.");
2144 VamsasStMenu.removeAll();
2145 VamsasStMenu.setVisible(false);
2150 // Not interested in the content. Just hide ourselves.
2151 VamsasStMenu.setVisible(false);
2156 public void vamsasSave_actionPerformed(ActionEvent e)
2158 if (v_client != null)
2160 JalviewFileChooser chooser = new JalviewFileChooser(
2161 jalview.bin.Cache.getProperty("LAST_DIRECTORY"), new String[]
2162 { "vdj" }, // TODO: VAMSAS DOCUMENT EXTENSION is VDJ
2163 new String[] { "Vamsas Document" }, "Vamsas Document");
2165 chooser.setFileView(new JalviewFileView());
2166 chooser.setDialogTitle(MessageManager
2167 .getString("label.save_vamsas_document_archive"));
2169 int value = chooser.showSaveDialog(this);
2171 if (value == JalviewFileChooser.APPROVE_OPTION)
2173 java.io.File choice = chooser.getSelectedFile();
2174 JPanel progpanel = addProgressPanel(MessageManager.formatMessage(
2175 "label.saving_vamsas_doc",
2176 new Object[] { choice.getName() }));
2177 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice.getParent());
2178 String warnmsg = null;
2179 String warnttl = null;
2182 v_client.vclient.storeDocument(choice);
2185 warnttl = "Serious Problem saving Vamsas Document";
2186 warnmsg = ex.toString();
2187 jalview.bin.Cache.log.error("Error Whilst saving document to "
2190 } catch (Exception ex)
2192 warnttl = "Problem saving Vamsas Document.";
2193 warnmsg = ex.toString();
2194 jalview.bin.Cache.log.warn("Exception Whilst saving document to "
2198 removeProgressPanel(progpanel);
2199 if (warnmsg != null)
2201 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2203 warnmsg, warnttl, JOptionPane.ERROR_MESSAGE);
2209 JPanel vamUpdate = null;
2212 * hide vamsas user gui bits when a vamsas document event is being handled.
2215 * true to hide gui, false to reveal gui
2217 public void setVamsasUpdate(boolean b)
2219 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "
2220 + (b ? "in progress" : "finished"));
2222 if (vamUpdate != null)
2224 this.removeProgressPanel(vamUpdate);
2228 vamUpdate = this.addProgressPanel(MessageManager
2229 .getString("label.updating_vamsas_session"));
2231 vamsasStart.setVisible(!b);
2232 vamsasStop.setVisible(!b);
2233 vamsasSave.setVisible(!b);
2236 public JInternalFrame[] getAllFrames()
2238 return desktop.getAllFrames();
2242 * Checks the given url to see if it gives a response indicating that the user
2243 * should be informed of a new questionnaire.
2247 public void checkForQuestionnaire(String url)
2249 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
2250 // javax.swing.SwingUtilities.invokeLater(jvq);
2251 new Thread(jvq).start();
2255 * Proxy class for JDesktopPane which optionally displays the current memory
2256 * usage and highlights the desktop area with a red bar if free memory runs
2261 public class MyDesktopPane extends JDesktopPane implements Runnable
2264 private static final float ONE_MB = 1048576f;
2266 boolean showMemoryUsage = false;
2270 java.text.NumberFormat df;
2272 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
2275 public MyDesktopPane(boolean showMemoryUsage)
2277 showMemoryUsage(showMemoryUsage);
2280 public void showMemoryUsage(boolean showMemory)
2282 this.showMemoryUsage = showMemory;
2285 Thread worker = new Thread(this);
2290 public boolean isShowMemoryUsage()
2292 return showMemoryUsage;
2298 df = java.text.NumberFormat.getNumberInstance();
2299 df.setMaximumFractionDigits(2);
2300 runtime = Runtime.getRuntime();
2302 while (showMemoryUsage)
2306 maxMemory = runtime.maxMemory() / ONE_MB;
2307 allocatedMemory = runtime.totalMemory() / ONE_MB;
2308 freeMemory = runtime.freeMemory() / ONE_MB;
2309 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
2311 percentUsage = (totalFreeMemory / maxMemory) * 100;
2313 // if (percentUsage < 20)
2315 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12,
2317 // instance.set.setBorder(border1);
2320 // sleep after showing usage
2322 } catch (Exception ex)
2324 ex.printStackTrace();
2330 public void paintComponent(Graphics g)
2332 if (showMemoryUsage && g != null && df != null)
2334 if (percentUsage < 20)
2336 g.setColor(Color.red);
2338 FontMetrics fm = g.getFontMetrics();
2341 g.drawString(MessageManager.formatMessage(
2342 "label.memory_stats",
2343 new Object[] { df.format(totalFreeMemory),
2344 df.format(maxMemory), df.format(percentUsage) }), 10,
2345 getHeight() - fm.getHeight());
2352 * fixes stacking order after a modal dialog to ensure windows that should be
2353 * on top actually are
2355 public void relayerWindows()
2360 protected JMenuItem groovyShell;
2363 * Accessor method to quickly get all the AlignmentFrames loaded.
2365 * @return an array of AlignFrame, or null if none found
2367 public static AlignFrame[] getAlignFrames()
2369 if (Jalview.isHeadlessMode())
2371 // Desktop.desktop is null in headless mode
2372 return new AlignFrame[] { Jalview.currentAlignFrame };
2375 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
2381 List<AlignFrame> avp = new ArrayList<AlignFrame>();
2383 for (int i = frames.length - 1; i > -1; i--)
2385 if (frames[i] instanceof AlignFrame)
2387 avp.add((AlignFrame) frames[i]);
2389 else if (frames[i] instanceof SplitFrame)
2392 * Also check for a split frame containing an AlignFrame
2394 GSplitFrame sf = (GSplitFrame) frames[i];
2395 if (sf.getTopFrame() instanceof AlignFrame)
2397 avp.add((AlignFrame) sf.getTopFrame());
2399 if (sf.getBottomFrame() instanceof AlignFrame)
2401 avp.add((AlignFrame) sf.getBottomFrame());
2405 if (avp.size() == 0)
2409 AlignFrame afs[] = avp.toArray(new AlignFrame[avp.size()]);
2414 * Returns an array of any AppJmol frames in the Desktop (or null if none).
2418 public GStructureViewer[] getJmols()
2420 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
2426 List<GStructureViewer> avp = new ArrayList<GStructureViewer>();
2428 for (int i = frames.length - 1; i > -1; i--)
2430 if (frames[i] instanceof AppJmol)
2432 GStructureViewer af = (GStructureViewer) frames[i];
2436 if (avp.size() == 0)
2440 GStructureViewer afs[] = avp.toArray(new GStructureViewer[avp.size()]);
2445 * Add Groovy Support to Jalview
2447 public void groovyShell_actionPerformed()
2451 openGroovyConsole();
2452 } catch (Exception ex)
2454 jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
2455 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2457 MessageManager.getString("label.couldnt_create_groovy_shell"),
2458 MessageManager.getString("label.groovy_support_failed"),
2459 JOptionPane.ERROR_MESSAGE);
2464 * Open the Groovy console
2466 void openGroovyConsole()
2468 groovyConsole = new groovy.ui.Console();
2471 * bind groovy variable 'Jalview' to the Desktop object
2473 groovyConsole.setVariable("Jalview", this);
2478 groovyConsole.run();
2481 * Allow only one console at a time, so that the AlignFrame menu option
2482 * 'Calculate | Run Groovy script' is unambiguous.
2483 * Disable 'new console', and enable 'Run script', when the console is
2484 * opened, and the reverse when it is closed
2486 Window window = (Window) groovyConsole.getFrame();
2487 window.addWindowListener(new WindowAdapter()
2490 public void windowClosed(WindowEvent e)
2492 enableExecuteGroovy(false);
2497 * if we got this far, enable 'Run Groovy' in AlignFrame menus
2498 * and disable opening a second console
2500 enableExecuteGroovy(true);
2504 * Enable or disable 'Run Groovy script' in AlignFrame calculate menus
2507 * true if Groovy console is open
2509 public void enableExecuteGroovy(boolean enabled)
2512 * disable opening a second Groovy console
2513 * (or re-enable when the console is closed)
2515 groovyShell.setEnabled(!enabled);
2517 AlignFrame[] alignFrames = getAlignFrames();
2518 if (alignFrames != null)
2520 for (AlignFrame af : alignFrames)
2522 af.setGroovyEnabled(enabled);
2528 * Progress bars managed by the IProgressIndicator method.
2530 private Hashtable<Long, JPanel> progressBars;
2532 private Hashtable<Long, IProgressIndicatorHandler> progressBarHandlers;
2537 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
2540 public void setProgressBar(String message, long id)
2542 if (progressBars == null)
2544 progressBars = new Hashtable<Long, JPanel>();
2545 progressBarHandlers = new Hashtable<Long, IProgressIndicatorHandler>();
2548 if (progressBars.get(new Long(id)) != null)
2550 JPanel panel = progressBars.remove(new Long(id));
2551 if (progressBarHandlers.contains(new Long(id)))
2553 progressBarHandlers.remove(new Long(id));
2555 removeProgressPanel(panel);
2559 progressBars.put(new Long(id), addProgressPanel(message));
2566 * @see jalview.gui.IProgressIndicator#registerHandler(long,
2567 * jalview.gui.IProgressIndicatorHandler)
2570 public void registerHandler(final long id,
2571 final IProgressIndicatorHandler handler)
2573 if (progressBarHandlers == null
2574 || !progressBars.containsKey(new Long(id)))
2578 .getString("error.call_setprogressbar_before_registering_handler"));
2580 progressBarHandlers.put(new Long(id), handler);
2581 final JPanel progressPanel = progressBars.get(new Long(id));
2582 if (handler.canCancel())
2584 JButton cancel = new JButton(
2585 MessageManager.getString("action.cancel"));
2586 final IProgressIndicator us = this;
2587 cancel.addActionListener(new ActionListener()
2591 public void actionPerformed(ActionEvent e)
2593 handler.cancelActivity(id);
2594 us.setProgressBar(MessageManager.formatMessage(
2595 "label.cancelled_params",
2596 new Object[] { ((JLabel) progressPanel.getComponent(0))
2600 progressPanel.add(cancel, BorderLayout.EAST);
2606 * @return true if any progress bars are still active
2609 public boolean operationInProgress()
2611 if (progressBars != null && progressBars.size() > 0)
2619 * This will return the first AlignFrame holding the given viewport instance.
2620 * It will break if there are more than one AlignFrames viewing a particular
2624 * @return alignFrame for viewport
2626 public static AlignFrame getAlignFrameFor(AlignViewportI viewport)
2628 if (desktop != null)
2630 AlignmentPanel[] aps = getAlignmentPanels(viewport.getSequenceSetId());
2631 for (int panel = 0; aps != null && panel < aps.length; panel++)
2633 if (aps[panel] != null && aps[panel].av == viewport)
2635 return aps[panel].alignFrame;
2642 public VamsasApplication getVamsasApplication()
2649 * flag set if jalview GUI is being operated programmatically
2651 private boolean inBatchMode = false;
2654 * check if jalview GUI is being operated programmatically
2656 * @return inBatchMode
2658 public boolean isInBatchMode()
2664 * set flag if jalview GUI is being operated programmatically
2666 * @param inBatchMode
2668 public void setInBatchMode(boolean inBatchMode)
2670 this.inBatchMode = inBatchMode;
2673 public void startServiceDiscovery()
2675 startServiceDiscovery(false);
2678 public void startServiceDiscovery(boolean blocking)
2680 boolean alive = true;
2681 Thread t0 = null, t1 = null, t2 = null;
2682 // JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
2685 // todo: changesupport handlers need to be transferred
2686 if (discoverer == null)
2688 discoverer = new jalview.ws.jws1.Discoverer();
2689 // register PCS handler for desktop.
2690 discoverer.addPropertyChangeListener(changeSupport);
2692 // JAL-940 - disabled JWS1 service configuration - always start discoverer
2693 // until we phase out completely
2694 (t0 = new Thread(discoverer)).start();
2697 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
2699 if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning())
2701 jalview.ws.jws2.Jws2Discoverer.getDiscoverer().setAborted(true);
2703 t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(
2709 // TODO: do rest service discovery
2718 } catch (Exception e)
2721 alive = (t1 != null && t1.isAlive())
2722 || (t2 != null && t2.isAlive())
2723 || (t3 != null && t3.isAlive())
2724 || (t0 != null && t0.isAlive());
2730 * called to check if the service discovery process completed successfully.
2734 protected void JalviewServicesChanged(PropertyChangeEvent evt)
2736 if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
2738 final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
2739 .getErrorMessages();
2742 if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
2744 if (serviceChangedDialog == null)
2746 // only run if we aren't already displaying one of these.
2747 addDialogThread(serviceChangedDialog = new Runnable()
2754 * JalviewDialog jd =new JalviewDialog() {
2756 * @Override protected void cancelPressed() { // TODO
2757 * Auto-generated method stub
2759 * }@Override protected void okPressed() { // TODO
2760 * Auto-generated method stub
2762 * }@Override protected void raiseClosed() { // TODO
2763 * Auto-generated method stub
2765 * } }; jd.initDialogFrame(new
2766 * JLabel("<html><table width=\"450\"><tr><td>" + ermsg +
2767 * "<br/>It may be that you have invalid JABA URLs in your web service preferences,"
2768 * + " or mis-configured HTTP proxy settings.<br/>" +
2769 * "Check the <em>Connections</em> and <em>Web services</em> tab of the"
2771 * " Tools->Preferences dialog box to change them.</td></tr></table></html>"
2772 * ), true, true, "Web Service Configuration Problem", 450,
2775 * jd.waitForInput();
2781 "<html><table width=\"450\"><tr><td>"
2783 + "</td></tr></table>"
2784 + "<p>It may be that you have invalid JABA URLs<br/>in your web service preferences,"
2785 + "<br>or as a command-line argument, or mis-configured HTTP proxy settings.</p>"
2786 + "<p>Check the <em>Connections</em> and <em>Web services</em> tab<br/>of the"
2787 + " Tools->Preferences dialog box to change them.</p></html>"),
2788 "Web Service Configuration Problem",
2789 JOptionPane.DEFAULT_OPTION,
2790 JOptionPane.ERROR_MESSAGE);
2791 serviceChangedDialog = null;
2800 .error("Errors reported by JABA discovery service. Check web services preferences.\n"
2807 private Runnable serviceChangedDialog = null;
2810 * start a thread to open a URL in the configured browser. Pops up a warning
2811 * dialog to the user if there is an exception when calling out to the browser
2816 public static void showUrl(final String url)
2818 showUrl(url, Desktop.instance);
2822 * Like showUrl but allows progress handler to be specified
2826 * (null) or object implementing IProgressIndicator
2828 public static void showUrl(final String url,
2829 final IProgressIndicator progress)
2831 new Thread(new Runnable()
2838 if (progress != null)
2840 progress.setProgressBar(MessageManager.formatMessage(
2841 "status.opening_params", new Object[] { url }), this
2844 jalview.util.BrowserLauncher.openURL(url);
2845 } catch (Exception ex)
2847 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2849 .getString("label.web_browser_not_found_unix"),
2850 MessageManager.getString("label.web_browser_not_found"),
2851 JOptionPane.WARNING_MESSAGE);
2853 ex.printStackTrace();
2855 if (progress != null)
2857 progress.setProgressBar(null, this.hashCode());
2863 public static WsParamSetManager wsparamManager = null;
2865 public static ParamManager getUserParameterStore()
2867 if (wsparamManager == null)
2869 wsparamManager = new WsParamSetManager();
2871 return wsparamManager;
2875 * static hyperlink handler proxy method for use by Jalview's internal windows
2879 public static void hyperlinkUpdate(HyperlinkEvent e)
2881 if (e.getEventType() == EventType.ACTIVATED)
2886 url = e.getURL().toString();
2887 Desktop.showUrl(url);
2888 } catch (Exception x)
2892 if (Cache.log != null)
2894 Cache.log.error("Couldn't handle string " + url + " as a URL.");
2898 System.err.println("Couldn't handle string " + url
2902 // ignore any exceptions due to dud links.
2909 * single thread that handles display of dialogs to user.
2911 ExecutorService dialogExecutor = Executors.newSingleThreadExecutor();
2914 * flag indicating if dialogExecutor should try to acquire a permit
2916 private volatile boolean dialogPause = true;
2921 private java.util.concurrent.Semaphore block = new Semaphore(0);
2923 private static groovy.ui.Console groovyConsole;
2926 * add another dialog thread to the queue
2930 public void addDialogThread(final Runnable prompter)
2932 dialogExecutor.submit(new Runnable()
2942 } catch (InterruptedException x)
2947 if (instance == null)
2953 SwingUtilities.invokeAndWait(prompter);
2954 } catch (Exception q)
2956 Cache.log.warn("Unexpected Exception in dialog thread.", q);
2962 public void startDialogQueue()
2964 // set the flag so we don't pause waiting for another permit and semaphore
2965 // the current task to begin
2966 dialogPause = false;
2971 protected void snapShotWindow_actionPerformed(ActionEvent e)
2975 ImageMaker im = new jalview.util.ImageMaker(this, ImageMaker.TYPE.EPS,
2976 "View of Desktop", getWidth(), getHeight(), of = new File(
2977 "Jalview_snapshot" + System.currentTimeMillis()
2978 + ".eps"), "View of desktop", null, 0, false);
2981 paintAll(im.getGraphics());
2983 } catch (Exception q)
2985 Cache.log.error("Couldn't write snapshot to " + of.getAbsolutePath(),
2989 Cache.log.info("Successfully written snapshot to file "
2990 + of.getAbsolutePath());
2994 * Explode the views in the given SplitFrame into separate SplitFrame windows.
2995 * This respects (remembers) any previous 'exploded geometry' i.e. the size
2996 * and location last time the view was expanded (if any). However it does not
2997 * remember the split pane divider location - this is set to match the
2998 * 'exploding' frame.
3002 public void explodeViews(SplitFrame sf)
3004 AlignFrame oldTopFrame = (AlignFrame) sf.getTopFrame();
3005 AlignFrame oldBottomFrame = (AlignFrame) sf.getBottomFrame();
3006 List<? extends AlignmentViewPanel> topPanels = oldTopFrame
3008 List<? extends AlignmentViewPanel> bottomPanels = oldBottomFrame
3010 int viewCount = topPanels.size();
3017 * Processing in reverse order works, forwards order leaves the first panels
3018 * not visible. I don't know why!
3020 for (int i = viewCount - 1; i >= 0; i--)
3023 * Make new top and bottom frames. These take over the respective
3024 * AlignmentPanel objects, including their AlignmentViewports, so the
3025 * cdna/protein relationships between the viewports is carried over to the
3028 * explodedGeometry holds the (x, y) position of the previously exploded
3029 * SplitFrame, and the (width, height) of the AlignFrame component
3031 AlignmentPanel topPanel = (AlignmentPanel) topPanels.get(i);
3032 AlignFrame newTopFrame = new AlignFrame(topPanel);
3033 newTopFrame.setSize(oldTopFrame.getSize());
3034 newTopFrame.setVisible(true);
3035 Rectangle geometry = ((AlignViewport) topPanel.getAlignViewport())
3036 .getExplodedGeometry();
3037 if (geometry != null)
3039 newTopFrame.setSize(geometry.getSize());
3042 AlignmentPanel bottomPanel = (AlignmentPanel) bottomPanels.get(i);
3043 AlignFrame newBottomFrame = new AlignFrame(bottomPanel);
3044 newBottomFrame.setSize(oldBottomFrame.getSize());
3045 newBottomFrame.setVisible(true);
3046 geometry = ((AlignViewport) bottomPanel.getAlignViewport())
3047 .getExplodedGeometry();
3048 if (geometry != null)
3050 newBottomFrame.setSize(geometry.getSize());
3053 topPanel.av.setGatherViewsHere(false);
3054 bottomPanel.av.setGatherViewsHere(false);
3055 JInternalFrame splitFrame = new SplitFrame(newTopFrame,
3057 if (geometry != null)
3059 splitFrame.setLocation(geometry.getLocation());
3061 Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1);
3065 * Clear references to the panels (now relocated in the new SplitFrames)
3066 * before closing the old SplitFrame.
3069 bottomPanels.clear();
3074 * Gather expanded split frames, sharing the same pairs of sequence set ids,
3075 * back into the given SplitFrame as additional views. Note that the gathered
3076 * frames may themselves have multiple views.
3080 public void gatherViews(GSplitFrame source)
3083 * special handling of explodedGeometry for a view within a SplitFrame: - it
3084 * holds the (x, y) position of the enclosing SplitFrame, and the (width,
3085 * height) of the AlignFrame component
3087 AlignFrame myTopFrame = (AlignFrame) source.getTopFrame();
3088 AlignFrame myBottomFrame = (AlignFrame) source.getBottomFrame();
3089 myTopFrame.viewport.setExplodedGeometry(new Rectangle(source.getX(),
3090 source.getY(), myTopFrame.getWidth(), myTopFrame.getHeight()));
3091 myBottomFrame.viewport.setExplodedGeometry(new Rectangle(source.getX(),
3092 source.getY(), myBottomFrame.getWidth(), myBottomFrame
3094 myTopFrame.viewport.setGatherViewsHere(true);
3095 myBottomFrame.viewport.setGatherViewsHere(true);
3096 String topViewId = myTopFrame.viewport.getSequenceSetId();
3097 String bottomViewId = myBottomFrame.viewport.getSequenceSetId();
3099 JInternalFrame[] frames = desktop.getAllFrames();
3100 for (JInternalFrame frame : frames)
3102 if (frame instanceof SplitFrame && frame != source)
3104 SplitFrame sf = (SplitFrame) frame;
3105 AlignFrame topFrame = (AlignFrame) sf.getTopFrame();
3106 AlignFrame bottomFrame = (AlignFrame) sf.getBottomFrame();
3107 boolean gatherThis = false;
3108 for (int a = 0; a < topFrame.alignPanels.size(); a++)
3110 AlignmentPanel topPanel = topFrame.alignPanels.get(a);
3111 AlignmentPanel bottomPanel = bottomFrame.alignPanels.get(a);
3112 if (topViewId.equals(topPanel.av.getSequenceSetId())
3113 && bottomViewId.equals(bottomPanel.av.getSequenceSetId()))
3116 topPanel.av.setGatherViewsHere(false);
3117 bottomPanel.av.setGatherViewsHere(false);
3118 topPanel.av.setExplodedGeometry(new Rectangle(sf.getLocation(),
3119 topFrame.getSize()));
3120 bottomPanel.av.setExplodedGeometry(new Rectangle(sf
3121 .getLocation(), bottomFrame.getSize()));
3122 myTopFrame.addAlignmentPanel(topPanel, false);
3123 myBottomFrame.addAlignmentPanel(bottomPanel, false);
3129 topFrame.getAlignPanels().clear();
3130 bottomFrame.getAlignPanels().clear();
3137 * The dust settles...give focus to the tab we did this from.
3139 myTopFrame.setDisplayedView(myTopFrame.alignPanel);
3142 public static groovy.ui.Console getGroovyConsole()
3144 return groovyConsole;
3147 public static void transferFromDropTarget(List<String> files,
3148 List<String> protocols, DropTargetDropEvent evt, Transferable t)
3152 DataFlavor uriListFlavor = new DataFlavor(
3153 "text/uri-list;class=java.lang.String");
3154 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3156 // Works on Windows and MacOSX
3157 Cache.log.debug("Drop handled as javaFileListFlavor");
3158 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3159 for (Object file : (List) t
3160 .getTransferData(DataFlavor.javaFileListFlavor))
3162 files.add(((File)file).toString());
3163 protocols.add(FormatAdapter.FILE);
3168 // Unix like behaviour
3169 boolean added = false;
3171 if (t.isDataFlavorSupported(uriListFlavor))
3173 Cache.log.debug("Drop handled as uriListFlavor");
3174 // This is used by Unix drag system
3175 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3176 data = (String) t.getTransferData(uriListFlavor);
3180 // fallback to text: workaround - on OSX where there's a JVM bug
3181 Cache.log.debug("standard URIListFlavor failed. Trying text");
3182 // try text fallback
3183 data = (String) t.getTransferData(new DataFlavor(
3184 "text/plain;class=java.lang.String"));
3185 if (Cache.log.isDebugEnabled())
3187 Cache.log.debug("fallback returned " + data);
3190 while (protocols.size() < files.size())
3192 Cache.log.debug("Adding missing FILE protocol for "
3193 + files.get(protocols.size()));
3194 protocols.add(FormatAdapter.FILE);
3196 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3197 data, "\r\n"); st.hasMoreTokens();)
3200 String s = st.nextToken();
3201 if (s.startsWith("#"))
3203 // the line is a comment (as per the RFC 2483)
3206 java.net.URI uri = new java.net.URI(s);
3207 if (uri.getScheme().toLowerCase().startsWith("http"))
3209 protocols.add(FormatAdapter.URL);
3210 files.add(uri.toString());
3214 // otherwise preserve old behaviour: catch all for file objects
3215 java.io.File file = new java.io.File(uri);
3216 protocols.add(FormatAdapter.FILE);
3217 files.add(file.toString());
3220 if (Cache.log.isDebugEnabled())
3222 if (data == null || !added)
3225 .debug("Couldn't resolve drop data. Here are the supported flavors:");
3226 for (DataFlavor fl : t.getTransferDataFlavors())
3228 Cache.log.debug("Supported transfer dataflavor: "
3230 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3231 Object df = t.getTransferData(fl);
3234 Cache.log.debug("Retrieves: " + df);
3238 Cache.log.debug("Retrieved nothing");