r731 - in trunk: . jrst jrst/src/main/java/org/nuiton/jrst/ui jrst/src/main/resources jrst/src/main/resources/icons
Author: tchemit Date: 2012-07-02 12:18:35 +0200 (Mon, 02 Jul 2012) New Revision: 731 Url: http://nuiton.org/repositories/revision/jrst/731 Log: refs #2130 : down to jaxx 2.4.2 Added: trunk/jrst/src/main/java/org/nuiton/jrst/ui/BaseActionPanel.java trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditor.jaxx trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditorHandler.java trunk/jrst/src/main/resources/icons/ trunk/jrst/src/main/resources/icons/action-open.png Modified: trunk/jrst/pom.xml trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx trunk/pom.xml Modified: trunk/jrst/pom.xml =================================================================== --- trunk/jrst/pom.xml 2012-06-29 23:56:47 UTC (rev 730) +++ trunk/jrst/pom.xml 2012-07-02 10:18:35 UTC (rev 731) @@ -215,7 +215,7 @@ <plugins> <plugin> <groupId>org.nuiton.jaxx</groupId> - <artifactId>jaxx-maven-plugin</artifactId> + <artifactId>maven-jaxx-plugin</artifactId> <executions> <execution> <goals> Added: trunk/jrst/src/main/java/org/nuiton/jrst/ui/BaseActionPanel.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/BaseActionPanel.java (rev 0) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/BaseActionPanel.java 2012-07-02 10:18:35 UTC (rev 731) @@ -0,0 +1,79 @@ +/* + * #%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 org.nuiton.jrst.ui; + +import javax.swing.JPanel; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * TODO sletellier 15/06/2012 : find a better way to add onActionPerform on custom components + * + * @author sletellier <letellier@codelutin.com> + */ +public abstract class BaseActionPanel + extends JPanel { + + /** + * Notifies all listeners that have registered interest for + * notification on this event type. + * + * @see javax.swing.event.EventListenerList + */ + protected void fireActionEvent() { + ActionEvent e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "actionPerformed"); + + // Guaranteed to return a non-null array + Object[] listeners = listenerList.getListenerList(); + // Process the listeners last to first, notifying + // those that are interested in this event + for (Object listener : listeners) { + if (ActionListener.class.isInstance(listener)) { + ((ActionListener) listener).actionPerformed(e); + } + } + } + + /** + * Adds an <code>ActionListener</code>. + * <p/> + * The <code>ActionListener</code> will receive an <code>ActionEvent</code> + * when a selection has been made. If the combo box is editable, then + * an <code>ActionEvent</code> will be fired when editing has stopped. + * + * @param l the <code>ActionListener</code> that is to be notified + */ + public void addActionListener(ActionListener l) { + listenerList.add(ActionListener.class, l); + } + + /** + * Removes an <code>ActionListener</code>. + * + * @param l the <code>ActionListener</code> to remove + */ + public void removeActionListener(ActionListener l) { + listenerList.remove(ActionListener.class, l); + } +} Added: trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditor.jaxx =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditor.jaxx (rev 0) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditor.jaxx 2012-07-02 10:18:35 UTC (rev 731) @@ -0,0 +1,77 @@ +<!-- + #%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% + --> +<BaseActionPanel layout='{new BorderLayout()}'> + <import> + java.io.File + java.beans.PropertyChangeEvent + java.beans.PropertyChangeListener + </import> + <!--jaxx.runtime.swing.BaseActionPanel--> + + <FileEditorHandler id='handler' constructorParams='this'/> + + <Boolean id='acceptAllFileFilterUsed' javaBean='Boolean.TRUE'/> + + <Boolean id='directoryEnabled' javaBean='Boolean.TRUE'/> + + <Boolean id='fileEnabled' javaBean='Boolean.TRUE'/> + + <File id='selectedFile' javaBean='null'/> + + <String id='startPath' javaBean='null'/> + + <String id='title' javaBean='null'/> + + <String id='exts' javaBean='null'/> + + <String id='extsDescription' javaBean='null'/> + + <script><![CDATA[ + protected void $afterCompleteSetup() { + + addPropertyChangeListener(PROPERTY_SELECTED_FILE, new PropertyChangeListener() { + + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (selectedFile != null) { + pathField.setText(selectedFile.getAbsolutePath()); + fireActionEvent(); + } + } + }); + } + ]]></script> + + <JTextField id='pathField' + constraints='BorderLayout.CENTER' + enabled='{isEnabled()}' + text='{getStartPath()}' + onFocusLost='setSelectedFile(new File(pathField.getText()))'/> + + <JButton id='boutonXslLocation' + constraints='BorderLayout.EAST' + enabled='{isEnabled()}' + actionIcon='open' + onActionPerformed='handler.openLocation()'/> +</BaseActionPanel> \ No newline at end of file Added: trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditorHandler.java =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditorHandler.java (rev 0) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/FileEditorHandler.java 2012-07-02 10:18:35 UTC (rev 731) @@ -0,0 +1,149 @@ +/* + * #%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 org.nuiton.jrst.ui; + +import com.google.common.io.Files; + +import javax.swing.*; +import javax.swing.filechooser.FileFilter; +import java.io.File; + +/** + * @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(); + String startPath = view.getStartPath(); + if (startFile == null && startPath != null) { + + + // else filed start path + startFile = new File(startPath); + } else { + + // 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()); + + // TODO sletellier 14/06/2012 : activate multi selection +// boolean multiSelectionEnabled = view.isMultiSelectionEnabled(); +// fc.setMultiSelectionEnabled(multiSelectionEnabled); + + // used to enable directory selection + boolean directoryEnabled = view.isDirectoryEnabled(); + if (directoryEnabled) { + fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + } + + // used to enable file selection + boolean fileEnabled = view.isFileEnabled(); + if (fileEnabled) { + + if (directoryEnabled) { + + // both + fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); + } else { + fc.setFileSelectionMode(JFileChooser.FILES_ONLY); + } + String extsAsString = view.getExts(); + if (extsAsString != null) { + + // extentions can be separted by comma + String[] exts = extsAsString.split(SEPARATOR_REGEX); + String extsDescription = view.getExtsDescription(); + + String[] descs = new String[0]; + if (extsDescription != null) { + descs = extsDescription.split(SEPARATOR_REGEX); + } + for (int i = 0;i<exts.length;i++) { + + // use ext if no desc found + String ext = exts[i]; + String desc = ext; + if (descs.length > i) { + desc = descs[i]; + } + + fc.addChoosableFileFilter(new ExtentionFileFiler(ext, desc)); + } + } + } + + // directory or/and file must be enabled + if (!directoryEnabled && !fileEnabled) { + throw new IllegalArgumentException("You must enable at least file or directory to open dialog"); + } + + // show dialog + int returnVal = fc.showOpenDialog(view); + if (returnVal == JFileChooser.APPROVE_OPTION) { + + // 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; + } + } +} Modified: trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx 2012-06-29 23:56:47 UTC (rev 730) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/JRSTView.jaxx 2012-07-02 10:18:35 UTC (rev 731) @@ -33,8 +33,8 @@ java.awt.Dimension org.nuiton.jrst.JRST org.nuiton.util.Resource - jaxx.runtime.swing.editor.FileEditor </import> + <!--jaxx.runtime.swing.editor.FileEditor--> <JRSTViewHandler id='handler' constructorParams='this'/> Modified: trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx =================================================================== --- trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx 2012-06-29 23:56:47 UTC (rev 730) +++ trunk/jrst/src/main/java/org/nuiton/jrst/ui/XslPanel.jaxx 2012-07-02 10:18:35 UTC (rev 731) @@ -26,8 +26,8 @@ <import> java.awt.Dimension org.nuiton.util.Resource - jaxx.runtime.swing.editor.FileEditor </import> + <!--jaxx.runtime.swing.editor.FileEditor--> <Integer id='panelNumber' javaBean='0'/> <JRSTCommandModel id='model' javaBean='getContextValue(JRSTCommandModel.class)'/> Added: trunk/jrst/src/main/resources/icons/action-open.png =================================================================== (Binary files differ) Property changes on: trunk/jrst/src/main/resources/icons/action-open.png ___________________________________________________________________ Added: svn:executable + * Added: svn:mime-type + application/octet-stream Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2012-06-29 23:56:47 UTC (rev 730) +++ trunk/pom.xml 2012-07-02 10:18:35 UTC (rev 731) @@ -463,7 +463,7 @@ <nuitonUtilsVersion>2.5</nuitonUtilsVersion> <nuitonI18nVersion>2.4.1</nuitonI18nVersion> <xalanVersion>2.7.1</xalanVersion> - <jaxxVersion>2.5-SNAPSHOT</jaxxVersion> + <jaxxVersion>2.4.2</jaxxVersion> </properties> @@ -480,7 +480,7 @@ <plugin> <groupId>org.nuiton.jaxx</groupId> - <artifactId>jaxx-maven-plugin</artifactId> + <artifactId>maven-jaxx-plugin</artifactId> <version>${jaxxVersion}</version> </plugin>
participants (1)
-
tchemit@users.nuiton.org