下面列出了怎么用com.sun.jna.platform.WindowUtils的API类实例代码及写法,或者点击链接到github查看源代码。
private static void setAlphaMode(Window window, float ratio) {
try {
if (SystemInfo.isMacOSLeopard) {
if (window instanceof JWindow) {
((JWindow)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
}
else if (window instanceof JDialog) {
((JDialog)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
}
else if (window instanceof JFrame) {
((JFrame)window).getRootPane().putClientProperty("Window.alpha", 1.0f - ratio);
}
}
else if (isTranslucencySupported()) {
window.setOpacity(1.0f - ratio);
}
else {
WindowUtils.setWindowAlpha(window, 1.0f - ratio);
}
}
catch (Throwable e) {
LOG.debug(e);
}
}
@Override
public void setWindowMask(Window w, Icon mask) {
try {
WindowUtils.setWindowMask(w, mask);
} catch( ThreadDeath td ) {
throw td;
} catch( Throwable e ) {
LOG.log(Level.INFO, null, e);
}
}
private static String getGamePath() {
return WindowUtils.getAllWindows(false).stream().filter(window -> {
char[] className = new char[512];
User32.INSTANCE.GetClassName(window.getHWND(), className, 512);
return Native.toString(className).equals("POEWindowClass");
}).map(it -> {
String filePath = it.getFilePath();
return StringUtils.substringBeforeLast(filePath, "\\");
}).findAny().orElse(null);
}
@Test
public void testSoundReducer() throws IOException {
TestSubscriber<Map<String,String>> testSubscriber = new TestSubscriber<>();
List<DesktopWindow> allWindows = WindowUtils.getAllWindows(false);
allWindows.forEach(window -> {
System.out.println(window.getFilePath());
});
}
/**
* Repaints and revalidates the whole UI Tree.
*
* Calls {@link SwingUtilities#updateComponentTreeUI(Component c)}
* for every window owned by the application which cause UI skin and
* layout repaint.
*/
public void repaintUI()
{
if(!SwingUtilities.isEventDispatchThread())
{
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
repaintUI();
}
});
return;
}
if (UIManager.getLookAndFeel() instanceof SIPCommLookAndFeel)
((SIPCommLookAndFeel) UIManager.getLookAndFeel()).loadSkin();
Constants.reload();
ImageLoader.clearCache();
Window[] windows
= net.java.sip.communicator.plugin.desktoputil.WindowUtils
.getWindows();
for(Window win : windows)
{
reloadComponents(win);
ComponentUtils.updateComponentTreeUI(win);
}
}
private static boolean calcAlphaModelSupported() {
GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
if (device.isWindowTranslucencySupported(GraphicsDevice.WindowTranslucency.TRANSLUCENT)) {
return true;
}
try {
return WindowUtils.isWindowAlphaSupported();
}
catch (Throwable e) {
return false;
}
}
@Override
public void setWindowMask(final Window window, @Nullable final Shape mask) {
try {
if (isPerPixelTransparencySupported()) {
window.setShape(mask);
}
else {
WindowUtils.setWindowMask(window, mask);
}
}
catch (Throwable e) {
LOG.debug(e);
}
}
/**
* Initializes all frames and panels and shows the GUI.
*/
void loadApplicationGui()
{
this.setDefaultThemePack();
// Initialize the single window container if we're in this case. This
// should be done before initializing the main window, because he'll
// search for it.
if (ConfigurationUtils.isSingleWindowInterfaceEnabled())
singleWindowContainer = new SingleWindowContainer();
// Initialize the main window.
this.mainFrame = new MainFrame();
if (UIManager.getLookAndFeel() instanceof SIPCommLookAndFeel)
initCustomFonts();
/*
* The mainFrame isn't fully ready without the MetaContactListService so
* make sure it's set before allowing anything, such as LoginManager, to
* use the mainFrame. Otherwise, LoginManager, for example, will call
* back from its event listener(s) into the mainFrame and cause a
* NullPointerException.
*/
mainFrame.setContactList(GuiActivator.getContactListService());
// Initialize main window bounds.
this.mainFrame.initBounds();
// Register the main window as an exported window, so that other bundles
// could access it through the UIService.
GuiActivator.getUIService().registerExportedWindow(mainFrame);
// Initialize the login manager.
this.loginManager = new LoginManager(new LoginRendererSwingImpl());
this.popupDialog = new PopupDialogImpl();
this.wizardContainer = new AccountRegWizardContainerImpl(mainFrame);
if (ConfigurationUtils.isTransparentWindowEnabled())
{
try
{
WindowUtils.setWindowTransparent(mainFrame, true);
}
catch (UnsupportedOperationException ex)
{
logger.error(ex.getMessage(), ex);
ConfigurationUtils.setTransparentWindowEnabled(false);
}
}
if(ConfigurationUtils.isApplicationVisible()
|| Boolean.getBoolean("disable-tray")
|| ConfigurationUtils.isMinimizeInsteadOfHide())
{
mainFrame.setFrameVisible(true);
}
SwingUtilities.invokeLater(new RunLoginGui());
this.initExportedWindows();
KeyboardFocusManager focusManager
= KeyboardFocusManager.getCurrentKeyboardFocusManager();
focusManager.addKeyEventDispatcher(
new KeyBindingsDispatching(focusManager));
maybeShowMasterPasswordMissingWarningDialog();
}
/**
* Indicates that a <tt>PropertyChangeEvent</tt> has occurred.
*
* @param evt the <tt>PropertyChangeEvent</tt> that notified us
*/
public void propertyChange(PropertyChangeEvent evt)
{
String propertyName = evt.getPropertyName();
if (propertyName.equals(
"impl.gui.IS_TRANSPARENT_WINDOW_ENABLED"))
{
String isTransparentString = (String) evt.getNewValue();
boolean isTransparentWindowEnabled
= Boolean.parseBoolean(isTransparentString);
try
{
WindowUtils.setWindowTransparent( mainFrame,
isTransparentWindowEnabled);
}
catch (UnsupportedOperationException ex)
{
logger.error(ex.getMessage(), ex);
if (isTransparentWindowEnabled)
{
ResourceManagementService resources
= GuiActivator.getResources();
new ErrorDialog(
mainFrame,
resources.getI18NString("service.gui.ERROR"),
resources.getI18NString(
"service.gui.TRANSPARENCY_NOT_ENABLED"))
.showDialog();
}
ConfigurationUtils.setTransparentWindowEnabled(false);
}
}
else if (propertyName.equals(
"impl.gui.WINDOW_TRANSPARENCY"))
{
mainFrame.repaint();
}
}