| 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.JDialog; |
| 12 |
import javax.swing.JOptionPane; |
| 13 |
import javax.swing.KeyStroke; |
| 14 |
import javax.swing.UIManager; |
| 15 |
|
| 16 |
import net.oni2.aeinstaller.backend.Settings; |
| 17 |
|
| 18 |
import org.javabuilders.BuildResult; |
| 19 |
import org.javabuilders.swing.SwingJavaBuilder; |
| 20 |
|
| 21 |
/** |
| 22 |
* @author Christian Illy |
| 23 |
*/ |
| 24 |
public class SettingsDialog extends JDialog { |
| 25 |
private static final long serialVersionUID = -5719515325671846620L; |
| 26 |
|
| 27 |
private ResourceBundle bundle = ResourceBundle.getBundle(getClass() |
| 28 |
.getName()); |
| 29 |
@SuppressWarnings("unused") |
| 30 |
private BuildResult result = SwingJavaBuilder.build(this, bundle); |
| 31 |
|
| 32 |
private JComboBox cmbLaF; |
| 33 |
private LaFComboModel laFModel; |
| 34 |
|
| 35 |
/** |
| 36 |
* Open the settings |
| 37 |
*/ |
| 38 |
public SettingsDialog() { |
| 39 |
setMinimumSize(new Dimension(500, (int) getSize().getHeight() + 0)); |
| 40 |
|
| 41 |
AbstractAction closeAction = new AbstractAction() { |
| 42 |
|
| 43 |
private static final long serialVersionUID = 1L; |
| 44 |
|
| 45 |
public void actionPerformed(ActionEvent arg0) { |
| 46 |
dispose(); |
| 47 |
} |
| 48 |
}; |
| 49 |
KeyStroke ksCtrlW = KeyStroke |
| 50 |
.getKeyStroke('W', KeyEvent.CTRL_DOWN_MASK); |
| 51 |
getRootPane() |
| 52 |
.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) |
| 53 |
.put(ksCtrlW, "close"); |
| 54 |
getRootPane().getActionMap().put("close", closeAction); |
| 55 |
|
| 56 |
initValues(); |
| 57 |
} |
| 58 |
|
| 59 |
private void initValues() { |
| 60 |
Settings set = Settings.getInstance(); |
| 61 |
|
| 62 |
laFModel = new LaFComboModel(); |
| 63 |
cmbLaF.setModel(laFModel); |
| 64 |
} |
| 65 |
|
| 66 |
@SuppressWarnings("unused") |
| 67 |
private boolean save() { |
| 68 |
Settings set = Settings.getInstance(); |
| 69 |
|
| 70 |
String oldLaf = set.get("lookandfeel", |
| 71 |
UIManager.getLookAndFeel().getClass().getName()); |
| 72 |
String newLaf = laFModel.getSelectedClassName(); |
| 73 |
|
| 74 |
if (!newLaf.equals(oldLaf)) { |
| 75 |
set.put("lookandfeel", newLaf); |
| 76 |
JOptionPane.showMessageDialog(this, |
| 77 |
bundle.getString("newLaF.text"), |
| 78 |
bundle.getString("newLaF.title"), |
| 79 |
JOptionPane.INFORMATION_MESSAGE); |
| 80 |
} |
| 81 |
|
| 82 |
return true; |
| 83 |
} |
| 84 |
|
| 85 |
} |