📄 columndatesizer.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: ColumnDateSizer.java
package org.gudy.azureus2.ui.swt.views.tableitems;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.Display;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.util.TimeFormatter;
import org.gudy.azureus2.plugins.ui.menus.MenuItem;
import org.gudy.azureus2.plugins.ui.menus.MenuItemListener;
import org.gudy.azureus2.plugins.ui.tables.*;
import org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn;
public abstract class ColumnDateSizer extends CoreTableColumn
implements TableCellRefreshListener
{
private static int PADDING = 10;
int curFormat;
int maxWidthUsed[];
Date maxWidthDate[];
private boolean showTime;
private boolean multiline;
private static Font fontBold;
public ColumnDateSizer(Class forDataSrouceType, String columnID, int width, String tableID)
{
super(forDataSrouceType, columnID, 2, width, tableID);
curFormat = 0;
maxWidthUsed = new int[TimeFormatter.DATEFORMATS_DESC.length];
maxWidthDate = new Date[TimeFormatter.DATEFORMATS_DESC.length];
showTime = true;
multiline = true;
TableContextMenuItem menuShowTime = addContextMenuItem("TableColumn.menu.date_added.time");
menuShowTime.addListener(new MenuItemListener() {
final ColumnDateSizer this$0;
public void selected(MenuItem menu, Object target)
{
showTime = !showTime;
setUserData("showTime", new Long(showTime ? 1L : 0L));
maxWidthUsed = new int[TimeFormatter.DATEFORMATS_DESC.length];
maxWidthDate = new Date[TimeFormatter.DATEFORMATS_DESC.length];
curFormat = -1;
recalcWidth(new Date());
if (curFormat < 0)
curFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
}
{
this$0 = ColumnDateSizer.this;
super();
}
});
}
public void postConfigLoad()
{
Object oShowTime = getUserData("showTime");
if (oShowTime instanceof Number)
{
Number nShowTime = (Number)oShowTime;
showTime = nShowTime.byteValue() == 1;
} else
{
showTime = COConfigurationManager.getBooleanParameter("v3.Start Advanced");
}
}
public final void refresh(TableCell cell)
{
refresh(cell, 0L);
}
public void refresh(TableCell cell, long timestamp)
{
if (!cell.setSortValue(timestamp) && cell.isValid())
return;
if (timestamp <= 0L)
return;
Date date = new Date(timestamp);
if (curFormat >= 0)
{
if (multiline && cell.getHeight() < 20)
multiline = false;
String suffix = !showTime || multiline ? "" : " hh:mm a";
int newWidth = calcWidth(date, (new StringBuilder()).append(TimeFormatter.DATEFORMATS_DESC[curFormat]).append(suffix).toString());
if (newWidth > cell.getWidth() - PADDING)
{
if (newWidth > maxWidthUsed[curFormat])
{
maxWidthUsed[curFormat] = newWidth;
maxWidthDate[curFormat] = date;
}
recalcWidth(date);
}
String s = (new StringBuilder()).append(TimeFormatter.DATEFORMATS_DESC[curFormat]).append(suffix).toString();
SimpleDateFormat temp = new SimpleDateFormat((new StringBuilder()).append(s).append(!showTime || !multiline ? "" : "\nh:mm a").toString());
cell.setText(temp.format(date));
}
}
public void setWidth(int width)
{
int oldWidth = getWidth();
super.setWidth(width);
if (oldWidth == width)
return;
if (maxWidthDate != null)
{
if (maxWidthDate[curFormat] == null)
maxWidthDate[curFormat] = new Date();
recalcWidth(maxWidthDate[curFormat]);
}
}
public void recalcWidth(Date date)
{
int idxFormat;
Exception exception;
String suffix = !showTime || multiline ? "" : " hh:mm a";
int width = getWidth();
if (maxWidthDate == null)
{
maxWidthUsed = new int[TimeFormatter.DATEFORMATS_DESC.length];
maxWidthDate = new Date[TimeFormatter.DATEFORMATS_DESC.length];
}
idxFormat = TimeFormatter.DATEFORMATS_DESC.length - 1;
GC gc = new GC(Display.getDefault());
if (fontBold == null)
{
FontData fontData[] = gc.getFont().getFontData();
for (int i = 0; i < fontData.length; i++)
{
FontData fd = fontData[i];
fd.setStyle(1);
}
fontBold = new Font(gc.getDevice(), fontData);
}
gc.setFont(fontBold);
try
{
Point minSize = new Point(0x1869f, 0);
for (int i = 0; i < TimeFormatter.DATEFORMATS_DESC.length; i++)
{
if (maxWidthUsed[i] > width - PADDING)
continue;
SimpleDateFormat temp = new SimpleDateFormat((new StringBuilder()).append(TimeFormatter.DATEFORMATS_DESC[i]).append(suffix).toString());
Point newSize = gc.stringExtent(temp.format(date));
if (newSize.x < width - PADDING)
{
idxFormat = i;
if (maxWidthUsed[i] < newSize.x)
{
maxWidthUsed[i] = newSize.x;
maxWidthDate[i] = date;
}
break;
}
if (newSize.x < minSize.x)
{
minSize = newSize;
idxFormat = i;
}
}
}
catch (Throwable t)
{
gc.dispose();
return;
}
finally
{
gc.dispose();
}
gc.dispose();
break MISSING_BLOCK_LABEL_341;
throw exception;
if (curFormat != idxFormat)
{
curFormat = idxFormat;
invalidateCells();
}
return;
}
public int calcWidth(Date date, String format)
{
GC gc = new GC(Display.getDefault());
if (fontBold == null)
{
FontData fontData[] = gc.getFont().getFontData();
for (int i = 0; i < fontData.length; i++)
{
FontData fd = fontData[i];
fd.setStyle(1);
}
fontBold = new Font(gc.getDevice(), fontData);
}
gc.setFont(fontBold);
SimpleDateFormat temp = new SimpleDateFormat(format);
Point newSize = gc.stringExtent(temp.format(date));
gc.dispose();
return newSize.x;
}
public boolean getShowTime()
{
return showTime;
}
public void setShowTime(boolean showTime)
{
this.showTime = showTime;
}
public boolean isMultiline()
{
return multiline;
}
public void setMultiline(boolean multiline)
{
this.multiline = multiline;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -