2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import java.awt.FlowLayout;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.concurrent.Callable;
27 import java.util.concurrent.atomic.AtomicBoolean;
29 import javax.swing.BorderFactory;
30 import javax.swing.ButtonGroup;
31 import javax.swing.JCheckBox;
32 import javax.swing.JLabel;
33 import javax.swing.JPanel;
34 import javax.swing.JRadioButton;
36 import jalview.bin.Cache;
37 import jalview.util.MessageManager;
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")
43 public class LineartOptions extends JPanel
45 static final String PROMPT_EACH_TIME = "Prompt each time";
49 public boolean cancelled = false;
53 JRadioButton lineartRB;
55 JCheckBox askAgainCB = new JCheckBox();
59 private String dialogTitle;
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>.
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".
72 * image type e.g. EPS, SVG
74 * true to select Text, false for Lineart
76 public LineartOptions(String formatType, AtomicBoolean textOption)
78 this.asText = textOption;
79 dialogTitle = MessageManager.formatMessage(
80 "label.select_character_style_title", formatType);
81 String preferencesKey = formatType + "_RENDERING";
84 jbInit(preferencesKey, formatType);
85 } catch (Exception ex)
90 dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
94 * Registers a Runnable action to be performed for a particular user response
99 public void setResponseAction(Object response, Callable action)
101 dialog.setResponseHandler(response, action);
105 * Shows the dialog, and performs any registered actions depending on the user
108 public void showDialog()
110 Object[] options = new Object[] { MessageManager.getString("action.ok"),
111 MessageManager.getString("action.cancel") };
112 dialog.showInternalDialog(this, dialogTitle,
113 JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
114 options, MessageManager.getString("action.ok"));
118 * Initialises the panel layout
120 * @param preferencesKey
124 private void jbInit(String preferencesKey, String formatType)
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
131 lineartRB = new JRadioButton(MessageManager.getString("label.lineart"));
132 lineartRB.setFont(JvSwingUtils.getLabelFont());
133 lineartRB.setSelected(!asText.get());
134 lineartRB.addActionListener(new ActionListener()
137 public void actionPerformed(ActionEvent e)
139 asText.set(!lineartRB.isSelected());
143 JRadioButton textRB = new JRadioButton(
144 MessageManager.getString("action.text"));
145 textRB.setFont(JvSwingUtils.getLabelFont());
146 textRB.setSelected(asText.get());
147 textRB.addActionListener(new ActionListener()
150 public void actionPerformed(ActionEvent e)
152 asText.set(textRB.isSelected());
156 ButtonGroup bg = new ButtonGroup();
160 askAgainCB.setFont(JvSwingUtils.getLabelFont());
161 askAgainCB.setText(MessageManager.getString("label.dont_ask_me_again"));
163 JLabel prompt = new JLabel(MessageManager.formatMessage(
164 "label.select_character_rendering_style", formatType));
165 prompt.setFont(JvSwingUtils.getLabelFont());
167 this.setLayout(new FlowLayout(FlowLayout.LEFT));
168 setBorder(BorderFactory.createEtchedBorder());
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
180 * @param preferencesKey
182 protected void updatePreference(String preferencesKey)
184 value = lineartRB.isSelected() ? "Lineart" : "Text";
186 if (askAgainCB.isSelected())
188 Cache.setProperty(preferencesKey, value);
192 Cache.applicationProperties.remove(preferencesKey);
197 * Answers "Lineart" or "Text" as selected by the user.
201 public String getValue()