001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.directory;
019:
020: import java.awt.Color;
021: import java.awt.event.MouseAdapter;
022: import java.awt.event.MouseEvent;
023: import java.text.DateFormat;
024: import java.util.Date;
025:
026: import javax.swing.JLabel;
027: import javax.swing.JTable;
028: import javax.swing.border.Border;
029: import javax.swing.border.MatteBorder;
030: import javax.swing.table.TableCellRenderer;
031:
032: import de.finix.contelligent.client.base.ContelligentComponent;
033: import de.finix.contelligent.client.gui.ComponentRenderer;
034: import de.finix.contelligent.client.gui.DefaultView;
035: import de.finix.contelligent.client.gui.View;
036: import de.finix.contelligent.client.i18n.Resources;
037:
038: public class FolderTable extends JTable {
039:
040: static final Border bottomDropBorder = new MatteBorder(0, 0, 1, 0,
041: Color.RED);
042:
043: static final Border topDropBorder = new MatteBorder(1, 0, 0, 0,
044: Color.RED);
045:
046: int highlightedRow = -1;
047:
048: boolean bottomLine = false;
049:
050: private boolean editable = false;
051:
052: public FolderTable(FolderTableModel ftm) {
053: super (ftm);
054: setEditable(ftm.isEditable());
055: setDefaultRenderer(ContelligentComponent.class,
056: new FolderRenderer());
057:
058: addMouseListener(new MouseAdapter() {
059: public void mouseClicked(MouseEvent e) {
060: if (!isEditable()) {
061: if ((e.getButton() == MouseEvent.BUTTON1)
062: && (e.getClickCount() == 2)) {
063: int row = rowAtPoint(e.getPoint());
064: ContelligentComponent comp = (ContelligentComponent) getModel()
065: .getValueAt(row, 0);
066:
067: View view = ((FolderTableModel) getModel())
068: .getView();
069: view.navigate(comp.getPath(), true);
070: }
071: }
072: }
073: });
074:
075: }
076:
077: public void setHighlightedRow(int row, boolean bottom) {
078: if (row != highlightedRow) {
079: highlightedRow = row;
080: bottomLine = bottom;
081: repaint();
082: }
083: }
084:
085: public void setEditable(boolean editable) {
086: this .editable = editable;
087: }
088:
089: public boolean isEditable() {
090: return editable;
091: }
092:
093: class FolderRenderer implements TableCellRenderer {
094: JLabel cellRenderer;
095:
096: Color defaultBackground, defaultForeground;
097:
098: DateFormat format;
099:
100: public FolderRenderer() {
101: cellRenderer = new JLabel();
102: cellRenderer.setOpaque(true);
103: defaultBackground = getBackground();
104: defaultForeground = getForeground();
105: format = DateFormat.getDateTimeInstance(DateFormat.SHORT,
106: DateFormat.SHORT, Resources.getLocale());
107: }
108:
109: public java.awt.Component getTableCellRendererComponent(
110: JTable table, Object object, boolean isSelected,
111: boolean hasFocus, int row, int column) {
112: ContelligentComponent component = (ContelligentComponent) object;
113: cellRenderer.setFont(table.getFont());
114: if (column == 0) {
115: cellRenderer.setText(component.getName());
116: cellRenderer.setIcon(component.getSmallIcon());
117: }
118: if (column == 1) {
119: cellRenderer.setText(component.getType().getName());
120: cellRenderer.setIcon(null);
121: }
122: if (column == 2) {
123: cellRenderer.setText(format.format(new Date(component
124: .getLastModified())));
125: cellRenderer.setIcon(null);
126: }
127: if (isSelected) {
128: cellRenderer.setBackground(getSelectionBackground());
129: cellRenderer.setForeground(getSelectionForeground());
130: cellRenderer.setBorder(null);
131: } else {
132: cellRenderer.setBackground(defaultBackground);
133: cellRenderer.setForeground(defaultForeground);
134: if (row == highlightedRow) {
135: if (bottomLine) {
136: cellRenderer.setBorder(bottomDropBorder);
137: } else {
138: cellRenderer.setBorder(topDropBorder);
139: }
140: } else {
141: cellRenderer.setBorder(null);
142: }
143: }
144: return cellRenderer;
145: }
146: }
147: }
|