+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.gui;
+
+import jalview.bin.Cache;
+import jalview.util.MessageManager;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.ButtonGroup;
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+
+/**
+ * A dialog where the user may choose Text or Lineart rendering, and optionally
+ * save this as a preference
+ */
+public class LineartOptions extends JPanel
+{
+ JDialog dialog;
+
+ public boolean cancelled = false;
+
+ String value;
+
+ JRadioButton lineartRB;
+
+ JCheckBox askAgainCB = new JCheckBox();
+
+ /**
+ * Constructor
+ *
+ * @param preferencesKey
+ * the key under which the choice is saved as a user preference, if
+ * 'Don't ask me again' is selected
+ * @param formatType
+ */
+ public LineartOptions(String preferencesKey, String formatType)
+ {
+ try
+ {
+ jbInit(preferencesKey, formatType);
+ } catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+
+ JOptionPane pane = new JOptionPane(null, JvOptionPane.DEFAULT_OPTION,
+ JvOptionPane.DEFAULT_OPTION, null, new Object[]
+ { this });
+
+ String theTitle = MessageManager.formatMessage(
+ "label.select_character_style_title", formatType);
+ dialog = pane.createDialog(Desktop.desktop, theTitle);
+ dialog.setVisible(true);
+ }
+
+ private void jbInit(String preferencesKey, String formatType)
+ throws Exception
+ {
+ lineartRB = new JRadioButton(MessageManager.getString("label.lineart"));
+ lineartRB.setFont(JvSwingUtils.getLabelFont());
+ JRadioButton text = new JRadioButton(
+ MessageManager.getString("action.text"));
+ text.setFont(JvSwingUtils.getLabelFont());
+ text.setSelected(true);
+
+ ButtonGroup bg = new ButtonGroup();
+ bg.add(lineartRB);
+ bg.add(text);
+
+ askAgainCB.setFont(JvSwingUtils.getLabelFont());
+ askAgainCB.setText(MessageManager.getString("label.dont_ask_me_again"));
+ JButton ok = new JButton(MessageManager.getString("action.ok"));
+ ok.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ ok_actionPerformed(preferencesKey);
+ }
+ });
+ JButton cancel = new JButton(MessageManager.getString("action.cancel"));
+ cancel.addActionListener(new ActionListener()
+ {
+ @Override
+ public void actionPerformed(ActionEvent e)
+ {
+ cancel_actionPerformed(e);
+ }
+ });
+ JLabel jLabel1 = new JLabel(MessageManager.formatMessage(
+ "label.select_character_rendering_style", formatType));
+ jLabel1.setFont(JvSwingUtils.getLabelFont());
+
+ this.setLayout(new BorderLayout());
+ JPanel jPanel3 = new JPanel();
+ jPanel3.setBorder(BorderFactory.createEtchedBorder());
+ JPanel optionsPanel = new JPanel();
+ optionsPanel.add(text);
+ optionsPanel.add(lineartRB);
+ optionsPanel.add(askAgainCB);
+ JPanel okCancelPanel = new JPanel();
+ okCancelPanel.add(ok);
+ okCancelPanel.add(cancel);
+ jPanel3.add(jLabel1);
+ jPanel3.add(optionsPanel);
+ this.add(jPanel3, BorderLayout.CENTER);
+ this.add(okCancelPanel, BorderLayout.SOUTH);
+ }
+
+ /**
+ * Action on OK is to save the selected option as the <code>value</code> field
+ * and close the dialog. If "Don't ask me again" is selected, it is also saved
+ * as user preference, otherwise the existing user preference (if any) is
+ * removed.
+ *
+ * @param preferencesKey
+ */
+ protected void ok_actionPerformed(String preferencesKey)
+ {
+ if (lineartRB.isSelected())
+ {
+ value = "Lineart";
+ }
+ else
+ {
+ value = "Text";
+ }
+
+ if (!askAgainCB.isSelected())
+ {
+ Cache.applicationProperties.remove(preferencesKey);
+ }
+ else
+ {
+ Cache.setProperty(preferencesKey, value);
+ }
+ dialog.setVisible(false);
+ }
+
+ /**
+ * Action on Cancel is to hide the dialog
+ *
+ * @param e
+ */
+ protected void cancel_actionPerformed(ActionEvent e)
+ {
+ cancelled = true;
+ dialog.setVisible(false);
+ }
+
+ /**
+ * Answers "Lineart" or "Text" as selected by the user.
+ *
+ * @return
+ */
+ public String getValue()
+ {
+ return value;
+ }
+}