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