Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File EditNameDialog.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

4
23
4
1
127
70
7
0.3
5.75
4
1.75

Classes

Class Line # Actions
EditNameDialog 39 23 7 31
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.gui;
22   
23    import jalview.util.MessageManager;
24    import jalview.util.dialogrunner.RunResponse;
25   
26    import java.awt.FlowLayout;
27    import java.awt.Font;
28   
29    import javax.swing.BoxLayout;
30    import javax.swing.JButton;
31    import javax.swing.JComponent;
32    import javax.swing.JLabel;
33    import javax.swing.JPanel;
34    import javax.swing.JTextField;
35   
36    /**
37    * A dialog where a name and description may be edited
38    */
 
39    public class EditNameDialog
40    {
41    private static final Font COURIER_12 = new Font("Courier", Font.PLAIN,
42    12);
43    JTextField id;
44   
45    JTextField description;
46   
47    JButton ok = new JButton(MessageManager.getString("action.accept"));
48   
49    JButton cancel = new JButton(MessageManager.getString("action.cancel"));
50   
51    private JPanel panel;
52   
 
53  0 toggle public String getName()
54    {
55  0 return id.getText();
56    }
57   
 
58  0 toggle public String getDescription()
59    {
60  0 if (description.getText().length() < 1)
61    {
62  0 return null;
63    }
64    else
65    {
66  0 return description.getText();
67    }
68    }
69   
70    /**
71    * Constructor
72    *
73    * @param name
74    * @param desc
75    * @param label1
76    * @param label2
77    */
 
78  0 toggle public EditNameDialog(String name, String desc, String label1,
79    String label2)
80    {
81  0 panel = new JPanel();
82  0 panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
83  0 JPanel namePanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
84  0 JPanel descriptionPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
85  0 panel.add(namePanel);
86  0 panel.add(descriptionPanel);
87   
88  0 JLabel nameLabel = new JLabel(label1);
89  0 nameLabel.setFont(COURIER_12);
90  0 namePanel.add(nameLabel);
91   
92  0 id = new JTextField(name, 40);
93  0 namePanel.add(id);
94   
95  0 description = new JTextField(desc, 40);
96   
97    /*
98    * optionally add field for description
99    */
100  0 if (desc != null || label2 != null)
101    {
102  0 JLabel descLabel = new JLabel(label2);
103  0 descLabel.setFont(COURIER_12);
104  0 descriptionPanel.add(descLabel);
105  0 descriptionPanel.add(description);
106    }
107    }
108   
109    /**
110    * Shows the dialog, and runs the response action if OK is selected. Note the
111    * RunResponse should be constructed to act on dialog return value
112    * JvOptionPane.OK_OPTION.
113    *
114    * @param action
115    */
 
116  0 toggle public void showDialog(JComponent parent, String title,
117    RunResponse action)
118    {
119  0 Object[] options = new Object[] { MessageManager.getString("action.ok"),
120    MessageManager.getString("action.cancel") };
121  0 JvOptionPane.newOptionDialog(parent).response(action)
122    .showInternalDialog(panel, title,
123    JvOptionPane.YES_NO_CANCEL_OPTION,
124    JvOptionPane.PLAIN_MESSAGE, null, options,
125    MessageManager.getString("action.ok"));
126    }
127    }