Skip to content

Commit 43b1d32

Browse files
author
Tom Gottfried
committed
Replace deprecated JGoodies API in one dialog
This is a first proof of concept for the replacement of JGoodies with pure Swing.
1 parent 82ca18a commit 43b1d32

File tree

3 files changed

+99
-48
lines changed

3 files changed

+99
-48
lines changed

pom.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,6 @@
7272
<artifactId>jfreechart</artifactId>
7373
<version>1.5.4</version>
7474
</dependency>
75-
<dependency>
76-
<groupId>org.jfree</groupId>
77-
<artifactId>jcommon</artifactId>
78-
<version>1.0.23</version>
79-
</dependency>
8075

8176
<!--jackson-->
8277
<dependency>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* Copyright 2025, Stadt Bielefeld
3+
*
4+
* This file is part of AUIK (Anlagen- und Indirekteinleiter-Kataster).
5+
*
6+
* AUIK is free software: you can redistribute it and/or modify it under
7+
* the terms of the GNU General Public License as published by the
8+
* Free Software Foundation, either version 2 of the License, or (at your
9+
* option) any later version.
10+
*
11+
* AUIK is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
14+
* License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public
17+
* License along with AUIK. If not, see <http://www.gnu.org/licenses/>.
18+
*
19+
* AUIK has been developed by Stadt Bielefeld and Intevation GmbH.
20+
*/
21+
package de.bielefeld.umweltamt.aui.gui;
22+
23+
import java.awt.Component;
24+
25+
import javax.swing.JComponent;
26+
import javax.swing.JLabel;
27+
import javax.swing.JPanel;
28+
import javax.swing.Spring;
29+
import javax.swing.SpringLayout;
30+
31+
/**
32+
* Container for labels and fields.
33+
*
34+
* Fields and labels are displayed in a two-column grid with labels in the
35+
* first column. The column is sized to fit the largest label.
36+
*/
37+
public class Form extends JPanel {
38+
39+
private SpringLayout springLayout = new SpringLayout();
40+
41+
private static final Spring INIT = Spring.constant(0);
42+
private static final Spring PAD = Spring.constant(5);
43+
44+
public Form() {
45+
super();
46+
this.setLayout(springLayout);
47+
}
48+
49+
/**
50+
* Append label and field to form.
51+
* @param label String to put into label
52+
* @param field The field to be added to the form
53+
*/
54+
public void appendField(String label, JComponent field) {
55+
JLabel jLabel = new JLabel(label, JLabel.TRAILING);
56+
jLabel.setLabelFor(field);
57+
this.add(jLabel);
58+
this.add(field);
59+
60+
// Calculate grid cell dimensions
61+
Spring height = INIT, labelWidth = INIT;
62+
for (Component c : this.getComponents()) {
63+
height = Spring.max(height, Spring.height(c));
64+
if (c instanceof JLabel) {
65+
labelWidth = Spring.max(labelWidth, Spring.width(c));
66+
}
67+
}
68+
69+
// Position label-field pairs in in two-column grid
70+
Spring fieldX = Spring.sum(PAD, labelWidth);
71+
Spring y = INIT;
72+
Spring yOffset = Spring.sum(height, PAD);
73+
for (Component c : this.getComponents()) {
74+
SpringLayout.Constraints cons = springLayout.getConstraints(c);
75+
cons.setHeight(height);
76+
cons.setY(y);
77+
if (c instanceof JLabel) {
78+
// Set width for label
79+
cons.setWidth(labelWidth);
80+
} else {
81+
// Position field next to label
82+
cons.setX(fieldX);
83+
84+
// Next row
85+
y = Spring.sum(y, yOffset);
86+
}
87+
}
88+
}
89+
}

src/de/bielefeld/umweltamt/aui/gui/PasswordChangeDialog.java

Lines changed: 10 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,17 @@
2020
*/
2121
package de.bielefeld.umweltamt.aui.gui;
2222

23-
import java.awt.Dimension;
2423
import java.awt.HeadlessException;
2524
import java.util.Arrays;
2625

2726
import javax.swing.JComponent;
28-
import javax.swing.JLabel;
2927
import javax.swing.JOptionPane;
30-
import javax.swing.JPanel;
3128
import javax.swing.JPasswordField;
3229

33-
import com.jgoodies.forms.builder.PanelBuilder;
34-
import com.jgoodies.forms.factories.Paddings;
35-
import com.jgoodies.forms.layout.CellConstraints;
36-
import com.jgoodies.forms.layout.FormLayout;
37-
3830
import org.hibernate.HibernateException;
3931
import org.hibernate.Session;
4032
import org.hibernate.Transaction;
4133
import org.hibernate.query.NativeQuery;
42-
import org.jfree.ui.tabbedui.VerticalLayout;
4334

4435
import de.bielefeld.umweltamt.aui.HauptFrame;
4536
import de.bielefeld.umweltamt.aui.HibernateSessionFactory;
@@ -54,10 +45,6 @@ public class PasswordChangeDialog extends OkCancelDialog {
5445
/** Logging */
5546
private static final AuikLogger log = AuikLogger.getLogger();
5647

57-
private JLabel currentPasswordLabel;
58-
private JLabel newPasswordLabel;
59-
private JLabel newPasswordConfirmLabel;
60-
6148
private JPasswordField currentPasswordField;
6249
private JPasswordField newPasswordField;
6350
private JPasswordField newPasswordConfirmField;
@@ -74,38 +61,18 @@ public PasswordChangeDialog(HauptFrame owner){
7461

7562
@Override
7663
protected JComponent buildContentArea() {
77-
currentPasswordLabel = new JLabel("Aktuelles Passwort:");
78-
newPasswordLabel = new JLabel("Neues Passwort:");
79-
newPasswordConfirmLabel = new JLabel("Passwort bestätigen:");
80-
currentPasswordField = new JPasswordField();
81-
newPasswordField = new JPasswordField();
82-
newPasswordConfirmField = new JPasswordField();
83-
84-
currentPasswordField.setPreferredSize(new Dimension(150, 22));
64+
final int nColumns = 24;
65+
currentPasswordField = new JPasswordField(nColumns);
66+
newPasswordField = new JPasswordField(nColumns);
67+
newPasswordConfirmField = new JPasswordField(nColumns);
8568

8669
//Create form
87-
FormLayout layout = new FormLayout(
88-
"right:pref, 4dlu, pref:grow, 4dlu, pref", // Spalten
89-
"pref:grow, 3dlu, pref, 3dlu, pref, 3dlu, p" // Zeilen
90-
);
91-
92-
JPanel contentPanel = new JPanel(new VerticalLayout());
93-
94-
layout.setRowGroups(new int[][]{{1, 3, 5}});
95-
96-
PanelBuilder builder = new PanelBuilder(layout);
97-
CellConstraints cc = new CellConstraints();
98-
builder.add(currentPasswordLabel, cc.xy(1, 1));
99-
builder.add(currentPasswordField, cc.xy(3, 1));
100-
builder.add(newPasswordLabel, cc.xy(1, 3));
101-
builder.add(newPasswordField, cc.xy(3, 3));
102-
builder.add(newPasswordConfirmLabel, cc.xy(1, 5));
103-
builder.add(newPasswordConfirmField, cc.xy(3, 5));
104-
JPanel formPanel = builder.getPanel();
105-
formPanel.setBorder(Paddings.DIALOG);
106-
contentPanel.add(formPanel);
107-
108-
return contentPanel;
70+
Form formPanel = new Form();
71+
formPanel.appendField("Aktuelles Passwort:", currentPasswordField);
72+
formPanel.appendField("Neues Passwort:", newPasswordField);
73+
formPanel.appendField("Passwort bestätigen:", newPasswordConfirmField);
74+
75+
return formPanel;
10976
}
11077

11178
/**

0 commit comments

Comments
 (0)