Skip to content

Commit afba3e5

Browse files
committed
Code quality improvements
* Method extractions * Factorization of icon loading logic
1 parent be03758 commit afba3e5

File tree

11 files changed

+512
-493
lines changed

11 files changed

+512
-493
lines changed

src/main/java/net/sourceforge/dionysus/gui/AboutDialog.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.awt.Insets;
2525

2626
import javax.swing.Box;
27-
import javax.swing.ImageIcon;
2827
import javax.swing.JButton;
2928
import javax.swing.JDialog;
3029
import javax.swing.JLabel;
@@ -47,90 +46,88 @@ public AboutDialog() {
4746
setModal(true);
4847
setSize(400, 420);
4948
setLocationRelativeTo(null);
50-
GridBagLayout gridBagLayout = new GridBagLayout();
49+
final GridBagLayout gridBagLayout = new GridBagLayout();
5150
gridBagLayout.columnWidths = new int[] { 444, 0 };
5251
gridBagLayout.rowHeights = new int[] { 249, 23, 0 };
5352
gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
5453
gridBagLayout.rowWeights = new double[] { 1.0, 0.0, Double.MIN_VALUE };
5554
getContentPane().setLayout(gridBagLayout);
5655

57-
JPanel panel = new JPanel();
58-
GridBagConstraints gbc_panel = new GridBagConstraints();
56+
final JPanel panel = new JPanel();
57+
final GridBagConstraints gbc_panel = new GridBagConstraints();
5958
gbc_panel.insets = new Insets(0, 0, 5, 0);
6059
gbc_panel.fill = GridBagConstraints.BOTH;
6160
gbc_panel.gridx = 0;
6261
gbc_panel.gridy = 0;
6362
getContentPane().add(panel, gbc_panel);
64-
GridBagLayout gbl_panel = new GridBagLayout();
63+
final GridBagLayout gbl_panel = new GridBagLayout();
6564
gbl_panel.columnWidths = new int[] { 0, 0, 0 };
6665
gbl_panel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0 };
6766
gbl_panel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
6867
gbl_panel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
6968
panel.setLayout(gbl_panel);
7069

71-
JLabel lblLogo = new JLabel(Messages.getString("AboutDialog.1")); //$NON-NLS-1$
72-
GridBagConstraints gbc_lblLogo = new GridBagConstraints();
70+
final JLabel lblLogo = new JLabel(Messages.getString("AboutDialog.1")); //$NON-NLS-1$
71+
final GridBagConstraints gbc_lblLogo = new GridBagConstraints();
7372
gbc_lblLogo.insets = new Insets(0, 0, 5, 5);
7473
gbc_lblLogo.gridx = 0;
7574
gbc_lblLogo.gridy = 0;
7675
panel.add(lblLogo, gbc_lblLogo);
7776

78-
JLabel lblSoftwareName = new JLabel(Constants.SOFTWARE_NAME + Messages.getString("AboutDialog.2") //$NON-NLS-1$
77+
final JLabel lblSoftwareName = new JLabel(Constants.SOFTWARE_NAME + Messages.getString("AboutDialog.2") //$NON-NLS-1$
7978
+ Constants.SOFTWARE_VERSION + Messages.getString("AboutDialog.3") + Constants.SOFTWARE_VERSION_NICK); //$NON-NLS-1$
8079
lblSoftwareName.setHorizontalAlignment(SwingConstants.LEFT);
8180
lblSoftwareName.setFont(new Font(Messages.getString("AboutDialog.4"), Font.BOLD, 20)); //$NON-NLS-1$
82-
GridBagConstraints gbc_lblSoftwareName = new GridBagConstraints();
81+
final GridBagConstraints gbc_lblSoftwareName = new GridBagConstraints();
8382
gbc_lblSoftwareName.anchor = GridBagConstraints.WEST;
8483
gbc_lblSoftwareName.insets = new Insets(0, 0, 5, 0);
8584
gbc_lblSoftwareName.gridx = 1;
8685
gbc_lblSoftwareName.gridy = 0;
8786
panel.add(lblSoftwareName, gbc_lblSoftwareName);
8887

89-
JLabel lblDesc = new JLabel(Messages.getString("AboutDialog.5")); //$NON-NLS-1$
90-
GridBagConstraints gbc_lblDesc = new GridBagConstraints();
88+
final JLabel lblDesc = new JLabel(Messages.getString("AboutDialog.5")); //$NON-NLS-1$
89+
final GridBagConstraints gbc_lblDesc = new GridBagConstraints();
9190
gbc_lblDesc.anchor = GridBagConstraints.WEST;
9291
gbc_lblDesc.insets = new Insets(0, 0, 5, 0);
9392
gbc_lblDesc.gridx = 1;
9493
gbc_lblDesc.gridy = 1;
9594
panel.add(lblDesc, gbc_lblDesc);
9695

97-
JLabel lblCopyright = new JLabel(Messages.getString("AboutDialog.6") //$NON-NLS-1$
96+
final JLabel lblCopyright = new JLabel(Messages.getString("AboutDialog.6") //$NON-NLS-1$
9897
+ Messages.getString("AboutDialog.7")); //$NON-NLS-1$
9998
lblCopyright.setHorizontalAlignment(SwingConstants.LEFT);
100-
GridBagConstraints gbc_lblCopyright = new GridBagConstraints();
99+
final GridBagConstraints gbc_lblCopyright = new GridBagConstraints();
101100
gbc_lblCopyright.insets = new Insets(0, 0, 5, 0);
102101
gbc_lblCopyright.anchor = GridBagConstraints.WEST;
103102
gbc_lblCopyright.gridx = 1;
104103
gbc_lblCopyright.gridy = 2;
105104
panel.add(lblCopyright, gbc_lblCopyright);
106105

107-
JLabel lblIconCopyright = new JLabel(Messages.getString("AboutDialog.8")); //$NON-NLS-1$
106+
final JLabel lblIconCopyright = new JLabel(Messages.getString("AboutDialog.8")); //$NON-NLS-1$
108107
lblIconCopyright.setHorizontalAlignment(SwingConstants.LEFT);
109-
GridBagConstraints gbc_lblIconCopyright = new GridBagConstraints();
108+
final GridBagConstraints gbc_lblIconCopyright = new GridBagConstraints();
110109
gbc_lblIconCopyright.anchor = GridBagConstraints.WEST;
111110
gbc_lblIconCopyright.insets = new Insets(0, 0, 5, 0);
112111
gbc_lblIconCopyright.gridx = 1;
113112
gbc_lblIconCopyright.gridy = 3;
114113
panel.add(lblIconCopyright, gbc_lblIconCopyright);
115114

116-
Component verticalStrut = Box.createVerticalStrut(20);
117-
GridBagConstraints gbc_verticalStrut = new GridBagConstraints();
115+
final Component verticalStrut = Box.createVerticalStrut(20);
116+
final GridBagConstraints gbc_verticalStrut = new GridBagConstraints();
118117
gbc_verticalStrut.insets = new Insets(0, 0, 5, 0);
119118
gbc_verticalStrut.gridx = 1;
120119
gbc_verticalStrut.gridy = 4;
121120
panel.add(verticalStrut, gbc_verticalStrut);
122121

123-
JLabel lblLicenseInfo = new JLabel(Messages.getString("AboutDialog.9")); //$NON-NLS-1$
124-
GridBagConstraints gbc_lblLicenseInfo = new GridBagConstraints();
122+
final JLabel lblLicenseInfo = new JLabel(Messages.getString("AboutDialog.9")); //$NON-NLS-1$
123+
final GridBagConstraints gbc_lblLicenseInfo = new GridBagConstraints();
125124
gbc_lblLicenseInfo.fill = GridBagConstraints.HORIZONTAL;
126125
gbc_lblLicenseInfo.gridx = 1;
127126
gbc_lblLicenseInfo.gridy = 5;
128127
panel.add(lblLicenseInfo, gbc_lblLicenseInfo);
129128

130-
ImageIcon ok = new ImageIcon(getClass().getResource(Messages.getString("AboutDialog.10"))); //$NON-NLS-1$
131-
132-
JButton btnOK = new JButton(Messages.getString("AboutDialog.11"), ok); //$NON-NLS-1$
133-
GridBagConstraints gbc_btnOK = new GridBagConstraints();
129+
final JButton btnOK = new JButton(Messages.getString("AboutDialog.11"), Constants.ok); //$NON-NLS-1$
130+
final GridBagConstraints gbc_btnOK = new GridBagConstraints();
134131
gbc_btnOK.anchor = GridBagConstraints.NORTH;
135132
gbc_btnOK.gridx = 0;
136133
gbc_btnOK.gridy = 1;

src/main/java/net/sourceforge/dionysus/gui/Constants.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package net.sourceforge.dionysus.gui;
1818

19+
import javax.swing.ImageIcon;
20+
1921
/**
2022
* Some constants for use across the software
2123
*/
@@ -28,11 +30,20 @@ public final class Constants {
2830
/** Version nickname */
2931
public static final String SOFTWARE_VERSION_NICK = "\"Riesling\"";
3032

33+
// IMAGES
34+
public static final ImageIcon plus = new ImageIcon(Constants.class.getResource("/list-add.png"));
35+
public static final ImageIcon minus = new ImageIcon(Constants.class.getResource("/list-remove.png"));
36+
public static final ImageIcon edit = new ImageIcon(Constants.class.getResource("/gtk-edit.png"));
37+
public static final ImageIcon ok = new ImageIcon(Constants.class.getResource("/gtk-ok.png"));
38+
public static final ImageIcon cancel = new ImageIcon(Constants.class.getResource("/gtk-cancel.png"));
39+
public static final ImageIcon exit = new ImageIcon(Constants.class.getResource("/application-exit.png"));
40+
public static final ImageIcon convert = new ImageIcon(Constants.class.getResource("/gtk-convert.png"));
41+
public static final ImageIcon about = new ImageIcon(Constants.class.getResource("/dialog-information.png"));
42+
3143
/**
3244
* Private constructor
3345
*/
3446
private Constants() {
35-
super();
3647
}
3748

3849
}

0 commit comments

Comments
 (0)