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.DataSourceType;
28 import jalview.io.FileFormat;
29 import jalview.io.FileFormatException;
30 import jalview.io.FileFormatI;
31 import jalview.io.FileLoader;
32 import jalview.io.IdentifyFile;
33 import jalview.io.JalviewFileChooser;
34 import jalview.io.JalviewFileView;
35 import jalview.jbgui.GSplitFrame;
36 import jalview.jbgui.GStructureViewer;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.util.ImageMaker;
39 import jalview.util.MessageManager;
40 import jalview.util.Platform;
41 import jalview.viewmodel.AlignmentViewport;
42 import jalview.ws.params.ParamManager;
44 import java.awt.BorderLayout;
45 import java.awt.Color;
46 import java.awt.Dimension;
47 import java.awt.FontMetrics;
48 import java.awt.Graphics;
49 import java.awt.GridLayout;
50 import java.awt.Point;
51 import java.awt.Rectangle;
52 import java.awt.Toolkit;
53 import java.awt.Window;
54 import java.awt.datatransfer.Clipboard;
55 import java.awt.datatransfer.ClipboardOwner;
56 import java.awt.datatransfer.DataFlavor;
57 import java.awt.datatransfer.Transferable;
58 import java.awt.dnd.DnDConstants;
59 import java.awt.dnd.DropTargetDragEvent;
60 import java.awt.dnd.DropTargetDropEvent;
61 import java.awt.dnd.DropTargetEvent;
62 import java.awt.dnd.DropTargetListener;
63 import java.awt.event.ActionEvent;
64 import java.awt.event.ActionListener;
65 import java.awt.event.FocusEvent;
66 import java.awt.event.FocusListener;
67 import java.awt.event.KeyEvent;
68 import java.awt.event.MouseAdapter;
69 import java.awt.event.MouseEvent;
70 import java.awt.event.MouseListener;
71 import java.awt.event.WindowAdapter;
72 import java.awt.event.WindowEvent;
73 import java.beans.PropertyChangeEvent;
74 import java.beans.PropertyChangeListener;
75 import java.beans.PropertyVetoException;
76 import java.io.BufferedInputStream;
78 import java.io.FileOutputStream;
80 import java.util.ArrayList;
81 import java.util.Hashtable;
82 import java.util.List;
83 import java.util.StringTokenizer;
84 import java.util.Vector;
85 import java.util.concurrent.ExecutorService;
86 import java.util.concurrent.Executors;
87 import java.util.concurrent.Semaphore;
89 import javax.swing.AbstractAction;
90 import javax.swing.DefaultDesktopManager;
91 import javax.swing.DesktopManager;
92 import javax.swing.JButton;
93 import javax.swing.JComboBox;
94 import javax.swing.JComponent;
95 import javax.swing.JDesktopPane;
96 import javax.swing.JFrame;
97 import javax.swing.JInternalFrame;
98 import javax.swing.JLabel;
99 import javax.swing.JMenuItem;
100 import javax.swing.JOptionPane;
101 import javax.swing.JPanel;
102 import javax.swing.JPopupMenu;
103 import javax.swing.JProgressBar;
104 import javax.swing.KeyStroke;
105 import javax.swing.SwingUtilities;
106 import javax.swing.event.HyperlinkEvent;
107 import javax.swing.event.HyperlinkEvent.EventType;
108 import javax.swing.event.MenuEvent;
109 import javax.swing.event.MenuListener;
116 * @version $Revision: 1.155 $
118 public class Desktop extends jalview.jbgui.GDesktop implements
119 DropTargetListener, ClipboardOwner, IProgressIndicator,
120 jalview.api.StructureSelectionManagerProvider
123 private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
126 * news reader - null if it was never started.
128 private BlogReader jvnews = null;
130 private File projectFile;
134 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
136 public void addJalviewPropertyChangeListener(
137 PropertyChangeListener listener)
139 changeSupport.addJalviewPropertyChangeListener(listener);
143 * @param propertyName
145 * @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
146 * java.beans.PropertyChangeListener)
148 public void addJalviewPropertyChangeListener(String propertyName,
149 PropertyChangeListener listener)
151 changeSupport.addJalviewPropertyChangeListener(propertyName, listener);
155 * @param propertyName
157 * @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
158 * java.beans.PropertyChangeListener)
160 public void removeJalviewPropertyChangeListener(String propertyName,
161 PropertyChangeListener listener)
163 changeSupport.removeJalviewPropertyChangeListener(propertyName,
167 /** Singleton Desktop instance */
168 public static Desktop instance;
170 public static MyDesktopPane desktop;
172 static int openFrameCount = 0;
174 static final int xOffset = 30;
176 static final int yOffset = 30;
178 public static jalview.ws.jws1.Discoverer discoverer;
180 public static Object[] jalviewClipboard;
182 public static boolean internalCopy = false;
184 static int fileLoadingCount = 0;
186 class MyDesktopManager implements DesktopManager
189 private DesktopManager delegate;
191 public MyDesktopManager(DesktopManager delegate)
193 this.delegate = delegate;
197 public void activateFrame(JInternalFrame f)
201 delegate.activateFrame(f);
202 } catch (NullPointerException npe)
204 Point p = getMousePosition();
205 instance.showPasteMenu(p.x, p.y);
210 public void beginDraggingFrame(JComponent f)
212 delegate.beginDraggingFrame(f);
216 public void beginResizingFrame(JComponent f, int direction)
218 delegate.beginResizingFrame(f, direction);
222 public void closeFrame(JInternalFrame f)
224 delegate.closeFrame(f);
228 public void deactivateFrame(JInternalFrame f)
230 delegate.deactivateFrame(f);
234 public void deiconifyFrame(JInternalFrame f)
236 delegate.deiconifyFrame(f);
240 public void dragFrame(JComponent f, int newX, int newY)
246 delegate.dragFrame(f, newX, newY);
250 public void endDraggingFrame(JComponent f)
252 delegate.endDraggingFrame(f);
256 public void endResizingFrame(JComponent f)
258 delegate.endResizingFrame(f);
262 public void iconifyFrame(JInternalFrame f)
264 delegate.iconifyFrame(f);
268 public void maximizeFrame(JInternalFrame f)
270 delegate.maximizeFrame(f);
274 public void minimizeFrame(JInternalFrame f)
276 delegate.minimizeFrame(f);
280 public void openFrame(JInternalFrame f)
282 delegate.openFrame(f);
286 public void resizeFrame(JComponent f, int newX, int newY, int newWidth,
293 delegate.resizeFrame(f, newX, newY, newWidth, newHeight);
297 public void setBoundsForFrame(JComponent f, int newX, int newY,
298 int newWidth, int newHeight)
300 delegate.setBoundsForFrame(f, newX, newY, newWidth, newHeight);
303 // All other methods, simply delegate
308 * Creates a new Desktop object.
313 * A note to implementors. It is ESSENTIAL that any activities that might
314 * block are spawned off as threads rather than waited for during this
318 doVamsasClientCheck();
320 groovyShell = new JMenuItem();
321 groovyShell.setText(MessageManager.getString("label.groovy_console"));
322 groovyShell.addActionListener(new ActionListener()
325 public void actionPerformed(ActionEvent e)
327 groovyShell_actionPerformed();
330 toolsMenu.add(groovyShell);
331 groovyShell.setVisible(true);
333 doConfigureStructurePrefs();
334 setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
335 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
336 boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",
338 boolean showjconsole = jalview.bin.Cache.getDefault(
339 "SHOW_JAVA_CONSOLE", false);
340 desktop = new MyDesktopPane(selmemusage);
341 if (Platform.isAMac())
343 desktop.setDoubleBuffered(false);
345 showMemusage.setSelected(selmemusage);
346 desktop.setBackground(Color.white);
347 getContentPane().setLayout(new BorderLayout());
348 // alternate config - have scrollbars - see notes in JAL-153
349 // JScrollPane sp = new JScrollPane();
350 // sp.getViewport().setView(desktop);
351 // getContentPane().add(sp, BorderLayout.CENTER);
352 getContentPane().add(desktop, BorderLayout.CENTER);
353 desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
355 // This line prevents Windows Look&Feel resizing all new windows to maximum
356 // if previous window was maximised
357 desktop.setDesktopManager(new MyDesktopManager(
358 new DefaultDesktopManager()));
360 Rectangle dims = getLastKnownDimensions("");
367 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
368 setBounds((screenSize.width - 900) / 2,
369 (screenSize.height - 650) / 2, 900, 650);
371 jconsole = new Console(this, showjconsole);
372 // add essential build information
373 jconsole.setHeader("Jalview Version: "
374 + jalview.bin.Cache.getProperty("VERSION") + "\n"
375 + "Jalview Installation: "
376 + jalview.bin.Cache.getDefault("INSTALLATION", "unknown")
377 + "\n" + "Build Date: "
378 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
379 + "Java version: " + System.getProperty("java.version") + "\n"
380 + System.getProperty("os.arch") + " "
381 + System.getProperty("os.name") + " "
382 + System.getProperty("os.version"));
384 showConsole(showjconsole);
386 showNews.setVisible(false);
388 this.addWindowListener(new WindowAdapter()
391 public void windowClosing(WindowEvent evt)
398 this.addMouseListener(ma = new MouseAdapter()
401 public void mousePressed(MouseEvent evt)
403 if (evt.isPopupTrigger())
405 showPasteMenu(evt.getX(), evt.getY());
409 desktop.addMouseListener(ma);
411 this.addFocusListener(new FocusListener()
415 public void focusLost(FocusEvent e)
417 // TODO Auto-generated method stub
422 public void focusGained(FocusEvent e)
424 Cache.log.debug("Relaying windows after focus gain");
425 // make sure that we sort windows properly after we gain focus
426 instance.relayerWindows();
429 this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
430 // Spawn a thread that shows the splashscreen
431 SwingUtilities.invokeLater(new Runnable()
441 // Thread off a new instance of the file chooser - this reduces the time it
442 // takes to open it later on.
443 new Thread(new Runnable()
448 Cache.log.debug("Filechooser init thread started.");
449 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
450 JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"),
451 // jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
452 // jalview.io.AppletFormatAdapter.READABLE_FNAMES,
454 Cache.log.debug("Filechooser init thread finished.");
457 // Add the service change listener
458 changeSupport.addJalviewPropertyChangeListener("services",
459 new PropertyChangeListener()
463 public void propertyChange(PropertyChangeEvent evt)
465 Cache.log.debug("Firing service changed event for "
466 + evt.getNewValue());
467 JalviewServicesChanged(evt);
473 public void doConfigureStructurePrefs()
475 // configure services
476 StructureSelectionManager ssm = StructureSelectionManager
477 .getStructureSelectionManager(this);
478 if (jalview.bin.Cache.getDefault(Preferences.ADD_SS_ANN, true))
480 ssm.setAddTempFacAnnot(jalview.bin.Cache.getDefault(
481 Preferences.ADD_TEMPFACT_ANN, true));
482 ssm.setProcessSecondaryStructure(jalview.bin.Cache.getDefault(
483 Preferences.STRUCT_FROM_PDB, true));
484 ssm.setSecStructServices(jalview.bin.Cache.getDefault(
485 Preferences.USE_RNAVIEW, true));
489 ssm.setAddTempFacAnnot(false);
490 ssm.setProcessSecondaryStructure(false);
491 ssm.setSecStructServices(false);
495 public void checkForNews()
497 final Desktop me = this;
498 // Thread off the news reader, in case there are connection problems.
499 addDialogThread(new Runnable()
504 Cache.log.debug("Starting news thread.");
506 jvnews = new BlogReader(me);
507 showNews.setVisible(true);
508 Cache.log.debug("Completed news thread.");
514 protected void showNews_actionPerformed(ActionEvent e)
516 showNews(showNews.isSelected());
519 void showNews(boolean visible)
522 Cache.log.debug((visible ? "Showing" : "Hiding") + " news.");
523 showNews.setSelected(visible);
524 if (visible && !jvnews.isVisible())
526 new Thread(new Runnable()
531 long now = System.currentTimeMillis();
532 Desktop.instance.setProgressBar(
533 MessageManager.getString("status.refreshing_news"), now);
534 jvnews.refreshNews();
535 Desktop.instance.setProgressBar(null, now);
544 * recover the last known dimensions for a jalview window
547 * - empty string is desktop, all other windows have unique prefix
548 * @return null or last known dimensions scaled to current geometry (if last
549 * window geom was known)
551 Rectangle getLastKnownDimensions(String windowName)
553 // TODO: lock aspect ratio for scaling desktop Bug #0058199
554 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
555 String x = jalview.bin.Cache.getProperty(windowName + "SCREEN_X");
556 String y = jalview.bin.Cache.getProperty(windowName + "SCREEN_Y");
557 String width = jalview.bin.Cache.getProperty(windowName
559 String height = jalview.bin.Cache.getProperty(windowName
561 if ((x != null) && (y != null) && (width != null) && (height != null))
563 int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer
564 .parseInt(width), ih = Integer.parseInt(height);
565 if (jalview.bin.Cache.getProperty("SCREENGEOMETRY_WIDTH") != null)
567 // attempt #1 - try to cope with change in screen geometry - this
568 // version doesn't preserve original jv aspect ratio.
569 // take ratio of current screen size vs original screen size.
570 double sw = ((1f * screenSize.width) / (1f * Integer
571 .parseInt(jalview.bin.Cache
572 .getProperty("SCREENGEOMETRY_WIDTH"))));
573 double sh = ((1f * screenSize.height) / (1f * Integer
574 .parseInt(jalview.bin.Cache
575 .getProperty("SCREENGEOMETRY_HEIGHT"))));
576 // rescale the bounds depending upon the current screen geometry.
577 ix = (int) (ix * sw);
578 iw = (int) (iw * sw);
579 iy = (int) (iy * sh);
580 ih = (int) (ih * sh);
581 while (ix >= screenSize.width)
583 jalview.bin.Cache.log
584 .debug("Window geometry location recall error: shifting horizontal to within screenbounds.");
585 ix -= screenSize.width;
587 while (iy >= screenSize.height)
589 jalview.bin.Cache.log
590 .debug("Window geometry location recall error: shifting vertical to within screenbounds.");
591 iy -= screenSize.height;
593 jalview.bin.Cache.log.debug("Got last known dimensions for "
594 + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
597 // return dimensions for new instance
598 return new Rectangle(ix, iy, iw, ih);
603 private void doVamsasClientCheck()
605 if (jalview.bin.Cache.vamsasJarsPresent())
607 setupVamsasDisconnectedGui();
608 VamsasMenu.setVisible(true);
609 final Desktop us = this;
610 VamsasMenu.addMenuListener(new MenuListener()
612 // this listener remembers when the menu was first selected, and
613 // doesn't rebuild the session list until it has been cleared and
615 boolean refresh = true;
618 public void menuCanceled(MenuEvent e)
624 public void menuDeselected(MenuEvent e)
630 public void menuSelected(MenuEvent e)
634 us.buildVamsasStMenu();
639 vamsasStart.setVisible(true);
643 void showPasteMenu(int x, int y)
645 JPopupMenu popup = new JPopupMenu();
646 JMenuItem item = new JMenuItem(
647 MessageManager.getString("label.paste_new_window"));
648 item.addActionListener(new ActionListener()
651 public void actionPerformed(ActionEvent evt)
658 popup.show(this, x, y);
665 Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
666 Transferable contents = c.getContents(this);
668 if (contents != null)
670 String file = (String) contents
671 .getTransferData(DataFlavor.stringFlavor);
673 FileFormatI format = new IdentifyFile().identify(file,
674 DataSourceType.PASTE);
676 new FileLoader().LoadFile(file, DataSourceType.PASTE, format);
679 } catch (Exception ex)
682 .println("Unable to paste alignment from system clipboard:\n"
688 * Adds and opens the given frame to the desktop
699 public static synchronized void addInternalFrame(
700 final JInternalFrame frame, String title, int w, int h)
702 addInternalFrame(frame, title, true, w, h, true);
706 * Add an internal frame to the Jalview desktop
713 * When true, display frame immediately, otherwise, caller must call
714 * setVisible themselves.
720 public static synchronized void addInternalFrame(
721 final JInternalFrame frame, String title, boolean makeVisible,
724 addInternalFrame(frame, title, makeVisible, w, h, true);
728 * Add an internal frame to the Jalview desktop and make it visible
741 public static synchronized void addInternalFrame(
742 final JInternalFrame frame, String title, int w, int h,
745 addInternalFrame(frame, title, true, w, h, resizable);
749 * Add an internal frame to the Jalview desktop
756 * When true, display frame immediately, otherwise, caller must call
757 * setVisible themselves.
765 public static synchronized void addInternalFrame(
766 final JInternalFrame frame, String title, boolean makeVisible,
767 int w, int h, boolean resizable)
770 // TODO: allow callers to determine X and Y position of frame (eg. via
772 // TODO: consider fixing method to update entries in the window submenu with
773 // the current window title
775 frame.setTitle(title);
776 if (frame.getWidth() < 1 || frame.getHeight() < 1)
780 // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
781 // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
782 // IF JALVIEW IS RUNNING HEADLESS
783 // ///////////////////////////////////////////////
785 || (System.getProperty("java.awt.headless") != null && System
786 .getProperty("java.awt.headless").equals("true")))
793 frame.setVisible(makeVisible);
794 frame.setClosable(true);
795 frame.setResizable(resizable);
796 frame.setMaximizable(resizable);
797 frame.setIconifiable(resizable);
798 if (Platform.isAMac())
800 frame.setIconifiable(false);
801 frame.setFrameIcon(null);
802 // frame.setDesktopIcon(null);
803 frame.setDoubleBuffered(false);
805 if (frame.getX() < 1 && frame.getY() < 1)
807 frame.setLocation(xOffset * openFrameCount, yOffset
808 * ((openFrameCount - 1) % 10) + yOffset);
811 final JMenuItem menuItem = new JMenuItem(title);
812 frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter()
815 public void internalFrameActivated(
816 javax.swing.event.InternalFrameEvent evt)
818 JInternalFrame itf = desktop.getSelectedFrame();
827 public void internalFrameClosed(
828 javax.swing.event.InternalFrameEvent evt)
830 PaintRefresher.RemoveComponent(frame);
832 windowMenu.remove(menuItem);
833 JInternalFrame itf = desktop.getSelectedFrame();
842 menuItem.addActionListener(new ActionListener()
845 public void actionPerformed(ActionEvent e)
849 frame.setSelected(true);
850 frame.setIcon(false);
851 } catch (java.beans.PropertyVetoException ex)
857 menuItem.addMouseListener(new MouseListener()
861 public void mouseReleased(MouseEvent e)
866 public void mousePressed(MouseEvent e)
871 public void mouseExited(MouseEvent e)
875 frame.setSelected(false);
876 } catch (PropertyVetoException e1)
882 public void mouseEntered(MouseEvent e)
886 frame.setSelected(true);
887 } catch (PropertyVetoException e1)
893 public void mouseClicked(MouseEvent e)
899 windowMenu.add(menuItem);
905 frame.setSelected(true);
906 frame.requestFocus();
907 } catch (java.beans.PropertyVetoException ve)
909 } catch (java.lang.ClassCastException cex)
912 .warn("Squashed a possible GUI implementation error. If you can recreate this, please look at http://issues.jalview.org/browse/JAL-869",
918 public void lostOwnership(Clipboard clipboard, Transferable contents)
922 Desktop.jalviewClipboard = null;
925 internalCopy = false;
929 public void dragEnter(DropTargetDragEvent evt)
934 public void dragExit(DropTargetEvent evt)
939 public void dragOver(DropTargetDragEvent evt)
944 public void dropActionChanged(DropTargetDragEvent evt)
955 public void drop(DropTargetDropEvent evt)
957 boolean success = true;
958 Transferable t = evt.getTransferable();
959 List<String> files = new ArrayList<String>();
960 List<DataSourceType> protocols = new ArrayList<DataSourceType>();
964 Desktop.transferFromDropTarget(files, protocols, evt, t);
965 } catch (Exception e)
975 for (int i = 0; i < files.size(); i++)
977 String file = files.get(i).toString();
978 DataSourceType protocol = (protocols == null) ? DataSourceType.FILE
980 FileFormatI format = null;
982 if (file.endsWith(".jar"))
984 format = FileFormat.Jalview;
989 format = new IdentifyFile().identify(file, protocol);
992 new FileLoader().LoadFile(file, protocol, format);
995 } catch (Exception ex)
1000 evt.dropComplete(success); // need this to ensure input focus is properly
1001 // transfered to any new windows created
1011 public void inputLocalFileMenuItem_actionPerformed(AlignViewport viewport)
1013 String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
1014 JalviewFileChooser chooser = JalviewFileChooser.forRead(
1015 Cache.getProperty("LAST_DIRECTORY"),
1016 // AppletFormatAdapter.READABLE_EXTENSIONS,
1017 // AppletFormatAdapter.READABLE_FNAMES,
1020 chooser.setFileView(new JalviewFileView());
1021 chooser.setDialogTitle(MessageManager
1022 .getString("label.open_local_file"));
1023 chooser.setToolTipText(MessageManager.getString("action.open"));
1025 int value = chooser.showOpenDialog(this);
1027 if (value == JalviewFileChooser.APPROVE_OPTION)
1029 String choice = chooser.getSelectedFile().getPath();
1030 Cache.setProperty("LAST_DIRECTORY", chooser
1031 .getSelectedFile().getParent());
1033 FileFormatI format = null;
1034 if (chooser.getSelectedFormat() != null
1035 && chooser.getSelectedFormat() == FileFormat.Jalview)
1037 format = FileFormat.Jalview;
1043 format = new IdentifyFile().identify(choice, DataSourceType.FILE);
1044 } catch (FileFormatException e)
1050 if (viewport != null)
1052 new FileLoader().LoadFile(viewport, choice, DataSourceType.FILE,
1057 new FileLoader().LoadFile(choice, DataSourceType.FILE, format);
1067 * @throws FileFormatException
1070 public void inputURLMenuItem_actionPerformed(AlignViewport viewport)
1071 // throws FileFormatException
1073 // This construct allows us to have a wider textfield
1075 JLabel label = new JLabel(
1076 MessageManager.getString("label.input_file_url"));
1077 final JComboBox history = new JComboBox();
1079 JPanel panel = new JPanel(new GridLayout(2, 1));
1082 history.setPreferredSize(new Dimension(400, 20));
1083 history.setEditable(true);
1084 history.addItem("http://www.");
1086 String historyItems = jalview.bin.Cache.getProperty("RECENT_URL");
1090 if (historyItems != null)
1092 st = new StringTokenizer(historyItems, "\t");
1094 while (st.hasMoreTokens())
1096 history.addItem(st.nextElement());
1100 int reply = JOptionPane.showInternalConfirmDialog(desktop, panel,
1101 MessageManager.getString("label.input_alignment_from_url"),
1102 JOptionPane.OK_CANCEL_OPTION);
1104 if (reply != JOptionPane.OK_OPTION)
1109 String url = history.getSelectedItem().toString();
1111 if (url.toLowerCase().endsWith(".jar"))
1113 if (viewport != null)
1115 new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
1116 FileFormat.Jalview);
1120 new FileLoader().LoadFile(url, DataSourceType.URL,
1121 FileFormat.Jalview);
1126 FileFormatI format = null;
1129 format = new IdentifyFile().identify(url, DataSourceType.URL);
1130 } catch (FileFormatException e)
1132 // TODO revise error handling, distinguish between
1133 // URL not found and response not valid
1138 JOptionPane.showInternalMessageDialog(Desktop.desktop,
1139 MessageManager.formatMessage("label.couldnt_locate",
1140 new Object[] { url }), MessageManager
1141 .getString("label.url_not_found"),
1142 JOptionPane.WARNING_MESSAGE);
1147 if (viewport != null)
1150 .LoadFile(viewport, url, DataSourceType.URL, format);
1154 new FileLoader().LoadFile(url, DataSourceType.URL, format);
1160 * Opens the CutAndPaste window for the user to paste an alignment in to
1163 * - if not null, the pasted alignment is added to the current
1164 * alignment; if null, to a new alignment window
1167 public void inputTextboxMenuItem_actionPerformed(
1168 AlignmentViewPanel viewPanel)
1170 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1171 cap.setForInput(viewPanel);
1172 Desktop.addInternalFrame(cap,
1173 MessageManager.getString("label.cut_paste_alignmen_file"),
1183 Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
1185 .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
1186 jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
1188 storeLastKnownDimensions("", new Rectangle(getBounds().x,
1189 getBounds().y, getWidth(), getHeight()));
1191 if (jconsole != null)
1193 storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
1194 jconsole.stopConsole();
1198 storeLastKnownDimensions("JALVIEW_RSS_WINDOW_", jvnews.getBounds());
1201 if (dialogExecutor != null)
1203 dialogExecutor.shutdownNow();
1205 closeAll_actionPerformed(null);
1207 if (groovyConsole != null)
1209 // suppress a possible repeat prompt to save script
1210 groovyConsole.setDirty(false);
1211 groovyConsole.exit();
1216 private void storeLastKnownDimensions(String string, Rectangle jc)
1218 jalview.bin.Cache.log.debug("Storing last known dimensions for "
1219 + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
1220 + " height:" + jc.height);
1222 jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
1223 jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
1224 jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
1225 jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
1235 public void aboutMenuItem_actionPerformed(ActionEvent e)
1237 // StringBuffer message = getAboutMessage(false);
1238 // JOptionPane.showInternalMessageDialog(Desktop.desktop,
1240 // message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE);
1241 new Thread(new Runnable()
1246 new SplashScreen(true);
1251 public StringBuffer getAboutMessage(boolean shortv)
1253 StringBuffer message = new StringBuffer();
1254 message.append("<html>");
1257 message.append("<h1><strong>Version: "
1258 + jalview.bin.Cache.getProperty("VERSION") + "</strong></h1>");
1259 message.append("<strong>Last Updated: <em>"
1260 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")
1261 + "</em></strong>");
1267 message.append("<strong>Version "
1268 + jalview.bin.Cache.getProperty("VERSION")
1269 + "; last updated: "
1270 + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown"));
1273 if (jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking").equals(
1276 message.append("<br>...Checking latest version...</br>");
1278 else if (!jalview.bin.Cache.getDefault("LATEST_VERSION", "Checking")
1279 .equals(jalview.bin.Cache.getProperty("VERSION")))
1281 boolean red = false;
1282 if (jalview.bin.Cache.getProperty("VERSION").toLowerCase()
1283 .indexOf("automated build") == -1)
1286 // Displayed when code version and jnlp version do not match and code
1287 // version is not a development build
1288 message.append("<div style=\"color: #FF0000;font-style: bold;\">");
1291 message.append("<br>!! Version "
1292 + jalview.bin.Cache.getDefault("LATEST_VERSION",
1294 + " is available for download from "
1295 + jalview.bin.Cache.getDefault("www.jalview.org",
1296 "http://www.jalview.org") + " !!");
1299 message.append("</div>");
1302 message.append("<br>Authors: "
1304 .getDefault("AUTHORFNAMES",
1305 "The Jalview Authors (See AUTHORS file for current list)")
1306 + "<br><br>Development managed by The Barton Group, University of Dundee, Scotland, UK.<br>"
1307 + "<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"
1308 + "<br><br>If you use Jalview, please cite:"
1309 + "<br>Waterhouse, A.M., Procter, J.B., Martin, D.M.A, Clamp, M. and Barton, G. J. (2009)"
1310 + "<br>Jalview Version 2 - a multiple sequence alignment editor and analysis workbench"
1311 + "<br>Bioinformatics doi: 10.1093/bioinformatics/btp033"
1323 public void documentationMenuItem_actionPerformed(ActionEvent e)
1327 Help.showHelpWindow();
1328 } catch (Exception ex)
1334 public void closeAll_actionPerformed(ActionEvent e)
1336 JInternalFrame[] frames = desktop.getAllFrames();
1337 for (int i = 0; i < frames.length; i++)
1341 frames[i].setClosed(true);
1342 } catch (java.beans.PropertyVetoException ex)
1346 System.out.println("ALL CLOSED");
1347 if (v_client != null)
1349 // TODO clear binding to vamsas document objects on close_all
1353 * reset state of singleton objects as appropriate (clear down session state
1354 * when all windows are closed)
1356 StructureSelectionManager ssm = StructureSelectionManager
1357 .getStructureSelectionManager(this);
1365 public void raiseRelated_actionPerformed(ActionEvent e)
1367 reorderAssociatedWindows(false, false);
1371 public void minimizeAssociated_actionPerformed(ActionEvent e)
1373 reorderAssociatedWindows(true, false);
1376 void closeAssociatedWindows()
1378 reorderAssociatedWindows(false, true);
1384 * @seejalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.
1388 protected void garbageCollect_actionPerformed(ActionEvent e)
1390 // We simply collect the garbage
1391 jalview.bin.Cache.log.debug("Collecting garbage...");
1393 jalview.bin.Cache.log.debug("Finished garbage collection.");
1400 * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
1404 protected void showMemusage_actionPerformed(ActionEvent e)
1406 desktop.showMemoryUsage(showMemusage.isSelected());
1413 * jalview.jbgui.GDesktop#showConsole_actionPerformed(java.awt.event.ActionEvent
1417 protected void showConsole_actionPerformed(ActionEvent e)
1419 showConsole(showConsole.isSelected());
1422 Console jconsole = null;
1425 * control whether the java console is visible or not
1429 void showConsole(boolean selected)
1431 showConsole.setSelected(selected);
1432 // TODO: decide if we should update properties file
1433 Cache.setProperty("SHOW_JAVA_CONSOLE", Boolean.valueOf(selected)
1435 jconsole.setVisible(selected);
1438 void reorderAssociatedWindows(boolean minimize, boolean close)
1440 JInternalFrame[] frames = desktop.getAllFrames();
1441 if (frames == null || frames.length < 1)
1446 AlignmentViewport source = null, target = null;
1447 if (frames[0] instanceof AlignFrame)
1449 source = ((AlignFrame) frames[0]).getCurrentView();
1451 else if (frames[0] instanceof TreePanel)
1453 source = ((TreePanel) frames[0]).getViewPort();
1455 else if (frames[0] instanceof PCAPanel)
1457 source = ((PCAPanel) frames[0]).av;
1459 else if (frames[0].getContentPane() instanceof PairwiseAlignPanel)
1461 source = ((PairwiseAlignPanel) frames[0].getContentPane()).av;
1466 for (int i = 0; i < frames.length; i++)
1469 if (frames[i] == null)
1473 if (frames[i] instanceof AlignFrame)
1475 target = ((AlignFrame) frames[i]).getCurrentView();
1477 else if (frames[i] instanceof TreePanel)
1479 target = ((TreePanel) frames[i]).getViewPort();
1481 else if (frames[i] instanceof PCAPanel)
1483 target = ((PCAPanel) frames[i]).av;
1485 else if (frames[i].getContentPane() instanceof PairwiseAlignPanel)
1487 target = ((PairwiseAlignPanel) frames[i].getContentPane()).av;
1490 if (source == target)
1496 frames[i].setClosed(true);
1500 frames[i].setIcon(minimize);
1503 frames[i].toFront();
1507 } catch (java.beans.PropertyVetoException ex)
1522 protected void preferences_actionPerformed(ActionEvent e)
1534 public void saveState_actionPerformed(ActionEvent e)
1536 JalviewFileChooser chooser = new JalviewFileChooser(
1537 Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project",
1540 chooser.setFileView(new JalviewFileView());
1541 chooser.setDialogTitle(MessageManager.getString("label.save_state"));
1543 int value = chooser.showSaveDialog(this);
1545 if (value == JalviewFileChooser.APPROVE_OPTION)
1547 final Desktop me = this;
1548 final java.io.File choice = chooser.getSelectedFile();
1549 setProjectFile(choice);
1551 new Thread(new Runnable()
1556 // TODO: refactor to Jalview desktop session controller action.
1557 setProgressBar(MessageManager.formatMessage(
1558 "label.saving_jalview_project",
1559 new Object[] { choice.getName() }), choice.hashCode());
1560 jalview.bin.Cache.setProperty("LAST_DIRECTORY",
1561 choice.getParent());
1562 // TODO catch and handle errors for savestate
1563 // TODO prevent user from messing with the Desktop whilst we're saving
1566 new Jalview2XML().saveState(choice);
1567 } catch (OutOfMemoryError oom)
1569 new OOMWarning("Whilst saving current state to "
1570 + choice.getName(), oom);
1571 } catch (Exception ex)
1574 "Problems whilst trying to save to " + choice.getName(),
1576 JOptionPane.showMessageDialog(me, MessageManager.formatMessage(
1577 "label.error_whilst_saving_current_state_to",
1578 new Object[] { choice.getName() }), MessageManager
1579 .getString("label.couldnt_save_project"),
1580 JOptionPane.WARNING_MESSAGE);
1582 setProgressBar(null, choice.hashCode());
1588 private void setProjectFile(File choice)
1590 this.projectFile = choice;
1593 public File getProjectFile()
1595 return this.projectFile;
1605 public void loadState_actionPerformed(ActionEvent e)
1607 JalviewFileChooser chooser = new JalviewFileChooser(
1608 Cache.getProperty("LAST_DIRECTORY"), new String[] {
1609 "jvp", "jar" }, new String[] { "Jalview Project",
1610 "Jalview Project (old)" }, "Jalview Project");
1611 chooser.setFileView(new JalviewFileView());
1612 chooser.setDialogTitle(MessageManager.getString("label.restore_state"));
1614 int value = chooser.showOpenDialog(this);
1616 if (value == JalviewFileChooser.APPROVE_OPTION)
1618 final File selectedFile = chooser.getSelectedFile();
1619 setProjectFile(selectedFile);
1620 final String choice = selectedFile.getAbsolutePath();
1621 Cache.setProperty("LAST_DIRECTORY",
1622 selectedFile.getParent());
1623 new Thread(new Runnable()
1629 MessageManager.formatMessage(
1630 "label.loading_jalview_project",
1631 new Object[] { choice }), choice.hashCode());
1634 new Jalview2XML().loadJalviewAlign(choice);
1635 } catch (OutOfMemoryError oom)
1637 new OOMWarning("Whilst loading project from " + choice, oom);
1638 } catch (Exception ex)
1640 Cache.log.error("Problems whilst loading project from "
1642 JOptionPane.showMessageDialog(Desktop.desktop, MessageManager
1644 "label.error_whilst_loading_project_from",
1645 new Object[] { choice }), MessageManager
1646 .getString("label.couldnt_load_project"),
1647 JOptionPane.WARNING_MESSAGE);
1649 setProgressBar(null, choice.hashCode());
1656 public void inputSequence_actionPerformed(ActionEvent e)
1658 new SequenceFetcher(this);
1661 JPanel progressPanel;
1663 ArrayList<JPanel> fileLoadingPanels = new ArrayList<JPanel>();
1665 public void startLoading(final String fileName)
1667 if (fileLoadingCount == 0)
1669 fileLoadingPanels.add(addProgressPanel(MessageManager.formatMessage(
1670 "label.loading_file", new Object[] { fileName })));
1675 private JPanel addProgressPanel(String string)
1677 if (progressPanel == null)
1679 progressPanel = new JPanel(new GridLayout(1, 1));
1680 totalProgressCount = 0;
1681 instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
1683 JPanel thisprogress = new JPanel(new BorderLayout(10, 5));
1684 JProgressBar progressBar = new JProgressBar();
1685 progressBar.setIndeterminate(true);
1687 thisprogress.add(new JLabel(string), BorderLayout.WEST);
1689 thisprogress.add(progressBar, BorderLayout.CENTER);
1690 progressPanel.add(thisprogress);
1691 ((GridLayout) progressPanel.getLayout())
1692 .setRows(((GridLayout) progressPanel.getLayout()).getRows() + 1);
1693 ++totalProgressCount;
1694 instance.validate();
1695 return thisprogress;
1698 int totalProgressCount = 0;
1700 private void removeProgressPanel(JPanel progbar)
1702 if (progressPanel != null)
1704 synchronized (progressPanel)
1706 progressPanel.remove(progbar);
1707 GridLayout gl = (GridLayout) progressPanel.getLayout();
1708 gl.setRows(gl.getRows() - 1);
1709 if (--totalProgressCount < 1)
1711 this.getContentPane().remove(progressPanel);
1712 progressPanel = null;
1719 public void stopLoading()
1722 if (fileLoadingCount < 1)
1724 while (fileLoadingPanels.size() > 0)
1726 removeProgressPanel(fileLoadingPanels.remove(0));
1728 fileLoadingPanels.clear();
1729 fileLoadingCount = 0;
1734 public static int getViewCount(String alignmentId)
1736 AlignmentViewport[] aps = getViewports(alignmentId);
1737 return (aps == null) ? 0 : aps.length;
1742 * @param alignmentId
1743 * - if null, all sets are returned
1744 * @return all AlignmentPanels concerning the alignmentId sequence set
1746 public static AlignmentPanel[] getAlignmentPanels(String alignmentId)
1748 if (Desktop.desktop == null)
1750 // no frames created and in headless mode
1751 // TODO: verify that frames are recoverable when in headless mode
1754 List<AlignmentPanel> aps = new ArrayList<AlignmentPanel>();
1755 AlignFrame[] frames = getAlignFrames();
1760 for (AlignFrame af : frames)
1762 for (AlignmentPanel ap : af.alignPanels)
1764 if (alignmentId == null
1765 || alignmentId.equals(ap.av.getSequenceSetId()))
1771 if (aps.size() == 0)
1775 AlignmentPanel[] vap = aps.toArray(new AlignmentPanel[aps.size()]);
1780 * get all the viewports on an alignment.
1782 * @param sequenceSetId
1783 * unique alignment id (may be null - all viewports returned in that
1785 * @return all viewports on the alignment bound to sequenceSetId
1787 public static AlignmentViewport[] getViewports(String sequenceSetId)
1789 List<AlignmentViewport> viewp = new ArrayList<AlignmentViewport>();
1790 if (desktop != null)
1792 AlignFrame[] frames = Desktop.getAlignFrames();
1794 for (AlignFrame afr : frames)
1796 if (sequenceSetId == null
1797 || afr.getViewport().getSequenceSetId()
1798 .equals(sequenceSetId))
1800 if (afr.alignPanels != null)
1802 for (AlignmentPanel ap : afr.alignPanels)
1804 if (sequenceSetId == null
1805 || sequenceSetId.equals(ap.av.getSequenceSetId()))
1813 viewp.add(afr.getViewport());
1817 if (viewp.size() > 0)
1819 return viewp.toArray(new AlignmentViewport[viewp.size()]);
1826 * Explode the views in the given frame into separate AlignFrame
1830 public static void explodeViews(AlignFrame af)
1832 int size = af.alignPanels.size();
1838 for (int i = 0; i < size; i++)
1840 AlignmentPanel ap = af.alignPanels.get(i);
1841 AlignFrame newaf = new AlignFrame(ap);
1844 * Restore the view's last exploded frame geometry if known. Multiple
1845 * views from one exploded frame share and restore the same (frame)
1846 * position and size.
1848 Rectangle geometry = ap.av.getExplodedGeometry();
1849 if (geometry != null)
1851 newaf.setBounds(geometry);
1854 ap.av.setGatherViewsHere(false);
1856 addInternalFrame(newaf, af.getTitle(), AlignFrame.DEFAULT_WIDTH,
1857 AlignFrame.DEFAULT_HEIGHT);
1860 af.alignPanels.clear();
1861 af.closeMenuItem_actionPerformed(true);
1866 * Gather expanded views (separate AlignFrame's) with the same sequence set
1867 * identifier back in to this frame as additional views, and close the
1868 * expanded views. Note the expanded frames may themselves have multiple
1869 * views. We take the lot.
1873 public void gatherViews(AlignFrame source)
1875 source.viewport.setGatherViewsHere(true);
1876 source.viewport.setExplodedGeometry(source.getBounds());
1877 JInternalFrame[] frames = desktop.getAllFrames();
1878 String viewId = source.viewport.getSequenceSetId();
1880 for (int t = 0; t < frames.length; t++)
1882 if (frames[t] instanceof AlignFrame && frames[t] != source)
1884 AlignFrame af = (AlignFrame) frames[t];
1885 boolean gatherThis = false;
1886 for (int a = 0; a < af.alignPanels.size(); a++)
1888 AlignmentPanel ap = af.alignPanels.get(a);
1889 if (viewId.equals(ap.av.getSequenceSetId()))
1892 ap.av.setGatherViewsHere(false);
1893 ap.av.setExplodedGeometry(af.getBounds());
1894 source.addAlignmentPanel(ap, false);
1900 af.alignPanels.clear();
1901 af.closeMenuItem_actionPerformed(true);
1908 jalview.gui.VamsasApplication v_client = null;
1911 public void vamsasImport_actionPerformed(ActionEvent e)
1913 if (v_client == null)
1915 // Load and try to start a session.
1916 JalviewFileChooser chooser = new JalviewFileChooser(
1917 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1919 chooser.setFileView(new JalviewFileView());
1920 chooser.setDialogTitle(MessageManager
1921 .getString("label.open_saved_vamsas_session"));
1922 chooser.setToolTipText(MessageManager
1923 .getString("label.select_vamsas_session_opened_as_new_vamsas_session"));
1925 int value = chooser.showOpenDialog(this);
1927 if (value == JalviewFileChooser.APPROVE_OPTION)
1929 String fle = chooser.getSelectedFile().toString();
1930 if (!vamsasImport(chooser.getSelectedFile()))
1933 .showInternalMessageDialog(
1935 MessageManager.formatMessage(
1936 "label.couldnt_import_as_vamsas_session",
1937 new Object[] { fle }),
1939 .getString("label.vamsas_document_import_failed"),
1940 JOptionPane.ERROR_MESSAGE);
1946 jalview.bin.Cache.log
1947 .error("Implementation error - load session from a running session is not supported.");
1952 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
1955 * @return true if import was a success and a session was started.
1957 public boolean vamsasImport(URL url)
1959 // TODO: create progress bar
1960 if (v_client != null)
1963 jalview.bin.Cache.log
1964 .error("Implementation error - load session from a running session is not supported.");
1970 // copy the URL content to a temporary local file
1971 // TODO: be a bit cleverer here with nio (?!)
1972 File file = File.createTempFile("vdocfromurl", ".vdj");
1973 FileOutputStream fos = new FileOutputStream(file);
1974 BufferedInputStream bis = new BufferedInputStream(url.openStream());
1975 byte[] buffer = new byte[2048];
1977 while ((ln = bis.read(buffer)) > -1)
1979 fos.write(buffer, 0, ln);
1983 v_client = new jalview.gui.VamsasApplication(this, file,
1984 url.toExternalForm());
1985 } catch (Exception ex)
1987 jalview.bin.Cache.log.error(
1988 "Failed to create new vamsas session from contents of URL "
1992 setupVamsasConnectedGui();
1993 v_client.initial_update(); // TODO: thread ?
1994 return v_client.inSession();
1998 * import file into a new vamsas session (uses jalview.gui.VamsasApplication)
2001 * @return true if import was a success and a session was started.
2003 public boolean vamsasImport(File file)
2005 if (v_client != null)
2008 jalview.bin.Cache.log
2009 .error("Implementation error - load session from a running session is not supported.");
2013 setProgressBar(MessageManager.formatMessage(
2014 "status.importing_vamsas_session_from",
2015 new Object[] { file.getName() }), file.hashCode());
2018 v_client = new jalview.gui.VamsasApplication(this, file, null);
2019 } catch (Exception ex)
2021 setProgressBar(MessageManager.formatMessage(
2022 "status.importing_vamsas_session_from",
2023 new Object[] { file.getName() }), file.hashCode());
2024 jalview.bin.Cache.log.error(
2025 "New vamsas session from existing session file failed:", ex);
2028 setupVamsasConnectedGui();
2029 v_client.initial_update(); // TODO: thread ?
2030 setProgressBar(MessageManager.formatMessage(
2031 "status.importing_vamsas_session_from",
2032 new Object[] { file.getName() }), file.hashCode());
2033 return v_client.inSession();
2036 public boolean joinVamsasSession(String mysesid)
2038 if (v_client != null)
2042 .getString("error.try_join_vamsas_session_another"));
2044 if (mysesid == null)
2047 MessageManager.getString("error.invalid_vamsas_session_id"));
2049 v_client = new VamsasApplication(this, mysesid);
2050 setupVamsasConnectedGui();
2051 v_client.initial_update();
2052 return (v_client.inSession());
2056 public void vamsasStart_actionPerformed(ActionEvent e)
2058 if (v_client == null)
2061 // we just start a default session for moment.
2063 * JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache.
2064 * getProperty("LAST_DIRECTORY"));
2066 * chooser.setFileView(new JalviewFileView());
2067 * chooser.setDialogTitle("Load Vamsas file");
2068 * chooser.setToolTipText("Import");
2070 * int value = chooser.showOpenDialog(this);
2072 * if (value == JalviewFileChooser.APPROVE_OPTION) { v_client = new
2073 * jalview.gui.VamsasApplication(this, chooser.getSelectedFile());
2075 v_client = new VamsasApplication(this);
2076 setupVamsasConnectedGui();
2077 v_client.initial_update(); // TODO: thread ?
2081 // store current data in session.
2082 v_client.push_update(); // TODO: thread
2086 protected void setupVamsasConnectedGui()
2088 vamsasStart.setText(MessageManager.getString("label.session_update"));
2089 vamsasSave.setVisible(true);
2090 vamsasStop.setVisible(true);
2091 vamsasImport.setVisible(false); // Document import to existing session is
2092 // not possible for vamsas-client-1.0.
2095 protected void setupVamsasDisconnectedGui()
2097 vamsasSave.setVisible(false);
2098 vamsasStop.setVisible(false);
2099 vamsasImport.setVisible(true);
2100 vamsasStart.setText(MessageManager
2101 .getString("label.new_vamsas_session"));
2105 public void vamsasStop_actionPerformed(ActionEvent e)
2107 if (v_client != null)
2109 v_client.end_session();
2111 setupVamsasDisconnectedGui();
2115 protected void buildVamsasStMenu()
2117 if (v_client == null)
2119 String[] sess = null;
2122 sess = VamsasApplication.getSessionList();
2123 } catch (Exception e)
2125 jalview.bin.Cache.log.warn(
2126 "Problem getting current sessions list.", e);
2131 jalview.bin.Cache.log.debug("Got current sessions list: "
2132 + sess.length + " entries.");
2133 VamsasStMenu.removeAll();
2134 for (int i = 0; i < sess.length; i++)
2136 JMenuItem sessit = new JMenuItem();
2137 sessit.setText(sess[i]);
2138 sessit.setToolTipText(MessageManager.formatMessage(
2139 "label.connect_to_session", new Object[] { sess[i] }));
2140 final Desktop dsktp = this;
2141 final String mysesid = sess[i];
2142 sessit.addActionListener(new ActionListener()
2146 public void actionPerformed(ActionEvent e)
2148 if (dsktp.v_client == null)
2150 Thread rthr = new Thread(new Runnable()
2156 dsktp.v_client = new VamsasApplication(dsktp, mysesid);
2157 dsktp.setupVamsasConnectedGui();
2158 dsktp.v_client.initial_update();
2166 VamsasStMenu.add(sessit);
2168 // don't show an empty menu.
2169 VamsasStMenu.setVisible(sess.length > 0);
2174 jalview.bin.Cache.log.debug("No current vamsas sessions.");
2175 VamsasStMenu.removeAll();
2176 VamsasStMenu.setVisible(false);
2181 // Not interested in the content. Just hide ourselves.
2182 VamsasStMenu.setVisible(false);
2187 public void vamsasSave_actionPerformed(ActionEvent e)
2189 if (v_client != null)
2191 JalviewFileChooser chooser = new JalviewFileChooser(
2192 Cache.getProperty("LAST_DIRECTORY"), "vdj",
2193 "Vamsas Document", "Vamsas Document");
2195 chooser.setFileView(new JalviewFileView());
2196 chooser.setDialogTitle(MessageManager
2197 .getString("label.save_vamsas_document_archive"));
2199 int value = chooser.showSaveDialog(this);
2201 if (value == JalviewFileChooser.APPROVE_OPTION)
2203 java.io.File choice = chooser.getSelectedFile();
2204 JPanel progpanel = addProgressPanel(MessageManager.formatMessage(
2205 "label.saving_vamsas_doc",
2206 new Object[] { choice.getName() }));
2207 Cache.setProperty("LAST_DIRECTORY", choice.getParent());
2208 String warnmsg = null;
2209 String warnttl = null;
2212 v_client.vclient.storeDocument(choice);
2215 warnttl = "Serious Problem saving Vamsas Document";
2216 warnmsg = ex.toString();
2217 jalview.bin.Cache.log.error("Error Whilst saving document to "
2220 } catch (Exception ex)
2222 warnttl = "Problem saving Vamsas Document.";
2223 warnmsg = ex.toString();
2224 jalview.bin.Cache.log.warn("Exception Whilst saving document to "
2228 removeProgressPanel(progpanel);
2229 if (warnmsg != null)
2231 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2233 warnmsg, warnttl, JOptionPane.ERROR_MESSAGE);
2239 JPanel vamUpdate = null;
2242 * hide vamsas user gui bits when a vamsas document event is being handled.
2245 * true to hide gui, false to reveal gui
2247 public void setVamsasUpdate(boolean b)
2249 jalview.bin.Cache.log.debug("Setting gui for Vamsas update "
2250 + (b ? "in progress" : "finished"));
2252 if (vamUpdate != null)
2254 this.removeProgressPanel(vamUpdate);
2258 vamUpdate = this.addProgressPanel(MessageManager
2259 .getString("label.updating_vamsas_session"));
2261 vamsasStart.setVisible(!b);
2262 vamsasStop.setVisible(!b);
2263 vamsasSave.setVisible(!b);
2266 public JInternalFrame[] getAllFrames()
2268 return desktop.getAllFrames();
2272 * Checks the given url to see if it gives a response indicating that the user
2273 * should be informed of a new questionnaire.
2277 public void checkForQuestionnaire(String url)
2279 UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
2280 // javax.swing.SwingUtilities.invokeLater(jvq);
2281 new Thread(jvq).start();
2285 * Proxy class for JDesktopPane which optionally displays the current memory
2286 * usage and highlights the desktop area with a red bar if free memory runs
2291 public class MyDesktopPane extends JDesktopPane implements Runnable
2294 private static final float ONE_MB = 1048576f;
2296 boolean showMemoryUsage = false;
2300 java.text.NumberFormat df;
2302 float maxMemory, allocatedMemory, freeMemory, totalFreeMemory,
2305 public MyDesktopPane(boolean showMemoryUsage)
2307 showMemoryUsage(showMemoryUsage);
2310 public void showMemoryUsage(boolean showMemory)
2312 this.showMemoryUsage = showMemory;
2315 Thread worker = new Thread(this);
2320 public boolean isShowMemoryUsage()
2322 return showMemoryUsage;
2328 df = java.text.NumberFormat.getNumberInstance();
2329 df.setMaximumFractionDigits(2);
2330 runtime = Runtime.getRuntime();
2332 while (showMemoryUsage)
2336 maxMemory = runtime.maxMemory() / ONE_MB;
2337 allocatedMemory = runtime.totalMemory() / ONE_MB;
2338 freeMemory = runtime.freeMemory() / ONE_MB;
2339 totalFreeMemory = freeMemory + (maxMemory - allocatedMemory);
2341 percentUsage = (totalFreeMemory / maxMemory) * 100;
2343 // if (percentUsage < 20)
2345 // border1 = BorderFactory.createMatteBorder(12, 12, 12, 12,
2347 // instance.set.setBorder(border1);
2350 // sleep after showing usage
2352 } catch (Exception ex)
2354 ex.printStackTrace();
2360 public void paintComponent(Graphics g)
2362 if (showMemoryUsage && g != null && df != null)
2364 if (percentUsage < 20)
2366 g.setColor(Color.red);
2368 FontMetrics fm = g.getFontMetrics();
2371 g.drawString(MessageManager.formatMessage(
2372 "label.memory_stats",
2373 new Object[] { df.format(totalFreeMemory),
2374 df.format(maxMemory), df.format(percentUsage) }), 10,
2375 getHeight() - fm.getHeight());
2382 * fixes stacking order after a modal dialog to ensure windows that should be
2383 * on top actually are
2385 public void relayerWindows()
2390 protected JMenuItem groovyShell;
2393 * Accessor method to quickly get all the AlignmentFrames loaded.
2395 * @return an array of AlignFrame, or null if none found
2397 public static AlignFrame[] getAlignFrames()
2399 if (Jalview.isHeadlessMode())
2401 // Desktop.desktop is null in headless mode
2402 return new AlignFrame[] { Jalview.currentAlignFrame };
2405 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
2411 List<AlignFrame> avp = new ArrayList<AlignFrame>();
2413 for (int i = frames.length - 1; i > -1; i--)
2415 if (frames[i] instanceof AlignFrame)
2417 avp.add((AlignFrame) frames[i]);
2419 else if (frames[i] instanceof SplitFrame)
2422 * Also check for a split frame containing an AlignFrame
2424 GSplitFrame sf = (GSplitFrame) frames[i];
2425 if (sf.getTopFrame() instanceof AlignFrame)
2427 avp.add((AlignFrame) sf.getTopFrame());
2429 if (sf.getBottomFrame() instanceof AlignFrame)
2431 avp.add((AlignFrame) sf.getBottomFrame());
2435 if (avp.size() == 0)
2439 AlignFrame afs[] = avp.toArray(new AlignFrame[avp.size()]);
2444 * Returns an array of any AppJmol frames in the Desktop (or null if none).
2448 public GStructureViewer[] getJmols()
2450 JInternalFrame[] frames = Desktop.desktop.getAllFrames();
2456 List<GStructureViewer> avp = new ArrayList<GStructureViewer>();
2458 for (int i = frames.length - 1; i > -1; i--)
2460 if (frames[i] instanceof AppJmol)
2462 GStructureViewer af = (GStructureViewer) frames[i];
2466 if (avp.size() == 0)
2470 GStructureViewer afs[] = avp.toArray(new GStructureViewer[avp.size()]);
2475 * Add Groovy Support to Jalview
2477 public void groovyShell_actionPerformed()
2481 openGroovyConsole();
2482 } catch (Exception ex)
2484 jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex);
2485 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2487 MessageManager.getString("label.couldnt_create_groovy_shell"),
2488 MessageManager.getString("label.groovy_support_failed"),
2489 JOptionPane.ERROR_MESSAGE);
2494 * Open the Groovy console
2496 void openGroovyConsole()
2498 if (groovyConsole == null)
2500 groovyConsole = new groovy.ui.Console();
2501 groovyConsole.setVariable("Jalview", this);
2502 groovyConsole.run();
2505 * We allow only one console at a time, so that AlignFrame menu option
2506 * 'Calculate | Run Groovy script' is unambiguous.
2507 * Disable 'Groovy Console', and enable 'Run script', when the console is
2508 * opened, and the reverse when it is closed
2510 Window window = (Window) groovyConsole.getFrame();
2511 window.addWindowListener(new WindowAdapter()
2514 public void windowClosed(WindowEvent e)
2517 * rebind CMD-Q from Groovy Console to Jalview Quit
2520 enableExecuteGroovy(false);
2526 * show Groovy console window (after close and reopen)
2528 ((Window) groovyConsole.getFrame()).setVisible(true);
2531 * if we got this far, enable 'Run Groovy' in AlignFrame menus
2532 * and disable opening a second console
2534 enableExecuteGroovy(true);
2538 * Bind Ctrl/Cmd-Q to Quit - for reset as Groovy Console takes over this
2539 * binding when opened
2541 protected void addQuitHandler()
2543 getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
2544 KeyStroke.getKeyStroke(KeyEvent.VK_Q, Toolkit
2545 .getDefaultToolkit().getMenuShortcutKeyMask()),
2547 getRootPane().getActionMap().put("Quit", new AbstractAction()
2550 public void actionPerformed(ActionEvent e)
2558 * Enable or disable 'Run Groovy script' in AlignFrame calculate menus
2561 * true if Groovy console is open
2563 public void enableExecuteGroovy(boolean enabled)
2566 * disable opening a second Groovy console
2567 * (or re-enable when the console is closed)
2569 groovyShell.setEnabled(!enabled);
2571 AlignFrame[] alignFrames = getAlignFrames();
2572 if (alignFrames != null)
2574 for (AlignFrame af : alignFrames)
2576 af.setGroovyEnabled(enabled);
2582 * Progress bars managed by the IProgressIndicator method.
2584 private Hashtable<Long, JPanel> progressBars;
2586 private Hashtable<Long, IProgressIndicatorHandler> progressBarHandlers;
2591 * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
2594 public void setProgressBar(String message, long id)
2596 if (progressBars == null)
2598 progressBars = new Hashtable<Long, JPanel>();
2599 progressBarHandlers = new Hashtable<Long, IProgressIndicatorHandler>();
2602 if (progressBars.get(new Long(id)) != null)
2604 JPanel panel = progressBars.remove(new Long(id));
2605 if (progressBarHandlers.contains(new Long(id)))
2607 progressBarHandlers.remove(new Long(id));
2609 removeProgressPanel(panel);
2613 progressBars.put(new Long(id), addProgressPanel(message));
2620 * @see jalview.gui.IProgressIndicator#registerHandler(long,
2621 * jalview.gui.IProgressIndicatorHandler)
2624 public void registerHandler(final long id,
2625 final IProgressIndicatorHandler handler)
2627 if (progressBarHandlers == null
2628 || !progressBars.containsKey(new Long(id)))
2632 .getString("error.call_setprogressbar_before_registering_handler"));
2634 progressBarHandlers.put(new Long(id), handler);
2635 final JPanel progressPanel = progressBars.get(new Long(id));
2636 if (handler.canCancel())
2638 JButton cancel = new JButton(
2639 MessageManager.getString("action.cancel"));
2640 final IProgressIndicator us = this;
2641 cancel.addActionListener(new ActionListener()
2645 public void actionPerformed(ActionEvent e)
2647 handler.cancelActivity(id);
2648 us.setProgressBar(MessageManager.formatMessage(
2649 "label.cancelled_params",
2650 new Object[] { ((JLabel) progressPanel.getComponent(0))
2654 progressPanel.add(cancel, BorderLayout.EAST);
2660 * @return true if any progress bars are still active
2663 public boolean operationInProgress()
2665 if (progressBars != null && progressBars.size() > 0)
2673 * This will return the first AlignFrame holding the given viewport instance.
2674 * It will break if there are more than one AlignFrames viewing a particular
2678 * @return alignFrame for viewport
2680 public static AlignFrame getAlignFrameFor(AlignViewportI viewport)
2682 if (desktop != null)
2684 AlignmentPanel[] aps = getAlignmentPanels(viewport.getSequenceSetId());
2685 for (int panel = 0; aps != null && panel < aps.length; panel++)
2687 if (aps[panel] != null && aps[panel].av == viewport)
2689 return aps[panel].alignFrame;
2696 public VamsasApplication getVamsasApplication()
2703 * flag set if jalview GUI is being operated programmatically
2705 private boolean inBatchMode = false;
2708 * check if jalview GUI is being operated programmatically
2710 * @return inBatchMode
2712 public boolean isInBatchMode()
2718 * set flag if jalview GUI is being operated programmatically
2720 * @param inBatchMode
2722 public void setInBatchMode(boolean inBatchMode)
2724 this.inBatchMode = inBatchMode;
2727 public void startServiceDiscovery()
2729 startServiceDiscovery(false);
2732 public void startServiceDiscovery(boolean blocking)
2734 boolean alive = true;
2735 Thread t0 = null, t1 = null, t2 = null;
2736 // JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
2739 // todo: changesupport handlers need to be transferred
2740 if (discoverer == null)
2742 discoverer = new jalview.ws.jws1.Discoverer();
2743 // register PCS handler for desktop.
2744 discoverer.addPropertyChangeListener(changeSupport);
2746 // JAL-940 - disabled JWS1 service configuration - always start discoverer
2747 // until we phase out completely
2748 (t0 = new Thread(discoverer)).start();
2751 if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
2753 if (jalview.ws.jws2.Jws2Discoverer.getDiscoverer().isRunning())
2755 jalview.ws.jws2.Jws2Discoverer.getDiscoverer().setAborted(true);
2757 t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer().startDiscoverer(
2763 // TODO: do rest service discovery
2772 } catch (Exception e)
2775 alive = (t1 != null && t1.isAlive())
2776 || (t2 != null && t2.isAlive())
2777 || (t3 != null && t3.isAlive())
2778 || (t0 != null && t0.isAlive());
2784 * called to check if the service discovery process completed successfully.
2788 protected void JalviewServicesChanged(PropertyChangeEvent evt)
2790 if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
2792 final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
2793 .getErrorMessages();
2796 if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
2798 if (serviceChangedDialog == null)
2800 // only run if we aren't already displaying one of these.
2801 addDialogThread(serviceChangedDialog = new Runnable()
2808 * JalviewDialog jd =new JalviewDialog() {
2810 * @Override protected void cancelPressed() { // TODO
2811 * Auto-generated method stub
2813 * }@Override protected void okPressed() { // TODO
2814 * Auto-generated method stub
2816 * }@Override protected void raiseClosed() { // TODO
2817 * Auto-generated method stub
2819 * } }; jd.initDialogFrame(new
2820 * JLabel("<html><table width=\"450\"><tr><td>" + ermsg +
2821 * "<br/>It may be that you have invalid JABA URLs in your web service preferences,"
2822 * + " or mis-configured HTTP proxy settings.<br/>" +
2823 * "Check the <em>Connections</em> and <em>Web services</em> tab of the"
2825 * " Tools->Preferences dialog box to change them.</td></tr></table></html>"
2826 * ), true, true, "Web Service Configuration Problem", 450,
2829 * jd.waitForInput();
2835 "<html><table width=\"450\"><tr><td>"
2837 + "</td></tr></table>"
2838 + "<p>It may be that you have invalid JABA URLs<br/>in your web service preferences,"
2839 + "<br>or as a command-line argument, or mis-configured HTTP proxy settings.</p>"
2840 + "<p>Check the <em>Connections</em> and <em>Web services</em> tab<br/>of the"
2841 + " Tools->Preferences dialog box to change them.</p></html>"),
2842 "Web Service Configuration Problem",
2843 JOptionPane.DEFAULT_OPTION,
2844 JOptionPane.ERROR_MESSAGE);
2845 serviceChangedDialog = null;
2854 .error("Errors reported by JABA discovery service. Check web services preferences.\n"
2861 private Runnable serviceChangedDialog = null;
2864 * start a thread to open a URL in the configured browser. Pops up a warning
2865 * dialog to the user if there is an exception when calling out to the browser
2870 public static void showUrl(final String url)
2872 showUrl(url, Desktop.instance);
2876 * Like showUrl but allows progress handler to be specified
2880 * (null) or object implementing IProgressIndicator
2882 public static void showUrl(final String url,
2883 final IProgressIndicator progress)
2885 new Thread(new Runnable()
2892 if (progress != null)
2894 progress.setProgressBar(MessageManager.formatMessage(
2895 "status.opening_params", new Object[] { url }), this
2898 jalview.util.BrowserLauncher.openURL(url);
2899 } catch (Exception ex)
2901 JOptionPane.showInternalMessageDialog(Desktop.desktop,
2903 .getString("label.web_browser_not_found_unix"),
2904 MessageManager.getString("label.web_browser_not_found"),
2905 JOptionPane.WARNING_MESSAGE);
2907 ex.printStackTrace();
2909 if (progress != null)
2911 progress.setProgressBar(null, this.hashCode());
2917 public static WsParamSetManager wsparamManager = null;
2919 public static ParamManager getUserParameterStore()
2921 if (wsparamManager == null)
2923 wsparamManager = new WsParamSetManager();
2925 return wsparamManager;
2929 * static hyperlink handler proxy method for use by Jalview's internal windows
2933 public static void hyperlinkUpdate(HyperlinkEvent e)
2935 if (e.getEventType() == EventType.ACTIVATED)
2940 url = e.getURL().toString();
2941 Desktop.showUrl(url);
2942 } catch (Exception x)
2946 if (Cache.log != null)
2948 Cache.log.error("Couldn't handle string " + url + " as a URL.");
2952 System.err.println("Couldn't handle string " + url
2956 // ignore any exceptions due to dud links.
2963 * single thread that handles display of dialogs to user.
2965 ExecutorService dialogExecutor = Executors.newSingleThreadExecutor();
2968 * flag indicating if dialogExecutor should try to acquire a permit
2970 private volatile boolean dialogPause = true;
2975 private java.util.concurrent.Semaphore block = new Semaphore(0);
2977 private static groovy.ui.Console groovyConsole;
2980 * add another dialog thread to the queue
2984 public void addDialogThread(final Runnable prompter)
2986 dialogExecutor.submit(new Runnable()
2996 } catch (InterruptedException x)
3001 if (instance == null)
3007 SwingUtilities.invokeAndWait(prompter);
3008 } catch (Exception q)
3010 Cache.log.warn("Unexpected Exception in dialog thread.", q);
3016 public void startDialogQueue()
3018 // set the flag so we don't pause waiting for another permit and semaphore
3019 // the current task to begin
3020 dialogPause = false;
3025 protected void snapShotWindow_actionPerformed(ActionEvent e)
3029 ImageMaker im = new jalview.util.ImageMaker(this, ImageMaker.TYPE.EPS,
3030 "View of Desktop", getWidth(), getHeight(), of = new File(
3031 "Jalview_snapshot" + System.currentTimeMillis()
3032 + ".eps"), "View of desktop", null, 0, false);
3035 paintAll(im.getGraphics());
3037 } catch (Exception q)
3039 Cache.log.error("Couldn't write snapshot to " + of.getAbsolutePath(),
3043 Cache.log.info("Successfully written snapshot to file "
3044 + of.getAbsolutePath());
3048 * Explode the views in the given SplitFrame into separate SplitFrame windows.
3049 * This respects (remembers) any previous 'exploded geometry' i.e. the size
3050 * and location last time the view was expanded (if any). However it does not
3051 * remember the split pane divider location - this is set to match the
3052 * 'exploding' frame.
3056 public void explodeViews(SplitFrame sf)
3058 AlignFrame oldTopFrame = (AlignFrame) sf.getTopFrame();
3059 AlignFrame oldBottomFrame = (AlignFrame) sf.getBottomFrame();
3060 List<? extends AlignmentViewPanel> topPanels = oldTopFrame
3062 List<? extends AlignmentViewPanel> bottomPanels = oldBottomFrame
3064 int viewCount = topPanels.size();
3071 * Processing in reverse order works, forwards order leaves the first panels
3072 * not visible. I don't know why!
3074 for (int i = viewCount - 1; i >= 0; i--)
3077 * Make new top and bottom frames. These take over the respective
3078 * AlignmentPanel objects, including their AlignmentViewports, so the
3079 * cdna/protein relationships between the viewports is carried over to the
3082 * explodedGeometry holds the (x, y) position of the previously exploded
3083 * SplitFrame, and the (width, height) of the AlignFrame component
3085 AlignmentPanel topPanel = (AlignmentPanel) topPanels.get(i);
3086 AlignFrame newTopFrame = new AlignFrame(topPanel);
3087 newTopFrame.setSize(oldTopFrame.getSize());
3088 newTopFrame.setVisible(true);
3089 Rectangle geometry = ((AlignViewport) topPanel.getAlignViewport())
3090 .getExplodedGeometry();
3091 if (geometry != null)
3093 newTopFrame.setSize(geometry.getSize());
3096 AlignmentPanel bottomPanel = (AlignmentPanel) bottomPanels.get(i);
3097 AlignFrame newBottomFrame = new AlignFrame(bottomPanel);
3098 newBottomFrame.setSize(oldBottomFrame.getSize());
3099 newBottomFrame.setVisible(true);
3100 geometry = ((AlignViewport) bottomPanel.getAlignViewport())
3101 .getExplodedGeometry();
3102 if (geometry != null)
3104 newBottomFrame.setSize(geometry.getSize());
3107 topPanel.av.setGatherViewsHere(false);
3108 bottomPanel.av.setGatherViewsHere(false);
3109 JInternalFrame splitFrame = new SplitFrame(newTopFrame,
3111 if (geometry != null)
3113 splitFrame.setLocation(geometry.getLocation());
3115 Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1);
3119 * Clear references to the panels (now relocated in the new SplitFrames)
3120 * before closing the old SplitFrame.
3123 bottomPanels.clear();
3128 * Gather expanded split frames, sharing the same pairs of sequence set ids,
3129 * back into the given SplitFrame as additional views. Note that the gathered
3130 * frames may themselves have multiple views.
3134 public void gatherViews(GSplitFrame source)
3137 * special handling of explodedGeometry for a view within a SplitFrame: - it
3138 * holds the (x, y) position of the enclosing SplitFrame, and the (width,
3139 * height) of the AlignFrame component
3141 AlignFrame myTopFrame = (AlignFrame) source.getTopFrame();
3142 AlignFrame myBottomFrame = (AlignFrame) source.getBottomFrame();
3143 myTopFrame.viewport.setExplodedGeometry(new Rectangle(source.getX(),
3144 source.getY(), myTopFrame.getWidth(), myTopFrame.getHeight()));
3145 myBottomFrame.viewport.setExplodedGeometry(new Rectangle(source.getX(),
3146 source.getY(), myBottomFrame.getWidth(), myBottomFrame
3148 myTopFrame.viewport.setGatherViewsHere(true);
3149 myBottomFrame.viewport.setGatherViewsHere(true);
3150 String topViewId = myTopFrame.viewport.getSequenceSetId();
3151 String bottomViewId = myBottomFrame.viewport.getSequenceSetId();
3153 JInternalFrame[] frames = desktop.getAllFrames();
3154 for (JInternalFrame frame : frames)
3156 if (frame instanceof SplitFrame && frame != source)
3158 SplitFrame sf = (SplitFrame) frame;
3159 AlignFrame topFrame = (AlignFrame) sf.getTopFrame();
3160 AlignFrame bottomFrame = (AlignFrame) sf.getBottomFrame();
3161 boolean gatherThis = false;
3162 for (int a = 0; a < topFrame.alignPanels.size(); a++)
3164 AlignmentPanel topPanel = topFrame.alignPanels.get(a);
3165 AlignmentPanel bottomPanel = bottomFrame.alignPanels.get(a);
3166 if (topViewId.equals(topPanel.av.getSequenceSetId())
3167 && bottomViewId.equals(bottomPanel.av.getSequenceSetId()))
3170 topPanel.av.setGatherViewsHere(false);
3171 bottomPanel.av.setGatherViewsHere(false);
3172 topPanel.av.setExplodedGeometry(new Rectangle(sf.getLocation(),
3173 topFrame.getSize()));
3174 bottomPanel.av.setExplodedGeometry(new Rectangle(sf
3175 .getLocation(), bottomFrame.getSize()));
3176 myTopFrame.addAlignmentPanel(topPanel, false);
3177 myBottomFrame.addAlignmentPanel(bottomPanel, false);
3183 topFrame.getAlignPanels().clear();
3184 bottomFrame.getAlignPanels().clear();
3191 * The dust settles...give focus to the tab we did this from.
3193 myTopFrame.setDisplayedView(myTopFrame.alignPanel);
3196 public static groovy.ui.Console getGroovyConsole()
3198 return groovyConsole;
3201 public static void transferFromDropTarget(List<String> files,
3202 List<DataSourceType> protocols, DropTargetDropEvent evt,
3207 DataFlavor uriListFlavor = new DataFlavor(
3208 "text/uri-list;class=java.lang.String");
3209 if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor))
3211 // Works on Windows and MacOSX
3212 Cache.log.debug("Drop handled as javaFileListFlavor");
3213 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3214 for (Object file : (List) t
3215 .getTransferData(DataFlavor.javaFileListFlavor))
3217 files.add(((File)file).toString());
3218 protocols.add(DataSourceType.FILE);
3223 // Unix like behaviour
3224 boolean added = false;
3226 if (t.isDataFlavorSupported(uriListFlavor))
3228 Cache.log.debug("Drop handled as uriListFlavor");
3229 // This is used by Unix drag system
3230 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3231 data = (String) t.getTransferData(uriListFlavor);
3235 // fallback to text: workaround - on OSX where there's a JVM bug
3236 Cache.log.debug("standard URIListFlavor failed. Trying text");
3237 // try text fallback
3238 data = (String) t.getTransferData(new DataFlavor(
3239 "text/plain;class=java.lang.String"));
3240 if (Cache.log.isDebugEnabled())
3242 Cache.log.debug("fallback returned " + data);
3245 while (protocols.size() < files.size())
3247 Cache.log.debug("Adding missing FILE protocol for "
3248 + files.get(protocols.size()));
3249 protocols.add(DataSourceType.FILE);
3251 for (java.util.StringTokenizer st = new java.util.StringTokenizer(
3252 data, "\r\n"); st.hasMoreTokens();)
3255 String s = st.nextToken();
3256 if (s.startsWith("#"))
3258 // the line is a comment (as per the RFC 2483)
3261 java.net.URI uri = new java.net.URI(s);
3262 if (uri.getScheme().toLowerCase().startsWith("http"))
3264 protocols.add(DataSourceType.URL);
3265 files.add(uri.toString());
3269 // otherwise preserve old behaviour: catch all for file objects
3270 java.io.File file = new java.io.File(uri);
3271 protocols.add(DataSourceType.FILE);
3272 files.add(file.toString());
3275 if (Cache.log.isDebugEnabled())
3277 if (data == null || !added)
3280 .debug("Couldn't resolve drop data. Here are the supported flavors:");
3281 for (DataFlavor fl : t.getTransferDataFlavors())
3283 Cache.log.debug("Supported transfer dataflavor: "
3285 evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
3286 Object df = t.getTransferData(fl);
3289 Cache.log.debug("Retrieves: " + df);
3293 Cache.log.debug("Retrieved nothing");