From b88f00509e6442b5f933b1d11d0585f75754e384 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 27 May 2008 00:00:58 +0200 Subject: [PATCH] add close button to file manager --- src/net/pterodactylus/jsite/gui/FileManager.java | 63 ++++++++++++++++++++-- src/net/pterodactylus/jsite/i18n/jSite.properties | 7 +++ .../pterodactylus/jsite/i18n/jSite_de.properties | 6 +++ 3 files changed, 73 insertions(+), 3 deletions(-) diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index a7d8c7c..7ce0d41 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -20,6 +20,9 @@ package net.pterodactylus.jsite.gui; import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; @@ -28,6 +31,8 @@ import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; +import javax.swing.BorderFactory; +import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JPanel; @@ -39,6 +44,7 @@ import javax.swing.tree.TreePath; import net.pterodactylus.jsite.i18n.I18n; import net.pterodactylus.jsite.i18n.I18nable; +import net.pterodactylus.jsite.i18n.gui.I18nAction; import net.pterodactylus.jsite.project.Entry; import net.pterodactylus.jsite.project.Project; import net.pterodactylus.util.data.Node; @@ -62,6 +68,9 @@ public class FileManager extends JDialog implements I18nable { /** The tree model for the project files. */ private final FileTreeModel fileTreeModel; + /** The “close” action. */ + private I18nAction closeAction; + /** The tree that shows the files. */ private JTree fileTree; @@ -78,25 +87,73 @@ public class FileManager extends JDialog implements I18nable { logger.log(Level.FINEST, "project: " + project); this.project = project; fileTreeModel = new FileTreeModel(); + initActions(); initComponents(); SwingUtils.repackCentered(this); } // - // PRIVATE ACTIONS + // PRIVATE METHODS // /** + * Initializes all actions. + */ + private void initActions() { + closeAction = new I18nAction("fileManager.button.close") { + + /** + * {@inheritDoc} + */ + public void actionPerformed(ActionEvent e) { + setVisible(false); + } + }; + } + + /** * Initializes all components. */ private void initComponents() { JPanel contentPanel = new JPanel(new BorderLayout(12, 12)); + contentPanel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12)); + + contentPanel.add(createFileManagerPanel(), BorderLayout.CENTER); + contentPanel.add(createButtonPanel(), BorderLayout.PAGE_END); + + setContentPane(contentPanel); + } + + /** + * Creates the main panel with the file tree and the file properties. + * + * @return The mail panel + */ + private Component createFileManagerPanel() { + JPanel fileManagerPanel = new JPanel(new BorderLayout(12, 12)); + fileManagerPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(), BorderFactory.createEmptyBorder(12, 12, 12, 12))); fileTree = new JTree(fileTreeModel); fileTree.setShowsRootHandles(false); - contentPanel.add(new JScrollPane(fileTree), BorderLayout.CENTER); + fileManagerPanel.add(new JScrollPane(fileTree), BorderLayout.CENTER); - setContentPane(contentPanel); + return fileManagerPanel; + } + + /** + * Creates the button panel. + * + * @return The button panel + */ + private Component createButtonPanel() { + JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING, 12, 12)); + + buttonPanel.setBorder(BorderFactory.createEmptyBorder(-12, -12, -12, -12)); + JButton closeButton = new JButton(closeAction); + buttonPanel.add(closeButton); + + getRootPane().setDefaultButton(closeButton); + return buttonPanel; } // diff --git a/src/net/pterodactylus/jsite/i18n/jSite.properties b/src/net/pterodactylus/jsite/i18n/jSite.properties index 3ae4b6a..a5b75a2 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite.properties @@ -318,3 +318,10 @@ logWindow.table.column.message.name: Message # the file manager # fileManager.title: File Manager for Project \u201c{0}\u201d + +fileManager.button.close.name: Close +fileManager.button.close.mnemonic: VK_C +fileManager.button.close.accelerator: VK_ESC +fileManager.button.close.shortDescription: Close the file manager +fileManager.button.close.longDescription: Close the file manager + diff --git a/src/net/pterodactylus/jsite/i18n/jSite_de.properties b/src/net/pterodactylus/jsite/i18n/jSite_de.properties index 1c3f562..37b7731 100644 --- a/src/net/pterodactylus/jsite/i18n/jSite_de.properties +++ b/src/net/pterodactylus/jsite/i18n/jSite_de.properties @@ -318,3 +318,9 @@ logWindow.table.column.message.name: Meldung # the file manager # fileManager.title: Dateiverwaltung für Projekt \u201e{0}\u201c + +fileManager.button.close.name: Schließen +fileManager.button.close.mnemonic: VK_S +fileManager.button.close.accelerator: VK_ESC +fileManager.button.close.shortDescription: Beendet die Dateiverwaltung +fileManager.button.close.longDescription: Beendet die Dateiverwaltung -- 2.7.4