1 /* 2 3 dsh-eventlist-view Views for event lists. 4 Copyright (c) 2010-2019 held jointly by the individual authors. 5 6 This library is free software; you can redistribute it and/or modify it 7 under the terms of the GNU Lesser General Public License as published 8 by the Free Software Foundation; either version 3 of the License, or (at 9 your option) any later version. 10 11 This library is distributed in the hope that it will be useful, but WITHOUT 12 ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 14 License for more details. 15 16 You should have received a copy of the GNU Lesser General Public License 17 along with this library; if not, write to the Free Software Foundation, 18 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 19 20 > http://www.fsf.org/licensing/licenses/lgpl.html 21 > http://www.opensource.org/licenses/lgpl-license.php 22 23 */ 24 package org.dishevelled.eventlist.view; 25 26 import ca.odell.glazedlists.EventList; 27 28 import ca.odell.glazedlists.gui.TableFormat; 29 30 import org.dishevelled.iconbundle.IconSize; 31 32 import org.dishevelled.iconbundle.tango.TangoProject; 33 34 import org.dishevelled.identify.IdTableCellRenderer; 35 36 /** 37 * Identifiable elements table. 38 * 39 * @param <E> model element type 40 * @author Michael Heuer 41 */ 42 public class IdElementsTable<E> 43 extends ElementsTable<E> 44 { 45 /** Identifiable table cell renderer. */ 46 private final IdTableCellRenderer tableCellRenderer = new IdTableCellRenderer(DEFAULT_ICON_SIZE); 47 48 /** Default icon size, {@link TangoProject#EXTRA_SMALL}. */ 49 public static final IconSize DEFAULT_ICON_SIZE = TangoProject.EXTRA_SMALL; 50 51 52 /** 53 * Create a new identifiable elements table view with the specified model, table format, and column class. 54 * 55 * @param model model, must not be null 56 * @param tableFormat table format, must not be null 57 * @param columnClass column class, must not be null 58 */ 59 public IdElementsTable(final EventList<E> model, 60 final TableFormat<E> tableFormat, 61 final Class<? extends E> columnClass) 62 { 63 super(model, tableFormat); 64 if (columnClass == null) 65 { 66 throw new IllegalArgumentException("columnClass must not be null"); 67 } 68 getTable().setDefaultRenderer(columnClass, tableCellRenderer); 69 updateRowHeight(); 70 } 71 72 /** 73 * Create a new identifiable elements table view with the specified label text, model, table format, 74 * and column class. 75 * 76 * @param labelText label text 77 * @param model model, must not be null 78 * @param tableFormat table format, must not be null 79 * @param columnClass column class, must not be null 80 */ 81 public IdElementsTable(final String labelText, 82 final EventList<E> model, 83 final TableFormat<E> tableFormat, 84 final Class<? extends E> columnClass) 85 { 86 super(labelText, model, tableFormat); 87 if (columnClass == null) 88 { 89 throw new IllegalArgumentException("columnClass must not be null"); 90 } 91 getTable().setDefaultRenderer(columnClass, tableCellRenderer); 92 updateRowHeight(); 93 } 94 95 96 /** 97 * Return the icon size for this identifiable elements table. 98 * 99 * @return the icon size for this identifiable elements table 100 */ 101 public final IconSize getIconSize() 102 { 103 return tableCellRenderer.getIconSize(); 104 } 105 106 /** 107 * Set the icon size for this identifiable elements table to <code>iconSize</code>. 108 * Defaults to {@link #DEFAULT_ICON_SIZE}. 109 * 110 * <p>This is a bound property.</p> 111 * 112 * @param iconSize icon size for this identifiable elements table, must not be null 113 */ 114 public final void setIconSize(final IconSize iconSize) 115 { 116 IconSize oldIconSize = tableCellRenderer.getIconSize(); 117 tableCellRenderer.setIconSize(iconSize); 118 updateRowHeight(); 119 firePropertyChange("iconSize", oldIconSize, iconSize); 120 } 121 122 /** 123 * Update row height, called when the icon size changes. 124 * 125 * @since 2.1 126 */ 127 protected void updateRowHeight() 128 { 129 getTable().setRowHeight(getIconSize().getHeight() + 4); 130 } 131 }