From 4537a4519bf4a07e0d01589fe4c1280d86138323 Mon Sep 17 00:00:00 2001 From: jprocter Date: Sat, 19 Jun 2010 16:44:37 +0000 Subject: [PATCH] new web services preference tab (JAL-589) --- src/jalview/gui/Preferences.java | 8 +- src/jalview/gui/WsPreferences.java | 266 +++++++++++++++++++++++ src/jalview/jbgui/GPreferences.java | 11 +- src/jalview/jbgui/GWsPreferences.java | 374 +++++++++++++++++++++++++++++++++ 4 files changed, 656 insertions(+), 3 deletions(-) create mode 100644 src/jalview/gui/WsPreferences.java create mode 100644 src/jalview/jbgui/GWsPreferences.java diff --git a/src/jalview/gui/Preferences.java b/src/jalview/gui/Preferences.java index e5397bf..2c15df4 100755 --- a/src/jalview/gui/Preferences.java +++ b/src/jalview/gui/Preferences.java @@ -98,6 +98,8 @@ public class Preferences extends GPreferences DasSourceBrowser dasSource; + private WsPreferences wsPrefs; + /** * Creates a new Preferences object. */ @@ -108,7 +110,8 @@ public class Preferences extends GPreferences frame.setContentPane(this); dasSource = new DasSourceBrowser(); dasPanel.add(dasSource, BorderLayout.CENTER); - + wsPrefs = new WsPreferences(); + wsPanel.add(wsPrefs, BorderLayout.CENTER); int width = 500, height = 420; if (new jalview.util.Platform().isAMac()) { @@ -444,7 +447,7 @@ public class Preferences extends GPreferences .toString(padGaps.isSelected())); dasSource.saveProperties(Cache.applicationProperties); - + wsPrefs.updateWsMenuConfig(false); Cache.saveProperties(); try { @@ -489,6 +492,7 @@ public class Preferences extends GPreferences { try { + wsPrefs.updateWsMenuConfig(true); frame.setClosed(true); } catch (Exception ex) { diff --git a/src/jalview/gui/WsPreferences.java b/src/jalview/gui/WsPreferences.java new file mode 100644 index 0000000..8ab305e --- /dev/null +++ b/src/jalview/gui/WsPreferences.java @@ -0,0 +1,266 @@ +package jalview.gui; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.net.URL; +import java.util.Vector; + +import javax.swing.JCheckBox; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import jalview.bin.Cache; +import jalview.jbgui.GWsPreferences; + +public class WsPreferences extends GWsPreferences +{ + + public WsPreferences() + { + super(); + initFromPreferences(); + } + + Vector wsUrls,oldUrls; + private boolean needWsMenuUpdate; + private boolean oldJws1,oldJws2,oldIndexByHost,oldIndexByType,oldEnfin; + private void initFromPreferences() + { + + wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls(); + if (wsUrls!=null) { + oldUrls = new Vector(wsUrls); + } else { + oldUrls=null; + wsUrls=new Vector(); + } + updateList(); + enableEnfinServices.setSelected(oldEnfin=Cache.getDefault( + "SHOW_ENVISION2_SERVICES", true)); + enableJws1Services.setSelected(oldJws1=Cache.getDefault("SHOW_JWS1_SERVICES", + true)); + enableJws2Services.setSelected(oldJws2=Cache.getDefault("SHOW_JWS2_SERVICES", + true)); + indexByHost.setSelected(oldIndexByHost=Cache.getDefault("WSMENU_BYHOST", true)); + indexByType.setSelected(oldIndexByType=Cache.getDefault("WSMENU_BYTYPE", true)); + } + private void updateList() { + wsList.setListData(wsUrls); + } + private void updateServiceList() { + jalview.ws.jws2.Jws2Discoverer.setServiceUrls(wsUrls); + } + /* (non-Javadoc) + * @see jalview.jbgui.GWsPreferences#deleteWsUrl_actionPerformed(java.awt.event.ActionEvent) + */ + @Override + protected void deleteWsUrl_actionPerformed(ActionEvent e) + { + int sel = wsList.getSelectedIndex(); + if (sel>-1) + { + wsUrls.removeElementAt(sel); + updateList(); + } + } + + /* (non-Javadoc) + * @see jalview.jbgui.GWsPreferences#editWsUrl_actionPerformed(java.awt.event.ActionEvent) + */ + @Override + protected void editWsUrl_actionPerformed(ActionEvent e) + { + int sel = wsList.getSelectedIndex(); + if (sel>-1) + { + String url=editUrl(wsUrls.elementAt(sel),"Edit JWS2 URL"); + if (url!=null) + { + int present = wsUrls.indexOf(url); + if (present==-1) + { + wsUrls.setElementAt(url,sel); + updateList(); + } else { + if (present!=sel) + { + wsUrls.removeElementAt(sel); + updateList(); + } + } + } + } + } + + void updateWsMenuConfig(boolean old) { + if (old) { + wsUrls = (oldUrls==null) ? null : new Vector(oldUrls); + } + Cache.setProperty("SHOW_ENFIN_SERVICES", Boolean.valueOf(old ? oldEnfin : enableEnfinServices.isSelected()).toString()); + Cache.setProperty("SHOW_JWS1_SERVICES", Boolean.valueOf(old ? oldJws1 : enableJws1Services.isSelected()).toString()); + Cache.setProperty("SHOW_JWS2_SERVICES", Boolean.valueOf(old ? oldJws2 : enableJws2Services.isSelected()).toString()); + Cache.setProperty("WSMENU_BYHOST", Boolean.valueOf(old ? oldIndexByHost : indexByHost.isSelected()).toString()); + Cache.setProperty("WSMENU_BYTYPE", Boolean.valueOf(old ? oldIndexByType : indexByType.isSelected()).toString()); + updateServiceList(); + } + + /* (non-Javadoc) + * @see jalview.jbgui.GWsPreferences#moveWsUrlDown_actionPerformed(java.awt.event.ActionEvent) + */ + @Override + protected void moveWsUrlDown_actionPerformed(ActionEvent e) + { + int p=wsList.getSelectedIndex(); + if (p>-1 && p0) + { + String t = wsUrls.get(p-1); + wsUrls.setElementAt(wsUrls.elementAt(p), p-1); + wsUrls.setElementAt(t, p); + updateList(); + wsList.setSelectedIndex(p-1); + } + } + + private String editUrl(String initUrl, String title) + { + String url=initUrl; + URL foo; + if (url==null) + { + url = ""; + } + JTextField urltf = new JTextField(url, 40); + JPanel panel = new JPanel(new BorderLayout()); + JPanel pane12 = new JPanel(new BorderLayout()); + pane12.add(new JLabel("URL: "), BorderLayout.CENTER); + pane12.add(urltf, BorderLayout.EAST); + panel.add(pane12, BorderLayout.NORTH); + boolean valid=false; + int resp=JOptionPane.CANCEL_OPTION; + while (!valid && (resp=JOptionPane.showInternalConfirmDialog(Desktop.desktop, panel, title, JOptionPane.OK_CANCEL_OPTION))==JOptionPane.OK_OPTION) + { + try { + // TODO: do a better job of checking that the url is a valid discovery URL for web services. + foo = new URL(urltf.getText().trim()); + valid = true; + } catch (Exception e) + { + valid = false; + JOptionPane.showInternalMessageDialog(Desktop.desktop, "Invalid URL !"); + } + } + if (valid && resp==JOptionPane.OK_OPTION) + { + return urltf.getText().trim(); + } + return initUrl; + } + /* (non-Javadoc) + * @see jalview.jbgui.GWsPreferences#newWsUrl_actionPerformed(java.awt.event.ActionEvent) + */ + @Override + protected void newWsUrl_actionPerformed(ActionEvent e) + { + String url=editUrl(null,"Add new JWS2 URL"); + if (url!=null) + { + if (!wsUrls.contains(url)) + { + int selind = wsList.getSelectedIndex(); + if (selind>-1) + { + wsUrls.insertElementAt(url, selind); + } else { + wsUrls.addElement(url); + } + updateList(); + } + } + } + + /* (non-Javadoc) + * @see jalview.jbgui.GWsPreferences#refreshWs_actionPerformed(java.awt.event.ActionEvent) + */ + @Override + protected void refreshWs_actionPerformed(ActionEvent e) + { + new Thread(new Runnable() { + + @Override + public void run() + { + updateWsMenuConfig(false); + refreshWsMenu(true); + } + }).start(); + + } + + protected void refreshWsMenu(boolean showProgress) + { + if (showProgress) + { + new Thread(new Runnable() { + + @Override + public void run() + { + progressBar.setVisible(true); + validate(); + progressBar.setIndeterminate(true); + Desktop.instance.startServiceDiscovery(true); // wait around for all threads to complete + progressBar.setIndeterminate(false); + progressBar.setVisible(false); + validate(); + } + }).start(); + + } else { + new Thread(new Runnable() { + + @Override + public void run() + { + Desktop.instance.startServiceDiscovery(false); + } + + }).start(); + } + } + + /* (non-Javadoc) + * @see jalview.jbgui.GWsPreferences#resetWs_actionPerformed(java.awt.event.ActionEvent) + */ + @Override + protected void resetWs_actionPerformed(ActionEvent e) + { + jalview.ws.jws2.Jws2Discoverer.setServiceUrls(null); + wsUrls = jalview.ws.jws2.Jws2Discoverer.getServiceUrls(); + updateList(); + } + protected void ok_ActionPerformed(ActionEvent e) { + updateWsMenuConfig(false); + // todo: work out if the ws list needs updating ? + updateServiceList(); + refreshWsMenu(false); + } +} diff --git a/src/jalview/jbgui/GPreferences.java b/src/jalview/jbgui/GPreferences.java index ad9a308..8393b3a 100755 --- a/src/jalview/jbgui/GPreferences.java +++ b/src/jalview/jbgui/GPreferences.java @@ -186,9 +186,13 @@ public class GPreferences extends JPanel protected JCheckBox modellerOutput = new JCheckBox(); protected JPanel dasPanel = new JPanel(); - + BorderLayout borderLayout4 = new BorderLayout(); + protected JPanel wsPanel = new JPanel(); + + BorderLayout borderLayout5 = new BorderLayout(); + protected JCheckBox wrap = new JCheckBox(); protected JCheckBox rightAlign = new JCheckBox(); @@ -224,6 +228,9 @@ public class GPreferences extends JPanel protected JCheckBox shareSelections = new JCheckBox(); protected JCheckBox followHighlight = new JCheckBox(); + + + /** * Creates a new GPreferences object. @@ -589,6 +596,7 @@ public class GPreferences extends JPanel modellerOutput.setText("Use Modeller Output"); modellerOutput.setBounds(new Rectangle(228, 226, 168, 23)); dasPanel.setLayout(borderLayout4); + wsPanel.setLayout(borderLayout5); wrap.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11)); wrap.setHorizontalAlignment(SwingConstants.TRAILING); wrap.setHorizontalTextPosition(SwingConstants.LEADING); @@ -737,6 +745,7 @@ public class GPreferences extends JPanel calcTab.add(autoCalculateConsCheck); calcTab.add(padGaps); tabbedPane.add(dasPanel, "DAS Settings"); + tabbedPane.add(wsPanel, "Web Services"); exportTab.add(epsLabel); exportTab.add(epsRendering); diff --git a/src/jalview/jbgui/GWsPreferences.java b/src/jalview/jbgui/GWsPreferences.java new file mode 100644 index 0000000..4ffd193 --- /dev/null +++ b/src/jalview/jbgui/GWsPreferences.java @@ -0,0 +1,374 @@ +/** + * + */ +package jalview.jbgui; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Font; +import java.awt.GridBagLayout; +import java.awt.GridLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JProgressBar; +import javax.swing.JScrollPane; +import javax.swing.ListSelectionModel; +import javax.swing.SwingConstants; +import javax.swing.border.TitledBorder; + +/** + * Preference dialog for jalview web services + * + * @author JimP + */ +public class GWsPreferences extends JPanel +{ + protected JList wsList = new JList(); + + protected TitledBorder wsListTitleBorder = new TitledBorder( + "Web Service Discovery URLS"); + + protected JButton newWsUrl = new JButton(); + + protected JButton editWsUrl = new JButton(); + + protected JButton deleteWsUrl = new JButton(); + + protected JButton moveWsUrlUp = new JButton(); + + protected JButton moveWsUrlDown = new JButton(); + + protected JCheckBox indexByHost = new JCheckBox(); + + protected JCheckBox indexByType = new JCheckBox(); + + protected JCheckBox enableJws1Services = new JCheckBox(); + + protected JCheckBox enableJws2Services = new JCheckBox(); + + protected JCheckBox enableEnfinServices = new JCheckBox(); + + protected JButton refreshWs = new JButton(); + protected JButton resetWs = new JButton(); + + protected JProgressBar progressBar = new JProgressBar(); + + JScrollPane wsListPane = new JScrollPane(); + + JPanel wsListUrlPanel = new JPanel(); + + JPanel wsListPanel = new JPanel(); + + JPanel wsListButtons = new JPanel(); + + JPanel wsListNavButs = new JPanel(); + + BorderLayout myBorderlayout = new BorderLayout(); + + BorderLayout wsListBorderlayout = new BorderLayout(); + + GridBagLayout wsPrefLayout = new GridBagLayout(); + + GridBagLayout wsListLayout = new GridBagLayout(); + + GridBagLayout wsMenuLayout = new GridBagLayout(); + + JPanel wsMenuButtons = new JPanel(); + JPanel wsMenuRefreshButs = new JPanel(); + public GWsPreferences() + { + jbInit(); + } + + private void jbInit() + { + + refreshWs.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + refreshWs.setText("Refresh Services"); + refreshWs.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + refreshWs_actionPerformed(e); + } + }); + resetWs.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + resetWs.setText("Reset Services"); + + resetWs.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + resetWs_actionPerformed(e); + } + }); + indexByHost.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + indexByHost.setText("Index by host"); + indexByHost + .setToolTipText("Index web services in menu by the host site."); + indexByHost.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + indexByHost_actionPerformed(e); + } + }); + indexByType.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + indexByType.setText("Index by type"); + indexByType.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + indexByType_actionPerformed(e); + } + }); + enableEnfinServices + .setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + enableEnfinServices.setText("Enable Enfin Services"); + enableEnfinServices.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + enableEnfinServices_actionPerformed(e); + } + }); + enableJws2Services + .setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + enableJws2Services.setText("Enable JWS2 Services"); + enableJws2Services.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + enableJws2Services_actionPerformed(e); + } + }); + enableJws1Services + .setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + enableJws1Services.setText("Enable JWS1 Services"); + enableJws1Services.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + enableJws1Services_actionPerformed(e); + } + }); + newWsUrl.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + newWsUrl.setText("New Service URL"); + newWsUrl.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + newWsUrl_actionPerformed(e); + } + }); + editWsUrl.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + editWsUrl.setText("Edit Service URL"); + editWsUrl.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + editWsUrl_actionPerformed(e); + } + }); + + deleteWsUrl.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + deleteWsUrl.setText("Delete Service URL"); + deleteWsUrl.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + deleteWsUrl_actionPerformed(e); + } + }); + moveWsUrlUp.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + moveWsUrlUp.setText("Up"); + moveWsUrlUp.setToolTipText("Move URL up"); + moveWsUrlUp.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + moveWsUrlUp_actionPerformed(e); + } + }); + moveWsUrlDown.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + moveWsUrlDown.setText("Down"); + moveWsUrlDown.setToolTipText("Move URL Down"); + moveWsUrlDown.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + moveWsUrlDown_actionPerformed(e); + } + }); + + setLayout(myBorderlayout); + setPreferredSize(new Dimension(500,400)); + progressBar.setPreferredSize(new Dimension(450, 20)); + progressBar.setString(""); + wsListUrlPanel.setBorder(BorderFactory.createEtchedBorder()); + wsListUrlPanel.setLayout(new BorderLayout()); +// wsListUrlPanel.setPreferredSize(new Dimension(482,202)); + wsListPane.setBorder(BorderFactory.createEtchedBorder()); + wsListPane.getViewport().add(wsList); + wsListPane.setPreferredSize(new Dimension(380, 200)); + wsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + wsList.addMouseListener(new MouseListener() { + + @Override + public void mouseClicked(MouseEvent e) + { + if (e.getClickCount()>1) + { + editWsUrl_actionPerformed(null); + } + // TODO Auto-generated method stub + + } + + @Override + public void mouseEntered(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExited(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void mousePressed(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + @Override + public void mouseReleased(MouseEvent e) + { + // TODO Auto-generated method stub + + } + + }); +// wsListButtons.setPreferredSize(new Dimension(480, 60)); + wsListButtons.setLayout(new FlowLayout()); + //wsListButtons.add(moveWsUrlUp); + //wsListButtons.add(moveWsUrlDown); + wsListButtons.add(newWsUrl); + wsListButtons.add(editWsUrl); + wsListButtons.add(deleteWsUrl); + wsListNavButs.setSize(new Dimension(80,80)); + wsListNavButs.setPreferredSize(new Dimension(80,80)); + wsListNavButs.setLayout(new FlowLayout()); + wsListNavButs.add(moveWsUrlUp); + wsListNavButs.add(moveWsUrlDown); + wsListUrlPanel.add(wsListPane,BorderLayout.EAST); + wsListUrlPanel.add(wsListNavButs,BorderLayout.WEST); + wsListPanel.setBorder(wsListTitleBorder); + wsListPanel.setLayout(new BorderLayout()); + wsListPanel.add(wsListUrlPanel, BorderLayout.NORTH); + wsListPanel.add(wsListButtons, BorderLayout.SOUTH); + wsMenuButtons.setLayout(new GridLayout(2,3)); + wsMenuButtons.add(indexByHost); + wsMenuButtons.add(indexByType); + wsMenuButtons.add(enableJws1Services); + wsMenuButtons.add(enableJws2Services); + wsMenuButtons.add(enableEnfinServices); + wsMenuRefreshButs.setLayout(new FlowLayout()); + wsMenuRefreshButs.setPreferredSize(new Dimension(480,30)); + wsMenuRefreshButs.setSize(new Dimension(480,30)); + wsMenuRefreshButs.add(refreshWs,null); + wsMenuRefreshButs.add(resetWs,null); + wsMenuRefreshButs.add(progressBar,null); + myBorderlayout.setHgap(3); + add(wsListPanel,BorderLayout.NORTH); + add(wsMenuButtons,BorderLayout.CENTER); + add(wsMenuRefreshButs, BorderLayout.SOUTH); + } + + protected void resetWs_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void indexByType_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void indexByHost_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void newWsUrl_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void editWsUrl_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void deleteWsUrl_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void moveWsUrlUp_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void moveWsUrlDown_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void enableEnfinServices_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void enableJws2Services_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void enableJws1Services_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + + protected void refreshWs_actionPerformed(ActionEvent e) + { + // TODO Auto-generated method stub + + } + +} -- 1.7.10.2