📄 twistielabel.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: TwistieLabel.java
package org.gudy.azureus2.ui.swt;
import java.util.*;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
// Referenced classes of package org.gudy.azureus2.ui.swt:
// ITwistieConstants, ITwistieListener
public class TwistieLabel extends Composite
implements ITwistieConstants
{
private class MouseInterceptor extends MouseAdapter
{
final TwistieLabel this$0;
public void mouseDown(MouseEvent e)
{
isCollapsed = !isCollapsed;
redraw();
notifyTwistieListeners();
}
private MouseInterceptor()
{
this$0 = TwistieLabel.this;
super();
}
}
private int style;
static final int points_for_expanded[] = {
0, 2, 8, 2, 4, 6
};
static final int points_for_collapsed[] = {
2, -1, 2, 8, 6, 4
};
private Label titleLabel;
private Color twistieColor;
private boolean isCollapsed;
private Label descriptionLabel;
private List listeners;
public TwistieLabel(Composite parent, int style)
{
super(parent, 0);
this.style = 2;
titleLabel = null;
twistieColor = null;
isCollapsed = true;
descriptionLabel = null;
listeners = new ArrayList();
setBackgroundMode(2);
this.style = style;
GridLayout gLayout = new GridLayout();
gLayout.marginHeight = 0;
gLayout.marginWidth = 0;
gLayout.verticalSpacing = 0;
gLayout.horizontalSpacing = 0;
setLayout(gLayout);
titleLabel = new Label(this, 0);
if ((this.style & 8) != 0)
{
Label separator = new Label(this, 258);
GridData labelData = new GridData(4, 0x1000000, true, false);
labelData.horizontalIndent = 10;
separator.setLayoutData(labelData);
}
GridData labelData;
if ((this.style & 4) != 0)
{
descriptionLabel = new Label(this, 64);
labelData = new GridData(4, 4, true, false);
labelData.horizontalIndent = 10;
descriptionLabel.setLayoutData(labelData);
Font initialFont = descriptionLabel.getFont();
FontData fontData[] = initialFont.getFontData();
for (int i = 0; i < fontData.length; i++)
fontData[i].setStyle(fontData[i].getStyle() | 2);
descriptionLabel.setFont(new Font(getDisplay(), fontData));
}
if ((this.style & 0x10) != 0)
isCollapsed = false;
labelData = new GridData(4, 0x1000000, true, false);
labelData.horizontalIndent = 10;
titleLabel.setLayoutData(labelData);
MouseInterceptor interceptor = new MouseInterceptor();
super.addMouseListener(interceptor);
titleLabel.addMouseListener(interceptor);
addPaintListener(new PaintListener() {
final TwistieLabel this$0;
public void paintControl(PaintEvent e)
{
int offsetX = titleLabel.getBounds().x - 10;
int offsetY = titleLabel.getBounds().y + 3;
if (null != twistieColor)
e.gc.setBackground(twistieColor);
else
e.gc.setBackground(getForeground());
if (isCollapsed)
e.gc.fillPolygon(translate(TwistieLabel.points_for_collapsed, offsetX, offsetY));
else
e.gc.fillPolygon(translate(TwistieLabel.points_for_expanded, offsetX, offsetY));
}
{
this$0 = TwistieLabel.this;
super();
}
});
}
private int[] translate(int data[], int x, int y)
{
int target[] = new int[data.length];
for (int i = 0; i < data.length; i += 2)
target[i] = data[i] + x;
for (int i = 1; i < data.length; i += 2)
target[i] = data[i] + y;
return target;
}
public void addMouseListener(MouseListener listener)
{
if (null != titleLabel)
titleLabel.addMouseListener(listener);
super.addMouseListener(listener);
}
public void removeMouseListener(MouseListener listener)
{
if (null != titleLabel)
titleLabel.removeMouseListener(listener);
super.removeMouseListener(listener);
}
public void setTwistieForeground(Color color)
{
twistieColor = color;
}
public void setForeground(Color color)
{
if (null != titleLabel && !titleLabel.isDisposed())
titleLabel.setForeground(color);
if (null != descriptionLabel && !descriptionLabel.isDisposed())
descriptionLabel.setForeground(color);
if (null == twistieColor)
twistieColor = color;
super.setForeground(color);
}
public void setBackground(Color color)
{
if (null != titleLabel)
titleLabel.setBackground(color);
if (null != descriptionLabel)
descriptionLabel.setBackground(color);
super.setBackground(color);
}
public void setTitle(String string)
{
if (null != titleLabel)
titleLabel.setText(string);
}
public void setDescription(String string)
{
if (null != descriptionLabel)
descriptionLabel.setText(string);
}
public void setToolTipText(String string)
{
if (null != titleLabel)
titleLabel.setToolTipText(string);
if (null != descriptionLabel)
descriptionLabel.setToolTipText(string);
super.setToolTipText(string);
}
public void setEnabled(boolean enabled)
{
if (null != titleLabel)
titleLabel.setEnabled(enabled);
super.setEnabled(enabled);
}
public boolean isCollapsed()
{
return isCollapsed;
}
public void addTwistieListener(ITwistieListener listener)
{
listeners.add(listener);
}
public void removeTwistieListener(ITwistieListener listener)
{
listeners.remove(listener);
}
private void notifyTwistieListeners()
{
for (Iterator iterator = listeners.iterator(); iterator.hasNext(); ((ITwistieListener)iterator.next()).isCollapsed(isCollapsed()));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -