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 jalview.bin.Cache;
24 import jalview.util.MessageManager;
26 import java.awt.FlowLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29 import java.util.concurrent.atomic.AtomicBoolean;
31 import javax.swing.BorderFactory;
32 import javax.swing.ButtonGroup;
33 import javax.swing.JCheckBox;
34 import javax.swing.JLabel;
35 import javax.swing.JPanel;
36 import javax.swing.JRadioButton;
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")
42 public class LineartOptions extends JPanel
44 static final String PROMPT_EACH_TIME = "Prompt each time";
48 public boolean cancelled = false;
52 JRadioButton lineartRB;
54 JCheckBox askAgainCB = new JCheckBox();
58 private String dialogTitle;
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>.
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".
71 * image type e.g. EPS, SVG
73 * true to select Text, false for Lineart
75 public LineartOptions(String formatType, AtomicBoolean textOption)
77 this.asText = textOption;
78 dialogTitle = MessageManager.formatMessage(
79 "label.select_character_style_title", formatType);
80 String preferencesKey = formatType + "_RENDERING";
83 jbInit(preferencesKey, formatType);
84 } catch (Exception ex)
89 dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
93 * Registers a Runnable action to be performed for a particular user response
98 public void setResponseAction(Object response, Runnable action)
100 dialog.setResponseHandler(response, action);
104 * Shows the dialog, and performs any registered actions depending on the user
107 public void showDialog()
109 Object[] options = new Object[] { MessageManager.getString("action.ok"),
110 MessageManager.getString("action.cancel") };
111 dialog.showInternalDialog(this, dialogTitle,
112 JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
113 options, MessageManager.getString("action.ok"));
117 * Initialises the panel layout
119 * @param preferencesKey
123 private void jbInit(String preferencesKey, String formatType)
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
130 lineartRB = new JRadioButton(MessageManager.getString("label.lineart"));
131 lineartRB.setFont(JvSwingUtils.getLabelFont());
132 lineartRB.setSelected(!asText.get());
133 lineartRB.addActionListener(new ActionListener()
136 public void actionPerformed(ActionEvent e)
138 asText.set(!lineartRB.isSelected());
142 JRadioButton textRB = new JRadioButton(
143 MessageManager.getString("action.text"));
144 textRB.setFont(JvSwingUtils.getLabelFont());
145 textRB.setSelected(asText.get());
146 textRB.addActionListener(new ActionListener()
149 public void actionPerformed(ActionEvent e)
151 asText.set(textRB.isSelected());
155 ButtonGroup bg = new ButtonGroup();
159 askAgainCB.setFont(JvSwingUtils.getLabelFont());
160 askAgainCB.setText(MessageManager.getString("label.dont_ask_me_again"));
162 JLabel prompt = new JLabel(MessageManager.formatMessage(
163 "label.select_character_rendering_style", formatType));
164 prompt.setFont(JvSwingUtils.getLabelFont());
166 this.setLayout(new FlowLayout(FlowLayout.LEFT));
167 setBorder(BorderFactory.createEtchedBorder());
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
179 * @param preferencesKey
181 protected void updatePreference(String preferencesKey)
183 value = lineartRB.isSelected() ? "Lineart" : "Text";
185 if (askAgainCB.isSelected())
187 Cache.setProperty(preferencesKey, value);
191 Cache.applicationProperties.remove(preferencesKey);
196 * Answers "Lineart" or "Text" as selected by the user.
200 public String getValue()