progressBarHandlers;
/*
* (non-Javadoc)
*
* @see jalview.gui.IProgressIndicator#setProgressBar(java.lang.String, long)
*/
@Override
public void setProgressBar(String message, long id)
{
Platform.timeCheck("Desktop " + message, Platform.TIME_MARK);
if (progressBars == null)
{
progressBars = new Hashtable<>();
progressBarHandlers = new Hashtable<>();
}
if (progressBars.get(new Long(id)) != null)
{
JPanel panel = progressBars.remove(new Long(id));
if (progressBarHandlers.contains(new Long(id)))
{
progressBarHandlers.remove(new Long(id));
}
removeProgressPanel(panel);
}
else
{
progressBars.put(new Long(id), addProgressPanel(message));
}
}
/*
* (non-Javadoc)
*
* @see jalview.gui.IProgressIndicator#registerHandler(long,
* jalview.gui.IProgressIndicatorHandler)
*/
@Override
public void registerHandler(final long id,
final IProgressIndicatorHandler handler)
{
if (progressBarHandlers == null
|| !progressBars.containsKey(new Long(id)))
{
throw new Error(MessageManager.getString(
"error.call_setprogressbar_before_registering_handler"));
}
progressBarHandlers.put(new Long(id), handler);
final JPanel progressPanel = progressBars.get(new Long(id));
if (handler.canCancel())
{
JButton cancel = new JButton(
MessageManager.getString("action.cancel"));
final IProgressIndicator us = this;
cancel.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
handler.cancelActivity(id);
us.setProgressBar(MessageManager
.formatMessage("label.cancelled_params", new Object[]
{ ((JLabel) progressPanel.getComponent(0)).getText() }),
id);
}
});
progressPanel.add(cancel, BorderLayout.EAST);
}
}
/**
*
* @return true if any progress bars are still active
*/
@Override
public boolean operationInProgress()
{
if (progressBars != null && progressBars.size() > 0)
{
return true;
}
return false;
}
/**
* This will return the first AlignFrame holding the given viewport instance. It
* will break if there are more than one AlignFrames viewing a particular av.
*
* @param viewport
* @return alignFrame for viewport
*/
public static AlignFrame getAlignFrameFor(AlignViewportI viewport)
{
if (desktop != null)
{
AlignmentPanel[] aps = getAlignmentPanels(
viewport.getSequenceSetId());
for (int panel = 0; aps != null && panel < aps.length; panel++)
{
if (aps[panel] != null && aps[panel].av == viewport)
{
return aps[panel].alignFrame;
}
}
}
return null;
}
public VamsasApplication getVamsasApplication()
{
return v_client;
}
/**
* flag set if jalview GUI is being operated programmatically
*/
private boolean inBatchMode = false;
/**
* check if jalview GUI is being operated programmatically
*
* @return inBatchMode
*/
public boolean isInBatchMode()
{
return inBatchMode;
}
/**
* set flag if jalview GUI is being operated programmatically
*
* @param inBatchMode
*/
public void setInBatchMode(boolean inBatchMode)
{
this.inBatchMode = inBatchMode;
}
public void startServiceDiscovery()
{
startServiceDiscovery(false);
}
public void startServiceDiscovery(boolean blocking)
{
boolean alive = true;
Thread t0 = null, t1 = null, t2 = null;
// JAL-940 - JALVIEW 1 services are now being EOLed as of JABA 2.1 release
if (true)
{
// todo: changesupport handlers need to be transferred
if (discoverer == null)
{
discoverer = new jalview.ws.jws1.Discoverer();
// 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();
}
if (Cache.getDefault("SHOW_JWS2_SERVICES", true))
{
t2 = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
.startDiscoverer(changeSupport);
}
Thread t3 = null;
{
// TODO: do rest service discovery
}
if (blocking)
{
while (alive)
{
try
{
Thread.sleep(15);
} catch (Exception e)
{
}
alive = (t1 != null && t1.isAlive()) || (t2 != null && t2.isAlive())
|| (t3 != null && t3.isAlive())
|| (t0 != null && t0.isAlive());
}
}
}
/**
* called to check if the service discovery process completed successfully.
*
* @param evt
*/
protected void JalviewServicesChanged(PropertyChangeEvent evt)
{
if (evt.getNewValue() == null || evt.getNewValue() instanceof Vector)
{
final String ermsg = jalview.ws.jws2.Jws2Discoverer.getDiscoverer()
.getErrorMessages();
if (ermsg != null)
{
if (Cache.getDefault("SHOW_WSDISCOVERY_ERRORS", true))
{
if (serviceChangedDialog == null)
{
// only run if we aren't already displaying one of these.
addDialogThread(serviceChangedDialog = new Runnable()
{
@Override
public void run()
{
/*
* JalviewDialog jd =new JalviewDialog() {
*
* @Override protected void cancelPressed() { // TODO
* Auto-generated method stub
*
* }@Override protected void okPressed() { // TODO
* Auto-generated method stub
*
* }@Override protected void raiseClosed() { // TODO
* Auto-generated method stub
*
* } }; jd.initDialogFrame(new
* JLabel("" + ermsg +
* " It may be that you have invalid JABA URLs in your web service preferences,"
* + " or mis-configured HTTP proxy settings. " +
* "Check the Connections and Web services tab of the"
* +
* " Tools->Preferences dialog box to change them. |
"
* ), true, true, "Web Service Configuration Problem", 450,
* 400);
*
* jd.waitForInput();
*/
JvOptionPane.showConfirmDialog(Desktop.desktop,
new JLabel(""
+ "It may be that you have invalid JABA URLs
in your web service preferences,"
+ "
or as a command-line argument, or mis-configured HTTP proxy settings.
"
+ "Check the Connections and Web services tab
of the"
+ " Tools->Preferences dialog box to change them.
"),
"Web Service Configuration Problem",
JvOptionPane.DEFAULT_OPTION,
JvOptionPane.ERROR_MESSAGE);
serviceChangedDialog = null;
}
});
}
}
else
{
Cache.log.error(
"Errors reported by JABA discovery service. Check web services preferences.\n"
+ ermsg);
}
}
}
}
private Runnable serviceChangedDialog = null;
/**
* start a thread to open a URL in the configured browser. Pops up a warning
* dialog to the user if there is an exception when calling out to the browser
* to open the URL.
*
* @param url
*/
public static void showUrl(final String url)
{
showUrl(url, Desktop.instance);
}
/**
* Like showUrl but allows progress handler to be specified
*
* @param url
* @param progress
* (null) or object implementing IProgressIndicator
*/
public static void showUrl(final String url,
final IProgressIndicator progress)
{
new Thread(new Runnable()
{
@Override
public void run()
{
try
{
if (progress != null)
{
progress.setProgressBar(MessageManager
.formatMessage("status.opening_params", new Object[]
{ url }), this.hashCode());
}
jalview.util.BrowserLauncher.openURL(url);
} catch (Exception ex)
{
JvOptionPane.showInternalMessageDialog(Desktop.desktop,
MessageManager
.getString("label.web_browser_not_found_unix"),
MessageManager.getString("label.web_browser_not_found"),
JvOptionPane.WARNING_MESSAGE);
ex.printStackTrace();
}
if (progress != null)
{
progress.setProgressBar(null, this.hashCode());
}
}
}).start();
}
public static WsParamSetManager wsparamManager = null;
public static ParamManager getUserParameterStore()
{
if (wsparamManager == null)
{
wsparamManager = new WsParamSetManager();
}
return wsparamManager;
}
/**
* static hyperlink handler proxy method for use by Jalview's internal windows
*
* @param e
*/
public static void hyperlinkUpdate(HyperlinkEvent e)
{
if (e.getEventType() == EventType.ACTIVATED)
{
String url = null;
try
{
url = e.getURL().toString();
Desktop.showUrl(url);
} catch (Exception x)
{
if (url != null)
{
if (Cache.log != null)
{
Cache.log.error("Couldn't handle string " + url + " as a URL.");
}
else
{
System.err.println(
"Couldn't handle string " + url + " as a URL.");
}
}
// ignore any exceptions due to dud links.
}
}
}
/**
* single thread that handles display of dialogs to user.
*/
ExecutorService dialogExecutor = Executors.newSingleThreadExecutor();
/**
* flag indicating if dialogExecutor should try to acquire a permit
*/
private volatile boolean dialogPause = true;
/**
* pause the queue
*/
private java.util.concurrent.Semaphore block = new Semaphore(0);
private static groovy.ui.Console groovyConsole;
/**
* add another dialog thread to the queue
*
* @param prompter
*/
public void addDialogThread(final Runnable prompter)
{
dialogExecutor.submit(new Runnable()
{
@Override
public void run()
{
if (dialogPause)
{
try
{
block.acquire();
} catch (InterruptedException x)
{
}
;
}
if (instance == null)
{
return;
}
try
{
SwingUtilities.invokeAndWait(prompter);
} catch (Exception q)
{
Cache.log.warn("Unexpected Exception in dialog thread.", q);
}
}
});
}
public void startDialogQueue()
{
// set the flag so we don't pause waiting for another permit and semaphore
// the current task to begin
dialogPause = false;
block.release();
}
/**
* Outputs an image of the desktop to file in EPS format, after prompting the
* user for choice of Text or Lineart character rendering (unless a preference
* has been set). The file name is generated as
*
*
* Jalview_snapshot_nnnnn.eps where nnnnn is the current timestamp in milliseconds
*
*/
@Override
protected void snapShotWindow_actionPerformed(ActionEvent e)
{
// currently the menu option to do this is not shown
invalidate();
int width = getWidth();
int height = getHeight();
File of = new File(
"Jalview_snapshot_" + System.currentTimeMillis() + ".eps");
ImageWriterI writer = new ImageWriterI()
{
@Override
public void exportImage(Graphics g) throws Exception
{
paintAll(g);
Cache.log.info("Successfully written snapshot to file "
+ of.getAbsolutePath());
}
};
String title = "View of desktop";
ImageExporter exporter = new ImageExporter(writer, null, TYPE.EPS,
title);
exporter.doExport(of, this, width, height, title);
}
/**
* 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
*/
public void explodeViews(SplitFrame sf)
{
AlignFrame oldTopFrame = (AlignFrame) sf.getTopFrame();
AlignFrame oldBottomFrame = (AlignFrame) sf.getBottomFrame();
List extends AlignmentViewPanel> topPanels = oldTopFrame
.getAlignPanels();
List extends AlignmentViewPanel> bottomPanels = oldBottomFrame
.getAlignPanels();
int viewCount = topPanels.size();
if (viewCount < 2)
{
return;
}
/*
* 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.
*
* 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(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(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);
if (geometry != null)
{
splitFrame.setLocation(geometry.getLocation());
}
Desktop.addInternalFrame(splitFrame, sf.getTitle(), -1, -1);
}
/*
* Clear references to the panels (now relocated in the new SplitFrames)
* before closing the old SplitFrame.
*/
topPanels.clear();
bottomPanels.clear();
sf.close();
}
/**
* Gather expanded split frames, sharing the same pairs of sequence set ids,
* back into the given SplitFrame as additional views. Note that the gathered
* frames may themselves have multiple views.
*
* @param source
*/
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(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();
String bottomViewId = myBottomFrame.viewport.getSequenceSetId();
JInternalFrame[] frames = desktop.getAllFrames();
for (JInternalFrame frame : frames)
{
if (frame instanceof SplitFrame && frame != source)
{
SplitFrame sf = (SplitFrame) frame;
AlignFrame topFrame = (AlignFrame) sf.getTopFrame();
AlignFrame bottomFrame = (AlignFrame) sf.getBottomFrame();
boolean gatherThis = false;
for (int a = 0; a < topFrame.alignPanels.size(); a++)
{
AlignmentPanel topPanel = topFrame.alignPanels.get(a);
AlignmentPanel bottomPanel = bottomFrame.alignPanels.get(a);
if (topViewId.equals(topPanel.av.getSequenceSetId())
&& bottomViewId.equals(bottomPanel.av.getSequenceSetId()))
{
gatherThis = true;
topPanel.av.setGatherViewsHere(false);
bottomPanel.av.setGatherViewsHere(false);
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);
}
}
if (gatherThis)
{
topFrame.getAlignPanels().clear();
bottomFrame.getAlignPanels().clear();
sf.close();
}
}
}
/*
* The dust settles...give focus to the tab we did this from.
*/
myTopFrame.setDisplayedView(myTopFrame.alignPanel);
}
public static groovy.ui.Console getGroovyConsole()
{
return groovyConsole;
}
/**
* handles the payload of a drag and drop event.
*
* TODO refactor to desktop utilities class
*
* @param files
* - Data source strings extracted from the drop event
* @param protocols
* - protocol for each data source extracted from the drop event
* @param evt
* - the drop event
* @param t
* - the payload from the drop event
* @throws Exception
*/
public static void transferFromDropTarget(List