⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bufferedtablerow.java

📁 java 文件下载器。可自定义
💻 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:   BufferedTableRow.java

package org.gudy.azureus2.ui.swt.components;

import java.io.PrintStream;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.ui.swt.Utils;
import org.gudy.azureus2.ui.swt.mainwindow.Colors;

public class BufferedTableRow
{

	private static final int VALUE_SIZE_INC = 8;
	private static Color alternatingColors[] = null;
	public static final int REQUIRE_TABLEITEM = 0;
	public static final int REQUIRE_TABLEITEM_INITIALIZED = 1;
	public static final int REQUIRE_VISIBILITY = 2;
	protected Table table;
	protected TableItem item;
	protected Image image_values[];
	protected Color foreground_colors[];
	protected Color foreground;
	protected Color ourForeground;
	private Point ptIconSize;
	private Image imageBG;
	private static final boolean DEBUG_SET_FOREGROUND = System.getProperty("debug.setforeground") != null;

	public BufferedTableRow(Table _table)
	{
		image_values = new Image[0];
		foreground_colors = new Color[0];
		ptIconSize = null;
		table = _table;
		item = null;
	}

	public void createSWTRow()
	{
		item = new TableItem(table, 0);
		setAlternatingBGColor(true);
	}

	public void createSWTRow(int index)
	{
		new TableItem(table, 0);
		setTableItem(index, false);
	}

	public void setAlternatingBGColor(boolean bEvenIfNotVisible)
	{
		if (Utils.TABLE_GRIDLINE_IS_ALTERNATING_COLOR)
			return;
		if ((table.getStyle() & 0x10000000) != 0 && !bEvenIfNotVisible && !isVisible())
			return;
		if (item == null || item.isDisposed())
			return;
		int index = table.indexOf(item);
		if (index == -1)
			return;
		try
		{
			if (alternatingColors == null || alternatingColors[1].isDisposed())
				alternatingColors = (new Color[] {
					table.getDisplay().getSystemColor(25), Colors.colorAltRow
				});
			Color newColor = alternatingColors[index % alternatingColors.length];
			if (!newColor.equals(getBackground()))
				item.setBackground(newColor);
		}
		catch (Exception e)
		{
			Debug.out(e);
		}
	}

	public void dispose()
	{
		if (table != null && !table.isDisposed() && Utils.isThisThreadSWT())
		{
			if (!checkWidget(0))
			{
				TableItem items[] = table.getItems();
				for (int i = items.length - 1; i >= 0; i--)
				{
					TableItem item = items[i];
					if (item.isDisposed())
						continue;
					Object itemRow = item.getData("TableRow");
					if (itemRow != null && itemRow != this)
						continue;
					this.item = item;
					break;
				}

			}
			boolean itemNeedsDisposal = this.item != null && !this.item.isDisposed();
			if (ourForeground != null && !ourForeground.isDisposed())
			{
				if (itemNeedsDisposal)
					this.item.setForeground(null);
				ourForeground.dispose();
			}
			if (itemNeedsDisposal)
				this.item.dispose();
			else
			if (table.getItemCount() > 0)
				System.err.println("No table row was found to dispose");
		} else
		if (!Utils.isThisThreadSWT())
		{
			System.err.println("Calling BufferedTableRow.dispose on non-SWT thread!");
			System.err.println(Debug.getStackTrace(false, false));
		}
		this.item = null;
	}

	public void setImage(int index, Image new_image)
	{
		if (!checkWidget(1))
			return;
		if (index >= image_values.length)
		{
			int new_size = Math.max(index + 1, image_values.length + 8);
			Image new_images[] = new Image[new_size];
			System.arraycopy(image_values, 0, new_images, 0, image_values.length);
			image_values = new_images;
		}
		Image image = image_values[index];
		if (new_image == image)
		{
			return;
		} else
		{
			image_values[index] = new_image;
			item.setImage(index, new_image);
			return;
		}
	}

	public Image getImage(int index)
	{
		if (!checkWidget(1))
			return null;
		else
			return item.getImage(index);
	}

	public boolean checkWidget(int checkFlags)
	{
		boolean bWidgetOk = !table.isDisposed() && item != null && !item.isDisposed() && item.getData("TableRow") == this;
		boolean bCheckVisibility = (checkFlags & 2) > 0;
		boolean bCheckInitialized = (checkFlags & 1) > 0;
		if (bWidgetOk && bCheckInitialized)
			bWidgetOk = (table.getStyle() & 0x10000000) == 0 || item.getData("SD") != null;
		if (bWidgetOk && bCheckVisibility)
			if (_isVisible())
			{
				if (!bCheckInitialized && (table.getStyle() & 0x10000000) != 0 && item.getData("SD") == null)
				{
					try
					{
						item.setData("SD", "1");
					}
					catch (NullPointerException badSWT) { }
					setAlternatingBGColor(true);
					setIconSize(ptIconSize);
					invalidate();
				}
			} else
			{
				bWidgetOk = false;
			}
		return bWidgetOk;
	}

	private boolean _isVisible()
	{
		if (!table.isVisible())
			return false;
		int index = table.indexOf(item);
		if (index == -1)
			return false;
		int iTopIndex = table.getTopIndex();
		if (index < iTopIndex)
			return false;
		int iBottomIndex = Utils.getTableBottomIndex(table, iTopIndex);
		return index <= iBottomIndex;
	}

	public Color getForeground()
	{
		if (!checkWidget(1))
			return null;
		if (ourForeground == null && table.isSelected(table.indexOf(item)))
			return table.getDisplay().getSystemColor(27);
		else
			return item.getForeground();
	}

	private static void setForegroundDebug(String method_sig, Color c)
	{
		if (DEBUG_SET_FOREGROUND && c != null)
			Debug.out((new StringBuilder()).append("BufferedTableRow ").append(method_sig).append(" -> ").append(c).toString());
	}

	private static void setForegroundDebug(String method_sig, int r, int g, int b)
	{
		if (DEBUG_SET_FOREGROUND && (r != 0 || g != 0 || b != 0))
			Debug.out((new StringBuilder()).append("BufferedTableRow ").append(method_sig).append(" -> ").append(r).append(",").append(g).append(",").append(b).toString());
	}

	public void setForeground(Color c)
	{
		setForegroundDebug("setForeground(Color)", c);
		if (!checkWidget(1))
			return;
		if (foreground == null && c == null)
			return;
		if (foreground != null && foreground.equals(c))
			return;
		foreground = c;
		if (ourForeground != null)
		{
			if (!ourForeground.isDisposed())
				ourForeground.dispose();
			ourForeground = null;
		}
		item.setForeground(foreground);
	}

	public void setForeground(int red, int green, int blue)
	{
		setForegroundDebug("setForeground(r,g,b)", red, green, blue);
		if (!checkWidget(1))
			return;
		if (red == -1 && green == -1 && blue == -1)
		{
			setForeground(null);
			return;
		}
		RGB newRGB = new RGB(red, green, blue);
		if (foreground != null && foreground.getRGB().equals(newRGB))
			return;
		Color newColor = new Color(getTable().getDisplay(), newRGB);
		item.setForeground(newColor);
		if (ourForeground != null && !ourForeground.isDisposed())
			ourForeground.dispose();
		foreground = newColor;
		ourForeground = newColor;
	}

	public boolean setForeground(int index, Color new_color)
	{
		setForegroundDebug("setForeground(int,Color)", new_color);
		if (!checkWidget(1))
			return false;
		if (index >= foreground_colors.length)
		{
			int new_size = Math.max(index + 1, foreground_colors.length + 8);
			Color new_colors[] = new Color[new_size];
			System.arraycopy(foreground_colors, 0, new_colors, 0, foreground_colors.length);
			foreground_colors = new_colors;
		}
		Color value = foreground_colors[index];
		if (new_color == value)
			return false;
		if (new_color != null && value != null && new_color.equals(value))
			return false;
		foreground_colors[index] = new_color;
		try
		{
			item.setForeground(index, new_color);
		}
		catch (NoSuchMethodError e) { }
		return true;
	}

	public Color getForeground(int index)
	{
		if (!checkWidget(1))
			return null;
		if (index >= foreground_colors.length)
			return getForeground();
		if (foreground_colors[index] == null && isSelected())
		{
			Color systemColor = table.getDisplay().getSystemColor(table.isFocusControl() ? 27 : 21);
			return systemColor;
		} else
		{
			return foreground_colors[index];
		}
	}

	protected String getText(int index)
	{
		if (!checkWidget(1))
			return "";
		else
			return item.getText(index);
	}

	public boolean setText(int index, String new_value)
	{
		if (!checkWidget(1))
			return false;
		if (index < 0 || index >= table.getColumnCount())
			return false;
		if (new_value == null)
			new_value = "";
		if (item.getText(index).equals(new_value))
		{
			return false;
		} else
		{
			item.setText(index, new_value);
			return true;
		}
	}

	public Rectangle getBounds(int index)
	{
		if (!checkWidget(1))
			return null;
		if (table.indexOf(item) == -1)
			return null;
		Rectangle r = item.getBounds(index);
		if (r == null || r.width == 0 || r.height == 0)
			return null;
		else
			return r;
	}

	protected Table getTable()
	{
		return table;
	}

	public Color getBackground()
	{
		if (!checkWidget(1))
			return null;
		if (isSelected())
			return table.getDisplay().getSystemColor(table.isFocusControl() ? 26 : 22);
		else
			return item.getBackground();
	}

	public int getIndex()
	{
		if (!checkWidget(0))
			return -1;
		else
			return table.indexOf(item);
	}

	private void copyToItem(TableItem newItem)
	{
		Table table = getTable();
		if (table == null || item == null)
			return;
		newItem.setImage(image_values);
		Color colorFG = item.getForeground();
		Color colorBG = item.getBackground();
		newItem.setForeground(colorFG);
		newItem.setBackground(colorBG);
		int numColumns = table.getColumnCount();
		for (int i = 0; i < numColumns; i++)
			try
			{
				newItem.setText(i, item.getText(i));
				Color colorColumnFG = item.getForeground(i);
				Color colorColumnBG = item.getBackground(i);
				if (!colorColumnFG.equals(colorFG))
					newItem.setForeground(i, colorColumnFG);
				if (!colorColumnBG.equals(colorBG))
					newItem.setBackground(i, colorColumnBG);
			}
			catch (NoSuchMethodError e) { }

		if (isSelected())
			table.select(table.indexOf(newItem));
		else
			table.deselect(table.indexOf(newItem));
		newItem.setData("TableRow", item.getData("TableRow"));
	}

	public boolean isSelected()
	{
		if (!checkWidget(0))
			return false;
		else
			return table.isSelected(table.indexOf(item));
	}

	public void setSelected(boolean bSelected)
	{
		if (!checkWidget(0))
			return;
		if (bSelected)
			table.select(getIndex());
		else
			table.deselect(getIndex());
	}

	public boolean setTableItem(int newIndex, boolean bCopyFromOld)
	{
		return setTableItem(newIndex, bCopyFromOld, true);
	}

	public boolean setTableItem(int newIndex, boolean bCopyFromOld, boolean isVisible)
	{
		TableItem newRow;
		try
		{
			newRow = table.getItem(newIndex);
		}
		catch (IllegalArgumentException er)
		{
			if (item == null || item.isDisposed())
			{
				return false;
			} else
			{
				item = null;
				return true;
			}
		}
		catch (Throwable e)
		{
			System.out.println((new StringBuilder()).append("setTableItem(").append(newIndex).append(", ").append(bCopyFromOld).append(")").toString());
			e.printStackTrace();
			return false;
		}
		if (newRow.isDisposed())
		{
			Debug.out((new StringBuilder()).append("newRow disposed from ").append(Debug.getCompressedStackTrace()).toString());
			return false;
		}
		if (newRow == item && newRow.getData("TableRow") == this)
		{
			if (isVisible)
				setAlternatingBGColor(false);
			return false;
		}
		if (newRow.getParent() != table)
			return false;
		if (bCopyFromOld)
			copyToItem(newRow);
		else
		if (newRow.getData("SD") != null)
		{
			newRow.setForeground(null);
			int numColumns = table.getColumnCount();
			for (int i = 0; i < numColumns; i++)
				try
				{
					newRow.setImage(i, null);
					newRow.setForeground(i, null);
				}
				catch (NoSuchMethodError e) { }

		} else
		{
			newRow.setData("SD", "1");
			setIconSize(ptIconSize);
		}
		if (isVisible)
			setAlternatingBGColor(false);
		try
		{
			newRow.setData("TableRow", this);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			System.out.println((new StringBuilder()).append("Disposed? ").append(newRow.isDisposed()).toString());
			if (!newRow.isDisposed())
			{
				System.out.println((new StringBuilder()).append("TR? ").append(newRow.getData("TableRow")).toString());
				System.out.println((new StringBuilder()).append("SD? ").append(newRow.getData("SD")).toString());
			}
		}
		image_values = new Image[0];
		foreground_colors = new Color[0];
		foreground = null;
		if (item != null && !item.isDisposed() && item.getData("TableRow") == this && newRow != item)
		{
			item.setData("TableRow", null);
			int numColumns = table.getColumnCount();
			for (int i = 0; i < numColumns; i++)
				try
				{
					item.setImage(i, null);
					item.setForeground(i, null);
				}
				catch (NoSuchMethodError e) { }

		}
		item = newRow;
		invalidate();
		return true;
	}

	public boolean setHeight(int iHeight)
	{
		return setIconSize(new Point(1, iHeight));
	}

	public boolean setIconSize(Point pt)
	{
		ptIconSize = pt;
		if (pt == null)
			return false;
		if (!checkWidget(1))
			return false;
		Image oldImage = item.getImage(0);
		if (oldImage != null)
		{
			Rectangle r = oldImage.getBounds();
			if (r.width == pt.x && r.height == pt.y)
				return false;
		}
		Image image = new Image(item.getDisplay(), pt.x, pt.y);
		item.setImage(0, image);
		item.setImage(0, null);
		image.dispose();
		return true;
	}

	public boolean isVisible()
	{
		return checkWidget(2);
	}

	public void invalidate()
	{
		Utils.execSWTThread(new AERunnable() {

			final BufferedTableRow this$0;

			public void runSupport()
			{
				if (!checkWidget(3))
				{
					return;
				} else
				{
					Rectangle r = item.getBounds(0);
					table.redraw(0, r.y, table.getClientArea().width, r.height, true);
					return;
				}
			}

			
			{
				this$0 = BufferedTableRow.this;
				AERunnable();
			}
		});
	}

	public void setBackgroundImage(Image image)
	{
		if (imageBG != null && !imageBG.isDisposed())
			imageBG.dispose();
		imageBG = image;
	}

	public Image getBackgroundImage()
	{
		return imageBG;
	}

	static 
	{
		Colors.getInstance().addColorsChangedListener(new ParameterListener() {

			public void parameterChanged(String parameterName)
			{
				BufferedTableRow.alternatingColors = null;
			}

		});
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -