8000 Merge pull request #502 from neph1/make_texture_panel_resizable · jMonkeyEngine/sdk@e7cbb2a · GitHub
[go: up one dir, main page]

Skip to content

Commit e7cbb2a

Browse files
authored
Merge pull request #502 from neph1/make_texture_panel_resizable
makes most widgets resizable. center pane is still a bit greedy. the …
2 parents 88ef54e + 86ea7ba commit e7cbb2a

16 files changed

+156
-164
lines changed

jme3-materialeditor/src/com/jme3/gde/materials/MaterialPreviewRenderer.java

Lines changed: 47 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.jme3.math.Vector3f;
4747
import com.jme3.renderer.RendererException;
4848
import com.jme3.scene.Geometry;
49-
import com.jme3.scene.Spatial;
5049
import com.jme3.scene.shape.Box;
5150
import com.jme3.scene.shape.Quad;
5251
import com.jme3.scene.shape.Sphere;
@@ -59,8 +58,9 @@
5958
import javax.swing.JLabel;
6059

6160
/**
62-
* Handles rendering of materials in preview widgets of Material and Shader Node editor.
63-
*
61+
* Handles rendering of materials in preview widgets of Material and Shader Node
62+
* editor.
63+
*
6464
* @author Nehon
6565
*/
6666
public class MaterialPreviewRenderer implements SceneListener {
@@ -108,14 +108,14 @@ private void init() {
108108
quad = new Geometry("previewQuad", quadMesh);
109109
quad.setLocalTranslation(new Vector3f(-2.25f, -2.25f, 0));
110110
MikktspaceTangentGenerator.generate(quad);
111-
111+
112112
teapot = (Geometry) SceneApplication.getApplication().getAssetManager()
113113
.loadModel("Models/Teapot/Teapot.obj");
114114
teapot.scale(3.5f);
115115
teapot.rotate(FastMath.PI, -FastMath.QUARTER_PI * 0.5f, -0.0f);
116116
teapot.setLocalTranslation(new Vector3f(-0.5f, 1.75f, 0));
117117
MikktspaceTangentGenerator.generate(teapot);
118-
118+
119119
currentGeom = sphere;
120120
init = true;
121121
}
@@ -125,19 +125,14 @@ public void showMaterial(final ProjectAssetManager assetManager, final String ma
125125
if (!init) {
126126
init();
127127
}
128-
exec.execute(new Runnable() {
129-
130-
@Override
131-
public void run() {
132-
MaterialKey key = new MaterialKey(assetManager.getRelativeAssetPath(materialFileName));
133-
assetManager.deleteFromCache(key);
134-
Material mat = assetManager.loadAsset(key);
135-
if (mat != null) {
136-
showMaterial(mat);
137-
}
128+
exec.execute(() -> {
129+
MaterialKey key = new MaterialKey(assetManager.getRelativeAssetPath(materialFileName));
130+
assetManager.deleteFromCache(key);
131+
Material mat = assetManager.loadAsset(key);
132+
if (mat != null) {
133+
showMaterial(mat);
138134
}
139135
});
140-
141136

142137
}
143138

@@ -149,46 +144,36 @@ public void showMaterial(final Material m, final String techniqueName) {
149144
if (!init) {
150145
init();
151146
}
152-
SceneApplication.getApplication().enqueue(new Callable<Material>() {
153-
154-
@Override
155-
public Material call() throws Exception {
156-
if (techniqueName != null) {
147+
SceneApplication.getApplication().enqueue(() -> {
148+
if (techniqueName != null) {
149+
try {
150+
m.selectTechnique(techniqueName, SceneApplication.getApplication().getRenderManager());
151+
} catch (Exception e) {
152+
//
153+
}
154+
}
155+
final Material mat = reloadMaterial(m);
156+
if (mat != null) {
157+
java.awt.EventQueue.invokeLater(() -> {
158+
currentMaterial = mat;
159+
currentGeom.setMaterial(mat);
157160
try {
158-
m.selectTechnique(techniqueName, SceneApplication.getApplication().getRenderManager());
161+
if (currentGeom.getMaterial() != null) {
162+
PreviewRequest request = new PreviewRequest(MaterialPreviewRenderer.this, currentGeom, label.getWidth(), label.getHeight());
163+
request.getCameraRequest().setLocation(new Vector3f(0, 0, 7));
164+
request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y);
165+
SceneApplication.getApplication().createPreview(request);
166+
}
159167
} catch (Exception e) {
160-
//
168+
java.awt.EventQueue.invokeLater(() -> {
169+
label.setIcon(Icons.error);
170+
});
171+
smartLog("Error rendering material{0}", e.getMessage());
161172
}
162-
}
163-
final Material mat = reloadMaterial(m);
164-
if (mat != null) {
165-
java.awt.EventQueue.invokeLater(new Runnable() {
166-
@Override
167-
public void run() {
168-
currentMaterial = mat;
169-
currentGeom.setMaterial(mat);
170-
try {
171-
if (currentGeom.getMaterial() != null) {
172-
PreviewRequest request = new PreviewRequest(MaterialPreviewRenderer.this, currentGeom, label.getWidth(), label.getHeight());
173-
request.getCameraRequest().setLocation(new Vector3f(0, 0, 7));
174-
request.getCameraRequest().setLookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y);
175-
SceneApplication.getApplication().createPreview(request);
176-
}
177-
} catch (Exception e) {
178-
java.awt.EventQueue.invokeLater(new Runnable() {
179-
@Override
180-
public void run() {
181-
label.setIcon(Icons.error);
182-
}
183-
});
184-
smartLog("Error rendering material{0}", e.getMessage());
185-
}
186-
}
187-
});
173+
});
188174

189-
}
190-
return mat;
191175
}
176+
return mat;
192177
});
193178
}
194179

@@ -209,7 +194,7 @@ public Material reloadMaterial(Material mat) {
209194

210195
//creating a dummy mat with the mat def of the mat to reload
211196
dummy = new Material(mat.getMaterialDef());
212-
197+
213198
for (MatParam matParam : mat.getParams()) {
214199
dummy.setParam(matParam.getName(), matParam.getVarType(), matParam.getValue());
215200
}
@@ -231,12 +216,7 @@ public Material reloadMaterial(Material mat) {
231216
//Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, e.getMessage());
232217
smartLog("{0}", e.getMessage());
233218

234-
java.awt.EventQueue.invokeLater(new Runnable() {
235-
@Override
236-
public void run() {
237-
label.setIcon(Icons.error);
238-
}
239-
});
219+
java.awt.EventQueue.invokeLater(() -> label.setIcon(Icons.error));
240220
return null;
241221
} catch (NullPointerException npe) {
242222
//utterly bad, but for some reason I get random NPE here and can't figure out why so to avoid bigger issues, I just catch it.
@@ -282,11 +262,8 @@ public void sceneClosed(SceneRequest request) {
282262
public void previewCreated(PreviewRequest request) {
283263
if (request.getRequester() == this) E377 {
284264
final ImageIcon icon = new ImageIcon(request.getImage());
285-
java.awt.EventQueue.invokeLater(new Runnable() {
286-
@Override
287-
public void run() {
288-
label.setIcon(icon);
289-
}
265+
java.awt.EventQueue.invokeLater(() -> {
266+
label.setIcon(icon);
290267
});
291268
previewRequested = false;
292269
}
@@ -296,15 +273,16 @@ public void cleanUp() {
296273
SceneApplication.getApplication().removeSceneListener(this);
297274
exec.shutdownNow();
298275
}
299-
300-
public boolean isPreviewRequested(){
276+
277+
public boolean isPreviewRequested() {
301278
return previewRequested;
302279
}
303-
280+
304281
/**
305-
* A more lightweight refresh than showMaterials that doesn't rebuild the material
282+
* A more lightweight refresh than showMaterials that doesn't rebuild the
283+
* material
306284
*/
307-
public void refreshOnly(){
285+
public void refreshOnly() {
308286
previewRequested = true;
309287
SceneApplication.getApplication().enqueue((Callable<Object>) () -> {
310288
if (currentGeom.getMaterial() != null) {
@@ -316,5 +294,5 @@ public void refreshOnly(){
316294
return null;
317295
});
318296
}
319-
297+
320298
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@
8787
<Group type="102" attributes="0">
8888
<Group type="103" groupAlignment="0" attributes="0">
8989
<Component id="materialPreviewWidget1" min="-2" pref="255" max="-2" attributes="0"/>
90-
<Component id="jTabbedPane3" pref="477" max="32767" attributes="0"/>
90+
<Component id="jTabbedPane3" max="32767" attributes="0"/>
9191
</Group>
9292
<EmptySpace max="-2" attributes="0"/>
9393
<Group type="103" groupAlignment="0" attributes="0">
9494
<Group type="102" alignment="0" attributes="0">
95-
<Component id="texturesAndColorsPane" min="-2" pref="496" max="-2" attributes="0"/>
95+
<Component id="texturesAndColorsPane" pref="496" max="32767" attributes="0"/>
9696
<EmptySpace max="-2" attributes="0"/>
97-
<Component id="additionalRenderStatePane" pref="352" max="32767" attributes="0"/>
97+
<Component id="additionalRenderStatePane" pref="329" max="32767" attributes="0"/>
9898
<EmptySpace pref="12" max="32767" attributes="0"/>
9999
</Group>
100100
<Group type="102" alignment="0" attributes="0">
@@ -182,6 +182,7 @@
182182
</Container>
183183
<Container class="javax.swing.JTabbedPane" name="jTabbedPane3">
184184
<Properties>
185+
<Property name="tabLayoutPolicy" type="int" value="1"/>
185186
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
186187
<Dimension value="[380, 355]"/>
187188
</Property>
@@ -374,8 +375,9 @@
374375
</Component>
375376
<Container class="javax.swing.JTabbedPane" name="additionalRenderStatePane">
376377
<Properties>
378+
<Property name="tabLayoutPolicy" type="int" value="1"/>
377379
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
378-
<Dimension value="[150, 100]"/>
380+
<Dimension value="[100, 100]"/>
379381
</Property>
380382
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
381383
<Dimension value="[380, 355]"/>

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private void initComponents() {
169169

170170
texturesAndColorsPane.addTab(org.openide.util.NbBundle.getMessage(MaterialEditorTopComponent.class, "MaterialEditorTopComponent.jScrollPane3.TabConstraints.tabTitle"), jScrollPane3); // NOI18N
171171

172+
jTabbedPane3.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
172173
jTabbedPane3.setMinimumSize(new java.awt.Dimension(380, 355));
173174
jTabbedPane3.setPreferredSize(new java.awt.Dimension(500, 355));
174175

@@ -180,7 +181,6 @@ private void initComponents() {
180181

181182
jTabbedPane3.addTab(org.openide.util.NbBundle.getMessage(MaterialEditorTopComponent.class, "MaterialEditorTopComponent.jScrollPane2.TabConstraints.tabTitle_1"), jScrollPane2); // NOI18N
182183

183-
jToolBar2.setFloatable(false);
184184
jToolBar2.setRollover(true);
185185

186186
jPanel3.setPreferredSize(new java.awt.Dimension(0, 21));
@@ -215,7 +215,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
215215
}
216216
});
217217
jToolBar2.add(jComboBox1);
218-
jToolBar3.setFloatable(false);
218+
219219
jToolBar3.setRollover(true);
220220

221221
jPanel1.setPreferredSize(new java.awt.Dimension(140, 21));
@@ -256,7 +256,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
256256
}
257257
});
258258

259-
additionalRenderStatePane.setMinimumSize(new java.awt.Dimension(150, 100));
259+
additionalRenderStatePane.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
260+
additionalRenderStatePane.setMinimumSize(new java.awt.Dimension(100, 100));
260261
additionalRenderStatePane.setPreferredSize(new java.awt.Dimension(380, 355));
261262

262263
jScrollPane10.setBorder(null);
@@ -273,13 +274,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
273274
.addGroup(editorPanelLayout.createSequentialGroup()
274275
.addGroup(editorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
275276
.addComponent(materialPreviewWidget1, javax.swing.GroupLayout.PREFERRED_SIZE, 255, javax.swing.GroupLayout.PREFERRED_SIZE)
276-
.addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 477, Short.MAX_VALUE))
277+
.addComponent(jTabbedPane3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
277278
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
278279
.addGroup(editorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279280
.addGroup(editorPanelLayout.createSequentialGroup()
280-
.addComponent(texturesAndColorsPane, javax.swing.GroupLayout.PREFERRED_SIZE, 496, javax.swing.GroupLayout.PREFERRED_SIZE)
281+
.addComponent(texturesAndColorsPane, javax.swing.GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE)
281282
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
282-
.addComponent(additionalRenderStatePane, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
283+
.addComponent(additionalRenderStatePane, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
283284
.addContainerGap(12, Short.MAX_VALUE))
284285
.addGroup(editorPanelLayout.createSequentialGroup()
285286
.addGroup(editorPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

0 commit comments

Comments
 (0)
0