From d802881331f7f973d214a9b27912663814797fa7 Mon Sep 17 00:00:00 2001 From: AterAnimAvis Date: Fri, 9 Feb 2024 16:06:57 +0000 Subject: [PATCH] Fix Installer when using Nimbus LookAndFeel (#15) Fixes #14 --- .../installer/ui/InstallerPanel.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/main/java/net/minecraftforge/installer/ui/InstallerPanel.java b/src/main/java/net/minecraftforge/installer/ui/InstallerPanel.java index e8ef101..054fce0 100644 --- a/src/main/java/net/minecraftforge/installer/ui/InstallerPanel.java +++ b/src/main/java/net/minecraftforge/installer/ui/InstallerPanel.java @@ -258,7 +258,7 @@ private void updateFilePath() Action action = actions.get(choiceButtonGroup.getSelection().getActionCommand()).apply(null); TargetValidator.ValidationResult valid = action.getTargetValidator().validate(targetDir); - if (profile.getMirror() != null) + if (profile.getMirror() != null && profile.getMirror().isAdvertised()) { sponsorButton.setText(action.getSponsorMessage()); sponsorButton.setToolTipText(profile.getMirror().getHomepage()); @@ -304,22 +304,13 @@ public void run(ProgressCallback monitor) languageBox.setSelectedItem(known.stream().filter(locate -> locate.locale.equals(current)).findFirst().orElse(known.get(0))); languageBox.addActionListener(e -> TRANSLATIONS.setLocale(((L10nManager.LocaleSelection)languageBox.getSelectedItem()).locale, true)); - JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[] { - TRANSLATIONS.button("installer.button.proceed"), TRANSLATIONS.button("installer.button.cancel"), languageBox - }); - - // Attempt to change the OK button to a Proceed button - // Use index 1 (the buttons panel) as 0 is this panel - final JPanel buttonPanel = (JPanel) optionPane.getComponents()[1]; - final List buttons = Arrays.stream(buttonPanel.getComponents()) - .filter(comp -> comp instanceof JButton) - .map(JButton.class::cast) - .collect(Collectors.toList()); - if (buttons.size() == 2) { - proceedButton = Optional.of(buttons.get(0)); - buttons.get(0).addActionListener(e -> optionPane.setValue(JOptionPane.OK_OPTION)); - buttons.get(1).addActionListener(e -> optionPane.setValue(JOptionPane.OK_CANCEL_OPTION)); - } + JButton proceedButton = TRANSLATIONS.button("installer.button.proceed"); + JButton cancelButton = TRANSLATIONS.button("installer.button.cancel"); + JOptionPane optionPane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, new Object[] { proceedButton, cancelButton, languageBox }); + + proceedButton.addActionListener(e -> optionPane.setValue(JOptionPane.OK_OPTION)); + cancelButton.addActionListener(e -> optionPane.setValue(JOptionPane.OK_CANCEL_OPTION)); + this.proceedButton = Optional.of(proceedButton); dialog = optionPane.createDialog(""); TRANSLATIONS.translate(dialog, new TranslationTarget<>(Dialog::setTitle), "installer.window.title", profile.getProfile());