From 164c7174571672ca255b918a56c8db9336e31d19 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 13 Jun 2008 17:43:57 +0200 Subject: [PATCH] add insert listener --- src/net/pterodactylus/jsite/core/CoreImpl.java | 38 ++++++++++ src/net/pterodactylus/jsite/core/FileOverride.java | 2 +- .../pterodactylus/jsite/core/InsertListener.java | 80 ++++++++++++++++++++++ src/net/pterodactylus/jsite/core/Node.java | 2 +- src/net/pterodactylus/jsite/core/NodeManager.java | 22 ++++-- src/net/pterodactylus/jsite/core/Project.java | 8 +++ src/net/pterodactylus/jsite/gui/FileManager.java | 3 +- src/net/pterodactylus/jsite/gui/ProjectPanel.java | 32 +++++++++ 8 files changed, 179 insertions(+), 8 deletions(-) create mode 100644 src/net/pterodactylus/jsite/core/InsertListener.java diff --git a/src/net/pterodactylus/jsite/core/CoreImpl.java b/src/net/pterodactylus/jsite/core/CoreImpl.java index cd65bf4..3654c4f 100644 --- a/src/net/pterodactylus/jsite/core/CoreImpl.java +++ b/src/net/pterodactylus/jsite/core/CoreImpl.java @@ -25,7 +25,10 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors; +import java.util.logging.Level; +import java.util.logging.Logger; +import net.pterodactylus.util.logging.Logging; /** * The core of jSite. @@ -34,6 +37,9 @@ import java.util.concurrent.Executors; */ public class CoreImpl implements Core, NodeListener, RequestListener { + /** The logger. */ + private static final Logger logger = Logging.getLogger(CoreImpl.class.getName()); + /** The core listeners. */ private final List coreListeners = new ArrayList(); @@ -59,6 +65,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void addCoreListener(CoreListener coreListener) { + logger.log(Level.FINEST, "adding core listener: " + coreListener); coreListeners.add(coreListener); } @@ -66,6 +73,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void removeCoreListener(CoreListener coreListener) { + logger.log(Level.FINEST, "removing core listener: " + coreListener); coreListeners.remove(coreListener); } @@ -76,6 +84,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the projects were loaded from */ private void fireLoadingProjectsDone(String directory) { + logger.log(Level.FINEST, "firing loadingProjectsDone event with [directory=" + directory + "]"); for (CoreListener coreListener : coreListeners) { coreListener.loadingProjectsDone(directory); } @@ -91,6 +100,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured when loading projects */ private void fireLoadingProjectsFailed(String directory, Throwable throwable) { + logger.log(Level.FINEST, "firing loadingProjectsFailed event with [directory=" + directory + ",throwable=" + throwable + "]"); for (CoreListener coreListener : coreListeners) { coreListener.loadingProjectsFailed(directory, throwable); } @@ -103,6 +113,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the projects were saved to */ private void fireSavingProjectsDone(String directory) { + logger.log(Level.FINEST, "firing savingProjectsDone event with [directory=" + directory + "]"); for (CoreListener coreListener : coreListeners) { coreListener.savingProjectsDone(directory); } @@ -117,6 +128,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured when saving the projects */ private void fireSavingProjectsFailed(String directory, Throwable throwable) { + logger.log(Level.FINEST, "firing savingProjectsFailed event with [directory=" + directory + ",throwable=" + throwable + "]"); for (CoreListener coreListener : coreListeners) { coreListener.savingProjectsFailed(directory, throwable); } @@ -129,6 +141,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The project that was added */ private void fireProjectAdded(Project project) { + logger.log(Level.FINEST, "firing projectAdded event with [project=" + project + "]"); for (CoreListener coreListener : coreListeners) { coreListener.projectAdded(project); } @@ -143,6 +156,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The clone of the project */ private void fireProjectCloned(Project clonedProject, Project projectClone) { + logger.log(Level.FINEST, "firing projectCloned event with [clonedProject=" + clonedProject + ",projectClone=" + projectClone + "]"); for (CoreListener coreListener : coreListeners) { coreListener.projectCloned(clonedProject, projectClone); } @@ -155,6 +169,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The project that was removed */ private void fireProjectRemoved(Project project) { + logger.log(Level.FINEST, "firing projectRemoved event with [project=" + project + "]"); for (CoreListener coreListener : coreListeners) { coreListener.projectRemoved(project); } @@ -167,6 +182,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the nodes were loaded from */ private void fireLoadingNodesDone(String directory) { + logger.log(Level.FINEST, "firing loadingNodesDone event with [directory=" + directory + "]"); for (CoreListener coreListener : coreListeners) { coreListener.loadingNodesDone(directory); } @@ -181,6 +197,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured while loading the nodes */ private void fireLoadingNodesFailed(String directory, Throwable throwable) { + logger.log(Level.FINEST, "firing loadingNodesFailed event with [directory=" + directory + ",throwable=" + throwable + "]"); for (CoreListener coreListener : coreListeners) { coreListener.loadingNodesFailed(directory, throwable); } @@ -193,6 +210,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The directory the nodes were saved to */ private void fireSavingNodesDone(String directory) { + logger.log(Level.FINEST, "firing savingNodesDone event with [directory=" + directory + "]"); for (CoreListener coreListener : coreListeners) { coreListener.savingNodesDone(directory); } @@ -207,6 +225,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The exception that occured while saving the nodes */ private void fireSavingNodesFailed(String directory, Throwable throwable) { + logger.log(Level.FINEST, "firing savingNodesFailed event with [directory=" + directory + ",throwable=" + throwable + "]"); for (CoreListener coreListener : coreListeners) { coreListener.savingProjectsFailed(directory, throwable); } @@ -216,6 +235,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * Notifies all core listeners that the core has loaded and is ready to run. */ private void fireCoreLoaded() { + logger.log(Level.FINEST, "firing coreLoaded event"); for (CoreListener coreListener : coreListeners) { coreListener.coreLoaded(); } @@ -225,6 +245,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * Notifies all listeners that the core was stopped. */ private void fireCoreStopped() { + logger.log(Level.FINEST, "firing coreStopped event"); for (CoreListener coreListener : coreListeners) { coreListener.coreStopped(); } @@ -237,6 +258,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that was added */ private void fireNodeAdded(Node node) { + logger.log(Level.FINEST, "firing nodeAdded event with [node=" + node + "]"); for (CoreListener coreListener : coreListeners) { coreListener.nodeAdded(node); } @@ -249,6 +271,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that was removed */ private void fireNodeRemoved(Node node) { + logger.log(Level.FINEST, "firing nodeRemoved event with [node=" + node + "]"); for (CoreListener coreListener : coreListeners) { coreListener.nodeRemoved(node); } @@ -262,6 +285,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that is being connected to */ private void fireNodeConnecting(Node node) { + logger.log(Level.FINEST, "firing nodeConnecting event with [node=" + node + "]"); for (CoreListener coreListener : coreListeners) { coreListener.nodeConnecting(node); } @@ -274,6 +298,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The node that is now connected */ private void fireNodeConnected(Node node) { + logger.log(Level.FINEST, "firing nodeConnected event with [node=" + node + "]"); for (CoreListener coreListener : coreListeners) { coreListener.nodeConnected(node); } @@ -288,6 +313,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * The cause of the failure */ private void fireNodeConnectionFailed(Node node, Throwable cause) { + logger.log(Level.FINEST, "firing nodeConnectionFailed event with [node=" + node + ",cause=" + cause + "]"); for (CoreListener coreListener : coreListeners) { coreListener.nodeConnectionFailed(node, cause); } @@ -303,6 +329,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * if there was no exception */ private void fireNodeDisconnected(Node node, Throwable throwable) { + logger.log(Level.FINEST, "firing nodeDisconnected event with [node=" + node + ",throwable=" + throwable + "]"); for (CoreListener coreListener : coreListeners) { coreListener.nodeDisconnected(node, throwable); } @@ -396,6 +423,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void start() { + logger.log(Level.INFO, "starting core…"); try { nodeManager.load(); fireLoadingNodesDone(nodeManager.getDirectory()); @@ -415,6 +443,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void stop() { + logger.log(Level.INFO, "stopping core…"); try { projectManager.save(); fireSavingProjectsDone(projectManager.getDirectory()); @@ -434,6 +463,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public boolean addNode(Node node) throws UnknownHostException { + logger.log(Level.FINEST, "addNode(node=" + node + ")"); return nodeManager.addNode(node); } @@ -441,6 +471,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void removeNode(Node node) { + logger.log(Level.FINEST, "removeNode(node=" + node + ")"); nodeManager.removeNode(node); } @@ -448,6 +479,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void connectToNode(Node node) { + logger.log(Level.FINEST, "connectToNode(node=" + node + ")"); fireNodeConnecting(node); nodeManager.connect(node); } @@ -456,6 +488,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void disconnectFromNode(Node node) { + logger.log(Level.FINEST, "disconnectFromNode(node=" + node + ")"); nodeManager.disconnect(node); } @@ -463,6 +496,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void createProject() throws IOException, JSiteException { + logger.log(Level.FINEST, "createProject()"); Project newProject = projectManager.createProject(); fireProjectAdded(newProject); } @@ -471,6 +505,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void cloneProject(Project project) { + logger.log(Level.FINEST, "cloneProject(project=" + project + ")"); Project projectClone = projectManager.cloneProject(project); fireProjectCloned(project, projectClone); } @@ -479,6 +514,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { * {@inheritDoc} */ public void removeProject(Project project) { + logger.log(Level.FINEST, "removeProject(project=" + project + ")"); projectManager.removeProject(project); fireProjectRemoved(project); } @@ -492,6 +528,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { */ @SuppressWarnings("unused") private void loadConfig() { + logger.log(Level.FINEST, "loadConfig()"); /* TODO */ } @@ -500,6 +537,7 @@ public class CoreImpl implements Core, NodeListener, RequestListener { */ @SuppressWarnings("unused") private void saveConfig() { + logger.log(Level.FINEST, "saveConfig()"); /* TODO */ } diff --git a/src/net/pterodactylus/jsite/core/FileOverride.java b/src/net/pterodactylus/jsite/core/FileOverride.java index 806d538..474d057 100644 --- a/src/net/pterodactylus/jsite/core/FileOverride.java +++ b/src/net/pterodactylus/jsite/core/FileOverride.java @@ -123,7 +123,7 @@ public class FileOverride { /** * @see java.lang.Object#toString() */ - @java.lang.Override + @Override public String toString() { return ((insert != null) ? String.valueOf(insert) : "") + "|" + ((contentType != null) ? contentType : "") + "|" + ((redirectTarget != null) ? redirectTarget : ""); } diff --git a/src/net/pterodactylus/jsite/core/InsertListener.java b/src/net/pterodactylus/jsite/core/InsertListener.java new file mode 100644 index 0000000..0ab6acb --- /dev/null +++ b/src/net/pterodactylus/jsite/core/InsertListener.java @@ -0,0 +1,80 @@ +/* + * jSite2 - InsertListener.java - Copyright © 2008 David Roden + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 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 General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307, USA. + */ +package net.pterodactylus.jsite.core; + +import java.util.EventListener; + +/** + * Interface for objects that want to be notified on events emitted by the + * {@link InsertManager}. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + */ +public interface InsertListener extends EventListener { + + /** + * Notifies a listener that an insert was added. + * + * @param insert + * The insert that was added + */ + public void insertAdded(Insert insert); + + /** + * Notifies a listener that an insert was removed. + * + * @param insert + * The insert that was removed + */ + public void insertRemoved(Insert insert); + + /** + * Notifies a listener that an insert was started. + * + * @param insert + * The insert that was started + */ + public void insertStarted(Insert insert); + + /** + * Notifies a listener that an insert made some progress. + * + * @param insert + * The insert that made some progress + */ + public void insertProgressed(Insert insert); + + /** + * Notifies listeners that an insert generated a URI. + * + * @param insert + * The insert that generated a URI + * @param uri + * The generated URI + */ + public void insertGeneratedURI(Insert insert, String uri); + + /** + * Notifies a listener that an insert has finished. + * + * @param insert + * The insert that has finished + */ + public void insertFinished(Insert insert); + +} diff --git a/src/net/pterodactylus/jsite/core/Node.java b/src/net/pterodactylus/jsite/core/Node.java index bb61ee9..b632eea 100644 --- a/src/net/pterodactylus/jsite/core/Node.java +++ b/src/net/pterodactylus/jsite/core/Node.java @@ -148,7 +148,7 @@ public class Node extends AbstractBean { */ @Override public String toString() { - return name + " (" + hostname + ((port == 9481) ? ("") : (":" + port)) + ")"; + return getClass().getName() + "[name=" + name + ",hostname=" + hostname + ",port=" + port + "]"; } } diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index c251232..922a85a 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -125,6 +125,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node that was added. */ private void fireNodeAdded(Node node) { + logger.log(Level.FINEST, "firing nodeAdded event with [node=" + node + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeAdded(node); } @@ -137,6 +138,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node that was removed */ private void fireNodeRemoved(Node node) { + logger.log(Level.FINEST, "firing nodeRemoved event with [node=" + node + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeRemoved(node); } @@ -149,6 +151,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node that is now connected */ private void fireNodeConnected(Node node) { + logger.log(Level.FINEST, "firing nodeConnected event with [node=" + node + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeConnected(node); } @@ -163,6 +166,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The cause of the failure */ private void fireNodeConnectionFailed(Node node, Throwable cause) { + logger.log(Level.FINEST, "firing nodeConnectionFailed event with [node=" + node + ",cause=" + cause + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeConnectionFailed(node, cause); } @@ -178,6 +182,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if there was no exception */ private void fireNodeDisconnected(Node node, Throwable throwable) { + logger.log(Level.FINEST, "firing nodeDisconnected event with [node=" + node + ",throwable=" + throwable + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeDisconnected(node, throwable); } @@ -226,6 +231,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if an I/O error occurs loading the nodes */ public void load() throws IOException { + logger.log(Level.FINEST, "load()"); File directoryFile = new File(directory); File nodeFile = new File(directoryFile, "nodes.properties"); if (!nodeFile.exists() || !nodeFile.isFile() || !nodeFile.canRead()) { @@ -277,7 +283,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High newNode.setPort(nodePort); loadedNodes.add(newNode); } - logger.fine("loaded " + loadedNodes.size() + " nodes from config"); + logger.log(Level.FINE, "loaded " + loadedNodes.size() + " nodes from config"); synchronized (syncObject) { nodes.clear(); for (Node node : loadedNodes) { @@ -293,6 +299,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if an I/O error occurs saving the nodes */ public void save() throws IOException { + logger.log(Level.FINEST, "save()"); File directoryFile = new File(directory); if (!directoryFile.exists()) { if (!directoryFile.mkdirs()) { @@ -328,8 +335,9 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if the node was not added because it was already known */ public boolean addNode(Node node) { + logger.log(Level.FINEST, "addNode(node=" + node + ")"); if (nodes.contains(node)) { - logger.warning("was told to add already known node: " + node); + logger.log(Level.WARNING, "was told to add already known node: " + node); return false; } node.addPropertyChangeListener(this); @@ -351,6 +359,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node to remove */ public void removeNode(Node node) { + logger.log(Level.FINEST, "removeNode(node=" + node + ")"); synchronized (syncObject) { if (!nodes.contains(node)) { return; @@ -372,10 +381,11 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node to connect to */ public void connect(Node node) { + logger.log(Level.FINEST, "connect(node=" + node + ")"); HighLevelClient highLevelClient; highLevelClient = nodeClients.get(node); if (highLevelClient == null) { - logger.warning("was told to connect to unknown node: " + node); + logger.log(Level.WARNING, "was told to connect to unknown node: " + node); return; } try { @@ -394,6 +404,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node to disconnect */ public void disconnect(Node node) { + logger.log(Level.FINEST, "disconnect(node=" + node + ")"); synchronized (syncObject) { if (!nodes.contains(node)) { return; @@ -459,6 +470,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if there is a problem with the node */ public String[] generateKeyPair() throws IOException, JSiteException { + logger.log(Level.FINEST, "generateKeyPair()"); if (nodes.isEmpty()) { throw new NoNodeException("no node configured"); } @@ -487,7 +499,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * {@inheritDoc} */ public void clientConnected(HighLevelClient highLevelClient) { - logger.log(Level.FINER, "clientConnected(c=" + highLevelClient + ")"); + logger.log(Level.FINEST, "clientConnected(highLevelClient=" + highLevelClient + ")"); Node node = clientNodes.get(highLevelClient); if (node == null) { logger.log(Level.WARNING, "got event for unknown client"); @@ -500,7 +512,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * {@inheritDoc} */ public void clientDisconnected(HighLevelClient highLevelClient, Throwable throwable) { - logger.log(Level.FINER, "clientDisconnected(c=" + highLevelClient + ",t=" + throwable + ")"); + logger.log(Level.FINEST, "clientDisconnected(highLevelClient=" + highLevelClient + ",throwable=" + throwable + ")"); synchronized (syncObject) { Node node = clientNodes.get(highLevelClient); if (node == null) { diff --git a/src/net/pterodactylus/jsite/core/Project.java b/src/net/pterodactylus/jsite/core/Project.java index d250af1..8bc45dd 100644 --- a/src/net/pterodactylus/jsite/core/Project.java +++ b/src/net/pterodactylus/jsite/core/Project.java @@ -399,6 +399,14 @@ public class Project extends AbstractBean { fireIfPropertyChanged(PROPERTY_NODE, oldNode, node); } + /** + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return getClass().getName() + "[id=" + id + ",name=" + name + ",description=" + description + ",publicKey=" + publicKey + ",privateKey=" + privateKey + ",basePath=" + basePath + ",defaultFile=" + defaultFile + ",node=" + node + "]"; + } + // // PRIVATE METHODS // diff --git a/src/net/pterodactylus/jsite/gui/FileManager.java b/src/net/pterodactylus/jsite/gui/FileManager.java index b919bb6..996d609 100644 --- a/src/net/pterodactylus/jsite/gui/FileManager.java +++ b/src/net/pterodactylus/jsite/gui/FileManager.java @@ -408,6 +408,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe } } }; + overrideContentTypeDefaultAction.setEnabled(false); contentTypeOverrideAction = new AbstractAction() { /** @@ -845,7 +846,7 @@ public class FileManager extends JDialog implements I18nable, TreeSelectionListe boolean overrideInsertSelected = false; boolean insertOverrideEnabled = false; boolean insertOverrideSelected = false; - String defaultContentType = MimeTypes.DEFAULT_CONTENT_TYPE; + String defaultContentType = ""; boolean overrideContentTypeEnabled = false; boolean overrideContentTypeSelected = false; boolean contentTypeOverrideEnabled = false; diff --git a/src/net/pterodactylus/jsite/gui/ProjectPanel.java b/src/net/pterodactylus/jsite/gui/ProjectPanel.java index 187e057..2dd1031 100644 --- a/src/net/pterodactylus/jsite/gui/ProjectPanel.java +++ b/src/net/pterodactylus/jsite/gui/ProjectPanel.java @@ -20,6 +20,7 @@ package net.pterodactylus.jsite.gui; import java.awt.BorderLayout; +import java.awt.Component; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; @@ -32,9 +33,11 @@ import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.BorderFactory; import javax.swing.DefaultComboBoxModel; +import javax.swing.DefaultListCellRenderer; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFileChooser; +import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.event.DocumentEvent; @@ -240,6 +243,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { propertiesPanel.add(editFilesButton, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(12, 12, 0, 0), 0, 0)); nodeComboBox = new JComboBox(new DefaultComboBoxModel()); + nodeComboBox.setRenderer(new NodeComboBoxCellRenderer()); ((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(null); for (Node node : swingInterface.getNodes()) { ((DefaultComboBoxModel) nodeComboBox.getModel()).addElement(node); @@ -352,4 +356,32 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { textFieldsUpdated(documentEvent.getDocument()); } + /** + * Cell cenderer for the node combo box. + * + * @author David ‘Bombe’ Roden <bombe@freenetproject.org> + */ + private static class NodeComboBoxCellRenderer extends DefaultListCellRenderer { + + /** + * Empty constructor. + */ + public NodeComboBoxCellRenderer() { + super(); + } + + /** + * @see javax.swing.DefaultListCellRenderer#getListCellRendererComponent(javax.swing.JList, + * java.lang.Object, int, boolean, boolean) + */ + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + if (value == null) { + return super.getListCellRendererComponent(list, "\u00a0", index, isSelected, cellHasFocus); + } + return super.getListCellRendererComponent(list, ((Node) value).getName(), index, isSelected, cellHasFocus); + } + + } + } -- 2.7.4