How to Support JFrame transparency on Linux - swing

I'm making a java swing application which is executed on linux machine and shown in users' computer by X11 forwarding.
I want to apply rounded corners on JFrame, so I changed its background to new Color(0,0,0,0).
The frame is now hidden on my computer(windows 10). But the linux(centOS7) doesn't seem not to support Window Frame transparency.
It returns error below.
Exception in thread "AWT-EventQueue-0"
java.lang.UnsupportedOperationException: PERPIXEL_TRANSLUCENT translucency is not supported
at java.awt.Window.setBackground(Window.java:3844)
at java.awt.Frame.setBackground(Frame.java:988)
Without changing its background works fine on both but the default background is also shown.
Is there any way to make rounded corners??
Thank you.

Not every platfrom supports transparency.
Take a look at https://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html
chapter
Determining a Platform's Capabilities
import static java.awt.GraphicsDevice.WindowTranslucency.*;
// Determine what the default GraphicsDevice can support.
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
boolean isUniformTranslucencySupported =
gd.isWindowTranslucencySupported(TRANSLUCENT);
boolean isPerPixelTranslucencySupported =
gd.isWindowTranslucencySupported(PERPIXEL_TRANSLUCENT);
boolean isShapedWindowSupported =
gd.isWindowTranslucencySupported(PERPIXEL_TRANSPARENT);
To be tested, but I don't thing that X11 forwarding allows transparency !
EDIT
Just made a test, through ssh -X, java version 1.8.0_162-b12
and it works.
What is your java version ?

Related

How to activate IWiFiDirectDevice in Win32 Console APP using WRL?

I want to use WinRT API for WiFi Direct from Windows 10 SDK in Win32 Console Application. I know about C++/CX (and even made some progress going that way), but still want to make it work without this extension.
My problem is that I can't activate IWifiDirectDevice interface (from ABI::Windows::Devices::WiFiDirect) to access IWifiDirectDeviceStatics that provides an GetDeviceSelector method.
HStringReference strDevice(RuntimeClass_Windows_Devices_WiFiDirect_WiFiDirectDevice);
ComPtr<IInspectable> insp;
hr = RoActivateInstance(strDevice.Get(), insp.GetAddressOf());
This code ends up with E_NOTIMPL as a result. In Microsoft's example they used factories for activation, but ABI::Windows::Devices::WiFiDirect namespace has no factories.
Worth mentioning that IWifiDirectAdvertisementPublisher works just fine when activated the way I wrote before.
So how to activate IWifiDirectDevice from WRL?
Windows.Devices.WiFiDirect.WiFiDirectDevice is not an activatable class. You can see that by looking at windows.devices.wifidirect.idl.
You will need to use the static methods, e.g.:
HStringReference strDevice(RuntimeClass_Windows_Devices_WiFiDirect_WiFiDirectDevice);
ComPtr<IWiFiDirectDeviceStatics> wiFiDirectDeviceStatics;
hr = Windows::Foundation::GetActivationFactory(
strDevice.Get(),
&wiFiDirectDeviceStatics);
ComPtr<IWiFiDirectDevice> wiFiDirectDevice;
ComPtr<IAsyncOperation<WiFiDirectDevice*>> asyncOperation;
hr = wiFiDirectDeviceStatics->FromIdAsync(deviceId.Get(), &asyncOperation);
Consider taking a look at the Wi-Fi Direct sample.

Flash ActionScript - Trace from background Worker

Is it possible at all, or traces are part of the API which is not avalible from background Worker?
Consider this code:
public class Main extends Sprite {
public function Main(container : DisplayObjectContainer = null)
{
if(Worker.current.isPrimordial) {
trace("isPrimordial");
var m_worker : Worker = WorkerDomain.current.createWorker(this.loaderInfo.bytes);
m_worker.start();
}
else {
trace("is NOT Primordial");
}
}
The string "is NOT Primordial" does not appear, however I do see that m_worker.state is "WorkerState.RUNNING".
Some UPDATE: The main thread works and racts to events, however it appears like the backgroung worker does not start until I desconnect the debugger.
And if it is possible, how do I setup the fdb to show these logs?
PS. Im using flash standalone debug player 13 with latest FDT and Apache Flex 4.12.1 SDK.
Ok, so the results for now are:
The background thread (Worker) can write traces with no problems at all if the debugger is not attached, for example if we are using flashlog.txt for the output (output to file).
What is required is: flash debug player (me used v. 14 stand alone and firefox versions).
The setup for using text file as output discussed here:
http://helpx.adobe.com/flash-player/kb/configure-debugger-version-flash-player.html
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fc9.html
Correct location of mm.cfg on modern operating systems (and not on Win95!) discussed here:
https://forums.adobe.com/thread/1218258
For me the output to file started to work only after the flashlog.txt file was created by some 3rd party tool (I used Vizzy), but probably it is a permission problem of flasho n windows 8 and the file just can be created manually.
Detailed discussion of the flash traces topic (althoug a little old, but mostly still relevant) is here:
See trace() of Flash when running in browser
Thanks everyone for help.
Create a static Log class that output it's log to trace. Use this log class in your main thread and in your worker. Only the main thread log definition will be used allowing to trace from anywhere.

starling atf textures not displaying

So i'm running air 3.7, the latest starling frameworks, added -swf-version=20 -target-player=11.7 in compiler arguments and running the code
[Embed(source="/assets/wtf4.atf", mimeType="application/octet-stream")]
private static const why:Class;
var data:ByteArray = new why();
var texture:starling.textures.Texture = starling.textures.Texture.fromAtfData(data);
var image:Image = new Image(texture);
addChild(image);
if I'm using the starling atf that came with the framework demo it works fine, but whenever i try to display my own png that I create in photoshop converted into atf it gives me a error saying
ArgumentError: Error #3677: Texture decoding failed. Internal error.
The image I'm trying to convert into atf is just a red square png with 512x512 sizes with the compiler arguments: png2atf -c -i example.png -o example.atf. I'm not sure whether my flash builder isn't setup to decode atfs or if i'm creating the atfs wrong for some reason, if someone could shed some light on this it would be awesome!
When creating the .atf, did you created mipmaps also? If not, you need to set the second argument of the Texture.fromAtfData() function to false - don't use Mipmaps.
From Starlign wiki:
"If you omit mipmaps, you must set the parameter “useMipMaps” of the “Texture.fromAtfData()” method to “false”! Otherwise, you'll get a run-time error."
http://wiki.starling-framework.org/manual/atf_textures
The latest version of ATF requires AIR 3.8 (which is currently in beta). You need to download the AIR installer, and the latest AIR SDK. More details here: http://forum.starling-framework.org/topic/error-3677-texture-decoding-failed-internal-error

Disable Windows 8 edge gestures/hot corners for multi-touch applications while running in full screen

I have a full screen AS3 game maby with Adobe AIR that runs in Windows 7.
In this game it may not be easy to exit (think about kiosk mode, only exit by pressing esc and enter a password).
Now I want this game to run in Windows 8. The game is working like expected but the anoying things are these edge gestures/hot corners (left, top, right, bottom) and the shortcuts.
I've read articles but none helped me. People talk about registery edits, but I dont get this working + the user needs to restart his/hers computer.
I want to open my game, turn off gestures/hot corners and when the game closes the gestures/hot corners need to come back available again.
I have seen some applications doing the same what I want to accomplish.
I found this so I am able to detect the gestures. But how to ignore they're actions?
I also read ASUS Smart Gestures but this is for the touch-pad.
And I have tried Classic Shell but I need to disable the edge gestures/hot corners without such programs, just on-the-fly.
I also found this but I don't know how to implement this.
HRESULT SetTouchDisableProperty(HWND hwnd, BOOL fDisableTouch)
{
IPropertyStore* pPropStore;
HRESULT hrReturnValue = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pPropStore));
if (SUCCEEDED(hrReturnValue))
{
PROPVARIANT var;
var.vt = VT_BOOL;
var.boolVal = fDisableTouch ? VARIANT_TRUE : VARIANT_FALSE;
hrReturnValue = pPropStore->SetValue(PKEY_EdgeGesture_DisableTouchWhenFullscreen, var);
pPropStore->Release();
}
return hrReturnValue;
}
Does anyone know how I can do this? Or point me into the right direction?
I have tried some in C# and C++, but I aint a skilled C#/C++ developer. Also the game is made in AS3 so it will be hard to implement this in C#/C++.
I work on the Lenovo aio (All in one) with Windows 8.
I am making a kiosk application for windows 8 using C#,
I succesfully disabled the swipe gestures by killing the explorer process
when the program starts up. I don't know how it's done in C++
but in C# it's like this.
var explorers = Process.GetProcessesByName("explorer");
foreach (var explorer in explorers) {
explorer.Kill();
}
On the closing event of my program I just start the process again.
Process.Start("explorer.exe");
Before this works you might have to edit your register to prevent explorer
from restarting after you kill it.
In regedit go to
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Set the AutoRestartShell to 0.
(as long as your running off AIR - which it sounds like) You can use AIR 2.0's NativeProcess to execute it.
From there I can think of two solutions:
If there are command line options in Classic Shell, call it from within your AS3 and toggle the gestures on/off through it.
Write a C++ application that toggles the gestures on/off manually.
If you can get that example working in C++, add a bit to the C++ to handle a on/off command line argument and call the C++ exe on initialization and exit of your AS3 application to toggle.
I don't have C++ installed here (at work), but it looks like that C++ function just requires the window handle of your application (hWnd). This tutorial should get you compiled and running, but the window handle you see there will be for the C++ application's window.
Accessing the flash window's handle will be slightly more difficult:
for a direct solution; you'll need to use .NET - Process.MainWindowHandle,
or alternatively without .NET -
How to get main window handle from process id?
Either way you'll need to use the Process name or ID to identify it as your AS3 process.
This solution also depends on your ability to install things other than the AIR app on the client PC. (ie .NET runtimes, C++ runtimes, Classic Shell installer)
I'm trying to do the same thing. The C++ below disables Win8 Gestures on every running application/window. As JonoRR mentioned, the next step would be calling it only on the HWND you would like to target. If the targeted application is closed, then re-opened, the gestures will return.
#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <propsys.h>
#include <propkey.h>
using namespace std;
HWND windowHandle;
HRESULT SetTouchDisableProperty(HWND hwnd, BOOL fDisableTouch)
{
IPropertyStore* pPropStore;
HRESULT hrReturnValue = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pPropStore));
if (SUCCEEDED(hrReturnValue))
{
PROPVARIANT var;
var.vt = VT_BOOL;
var.boolVal = fDisableTouch ? VARIANT_TRUE : VARIANT_FALSE;
hrReturnValue = pPropStore->SetValue(PKEY_EdgeGesture_DisableTouchWhenFullscreen, var);
pPropStore->Release();
}
return hrReturnValue;
}
BOOL CALLBACK MyEnumProc(HWND hWnd, LPARAM lParam)
{
TCHAR title[500];
ZeroMemory(title, sizeof(title));
GetWindowText(hWnd, title, sizeof(title)/sizeof(title[0]));
SetTouchDisableProperty(hWnd,true);
_tprintf(_T("Value is %s\n"), title);
return TRUE;
}
int _tmain(int argc, _TCHAR* argv[])
{
EnumWindows(MyEnumProc, 0);
return 0;
}
The answer below is based on Dovogja's brilliant answer, but it uses a batch file to do it. This way you just have to launch with a launch.bat
Windows charms bar is operated by explorer.exe. So if your app can run without it then you can hack around it by first disabling the autorestart of explorer.exe via (run as administrator):
reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "AutoRestartShell" /t REG_DWORD /d 0
Then the lines below represent my launch.bat - which works in the end as expected:
;; kill explorer (this disables all windows functionalities
taskkill /f /im explorer.exe
;; start your kiosk app - should block the batch execution (so explorer.exe doesn't get executed at the end)
"\path\to\your\app.exe"
;; after you close both the app window and the opened chrome window relaunch explorer.exe to give back the functionality to windows
explorer.exe
I use the approach outlined above to let a keyboardless kiosk app run. Because with a keyboard you can still close the app with alt+f4.

BlackBerry - Exception when creating a graphics object from a bitmap

I am making the following call in my blackberry application (API ver 4.5)...
public void annotate(String msg, EncodedImage ei)
{
Bitmap bitmap = ei.getBitmap();
Graphics g = new Graphics(bitmap);
g.drawText(msg,0,0);
}
And I keep getting an IllegalArgumentException when I instantiate the Graphics object. Looking at the documentation for Graphics is confusing as it leaves many things unstated.
What does it mean by 'default type of the device'?
How do you know if the type of 'bitmap' is not supported? Does this mean that there are different types of bitmaps? Can different encodedImages generate different types of bitmaps?
Is there another way to add my string to the associated encoded image?
public Graphics(Bitmap bitmap)
Constructs a Graphics object for drawing to a bitmap.
Parameters:
bitmap - Bitmap to draw into. Must be Bitmap.COLUMNWISE_MONOCHROME or the default type of the device.
Throws:
IllegalArgumentException - If the type of 'bitmap' is not supported, or the bitmap is readonly.
Are you sure that your Bitmap is mutable? You can't create Graphics objects from immutable Bitmaps. That is one cause of an IllegalArgumentException. You can set the decode mode for your EncodedImage (EncodeImage.setDecodeMode). There are different modes that allow you to specify whether the file is native or readonly...along with other modes that can be combined.
The size of the bitmap might be another IllegalArgumentException. Of course, this is relevant to the target device.
I'd imagine that the default type depends on the graphics chip and hardware. (If you have a monochrome screen, the default would probably be different than if you had a color one.)
Bitmap has a static method getDefaultType(), which "Queries the default Bitmap type for the device". There's also a non-static method getType(). It seems to be telling you the rule is that for the code above to work then either:
bitmap.getType() == Bitmap.getDefaultType()
...or...
bitmap.getType() == COLUMNWISE_MONOCHROME
And presumably neither of these conditions are true. You can do a sanity check on that, and maybe print out the result of getDefaultType() so you know what your target is.
Looks like you'll have to convert the bitmap or get it from somewhere else.
The Graphics object isn't normally constructed explicitly. Rather, you are given an instance of it in the paint() method, if you've overridden it.
I suspect what you want to do is create a subclass of BitmapField and override the paint() method to include your code for drawing text on the bitmap.