Update to meet Google Java Coding Guidlines

This commit is contained in:
Marcel Kapfer (mmk2410) 2016-04-15 17:49:40 +02:00
parent 280f195755
commit 85261470cc
15 changed files with 474 additions and 573 deletions

View file

@ -145,6 +145,7 @@
</constraints>
<properties>
<foreground color="-4517120"/>
<labelFor value="b553f"/>
<text resource-bundle="de/marcelkapfer/c/morseconverter/text" key="aboutUpdateAvailable"/>
<visible value="false"/>
</properties>
@ -160,4 +161,7 @@
</tabbedpane>
</children>
</grid>
<inspectionSuppressions>
<suppress inspection="NoLabelFor"/>
</inspectionSuppressions>
</form>

View file

@ -50,8 +50,8 @@ public class Main extends JFrame {
public static final int currentVersion = 200;
public static int latestVersion = currentVersion;
public static ResourceBundle resourceBundle = ResourceBundle.getBundle("de.marcelkapfer.c.morseconverter.text");
public JTabbedPane morseConverterPane;
private static final ResourceBundle resourceBundle = ResourceBundle.getBundle("de.marcelkapfer.c.morseconverter.text");
private JTabbedPane morseConverterPane;
private JPanel panel1;
private JTextArea inputAreaWrittenMorse;
private JTextArea outputAreaWrittenMorse;
@ -96,13 +96,7 @@ public class Main extends JFrame {
updateDialogButton.setText(resourceBundle.getString("aboutUpdateAvailableButton"));
}
updateDialogButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateDialog();
}
});
updateDialogButton.addActionListener(e -> updateDialog());
// Mouse listener for selecting text on left click in output text area
outputAreaWrittenMorse.addMouseListener(new MouseListener() {
@ -174,23 +168,15 @@ public class Main extends JFrame {
// Item for paste
JMenuItem pasteWInput = new JMenuItem(resourceBundle.getString("paste"));
pasteWInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onPaste(inputAreaWrittenMorse);
instantWrittenMorseConvert();
}
pasteWInput.addActionListener(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);
}
});
clearWInput.addActionListener(e -> clear(inputAreaWrittenMorse));
wInputPopup.add(clearWInput);
// Popup Menu for writtenMorse output text field
@ -199,12 +185,7 @@ public class Main extends JFrame {
// Item for copy
JMenuItem copyWOutput = new JMenuItem(resourceBundle.getString("copy"));
copyWOutput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCopy(outputAreaWrittenMorse);
}
});
copyWOutput.addActionListener(e -> onCopy(outputAreaWrittenMorse));
wOutputPopup.add(copyWOutput);
@ -216,23 +197,15 @@ public class Main extends JFrame {
// Item for paste
JMenuItem nPasteInput = new JMenuItem(resourceBundle.getString("paste"));
nPasteInput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onPaste(inputAreaNormalMorse);
instantNormalMorseConvert();
}
nPasteInput.addActionListener(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);
}
});
nClearInput.addActionListener(e -> clear(inputAreaNormalMorse));
nInputMenu.add(nClearInput);
// Popup for output text field
@ -240,14 +213,9 @@ public class Main extends JFrame {
JPopupMenu nOutputMenu = new JPopupMenu();
addPopup(outputAreaNormalMorse, nOutputMenu);
// Menü item for copy
// Menu item for copy
JMenuItem nCopyOutput = new JMenuItem(resourceBundle.getString("copy"));
nCopyOutput.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
onCopy(outputAreaNormalMorse);
}
});
nCopyOutput.addActionListener(e -> onCopy(outputAreaNormalMorse));
nOutputMenu.add(nCopyOutput);
}

View file

@ -34,7 +34,7 @@ public class DecodeNormalMorseManager {
// Variables
StringBuffer input = new StringBuffer();
input = input.replace(0, input.length(), message.toString().toUpperCase());
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
if (input.toString().equals("LETTERSPACE")) {
output.replace(0, output.length(), " ");
} else if (input.toString().equals("END OF WORK")) {

View file

@ -34,7 +34,7 @@ public class DecodeWrittenMorseManager {
// Variables
StringBuffer input = new StringBuffer();
input = input.replace(0, input.length(), message.toString().toUpperCase());
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
if (input.toString().equals("LETTERSPACE")) {
output.replace(0, output.length(), "#");
} else if (input.toString().equals("END OF WORK")) {

View file

@ -38,16 +38,16 @@ public class EncodeNormalMorseManager {
}
// Declaring variables
String input;
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
input = message.toString() + " ";
input = input.replace(System.lineSeparator(), "\n");
input = input.replace("\r", "\n");
input = input.replace("\r\n", "\n");
StringBuffer inputToSign = new StringBuffer(input);
StringBuilder inputToSign = new StringBuilder(input);
while (!inputToSign.toString().equals(" ")) {
int d = 0;
boolean signFull = true;
StringBuffer sign = new StringBuffer();
StringBuilder sign = new StringBuilder();
while (signFull) {
if (inputToSign.toString().startsWith(" ")) {
output.append(" ");

View file

@ -37,16 +37,16 @@ public class EncodeWrittenMorseManager {
}
// Variables
String input;
StringBuffer output = new StringBuffer();
StringBuilder output = new StringBuilder();
input = message.toString().toUpperCase() + "#";
input = input.replace(System.lineSeparator(), "\n");
input = input.replace("\r", "\n");
input = input.replace("\r\n", "\n");
StringBuffer inputToSign = new StringBuffer(input);
StringBuilder inputToSign = new StringBuilder(input);
while (!inputToSign.toString().equals("#")) {
int d = 0;
boolean signFull = true;
StringBuffer sign = new StringBuffer();
StringBuilder sign = new StringBuilder();
while (signFull) {
if (inputToSign.toString().charAt(d) == '+'
|| inputToSign.toString().charAt(d) == '#'

View file

@ -22,13 +22,14 @@ package de.marcelkapfer.c.morseconverter.intelligentCodeRecognization;
*/
/**
* Created by mmk on 5/31/15.
* Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
* Licensed under
*/
public class NormalMorseCodeRecognization {
public static Boolean isCode(String input){
input = input.toLowerCase();
if(input.contains("a") || input.contains("b") ||
return !(input.contains("a") || input.contains("b") ||
input.contains("c") || input.contains("d") ||
input.contains("e") || input.contains("f") ||
input.contains("g") || input.contains("h") ||
@ -54,11 +55,7 @@ public class NormalMorseCodeRecognization {
input.contains("+") || input.contains("_") ||
input.contains("(") || input.contains(")") ||
input.contains("=") || input.contains("/") ||
input.contains("@") || input.contains("'")){
return false;
} else {
return true;
}
input.contains("@") || input.contains("'"));
}
}

View file

@ -22,13 +22,14 @@ package de.marcelkapfer.c.morseconverter.intelligentCodeRecognization;
*/
/**
* Created by mmk on 5/31/15.
* Marcel Kapfer (mmk2410) <marcelmichaelkapfer@yahoo.co.nz>
* Licensed under
*/
public class WrittenMorseCodeRecognization {
public static Boolean isCode(String input){
input = input.toLowerCase();
if(input.contains("a") || input.contains("b") ||
return !(input.contains("a") || input.contains("b") ||
input.contains("c") || input.contains("d") ||
input.contains("e") || input.contains("f") ||
input.contains("g") || input.contains("h") ||
@ -54,11 +55,7 @@ public class WrittenMorseCodeRecognization {
input.contains("(") || input.contains(")") ||
input.contains("=") || input.contains("/") ||
input.contains("@") || input.contains("'") ||
input.contains("$")){
return false;
} else {
return true;
}
input.contains("$"));
}
}

View file

@ -1,5 +1,5 @@
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
aboutUpdateAvailable=&Update available
aboutUpdateAvailableButton=Install Update
clear=Clear
copy=Copy
@ -13,7 +13,7 @@ update-no-connection=The connection to the server was not possible.\nTry again l
update-not-successful=Update not successful
update-successful=Update successful.\nPlease restart the software to activate the changes.
updateAvailable=An Update is available\!\nGo to the 'About' section for more.
updateButton=Check for updates
updateButton=&Check for updates
updateDialogClose=Close
updateDialogNewVersion=A new version of the Morse Converter is available.
updateDialogUpToDateText=You're running the latest version.

View file

@ -39,7 +39,7 @@ public class Update {
* Argument: The URL of the file with the version number as a string
*
*/
public static boolean isConnected(String url){
public static boolean isConnected(@SuppressWarnings("SameParameterValue") String url){
try {
update = new URL(url);
update.openStream();
@ -57,7 +57,7 @@ public class Update {
* Arguments: The path where the jar file is located, the name of the jar file
*
*/
public static boolean update(String path, String filename){
public static boolean update(String path, @SuppressWarnings("SameParameterValue") String filename){
try {
ReadableByteChannel updateChannel = Channels.newChannel(update.openStream());
FileOutputStream updateOutputStream = new FileOutputStream(path + filename);
@ -78,6 +78,7 @@ public class Update {
* It is highly recommended to give also the version number of the current version as an argument
*
*/
@SuppressWarnings("unused")
public static int getLatestVersion(String versionFile){
return getLatestVersion(versionFile, 0);
}

View file

@ -3,7 +3,7 @@
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="10" left="10" bottom="10" right="10"/>
<constraints>
<xy x="48" y="54" width="551" height="297"/>
<xy x="48" y="54" width="720" height="297"/>
</constraints>
<properties/>
<border type="none"/>
@ -34,7 +34,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Yes"/>
<text value="&amp;Yes"/>
</properties>
</component>
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
@ -42,7 +42,7 @@
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="No"/>
<text value="&amp;No"/>
</properties>
</component>
</children>

View file

@ -32,13 +32,13 @@ import java.util.ResourceBundle;
public class UpdateDialog extends JDialog {
private JPanel contentPane;
public JButton buttonOK;
public JButton buttonCancel;
public JLabel updateDialogQuestion;
public JLabel updateDialogNewVersion;
private ResourceBundle resourceBundle = ResourceBundle.getBundle("de.marcelkapfer.c.morseconverter.text");
private JButton buttonOK;
private JButton buttonCancel;
private JLabel updateDialogQuestion;
private JLabel updateDialogNewVersion;
private final ResourceBundle resourceBundle = ResourceBundle.getBundle("de.marcelkapfer.c.morseconverter.text");
public UpdateDialog() {
private UpdateDialog() {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
@ -48,17 +48,9 @@ public class UpdateDialog extends JDialog {
updateDialogNewVersion.setVisible(false);
updateDialogQuestion.setText(resourceBundle.getString("updateDialogUpToDateText"));
}
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onOK();
}
});
buttonOK.addActionListener(e -> onOK());
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
});
buttonCancel.addActionListener(e -> onCancel());
// call onCancel() when cross is clicked
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
@ -69,11 +61,7 @@ public class UpdateDialog extends JDialog {
});
// call onCancel() on ESCAPE
contentPane.registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
onCancel();
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}
private void onOK() {