Skip to content

Commit

Permalink
#4 Code improvement - Spotbugs, SonarLint
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Jul 7, 2021
1 parent 537a35e commit 4f897e0
Show file tree
Hide file tree
Showing 93 changed files with 994 additions and 550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public abstract class DataViewer extends JTextPane {
/**
* Constructor.
*/
public DataViewer() {
DataViewer() {
super();
this.setEditable(false);
this.setBorder(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import java.awt.BorderLayout;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -103,19 +102,12 @@ public final class JBinaryViewer extends JPanel {
*/
public JBinaryViewer() {
this.setLayout(new BorderLayout());
// this.setFont(JBinaryViewer.FONT);
this.addComponentListener(new ComponentResizedAdapter());
this.addMouseWheelListener(new MouseWheelAdapter());

// Vertical Bar
this.vBar = new JScrollBar();
this.vBar.addAdjustmentListener(new AdjustmentListener() {

@Override
public void adjustmentValueChanged(final AdjustmentEvent e) {
updateViewContent();
}
});
this.vBar.addAdjustmentListener((final AdjustmentEvent e) -> updateViewContent());
this.vBar.setVisible(false);

this.add(this.vBar, BorderLayout.EAST);
Expand Down Expand Up @@ -219,12 +211,7 @@ private void updateViewContent() {
diff = (diff > 0) ? diff : 0;
this.vBar.setValue(diff);
}

if (extent > this.rowMax + JBinaryViewer.ROW_EMPTYROW_COUNT) {
this.vBar.setVisible(false);
} else {
this.vBar.setVisible(true);
}
this.vBar.setVisible(extent < this.rowMax + JBinaryViewer.ROW_EMPTYROW_COUNT);

// Revise row viewer, raw data viewer, ASCII data viewer
this.rowViewer.setData(this.vBar.getValue(), extent, this.rowMax);
Expand Down Expand Up @@ -339,6 +326,7 @@ public void mouseWheelMoved(final MouseWheelEvent e) {
class KeyboardAdapter implements KeyListener {

@Override
@SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule
public void keyTyped(final KeyEvent e) {
}

Expand Down Expand Up @@ -377,6 +365,7 @@ public void keyPressed(final KeyEvent e) {
}

@Override
@SuppressWarnings("java:S1186") // Methods should not be empty --- Ignore this rule
public void keyReleased(final KeyEvent e) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

/**
*
Expand All @@ -37,7 +37,7 @@ class JDialogAbout extends JDialog {
*/
JDialogAbout(final Frame owner, final String title) {
super(owner, title);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setModal(true);

this.initComponents();
Expand All @@ -49,9 +49,7 @@ private void initComponents() {
this.setLayout(new FlowLayout());

final JButton buttonClose = new JButton("Close");
buttonClose.addActionListener((final ActionEvent e) -> {
buttonOK_Clicked();
});
buttonClose.addActionListener((final ActionEvent e) -> buttonOKClicked());

// Lay out the labels from top to bottom.
final JPanel listPane = new JPanel();
Expand Down Expand Up @@ -88,7 +86,7 @@ private void initComponents() {

}

private void buttonOK_Clicked() {
private void buttonOKClicked() {
this.setVisible(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumnModel;
Expand All @@ -44,7 +44,7 @@ class JDialogPlugins extends JDialog {
*/
JDialogPlugins(final Frame owner, final String title) {
super(owner, title);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setModal(true);

this.initComponents();
Expand All @@ -56,9 +56,7 @@ private void initComponents() {
this.setLayout(new BorderLayout());

final JButton buttonClose = new JButton("Close");
buttonClose.addActionListener((final ActionEvent e) -> {
buttonOK_Clicked();
});
buttonClose.addActionListener((final ActionEvent e) -> buttonOKClicked());

// Lay out the labels from top to bottom.
final JTable table = new JTable(new PluginsModel());
Expand All @@ -84,7 +82,7 @@ private void initComponents() {
contentPane.add(buttonPane, BorderLayout.PAGE_END);
}

private void buttonOK_Clicked() {
private void buttonOKClicked() {
this.setVisible(false);
}

Expand All @@ -103,8 +101,8 @@ private void resizeColumnWidth(JTable table) {

public static class PluginsModel extends AbstractTableModel {

List<String> columnNames = new LinkedList<>();
List<List<String>> rowData = new LinkedList<>();
transient List<String> columnNames = new LinkedList<>();
transient List<List<String>> rowData = new LinkedList<>();

PluginsModel() {
Map<String, PluginDescriptor> plugins = PluginManager.getPlugins();
Expand All @@ -115,10 +113,10 @@ public static class PluginsModel extends AbstractTableModel {
this.columnNames.add("Extension Description");

// Row Data
for (Map.Entry pair : plugins.entrySet()) {
for (Map.Entry<String, PluginDescriptor> pair : plugins.entrySet()) {
PluginDescriptor value = (PluginDescriptor) pair.getValue();
List<String> row = new LinkedList<>();
row.add(pair.getKey().toString());
row.add(pair.getKey());
row.add(value.getFileFormatClass().getName());
row.add(value.getExtensionDescription());
this.rowData.add(row);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
Expand Down Expand Up @@ -73,17 +72,15 @@ public final class JPanelForTree extends JPanel {
* @param jTree The tree to be contained
* @param frame The parent window
*/
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value="EI_EXPOSE_REP2", justification="We need it")
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "We need it")
public JPanelForTree(final JTree jTree, final JFrame frame) {
if (jTree == null) {
throw new IllegalArgumentException("[tree] cannot be null.");
}

this.tree = jTree;
this.topLevelFrame = frame;
this.tree.addTreeSelectionListener((final javax.swing.event.TreeSelectionEvent evt) -> {
treeSelectionChanged(evt);
});
this.tree.addTreeSelectionListener(this::treeSelectionChanged);

this.toolbar = new JToolBar();
this.toolbarbtnDetails = new JButton("Details");
Expand Down Expand Up @@ -122,43 +119,21 @@ private void layoutComponents() {

private void initToolbar() {
this.toolbar.setRollover(true);
//this.toolbar.setFloatable(false);

// Button: Expand All
final JButton buttonExpandAll = new JButton("Expand All");
buttonExpandAll.addActionListener(new ActionListener() {

@Override
public void actionPerformed(final ActionEvent e) {
toolbarExpandAll();
}
});
buttonExpandAll.addActionListener((final ActionEvent e) -> toolbarExpandAll());
this.toolbar.add(buttonExpandAll);

// Button: Collapse All
final JButton buttonCollapseAll = new JButton("Collapse All");
buttonCollapseAll.addActionListener(new ActionListener() {

@Override
public void actionPerformed(final ActionEvent e) {
toolbarCollapseAll();
}
});
buttonCollapseAll.addActionListener((final ActionEvent e) -> toolbarCollapseAll());
this.toolbar.add(buttonCollapseAll);

// Button: Details
this.toolbarbtnDetails.setVisible(false);
this.toolbarbtnDetails.addActionListener(new ActionListener() {

public void actionPerformed(final ActionEvent e) {
toolbarShowDetails();
}
});
//this.toolbar.addSeparator();
this.toolbarbtnDetails.addActionListener((final ActionEvent e) -> toolbarShowDetails());
this.toolbar.add(this.toolbarbtnDetails);

// Button: Find
//this.toolbar.add(new JButton("Find"));
}

private void toolbarExpandAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public JSplitPaneFile(final File file, final JFrame frame) throws FileFormatExce
this.createAndShowGUI();
}

@SuppressWarnings("java:S3776") // Cognitive Complexity of methods should not be too high
private void createAndShowGUI() {

final DefaultMutableTreeNode root = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
Expand Down
Loading

0 comments on commit 4f897e0

Please sign in to comment.