From b232aebb9732be0bb6b6252c57bca77836a9298b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 12 Jun 2008 16:22:35 +0200 Subject: [PATCH] change node representation use custom cell renderer for project panel --- src/net/pterodactylus/jsite/core/Node.java | 2 +- src/net/pterodactylus/jsite/gui/ProjectPanel.java | 32 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) 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/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