Version 1.0
This commit is contained in:
parent
5cf5d2d938
commit
544ae7ce43
149 changed files with 39001 additions and 0 deletions
|
@ -0,0 +1,478 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("New label");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblLic = new JLabel("New label");
|
||||
lblLic.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblVer = new JLabel("New label");
|
||||
lblVer.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblVer);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,555 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.requestFocus();
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
if(output.toString().endsWith("#") && (output.toString().equals("#") == false)){
|
||||
output.delete(output.length() - 1, output.length());
|
||||
}
|
||||
tfOutput.setText(output.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("marcel-kapfer.de/projects/morse");
|
||||
lblNewLabel.setBounds(124, 44, 307, 15);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("marcelmichaelkapfer@yahoo.co.nz");
|
||||
lblNewLabel_1.setBounds(124, 71, 307, 15);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("0.99");
|
||||
lblNewLabel_2.setBounds(124, 98, 307, 15);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("GNU v3.0");
|
||||
lblNewLabel_3.setBounds(124, 125, 307, 15);
|
||||
panel.add(lblNewLabel_3);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,540 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,545 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,558 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "Developer", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 37);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Developer: Marcel Kapfer");
|
||||
lblDeveloper.setBounds(5, 17, 426, 15);
|
||||
panel.add(lblDeveloper);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,560 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.requestFocus();
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
if(output.toString().endsWith("#") && (output.toString().equals("#") == false)){
|
||||
output.delete(output.length() - 1, output.length());
|
||||
}
|
||||
tfOutput.setText(output.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,125 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
import java.awt.Desktop;
|
||||
import java.net.URI;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("marcel-kapfer.de/projects/morse");
|
||||
lblNewLabel.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
|
||||
if(Desktop.isDesktopSupported())
|
||||
{
|
||||
Desktop.getDesktop().browse(new URI("http://www.example.com"));
|
||||
}
|
||||
}
|
||||
});
|
||||
lblNewLabel.setBounds(124, 44, 307, 15);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("marcelmichaelkapfer@yahoo.co.nz");
|
||||
lblNewLabel_1.setBounds(124, 71, 307, 15);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("0.99");
|
||||
lblNewLabel_2.setBounds(124, 98, 307, 15);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("GNU v3.0");
|
||||
lblNewLabel_3.setBounds(124, 125, 307, 15);
|
||||
panel.add(lblNewLabel_3);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,555 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,535 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 236);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblLic = new JLabel("Version");
|
||||
lblLic.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblVer = new JLabel("License");
|
||||
lblVer.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblVer);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,545 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.replaceSelection(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "Developer", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 37);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(5, 17, 426, 15);
|
||||
panel.add(lblDeveloper);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("New label");
|
||||
lblNewLabel.setBounds(124, 44, 307, 15);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("New label");
|
||||
lblNewLabel_1.setBounds(124, 71, 307, 15);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("New label");
|
||||
lblNewLabel_2.setBounds(124, 98, 307, 15);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("New label");
|
||||
lblNewLabel_3.setBounds(124, 125, 307, 15);
|
||||
panel.add(lblNewLabel_3);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,561 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.requestFocus();
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
if(output.toString().endsWith("#")){
|
||||
output.delete(output.length() - 1, output.length());
|
||||
}
|
||||
tfOutput.setText(output.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,557 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,526 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
//StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
tfInput.setText(clipboard.toString());
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,545 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.removeAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("marcel-kapfer.de");
|
||||
lblNewLabel.setBounds(124, 44, 307, 15);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("marcelmichaelkapfer@gmail.com");
|
||||
lblNewLabel_1.setBounds(124, 71, 307, 15);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("0.99");
|
||||
lblNewLabel_2.setBounds(124, 98, 307, 15);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("GNU v3.0");
|
||||
lblNewLabel_3.setBounds(124, 125, 307, 15);
|
||||
panel.add(lblNewLabel_3);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,545 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 2)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("New label");
|
||||
lblNewLabel.setBounds(124, 44, 70, 15);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("New label");
|
||||
lblNewLabel_1.setBounds(124, 71, 70, 15);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("New label");
|
||||
lblNewLabel_2.setBounds(124, 98, 70, 15);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("New label");
|
||||
lblNewLabel_3.setBounds(124, 125, 70, 15);
|
||||
panel.add(lblNewLabel_3);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,544 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setLayout(new FlowLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,560 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.requestFocus();
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
if(output.toString().endsWith("#")){
|
||||
output.delete(output.length() - 1, output.length());
|
||||
}
|
||||
tfOutput.setText(output.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,559 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.requestFocus();
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("marcel-kapfer.de/projects/morse");
|
||||
lblNewLabel.setBounds(124, 44, 307, 15);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("marcelmichaelkapfer@yahoo.co.nz");
|
||||
lblNewLabel_1.setBounds(124, 71, 307, 15);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("0.99");
|
||||
lblNewLabel_2.setBounds(124, 98, 307, 15);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("GNU v3.0");
|
||||
lblNewLabel_3.setBounds(124, 125, 307, 15);
|
||||
panel.add(lblNewLabel_3);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,545 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 37);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(5, 17, 426, 15);
|
||||
panel.add(lblDeveloper);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,561 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.requestFocus();
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
return;
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
if(output.toString().endsWith("#") && (output.toString().equals("#") == false)){
|
||||
output.delete(output.length() - 1, output.length());
|
||||
}
|
||||
tfOutput.setText(output.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,519 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPase = new JMenuItem("Pase from Clipboard");
|
||||
popupMenuIp.add(mntmIpPase);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
//TODO add right click popup menu
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.deleteCharAt(output.length() - 1)
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import javax.swing.JApplet;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.TitledBorder;
|
||||
|
||||
public class MorseApplet extends JApplet {
|
||||
|
||||
/**
|
||||
* Create the applet.
|
||||
*/
|
||||
public MorseApplet() {
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblWebsite = new JLabel("marcel-kapfer.de/projects/morse");
|
||||
lblWebsite.setBounds(124, 44, 307, 15);
|
||||
panel.add(lblWebsite);
|
||||
|
||||
JLabel lblContact = new JLabel("marcelmichaelkapfer@yahoo.co.nz");
|
||||
lblContact.setBounds(124, 71, 307, 15);
|
||||
panel.add(lblContact);
|
||||
|
||||
JLabel lblVersion = new JLabel("0.99-08112014 beta");
|
||||
lblVersion.setBounds(124, 98, 307, 15);
|
||||
panel.add(lblVersion);
|
||||
|
||||
JLabel lblLicense = new JLabel("GNU v3.0");
|
||||
lblLicense.setBounds(124, 125, 307, 15);
|
||||
panel.add(lblLicense);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,566 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
mntmOpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfOutput.requestFocus();
|
||||
tfOutput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
if(output.toString().endsWith("#") && (output.toString().equals("#") == false)){
|
||||
output.delete(output.length() - 1, output.length());
|
||||
}
|
||||
tfOutput.setText(output.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* popup menu
|
||||
*/
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* Past function
|
||||
*/
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
|
||||
/*
|
||||
* Copy function
|
||||
*/
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package morse;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class About extends JDialog {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final JPanel contentPanel = new JPanel();
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
About dialog = new About();
|
||||
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
dialog.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the dialog.
|
||||
*/
|
||||
public About() {
|
||||
setUndecorated(true);
|
||||
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 223);
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
getContentPane().add(contentPanel, BorderLayout.CENTER);
|
||||
contentPanel.setLayout(null);
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setBorder(new TitledBorder(null, "About", TitledBorder.LEADING, TitledBorder.TOP, null, null));
|
||||
panel.setBounds(5, 17, 436, 148);
|
||||
contentPanel.add(panel);
|
||||
panel.setLayout(null);
|
||||
|
||||
JLabel lblDeveloper = new JLabel("Marcel Kapfer");
|
||||
lblDeveloper.setBounds(124, 17, 307, 15);
|
||||
panel.add(lblDeveloper);
|
||||
|
||||
JLabel lblDev = new JLabel("Developer");
|
||||
lblDev.setBounds(12, 17, 100, 15);
|
||||
panel.add(lblDev);
|
||||
|
||||
JLabel lblWeb = new JLabel("Website");
|
||||
lblWeb.setBounds(12, 44, 100, 15);
|
||||
panel.add(lblWeb);
|
||||
|
||||
JLabel lblCont = new JLabel("Contact");
|
||||
lblCont.setBounds(12, 71, 100, 15);
|
||||
panel.add(lblCont);
|
||||
|
||||
JLabel lblVer = new JLabel("Version");
|
||||
lblVer.setBounds(12, 98, 100, 15);
|
||||
panel.add(lblVer);
|
||||
|
||||
JLabel lblLic = new JLabel("License");
|
||||
lblLic.setBounds(12, 125, 100, 15);
|
||||
panel.add(lblLic);
|
||||
|
||||
JLabel lblNewLabel = new JLabel("marcel-kapfer.de/projects/morse");
|
||||
lblNewLabel.setBounds(124, 44, 307, 15);
|
||||
panel.add(lblNewLabel);
|
||||
|
||||
JLabel lblNewLabel_1 = new JLabel("marcelmichaelkapfer@yahoo.co.nz");
|
||||
lblNewLabel_1.setBounds(124, 71, 307, 15);
|
||||
panel.add(lblNewLabel_1);
|
||||
|
||||
JLabel lblNewLabel_2 = new JLabel("0.99");
|
||||
lblNewLabel_2.setBounds(124, 98, 307, 15);
|
||||
panel.add(lblNewLabel_2);
|
||||
|
||||
JLabel lblNewLabel_3 = new JLabel("GNU v3.0");
|
||||
lblNewLabel_3.setBounds(124, 125, 307, 15);
|
||||
panel.add(lblNewLabel_3);
|
||||
{
|
||||
JPanel buttonPane = new JPanel();
|
||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||
{
|
||||
JButton cancelButton = new JButton("Close");
|
||||
cancelButton.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
cancelButton.setActionCommand("Cancel");
|
||||
buttonPane.add(cancelButton);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,552 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
StringSelection selection = new StringSelection(tfOutput.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
}
|
|
@ -0,0 +1,552 @@
|
|||
/*
|
||||
* This is a programm to translate latin letters to morse or written morse or backwards.
|
||||
*
|
||||
* Marcel Michael Kapfer
|
||||
*
|
||||
* GPL v3.0
|
||||
*
|
||||
* 2014
|
||||
*
|
||||
* Version: 0.99 beta
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
package morse;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JMenu;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.*;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JPopupMenu;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
public class Morse extends JFrame {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4342211364299252760L;
|
||||
private JPanel contentPane;
|
||||
private JTextArea tfOutput;
|
||||
private JTextArea tfInput;
|
||||
private JRadioButton rdbtnwmll;
|
||||
private JRadioButton rdbtnllwm;
|
||||
private JRadioButton rdbtnmll;
|
||||
private JRadioButton rdbtnllm;
|
||||
private JButton btnConvert;
|
||||
private JButton btnSelectInput;
|
||||
private final ButtonGroup buttonGroup = new ButtonGroup();
|
||||
private JCheckBoxMenuItem chckbxmntmClipboardAutomatic;
|
||||
|
||||
/**
|
||||
* Launch the application.
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Morse frame = new Morse();
|
||||
frame.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public Morse() {
|
||||
setResizable(false);
|
||||
setTitle("Morse Converter");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setBounds(100, 100, 792, 420);
|
||||
contentPane = new JPanel();
|
||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
setContentPane(contentPane);
|
||||
contentPane.setLayout(null);
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
menuBar.setBorderPainted(false);
|
||||
menuBar.setBounds(0, 0, 820, 21);
|
||||
contentPane.add(menuBar);
|
||||
|
||||
JMenu mnMain = new JMenu("Main Menu");
|
||||
menuBar.add(mnMain);
|
||||
|
||||
JMenuItem mntmAbout = new JMenuItem("About");
|
||||
mntmAbout.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
About.main(null);
|
||||
}
|
||||
});
|
||||
mnMain.add(mntmAbout);
|
||||
|
||||
JMenuItem mntmBug = new JMenuItem("Bug");
|
||||
mnMain.add(mntmBug);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmHowTo = new JMenuItem("How to");
|
||||
mnMain.add(mntmHowTo);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmMissingCode = new JMenuItem("Missing Code");
|
||||
mnMain.add(mntmMissingCode);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenu mnClipboard = new JMenu("Clipboard");
|
||||
menuBar.add(mnClipboard);
|
||||
|
||||
JMenuItem mntnPaste = new JMenuItem("Paste from Clipboard");
|
||||
mnClipboard.add(mntnPaste);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
JMenuItem mntmCopy = new JMenuItem("Copy into Clipboard");
|
||||
mnClipboard.add(mntmCopy);
|
||||
//TODO add jDialog and event listner
|
||||
|
||||
chckbxmntmClipboardAutomatic = new JCheckBoxMenuItem(
|
||||
"Copy automatically into Clipboard");
|
||||
mnClipboard.add(chckbxmntmClipboardAutomatic);
|
||||
|
||||
JScrollPane scrollPaneInput = new JScrollPane();
|
||||
scrollPaneInput.setBounds(12, 60, 758, 140);
|
||||
contentPane.add(scrollPaneInput);
|
||||
|
||||
tfInput = new JTextArea();
|
||||
scrollPaneInput.setViewportView(tfInput);
|
||||
tfInput.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
|
||||
ChooseProcess();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
}
|
||||
});
|
||||
tfInput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuIp = new JPopupMenu();
|
||||
addPopup(tfInput, popupMenuIp);
|
||||
|
||||
JMenuItem mntmIpPaste = new JMenuItem("Paste from Clipboard");
|
||||
mntmIpPaste.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onPaste(tfInput);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpPaste);
|
||||
|
||||
JMenuItem mntnIpSelect = new JMenuItem("Select text");
|
||||
mntnIpSelect.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.selectAll();
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntnIpSelect);
|
||||
|
||||
JMenuItem mntmIpDelete = new JMenuItem("Delete text");
|
||||
mntmIpDelete.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.setText(null);
|
||||
}
|
||||
});
|
||||
popupMenuIp.add(mntmIpDelete);
|
||||
|
||||
JLabel lblEnterYourText = new JLabel("Enter your text:");
|
||||
lblEnterYourText.setBounds(10, 33, 111, 15);
|
||||
contentPane.add(lblEnterYourText);
|
||||
|
||||
rdbtnwmll = new JRadioButton("writtenMorse to Latin Letters");
|
||||
buttonGroup.add(rdbtnwmll);
|
||||
rdbtnwmll.setBounds(12, 208, 250, 23);
|
||||
contentPane.add(rdbtnwmll);
|
||||
|
||||
rdbtnllwm = new JRadioButton("Latin Letters to writtenMorse");
|
||||
buttonGroup.add(rdbtnllwm);
|
||||
rdbtnllwm.setBounds(266, 208, 250, 23);
|
||||
contentPane.add(rdbtnllwm);
|
||||
|
||||
rdbtnmll = new JRadioButton("Morse to Latin Letters");
|
||||
buttonGroup.add(rdbtnmll);
|
||||
rdbtnmll.setBounds(12, 235, 250, 23);
|
||||
contentPane.add(rdbtnmll);
|
||||
|
||||
rdbtnllm = new JRadioButton("Latin Letters to Morse");
|
||||
buttonGroup.add(rdbtnllm);
|
||||
rdbtnllm.setBounds(266, 235, 250, 23);
|
||||
contentPane.add(rdbtnllm);
|
||||
|
||||
btnConvert = new JButton("Convert");
|
||||
btnConvert.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ChooseProcess();
|
||||
}
|
||||
});
|
||||
btnConvert.setBounds(612, 218, 160, 25);
|
||||
contentPane.add(btnConvert);
|
||||
|
||||
JScrollPane scrollPaneOutput = new JScrollPane();
|
||||
scrollPaneOutput.setBounds(12, 266, 758, 140);
|
||||
contentPane.add(scrollPaneOutput);
|
||||
|
||||
tfOutput = new JTextArea();
|
||||
scrollPaneOutput.setViewportView(tfOutput);
|
||||
tfOutput.setEditable(false);
|
||||
tfOutput.setLineWrap(true);
|
||||
|
||||
JPopupMenu popupMenuOp = new JPopupMenu();
|
||||
addPopup(tfOutput, popupMenuOp);
|
||||
|
||||
JMenuItem mntmOpClipboardCopy = new JMenuItem("Copy into Clipboard");
|
||||
mntmOpClipboardCopy.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
});
|
||||
popupMenuOp.add(mntmOpClipboardCopy);
|
||||
|
||||
JMenuItem mntmOpSelect = new JMenuItem("Select Text");
|
||||
popupMenuOp.add(mntmOpSelect);
|
||||
//TODO add right click popup menu
|
||||
|
||||
btnSelectInput = new JButton("Select Input Text");
|
||||
btnSelectInput.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
tfInput.requestFocus();
|
||||
tfInput.selectAll();
|
||||
btnSelectInput.setVisible(false);
|
||||
}
|
||||
});
|
||||
btnSelectInput.setBounds(612, 28, 158, 25);
|
||||
btnSelectInput.setVisible(false);
|
||||
contentPane.add(btnSelectInput);
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose the convert process
|
||||
*/
|
||||
private void ChooseProcess() {
|
||||
if (rdbtnwmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllwm.isSelected()) {
|
||||
LlWm();
|
||||
} else if (rdbtnmll.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else if (rdbtnllm.isSelected()) {
|
||||
tfOutput.setText("Process not available");
|
||||
// TODO Add function
|
||||
} else {
|
||||
tfOutput.setText("Please select a convert process");
|
||||
rdbtnwmll.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tasks to do after the converting process
|
||||
*/
|
||||
private void After() {
|
||||
tfOutput.selectAll();
|
||||
btnSelectInput.setVisible(true);
|
||||
if (chckbxmntmClipboardAutomatic.isSelected()) {
|
||||
onCopy(tfOutput);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Code for converting latin letters into written morse
|
||||
*/
|
||||
private void LlWm() {
|
||||
// Variables
|
||||
StringBuffer input = new StringBuffer();
|
||||
input = input.replace(0, input.length(), tfInput.getText()
|
||||
.toUpperCase());
|
||||
StringBuffer output = new StringBuffer();
|
||||
if (input.toString().equals("")) {
|
||||
tfOutput.setText("Please enter at least one character");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTERSPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("END OF WORK")) {
|
||||
tfOutput.setText("000101");
|
||||
After();
|
||||
} else if (input.toString().equals("ERROR")) {
|
||||
tfOutput.setText("00000000");
|
||||
After();
|
||||
} else if (input.toString().equals("STARTING SIGNAL")) {
|
||||
tfOutput.setText("10101");
|
||||
After();
|
||||
} else if (input.toString().equals("ENDING SIGNAL")) {
|
||||
tfOutput.setText("01010");
|
||||
After();
|
||||
} else if (input.toString().equals("UNDERSTOOD")) {
|
||||
tfOutput.setText("00010");
|
||||
After();
|
||||
} else if (input.toString().equals("WAIT")) {
|
||||
tfOutput.setText("01000");
|
||||
After();
|
||||
} else if (input.toString().equals("SOS")) {
|
||||
tfOutput.setText("000111000");
|
||||
After();
|
||||
} else if (input.toString().equals("LETTER SPACE")) {
|
||||
tfOutput.setText("#");
|
||||
After();
|
||||
} else if (input.toString().equals("WORD SPACE")) {
|
||||
tfOutput.setText("+");
|
||||
After();
|
||||
} else {
|
||||
for (int c = input.length(); c > 0; c--) {
|
||||
if (input.toString().startsWith(" ")) {
|
||||
if (output.toString().endsWith("#")) {
|
||||
output.delete((output.length() - 1), output.length());
|
||||
}
|
||||
output.append("+");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("\n")) {
|
||||
output.append("\n");
|
||||
} else if (input.toString().startsWith("A")) {
|
||||
output.append("01#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("B")) {
|
||||
output.append("1000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("C")) {
|
||||
output.append("1010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("D")) {
|
||||
output.append("100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("E")) {
|
||||
output.append("0#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("F")) {
|
||||
output.append("0010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("G")) {
|
||||
output.append("110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("H")) {
|
||||
output.append("0000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("I")) {
|
||||
output.append("00#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("J")) {
|
||||
output.append("0111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("K")) {
|
||||
output.append("101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("L")) {
|
||||
output.append("0100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("M")) {
|
||||
output.append("11#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("N")) {
|
||||
output.append("10#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("O")) {
|
||||
output.append("111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("P")) {
|
||||
output.append("0110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Q")) {
|
||||
output.append("1101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("R")) {
|
||||
output.append("010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("S")) {
|
||||
output.append("000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("T")) {
|
||||
output.append("1#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("U")) {
|
||||
output.append("001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("V")) {
|
||||
output.append("0001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("W")) {
|
||||
output.append("011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("X")) {
|
||||
output.append("1001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Y")) {
|
||||
output.append("1011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Z")) {
|
||||
output.append("1100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("0")) {
|
||||
output.append("11111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("1")) {
|
||||
output.append("01111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("2")) {
|
||||
output.append("00111#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("3")) {
|
||||
output.append("00011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("4")) {
|
||||
output.append("00001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("5")) {
|
||||
output.append("00000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("6")) {
|
||||
output.append("10000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("7")) {
|
||||
output.append("11000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("8")) {
|
||||
output.append("11100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("9")) {
|
||||
output.append("11110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ä")) {
|
||||
output.append("0101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ö")) {
|
||||
output.append("1110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("Ü")) {
|
||||
output.append("0011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("ß")) {
|
||||
output.append("00011000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(".")) {
|
||||
output.append("010101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(",")) {
|
||||
output.append("110011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(":")) {
|
||||
output.append("111000#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(";")) {
|
||||
output.append("101010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("?")) {
|
||||
output.append("001100#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("!")) {
|
||||
output.append("101011#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("-")) {
|
||||
output.append("100001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("_")) {
|
||||
output.append("001101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("(")) {
|
||||
output.append("10110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith(")")) {
|
||||
output.append("101101#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("=")) {
|
||||
output.append("10001#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("+")) {
|
||||
output.append("01010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("/")) {
|
||||
output.append("10010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("@")) {
|
||||
output.append("011010#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("'")) {
|
||||
output.append("011110#");
|
||||
input.delete(0, 1);
|
||||
} else if (input.toString().startsWith("$")) {
|
||||
output.append("0001001#");
|
||||
input.delete(0, 1);
|
||||
} else {
|
||||
tfOutput.setText("Code not listed or wrong.");
|
||||
}
|
||||
}
|
||||
tfOutput.setText(output.delete(output.length() - 1, output.length())
|
||||
.toString());
|
||||
After();
|
||||
}
|
||||
}
|
||||
private static void addPopup(Component component, final JPopupMenu popup) {
|
||||
component.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
showMenu(e);
|
||||
}
|
||||
}
|
||||
private void showMenu(MouseEvent e) {
|
||||
popup.show(e.getComponent(), e.getX(), e.getY());
|
||||
}
|
||||
});
|
||||
}
|
||||
private void onPaste(JTextArea tf){
|
||||
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
Transferable t = c.getContents(this);
|
||||
if (t == null)
|
||||
return;
|
||||
try {
|
||||
tf.setText((String) t.getTransferData(DataFlavor.stringFlavor));
|
||||
} catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}//try
|
||||
}//onPaste
|
||||
private void onCopy(JTextArea tf){
|
||||
StringSelection selection = new StringSelection(tf.getText());
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard();
|
||||
clipboard.setContents(selection, selection);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package morse;
|
||||
|
||||
import javax.swing.JApplet;
|
||||
|
||||
public class MorseApplet extends JApplet {
|
||||
|
||||
/**
|
||||
* Create the applet.
|
||||
*/
|
||||
public MorseApplet() {
|
||||
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
|
BIN
.metadata/.plugins/org.eclipse.core.resources/.root/35.tree
Normal file
BIN
.metadata/.plugins/org.eclipse.core.resources/.root/35.tree
Normal file
Binary file not shown.
Binary file not shown.
Reference in a new issue