From d6df89b7d2a14bff2a3f25d88cb25448d6314d1a Mon Sep 17 00:00:00 2001 From: rickard Date: Sat, 2 Mar 2024 19:50:23 +0100 Subject: [PATCH] Fixes 561 and refactors how TexturePanel handles texture name components --- .../materials/multiview/widgets/TexturePanel.java | 15 ++++++++------- .../multiview/widgets/TexturePanelTest.java | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java b/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java index 9c7cbd13..0c85251b 100644 --- a/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java +++ b/jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java @@ -83,17 +83,17 @@ private void displayPreview() { // visible for tests protected String extractTextureName(final String property) { final String[] textureNameComponents = property.split("\""); - if(property.endsWith("\"")) { - // texture name is last in property - return textureNameComponents[textureNameComponents.length - 1]; + final int length = textureNameComponents.length; + if(property.endsWith("\"") || length == 1) { + // texture name is last in property, or it's empty + return textureNameComponents[length - 1].trim(); } // has extra properties after name, return segment second to last - return textureNameComponents[textureNameComponents.length - 2]; + return textureNameComponents[length - 2].trim(); } // visible for tests protected void updateFlipRepeat() { - String propertyValue = ""; final List segments = new ArrayList<>(); if (flip) { segments.add(FLIP); @@ -285,7 +285,7 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI @Override protected void readProperty() { java.awt.EventQueue.invokeLater(() -> { - String prop = property.getValue(); + String prop = property.getValue().trim(); if (prop.contains(FLIP)) { flip = true; prop = prop.replace(FLIP, EMPTY).trim(); @@ -334,8 +334,9 @@ public void setTexture(String name) { textureName = "\"" + name + "\""; } property.setValue(textureName); - displayPreview(); + updateFlipRepeat(); + displayPreview(); java.awt.EventQueue.invokeLater(() -> { fireChanged(); }); diff --git a/jme3-materialeditor/test/unit/src/com/jme3/gde/materials/multiview/widgets/TexturePanelTest.java b/jme3-materialeditor/test/unit/src/com/jme3/gde/materials/multiview/widgets/TexturePanelTest.java index 38193478..9e414bd4 100644 --- a/jme3-materialeditor/test/unit/src/com/jme3/gde/materials/multiview/widgets/TexturePanelTest.java +++ b/jme3-materialeditor/test/unit/src/com/jme3/gde/materials/multiview/widgets/TexturePanelTest.java @@ -55,7 +55,7 @@ public TexturePanelTest() { String textureNameWithSpaces = "\"texture name with spaces.jpg\""; String textureNameWithSpaceAndModifier = "Flip Repeat \"texture name with spaces.jpg\""; String textureName = "\"simple_name.jpg\""; - String textureNameWithExtraInfo = "\"simple_name.jpg\" LINEAR"; + String textureNameWithExtraInfo = "Flip \"simple_name.jpg\" LINEAR"; @Test public void testExtractTextureName() {