33 * and open the template in the editor.
44 */
55
6- /*
6+ /*
77 * SelectionPanel.java
88 *
99 * Created on 14.06.2010, 16:52:22
2525import java .util .logging .Logger ;
2626
2727/**
28- * The TexturePanel is a row in the material editor representing a special texture
28+ * The TexturePanel is a row in the material editor representing a special
29+ * texture
30+ *
2931 * @author normenhansen
3032 */
3133public class TexturePanel extends MaterialPropertyWidget {
3234
33- private final TexturePropertyEditor editor ;
34- private final ProjectAssetManager manager ;
35+ private TexturePropertyEditor editor ;
36+ private ProjectAssetManager manager ;
3537 private boolean flip = false ;
3638 private boolean repeat = false ;
3739 protected String textureName = null ; // always enclosed with ""
3840 private TexturePreview texPreview ;
3941 private final ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor (1 );
4042
41- /** Creates new form SelectionPanel */
43+ /**
44+ * Used by tests
45+ */
46+ protected TexturePanel () {
47+
48+ }
49+
50+ /**
51+ * Creates new form SelectionPanel
52+ */
4253 public TexturePanel (ProjectAssetManager manager ) {
4354 this .manager = manager ;
4455 editor = new TexturePropertyEditor (manager );
@@ -50,25 +61,27 @@ private void displayPreview() {
5061 exec .execute (new Runnable () {
5162 @ Override
5263 public void run () {
53- try {
64+ try {
5465 if (texPreview == null ) {
5566 texPreview = new TexturePreview (manager );
5667 }
57- final String [] textureNameComponents = textureName .split (" " );
58- texPreview .requestPreview (stripQuotes (textureNameComponents [textureNameComponents .length - 1 ]), "" , 80 , 25 , texturePreview , null );
68+ texPreview .requestPreview (extractTextureName (textureName ), "" , 80 , 25 , texturePreview , null );
5969 } catch (AssetNotFoundException a ) {
6070 Logger .getLogger (MaterialEditorTopComponent .class .getName ()).log (Level .WARNING , "Could not load texture {0}" , textureName );
6171 }
6272 }
6373 });
6474 }
6575 }
66-
67- private String stripQuotes (String s ) {
68- return s .substring (1 , s .length () - 1 );
76+
77+ // visible for tests
78+ protected String extractTextureName (String textureName ) {
79+ final String [] textureNameComponents = textureName .split ("\" " );
80+ return textureNameComponents [textureNameComponents .length - 1 ];
6981 }
7082
71- private void updateFlipRepeat () {
83+ // visible for tests
84+ protected void updateFlipRepeat () {
7285 String propertyValue = property .getValue ();
7386 propertyValue = propertyValue .replaceFirst (textureName , "" );
7487 if (flip && !propertyValue .contains ("Flip " )) {
@@ -104,10 +117,10 @@ private static BufferedImage resizeImage(BufferedImage originalImage) {
104117 return resizedImage ;
105118 }
106119
107- /** This method is called from within the constructor to
108- * initialize the form.
109- * WARNING: Do NOT modify this code. The content of this method is
110- * always regenerated by the Form Editor.
120+ /**
121+ * This method is called from within the constructor to initialize the form.
122+ * WARNING: Do NOT modify this code. The content of this method is always
123+ * regenerated by the Form Editor.
111124 */
112125 @ SuppressWarnings ("unchecked" )
113126 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
@@ -263,6 +276,7 @@ private void jCheckBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FI
263276
264277 private void texturePreviewMouseClicked (java .awt .event .MouseEvent evt ) {//GEN-FIRST:event_texturePreviewMouseClicked
265278 Component view = editor .getCustomEditor ();
279+ property .setValue ("" );
266280 view .setVisible (true );
267281 if (editor .getValue () != null ) {
268282 textureName = "\" " + editor .getAsText () + "\" " ;
@@ -273,7 +287,6 @@ private void texturePreviewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FI
273287 textureName = "\" \" " ;
274288 texturePreview .setIcon (null );
275289 texturePreview .setToolTipText ("" );
276- property .setValue ("" );
277290 fireChanged ();
278291 }
279292 }//GEN-LAST:event_texturePreviewMouseClicked
0 commit comments