applied copyright 2008
[jalview.git] / src / jalview / gui / EPSOptions.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18  */
19 package jalview.gui;
20
21 import java.awt.*;
22 import java.awt.event.*;
23 import javax.swing.*;
24
25 public class EPSOptions
26     extends JPanel
27 {
28   JDialog dialog;
29   public boolean cancelled = false;
30   String value;
31
32   public EPSOptions()
33   {
34     try
35     {
36       jbInit();
37     }
38     catch (Exception ex)
39     {
40       ex.printStackTrace();
41     }
42
43     ButtonGroup bg = new ButtonGroup();
44     bg.add(lineart);
45     bg.add(text);
46
47     JOptionPane pane = new JOptionPane(null,
48                                        JOptionPane.DEFAULT_OPTION,
49                                        JOptionPane.DEFAULT_OPTION,
50                                        null, new Object[]
51                                        {this});
52
53     dialog = pane.createDialog(Desktop.desktop, "EPS Rendering options");
54     dialog.setVisible(true);
55
56   }
57
58   private void jbInit()
59       throws Exception
60   {
61     lineart.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
62     lineart.setText("Lineart");
63     text.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
64     text.setText("Text");
65     text.setSelected(true);
66     askAgain.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
67     askAgain.setText("Don\'t ask me again");
68     ok.setText("OK");
69     ok.addActionListener(new ActionListener()
70     {
71       public void actionPerformed(ActionEvent e)
72       {
73         ok_actionPerformed(e);
74       }
75     });
76     cancel.setText("Cancel");
77     cancel.addActionListener(new ActionListener()
78     {
79       public void actionPerformed(ActionEvent e)
80       {
81         cancel_actionPerformed(e);
82       }
83     });
84     jLabel1.setFont(new java.awt.Font("Verdana", Font.PLAIN, 11));
85     jLabel1.setText("Select EPS character rendering style");
86     this.setLayout(borderLayout1);
87     jPanel3.setBorder(BorderFactory.createEtchedBorder());
88     jPanel2.add(text);
89     jPanel2.add(lineart);
90     jPanel2.add(askAgain);
91     jPanel1.add(ok);
92     jPanel1.add(cancel);
93     jPanel3.add(jLabel1);
94     jPanel3.add(jPanel2);
95     this.add(jPanel3, java.awt.BorderLayout.CENTER);
96     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
97   }
98
99   JRadioButton lineart = new JRadioButton();
100   JRadioButton text = new JRadioButton();
101   JCheckBox askAgain = new JCheckBox();
102   JButton ok = new JButton();
103   JButton cancel = new JButton();
104   JPanel jPanel1 = new JPanel();
105   JLabel jLabel1 = new JLabel();
106   JPanel jPanel2 = new JPanel();
107   JPanel jPanel3 = new JPanel();
108   BorderLayout borderLayout1 = new BorderLayout();
109
110   public void ok_actionPerformed(ActionEvent e)
111   {
112     if (lineart.isSelected())
113     {
114       value = "Lineart";
115     }
116     else
117     {
118       value = "Text";
119     }
120
121     if (!askAgain.isSelected())
122     {
123       jalview.bin.Cache.applicationProperties.remove("EPS_RENDERING");
124     }
125     else
126     {
127       jalview.bin.Cache.setProperty("EPS_RENDERING", value);
128     }
129
130     dialog.setVisible(false);
131   }
132
133   public void cancel_actionPerformed(ActionEvent e)
134   {
135     cancelled = true;
136     dialog.setVisible(false);
137   }
138
139   public String getValue()
140   {
141     return value;
142   }
143 }