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 b6ca698 commit 599c377
Show file tree
Hide file tree
Showing 27 changed files with 333 additions and 158 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
Expand All @@ -24,19 +27,28 @@ public class JLabelHyperLink extends JLabel {

private static final long serialVersionUID = 4876543219876500000L;

/**
* Text of the label.
*/
private final String text;
/**
* Target URL of the label.
*/
private final String url;
/**
* Flag indicates whether current JVM support browser or not.
*/
private boolean isSupported;

/**
* Create a new Hyper Link enabled JLabel.
*
* @param text Text of the label
* @param url Target URL
* @param txt Text of the label
* @param link Target Link URL
*/
public JLabelHyperLink(final String text, final String url) {
this.text = text;
this.url = url;
public JLabelHyperLink(final String txt, final String link) {
this.text = txt;
this.url = link;

try {
this.isSupported = Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE);
Expand All @@ -63,9 +75,8 @@ public void mouseExited(final MouseEvent e) {
@Override
public void mouseClicked(final MouseEvent e) {
try {
Desktop.getDesktop().browse(
new java.net.URI(JLabelHyperLink.this.url));
} catch (Exception ex) {
Desktop.getDesktop().browse(new URI(JLabelHyperLink.this.url));
} catch (IOException | URISyntaxException ex) {
Logger.getLogger(JLabelHyperLink.class.getName()).log(Level.SEVERE, null, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
*
* @author Amos Shi
*/
public class JTreeCellRenderer extends DefaultTreeCellRenderer {
public final class JTreeCellRenderer extends DefaultTreeCellRenderer {

private static final long serialVersionUID = 4876543219876500000L;

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
public Component getTreeCellRendererComponent(final JTree tree, final Object value,
final boolean sel, final boolean expanded, final boolean leaf, final int row,
final boolean hasFocus) {

super.getTreeCellRendererComponent(tree, value,
sel, expanded, leaf, row,
Expand All @@ -37,10 +37,10 @@ public Component getTreeCellRendererComponent(JTree tree, Object value,
this.setIcon(icon);
}

if (fileComp.isDetailAvailable() == false) {
this.setText(fileComp.getText());
} else {
if (fileComp.isDetailAvailable()) {
this.setText("<html><font color=blue><u>" + fileComp.getText());
} else {
this.setText(fileComp.getText());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,102 +10,171 @@
import javax.swing.JPanel;

/**
* Tree node for a file component.
*
* @author Amos Shi
*/
public class JTreeNodeFileComponent {
public final class JTreeNodeFileComponent {

/**
* Binary data start position for current tree node.
*/
private final int startPos;
/**
* Binary data length for current tree node.
*/
private final int length;
/**
* Tree node text.
*/
private final String text;

/**
* Icon for current tree node.
*/
private Icon icon;
/**
* Description text for current tree node.
*/
private String description;
/**
* Detailed panel for current tree node.
*/
private JPanel panelDetail = null;
private boolean isDetailAvailable = false;

public JTreeNodeFileComponent(final int startPos, final int length, final String text) {
if (startPos < 0) {
throw new IllegalArgumentException("Start position cannot be less than zero; it is '" + startPos + "'.");
/**
* Constructor.
*
* @param nodeStartPos Value for {@link #startPos}
* @param nodeLength Value for {@link #length}
* @param nodeText Value for {@link #text}
*/
public JTreeNodeFileComponent(final int nodeStartPos, final int nodeLength, final String nodeText) {
if (nodeStartPos < 0) {
throw new IllegalArgumentException("Start position cannot be less than zero; it is '" + nodeStartPos + "'.");
}

if (length < 0) {
throw new IllegalArgumentException("Length cannot be less than zero; it is '" + length + "'.");
if (nodeLength < 0) {
throw new IllegalArgumentException("Length cannot be less than zero; it is '" + nodeLength + "'.");
}

if ((text == null) || (text.length() == 0)) {
if ((nodeText == null) || (nodeText.length() == 0)) {
throw new IllegalArgumentException("Text cannot be null or empty.");
}

this.startPos = startPos;
this.length = length;
this.text = text;
}

public JTreeNodeFileComponent(final int startPos, final int length, final String text, Icon icon) {
this(startPos, length, text);
this.icon = icon;
this.startPos = nodeStartPos;
this.length = nodeLength;
this.text = nodeText;
}

public JTreeNodeFileComponent(final int startPos, final int length, final String text, final String desc) {
this(startPos, length, text);
this.description = desc;
}

public JTreeNodeFileComponent(final int startPos, final int length, final String text, final String desc, Icon icon) {
this(startPos, length, text);
/**
* Constructor.
*
* @param nodeStartPos Value for {@link #startPos}
* @param nodeLength Value for {@link #length}
* @param nodeText Value for {@link #text}
* @param nodeIcon Value for {@link #icon}, could be null
* @param desc Value for {@link #description}, could be null
*/
public JTreeNodeFileComponent(final int nodeStartPos, final int nodeLength, final String nodeText, final Icon nodeIcon, final String desc) {
this(nodeStartPos, nodeLength, nodeText);
this.description = desc;
this.icon = icon;
this.icon = nodeIcon;
}

@Override
public String toString() {
return this.text;
}

/**
* Getter for {@link #startPos}.
*
* @return {@link #startPos} value
*/
public int getStartPos() {
return this.startPos;
}

/**
* Getter for {@link #length}.
*
* @return {@link #length} value
*/
public int getLength() {
return this.length;
}

/**
* Get the last position of current node plus 1, which equals to the first position of the next node.
* The value is ({@link #startPos} + {@link #length}).
*
* Get the last position of current node plus 1, which equals to the first
* position of the next node. The value is
* ({@link #startPos} + {@link #length}).
*
* @return Last position plus 1
*/
public int getLastPosPlus1(){
public int getLastPosPlus1() {
return this.startPos + this.length;
}

/**
* Getter for {@link #text}.
*
* @return {@link #text} value
*/
public String getText() {
return this.text;
}

/**
* Getter for {@link #icon}.
*
* @return {@link #icon} value
*/
public Icon getIcon() {
return this.icon;
}

public void setDescription(String description) {
this.description = description;
/**
* Setter for {@link #description}.
*
* @param d Value for {@link #description}
*/
public void setDescription(final String d) {
this.description = d;
}

/**
* Getter for {@link #description}.
*
* @return {@link #description} value
*/
public String getDescription() {
return this.description;
}

public void setDetailPanel(JPanel p) {
/**
* Setter for {@link #panelDetail}.
*
* @param p Value for {@link #panelDetail}
*/
public void setDetailPanel(final JPanel p) {
this.panelDetail = p;
this.isDetailAvailable = true;
}

/**
* Indicates whether we have a detailed panel {@link #panelDetail}.
*
* @return true if {@link #panelDetail} is not null, else false
*/
public boolean isDetailAvailable() {
return this.isDetailAvailable;
return this.panelDetail != null;
}

/**
* Getter for {@link #panelDetail}.
*
* @return {@link #panelDetail} value
*/
public JPanel getDetailPanel() {
return this.panelDetail;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static Icon getShortcutIcon() {
}


public static void showPopup(JFrame frame, JPanel panel, String title) {
public static void showPopup(final JFrame frame, final JPanel panel, final String title) {
if (frame == null || panel == null) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* JAsciiDataViewer.java September 08, 2019, 19:17 PM
*
* Copyright 2019, FreeInternals.org. All rights reserved.
* Use is subject to license terms.
*/
package org.freeinternals.commonlib.ui.binviewer;

import javax.swing.JTextPane;

/**
* Display binary data.
*
* @author Amos Shi
*/
public abstract class DataViewer extends JTextPane {

/**
* Binary data will be displayed.
*/
private byte[] data = null;
/**
* Start index to be high-lighted.
*/
private int selectedStartIndex = 0;
/**
* Length to be high-lighted.
*/
private int selectedLength = 0;

/**
* Constructor.
*/
public DataViewer() {
super();
this.setEditable(false);
this.setBorder(null);
this.setContentType("text/html");
}

/**
* Set the binary data to be displayed.
*
* @param bin Binary data.
*/
public void setData(final byte[] bin) {
this.data = bin;
this.updateContent();
}

/**
* Set the selection part to be high-lighted.
*
* @param startIndex Start index to be high-lighted
* @param length Length to be high-lighted
*/
public void setSelection(final int startIndex, final int length) {
this.selectedStartIndex = startIndex;
this.selectedLength = length;
this.updateContent();
}

/**
* Return value of {@link #data}.
*
* @return Value of {@link #data}
*/
protected byte[] getData() {
return this.data;
}

/**
* Return value of {@link #selectedStartIndex}.
*
* @return Value of {@link #selectedStartIndex}
*/
protected int getSelectedStartIndex() {
return this.selectedStartIndex;
}

/**
* Return value of {@link #selectedLength}.
*
* @return Value of {@link #selectedLength}
*/
protected int getSelectedLength() {
return this.selectedLength;
}

protected abstract void updateContent();
}
Loading

0 comments on commit 599c377

Please sign in to comment.