formatting
[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
56   protected JTabbedPane panels;
57
58   protected JPanel details, inputs, paste;
59
60   protected JTextArea urldesc, url, urlsuff, name, descr, parseRes;
61
62   protected JComboBox action, gapChar;
63
64   JLabel acttype;
65
66   protected JButton okButton;
67
68   protected JButton cancelButton;
69
70   JPanel svcattribs;
71
72   JPanel status;
73
74   protected JList iprms;
75
76   protected JList rdata;
77
78   JScrollPane iprmVp, rdataVp, parseResVp, urlVp, descrVp, urldescVp;
79
80   JButton rdataAdd, rdataRem, rdataNdown, rdataNup;
81
82   JButton iprmsAdd, iprmsRem;
83
84   protected JCheckBox hSeparable;
85
86   protected JCheckBox vSeparable;
87
88   protected JPanel parseWarnings;
89
90   public GRestServiceEditorPane()
91   {
92     jbInit();
93   }
94
95   protected void jbInit()
96   {
97     details = new JPanel();
98     details.setName("Details");
99     details.setLayout(new MigLayout());
100     inputs = new JPanel();
101     inputs.setName("Input/Output");
102     inputs.setLayout(new MigLayout("", "[grow 85,fill][]", ""));
103     paste = new JPanel();
104     paste.setName("Cut'n'Paste");
105     paste.setLayout(new MigLayout("", "[grow 100, fill]",
106             "[][grow 100,fill]"));
107
108     panels = new JTabbedPane();
109     panels.addTab(details.getName(), details);
110     panels.addTab(inputs.getName(), inputs);
111     panels.addTab(paste.getName(), paste);
112
113     JPanel cpanel;
114
115     // Name and URL Panel
116     cpanel = details;
117     name = new JTextArea(1, 12);
118
119     JvSwingUtils.mgAddtoLayout(cpanel,
120             "Short descriptive name for service", new JLabel("Name:"),
121             name, "wrap");
122     action = new JComboBox();
123     JvSwingUtils
124             .mgAddtoLayout(
125                     cpanel,
126                     "What kind of function the service performs (e.g. alignment, analysis, search, etc).",
127                     new JLabel("Service Action:"), action, "wrap");
128     descr = new JTextArea(4, 60);
129     descrVp = new JScrollPane();
130     descrVp.setViewportView(descr);
131     JvSwingUtils.mgAddtoLayout(cpanel, "Brief description of service",
132             new JLabel("Description:"), descrVp, "wrap");
133
134     url = new JTextArea(2, 60);
135     urlVp = new JScrollPane();
136     urlVp.setViewportView(url);
137     JvSwingUtils
138             .mgAddtoLayout(
139                     cpanel,
140                     "URL to post data to service. Include any special parameters needed here",
141                     new JLabel("POST URL:"), urlVp, "wrap");
142
143     urlsuff = new JTextArea();
144     urlsuff.setColumns(60);
145
146     JvSwingUtils
147             .mgAddtoLayout(
148                     cpanel,
149                     "Optional suffix added to URL when retrieving results from service",
150                     new JLabel("URL Suffix:"), urlsuff, "wrap");
151
152     // input options
153     // details.add(cpanel = new JPanel(), BorderLayout.CENTER);
154     // cpanel.setLayout(new FlowLayout());
155     hSeparable = new JCheckBox("per Sequence");
156     hSeparable
157             .setToolTipText("<html>"
158                     + JvSwingUtils
159                             .wrapTooltip("When checked, a job is created for every sequence in the current selection.")
160                     + "<html>");
161     hSeparable.addActionListener(new ActionListener()
162     {
163
164       @Override
165       public void actionPerformed(ActionEvent arg0)
166       {
167         hSeparable_actionPerformed(arg0);
168
169       }
170     });
171     vSeparable = new JCheckBox("Results are vertically separable");
172     vSeparable
173             .setToolTipText("<html>"
174                     + JvSwingUtils
175                             .wrapTooltip("When checked, a single job is created for the visible region and results"
176                                     + " mapped back onto their location in the alignment. Otherwise, a job would be"
177                                     + " created for every contiguous region visible in the alignment or current"
178                                     + " selection (e.g. a multiple alignment).")
179                     + "</html>");
180     vSeparable.addActionListener(new ActionListener()
181     {
182
183       @Override
184       public void actionPerformed(ActionEvent arg0)
185       {
186         vSeparable_actionPerformed(arg0);
187
188       }
189     });
190     gapChar = new JComboBox();
191     JvSwingUtils.mgAddtoLayout(cpanel,
192             "Which gap character does this service prefer ?", new JLabel(
193                     "Gap Character:"), gapChar, "wrap");
194
195     cpanel.add(hSeparable);
196     cpanel.add(vSeparable);
197
198     // Input and Output lists
199     // Inputparams
200     JPanel iprmsList = new JPanel();
201     iprmsList.setBorder(new TitledBorder("Data input parameters"));
202     iprmsList.setLayout(new MigLayout("", "[grow 90, fill][]"));
203     iprmVp = new JScrollPane();
204     iprmVp.getViewport().setView(iprms = new JList());
205     iprmsList.add(iprmVp);
206     iprms.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
207     iprms.addMouseListener(new MouseListener()
208     {
209
210       @Override
211       public void mouseReleased(MouseEvent e)
212       {
213         // TODO Auto-generated method stub
214
215       }
216
217       @Override
218       public void mousePressed(MouseEvent e)
219       {
220         // TODO Auto-generated method stub
221
222       }
223
224       @Override
225       public void mouseExited(MouseEvent e)
226       {
227         // TODO Auto-generated method stub
228
229       }
230
231       @Override
232       public void mouseEntered(MouseEvent e)
233       {
234         // TODO Auto-generated method stub
235
236       }
237
238       @Override
239       public void mouseClicked(MouseEvent e)
240       {
241         if (e.getClickCount() > 1)
242         {
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     urldesc = new JTextArea(4, 60);
386     urldesc.setEditable(true);
387     urldesc.setWrapStyleWord(true);
388     urldescVp = new JScrollPane();
389     urldescVp.setViewportView(urldesc);
390     JPanel urldescPane = new JPanel();
391     urldescPane.setLayout(new MigLayout("", "[grow 100, fill]",
392             "[grow 100, fill]"));
393     urldescPane.setBorder(new TitledBorder("RSBS Encoded Service"));
394     urldescPane.add(urldescVp, "span");
395     paste.add(urldescPane, "span");
396     urldescPane
397             .setToolTipText("<html>"
398                     + JvSwingUtils
399                             .wrapTooltip("Flat file representation of this rest service using the Really Simple Bioinformatics Service formalism"));
400
401     parseRes = new JTextArea();
402     parseResVp = new JScrollPane();
403     parseResVp.setViewportView(parseRes);
404     parseRes.setWrapStyleWord(true);
405     parseRes.setColumns(60);
406     parseWarnings = new JPanel(new MigLayout("", "[grow 100, fill]",
407             "[grow 100, fill]"));
408     parseWarnings.setBorder(new TitledBorder("Parsing errors"));
409     parseWarnings
410             .setToolTipText("<html>"
411                     + JvSwingUtils
412                             .wrapTooltip("Results of parsing the RSBS representation")
413                     + "</html>");
414     parseWarnings.add(parseResVp, "center");
415     parseRes.setEditable(false);
416     paste.add(parseWarnings, "span");
417     setLayout(new BorderLayout());
418     add(panels, BorderLayout.CENTER);
419     okButton = JvSwingUtils.makeButton("OK", "", new ActionListener()
420     {
421
422       @Override
423       public void actionPerformed(ActionEvent e)
424       {
425         ok_actionPerformed();
426       }
427     });
428     cancelButton = JvSwingUtils.makeButton("Cancel", "",
429             new ActionListener()
430             {
431
432               @Override
433               public void actionPerformed(ActionEvent e)
434               {
435                 cancel_actionPerformed();
436               }
437             });
438
439   }
440
441   protected void rdata_rightClicked(MouseEvent arg0)
442   {
443     // TODO Auto-generated method stub
444
445   }
446
447   protected void iprmListSelection_doubleClicked()
448   {
449     // TODO Auto-generated method stub
450
451   }
452
453   protected void hSeparable_actionPerformed(ActionEvent arg0)
454   {
455     // TODO Auto-generated method stub
456
457   }
458
459   protected void vSeparable_actionPerformed(ActionEvent arg0)
460   {
461     // TODO Auto-generated method stub
462
463   }
464
465   protected void cancel_actionPerformed()
466   {
467     // TODO Auto-generated method stub
468
469   }
470
471   protected void ok_actionPerformed()
472   {
473     // TODO Auto-generated method stub
474
475   }
476
477   protected void iprmsAdd_actionPerformed(ActionEvent e)
478   {
479     // TODO Auto-generated method stub
480
481   }
482
483   protected void iprmsRem_actionPerformed(ActionEvent e)
484   {
485     // TODO Auto-generated method stub
486
487   }
488
489   protected void rdataAdd_actionPerformed(ActionEvent e)
490   {
491     // TODO Auto-generated method stub
492
493   }
494
495   protected void rdataRem_actionPerformed(ActionEvent e)
496   {
497     // TODO Auto-generated method stub
498
499   }
500
501   protected void rdataNup_actionPerformed(ActionEvent e)
502   {
503     // TODO Auto-generated method stub
504
505   }
506
507   protected void rdataNdown_actionPerformed(ActionEvent e)
508   {
509     // TODO Auto-generated method stub
510
511   }
512
513   protected void ok_actionPerformed(ActionEvent e)
514   {
515     // TODO Auto-generated method stub
516
517   }
518
519   protected void cancel_actionPerformed(ActionEvent e)
520   {
521     // TODO Auto-generated method stub
522
523   }
524
525 }