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