JAL-1807 explicit imports (jalview.gui)
[jalview.git] / src / jalview / gui / SVGOptions.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.gui;
22
23 import jalview.bin.Cache;
24 import jalview.util.MessageManager;
25
26 import java.awt.BorderLayout;
27 import java.awt.event.ActionEvent;
28 import java.awt.event.ActionListener;
29
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;
39
40 public class SVGOptions extends JPanel
41 {
42   JDialog dialog;
43
44   public boolean cancelled = false;
45
46   String value;
47
48   public SVGOptions()
49   {
50     try
51     {
52       jbInit();
53     } catch (Exception ex)
54     {
55       ex.printStackTrace();
56     }
57
58     ButtonGroup bg = new ButtonGroup();
59     bg.add(lineart);
60     bg.add(text);
61
62     JOptionPane pane = new JOptionPane(null, JOptionPane.DEFAULT_OPTION,
63             JOptionPane.DEFAULT_OPTION, null, new Object[]
64             { this });
65
66     dialog = pane.createDialog(Desktop.desktop, "SVG Rendering options");
67     dialog.setVisible(true);
68
69   }
70
71   private void jbInit() throws Exception
72   {
73     lineart.setFont(JvSwingUtils.getLabelFont());
74     lineart.setText(MessageManager.getString("label.lineart"));
75     text.setFont(JvSwingUtils.getLabelFont());
76     text.setText(MessageManager.getString("action.text"));
77     text.setSelected(true);
78     askAgain.setFont(JvSwingUtils.getLabelFont());
79     askAgain.setText(MessageManager.getString("label.dont_ask_me_again"));
80     ok.setText(MessageManager.getString("action.ok"));
81     ok.addActionListener(new ActionListener()
82     {
83       public void actionPerformed(ActionEvent e)
84       {
85         ok_actionPerformed(e);
86       }
87     });
88     cancel.setText(MessageManager.getString("action.cancel"));
89     cancel.addActionListener(new ActionListener()
90     {
91       public void actionPerformed(ActionEvent e)
92       {
93         cancel_actionPerformed(e);
94       }
95     });
96     jLabel1.setFont(JvSwingUtils.getLabelFont());
97     jLabel1.setText("Select SVG character rendering style");
98     this.setLayout(borderLayout1);
99     jPanel3.setBorder(BorderFactory.createEtchedBorder());
100     jPanel2.add(text);
101     jPanel2.add(lineart);
102     jPanel2.add(askAgain);
103     jPanel1.add(ok);
104     jPanel1.add(cancel);
105     jPanel3.add(jLabel1);
106     jPanel3.add(jPanel2);
107     this.add(jPanel3, java.awt.BorderLayout.CENTER);
108     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
109   }
110
111   JRadioButton lineart = new JRadioButton();
112
113   JRadioButton text = new JRadioButton();
114
115   JCheckBox askAgain = new JCheckBox();
116
117   JButton ok = new JButton();
118
119   JButton cancel = new JButton();
120
121   JPanel jPanel1 = new JPanel();
122
123   JLabel jLabel1 = new JLabel();
124
125   JPanel jPanel2 = new JPanel();
126
127   JPanel jPanel3 = new JPanel();
128
129   BorderLayout borderLayout1 = new BorderLayout();
130
131   public void ok_actionPerformed(ActionEvent e)
132   {
133     if (lineart.isSelected())
134     {
135       value = "Lineart";
136     }
137     else
138     {
139       value = "Text";
140     }
141
142     if (!askAgain.isSelected())
143     {
144       Cache.applicationProperties.remove("SVG_RENDERING");
145     }
146     else
147     {
148       Cache.setProperty("SVG_RENDERING", value);
149     }
150
151     dialog.setVisible(false);
152   }
153
154   public void cancel_actionPerformed(ActionEvent e)
155   {
156     cancelled = true;
157     dialog.setVisible(false);
158   }
159
160   public String getValue()
161   {
162     return value;
163   }
164 }