From 2e0a24f1c33f0fce727fbc8be7d455130d8cc982 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Wed, 27 Apr 2022 00:24:09 +0200 Subject: [PATCH] [DEV] nearly fisnish to develop fileChooser --- old_widget/ListFileSystem.cpp | 0 old_widget/meta/FileChooser.cpp | 197 ---------- old_widget/meta/FileChooser.java | 106 ------ .../ewol/sampleButton/MainWindows.java | 6 +- src/org/atriasoft/ewol/object/EwolObject.java | 4 +- .../ewol/widget/WidgetXmlFactory.java | 2 + .../ewol/widget/meta/FileChooser.java | 345 ++++++++++++++++++ 7 files changed, 350 insertions(+), 310 deletions(-) delete mode 100644 old_widget/ListFileSystem.cpp delete mode 100644 old_widget/meta/FileChooser.cpp delete mode 100644 old_widget/meta/FileChooser.java create mode 100644 src/org/atriasoft/ewol/widget/meta/FileChooser.java diff --git a/old_widget/ListFileSystem.cpp b/old_widget/ListFileSystem.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/old_widget/meta/FileChooser.cpp b/old_widget/meta/FileChooser.cpp deleted file mode 100644 index 429890b..0000000 --- a/old_widget/meta/FileChooser.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ - - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -//#include -#include -#include -#include - -extern "C" { - // file browsing ... - #include -} - -#include -#include -ETK_DECLARE_TYPE(ewol::widget::FileChooser); - -ewol::widget::FileChooser::FileChooser() : - signalCancel(this, "cancel", ""), - signalValidate(this, "validate", ""), - propertyPath(this, "path", - etk::path::getHomePath(), - "", - ewol::widget::FileChooser::onChangePropertyPath), - propertyFile(this, "file", - "", - "", - ewol::widget::FileChooser::onChangePropertyFile), - propertyLabelTitle(this, "title", - "_T{FileChooser}", - "", - ewol::widget::FileChooser::onChangePropertyLabelTitle), - propertyLabelValidate(this, "label-validate", - "_T{Validate}", - "", - ewol::widget::FileChooser::onChangePropertyLabelValidate), - propertyLabelCancel(this, "label-cancel", - "_T{Cancel}", - "", - ewol::widget::FileChooser::onChangePropertyLabelCancel) { - addObjectType("ewol::widget::FileChooser"); -} - -void ewol::widget::FileChooser::init() { - ewol::widget::Composer::init(); - // Load file with replacing the "{ID}" with the local ID of the widget ==> obtain unique ID - loadFromFile("DATA:///ewol-gui-file-chooser.xml?lib=ewol", getId()); - // Basic replacement of labels - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:title-label", "value", propertyLabelTitle); - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:validate-label", "value", propertyLabelValidate); - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:cancel-label", "value", propertyLabelCancel); - - subBind(ewol::widget::CheckBox, "[" + etk::toString(getId()) + "]file-shooser:show-hiden-file", signalValue, sharedFromThis(), ewol::widget::FileChooser::onCallbackHidenFileChangeChangeValue); - subBind(ewol::widget::Button, "[" + etk::toString(getId()) + "]file-shooser:button-validate", signalPressed, sharedFromThis(), ewol::widget::FileChooser::onCallbackListValidate); - subBind(ewol::widget::Button, "[" + etk::toString(getId()) + "]file-shooser:button-cancel", signalPressed, sharedFromThis(), ewol::widget::FileChooser::onCallbackButtonCancelPressed); - subBind(ewol::widget::ListFileSystem, "[" + etk::toString(getId()) + "]file-shooser:list-folder", signalFolderValidate, sharedFromThis(), ewol::widget::FileChooser::onCallbackListFolderSelectChange); - subBind(ewol::widget::ListFileSystem, "[" + etk::toString(getId()) + "]file-shooser:list-files", signalFileSelect, sharedFromThis(), ewol::widget::FileChooser::onCallbackListFileSelectChange); - subBind(ewol::widget::ListFileSystem, "[" + etk::toString(getId()) + "]file-shooser:list-files", signalFileValidate, sharedFromThis(), ewol::widget::FileChooser::onCallbackListFileValidate); - subBind(ewol::widget::Entry, "[" + etk::toString(getId()) + "]file-shooser:entry-file", signalModify, sharedFromThis(), ewol::widget::FileChooser::onCallbackEntryFileChangeValue); - subBind(ewol::widget::Entry, "[" + etk::toString(getId()) + "]file-shooser:entry-file", signalEnter, sharedFromThis(), ewol::widget::FileChooser::onCallbackEntryFileChangeValidate); - subBind(ewol::widget::Entry, "[" + etk::toString(getId()) + "]file-shooser:entry-folder", signalModify, sharedFromThis(), ewol::widget::FileChooser::onCallbackEntryFolderChangeValue); - //composerBind(ewol::widget::CheckBox, "[" + etk::toString(getId()) + "]file-shooser:entry-folder", signalEnter, sharedFromThis(), ewol::widget::FileChooser::); - subBind(ewol::widget::Image, "[" + etk::toString(getId()) + "]file-shooser:img-home", signalPressed, sharedFromThis(), ewol::widget::FileChooser::onCallbackHomePressed); - // set the default Folder properties: - updateCurrentFolder(); - propertyCanFocus.set(true); -} - -void ewol::widget::FileChooser::onGetFocus() { - // transfert focus on a specific widget... - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:entry-file", "focus", "true"); -} - -ewol::widget::FileChooser::~FileChooser() { - -} - -void ewol::widget::FileChooser::onChangePropertyPath() { - propertyPath.getDirect() = *propertyPath + "/"; - updateCurrentFolder(); -} - -void ewol::widget::FileChooser::onChangePropertyFile() { - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:entry-file", "value", propertyFile.getFileName()); - //updateCurrentFolder(); -} - -void ewol::widget::FileChooser::onChangePropertyLabelTitle() { - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:title-label", "value", propertyLabelTitle); -} - -void ewol::widget::FileChooser::onChangePropertyLabelValidate() { - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:validate-label", "value", propertyLabelValidate); -} - -void ewol::widget::FileChooser::onChangePropertyLabelCancel() { - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:cancel-label", "value", propertyLabelCancel); -} - -void ewol::widget::FileChooser::onCallbackEntryFolderChangeValue( String _value) { - // == > change the folder name - // TODO : change the folder, if it exit ... -} - -void ewol::widget::FileChooser::onCallbackEntryFileChangeValue( String _value) { - // == > change the file name.get(.get( - propertyFile.setDirect(_value); - // update the selected file in the list : - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:list-files", "select", propertyFile.getString()); -} - -void ewol::widget::FileChooser::onCallbackButtonCancelPressed() { - // == > Auto remove ... - signalCancel.emit(); - autoDestroy(); -} - -void ewol::widget::FileChooser::onCallbackHidenFileChangeChangeValue( bool _value) { - if (_value == true) { - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:list-folder", "show-hidden", "true"); - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:list-files", "show-hidden", "true"); - } else { - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:list-folder", "show-hidden", "false"); - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:list-files", "show-hidden", "false"); - } -} - -void ewol::widget::FileChooser::onCallbackListFolderSelectChange( etk::Path _value) { - // == > this is an internal event ... - Log.debug(" old PATH: '" + *propertyPath + "' ==> '" + _value + "'"); - propertyPath.setDirect(_value); - Log.debug("new PATH: '" + *propertyPath + "'"); - propertyFile.setDirect(""); - updateCurrentFolder(); -} - -void ewol::widget::FileChooser::onCallbackListFileSelectChange( etk::Path _value) { - propertyFile.set(_value); - /* - String tmpFileCompleatName = this.folder; - tmpFileCompleatName += this.file; - // TODO : generateEventId(_msg.getMessage(), tmpFileCompleatName); - */ -} - -void ewol::widget::FileChooser::onCallbackListFileValidate( etk::Path _value) { - // select the file == > generate a validate - propertyFile.set(_value); - Log.verbose(" generate a fiel opening : '" + propertyFile + "'"); - signalValidate.emit(_value); - autoDestroy(); -} - -void ewol::widget::FileChooser::onCallbackEntryFileChangeValidate( String _value) { - onCallbackListFileValidate(_value); -} - -void ewol::widget::FileChooser::onCallbackListValidate() { - if (propertyFile.get() == "") { - Log.warning(" Validate : '" + *propertyFile + "' ==> error No name ..."); - return; - } - Log.debug(" generate a file opening : '" + *propertyFile + "'"); - signalValidate.emit(*propertyFile); - autoDestroy(); -} - -void ewol::widget::FileChooser::onCallbackHomePressed() { - etk::Path tmpUserFolder = etk::path::getHomePath(); - Log.debug("new PATH: '" + tmpUserFolder + "'"); - - propertyPath.setDirect(tmpUserFolder); - propertyFile.setDirect(""); - updateCurrentFolder(); -} - -void ewol::widget::FileChooser::updateCurrentFolder() { - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:list-files", "path", propertyPath.getString()); - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:list-folder", "path", propertyPath.getString()); - propertySetOnWidgetNamed("[" + etk::toString(getId()) + "]file-shooser:entry-folder", "value", propertyPath.getString()); - markToRedraw(); -} diff --git a/old_widget/meta/FileChooser.java b/old_widget/meta/FileChooser.java deleted file mode 100644 index e8fb9e8..0000000 --- a/old_widget/meta/FileChooser.java +++ /dev/null @@ -1,106 +0,0 @@ -/** @file - * @author Edouard DUPIN - * @copyright 2011, Edouard DUPIN, all right reserved - * @license MPL v2.0 (see license file) - */ -#pragma once - -#include -#include -#include -#include - -namespace ewol { - namespace widget { - class FileChooser; - using FileChooser = ememory::Ptr; - using FileChooserWeak = ememory::WeakPtr; - /** - * File Chooser is a simple selector of file for opening, saving, and what you want ... - * - * As all other pop-up methode ( wost case we can have) the creating is simple , but event back is not all the time simple: - * - * Fist global static declaration and inclusion: - * [code style=c++] - * #include - * [/code] - * - * The first step is to create the file chooser pop-up : (never in the ructor!!!) - * [code style=c++] - * ewol::widget::FileChooser tmpWidget = ewol::widget::FileChooser::create(); - * if (tmpWidget == null) { - * APPL_ERROR("Can not open File chooser !!! "); - * return -1; - * } - * // register on the Validate event: - * tmpWidget.signalValidate.connect(sharedFromThis(), ****::onCallbackOpenFile); - * // no need of this event watching ... - * tmpWidget.signalCancel.connect(sharedFromThis(), ****::onCallbackClosePopUp); - * // set the title: - * tmpWidget.propertyLabelTitle.set("Open files ..."); - * // Set the validate Label: - * tmpWidget.propertyLabelValidate.set("Open"); - * // simply set a folder (by default this is the home folder) - * //tmpWidget.propertyPath.set("/home/me"); - * // add the widget as windows pop-up ... - * ewol::widget::Windows tmpWindows = getWindows(); - * if (tmpWindows == null) { - * APPL_ERROR("Can not get the current windows !!! "); - * return -1; - * } - * tmpWindows.popUpWidgetPush(tmpWidget); - * [/code] - * - * Now we just need to wait the the open event message. - * - * [code style=c++] - * void ****::onCallbackOpenFile( String _value) { - * APPL_INFO("Request open file : '" + _value + "'"); - * } - * void ****::onCallbackClosePopUp() { - * APPL_INFO("The File chooser has been closed"); - * } - * [/code] - * This is the best example of a Meta-widget. - */ - class FileChooser : public ewol::widget::Composer { - public: // signals - esignal::Signal<> signalCancel; //!< abort the display of the pop-up or press cancel button - esignal::Signal signalValidate; //!< select file(s) - public: // properties - eproperty::Value propertyPath; //!< Current path to explore - eproperty::Value propertyFile; //!< Selected file - eproperty::Value propertyLabelTitle; //!< Label of the pop-up (can use translation) - eproperty::Value propertyLabelValidate; //!< Label of validate button of the pop-up (can use translation) - eproperty::Value propertyLabelCancel; //!< Label of cancel/close button of the pop-up (can use translation) - protected: - FileChooser(); - void init() ; - public: - DECLARE_WIDGET_FACTORY(FileChooser, "FileChooser"); - ~FileChooser(); - private: - void updateCurrentFolder(); - public: - void onGetFocus() ; - private: - // callback functions: - void onCallbackEntryFolderChangeValue( String _value); - void onCallbackEntryFileChangeValue( String _value); - void onCallbackEntryFileChangeValidate( String _value); - void onCallbackButtonCancelPressed(); - void onCallbackHidenFileChangeChangeValue( bool _value); - void onCallbackListFolderSelectChange( etk::Path _value); - void onCallbackListFileSelectChange( etk::Path _value); - void onCallbackListFileValidate( etk::Path _value); - void onCallbackListValidate(); - void onCallbackHomePressed(); - protected: - void onChangePropertyPath(); - void onChangePropertyFile(); - void onChangePropertyLabelTitle(); - void onChangePropertyLabelValidate(); - void onChangePropertyLabelCancel(); - }; - }; -}; diff --git a/samples/src/sample/atriasoft/ewol/sampleButton/MainWindows.java b/samples/src/sample/atriasoft/ewol/sampleButton/MainWindows.java index a2fa9b6..6750fa1 100644 --- a/samples/src/sample/atriasoft/ewol/sampleButton/MainWindows.java +++ b/samples/src/sample/atriasoft/ewol/sampleButton/MainWindows.java @@ -11,15 +11,13 @@ public class MainWindows extends BasicWindows { public MainWindows() { setPropertyTitle("Simple Button test"); //final Widget data = Composer.composerGenerateString(""); - //final Widget data = Composer.composerGenerateString(""); + final Widget data = Composer.composerGenerateString(""); /* final Widget data = Composer.composerGenerateString(""); */ - - final Widget data = Composer.composerGenerateFile(new Uri("DATA", "ewol-gui-file-chooser.xml", "ewol")); + //final Widget data = Composer.composerGenerateFile(new Uri("DATA", "ewol-gui-file-chooser.xml", "ewol")); this.setTestWidget(data); - /* final Button simpleButton = Button .createLabelButton("1 - My button internal
2 - label
3 - an other text ...
4 - and an other line to be sure ..."); diff --git a/src/org/atriasoft/ewol/object/EwolObject.java b/src/org/atriasoft/ewol/object/EwolObject.java index 7543d6a..c04639b 100644 --- a/src/org/atriasoft/ewol/object/EwolObject.java +++ b/src/org/atriasoft/ewol/object/EwolObject.java @@ -32,7 +32,7 @@ public class EwolObject { private static Integer valUID = 0; //!< Static used for the unique ID definition /** - * get the curent the system inteface. + * get the current the system interface. * @return current reference on the instance. */ protected static EwolContext getContext() { @@ -60,8 +60,6 @@ public class EwolObject { private boolean isResource = false; //!< enable this when you want to declare this element is auto-remove - //@EwolPropertyDescription("Object name, might be a unique reference in all the program") - //@JacksonXmlProperty(isAttribute = true, localName = "name") protected String name = ""; //!< name of the element ... protected WeakReference parent = null; //!< Reference on the current parent. diff --git a/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java b/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java index 3a003d0..b013e31 100644 --- a/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java +++ b/src/org/atriasoft/ewol/widget/WidgetXmlFactory.java @@ -3,6 +3,7 @@ package org.atriasoft.ewol.widget; import java.util.HashMap; import java.util.Map; +import org.atriasoft.ewol.widget.meta.FileChooser; import org.atriasoft.exml.annotation.XmlFactory.InterfaceXmlFactoryAccess; public class WidgetXmlFactory implements InterfaceXmlFactoryAccess { @@ -18,6 +19,7 @@ public class WidgetXmlFactory implements InterfaceXmlFactoryAccess { listWidgetAvaillable.put("CheckBox", CheckBox.class); listWidgetAvaillable.put("ListFileSystem", ListFileSystem.class); listWidgetAvaillable.put("PopUp", PopUp.class); + listWidgetAvaillable.put("FileChooser", FileChooser.class); } @Override diff --git a/src/org/atriasoft/ewol/widget/meta/FileChooser.java b/src/org/atriasoft/ewol/widget/meta/FileChooser.java new file mode 100644 index 0000000..5934ecf --- /dev/null +++ b/src/org/atriasoft/ewol/widget/meta/FileChooser.java @@ -0,0 +1,345 @@ +/** @file + * @author Edouard DUPIN + * @copyright 2011, Edouard DUPIN, all right reserved + * @license MPL v2.0 (see license file) + */ +package org.atriasoft.ewol.widget.meta; + +import java.io.File; + +import org.atriasoft.esignal.Signal; +import org.atriasoft.esignal.SignalEmpty; +import org.atriasoft.etk.Uri; +import org.atriasoft.ewol.annotation.EwolDescription; +import org.atriasoft.ewol.annotation.EwolSignal; +import org.atriasoft.ewol.internal.Log; +import org.atriasoft.ewol.widget.Button; +import org.atriasoft.ewol.widget.CheckBox; +import org.atriasoft.ewol.widget.Composer; +import org.atriasoft.ewol.widget.Entry; +import org.atriasoft.ewol.widget.ImageDisplay; +import org.atriasoft.ewol.widget.Label; +import org.atriasoft.ewol.widget.ListFileSystem; +import org.atriasoft.exml.annotation.XmlAttribute; +import org.atriasoft.exml.annotation.XmlManaged; +import org.atriasoft.exml.annotation.XmlName; + +/** + * File Chooser is a simple selector of file for opening, saving, and what you want ... + * + * As all other pop-up methode ( wost case we can have) the creating is simple , but event back is not all the time simple: + * + * Fist global static declaration and inclusion: + * [code style=c++] + * package org.atriasoft.ewol.widget.meta.FileChooser; + * [/code] + * + * The first step is to create the file chooser pop-up : (never in the ructor!!!) + * [code style=c++] + * ewol::widget::FileChooser tmpWidget = ewol::widget::FileChooser::create(); + * if (tmpWidget == null) { + * APPL_ERROR("Can not open File chooser !!! "); + * return -1; + * } + * // register on the Validate event: + * tmpWidget.signalValidate.connect(sharedFromThis(), ****::onCallbackOpenFile); + * // no need of this event watching ... + * tmpWidget.signalCancel.connect(sharedFromThis(), ****::onCallbackClosePopUp); + * // set the title: + * tmpWidget.propertyLabelTitle.set("Open files ..."); + * // Set the validate Label: + * tmpWidget.propertyLabelValidate.set("Open"); + * // simply set a folder (by default this is the home folder) + * //tmpWidget.propertyPath.set("/home/me"); + * // add the widget as windows pop-up ... + * ewol::widget::Windows tmpWindows = getWindows(); + * if (tmpWindows == null) { + * APPL_ERROR("Can not get the current windows !!! "); + * return -1; + * } + * tmpWindows.popUpWidgetPush(tmpWidget); + * [/code] + * + * Now we just need to wait the the open event message. + * + * [code style=c++] + * void ****::onCallbackOpenFile( String _value) { + * APPL_INFO("Request open file : '" + _value + "'"); + * } + * void ****::onCallbackClosePopUp() { + * APPL_INFO("The File chooser has been closed"); + * } + * [/code] + * This is the best example of a Meta-widget. + */ +public class FileChooser extends Composer { + + static void onCallbackButtonCancelPressed(final FileChooser self, final Boolean value) { + if (!value) { + return; + } + // == > Auto remove ... + self.signalCancel.emit(); + self.autoDestroy(); + } + + protected static void onCallbackEntryFileChangeValidate(final FileChooser self, final String value) { + onCallbackListFileValidate(self, value); + } + + protected static void onCallbackEntryFileChangeValue(final FileChooser self, final String value) { + // == > change the file name.get(.get( + self.propertyFile = value; + // update the selected file in the list : + if (self.getSubObjectNamed("[" + Long.toString(self.getId()) + "]file-shooser:list-files") instanceof final ListFileSystem tmp) { + tmp.setPropertyFile(new File(self.propertyFile)); + } + } + + protected static void onCallbackEntryFolderChangeValue(final FileChooser self, final String value) { + // == > change the folder name + // TODO : change the folder, if it exit ... + } + + protected static void onCallbackHidenFileChangeChangeValue(final FileChooser self, final Boolean value) { + if (self.getSubObjectNamed("[" + Long.toString(self.getId()) + "]file-shooser:list-files") instanceof final ListFileSystem tmp) { + tmp.setPropertyShowHidden(value); + } + if (self.getSubObjectNamed("[" + Long.toString(self.getId()) + "]file-shooser:list-folder") instanceof final ListFileSystem tmp) { + tmp.setPropertyShowHidden(value); + } + } + + protected static void onCallbackHomePressed(final FileChooser self) { + final String tmpUserFolder = System.getProperty("user.home"); + Log.debug("new PATH: '" + tmpUserFolder + "'"); + + self.propertyPath = tmpUserFolder; + self.propertyFile = ""; + self.updateCurrentFolder(); + } + + protected static void onCallbackListFileSelectChange(final FileChooser self, final String value) { + self.setPropertyFile(value); + /* + String tmpFileCompleatName = this.folder; + tmpFileCompleatName += this.file; + // TODO : generateEventId(_msg.getMessage(), tmpFileCompleatName); + */ + } + + protected static void onCallbackListFileValidate(final FileChooser self, final String value) { + // select the file == > generate a validate + self.setPropertyFile(value); + Log.verbose(" generate a fiel opening : '" + self.propertyFile + "'"); + self.signalValidate.emit(value); + self.autoDestroy(); + } + + protected static void onCallbackListFolderSelectChange(final FileChooser self, final String value) { + // == > this is an internal event ... + Log.debug(" old PATH: '" + self.propertyPath + "' ==> '" + value + "'"); + self.propertyPath = value; + Log.debug("new PATH: '" + self.propertyPath + "'"); + self.propertyFile = ""; + self.updateCurrentFolder(); + } + + protected static void onCallbackListValidate(final FileChooser self, final Boolean value) { + if (!value) { + return; + } + if (self.propertyFile.isEmpty()) { + Log.warning(" Validate : '" + self.propertyFile + "' ==> error No name ..."); + return; + } + Log.debug(" generate a file opening : '" + self.propertyFile + "'"); + self.signalValidate.emit(self.propertyFile); + self.autoDestroy(); + } + + @EwolSignal(name = "cancel") + @EwolDescription(value = "Cancel button is pressed") + public SignalEmpty signalCancel; //!< abort the display of the pop-up or press cancel button + + @EwolSignal(name = "validate") + @EwolDescription(value = "Validate button is pressed") + public Signal signalValidate; //!< select file(s) + // properties + public String propertyPath = System.getProperty("user.home"); //!< Current path to explore + + public String propertyFile = ""; //!< Selected file + public String propertyLabelTitle = "_T{FileChooser}"; //!< Label of the pop-up (can use translation) + + public String propertyLabelValidate = "_T{Validate}"; //!< Label of validate button of the pop-up (can use translation) + public String propertyLabelCancel = "_T{Cancel}"; //!< Label of cancel/close button of the pop-up (can use translation) + + public FileChooser() { + // Load file with replacing the "{ID}" with the local ID of the widget ==> obtain unique ID + loadFromFile(new Uri("DATA", "ewol-gui-file-chooser.xml", "ewol")); + // Basic replacement of labels + onChangePropertyLabelTitle(); + onChangePropertyLabelValidate(); + onChangePropertyLabelCancel(); + + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:show-hiden-file") instanceof final CheckBox tmp) { + tmp.signalValue.connectAuto(this, FileChooser::onCallbackHidenFileChangeChangeValue); + } + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:button-validate") instanceof final Button tmp) { + tmp.signalValue.connectAuto(this, FileChooser::onCallbackListValidate); + } + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:button-cancel") instanceof final Button tmp) { + tmp.signalValue.connectAuto(this, FileChooser::onCallbackButtonCancelPressed); + } + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:list-folder") instanceof final ListFileSystem tmp) { + tmp.signalFolderValidate.connectAuto(this, FileChooser::onCallbackListFolderSelectChange); + } + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:list-files") instanceof final ListFileSystem tmp) { + tmp.signalFileSelect.connectAuto(this, FileChooser::onCallbackListFileSelectChange); + tmp.signalFileValidate.connectAuto(this, FileChooser::onCallbackListFileValidate); + } + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:entry-file") instanceof final Entry tmp) { + tmp.signalModify.connectAuto(this, FileChooser::onCallbackEntryFileChangeValue); + tmp.signalEnter.connectAuto(this, FileChooser::onCallbackEntryFileChangeValidate); + } + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:entry-folder") instanceof final Entry tmp) { + tmp.signalModify.connectAuto(this, FileChooser::onCallbackEntryFolderChangeValue); + } + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:img-home") instanceof final ImageDisplay tmp) { + tmp.signalPressed.connectAuto(this, FileChooser::onCallbackHomePressed); + } + // set the default Folder properties: + updateCurrentFolder(); + setPropertyCanFocus(true); + } + + public String getPropertyFile() { + return this.propertyFile; + } + + public String getPropertyLabelCancel() { + return this.propertyLabelCancel; + } + + // callback functions: + public String getPropertyLabelTitle() { + return this.propertyLabelTitle; + } + + public String getPropertyLabelValidate() { + return this.propertyLabelValidate; + } + + public String getPropertyPath() { + return this.propertyPath; + } + + protected void onChangePropertyFile() { + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:entry-file") instanceof final ListFileSystem tmp) { + tmp.setPropertyFile(new File(this.propertyFile)); + } + } + + protected void onChangePropertyLabelCancel() { + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:cancel-label") instanceof final Label tmp) { + tmp.setPropertyValue(this.propertyLabelCancel); + } + } + + protected void onChangePropertyLabelTitle() { + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:title-label") instanceof final Label tmp) { + tmp.setPropertyValue(this.propertyLabelTitle); + } + } + + protected void onChangePropertyLabelValidate() { + if (this.getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:validate-label") instanceof final Label tmp) { + tmp.setPropertyValue(this.propertyLabelValidate); + } + } + + protected void onChangePropertyPath() { + this.propertyPath = this.propertyPath + "/"; + updateCurrentFolder(); + } + + @Override + public void onGetFocus() { + // transfert focus on a specific widget... + if (getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:entry-folder") instanceof final Entry tmp) { + tmp.keepFocus(); + } + } + + @XmlManaged + @XmlAttribute + @XmlName(value = "file") + public void setPropertyFile(final String propertyFile) { + if (this.propertyFile.equals(propertyFile)) { + return; + } + this.propertyFile = propertyFile; + onChangePropertyFile(); + } + + @XmlManaged + @XmlAttribute + @XmlName(value = "label-cancel") + @EwolDescription(value = "Label for cancel button") + public void setPropertyLabelCancel(final String propertyLabelCancel) { + if (this.propertyLabelCancel.equals(propertyLabelCancel)) { + return; + } + this.propertyLabelCancel = propertyLabelCancel; + onChangePropertyLabelCancel(); + } + + @XmlManaged + @XmlAttribute + @XmlName(value = "title") + @EwolDescription(value = "Titile of the Pop-up") + public void setPropertyLabelTitle(final String propertyLabelTitle) { + if (this.propertyLabelTitle.equals(propertyLabelTitle)) { + return; + } + this.propertyLabelTitle = propertyLabelTitle; + onChangePropertyLabelTitle(); + } + + @XmlManaged + @XmlAttribute + @XmlName(value = "label-validate") + @EwolDescription(value = "Label for validate button") + public void setPropertyLabelValidate(final String propertyLabelValidate) { + if (this.propertyLabelValidate.equals(propertyLabelValidate)) { + return; + } + this.propertyLabelValidate = propertyLabelValidate; + onChangePropertyLabelValidate(); + } + + @XmlManaged + @XmlAttribute + @XmlName(value = "path") + @EwolDescription(value = "Path of the File chooser") + public void setPropertyPath(final String propertyPath) { + if (this.propertyPath.equals(propertyPath)) { + return; + } + this.propertyPath = propertyPath; + onChangePropertyPath(); + } + + private void updateCurrentFolder() { + if (getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:list-files") instanceof final ListFileSystem tmp) { + tmp.setPropertyPath(this.propertyPath); + } + if (getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:list-folder") instanceof final ListFileSystem tmp) { + tmp.setPropertyPath(this.propertyPath); + } + if (getSubObjectNamed("[" + Long.toString(getId()) + "]file-shooser:entry-folder") instanceof final Entry tmp) { + tmp.setPropertyValue(this.propertyPath); + } + markToRedraw(); + } +}