+
+ private final String AAconsToggle = "AACons Calculations",
+ AAconsToggleTooltip = "When checked, AACons calculations are updated automatically.",
+ AAeditSettings = "Change AACons Settings...",
+ AAeditSettingsTooltip = "Modify settings for AACons calculations.";
+
+ // private final enableAAConsCalculation(final AlignFrame alignFrame, )
+ private void registerAAConsWSInstance(final JMenu wsmenu,
+ final Jws2Instance service, final AlignFrame alignFrame)
+ {
+ // register this in the AACons settings set
+ JCheckBoxMenuItem _aaConsEnabled = null;
+ for (int i = 0; i < wsmenu.getItemCount(); i++)
+ {
+ JMenuItem item = wsmenu.getItem(i);
+ if (item instanceof JCheckBoxMenuItem
+ && item.getText().equals(AAconsToggle))
+ {
+ _aaConsEnabled = (JCheckBoxMenuItem) item;
+ }
+ }
+ // is there an aaCons worker already present - if so, set it to use the
+ // given service handle
+ {
+ List<AlignCalcWorkerI> aaconsClient = alignFrame.getViewport()
+ .getCalcManager()
+ .getRegisteredWorkersOfClass(AAConsClient.class);
+ if (aaconsClient != null && aaconsClient.size() > 0)
+ {
+ AAConsClient worker = (AAConsClient) aaconsClient.get(0);
+ if (!worker.service.hosturl.equals(service.hosturl))
+ {
+ // javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ // @Override
+ // public void run()
+ {
+ removeCurrentAAConsWorkerFor(alignFrame);
+ buildCurrentAAConsWorkerFor(alignFrame, service);
+ }
+ }//);
+ }
+ }
+ }
+
+ // is there a service already registered ? there shouldn't be if we are
+ // being called correctly
+ if (_aaConsEnabled == null)
+ {
+ final JCheckBoxMenuItem aaConsEnabled = new JCheckBoxMenuItem(
+ AAconsToggle);
+ wsmenu.addMenuListener(new MenuListener()
+ {
+
+ @Override
+ public void menuSelected(MenuEvent arg0)
+ {
+ wsmenu.setEnabled(!alignFrame.getViewport().getAlignment()
+ .isNucleotide());
+ List<AlignCalcWorkerI> aaconsClient = alignFrame.getViewport()
+ .getCalcManager()
+ .getRegisteredWorkersOfClass(AAConsClient.class);
+ if (aaconsClient != null && aaconsClient.size() > 0)
+ {
+ aaConsEnabled.setSelected(true);
+ }
+ else
+ {
+ aaConsEnabled.setSelected(false);
+ }
+ }
+
+ @Override
+ public void menuDeselected(MenuEvent arg0)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void menuCanceled(MenuEvent arg0)
+ {
+ // TODO Auto-generated method stub
+
+ }
+ });
+ aaConsEnabled.setToolTipText("<html><p>"
+ + JvSwingUtils.wrapTooltip(AAconsToggleTooltip + "</p>")
+ + "</html>");
+ aaConsEnabled.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ // aaConsEnabled.setSelected(!aaConsEnabled.isSelected());
+ List<AlignCalcWorkerI> aaconsClient = alignFrame.getViewport()
+ .getCalcManager()
+ .getRegisteredWorkersOfClass(AAConsClient.class);
+ if (aaconsClient != null && aaconsClient.size() > 0)
+ {
+ removeCurrentAAConsWorkerFor(alignFrame);
+ }
+ else
+ {
+ buildCurrentAAConsWorkerFor(alignFrame);
+
+ }
+ }
+
+ });
+ wsmenu.add(aaConsEnabled);
+ JMenuItem modifyParams = new JMenuItem(AAeditSettings);
+ modifyParams.setToolTipText("<html><p>"
+ + JvSwingUtils.wrapTooltip(AAeditSettingsTooltip + "</p>")
+ + "</html>");
+ modifyParams.addActionListener(new ActionListener()
+ {
+
+ @Override
+ public void actionPerformed(ActionEvent arg0)
+ {
+ showAAConsAnnotationSettingsFor(alignFrame);
+ }
+ });
+ wsmenu.add(modifyParams);
+
+ }
+ }
+
+ private static void showAAConsAnnotationSettingsFor(AlignFrame alignFrame)
+ {
+ /*
+ * preferred settings Whether AACons is automatically recalculated Which
+ * AACons server to use What parameters to use
+ */
+ // could actually do a class search for this too
+ AAConsSettings fave = (AAConsSettings) alignFrame.getViewport()
+ .getCalcIdSettingsFor(AAConsCalcId);
+ if (fave == null)
+ {
+ fave = createDefaultAAConsSettings();
+ }
+ new SequenceAnnotationWSClient(fave, alignFrame, true);
+
+ }
+
+ private static void buildCurrentAAConsWorkerFor(AlignFrame alignFrame)
+ {
+ buildCurrentAAConsWorkerFor(alignFrame, null);
+ }
+
+ private static void buildCurrentAAConsWorkerFor(AlignFrame alignFrame,
+ Jws2Instance service)
+ {
+ /*
+ * preferred settings Whether AACons is automatically recalculated Which
+ * AACons server to use What parameters to use
+ */
+ AAConsSettings fave = (AAConsSettings) alignFrame.getViewport()
+ .getCalcIdSettingsFor(AAConsCalcId);
+ if (fave == null)
+ {
+ fave = createDefaultAAConsSettings(service);
+ }
+ else
+ {
+ if (service != null
+ && !fave.getService().hosturl.equals(service.hosturl))
+ {
+ Cache.log.debug("Changing AACons service to " + service.hosturl
+ + " from " + fave.getService().hosturl);
+ fave.setService(service);
+ }
+ }
+ new SequenceAnnotationWSClient(fave, alignFrame, false);
+ }
+
+ private static AAConsSettings createDefaultAAConsSettings()
+ {
+ return createDefaultAAConsSettings(null);
+ }
+
+ private static AAConsSettings createDefaultAAConsSettings(
+ Jws2Instance service)
+ {
+ if (service != null)
+ {
+ if (!service.serviceType.toString().equals(
+ compbio.ws.client.Services.AAConWS.toString()))
+ {
+ Cache.log
+ .warn("Ignoring invalid preferred service for AACons calculations (service type was "
+ + service.serviceType + ")");
+ service = null;
+ }
+ else
+ {
+ // check service is actually in the list of currently avaialable
+ // services
+ if (!Jws2Discoverer.getDiscoverer().getServices().contains(service))
+ {
+ // it isn't ..
+ service = null;
+ }
+ }
+ }
+ if (service == null)
+ {
+ // get the default service for AACons
+ service = Jws2Discoverer.getDiscoverer().getPreferredServiceFor(null,
+ compbio.ws.client.Services.AAConWS.toString());
+ /*
+ * for (Jws2Instance sv : Jws2Discoverer.getDiscoverer().getServices()) {
+ * if (sv.serviceType.toString().equals(
+ * compbio.ws.client.Services.AAConWS.toString())) { service = sv; break;
+ * } }
+ */
+ }
+ if (service == null)
+ {
+ // TODO raise dialog box explaining error, and/or open the JABA
+ // preferences menu.
+ throw new Error("No AACons service found.");
+ }
+ return new AAConsSettings(true, service, null, null);
+ }
+
+ private static void removeCurrentAAConsWorkerFor(AlignFrame alignFrame)
+ {
+ alignFrame.getViewport().getCalcManager()
+ .removeRegisteredWorkersOfClass(AAConsClient.class);
+ // AAConsClient.removeAAConsAnnotation(alignFrame.alignPanel);
+
+ }