Skip to content

Commit 90b2c2e

Browse files
committed
Fix missing checkbox in search dialog
1 parent dfe3675 commit 90b2c2e

File tree

2 files changed

+99
-3
lines changed

2 files changed

+99
-3
lines changed

enigma-swing/src/main/java/org/quiltmc/enigma/gui/dialog/SearchDialog.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.quiltmc.enigma.api.translation.representation.entry.FieldEntry;
1515
import org.quiltmc.enigma.api.translation.representation.entry.MethodEntry;
1616
import org.quiltmc.enigma.api.translation.representation.entry.ParentedEntry;
17+
import org.quiltmc.enigma.gui.util.WrapLayout;
1718
import org.quiltmc.enigma.util.I18n;
1819
import org.quiltmc.enigma.gui.search.SearchEntry;
1920
import org.quiltmc.enigma.gui.search.SearchUtil;
@@ -96,7 +97,7 @@ public void changedUpdate(DocumentEvent e) {
9697
this.onlyExactMatchesCheckbox.addActionListener(e -> this.updateList());
9798

9899
JPanel checkboxes = new JPanel();
99-
checkboxes.setLayout(new FlowLayout(FlowLayout.CENTER));
100+
checkboxes.setLayout(new WrapLayout(FlowLayout.CENTER));
100101

101102
this.classesCheckBox = new JCheckBox(I18n.translate("prompt.search.classes"));
102103
this.classesCheckBox.addMouseListener(this.createCheckboxListener(Type.CLASS));
@@ -342,8 +343,8 @@ public String getIdentifier() {
342343
}
343344

344345
@Override
345-
public Type getType() {
346-
return Type.get(this.obf);
346+
public int getTypePriority() {
347+
return Type.values().length - Type.get(this.obf).ordinal();
347348
}
348349

349350
@Override
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package org.quiltmc.enigma.gui.util;
2+
3+
import javax.swing.JScrollBar;
4+
import javax.swing.SwingUtilities;
5+
import java.awt.Component;
6+
import java.awt.Container;
7+
import java.awt.Dimension;
8+
import java.awt.FlowLayout;
9+
import java.awt.Insets;
10+
11+
public class WrapLayout extends FlowLayout {
12+
public WrapLayout() {
13+
super();
14+
}
15+
16+
public WrapLayout(int align) {
17+
super(align);
18+
}
19+
20+
public WrapLayout(int align, int hgap, int vgap) {
21+
super(align, hgap, vgap);
22+
}
23+
24+
@Override
25+
public Dimension preferredLayoutSize(Container target) {
26+
return this.computeLayoutSize(target, true);
27+
}
28+
29+
@Override
30+
public Dimension minimumLayoutSize(Container target) {
31+
Dimension minimum = this.computeLayoutSize(target, false);
32+
minimum.width -= (this.getHgap() + 1);
33+
34+
return minimum;
35+
}
36+
37+
private Dimension computeLayoutSize(Container target, boolean preferred) {
38+
int targetWidth = target.getSize().width;
39+
40+
if (targetWidth == 0) {
41+
targetWidth = Integer.MAX_VALUE;
42+
}
43+
44+
int horizontalGap = this.getHgap();
45+
Insets insets = target.getInsets();
46+
int horizontalSpacing = insets.left + insets.right + horizontalGap * 2;
47+
int maxWidth = targetWidth - horizontalSpacing;
48+
49+
Dimension layoutSize = new Dimension(0, 0);
50+
int rowWidth = 0;
51+
int rowHeight = 0;
52+
53+
int componentCount = target.getComponentCount();
54+
55+
for (int i = 0; i < componentCount; i++) {
56+
Component component = target.getComponent(i);
57+
58+
if (component.isVisible()) {
59+
Dimension componentSize = preferred ? component.getPreferredSize() : component.getMinimumSize();
60+
61+
if (rowWidth + componentSize.width > maxWidth) {
62+
this.addRow(layoutSize, rowWidth, rowHeight);
63+
rowWidth = 0;
64+
rowHeight = 0;
65+
} else if (rowWidth != 0) {
66+
rowWidth += horizontalGap;
67+
}
68+
69+
rowWidth += componentSize.width;
70+
rowHeight = Math.max(rowHeight, componentSize.height);
71+
}
72+
}
73+
74+
this.addRow(layoutSize, rowWidth, rowHeight);
75+
76+
layoutSize.width += horizontalSpacing;
77+
layoutSize.height += insets.top + insets.bottom + this.getVgap() * 2;
78+
79+
if (SwingUtilities.getAncestorOfClass(JScrollBar.class, target) != null) {
80+
layoutSize.width -= (horizontalGap + 1);
81+
}
82+
83+
return layoutSize;
84+
}
85+
86+
private void addRow(Dimension layoutSize, int width, int height) {
87+
layoutSize.width = Math.max(layoutSize.width, width);
88+
89+
if (layoutSize.height > 0) {
90+
layoutSize.height += this.getVgap();
91+
}
92+
93+
layoutSize.height += height;
94+
}
95+
}

0 commit comments

Comments
 (0)