Skip to content

Commit

Permalink
Encapsulate some fields. Convert some classes to records.
Browse files Browse the repository at this point in the history
  • Loading branch information
DolphFlynn committed Dec 30, 2022
1 parent baaf223 commit 9cdea12
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public class EditorPresenter extends Presenter {

private final List<MutableJOSEObject> mutableJoseObjects;

String message;

private String message;
private boolean selectionChanging;

/**
Expand Down
40 changes: 13 additions & 27 deletions src/main/java/com/blackberry/jwteditor/view/KeysView.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public class KeysView {
private JButton buttonNewOKP;
private JTable tableKeys;

JMenuItem menuItemDelete;
JMenuItem menuItemCopyJWK;
JMenuItem menuItemCopyPEM;
JMenuItem menuItemCopyPublicJWK;
JMenuItem menuItemCopyPublicPEM;
JMenuItem menuItemCopyPassword;
private JMenuItem menuItemDelete;
private JMenuItem menuItemCopyJWK;
private JMenuItem menuItemCopyPEM;
private JMenuItem menuItemCopyPublicJWK;
private JMenuItem menuItemCopyPublicPEM;
private JMenuItem menuItemCopyPassword;

public KeysView(
Window parent,
Expand Down Expand Up @@ -106,7 +106,6 @@ private enum KeysTableColumns {
* Model for the keys table
*/
public static class KeysTableModel extends AbstractTableModel {

private final List<Object[]> data = new ArrayList<>();

public void addRow(Object[] row) {
Expand Down Expand Up @@ -298,12 +297,7 @@ public Window getParent() {
return parent;
}

private static class OneTimeColumnResizeHierarchyListener implements HierarchyListener {
private final JTable table;

private OneTimeColumnResizeHierarchyListener(JTable table) {
this.table = table;
}
private record OneTimeColumnResizeHierarchyListener(JTable table) implements HierarchyListener {

@Override
public void hierarchyChanged(HierarchyEvent e) {
Expand All @@ -326,37 +320,29 @@ public void hierarchyChanged(HierarchyEvent e) {
}
}

private static class AlternateRowBackgroundDecoratingTableCellRenderer implements TableCellRenderer {
private final TableCellRenderer tableCellRenderer;

AlternateRowBackgroundDecoratingTableCellRenderer(TableCellRenderer tableCellRenderer) {
this.tableCellRenderer = tableCellRenderer;
}
private record AlternateRowBackgroundDecoratingTableCellRenderer(
TableCellRenderer tableCellRenderer) implements TableCellRenderer {

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = tableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

if (!isSelected && !hasFocus) {
Color alternateRowColor = UIManager.getColor("Table.alternateRowColor");

if (alternateRowColor != null && row % 2 != 0) {
component.setBackground(alternateRowColor);
component.setBackground(alternateRowColor);
}
}

return component;
}
}

private static class RowHeightDecoratingTableCellRenderer implements TableCellRenderer {
private record RowHeightDecoratingTableCellRenderer(TableCellRenderer tableCellRenderer) implements TableCellRenderer {
private static final int ADDITIONAL_HEIGHT_PIXELS = 5;

private final TableCellRenderer tableCellRenderer;

RowHeightDecoratingTableCellRenderer(TableCellRenderer tableCellRenderer) {
this.tableCellRenderer = tableCellRenderer;
}

@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = tableCellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
int componentHeight = component.getPreferredSize().height;
Expand Down

0 comments on commit 9cdea12

Please sign in to comment.