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;
25 import jalview.util.dialogrunner.RunResponse;
27 import java.awt.FlowLayout;
28 import java.awt.event.ActionEvent;
29 import java.awt.event.ActionListener;
30 import java.util.concurrent.atomic.AtomicBoolean;
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;
40 * A dialog where the user may choose Text or Lineart rendering, and optionally
41 * save this as a preference
43 public class LineartOptions extends JPanel
47 public boolean cancelled = false;
51 JRadioButton lineartRB;
53 JCheckBox askAgainCB = new JCheckBox();
57 private String dialogTitle;
60 * Constructor that passes in an initial choice of Text or Lineart, as a
61 * mutable boolean object. User action in the dialog should update this
62 * object, and the <em>same</em> object should be used in any action handler
63 * set by calling <code>setResponseAction</code>.
65 * @param preferencesKey
66 * the key under which the choice is saved as a user preference, if
67 * 'Don't ask me again' is selected
69 * image type e.g. EPS, SVG
71 * true to select Text, false for Lineart
73 public LineartOptions(String preferencesKey, String formatType,
74 AtomicBoolean textOption)
76 this.asText = textOption;
77 dialogTitle = MessageManager.formatMessage(
78 "label.select_character_style_title", formatType);
82 jbInit(preferencesKey, formatType);
83 } catch (Exception ex)
88 dialog = JvOptionPane.newOptionDialog(Desktop.desktop);
92 * Registers a Runnable action to be performed for a particular user response
97 public void setResponseAction(RunResponse action)
99 dialog.response(action);
103 * Shows the dialog, and performs any registered actions depending on the user
106 public void showDialog()
108 Object[] options = new Object[] { MessageManager.getString("action.ok"),
109 MessageManager.getString("action.cancel") };
110 dialog.showInternalDialog(this, dialogTitle,
111 JvOptionPane.OK_CANCEL_OPTION, JvOptionPane.PLAIN_MESSAGE, null,
112 options, MessageManager.getString("action.ok"));
116 * Initialises the panel layout
118 * @param preferencesKey
122 private void jbInit(String preferencesKey, String formatType)
126 * radio buttons for Text or Lineart - selection updates the value
127 * of field 'asText' so it is correct when used in the confirm action
129 lineartRB = new JRadioButton(MessageManager.getString("label.lineart"));
130 lineartRB.setFont(JvSwingUtils.getLabelFont());
131 lineartRB.setSelected(!asText.get());
132 lineartRB.addActionListener(new ActionListener()
135 public void actionPerformed(ActionEvent e)
137 asText.set(!lineartRB.isSelected());
141 JRadioButton textRB = new JRadioButton(
142 MessageManager.getString("action.text"));
143 textRB.setFont(JvSwingUtils.getLabelFont());
144 textRB.setSelected(asText.get());
145 textRB.addActionListener(new ActionListener()
148 public void actionPerformed(ActionEvent e)
150 asText.set(textRB.isSelected());
154 ButtonGroup bg = new ButtonGroup();
158 askAgainCB.setFont(JvSwingUtils.getLabelFont());
159 askAgainCB.setText(MessageManager.getString("label.dont_ask_me_again"));
161 JLabel prompt = new JLabel(MessageManager.formatMessage(
162 "label.select_character_rendering_style", formatType));
163 prompt.setFont(JvSwingUtils.getLabelFont());
165 this.setLayout(new FlowLayout(FlowLayout.LEFT));
166 setBorder(BorderFactory.createEtchedBorder());
174 * If "Don't ask me again" is selected, saves the selected option as the user
175 * preference, otherwise removes the existing user preference (if any) is
178 * @param preferencesKey
180 protected void updatePreference(String preferencesKey)
182 value = lineartRB.isSelected() ? "Lineart" : "Text";
184 if (askAgainCB.isSelected())
186 Cache.setProperty(preferencesKey, value);
190 Cache.applicationProperties.remove(preferencesKey);
195 * Answers "Lineart" or "Text" as selected by the user.
199 public String getValue()