| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 /* Copyright (C) 2005 Simon David Rycroft 2 3 This program is free software; you can redistribute it and/or 4 modify it under the terms of the GNU General Public License 5 as published by the Free Software Foundation; either version 2 6 of the License, or (at your option) any later version. 7 8 This program is distributed in the hope that it will be useful, 9 but WITHOUT ANY WARRANTY; without even the implied warranty of 10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License 14 along with this program; if not, write to the Free Software 15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ 16 17 import java.io.*; 18 import java.util.Vector; 19 import javax.swing.*; 20 import javax.swing.table.*; 21 import java.text.DecimalFormat; 22 23 public class TableData extends AbstractTableModel 24 { 25 Vector myTable; 26 int colCount; 27 String [] headers = {"Filename","Size - Kb"}; 28 int totalFileSize; 29 30 public TableData(String file, String size){ 31 32 myTable = new Vector(); 33 colCount = 2; 34 totalFileSize =0; 35 headers[0] = file; 36 headers[1] = size; 37 } 38 39 public String getColumnName(int i){ 40 if(i==1 && totalFileSize !=0) 41 { 42 //double totalFileSizeMB = totalFileSize/ 10485.76; 43 double thisSize = 0; 44 String thisSizeStr = ""; 45 DecimalFormat onePlaces = new DecimalFormat("0.0"); 46 if(totalFileSize > 1023) 47 { 48 if(totalFileSize > ((1024 * 1024) -1)) 49 { 50 if(totalFileSize > ((1024.0 * 1024.0 * 1024.0) -1)) 51 { 52 thisSize = totalFileSize/(1024.0*1024.0*1024.0); 53 thisSizeStr = onePlaces.format(thisSize) + " G"; 54 } 55 else 56 { 57 thisSize = totalFileSize/(1024.0*1024.0); 58 thisSizeStr = onePlaces.format(thisSize) + " M"; 59 } 60 }else 61 { 62 thisSize = totalFileSize/1024.0; 63 thisSizeStr = onePlaces.format(thisSize) + " K"; 64 } 65 66 }else{ 67 thisSizeStr = String.valueOf(totalFileSize) + " B"; 68 } 69 70 //totalFileSizeMB = (double)Math.round(totalFileSizeMB)/100; 71 return headers[i]+ " " +thisSizeStr; 72 } 73 else 74 return headers[i]; 75 } 76 77 public int getColumnCount(){ 78 return colCount; 79 } 80 81 public int getRowCount() 82 { 83 return myTable.size();} 84 85 public int getTotalFileSize() 86 { 87 return totalFileSize;} 88 89 public Object getValueAt(int row, int col) 90 { 91 return ((Object[])myTable.elementAt(row))[col];} 92 93 94 public void formatTable(String [][] data, int dataLength) 95 { 96 totalFileSize =0; 97 double thisSize = 0; 98 String thisSizeStr = ""; 99 myTable = new Vector(); 100 int j=0; 101 DecimalFormat onePlaces = new DecimalFormat("0.0"); 102 while (j<dataLength) 103 { 104 Object[] row = new Object[colCount]; 105 for (int k=0; k < colCount; k++) 106 { 107 if(k==1) 108 { 109 try{ 110 double thisFileSize = Integer.parseInt(data[j][k]); 111 totalFileSize += thisFileSize; 112 if(thisFileSize > 1023) 113 { 114 if(thisFileSize > ((1024 * 1024) -1)) 115 { 116 if(thisFileSize > ((1024 * 1024 * 1204) -1)) 117 { 118 thisSize = thisFileSize/(1024*1024*1204); 119 thisSizeStr = onePlaces.format(thisSize) + " G"; 120 } 121 else 122 { 123 thisSize = thisFileSize/(1024*1024); 124 thisSizeStr = onePlaces.format(thisSize) + " M"; 125 } 126 }else 127 { 128 thisSize = thisFileSize/1024; 129 thisSizeStr = onePlaces.format(thisSize) + " K"; 130 } 131 132 }else{ 133 thisSizeStr = String.valueOf(thisFileSize) + " B"; 134 } 135 136 //thisFileSize /=102.4; 137 //double thisFileKb = (double)thisFileSize/10; 138 row[k] = thisSizeStr; 139 } 140 catch(NumberFormatException nfe){;} 141 } 142 else 143 row[k] = data[j][k]; 144 } 145 myTable.addElement(row); 146 j++; 147 } 148 fireTableChanged(null); 149 } 150 } 151 152 153
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |