r2332 - in trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing: . editor
Author: sletellier Date: 2012-06-14 19:32:58 +0200 (Thu, 14 Jun 2012) New Revision: 2332 Url: http://nuiton.org/repositories/revision/jaxx/2332 Log: Allow using onActionPerformed on FileEditor Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/BaseActionPanel.java Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java Added: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/BaseActionPanel.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/BaseActionPanel.java (rev 0) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/BaseActionPanel.java 2012-06-14 17:32:58 UTC (rev 2332) @@ -0,0 +1,78 @@ +/* + * #%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; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import javax.swing.JPanel; + +/** + * @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 + * @see #setSelectedItem + */ + 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); + } +} Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx 2012-06-14 15:47:32 UTC (rev 2331) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditor.jaxx 2012-06-14 17:32:58 UTC (rev 2332) @@ -21,8 +21,7 @@ <http://www.gnu.org/licenses/lgpl-3.0.html>. #L% --> -<Table> - +<BaseActionPanel> <import> java.io.File java.beans.PropertyChangeEvent @@ -39,7 +38,7 @@ <File id='selectedFile' javaBean='null'/> - <File id='startFile' javaBean='null'/> + <String id='startPath' javaBean='null'/> <String id='title' javaBean='null'/> @@ -48,41 +47,35 @@ <String id='extsDescription' javaBean='null'/> <script><![CDATA[ - protected void $afterCompleteSetup() { + protected void $afterCompleteSetup() { - addPropertyChangeListener(PROPERTY_START_FILE, new PropertyChangeListener() { + addPropertyChangeListener(PROPERTY_SELECTED_FILE, new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - if (startFile != null) { - pathField.setText(startFile.getAbsolutePath()); - } - } - }); + @Override + public void propertyChange(PropertyChangeEvent evt) { + if (selectedFile != null) { + pathField.setText(selectedFile.getAbsolutePath()); + fireActionEvent(); + } + } + }); + } + ]]></script> - 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 + <Table constraints='BorderLayout.CENTER'> + <row> + <cell fill='horizontal' weightx='1'> + <JTextField id='pathField' + enabled='{isEnabled()}' + text='{getStartPath()}' + onFocusLost='setSelectedFile(new File(pathField.getText()))'/> + </cell> + <cell> + <JButton id='boutonXslLocation' + enabled='{isEnabled()}' + actionIcon='open' + onActionPerformed='handler.openLocation()'/> + </cell> + </row> + </Table> +</BaseActionPanel> \ No newline at end of file Modified: trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java =================================================================== --- trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java 2012-06-14 15:47:32 UTC (rev 2331) +++ trunk/jaxx-widgets/src/main/java/jaxx/runtime/swing/editor/FileEditorHandler.java 2012-06-14 17:32:58 UTC (rev 2332) @@ -44,13 +44,14 @@ // use last selected file File startFile = view.getSelectedFile(); - if (startFile == null) { + String startPath = view.getStartPath(); + if (startFile == null && startPath != null) { - // else filed start file - startFile = view.getStartFile(); - } - if (startFile == null) { + // else filed start path + startFile = new File(startPath); + } else { + // else start with user home startFile = new File(System.getProperty("user.home")); } @@ -85,7 +86,12 @@ // extentions can be separted by comma String[] exts = extsAsString.split(SEPARATOR_REGEX); - String[] descs = view.getExtsDescription().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
participants (1)
-
sletellier@users.nuiton.org