*/
package jalview.gui;
+import java.util.Locale;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.util.Hashtable;
import java.util.List;
import java.util.ListIterator;
-import java.util.Locale;
import java.util.Vector;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
import java.util.concurrent.Semaphore;
import javax.swing.AbstractAction;
import jalview.api.AlignViewportI;
import jalview.api.AlignmentViewPanel;
+import jalview.api.StructureSelectionManagerProvider;
+import jalview.bin.ApplicationSingletonProvider;
+import jalview.bin.ApplicationSingletonProvider.ApplicationSingletonI;
import jalview.bin.Cache;
import jalview.bin.Jalview;
import jalview.gui.ImageExporter.ImageWriterI;
import jalview.io.IdentifyFile;
import jalview.io.JalviewFileChooser;
import jalview.io.JalviewFileView;
+import jalview.jbgui.APQHandlers;
+import jalview.jbgui.GDesktop;
import jalview.jbgui.GSplitFrame;
import jalview.jbgui.GStructureViewer;
import jalview.project.Jalview2XML;
import jalview.util.LaunchUtils;
import jalview.util.MessageManager;
import jalview.util.Platform;
-import jalview.util.ShortcutKeyMaskExWrapper;
import jalview.util.UrlConstants;
import jalview.viewmodel.AlignmentViewport;
+import jalview.ws.WSDiscovererI;
import jalview.ws.params.ParamManager;
import jalview.ws.utils.UrlDownloadClient;
* @author $author$
* @version $Revision: 1.155 $
*/
-public class Desktop extends jalview.jbgui.GDesktop
+@SuppressWarnings("serial")
+public class Desktop extends GDesktop
implements DropTargetListener, ClipboardOwner, IProgressIndicator,
- jalview.api.StructureSelectionManagerProvider
+ StructureSelectionManagerProvider, ApplicationSingletonI
+
{
private static final String CITATION;
- static
- {
- URL bg_logo_url = ChannelProperties.getImageURL(
- "bg_logo." + String.valueOf(SplashScreen.logoSize));
- URL uod_logo_url = ChannelProperties.getImageURL(
- "uod_banner." + String.valueOf(SplashScreen.logoSize));
+ static {
+ URL bg_logo_url = ChannelProperties.getImageURL("bg_logo." + String.valueOf(SplashScreen.logoSize));
+ URL uod_logo_url = ChannelProperties.getImageURL("uod_banner." + String.valueOf(SplashScreen.logoSize));
boolean logo = (bg_logo_url != null || uod_logo_url != null);
StringBuilder sb = new StringBuilder();
sb.append(
{
sb.append("<br>");
}
- sb.append(bg_logo_url == null ? ""
- : "<img alt=\"Barton Group logo\" src=\""
- + bg_logo_url.toString() + "\">");
+ sb.append(bg_logo_url == null ? "" : "<img alt=\"Barton Group logo\" src=\"" + bg_logo_url.toString() + "\">");
sb.append(uod_logo_url == null ? ""
- : " <img alt=\"University of Dundee shield\" src=\""
- + uod_logo_url.toString() + "\">");
+ : " <img alt=\"University of Dundee shield\" src=\"" + uod_logo_url.toString() + "\">");
sb.append(
"<br><br>For help, see <a href=\"https://www.jalview.org/faq\">www.jalview.org/faq</a> and join <a href=\"https://discourse.jalview.org\">discourse.jalview.org</a>");
sb.append("<br><br>If you use Jalview, please cite:"
public static HashMap<String, FileWriter> savingFiles = new HashMap<String, FileWriter>();
+ @SuppressWarnings("deprecation")
private JalviewChangeSupport changeSupport = new JalviewChangeSupport();
public static boolean nosplash = false;
* @param listener
* @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.beans.PropertyChangeListener)
*/
+ @Deprecated
public void addJalviewPropertyChangeListener(
PropertyChangeListener listener)
{
* @see jalview.gui.JalviewChangeSupport#addJalviewPropertyChangeListener(java.lang.String,
* java.beans.PropertyChangeListener)
*/
+ @Deprecated
public void addJalviewPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
{
* @see jalview.gui.JalviewChangeSupport#removeJalviewPropertyChangeListener(java.lang.String,
* java.beans.PropertyChangeListener)
*/
+ @Deprecated
public void removeJalviewPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
{
listener);
}
- /** Singleton Desktop instance */
- public static Desktop instance;
+ private MyDesktopPane desktopPane;
+
+ public static MyDesktopPane getDesktopPane()
+ {
+ Desktop desktop = getInstance();
+ return desktop == null ? null : desktop.desktopPane;
+ }
- public static MyDesktopPane desktop;
+ /**
+ * Answers an 'application scope' singleton instance of this class. Separate
+ * SwingJS 'applets' running in the same browser page will each have a
+ * distinct instance of Desktop.
+ *
+ * @return
+ */
+ public static Desktop getInstance()
+ {
+ return Jalview.isHeadlessMode() ? null
+ : (Desktop) ApplicationSingletonProvider
+ .getInstance(Desktop.class);
+ }
- public static MyDesktopPane getDesktop()
+ public static StructureSelectionManager getStructureSelectionManager()
{
- // BH 2018 could use currentThread() here as a reference to a
- // Hashtable<Thread, MyDesktopPane> in JavaScript
- return desktop;
+ return StructureSelectionManager
+ .getStructureSelectionManager(getInstance());
}
- static int openFrameCount = 0;
+ int openFrameCount = 0;
- static final int xOffset = 30;
+ final int xOffset = 30;
- static final int yOffset = 30;
+ final int yOffset = 30;
- public static jalview.ws.jws1.Discoverer discoverer;
+ public jalview.ws.jws1.Discoverer discoverer;
- public static Object[] jalviewClipboard;
+ public Object[] jalviewClipboard;
- public static boolean internalCopy = false;
+ public boolean internalCopy = false;
- static int fileLoadingCount = 0;
+ int fileLoadingCount = 0;
class MyDesktopManager implements DesktopManager
{
} catch (NullPointerException npe)
{
Point p = getMousePosition();
- instance.showPasteMenu(p.x, p.y);
+ showPasteMenu(p.x, p.y);
}
}
public void endDraggingFrame(JComponent f)
{
delegate.endDraggingFrame(f);
- desktop.repaint();
+ desktopPane.repaint();
}
@Override
public void endResizingFrame(JComponent f)
{
delegate.endResizingFrame(f);
- desktop.repaint();
+ desktopPane.repaint();
}
@Override
}
/**
- * Creates a new Desktop object.
+ * Private constructor enforces singleton pattern. It is called by reflection
+ * from ApplicationSingletonProvider.getInstance().
*/
- public Desktop()
+ private Desktop()
{
super();
- /**
- * A note to implementors. It is ESSENTIAL that any activities that might
- * block are spawned off as threads rather than waited for during this
- * constructor.
- */
- instance = this;
+ try
+ {
+ /**
+ * A note to implementors. It is ESSENTIAL that any activities that might
+ * block are spawned off as threads rather than waited for during this
+ * constructor.
+ */
- doConfigureStructurePrefs();
- setTitle(ChannelProperties.getProperty("app_name") + " "
- + Cache.getProperty("VERSION"));
+ doConfigureStructurePrefs();
+ setTitle(ChannelProperties.getProperty("app_name") + " " + Cache.getProperty("VERSION"));
/**
* Set taskbar "grouped windows" name for linux desktops (works in GNOME and
- * KDE). This uses sun.awt.X11.XToolkit.awtAppClassName which is not
- * officially documented or guaranteed to exist, so we access it via
- * reflection. There appear to be unfathomable criteria about what this
- * string can contain, and it if doesn't meet those criteria then "java"
- * (KDE) or "jalview-bin-Jalview" (GNOME) is used. "Jalview", "Jalview
- * Develop" and "Jalview Test" seem okay, but "Jalview non-release" does
- * not. The reflection access may generate a warning: WARNING: An illegal
- * reflective access operation has occurred WARNING: Illegal reflective
- * access by jalview.gui.Desktop () to field
+ * KDE). This uses sun.awt.X11.XToolkit.awtAppClassName which is not officially
+ * documented or guaranteed to exist, so we access it via reflection. There
+ * appear to be unfathomable criteria about what this string can contain, and it
+ * if doesn't meet those criteria then "java" (KDE) or "jalview-bin-Jalview"
+ * (GNOME) is used. "Jalview", "Jalview Develop" and "Jalview Test" seem okay,
+ * but "Jalview non-release" does not. The reflection access may generate a
+ * warning: WARNING: An illegal reflective access operation has occurred
+ * WARNING: Illegal reflective access by jalview.gui.Desktop () to field
* sun.awt.X11.XToolkit.awtAppClassName which I don't think can be avoided.
*/
if (Platform.isLinux())
Field[] declaredFields = xToolkit.getClass().getDeclaredFields();
Field awtAppClassNameField = null;
- if (Arrays.stream(declaredFields)
- .anyMatch(f -> f.getName().equals("awtAppClassName")))
- {
- awtAppClassNameField = xToolkit.getClass()
- .getDeclaredField("awtAppClassName");
+ if (Arrays.stream(declaredFields).anyMatch(f -> f.getName().equals("awtAppClassName"))) {
+ awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
}
String title = ChannelProperties.getProperty("app_name");
- if (awtAppClassNameField != null)
- {
+ if (awtAppClassNameField != null) {
awtAppClassNameField.setAccessible(true);
awtAppClassNameField.set(xToolkit, title);
}
}
}
+ /**
+ * APQHandlers sets handlers for About, Preferences and Quit actions peculiar to
+ * macOS's application menu. APQHandlers will check to see if a handler is
+ * supported before setting it.
+ */
+ try {
+ APQHandlers.setAPQHandlers(this);
+ } catch (Exception e) {
+ System.out.println("Cannot set APQHandlers");
+ // e.printStackTrace();
+ } catch (Throwable t) {
+ jalview.bin.Console.warn("Error setting APQHandlers: " + t.toString());
+ jalview.bin.Console.trace(Cache.getStackTraceString(t));
+ }
+
setIconImages(ChannelProperties.getIconList());
- addWindowListener(new WindowAdapter()
- {
+ addWindowListener(new WindowAdapter() {
@Override
- public void windowClosing(WindowEvent ev)
- {
+ public void windowClosing(WindowEvent ev) {
quit();
}
});
- boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false);
+ boolean selmemusage = Cache.getDefault("SHOW_MEMUSAGE", false);
- boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false);
- desktop = new MyDesktopPane(selmemusage);
+ boolean showjconsole = Cache.getDefault("SHOW_JAVA_CONSOLE", false);
+ desktopPane = new MyDesktopPane(selmemusage);
- showMemusage.setSelected(selmemusage);
- desktop.setBackground(Color.white);
+ showMemusage.setSelected(selmemusage);
+ desktopPane.setBackground(Color.white);
- getContentPane().setLayout(new BorderLayout());
- // alternate config - have scrollbars - see notes in JAL-153
- // JScrollPane sp = new JScrollPane();
- // sp.getViewport().setView(desktop);
- // getContentPane().add(sp, BorderLayout.CENTER);
+ getContentPane().setLayout(new BorderLayout());
+ // alternate config - have scrollbars - see notes in JAL-153
+ // JScrollPane sp = new JScrollPane();
+ // sp.getViewport().setView(desktop);
+ // getContentPane().add(sp, BorderLayout.CENTER);
- // BH 2018 - just an experiment to try unclipped JInternalFrames.
- if (Platform.isJS())
- {
- getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
- }
+ // BH 2018 - just an experiment to try unclipped JInternalFrames.
+ if (Platform.isJS())
+ {
+ getRootPane().putClientProperty("swingjs.overflow.hidden", "false");
+ }
- getContentPane().add(desktop, BorderLayout.CENTER);
- desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
+ getContentPane().add(desktopPane, BorderLayout.CENTER);
+ desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
- // This line prevents Windows Look&Feel resizing all new windows to maximum
- // if previous window was maximised
- desktop.setDesktopManager(new MyDesktopManager(
- (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager()
- : Platform.isAMacAndNotJS()
- ? new AquaInternalFrameManager(
- desktop.getDesktopManager())
- : desktop.getDesktopManager())));
- Rectangle dims = getLastKnownDimensions("");
- if (dims != null)
- {
- setBounds(dims);
- }
- else
- {
- Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
- int xPos = Math.max(5, (screenSize.width - 900) / 2);
- int yPos = Math.max(5, (screenSize.height - 650) / 2);
- setBounds(xPos, yPos, 900, 650);
- }
+ // This line prevents Windows Look&Feel resizing all new windows to
+ // maximum
+ // if previous window was maximised
+ desktopPane.setDesktopManager(new MyDesktopManager(
+ (Platform.isWindowsAndNotJS() ? new DefaultDesktopManager()
+ : Platform.isAMacAndNotJS()
+ ? new AquaInternalFrameManager(
+ desktopPane.getDesktopManager())
+ : desktopPane.getDesktopManager())));
- if (!Platform.isJS())
- /**
- * Java only
- *
- * @j2sIgnore
- */
- {
- jconsole = new Console(this, showjconsole);
- jconsole.setHeader(Cache.getVersionDetailsForConsole());
- showConsole(showjconsole);
+ Rectangle dims = getLastKnownDimensions("");
+ if (dims != null)
+ {
+ setBounds(dims);
+ }
+ else
+ {
+ Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+ int xPos = Math.max(5, (screenSize.width - 900) / 2);
+ int yPos = Math.max(5, (screenSize.height - 650) / 2);
+ setBounds(xPos, yPos, 900, 650);
+ }
- showNews.setVisible(false);
+ if (!Platform.isJS())
+ /**
+ * Java only
+ *
+ * @j2sIgnore
+ */
+ {
+ jconsole = new Console(this, showjconsole);
+ jconsole.setHeader(Cache.getVersionDetailsForConsole());
+ showConsole(showjconsole);
- experimentalFeatures.setSelected(showExperimental());
+ showNews.setVisible(false); // not sure if we should only do this for interactive session?
- getIdentifiersOrgData();
+ experimentalFeatures.setSelected(showExperimental());
- checkURLLinks();
+ getIdentifiersOrgData();
- // Spawn a thread that shows the splashscreen
- if (!nosplash)
- {
- SwingUtilities.invokeLater(new Runnable()
+ if (Jalview.isInteractive())
{
- @Override
- public void run()
- {
- new SplashScreen(true);
+ // disabled for SeqCanvasTest
+ checkURLLinks();
+
+ // Spawn a thread that shows the splashscreen
+ if (!nosplash) {
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ new SplashScreen(true);
+ }
+ });
}
- });
+
+ // Thread off a new instance of the file chooser - this reduces the
+ // time
+ // it
+ // takes to open it later on.
+ new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ jalview.bin.Console.debug("Filechooser init thread started.");
+ String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
+ JalviewFileChooser.forRead(
+ Cache.getProperty("LAST_DIRECTORY"), fileFormat);
+ jalview.bin.Console.debug("Filechooser init thread finished.");
+ }
+ }).start();
+ // Add the service change listener
+ changeSupport.addJalviewPropertyChangeListener("services",
+ new PropertyChangeListener()
+ {
+
+ @Override
+ public void propertyChange(PropertyChangeEvent evt)
+ {
+ jalview.bin.Console.debug("Firing service changed event for "
+ + evt.getNewValue());
+ JalviewServicesChanged(evt);
+ }
+ });
+ }
}
- // Thread off a new instance of the file chooser - this reduces the time
- // it
- // takes to open it later on.
- new Thread(new Runnable()
+ this.setDropTarget(new java.awt.dnd.DropTarget(desktopPane, this));
+
+ this.addWindowListener(new WindowAdapter()
{
@Override
- public void run()
+ public void windowClosing(WindowEvent evt)
{
- jalview.bin.Console.debug("Filechooser init thread started.");
- String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
- JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"),
- fileFormat);
- jalview.bin.Console.debug("Filechooser init thread finished.");
+ quit();
}
- }).start();
- // Add the service change listener
- changeSupport.addJalviewPropertyChangeListener("services",
- new PropertyChangeListener()
- {
-
- @Override
- public void propertyChange(PropertyChangeEvent evt)
- {
- jalview.bin.Console
- .debug("Firing service changed event for "
- + evt.getNewValue());
- JalviewServicesChanged(evt);
- }
- });
- }
-
- this.setDropTarget(new java.awt.dnd.DropTarget(desktop, this));
-
- this.addWindowListener(new WindowAdapter()
- {
- @Override
- public void windowClosing(WindowEvent evt)
- {
- quit();
- }
- });
+ });
- MouseAdapter ma;
- this.addMouseListener(ma = new MouseAdapter()
- {
- @Override
- public void mousePressed(MouseEvent evt)
+ MouseAdapter ma;
+ this.addMouseListener(ma = new MouseAdapter()
{
- if (evt.isPopupTrigger()) // Mac
+ @Override
+ public void mousePressed(MouseEvent evt)
{
- showPasteMenu(evt.getX(), evt.getY());
+ if (evt.isPopupTrigger()) // Mac
+ {
+ showPasteMenu(evt.getX(), evt.getY());
+ }
}
- }
-
- @Override
- public void mouseReleased(MouseEvent evt)
- {
- if (evt.isPopupTrigger()) // Windows
+ @Override
+ public void mouseReleased(MouseEvent evt)
{
- showPasteMenu(evt.getX(), evt.getY());
+ if (evt.isPopupTrigger()) // Windows
+ {
+ showPasteMenu(evt.getX(), evt.getY());
+ }
}
- }
- });
- desktop.addMouseListener(ma);
+ });
+ desktopPane.addMouseListener(ma);
+ } catch (Throwable t)
+ {
+ t.printStackTrace();
+ }
}
/**
public void doConfigureStructurePrefs()
{
// configure services
- StructureSelectionManager ssm = StructureSelectionManager
- .getStructureSelectionManager(this);
- if (Cache.getDefault(Preferences.ADD_SS_ANN, true))
- {
- ssm.setAddTempFacAnnot(
- Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true));
- ssm.setProcessSecondaryStructure(
- Cache.getDefault(Preferences.STRUCT_FROM_PDB, true));
+ StructureSelectionManager ssm = StructureSelectionManager.getStructureSelectionManager(this);
+ if (Cache.getDefault(Preferences.ADD_SS_ANN, true)) {
+ ssm.setAddTempFacAnnot(Cache.getDefault(Preferences.ADD_TEMPFACT_ANN, true));
+ ssm.setProcessSecondaryStructure(Cache.getDefault(Preferences.STRUCT_FROM_PDB, true));
// JAL-3915 - RNAView is no longer an option so this has no effect
- ssm.setSecStructServices(
- Cache.getDefault(Preferences.USE_RNAVIEW, false));
- }
- else
- {
+ ssm.setSecStructServices(Cache.getDefault(Preferences.USE_RNAVIEW, false));
+ } else {
ssm.setAddTempFacAnnot(false);
ssm.setProcessSecondaryStructure(false);
ssm.setSecStructServices(false);
}
}
- public void checkForNews()
- {
+ public void checkForNews() {
final Desktop me = this;
// Thread off the news reader, in case there are connection problems.
- new Thread(new Runnable()
- {
+ new Thread(new Runnable() {
@Override
public void run()
{
}).start();
}
- public void getIdentifiersOrgData()
- {
- if (Cache.getProperty("NOIDENTIFIERSSERVICE") == null)
- {// Thread off the identifiers fetcher
- new Thread(new Runnable()
- {
+ public void getIdentifiersOrgData() {
+ if (Cache.getProperty("NOIDENTIFIERSSERVICE") == null) {
+ // Thread off the identifiers fetcher
+ new Thread(new Runnable() {
@Override
public void run()
{
- jalview.bin.Console
- .debug("Downloading data from identifiers.org");
+ jalview.bin.Console.debug("Downloading data from identifiers.org");
try
{
UrlDownloadClient.download(IdOrgSettings.getUrl(),
IdOrgSettings.getDownloadLocation());
} catch (IOException e)
{
- jalview.bin.Console
- .debug("Exception downloading identifiers.org data"
+ jalview.bin.Console.debug("Exception downloading identifiers.org data"
+ e.getMessage());
}
}
}).start();
- ;
}
}
@Override
- protected void showNews_actionPerformed(ActionEvent e)
- {
+ protected void showNews_actionPerformed(ActionEvent e) {
showNews(showNews.isSelected());
}
public void run()
{
long now = System.currentTimeMillis();
- Desktop.instance.setProgressBar(
- MessageManager.getString("status.refreshing_news"), now);
+ setProgressBar(MessageManager.getString("status.refreshing_news"),
+ now);
jvnews.refreshNews();
- Desktop.instance.setProgressBar(null, now);
+ setProgressBar(null, now);
jvnews.showNews();
}
}).start();
String y = Cache.getProperty(windowName + "SCREEN_Y");
String width = Cache.getProperty(windowName + "SCREEN_WIDTH");
String height = Cache.getProperty(windowName + "SCREEN_HEIGHT");
- if ((x != null) && (y != null) && (width != null) && (height != null))
- {
- int ix = Integer.parseInt(x), iy = Integer.parseInt(y),
- iw = Integer.parseInt(width), ih = Integer.parseInt(height);
- if (Cache.getProperty("SCREENGEOMETRY_WIDTH") != null)
- {
+ if ((x != null) && (y != null) && (width != null) && (height != null)) {
+ int ix = Integer.parseInt(x), iy = Integer.parseInt(y), iw = Integer.parseInt(width),
+ ih = Integer.parseInt(height);
+ if (Cache.getProperty("SCREENGEOMETRY_WIDTH") != null) {
// attempt #1 - try to cope with change in screen geometry - this
// version doesn't preserve original jv aspect ratio.
// take ratio of current screen size vs original screen size.
- double sw = ((1f * screenSize.width) / (1f * Integer
- .parseInt(Cache.getProperty("SCREENGEOMETRY_WIDTH"))));
- double sh = ((1f * screenSize.height) / (1f * Integer
- .parseInt(Cache.getProperty("SCREENGEOMETRY_HEIGHT"))));
+ double sw = ((1f * screenSize.width) / (1f * Integer.parseInt(Cache.getProperty("SCREENGEOMETRY_WIDTH"))));
+ double sh = ((1f * screenSize.height) / (1f * Integer.parseInt(Cache.getProperty("SCREENGEOMETRY_HEIGHT"))));
// rescale the bounds depending upon the current screen geometry.
ix = (int) (ix * sw);
iw = (int) (iw * sw);
}
}
- /**
- * Adds and opens the given frame to the desktop
- *
- * @param frame
- * Frame to show
- * @param title
- * Visible Title
- * @param w
- * width
- * @param h
- * height
- */
- public static synchronized void addInternalFrame(
- final JInternalFrame frame, String title, int w, int h)
- {
- addInternalFrame(frame, title, true, w, h, true, false);
- }
- /**
- * Add an internal frame to the Jalview desktop
- *
- * @param frame
- * Frame to show
- * @param title
- * Visible Title
- * @param makeVisible
- * When true, display frame immediately, otherwise, caller must call
- * setVisible themselves.
- * @param w
- * width
- * @param h
- * height
- */
- public static synchronized void addInternalFrame(
- final JInternalFrame frame, String title, boolean makeVisible,
- int w, int h)
- {
- addInternalFrame(frame, title, makeVisible, w, h, true, false);
- }
/**
- * Add an internal frame to the Jalview desktop and make it visible
+ * Adds and opens the given frame to the desktop that is visible, allowed to
+ * resize, and has a 300px minimum width.
*
* @param frame
* Frame to show
* width
* @param h
* height
- * @param resizable
- * Allow resize
*/
public static synchronized void addInternalFrame(
- final JInternalFrame frame, String title, int w, int h,
- boolean resizable)
+ final JInternalFrame frame, String title, int w, int h)
{
- addInternalFrame(frame, title, true, w, h, resizable, false);
+ // 58 classes
+
+ addInternalFrame(frame, title, Desktop.FRAME_MAKE_VISIBLE, w, h,
+ FRAME_ALLOW_RESIZE, FRAME_SET_MIN_SIZE_300);
}
/**
- * Add an internal frame to the Jalview desktop
+ * Add an internal frame to the Jalview desktop that may optionally be
+ * visible, resizable, and allowed to be any size
*
* @param frame
* Frame to show
final JInternalFrame frame, String title, boolean makeVisible,
int w, int h, boolean resizable, boolean ignoreMinSize)
{
+ // 15 classes call this method directly.
+
// TODO: allow callers to determine X and Y position of frame (eg. via
// bounds object).
{
frame.setSize(w, h);
}
- // THIS IS A PUBLIC STATIC METHOD, SO IT MAY BE CALLED EVEN IN
- // A HEADLESS STATE WHEN NO DESKTOP EXISTS. MUST RETURN
- // IF JALVIEW IS RUNNING HEADLESS
- // ///////////////////////////////////////////////
- if (instance == null || (System.getProperty("java.awt.headless") != null
- && System.getProperty("java.awt.headless").equals("true")))
- {
- return;
- }
+ if (getInstance() != null)
+ getInstance().addFrame(frame, makeVisible, resizable,
+ ignoreMinSize);
+ }
+
+ // These can now by put into a single int flag, if desired:
+
+ public final static boolean FRAME_MAKE_VISIBLE = true;
+
+ public final static boolean FRAME_NOT_VISIBLE = false;
+
+ public final static boolean FRAME_ALLOW_RESIZE = true;
+
+ public final static boolean FRAME_NOT_RESIZABLE = false;
+
+ public final static boolean FRAME_ALLOW_ANY_SIZE = true;
+
+ public final static boolean FRAME_SET_MIN_SIZE_300 = false;
+
+ private void addFrame(JInternalFrame frame,
+ boolean makeVisible, boolean resizable,
+ boolean ignoreMinSize)
+ {
openFrameCount++;
+
+ boolean isEmbedded = (Platform.getEmbeddedAttribute(frame, "id") != null);
+ boolean hasEmbeddedSize = (Platform.getDimIfEmbedded(frame, -1, -1) != null);
+ // Web page embedding allows us to ignore minimum size
+ ignoreMinSize |= hasEmbeddedSize;
+
if (!ignoreMinSize)
{
- frame.setMinimumSize(
- new Dimension(DEFAULT_MIN_WIDTH, DEFAULT_MIN_HEIGHT));
// Set default dimension for Alignment Frame window.
// The Alignment Frame window could be added from a number of places,
{
frame.setMinimumSize(new Dimension(ALIGN_FRAME_DEFAULT_MIN_WIDTH,
ALIGN_FRAME_DEFAULT_MIN_HEIGHT));
+ } else {
+ frame.setMinimumSize(
+ new Dimension(DEFAULT_MIN_WIDTH, DEFAULT_MIN_HEIGHT));
+
}
}
frame.setIconifiable(resizable);
frame.setOpaque(Platform.isJS());
- if (frame.getX() < 1 && frame.getY() < 1)
+ if (!isEmbedded && frame.getX() < 1 && frame.getY() < 1)
{
frame.setLocation(xOffset * openFrameCount,
yOffset * ((openFrameCount - 1) % 10) + yOffset);
}
/*
- * add an entry for the new frame in the Window menu (and remove it when the
- * frame is closed)
+ * add an entry for the new frame in the Window menu
+ * (and remove it when the frame is closed)
*/
- final JMenuItem menuItem = new JMenuItem(title);
+ final JMenuItem menuItem = new JMenuItem(frame.getTitle());
frame.addInternalFrameListener(new InternalFrameAdapter()
{
@Override
public void internalFrameActivated(InternalFrameEvent evt)
{
- JInternalFrame itf = desktop.getSelectedFrame();
+ JInternalFrame itf = getDesktopPane().getSelectedFrame();
if (itf != null)
{
if (itf instanceof AlignFrame)
PaintRefresher.RemoveComponent(frame);
/*
- * defensive check to prevent frames being added half off the window
+ * defensive check to prevent frames being
+ * added half off the window
*/
if (openFrameCount > 0)
{
{
menuItem.removeActionListener(menuItem.getActionListeners()[0]);
}
- windowMenu.remove(menuItem);
+ getInstance().windowMenu.remove(menuItem);
}
});
frame.setIcon(false);
} catch (java.beans.PropertyVetoException ex)
{
+ // System.err.println(ex.toString());
}
}
setKeyBindings(frame);
- desktop.add(frame);
+ getDesktopPane().add(frame);
- windowMenu.add(menuItem);
+ getInstance().windowMenu.add(menuItem);
frame.toFront();
try
/*
* set up key bindings for Ctrl-W and Cmd-W, with the same (Close) action
*/
- KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
- InputEvent.CTRL_DOWN_MASK);
- KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W,
- ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx());
+ KeyStroke ctrlWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK);
+ KeyStroke cmdWKey = KeyStroke.getKeyStroke(KeyEvent.VK_W, Platform.SHORTCUT_KEY_MASK);
InputMap inputMap = frame
.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
{
if (!internalCopy)
{
- Desktop.jalviewClipboard = null;
+ jalviewClipboard = null;
}
internalCopy = false;
try
{
- Desktop.transferFromDropTarget(files, protocols, evt, t);
+ transferFromDropTarget(files, protocols, evt, t);
} catch (Exception e)
{
e.printStackTrace();
/*
* Call IdentifyFile to verify the file contains what its extension implies.
- * Skip this step for dynamically added file formats, because IdentifyFile does
- * not know how to recognise them.
+ * Skip this step for dynamically added file formats, because
+ * IdentifyFile does not know how to recognise them.
*/
if (FileFormats.getInstance().isIdentifiable(format))
{
panel.add(label);
/*
- * the URL to fetch is input in Java: an editable combobox with history JS:
- * (pending JAL-3038) a plain text field
+ * the URL to fetch is
+ * Java: an editable combobox with history
+ * JS: (pending JAL-3038) a plain text field
*/
JComponent history;
String urlBase = "https://www.";
public void run()
{
@SuppressWarnings("unchecked")
- String url = (history instanceof JTextField
- ? ((JTextField) history).getText()
- : ((JComboBox<String>) history).getEditor().getItem()
- .toString().trim());
-
- if (url.toLowerCase(Locale.ROOT).endsWith(".jar"))
- {
- if (viewport != null)
- {
- new FileLoader().LoadFile(viewport, url, DataSourceType.URL,
- FileFormat.Jalview);
- }
- else
- {
- new FileLoader().LoadFile(url, DataSourceType.URL,
- FileFormat.Jalview);
+ String url = (history instanceof JTextField ? ((JTextField) history).getText()
+ : ((JComboBox<String>) history).getEditor().getItem().toString().trim());
+
+ if (url.toLowerCase(Locale.ROOT).endsWith(".jar")) {
+ if (viewport != null) {
+ new FileLoader().LoadFile(viewport, url, DataSourceType.URL, FileFormat.Jalview);
+ } else {
+ new FileLoader().LoadFile(url, DataSourceType.URL, FileFormat.Jalview);
}
- }
- else
- {
+ } else {
FileFormatI format = null;
try
{
{
String msg = MessageManager
.formatMessage("label.couldnt_locate", url);
- JvOptionPane.showInternalMessageDialog(Desktop.desktop, msg,
+ JvOptionPane.showInternalMessageDialog(getDesktopPane(), msg,
MessageManager.getString("label.url_not_found"),
JvOptionPane.WARNING_MESSAGE);
};
String dialogOption = MessageManager
.getString("label.input_alignment_from_url");
- JvOptionPane.newOptionDialog(desktop).setResponseHandler(0, action)
+ JvOptionPane.newOptionDialog(desktopPane).setResponseHandler(0, action)
.showInternalDialog(panel, dialogOption,
JvOptionPane.YES_NO_CANCEL_OPTION,
JvOptionPane.PLAIN_MESSAGE, null, options,
{
CutAndPasteTransfer cap = new CutAndPasteTransfer();
cap.setForInput(viewPanel);
- Desktop.addInternalFrame(cap,
- MessageManager.getString("label.cut_paste_alignmen_file"), true,
- 600, 500);
+ addInternalFrame(cap,
+ MessageManager.getString("label.cut_paste_alignmen_file"),
+ FRAME_MAKE_VISIBLE, 600, 500, FRAME_ALLOW_RESIZE,
+ FRAME_SET_MIN_SIZE_300);
}
/*
public String getAboutMessage()
{
StringBuilder message = new StringBuilder(1024);
- message.append("<div style=\"font-family: sans-serif;\">")
- .append("<h1><strong>Version: ")
- .append(Cache.getProperty("VERSION")).append("</strong></h1>")
- .append("<strong>Built: <em>")
- .append(Cache.getDefault("BUILD_DATE", "unknown"))
- .append("</em> from ").append(Cache.getBuildDetailsForSplash())
- .append("</strong>");
+ message.append("<div style=\"font-family: sans-serif;\">").append("<h1><strong>Version: ")
+ .append(Cache.getProperty("VERSION")).append("</strong></h1>").append("<strong>Built: <em>")
+ .append(Cache.getDefault("BUILD_DATE", "unknown")).append("</em> from ")
+ .append(Cache.getBuildDetailsForSplash()).append("</strong>");
String latestVersion = Cache.getDefault("LATEST_VERSION", "Checking");
- if (latestVersion.equals("Checking"))
- {
+ if (latestVersion.equals("Checking")) {
// JBP removed this message for 2.11: May be reinstated in future version
// message.append("<br>...Checking latest version...</br>");
- }
- else if (!latestVersion.equals(Cache.getProperty("VERSION")))
- {
+ } else if (!latestVersion.equals(Cache.getProperty("VERSION"))) {
boolean red = false;
- if (Cache.getProperty("VERSION").toLowerCase(Locale.ROOT)
- .indexOf("automated build") == -1)
- {
+ if (Cache.getProperty("VERSION").toLowerCase(Locale.ROOT).indexOf("automated build") == -1) {
red = true;
// Displayed when code version and jnlp version do not match and code
// version is not a development build
message.append("<div style=\"color: #FF0000;font-style: bold;\">");
}
- message.append("<br>!! Version ")
- .append(Cache.getDefault("LATEST_VERSION", "..Checking.."))
- .append(" is available for download from ")
- .append(Cache.getDefault("www.jalview.org",
- "https://www.jalview.org"))
- .append(" !!");
- if (red)
- {
+ message.append("<br>!! Version ").append(Cache.getDefault("LATEST_VERSION", "..Checking.."))
+ .append(" is available for download from ")
+ .append(Cache.getDefault("www.jalview.org", "https://www.jalview.org")).append(" !!");
+ if (red) {
message.append("</div>");
}
}
* Action on requesting Help documentation
*/
@Override
- public void documentationMenuItem_actionPerformed()
- {
- try
- {
- if (Platform.isJS())
- {
+ public void documentationMenuItem_actionPerformed() {
+ try {
+ if (Platform.isJS()) {
BrowserLauncher.openURL("https://www.jalview.org/help.html");
- }
- else
+ } else
/**
* Java only
*
{
Help.showHelpWindow();
}
- } catch (Exception ex)
- {
+ } catch (Exception ex) {
System.err.println("Error opening help: " + ex.getMessage());
}
}
public void closeAll_actionPerformed(ActionEvent e)
{
// TODO show a progress bar while closing?
- JInternalFrame[] frames = desktop.getAllFrames();
+ JInternalFrame[] frames = desktopPane.getAllFrames();
for (int i = 0; i < frames.length; i++)
{
try
/*
* (non-Javadoc)
*
- * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.
- * ActionEvent )
+ * @see
+ * jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent
+ * )
*/
@Override
protected void showMemusage_actionPerformed(ActionEvent e)
{
- desktop.showMemoryUsage(showMemusage.isSelected());
+ desktopPane.showMemoryUsage(showMemusage.isSelected());
}
/*
void reorderAssociatedWindows(boolean minimize, boolean close)
{
- JInternalFrame[] frames = desktop.getAllFrames();
+ JInternalFrame[] frames = desktopPane.getAllFrames();
if (frames == null || frames.length < 1)
{
return;
}
- AlignmentViewport source = null, target = null;
+ AlignViewportI source = null;
+ AlignViewportI target = null;
if (frames[0] instanceof AlignFrame)
{
source = ((AlignFrame) frames[0]).getCurrentView();
* DOCUMENT ME!
*/
@Override
- protected void preferences_actionPerformed(ActionEvent e)
- {
+ protected void preferences_actionPerformed(ActionEvent e) {
Preferences.openPreferences();
}
}
}
- if (approveSave || autoSave)
- {
+ if (approveSave || autoSave) {
final Desktop me = this;
final java.io.File chosenFile = projectFile;
new Thread(new Runnable()
{
jalview.bin.Console.error(
"Problems whilst loading project from " + choice, ex);
- JvOptionPane.showMessageDialog(Desktop.desktop,
+ JvOptionPane.showMessageDialog(getDesktopPane(),
MessageManager.formatMessage(
"label.error_whilst_loading_project_from",
new Object[]
{
progressPanel = new JPanel(new GridLayout(1, 1));
totalProgressCount = 0;
- instance.getContentPane().add(progressPanel, BorderLayout.SOUTH);
+ getContentPane().add(progressPanel, BorderLayout.SOUTH);
}
JPanel thisprogress = new JPanel(new BorderLayout(10, 5));
JProgressBar progressBar = new JProgressBar();
((GridLayout) progressPanel.getLayout()).setRows(
((GridLayout) progressPanel.getLayout()).getRows() + 1);
++totalProgressCount;
- instance.validate();
+ validate();
return thisprogress;
}
*/
public static AlignmentPanel[] getAlignmentPanels(String alignmentId)
{
- if (Desktop.desktop == null)
+ if (getDesktopPane() == null)
{
// no frames created and in headless mode
// TODO: verify that frames are recoverable when in headless mode
public static AlignmentViewport[] getViewports(String sequenceSetId)
{
List<AlignmentViewport> viewp = new ArrayList<>();
- if (desktop != null)
+ if (getDesktopPane() != null)
{
- AlignFrame[] frames = Desktop.getAlignFrames();
+ AlignFrame[] frames = getAlignFrames();
for (AlignFrame afr : frames)
{
}
/*
- * Restore the view's last exploded frame geometry if known. Multiple views from
- * one exploded frame share and restore the same (frame) position and size.
+ * Restore the view's last exploded frame geometry if known. Multiple
+ * views from one exploded frame share and restore the same (frame)
+ * position and size.
*/
Rectangle geometry = ap.av.getExplodedGeometry();
if (geometry != null)
{
source.viewport.setGatherViewsHere(true);
source.viewport.setExplodedGeometry(source.getBounds());
- JInternalFrame[] frames = desktop.getAllFrames();
+ JInternalFrame[] frames = desktopPane.getAllFrames();
String viewId = source.viewport.getSequenceSetId();
for (int t = 0; t < frames.length; t++)
{
public JInternalFrame[] getAllFrames()
{
- return desktop.getAllFrames();
+ return desktopPane.getAllFrames();
}
/**
});
msgPanel.add(jcb);
- JvOptionPane.showMessageDialog(Desktop.desktop, msgPanel,
+ JvOptionPane.showMessageDialog(desktopPane, msgPanel,
MessageManager
.getString("label.SEQUENCE_ID_no_longer_used"),
JvOptionPane.WARNING_MESSAGE);
}
// output debug scale message. Important for jalview.bin.HiDPISettingTest2
- Desktop.debugScaleMessage(Desktop.getDesktop().getGraphics());
+ Desktop.debugScaleMessage(Desktop.getDesktopPane().getGraphics());
}
}
{
if (Jalview.isHeadlessMode())
{
- // Desktop.desktop is null in headless mode
- return new AlignFrame[] { Jalview.currentAlignFrame };
+ return new AlignFrame[] { Jalview.getInstance().currentAlignFrame };
}
- JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+ JInternalFrame[] frames = getDesktopPane().getAllFrames();
if (frames == null)
{
*/
public GStructureViewer[] getJmols()
{
- JInternalFrame[] frames = Desktop.desktop.getAllFrames();
+ JInternalFrame[] frames = desktopPane.getAllFrames();
if (frames == null)
{
} catch (Exception ex)
{
jalview.bin.Console.error("Groovy Shell Creation failed.", ex);
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ JvOptionPane.showInternalMessageDialog(desktopPane,
MessageManager.getString("label.couldnt_create_groovy_shell"),
MessageManager.getString("label.groovy_support_failed"),
/*
* We allow only one console at a time, so that AlignFrame menu option
- * 'Calculate | Run Groovy script' is unambiguous. Disable 'Groovy Console', and
- * enable 'Run script', when the console is opened, and the reverse when it is
- * closed
+ * 'Calculate | Run Groovy script' is unambiguous.
+ * Disable 'Groovy Console', and enable 'Run script', when the console is
+ * opened, and the reverse when it is closed
*/
Window window = (Window) groovyConsole.getFrame();
window.addWindowListener(new WindowAdapter()
((Window) groovyConsole.getFrame()).setVisible(true);
/*
- * if we got this far, enable 'Run Groovy' in AlignFrame menus and disable
- * opening a second console
+ * if we got this far, enable 'Run Groovy' in AlignFrame menus
+ * and disable opening a second console
*/
enableExecuteGroovy(true);
}
*/
protected void addQuitHandler()
{
- getRootPane()
- .getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
- KeyStroke
- .getKeyStroke(KeyEvent.VK_Q,
- jalview.util.ShortcutKeyMaskExWrapper
- .getMenuShortcutKeyMaskEx()),
+
+ getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
+ .put(KeyStroke.getKeyStroke(KeyEvent.VK_Q,
+ Platform.SHORTCUT_KEY_MASK),
"Quit");
getRootPane().getActionMap().put("Quit", new AbstractAction()
{
public void enableExecuteGroovy(boolean enabled)
{
/*
- * disable opening a second Groovy console (or re-enable when the console is
- * closed)
+ * disable opening a second Groovy console
+ * (or re-enable when the console is closed)
*/
groovyShell.setEnabled(!enabled);
@Override
public void setProgressBar(String message, long id)
{
+ // Platform.timeCheck("Desktop " + message, Platform.TIME_MARK);
+
if (progressBars == null)
{
progressBars = new Hashtable<>();
progressBars.put(Long.valueOf(id), addProgressPanel(message));
}
}
+
+ @Override
+ public void removeProgressBar(long id)
+ {
+ //TODO
+ throw new UnsupportedOperationException("not implemented");
+ }
/*
* (non-Javadoc)
*/
public static AlignFrame getAlignFrameFor(AlignViewportI viewport)
{
- if (desktop != null)
+ if (getDesktopPane() != null)
{
AlignmentPanel[] aps = getAlignmentPanels(
viewport.getSequenceSetId());
*/
public void startServiceDiscovery(boolean blocking)
{
- startServiceDiscovery(blocking, false);
- }
+ jalview.bin.Console.debug("Starting service discovery");
- /**
- * start service discovery threads
- *
- * @param blocking
- * - false means call returns immediately
- * @param ignore_SHOW_JWS2_SERVICES_preference
- * - when true JABA services are discovered regardless of user's JWS2
- * discovery preference setting
- */
- public void startServiceDiscovery(boolean blocking,
- boolean ignore_SHOW_JWS2_SERVICES_preference)
- {
- boolean alive = true;
- Thread t0 = null, t1 = null, t2 = null;
+ var tasks = new ArrayList<Future<?>>();
// JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
- if (true)
+
+ System.out.println("loading services");
+
+ /** @j2sIgnore */
{
// todo: changesupport handlers need to be transferred
if (discoverer == null)
{
- discoverer = new jalview.ws.jws1.Discoverer();
+ discoverer = jalview.ws.jws1.Discoverer.getInstance();
// register PCS handler for desktop.
discoverer.addPropertyChangeListener(changeSupport);
}
// JAL-940 - disabled JWS1 service configuration - always start discoverer
// until we phase out completely
- (t0 = new Thread(discoverer)).start();
+ var f = new FutureTask<Void>(discoverer, null);
+ new Thread(f).start();
+ tasks.add(f);
}
- if (ignore_SHOW_JWS2_SERVICES_preference
- || Cache.getDefault("SHOW_JWS2_SERVICES", true))
+ if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
{
- t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
- .startDiscoverer(changeSupport);
+ tasks.add(jalview.ws.jws2.Jws2Discoverer.getInstance().startDiscoverer());
}
- Thread t3 = null;
+ if (Cache.getDefault("SHOW_SLIVKA_SERVICES", true))
{
- // TODO: do rest service discovery
+ tasks.add(jalview.ws.slivkaws.SlivkaWSDiscoverer.getInstance().startDiscoverer());
}
if (blocking)
{
- while (alive)
- {
+ for (Future<?> task : tasks) {
try
{
- Thread.sleep(15);
+ // block until all discovery tasks are done
+ task.get();
} catch (Exception e)
{
+ e.printStackTrace();
}
- alive = (t1 != null && t1.isAlive()) || (t2 != null && t2.isAlive())
- || (t3 != null && t3.isAlive())
- || (t0 != null && t0.isAlive());
}
}
}
{
if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
{
- final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
- .getErrorMessages();
+ final WSDiscovererI discoverer = jalview.ws.jws2.Jws2Discoverer
+ .getInstance();
+ final String ermsg = discoverer.getErrorMessages();
+ // CONFLICT:ALT:? final String ermsg = jalview.ws.jws2.Jws2Discoverer.getInstance()
if (ermsg != null)
{
if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
/*
* JalviewDialog jd =new JalviewDialog() {
*
- * @Override protected void cancelPressed() { // TODO Auto-generated method stub
+ * @Override protected void cancelPressed() { // TODO
+ * Auto-generated method stub
*
- * }@Override protected void okPressed() { // TODO Auto-generated method stub
+ * }@Override protected void okPressed() { // TODO
+ * Auto-generated method stub
*
- * }@Override protected void raiseClosed() { // TODO Auto-generated method stub
+ * }@Override protected void raiseClosed() { // TODO
+ * Auto-generated method stub
*
- * } }; jd.initDialogFrame(new JLabel("<html><table width=\"450\"><tr><td>" +
- * ermsg +
+ * } }; jd.initDialogFrame(new
+ * JLabel("<html><table width=\"450\"><tr><td>" + ermsg +
* "<br/>It may be that you have invalid JABA URLs in your web service preferences,"
* + " or mis-configured HTTP proxy settings.<br/>" +
- * "Check the <em>Connections</em> and <em>Web services</em> tab of the" +
- * " Tools->Preferences dialog box to change them.</td></tr></table></html>" ),
- * true, true, "Web Service Configuration Problem", 450, 400);
+ * "Check the <em>Connections</em> and <em>Web services</em> tab of the"
+ * +
+ * " Tools->Preferences dialog box to change them.</td></tr></table></html>"
+ * ), true, true, "Web Service Configuration Problem", 450,
+ * 400);
*
* jd.waitForInput();
*/
- JvOptionPane.showConfirmDialog(Desktop.desktop,
+ JvOptionPane.showConfirmDialog(desktopPane,
new JLabel("<html><table width=\"450\"><tr><td>"
+ ermsg + "</td></tr></table>"
+ "<p>It may be that you have invalid JABA URLs<br/>in your web service preferences,"
*/
public static void showUrl(final String url)
{
- showUrl(url, Desktop.instance);
+ showUrl(url, getInstance());
}
/**
jalview.util.BrowserLauncher.openURL(url);
} catch (Exception ex)
{
- JvOptionPane.showInternalMessageDialog(Desktop.desktop,
+ JvOptionPane.showInternalMessageDialog(getDesktopPane(),
MessageManager
.getString("label.web_browser_not_found_unix"),
MessageManager.getString("label.web_browser_not_found"),
try
{
url = e.getURL().toString();
- Desktop.showUrl(url);
+ showUrl(url);
} catch (Exception x)
{
if (url != null)
{
- jalview.bin.Console
- .error("Couldn't handle string " + url + " as a URL.");
+ // TODO does error send to stderr if no log exists ?
+ jalview.bin.Console.error("Couldn't handle string " + url + " as a URL.");
}
// ignore any exceptions due to dud links.
}
{
}
}
- if (instance == null)
+ if (Jalview.isHeadlessMode())
{
return;
}
SwingUtilities.invokeAndWait(prompter);
} catch (Exception q)
{
- jalview.bin.Console.warn("Unexpected Exception in dialog thread.",
- q);
+ jalview.bin.Console.warn("Unexpected Exception in dialog thread.", q);
}
}
});
}
/*
- * Processing in reverse order works, forwards order leaves the first panels not
- * visible. I don't know why!
+ * Processing in reverse order works, forwards order leaves the first panels
+ * not visible. I don't know why!
*/
for (int i = viewCount - 1; i >= 0; i--)
{
/*
- * Make new top and bottom frames. These take over the respective AlignmentPanel
- * objects, including their AlignmentViewports, so the cdna/protein
- * relationships between the viewports is carried over to the new split frames.
+ * Make new top and bottom frames. These take over the respective
+ * 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
{
splitFrame.setLocation(geometry.getLocation());
}
- Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1);
+ addInternalFrame(splitFrame, sf.getTitle(), -1, -1);
}
/*
- * Clear references to the panels (now relocated in the new SplitFrames) before
- * closing the old SplitFrame.
+ * Clear references to the panels (now relocated in the new SplitFrames)
+ * before closing the old SplitFrame.
*/
topPanels.clear();
bottomPanels.clear();
String topViewId = myTopFrame.viewport.getSequenceSetId();
String bottomViewId = myBottomFrame.viewport.getSequenceSetId();
- JInternalFrame[] frames = desktop.getAllFrames();
+ JInternalFrame[] frames = desktopPane.getAllFrames();
for (JInternalFrame frame : frames)
{
if (frame instanceof SplitFrame && frame != source)
* - the payload from the drop event
* @throws Exception
*/
+ @SuppressWarnings("unchecked")
public static void transferFromDropTarget(List<Object> files,
List<DataSourceType> protocols, DropTargetDropEvent evt,
Transferable t) throws Exception
{
+ // BH 2018 changed List<String> to List<Object> to allow for File from
+ // SwingJS
+
+ // DataFlavor[] flavors = t.getTransferDataFlavors();
+ // for (int i = 0; i < flavors.length; i++) {
+ // if (flavors[i].isFlavorJavaFileListType()) {
+ // evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
+ // List<File> list = (List<File>) t.getTransferData(flavors[i]);
+ // for (int j = 0; j < list.size(); j++) {
+ // File file = (File) list.get(j);
+ // byte[] data = getDroppedFileBytes(file);
+ // fileName.setText(file.getName() + " - " + data.length + " " +
+ // evt.getLocation());
+ // JTextArea target = (JTextArea) ((DropTarget)
+ // evt.getSource()).getComponent();
+ // target.setText(new String(data));
+ // }
+ // dtde.dropComplete(true);
+ // return;
+ // }
+ //
+
DataFlavor uriListFlavor = new DataFlavor(
"text/uri-list;class=java.lang.String"), urlFlavour = null;
try
{
// Works on Windows and MacOSX
jalview.bin.Console.debug("Drop handled as javaFileListFlavor");
- for (Object file : (List) t
+ for (File file : (List<File>) t
.getTransferData(DataFlavor.javaFileListFlavor))
{
files.add(file);
}
else
{
- jalview.bin.Console
- .debug("Couldn't resolve dataflavor for drop: "
+ jalview.bin.Console.debug("Couldn't resolve dataflavor for drop: "
+ t.toString());
}
}
}
if (Platform.isWindowsAndNotJS())
{
- jalview.bin.Console
- .debug("Scanning dropped content for Windows Link Files");
+ jalview.bin.Console.debug("Scanning dropped content for Windows Link Files");
// resolve any .lnk files in the file drop
for (int f = 0; f < files.size(); f++)
Class<? extends StructureViewerBase> structureViewerClass)
{
List<StructureViewerBase> result = new ArrayList<>();
- JInternalFrame[] frames = Desktop.instance.getAllFrames();
+ JInternalFrame[] frames = getAllFrames();
for (JInternalFrame frame : frames)
{
private static boolean debugScaleMessageDone = false;
- public static void debugScaleMessage(Graphics g)
- {
- if (debugScaleMessageDone)
- {
+ public static void debugScaleMessage(Graphics g) {
+ if (debugScaleMessageDone) {
return;
}
// output used by tests to check HiDPI scaling settings in action
- try
- {
+ try {
Graphics2D gg = (Graphics2D) g;
- if (gg != null)
- {
+ if (gg != null) {
AffineTransform t = gg.getTransform();
double scaleX = t.getScaleX();
double scaleY = t.getScaleY();