buffer stores 2 channels of double; colour using both channels; default supersample...
[maximus:sft.git] / SuperFractalThing / source / OptionsDialog.java
1 //      Options Dialog
2 //
3 //    Copyright 2013 Kevin Martin
4 //
5 //    This file is part of SuperFractalThing.
6 //
7 //    SuperFractalThing is free software: you can redistribute it and/or modify
8 //    it under the terms of the GNU General Public License as published by
9 //    the Free Software Foundation, either version 3 of the License, or
10 //    any later version.
11 //
12 //    SuperFractalThing is distributed in the hope that it will be useful,
13 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //    GNU General Public License for more details.
16 //
17 //    You should have received a copy of the GNU General Public License
18 //    along with SuperFractalThing.  If not, see <http://www.gnu.org/licenses/>.
19 //
20
21 import java.awt.Component;
22 import java.awt.Dimension;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
27 import java.text.NumberFormat;
28
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JFormattedTextField;
32 import javax.swing.JFrame;
33 import javax.swing.JLabel;
34 import javax.swing.JPanel;
35 import javax.swing.JComboBox;
36
37
38 public class OptionsDialog implements ActionListener
39 {
40         JDialog mDialog;
41         Component mComponent;
42         JFrame mFrame;
43         JButton mCancel_button;
44         JButton mOK_button;
45         boolean mOK;
46         JFormattedTextField mNum_threads;
47         JComboBox<String> mSuper_sample;
48         int mSave_ss;
49         int mSave_thr;
50         
51         public OptionsDialog(JFrame aFrame, Component aComponent)
52         {
53                 mComponent = aComponent;
54                 mFrame = aFrame;
55                 mOK = false;
56                 
57                 mDialog = new JDialog(aFrame, "SuperFractalThing Options", true);
58         
59                 JPanel p = new JPanel();
60         JLabel label;
61         mDialog.setSize(new Dimension(250,150));
62         p.setPreferredSize(new Dimension(250,150));
63
64         mDialog.setContentPane(p);
65   
66         mDialog.setLocationRelativeTo(aComponent);
67        
68         p.setLayout(new GridBagLayout());
69         GridBagConstraints gbc = new GridBagConstraints();
70         
71         gbc.gridy=0;
72         gbc.gridx=0;
73         gbc.gridwidth=1;
74         gbc.ipady=10;
75         gbc.fill = GridBagConstraints.HORIZONTAL;
76         label=new JLabel("Number of threads", null, JLabel.RIGHT);
77         p.add(label,gbc);       
78  
79         gbc.gridx=1;
80         gbc.fill = GridBagConstraints.HORIZONTAL;
81         mNum_threads = new JFormattedTextField(NumberFormat.getInstance());
82         mNum_threads.setPreferredSize(new Dimension(100,20));
83         mNum_threads.setValue(Runtime.getRuntime().availableProcessors());
84         p.add(mNum_threads, gbc);       
85         
86         gbc.gridy++;
87         gbc.gridx=0;
88         gbc.gridwidth=1;
89         gbc.fill = GridBagConstraints.HORIZONTAL;
90         label=new JLabel("Super Sample", null, JLabel.RIGHT);
91         p.add(label,gbc);       
92  
93         gbc.gridx=1;
94         gbc.fill = GridBagConstraints.HORIZONTAL;
95         String[] options = {"None", "x2","x4","x4 9 sample","x9"};
96         mSuper_sample = new JComboBox<String>(options);
97         mSuper_sample.setPreferredSize(new Dimension(150,20));
98         mSuper_sample.setSelectedIndex(0);
99         p.add(mSuper_sample, gbc);       
100   
101         gbc.ipady=0;
102         gbc.gridy++;
103         gbc.gridx=0;
104         gbc.fill = GridBagConstraints.HORIZONTAL;
105         gbc.gridwidth=1;
106         mCancel_button = new JButton("Cancel");
107         p.add(mCancel_button,gbc);
108         mCancel_button.addActionListener(this);       
109        
110         
111         gbc.gridx++;
112         gbc.fill = GridBagConstraints.HORIZONTAL;
113         gbc.gridwidth=1;
114         mOK_button = new JButton("   OK   ");
115         p.add(mOK_button,gbc);
116         mOK_button.addActionListener(this);             
117         }
118                 
119                 
120         public int GetNumThreads()
121         {
122                 String str=mNum_threads.getValue().toString();
123                 return Integer.parseInt(str);
124         }
125         
126         public SuperSampleType GetSuperSampleType()
127         {
128                 switch (mSuper_sample.getSelectedIndex())
129                 {
130                 case 0:
131                         return SuperSampleType.SUPER_SAMPLE_NONE;
132                 case 1:
133                         return SuperSampleType.SUPER_SAMPLE_2X;
134                 case 2:
135                         return SuperSampleType.SUPER_SAMPLE_4X;
136                 case 3:
137                         return SuperSampleType.SUPER_SAMPLE_4X_9;
138                 case 4:
139                         return SuperSampleType.SUPER_SAMPLE_9X;
140                 default:
141                         return SuperSampleType.SUPER_SAMPLE_NONE;
142                 }
143         }
144         public boolean Run()
145         {       
146         mDialog.setLocationRelativeTo(mComponent);
147                 mSave_ss = mSuper_sample.getSelectedIndex();
148                 mSave_thr = GetNumThreads();
149                 
150                 mDialog.setVisible(true);
151                 return true;
152         }
153
154
155         @Override
156         public void actionPerformed(ActionEvent event)
157         {
158                 // TODO Auto-generated method stub
159                 String command = event.getActionCommand();
160                 if (command=="   OK   ")
161                 {
162                         mOK=true;
163                         mDialog.setVisible(false);
164                 }
165                 else if (command=="Cancel")
166                 {
167                         mOK=false;
168                         mDialog.setVisible(false);
169                         mSuper_sample.setSelectedItem(mSuper_sample);
170                         mNum_threads.setValue(new Integer(mSave_thr));
171                 }               
172         }
173         
174 }