| 1 |
package net.oni2.aeinstaller.gui.settings; |
| 2 |
|
| 3 |
import java.awt.Dimension; |
| 4 |
import java.awt.event.ActionEvent; |
| 5 |
import java.awt.event.KeyEvent; |
| 6 |
import java.util.ResourceBundle; |
| 7 |
|
| 8 |
import javax.swing.AbstractAction; |
| 9 |
import javax.swing.JComboBox; |
| 10 |
import javax.swing.JComponent; |
| 11 |
import javax.swing.JFrame; |
| 12 |
import javax.swing.JOptionPane; |
| 13 |
import javax.swing.KeyStroke; |
| 14 |
import javax.swing.SwingUtilities; |
| 15 |
import javax.swing.UIManager; |
| 16 |
|
| 17 |
import net.oni2.aeinstaller.backend.Settings; |
| 18 |
|
| 19 |
import org.javabuilders.BuildResult; |
| 20 |
import org.javabuilders.swing.SwingJavaBuilder; |
| 21 |
|
| 22 |
/** |
| 23 |
* @author Christian Illy |
| 24 |
*/ |
| 25 |
public class SettingsDialog extends JFrame { |
| 26 |
private static final long serialVersionUID = -5719515325671846620L; |
| 27 |
|
| 28 |
private ResourceBundle bundle = ResourceBundle.getBundle(getClass() |
| 29 |
.getName()); |
| 30 |
@SuppressWarnings("unused") |
| 31 |
private BuildResult result = SwingJavaBuilder.build(this, bundle); |
| 32 |
|
| 33 |
private static SettingsDialog openWindow = null; |
| 34 |
|
| 35 |
private JComboBox cmbLaF; |
| 36 |
private LaFComboModel laFModel; |
| 37 |
|
| 38 |
/** |
| 39 |
* Open the Settings dialog if not currently opened or brings the existing |
| 40 |
* one to front |
| 41 |
*/ |
| 42 |
public static void openWindow() { |
| 43 |
if (openWindow != null) { |
| 44 |
SwingUtilities.invokeLater(new Runnable() { |
| 45 |
|
| 46 |
@Override |
| 47 |
public void run() { |
| 48 |
openWindow.toFront(); |
| 49 |
openWindow.repaint(); |
| 50 |
} |
| 51 |
}); |
| 52 |
} else { |
| 53 |
new SettingsDialog().setVisible(true); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
private SettingsDialog() { |
| 58 |
openWindow = this; |
| 59 |
setMinimumSize(new Dimension(500, (int) getSize().getHeight() + 0)); |
| 60 |
|
| 61 |
AbstractAction closeAction = new AbstractAction() { |
| 62 |
|
| 63 |
private static final long serialVersionUID = 1L; |
| 64 |
|
| 65 |
public void actionPerformed(ActionEvent arg0) { |
| 66 |
dispose(); |
| 67 |
} |
| 68 |
}; |
| 69 |
KeyStroke ksCtrlW = KeyStroke |
| 70 |
.getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK); |
| 71 |
getRootPane() |
| 72 |
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) |
| 73 |
.put(ksCtrlW, "close"); |
| 74 |
getRootPane().getActionMap().put("close", closeAction); |
| 75 |
|
| 76 |
initValues(); |
| 77 |
} |
| 78 |
|
| 79 |
private void initValues() { |
| 80 |
Settings set = Settings.getInstance(); |
| 81 |
|
| 82 |
laFModel = new LaFComboModel(); |
| 83 |
cmbLaF.setModel(laFModel); |
| 84 |
} |
| 85 |
|
| 86 |
@SuppressWarnings("unused") |
| 87 |
private void close() { |
| 88 |
openWindow = null; |
| 89 |
} |
| 90 |
|
| 91 |
@SuppressWarnings("unused") |
| 92 |
private boolean save() { |
| 93 |
Settings set = Settings.getInstance(); |
| 94 |
|
| 95 |
String oldLaf = set.get("lookandfeel", |
| 96 |
UIManager.getSystemLookAndFeelClassName()); |
| 97 |
String newLaf = laFModel.getSelectedClassName(); |
| 98 |
|
| 99 |
if (!newLaf.equals(oldLaf)) { |
| 100 |
set.put("lookandfeel", newLaf); |
| 101 |
JOptionPane.showMessageDialog(this, |
| 102 |
bundle.getString("newLaF.text"), |
| 103 |
bundle.getString("newLaF.title"), |
| 104 |
JOptionPane.INFORMATION_MESSAGE); |
| 105 |
} |
| 106 |
|
| 107 |
return true; |
| 108 |
} |
| 109 |
|
| 110 |
} |