Skip to content

Commit 4f261b2

Browse files
committed
Issue #534 fix wobbling GUI when number of decimals change on sliders
1 parent 5274e1b commit 4f261b2

File tree

4 files changed

+247
-91
lines changed

4 files changed

+247
-91
lines changed

jme3-scenecomposer/src/com/jme3/gde/scenecomposer/CameraPositionTrackerAppState.java

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,41 @@
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+
*/
132
package com.jme3.gde.scenecomposer;
233

334
import com.jme3.app.Application;
435
import com.jme3.app.state.BaseAppState;
36+
import com.jme3.math.Vector3f;
537
import com.jme3.renderer.Camera;
38+
import java.text.DecimalFormat;
639
import javax.swing.JLabel;
740
import javax.swing.SwingUtilities;
841

@@ -12,8 +45,11 @@
1245
* @author MeFisto94
1346
*/
1447
public class CameraPositionTrackerAppState extends BaseAppState {
15-
JLabel lblPos;
16-
JLabel lblLookAt;
48+
private final JLabel lblPos;
49+
private final JLabel lblLookAt;
50+
51+
private final Vector3f position = new Vector3f();
52+
private final Vector3f direction = new Vector3f();
1753

1854
public CameraPositionTrackerAppState(JLabel lblPos, JLabel lblLookAt) {
1955
this.lblPos = lblPos;
@@ -37,12 +73,12 @@ public void update(float tpf) {
3773
super.update(tpf);
3874

3975
final Camera cam = getApplication().getCamera();
40-
SwingUtilities.invokeLater(new Runnable() {
41-
@Override
42-
public void run() {
43-
lblPos.setText(cam.getLocation().toString());
44-
lblLookAt.setText(cam.getDirection().toString());
45-
}
76+
SwingUtilities.invokeLater(() -> {
77+
position.set(cam.getLocation());
78+
direction.set(cam.getDirection());
79+
lblPos.setText(SceneComposerUtil.trimDecimals(position));
80+
lblLookAt.setText(SceneComposerUtil.trimDecimals(direction));
4681
});
4782
}
83+
4884
}

jme3-scenecomposer/src/com/jme3/gde/scenecomposer/SceneComposerTopComponent.form

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
<EmptySpace max="-2" attributes="0"/>
2929
<Component id="sceneInfoPanel" min="-2" max="-2" attributes="0"/>
3030
<EmptySpace max="-2" attributes="0"/>
31-
<Component id="cameraPanel" min="-2" max="-2" attributes="0"/>
32-
<EmptySpace max="32767" attributes="0"/>
31+
<Component id="cameraPanel" max="32767" attributes="0"/>
32+
<EmptySpace max="-2" attributes="0"/>
3333
</Group>
34-
<Component id="jToolBar1" alignment="0" max="32767" attributes="0"/>
34+
<Component id="jToolBar1" alignment="0" pref="1231" max="32767" attributes="0"/>
3535
</Group>
3636
</DimensionLayout>
3737
<DimensionLayout dim="1">
@@ -74,13 +74,13 @@
7474
<Component id="jLabel10" alignment="0" min="-2" max="-2" attributes="0"/>
7575
<Component id="cursorPositionHeader" alignment="0" min="-2" max="-2" attributes="0"/>
7676
</Group>
77-
<EmptySpace min="-2" pref="34" max="-2" attributes="0"/>
77+
<EmptySpace type="separate" min="-2" max="-2" attributes="0"/>
7878
<Group type="103" groupAlignment="0" attributes="0">
7979
<Component id="cursorPositionLabel" min="-2" max="-2" attributes="0"/>
80-
<Component id="jLabel12" alignment="0" min="-2" max="-2" attributes="0"/>
81-
<Component id="jLabel11" alignment="0" min="-2" max="-2" attributes="0"/>
80+
<Component id="cameraDirectionLabel" alignment="0" min="-2" max="-2" attributes="0"/>
81+
<Component id="cameraPositionLabel" alignment="0" min="-2" max="-2" attributes="0"/>
8282
</Group>
83-
<EmptySpace pref="134" max="32767" attributes="0"/>
83+
<EmptySpace max="32767" attributes="0"/>
8484
</Group>
8585
<Group type="102" alignment="0" attributes="0">
8686
<Group type="103" groupAlignment="0" attributes="0">
@@ -139,12 +139,12 @@
139139
<EmptySpace max="-2" attributes="0"/>
140140
<Group type="103" groupAlignment="3" attributes="0">
141141
<Component id="jLabel9" alignment="3" min="-2" max="-2" attributes="0"/>
142-
<Component id="jLabel11" alignment="3" min="-2" max="-2" attributes="0"/>
142+
<Component id="cameraPositionLabel" alignment="3" min="-2" max="-2" attributes="0"/>
143143
</Group>
144144
<EmptySpace max="32767" attributes="0"/>
145145
<Group type="103" groupAlignment="3" attributes="0">
146146
<Component id="jLabel10" alignment="3" min="-2" max="-2" attributes="0"/>
147-
<Component id="jLabel12" alignment="3" min="-2" max="-2" attributes="0"/>
147+
<Component id="cameraDirectionLabel" alignment="3" min="-2" max="-2" attributes="0"/>
148148
</Group>
149149
<EmptySpace min="-2" pref="8" max="-2" attributes="0"/>
150150
<Group type="103" groupAlignment="3" attributes="0">
@@ -227,17 +227,35 @@
227227
</Property>
228228
</Properties>
229229
</Component>
230-
<Component class="javax.swing.JLabel" name="jLabel11">
230+
<Component class="javax.swing.JLabel" name="cameraPositionLabel">
231231
<Properties>
232232
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
233-
<ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.jLabel11.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
233+
<ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.cameraPositionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
234+
</Property>
235+
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
236+
<Dimension value="[170, 17]"/>
237+
</Property>
238+
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
239+
<Dimension value="[170, 17]"/>
240+
</Property>
241+
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
242+
<Dimension value="[170, 17]"/>
234243
</Property>
235244
</Properties>
236245
</Component>
237-
<Component class="javax.swing.JLabel" name="jLabel12">
246+
<Component class="javax.swing.JLabel" name="cameraDirectionLabel">
238247
<Properties>
239248
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
240-
<ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.jLabel12.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
249+
<ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.cameraDirectionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
250+
</Property>
251+
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
252+
<Dimension value="[170, 17]"/>
253+
</Property>
254+
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
255+
<Dimension value="[170, 17]"/>
256+
</Property>
257+
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
258+
<Dimension value="[170, 17]"/>
241259
</Property>
242260
</Properties>
243261
</Component>
@@ -253,6 +271,15 @@
253271
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
254272
<ResourceString bundle="com/jme3/gde/scenecomposer/Bundle.properties" key="SceneComposerTopComponent.cursorPositionLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
255273
</Property>
274+
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
275+
<Dimension value="[170, 17]"/>
276+
</Property>
277+
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
278+
<Dimension value="[170, 17]"/>
279+
</Property>
280+
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
281+
<Dimension value="[170, 17]"/>
282+
</Property>
256283
</Properties>
257284
</Component>
258285
<Component class="javax.swing.JLabel" name="jLabel13">

0 commit comments

Comments
 (0)