source: git/Singular/LIB/surfex/ConfigFrame.java @ 3de2ca

spielwiese
Last change on this file since 3de2ca was 3de2ca, checked in by Hans Schönemann <hannes@…>, 16 years ago
*hannes: surfex_0_90_00 git-svn-id: file:///usr/local/Singular/svn/trunk@11070 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 23.7 KB
Line 
1////////////////////////////////////////////////////////////////////////
2//
3// This file ConfigFrame.java is part of SURFEX.
4//
5////////////////////////////////////////////////////////////////////////
6
7////////////////////////////////////////////////////////////////////////
8// SURFEX version 0.90.00
9// =================
10//
11// Saarland University at Saarbruecken, Germany
12// Department of Mathematics and Computer Science
13//
14// SURFEX on the web: www.surfex.AlgebraicSurface.net
15//
16// Authors: Oliver Labs (2001-2008), Stephan Holzer (2004-2005)
17//
18// Copyright (C) 2001-2008
19//
20//
21// *NOTICE*
22// ========
23// 
24// This program is free software; you can redistribute it and/or modify it
25// under the terms of the GNU General Public License as published by the
26// Free Software Foundation ( version 3 or later of the License ).
27//
28// See LICENCE.TXT for details.
29//
30/////////////////////////////////////////////////////////////////////////
31
32import java.awt.BorderLayout;
33import java.awt.Color;
34import java.awt.Container;
35import java.awt.GridLayout;
36import java.awt.Panel;
37import java.awt.event.ActionEvent;
38import java.awt.event.ActionListener;
39import java.io.File;
40
41import javax.swing.AbstractButton;
42import javax.swing.ButtonGroup;
43import javax.swing.JButton;
44import javax.swing.JCheckBox;
45import javax.swing.JFileChooser;
46import javax.swing.JFrame;
47import javax.swing.JLabel;
48import javax.swing.JOptionPane;
49import javax.swing.JPanel;
50import javax.swing.JRadioButton;
51import javax.swing.JTextField;
52import javax.swing.event.ChangeEvent;
53import javax.swing.event.ChangeListener;
54import javax.swing.filechooser.FileFilter;
55
56//////////////////////////////////////////////////////////////
57//
58// class ConfigFrame
59//
60//////////////////////////////////////////////////////////////
61
62public class ConfigFrame extends JFrame {
63
64        JPanel panel, panel2, panel3, panel4, panel5, panel6, panel7;
65
66        surfex surfex_;
67
68        JCheckBox rayImme = new JCheckBox("raytrace preview immediately", false);
69
70        //UpdateRayframeImmediatlyThread updateRayframeImmediatlyThread;
71
72        JTextField interpolConst;
73
74        JTextField povPath = new JTextField();
75
76        JTextField surfPath = new JTextField();
77
78        JTextField impsurfPath = new JTextField();
79
80        JTextField iviewPath = new JTextField();
81
82        JTextField serverPath = new JTextField();
83
84        JRadioButton surf, pov, localPro, webPro;
85
86        boolean last[] = { true, false, false, true, false };
87
88        ChangeListener CL = new ChangeListener() {
89                public void stateChanged(ChangeEvent ev) {
90                        if (((AbstractButton) ev.getSource()).getText().hashCode() == rayImme
91                                        .getText().hashCode()) {
92                                if (rayImme.isSelected() && !last[4]
93                                                && surfex_.pane.getSelectedIndex() >= 0) {
94                                        last[4] = true;
95                                        double ang[] = surfex_.getCurrentProject().eqAdm
96                                                        .getAngles();
97                                        double scale[] = surfex_.getCurrentProject().eqAdm
98                                                        .getScales();
99                                        surfex_.newUpdateRayframeImmediatlyThread();
100                                        surfex_.updateRayframeImmediatlyThread.start();
101                                }
102                                if (!rayImme.isSelected() && last[4]) {
103                                        last[4] = false;
104                                        surfex_.updateRayframeImmediatlyThread.stop();
105                                }
106                        }
107
108                        if (((AbstractButton) ev.getSource()).getText().hashCode() == localPro
109                                        .getText().hashCode()) {
110
111                                // checke ob Programme installiert sind
112                                if (localPro.isSelected() && !last[0]) {
113                                        last[0] = true;
114                                        if (pov.isSelected() && !povAvailable()) {
115                                                ask4pov2();
116
117                                        } else {
118                                                if (surf.isSelected() && !surfAvailable()) {
119                                                        ask4surf2();
120                                                }
121                                        }
122                                        last[0] = localPro.isSelected();
123                                        last[1] = webPro.isSelected();
124                                } else {
125                                        // webPro wurde selected()
126                                        last[0] = localPro.isSelected();
127                                        last[1] = webPro.isSelected();
128                                }
129                        }
130                        if (((AbstractButton) ev.getSource()).getText().hashCode() == surf
131                                        .getText().hashCode()) {
132                                if (surf.isSelected() && !last[2]) {
133                                        last[2] = true;
134                                        // voruebergehend, damit  er nicht 10x den dialog aufruft, weil man die maus bewegt
135                                        // wurde auf surf geclickt
136                                        if (localPro.isSelected() && !surfAvailable()) {
137                                                // soll also local verfuegbar sein, isses abernet
138                                                ask4surf2();
139                                        }
140                                        last[2] = surf.isSelected();
141                                        last[3] = pov.isSelected();
142                                } else {
143                                        if (pov.isSelected() && !last[3]) {
144                                                last[3] = true;
145                                                // voruebergehend, damit  er nicht 10x den dialog aufruft, weil man die maus bewegt
146
147                                                // wurde auf surf geclickt
148                                                if (localPro.isSelected() && !povAvailable()) {
149                                                        // soll also local verfuegbar sein, isses abernet
150                                                        ask4pov2();
151                                                }
152                                                last[2] = surf.isSelected();
153                                                last[3] = pov.isSelected();
154                                        }
155                                }
156
157                        }
158                }
159        };
160
161        ActionListener AL = new ActionListener() {
162                public void actionPerformed(ActionEvent actionEvent) {
163                        action(actionEvent.getActionCommand());
164                }
165        };
166
167        public void action(String command) {
168                if (command == "OK") {
169                        setVisible(false);
170                }
171                if (command == "povPathButton") {
172                        filechooser("POV", ".exe");
173                }
174                if (command == "surfPathButton") {
175                        filechooser("surf", ".exe");
176                }
177                if (command == "impsurfPathButton") {
178                        filechooser("impsurf", ".exe");
179                }
180                if (command == "iviewPathButton") {
181                        filechooser("iview", ".exe");
182                }
183                if (command == "serverPath") {
184                        //filechooser("iview", ".exe");
185                }
186                //serverPath
187                /*
188                 if(command == "Default"){
189
190                 } */
191        }
192
193        ConfigFrame(String pPath, String sPath, String imPath, String ivPath,
194                        int iConst, String svPath, UpdateRayframeImmediatlyThread uT,
195                        surfex su) {
196                super("Config surfex");
197                surfex_ = su;
198                //updateRayframeImmediatlyThread = uT;
199                setSize(300, 350);
200                interpolConst = new JTextField((new Integer(iConst)).toString(), 1);
201                setLocation(100, 100);
202                Container cp = getContentPane();
203                cp.setLayout(new BorderLayout());
204                panel = new JPanel(new GridLayout(5, 1));
205
206                //  panel.add(rayImme);
207                rayImme.addChangeListener(CL);
208
209                panel2 = new JPanel(new GridLayout(1, 2));
210                panel2.add(new JLabel("     interpolation const."));
211                panel2.add(interpolConst);
212                panel.add(panel2);
213
214                panel3 = new JPanel(new GridLayout(1, 3));
215                panel3.add(new JLabel("     raytracer"));
216                surf = new JRadioButton("surf", true);
217                surf.addChangeListener(CL);
218                pov = new JRadioButton("POVray");
219                pov.addChangeListener(CL);
220                ButtonGroup group = new ButtonGroup();
221                group.add(surf);
222                panel3.add(surf);
223                if (!(surfex_.inAnApplet)) {
224                        group.add(pov);
225                        panel3.add(pov);
226                }
227                panel.add(panel3);
228
229                ButtonGroup group2 = new ButtonGroup();
230
231                if (surfex_.inAnApplet) {
232                        webPro = new JRadioButton("use web Programs", true);
233                        localPro = new JRadioButton("use local Programs");
234                        localPro.setEnabled(false);
235                } else {
236                        webPro = new JRadioButton("use web Programs");
237                        localPro = new JRadioButton("use local Programs", true);
238                }
239                localPro.addChangeListener(CL);
240                group2.add(localPro);
241                group2.add(webPro);
242                panel.add(webPro);
243                panel.add(localPro);
244
245                panel4 = new JPanel(new BorderLayout());
246                panel5 = new JPanel(new GridLayout(6, 1));
247                panel6 = new JPanel(new GridLayout(6, 1));
248                panel7 = new JPanel(new GridLayout(6, 1));
249
250                panel5.add(new JLabel("POV:"));
251                povPath.setText(pPath);
252                boolean temp = povAvailable();
253                panel6.add(povPath);
254                JButton povPathButton = new JButton("choose");
255                povPathButton.setActionCommand("povPathButton");
256                povPathButton.addActionListener(AL);
257                panel7.add(povPathButton);
258
259                panel5.add(new JLabel("SURF:"));
260                surfPath.setText(sPath);
261                temp = surfAvailable();
262                panel6.add(surfPath);
263                JButton surfPathButton = new JButton("choose");
264                surfPathButton.setActionCommand("surfPathButton");
265                surfPathButton.addActionListener(AL);
266                panel7.add(surfPathButton);
267
268                panel5.add(new JLabel("Impsurf:"));
269                impsurfPath.setText(imPath);
270                temp = impsurfAvailable();
271                panel6.add(impsurfPath);
272                JButton impsurfPathButton = new JButton("choose");
273                impsurfPathButton.setActionCommand("impsurfPathButton");
274                impsurfPathButton.addActionListener(AL);
275                panel7.add(impsurfPathButton);
276
277                panel5.add(new JLabel("Iview:"));
278                iviewPath.setText(ivPath);
279                temp = iviewAvailable();
280                panel6.add(iviewPath);
281                JButton iviewPathButton = new JButton("choose");
282                iviewPathButton.setActionCommand("iviewPathButton");
283                iviewPathButton.addActionListener(AL);
284                panel7.add(iviewPathButton);
285
286                panel5.add(new JLabel("Server:"));
287                serverPath.setText(svPath);
288                temp = serverAvailable();
289                panel6.add(serverPath);
290                JButton serverPathButton = new JButton("choose");
291                serverPathButton.setActionCommand("serverPathButton");
292                serverPathButton.addActionListener(AL);
293                panel7.add(serverPathButton);
294
295                panel5.add(new JLabel());
296                JButton OKButton = new JButton("OK");
297                OKButton.addActionListener(AL);
298                panel6.add(OKButton);
299                /*JButton cancelButton=new JButton("Cancel");
300                 OKButton.addActionListener(AL);
301                 */
302                panel7.add(new JLabel());//cancelButton);
303
304                if (!(surfex_.inAnApplet)) {
305                        panel4.add(panel5, BorderLayout.WEST);
306                        panel4.add(panel6, BorderLayout.CENTER);
307                        panel4.add(panel7, BorderLayout.EAST);
308                }
309
310                cp.add(panel4, BorderLayout.SOUTH);
311                cp.add(panel, BorderLayout.CENTER);
312
313                setVisible(false);
314
315        }
316
317        public boolean povAvailable() {
318                try {
319                        Runtime r = Runtime.getRuntime();
320                        Process p;
321                        p = r.exec(povPath.getText()
322                                        + " /NR /RENDER tmp_aviable_test.povtest /EXIT");
323                        povPath.setBackground(Color.white);
324                        return true;
325                } catch (Exception e1) {
326                        //      System.out.println(e1.toString());
327                        povPath.setBackground(Color.red);
328                        return (false);
329                }
330                //return false;
331        }
332
333        public boolean surfAvailable() {
334                try {
335                        Runtime r = Runtime.getRuntime();
336                        Process p;
337                        p = r.exec(surfPath.getText() + " testparameter");
338                        surfPath.setBackground(Color.white);
339                        return true;
340                } catch (Exception e1) {
341                        //      System.out.println(e1.toString());
342                        surfPath.setBackground(Color.red);
343                        return (false);
344                }
345        }
346
347        public boolean serverAvailable() {
348                /*try {
349                 Runtime r = Runtime.getRuntime();
350                 Process p;
351                 p = r.exec(surfPath.getText() + " testparameter");
352                 surfPath.setBackground(Color.white);
353                 return true;
354                 } catch (Exception e1) {
355                 //    System.out.println(e1.toString());
356                 surfPath.setBackground(Color.red);
357                 return (false);
358                 } */
359                return true;
360        }
361
362        public boolean impsurfAvailable() {
363                try {
364                        Runtime r = Runtime.getRuntime();
365                        Process p;
366                        p = r.exec(impsurfPath.getText() + " testparameter");
367                        impsurfPath.setBackground(Color.white);
368                        return true;
369                } catch (Exception e1) {
370                        //      System.out.println(e1.toString());
371                        impsurfPath.setBackground(Color.red);
372                        return (false);
373                }
374        }
375
376        public boolean iviewAvailable() {
377                try {
378                        Runtime r = Runtime.getRuntime();
379                        Process p;
380                        p = r.exec(iviewPath.getText() + " i_view32_test.jpg /convert="
381                                        + surfex_.tmpDir + "i_view32_test.jpg");
382                        iviewPath.setBackground(Color.white);
383                        return true;
384                } catch (Exception e1) {
385                        //      System.out.println(e1.toString());
386                        iviewPath.setBackground(Color.red);
387                        return (false);
388                }
389        }
390
391        public void askForSurf() {
392
393                int optReturn = JOptionPane.showConfirmDialog(new Panel(),
394                                "Can't find POV - do you want me to try using surf?",
395                                "Can't find POV", JOptionPane.YES_NO_CANCEL_OPTION,
396                                JOptionPane.QUESTION_MESSAGE);
397                switch (optReturn) {
398                case 0:
399                        // ja, dann nutze surf
400                        surf.setSelected(true);
401                        if (!surfAvailable()) {
402                                // der Pfad war wohl nich korrekt
403                                optReturn = JOptionPane
404                                                .showConfirmDialog(
405                                                                new Panel(),
406                                                                "Can't find SURF - do you konow where SURF is installed?",
407                                                                "Can't find SURF",
408
409                                                                JOptionPane.YES_NO_CANCEL_OPTION,
410                                                                JOptionPane.QUESTION_MESSAGE);
411                                switch (optReturn) {
412                                case 0:
413                                        // ja, dann suche surf
414                                        // creating new Frame
415                                        final JFrame frame2 = new JFrame("load surf");
416
417                                        // adding container
418                                        Container contentPane = frame2.getContentPane();
419
420                                        // creating Filechooser
421                                        JFileChooser fileChooser = new JFileChooser(
422                                                        surfex_.currentDirectory);
423
424                                        // adding filechooser
425                                        contentPane.add(fileChooser, BorderLayout.CENTER);
426
427                                        // Create ActionListener
428                                        ActionListener actionListener = new ActionListener() {
429                                                public void actionPerformed(ActionEvent actionEvent) {
430                                                        JFileChooser theFileChooser = (JFileChooser) actionEvent
431                                                                        .getSource();
432
433                                                        // get command2
434                                                        String command2 = actionEvent.getActionCommand();
435
436                                                        // check if doubleclickt or if "open" was pressed
437                                                        if (command2.equals(JFileChooser.APPROVE_SELECTION)) {
438                                                                File selectedFile = theFileChooser
439                                                                                .getSelectedFile();
440
441                                                                // making savepopup invisible/removing it
442                                                                frame2.dispose();
443
444                                                                // creating complete filepath
445                                                                String filelocation = new String(selectedFile
446                                                                                .getParent()
447                                                                                + File.separator
448                                                                                + selectedFile.getName());
449
450                                                                // ausgabe fehler bein z.B.: d:\ -> d:\\ bzw \ -> \\
451                                                                //          System.out.println("filelocation : "+ filelocation + "\n");
452
453                                                                povPath.setText(filelocation);
454
455                                                        } else {
456                                                                //if(command.equals(JFileChooser.CANCEL_SELECTION)){
457                                                                frame2.setVisible(false);
458                                                                //}
459                                                        }
460                                                        if (!surfAvailable()) {
461                                                                //falsch
462                                                                System.out
463                                                                                .println(" dann eghts halt nur mitm Netz");
464                                                                webPro.setSelected(true);
465                                                        }
466                                                }
467                                        };
468
469                                        FileFilter acfFilter = new ExtensionFileFilter(
470                                                        "all common files", new String[] { "exe" });
471                                        fileChooser.addChoosableFileFilter(acfFilter);
472
473                                        FileFilter spcFilter = new ExtensionFileFilter("*.exe",
474                                                        new String[] { "exe" });
475                                        fileChooser.addChoosableFileFilter(spcFilter);
476
477                                        // adding actionListener
478                                        fileChooser.addActionListener(actionListener);
479                                        frame2.pack();
480                                        frame2.setVisible(true);
481
482                                        break;
483                                case 1:
484                                        //nein
485                                        System.out.println(" dann eghts halt nur mitm Netz");
486                                        webPro.setSelected(true);
487                                        break;
488                                case 2: // abbrechen, also nic machen ...
489                                        break;
490                                }
491                                ;
492                        }
493                        break;
494                case 1:
495                        //nein
496                        System.out.println(" dann eghts halt nur mitm Netz");
497                        webPro.setSelected(true);
498                        break;
499                case 2: // abbrechen, also nic machen ...
500                        break;
501                }
502                ;
503
504        }
505
506        public void askForPOV() {
507                // der Pfad war wohl nich korrekt
508                int optReturn = JOptionPane.showConfirmDialog(new Panel(),
509                                "Can't find SURF - do you want me to try using POV?",
510                                "Can't find SURF", JOptionPane.YES_NO_CANCEL_OPTION,
511                                JOptionPane.QUESTION_MESSAGE);
512                switch (optReturn) {
513                case 0:
514                        // ja, dann nutze POV
515                        pov.setSelected(true);
516                        if (!povAvailable()) {
517                                // der Pfad war wohl nich korrekt
518                                optReturn = JOptionPane
519                                                .showConfirmDialog(
520                                                                new Panel(),
521                                                                "Can't find POV - do you konow where POV is installed2?",
522                                                                "Can't find POV",
523
524                                                                JOptionPane.YES_NO_CANCEL_OPTION,
525                                                                JOptionPane.QUESTION_MESSAGE);
526                                switch (optReturn) {
527                                case 0:
528                                        // ja, dann nutze POV
529                                        // creating new Frame
530                                        final JFrame frame2 = new JFrame("load POV");
531
532                                        // adding container
533                                        Container contentPane = frame2.getContentPane();
534
535                                        // creating Filechooser
536                                        JFileChooser fileChooser = new JFileChooser(
537                                                        surfex_.currentDirectory);
538
539                                        // adding filechooser
540                                        contentPane.add(fileChooser, BorderLayout.CENTER);
541
542                                        // Create ActionListener
543                                        ActionListener actionListener = new ActionListener() {
544                                                public void actionPerformed(ActionEvent actionEvent) {
545                                                        JFileChooser theFileChooser = (JFileChooser) actionEvent
546                                                                        .getSource();
547
548                                                        // get command2
549                                                        String command2 = actionEvent.getActionCommand();
550
551                                                        // check if doubleclickt or if "open" was pressed
552                                                        if (command2.equals(JFileChooser.APPROVE_SELECTION)) {
553                                                                File selectedFile = theFileChooser
554                                                                                .getSelectedFile();
555
556                                                                // making savepopup invisible/removing it
557                                                                frame2.dispose();
558
559                                                                // creating complete filepath
560                                                                String filelocation = new String(selectedFile
561                                                                                .getParent()
562                                                                                + File.separator
563                                                                                + selectedFile.getName());
564
565                                                                // ausgabe fehler bein z.B.: d:\ -> d:\\ bzw \ -> \\
566                                                                //          System.out.println("filelocation : "+ filelocation + "\n");
567
568                                                                povPath.setText(filelocation);
569
570                                                        } else {
571                                                                //if(command.equals(JFileChooser.CANCEL_SELECTION)){
572                                                                frame2.setVisible(false);
573                                                                //}
574                                                        }
575                                                        if (!povAvailable()) {
576                                                                //falsch
577                                                                //              System.out.println(" dann eghts halt nur mitm Netz");
578                                                                webPro.setSelected(true);
579                                                        }
580                                                }
581                                        };
582
583                                        FileFilter acfFilter = new ExtensionFileFilter(
584                                                        "all common files", new String[] { "exe" });
585                                        fileChooser.addChoosableFileFilter(acfFilter);
586
587                                        FileFilter spcFilter = new ExtensionFileFilter("*.exe",
588                                                        new String[] { "exe" });
589                                        fileChooser.addChoosableFileFilter(spcFilter);
590
591                                        // adding actionListener
592                                        fileChooser.addActionListener(actionListener);
593                                        frame2.pack();
594                                        frame2.setVisible(true);
595
596                                        break;
597                                case 1:
598                                        //nein
599                                        //          System.out.println(" dann eghts halt nur mitm Netz");
600                                        webPro.setSelected(true);
601                                        break;
602                                case 2: // abbrechen, also nic machen ...
603                                        break;
604                                }
605                                ;
606                        }
607
608                        break;
609                case 1:
610                        //nein
611                        //    System.out.println(" dann eghts halt nur mitm Netz");
612                        webPro.setSelected(true);
613                        break;
614                case 2: // abbrechen, also nic machen ...
615                        break;
616                }
617                ;
618        }
619
620        public void ask4surf2() {
621                int optReturn = JOptionPane.showConfirmDialog(new Panel(),
622                                "Can't find surf - do yout know where surf is installed?",
623                                "Can't find surf", JOptionPane.YES_NO_CANCEL_OPTION,
624                                JOptionPane.QUESTION_MESSAGE);
625                switch (optReturn) {
626                case 0:
627                        // ja, dann gib den Pfad an
628                        // creating new Frame
629                        final JFrame frame2 = new JFrame("load surf");
630
631                        // adding container
632                        Container contentPane = frame2.getContentPane();
633
634                        // creating Filechooser
635                        JFileChooser fileChooser = new JFileChooser(
636                                        surfex_.currentDirectory);
637
638                        // adding filechooser
639                        contentPane.add(fileChooser, BorderLayout.CENTER);
640
641                        // Create ActionListener
642                        ActionListener actionListener = new ActionListener() {
643                                public void actionPerformed(ActionEvent actionEvent) {
644                                        JFileChooser theFileChooser = (JFileChooser) actionEvent
645                                                        .getSource();
646
647                                        // get command2
648                                        String command2 = actionEvent.getActionCommand();
649
650                                        // check if doubleclickt or if "open" was pressed
651                                        if (command2.equals(JFileChooser.APPROVE_SELECTION)) {
652                                                File selectedFile = theFileChooser.getSelectedFile();
653
654                                                // making savepopup invisible/removing it
655                                                frame2.dispose();
656
657                                                // creating complete filepath
658                                                String filelocation = new String(selectedFile
659                                                                .getParent()
660                                                                + File.separator + selectedFile.getName());
661
662                                                // ausgabe fehler bein z.B.: d:\ -> d:\\ bzw \ -> \\
663                                                //          System.out.println("filelocation : "+ filelocation + "\n");
664
665                                                surfPath.setText(filelocation);
666
667                                        } else {
668                                                //if(command.equals(JFileChooser.CANCEL_SELECTION)){
669                                                frame2.setVisible(false);
670                                                //}
671                                        }
672                                        if (surf.isSelected() && !surfAvailable()) {
673                                                // der Pfad war wohl nich korrekt
674                                                askForPOV();
675                                        }
676                                }
677                        };
678
679                        FileFilter acfFilter = new ExtensionFileFilter("all common files",
680                                        new String[] { "exe" });
681                        fileChooser.addChoosableFileFilter(acfFilter);
682
683                        FileFilter spcFilter = new ExtensionFileFilter("*.exe",
684                                        new String[] { "exe" });
685                        fileChooser.addChoosableFileFilter(spcFilter);
686
687                        // adding actionListener
688                        fileChooser.addActionListener(actionListener);
689                        frame2.pack();
690                        frame2.setVisible(true);
691
692                        break;
693                case 1:
694                        // surf.setSelected(true);
695                        askForPOV();
696                        break;
697                case 2: // abbrechen, also nic machen ...
698                        break;
699                }
700                ;
701
702        }
703
704        public void ask4pov2() {
705                int optReturn = JOptionPane.showConfirmDialog(new Panel(),
706                                "Can't find POV - do yout know where POV is installed?",
707                                "Can't find POV", JOptionPane.YES_NO_CANCEL_OPTION,
708                                JOptionPane.QUESTION_MESSAGE);
709                switch (optReturn) {
710                case 0:
711                        // ja, dann gib den Pfad an
712                        // creating new Frame
713                        final JFrame frame2 = new JFrame("load POV");
714
715                        // adding container
716                        Container contentPane = frame2.getContentPane();
717
718                        // creating Filechooser
719                        JFileChooser fileChooser = new JFileChooser(
720                                        surfex_.currentDirectory);
721
722                        // adding filechooser
723                        contentPane.add(fileChooser, BorderLayout.CENTER);
724
725                        // Create ActionListener
726                        ActionListener actionListener = new ActionListener() {
727                                public void actionPerformed(ActionEvent actionEvent) {
728                                        JFileChooser theFileChooser = (JFileChooser) actionEvent
729                                                        .getSource();
730
731                                        // get command2
732                                        String command2 = actionEvent.getActionCommand();
733
734                                        // check if doubleclickt or if "open" was pressed
735                                        if (command2.equals(JFileChooser.APPROVE_SELECTION)) {
736                                                File selectedFile = theFileChooser.getSelectedFile();
737
738                                                // making savepopup invisible/removing it
739                                                frame2.dispose();
740
741                                                // creating complete filepath
742                                                String filelocation = new String(selectedFile
743                                                                .getParent()
744                                                                + File.separator + selectedFile.getName());
745
746                                                // ausgabe fehler bein z.B.: d:\ -> d:\\ bzw \ -> \\
747                                                //          System.out.println("filelocation : "+ filelocation + "\n");
748
749                                                povPath.setText(filelocation);
750
751                                        } else {
752                                                //if(command.equals(JFileChooser.CANCEL_SELECTION)){
753                                                frame2.setVisible(false);
754                                                //}
755                                        }
756                                        if (pov.isSelected() && !povAvailable()) {
757                                                // der Pfad war wohl nich korrekt
758                                                askForSurf();
759                                        }
760                                }
761                        };
762
763                        FileFilter acfFilter = new ExtensionFileFilter("all common files",
764                                        new String[] { "exe" });
765                        fileChooser.addChoosableFileFilter(acfFilter);
766
767                        FileFilter spcFilter = new ExtensionFileFilter("*.exe",
768                                        new String[] { "exe" });
769                        fileChooser.addChoosableFileFilter(spcFilter);
770
771                        // adding actionListener
772                        fileChooser.addActionListener(actionListener);
773                        frame2.pack();
774                        frame2.setVisible(true);
775
776                        break;
777                case 1:
778                        // surf.setSelected(true);
779                        askForSurf();
780                        break;
781                case 2: // abbrechen, also nic machen ...
782                        break;
783                }
784        }
785
786        public void filechooser(final String applicationName, String endung) {
787
788                // creating new Frame
789                final JFrame frame2 = new JFrame("load " + applicationName);
790
791                // adding container
792                Container contentPane = frame2.getContentPane();
793
794                // creating Filechooser
795                JFileChooser fileChooser = new JFileChooser(surfex_.currentDirectory);
796
797                // adding filechooser
798                contentPane.add(fileChooser, BorderLayout.CENTER);
799
800                // Create ActionListener
801                ActionListener actionListener = new ActionListener() {
802                        public void actionPerformed(ActionEvent actionEvent) {
803                                JFileChooser theFileChooser = (JFileChooser) actionEvent
804                                                .getSource();
805
806                                // get command2
807                                String command2 = actionEvent.getActionCommand();
808
809                                // check if doubleclickt or if "open" was pressed
810                                if (command2.equals(JFileChooser.APPROVE_SELECTION)) {
811                                        File selectedFile = theFileChooser.getSelectedFile();
812
813                                        // making savepopup invisible/removing it
814                                        frame2.dispose();
815
816                                        // creating complete filepath
817                                        String filelocation = new String(selectedFile.getParent()
818                                                        + File.separator + selectedFile.getName());
819
820                                        // ausgabe fehler bein z.B.: d:\ -> d:\\ bzw \ -> \\
821                                        //          System.out.println("filelocation : "+ filelocation + "\n");
822
823                                        if (applicationName == "POV") {
824                                                povPath.setText(filelocation);
825                                                boolean temp = povAvailable();
826                                        }
827                                        if (applicationName == "surf") {
828                                                surfPath.setText(filelocation);
829                                                boolean temp = surfAvailable();
830                                        }
831                                        if (applicationName == "impsurf") {
832                                                impsurfPath.setText(filelocation);
833                                                boolean temp = impsurfAvailable();
834                                        }
835                                        if (applicationName == "iview") {
836                                                iviewPath.setText(filelocation);
837                                                boolean temp = iviewAvailable();
838                                        }
839                                } else {
840                                        //if(command.equals(JFileChooser.CANCEL_SELECTION)){
841                                        frame2.setVisible(false);
842                                        //}
843                                }
844                        }
845                };
846
847                FileFilter acfFilter = new ExtensionFileFilter("all common files",
848                                new String[] { endung });
849                fileChooser.addChoosableFileFilter(acfFilter);
850
851                FileFilter spcFilter = new ExtensionFileFilter("*." + endung,
852                                new String[] { endung });
853                fileChooser.addChoosableFileFilter(spcFilter);
854
855                // adding actionListener
856                fileChooser.addActionListener(actionListener);
857                frame2.pack();
858                frame2.setVisible(true);
859
860                //oeffen den Kram unter filename;
861
862        } // end: command == "load"
863} // end class ConfigFrame
864
Note: See TracBrowser for help on using the repository browser.