2015-06-02 17:25:06 +02:00
|
|
|
package de.marcelkapfer.c.morseconverter.update;
|
|
|
|
|
|
|
|
/*
|
|
|
|
This is a Java application for converting writtenMorse and normal morse code.
|
|
|
|
Copyright (C) 2014-2015 Marcel Michael Kapfer
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Marcel Michael Kapfer
|
|
|
|
marcelmichaelkapfer@yahoo.co.nz
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
import de.marcelkapfer.c.morseconverter.Main;
|
|
|
|
|
|
|
|
import javax.swing.*;
|
|
|
|
import java.awt.event.*;
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.URISyntaxException;
|
2015-06-09 10:56:50 +02:00
|
|
|
import java.util.ResourceBundle;
|
2015-06-02 17:25:06 +02:00
|
|
|
|
|
|
|
public class UpdateDialog extends JDialog {
|
|
|
|
private JPanel contentPane;
|
2015-07-13 17:24:25 +02:00
|
|
|
public JButton buttonOK;
|
|
|
|
public JButton buttonCancel;
|
|
|
|
public JLabel updateDialogQuestion;
|
|
|
|
public JLabel updateDialogNewVersion;
|
2015-06-09 10:56:50 +02:00
|
|
|
private ResourceBundle resourceBundle = ResourceBundle.getBundle("de.marcelkapfer.c.morseconverter.text");
|
2015-06-02 17:25:06 +02:00
|
|
|
|
|
|
|
public UpdateDialog() {
|
|
|
|
setContentPane(contentPane);
|
|
|
|
setModal(true);
|
|
|
|
getRootPane().setDefaultButton(buttonOK);
|
2015-07-13 17:24:25 +02:00
|
|
|
if(Main.currentVersion == Main.latestVersion){
|
|
|
|
buttonOK.setVisible(false);
|
|
|
|
buttonCancel.setText(resourceBundle.getString("updateDialogClose"));
|
|
|
|
updateDialogNewVersion.setVisible(false);
|
|
|
|
updateDialogQuestion.setText(resourceBundle.getString("updateDialogUpToDateText"));
|
|
|
|
}
|
2015-06-02 17:25:06 +02:00
|
|
|
buttonOK.addActionListener(new ActionListener() {
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
onOK();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
buttonCancel.addActionListener(new ActionListener() {
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
onCancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// call onCancel() when cross is clicked
|
|
|
|
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
|
|
|
addWindowListener(new WindowAdapter() {
|
|
|
|
public void windowClosing(WindowEvent e) {
|
|
|
|
onCancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// call onCancel() on ESCAPE
|
|
|
|
contentPane.registerKeyboardAction(new ActionListener() {
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
onCancel();
|
|
|
|
}
|
|
|
|
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onOK() {
|
|
|
|
// add your code here
|
|
|
|
try {
|
|
|
|
String path = Main.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
|
2015-07-30 15:50:40 +02:00
|
|
|
path = path.substring(0, path.lastIndexOf("/"));
|
2015-07-13 17:24:25 +02:00
|
|
|
if(Update.isConnected("http://lab.marcel-kapfer.de/writtenmorse/desktop/morseconverter.jar")){
|
|
|
|
if(Update.update(path + File.separator, "morseconverter.jar")){
|
2015-06-09 10:56:50 +02:00
|
|
|
JOptionPane.showMessageDialog(null, resourceBundle.getString("update-successful"));
|
2015-06-02 17:25:06 +02:00
|
|
|
} else {
|
2015-06-09 10:56:50 +02:00
|
|
|
JOptionPane.showMessageDialog(null, resourceBundle.getString("update-not-successful"));
|
2015-06-02 17:25:06 +02:00
|
|
|
}
|
|
|
|
} else {
|
2015-06-09 10:56:50 +02:00
|
|
|
JOptionPane.showMessageDialog(null, resourceBundle.getString("update-no-connection"));
|
2015-06-02 17:25:06 +02:00
|
|
|
}
|
|
|
|
} catch (URISyntaxException e) {
|
|
|
|
e.printStackTrace();
|
2015-06-09 10:56:50 +02:00
|
|
|
JOptionPane.showMessageDialog(null, resourceBundle.getString("update-error"));
|
2015-06-02 17:25:06 +02:00
|
|
|
}
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void onCancel() {
|
|
|
|
// add your code here if necessary
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
UpdateDialog dialog = new UpdateDialog();
|
|
|
|
dialog.pack();
|
|
|
|
dialog.setVisible(true);
|
|
|
|
}
|
2015-07-13 17:24:25 +02:00
|
|
|
|
2015-06-02 17:25:06 +02:00
|
|
|
}
|