Clover icon

jalviewX

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

File LineartOptions.java

 

Coverage histogram

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

Code metrics

4
38
8
1
206
109
11
0.29
4.75
8
1.38

Classes

Class Line # Actions
LineartOptions 43 38 11 50
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.bin.Cache;
24    import jalview.util.MessageManager;
25    import jalview.util.dialogrunner.RunResponse;
26   
27    import java.awt.FlowLayout;
28    import java.awt.event.ActionEvent;
29    import java.awt.event.ActionListener;
30    import java.util.concurrent.atomic.AtomicBoolean;
31   
32    import javax.swing.BorderFactory;
33    import javax.swing.ButtonGroup;
34    import javax.swing.JCheckBox;
35    import javax.swing.JLabel;
36    import javax.swing.JPanel;
37    import javax.swing.JRadioButton;
38   
39    /**
40    * A dialog where the user may choose Text or Lineart rendering, and optionally
41    * save this as a preference ("Don't ask me again")
42    */
 
43    public class LineartOptions extends JPanel
44    {
45    static final String PROMPT_EACH_TIME = "Prompt each time";
46   
47    JvOptionPane dialog;
48   
49    public boolean cancelled = false;
50   
51    String value;
52   
53    JRadioButton lineartRB;
54   
55    JCheckBox askAgainCB = new JCheckBox();
56   
57    AtomicBoolean asText;
58   
59    private String dialogTitle;
60   
61    /**
62    * Constructor that passes in an initial choice of Text or Lineart, as a
63    * mutable boolean object. User action in the dialog should update this
64    * object, and the <em>same</em> object should be used in any action handler
65    * set by calling <code>setResponseAction</code>.
66    * <p>
67    * If the user chooses an option and also "Don't ask me again", the chosen
68    * option is saved as a property with key type_RENDERING i.e. "EPS_RENDERING",
69    * "SVG_RENDERING" or "HTML_RENDERING".
70    *
71    * @param formatType
72    * image type e.g. EPS, SVG
73    * @param textOption
74    * true to select Text, false for Lineart
75    */
 
76  0 toggle public LineartOptions(String formatType, AtomicBoolean textOption)
77    {
78  0 this.asText = textOption;
79  0 dialogTitle = MessageManager.formatMessage(
80    "label.select_character_style_title", formatType);
81  0 String preferencesKey = formatType + "_RENDERING";
82  0 try
83    {
84  0 jbInit(preferencesKey, formatType);
85    } catch (Exception ex)
86    {
87  0 ex.printStackTrace();
88    }
89   
90  0 dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
91    }
92   
93    /**
94    * Registers a Runnable action to be performed for a particular user response
95    * in the dialog
96    *
97    * @param action
98    */
 
99  0 toggle public void setResponseAction(RunResponse action)
100    {
101  0 dialog.response(action);
102    }
103   
104    /**
105    * Shows the dialog, and performs any registered actions depending on the user
106    * choices
107    */
 
108  0 toggle public void showDialog()
109    {
110  0 Object[] options = new Object[] { MessageManager.getString("action.ok"),
111    MessageManager.getString("action.cancel") };
112  0 dialog.showInternalDialog(this, dialogTitle,
113    JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
114    options, MessageManager.getString("action.ok"));
115    }
116   
117    /**
118    * Initialises the panel layout
119    *
120    * @param preferencesKey
121    * @param formatType
122    * @throws Exception
123    */
 
124  0 toggle private void jbInit(String preferencesKey, String formatType)
125    throws Exception
126    {
127    /*
128    * radio buttons for Text or Lineart - selection updates the value
129    * of field 'asText' so it is correct when used in the confirm action
130    */
131  0 lineartRB = new JRadioButton(MessageManager.getString("label.lineart"));
132  0 lineartRB.setFont(JvSwingUtils.getLabelFont());
133  0 lineartRB.setSelected(!asText.get());
134  0 lineartRB.addActionListener(new ActionListener()
135    {
 
136  0 toggle @Override
137    public void actionPerformed(ActionEvent e)
138    {
139  0 asText.set(!lineartRB.isSelected());
140    }
141    });
142   
143  0 JRadioButton textRB = new JRadioButton(
144    MessageManager.getString("action.text"));
145  0 textRB.setFont(JvSwingUtils.getLabelFont());
146  0 textRB.setSelected(asText.get());
147  0 textRB.addActionListener(new ActionListener()
148    {
 
149  0 toggle @Override
150    public void actionPerformed(ActionEvent e)
151    {
152  0 asText.set(textRB.isSelected());
153    }
154    });
155   
156  0 ButtonGroup bg = new ButtonGroup();
157  0 bg.add(lineartRB);
158  0 bg.add(textRB);
159   
160  0 askAgainCB.setFont(JvSwingUtils.getLabelFont());
161  0 askAgainCB.setText(MessageManager.getString("label.dont_ask_me_again"));
162   
163  0 JLabel prompt = new JLabel(MessageManager.formatMessage(
164    "label.select_character_rendering_style", formatType));
165  0 prompt.setFont(JvSwingUtils.getLabelFont());
166   
167  0 this.setLayout(new FlowLayout(FlowLayout.LEFT));
168  0 setBorder(BorderFactory.createEtchedBorder());
169  0 add(prompt);
170  0 add(textRB);
171  0 add(lineartRB);
172  0 add(askAgainCB);
173    }
174   
175    /**
176    * If "Don't ask me again" is selected, saves the selected option as the user
177    * preference, otherwise removes the existing user preference (if any) is
178    * removed
179    *
180    * @param preferencesKey
181    */
 
182  0 toggle protected void updatePreference(String preferencesKey)
183    {
184  0 value = lineartRB.isSelected() ? "Lineart" : "Text";
185   
186  0 if (askAgainCB.isSelected())
187    {
188  0 Cache.setProperty(preferencesKey, value);
189    }
190    else
191    {
192  0 Cache.applicationProperties.remove(preferencesKey);
193    }
194    }
195   
196    /**
197    * Answers "Lineart" or "Text" as selected by the user.
198    *
199    * @return
200    */
 
201  0 toggle public String getValue()
202    {
203    // todo remove
204  0 return value;
205    }
206    }