Redirect software updater download button to website
Shh, ignore the easter-eggs, you saw nothing.
This commit is contained in:
parent
79bae3470d
commit
94b9cedee6
@ -2,6 +2,7 @@ package net.sf.openrocket.communication;
|
||||
|
||||
import net.sf.openrocket.gui.util.SwingPreferences;
|
||||
import net.sf.openrocket.startup.Application;
|
||||
import net.sf.openrocket.util.BuildProperties;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -14,8 +15,9 @@ import java.util.TreeMap;
|
||||
* @author Sibo Van Gool <sibo.vangool@hotmail.com>
|
||||
*/
|
||||
public class AssetHandler {
|
||||
private static final Map<String, UpdatePlatform[]> mapExtensionToPlatform = new HashMap<>(); // Map file extensions to operating platform
|
||||
private static final Map<UpdatePlatform, String> mapPlatformToName = new HashMap<>(); // Map operating platform to a name
|
||||
private static final Map<String, UpdatePlatform[]> mapExtensionToPlatform = new HashMap<>(); // Map file extensions to operating platform
|
||||
private static final Map<UpdatePlatform[], String> mapPlatformToURL= new HashMap<>(); // Map operating platform to a URL to download the release for that OS
|
||||
private static final Map<UpdatePlatform, String> mapPlatformToName = new HashMap<>(); // Map operating platform to a name
|
||||
|
||||
public enum UpdatePlatform {
|
||||
WINDOWS,
|
||||
@ -32,6 +34,12 @@ public class AssetHandler {
|
||||
mapExtensionToPlatform.put(".sh", new UpdatePlatform[] {UpdatePlatform.LINUX, UpdatePlatform.UNIX});
|
||||
mapExtensionToPlatform.put(".jar", new UpdatePlatform[] {UpdatePlatform.JAR});
|
||||
|
||||
String baseURL = "https://openrocket.info/downloads.html?vers=%s#content-";
|
||||
mapPlatformToURL.put(new UpdatePlatform[] {UpdatePlatform.MAC_OS}, baseURL + "macOS");
|
||||
mapPlatformToURL.put(new UpdatePlatform[] {UpdatePlatform.WINDOWS}, baseURL + "Windows");
|
||||
mapPlatformToURL.put(new UpdatePlatform[] {UpdatePlatform.LINUX, UpdatePlatform.UNIX}, baseURL + "Linux");
|
||||
mapPlatformToURL.put(new UpdatePlatform[] {UpdatePlatform.JAR}, baseURL + "JAR");
|
||||
|
||||
mapPlatformToName.put(UpdatePlatform.MAC_OS, "macOS");
|
||||
mapPlatformToName.put(UpdatePlatform.WINDOWS, "Windows");
|
||||
mapPlatformToName.put(UpdatePlatform.LINUX, "Linux");
|
||||
@ -43,7 +51,7 @@ public class AssetHandler {
|
||||
* Maps a list of asset URLs to their respective operating platform name.
|
||||
* E.g. "https://github.com/openrocket/openrocket/releases/download/release-15.03/OpenRocket-15.03.dmg" is mapped a
|
||||
* map element with "macOS" as key and the url as value.
|
||||
* @param urls list of asset URLs
|
||||
* @param urls list of asset URLs from the GitHub release object
|
||||
* @return map with as key the operating platform name and as value the corresponding asset URL
|
||||
*/
|
||||
public static Map<UpdatePlatform, String> mapURLToPlatform(List<String> urls) {
|
||||
@ -60,6 +68,23 @@ public class AssetHandler {
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the URL to download the installer for the given platform.
|
||||
* @param platform platform to get the installer URL for
|
||||
* @param version version of the installer to download
|
||||
* @return URL to download the installer for the given platform
|
||||
*/
|
||||
public static String getInstallerURLForPlatform(UpdatePlatform platform, String version) {
|
||||
for (UpdatePlatform[] platforms : mapPlatformToURL.keySet()) {
|
||||
for (UpdatePlatform p : platforms) {
|
||||
if (p == platform) {
|
||||
return String.format(mapPlatformToURL.get(platforms), version);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the operating platform based on the operating system that the user is running on, or the value
|
||||
* stored in preferences.
|
||||
|
@ -1,10 +1,15 @@
|
||||
package net.sf.openrocket.gui.configdialog;
|
||||
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
@ -76,17 +81,41 @@ public class RocketConfig extends RocketComponentConfig {
|
||||
|
||||
/**
|
||||
* Little method that adds a fun easter-egg to the rocket config dialog.
|
||||
* If the name of the rocket is "Apollo 13", then a popup will appear saying
|
||||
* "Houston, we have a problem."
|
||||
*/
|
||||
private void addEasterEgg() {
|
||||
okButton.addActionListener(new ActionListener() {
|
||||
componentNameField.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (componentNameField.getText().equals("Apollo 13")) {
|
||||
JOptionPane.showMessageDialog(RocketConfig.this,
|
||||
"Houston, we have a problem.\n\nJust kidding, have fun building your 'Apollo 13' rocket!",
|
||||
"Oh oh...", JOptionPane.INFORMATION_MESSAGE);
|
||||
public void keyTyped(KeyEvent e) {
|
||||
String text = componentNameField.getText() + e.getKeyChar();
|
||||
String msg = null;
|
||||
String title = null;
|
||||
switch (text) {
|
||||
case "SA-508":
|
||||
msg = "Houston, we have a problem.\n\nJust kidding, have fun building your 'Apollo 13' rocket!";
|
||||
title = "Oh oh...";
|
||||
break;
|
||||
case "SA-506":
|
||||
msg = "One small step for a rocket, one giant leap for rocketkind.";
|
||||
title = "Or was that not the quote?";
|
||||
break;
|
||||
case "Vega":
|
||||
msg = "Viva las Vega!";
|
||||
title = "Vega, Ready for Launch and Laughs!";
|
||||
break;
|
||||
case "Ariane 5":
|
||||
msg = "Non, je ne regrette rien\u2026 except for that one overflow error\u2026";
|
||||
title = "Happens to the best of us";
|
||||
break;
|
||||
}
|
||||
if (msg != null) {
|
||||
JOptionPane optionPane = new JOptionPane(msg, JOptionPane.INFORMATION_MESSAGE);
|
||||
JDialog dialog = optionPane.createDialog(RocketConfig.this, title);
|
||||
// Make sure title doesn't get cut off
|
||||
FontMetrics fontMetrics = Toolkit.getDefaultToolkit().getFontMetrics(dialog.getFont());
|
||||
int width = Math.max(dialog.getPreferredSize().width, fontMetrics.stringWidth(title) + 100);
|
||||
int height = dialog.getPreferredSize().height;
|
||||
dialog.setSize(new Dimension(width, height));
|
||||
dialog.setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -161,7 +161,6 @@ public class UpdateInfoDialog extends JDialog {
|
||||
comboBox = new JComboBox<>(mappedAssets.keySet().toArray(new UpdatePlatform[0]));
|
||||
comboBox.setRenderer(new CustomComboBoxRenderer());
|
||||
UpdatePlatform platform = AssetHandler.getUpdatePlatform();
|
||||
// TODO: check select null?
|
||||
comboBox.setSelectedItem(platform);
|
||||
comboBox.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@ -178,7 +177,9 @@ public class UpdateInfoDialog extends JDialog {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (mappedAssets == null) return;
|
||||
String url = mappedAssets.get((UpdatePlatform) comboBox.getSelectedItem());
|
||||
String url = AssetHandler.getInstallerURLForPlatform((UpdatePlatform) comboBox.getSelectedItem(),
|
||||
release.getReleaseName());
|
||||
if (url == null) return;
|
||||
Desktop desktop = Desktop.getDesktop();
|
||||
try {
|
||||
desktop.browse(new URI(url));
|
||||
|
@ -1,14 +1,17 @@
|
||||
package net.sf.openrocket.gui.dialogs.preferences;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.LayoutManager;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSpinner;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
@ -72,6 +75,7 @@ public class LaunchPreferencesPanel extends PreferencesPanel {
|
||||
spin = new JSpinner(m.getSpinnerModel());
|
||||
spin.setEditor(new SpinnerEditor(spin));
|
||||
spin.setToolTipText(tip);
|
||||
addEasterEgg(spin);
|
||||
sub.add(spin, "w 65lp!");
|
||||
|
||||
unit = new UnitSelector(m);
|
||||
@ -456,4 +460,23 @@ public class LaunchPreferencesPanel extends PreferencesPanel {
|
||||
return trans.get("simedtdlg.IntensityDesc.Extreme");
|
||||
}
|
||||
|
||||
/**
|
||||
* Shh, don't tell anyone about this easter-egg. (displays a fun quote when the text of the spinner equals 42)
|
||||
* @param spinner the magic spinner!
|
||||
*/
|
||||
private void addEasterEgg(JSpinner spinner) {
|
||||
JTextField textField = ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField();
|
||||
textField.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
String text = textField.getText() + e.getKeyChar();
|
||||
if (text.equals("42")) {
|
||||
JOptionPane.showMessageDialog(LaunchPreferencesPanel.this,
|
||||
"The answer to the ultimate question of life, the universe, and everything.",
|
||||
"42", JOptionPane.INFORMATION_MESSAGE);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user