69fde89ad9a69e8f3a5a8d7785cc7d7a7030b54a
[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, JOptionPane.DEFAULT_OPTION,
62             JOptionPane.DEFAULT_OPTION, null, new Object[] { this });
63
64     dialog = pane.createDialog(Desktop.desktop, "EPS Rendering options");
65     dialog.setVisible(true);
66
67   }
68
69   private void jbInit() throws Exception
70   {
71     lineart.setFont(JvSwingUtils.getLabelFont());
72     lineart.setText(MessageManager.getString("label.lineart"));
73     text.setFont(JvSwingUtils.getLabelFont());
74     text.setText(MessageManager.getString("action.text"));
75     text.setSelected(true);
76     askAgain.setFont(JvSwingUtils.getLabelFont());
77     askAgain.setText(MessageManager.getString("label.dont_ask_me_again"));
78     ok.setText(MessageManager.getString("action.ok"));
79     ok.addActionListener(new ActionListener()
80     {
81       public void actionPerformed(ActionEvent e)
82       {
83         ok_actionPerformed(e);
84       }
85     });
86     cancel.setText(MessageManager.getString("action.cancel"));
87     cancel.addActionListener(new ActionListener()
88     {
89       public void actionPerformed(ActionEvent e)
90       {
91         cancel_actionPerformed(e);
92       }
93     });
94     jLabel1.setFont(JvSwingUtils.getLabelFont());
95     jLabel1.setText(MessageManager
96             .getString("label.select_eps_character_rendering_style"));
97     this.setLayout(borderLayout1);
98     jPanel3.setBorder(BorderFactory.createEtchedBorder());
99     jPanel2.add(text);
100     jPanel2.add(lineart);
101     jPanel2.add(askAgain);
102     jPanel1.add(ok);
103     jPanel1.add(cancel);
104     jPanel3.add(jLabel1);
105     jPanel3.add(jPanel2);
106     this.add(jPanel3, java.awt.BorderLayout.CENTER);
107     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
108   }
109
110   JRadioButton lineart = new JRadioButton();
111
112   JRadioButton text = new JRadioButton();
113
114   JCheckBox askAgain = new JCheckBox();
115
116   JButton ok = new JButton();
117
118   JButton cancel = new JButton();
119
120   JPanel jPanel1 = new JPanel();
121
122   JLabel jLabel1 = new JLabel();
123
124   JPanel jPanel2 = new JPanel();
125
126   JPanel jPanel3 = new JPanel();
127
128   BorderLayout borderLayout1 = new BorderLayout();
129
130   public void ok_actionPerformed(ActionEvent e)
131   {
132     if (lineart.isSelected())
133     {
134       value = "Lineart";
135     }
136     else
137     {
138       value = "Text";
139     }
140
141     if (!askAgain.isSelected())
142     {
143       jalview.bin.Cache.applicationProperties.remove("EPS_RENDERING");
144     }
145     else
146     {
147       jalview.bin.Cache.setProperty("EPS_RENDERING", value);
148     }
149
150     dialog.setVisible(false);
151   }
152
153   public void cancel_actionPerformed(ActionEvent e)
154   {
155     cancelled = true;
156     dialog.setVisible(false);
157   }
158
159   public String getValue()
160   {
161     return value;
162   }
163 }