X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FProjectPanel.java;h=b046a7c4ccf7c456b919b9622adddc206f7a555e;hb=c63257e8cc0ba1a5aca9364b22171abe7279d479;hp=187e0571ca6be16b27ce94b01fdae5232265bb92;hpb=f0bc03c6988cc9abcb2fcba8f149b1d41031ec5e;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/ProjectPanel.java b/src/net/pterodactylus/jsite/gui/ProjectPanel.java index 187e057..b046a7c 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; @@ -52,7 +55,7 @@ import net.pterodactylus.util.logging.Logging; /** * A panel that contains all information about a project and lets the user edit * the properties of the project. - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> */ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { @@ -102,7 +105,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** * Creates a new project panel. - * + * * @param swingInterface * The Swing interface * @param project @@ -123,7 +126,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** * Returns the project that is displayed in this panel. - * + * * @return The project of this panel */ public Project getProject() { @@ -136,7 +139,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** * Adds the given node to the node combo boxes in all {@link ProjectPanel}s. - * + * * @param node * The node to add */ @@ -147,7 +150,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** * Removes the given node from the node combo boxes in all * {@link ProjectPanel}s. - * + * * @param node * The node to remove */ @@ -211,7 +214,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** * Creates the properties panel. - * + * * @return The properties panel */ private JPanel createPropertiesPanel() { @@ -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); @@ -257,7 +261,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** * Creates the button panel. - * + * * @return The button panel */ private JPanel createButtonPanel() { @@ -272,7 +276,7 @@ public class ProjectPanel extends JPanel implements DocumentListener, I18nable { /** * Updates the project from changes in the text fields. - * + * * @param document * The document that was changed */ @@ -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); + } + + } + }