001: /*
002: * This program is free software; you can redistribute it and/or
003: * modify it under the terms of the GNU General Public License
004: * as published by the Free Software Foundation; either version 2
005: * of the License, or (at your option) any later version.
006: *
007: * This program is distributed in the hope that it will be useful,
008: * but WITHOUT ANY WARRANTY; without even the implied warranty of
009: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
010: * GNU General Public License for more details.
011:
012: * You should have received a copy of the GNU General Public License
013: * along with this program; if not, write to the Free Software
014: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
015: */
016: package net.sf.jftp.gui.base.dir;
017:
018: import net.sf.jftp.config.Settings;
019: import net.sf.jftp.system.logging.Log;
020: import net.sf.jftp.gui.base.LocalDir;
021: import net.sf.jftp.gui.base.RemoteDir;
022: import net.sf.jftp.gui.framework.GUIDefaults;
023:
024: import java.awt.*;
025: import java.awt.event.*;
026:
027: import java.text.*;
028:
029: import java.util.*;
030:
031: import javax.swing.*;
032:
033: // Display an icon and a string for each object in the list.
034: // class DirCellRenderer extends JLabel implements ListCellRenderer {
035: public class DirCellRenderer extends DefaultListCellRenderer {
036: final static ImageIcon longIcon = new ImageIcon(Settings.dirImage);
037: final static ImageIcon shortIcon = new ImageIcon(Settings.fileImage);
038: private Object value;
039:
040: public DirCellRenderer() {
041: }
042:
043: // This is the only method defined by ListCellRenderer.
044: // We just reconfigure the JLabel each time we're called.
045: public Component getListCellRendererComponent(JList list,
046: Object value, // value to display
047: int index, // cell index
048: boolean isSelected, // is the cell selected
049: boolean cellHasFocus) // the list and the cell have the focus
050: {
051: /* The DefaultListCellRenderer class will take care of
052: * the JLabels text property, it's foreground and background
053: * colors, and so on.
054: */
055: super .getListCellRendererComponent(list, value, index,
056: isSelected, cellHasFocus);
057:
058: ImageIcon i = new ImageIcon(((DirEntry) value).getImage());
059:
060: if (i == null) {
061: System.out.println("Img null: "
062: + ((DirEntry) value).toString() + "/"
063: + ((DirEntry) value).getImage());
064: } else {
065: setIcon((Icon) i);
066: }
067:
068: this .value = value;
069: Log.devnull(this .value); // prevents eclipse warning
070:
071: if (!((DirEntry) list.getModel().getElementAt(index))
072: .getNoRender()) {
073: String size = "";
074:
075: if (Settings.showFileSize) {
076: size = ((DirEntry) list.getModel().getElementAt(index))
077: .getFileSize();
078: }
079:
080: setFont(GUIDefaults.monospaced);
081:
082: String s = value.toString();
083:
084: String date = "";
085:
086: if (Settings.showDateNoSize
087: && (((DirEntry) list.getModel().getElementAt(index)).who instanceof RemoteDir)) {
088: size = ((DirEntry) list.getModel().getElementAt(index))
089: .getDate();
090:
091: int x = 12 - size.length();
092:
093: for (int j = 0; j < x; j++) {
094: size += " ";
095: }
096: } else if (Settings.showLocalDateNoSize
097: && (((DirEntry) list.getModel().getElementAt(index)).who instanceof LocalDir)) {
098: size = ((DirEntry) list.getModel().getElementAt(index))
099: .getDate();
100:
101: int x = 12 - size.length();
102:
103: for (int j = 0; j < x; j++) {
104: size += " ";
105: }
106: }
107:
108: setText(size + s);
109: } else {
110: setFont(GUIDefaults.small);
111:
112: String s = value.toString();
113: setText(s);
114: }
115:
116: int ok = ((DirEntry) value).getPermission();
117:
118: if (ok == DirEntry.DENIED) {
119: setForeground(GUIDefaults.deniedColor);
120: } else if (ok == DirEntry.W) {
121: setForeground(GUIDefaults.writableColor);
122: } else {
123: setForeground(GUIDefaults.defaultColor);
124: }
125:
126: if (((DirEntry) value).file.equals("..")) {
127: setBackground(GUIDefaults.cdColor);
128: }
129:
130: return this;
131: }
132: }
|