Added popup menus; Version 2.0.0

This commit is contained in:
mmk2410 2015-08-20 15:50:40 +02:00
parent b549c99096
commit 95cb753508
4 changed files with 443 additions and 113 deletions

View file

@ -36,17 +36,18 @@ import javax.swing.text.Element;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.*;
import java.io.IOException;
import java.util.ResourceBundle;
public class Main extends JFrame {
// Version numbers for update check
public static final int currentVersion = 193;
public static final int currentVersion = 200;
public static int latestVersion = currentVersion;
public static ResourceBundle resourceBundle = ResourceBundle.getBundle("de.marcelkapfer.c.morseconverter.text");
@ -102,6 +103,153 @@ public class Main extends JFrame {
}
});
// Mouse listener for selecting text on left click in output text area
outputAreaWrittenMorse.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
outputAreaWrittenMorse.requestFocus();
outputAreaWrittenMorse.selectAll();
}
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
outputAreaNormalMorse.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON1) {
outputAreaNormalMorse.requestFocus();
outputAreaNormalMorse.selectAll();
}
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
// Popup Menus
// Popup Menu for writtenMorse input text field
JPopupMenu wInputPopup = new JPopupMenu();
addPopup(inputAreaWrittenMorse, wInputPopup);
// Item for paste
JMenuItem pasteWInput = new JMenuItem(resourceBundle.getString("paste"));
pasteWInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onPaste(inputAreaWrittenMorse);
instantWrittenMorseConvert();
}
});
wInputPopup.add(pasteWInput);
// Item for clear
JMenuItem clearWInput = new JMenuItem(resourceBundle.getString("clear"));
clearWInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clear(inputAreaWrittenMorse);
}
});
wInputPopup.add(clearWInput);
// Popup Menu for writtenMorse output text field
JPopupMenu wOutputPopup = new JPopupMenu();
addPopup(outputAreaWrittenMorse, wOutputPopup);
// Item for copy
JMenuItem copyWOutput = new JMenuItem(resourceBundle.getString("copy"));
copyWOutput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCopy(outputAreaWrittenMorse);
}
});
wOutputPopup.add(copyWOutput);
// Popups for Normal Morse
// Popup for Normal Morse input text field
JPopupMenu nInputMenu = new JPopupMenu();
addPopup(inputAreaNormalMorse, nInputMenu);
// Item for paste
JMenuItem nPasteInput = new JMenuItem(resourceBundle.getString("paste"));
nPasteInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onPaste(inputAreaNormalMorse);
instantNormalMorseConvert();
}
});
nInputMenu.add(nPasteInput);
// Item for clear
JMenuItem nClearInput = new JMenuItem(resourceBundle.getString("clear"));
nClearInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
clear(inputAreaNormalMorse);
}
});
nInputMenu.add(nClearInput);
// Popup for output text field
JPopupMenu nOutputMenu = new JPopupMenu();
addPopup(outputAreaNormalMorse, nOutputMenu);
// Menü item for copy
JMenuItem nCopyOutput = new JMenuItem(resourceBundle.getString("copy"));
nCopyOutput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCopy(outputAreaNormalMorse);
}
});
nOutputMenu.add(nCopyOutput);
}
// The holy main method
public static void main(String[] args){
@ -114,7 +262,7 @@ public class Main extends JFrame {
// Starting the application
JFrame main = new JFrame("Main");
main.setContentPane(new Main().morseConverterPane);
main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
main.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Title
main.setTitle(resourceBundle.getString("title"));
main.pack();
@ -158,4 +306,55 @@ public class Main extends JFrame {
UpdateDialog.main(null);
}
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) {
try {
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
} catch (Exception e) {
e.printStackTrace();
}
}// onPaste
/*
* Copy function
*/
private void onCopy(JTextArea tf) {
StringSelection selection = new StringSelection(tf.getText());
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(selection, selection);
}
private void clear(JTextArea jTextArea) {
jTextArea.setText("");
}
}

View file

@ -1,7 +1,10 @@
about=<body style\="font-family\: sans-serif">\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Version</b><br>1.9.3 beta\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Developer</b><br>Marcel Michael Kapfer\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Website</b><br>marcel-kapfer.de/writtenmorse\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Contact</b><br>marcelmichaelkapfer@yahoo.co.nz\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>License</b><br>GNU GPL v3.0\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Bug</b><br>If you found a bug, please write me a mail to marcelmichaelkapfer@yahoo.co.nz with a short description of the problem.\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>How to</b><br>You can find a detailed guide on marcel-kapfer.de/writtenmorse/\#howto_desktop\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Missing Code</b><br>If you discovered, that a code is missing, then write me a mail to marcelmichaelkapfer@yahoo.co.nz and tell me about it.\n</p>\n</p>\n</body>
about=<body style\="font-family\: sans-serif">\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Version</b><br>2.0.0\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Developer</b><br>Marcel Michael Kapfer\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Website</b><br>marcel-kapfer.de/writtenmorse\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Contact</b><br>marcelmichaelkapfer@yahoo.co.nz\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>License</b><br>GNU GPL v3.0\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Bug</b><br>If you found a bug, please write me a mail to marcelmichaelkapfer@yahoo.co.nz with a short description of the problem.\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>How to</b><br>You can find a detailed guide on marcel-kapfer.de/writtenmorse/\#howto_desktop\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Missing Code</b><br>If you discovered, that a code is missing, then write me a mail to marcelmichaelkapfer@yahoo.co.nz and tell me about it.\n</p>\n</p>\n</body>
aboutUpdateAvailable=Update available
aboutUpdateAvailableButton=Install Update
clear=Clear
copy=Copy
inputText=Enter your text
paste=Paste
tabAbout=About
tabNormalMorse=Normal Morse
title=Morse Converter

View file

@ -1,7 +1,10 @@
about=<body style\="font-family\: sans-serif">\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Version</b><br>1.9.3 beta\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Entwickler</b><br>Marcel Michael Kapfer\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Website</b><br>marcel-kapfer.de/writtenmorse\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Kontakt</b><br>marcelmichaelkapfer@yahoo.co.nz\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Lizenz</b><br>GNU GPL v3.0\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Fehler</b><br>Wenn Du einen Fehler gefunden hast, schreibe mir bitte ein E-Mail an marcelmichaelkapfer@yahoo.co.nz\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>How to</b><br>Du kannst eine ausführliche Anleitung auf marcel-kapfer.de/writtenmorse/\#howto_android finden.\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Fehlender Code</b><br>Wenn Du auf einen fehlenden Code aufmerksam geworden bist, dann schreibe eine E-Mail an marcelmichaelkapfer@yahoo.co.nz.\n</p>\n</p>\n</body>
about=<body style\="font-family\: sans-serif">\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Version</b><br>2.0.0\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Entwickler</b><br>Marcel Michael Kapfer\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Website</b><br>marcel-kapfer.de/writtenmorse\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Kontakt</b><br>marcelmichaelkapfer@yahoo.co.nz\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Lizenz</b><br>GNU GPL v3.0\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Fehler</b><br>Wenn Du einen Fehler gefunden hast, schreibe mir bitte ein E-Mail an marcelmichaelkapfer@yahoo.co.nz\n</p>\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>How to</b><br>Du kannst eine ausführliche Anleitung auf marcel-kapfer.de/writtenmorse/\#howto_android finden.\n<p style\="margin-top\: 5px; margin-right\: 5px; margin-bottom\: 5px; margin-left\: 5px">\n<b>Fehlender Code</b><br>Wenn Du auf einen fehlenden Code aufmerksam geworden bist, dann schreibe eine E-Mail an marcelmichaelkapfer@yahoo.co.nz.\n</p>\n</p>\n</body>
aboutUpdateAvailable=Update verfügbar
aboutUpdateAvailableButton=Update installieren
clear=Bereinigen
copy=Kopieren
inputText=Geben Sie einen Text ein
paste=Einfügen
tabAbout=Über
tabNormalMorse=Normales Morse
title=Morse Umwandler