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.BorderLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
30 import javax.swing.BorderFactory;
31 import javax.swing.ButtonGroup;
32 import javax.swing.JButton;
33 import javax.swing.JCheckBox;
34 import javax.swing.JDialog;
35 import javax.swing.JLabel;
36 import javax.swing.JOptionPane;
37 import javax.swing.JPanel;
38 import javax.swing.JRadioButton;
41 * A dialog where the user may choose Text or Lineart rendering, and optionally
42 * save this as a preference
44 public class LineartOptions extends JPanel
48 public boolean cancelled = false;
52 JRadioButton lineartRB;
54 JCheckBox askAgainCB = new JCheckBox();
59 * @param preferencesKey
60 * the key under which the choice is saved as a user preference, if
61 * 'Don't ask me again' is selected
64 public LineartOptions(String preferencesKey, String formatType)
68 jbInit(preferencesKey, formatType);
69 } catch (Exception ex)
74 JOptionPane pane = new JOptionPane(null, JvOptionPane.DEFAULT_OPTION,
75 JvOptionPane.DEFAULT_OPTION, null, new Object[]
78 String theTitle = MessageManager.formatMessage(
79 "label.select_character_style_title", formatType);
80 dialog = pane.createDialog(Desktop.desktop, theTitle);
81 dialog.setVisible(true);
84 private void jbInit(String preferencesKey, String formatType)
87 lineartRB = new JRadioButton(MessageManager.getString("label.lineart"));
88 lineartRB.setFont(JvSwingUtils.getLabelFont());
89 JRadioButton text = new JRadioButton(
90 MessageManager.getString("action.text"));
91 text.setFont(JvSwingUtils.getLabelFont());
92 text.setSelected(true);
94 ButtonGroup bg = new ButtonGroup();
98 askAgainCB.setFont(JvSwingUtils.getLabelFont());
99 askAgainCB.setText(MessageManager.getString("label.dont_ask_me_again"));
100 JButton ok = new JButton(MessageManager.getString("action.ok"));
101 ok.addActionListener(new ActionListener()
104 public void actionPerformed(ActionEvent e)
106 ok_actionPerformed(preferencesKey);
109 JButton cancel = new JButton(MessageManager.getString("action.cancel"));
110 cancel.addActionListener(new ActionListener()
113 public void actionPerformed(ActionEvent e)
115 cancel_actionPerformed(e);
118 JLabel jLabel1 = new JLabel(MessageManager.formatMessage(
119 "label.select_character_rendering_style", formatType));
120 jLabel1.setFont(JvSwingUtils.getLabelFont());
122 this.setLayout(new BorderLayout());
123 JPanel jPanel3 = new JPanel();
124 jPanel3.setBorder(BorderFactory.createEtchedBorder());
125 JPanel optionsPanel = new JPanel();
126 optionsPanel.add(text);
127 optionsPanel.add(lineartRB);
128 optionsPanel.add(askAgainCB);
129 JPanel okCancelPanel = new JPanel();
130 okCancelPanel.add(ok);
131 okCancelPanel.add(cancel);
132 jPanel3.add(jLabel1);
133 jPanel3.add(optionsPanel);
134 this.add(jPanel3, BorderLayout.CENTER);
135 this.add(okCancelPanel, BorderLayout.SOUTH);
139 * Action on OK is to save the selected option as the <code>value</code> field
140 * and close the dialog. If "Don't ask me again" is selected, it is also saved
141 * as user preference, otherwise the existing user preference (if any) is
144 * @param preferencesKey
146 protected void ok_actionPerformed(String preferencesKey)
148 if (lineartRB.isSelected())
157 if (!askAgainCB.isSelected())
159 Cache.applicationProperties.remove(preferencesKey);
163 Cache.setProperty(preferencesKey, value);
165 dialog.setVisible(false);
169 * Action on Cancel is to hide the dialog
173 protected void cancel_actionPerformed(ActionEvent e)
176 dialog.setVisible(false);
180 * Answers "Lineart" or "Text" as selected by the user.
184 public String getValue()