buffer stores 2 channels of double; colour using both channels; default supersample...
[maximus:sft.git] / SuperFractalThing / source / SuperFractalThing.java
1 //      SuperFractalThing
2 //
3 //
4 //    Copyright 2013 Kevin Martin
5 //    Copyright 2013 Claude Heiland-Allen
6 //
7 //    This file is part of SuperFractalThing.
8 //
9 //    SuperFractalThing is free software: you can redistribute it and/or modify
10 //    it under the terms of the GNU General Public License as published by
11 //    the Free Software Foundation, either version 3 of the License, or
12 //    any later version.
13 //
14 //    SuperFractalThing is distributed in the hope that it will be useful,
15 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
16 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 //    GNU General Public License for more details.
18 //
19 //    You should have received a copy of the GNU General Public License
20 //    along with SuperFractalThing.  If not, see <http://www.gnu.org/licenses/>.
21 //
22 import javax.swing.JApplet;
23 import javax.swing.JFrame;
24 import javax.swing.JPanel;
25 //import javax.swing.JTextField;
26 import javax.swing.JButton;
27 import javax.swing.JFormattedTextField;
28 import javax.swing.JLabel;
29 import javax.swing.JMenuBar;
30 import javax.swing.JMenu;
31 import javax.swing.JMenuItem;
32 import javax.swing.JFileChooser;
33 import javax.swing.JOptionPane;
34 import javax.swing.JProgressBar;
35 import javax.swing.filechooser.FileNameExtensionFilter;
36 import javax.swing.text.InternationalFormatter;
37 import javax.swing.text.NumberFormatter;
38
39 import java.awt.event.ActionListener;
40 import java.awt.event.ActionEvent;
41 import java.awt.image.*;
42 import java.awt.*;
43 import java.io.BufferedWriter;
44 import java.io.ByteArrayOutputStream;
45 import java.io.File;
46 import java.io.FileNotFoundException;
47 import java.io.FileOutputStream;
48 import java.io.FileReader;
49 import java.io.FileWriter;
50
51 import javax.imageio.ImageIO;
52
53 import java.io.BufferedReader;
54 import java.io.IOException;
55 import java.math.BigDecimal;
56 import java.text.DecimalFormatSymbols;
57 import java.text.FieldPosition;
58 import java.text.NumberFormat;
59 import java.text.Format;
60 import java.text.DecimalFormat;
61 import java.text.AttributedCharacterIterator;
62 import java.text.ParsePosition;
63
64
65
66
67 public class SuperFractalThing  extends JApplet implements SFTGui, ActionListener, LibraryLoader // , PaletteIO
68 {
69
70         /**
71          * 
72          */
73         private static final long serialVersionUID = 0;//get rid of warning
74         static SftComponent mComp;
75         static JFormattedTextField mSize_box;
76         static JFormattedTextField mPos_x_box;
77         static JFormattedTextField mPos_y_box;
78         static JFormattedTextField mIterations_box;
79         static BigDecimal mPos_x;
80         static BigDecimal mPos_y;
81         static BigDecimal mSize;
82         JLabel mSize_label;
83         JProgressBar mProgress_bar;
84         JButton mCancel_button;
85         JLabel mIterations_label;
86         PositionLibrary mLibrary;
87         JLabel mTime_label;
88         JMenuBar mMenu_bar;
89         ExportDialog mDialog;
90 //      PaletteDialog mPalette_dialog;
91         OptionsDialog mOptions_dialog;
92         SFTPalette mPalette;
93         UndoBuffer mUndo_buffer;
94         JMenuItem mRedo_item;
95         JMenuItem mUndo_item;
96         
97         static JFrame mFrame;
98         /**
99          * @param args
100          */
101
102         public static void main(String[] args)
103         {
104                 
105                 mFrame = new JFrame("SuperFractalThing");
106                 mFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
107
108                 SuperFractalThing ap = new SuperFractalThing();
109                 ap.init();
110             ap.start();
111
112     
113             mFrame.add("Center", ap);
114             mFrame.pack();
115             mFrame.setVisible(true);
116
117  
118         }
119
120         public void start()
121         {
122            // init();
123             
124
125                 mUndo_buffer = new UndoBuffer();
126             initComponents();   
127             
128         }
129         
130         public void SetProgress(int aProgress, int pMax)
131         {
132                 mProgress_bar.setMaximum(pMax);
133                 mProgress_bar.setValue(aProgress);
134         }
135
136     public void AddToUndoBuffer()
137     {
138         BigDecimal coords[] = GetCoords();
139                 mUndo_buffer.Push(coords[0],coords[1],GetTheSize(),GetIterations());
140                 if (mUndo_item!=null)
141                         mUndo_item.setEnabled(mUndo_buffer.CanUndo());
142                 if (mRedo_item!=null)
143                         mRedo_item.setEnabled(mUndo_buffer.CanRedo());
144     }
145     
146     public void OutOfMemory()
147     {
148                 JOptionPane.showMessageDialog(mFrame,
149                             "Out of Memory!\n",
150                             "Error",
151                             JOptionPane.WARNING_MESSAGE);
152     }   
153     
154         public void SetCalculationTime(long aTime_ms)
155         {
156                 String text;
157                 if (aTime_ms>=0)
158                         text = "  Last calculation time: " + Double.toString((double)aTime_ms / 1000 )+" seconds";
159                 else
160                         text="";
161                 mTime_label.setText(text);
162         }
163         
164         public void actionPerformed(ActionEvent event)
165         {
166                 String command = event.getActionCommand();
167                 
168                 if (command=="Cancel")
169                 {
170                         mComp.Cancel();
171                 }
172                 if (command=="Open")
173                 {
174                         OpenFile();
175                 }
176                 else if (command=="Save")
177                 {
178                         String str;
179                         BigDecimal half = new BigDecimal(0.5);
180                         BigDecimal half_size =  GetTheSize().multiply(half);
181                         //size*=0.5f;
182                         
183                         str="s="+half_size.toString()+"\n";
184                         str+="r="+mPos_x_box.getText()+"\n";
185                         str+="i="+mPos_y_box.getText()+"\n";
186                         str+="iteration_limit="+mIterations_box.getText().replaceAll(",", "")+"\n";
187
188                         
189                         SaveFile(str);
190                         
191
192                 }
193                 else if (command=="Reset")
194                 {
195                         mPos_x_box.setValue(new BigDecimal(-0.75));
196                         mPos_y_box.setValue(new BigDecimal(0.0));
197                         mSize_box.setValue(new BigDecimal(3.0));
198                         mIterations_box.setValue(new Integer(1024));
199                         mSize = new BigDecimal(3.0);
200                         AddToUndoBuffer();
201                         mComp.Refresh();
202                         mComp.repaint();                                                
203                 }
204                 else if (command=="Export PNG")
205                 {
206                         
207                         //ExportDialog dialog = new ExportDialog(mFrame, mComp);
208                         boolean res = mDialog.Run();
209                         if (!res)
210                                 return;
211                         
212                         if (mDialog.GetWidth()>50000 || mDialog.GetHeight()>50000 || mDialog.GetWidth()<32 || mDialog.GetHeight()<32)
213                         {
214                                 JOptionPane.showMessageDialog(mFrame,
215                                             "Invalid Image Size",
216                                             "Error",
217                                             JOptionPane.WARNING_MESSAGE);
218                                 return;
219                 
220                         }
221                         try
222                         {
223                                 mComp.ExportCalculation(mDialog.GetWidth(), mDialog.GetHeight(), mDialog.GetSuperSample());
224                         } catch (OutOfMemoryError e) {
225                                 // TODO Auto-generated catch block
226                                 JOptionPane.showMessageDialog(mFrame,
227                                             "Out of Memory!\n Try using a 64 bit browser.",
228                                             "Error",
229                                             JOptionPane.WARNING_MESSAGE);
230                                 EndProcessing();
231                                 return;
232                         };
233                         
234 /*                      ByteArrayOutputStream bos = new ByteArrayOutputStream();
235                         try {
236                                 ImageIO.write(mComp.GetImage(),"PNG",bos);
237                         } catch (IOException e1) {
238                                 // TODO Auto-generated catch block
239                                 e1.printStackTrace();
240                                 return;
241                         }
242
243                         FileSaveService fss; 
244                     try { 
245                         fss = (FileSaveService)ServiceManager.lookup("javax.jnlp.FileSaveService"); 
246                     } catch (UnavailableServiceException e) { 
247                         fss = null; 
248                         return;
249                     } 
250                     
251                     ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
252                     String[] exts={"png"};
253                         try {
254                                 fss.saveFileDialog(null,exts,bis,"sft_exp.png");
255                         } catch (IOException e) {
256                                 // TODO Auto-generated catch block
257                                 e.printStackTrace();
258                         }
259 */              }
260                 else if (command=="Refresh")
261                 {
262                         mComp.Refresh();
263                         mComp.repaint();                        
264                 }                   
265                 else if (command=="About")
266                 {
267                         //JOptionPane.showMessageDialog(mFrame, "Abitrary(ish) precision Mandelbrot set rendering in Java.\n\nVersion 0.1\n\n(c) Kevin Martin","SuperFractalThing Java",JOptionPane.PLAIN_MESSAGE);
268                         AboutDialog ad = new AboutDialog(mFrame,mComp);
269                         ad.Run();
270                 }
271 /*
272                 else if (command=="Palette")
273                 {
274                         mPalette_dialog.Run();
275                 }
276 */
277                 else if (command=="Options")
278                 {
279                         mOptions_dialog.Run();
280                         mComp.SetSuperSampleType(mOptions_dialog.GetSuperSampleType());
281                         mComp.SetNumThreads(mOptions_dialog.GetNumThreads());
282                 }
283                 else if (command == "Undo")
284                 {
285                         if (mUndo_buffer.CanUndo())
286                         {
287                                 mUndo_buffer.Undo();
288                                 mPos_x_box.setValue(mUndo_buffer.GetX());
289                                 mPos_y_box.setValue(mUndo_buffer.GetY());
290                                 mSize_box.setValue(mUndo_buffer.GetSize());
291                                 mIterations_box.setValue(mUndo_buffer.GetIterations());
292                                 mComp.Refresh();
293                                 mComp.repaint();                        
294                                 mUndo_item.setEnabled(mUndo_buffer.CanUndo());
295                                 mRedo_item.setEnabled(mUndo_buffer.CanRedo());
296                         }
297                 }
298                 else if (command == "Redo")
299                 {
300                         if (mUndo_buffer.CanRedo())
301                         {
302                                 mUndo_buffer.Redo();
303                                 mPos_x_box.setValue(mUndo_buffer.GetX());
304                                 mPos_y_box.setValue(mUndo_buffer.GetY());
305                                 mSize_box.setValue(mUndo_buffer.GetSize());
306                                 mIterations_box.setValue(mUndo_buffer.GetIterations());
307                                 mComp.Refresh();
308                                 mComp.repaint();                        
309                                 mUndo_item.setEnabled(mUndo_buffer.CanUndo());
310                                 mRedo_item.setEnabled(mUndo_buffer.CanRedo());
311                         }
312                 }
313         }
314         
315         void OpenFile()
316         {
317                 JFileChooser chooser = new JFileChooser();
318                  
319             FileNameExtensionFilter filter = new FileNameExtensionFilter("SuperFractalThingFile",  "txt");
320             chooser.setFileFilter(filter);
321             int returnVal = chooser.showOpenDialog(this);
322             if(returnVal == JFileChooser.APPROVE_OPTION)
323             {
324                System.out.println("You chose to open this file: " +
325                     chooser.getSelectedFile().getName());
326                
327                File f = chooser.getSelectedFile();
328                
329                LoadTheFile(f);
330                
331             } 
332             return;
333         }
334         
335         void SaveFile(String str)
336         {
337                 JFileChooser chooser = new JFileChooser();
338                  
339             FileNameExtensionFilter filter = new FileNameExtensionFilter("SuperFractalThingFile",  "txt");
340             chooser.setFileFilter(filter);
341             int returnVal = chooser.showSaveDialog(this);
342             if(returnVal == JFileChooser.APPROVE_OPTION)
343             {
344                System.out.println("You chose to open this file: " +
345                     chooser.getSelectedFile().getName());
346                
347                File f = chooser.getSelectedFile();
348                
349                BufferedWriter file;
350                         try {
351                                 file = new BufferedWriter(new FileWriter(f));
352                                 file.write(str);
353                                 file.close();
354                         } catch (IOException e) {
355                                 // TODO Auto-generated catch block
356                                 e.printStackTrace();
357                         };
358             } 
359         }
360
361         public void ExportImage(BufferedImage aImage)
362         {
363                 ByteArrayOutputStream bos = new ByteArrayOutputStream();
364                 try {
365                         ImageIO.write(aImage,"PNG",bos);
366                 } catch (IOException e1) {
367                         // TODO Auto-generated catch block
368                         e1.printStackTrace();
369                         return;
370                 }
371
372                 SaveByteArrayOutputStream(bos);
373         }
374         
375         
376         void SaveByteArrayOutputStream(ByteArrayOutputStream bos)
377         {       
378             JFileChooser chooser = new JFileChooser();
379                  
380             FileNameExtensionFilter filter = new FileNameExtensionFilter("PNG",  "png");
381             chooser.setFileFilter(filter);
382             int returnVal = chooser.showSaveDialog(this);
383             if(returnVal == JFileChooser.APPROVE_OPTION)
384             {
385                
386                File f = chooser.getSelectedFile();
387                
388                FileOutputStream fs;
389                         try {
390                                 fs = new FileOutputStream(f);
391                        fs.write(bos.toByteArray());
392                        fs.close();
393                         } catch (FileNotFoundException e) {
394                                 // TODO Auto-generated catch block
395                                 e.printStackTrace();
396                         } catch (IOException e) {
397                                 // TODO Auto-generated catch block
398                                 e.printStackTrace();
399                         }
400             }
401             return;             
402         }
403
404         public void SetHoverIndex(double index)
405         {
406                 String str = Double.toString(index);
407                 mIterations_label.setText(str);
408         }
409         
410         public void LoadTheFile(File f)
411     {
412         try
413         {
414                         FileReader fr = new FileReader(f);
415                         BufferedReader br = new BufferedReader(fr);
416                         LoadTheFile(br);
417                 } catch (FileNotFoundException e) {
418                         // TODO Auto-generated catch block
419                         e.printStackTrace();
420                 }
421         }
422
423     public void LoadTheFile(BufferedReader br)
424     {
425         try
426         {
427                         String line1 = br.readLine();
428                         String line2 = br.readLine();
429                         String line3 = br.readLine();
430                         String line4 = br.readLine();
431                         
432                         
433                         if (line1.startsWith("s=") && line2.startsWith("r=") && line3.startsWith("i=") && line4.startsWith("iteration_limit="))
434                         {
435                                 //double size = Double.parseDouble(line1.substring(2));
436                                 //mSize_box.setText(Double.toString(size*2));
437                                 BigDecimal size = new BigDecimal(line1.substring(2));
438                                 size = size.add(size);
439                                 mSize_box.setText(size.toString());
440                                 mPos_x_box.setText(line2.substring(2));
441                                 mPos_y_box.setText(line3.substring(2));
442                                 mIterations_box.setValue(Integer.parseInt(line4.substring(16)));
443                                 mComp.repaint();
444                                 AddToUndoBuffer();
445                                 mComp.DoCalculation();
446                                 mComp.repaint();
447                                 
448                         }
449                 
450
451                 } catch (FileNotFoundException e) {
452                         // TODO Auto-generated catch block
453                         e.printStackTrace();
454                 } catch (IOException e) {
455                         // TODO Auto-generated catch block
456                         e.printStackTrace();
457                 }
458         }
459     
460         public void SetCoords( BigDecimal aSize, BigDecimal x, BigDecimal y, int iterations)
461         {
462                 mSize_box.setValue(aSize);
463                 mPos_x_box.setValue(x);
464                 mPos_y_box.setValue(y);
465                 mIterations_box.setValue(iterations);
466         }
467         
468         public BigDecimal GetTheSize()
469         {
470                 return new BigDecimal(mSize_box.getText());
471         }
472         public int GetIterations()
473         {
474                 String str = mIterations_box.getText().replaceAll(",", "");
475                 str = str.replaceAll(" ", "");
476                 str = str.replaceAll("\\.", "");
477                 return Integer.parseInt(str);
478         }
479         public void SetIterations(int aValue)
480         {
481 //              mIterations_box.setText(Integer.toString(aValue));
482                 mIterations_box.setValue(aValue);
483         }
484         public BigDecimal[] GetCoords()
485         {
486                 BigDecimal[] x=new BigDecimal[2];
487                 x[0]=new BigDecimal(mPos_x_box.getText());
488                 x[1]=new BigDecimal(mPos_y_box.getText());
489                 return x;
490         }
491     public void initComponents()
492     {     
493         //setLayout(new BorderLayout());
494         JPanel p = new JPanel();
495         p.setLayout(new GridBagLayout());
496         GridBagConstraints gbc = new GridBagConstraints();
497         gbc.gridx=0;
498         gbc.gridy=0;
499         gbc.gridwidth=8;
500         //p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
501         mComp = new SftComponent(this);
502         mPalette = new SFTPalette(mComp);
503         mComp.SetPalette( mPalette );
504         
505         p.add(mComp,gbc);
506
507         p.addMouseListener(mComp);
508         p.addMouseMotionListener(mComp);
509         add("North", p);
510         
511         gbc.gridy+=1;
512         gbc.gridwidth=7;
513         gbc.fill = GridBagConstraints.HORIZONTAL;
514         mProgress_bar = new JProgressBar(0, 1024*768);
515         mProgress_bar.setSize(new Dimension(896,20));
516         mProgress_bar.setPreferredSize(new Dimension(896,20));
517         p.add(mProgress_bar,gbc);
518         mProgress_bar.setVisible(false);
519         
520         gbc.gridx=7;
521         gbc.fill = GridBagConstraints.HORIZONTAL;
522         gbc.gridwidth=1;
523         mCancel_button = new JButton("Cancel");
524         p.add(mCancel_button,gbc);
525         mCancel_button.setVisible(false);
526         mCancel_button.addActionListener(this);
527         
528         gbc.ipady=(mProgress_bar.getHeight()-mCancel_button.getHeight())/2;
529         gbc.gridx=0;
530         gbc.gridy+=1;
531         gbc.gridwidth=1;
532         gbc.fill = GridBagConstraints.HORIZONTAL;
533         mSize_label=new JLabel("Horizontal size", null, JLabel.LEFT);
534         p.add(mSize_label,gbc);
535        
536         gbc.gridx=1;
537         gbc.gridwidth=2; 
538         gbc.fill = GridBagConstraints.HORIZONTAL;
539         DecimalFormat format = new DecimalFormat("#.#####E0");
540         mSize = new BigDecimal(1.5);
541         mSize_box = new JFormattedTextField(format);
542         mSize_box.setPreferredSize(new Dimension(400,20));
543         //mSize_box.setAlignmentY(1);
544         p.add(mSize_box, gbc);
545  
546         gbc.gridx=6;
547         gbc.gridwidth=2;
548         gbc.fill = GridBagConstraints.HORIZONTAL;
549         mIterations_label = new JLabel("Iterations:", null, JLabel.CENTER);
550         p.add(mIterations_label,gbc);
551         
552         gbc.ipady=0;
553         gbc.gridx=0;
554         gbc.gridy+=1;
555         gbc.gridwidth=1;
556         gbc.fill = GridBagConstraints.HORIZONTAL;
557         p.add(new JLabel("Real position", null, JLabel.LEFT),gbc);
558         
559         gbc.gridx=1;
560         gbc.gridwidth=7;
561         //Format f2 = new BigDecimalFormat();
562         InternationalFormatter f2 = new InternationalFormatter();
563         f2.setFormat(new BigDecimalFormat());
564         f2.setAllowsInvalid(false);
565         
566         //f2.setMaximumFractionDigits(1000);
567         mPos_x = new BigDecimal(-0.5);
568         mPos_x_box = new JFormattedTextField(f2);
569         mPos_x_box.setPreferredSize(new Dimension(200,20));
570         //mPos_x_box.setAlignmentY(1);
571         p.add(mPos_x_box, gbc);
572         
573         gbc.gridx=0;
574         gbc.gridy+=1;
575         gbc.gridwidth=1;
576         gbc.fill = GridBagConstraints.HORIZONTAL;
577         p.add(new JLabel("Imaginary position", null, JLabel.LEFT),gbc);
578
579         gbc.gridx=1;
580         gbc.gridwidth=7;
581         mPos_y = new BigDecimal(0);
582         mPos_y_box = new JFormattedTextField(f2);
583         mPos_y_box.setPreferredSize(new Dimension(200,20));
584         //mPos_y_box.setAlignmentY(1);
585         p.add(mPos_y_box, gbc);   
586  
587         
588         gbc.gridx=0;
589         gbc.gridy+=1;
590         gbc.gridwidth=1;
591         gbc.fill = GridBagConstraints.HORIZONTAL;
592         p.add(new JLabel("Iteration Limit", null, JLabel.LEFT),gbc);
593
594         gbc.gridx=1;
595         gbc.gridwidth=4;
596         NumberFormat iformat = NumberFormat.getInstance();// new DecimalFormat("#################");
597         mIterations_box = new JFormattedTextField(iformat);
598         mIterations_box.setPreferredSize(new Dimension(400,20));
599         p.add(mIterations_box, gbc);   
600         
601         gbc.gridx=5;
602         gbc.gridwidth=2;
603         gbc.fill = GridBagConstraints.HORIZONTAL;
604         mTime_label =new JLabel("", null, JLabel.CENTER);
605         p.add(mTime_label, gbc);   
606
607         mComp.CreateImage();
608
609         
610            //Menu bar
611             JMenuBar menuBar = new JMenuBar();
612             JMenu menu = new JMenu("SuperFractalThing");
613             JMenu navigate = new JMenu("Controls");
614  
615             JMenuItem menuItem = new JMenuItem("Refresh");
616         menuItem.addActionListener(this);
617         navigate.add(menuItem);
618  
619             menuItem = new JMenuItem("Undo");
620         menuItem.addActionListener(this);
621         navigate.add(menuItem);
622         mUndo_item = menuItem;
623         mUndo_item.setEnabled(false);
624        
625             menuItem = new JMenuItem("Redo");
626         menuItem.addActionListener(this);
627         navigate.add(menuItem);
628         mRedo_item = menuItem;
629         mRedo_item.setEnabled(false);
630         
631         menuItem = new JMenuItem("Reset");
632         menuItem.addActionListener(this);
633         navigate.add(menuItem);
634         
635         
636         menuItem = new JMenuItem("Open");
637         menuItem.addActionListener(this);
638         menu.add(menuItem);
639         
640         menuItem = new JMenuItem("Save");
641         menuItem.addActionListener(this);
642         menu.add(menuItem);
643
644         menuItem = new JMenuItem("Export PNG");
645         menuItem.addActionListener(this);
646         menu.add(menuItem);
647
648 /*
649         menuItem = new JMenuItem("Palette");
650         menuItem.addActionListener(this);
651         menu.add(menuItem);
652 */
653
654         menuItem = new JMenuItem("Options");
655         menuItem.addActionListener(this);
656         menu.add(menuItem);
657
658
659         menuItem = new JMenuItem("About");
660         menuItem.addActionListener(this);
661         menu.add(menuItem);
662       
663         menuBar.add(menu);
664         menuBar.add(navigate);
665         
666         mLibrary = new PositionLibrary(menuBar, this);
667
668         setJMenuBar(menuBar);
669             mMenu_bar = menuBar;
670             
671                 mDialog = new ExportDialog(mFrame, mComp);
672 /*
673                 mPalette_dialog = new PaletteDialog(mFrame, mComp, mPalette, this);
674 */
675                 mOptions_dialog = new OptionsDialog(mFrame, mComp);
676
677                 mComp.SetSuperSampleType(mOptions_dialog.GetSuperSampleType());
678                 mComp.SetNumThreads(mOptions_dialog.GetNumThreads());
679
680     }
681     
682     public void StartProcessing()
683     {
684         mMenu_bar.getComponent(0).setEnabled(false);
685         mMenu_bar.getComponent(1).setEnabled(false);
686         mMenu_bar.getComponent(2).setEnabled(false);
687                 SetProgress(0,1024);
688         mProgress_bar.setVisible(true);
689         mCancel_button.setVisible(true);
690         mSize_label.setVisible(false);
691         mIterations_label.setVisible(false);
692         mSize_box.setVisible(false);
693     }
694     
695     public void EndProcessing()
696     {
697         mMenu_bar.getComponent(0).setEnabled(true);
698         mMenu_bar.getComponent(1).setEnabled(true);
699         mMenu_bar.getComponent(2).setEnabled(true);
700         mProgress_bar.setVisible(false);
701         mCancel_button.setVisible(false);
702         mSize_label.setVisible(true);
703         mIterations_label.setVisible(true);
704         mSize_box.setVisible(true);     
705    }
706
707 /*
708         @Override
709         public void SavePalette(String str)
710         {
711                 JFileChooser chooser = new JFileChooser();
712                  
713             FileNameExtensionFilter filter = new FileNameExtensionFilter("SuperFractalThingFile",  "txt");
714             chooser.setFileFilter(filter);
715             int returnVal = chooser.showSaveDialog(mComp);
716             if(returnVal == JFileChooser.APPROVE_OPTION)
717             {
718                System.out.println("You chose to open this file: " +
719                     chooser.getSelectedFile().getName());
720                
721                File f = chooser.getSelectedFile();
722                
723                BufferedWriter file;
724                         try {
725                                 file = new BufferedWriter(new FileWriter(f));
726                                 file.write(str);
727                                 file.close();
728                         } catch (IOException e) {
729                                 // TODO Auto-generated catch block
730                                 e.printStackTrace();
731                                 return;
732                         };
733             } 
734             return;
735         }
736
737         @Override
738         public String LoadPalette()
739         {
740                 JFileChooser chooser = new JFileChooser();
741                  
742             FileNameExtensionFilter filter = new FileNameExtensionFilter("SuperFractalThingFile",  "txt");
743             chooser.setFileFilter(filter);
744             int returnVal = chooser.showOpenDialog(mComp);
745             if(returnVal == JFileChooser.APPROVE_OPTION)
746             {
747                System.out.println("You chose to open this file: " +
748                     chooser.getSelectedFile().getName());
749                
750                File f = chooser.getSelectedFile();
751                
752                         try
753                         {
754                                 FileReader fr = new FileReader(f);
755                                 BufferedReader br = new BufferedReader(fr);
756                                 char arr[]=new char[2048];
757                                 br.read(arr, 0,2048);
758                                 String str = String.copyValueOf(arr);
759                                 br.close();
760                                 return str;
761                                 
762                         }
763                         catch (FileNotFoundException e)
764                         {
765                                 // TODO Auto-generated catch block
766                                 e.printStackTrace();
767                                 return null;
768                         }
769                         catch (IOException e)
770                         {
771                                 return null;                    
772                         }
773
774                 }  
775             return null;
776         }
777
778 */
779
780 }
781
782
783 class BigDecimalFormatter extends NumberFormatter
784 {
785         private static final long serialVersionUID = 0;
786
787         BigDecimalFormatter()
788         {
789                 //setAllowsInvalid(false);
790         }
791         
792         public Object stringToValue(String text) //throws ParseException
793         {
794                 if("".equals(text.trim()))
795                 {
796                 return null;
797                 }
798                 char ds = getDefaultLocaleDecimalSeparator();
799
800  
801                 try
802                 {
803                         String val = text;
804                         if(ds != '.')
805                         {
806                                 val = val.replace(".", "").replace(ds, '.');
807                         }
808                         return new BigDecimal(val);
809                 } catch(NumberFormatException e)
810                 {
811                         return null;
812                 }
813         }
814         
815         public String valueToString(Object value) //throws ParseException
816         {
817                 if (value!=null)
818                         return value.toString();
819                 else
820                         return null;
821         }
822          
823         private char getDefaultLocaleDecimalSeparator()
824         {
825                 DecimalFormatSymbols symbols = new DecimalFormat("0").getDecimalFormatSymbols();
826                 char ds = symbols.getDecimalSeparator();
827                 return ds;
828         }
829
830 }
831
832
833 class BigDecimalFormat extends Format
834 {
835         private static final long serialVersionUID = 0;//get rid of warning
836         BigDecimal mOld_value;
837         String mOld_string;
838
839         String Format(Object number)
840         {
841                 BigDecimal x=(BigDecimal)number;
842                 return x.toString();
843         }
844         
845         public AttributedCharacterIterator formatToCharacterIterator(Object obj)
846         {
847                 return null;
848         }
849
850         public Object   parseObject(String source)
851         {
852                 mOld_string = null;
853                 try
854                 {
855                         BigDecimal x= new BigDecimal(source);
856                         mOld_value = x;
857                         if (source.endsWith(".") || source.contentEquals("-0"))
858                                 mOld_string = source;
859                         return x;
860                 }
861                 catch (NumberFormatException e)
862                 {
863                         if (source.length()==0)
864                         {
865                                 mOld_value=null;
866                                 mOld_string=null;
867                                 return null;
868                         }
869                         if (source.equals("-"))
870                         {
871                                 mOld_string = source;
872                                 mOld_value = new BigDecimal(0);
873                                 return mOld_value;
874                         }
875                         return mOld_value;
876                 }
877         }
878
879         @Override
880         public StringBuffer format(Object arg0, StringBuffer arg1,
881                         FieldPosition arg2)
882         {
883                 if (mOld_string!=null && mOld_value==arg0)
884                 {
885                         arg1.append(mOld_string);
886                         return arg1;
887                 }
888                 
889                 BigDecimal x=(BigDecimal)arg0;
890                 String str = x.toString();
891                 arg1.append(str);
892                 return arg1;
893         }
894
895         @Override
896         public Object parseObject(String arg0, ParsePosition arg1)
897         {
898                 return parseObject(arg0);
899         }
900 }