📄 styledshell.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: StyledShell.java
package org.gudy.azureus2.ui.swt.components.shell;
import com.aelitis.azureus.ui.swt.UIFunctionsManagerSWT;
import com.aelitis.azureus.ui.swt.UIFunctionsSWT;
import com.aelitis.azureus.ui.swt.utils.ColorCache;
import org.eclipse.swt.events.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.*;
import org.gudy.azureus2.core3.util.AERunnable;
import org.gudy.azureus2.core3.util.Constants;
import org.gudy.azureus2.ui.swt.Utils;
// Referenced classes of package org.gudy.azureus2.ui.swt.components.shell:
// ShellFactory
public class StyledShell
{
public static final int HINT_ALIGN_CENTER = 2;
public static final int HINT_ALIGN_FIT_IN_MONITOR = 4;
public static final int HINT_ALIGN_NONE = 1;
private Shell parentShell;
private Shell styledShell;
private Display display;
private Composite borderedBackground;
private Composite content;
private int borderWidth;
private boolean isAlreadyOpened;
private int alpha;
private boolean isAnimating;
private Monitor monitor;
private boolean useCustomTrim;
private Region region;
private boolean isAlphaSupported;
private UIFunctionsSWT uiFunctions;
public StyledShell(Shell parentShell, int borderWidth)
{
this(parentShell, borderWidth, true);
}
public StyledShell(Shell parentShell, int borderWidth, boolean useCustomTrim)
{
isAlreadyOpened = false;
alpha = 255;
isAnimating = false;
monitor = null;
this.useCustomTrim = true;
isAlphaSupported = true;
this.parentShell = parentShell;
this.borderWidth = borderWidth;
this.useCustomTrim = useCustomTrim;
if (null == parentShell)
throw new NullPointerException("parentShell can not be null");
try
{
parentShell.setAlpha(parentShell.getAlpha());
}
catch (Throwable t)
{
isAlphaSupported = false;
}
display = parentShell.getDisplay();
if (useCustomTrim)
{
createCustomShell();
if (null != styledShell)
styledShell.addDisposeListener(new DisposeListener() {
final StyledShell this$0;
public void widgetDisposed(DisposeEvent e)
{
if (null != region && !region.isDisposed())
region.dispose();
}
{
this$0 = StyledShell.this;
super();
}
});
} else
{
createStandardShell();
}
}
private void createCustomShell()
{
styledShell = ShellFactory.createShell(parentShell, getShellStyle(0));
FillLayout fillLayout = new FillLayout();
fillLayout.marginHeight = borderWidth;
fillLayout.marginWidth = borderWidth;
styledShell.setLayout(fillLayout);
if (Constants.isOSX)
getUIFunctions().createMainMenu(styledShell);
borderedBackground = new Composite(styledShell, 0);
fillLayout = new FillLayout();
fillLayout.marginHeight = borderWidth;
fillLayout.marginWidth = borderWidth;
borderedBackground.setLayout(fillLayout);
content = new Composite(borderedBackground, 0x20000000);
content.setBackgroundMode(1);
setBackground(ColorCache.getColor(styledShell.getDisplay(), 38, 38, 38));
content.setBackground(ColorCache.getColor(styledShell.getDisplay(), 13, 13, 13));
content.setForeground(ColorCache.getColor(styledShell.getDisplay(), 206, 206, 206));
borderedBackground.addPaintListener(new PaintListener() {
final StyledShell this$0;
public void paintControl(PaintEvent e)
{
Rectangle bounds = borderedBackground.getClientArea();
int r = borderWidth;
int d = r * 2;
try
{
e.gc.setAntialias(1);
}
catch (Throwable t) { }
e.gc.setBackground(styledShell.getBackground());
e.gc.fillRectangle(0, 0, r, r);
e.gc.fillRectangle(bounds.width - r, 0, r, r);
e.gc.fillRectangle(bounds.width - r, bounds.height - r, r, r);
e.gc.fillRectangle(0, bounds.height - r, r, r);
e.gc.setBackground(content.getBackground());
e.gc.fillPolygon(circle(r, r, r));
e.gc.fillPolygon(circle(r, r, bounds.height - r));
e.gc.fillPolygon(circle(r, bounds.width - r, r));
e.gc.fillPolygon(circle(r, bounds.width - r, bounds.height - r));
e.gc.fillRectangle(new Rectangle(r, 0, bounds.width - d, r));
e.gc.fillRectangle(new Rectangle(r, bounds.height - r, bounds.width - d, r));
e.gc.fillRectangle(new Rectangle(0, r, bounds.width, bounds.height - d));
}
{
this$0 = StyledShell.this;
super();
}
});
Listener l = new Listener() {
int startX;
int startY;
final StyledShell this$0;
public void handleEvent(Event e)
{
if (e.type == 1 && e.character == '\033')
styledShell.dispose();
if (e.type == 3 && e.button == 1)
{
startX = e.x;
startY = e.y;
}
if (e.type == 5 && (e.stateMask & 0x80000) != 0)
{
Point p = styledShell.toDisplay(e.x, e.y);
p.x -= startX;
p.y -= startY;
styledShell.setLocation(p);
}
if (e.type == 11)
styledShell.setRegion(getRoundedRegion(styledShell.getBounds()));
}
{
this$0 = StyledShell.this;
super();
}
};
styledShell.addListener(1, l);
styledShell.addListener(3, l);
styledShell.addListener(5, l);
styledShell.addListener(11, l);
styledShell.setCursor(display.getSystemCursor(5));
content.setCursor(display.getSystemCursor(0));
}
private void createStandardShell()
{
styledShell = ShellFactory.createShell(parentShell, getShellStyle(0));
FillLayout fillLayout = new FillLayout();
fillLayout.marginHeight = 0;
fillLayout.marginWidth = 0;
styledShell.setLayout(fillLayout);
if (Constants.isOSX)
getUIFunctions().createMainMenu(styledShell);
Utils.setShellIcon(styledShell);
content = new Composite(styledShell, 0x20000000);
content.setBackgroundMode(1);
alpha = 255;
}
private int getShellStyle(int style)
{
if (useCustomTrim)
{
if (Constants.isOSX)
{
if (isAlphaSupported)
style |= 8;
} else
{
style |= 8;
}
return style;
} else
{
return 2160;
}
}
private Region getRoundedRegion(Rectangle bounds)
{
int r = borderWidth;
int d = r * 2;
if (null != region && !region.isDisposed())
region.dispose();
region = new Region();
region.add(circle(r, r, r));
region.add(circle(r, r, bounds.height - r));
region.add(circle(r, bounds.width - r, r));
region.add(circle(r, bounds.width - r, bounds.height - r));
region.add(new Rectangle(r, 0, bounds.width - d, r));
region.add(new Rectangle(r, bounds.height - r, bounds.width - d, r));
region.add(new Rectangle(0, r, bounds.width, bounds.height - d));
return region;
}
private int[] circle(int r, int offsetX, int offsetY)
{
int polygon[] = new int[8 * r + 4];
for (int i = 0; i < 2 * r + 1; i++)
{
int x = i - r;
int y = (int)Math.sqrt(r * r - x * x);
polygon[2 * i] = offsetX + x;
polygon[2 * i + 1] = offsetY + y;
polygon[8 * r - 2 * i - 2] = offsetX + x;
polygon[8 * r - 2 * i - 1] = offsetY - y;
}
return polygon;
}
public void addListener(int eventType, Listener listener)
{
if (isAlive())
styledShell.addListener(eventType, listener);
}
public void open()
{
if (isAlive())
{
Point cursorLocation = display.getCursorLocation();
monitor = Utils.getMonitor(cursorLocation);
styledShell.open();
isAlreadyOpened = true;
}
}
public void close()
{
if (isAlive())
{
styledShell.close();
isAlreadyOpened = false;
}
}
public void forceActive()
{
if (isAlive())
{
styledShell.setVisible(true);
styledShell.forceActive();
}
}
public void pack()
{
if (isAlive())
styledShell.pack();
}
public void pack(boolean changed)
{
if (isAlive())
styledShell.pack(changed);
}
public void setSize(int width, int height)
{
setSize(width, height, isAlreadyOpened ? 0 : 2);
}
public void setSize(int width, int height, int hint)
{
if (isAlive())
{
Rectangle outerBounds = styledShell.getBounds();
if (useCustomTrim)
{
width += borderWidth * 4;
height += borderWidth * 4;
} else
{
width += styledShell.getBounds().width - styledShell.getClientArea().width;
height += styledShell.getBounds().height - styledShell.getClientArea().height;
}
if (outerBounds.width != width || outerBounds.height != height)
{
outerBounds.width = width;
outerBounds.height = height;
if ((hint & 2) != 0)
Utils.centerRelativeTo(outerBounds, getUIFunctions().getMainShell().getBounds());
if ((hint & 4) != 0)
if (null != monitor)
Utils.makeVisibleOnMonitor(outerBounds, monitor);
else
Utils.makeVisibleOnCursor(outerBounds);
styledShell.setBounds(outerBounds);
if (useCustomTrim)
styledShell.setRegion(getRoundedRegion(outerBounds));
styledShell.forceActive();
}
}
}
public void centersShell()
{
if (isAlive())
{
Rectangle bounds = styledShell.getBounds();
Utils.centerRelativeTo(bounds, getUIFunctions().getMainShell().getBounds());
styledShell.setBounds(bounds);
}
}
public void makeShellVisible()
{
if (isAlive())
{
Rectangle bounds = styledShell.getBounds();
if (null != monitor)
Utils.makeVisibleOnMonitor(bounds, monitor);
else
Utils.makeVisibleOnCursor(bounds);
styledShell.setBounds(bounds);
}
}
public void animateFade(final int milliSeconds)
{
if (!isAlive() || isAnimating || !isAlphaSupported)
{
return;
} else
{
Utils.execSWTThreadLater(0, new AERunnable() {
final int val$milliSeconds;
final StyledShell this$0;
public void runSupport()
{
if (!isAlive())
return;
isAnimating = true;
int seconds = milliSeconds;
int currentAlpha = 0;
int delay = 3;
int sleepIncrement = milliSeconds / (10 + delay);
if (isAlive())
{
setAlpha(styledShell, currentAlpha);
styledShell.setVisible(true);
}
while (seconds > 0)
{
Thread.sleep(sleepIncrement);
seconds -= sleepIncrement;
if (!isAlive())
break;
if (delay <= 0)
{
setAlpha(styledShell, Math.min(currentAlpha, alpha));
currentAlpha += 20;
}
delay--;
}
if (isAlive())
setAlpha(styledShell, alpha);
isAnimating = false;
styledShell.forceActive();
break MISSING_BLOCK_LABEL_310;
InterruptedException e;
e;
e.printStackTrace();
if (isAlive())
setAlpha(styledShell, alpha);
isAnimating = false;
styledShell.forceActive();
break MISSING_BLOCK_LABEL_310;
Exception exception;
exception;
if (isAlive())
setAlpha(styledShell, alpha);
isAnimating = false;
styledShell.forceActive();
throw exception;
}
{
this$0 = StyledShell.this;
milliSeconds = i;
super();
}
});
return;
}
}
public void setVisible(boolean visible)
{
if (isAlive())
styledShell.setVisible(visible);
}
public void removeListener(int eventType, Listener listener)
{
if (isAlive())
styledShell.removeListener(eventType, listener);
}
public void setCursor(Cursor cursor)
{
if (isAlive())
styledShell.setCursor(cursor);
}
public void setData(String key, Object value)
{
if (isAlive())
styledShell.setData(key, value);
}
public boolean isAlive()
{
return null != styledShell && !styledShell.isDisposed();
}
public Composite getContent()
{
return content;
}
public Shell getShell()
{
return styledShell;
}
public boolean isAlreadyOpened()
{
return isAlreadyOpened;
}
public void setBackground(Color color)
{
styledShell.setBackground(color);
}
public int getAlpha()
{
return alpha;
}
public void setAlpha(int alpha)
{
this.alpha = alpha;
}
public void hideShell(boolean value)
{
if (value)
setAlpha(styledShell, 0);
else
setAlpha(styledShell, alpha);
}
public String getText()
{
return !isAlive() ? null : styledShell.getText();
}
public void setText(String string)
{
if (isAlive())
styledShell.setText(string);
}
public boolean isUseCustomTrim()
{
return useCustomTrim;
}
private UIFunctionsSWT getUIFunctions()
{
if (null == uiFunctions)
{
uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (null == uiFunctions)
throw new NullPointerException("An initialized instance of UIFunctionsSWT is required to create a LightBoxShell");
}
return uiFunctions;
}
private void setAlpha(Shell shell, int alpha)
{
if (isAlphaSupported && null != shell)
shell.setAlpha(alpha);
}
public Rectangle getBounds()
{
return styledShell.getBounds();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -