X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FDesktop.java;h=7f36f7ffd13c34c8a506fe1c7e6376adc9de119b;hb=65d6d09cd08743d481d39521bb0298ea683888f8;hp=270805a32bba31c64342d3a9193361f74be415ca;hpb=4d7f98a6dd54d9863ba449ec79dcd95d25ed863d;p=jalview.git diff --git a/src/jalview/gui/Desktop.java b/src/jalview/gui/Desktop.java index 270805a..7f36f7f 100644 --- a/src/jalview/gui/Desktop.java +++ b/src/jalview/gui/Desktop.java @@ -23,6 +23,7 @@ package jalview.gui; import jalview.api.AlignViewportI; import jalview.api.AlignmentViewPanel; import jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.io.FileLoader; import jalview.io.FormatAdapter; import jalview.io.IdentifyFile; @@ -33,6 +34,7 @@ import jalview.jbgui.GStructureViewer; import jalview.structure.StructureSelectionManager; import jalview.util.ImageMaker; import jalview.util.MessageManager; +import jalview.util.Platform; import jalview.viewmodel.AlignmentViewport; import jalview.ws.params.ParamManager; @@ -45,6 +47,7 @@ import java.awt.GridLayout; import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; +import java.awt.Window; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.DataFlavor; @@ -69,7 +72,6 @@ import java.beans.PropertyVetoException; import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; -import java.lang.reflect.Constructor; import java.net.URL; import java.util.ArrayList; import java.util.Hashtable; @@ -187,6 +189,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements this.delegate = delegate; } + @Override public void activateFrame(JInternalFrame f) { try @@ -199,31 +202,37 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void beginDraggingFrame(JComponent f) { delegate.beginDraggingFrame(f); } + @Override public void beginResizingFrame(JComponent f, int direction) { delegate.beginResizingFrame(f, direction); } + @Override public void closeFrame(JInternalFrame f) { delegate.closeFrame(f); } + @Override public void deactivateFrame(JInternalFrame f) { delegate.deactivateFrame(f); } + @Override public void deiconifyFrame(JInternalFrame f) { delegate.deiconifyFrame(f); } + @Override public void dragFrame(JComponent f, int newX, int newY) { if (newY < 0) @@ -233,31 +242,37 @@ public class Desktop extends jalview.jbgui.GDesktop implements delegate.dragFrame(f, newX, newY); } + @Override public void endDraggingFrame(JComponent f) { delegate.endDraggingFrame(f); } + @Override public void endResizingFrame(JComponent f) { delegate.endResizingFrame(f); } + @Override public void iconifyFrame(JInternalFrame f) { delegate.iconifyFrame(f); } + @Override public void maximizeFrame(JInternalFrame f) { delegate.maximizeFrame(f); } + @Override public void minimizeFrame(JInternalFrame f) { delegate.minimizeFrame(f); } + @Override public void openFrame(JInternalFrame f) { delegate.openFrame(f); @@ -274,6 +289,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements delegate.resizeFrame(f, newX, newY, newWidth, newHeight); } + @Override public void setBoundsForFrame(JComponent f, int newX, int newY, int newWidth, int newHeight) { @@ -296,7 +312,20 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ instance = this; doVamsasClientCheck(); - doGroovyCheck(); + + groovyShell = new JMenuItem(); + groovyShell.setText(MessageManager.getString("label.groovy_console")); + groovyShell.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + groovyShell_actionPerformed(); + } + }); + toolsMenu.add(groovyShell); + groovyShell.setVisible(true); + doConfigureStructurePrefs(); setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION")); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -305,6 +334,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements boolean showjconsole = jalview.bin.Cache.getDefault( "SHOW_JAVA_CONSOLE", false); desktop = new MyDesktopPane(selmemusage); + if (Platform.isAMac()) + { + desktop.setDoubleBuffered(false); + } showMemusage.setSelected(selmemusage); desktop.setBackground(Color.white); getContentPane().setLayout(new BorderLayout()); @@ -350,6 +383,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements this.addWindowListener(new WindowAdapter() { + @Override public void windowClosing(WindowEvent evt) { quit(); @@ -359,9 +393,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements MouseAdapter ma; this.addMouseListener(ma = new MouseAdapter() { + @Override public void mousePressed(MouseEvent evt) { - if (SwingUtilities.isRightMouseButton(evt)) + if (evt.isPopupTrigger()) { showPasteMenu(evt.getX(), evt.getY()); } @@ -391,6 +426,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // Spawn a thread that shows the splashscreen SwingUtilities.invokeLater(new Runnable() { + @Override public void run() { new SplashScreen(); @@ -402,6 +438,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // takes to open it later on. new Thread(new Runnable() { + @Override public void run() { Cache.log.debug("Filechooser init thread started."); @@ -573,16 +610,19 @@ public class Desktop extends jalview.jbgui.GDesktop implements // reselected again. boolean refresh = true; + @Override public void menuCanceled(MenuEvent e) { refresh = true; } + @Override public void menuDeselected(MenuEvent e) { refresh = true; } + @Override public void menuSelected(MenuEvent e) { if (refresh) @@ -603,6 +643,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements MessageManager.getString("label.paste_new_window")); item.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent evt) { paste(); @@ -625,7 +666,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements String file = (String) contents .getTransferData(DataFlavor.stringFlavor); - String format = new IdentifyFile().Identify(file, + String format = new IdentifyFile().identify(file, FormatAdapter.PASTE); new FileLoader().LoadFile(file, FormatAdapter.PASTE, format); @@ -750,8 +791,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements frame.setResizable(resizable); frame.setMaximizable(resizable); frame.setIconifiable(resizable); - frame.setFrameIcon(null); - + if (Platform.isAMac()) + { + frame.setIconifiable(false); + frame.setFrameIcon(null); + // frame.setDesktopIcon(null); + frame.setDoubleBuffered(false); + } if (frame.getX() < 1 && frame.getY() < 1) { frame.setLocation(xOffset * openFrameCount, yOffset @@ -761,6 +807,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements final JMenuItem menuItem = new JMenuItem(title); frame.addInternalFrameListener(new javax.swing.event.InternalFrameAdapter() { + @Override public void internalFrameActivated( javax.swing.event.InternalFrameEvent evt) { @@ -772,6 +819,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } + @Override public void internalFrameClosed( javax.swing.event.InternalFrameEvent evt) { @@ -789,6 +837,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements menuItem.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { try @@ -861,6 +910,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } } + @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { if (!internalCopy) @@ -871,14 +921,17 @@ public class Desktop extends jalview.jbgui.GDesktop implements internalCopy = false; } + @Override public void dragEnter(DropTargetDragEvent evt) { } + @Override public void dragExit(DropTargetEvent evt) { } + @Override public void dragOver(DropTargetDragEvent evt) { } @@ -894,6 +947,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @param evt * DOCUMENT ME! */ + @Override public void drop(DropTargetDropEvent evt) { boolean success = true; @@ -966,7 +1020,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } else { - format = new IdentifyFile().Identify(file, protocol); + format = new IdentifyFile().identify(file, protocol); } new FileLoader().LoadFile(file, protocol, format); @@ -1017,20 +1071,13 @@ public class Desktop extends jalview.jbgui.GDesktop implements } else { - format = new IdentifyFile().Identify(choice, FormatAdapter.FILE); + format = new IdentifyFile().identify(choice, FormatAdapter.FILE); } if (viewport != null) { new FileLoader().LoadFile(viewport, choice, FormatAdapter.FILE, format); - // viewport.setShowSequenceFeatures(JSONFile.isSeqFeaturesEnabled()); - // AlignFrame af = viewport.getAlignPanel().alignFrame; - // if (af != null) - // { - // af.changeColour(JSONFile.getColourScheme()); - // af.setMenusForViewport(); - // } } else { @@ -1100,7 +1147,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements } else { - String format = new IdentifyFile().Identify(url, FormatAdapter.URL); + String format = new IdentifyFile().identify(url, FormatAdapter.URL); if (format.equals("URL NOT FOUND")) { @@ -1201,6 +1248,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // message.toString(), "About Jalview", JOptionPane.INFORMATION_MESSAGE); new Thread(new Runnable() { + @Override public void run() { new SplashScreen(true); @@ -1511,6 +1559,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements new Thread(new Runnable() { + @Override public void run() { // TODO: refactor to Jalview desktop session controller action. @@ -1582,6 +1631,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements selectedFile.getParent()); new Thread(new Runnable() { + @Override public void run() { setProgressBar( @@ -2101,6 +2151,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements sessit.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { if (dsktp.v_client == null) @@ -2108,6 +2159,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements Thread rthr = new Thread(new Runnable() { + @Override public void run() { dsktp.v_client = new VamsasApplication(dsktp, mysesid); @@ -2280,6 +2332,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements return showMemoryUsage; } + @Override public void run() { df = java.text.NumberFormat.getNumberInstance(); @@ -2346,24 +2399,6 @@ public class Desktop extends jalview.jbgui.GDesktop implements protected JMenuItem groovyShell; - public void doGroovyCheck() - { - if (jalview.bin.Cache.groovyJarsPresent()) - { - groovyShell = new JMenuItem(); - groovyShell.setText(MessageManager.getString("label.groovy_console")); - groovyShell.addActionListener(new ActionListener() - { - public void actionPerformed(ActionEvent e) - { - groovyShell_actionPerformed(); - } - }); - toolsMenu.add(groovyShell); - groovyShell.setVisible(true); - } - } - /** * Accessor method to quickly get all the AlignmentFrames loaded. * @@ -2371,6 +2406,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ public static AlignFrame[] getAlignFrames() { + if (Jalview.isHeadlessMode()) + { + // Desktop.desktop is null in headless mode + return new AlignFrame[] { currentAlignFrame }; + } + JInternalFrame[] frames = Desktop.desktop.getAllFrames(); if (frames == null) @@ -2445,24 +2486,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ public void groovyShell_actionPerformed() { - // use reflection to avoid creating compilation dependency. - if (!jalview.bin.Cache.groovyJarsPresent()) - { - throw new Error( - MessageManager - .getString("error.implementation_error_cannot_create_groovyshell")); - } try { - Class gcClass = Desktop.class.getClassLoader().loadClass( - "groovy.ui.Console"); - Constructor gccons = gcClass.getConstructor(); - java.lang.reflect.Method setvar = gcClass.getMethod("setVariable", - new Class[] { String.class, Object.class }); - java.lang.reflect.Method run = gcClass.getMethod("run"); - Object gc = gccons.newInstance(); - setvar.invoke(gc, new Object[] { "Jalview", this }); - run.invoke(gc); + openGroovyConsole(); } catch (Exception ex) { jalview.bin.Cache.log.error("Groovy Shell Creation failed.", ex); @@ -2475,6 +2501,65 @@ public class Desktop extends jalview.jbgui.GDesktop implements } /** + * Open the Groovy console + */ + void openGroovyConsole() + { + groovyConsole = new groovy.ui.Console(); + + /* + * bind groovy variable 'Jalview' to the Desktop object + */ + groovyConsole.setVariable("Jalview", this); + + /* + * start the console + */ + groovyConsole.run(); + + /* + * Allow only one console at a time, so that the AlignFrame menu option + * 'Calculate | Run Groovy script' is unambiguous. + * Disable 'new console', and enable 'Run script', when the console is + * opened, and the reverse when it is closed + */ + Window window = (Window) groovyConsole.getFrame(); + window.addWindowListener(new WindowAdapter() + { + @Override + public void windowClosed(WindowEvent e) + { + groovyShell.setEnabled(true); + enableExecuteGroovy(false); + } + }); + + /* + * if we got this far, enable 'Run Groovy' in AlignFrame menus + * and disable opening a second console + */ + groovyShell.setEnabled(false); + enableExecuteGroovy(true); + } + + /** + * Enable or disable 'Run Groovy script' in AlignFrame calculate menus + * + * @param enabled + */ + public void enableExecuteGroovy(boolean enabled) + { + AlignFrame[] alignFrames = getAlignFrames(); + if (alignFrames != null) + { + for (AlignFrame af : alignFrames) + { + af.setGroovyEnabled(enabled); + } + } + } + + /** * Progress bars managed by the IProgressIndicator method. */ private Hashtable progressBars; @@ -2486,6 +2571,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * * @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long) */ + @Override public void setProgressBar(String message, long id) { if (progressBars == null) @@ -2515,6 +2601,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements * @see jalview.gui.IProgressIndicator#registerHandler(long, * jalview.gui.IProgressIndicatorHandler) */ + @Override public void registerHandler(final long id, final IProgressIndicatorHandler handler) { @@ -2535,6 +2622,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements cancel.addActionListener(new ActionListener() { + @Override public void actionPerformed(ActionEvent e) { handler.cancelActivity(id); @@ -2693,6 +2781,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements // only run if we aren't already displaying one of these. addDialogThread(serviceChangedDialog = new Runnable() { + @Override public void run() { @@ -2776,6 +2865,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { new Thread(new Runnable() { + @Override public void run() { try @@ -2865,6 +2955,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ private java.util.concurrent.Semaphore block = new Semaphore(0); + private static groovy.ui.Console groovyConsole; + /** * add another dialog thread to the queue * @@ -2874,6 +2966,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements { dialogExecutor.submit(new Runnable() { + @Override public void run() { if (dialogPause) @@ -2917,7 +3010,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements ImageMaker im = new jalview.util.ImageMaker(this, ImageMaker.TYPE.EPS, "View of Desktop", getWidth(), getHeight(), of = new File( "Jalview_snapshot" + System.currentTimeMillis() - + ".eps"), "View of desktop"); + + ".eps"), "View of desktop", null, 0, false); try { paintAll(im.getGraphics()); @@ -2933,7 +3026,11 @@ public class Desktop extends jalview.jbgui.GDesktop implements } /** - * Explode the views in the given frame into separate AlignFrame windows. + * Explode the views in the given SplitFrame into separate SplitFrame windows. + * This respects (remembers) any previous 'exploded geometry' i.e. the size + * and location last time the view was expanded (if any). However it does not + * remember the split pane divider location - this is set to match the + * 'exploding' frame. * * @param sf */ @@ -2962,27 +3059,39 @@ public class Desktop extends jalview.jbgui.GDesktop implements * AlignmentPanel objects, including their AlignmentViewports, so the * cdna/protein relationships between the viewports is carried over to the * new split frames. + * + * explodedGeometry holds the (x, y) position of the previously exploded + * SplitFrame, and the (width, height) of the AlignFrame component */ AlignmentPanel topPanel = (AlignmentPanel) topPanels.get(i); AlignFrame newTopFrame = new AlignFrame(topPanel); - newTopFrame.setSize(new Dimension(AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT)); + newTopFrame.setSize(oldTopFrame.getSize()); newTopFrame.setVisible(true); + Rectangle geometry = ((AlignViewport) topPanel.getAlignViewport()) + .getExplodedGeometry(); + if (geometry != null) + { + newTopFrame.setSize(geometry.getSize()); + } + AlignmentPanel bottomPanel = (AlignmentPanel) bottomPanels.get(i); AlignFrame newBottomFrame = new AlignFrame(bottomPanel); - newBottomFrame.setSize(new Dimension(AlignFrame.DEFAULT_WIDTH, - AlignFrame.DEFAULT_HEIGHT)); + newBottomFrame.setSize(oldBottomFrame.getSize()); newBottomFrame.setVisible(true); + geometry = ((AlignViewport) bottomPanel.getAlignViewport()) + .getExplodedGeometry(); + if (geometry != null) + { + newBottomFrame.setSize(geometry.getSize()); + } + topPanel.av.setGatherViewsHere(false); bottomPanel.av.setGatherViewsHere(false); JInternalFrame splitFrame = new SplitFrame(newTopFrame, newBottomFrame); - // either panel may hold previous exploded frame geometry - Rectangle geometry = ((AlignViewport) topPanel.getAlignViewport()) - .getExplodedGeometry(); if (geometry != null) { - splitFrame.setBounds(geometry); + splitFrame.setLocation(geometry.getLocation()); } Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1); } @@ -3005,10 +3114,18 @@ public class Desktop extends jalview.jbgui.GDesktop implements */ public void gatherViews(GSplitFrame source) { + /* + * special handling of explodedGeometry for a view within a SplitFrame: - it + * holds the (x, y) position of the enclosing SplitFrame, and the (width, + * height) of the AlignFrame component + */ AlignFrame myTopFrame = (AlignFrame) source.getTopFrame(); AlignFrame myBottomFrame = (AlignFrame) source.getBottomFrame(); - myTopFrame.viewport.setExplodedGeometry(source.getBounds()); - myBottomFrame.viewport.setExplodedGeometry(source.getBounds()); + myTopFrame.viewport.setExplodedGeometry(new Rectangle(source.getX(), + source.getY(), myTopFrame.getWidth(), myTopFrame.getHeight())); + myBottomFrame.viewport.setExplodedGeometry(new Rectangle(source.getX(), + source.getY(), myBottomFrame.getWidth(), myBottomFrame + .getHeight())); myTopFrame.viewport.setGatherViewsHere(true); myBottomFrame.viewport.setGatherViewsHere(true); String topViewId = myTopFrame.viewport.getSequenceSetId(); @@ -3033,10 +3150,10 @@ public class Desktop extends jalview.jbgui.GDesktop implements gatherThis = true; topPanel.av.setGatherViewsHere(false); bottomPanel.av.setGatherViewsHere(false); - // both panels refer to the same split frame geometry - Rectangle position = sf.getBounds(); - topPanel.av.setExplodedGeometry(position); - bottomPanel.av.setExplodedGeometry(position); + topPanel.av.setExplodedGeometry(new Rectangle(sf.getLocation(), + topFrame.getSize())); + bottomPanel.av.setExplodedGeometry(new Rectangle(sf + .getLocation(), bottomFrame.getSize())); myTopFrame.addAlignmentPanel(topPanel, false); myBottomFrame.addAlignmentPanel(bottomPanel, false); } @@ -3068,4 +3185,9 @@ public class Desktop extends jalview.jbgui.GDesktop implements Desktop.currentAlignFrame = currentAlignFrame; } + public static groovy.ui.Console getGroovyConsole() + { + return groovyConsole; + } + }