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