From e7aa2be1e0c3d47a6c79dd0299e1973473004348 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:47:39 +0000 Subject: [PATCH 1/6] Initial plan From ff939b955dcfd73a99b736d0e873a057cec4ffc3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:54:20 +0000 Subject: [PATCH 2/6] Fix texture cancellation issue in material editor Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com> --- .../multiview/widgets/TexturePanel.java | 21 ++++-- .../multiview/widgets/TexturePanelTest.java | 74 +++++++++++++++++++ 2 files changed, 90 insertions(+), 5 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 0c85251b..95f3966d 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 @@ -267,6 +267,8 @@ private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_texturePreviewMouseClicked Component view = editor.getCustomEditor(); + String originalValue = property.getValue(); // Store original value before clearing + String originalTextureName = textureName; // Store original texture name property.setValue(EMPTY); view.setVisible(true); if (editor.getValue() != null) { @@ -274,11 +276,20 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI displayPreview(); updateFlipRepeat(); fireChanged(); - } else { // "No Texture" has been clicked - textureName = "\"\""; - texturePreview.setIcon(null); - texturePreview.setToolTipText(""); - fireChanged(); + } else { // "No Texture" has been clicked or dialog was cancelled + String asText = editor.getAsText(); + if (asText == null) { + // "No Texture" was explicitly selected + textureName = "\"\""; + texturePreview.setIcon(null); + texturePreview.setToolTipText(""); + fireChanged(); + } else { + // Dialog was cancelled, restore original values + property.setValue(originalValue); + textureName = originalTextureName; + displayPreview(); // Restore the preview + } } }//GEN-LAST:event_texturePreviewMouseClicked 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 9e414bd4..910f076c 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 @@ -171,5 +171,79 @@ public void testUpdateFlipRepeatExtraProperty() { assertTrue(texturePanel.property.getValue().contains("LINEAR")); } + + @Test + public void testTexturePreviewClickCancel() { + // This test simulates the scenario described in the issue: + // When a user clicks on a texture preview and then cancels the dialog, + // the original texture should be preserved instead of being unset. + + TexturePanel texturePanel = new TexturePanel(); + texturePanel.setProperty(new MaterialProperty()); + + // Set up initial texture state + String originalTexture = "\"original_texture.jpg\""; + texturePanel.property.setValue(originalTexture); + texturePanel.textureName = originalTexture; + + // Simulate the user clicking on texture preview and then canceling + // This is a simplified version of what happens in texturePreviewMouseClicked + String originalValue = texturePanel.property.getValue(); + String originalTextureName = texturePanel.textureName; + + // Clear the property (this happens when the dialog opens) + texturePanel.property.setValue(""); + + // Simulate cancel: editor.getValue() returns null and editor.getAsText() returns original value + // (not null, because setAsText was never called) + // This is the logic from the fixed texturePreviewMouseClicked method + String asText = originalTexture; // Would be returned by editor.getAsText() on cancel + if (asText != null) { + // Dialog was cancelled, restore original values + texturePanel.property.setValue(originalValue); + texturePanel.textureName = originalTextureName; + } + + // Verify that the original texture is preserved + assertEquals(originalTexture, texturePanel.property.getValue()); + assertEquals(originalTexture, texturePanel.textureName); + } + + @Test + public void testTexturePreviewClickNoTexture() { + // This test verifies that explicitly selecting "No Texture" still works correctly + + TexturePanel texturePanel = new TexturePanel(); + texturePanel.setProperty(new MaterialProperty()); + + // Set up initial texture state + String originalTexture = "\"original_texture.jpg\""; + texturePanel.property.setValue(originalTexture); + texturePanel.textureName = originalTexture; + + // Simulate the user clicking on texture preview and then selecting "No Texture" + String originalValue = texturePanel.property.getValue(); + String originalTextureName = texturePanel.textureName; + + // Clear the property (this happens when the dialog opens) + texturePanel.property.setValue(""); + + // Simulate "No Texture" selection: editor.getValue() returns null and editor.getAsText() returns null + // This is the logic from the fixed texturePreviewMouseClicked method + String asText = null; // Would be returned by editor.getAsText() when "No Texture" is selected + if (asText == null) { + // "No Texture" was explicitly selected + texturePanel.textureName = "\"\""; + texturePanel.property.setValue(""); + } else { + // Dialog was cancelled, restore original values + texturePanel.property.setValue(originalValue); + texturePanel.textureName = originalTextureName; + } + + // Verify that the texture is properly cleared + assertEquals("", texturePanel.property.getValue()); + assertEquals("\"\"", texturePanel.textureName); + } } From 91992b518c00b2e420d22c7ee22084d16e9f3655 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 15:56:59 +0000 Subject: [PATCH 3/6] Improve texture cancellation fix to preserve dialog initialization Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com> --- .../multiview/widgets/TexturePanel.java | 26 ++++++++------ .../multiview/widgets/TexturePanelTest.java | 34 ++++++------------- 2 files changed, 27 insertions(+), 33 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 95f3966d..2b590398 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 @@ -266,30 +266,36 @@ private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI }//GEN-LAST:event_jCheckBox2ActionPerformed private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_texturePreviewMouseClicked + // Set the current texture on the editor so the dialog initializes correctly + if (textureName != null && !textureName.equals("\"\"")) { + String currentTexture = extractTextureName(textureName); + editor.setAsText(currentTexture); + } else { + editor.setAsText(null); + } + Component view = editor.getCustomEditor(); - String originalValue = property.getValue(); // Store original value before clearing - String originalTextureName = textureName; // Store original texture name - property.setValue(EMPTY); view.setVisible(true); + if (editor.getValue() != null) { + // A texture was selected + property.setValue(EMPTY); // Clear before setting new value textureName = "\"" + editor.getAsText() + "\""; displayPreview(); updateFlipRepeat(); fireChanged(); - } else { // "No Texture" has been clicked or dialog was cancelled + } else { + // getValue() is null - either "No Texture" was selected or dialog was cancelled String asText = editor.getAsText(); if (asText == null) { - // "No Texture" was explicitly selected + // "No Texture" was explicitly selected (setAsText(null) was called) + property.setValue(EMPTY); textureName = "\"\""; texturePreview.setIcon(null); texturePreview.setToolTipText(""); fireChanged(); - } else { - // Dialog was cancelled, restore original values - property.setValue(originalValue); - textureName = originalTextureName; - displayPreview(); // Restore the preview } + // If asText is not null, it means dialog was cancelled - do nothing to preserve original state } }//GEN-LAST:event_texturePreviewMouseClicked 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 910f076c..8b56b2f4 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 @@ -187,21 +187,16 @@ public void testTexturePreviewClickCancel() { texturePanel.textureName = originalTexture; // Simulate the user clicking on texture preview and then canceling - // This is a simplified version of what happens in texturePreviewMouseClicked - String originalValue = texturePanel.property.getValue(); - String originalTextureName = texturePanel.textureName; + // In the fixed implementation, the property is not cleared until we know the user's choice - // Clear the property (this happens when the dialog opens) - texturePanel.property.setValue(""); + // Simulate cancel: editor.getValue() returns null and editor.getAsText() returns original texture + // (the editor was initialized with the current texture, and cancel doesn't change it) + String asText = "original_texture.jpg"; // Would be returned by editor.getAsText() on cancel - // Simulate cancel: editor.getValue() returns null and editor.getAsText() returns original value - // (not null, because setAsText was never called) - // This is the logic from the fixed texturePreviewMouseClicked method - String asText = originalTexture; // Would be returned by editor.getAsText() on cancel + // This simulates the logic from the fixed texturePreviewMouseClicked method if (asText != null) { - // Dialog was cancelled, restore original values - texturePanel.property.setValue(originalValue); - texturePanel.textureName = originalTextureName; + // Dialog was cancelled - do nothing to preserve original state + // Property and textureName remain unchanged } // Verify that the original texture is preserved @@ -222,23 +217,16 @@ public void testTexturePreviewClickNoTexture() { texturePanel.textureName = originalTexture; // Simulate the user clicking on texture preview and then selecting "No Texture" - String originalValue = texturePanel.property.getValue(); - String originalTextureName = texturePanel.textureName; - - // Clear the property (this happens when the dialog opens) - texturePanel.property.setValue(""); + // In the fixed implementation, the property is not cleared until we know the user's choice // Simulate "No Texture" selection: editor.getValue() returns null and editor.getAsText() returns null - // This is the logic from the fixed texturePreviewMouseClicked method String asText = null; // Would be returned by editor.getAsText() when "No Texture" is selected + + // This simulates the logic from the fixed texturePreviewMouseClicked method if (asText == null) { // "No Texture" was explicitly selected - texturePanel.textureName = "\"\""; texturePanel.property.setValue(""); - } else { - // Dialog was cancelled, restore original values - texturePanel.property.setValue(originalValue); - texturePanel.textureName = originalTextureName; + texturePanel.textureName = "\"\""; } // Verify that the texture is properly cleared From 6bcbf134188a8f8deedd8ee59eb36d2e6348312a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 21 Sep 2025 16:00:02 +0000 Subject: [PATCH 4/6] Changes before error encountered Co-authored-by: neph1 <7988802+neph1@users.noreply.github.com> --- .../multiview/widgets/TexturePanel.java | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 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 2b590398..a6ccae21 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 @@ -267,9 +267,10 @@ private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_texturePreviewMouseClicked // Set the current texture on the editor so the dialog initializes correctly + String originalAssetKey = null; if (textureName != null && !textureName.equals("\"\"")) { - String currentTexture = extractTextureName(textureName); - editor.setAsText(currentTexture); + originalAssetKey = extractTextureName(textureName); + editor.setAsText(originalAssetKey); } else { editor.setAsText(null); } @@ -277,26 +278,32 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI Component view = editor.getCustomEditor(); view.setVisible(true); - if (editor.getValue() != null) { - // A texture was selected + // Check what the user selected by examining the editor state after the dialog + String newAssetKey = editor.getAsText(); + + if (newAssetKey != null && !newAssetKey.equals(originalAssetKey)) { + // A different texture was selected property.setValue(EMPTY); // Clear before setting new value - textureName = "\"" + editor.getAsText() + "\""; + textureName = "\"" + newAssetKey + "\""; displayPreview(); updateFlipRepeat(); fireChanged(); - } else { - // getValue() is null - either "No Texture" was selected or dialog was cancelled - String asText = editor.getAsText(); - if (asText == null) { - // "No Texture" was explicitly selected (setAsText(null) was called) - property.setValue(EMPTY); - textureName = "\"\""; - texturePreview.setIcon(null); - texturePreview.setToolTipText(""); - fireChanged(); - } - // If asText is not null, it means dialog was cancelled - do nothing to preserve original state + } else if (newAssetKey == null && originalAssetKey != null) { + // "No Texture" was explicitly selected (from having a texture to null) + property.setValue(EMPTY); + textureName = "\"\""; + texturePreview.setIcon(null); + texturePreview.setToolTipText(""); + fireChanged(); + } else if (newAssetKey == null && originalAssetKey == null) { + // "No Texture" was selected when no texture was already set + property.setValue(EMPTY); + textureName = "\"\""; + texturePreview.setIcon(null); + texturePreview.setToolTipText(""); + fireChanged(); } + // If newAssetKey equals originalAssetKey, then dialog was cancelled - do nothing }//GEN-LAST:event_texturePreviewMouseClicked @Override From 7ef9a1d8e425ddd1861fb9ec9b8d84027153c5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rickard=20Ed=C3=A9n?= Date: Sun, 21 Sep 2025 19:46:36 +0200 Subject: [PATCH 5/6] Update jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java --- .../gde/materials/multiview/widgets/TexturePanel.java | 9 +-------- 1 file changed, 1 insertion(+), 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 a6ccae21..dee28ac1 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 @@ -288,14 +288,7 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI displayPreview(); updateFlipRepeat(); fireChanged(); - } else if (newAssetKey == null && originalAssetKey != null) { - // "No Texture" was explicitly selected (from having a texture to null) - property.setValue(EMPTY); - textureName = "\"\""; - texturePreview.setIcon(null); - texturePreview.setToolTipText(""); - fireChanged(); - } else if (newAssetKey == null && originalAssetKey == null) { + } else if (newAssetKey == null) { // "No Texture" was selected when no texture was already set property.setValue(EMPTY); textureName = "\"\""; From 374225842ef98fcee7b1b61f9d0b15aa57e8dc90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rickard=20Ed=C3=A9n?= Date: Sun, 21 Sep 2025 19:48:00 +0200 Subject: [PATCH 6/6] Update jme3-materialeditor/src/com/jme3/gde/materials/multiview/widgets/TexturePanel.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../com/jme3/gde/materials/multiview/widgets/TexturePanel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 dee28ac1..3721d21d 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 @@ -289,7 +289,7 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI updateFlipRepeat(); fireChanged(); } else if (newAssetKey == null) { - // "No Texture" was selected when no texture was already set + // "No Texture" was selected, regardless of whether a texture was previously set property.setValue(EMPTY); textureName = "\"\""; texturePreview.setIcon(null);