Skip to content

Commit

Permalink
#4 Checkstyle improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Sep 9, 2019
1 parent e428b8e commit 69c2cb7
Show file tree
Hide file tree
Showing 215 changed files with 978 additions and 731 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.freeinternals.commonlib.ui.JPanelForTree;
import org.freeinternals.commonlib.ui.JTreeCellRenderer;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.format.FileFormatException;
import org.freeinternals.commonlib.core.FileFormatException;

/**
* A split panel created from a class file byte array.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import javax.swing.UIManager;
import org.freeinternals.biv.plugin.PluginManager;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.format.FileFormatException;
import org.freeinternals.commonlib.core.FileFormatException;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.io.File;
import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.format.FileFormatException;
import org.freeinternals.commonlib.core.FileFormatException;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import org.freeinternals.format.FileFormatException;
import org.freeinternals.commonlib.core.FileFormatException;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import java.util.zip.ZipFile;

/**
* Utility Class.
* Utility Class for bytes array (binary data).
*
* @author Amos Shi
*/
public final class BytesTool {

public static boolean isByteArrayEmpty(byte[] buff, int startPos, int length) {
public static boolean isByteArrayEmpty(final byte[] buff, final int startPos, final int length) {
boolean result = false;

if (buff[startPos] == 0x00 || buff[startPos] == ((byte) 0xFF)) {
Expand Down Expand Up @@ -52,7 +52,7 @@ public static boolean isByteArrayEmpty(byte[] buff, int startPos, int length) {
* @param bin2 The second byte array
* @return <code>true</code> if the content are the same, else false
*/
public static boolean isByteArraySame(byte[] bin1, byte[] bin2) {
public static boolean isByteArraySame(final byte[] bin1, final byte[] bin2) {
if (bin1 == null || bin2 == null) {
return false;
}
Expand Down Expand Up @@ -83,7 +83,7 @@ public static boolean isByteArraySame(byte[] bin1, byte[] bin2) {
* @param start The start position for compare
* @return <code>true</code> if the content are the same, else false
*/
public static boolean isByteArraySame(byte[] bin1, byte[] bin2, int start) {
public static boolean isByteArraySame(final byte[] bin1, final byte[] bin2, final int start) {
if (bin1 == null || bin2 == null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.SortedMap;
import java.util.TreeMap;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.format.FileFormatException;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright 2011, FreeInternals.org. All rights reserved.
* Use is subject to license terms.
*/
package org.freeinternals.format;
package org.freeinternals.commonlib.core;

/**
*
Expand All @@ -26,7 +26,7 @@ public FileFormatException() {
* specified detail message.
* @param msg the detail message.
*/
public FileFormatException(String msg) {
public FileFormatException(final String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @author Amos Shi
*/
public class PosByteArrayInputStream extends ByteArrayInputStream {
public final class PosByteArrayInputStream extends ByteArrayInputStream {

/**
* Creates a new instance of PosByteArrayInputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*
* @author Amos Shi
*/
public class PosDataInputStream extends DataInputStream implements DataInputEx {
public final class PosDataInputStream extends DataInputStream implements DataInputEx {

/**
* Offset of the 1st byte
Expand Down Expand Up @@ -235,7 +235,7 @@ public BigInteger readUnsignedLong_LittleEndian() throws IOException {
}

@Override
public String readASCII(int length) throws IOException {
public String readASCII(final int length) throws IOException {
if (length <= 0) {
throw new IllegalArgumentException(
String.format("Parameter length should be greater than 0. (length = %d)", length));
Expand All @@ -261,7 +261,7 @@ public String readASCII() throws IOException {
* @throws java.io.IOException
*/
@Override
public String readASCIIUntil(byte end) throws IOException {
public String readASCIIUntil(final byte end) throws IOException {
byte b;
StringBuilder sb = new StringBuilder(100);

Expand Down Expand Up @@ -333,7 +333,7 @@ public ASCIILine readASCIILine() throws IOException {
return new ASCIILine(line, nlLen);
}

private boolean _contains(byte v, byte[] list) {
private boolean _contains(final byte v, final byte[] list) {
boolean result = false;
for (int i = 0; i < list.length; i++) {
if (list[i] == v) {
Expand Down Expand Up @@ -382,7 +382,7 @@ public byte[] readBinary() throws IOException {
* @see PosByteArrayInputStream
*/
@Override
public int backward(int i) {
public int backward(final int i) {
int result = -1;

if (this.in instanceof PosByteArrayInputStream) {
Expand All @@ -405,7 +405,7 @@ public int backward(int i) {
* @return the new position, or -1 if <code>b</code> not found
*/
@Override
public int backwardTo(byte b) {
public int backwardTo(final byte b) {
int result = -1;

if (this.in instanceof PosByteArrayInputStream) {
Expand Down Expand Up @@ -436,7 +436,7 @@ public int backwardTo(byte b) {
* @see PosByteArrayInputStream
* @return the new position, or -1 if <code>b</code> not found
*/
public int forwardTo(byte b) {
public int forwardTo(final byte b) {
int result = -1;

if (this.in instanceof PosByteArrayInputStream) {
Expand Down Expand Up @@ -466,7 +466,7 @@ public int forwardTo(byte b) {
* @see PosByteArrayInputStream
*/
@Override
public int backwardTo(byte[] b) {
public int backwardTo(final byte[] b) {
int result = -1;

if ((b == null) || (b.length == 0)) {
Expand Down Expand Up @@ -508,14 +508,14 @@ public void skipToEnd() throws IOException {

/**
* Fly to the specific <code>position</code>.
*
*
* This method supports {@link PosByteArrayInputStream} only, nothing will
* do for other input stream types.
*
* @see PosByteArrayInputStream
*/
@Override
public void flyTo(int position) {
public void flyTo(final int position) {
if (this.in instanceof PosByteArrayInputStream) {
((PosByteArrayInputStream) this.in).setPos(position);
}
Expand Down
104 changes: 84 additions & 20 deletions CommonLib/src/main/java/org/freeinternals/commonlib/ui/HTMLKit.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,104 @@
package org.freeinternals.commonlib.ui;

/**
* HTML Kit for the
* <code>JTextPane</code> control.
* HTML Kit for the <code>JTextPane</code> control.
*
* @author Amos
*/
public class HTMLKit {
public final class HTMLKit {

private static final int FONT_SIZE = 12;
/**
* Font color yellow.
*/
public static final String FONT_COLOR_YELLOW = "yellow";

/**
* Font color orange.
*/
public static final String FONT_COLOR_ORANGE = "#FFA500";

public static String Start() {
/**
* ASCII code 32.
*/
private static final int ASCII_32 = 32;
/**
* ASCII code 127.
*/
private static final int ASCII_127 = 127;
/**
* ASCII code 160.
*/
private static final int ASCII_160 = 160;
/**
* ASCII code 255.
*/
private static final int ASCII_255 = 255;

private HTMLKit() {
}

/**
* HTML start tags.
*
* @return HTML tags for start
*/
public static String start() {
return "<!DOCTYPE html><html><head></head><body>";
}

public static String End() {
/**
* HTML end tags.
*
* @return HTML tags for end
*/
public static String end() {
return "\n</body>\n</html>";
}

public static String NewLine() {
/**
* HTML new line.
*
* @return HTML new line tag
*/
public static String newLine() {
return "<br />";
}

public static String Space() {
/**
* HTML space.
*
* @return HTML space tag
*/
public static String space() {
return "&nbsp;";
}

/**
* Get HTML format for text with new line.
*
* @param text Text inside the span
* @return HTML code of span
*/
public static String Span(String text) {
public static String span(final String text) {
// TODO the "\n" is no needed?
return String.format("\n<span style=\"font-size:%dpx; font-family:%s;\">%s</span>",
FONT_SIZE,
JBinaryViewer.FONT.getSize() - 2,
JBinaryViewer.FONT.getFamily(),
text);
}

public static String Span(String text, String color) {
/**
* Get HTML format for text with new line and specified color.
*
* @param text Text inside the span
* @param color Color of the text
* @return HTML code of span
*/
public static String span(final String text, final String color) {
// TODO the "\n" is no needed?
return String.format("\n<span style=\"background-color:%s; font-size:%dpx; font-family:%s;\">%s</span>",
color,
FONT_SIZE,
JBinaryViewer.FONT.getSize() - 2,
JBinaryViewer.FONT.getFamily(),
text);
}
Expand All @@ -50,27 +107,34 @@ public static String Span(String text, String color) {
* Get HTML marks for the byte.
*
* @param b Byte value
* @return HTML mark for the byte value
* @return HTML mark for the byte value
* @see <a href="http://ascii.cl/htmlcodes.htm">HTML Codes - Characters and
* symbols</a>
*/
static public String getByteText(final byte b) {
public static String getByteText(final byte b) {
String s = ".";

if (((b > 32) && (b < 127))
|| ((b > 160) && (b <= 255))) {
if (((b > ASCII_32) && (b < ASCII_127))
|| ((b > ASCII_160) && (b <= ASCII_255))) {
s = String.format("&#%d;", b);
}

return s;
}

static public String EscapeFilter(String text) {
/**
* Escape HTML special character &gt and &lt.
*
* @param text Input text to process
* @return Escaped result
*/
public static String escapeFilter(final String text) {
String result = null;
if (text != null) {
text = text.replaceAll("<", "&lt;");
text = text.replaceAll(">", "&gt;");
result = text.replaceAll("<", "&lt;");
result = result.replaceAll(">", "&gt;");
}

return text;
return result;
}
}
Loading

0 comments on commit 69c2cb7

Please sign in to comment.