summaryrefslogtreecommitdiff
path: root/sources/prefs/editors/VSEditor.java
blob: f1d4991feedfcb267fe1170eb4f34e554a48d208 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
/*
 * VS is (c) 2008 by Paul C. Buetow
 * vs@dev.buetow.org
 */
package prefs.editors;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;

import utils.*;
import prefs.VSPrefs;

// TODO: Auto-generated Javadoc
/**
 * The Class VSEditor.
 */
public abstract class VSEditor implements ActionListener {

    /** The boolean keys. */
    private ArrayList<String> booleanKeys;

    /** The color keys. */
    private ArrayList<String> colorKeys;

    /** The float keys. */
    private ArrayList<String> floatKeys;

    /** The integer keys. */
    private ArrayList<String> integerKeys;

    /** The long keys. */
    private ArrayList<String> longKeys;

    /** The string keys. */
    private ArrayList<String> stringKeys;

    /** The boolean fields. */
    private HashMap<String,JCheckBox> booleanFields;

    /** The integer fields. */
    private HashMap<String,JComboBox> integerFields;

    /** The color fields. */
    private HashMap<String,JTextField> colorFields;

    /** The float fields. */
    private HashMap<String,JTextField> floatFields;

    /** The long fields. */
    private HashMap<String,JTextField> longFields;

    /** The string fields. */
    private HashMap<String,JTextField> stringFields;

    /** The prefs to edit map. */
    private HashMap<String,VSPrefs> prefsToEditMap;

    /** The button panel. */
    private JPanel buttonPanel;

    /** The edit panel. */
    private JPanel editPanel;

    /** The edit table. */
    private VSEditorTable editTable;

    /** The frame. */
    private VSFrame frame;

    /** The expert mode changed. */
    private boolean expertModeChanged;

    /** The prefs. */
    protected VSPrefs prefs;

    /** The prefs to edit. */
    protected VSPrefs prefsToEdit;

    /** The Constant MIN_UNIT_LENGTH. */
    protected static final int MIN_UNIT_LENGTH = 5;

    /** The Constant VALUE_FIELD_COLS. */
    protected static final int VALUE_FIELD_COLS = 9;

    /** The Constant ALL_PREFERENCES. */
    public static final int ALL_PREFERENCES = 0;

    /** The Constant SIMULATION_PREFERENCES. */
    public static final int SIMULATION_PREFERENCES = 1;

    /**
     * Instantiates a new lang.process.removeeditor.
     *
     * @param prefs the prefs
     * @param prefsToEdit the prefs to edit
     */
    public VSEditor(VSPrefs prefs, VSPrefs prefsToEdit) {
        init(prefs, prefsToEdit);
    }

    /**
     * Adds the to button panel front.
     *
     * @param buttonPanel the button panel
     */
    abstract protected void addToButtonPanelFront(JPanel buttonPanel);

    /**
     * Adds the to button panel last.
     *
     * @param buttonPanel the button panel
     */
    abstract protected void addToButtonPanelLast(JPanel buttonPanel);

    /**
     * Adds the to edit table last.
     */
    abstract protected void addToEditTableLast();

    /**
     * Sets the prefs.
     *
     * @param prefs the new prefs
     */
    public void setPrefs(VSPrefs prefs) {
        this.prefs = prefs;
    }

    /**
     * Sets the prefs to edit.
     *
     * @param prefsToEdit the new prefs to edit
     */
    public void setPrefsToEdit(VSPrefs prefsToEdit) {
        this.prefsToEdit = prefsToEdit;
    }

    /**
     * Sets the frame.
     *
     * @param frame the new frame
     */
    public void setFrame(VSFrame frame) {
        this.frame = frame;
    }

    /**
     * Gets the frame.
     *
     * @return the frame
     */
    public VSFrame getFrame() {
        return frame;
    }

    /**
     * Dispose frame if exists.
     */
    protected void disposeFrameIfExists() {
        if (frame != null)
            frame.dispose();
    }

    /**
     * Dispose frame with parent if exists.
     */
    protected void disposeFrameWithParentIfExists() {
        if (frame != null)
            frame.disposeWithParent();
    }

    /**
     * Inits the.
     *
     * @param prefs the prefs
     * @param prefsToEdit the prefs to edit
     */
    private void init(VSPrefs prefs, VSPrefs prefsToEdit) {
        this.prefs = prefs;
        this.prefsToEdit = prefsToEdit;

        editPanel = createEditPanel();
        buttonPanel = createButtonPanel();

        prefsToEditMap = new HashMap<String,VSPrefs>();

        colorFields = new HashMap<String,JTextField>();
        floatFields = new HashMap<String,JTextField>();
        integerFields = new HashMap<String,JComboBox>();
        longFields = new HashMap<String,JTextField>();
        booleanFields = new HashMap<String,JCheckBox>();
        stringFields = new HashMap<String,JTextField>();

        colorKeys = filterKeys(prefsToEdit.getColorKeySet());
        floatKeys = filterKeys(prefsToEdit.getFloatKeySet());
        integerKeys = filterKeys(prefsToEdit.getIntegerKeySet());
        longKeys = filterKeys(prefsToEdit.getLongKeySet());
        booleanKeys = filterKeys(prefsToEdit.getBooleanKeySet());
        stringKeys = filterKeys(prefsToEdit.getStringKeySet());

        fillEditPanel(prefsToEdit);
    }

    /**
     * Filter keys.
     *
     * @param set the set
     *
     * @return the array list< string>
     */
    private ArrayList<String> filterKeys(Set<String> set) {
        ArrayList<String> filtered = new ArrayList<String>();
        boolean expertMode = prefs.getBoolean("sim.mode.expert");

        for (String elem : set) {
            if (!elem.startsWith("lang.") && !elem.startsWith("keyevent")) {
                if (expertMode)
                    filtered.add(elem);
                else if (!elem.startsWith("col.") && (!elem.startsWith("div.")))
                    filtered.add(elem);
            }
        }

        return filtered;
    }

    /**
     * Creates the button panel.
     *
     * @return the j panel
     */
    private JPanel createButtonPanel() {
        JPanel buttonPanel = new JPanel();
        buttonPanel.setBackground(Color.WHITE);
        addToButtonPanelFront(buttonPanel);

        JButton resetButton = new JButton(
            prefs.getString("lang.reset"));
        resetButton.setMnemonic(prefs.getInteger("keyevent.reset"));
        resetButton.addActionListener(this);
        buttonPanel.add(resetButton);

        addToButtonPanelLast(buttonPanel);

        return buttonPanel;
    }

    /**
     * Creates the unit panel.
     *
     * @param comp the comp
     * @param key the key
     *
     * @return the j panel
     */
    private JPanel createUnitPanel(Component comp, String key) {
        JPanel unitPanel = new JPanel(new GridBagLayout());
        unitPanel.setBackground(Color.WHITE);
        unitPanel.setBorder(null);

        String unitText = prefs.getUnit(key);
        if (unitText == null)
            unitText = "";

        unitText = " " + unitText;
        while (unitText.length() < MIN_UNIT_LENGTH)
            unitText = unitText + " ";
        JLabel unitLabel = new JLabel(unitText);

        unitPanel.setLayout(new BoxLayout(unitPanel, BoxLayout.X_AXIS));
        unitPanel.add(comp);
        unitPanel.add(unitLabel);

        return unitPanel;
    }

    /**
     * Creates the edit panel.
     *
     * @return the j panel
     */
    private JPanel createEditPanel() {
        JPanel editPanel = new JPanel();
        editPanel.setLayout(new BoxLayout(editPanel, BoxLayout.Y_AXIS));
        editPanel.setBackground(Color.WHITE);

        editTable = new VSEditorTable(prefs);
        JScrollPane scrollPane = new JScrollPane(editTable);
        editPanel.add(scrollPane);

        return editPanel;
    }

    /**
     * Creates the integer component.
     *
     * @param fullKey the full key
     * @param key the key
     * @param prefsToEdit the prefs to edit
     *
     * @return the lang.process.removetupel< string, component, j combo box>
     */
    protected VSTupel<String,Component,JComboBox> createIntegerComponent(String fullKey, String key, VSPrefs prefsToEdit) {
        String descr = prefsToEdit.getDescription(fullKey);
        String label = descr == null ? fullKey : descr;
        Integer integer = prefsToEdit.getInteger(key);
        Integer initialSelection[] = { integer };
        JComboBox valComboBox = new JComboBox(initialSelection);
        VSPrefs.SettingRestriction settingRestriction = prefsToEdit.getRestriction(fullKey);

        int minValue, maxValue;
        if (settingRestriction != null) {
            VSPrefs.IntegerSettingRestriction integerSettingRestriction =
                (VSPrefs.IntegerSettingRestriction) settingRestriction;
            minValue = integerSettingRestriction.getMinValue();
            maxValue = integerSettingRestriction.getMaxValue();

        } else {
            minValue = 0;
            maxValue = 100;
        }

        for (int i = minValue; i <= maxValue; ++i)
            valComboBox.addItem(new Integer(i));
        valComboBox.setBorder(null);

        return new VSTupel<String,Component,JComboBox>(label, createUnitPanel(valComboBox, fullKey), valComboBox);
    }

    /**
     * Creates the boolean component.
     *
     * @param fullKey the full key
     * @param key the key
     * @param prefsToEdit the prefs to edit
     *
     * @return the lang.process.removetupel< string, component, j check box>
     */
    protected VSTupel<String,Component,JCheckBox> createBooleanComponent(String fullKey, String key, VSPrefs prefsToEdit) {
        final String activated = prefs.getString("lang.activated");
        String descr = prefsToEdit.getDescription(fullKey);
        String label = descr == null ? fullKey : descr;
        JCheckBox valField = new JCheckBox(activated, prefsToEdit.getBoolean(key));
        valField.setBackground(Color.WHITE);
        valField.setBorder(null);
        return new VSTupel<String,Component,JCheckBox>(label, createUnitPanel(valField, fullKey), valField);
    }

    /**
     * Creates the long component.
     *
     * @param fullKey the full key
     * @param key the key
     * @param prefsToEdit the prefs to edit
     *
     * @return the lang.process.removetupel< string, component, j text field>
     */
    protected VSTupel<String,Component,JTextField> createLongComponent(String fullKey, String key, VSPrefs prefsToEdit) {
        String descr = prefsToEdit.getDescription(fullKey);
        String label = descr == null ? fullKey : descr;
        JTextField valField = new JTextField(VALUE_FIELD_COLS);
        valField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent e) {
                JTextField valField = (JTextField)e.getSource();
                if (valField.getText().length() >= valField.getColumns() + 10)
                    e.consume();
            }
        });
        valField.setText(""+prefsToEdit.getLong(key));
        valField.setBorder(null);
        return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
    }

    /**
     * Creates the float component.
     *
     * @param fullKey the full key
     * @param key the key
     * @param prefsToEdit the prefs to edit
     *
     * @return the lang.process.removetupel< string, component, j text field>
     */
    protected VSTupel<String,Component,JTextField> createFloatComponent(String fullKey, String key, VSPrefs prefsToEdit) {
        String descr = prefsToEdit.getDescription(fullKey);
        String label = descr == null ? fullKey : descr;
        JTextField valField = new JTextField(VALUE_FIELD_COLS);
        valField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent e) {
                JTextField valField = (JTextField)e.getSource();
                if (valField.getText().length() >= valField.getColumns() + 10)
                    e.consume();
            }
        });
        valField.setText(""+prefsToEdit.getFloat(key));
        valField.setBorder(null);
        return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
    }

    /**
     * Creates the color component.
     *
     * @param fullKey the full key
     * @param key the key
     * @param prefsToEdit the prefs to edit
     *
     * @return the lang.process.removetupel< string, component, j text field>
     */
    protected VSTupel<String,Component,JTextField> createColorComponent(String fullKey, String key, final VSPrefs prefsToEdit) {
        String descr = prefsToEdit.getDescription(fullKey);
        String label = descr == null ? fullKey : descr;
        final JTextField valField = new JTextField(VALUE_FIELD_COLS);
        Color color = prefsToEdit.getColor(key);
        valField.setBackground(color);
        valField.setEditable(false);
        valField.addMouseListener(new MouseListener() {
            public void mouseExited(MouseEvent e) { }
            public void mouseReleased(MouseEvent e) { }
            public void mouseEntered(MouseEvent e) { }
            public void mousePressed(MouseEvent e) { }
            public void mouseClicked(MouseEvent e) {
                JFrame parentFrame = getFrame();
                JFrame frame = new VSFrame(
                    prefs.getString("lang.name") + " - " +
                    prefs.getString(
                        "lang.colorchooser"),parentFrame);
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

                JComponent colorChooserPane = new VSColorChooser(prefs, valField);
                colorChooserPane.setOpaque(true);

                frame.setContentPane(colorChooserPane);
                frame.pack();
                frame.setVisible(true);
            }
        });
        valField.setBorder(null);
        return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
    }

    /**
     * Creates the string component.
     *
     * @param fullKey the full key
     * @param key the key
     * @param prefsToEdit the prefs to edit
     *
     * @return the lang.process.removetupel< string, component, j text field>
     */
    protected VSTupel<String,Component,JTextField> createStringComponent(String fullKey, String key, VSPrefs prefsToEdit) {
        String descr = prefsToEdit.getDescription(fullKey);
        String label = descr == null ? fullKey : descr;
        JTextField valField = new JTextField(VALUE_FIELD_COLS);
        valField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent e) {
                JTextField valField = (JTextField)e.getSource();
                if (valField.getText().length() >= valField.getColumns() + 10)
                    e.consume();
            }
        });
        valField.setText(prefsToEdit.getString(key));
        valField.setBorder(null);
        return new VSTupel<String,Component,JTextField>(label, createUnitPanel(valField, fullKey), valField);
    }

    /**
     * Fill edit panel.
     *
     * @param prefsToEdit the prefs to edit
     */
    private void fillEditPanel(VSPrefs prefsToEdit) {
        HashMap<String,Component> components = new HashMap<String,Component>();
        HashMap<String,String> labels = new HashMap<String,String>();

        for (String key : integerKeys) {
            String fullKey = VSPrefs.INTEGER_PREFIX + key;
            VSTupel<String,Component,JComboBox> tupel = createIntegerComponent(fullKey, key, prefsToEdit);
            labels.put(fullKey, tupel.getA());
            components.put(fullKey, tupel.getB());
            integerFields.put(key, tupel.getC());
        }

        for (String key : booleanKeys) {
            String fullKey = VSPrefs.BOOLEAN_PREFIX + key;
            VSTupel<String,Component,JCheckBox> tupel = createBooleanComponent(fullKey, key, prefsToEdit);
            labels.put(fullKey, tupel.getA());
            components.put(fullKey, tupel.getB());
            booleanFields.put(key, tupel.getC());
        }

        for (String key : longKeys) {
            String fullKey = VSPrefs.LONG_PREFIX + key;
            VSTupel<String,Component,JTextField> tupel = createLongComponent(fullKey, key, prefsToEdit);
            labels.put(fullKey, tupel.getA());
            components.put(fullKey, tupel.getB());
            longFields.put(key, tupel.getC());
        }


        for (String key : floatKeys) {
            String fullKey = VSPrefs.FLOAT_PREFIX + key;
            VSTupel<String,Component,JTextField> tupel = createFloatComponent(fullKey, key, prefsToEdit);
            labels.put(fullKey, tupel.getA());
            components.put(fullKey, tupel.getB());
            floatFields.put(key, tupel.getC());
        }


        for (String key : colorKeys) {
            String fullKey = VSPrefs.COLOR_PREFIX + key;
            VSTupel<String,Component,JTextField> tupel = createColorComponent(fullKey, key, prefsToEdit);
            labels.put(fullKey, tupel.getA());
            components.put(fullKey, tupel.getB());
            colorFields.put(key, tupel.getC());
        }

        for (String key : stringKeys) {
            String fullKey = VSPrefs.STRING_PREFIX + key;
            VSTupel<String,Component,JTextField> tupel = createStringComponent(fullKey, key, prefsToEdit);
            labels.put(fullKey, tupel.getA());
            components.put(fullKey, tupel.getB());
            stringFields.put(key, tupel.getC());
        }

        ArrayList<String> fullKeys = new ArrayList<String>();
        fullKeys.addAll(components.keySet());
        Collections.sort(fullKeys);

        boolean flag = false;
        for (String fullKey : fullKeys) {
            String key = fullKey.substring(fullKey.indexOf(' ')+1);
            if (key.startsWith("sim.")) {
                if (!flag) {
                    flag = true;
                    addSeparator(prefs.getString("lang.prefs.simulation"));
                }
                addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit);
            }
        }

        flag = false;
        for (String fullKey : fullKeys) {
            String key = fullKey.substring(fullKey.indexOf(' ')+1);
            if (key.startsWith("process.")) {
                if (!flag) {
                    flag = true;
                    addSeparator(prefs.getString("lang.prefs.process"));
                }
                addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit);
            }
        }

        flag = false;
        for (String fullKey : fullKeys) {
            String key = fullKey.substring(fullKey.indexOf(' ')+1);
            if (key.startsWith("message.")) {
                if (!flag) {
                    flag = true;
                    addSeparator(prefs.getString("lang.prefs.message"));
                }
                addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit);
            }
        }

        flag = false;
        for (String fullKey : fullKeys) {
            String key = fullKey.substring(fullKey.indexOf(' ')+1);
            if (key.startsWith("col.")) {
                if (!flag) {
                    flag = true;
                    addSeparator(prefs.getString("lang.prefs.color"));
                }
                addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit);
            }
        }

        flag = false;
        for (String fullKey : fullKeys) {
            String key = fullKey.substring(fullKey.indexOf(' ')+1);
            if (key.startsWith("div.")) {
                if (!flag) {
                    flag = true;
                    addSeparator(prefs.getString("lang.prefs.diverse"));
                }
                addVariable(labels.get(fullKey), components.get(fullKey), prefsToEdit);
            }
        }

        addToEditTableLast();
        editTable.fireTableDataChanged();
    }

    /**
     * Adds the to editor.
     *
     * @param label the label
     * @param prefsKey the prefs key
     * @param prefsToAdd the prefs to add
     */
    protected void addToEditor(String label, String prefsKey, VSPrefs prefsToAdd) {
        addSeparator(label);
        prefsKey = "(" + prefsKey + ")";

        ArrayList<String> fullKeys = new ArrayList<String>();

        Set<String> integerKeys = prefsToAdd.getIntegerKeySet();
        Set<String> floatKeys = prefsToAdd.getFloatKeySet();
        Set<String> longKeys = prefsToAdd.getLongKeySet();
        Set<String> booleanKeys = prefsToAdd.getBooleanKeySet();
        Set<String> stringKeys = prefsToAdd.getStringKeySet();

        for (String key : integerKeys) fullKeys.add(VSPrefs.INTEGER_PREFIX + key);
        for (String key : floatKeys) fullKeys.add(VSPrefs.FLOAT_PREFIX + key);
        for (String key : longKeys) fullKeys.add(VSPrefs.LONG_PREFIX + key);
        for (String key : booleanKeys) fullKeys.add(VSPrefs.BOOLEAN_PREFIX + key);
        for (String key : stringKeys) fullKeys.add(VSPrefs.STRING_PREFIX + key);

        Collections.sort(fullKeys);

        for (String fullKey : fullKeys) {
            String key = fullKey.substring(fullKey.indexOf(": ") + 2);
            if (fullKey.startsWith(VSPrefs.INTEGER_PREFIX)) {
                VSTupel<String,Component,JComboBox> tupel =
                    createIntegerComponent(fullKey, key, prefsToAdd);
                this.integerKeys.add(prefsKey+key);
                this.integerFields.put(prefsKey+key, tupel.getC());
                addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd);

            } else if (fullKey.startsWith(VSPrefs.BOOLEAN_PREFIX)) {
                VSTupel<String,Component,JCheckBox> tupel =
                    createBooleanComponent(fullKey, key, prefsToAdd);
                this.booleanKeys.add(prefsKey + key);
                this.booleanFields.put(prefsKey+key, tupel.getC());
                addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd);

            } else if (fullKey.startsWith(VSPrefs.LONG_PREFIX)) {
                VSTupel<String,Component,JTextField> tupel =
                    createLongComponent(fullKey, key, prefsToAdd);
                this.longKeys.add(prefsKey+key);
                this.longFields.put(prefsKey+key, tupel.getC());
                addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd);

            } else if (fullKey.startsWith(VSPrefs.FLOAT_PREFIX)) {
                VSTupel<String,Component,JTextField> tupel =
                    createFloatComponent(fullKey, key, prefsToAdd);
                this.floatKeys.add(prefsKey + key);
                this.floatFields.put(prefsKey+key, tupel.getC());
                addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd);

            } else if (fullKey.startsWith(VSPrefs.STRING_PREFIX)) {
                VSTupel<String,Component,JTextField> tupel =
                    createStringComponent(fullKey, key, prefsToAdd);
                this.stringKeys.add(prefsKey + key);
                this.stringFields.put(prefsKey+key, tupel.getC());
                addVariable(prefsKey, tupel.getA(), tupel.getB(), prefsToAdd);
            }

        }
    }

    /**
     * Adds the separator.
     *
     * @param label the label
     */
    private void addSeparator(String label) {
        editTable.addSeparator(label);
    }

    /**
     * Adds the variable.
     *
     * @param label the label
     * @param component the component
     * @param prefs the prefs
     */
    private void addVariable(String label, Component component, VSPrefs prefs) {
        addVariable("", label, component, prefs);
    }

    /**
     * Adds the variable.
     *
     * @param prefsKey the prefs key
     * @param label the label
     * @param component the component
     * @param prefs the prefs
     */
    private void addVariable(String prefsKey, String label, Component component, VSPrefs prefs) {
        prefsToEditMap.put(prefsKey, prefs);
        editTable.addVariable(label, component);
    }

    /**
     * Reset edit panel.
     */
    protected void resetEditPanel() {
        for (String key : integerKeys) {
            JComboBox valComboBox = integerFields.get(key);
            valComboBox.setSelectedIndex(0);
        }

        for (String key : booleanKeys) {
            String keys[] = getKeys(key);
            JCheckBox valField = booleanFields.get(key);
            valField.setSelected(prefsToEditMap.get(keys[1]).getBoolean(keys[0]));
        }

        for (String key : floatKeys) {
            String keys[] = getKeys(key);
            JTextField valField = floatFields.get(key);
            valField.setText(""+prefsToEditMap.get(keys[1]).getFloat(keys[0]));
        }

        for (String key : longKeys) {
            String keys[] = getKeys(key);
            JTextField valField = longFields.get(key);
            valField.setText(""+prefsToEditMap.get(keys[1]).getLong(keys[0]));
        }

        for (String key : colorKeys) {
            String keys[] = getKeys(key);
            JTextField valField = colorFields.get(key);
            valField.setBackground(prefsToEditMap.get(keys[1]).getColor(keys[0]));
        }

        for (String key : stringKeys) {
            String keys[] = getKeys(key);
            JTextField valField = stringFields.get(keys);
            valField.setText(prefsToEditMap.get(keys[1]).getString(keys[0]));
        }
    }

    /**
     * Gets the keys.
     *
     * @param key the key
     *
     * @return [0] := key, [1] := prefsKey
     */
    private String[] getKeys(String key) {
        String keys[] = { key, "" };

        if (key.startsWith("(")) {
            keys[1] = key.substring(0, key.indexOf(")") + 1);
            keys[0] = key.substring(key.indexOf(")")+1);
        }

        return keys;
    }

    /**
     * Save prefs.
     */
    protected void savePrefs() {
        boolean expertMode = prefs.getBoolean("sim.mode.expert");

        for (String key : integerKeys) {
            String keys[] = getKeys(key);
            //String fullKey = VSPrefs.INTEGER_PREFIX + keys[0];
            JComboBox valComboBox = integerFields.get(key);
            prefsToEditMap.get(keys[1]).setInteger(keys[0], (Integer) valComboBox.getSelectedItem());
        }

        for (String key : booleanKeys) {
            String keys[] = getKeys(key);
            //String fullKey = VSPrefs.BOOLEAN_PREFIX + keys[0];
            JCheckBox valField = booleanFields.get(key);
            prefsToEditMap.get(keys[1]).setBoolean(keys[0], valField.isSelected());
        }

        for (String key : floatKeys) {
            String keys[] = getKeys(key);
            JTextField valField = floatFields.get(key);

            try {
                //String fullKey = VSPrefs.FLOAT_PREFIX + keys[0];
                Float val = Float.valueOf(valField.getText());
                prefsToEditMap.get(keys[1]).setFloat(keys[0], val);

            } catch (NumberFormatException e) {
                valField.setText("0.0");
            }
        }

        for (String key : longKeys) {
            String keys[] = getKeys(key);
            JTextField valField = longFields.get(key);

            try {
                //String fullKey = VSPrefs.LONG_PREFIX + keys[0];
                Long val = Long.valueOf(valField.getText());
                prefsToEditMap.get(keys[1]).setLong(keys[0], val);

            } catch (NumberFormatException e) {
                valField.setText("0");
            }
        }

        for (String key : colorKeys) {
            String keys[] = getKeys(key);
            //String fullKey = VSPrefs.COLOR_PREFIX + keys[0];
            JTextField valField = colorFields.get(key);
            prefsToEditMap.get(keys[1]).setColor(keys[0], valField.getBackground());
        }

        for (String key : stringKeys) {
            String keys[] = getKeys(key);
            //String fullKey = VSPrefs.STRING_PREFIX + keys[0];
            JTextField valField = stringFields.get(key);
            prefsToEditMap.get(keys[1]).setString(keys[0], valField.getText());
        }

        expertModeChanged = expertMode != prefs.getBoolean("sim.mode.expert");
    }

    /**
     * Expert mode changed.
     *
     * @return true, if successful
     */
    public boolean expertModeChanged() {
        boolean ret = expertModeChanged;

        if (expertModeChanged)
            expertModeChanged = false;

        return ret;
    }

    /* (non-Javadoc)
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
        String actionCommand = e.getActionCommand();

        if (actionCommand.equals(prefs.getString("lang.takeover"))) {
            savePrefs();

        } else if (actionCommand.equals(prefs.getString("lang.reset"))) {
            resetEditPanel();
        }
    }

    /**
     * Gets the edits the panel.
     *
     * @return the edits the panel
     */
    public JPanel getEditPanel() {
        return editPanel;
    }

    /**
     * Gets the edits the table.
     *
     * @return the edits the table
     */
    public VSEditorTable getEditTable() {
        return editTable;
    }

    /**
     * Gets the button panel.
     *
     * @return the button panel
     */
    public JPanel getButtonPanel() {
        return buttonPanel;
    }
}