Skip to content

Commit a937e09

Browse files
committed
Fix some of the SonarQube issues
1 parent e6998d6 commit a937e09

File tree

10 files changed

+38
-51
lines changed

10 files changed

+38
-51
lines changed

src/main/java/com/itextpdf/rups/controller/PdfReaderController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ This file is part of the iText (R) project.
7979

8080
import java.awt.Color;
8181
import java.awt.event.KeyListener;
82+
import java.util.ArrayDeque;
83+
import java.util.Deque;
8284
import java.util.Stack;
8385
import java.util.function.Consumer;
8486
import javax.swing.JPanel;
@@ -145,7 +147,7 @@ public class PdfReaderController implements IPdfObjectPanelEventListener, IRupsE
145147
*/
146148
protected PlainText text;
147149

148-
private final Stack<IconTreeNode> highlights = new Stack<>();
150+
private final Deque<IconTreeNode> highlights = new ArrayDeque<>();
149151

150152
private final PdfSyntaxParser parser = new PdfSyntaxParser();
151153

@@ -359,7 +361,7 @@ protected void highlightChanges(CompareTool.CompareResult compareResult) {
359361
}
360362

361363
protected void clearHighlights() {
362-
while (!highlights.empty()) {
364+
while (!highlights.isEmpty()) {
363365
highlights.pop().restoreDefaultTextColor();
364366
}
365367
}

src/main/java/com/itextpdf/rups/view/Console.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ This file is part of the iText (R) project.
6363
/**
6464
* A Class that is used for displaying logger messages to a {@link JTextPane}.
6565
*/
66-
public class Console implements IRupsEventListener {
66+
public final class Console implements IRupsEventListener {
6767

6868
/**
6969
* Single Console instance.

src/main/java/com/itextpdf/rups/view/RupsMenuBar.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,6 @@ This file is part of the iText (R) project.
6565

6666
public final class RupsMenuBar extends JMenuBar implements IRupsEventListener {
6767
private final IRupsController controller;
68-
/**
69-
* The action needed to open a file.
70-
*/
71-
private final PdfFileOpenAction fileOpenAction;
7268
/**
7369
* The Preferences Window
7470
*/
@@ -87,13 +83,11 @@ public RupsMenuBar(RupsController controller) {
8783

8884
preferencesWindow = new PreferencesWindow();
8985

90-
fileOpenAction = new PdfFileOpenAction(controller::openNewFile, controller.getMasterComponent());
91-
9286
final JMenu file = new JMenu(Language.MENU_BAR_FILE.getString());
9387
addItem(
9488
file,
9589
Language.MENU_BAR_OPEN,
96-
fileOpenAction,
90+
new PdfFileOpenAction(controller::openNewFile, controller.getMasterComponent()),
9791
KeyStroke.getKeyStroke('O', InputEvent.CTRL_DOWN_MASK)
9892
);
9993
file.add(createOpenRecentSubMenu());

src/main/java/com/itextpdf/rups/view/itext/CloseableTabComponent.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ This file is part of the iText (R) project.
6767
* </p>
6868
*/
6969
public final class CloseableTabComponent extends JPanel {
70+
private static final int SEPARATOR_WIDTH = 8;
71+
7072
private final List<IntConsumer> closeButtonListeners = new ArrayList<>();
7173

7274
public CloseableTabComponent(JTabbedPane parent) {
@@ -88,7 +90,7 @@ public String getText() {
8890

8991
final JButton button = new CloseButton();
9092
button.addActionListener((ActionEvent e) -> {
91-
final int idx = parent.indexOfTabComponent(CloseableTabComponent.this);
93+
final int idx = parent.indexOfTabComponent(this);
9294
if (idx >= 0) {
9395
for (final IntConsumer listener : closeButtonListeners) {
9496
listener.accept(idx);
@@ -97,7 +99,7 @@ public String getText() {
9799
});
98100

99101
add(label);
100-
add(Box.createHorizontalStrut(8));
102+
add(Box.createHorizontalStrut(SEPARATOR_WIDTH));
101103
add(button);
102104
}
103105

src/main/java/com/itextpdf/rups/view/itext/FormTree.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,16 @@ public final class FormTree extends JTree implements TreeSelectionListener, IRup
7575
/**
7676
* Nodes in the FormTree correspond with nodes in the main PdfTree.
7777
*/
78-
private PdfReaderController controller;
78+
private final PdfReaderController controller;
7979

80-
/**
81-
* If the form is an XFA form, the XML file is stored in this object.
82-
*/
83-
private XfaFile xfaFile;
8480
/**
8581
* Treeview of the XFA file.
8682
*/
87-
private XfaTree xfaTree;
83+
private final XfaTree xfaTree;
8884
/**
8985
* Textview of the XFA file.
9086
*/
91-
private XfaTextArea xfaTextArea;
87+
private final XfaTextArea xfaTextArea;
9288

9389
/**
9490
* Creates a new FormTree.
@@ -193,7 +189,6 @@ void loadXfa(TreeNodeFactory factory, XfaTreeNode form_node, PdfObjectTreeNode o
193189

194190
@Override
195191
public void handleCloseDocument() {
196-
xfaFile = null;
197192
xfaTree.clear();
198193
xfaTextArea.clear();
199194
setModel(new DefaultTreeModel(new FormTreeNode()));
@@ -223,7 +218,7 @@ public void handleOpenDocument(ObjectLoader loader) {
223218
loadXfa(factory, node, xfa);
224219
root.add(node);
225220
try {
226-
xfaFile = new XfaFile(node);
221+
final XfaFile xfaFile = new XfaFile(node);
227222
xfaTree.load(xfaFile);
228223
xfaTextArea.load(xfaFile);
229224
} catch (IOException e) {

src/main/java/com/itextpdf/rups/view/itext/OutlineTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public final class OutlineTree extends JTree implements TreeSelectionListener, I
6666
/**
6767
* Nodes in the FormTree correspond with nodes in the main PdfTree.
6868
*/
69-
private PdfReaderController controller;
69+
private final PdfReaderController controller;
7070

7171
/**
7272
* Creates a new outline tree.

src/main/java/com/itextpdf/rups/view/itext/PdfObjectPanel.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ public final class PdfObjectPanel implements IRupsEventListener {
7979
private static final String ADD_ICON = "add.png";
8080
private static final String CROSS_ICON = "cross.png";
8181

82-
/**
83-
* Name of a panel in the CardLayout.
84-
*/
85-
private static final String TABLE = Language.TABLE.getString();
86-
87-
/**
88-
* Name of a panel in the CardLayout.
89-
*/
90-
private static final String TEXT = Language.TEXT.getString();
91-
9282
/**
9383
* The layout that will show the info about the PDF object that is being analyzed.
9484
*/
@@ -122,13 +112,13 @@ public PdfObjectPanel() {
122112
// dictionary / array / stream
123113
final JScrollPane dictScrollPane = new JScrollPane();
124114
dictScrollPane.setViewportView(table);
125-
panel.add(dictScrollPane, TABLE);
115+
panel.add(dictScrollPane);
126116

127117
// number / string / ...
128118
final JScrollPane textScrollPane = new JScrollPane();
129119
textScrollPane.setViewportView(text);
130120
text.setEditable(false);
131-
panel.add(textScrollPane, TEXT);
121+
panel.add(textScrollPane);
132122

133123
table.addMouseListener(new JTableButtonMouseListener());
134124
}
@@ -144,7 +134,7 @@ public void clear() {
144134
target = null;
145135
table.setModel(new DefaultTableModel());
146136
text.setText(null);
147-
layout.show(panel, TEXT);
137+
layout.show(panel, Language.TEXT.getString());
148138
}
149139

150140
@Override
@@ -190,7 +180,7 @@ public void render(PdfObjectTreeNode node, PdfSyntaxParser parser) {
190180
if (object == null) {
191181
text.setText(null);
192182
table.setModel(new DefaultTableModel());
193-
layout.show(panel, TEXT);
183+
layout.show(panel, Language.TEXT.getString());
194184
panel.repaint();
195185
text.repaint();
196186
return;
@@ -208,7 +198,7 @@ public void render(PdfObjectTreeNode node, PdfSyntaxParser parser) {
208198
DictionaryTableModelButton.class,
209199
new DictionaryTableModelButton(IconFetcher.getIcon(CROSS_ICON), IconFetcher.getIcon(ADD_ICON))
210200
);
211-
layout.show(panel, TABLE);
201+
layout.show(panel, Language.TABLE.getString());
212202
panel.repaint();
213203
break;
214204
case PdfObject.ARRAY:
@@ -221,16 +211,16 @@ public void render(PdfObjectTreeNode node, PdfSyntaxParser parser) {
221211
DictionaryTableModelButton.class,
222212
new DictionaryTableModelButton(IconFetcher.getIcon(CROSS_ICON), IconFetcher.getIcon(ADD_ICON))
223213
);
224-
layout.show(panel, TABLE);
214+
layout.show(panel, Language.TABLE.getString());
225215
panel.repaint();
226216
break;
227217
case PdfObject.STRING:
228218
text.setText(((PdfString) object).toUnicodeString());
229-
layout.show(panel, TEXT);
219+
layout.show(panel, Language.TEXT.getString());
230220
break;
231221
default:
232222
text.setText(object.toString());
233-
layout.show(panel, TEXT);
223+
layout.show(panel, Language.TEXT.getString());
234224
break;
235225
}
236226
}
@@ -243,6 +233,12 @@ private AbstractPdfObjectPanelTableModel getTableModel() {
243233
return null;
244234
}
245235

236+
private void fireEvent(Consumer<IPdfObjectPanelEventListener> func) {
237+
for (final IPdfObjectPanelEventListener listener: eventListeners) {
238+
func.accept(listener);
239+
}
240+
}
241+
246242
private class JTableButtonMouseListener extends MouseAdapter {
247243
public void mouseClicked(MouseEvent e) {
248244
final int selectedColumn = table.getSelectedColumn();
@@ -314,10 +310,4 @@ public void tableChanged(TableModelEvent e) {
314310
}
315311
}
316312
}
317-
318-
private void fireEvent(Consumer<IPdfObjectPanelEventListener> func) {
319-
for (final IPdfObjectPanelEventListener listener: eventListeners) {
320-
func.accept(listener);
321-
}
322-
}
323313
}

src/main/java/com/itextpdf/rups/view/itext/PlainText.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ public final class PlainText extends ReadOnlyTextArea implements IRupsEventListe
5555

5656
private boolean loaded = false;
5757

58-
private IPdfFile file;
58+
private IPdfFile file = null;
5959

60-
private SwingWorker<String, Object> worker;
60+
private SwingWorker<String, Object> worker = null;
61+
62+
public PlainText() {
63+
// Empty
64+
}
6165

6266
public void openPlainText() {
6367
if (file == null || loaded) {

src/main/java/com/itextpdf/rups/view/itext/StructureTree.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public final class StructureTree extends JTree implements TreeSelectionListener,
8585
/**
8686
* Nodes in the FormTree correspond with nodes in the main PdfTree.
8787
*/
88-
private PdfReaderController controller;
88+
private final PdfReaderController controller;
8989

9090
private ObjectLoader loader;
9191

src/main/java/com/itextpdf/rups/view/itext/SyntaxHighlightedStreamPane.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public final class SyntaxHighlightedStreamPane extends JScrollPane implements IR
9797
*/
9898
private final JSyntaxPane text;
9999

100-
private StreamPanelContextMenu popupMenu;
100+
private final StreamPanelContextMenu popupMenu;
101101

102102
private PdfObjectTreeNode target;
103103

104-
private UndoManager manager;
104+
private final UndoManager manager;
105105

106106
//Todo: Remove that field after proper application structure will be implemented.
107107
private final PdfReaderController controller;

0 commit comments

Comments
 (0)