22
33import com .ss .editor .Messages ;
44import com .ss .editor .config .EditorConfig ;
5+ import com .ss .editor .manager .JavaFXImageManager ;
56import com .ss .editor .ui .component .asset .tree .ResourceTree ;
67import com .ss .editor .ui .component .asset .tree .resource .ResourceElement ;
78import com .ss .editor .ui .dialog .EditorDialog ;
89
910import java .awt .*;
11+ import java .nio .file .Files ;
1012import java .nio .file .Path ;
1113import java .util .function .Consumer ;
1214
1315import javafx .geometry .Insets ;
16+ import javafx .geometry .Pos ;
1417import javafx .scene .control .Button ;
1518import javafx .scene .control .MultipleSelectionModel ;
1619import javafx .scene .control .TreeItem ;
20+ import javafx .scene .image .Image ;
21+ import javafx .scene .image .ImageView ;
1722import javafx .scene .layout .HBox ;
1823import javafx .scene .layout .VBox ;
1924import rlib .ui .util .FXUtils ;
2227import static com .ss .editor .ui .css .CSSIds .ASSET_EDITOR_DIALOG_BUTTON_CANCEL ;
2328import static com .ss .editor .ui .css .CSSIds .ASSET_EDITOR_DIALOG_BUTTON_CONTAINER ;
2429import static com .ss .editor .ui .css .CSSIds .ASSET_EDITOR_DIALOG_BUTTON_OK ;
30+ import static com .ss .editor .ui .css .CSSIds .ASSET_EDITOR_DIALOG_PREVIEW_CONTAINER ;
2531
2632/**
2733 * Реализация диалога для выбора объекта из Asset.
@@ -33,6 +39,9 @@ public class AssetEditorDialog extends EditorDialog {
3339 private static final Insets OK_BUTTON_OFFSET = new Insets (0 , 4 , 0 , 0 );
3440 private static final Insets CANCEL_BUTTON_OFFSET = new Insets (0 , 15 , 0 , 0 );
3541
42+ private static final Insets PREVIEW_OFFSET = new Insets (0 , 15 , 0 , 0 );
43+ public static final JavaFXImageManager JAVA_FX_IMAGE_MANAGER = JavaFXImageManager .getInstance ();
44+
3645 /**
3746 * Функция для использования выбранного ресурса.
3847 */
@@ -43,13 +52,21 @@ public class AssetEditorDialog extends EditorDialog {
4352 */
4453 private ResourceTree resourceTree ;
4554
55+ /**
56+ * Превью картинок.
57+ */
58+ private ImageView imageView ;
59+
4660 public AssetEditorDialog (final Consumer <Path > consumer ) {
4761 this .consumer = consumer ;
4862 }
4963
5064 @ Override
5165 protected void createContent (final VBox root ) {
5266
67+ final HBox container = new HBox ();
68+ container .setAlignment (Pos .CENTER_LEFT );
69+
5370 final EditorConfig editorConfig = EditorConfig .getInstance ();
5471 final Consumer <ResourceElement > openFunction = element -> {
5572
@@ -62,8 +79,55 @@ protected void createContent(final VBox root) {
6279 resourceTree = new ResourceTree (openFunction , true );
6380 resourceTree .fill (editorConfig .getCurrentAsset ());
6481 resourceTree .prefHeightProperty ().bind (root .heightProperty ());
82+ resourceTree .prefWidthProperty ().bind (root .widthProperty ());
83+ resourceTree .getSelectionModel ().selectedItemProperty ().addListener ((observable , oldValue , newValue ) -> processSelected (newValue ));
84+
85+
86+ final VBox previewContainer = new VBox ();
87+ previewContainer .setId (ASSET_EDITOR_DIALOG_PREVIEW_CONTAINER );
88+
89+ imageView = new ImageView ();
90+ imageView .fitHeightProperty ().bind (previewContainer .heightProperty ().subtract (2 ));
91+ imageView .fitWidthProperty ().bind (previewContainer .widthProperty ().subtract (2 ));
92+
93+ FXUtils .addToPane (resourceTree , container );
94+ FXUtils .addToPane (imageView , previewContainer );
95+ FXUtils .addToPane (previewContainer , container );
96+ FXUtils .addToPane (container , root );
97+
98+ HBox .setMargin (previewContainer , PREVIEW_OFFSET );
99+ }
100+
101+ /**
102+ * @return превью картинок.
103+ */
104+ private ImageView getImageView () {
105+ return imageView ;
106+ }
107+
108+ /**
109+ * Обработка выбора в дереве элемента.
110+ */
111+ private void processSelected (final TreeItem <ResourceElement > newValue ) {
112+
113+ final ImageView imageView = getImageView ();
114+
115+ if (newValue == null ) {
116+ imageView .setImage (null );
117+ return ;
118+ }
119+
120+ final ResourceElement element = newValue .getValue ();
121+ final Path file = element .getFile ();
122+
123+ if (Files .isDirectory (file ) || !JavaFXImageManager .isImage (file )) {
124+ imageView .setImage (null );
125+ return ;
126+ }
127+
128+ final Image preview = JAVA_FX_IMAGE_MANAGER .getTexturePreview (file , (int ) imageView .getFitWidth (), (int ) imageView .getFitHeight ());
65129
66- FXUtils . addToPane ( resourceTree , root );
130+ imageView . setImage ( preview );
67131 }
68132
69133 @ Override
0 commit comments