001: /*
002: * FileiInfoFrame.java Copyright (c) 2006,07 Swaroop Belur
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008:
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013:
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
017: *
018: */
019:
020: package net.sf.jdec.ui.core;
021:
022: import java.awt.Component;
023: import java.awt.Dimension;
024: import java.io.File;
025: import java.util.Date;
026:
027: import javax.swing.JInternalFrame;
028: import javax.swing.JScrollPane;
029: import javax.swing.JTable;
030: import javax.swing.ScrollPaneConstants;
031: import javax.swing.table.DefaultTableModel;
032: import javax.swing.table.TableCellRenderer;
033: import javax.swing.table.TableColumn;
034: import javax.swing.table.TableColumnModel;
035:
036: /**
037: *
038: *@author swaroop belur
039: *
040: *
041: */
042: public class FileInfoFrame extends UIObject {
043:
044: String fileName = " ";
045: String fileSize = "";
046: String location = " ";
047: String type = " ";
048:
049: public Component getDetails() {
050:
051: return details;
052: }
053:
054: private JInternalFrame details = null;
055:
056: public void setFileName(String fileName) {
057: this .fileName = fileName;
058: }
059:
060: public void setFileSize(String fileSize) {
061: this .fileSize = fileSize;
062: }
063:
064: public void setLocation(String location) {
065: this .location = location;
066: }
067:
068: public void setDesc(java.lang.String desc) {
069: this .whatAmI = desc;
070: }
071:
072: public FileInfoFrame() {
073: createDetailsFrame();
074: }
075:
076: private String read, write, lm;
077:
078: private void createDetailsFrame() {
079: Object[][] TABLE_DATA = {
080:
081: { "File Name:", fileName, " " },
082: { "File Size:", fileSize, " " },
083: { "File Location:", location, " " },
084: { "File type:", type, " " },
085: { "Read-Permission", read, "" },
086: { "Write-Permission", write, "" },
087: { "Last-Modified", lm, "" },
088:
089: };
090:
091: String[] COLUMN_NAMES = { " Title ", " Value " };
092: mod = new DefaultTableModel(TABLE_DATA, COLUMN_NAMES);
093:
094: JTable table = new JTable(mod);
095: // table.setBackground(Color.LIGHT_GRAY);
096: table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
097: table.setAutoscrolls(true);
098:
099: int c = table.getSelectedColumn();
100: int r = table.getSelectedRow();
101: if (r >= 0 && c >= 0) {
102: String v = TABLE_DATA[r][c].toString();
103: table.setToolTipText(v);
104: }
105:
106: //table.setMinimumSize(new Dimension(300,180));
107: // table.setMinimumSize(new Dimension(100,180));
108: //table.setBounds(0,0,table.getWidth()+100, table.getHeight());
109: //table.setAutoscrolls(true);
110: JScrollPane pane = new JScrollPane(table,
111: ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
112: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
113: details = new JInternalFrame("Project Details...");
114: //table.setMinimumSize(new Dimension(240,110));
115: Dimension d = details.getContentPane().getSize();
116: //details.setSize(50,100);
117: details.getContentPane().add(table);
118: table.setAutoCreateColumnsFromModel(true);
119: //table.setSize(300,300);
120: details.setAutoscrolls(true);
121: //details.setMinimumSize(new Dimension(details.getWidth()+150,details.getHeight()+30));
122: pane.add(details);
123: TableColumnModel columnModel = table.getColumnModel();
124:
125: for (int col = 0; col < table.getColumnCount(); col++) {
126:
127: int maxwidth = 0;
128: for (int row = 0; row < table.getRowCount(); row++) {
129: TableCellRenderer rend = table
130: .getCellRenderer(row, col);
131: Object value = table.getValueAt(row, col);
132: Component comp = rend.getTableCellRendererComponent(
133: table, value, false, false, row, col);
134: maxwidth = Math.max(comp.getPreferredSize().width,
135: maxwidth) + 20;
136: } // for row
137: TableColumn column = columnModel.getColumn(col);
138: if (col != 0)
139: column.setPreferredWidth(maxwidth + 20);
140: }
141:
142: details.setVisible(true);
143: }
144:
145: public void recreateDetailsFrame(String filename) {
146: File f = new File(filename);
147:
148: String length = "" + f.length() + " Bytes";
149: int sep = filename.lastIndexOf(File.separator);
150: String baseName = "";
151: String loc = "";
152: String ext = baseName;
153: if (sep != -1) {
154: loc = filename.substring(0, sep);
155: ext = filename.substring(sep + 1);
156: baseName = ext;
157: int dot = ext.indexOf(".");
158: ext = ext.substring(dot + 1);
159: baseName = baseName.substring(0, dot);
160: fileName = baseName;
161: }
162: this .location = loc;
163: this .fileSize = length;
164: read = "" + f.canRead();
165: write = "" + f.canWrite();
166: lm = "" + new Date(f.lastModified()).toString();
167: this .type = ext;
168: details = null;
169: updateDetaisFrame();
170:
171: }
172:
173: private void updateDetaisFrame() {
174: Object[][] TABLE_DATA = {
175:
176: { "File Name:", fileName, " " },
177: { "File Size:", fileSize, " " },
178: { "File Location:", location, " " },
179: { "File type:", type, " " },
180: { "Read-Permission", read, "" },
181: { "Write-Permission", write, "" },
182: { "Last-Modified", lm, "" }
183:
184: };
185:
186: String[] COLUMN_NAMES = { " Title ", " Value " };
187: mod = new DefaultTableModel(TABLE_DATA, COLUMN_NAMES);
188:
189: JTable table = new JTable(mod);
190: //table.setBackground(Color.LIGHT_GRAY);
191: table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
192: table.setAutoscrolls(true);
193:
194: int c = table.getSelectedColumn();
195: int r = table.getSelectedRow();
196: if (r >= 0 && c >= 0) {
197: String v = TABLE_DATA[r][c].toString();
198: table.setToolTipText(v);
199: }
200:
201: //table.setMinimumSize(new Dimension(300,180));
202: // table.setMinimumSize(new Dimension(100,180));
203: //table.setBounds(0,0,table.getWidth()+100, table.getHeight());
204: //table.setAutoscrolls(true);
205: JScrollPane pane = new JScrollPane(table,
206: ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
207: ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
208: details = new JInternalFrame("Project Details...");
209: //table.setMinimumSize(new Dimension(240,110));
210: Dimension d = details.getContentPane().getSize();
211: //details.setSize(50,100);
212: details.getContentPane().add(table);
213: table.setAutoCreateColumnsFromModel(true);
214: //table.setSize(300,300);
215: details.setAutoscrolls(true);
216: //details.setMinimumSize(new Dimension(details.getWidth()+150,details.getHeight()+30));
217: pane.add(details);
218: TableColumnModel columnModel = table.getColumnModel();
219:
220: for (int col = 0; col < table.getColumnCount(); col++) {
221:
222: int maxwidth = 0;
223: for (int row = 0; row < table.getRowCount(); row++) {
224: TableCellRenderer rend = table
225: .getCellRenderer(row, col);
226: Object value = table.getValueAt(row, col);
227: Component comp = rend.getTableCellRendererComponent(
228: table, value, false, false, row, col);
229: maxwidth = Math.max(comp.getPreferredSize().width,
230: maxwidth) + 40;
231: } // for row
232: TableColumn column = columnModel.getColumn(col);
233: if (col == 0)
234: column.setPreferredWidth(maxwidth + 40);
235: else {
236: column.setPreferredWidth(maxwidth + 40);
237:
238: int i;
239: }
240:
241: }
242: details.setToolTipText(location);
243:
244: details.setVisible(true);
245:
246: }
247:
248: private DefaultTableModel mod;
249:
250: public DefaultTableModel getModel() {
251: return mod;
252: }
253:
254: }
|