ColumnDateCompleted2Linerpublic class ColumnDateCompleted2Liner extends org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn implements org.gudy.azureus2.plugins.ui.tables.TableCellRefreshListener
Fields Summary |
---|
public static String | COLUMN_ID | static final String[] | FORMATS | static int | globalFormat | int | curFormat |
Constructors Summary |
---|
public ColumnDateCompleted2Liner(String sTableID, boolean bVisible)
super(COLUMN_ID, ALIGN_TRAIL,
bVisible ? POSITION_LAST : POSITION_INVISIBLE, 70, sTableID);
setMaxWidthAuto(true);
|
Methods Summary |
---|
public void | refresh(org.gudy.azureus2.plugins.ui.tables.TableCell cell)
DownloadManager dm = (DownloadManager) cell.getDataSource();
long value = 0;
if (dm != null && dm.isDownloadComplete(false)) {
long completedTime = dm.getDownloadState().getLongParameter(
DownloadManagerState.PARAM_DOWNLOAD_COMPLETED_TIME);
if (completedTime <= 0) {
value = dm.getDownloadState().getLongParameter(
DownloadManagerState.PARAM_DOWNLOAD_ADDED_TIME);
} else {
value = completedTime;
}
}
if (!cell.setSortValue(value) && cell.isValid()
&& curFormat == globalFormat) {
return;
}
if (!cell.isShown()) {
return;
}
if (value <= 0) {
cell.setText("");
return;
}
int cellWidth = cell.getWidth();
Date date = new Date(value);
GC gc = new GC(Display.getDefault());
Point minSize = new Point(99999, 0);
int idxFormat = -1;
for (int i = globalFormat; i < FORMATS.length; i++) {
SimpleDateFormat temp = new SimpleDateFormat(FORMATS[i]);
Point newSize = gc.stringExtent(temp.format(date));
if (newSize.x < cellWidth) {
idxFormat = i;
break;
}
if (newSize.x < minSize.x) {
minSize = newSize;
idxFormat = i;
}
}
gc.dispose();
if (idxFormat >= 0) {
if (idxFormat > globalFormat) {
globalFormat = idxFormat;
cell.getTableColumn().invalidateCells();
} else if (idxFormat < globalFormat) {
idxFormat = globalFormat;
}
curFormat = idxFormat;
SimpleDateFormat temp = new SimpleDateFormat(FORMATS[idxFormat]
+ "\nh:mm a");
cell.setText(temp.format(date));
}
|
|