Skip to content

Commit b13ee6f

Browse files
Copilotneph1
andcommitted
Fix Material Editor scrolling by removing hardcoded preferred size
Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com>
1 parent 2d6e374 commit b13ee6f

3 files changed

Lines changed: 93 additions & 7 deletions

File tree

jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.form

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@
7575
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
7676
<SubComponents>
7777
<Container class="javax.swing.JPanel" name="editorPanel">
78-
<Properties>
79-
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
80-
<Dimension value="[0, 0]"/>
81-
</Property>
82-
</Properties>
8378

8479
<Layout>
8580
<DimensionLayout dim="0">

jme3-materialeditor/src/com/jme3/gde/materials/multiview/MaterialEditorTopComponent.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ private void initComponents() {
200200

201201
jScrollPane4.setPreferredSize(new java.awt.Dimension(0, 0));
202202

203-
editorPanel.setPreferredSize(new java.awt.Dimension(0, 0));
204-
205203
texturesAndColorsPane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
206204
texturesAndColorsPane.setMinimumSize(new java.awt.Dimension(150, 31));
207205
texturesAndColorsPane.setPreferredSize(new java.awt.Dimension(480, 355));
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2009-2023 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.gde.materials.multiview;
33+
34+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
35+
import static org.junit.jupiter.api.Assertions.assertTrue;
36+
import org.junit.jupiter.api.Test;
37+
import java.awt.Dimension;
38+
import java.awt.EventQueue;
39+
import java.lang.reflect.InvocationTargetException;
40+
import java.lang.reflect.Field;
41+
import javax.swing.JPanel;
42+
import org.openide.util.Exceptions;
43+
44+
/**
45+
* Test for Material Editor scrolling functionality
46+
* @author copilot
47+
*/
48+
public class MaterialEditorScrollTest {
49+
50+
public MaterialEditorScrollTest() {
51+
}
52+
53+
@Test
54+
public void testEditorPanelDoesNotHaveHardcodedZeroSize() {
55+
MaterialEditorTopComponent editor = new MaterialEditorTopComponent();
56+
57+
try {
58+
EventQueue.invokeAndWait(() -> {
59+
// Access the editorPanel via reflection to check it doesn't have hardcoded (0,0) size
60+
try {
61+
Field editorPanelField = MaterialEditorTopComponent.class.getDeclaredField("editorPanel");
62+
editorPanelField.setAccessible(true);
63+
JPanel editorPanel = (JPanel) editorPanelField.get(editor);
64+
65+
// The panel should not have a hardcoded (0,0) preferred size
66+
Dimension preferredSize = editorPanel.getPreferredSize();
67+
68+
// The preferred size should not be exactly (0,0) as that was the bug
69+
// Note: it might still be (0,0) if no components are added yet, but it should not be hardcoded
70+
// We can't test the exact size since it depends on content, but we can ensure it's not artificially set to (0,0)
71+
72+
// The key test is that when components are added, the preferred size should grow
73+
// For now, we just ensure the panel exists and can calculate a preferred size
74+
assertTrue(preferredSize != null, "Preferred size should not be null");
75+
76+
// Add a dummy component to test that preferred size calculation works
77+
editorPanel.add(new javax.swing.JLabel("Test"));
78+
editorPanel.revalidate();
79+
80+
Dimension newPreferredSize = editorPanel.getPreferredSize();
81+
// Now it should have a non-zero size since we added a component
82+
assertTrue(newPreferredSize.width > 0 || newPreferredSize.height > 0,
83+
"Preferred size should grow when components are added");
84+
85+
} catch (NoSuchFieldException | IllegalAccessException ex) {
86+
Exceptions.printStackTrace(ex);
87+
}
88+
});
89+
} catch (InterruptedException | InvocationTargetException ex) {
90+
Exceptions.printStackTrace(ex);
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)