Skip to content

Commit 3bf8db4

Browse files
committed
PMD: AccessorMethodGeneration
1 parent 56a8aa5 commit 3bf8db4

File tree

13 files changed

+135
-133
lines changed

13 files changed

+135
-133
lines changed

SameSizeButtons/src/java/example/MainPanel.java

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,46 @@
77
import javax.swing.*;
88

99
public final class MainPanel extends JPanel {
10-
private final JCheckBox borderCheck = new JCheckBox("OptionPane.buttonAreaBorder");
11-
private final JOptionPane op = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
12-
13-
public MainPanel() {
10+
private MainPanel() {
1411
super(new BorderLayout());
1512

16-
JPanel p1 = new JPanel();
17-
p1.add(new JButton(new AbstractAction("default") {
18-
@Override public void actionPerformed(ActionEvent e) {
19-
UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", false);
20-
//JOptionPane.showConfirmDialog(getRootPane(), "message");
21-
//JOptionPane pane1 = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
22-
UIDefaults d = new UIDefaults();
23-
d.put("OptionPane.sameSizeButtons", false);
24-
op.putClientProperty("Nimbus.Overrides", d);
25-
op.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
26-
SwingUtilities.updateComponentTreeUI(op);
27-
op.createDialog(getRootPane(), "title").setVisible(true);
28-
}
29-
}));
30-
p1.add(new JButton(new AbstractAction("sameSizeButtons") {
31-
@Override public void actionPerformed(ActionEvent e) {
32-
//UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", true);
33-
//UIManager.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10));
34-
//JOptionPane.showConfirmDialog(getRootPane(), "message");
35-
UIDefaults d = new UIDefaults();
36-
if (borderCheck.isSelected()) {
37-
d.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10));
38-
} else {
39-
d.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder());
40-
}
41-
d.put("OptionPane.sameSizeButtons", true);
42-
op.putClientProperty("Nimbus.Overrides", d);
43-
op.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
44-
SwingUtilities.updateComponentTreeUI(op);
45-
op.createDialog(getRootPane(), "title").setVisible(true);
13+
JCheckBox borderCheck = new JCheckBox("OptionPane.buttonAreaBorder");
14+
JOptionPane op = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
15+
16+
JButton button1 = new JButton("default");
17+
button1.addActionListener(e -> {
18+
UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", false);
19+
//JOptionPane.showConfirmDialog(getRootPane(), "message");
20+
//JOptionPane pane1 = new JOptionPane("message", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION);
21+
UIDefaults d = new UIDefaults();
22+
d.put("OptionPane.sameSizeButtons", false);
23+
op.putClientProperty("Nimbus.Overrides", d);
24+
op.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
25+
SwingUtilities.updateComponentTreeUI(op);
26+
op.createDialog(getRootPane(), "title").setVisible(true);
27+
});
28+
29+
JButton button2 = new JButton("sameSizeButtons");
30+
button2.addActionListener(e -> {
31+
//UIManager.getLookAndFeelDefaults().put("OptionPane.sameSizeButtons", true);
32+
//UIManager.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10));
33+
//JOptionPane.showConfirmDialog(getRootPane(), "message");
34+
UIDefaults d = new UIDefaults();
35+
if (borderCheck.isSelected()) {
36+
d.put("OptionPane.buttonAreaBorder", BorderFactory.createLineBorder(Color.RED, 10));
37+
} else {
38+
d.put("OptionPane.buttonAreaBorder", BorderFactory.createEmptyBorder());
4639
}
47-
}));
40+
d.put("OptionPane.sameSizeButtons", true);
41+
op.putClientProperty("Nimbus.Overrides", d);
42+
op.putClientProperty("Nimbus.Overrides.InheritDefaults", true);
43+
SwingUtilities.updateComponentTreeUI(op);
44+
op.createDialog(getRootPane(), "title").setVisible(true);
45+
});
46+
47+
JPanel p1 = new JPanel();
48+
p1.add(button1);
49+
p1.add(button2);
4850

4951
JPanel p2 = new JPanel();
5052
p2.add(borderCheck);

ScrollBarSearchHighlighter/src/java/example/MainPanel.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
import javax.swing.text.*;
1313
import com.sun.java.swing.plaf.windows.WindowsScrollBarUI;
1414

15-
public final class MainPanel extends JPanel {
16-
private static final String PATTERN = "Swing";
17-
private static final String INITTXT =
15+
public class MainPanel extends JPanel {
16+
protected static final String PATTERN = "Swing";
17+
protected static final String INITTXT =
1818
"Trail: Creating a GUI with JFC/Swing\n"
1919
+ "Lesson: Learning Swing by Example\n"
2020
+ "This lesson explains the concepts you need to\n"
@@ -29,23 +29,24 @@ public final class MainPanel extends JPanel {
2929
+ " so you can test yourself on what you've learned.\n"
3030
+ "http://docs.oracle.com/javase/tutorial/uiswing/learn/index.html\n";
3131

32-
private final transient Highlighter.HighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
33-
private final JTextArea textArea = new JTextArea();
34-
private final JScrollPane scroll = new JScrollPane(textArea);
35-
private final JScrollBar scrollbar = new JScrollBar(Adjustable.VERTICAL);
36-
// private final JScrollBar scrollbar = new JScrollBar(Adjustable.VERTICAL) {
32+
protected final transient Highlighter.HighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(Color.YELLOW);
33+
protected final JTextArea textArea = new JTextArea();
34+
protected final JScrollPane scroll = new JScrollPane(textArea);
35+
protected final JScrollBar scrollbar = new JScrollBar(Adjustable.VERTICAL);
36+
// protected final JScrollBar scrollbar = new JScrollBar(Adjustable.VERTICAL) {
3737
// @Override public Dimension getPreferredSize() {
3838
// Dimension d = super.getPreferredSize();
3939
// d.width += 4; //getInsets().left;
4040
// return d;
4141
// }
4242
// };
43-
private final JCheckBox check = new JCheckBox(new AbstractAction("LineWrap") {
43+
protected final JCheckBox check = new JCheckBox(new AbstractAction("LineWrap") {
4444
@Override public void actionPerformed(ActionEvent e) {
4545
JCheckBox c = (JCheckBox) e.getSource();
4646
textArea.setLineWrap(c.isSelected());
4747
}
4848
});
49+
4950
public MainPanel() {
5051
super(new BorderLayout());
5152
textArea.setEditable(false);

SearchBarLayoutComboBox/src/java/example/BasicSearchBarComboBoxUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public void unconfigureLoupeButton() {
171171
@Override protected LayoutManager createLayoutManager() {
172172
return new SearchBarLayout();
173173
}
174-
private static Icon makeRolloverIcon(Icon srcIcon) {
174+
protected static Icon makeRolloverIcon(Icon srcIcon) {
175175
RescaleOp op = new RescaleOp(
176176
new float[] {1.2f, 1.2f, 1.2f, 1f},
177177
new float[] {0f, 0f, 0f, 0f}, null);

SecondaryLoop/src/java/example/MainPanel.java

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,37 @@
99
import javax.swing.plaf.LayerUI;
1010

1111
public final class MainPanel extends JPanel {
12-
private final DisableInputLayerUI<JComponent> layerUI = new DisableInputLayerUI<>();
13-
public MainPanel() {
12+
private MainPanel() {
1413
super(new BorderLayout());
14+
15+
DisableInputLayerUI<JComponent> layerUI = new DisableInputLayerUI<>();
16+
JButton button = new JButton("Stop 5sec");
17+
button.addActionListener(e -> {
18+
layerUI.setInputBlock(true);
19+
SecondaryLoop loop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
20+
Thread work = new Thread() {
21+
@Override public void run() {
22+
try {
23+
Thread.sleep(5000);
24+
} catch (InterruptedException ex) {
25+
ex.printStackTrace();
26+
}
27+
layerUI.setInputBlock(false);
28+
loop.exit();
29+
}
30+
};
31+
work.start();
32+
loop.enter();
33+
});
34+
1535
JPanel p = new JPanel();
1636
p.add(new JCheckBox());
1737
p.add(new JTextField(10));
18-
p.add(new JButton(new AbstractAction("Stop 5sec") {
19-
@Override public void actionPerformed(ActionEvent e) {
20-
layerUI.setInputBlock(true);
21-
final SecondaryLoop loop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();
22-
Thread work = new Thread() {
23-
@Override public void run() {
24-
doInBackground();
25-
layerUI.setInputBlock(false);
26-
loop.exit();
27-
}
28-
};
29-
work.start();
30-
loop.enter();
31-
}
32-
}));
38+
p.add(button);
3339
add(new JLayer<>(p, layerUI), BorderLayout.NORTH);
3440
add(new JScrollPane(new JTextArea("dummy")));
3541
setPreferredSize(new Dimension(320, 240));
3642
}
37-
private void doInBackground() {
38-
try {
39-
Thread.sleep(5000);
40-
} catch (InterruptedException ex) {
41-
ex.printStackTrace();
42-
}
43-
}
4443
public static void main(String... args) {
4544
EventQueue.invokeLater(new Runnable() {
4645
@Override public void run() {

SelectAllButton/src/java/example/MainPanel.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@
77
import javax.swing.*;
88
import javax.swing.table.*;
99

10-
public final class MainPanel extends JPanel {
11-
private final String[] columnNames = {"String", "Integer", "Boolean"};
12-
private final Object[][] data = {
10+
public class MainPanel extends JPanel {
11+
protected final String[] columnNames = {"String", "Integer", "Boolean"};
12+
protected final Object[][] data = {
1313
{"aaa", 12, true}, {"bbb", 5, false},
1414
{"CCC", 92, true}, {"DDD", 0, false}
1515
};
16-
private final TableModel model = new DefaultTableModel(data, columnNames) {
16+
protected final TableModel model = new DefaultTableModel(data, columnNames) {
1717
@Override public Class<?> getColumnClass(int column) {
1818
return getValueAt(0, column).getClass();
1919
}
2020
};
21-
private final JTable table = new JTable(model);
21+
protected final JTable table = new JTable(model);
2222
private final Action selectAllAction = new AbstractAction("selectAll") {
2323
@Override public void actionPerformed(ActionEvent e) {
2424
e.setSource(table);

SelectionColor/src/java/example/MainPanel.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// vim:set fileencoding=utf-8:
44
//@homepage@
55
import java.awt.*;
6-
import java.awt.event.ActionEvent;
76
import java.awt.geom.AffineTransform;
87
import java.awt.image.*;
98
import java.io.IOException;
@@ -20,20 +19,17 @@ public final class MainPanel extends JPanel {
2019
private static final Color SELECTION_COLOR = new Color(0xC86464FF, true);
2120
private final transient Highlighter.HighlightPainter highlightPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(0x64FFFF32, true));
2221
private final JEditorPane area = new JEditorPane();
23-
//private final JTextArea area = new JTextArea();
2422

25-
private final JCheckBox check = new JCheckBox(new AbstractAction("setSelectionColor(#C86464FF)") {
26-
@Override public void actionPerformed(ActionEvent e) {
23+
public MainPanel() {
24+
super(new BorderLayout());
25+
26+
JCheckBox check = new JCheckBox("setSelectionColor(#C86464FF)", true);
27+
check.addActionListener(e -> {
2728
JCheckBox c = (JCheckBox) e.getSource();
2829
//http://docs.oracle.com/javase/7/docs/api/javax/swing/text/JTextComponent.html#setSelectionColor(java.awt.Color)
2930
//DOUBT?: Setting the color to null is the same as setting Color.white.
3031
area.setSelectionColor(c.isSelected() ? SELECTION_COLOR : null);
31-
}
32-
});
33-
34-
public MainPanel() {
35-
super(new BorderLayout());
36-
check.setSelected(true);
32+
});
3733

3834
//http://ateraimemo.com/Swing/StyleSheet.html
3935
StyleSheet styleSheet = new StyleSheet();
@@ -64,6 +60,16 @@ public MainPanel() {
6460
//DefaultHighlighter dh = (DefaultHighlighter) area.getHighlighter();
6561
//dh.setDrawsLayeredHighlights(false);
6662

63+
JToggleButton button = new JToggleButton("highlight");
64+
button.addActionListener(e -> {
65+
JToggleButton t = (JToggleButton) e.getSource();
66+
if (t.isSelected()) {
67+
setHighlight(area, PATTERN);
68+
} else {
69+
area.getHighlighter().removeAllHighlights();
70+
}
71+
});
72+
6773
URL url = getClass().getResource("tokeidai.jpg");
6874
BufferedImage bi = getFilteredImage(url);
6975
JScrollPane scroll = new JScrollPane(area);
@@ -75,16 +81,7 @@ public MainPanel() {
7581
Box box = Box.createHorizontalBox();
7682
box.add(check);
7783
box.add(Box.createHorizontalGlue());
78-
box.add(new JToggleButton(new AbstractAction("highlight") {
79-
@Override public void actionPerformed(ActionEvent e) {
80-
JToggleButton t = (JToggleButton) e.getSource();
81-
if (t.isSelected()) {
82-
setHighlight(area, PATTERN);
83-
} else {
84-
area.getHighlighter().removeAllHighlights();
85-
}
86-
}
87-
}));
84+
box.add(button);
8885
box.add(Box.createHorizontalStrut(2));
8986
add(box, BorderLayout.SOUTH);
9087
setPreferredSize(new Dimension(320, 240));

SelectionKeeper/src/java/example/MainPanel.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import javax.swing.*;
77
import javax.swing.table.*;
88

9-
public final class MainPanel extends JPanel {
9+
public class MainPanel extends JPanel {
1010
private final String[] columnNames = {"String", "Integer", "Boolean"};
1111
private final Object[][] data = {
1212
{"aaa", 12, true}, {"bbb", 5, false},
@@ -18,8 +18,8 @@ public final class MainPanel extends JPanel {
1818
return getValueAt(0, column).getClass();
1919
}
2020
};
21-
private final TableSorter sorter = new TableSorter(model);
22-
private final JTable table = new JTable(sorter) {
21+
protected final TableSorter sorter = new TableSorter(model);
22+
protected final JTable table = new JTable(sorter) {
2323
@Override public void updateUI() {
2424
sorter.setTableHeader(null);
2525
super.updateUI();
@@ -30,7 +30,7 @@ public final class MainPanel extends JPanel {
3030
});
3131
}
3232
};
33-
private MainPanel() {
33+
public MainPanel() {
3434
super(new BorderLayout());
3535
add(new JScrollPane(table));
3636
setPreferredSize(new Dimension(320, 240));

SelectionKeeper/src/java/example/TableSorter.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ public class TableSorter extends AbstractTableModel {
107107

108108
protected TableModel tableModel;
109109

110-
private final List<Row> viewToModel = new ArrayList<>();
111-
private final List<Integer> modelToView = new ArrayList<>();
112-
private final List<Directive> sortingColumns = new ArrayList<>();
110+
protected final List<Row> viewToModel = new ArrayList<>();
111+
protected final List<Integer> modelToView = new ArrayList<>();
112+
protected final List<Directive> sortingColumns = new ArrayList<>();
113113

114114
private JTableHeader tableHeader;
115115
private final transient Map<Class, Comparator> columnComparators = new ConcurrentHashMap<>();
@@ -145,7 +145,7 @@ public TableSorter(TableModel tableModel, JTableHeader tableHeader) {
145145
setTableModel(tableModel);
146146
}
147147

148-
private void clearSortingState() {
148+
protected void clearSortingState() {
149149
viewToModel.clear();
150150
modelToView.clear();
151151
}
@@ -164,8 +164,12 @@ public final void setTableModel(TableModel tableModel) {
164164
this.tableModel.addTableModelListener(tableModelListener);
165165
}
166166

167-
clearSortingState();
168-
fireTableStructureChanged();
167+
EventQueue.invokeLater(new Runnable() {
168+
@Override public void run() {
169+
clearSortingState();
170+
fireTableStructureChanged();
171+
}
172+
});
169173
}
170174

171175
// public JTableHeader getTableHeader() {
@@ -231,7 +235,7 @@ public Icon getHeaderRendererIcon(int column, int size) {
231235
return new Arrow(directive.direction == DESCENDING, size, sortingColumns.indexOf(directive));
232236
}
233237

234-
private void cancelSorting() {
238+
protected void cancelSorting() {
235239
sortingColumns.clear();
236240
sortingStatusChanged();
237241
}
@@ -274,7 +278,7 @@ public int modelIndex(int viewIndex) {
274278
return getViewToModel().get(viewIndex).modelIndex;
275279
}
276280

277-
private List<Integer> getModelToView() {
281+
protected List<Integer> getModelToView() {
278282
if (modelToView.isEmpty()) {
279283
int n = getViewToModel().size();
280284
for (int i = 0; i < n; i++) {

0 commit comments

Comments
 (0)