001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.addressbook.gui.table;
019:
020: import java.awt.Dimension;
021:
022: import javax.swing.JTable;
023: import javax.swing.table.TableColumn;
024: import javax.swing.table.TableModel;
025:
026: import org.columba.addressbook.gui.table.renderer.DefaultHeaderRenderer;
027: import org.columba.addressbook.util.AddressbookResourceLoader;
028:
029: /**
030: * JTable customized with renderers.
031: *
032: * @author fdietz
033: */
034: public class TableView extends JTable {
035:
036: private TableController controller;
037:
038: public TableView(TableController controller, TableModel tableModel) {
039: super (tableModel);
040:
041: this .controller = controller;
042:
043: // this.addressbookModel = addressbookModel;
044: setIntercellSpacing(new Dimension(0, 0));
045: setShowGrid(false);
046: setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
047:
048: // set renderers for columns
049: TableColumn tc = getColumnModel().getColumn(0);
050:
051: tc = getColumnModel().getColumn(0);
052: tc.setHeaderRenderer(createHeader("displayname"));
053: tc = getColumnModel().getColumn(1);
054: tc.setHeaderRenderer(createHeader("given"));
055: tc = getColumnModel().getColumn(2);
056: tc.setHeaderRenderer(createHeader("family"));
057: tc = getColumnModel().getColumn(3);
058: tc.setHeaderRenderer(createHeader("email;internet"));
059: tc = getColumnModel().getColumn(4);
060: tc.setHeaderRenderer(createHeader("url"));
061: }
062:
063: public boolean getScrollableTracksViewportHeight() {
064: return getPreferredSize().height < getParent().getHeight();
065: }
066:
067: /**
068: * Create table header renderer. Names use semicolon ";" character to define
069: * subtypes.
070: * <p>
071: * For example:email;internet or: tel;fax
072: * <p>
073: * Method searches for a semicolon and creates a string representation,
074: * setting the subtype in braces.
075: *
076: * @param name
077: * @return
078: */
079: private DefaultHeaderRenderer createHeader(String name) {
080: int index = name.indexOf(";");
081:
082: if (index != -1) {
083: String prefix = AddressbookResourceLoader.getString(
084: "header", name.substring(0, index));
085: String suffix = AddressbookResourceLoader.getString(
086: "header", name.substring(index + 1, name.length()));
087:
088: return new DefaultHeaderRenderer(controller
089: .getSortDecorator(), prefix + " (" + suffix + ")");
090: } else {
091: String trans = AddressbookResourceLoader.getString(
092: "header", name);
093: return new DefaultHeaderRenderer(controller
094: .getSortDecorator(), trans);
095: }
096:
097: // return new DefaultHeaderRenderer(controller.getSortDecorator(),
098: // name);
099: }
100: }
|