JavaFx FileChooser user defined filename - javafx

I'm trying to use FileChooser, but I'm stuck with a trivial problem: after opening a FileChoser window, I can't seem to change the initial filename. This seems like a textbook task, but it got me.
Here is the code, which I'm trying to use:
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Save Image");
fileChooser.setInitialFileName("capture");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("JPG", "*.jpg")
);
File file = fileChooser.showSaveDialog(this.primaryStage);

Okay, I've found the culprit. The problem was with that I was using system-hook (https://github.com/kristian/system-hook), and this if the hook is initialized with raw=true value, the UI elements keyboard listeners stops working properly, reasons unknown. Using raw=false fixes this.

Related

How to export a gwt-openlayers map as an image

We have gwt webapplication, showing map, implemented with gwt-openlayers.
I would like to implement a function to export the current map as an image (for example png).
I'm aware of this example from openlayers, but I struggle getting it done with gwt.
https://openlayers.org/en/latest/examples/export-map.html
Help would be appreciated
After more trial & error I found this solution which partly solves my problem:
https://stackoverflow.com/a/25486443/6919820
However, after closing the print dialog, the printed layout remains as some kind of overlay on my previous window. So my approach was to create a new map and copy all relevant data from the original one. Then print the new map and destroy it afterwards.
buttonPrint.addClickHandler(event -> {
// mapPrintLayout contains my new MapWidget
print(mapPrintLayout.getElement().getInnerHTML());
mapPrintLayout.destroy();
});
public static final native void print(String html) /*-{
top.consoleRef=$wnd.open('','_blank', "", false);
top.consoleRef.document.write(html);
top.consoleRef.print();
top.consoleRef.close();
}-*/;
It works, but I'm not convinced by my approach. Maybe there are better ways to do it.

JavaFX 3D - Scene Camera Issues, SubScene Errors, and MeshViews not Visible

I will try to be as brief as possible while providing enough info so that someone might be able to help point me in the right direction. I am trying to add a 3D scene to the center or a borderpane that will contain a set of meshviews that I read from an obj file using an obj loader that has been well tested by others (so I'm confident it works). I will give my summary step by step and provide an image to show my progress and issues.
I start with my borderpane empty:
Next, I started by taking an example from a book that add me create three primitives and add them to a scene and changed it so that this is added to the center part of my borderpane. I created a method that is tied to the File/Open action that when I click File/Open, it calls that method and creates the primitives and adds them to the center of the borderpane:
Next, I tried to add a camera to the main scene that is created as part of the initial Application start method using the following lines:
(line 29 to 33 were commented out in earlier pictures)
However, this leads to the following issue where the borderpane is projected into the third dimension:
I then tried using a SubScene in the center of the borderpane but kept getting a lot of errors of the type nullpointerexception and the info was too vague for me to use to figure out what it was not happy about.
The other and more important issue that I am dealing with while trying to figure this out, is the final version meant to read a group of meshviews from an obj file and add them to the center does not work. The code reads the obj file and imports the meshviews from it. I have printed out to the console number of meshviews read and it matches what was in the test file, so I feel confident I'm using it correctly and this loader has been used a lot by others so has been tested. But when I try to change out and use that to add meshviews to the center I just get a blank center screen and a console printout showing it read the file and that it read the correct number of meshviews. I have not been able to find a good way to debug/figure this out. so could use some advice on that as well.
Thanks for any help you can provide.
instead of
Scene scene = new Scene(borderPane,sceneWidth,sceneHeight);
add this
Scene scene = new Scene(borderPane,sceneWidth,sceneHeight,true, SceneAntialiasing.BALANCED);
the last two parameters are = depthBuffer and antialiasing

QT: Getting text content from web page

I've been trying to start with a simple app that retrieves data from a simple HTML page upon clicking a button and stumbled upon a rather helpful tutorial on QT-Project and have been trying to implement it for my own project.
Everything manages to compile until I try to actually try to implement the loadImage function (as found in the tutorial). (I actually had to initialize m_pImgCtrl as Filedownloader * m_pImgCtrl = new FileDownloader(imageUrl, this); and I'm not exactly sure how it's suppose to work without prior object declaration?)
From what I get, m_pImgCtrl isn't actually defined in the loadImage() function since it is initialized outside of the function? Or does the connect() function do something that I'm not too aware of?
Thanks for the help!
The tutorial doesn't tell you the whole story.
The code in section Usage is supposed to be part of a class MainWindow – the controller of your main window (see line 1 of tutorial's last snippet). This class contains a slot loadImaged() called when the NetworkReply has finished. It also has a member FileDownloader * m_pImgCtrl.
For instance, the second Usage snippet could be part of a slot MainWindow::buttonClicked() like
void MainWindow::buttonClicked()
{
QUrl imageUrl("http://qt.digia.com/Documents/1/QtLogo.png");
m_pImgCtrl = new FileDownloader(imageUrl, this);
connect(m_pImgCtrl, SIGNAL(downloaded()), SLOT(loadImage()));
}

QObject::findChild returns null, can't find cross QML objects

I have a question about accessing QML components on the C++ side, sorry it might be little beginner.
I am currently working with the sample map view, the app alone works great, but after I try to put this sample together with a navigation panel, it stopped working.
I have added my own main.qml, another page called menu.qml, and renamed the app's original main.qml to map.qml. So now user would require to navigate the panel like this: main.qml -> menu.qml -> map.qml
My problem is:
Originally, from the sample, app constructor saves a mapView pointer when it creates main.qml so later it can add markers/change location to the mapview.
It gets mapView pointer by calling:
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("_mapViewTest", this);
AbstractPane *root = qml->createRootObject<AbstractPane>();
QObject* mapViewAsQObject = root->findChild<QObject*>(QString("mapViewObj"));
mapView = qobject_cast<bb::cascades::maps::MapView*>(mapViewAsQObject);
However, I have changed the name to map.qml, findChild returned as null. Since my app is unable to find mapView, the whole app crushes when I try to set a marker/locate myself.
I tried to QmlDocument::create("asset:///map.qml"), and use the same method as above to find the mapview, and I was able to get it, but nothing happens when I try to put down a marker/locate.
I have also tried to add a new function that calls findChild and get the mapView pointer. The function gets called in onCreationCompleted inside the map.qml page, but mapViewAsQObject still returned null and app crushed.
Any hints would be really appreciated! Thanks
I have found the solution to my problem, when the next button is clicked, I have to nav push the page using C++, this way it can find the right mapView pointer.
QmlDocument *qml = QmlDocument::create("asset:///map.qml").parent(this);
qml->setContextProperty("_mapViewTest", this);
Page *root = qml->createRootObject<Page>();
QObject* mapViewAsQObject = root->findChild<QObject*>(QString("mapViewObj"));
... etc
nav->push(root);

How to transfer the NativeApplication instance to another NativeWindow

Not sure if my title accurately describes what I'm trying to do, but basically I've created a new NativeWindow as follows (using an example from the Adobe NativeWindow documentation http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/NativeWindow.html?filter_flex=4.1&filter_flashplayer=10.1&filter_air=2#minSize):
var windowOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
windowOptions.systemChrome = NativeWindowSystemChrome.STANDARD;
windowOptions.type = NativeWindowType.NORMAL;
var newWindow:NativeWindow = new NativeWindow(windowOptions);
newWindow.stage.scaleMode = StageScaleMode.NO_SCALE;
newWindow.stage.align = StageAlign.TOP_LEFT;
newWindow.bounds = new Rectangle(100, 100, 800, 800);
newWindow.activate();
However, now that I have my new window, I want to close the old window and make the new window the active NativeApplication, basically transferring all control over to the new one. Any idea how to do this? All help greatly appreciated.
Edit:
For anyone who is interested, and thanks to the answers provided, here's what I now do. Just create an mxml file using
<?xml version="1.0" encoding="utf-8"?>
<mx:Window
xmlns:mx="http://www.adobe.com/2006/mxml"
...
>
Call this MyWindow.mxml or whatever, and then in the main controller create an instance of this using
private var myWindow:MyWindow = new MyWindow.
You can then set the height width minimizable and maximisable attributes accordingly, like myWindow.width = 400. To open the window you can then do either window.open(true) or window.visible = false; window.open(true) - the latter making the window invisible but available for use.
Jeff's pretty much got the answer in his comment, but he's got way more karma than me so I'll comment as an answer ;)
If you look at your AIR -app.xml file, it has elements for whether the application is initially visible, etc.
What you want to do, is make it initially invisible. In fact you don't really want it to have any visible presence at all. What it will do though is spawn a Native Window the way you want it, and if you need to change the properties, tear that one down and replace it with a new one.
I looks pretty simple on the face of it, but I'm positive there will be some additional complications. Each NativeWindow has its own stage (IIRC) so you might not have the resourceManager moved across correctly for example. I've never gone further than a quick demo with this, so you might run into a limitation that's insurmountable (as Jeff's intuition is telling him)

Resources