Created
July 27, 2016 00:47
-
-
Save DarkGuardsman/b86c542cc168d1c792a01a4d44dba229 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ConfigurationDialog extends ODialog | |
{ | |
private final Configuration config; | |
private final ObjectSwingMapper mapper; | |
private final FormPanel javaSettingsPanel = new FormPanel(); | |
private final FormPanel gameSettingsPanel = new FormPanel(); | |
private final FormPanel proxySettingsPanel = new FormPanel(); | |
private final FormPanel advancedPanel = new FormPanel(); | |
private final FormPanel generalSettingsPanel = new FormPanel(); | |
private final JPanel tabContainer = new JPanel(new BorderLayout()); | |
private final JTextField jvmPathText = new JTextField(); | |
private final JTextField jvmArgsText = new JTextField(); | |
private final JSpinner minMemorySpinner = new JSpinner(); | |
private final JSpinner maxMemorySpinner = new JSpinner(); | |
private final JSpinner permGenSpinner = new JSpinner(); | |
private final JSpinner widthSpinner = new JSpinner(); | |
private final JSpinner heightSpinner = new JSpinner(); | |
private final JCheckBox useProxyCheck = new JCheckBox(SharedLocale.tr("options.useProxyCheck")); | |
private final JTextField proxyHostText = new JTextField(); | |
private final JSpinner proxyPortText = new JSpinner(); | |
private final JTextField proxyUsernameText = new JTextField(); | |
private final JPasswordField proxyPasswordText = new JPasswordField(); | |
private final JTextField gameKeyText = new JTextField(); | |
private final LinedBoxPanel buttonsPanel = new LinedBoxPanel(true); | |
private final JButton okButton = new JButton(SharedLocale.tr("button.ok")); | |
private final JButton cancelButton = new JButton(SharedLocale.tr("button.cancel")); | |
private final JButton aboutButton = new JButton(SharedLocale.tr("options.about")); | |
private final JButton logButton = new JButton(SharedLocale.tr("options.launcherConsole")); | |
private final JTextField installFolder = new JTextField(); | |
/** | |
* Create a new configuration dialog. | |
* | |
* @param owner the window owner | |
* @param launcher the launcher | |
*/ | |
public ConfigurationDialog(Window owner, @NonNull Launcher launcher) | |
{ | |
super(owner); | |
this.config = launcher.getConfig(); | |
mapper = new ObjectSwingMapper(config); | |
setTitle(SharedLocale.tr("options.title")); | |
setDefaultCloseOperation(DISPOSE_ON_CLOSE); | |
setSize(new Dimension(400, 500)); | |
setLocationRelativeTo(owner); | |
initComponents(); | |
mapper.map(installFolder, "installFolder"); | |
mapper.map(jvmPathText, "jvmPath"); | |
mapper.map(jvmArgsText, "jvmArgs"); | |
mapper.map(minMemorySpinner, "minMemory"); | |
mapper.map(maxMemorySpinner, "maxMemory"); | |
mapper.map(permGenSpinner, "permGen"); | |
mapper.map(widthSpinner, "windowWidth"); | |
mapper.map(heightSpinner, "widowHeight"); | |
mapper.map(useProxyCheck, "proxyEnabled"); | |
mapper.map(proxyHostText, "proxyHost"); | |
mapper.map(proxyPortText, "proxyPort"); | |
mapper.map(proxyUsernameText, "proxyUsername"); | |
mapper.map(proxyPasswordText, "proxyPassword"); | |
mapper.map(gameKeyText, "gameKey"); | |
mapper.copyFromObject(); | |
} | |
@Override | |
protected void initComponents() | |
{ | |
getRootPane().getContentPane().setLayout(new CardLayout()); | |
getRootPane().getContentPane().setBackground(LauncherFrame.secondaryColor); | |
JPanel mainPanel = new ODialogPanel(); | |
mainPanel.setBorder(new EmptyBorder(0, 0, 0, 0)); | |
mainPanel.setBackground(LauncherFrame.secondaryColor); | |
mainPanel.setLayout(new MigLayout("fill", "[]", "[][grow]")); | |
//Load header parts | |
JPanel header = initHeader(); | |
//Load center panel | |
JPanel body = initBody(); | |
mainPanel.add(header, "cell 0 0, growx, span"); | |
mainPanel.add(body, "cell 0 1"); | |
getRootPane().getContentPane().add(mainPanel); | |
} | |
@Override | |
protected JPanel initBody() | |
{ | |
tabContainer.setOpaque(false); | |
generalSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.installFolder")), installFolder); | |
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.jvmPath")), jvmPathText); | |
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.jvmArguments")), jvmArgsText); | |
javaSettingsPanel.addRow(Box.createVerticalStrut(15)); | |
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.64BitJavaWarning"))); | |
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.minMemory")), minMemorySpinner); | |
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.maxMemory")), maxMemorySpinner); | |
javaSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.permGen")), permGenSpinner); | |
gameSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.windowWidth")), widthSpinner); | |
gameSettingsPanel.addRow(new JLabel(SharedLocale.tr("options.windowHeight")), heightSpinner); | |
proxySettingsPanel.addRow(useProxyCheck); | |
proxySettingsPanel.addRow(new JLabel(SharedLocale.tr("options.proxyHost")), proxyHostText); | |
proxySettingsPanel.addRow(new JLabel(SharedLocale.tr("options.proxyPort")), proxyPortText); | |
proxySettingsPanel.addRow(new JLabel(SharedLocale.tr("options.proxyUsername")), proxyUsernameText); | |
proxySettingsPanel.addRow(new JLabel(SharedLocale.tr("options.proxyPassword")), proxyPasswordText); | |
advancedPanel.addRow(new JLabel(SharedLocale.tr("options.gameKey")), gameKeyText); | |
buttonsPanel.addElement(logButton); | |
buttonsPanel.addElement(aboutButton); | |
buttonsPanel.addGlue(); | |
buttonsPanel.addElement(okButton); | |
buttonsPanel.addElement(cancelButton); | |
//SwingHelper.removeOpaqueness(javaSettingsPanel); | |
//SwingHelper.removeOpaqueness(gameSettingsPanel); | |
//SwingHelper.removeOpaqueness(proxySettingsPanel); | |
//SwingHelper.removeOpaqueness(advancedPanel); | |
//SwingHelper.removeOpaqueness(generalSettingsPanel); | |
JTabbedPane tabbedPane = new TabPanel(); | |
tabbedPane.setOpaque(true); | |
tabbedPane.setBackground(LauncherFrame.secondaryColor); | |
tabbedPane.addTab(SharedLocale.tr("options.generalTab"), SwingHelper.alignTabbedPane(generalSettingsPanel)); | |
tabbedPane.addTab(SharedLocale.tr("options.javaTab"), SwingHelper.alignTabbedPane(javaSettingsPanel)); | |
tabbedPane.addTab(SharedLocale.tr("options.minecraftTab"), SwingHelper.alignTabbedPane(gameSettingsPanel)); | |
tabbedPane.addTab(SharedLocale.tr("options.proxyTab"), SwingHelper.alignTabbedPane(proxySettingsPanel)); | |
tabbedPane.addTab(SharedLocale.tr("options.advancedTab"), SwingHelper.alignTabbedPane(advancedPanel)); | |
for(int i =0; i < 5; i++) | |
{ | |
tabbedPane.setBackgroundAt(i, LauncherFrame.primaryColor); | |
((JPanel)tabbedPane.getComponentAt(i)).setOpaque(true); | |
tabbedPane.getComponentAt(i).setBackground(LauncherFrame.primaryColor); | |
} | |
tabContainer.add(tabbedPane, BorderLayout.CENTER); | |
tabContainer.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); | |
JPanel panel = newPanel(); | |
panel.setLayout(new BorderLayout()); | |
panel.add(tabContainer, BorderLayout.CENTER); | |
panel.add(buttonsPanel, BorderLayout.SOUTH); | |
SwingHelper.equalWidth(okButton, cancelButton); | |
cancelButton.addActionListener(ActionListeners.dispose(this)); | |
aboutButton.addActionListener(e -> AboutDialog.showAboutDialog(ConfigurationDialog.this)); | |
okButton.addActionListener(e -> save()); | |
logButton.addActionListener(e -> ConsoleFrame.showMessages()); | |
return panel; | |
} | |
/** | |
* Save the configuration and close the dialog. | |
*/ | |
public void save() | |
{ | |
mapper.copyFromSwing(); | |
Persistence.commitAndForget(config); | |
removeListeners(); | |
dispose(); | |
} | |
private class TabPanel extends JTabbedPane | |
{ | |
@Override | |
public void paint(Graphics g) | |
{ | |
super.paint(g); | |
} | |
} | |
private class TabUI extends BasicTabbedPaneUI | |
{ | |
@Override | |
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected ) { | |
g.setColor(LauncherFrame.secondaryColor); | |
switch(tabPlacement) { | |
case LEFT: | |
g.fillRect(x+1, y+1, w-1, h-3); | |
break; | |
case RIGHT: | |
g.fillRect(x, y+1, w-2, h-3); | |
break; | |
case BOTTOM: | |
g.fillRect(x+1, y, w-3, h-1); | |
break; | |
case TOP: | |
default: | |
g.fillRect(x+1, y+1, w-3, h-1); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment