I am running in the following:
I have an eclipse plugin(Luna/JVM 1.8) that presents some information to the user in a CTabItem. In this CTabItem, I have a class that updates a TextViewer's widget contents using asyncExec(....).
A brute force approach of getTextWidget().append(String) process the String[] inside the UI/asyncExec();
This logic has worked reliably in OS X (El Capitan). I am using linux (openSuse Leap) now and the updates rarely show up in the TextViewer. I have checked and the runnable inside the asyncExec(...) gets called.
The rest of the UI elements work normally in both OSs.
What do I need to change or am I missing? This seems more due to my lack of understanding of cross-platform SWT than anything else.
Thanks a lot!
I made 2 simple changes:
Instead of calling getTextWidget().append(String) I am using a StringBuilder and making just one call to getTextWidget().append(String).
After this I call refresh().
These two did the trick.
Related
Context
I'm writing a fabric mod that needs to replace blocks in the world.
Code
Currently Im using World#setBlockState(pos, state)
BlockPos pos = new BlockPos(x, y, z);
BlockState state = Blocks.STONE.getDefaultState();
world.setBlockState(pos, state);
Problem
This seems to work, but if I right-click the replaced blocks, they turn back into the block they were before
I also tried this Block.replace(world.getBlockState(pos), state, world, pos), but this reproduces the same.
For now, the mod is only supposed to be used on client-side with minecraft-1.17.1.
Question
Is this because the client cannot modify the world in that way?
If not, what could be the issue and how can I fix it?
Such as you mentionned, it's on the client-side. So, you can change everything, it will only be visual.
It replaced the block when right-click because the server send the real block present on the world (instead of visual one).
If you want to do something like that, it can be difficult. All client that are manually placing block on server are cheat, because they are making something that is not allowed in basic minecraft.
But, maybe there is possibilities :
Use event to change the block that will be placed, and instead of placing the default one and change it after, you can directly change it on the server.
Run a command to change the block such as /setblock (wiki)
I have a Java application that I want to automate for testing. Unfortunately, the app window only registers as a SunAWTFrame, which means none of the controls are exposed to typical window analysis and automation tools.
My search has lead me to C# and utilising Java Access Bridge DLLS in a C# program to automate it.
Has anyone had any experience of this?
Oracle provides JavaAccessBridge (JAB) with some DLLS to help with this as I understand it after reading a few articles around the internet. There are some code examples but I'm really not groking it right now. By breaking it down, I think this is what needs to be achieved:
Import / load / parse the JAB dlls
Map functions in the JAB dll to methods / calls within my program
Have the Java application to automate run (with JAB enabled) and get handle of it to my program
Utilise the JAB functions to control the Java application
I don't know C# as well as I know Java, but that's not going to stop me.
If anyone can provide help, guidance, pointers or anything to get me started, that'd be truly awesome.
As of 2019 we have a great tool AccessBridgeExplorer created and open-sourced by google. It's a really good staring point that contains a WindowsAccessBridgeInterop project which encapsulates almost every JAB API into a class oriented, .NET friendly assembly.
One notable thing, AccessBridge.Initialize() must be called in WPF/WinForm UI thread or in your own messaging pump thread, otherwise some methods like AccessBridge.EnumJvms() will always return false/empty.
Building on Stackia's great tip to use Google's AccessBridgeExplorer, Here are some tips to get you going:
Download Access Bridge Explorer
Use the WindowsAccessBridgeInterop.dll in your own (WinForms not Console) project (Add> Project Reference> Select the DLL)
Create a new access bridge object
AccessBridge Java = new AccessBridge();
Initialize the Access Bridge object
Java.Initialize();
Call Application.DoEvents() - A hack to wait for Java.Initialize to complete (My simple understanding is Java Access Bridge Uses a hidden window or similar)
Application.DoEvents(); //this waits for Java Bridge to initilize ;)
Get the handle of the Java Window
(plenty of examples online of how to get a Window Handle in C#)
Get Access to the Java Object that represents the window:
Java.Functions.GetAccessibleContextFromHWND(Handle, out int vmid, out JavaObjectHandle javaObjectHandle);
Get AccessibleWindow Object for Window (so you can find its children)
AccessibleWindow win = Java.CreateAccessibleWindow(handle);
Come up with your own way to cycle through the children, and the childrens children until you find the object you are after:
//Similar to:
foreach(var child in win.GetChildren())
JavaObjectHandle? javaObject = Java.Functions.GetAccessibleChildFromContext(node.JvmId, parentJavaObject, child.GetIndexInParent());
//to get the label or title of the object:
child.GetTitle();
To Interact with an object (eg click a button), do similar to the following:
(please note where it says JavaObject - it means the child java object (eg. to click a button you need to get the JavaObject for that button using GetAccessibleChildFromContext as i mentioned above)
//Get Possible Actions
JavaAutomation.Java.Functions.GetAccessibleActions(VMID, JavaObject, out AccessibleActions accessibleActions);
foreach( var action in accessibleActions.actionInfo)
{
Log.Info($"DoAction: {action.name}");
}
AccessibleActionsToDo accessibleActionsToDo = new AccessibleActionsToDo();
accessibleActionsToDo.actions = accessibleActions.actionInfo;
accessibleActionsToDo.actionsCount = accessibleActions.actionsCount;
//Do Actions
JavaAutomation.Java.Functions.DoAccessibleActions(VMID, JavaObject, ref accessibleActionsToDo, out int failure);
So I asked this question concerning how to combine 3 different applications into 1 Combining Processing Applications into 1 Big Executable?
From lurking I have learned the following methods I could go about to do this:
use Java and embed my sketches in a Swing interface (rewrite
programs into some complicated Java monstrosity)
Rewitre code to launch separate windows using G4P
http://www.lagers.org.uk/g4p/ex-windows/index.html (seems better
than option 1 but still a pain in the ass because trying to write
functions to get the LEAP motion api calls to work in the separate
windows wont be easy)
Use Open() at the end of each program to run
the next program (quick and dirty, just the way I like it!)
Combine all 3 into a batch file. (I dont really understand how to go about doing this but seems similar to previous option).
Now theoretically I could get more functionality from 1 and 2 (in terms of program flow and better user interface) and would probably learn more and be better off in my future efforts, however time is of the essence at the moment. Each of the programs creates csv data files from user input that I will use to create a visualization so the manner in which I get the programs to run is somewhat irrelevant at this point. Only problem is I cant get open() to work correctly. See below:
void setup() {
size(200, 200);
}
void draw() {
// draw() must be present for mousePressed() to work
}
void mousePressed() {
open("C:/Users/corbett2/Documents/Processing/test/application.windows64/test.bat"); //doesn't work
open(new String[] { "cmd", "/c", "start", "/w", "C:/Users/corbett2/Documents/Processing/test/application.windows64/test.bat"}); //also doesn't work
}
I've tried a bunch of different ways to use open() but it wont run the program. I'm using windows 8. I exported the application "test" which created the "test.bat" located in C:/Users/corbett2/Documents/Processing/test/application.windows64. I believe you have to export your sketch before you can try to use open() on it right? As said before, the idea here is to use a call to open() at the close of each of my 3 applications in order to run them.
So my specific questions are as follows:
Which of the 4 methods I listed would you recommend I pursue for my issue? If none, please feel free to suggest something else.
Will option 3 using open() work? Why or why not?
Correct my open() issue.
Thanks in advance!
When I export application it creates test.exe for windows32 bit architecture (but running on 64bit OS) and then using your second case of open() works fine for me:
void mousePressed() {
//open second window with test app running
open("C:/Users/corbett2/Documents/Processing/test/application.windows32/test.exe");
//this will close first window
exit();
}
[but this didn't work with export to 64bit architecture (for me) so your problem should be with some settings of platform's launcher]
Anyway this approach works fine just you also need to close first window so user will not be confused.
I have to take one input from console in first java program. That input i have to pass in second java program which is getting executed as thread from the main method of first java program.
I made the variable as static and tried accessing in second java program but it is showing null value(default value).
I am not supposed to make the object of first program also.
Please suggest me how to do?
If your first java program is starting the second using O.S.-like functions that produces the same effect as if you were starting from the console, then you will have a second instance of the JVM, with everything "reseted". That's why you're getting that null.
A suggestion would be passing the value as a parameter for the second program.
As far as I know there's no shared memory mechanism implemented in Java. Pipes also don't work across VM boundaries, so you would have to use the JNI and C code to create a mechanism.
But then if the two programs cooperate that close together, why not let them in one VM and use threads? Security reasons is the only thing I could think of.
Apple seems to have quart rendering on by default:
http://lists.apple.com/archives/Java-dev/2007/Jun/msg00066.html
However there are cases where this is attrociously slow. From a desktop app, I merely add:
-Dapple.awt.graphics.UseQuartz=false
This fixes the slow rendering. But there's isn't a place in the Java preferences panel to set this, and all of my attempts to set it in ~/Library/Caches/Java/deployment.properties have failed so far.
Is there a workaround?
Also, will it be possible to generate an applet that sets this for the user in some way?
I believe what you are trying to do can be solved with this:
System.setProperty("apple.awt.graphics.UseQuartz","false");
Whenever you use the setProperty method, make sure to use it at the beginning of your main method so it gets set as soon as possible or else it may not take effect.
What I don't understand is why it was set to true in Java 1.5 and false in 1.6.