97cbcb030e72d063c99708e89dce086c0ab0597c
[jalview.git] / src / jalview / gui / HTMLOptions.java
1 package jalview.gui;
2
3 import jalview.util.MessageManager;
4
5 import java.awt.BorderLayout;
6 import java.awt.event.ActionEvent;
7 import java.awt.event.ActionListener;
8
9 import javax.swing.BorderFactory;
10 import javax.swing.ButtonGroup;
11 import javax.swing.JButton;
12 import javax.swing.JCheckBox;
13 import javax.swing.JDialog;
14 import javax.swing.JLabel;
15 import javax.swing.JOptionPane;
16 import javax.swing.JPanel;
17 import javax.swing.JRadioButton;
18
19 public class HTMLOptions extends JPanel
20 {
21   JDialog dialog;
22
23   public boolean cancelled = false;
24
25   String value;
26
27   public HTMLOptions()
28   {
29     try
30     {
31       jbInit();
32     } catch (Exception ex)
33     {
34       ex.printStackTrace();
35     }
36
37     ButtonGroup bg = new ButtonGroup();
38     bg.add(lineart);
39     bg.add(text);
40
41     JOptionPane pane = new JOptionPane(null, JOptionPane.DEFAULT_OPTION,
42             JOptionPane.DEFAULT_OPTION, null, new Object[] { this });
43
44     dialog = pane.createDialog(Desktop.desktop, "HTML Rendering options");
45     dialog.setVisible(true);
46
47   }
48
49   private void jbInit() throws Exception
50   {
51     lineart.setFont(JvSwingUtils.getLabelFont());
52     lineart.setText(MessageManager.getString("label.lineart"));
53     text.setFont(JvSwingUtils.getLabelFont());
54     text.setText(MessageManager.getString("action.text"));
55     text.setSelected(true);
56     askAgain.setFont(JvSwingUtils.getLabelFont());
57     askAgain.setText(MessageManager.getString("label.dont_ask_me_again"));
58     ok.setText(MessageManager.getString("action.ok"));
59     ok.addActionListener(new ActionListener()
60     {
61       public void actionPerformed(ActionEvent e)
62       {
63         ok_actionPerformed(e);
64       }
65     });
66     cancel.setText(MessageManager.getString("action.cancel"));
67     cancel.addActionListener(new ActionListener()
68     {
69       public void actionPerformed(ActionEvent e)
70       {
71         cancel_actionPerformed(e);
72       }
73     });
74     jLabel1.setFont(JvSwingUtils.getLabelFont());
75     jLabel1.setText("Select HTML character rendering style");
76     this.setLayout(borderLayout1);
77     jPanel3.setBorder(BorderFactory.createEtchedBorder());
78     jPanel2.add(text);
79     jPanel2.add(lineart);
80     jPanel2.add(askAgain);
81     jPanel1.add(ok);
82     jPanel1.add(cancel);
83     jPanel3.add(jLabel1);
84     jPanel3.add(jPanel2);
85     this.add(jPanel3, java.awt.BorderLayout.CENTER);
86     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
87   }
88
89   JRadioButton lineart = new JRadioButton();
90
91   JRadioButton text = new JRadioButton();
92
93   JCheckBox askAgain = new JCheckBox();
94
95   JButton ok = new JButton();
96
97   JButton cancel = new JButton();
98
99   JPanel jPanel1 = new JPanel();
100
101   JLabel jLabel1 = new JLabel();
102
103   JPanel jPanel2 = new JPanel();
104
105   JPanel jPanel3 = new JPanel();
106
107   BorderLayout borderLayout1 = new BorderLayout();
108
109   public void ok_actionPerformed(ActionEvent e)
110   {
111     if (lineart.isSelected())
112     {
113       value = "Lineart";
114     }
115     else
116     {
117       value = "Text";
118     }
119
120     if (!askAgain.isSelected())
121     {
122       jalview.bin.Cache.applicationProperties.remove("HTML_RENDERING");
123     }
124     else
125     {
126       jalview.bin.Cache.setProperty("HTML_RENDERING", value);
127     }
128
129     dialog.setVisible(false);
130   }
131
132   public void cancel_actionPerformed(ActionEvent e)
133   {
134     cancelled = true;
135     dialog.setVisible(false);
136   }
137
138   public String getValue()
139   {
140     return value;
141   }
142 }