691b3d00f051f3cd7cf023181215015d2a708e5e
[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.getString("label.select_eps_character_rendering_style"));
87     this.setLayout(borderLayout1);
88     jPanel3.setBorder(BorderFactory.createEtchedBorder());
89     jPanel2.add(text);
90     jPanel2.add(lineart);
91     jPanel2.add(askAgain);
92     jPanel1.add(ok);
93     jPanel1.add(cancel);
94     jPanel3.add(jLabel1);
95     jPanel3.add(jPanel2);
96     this.add(jPanel3, java.awt.BorderLayout.CENTER);
97     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
98   }
99
100   JRadioButton lineart = new JRadioButton();
101
102   JRadioButton text = new JRadioButton();
103
104   JCheckBox askAgain = new JCheckBox();
105
106   JButton ok = new JButton();
107
108   JButton cancel = new JButton();
109
110   JPanel jPanel1 = new JPanel();
111
112   JLabel jLabel1 = new JLabel();
113
114   JPanel jPanel2 = new JPanel();
115
116   JPanel jPanel3 = new JPanel();
117
118   BorderLayout borderLayout1 = new BorderLayout();
119
120   public void ok_actionPerformed(ActionEvent e)
121   {
122     if (lineart.isSelected())
123     {
124       value = "Lineart";
125     }
126     else
127     {
128       value = "Text";
129     }
130
131     if (!askAgain.isSelected())
132     {
133       jalview.bin.Cache.applicationProperties.remove("EPS_RENDERING");
134     }
135     else
136     {
137       jalview.bin.Cache.setProperty("EPS_RENDERING", value);
138     }
139
140     dialog.setVisible(false);
141   }
142
143   public void cancel_actionPerformed(ActionEvent e)
144   {
145     cancelled = true;
146     dialog.setVisible(false);
147   }
148
149   public String getValue()
150   {
151     return value;
152   }
153 }