Clover icon

Coverage Report

  1. Project Clover database Thu Nov 28 2024 18:06:40 GMT
  2. Package jalview.gui

File LineartOptions.java

 

Coverage histogram

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

Code metrics

4
38
8
1
205
108
11
0.29
4.75
8
1.38

Classes

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