This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
morse-converter/src/de/marcelkapfer/c/morseconverter/update/UpdateDialog.java

106 lines
3.6 KiB
Java
Raw Normal View History

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;
import java.nio.file.Path;
import java.nio.file.Paths;
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;
private JButton buttonOK;
private JButton buttonCancel;
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);
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();
path = path.substring(0, path.lastIndexOf(File.separator));
if(Update.isConnected("http://c2/LAB/java/morseconverter/morseconverter-1.jar")){
if(Update.update(path + File.separator, "morseconverter-1.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);
}
}