]> git.xonotic.org Git - xonotic/xonotic.git/blobdiff - misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/ui/swinggui/PreferencesDialog.java
fix lots of CRLFs
[xonotic/xonotic.git] / misc / tools / NexuizDemoRecorder / main / src / main / java / com / nexuiz / demorecorder / ui / swinggui / PreferencesDialog.java
index 7af4a2b4d97c88393c04c3d071dc111275b36470..cc64b461cbb3522bbbf4adac2c4908d4e499285c 100644 (file)
-package com.nexuiz.demorecorder.ui.swinggui;\r
-\r
-import java.awt.Frame;\r
-import java.awt.event.ActionEvent;\r
-import java.awt.event.ActionListener;\r
-import java.io.File;\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-import java.util.Properties;\r
-import java.util.Set;\r
-\r
-import javax.swing.JButton;\r
-import javax.swing.JCheckBox;\r
-import javax.swing.JComponent;\r
-import javax.swing.JDialog;\r
-import javax.swing.JFileChooser;\r
-import javax.swing.JLabel;\r
-import javax.swing.JPanel;\r
-import javax.swing.JTextField;\r
-\r
-import net.miginfocom.swing.MigLayout;\r
-\r
-import org.jdesktop.swingx.JXTitledSeparator;\r
-\r
-import com.nexuiz.demorecorder.application.DemoRecorderApplication;\r
-import com.nexuiz.demorecorder.application.NDRPreferences;\r
-import com.nexuiz.demorecorder.application.plugins.EncoderPlugin;\r
-import com.nexuiz.demorecorder.ui.swinggui.utils.SwingGUIUtils;\r
-\r
-public class PreferencesDialog extends JDialog implements ActionListener {\r
-\r
-       private static final long serialVersionUID = 7328399646538571333L;\r
-       private Frame parentFrame;\r
-       private DemoRecorderApplication appLayer;\r
-       private NDRPreferences preferences;\r
-       private Map<String, JComponent> dialogSettings;\r
-       \r
-       private JButton saveButton = new JButton("Save");\r
-       private JButton cancelButton = new JButton("Cancel");\r
-       \r
-       public PreferencesDialog(Frame owner, DemoRecorderApplication appLayer) {\r
-               super(owner, true);\r
-               this.parentFrame = owner;\r
-               this.appLayer = appLayer;\r
-               this.preferences = appLayer.getPreferences();\r
-               this.dialogSettings = new HashMap<String, JComponent>();\r
-               setDefaultCloseOperation(DISPOSE_ON_CLOSE);\r
-\r
-               setTitle("Preferences");\r
-\r
-               this.setupLayout();\r
-       }\r
-\r
-       private void setupLayout() {\r
-               setLayout(new MigLayout("wrap 2", "[][::150,fill]"));\r
-               \r
-               //add heading\r
-               JXTitledSeparator applicationHeading = new JXTitledSeparator("Application settings");\r
-               getContentPane().add(applicationHeading, "span 2,grow");\r
-               \r
-               for (int i = 0; i < DemoRecorderApplication.Preferences.PREFERENCES_ORDER.length; i++) {\r
-                       String currentSetting = DemoRecorderApplication.Preferences.PREFERENCES_ORDER[i];\r
-                       if (this.preferences.getProperty(NDRPreferences.MAIN_APPLICATION, currentSetting) != null) {\r
-                               this.setupSingleSetting(NDRPreferences.MAIN_APPLICATION, currentSetting);\r
-                       }\r
-               }\r
-               \r
-               //add plugin settings\r
-               for (EncoderPlugin plugin : this.appLayer.getEncoderPlugins()) {\r
-                       String pluginName = plugin.getName();\r
-                       //only display settings if the plugin actually has any...\r
-                       Properties pluginPreferences = plugin.getGlobalPreferences();\r
-                       if (pluginPreferences.size() > 0) {\r
-                               //add heading\r
-                               JXTitledSeparator pluginHeading = new JXTitledSeparator(pluginName + " plugin settings");\r
-                               getContentPane().add(pluginHeading, "span 2,grow");\r
-                               \r
-                               for (String pluginKey : plugin.getGlobalPreferencesOrder()) {\r
-                                       if (this.preferences.getProperty(pluginName, pluginKey) != null) {\r
-                                               this.setupSingleSetting(pluginName, pluginKey);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-               \r
-               JPanel buttonPanel = new JPanel();\r
-               buttonPanel.add(saveButton);\r
-               buttonPanel.add(cancelButton);\r
-               saveButton.addActionListener(this);\r
-               cancelButton.addActionListener(this);\r
-               getContentPane().add(buttonPanel, "span 2");\r
-       }\r
-       \r
-       private void setupSingleSetting(String category, String setting) {\r
-               getContentPane().add(new JLabel(setting + ":"));\r
-               \r
-               String value = this.preferences.getProperty(category, setting);\r
-               if (SwingGUIUtils.isBooleanValue(value)) {\r
-                       JCheckBox checkbox = new JCheckBox();\r
-                       this.dialogSettings.put(NDRPreferences.getConcatenatedKey(category, setting), checkbox);\r
-                       getContentPane().add(checkbox);\r
-               } else if (SwingGUIUtils.isFileChooser(value)) {\r
-                       final JFileChooser fc = new JFileChooser();\r
-                       fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);\r
-                       JButton fcButton = new JButton("...");\r
-                       fcButton.addActionListener(new ActionListener() {\r
-                               @Override\r
-                               public void actionPerformed(ActionEvent e) {\r
-                                       fc.showOpenDialog(PreferencesDialog.this);\r
-                               }\r
-                       });\r
-                       this.dialogSettings.put(NDRPreferences.getConcatenatedKey(category, setting), fc);\r
-                       getContentPane().add(fcButton);\r
-               } else {\r
-                       JTextField textField = new JTextField();\r
-                       this.dialogSettings.put(NDRPreferences.getConcatenatedKey(category, setting), textField);\r
-                       getContentPane().add(textField);\r
-               }\r
-       }\r
-       \r
-       \r
-       \r
-       public void showDialog() {\r
-               this.loadSettings();\r
-               this.pack();\r
-               this.setLocationRelativeTo(this.parentFrame);\r
-               setResizable(false);\r
-               this.setVisible(true);\r
-       }\r
-       \r
-       /**\r
-        * Loads the settings from the application layer (and global plug-in settings) to the form.\r
-        */\r
-       private void loadSettings() {\r
-               Set<Object> keys = this.preferences.keySet();\r
-               for (Object keyObj : keys) {\r
-                       String concatenatedKey = (String) keyObj;\r
-                       String value;\r
-                       JComponent component = null;\r
-                       if ((value = this.preferences.getProperty(concatenatedKey)) != null) {\r
-                               if (SwingGUIUtils.isBooleanValue(value)) {\r
-                                       component = this.dialogSettings.get(concatenatedKey);\r
-                                       if (component != null) {\r
-                                               ((JCheckBox) component).setSelected(Boolean.valueOf(value));\r
-                                       }\r
-                               } else if (SwingGUIUtils.isFileChooser(value)) {\r
-                                       component = this.dialogSettings.get(concatenatedKey);\r
-                                       try {\r
-                                               File selectedFile = new File(value);\r
-                                               if (selectedFile.exists() && component != null) {\r
-                                                       ((JFileChooser) component).setSelectedFile(selectedFile);\r
-                                               }\r
-                                       } catch (Throwable e) {}\r
-                                       \r
-                               } else {\r
-                                       component = this.dialogSettings.get(concatenatedKey);\r
-                                       if (component != null) {\r
-                                               ((JTextField) component).setText(value);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       @Override\r
-       public void actionPerformed(ActionEvent e) {\r
-               if (e.getSource() == cancelButton) {\r
-                       this.setVisible(false);\r
-               } else if (e.getSource() == saveButton) {\r
-                       this.saveSettings();\r
-               }\r
-       }\r
-\r
-       private void saveSettings() {\r
-               Set<String> keys = this.dialogSettings.keySet();\r
-               //remember, the keys are concatenated, containing both the category and actual key \r
-               for (String key : keys) {\r
-                       JComponent component = this.dialogSettings.get(key);\r
-                       if (component instanceof JCheckBox) {\r
-                               JCheckBox checkbox = (JCheckBox) component;\r
-                               this.appLayer.setPreference(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), checkbox.isSelected());\r
-                       } else if (component instanceof JFileChooser) {\r
-                               JFileChooser fileChooser = (JFileChooser) component;\r
-                               if (fileChooser.getSelectedFile() != null) {\r
-                                       String path = fileChooser.getSelectedFile().getAbsolutePath();\r
-                                       this.appLayer.setPreference(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), path);\r
-                               }\r
-                       } else if (component instanceof JTextField) {\r
-                               JTextField textField = (JTextField) component;\r
-                               this.appLayer.setPreference(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), textField.getText());\r
-                       }\r
-               }\r
-               this.setVisible(false);\r
-       }\r
-}\r
+package com.nexuiz.demorecorder.ui.swinggui;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JFileChooser;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+import net.miginfocom.swing.MigLayout;
+
+import org.jdesktop.swingx.JXTitledSeparator;
+
+import com.nexuiz.demorecorder.application.DemoRecorderApplication;
+import com.nexuiz.demorecorder.application.NDRPreferences;
+import com.nexuiz.demorecorder.application.plugins.EncoderPlugin;
+import com.nexuiz.demorecorder.ui.swinggui.utils.SwingGUIUtils;
+
+public class PreferencesDialog extends JDialog implements ActionListener {
+
+       private static final long serialVersionUID = 7328399646538571333L;
+       private Frame parentFrame;
+       private DemoRecorderApplication appLayer;
+       private NDRPreferences preferences;
+       private Map<String, JComponent> dialogSettings;
+       
+       private JButton saveButton = new JButton("Save");
+       private JButton cancelButton = new JButton("Cancel");
+       
+       public PreferencesDialog(Frame owner, DemoRecorderApplication appLayer) {
+               super(owner, true);
+               this.parentFrame = owner;
+               this.appLayer = appLayer;
+               this.preferences = appLayer.getPreferences();
+               this.dialogSettings = new HashMap<String, JComponent>();
+               setDefaultCloseOperation(DISPOSE_ON_CLOSE);
+
+               setTitle("Preferences");
+
+               this.setupLayout();
+       }
+
+       private void setupLayout() {
+               setLayout(new MigLayout("wrap 2", "[][::150,fill]"));
+               
+               //add heading
+               JXTitledSeparator applicationHeading = new JXTitledSeparator("Application settings");
+               getContentPane().add(applicationHeading, "span 2,grow");
+               
+               for (int i = 0; i < DemoRecorderApplication.Preferences.PREFERENCES_ORDER.length; i++) {
+                       String currentSetting = DemoRecorderApplication.Preferences.PREFERENCES_ORDER[i];
+                       if (this.preferences.getProperty(NDRPreferences.MAIN_APPLICATION, currentSetting) != null) {
+                               this.setupSingleSetting(NDRPreferences.MAIN_APPLICATION, currentSetting);
+                       }
+               }
+               
+               //add plugin settings
+               for (EncoderPlugin plugin : this.appLayer.getEncoderPlugins()) {
+                       String pluginName = plugin.getName();
+                       //only display settings if the plugin actually has any...
+                       Properties pluginPreferences = plugin.getGlobalPreferences();
+                       if (pluginPreferences.size() > 0) {
+                               //add heading
+                               JXTitledSeparator pluginHeading = new JXTitledSeparator(pluginName + " plugin settings");
+                               getContentPane().add(pluginHeading, "span 2,grow");
+                               
+                               for (String pluginKey : plugin.getGlobalPreferencesOrder()) {
+                                       if (this.preferences.getProperty(pluginName, pluginKey) != null) {
+                                               this.setupSingleSetting(pluginName, pluginKey);
+                                       }
+                               }
+                       }
+               }
+               
+               JPanel buttonPanel = new JPanel();
+               buttonPanel.add(saveButton);
+               buttonPanel.add(cancelButton);
+               saveButton.addActionListener(this);
+               cancelButton.addActionListener(this);
+               getContentPane().add(buttonPanel, "span 2");
+       }
+       
+       private void setupSingleSetting(String category, String setting) {
+               getContentPane().add(new JLabel(setting + ":"));
+               
+               String value = this.preferences.getProperty(category, setting);
+               if (SwingGUIUtils.isBooleanValue(value)) {
+                       JCheckBox checkbox = new JCheckBox();
+                       this.dialogSettings.put(NDRPreferences.getConcatenatedKey(category, setting), checkbox);
+                       getContentPane().add(checkbox);
+               } else if (SwingGUIUtils.isFileChooser(value)) {
+                       final JFileChooser fc = new JFileChooser();
+                       fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
+                       JButton fcButton = new JButton("...");
+                       fcButton.addActionListener(new ActionListener() {
+                               @Override
+                               public void actionPerformed(ActionEvent e) {
+                                       fc.showOpenDialog(PreferencesDialog.this);
+                               }
+                       });
+                       this.dialogSettings.put(NDRPreferences.getConcatenatedKey(category, setting), fc);
+                       getContentPane().add(fcButton);
+               } else {
+                       JTextField textField = new JTextField();
+                       this.dialogSettings.put(NDRPreferences.getConcatenatedKey(category, setting), textField);
+                       getContentPane().add(textField);
+               }
+       }
+       
+       
+       
+       public void showDialog() {
+               this.loadSettings();
+               this.pack();
+               this.setLocationRelativeTo(this.parentFrame);
+               setResizable(false);
+               this.setVisible(true);
+       }
+       
+       /**
+        * Loads the settings from the application layer (and global plug-in settings) to the form.
+        */
+       private void loadSettings() {
+               Set<Object> keys = this.preferences.keySet();
+               for (Object keyObj : keys) {
+                       String concatenatedKey = (String) keyObj;
+                       String value;
+                       JComponent component = null;
+                       if ((value = this.preferences.getProperty(concatenatedKey)) != null) {
+                               if (SwingGUIUtils.isBooleanValue(value)) {
+                                       component = this.dialogSettings.get(concatenatedKey);
+                                       if (component != null) {
+                                               ((JCheckBox) component).setSelected(Boolean.valueOf(value));
+                                       }
+                               } else if (SwingGUIUtils.isFileChooser(value)) {
+                                       component = this.dialogSettings.get(concatenatedKey);
+                                       try {
+                                               File selectedFile = new File(value);
+                                               if (selectedFile.exists() && component != null) {
+                                                       ((JFileChooser) component).setSelectedFile(selectedFile);
+                                               }
+                                       } catch (Throwable e) {}
+                                       
+                               } else {
+                                       component = this.dialogSettings.get(concatenatedKey);
+                                       if (component != null) {
+                                               ((JTextField) component).setText(value);
+                                       }
+                               }
+                       }
+               }
+       }
+
+       @Override
+       public void actionPerformed(ActionEvent e) {
+               if (e.getSource() == cancelButton) {
+                       this.setVisible(false);
+               } else if (e.getSource() == saveButton) {
+                       this.saveSettings();
+               }
+       }
+
+       private void saveSettings() {
+               Set<String> keys = this.dialogSettings.keySet();
+               //remember, the keys are concatenated, containing both the category and actual key 
+               for (String key : keys) {
+                       JComponent component = this.dialogSettings.get(key);
+                       if (component instanceof JCheckBox) {
+                               JCheckBox checkbox = (JCheckBox) component;
+                               this.appLayer.setPreference(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), checkbox.isSelected());
+                       } else if (component instanceof JFileChooser) {
+                               JFileChooser fileChooser = (JFileChooser) component;
+                               if (fileChooser.getSelectedFile() != null) {
+                                       String path = fileChooser.getSelectedFile().getAbsolutePath();
+                                       this.appLayer.setPreference(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), path);
+                               }
+                       } else if (component instanceof JTextField) {
+                               JTextField textField = (JTextField) component;
+                               this.appLayer.setPreference(NDRPreferences.getCategory(key), NDRPreferences.getKey(key), textField.getText());
+                       }
+               }
+               this.setVisible(false);
+       }
+}