下面列出了怎么用javax.swing.JInternalFrame.JDesktopIcon的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* {@inheritDoc}
*/
public boolean isInState(JComponent c) {
Component parent = c;
while (parent.getParent() != null) {
if (parent instanceof JInternalFrame || parent instanceof JDesktopIcon) {
break;
}
parent = parent.getParent();
}
if (parent instanceof JInternalFrame) {
return ((JInternalFrame) parent).isIcon();
} else if (parent instanceof JDesktopIcon) {
return true;
}
return false;
}
/**
* Installs the UI delegate on the desktop icon if necessary.
*
* @param jdi
* Desktop icon.
*/
void installIfNecessary(JDesktopIcon jdi) {
// fix for issue 344 - reopening an internal frame
// that has been closed.
if (this.desktopIcon == null) {
this.installUI(jdi);
}
}
/**
* Uninstalls the UI delegate from the desktop icon if necessary.
*
* @param jdi
* Desktop icon.
*/
void uninstallIfNecessary(JDesktopIcon jdi) {
// fix for issue 345 - an internal frame used in inner option pane
// gets closed twice
if (this.desktopIcon == jdi) {
this.uninstallUI(jdi);
}
}
/**
* Searches JInternalframe in container.
*
* @param cont Container to search component in.
* @param chooser a component chooser specifying searching criteria.
* @param index Ordinal component index.
* @return JInternalframe instance or null if component was not found.
*/
public static JInternalFrame findJInternalFrame(Container cont, ComponentChooser chooser, int index) {
Component res = findComponent(cont, new JInternalFrameFinder(chooser), index);
if (res instanceof JInternalFrame) {
return (JInternalFrame) res;
} else if (res instanceof JInternalFrame.JDesktopIcon) {
return ((JInternalFrame.JDesktopIcon) res).getInternalFrame();
} else {
return null;
}
}
/**
* Waits JInternalframe in container.
*
* @param cont Container to search component in.
* @param chooser a component chooser specifying searching criteria.
* @param index Ordinal component index.
* @return JInternalframe instance.
*
*/
public static JInternalFrame waitJInternalFrame(final Container cont, final ComponentChooser chooser, final int index) {
Component res = waitComponent(cont, new JInternalFrameFinder(chooser), index);
if (res instanceof JInternalFrame) {
return (JInternalFrame) res;
} else if (res instanceof JInternalFrame.JDesktopIcon) {
return ((JInternalFrame.JDesktopIcon) res).getInternalFrame();
} else {
throw (new TimeoutExpiredException(chooser.getDescription()));
}
}
/**
* Maps {@code JInternalFrame.getDesktopIcon()} through queue
*/
public JDesktopIcon getDesktopIcon() {
return (runMapping(new MapAction<JDesktopIcon>("getDesktopIcon") {
@Override
public JDesktopIcon map() {
return ((JInternalFrame) getSource()).getDesktopIcon();
}
}));
}
/**
* Maps {@code JInternalFrame.setDesktopIcon(JDesktopIcon)} through queue
*/
public void setDesktopIcon(final JDesktopIcon jDesktopIcon) {
runMapping(new MapVoidAction("setDesktopIcon") {
@Override
public void map() {
((JInternalFrame) getSource()).setDesktopIcon(jDesktopIcon);
}
});
}
private static JInternalFrame findOne(ContainerOperator<?> cont, String text, int index) {
Component source = waitComponent(cont,
new JInternalFrameByTitleFinder(text,
cont.getComparator()),
index);
if (source instanceof JInternalFrame) {
return (JInternalFrame) source;
} else if (source instanceof JInternalFrame.JDesktopIcon) {
return ((JInternalFrame.JDesktopIcon) source).getInternalFrame();
} else {
throw (new TimeoutExpiredException("No internal frame was found"));
}
}
@Override
public void paintComponent(Graphics g) {
Graphics2D graphics = (Graphics2D) g.create();
// Desktop icon is translucent.
final float coef = (this.getParent() instanceof JDesktopIcon) ? 0.9f : 1.0f;
graphics.setComposite(WidgetUtilities.getAlphaComposite(this.frame, coef, g));
boolean leftToRight = this.frame.getComponentOrientation().isLeftToRight();
int width = this.getWidth();
int height = this.getHeight() + 2;
SubstanceColorScheme scheme = SubstanceCoreUtilities.getSkin(this.frame)
.getEnabledColorScheme(DecorationAreaType.SECONDARY_TITLE_PANE);
JInternalFrame hostFrame = (JInternalFrame) SwingUtilities
.getAncestorOfClass(JInternalFrame.class, this);
JComponent hostForColorization = hostFrame;
if (hostFrame == null) {
// try desktop icon
JDesktopIcon desktopIcon = (JDesktopIcon) SwingUtilities
.getAncestorOfClass(JDesktopIcon.class, this);
if (desktopIcon != null)
hostFrame = desktopIcon.getInternalFrame();
hostForColorization = desktopIcon;
}
Color backgr = hostFrame.getBackground();
if (!(backgr instanceof UIResource)) {
double colorization = SubstanceCoreUtilities.getColorizationFactor(hostForColorization);
scheme = SubstanceColorSchemeUtilities.getShiftedScheme(scheme, backgr, colorization,
null, 0.0);
}
BackgroundPaintingUtils.update(graphics, SubstanceInternalFrameTitlePane.this, false);
String theTitle = this.frame.getTitle();
String displayTitle = getDisplayTitle();
Font font = SubstanceCortex.GlobalScope.getFontPolicy().getFontSet().getWindowTitleFont();
graphics.setFont(font);
if (displayTitle != null) {
Rectangle titleTextRect = SubstanceTitlePaneUtilities.getTitlePaneTextRectangle(this,
this.frame);
FontMetrics fm = SubstanceMetricsUtilities.getFontMetrics(font);
int displayTitleWidth = fm.stringWidth(displayTitle);
// show tooltip with full title only if necessary
if (theTitle.equals(displayTitle)) {
this.setToolTipText(null);
} else {
this.setToolTipText(theTitle);
}
int xOffset = 0;
SubstanceSlices.HorizontalGravity titleTextGravity = SubstanceTitlePaneUtilities
.getTitlePaneTextGravity();
switch (titleTextGravity) {
case LEADING:
xOffset = leftToRight ? titleTextRect.x
: titleTextRect.x + titleTextRect.width - displayTitleWidth;
break;
case TRAILING:
xOffset = leftToRight
? titleTextRect.x + titleTextRect.width - displayTitleWidth
: titleTextRect.x;
break;
default:
xOffset = titleTextRect.x + (titleTextRect.width - displayTitleWidth) / 2;
}
int yOffset = titleTextRect.y + (int) ((titleTextRect.getHeight() - fm.getHeight()) / 2)
+ fm.getAscent();
SubstanceColorScheme fillScheme = SubstanceCoreUtilities.getSkin(this.frame)
.getBackgroundColorScheme(DecorationAreaType.SECONDARY_TITLE_PANE);
Color echoColor = !fillScheme.isDark() ? fillScheme.getUltraDarkColor()
: fillScheme.getUltraLightColor();
SubstanceTextUtilities.paintTextWithDropShadow(this, graphics,
SubstanceColorUtilities.getForegroundColor(scheme), echoColor, displayTitle,
width, height, xOffset, yOffset);
}
graphics.dispose();
}
/**
* Constructs JDesktopIconOperator.
*
* @param b a component
*/
public JDesktopIconOperator(JInternalFrame.JDesktopIcon b) {
super(b);
setOutput(JemmyProperties.getCurrentOutput());
setTimeouts(JemmyProperties.getCurrentTimeouts());
}
@Override
public boolean checkComponent(Component comp) {
return ((comp instanceof JInternalFrame || comp instanceof JInternalFrame.JDesktopIcon)
&& sf.checkComponent(comp));
}