Skip to content

Commit 472629c

Browse files
authored
Fix #463 by allowing other texture settings and only changing Flip an… (#467)
* Fix #463 by allowing other texture settings and only changing Flip and Repeat * updated TexturePanelSquare * formatting
1 parent 7c4c953 commit 472629c

File tree

2 files changed

+68
-76
lines changed

2 files changed

+68
-76
lines changed

jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public void run() {
5454
if (texPreview == null) {
5555
texPreview = new TexturePreview(manager);
5656
}
57-
texPreview.requestPreview(stripQuotes(textureName), "", 80, 25, texturePreview, null);
57+
final String[] textureNameComponents = textureName.split(" ");
58+
texPreview.requestPreview(stripQuotes(textureNameComponents[textureNameComponents.length - 1]), "", 80, 25, texturePreview, null);
5859
} catch (AssetNotFoundException a) {
5960
Logger.getLogger(MaterialEditorTopComponent.class.getName()).log(Level.WARNING, "Could not load texture {0}", textureName);
6061
}
@@ -68,19 +69,21 @@ private String stripQuotes(String s) {
6869
}
6970

7071
private void updateFlipRepeat() {
71-
if (flip && repeat) {
72-
property.setValue("Flip Repeat " + textureName);
73-
texturePreview.setToolTipText("Flip Repeat " + textureName);
74-
} else if (flip) {
75-
property.setValue("Flip " + textureName);
76-
texturePreview.setToolTipText("Flip " + textureName);
77-
} else if (repeat) {
78-
property.setValue("Repeat " + textureName);
79-
texturePreview.setToolTipText("Repeat " + textureName);
80-
} else {
81-
property.setValue(textureName);
82-
texturePreview.setToolTipText(textureName);
72+
String propertyValue = property.getValue();
73+
propertyValue = propertyValue.replaceFirst(textureName, "");
74+
if (flip && !propertyValue.contains("Flip ")) {
75+
propertyValue += "Flip ";
76+
} else if (!flip) {
77+
propertyValue = propertyValue.replaceFirst("Flip ", "");
8378
}
79+
if (repeat && !propertyValue.contains("Repeat ")) {
80+
propertyValue += "Repeat ";
81+
} else if (!repeat) {
82+
propertyValue = propertyValue.replaceFirst("Repeat ", "");
83+
}
84+
propertyValue += textureName;
85+
property.setValue(propertyValue);
86+
texturePreview.setToolTipText(propertyValue);
8487
}
8588

8689
private static BufferedImage resizeImage(BufferedImage originalImage) {
@@ -277,33 +280,26 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI
277280

278281
@Override
279282
protected void readProperty() {
280-
java.awt.EventQueue.invokeLater(new Runnable() {
281-
282-
@Override
283-
public void run() {
284-
if (property.getValue().startsWith("Flip Repeat ")) {
285-
flip = true;
286-
repeat = true;
287-
textureName = property.getValue().replaceFirst("Flip Repeat ", "").trim();
288-
} else if (property.getValue().startsWith("Flip ")) {
289-
flip = true;
290-
textureName = property.getValue().replaceFirst("Flip ", "").trim();
291-
} else if (property.getValue().startsWith("Repeat ")) {
292-
repeat = true;
293-
textureName = property.getValue().replaceFirst("Repeat ", "").trim();
294-
} else {
295-
textureName = property.getValue();
296-
}
297-
jLabel1.setText(property.getName());
298-
jLabel1.setToolTipText(property.getName());
299-
displayPreview();
300-
texturePreview.setToolTipText(property.getValue());
301-
MaterialProperty prop = property;
302-
property = null;
303-
jCheckBox1.setSelected(flip);
304-
jCheckBox2.setSelected(repeat);
305-
property = prop;
283+
java.awt.EventQueue.invokeLater(() -> {
284+
textureName = property.getValue();
285+
if (textureName.contains("Flip ")) {
286+
flip = true;
287+
textureName = textureName.replaceFirst("Flip ", "").trim();
288+
}
289+
if (textureName.contains("Repeat ")) {
290+
repeat = true;
291+
textureName = textureName.replaceFirst("Repeat ", "").trim();
306292
}
293+
property.setValue(textureName);
294+
jLabel1.setText(property.getName());
295+
jLabel1.setToolTipText(property.getName());
296+
displayPreview();
297+
texturePreview.setToolTipText(property.getValue());
298+
MaterialProperty prop = property;
299+
property = null;
300+
jCheckBox1.setSelected(flip);
301+
jCheckBox2.setSelected(repeat);
302+
property = prop;
307303
});
308304
}
309305

jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanelSquare.java

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public void run() {
110110
if (texPreview == null) {
111111
texPreview = new TexturePreview(manager);
112112
}
113-
texPreview.requestPreview(stripQuotes(textureName), "", 80, 25, texturePreview, null);
113+
final String[] textureNameComponents = textureName.split(" ");
114+
texPreview.requestPreview(stripQuotes(textureNameComponents[textureNameComponents.length - 1]), "", 80, 25, texturePreview, null);
114115
} catch (AssetNotFoundException a) {
115116
Logger.getLogger(MaterialEditorTopComponent.class.getName()).log(Level.WARNING, "Could not load texture {0}", textureName);
116117
}
@@ -124,19 +125,21 @@ private String stripQuotes(String s) {
124125
}
125126

126127
private void updateFlipRepeat() {
127-
if (flip && repeat) {
128-
property.setValue("Flip Repeat " + textureName);
129-
texturePreview.setToolTipText("Flip Repeat " + textureName);
130-
} else if (flip) {
131-
property.setValue("Flip " + textureName);
132-
texturePreview.setToolTipText("Flip " + textureName);
133-
} else if (repeat) {
134-
property.setValue("Repeat " + textureName);
135-
texturePreview.setToolTipText("Repeat " + textureName);
136-
} else {
137-
property.setValue(textureName);
138-
texturePreview.setToolTipText(textureName);
128+
String propertyValue = property.getValue();
129+
propertyValue = propertyValue.replaceFirst(textureName, "");
130+
if (flip && !propertyValue.contains("Flip ")) {
131+
propertyValue += "Flip ";
132+
} else if (!flip) {
133+
propertyValue = propertyValue.replaceFirst("Flip ", "");
134+
}
135+
if (repeat && !propertyValue.contains("Repeat ")) {
136+
propertyValue += "Repeat ";
137+
} else if (!repeat) {
138+
propertyValue = propertyValue.replaceFirst("Repeat ", "");
139139
}
140+
propertyValue += textureName;
141+
property.setValue(propertyValue);
142+
texturePreview.setToolTipText(propertyValue);
140143
}
141144

142145
/** This method is called from within the constructor to
@@ -268,31 +271,24 @@ private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
268271

269272
@Override
270273
protected void readProperty() {
271-
java.awt.EventQueue.invokeLater(new Runnable() {
272-
273-
@Override
274-
public void run() {
275-
if (property.getValue().startsWith("Flip Repeat ")) {
276-
flip = true;
277-
repeat = true;
278-
textureName = property.getValue().replaceFirst("Flip Repeat ", "").trim();
279-
} else if (property.getValue().startsWith("Flip ")) {
280-
flip = true;
281-
textureName = property.getValue().replaceFirst("Flip ", "").trim();
282-
} else if (property.getValue().startsWith("Repeat ")) {
283-
repeat = true;
284-
textureName = property.getValue().replaceFirst("Repeat ", "").trim();
285-
} else {
286-
textureName = property.getValue();
287-
}
288-
displayPreview();
289-
texturePreview.setToolTipText(property.getValue());
290-
MaterialProperty prop = property;
291-
property = null;
292-
jCheckBox1.setSelected(flip);
293-
jCheckBox2.setSelected(repeat);
294-
property = prop;
274+
java.awt.EventQueue.invokeLater(() -> {
275+
textureName = property.getValue();
276+
if (textureName.contains("Flip ")) {
277+
flip = true;
278+
textureName = textureName.replaceFirst("Flip ", "").trim();
279+
}
280+
if (textureName.contains("Repeat ")) {
281+
repeat = true;
282+
textureName = textureName.replaceFirst("Repeat ", "").trim();
295283
}
284+
property.setValue(textureName);
285+
displayPreview();
286+
texturePreview.setToolTipText(property.getValue());
287+
MaterialProperty prop = property;
288+
property = null;
289+
jCheckBox1.setSelected(flip);
290+
jCheckBox2.setSelected(repeat);
291+
property = prop;
296292
});
297293
}
298294

0 commit comments

Comments
 (0)