Author: sletellier Date: 2012-06-14 15:12:29 +0200 (Thu, 14 Jun 2012) New Revision: 2329 Url: http://nuiton.org/repositories/revision/jaxx/2329 Log: - fixes #2137 : Add component to choose a file - add file choose demo ui - add guava dependency - add open icon Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/FileEditorDemo.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java trunk/jaxx-widgets/src/main/resources/icons/action-open.png Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/DatePickerDemo.jaxx trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties trunk/jaxx-widgets/pom.xml Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/DatePickerDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/DatePickerDemo.jaxx 2012-06-14 09:50:58 UTC (rev 2328) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/DatePickerDemo.jaxx 2012-06-14 13:12:29 UTC (rev 2329) @@ -61,7 +61,7 @@ <Table fill='both'> <row> - <cell columns='2'> + <cell columns='2' fill='horizontal' weightx='1'> <JCheckBox id='showPopupButton' text='jaxxdemo.datePickerEditor.showPopupButton' selected='false'/> @@ -71,17 +71,14 @@ <cell> <JLabel text='jaxxdemo.datePickerEditor.patternLayout'/> </cell> - <cell> + <cell fill='horizontal' weightx='1'> <JTextField id='patternLayoutField' text='{patternLayout}' onFocusLost='setPatternLayout(patternLayoutField.getText())'/> </cell> </row> <row> - <cell> - <JLabel text='jaxxdemo.i18neditor.datePicker'/> - </cell> - <cell> + <cell fill='horizontal' weightx='1' columns='2'> <JAXXDatePicker id='datePicker' date='{date}' patternLayout='{patternLayout}' @@ -93,7 +90,7 @@ <cell> <JLabel text='jaxxdemo.datePickerEditor.dateResult'/> </cell> - <cell> + <cell fill='horizontal' weightx='1'> <JLabel id='resultView' text='{dateFormat.format(date)}'/> </cell> </row> Added: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/FileEditorDemo.jaxx =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/FileEditorDemo.jaxx (rev 0) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/editor/FileEditorDemo.jaxx 2012-06-14 13:12:29 UTC (rev 2329) @@ -0,0 +1,73 @@ +<!-- + #%L + JAXX :: Demo + $Id:$ + $HeadURL:$ + %% + Copyright (C) 2008 - 2012 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<jaxx.demo.DemoPanel> + <import> + jaxx.runtime.swing.editor.FileEditor + </import> + + <String id='title' javaBean='"Open file"'/> + <String id='exts' javaBean='"txt, png"'/> + <String id='extsDescription' javaBean='"Text (*.txt), Images (*.png)"'/> + + <Table fill='both'> + <row> + <cell fill='horizontal' weightx='1'> + <JLabel text='jaxxdemo.fileEditor.titleLbl'/> + </cell> + <cell fill='horizontal' weightx='1'> + <JTextField id='titleField' + text='{getTitle()}' + onKeyReleased='setTitle(titleField.getText())'/> + </cell> + </row> + <row> + <cell fill='horizontal' weightx='1'> + <JLabel text='jaxxdemo.fileEditor.extsLbl'/> + </cell> + <cell fill='horizontal' weightx='1'> + <JTextField id='extsField' + text='{getExts()}' + onKeyReleased='setExts(extsField.getText())'/> + </cell> + </row> + <row> + <cell fill='horizontal' weightx='1'> + <JLabel text='jaxxdemo.fileEditor.extsDescLbl'/> + </cell> + <cell fill='horizontal' weightx='1'> + <JTextField id='extsDescriptionField' + text='{getExtsDescription()}' + onKeyReleased='setExtsDescription(extsDescriptionField.getText())'/> + </cell> + </row> + <row> + <cell fill='horizontal' weightx='1' columns='2'> + <FileEditor id='fileChooser' + title='{getTitle()}' + exts='{getExts()}' + extsDescription='{getExtsDescription()}'/> + </cell> + </row> + </Table> +</jaxx.demo.DemoPanel> Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java 2012-06-14 09:50:58 UTC (rev 2328) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/tree/DemoDataProvider.java 2012-06-14 13:12:29 UTC (rev 2329) @@ -33,6 +33,7 @@ import jaxx.demo.component.jaxx.StatusMessagePanelDemo; import jaxx.demo.component.jaxx.editor.ComboEditorDemo; import jaxx.demo.component.jaxx.editor.DatePickerDemo; +import jaxx.demo.component.jaxx.editor.FileEditorDemo; import jaxx.demo.component.jaxx.editor.I18nEditorDemo; import jaxx.demo.component.jaxx.editor.NumberEditorDemo; import jaxx.demo.component.jaxx.editor.TimeEditorDemo; @@ -153,7 +154,8 @@ NumberEditorDemo.class, ComboEditorDemo.class, I18nEditorDemo.class, - DatePickerDemo.class + DatePickerDemo.class, + FileEditorDemo.class ); addMapping(n_("jaxxdemo.feature"), Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties 2012-06-14 09:50:58 UTC (rev 2328) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_en_GB.properties 2012-06-14 13:12:29 UTC (rev 2329) @@ -195,6 +195,9 @@ jaxxdemo.feature.databinding=Data Binding jaxxdemo.feature.nav=Jaxx nav API jaxxdemo.feature.validation=Validation +jaxxdemo.fileEditor.extsDescLbl=Extensions description (separated by comma, ex \: text (*.txt), images (*.png)) +jaxxdemo.fileEditor.extsLbl=Extensions (separated by comma, ex \: txt, png) +jaxxdemo.fileEditor.titleLbl=Open dialog title jaxxdemo.fun=Fun jaxxdemo.i18neditor.configuration=Configuration jaxxdemo.i18neditor.popup.title=Title of popup Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties 2012-06-14 09:50:58 UTC (rev 2328) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_es_ES.properties 2012-06-14 13:12:29 UTC (rev 2329) @@ -195,6 +195,9 @@ jaxxdemo.feature.databinding=Data binding jaxxdemo.feature.nav=API JAXX pour les arbres jaxxdemo.feature.validation=Validation +jaxxdemo.fileEditor.extsDescLbl=Description des extensions (séparées par des virgules, ex \: Texte (*.txt), Images (*.png)) +jaxxdemo.fileEditor.extsLbl=Extensions (separated by comma, ex \: txt, png) +jaxxdemo.fileEditor.titleLbl=Titre du dialog d'ouverture de fichier jaxxdemo.fun=Fun jaxxdemo.i18neditor.configuration=Configuration jaxxdemo.i18neditor.popup.title=Titre de la popup Modified: trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties =================================================================== --- trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties 2012-06-14 09:50:58 UTC (rev 2328) +++ trunk/jaxx-demo/src/main/resources/i18n/jaxx-demo_fr_FR.properties 2012-06-14 13:12:29 UTC (rev 2329) @@ -195,6 +195,9 @@ jaxxdemo.feature.databinding=Data binding jaxxdemo.feature.nav=API JAXX pour les arbres jaxxdemo.feature.validation=Validation +jaxxdemo.fileEditor.extsDescLbl=Description des extensions (séparées par des virgules, ex \: Texte (*.txt), Images (*.png)) +jaxxdemo.fileEditor.extsLbl=Extensions (separated by comma, ex \: txt, png) +jaxxdemo.fileEditor.titleLbl=Titre de la fenêtre de sélection de fichier jaxxdemo.fun=Fun jaxxdemo.i18neditor.configuration=Configuration jaxxdemo.i18neditor.popup.title=Titre de la popup Modified: trunk/jaxx-widgets/pom.xml =================================================================== --- trunk/jaxx-widgets/pom.xml 2012-06-14 09:50:58 UTC (rev 2328) +++ trunk/jaxx-widgets/pom.xml 2012-06-14 13:12:29 UTC (rev 2329) @@ -67,6 +67,11 @@ </dependency> <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + + <dependency> <groupId>commons-lang</groupId> <artifactId>commons-lang</artifactId> </dependency> Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx 2012-06-14 13:12:29 UTC (rev 2329) @@ -0,0 +1,84 @@ +<!-- + #%L + JAXX :: Widgets + $Id:$ + $HeadURL:$ + %% + Copyright (C) 2008 - 2012 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> +<Table> + + <import> + java.io.File + java.beans.PropertyChangeEvent + java.beans.PropertyChangeListener + </import> + + <FileEditorHandler id='handler' constructorParams='this'/> + + <Boolean id='acceptAllFileFilterUsed' javaBean='Boolean.TRUE'/> + + <File id='selectedFile' javaBean='null'/> + + <File id='startFile' javaBean='null'/> + + <String id='title' javaBean='null'/> + + <String id='exts' javaBean='null'/> + + <String id='extsDescription' javaBean='null'/> + + <script><![CDATA[ + protected void $afterCompleteSetup() { + + addPropertyChangeListener(PROPERTY_START_FILE, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (startFile != null) { + pathField.setText(startFile.getAbsolutePath()); + } + } + }); + + addPropertyChangeListener(PROPERTY_SELECTED_FILE, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (selectedFile != null) { + pathField.setText(selectedFile.getAbsolutePath()); + } + } + }); + } + ]]></script> + + <row> + <cell fill='horizontal' weightx='1'> + <JTextField id='pathField' + enabled='{isEnabled()}' + onFocusLost='setSelectedFile(new File(pathField.getText()))'/> + </cell> + <cell> + <JButton id='boutonXslLocation' + enabled='{isEnabled()}' + actionIcon='open' + onActionPerformed='handler.openLocation()'/> + </cell> + </row> +</Table> \ No newline at end of file Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java 2012-06-14 13:12:29 UTC (rev 2329) @@ -0,0 +1,105 @@ +/* + * #%L + * JAXX :: Widgets + * $Id:$ + * $HeadURL:$ + * %% + * Copyright (C) 2008 - 2012 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ +package jaxx.runtime.swing.editor; + +import com.google.common.io.Files; +import java.io.File; +import javax.swing.JFileChooser; +import javax.swing.filechooser.FileFilter; + +/** + * @author sletellier <letellier@codelutin.com> + */ +public class FileEditorHandler { + + public static final String SEPARATOR_REGEX = "\\s*,\\s*"; + protected FileEditor view; + + public FileEditorHandler(FileEditor view) { + this.view = view; + } + + public void openLocation() { + + // use last selected file + File startFile = view.getSelectedFile(); + if (startFile == null) { + + // else filed start file + startFile = view.getStartFile(); + } + if (startFile == null) { + + // else start with user home + startFile = new File(System.getProperty("user.home")); + } + JFileChooser fc = new JFileChooser(startFile); + + fc.setDialogTitle(view.getTitle()); + fc.setAcceptAllFileFilterUsed(view.getAcceptAllFileFilterUsed()); + + String extsAsString = view.getExts(); + if (extsAsString != null) { + + // extentions can be separted by comma + String[] exts = extsAsString.split(SEPARATOR_REGEX); + String[] descs = view.getExtsDescription().split(SEPARATOR_REGEX); + for (int i = 0;i<exts.length;i++) { + + fc.addChoosableFileFilter(new ExtentionFileFiler(exts[i], descs[i])); + } + } + + // show dialog + fc.showOpenDialog(view); + + // get selected to display in ui + File file = fc.getSelectedFile(); + view.setSelectedFile(file); + } + + public static class ExtentionFileFiler extends FileFilter { + protected String ext; + protected String desciption; + + public ExtentionFileFiler(String ext, String desciption) { + this.ext = ext; + this.desciption = desciption; + } + + @Override + public boolean accept(File file) { + if (file.isDirectory()) { + return true; + } + String fileExtension = Files.getFileExtension(file.getName()); + return ext.equals(fileExtension); + } + + @Override + public String getDescription() { + return desciption; + } + } +} Added: trunk/jaxx-widgets/src/main/resources/icons/action-open.png =================================================================== (Binary files differ) Property changes on: trunk/jaxx-widgets/src/main/resources/icons/action-open.png ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream