d8f0d9a6662230f01a93f0250fd78e9b75ac5c3d
[jalview.git] / src / jalview / gui / EPSOptions.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.util.MessageManager;
24
25 import java.awt.BorderLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28
29 import javax.swing.BorderFactory;
30 import javax.swing.ButtonGroup;
31 import javax.swing.JButton;
32 import javax.swing.JCheckBox;
33 import javax.swing.JDialog;
34 import javax.swing.JLabel;
35 import javax.swing.JOptionPane;
36 import javax.swing.JPanel;
37 import javax.swing.JRadioButton;
38
39 public class EPSOptions extends JPanel
40 {
41   JDialog dialog;
42
43   public boolean cancelled = false;
44
45   String value;
46
47   public EPSOptions()
48   {
49     try
50     {
51       jbInit();
52     } catch (Exception ex)
53     {
54       ex.printStackTrace();
55     }
56
57     ButtonGroup bg = new ButtonGroup();
58     bg.add(lineart);
59     bg.add(text);
60
61     JOptionPane pane = new JOptionPane(null, JvOptionPane.DEFAULT_OPTION,
62             JvOptionPane.DEFAULT_OPTION, null, new Object[]
63             { this });
64
65     dialog = pane.createDialog(Desktop.desktop, "EPS Rendering options");
66     dialog.setVisible(true);
67
68   }
69
70   private void jbInit() throws Exception
71   {
72     lineart.setFont(JvSwingUtils.getLabelFont());
73     lineart.setText(MessageManager.getString("label.lineart"));
74     text.setFont(JvSwingUtils.getLabelFont());
75     text.setText(MessageManager.getString("action.text"));
76     text.setSelected(true);
77     askAgain.setFont(JvSwingUtils.getLabelFont());
78     askAgain.setText(MessageManager.getString("label.dont_ask_me_again"));
79     ok.setText(MessageManager.getString("action.ok"));
80     ok.addActionListener(new ActionListener()
81     {
82       @Override
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       @Override
92       public void actionPerformed(ActionEvent e)
93       {
94         cancel_actionPerformed(e);
95       }
96     });
97     jLabel1.setFont(JvSwingUtils.getLabelFont());
98     jLabel1.setText(MessageManager
99             .getString("label.select_eps_character_rendering_style"));
100     this.setLayout(borderLayout1);
101     jPanel3.setBorder(BorderFactory.createEtchedBorder());
102     jPanel2.add(text);
103     jPanel2.add(lineart);
104     jPanel2.add(askAgain);
105     jPanel1.add(ok);
106     jPanel1.add(cancel);
107     jPanel3.add(jLabel1);
108     jPanel3.add(jPanel2);
109     this.add(jPanel3, java.awt.BorderLayout.CENTER);
110     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
111   }
112
113   JRadioButton lineart = new JRadioButton();
114
115   JRadioButton text = new JRadioButton();
116
117   JCheckBox askAgain = new JCheckBox();
118
119   JButton ok = new JButton();
120
121   JButton cancel = new JButton();
122
123   JPanel jPanel1 = new JPanel();
124
125   JLabel jLabel1 = new JLabel();
126
127   JPanel jPanel2 = new JPanel();
128
129   JPanel jPanel3 = new JPanel();
130
131   BorderLayout borderLayout1 = new BorderLayout();
132
133   public void ok_actionPerformed(ActionEvent e)
134   {
135     if (lineart.isSelected())
136     {
137       value = "Lineart";
138     }
139     else
140     {
141       value = "Text";
142     }
143
144     if (!askAgain.isSelected())
145     {
146       jalview.bin.Cache.applicationProperties.remove("EPS_RENDERING");
147     }
148     else
149     {
150       jalview.bin.Cache.setProperty("EPS_RENDERING", value);
151     }
152
153     dialog.setVisible(false);
154   }
155
156   public void cancel_actionPerformed(ActionEvent e)
157   {
158     cancelled = true;
159     dialog.setVisible(false);
160   }
161
162   public String getValue()
163   {
164     return value;
165   }
166 }