use of net.technicpack.ui.listitems.javaversion.JavaVersionItem in project LauncherV3 by TechnicPack.
the class OptionsDialog method selectOtherVersion.
protected void selectOtherVersion() {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
final String osJavaName = new File(OperatingSystem.getJavaDir()).getName();
chooser.setFileFilter(new FileFilter() {
@Override
public boolean accept(File f) {
if (f.isDirectory())
return true;
return (f.getName().equals(osJavaName));
}
@Override
public String getDescription() {
return resources.getString("launcheroptions.java.filter", osJavaName);
}
});
int result = chooser.showOpenDialog(this);
if (result == JFileChooser.APPROVE_OPTION) {
if (chooser.getSelectedFile() == null || !chooser.getSelectedFile().exists() || !chooser.getSelectedFile().canExecute()) {
JOptionPane.showMessageDialog(this, resources.getString("launcheroptions.java.badfile"));
return;
}
FileBasedJavaVersion chosenJava = new FileBasedJavaVersion(chooser.getSelectedFile());
if (!chosenJava.verify()) {
JOptionPane.showMessageDialog(this, resources.getString("launcheroptions.java.badfile"));
return;
}
IJavaVersion existingVersion = javaVersions.getVersion(chosenJava.getVersionNumber(), chosenJava.is64Bit());
if (existingVersion.getJavaPath() != null) {
JOptionPane.showMessageDialog(this, resources.getString("launcheroptions.java.versionexists"));
return;
}
fileJavaSource.addVersion(chosenJava);
javaVersions.addVersion(chosenJava);
javaVersions.selectVersion(chosenJava.getVersionNumber(), chosenJava.is64Bit());
JavaVersionItem item = new JavaVersionItem(chosenJava, resources);
versionSelect.addItem(item);
versionSelect.setSelectedItem(item);
settings.setJavaVersion(chosenJava.getVersionNumber());
settings.setJavaBitness(chosenJava.is64Bit());
settings.save();
}
}
use of net.technicpack.ui.listitems.javaversion.JavaVersionItem in project LauncherV3 by TechnicPack.
the class OptionsDialog method initControlValues.
private void initControlValues() {
javaArgs.getDocument().removeDocumentListener(javaArgsListener);
javaArgs.setText(settings.getJavaArgs());
javaArgs.getDocument().addDocumentListener(javaArgsListener);
wrapperCommand.getDocument().removeDocumentListener(wrapperCommandListener);
wrapperCommand.setText(settings.getWrapperCommand());
wrapperCommand.getDocument().addDocumentListener(wrapperCommandListener);
installField.setText(settings.getTechnicRoot().getAbsolutePath());
clientId.setText(settings.getClientId());
for (ActionListener listener : showConsole.getActionListeners()) showConsole.removeActionListener(listener);
showConsole.setSelected(settings.getShowConsole());
showConsole.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeShowConsole();
}
});
for (ActionListener listener : askFirstBox.getActionListeners()) askFirstBox.removeActionListener(listener);
askFirstBox.setSelected(!settings.shouldAutoAcceptModpackRequirements());
askFirstBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeAskFirst();
}
});
for (ActionListener listener : useMojangJava.getActionListeners()) useMojangJava.removeActionListener(listener);
useMojangJava.setSelected(settings.shouldUseMojangJava());
useMojangJava.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeUseMojangJava();
}
});
for (ActionListener listener : launchToModpacks.getActionListeners()) launchToModpacks.removeActionListener(listener);
launchToModpacks.setSelected(settings.getLaunchToModpacks());
launchToModpacks.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeLaunchToModpacks();
}
});
for (ActionListener listener : versionSelect.getActionListeners()) versionSelect.removeActionListener(listener);
versionSelect.removeAllItems();
versionSelect.addItem(new DefaultVersionItem(javaVersions.getVersion(null, true), resources));
IJavaVersion best64Bit = javaVersions.getBest64BitVersion();
if (best64Bit != null)
versionSelect.addItem(new Best64BitVersionItem(javaVersions.getVersion("64bit", true), resources));
for (IJavaVersion version : javaVersions.getVersions()) {
versionSelect.addItem(new JavaVersionItem(version, resources));
}
String settingsVersion = settings.getJavaVersion();
boolean settingsBitness = settings.getJavaBitness();
if (settingsVersion == null || settingsVersion.isEmpty() || settingsVersion.equals("default"))
versionSelect.setSelectedIndex(0);
else if (settingsVersion.equals("64bit"))
versionSelect.setSelectedIndex(1);
else {
for (int i = 2; i < versionSelect.getItemCount(); i++) {
if (((JavaVersionItem) versionSelect.getItemAt(i)).getVersionNumber().equals(settingsVersion) && ((JavaVersionItem) versionSelect.getItemAt(i)).is64Bit() == settingsBitness) {
versionSelect.setSelectedIndex(i);
break;
}
}
}
versionSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeJavaVersion();
}
});
rebuildMemoryList();
for (ActionListener listener : streamSelect.getActionListeners()) {
streamSelect.removeActionListener(listener);
}
streamSelect.removeAllItems();
streamSelect.addItem(new StreamItem(resources.getString("launcheroptions.build.stable"), "stable"));
streamSelect.addItem(new StreamItem(resources.getString("launcheroptions.build.beta"), "beta"));
streamSelect.setSelectedIndex((settings.getBuildStream().equals("beta")) ? 1 : 0);
streamSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeStream();
}
});
for (ActionListener listener : launchSelect.getActionListeners()) launchSelect.removeActionListener(listener);
launchSelect.removeAllItems();
launchSelect.addItem(new OnLaunchItem(resources.getString("launcheroptions.packlaunch.hide"), LaunchAction.HIDE));
launchSelect.addItem(new OnLaunchItem(resources.getString("launcheroptions.packlaunch.close"), LaunchAction.CLOSE));
launchSelect.addItem(new OnLaunchItem(resources.getString("launcheroptions.packlaunch.nothing"), LaunchAction.NOTHING));
switch(settings.getLaunchAction()) {
case HIDE:
launchSelect.setSelectedIndex(0);
break;
case CLOSE:
launchSelect.setSelectedIndex(1);
break;
case NOTHING:
launchSelect.setSelectedIndex(2);
break;
default:
launchSelect.setSelectedIndex(0);
}
launchSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeLaunchAction();
}
});
for (ActionListener listener : langSelect.getActionListeners()) langSelect.removeActionListener(listener);
langSelect.removeAllItems();
String defaultLocaleText = resources.getString("launcheroptions.language.default");
if (!resources.isDefaultLocaleSupported()) {
defaultLocaleText = defaultLocaleText.concat(" (" + resources.getString("launcheroptions.language.unavailable") + ")");
}
langSelect.setRenderer(new LanguageCellRenderer(resources, null, langSelect.getBackground(), langSelect.getForeground()));
langSelect.addItem(new LanguageItem(ResourceLoader.DEFAULT_LOCALE, defaultLocaleText, resources));
for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
langSelect.addItem(new LanguageItem(resources.getCodeFromLocale(LauncherMain.supportedLanguages[i]), LauncherMain.supportedLanguages[i].getDisplayName(LauncherMain.supportedLanguages[i]), resources.getVariant(LauncherMain.supportedLanguages[i])));
}
if (!settings.getLanguageCode().equalsIgnoreCase(ResourceLoader.DEFAULT_LOCALE)) {
Locale loc = resources.getLocaleFromCode(settings.getLanguageCode());
for (int i = 0; i < LauncherMain.supportedLanguages.length; i++) {
if (loc.equals(LauncherMain.supportedLanguages[i])) {
langSelect.setSelectedIndex(i + 1);
break;
}
}
}
langSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeLanguage();
}
});
widthInput.getDocument().removeDocumentListener(dimensionListener);
heightInput.getDocument().removeDocumentListener(dimensionListener);
int width = settings.getCustomWidth();
int height = settings.getCustomHeight();
width = (width < 1) ? 800 : width;
height = (height < 1) ? 600 : height;
widthInput.setText(Integer.toString(width));
heightInput.setText(Integer.toString(height));
widthInput.getDocument().addDocumentListener(dimensionListener);
heightInput.getDocument().addDocumentListener(dimensionListener);
for (ActionListener listener : windowSelect.getActionListeners()) {
windowSelect.removeActionListener(listener);
}
windowSelect.removeAllItems();
windowSelect.addItem(resources.getString("launcheroptions.video.windowSize.default"));
windowSelect.addItem(resources.getString("launcheroptions.video.windowSize.fullscreen"));
windowSelect.addItem(resources.getString("launcheroptions.video.windowSize.custom"));
switch(settings.getLaunchWindowType()) {
case DEFAULT:
windowSelect.setSelectedIndex(0);
break;
case FULLSCREEN:
windowSelect.setSelectedIndex(1);
break;
case CUSTOM:
windowSelect.setSelectedIndex(2);
break;
}
windowSelect.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeWindowType();
}
});
updateDimensionsEnabled();
for (ActionListener listener : useStencil.getActionListeners()) {
useStencil.removeActionListener(listener);
}
useStencil.removeAllItems();
useStencil.addItem(resources.getString("launcheroptions.video.stencil.enabled"));
useStencil.addItem(resources.getString("launcheroptions.video.stencil.disabled"));
if (settings.shouldUseStencilBuffer())
useStencil.setSelectedIndex(0);
else
useStencil.setSelectedIndex(1);
useStencil.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
changeEnableStencil();
}
});
}
Aggregations