2015-05-31 23:21:32 +02:00
|
|
|
package de.marcelkapfer.c.morseconverter;
|
|
|
|
|
|
|
|
/*
|
|
|
|
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.engine.DecodeNormalMorseManager;
|
|
|
|
import de.marcelkapfer.c.morseconverter.engine.DecodeWrittenMorseManager;
|
|
|
|
import de.marcelkapfer.c.morseconverter.engine.EncodeNormalMorseManager;
|
|
|
|
import de.marcelkapfer.c.morseconverter.engine.EncodeWrittenMorseManager;
|
|
|
|
import de.marcelkapfer.c.morseconverter.intelligentCodeRecognization.NormalMorseCodeRecognization;
|
|
|
|
import de.marcelkapfer.c.morseconverter.intelligentCodeRecognization.WrittenMorseCodeRecognization;
|
2015-06-02 17:25:06 +02:00
|
|
|
import de.marcelkapfer.c.morseconverter.update.Update;
|
|
|
|
import de.marcelkapfer.c.morseconverter.update.UpdateDialog;
|
2015-05-31 23:21:32 +02:00
|
|
|
|
|
|
|
import javax.swing.*;
|
2015-06-02 17:25:06 +02:00
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
import java.awt.event.ActionListener;
|
2015-05-31 23:21:32 +02:00
|
|
|
import java.awt.event.KeyAdapter;
|
|
|
|
import java.awt.event.KeyEvent;
|
2015-06-09 10:56:50 +02:00
|
|
|
import java.util.ResourceBundle;
|
2015-05-31 23:21:32 +02:00
|
|
|
|
|
|
|
public class Main extends JFrame {
|
|
|
|
|
2015-06-01 23:34:04 +02:00
|
|
|
// Version numbers for update check
|
2015-06-02 17:25:06 +02:00
|
|
|
public static final int currentVersion = 200;
|
|
|
|
public int latestVersion = currentVersion;
|
2015-06-01 23:34:04 +02:00
|
|
|
|
2015-06-09 10:56:50 +02:00
|
|
|
public static ResourceBundle resourceBundle = ResourceBundle.getBundle("de.marcelkapfer.c.morseconverter.text");
|
2015-05-31 23:21:32 +02:00
|
|
|
public JTabbedPane morseConverterPane;
|
|
|
|
private JPanel panel1;
|
|
|
|
private JTextArea inputAreaWrittenMorse;
|
|
|
|
private JTextArea outputAreaWrittenMorse;
|
|
|
|
private JTextArea inputAreaNormalMorse;
|
|
|
|
private JTextArea outputAreaNormalMorse;
|
2015-06-02 17:25:06 +02:00
|
|
|
private JButton updateDialogButton;
|
2015-05-31 23:21:32 +02:00
|
|
|
|
|
|
|
// Contains mainly listeners
|
|
|
|
public Main() {
|
|
|
|
// Listener for the writtenMorse input field
|
|
|
|
inputAreaWrittenMorse.addKeyListener(new KeyAdapter() {
|
|
|
|
@Override
|
|
|
|
public void keyReleased(KeyEvent e) {
|
|
|
|
instantWrittenMorseConvert();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// Listener for the normal Morse input field
|
|
|
|
inputAreaNormalMorse.addKeyListener(new KeyAdapter() {
|
|
|
|
@Override
|
|
|
|
public void keyReleased(KeyEvent e) {
|
|
|
|
instantNormalMorseConvert();
|
|
|
|
}
|
|
|
|
});
|
2015-06-01 23:34:04 +02:00
|
|
|
|
|
|
|
// Trying to read a file from a server
|
2015-06-02 17:25:06 +02:00
|
|
|
latestVersion = Update.getLatestVersion("http://c2/LAB/java/morseconverter/version.txt", currentVersion);
|
2015-06-01 23:34:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
//TODO To be also shown in the about view
|
2015-06-02 17:25:06 +02:00
|
|
|
if (currentVersion < latestVersion){
|
2015-06-09 10:56:50 +02:00
|
|
|
JOptionPane.showMessageDialog(null, resourceBundle.getString("updateAvailable"));
|
2015-06-01 23:34:04 +02:00
|
|
|
}
|
|
|
|
|
2015-06-02 17:25:06 +02:00
|
|
|
updateDialogButton.addActionListener(new ActionListener() {
|
|
|
|
@Override
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
updateDialog();
|
|
|
|
}
|
2015-05-31 23:21:32 +02:00
|
|
|
|
2015-06-02 17:25:06 +02:00
|
|
|
});
|
|
|
|
}
|
2015-05-31 23:21:32 +02:00
|
|
|
// The holy main method
|
|
|
|
public static void main(String[] args){
|
|
|
|
// Tries to present the app in an native look
|
|
|
|
try{
|
|
|
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
|
|
} catch (Exception e){
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
// Starting the application
|
|
|
|
JFrame main = new JFrame("Main");
|
|
|
|
main.setContentPane(new Main().morseConverterPane);
|
|
|
|
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
// Title
|
2015-06-09 10:56:50 +02:00
|
|
|
main.setTitle(resourceBundle.getString("title"));
|
2015-05-31 23:21:32 +02:00
|
|
|
main.pack();
|
|
|
|
// Window position and Size
|
|
|
|
main.setBounds(100, 100, 800, 400);
|
|
|
|
// MAKE IT HAPPEN :D
|
|
|
|
main.setVisible(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method for converting writtenMorse
|
|
|
|
private void instantWrittenMorseConvert(){
|
|
|
|
// Gets the text from the input field
|
|
|
|
String input = inputAreaWrittenMorse.getText();
|
|
|
|
// checks if the code is a writtenMorse code
|
|
|
|
if(WrittenMorseCodeRecognization.isCode(input)) {
|
|
|
|
// converts the code into normal letters
|
|
|
|
outputAreaWrittenMorse.setText(EncodeWrittenMorseManager.getEncodedString(input));
|
|
|
|
} else {
|
|
|
|
// converts the code into writtenMorse
|
|
|
|
outputAreaWrittenMorse.setText(DecodeWrittenMorseManager.getDecodedString(input));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Method for converting normal Morse
|
|
|
|
private void instantNormalMorseConvert(){
|
|
|
|
// Gets the text from the input field
|
|
|
|
String input = inputAreaNormalMorse.getText();
|
2015-06-09 10:56:50 +02:00
|
|
|
// checks if the code is a normal Morse code
|
2015-05-31 23:21:32 +02:00
|
|
|
if(NormalMorseCodeRecognization.isCode(input)){
|
|
|
|
// converts the code into normal letters
|
|
|
|
outputAreaNormalMorse.setText(EncodeNormalMorseManager.getEncodedString(input));
|
|
|
|
} else {
|
|
|
|
// converts the code into writtenMorse
|
|
|
|
outputAreaNormalMorse.setText(DecodeNormalMorseManager.getDecodedString(input));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-02 17:25:06 +02:00
|
|
|
private void updateDialog() {
|
|
|
|
UpdateDialog.main(null);
|
|
|
|
}
|
|
|
|
|
2015-05-31 23:21:32 +02:00
|
|
|
}
|