update author list in license for (JAL-826)
[jalview.git] / src / jalview / jbgui / GRestServiceEditorPane.java
1 /*******************************************************************************
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  *
5  * This file is part of Jalview.
6  *
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  *******************************************************************************/
18 package jalview.jbgui;
19
20 import jalview.gui.JvSwingUtils;
21
22 import java.awt.BorderLayout;
23 import java.awt.Dimension;
24 import java.awt.FlowLayout;
25 import java.awt.GridLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.awt.event.MouseEvent;
29 import java.awt.event.MouseListener;
30
31 import javax.swing.BoxLayout;
32 import javax.swing.JButton;
33 import javax.swing.JCheckBox;
34 import javax.swing.JComboBox;
35 import javax.swing.JLabel;
36 import javax.swing.JList;
37 import javax.swing.JPanel;
38 import javax.swing.JScrollPane;
39 import javax.swing.JTabbedPane;
40 import javax.swing.JTextArea;
41 import javax.swing.JViewport;
42 import javax.swing.ListSelectionModel;
43 import javax.swing.UIManager;
44 import javax.swing.border.TitledBorder;
45 import javax.swing.event.CaretEvent;
46 import javax.swing.event.CaretListener;
47 import javax.swing.event.DocumentEvent;
48 import javax.swing.event.DocumentListener;
49 import javax.swing.event.ListSelectionListener;
50
51 import net.miginfocom.swing.MigLayout;
52
53 public class GRestServiceEditorPane extends JPanel {
54
55   protected JTabbedPane panels;
56
57   protected JPanel details, inputs, paste;
58
59   protected JTextArea urldesc, url, urlsuff, name, descr, parseRes;
60
61   protected JComboBox action, gapChar;
62
63   JLabel acttype;
64
65   protected JButton okButton;
66
67   protected JButton cancelButton;
68
69   JPanel svcattribs;
70
71   JPanel status;
72
73   protected JList iprms;
74
75   protected JList rdata;
76
77   JScrollPane iprmVp, rdataVp, parseResVp, urlVp, descrVp, urldescVp;
78
79   JButton rdataAdd, rdataRem, rdataNdown, rdataNup;
80
81   JButton iprmsAdd, iprmsRem;
82
83   protected JCheckBox hSeparable;
84
85   protected JCheckBox vSeparable;
86
87   protected JPanel parseWarnings;
88
89   public GRestServiceEditorPane()
90   {
91     jbInit();
92   }
93
94   protected void jbInit()
95   {
96     details = new JPanel();
97     details.setName("Details");
98     details.setLayout(new MigLayout());
99     inputs = new JPanel();
100     inputs.setName("Input/Output");
101     inputs.setLayout(new MigLayout("","[grow 85,fill][]",""));
102     paste = new JPanel();
103     paste.setName("Cut'n'Paste");
104     paste.setLayout(new MigLayout("","[grow 100, fill]","[][grow 100,fill]"));
105
106     panels = new JTabbedPane();
107     panels.addTab(details.getName(), details);
108     panels.addTab(inputs.getName(), inputs);
109     panels.addTab(paste.getName(), paste);
110
111     JPanel cpanel;
112
113     // Name and URL Panel
114     cpanel = details;
115     name = new JTextArea(1, 12);
116
117     JvSwingUtils
118             .mgAddtoLayout(cpanel, "Short descriptive name for service",
119                     new JLabel("Name:"), name,"wrap");
120     action = new JComboBox();
121     JvSwingUtils
122             .mgAddtoLayout(
123                     cpanel,
124                     "What kind of function the service performs (e.g. alignment, analysis, search, etc).",
125                     new JLabel("Service Action:"), action,"wrap");
126     descr = new JTextArea(4, 60);
127     descrVp = new JScrollPane();
128     descrVp.setViewportView(descr);
129     JvSwingUtils.mgAddtoLayout(cpanel, "Brief description of service",
130             new JLabel("Description:"), descrVp,"wrap");
131
132     url = new JTextArea(2, 60);
133     urlVp = new JScrollPane();
134     urlVp.setViewportView(url);
135     JvSwingUtils
136             .mgAddtoLayout(
137                     cpanel,
138                     "URL to post data to service. Include any special parameters needed here",
139                     new JLabel("POST URL:"), urlVp,"wrap");
140
141     urlsuff = new JTextArea();
142     urlsuff.setColumns(60);
143
144     JvSwingUtils
145             .mgAddtoLayout(
146                     cpanel,
147                     "Optional suffix added to URL when retrieving results from service",
148                     new JLabel("URL Suffix:"), urlsuff,"wrap");
149
150     // input options
151     // details.add(cpanel = new JPanel(), BorderLayout.CENTER);
152     // cpanel.setLayout(new FlowLayout());
153     hSeparable = new JCheckBox("per Sequence");
154     hSeparable
155             .setToolTipText("<html>"
156                     + JvSwingUtils
157                             .wrapTooltip("When checked, a job is created for every sequence in the current selection.")
158                     + "<html>");
159     hSeparable.addActionListener(new ActionListener()
160     {
161
162       @Override
163       public void actionPerformed(ActionEvent arg0)
164       {
165         hSeparable_actionPerformed(arg0);
166
167       }
168     });
169     vSeparable = new JCheckBox("Results are vertically separable");
170     vSeparable
171             .setToolTipText("<html>"
172                     + JvSwingUtils
173                             .wrapTooltip("When checked, a single job is created for the visible region and results"
174                                     + " mapped back onto their location in the alignment. Otherwise, a job would be"
175                                     + " created for every contiguous region visible in the alignment or current"
176                                     + " selection (e.g. a multiple alignment).")
177                     + "</html>");
178     vSeparable.addActionListener(new ActionListener()
179     {
180
181       @Override
182       public void actionPerformed(ActionEvent arg0)
183       {
184         vSeparable_actionPerformed(arg0);
185
186       }
187     });
188     gapChar = new JComboBox();
189     JvSwingUtils
190             .mgAddtoLayout(
191                     cpanel,
192                     "Which gap character does this service prefer ?",
193                     new JLabel("Gap Character:"), gapChar,"wrap");
194     
195
196     cpanel.add(hSeparable);
197     cpanel.add(vSeparable);
198
199     // Input and Output lists
200     // Inputparams
201     JPanel iprmsList = new JPanel();
202     iprmsList.setBorder(new TitledBorder("Data input parameters"));
203     iprmsList.setLayout(new MigLayout("","[grow 90, fill][]"));
204     iprmVp = new JScrollPane();
205     iprmVp.getViewport().setView(iprms = new JList());
206     iprmsList.add(iprmVp);
207     iprms.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
208     iprms.addMouseListener(new MouseListener()
209     {
210       
211       @Override
212       public void mouseReleased(MouseEvent e)
213       {
214         // TODO Auto-generated method stub
215         
216       }
217       
218       @Override
219       public void mousePressed(MouseEvent e)
220       {
221         // TODO Auto-generated method stub
222         
223       }
224       
225       @Override
226       public void mouseExited(MouseEvent e)
227       {
228         // TODO Auto-generated method stub
229         
230       }
231       
232       @Override
233       public void mouseEntered(MouseEvent e)
234       {
235         // TODO Auto-generated method stub
236         
237       }
238       
239       @Override
240       public void mouseClicked(MouseEvent e)
241       {
242         if (e.getClickCount()>1) {
243           iprmListSelection_doubleClicked();
244         }
245          
246       }
247     });
248     JPanel iprmButs = new JPanel();
249     iprmButs.setLayout(new MigLayout());
250
251     iprmsAdd = JvSwingUtils.makeButton("+", "Add input parameter",
252             new ActionListener()
253             {
254
255               @Override
256               public void actionPerformed(ActionEvent e)
257               {
258                 iprmsAdd_actionPerformed(e);
259
260               }
261             });
262     iprmsRem = JvSwingUtils.makeButton("-",
263             "Remove selected input parameter", new ActionListener()
264             {
265
266               @Override
267               public void actionPerformed(ActionEvent e)
268               {
269                 iprmsRem_actionPerformed(e);
270
271               }
272             });
273
274     iprmButs.add(iprmsAdd,"wrap");
275     iprmButs.add(iprmsRem,"wrap");
276     iprmsList.add(iprmButs, "wrap");
277     inputs.add(iprmsList, "wrap");
278
279     // Return Parameters
280     
281     rdataAdd = JvSwingUtils.makeButton("+", "Add return datatype",
282             new ActionListener()
283             {
284
285               @Override
286               public void actionPerformed(ActionEvent e)
287               {
288                 rdataAdd_actionPerformed(e);
289
290               }
291             });
292     rdataRem = JvSwingUtils.makeButton("-", "Remove return datatype",
293             new ActionListener()
294             {
295
296               @Override
297               public void actionPerformed(ActionEvent e)
298               {
299                 rdataRem_actionPerformed(e);
300
301               }
302             });
303     rdataNup = JvSwingUtils.makeButton("Move Up",
304             "Move return type up order", new ActionListener()
305             {
306
307               @Override
308               public void actionPerformed(ActionEvent e)
309               {
310                 rdataNup_actionPerformed(e);
311
312               }
313             });
314     rdataNdown = JvSwingUtils.makeButton("Move Down",
315             "Move return type down order", new ActionListener()
316             {
317
318               @Override
319               public void actionPerformed(ActionEvent e)
320               {
321                 rdataNdown_actionPerformed(e);
322
323               }
324             });
325
326     JPanel rparamList = new JPanel();
327     rparamList.setBorder(new TitledBorder("Data returned by service"));
328     rparamList.setLayout(new MigLayout("","[grow 90, fill][]"));
329     rdata = new JList();
330     rdata.setToolTipText("Right click to edit currently selected parameter.");
331     rdata.addMouseListener(new MouseListener()
332     {
333       
334       @Override
335       public void mouseReleased(MouseEvent arg0)
336       {
337         // TODO Auto-generated method stub
338         
339       }
340       
341       @Override
342       public void mousePressed(MouseEvent arg0)
343       {
344         
345       }
346       
347       @Override
348       public void mouseExited(MouseEvent arg0)
349       {
350         // TODO Auto-generated method stub
351         
352       }
353       
354       @Override
355       public void mouseEntered(MouseEvent arg0)
356       {
357         // TODO Auto-generated method stub
358         
359       }
360       
361       @Override
362       public void mouseClicked(MouseEvent arg0)
363       {
364         if (arg0.getButton()==MouseEvent.BUTTON3)
365         {
366           rdata_rightClicked(arg0);
367         }
368         
369       }
370     });
371     rdataVp = new JScrollPane();
372     rdataVp.getViewport().setView(rdata);
373     rparamList.add(rdataVp);
374     JPanel rparamButs = new JPanel();
375     rparamButs.setLayout(new MigLayout());
376     rparamButs.add(rdataAdd,"wrap");
377     rparamButs.add(rdataRem,"wrap");
378     rparamButs.add(rdataNup,"wrap");
379     rparamButs.add(rdataNdown,"wrap");
380     rparamList.add(rparamButs,"wrap");
381     inputs.add(rparamList,"wrap");
382  
383     // Parse flat-text to a service
384
385     
386     urldesc = new JTextArea(4,60);
387     urldesc.setEditable(true);
388     urldesc.setWrapStyleWord(true);
389     urldescVp = new JScrollPane();
390     urldescVp.setViewportView(urldesc);
391     JPanel urldescPane = new JPanel();
392     urldescPane.setLayout(new MigLayout("","[grow 100, fill]", "[grow 100, fill]"));
393     urldescPane.setBorder(new TitledBorder("RSBS Encoded Service"));
394     urldescPane.add(urldescVp, "span");
395     paste.add(urldescPane,"span");
396     urldescPane.setToolTipText("<html>"+JvSwingUtils.wrapTooltip("Flat file representation of this rest service using the Really Simple Bioinformatics Service formalism"));
397     
398     parseRes = new JTextArea();
399     parseResVp = new JScrollPane();
400     parseResVp.setViewportView(parseRes);
401     parseRes.setWrapStyleWord(true);
402     parseRes.setColumns(60);
403     parseWarnings = new JPanel(new MigLayout("","[grow 100, fill]", "[grow 100, fill]"));
404     parseWarnings.setBorder(new TitledBorder("Parsing errors"));
405     parseWarnings.setToolTipText("<html>"+JvSwingUtils.wrapTooltip("Results of parsing the RSBS representation")+"</html>");
406     parseWarnings.add(parseResVp, "center");
407     parseRes.setEditable(false);
408     paste.add(parseWarnings, "span");
409     setLayout(new BorderLayout());
410     add(panels, BorderLayout.CENTER);
411     okButton = JvSwingUtils.makeButton("OK", "", new ActionListener()
412     {
413
414       @Override
415       public void actionPerformed(ActionEvent e)
416       {
417         ok_actionPerformed();
418       }
419     });
420     cancelButton = JvSwingUtils.makeButton("Cancel", "",
421             new ActionListener()
422             {
423
424               @Override
425               public void actionPerformed(ActionEvent e)
426               {
427                 cancel_actionPerformed();
428               }
429             });
430
431   }
432
433   protected void rdata_rightClicked(MouseEvent arg0)
434   {
435     // TODO Auto-generated method stub
436     
437   }
438
439   protected void iprmListSelection_doubleClicked()
440   {
441     // TODO Auto-generated method stub
442     
443   }
444
445   protected void hSeparable_actionPerformed(ActionEvent arg0)
446   {
447     // TODO Auto-generated method stub
448
449   }
450
451   protected void vSeparable_actionPerformed(ActionEvent arg0)
452   {
453     // TODO Auto-generated method stub
454
455   }
456
457   protected void cancel_actionPerformed()
458   {
459     // TODO Auto-generated method stub
460
461   }
462
463   protected void ok_actionPerformed()
464   {
465     // TODO Auto-generated method stub
466
467   }
468
469   protected void iprmsAdd_actionPerformed(ActionEvent e)
470   {
471     // TODO Auto-generated method stub
472
473   }
474
475   protected void iprmsRem_actionPerformed(ActionEvent e)
476   {
477     // TODO Auto-generated method stub
478
479   }
480
481   protected void rdataAdd_actionPerformed(ActionEvent e)
482   {
483     // TODO Auto-generated method stub
484
485   }
486
487   protected void rdataRem_actionPerformed(ActionEvent e)
488   {
489     // TODO Auto-generated method stub
490
491   }
492
493   protected void rdataNup_actionPerformed(ActionEvent e)
494   {
495     // TODO Auto-generated method stub
496
497   }
498
499   protected void rdataNdown_actionPerformed(ActionEvent e)
500   {
501     // TODO Auto-generated method stub
502
503   }
504
505   protected void ok_actionPerformed(ActionEvent e)
506   {
507     // TODO Auto-generated method stub
508
509   }
510
511   protected void cancel_actionPerformed(ActionEvent e)
512   {
513     // TODO Auto-generated method stub
514
515   }
516
517 }