[Schmitzm-commits] r1875 - in trunk/schmitzm-core/src/main: java/de/schmitzm/io java/de/schmitzm/swing java/de/schmitzm/swing/table resources/de/schmitzm/swing/resource/locales

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Sun Feb 26 22:28:22 CET 2012


Author: mojays
Date: 2012-02-26 22:28:21 +0100 (Sun, 26 Feb 2012)
New Revision: 1875

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/OkCancelDialog.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
Log:
new OkCancelDialog: superclass e.g. for individual choosers
new WebFilesChooser/WebFilesChooserPanel: select files from web directory and navigate through web directory structure
FilesSelectionTable: Tooltip for table cell to show complete path/url

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-02-26 15:20:04 UTC (rev 1874)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-02-26 21:28:21 UTC (rev 1875)
@@ -57,6 +57,7 @@
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Enumeration;
 import java.util.List;
 import java.util.Vector;
@@ -898,18 +899,27 @@
 	 * Test whether it is possible to access the given URL. Times-out after 3s
 	 */
 	public static boolean urlExists(final URL url) {
-		try {
-			URLConnection conn = url.openConnection();
-			conn.setConnectTimeout(3000);
-			conn.setReadTimeout(3000);
-			conn.getInputStream().close();
-		} catch (final IOException e) {
-			return false;
-		}
-		return true;
+	  return urlExists(url, 3000);
 	}
 
-	/**
+    /**
+     * Test whether it is possible to access the given URL.
+     * @param timeout timeout in ms to wait before check is canceled and {@code false}
+     *                is returned
+     */
+    public static boolean urlExists(final URL url, int timeout) {
+        try {
+            URLConnection conn = url.openConnection();
+            conn.setConnectTimeout(timeout);
+            conn.setReadTimeout(timeout);
+            conn.getInputStream().close();
+        } catch (final IOException e) {
+            return false;
+        }
+        return true;
+    }
+
+    /**
 	 * Test whether it is possible to access the given URL. Times-out after 3s.
 	 * Returns <code>false</code> if the String is no valid URL.
 	 */
@@ -1201,9 +1211,12 @@
 	public static List<String> extractLinksFromURL(URL url) throws IOException {
 	  if ( url == null )
 	    return new ArrayList<String>();
-	  
 	  // load document from URL
-	  String str = IOUtil.convertStreamToString(url.openStream());
+	  URLConnection conn = url.openConnection();
+	  conn.setConnectTimeout(1000);
+	  conn.setReadTimeout(1000);
+	  String str = IOUtil.convertStreamToString(conn.getInputStream()); 
+	  closeInputStream(conn.getInputStream());
 
 	  // create matcher to extract "href" tags from document
 	  final String  regEx = "href=\"([^\"]*)\"";
@@ -1265,7 +1278,7 @@
      * @param files destination list to store the file urls in
      * @param dirs  destination list to store the directory urls in
      */
-    public static void listFilesAndDirectoriesFromURL(URL url,  List<URL> files,  List<URL> dirs) throws IOException {
+    public static void listFilesAndDirectoriesFromURL(URL url,  Collection<URL> files,  Collection<URL> dirs) throws IOException {
       // #### TODO: improve this workaround method! ####
 
       // extract links from URL
@@ -1273,6 +1286,13 @@
       // combine file names with source URL
       for (String fileName : fileNames) {
         URL fileURL = new URL(url,fileName);
+        // only take "real" links into account; ignore e.g. javascript links 
+        String prot = fileURL.getProtocol();
+        if ( !"http".equalsIgnoreCase(prot) &&
+             !"https".equalsIgnoreCase(prot) &&
+             !"ftp".equalsIgnoreCase(prot) )
+          continue;
+        
         // Differ between files and directories
         if ( fileName.endsWith("/") ) {
           if ( dirs != null )

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/OkCancelDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/OkCancelDialog.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/OkCancelDialog.java	2012-02-26 21:28:21 UTC (rev 1875)
@@ -0,0 +1,181 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * 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 Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
+
+import javax.swing.Action;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.KeyStroke;
+
+
+/**
+ * Dialog (with {@link BorderLayout}), which already provides OK and Cancel options (in
+ * {@link BorderLayout#SOUTH} region).
+ * @author Martin O.J. Schmitz
+ */
+public abstract class OkCancelDialog extends JDialog implements ActionListener, Disposable {
+  /** Holds the buttons */
+  protected JPanel buttonPanel = null;
+  
+  /** Button to approve the dialog. */
+  protected JButton okButton = null;
+  /** Action of the OK button. */
+  protected JButton cancelButton = null;
+  
+  /** Button to cancel the dialog. */
+  protected Action  okAction = null;
+  /** Action of the CANCEL button. */
+  protected Action  cancelAction = null;
+  
+  /** Holds the button which was clicked. Is {@code null} while dialog is visible. */
+  protected JButton lastClickedButton = null;
+  /** Flag whether dialog was closed by OK ({@code true}) or CANCEL ({@code false}).
+   *  Flag is {@code null} while dialog is visible. */
+  protected Boolean dialogApproved = null;
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   * @param modal indicates whether the dialog is modal
+   */
+  public OkCancelDialog(Frame owner, String title, boolean modal) {
+    super(owner, title, modal);
+    init();
+  }
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   * @param modal indicates whether the dialog is modal
+   */
+  public OkCancelDialog(Dialog owner, String title, boolean modal) {
+    super(owner, title, modal);
+    init();
+  }
+  
+  /**
+   * Called immediately by the constructor to initialize the
+   * dialog.
+   */
+  protected void init() {
+    setModal(true);
+    setPreferredSize( new Dimension(500,300) );
+    setLayout( new BorderLayout() );
+
+    this.buttonPanel = new JPanel( new FlowLayout(FlowLayout.CENTER) );
+    this.okAction = SwingUtil.createAction(SwingUtil.R("Ok"), this, "OK", SwingUtil.R("Ok.Desc"),
+                                           SwingUtil.createImageIconFromResourcePath("resource/icons/small/ok.png", null));
+    this.okButton = new JButton(okAction);
+    buttonPanel.add(okButton);
+    this.cancelAction = SwingUtil.createAction(SwingUtil.R("Cancel"), this, "CANCEL", SwingUtil.R("Cancel.Desc"),
+                                               SwingUtil.createImageIconFromResourcePath("resource/icons/small/cancel.png", null));
+    this.cancelButton = new JButton(cancelAction);
+    buttonPanel.add(cancelButton);
+         
+    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
+    
+    // ActionListener fuer ESC-Taste
+    ActionListener escapeActionListener = new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+        cancelButton.doClick();
+      }
+    };
+    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
+    buttonPanel.registerKeyboardAction(escapeActionListener, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
+
+    pack();
+  }
+  
+  /**
+   * Disposes the dialog.
+   */
+  public void dispose() {
+    okButton.removeActionListener(this);
+    cancelButton.removeActionListener(this);
+    super.dispose();
+  }
+  
+  /**
+   * Besides calling super method, the {@link #approved} flag is
+   * initialized with {@code null}.
+   */
+  public void setVisible(boolean visible) {
+    if ( visible ) {
+      this.dialogApproved = null;
+      this.lastClickedButton = null;
+    } else {
+      this.dialogApproved = (lastClickedButton == okButton);
+    }
+    super.setVisible(visible);
+      
+  }
+  
+  /**
+   * Performs the actions of the OK and CANCEL Button.
+   */
+  @Override
+  public void actionPerformed(ActionEvent e) {
+    if ( e.getSource() instanceof JButton )
+      lastClickedButton = (JButton)e.getSource(); 
+    setVisible(false);
+  }
+  
+  /**
+   * Returns the last clicked Button.
+   * @return {@code null} while dialog is visible
+   */
+  public JButton getLastClickedButton() {
+    return lastClickedButton;
+  }
+  
+  /**
+   * Returns whether dialog was closed by OK ({@code true}) or CANCEL ({@code false}).
+   * @return {@code null} while dialog is visible
+   */
+  public Boolean isDialogApproved() {
+    return dialogApproved;
+  }
+  
+
+
+}

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java	2012-02-26 21:28:21 UTC (rev 1875)
@@ -0,0 +1,170 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * 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 Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.net.URL;
+import java.util.List;
+
+import de.schmitzm.swing.OkCancelDialog;
+
+/**
+ * Dialog to select files from a web directory.
+ * <b>Note:</b>The panel expects that the base URL does specify a simple web
+ * directory (without any index.html or something like that) and
+ * NOT a web site. Otherwise the link and directory lists may have unexpected
+ * results!
+ * @author Martin O.J. Schmitz
+ *
+ */
+public class WebFilesChooser extends OkCancelDialog {
+
+  /** Holds the component to choose file(s). */
+  protected WebFilesChooserPanel filesChooserPanel;
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   */
+  public WebFilesChooser(Frame owner, String title) {
+    this(owner, title,(String)null);
+  }
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   */
+  public WebFilesChooser(Dialog owner, String title) {
+    this(owner, title,(String)null);
+  }
+
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   * @param baseUrl initial url (= web directory)
+   */
+  public WebFilesChooser(Frame owner, String title, URL baseUrl) {
+    super(owner, title, true);
+    setBaseURL(baseUrl);
+  }
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   * @param baseUrl initial url (= web directory)
+   */
+  public WebFilesChooser(Dialog owner, String title, URL baseUrl) {
+    super(owner, title,true);
+    setBaseURL(baseUrl);
+  }
+
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   * @param baseUrl initial url (= web directory)
+   */
+  public WebFilesChooser(Frame owner, String title, String baseUrl) {
+    super(owner, title, true);
+    setBaseURL(baseUrl);
+  }
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   * @param baseUrl initial url (= web directory)
+   */
+  public WebFilesChooser(Dialog owner, String title, String baseUrl) {
+    super(owner, title, true);
+    setBaseURL(baseUrl);
+  }
+  
+  /**
+   * Called immediately by the constructor to initialize the
+   * dialog.
+   */
+  @Override
+  protected void init() {
+    super.init();
+    setPreferredSize( new Dimension(500,300) );
+
+    this.filesChooserPanel = new WebFilesChooserPanel();
+
+    getRootPane().setDefaultButton(filesChooserPanel.getUpdateButton());
+    getContentPane().add(filesChooserPanel, BorderLayout.CENTER);
+    
+    pack();
+
+  }
+  
+  /**
+   * Returns the url currently entered in address text field.
+   */
+  public String getBaseURL() {
+    return filesChooserPanel.getBaseURL();
+  }
+  
+  /**
+   * Sets the url currently entered in address text field.
+   * The files and directories table are updated immediately
+   * according to the URL.
+   */
+  public void setBaseURL(String baseURL) {
+    filesChooserPanel.setBaseURL(baseURL);
+  }
+  
+  /**
+   * Sets the url currently entered in address text field.
+   * The files and directories table are updated immediately
+   * according to the URL.
+   */
+  public void setBaseURL(URL baseURL) {
+    filesChooserPanel.setBaseURL(baseURL);
+  }
+
+  /**
+   * Returns the selected files.
+   * @return {@code null} if dialog was not closed by OK 
+   */
+  public List<URL> getSelectedFiles() {
+    if ( isDialogApproved() )
+      return filesChooserPanel.getSelectedFiles();
+    return null;
+  }
+
+}

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java	2012-02-26 21:28:21 UTC (rev 1875)
@@ -0,0 +1,287 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * 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 Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Cursor;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.io.IOException;
+import java.net.SocketTimeoutException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.TreeSet;
+
+import javax.swing.BorderFactory;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JTextField;
+import javax.swing.ListSelectionModel;
+
+import org.apache.log4j.Logger;
+
+import net.miginfocom.swing.MigLayout;
+import de.schmitzm.io.IOUtil;
+import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.ExceptionDialog;
+import de.schmitzm.swing.JPanel;
+import de.schmitzm.swing.SwingUtil;
+import de.schmitzm.swing.URLAddressPanel;
+import de.schmitzm.swing.table.FilesSelectionTable;
+import de.schmitzm.swing.table.FilesSelectionTable.FilesSelectionTableModel;
+
+/**
+ * A panel (like a file chooser) which shows the directory- and file-links of a web
+ * directory. By selection links from the directory list you can navigate through
+ * the web directory structure.
+ * <b>Note:</b>The panel expects that the base URL does specify a simple web directory and
+ * NOT a web site. Otherwise the link lists may have an unexpected result! 
+ * @author Martin O.J. Schmitz
+ */
+public class WebFilesChooserPanel extends JPanel {
+  protected Logger LOGGER = LangUtil.createLogger(this);
+  
+  /** Holds the text field (and update button) to specify an URL. */
+  protected UpdateURLAddressPanel baseUrl;
+  /** Holds the list of URLs which specify a directory. */
+  protected FilesSelectionTable<URL> dirsTable;
+  /** Holds the list of URLs which specify a file. */
+  protected FilesSelectionTable<URL> filesTable;
+
+  /** Compares to URLs just by their filename (last part). Comparison is made
+   *  case-insensitive! */
+  private static final Comparator<URL> FILENAME_COMPARATOR = new Comparator<URL>() {
+    @Override
+    public int compare(URL url1, URL url2) {
+      String filename1 = (url1 != null) ? IOUtil.getFilename(url1) : "";
+      String filename2 = (url2 != null) ? IOUtil.getFilename(url2) : "";
+      return filename1.toUpperCase().compareTo(filename2.toUpperCase());
+    }
+  };
+
+  
+  /**
+   * Table model for the directories table.
+   */
+  private FilesSelectionTableModel<URL> dirsSelectionTableModel = new FilesSelectionTable.FilesSelectionTableModel<URL>(false) {
+    /**
+     * Returns the column names.
+     */
+    @Override
+    public String[] createColumnNames() {
+      return new String[] {
+                           SwingUtil.R("FilesSelectionTable.Dirs")
+      };
+    }
+
+    /**
+     * Returns the description of a file shown in the table column.
+     */
+    @Override
+    protected String getFileName(URL file) {
+      String fileName = super.getFileName(file);
+      // If directory is prefix of the current base URL, it is
+      // the parent directory
+      if ( baseUrl.getText().startsWith(file.toExternalForm()) )
+        fileName = "...";
+      return fileName;
+    }
+  };
+
+  
+  /**
+   * Creates a new panel.
+   */
+  public WebFilesChooserPanel() {
+    super(new MigLayout("wrap 1","[grow]","top"));
+    
+    baseUrl = new UpdateURLAddressPanel();
+    
+    filesTable = new FilesSelectionTable<URL>();
+    filesTable.setTableHeader(null);
+    filesTable.setShowGrid(false);
+    
+    dirsTable = new FilesSelectionTable<URL>(false,dirsSelectionTableModel);
+    dirsTable.setSelectionMode( ListSelectionModel.SINGLE_SELECTION );
+    dirsTable.setTableHeader(null);
+    dirsTable.setShowGrid(false);
+    // add mouse listener to table, to open folder on
+    // double click
+    dirsTable.addMouseListener( new MouseAdapter() {
+      @Override
+      public void mouseClicked(MouseEvent e) {
+        if ( e.getButton() != MouseEvent.BUTTON1 ||
+             e.getClickCount() < 2 ||
+             dirsTable.getSelectedRowCount() == 0 )
+          return;
+        
+        URL dir = dirsTable.getSelectedFiles().get(0);
+        setBaseURL(dir);
+      }
+    });
+    
+    // combine tables and caption labels
+    JPanel dirsPanel = new JPanel(new BorderLayout());
+    JLabel dirsCaption = new JLabel( SwingUtil.R("FilesSelectionTable.Dirs")+":");
+    dirsCaption.setBorder( BorderFactory.createEmptyBorder(3, 3, 3, 3));
+    JScrollPane dirsTableScrollPane = new JScrollPane(dirsTable);
+    dirsTableScrollPane.getViewport().setBackground( dirsTable.getDefaultColumnBackground() );
+    dirsPanel.add(dirsCaption,BorderLayout.NORTH);
+    dirsPanel.add(dirsTableScrollPane,BorderLayout.CENTER);
+    
+    JPanel filesPanel = new JPanel(new BorderLayout());
+    JLabel filesCaption = new JLabel( SwingUtil.R("FilesSelectionTable.Files")+":");
+    filesCaption.setBorder( BorderFactory.createEmptyBorder(3, 3, 3, 3));
+    JScrollPane filesTableScrollPane = new JScrollPane(filesTable);
+    filesTableScrollPane.getViewport().setBackground( filesTable.getDefaultColumnBackground() );
+    filesPanel.add(filesCaption,BorderLayout.NORTH);
+    filesPanel.add(filesTableScrollPane,BorderLayout.CENTER);
+    
+    // put tables in splitpane
+    JSplitPane splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
+                                          dirsPanel, 
+                                          filesPanel);
+//    splitpane.setBorder(BorderFactory.createEmptyBorder());
+    splitpane.setResizeWeight(0.3);
+    
+    add(baseUrl, "growx");
+    add(splitpane,"growx, growy");
+  }
+  
+  /**
+   * Returns the "update" button of the URL address field.
+   * Allows the surrounding frame or dialog class to set this
+   * button as default button. 
+   */
+  public JButton getUpdateButton() {
+    return baseUrl.getActionButton();
+  }
+  
+  /**
+   * Returns the url currently entered in address text field.
+   */
+  public String getBaseURL() {
+    return baseUrl.getText();
+  }
+  
+  /**
+   * Sets the url currently entered in address text field.
+   * The files and directories table are updated immediately
+   * according to the URL.
+   */
+  public void setBaseURL(String baseURL) {
+    baseUrl.setText(baseURL);
+    baseUrl.performAction(null, baseUrl.getText());
+  }
+  
+  /**
+   * Sets the url currently entered in address text field.
+   * The files and directories table are updated immediately
+   * according to the URL.
+   */
+  public void setBaseURL(URL baseURL) {
+    String urlStr = baseURL != null ? baseURL.toExternalForm() : "";
+    setBaseURL(urlStr);
+  }
+
+  /**
+   * Returns the selected files.
+   * @return
+   */
+  public List<URL> getSelectedFiles() {
+    return filesTable.getSelectedFiles();
+  }
+
+ 
+  /**
+   * Text field to enter the URL plus a button to update the table(s).
+   * @author Martin O.J. Schmitz
+   *
+   */
+  private class UpdateURLAddressPanel extends URLAddressPanel {
+    /**
+     * Creates a new text field.
+     */
+    public UpdateURLAddressPanel() {
+      super();
+      
+    }
+
+    /**
+     * Initializes the panel. Called by the constructor.
+     * @param buttonText text for action on button or in menu (if icon
+     *                   is specified, the button shows only the icon!)
+     * @param tooltipText tooltip for the button
+     * @param buttonIcon icon to show on the button (optional)
+     * @param actionCommand action command for the action event (if
+     *                      {@code null}, "BUTTON_ACTION" is used)
+     */
+    protected void init(String buttonText, String tooltipText, ImageIcon buttonIcon, String actionCommand) {
+      buttonText    = "update";
+      tooltipText   = "Update files from URL in table";
+      buttonIcon    = SwingUtil.createImageIconFromResourcePath("resource/icons/small/arrow_refresh_small.png", null);
+      actionCommand = "UPDATE_TABLE";
+      super.init(buttonText, tooltipText, buttonIcon, actionCommand);
+    }
+
+    /**
+     * Called by the button action. Updates table by loading files from
+     * URL.
+     */
+    @Override
+    protected void performAction(ActionEvent e, String destAddr) {
+      try {
+        WebFilesChooserPanel.this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+        URL baseURL = IOUtil.createURL(destAddr,"http");
+        TreeSet<URL> files = new TreeSet<URL>(FILENAME_COMPARATOR); // sorted by filename
+        TreeSet<URL> dirs = new TreeSet<URL>(FILENAME_COMPARATOR); // sorted by filename
+        IOUtil.listFilesAndDirectoriesFromURL(baseURL,files,dirs);
+        filesTable.setFiles(new ArrayList<URL>(files));
+        dirsTable.setFiles(new ArrayList<URL>(dirs));
+        setText( baseURL != null ? baseURL.toExternalForm() : "" );
+      } catch (SocketTimeoutException err) {
+        ExceptionDialog.show(err);
+      } catch (IOException err) {
+        ExceptionDialog.show(err);
+        filesTable.setFiles(null);
+        dirsTable.setFiles(null);
+      } finally {
+        WebFilesChooserPanel.this.setCursor(Cursor.getDefaultCursor());
+      }
+    }
+  }
+}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java	2012-02-26 15:20:04 UTC (rev 1874)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/table/FilesSelectionTable.java	2012-02-26 21:28:21 UTC (rev 1875)
@@ -29,11 +29,15 @@
  */
 package de.schmitzm.swing.table;
 
+import java.awt.Component;
 import java.io.File;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.swing.JComponent;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableCellRenderer;
 import javax.swing.table.TableModel;
 
 import de.schmitzm.io.IOUtil;
@@ -88,6 +92,18 @@
   }
 
   /**
+   * After calling the super method this method sets the complete URL string
+   * as tool tip for the rendering component.
+   */
+  @Override
+  public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
+    Component c = super.prepareRenderer(renderer, row, column);
+    if (c instanceof JComponent)
+        ((JComponent)c).setToolTipText( getOriginModel().getFiles().get(row).toString());
+    return c;
+  }
+
+  /**
    * Returns the table model.
    */
   public FilesSelectionTableModel<FILETYPE> getOriginModel() {

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-02-26 15:20:04 UTC (rev 1874)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-02-26 21:28:21 UTC (rev 1875)
@@ -59,7 +59,9 @@
 # ---------------------------------------------------------------
 
 Ok=Ok
+Ok.Desc=Approves the operation
 Cancel=Cancel
+Cancel.Desc=Cancels the operation
 Apply=Apply
 Ready=Ready
 Open=Open

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-02-26 15:20:04 UTC (rev 1874)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-02-26 21:28:21 UTC (rev 1875)
@@ -32,7 +32,9 @@
 # ------ in Package schmitzm.swing              ------
 # ----------------------------------------------------
 
+Ok.Desc=Aktion ausführen
 Cancel=Abbrechen
+Cancel.Desc=Aktion abbrechen
 Apply=\u00DCbernehmen
 Ready=Fertig
 Open=\u00D6ffnen



More information about the Schmitzm-commits mailing list