JavaFX - Extends Stage, but inherited method is undefined - javafx

I'm working with JavaFX using Java 8 and I have a class where Stage is extended. I got this code from another student and it works fine for everyone else, but for me I get an error on setAlwaysOnTop. It says the method is undefined, but it is inherited from Stage. It seems to be only that method which is giving this error.
It would be easier with an image, but I can't post images yet so I had to just copy-paste the relevant code:
public class NotificationWindow extends Stage {
public void showNotification(){
Rectangle2D screenBounds=Screen.getPrimary().getVisualBounds();
this.setAlwaysOnTop(true); //Error here
this.setX(screenBounds.getMaxX()-scene.getWidth());
this.setY(screenBounds.getMaxY()-scene.getHeight());
this.show();
}
}

The alwaysOnTop property was introduced in JavaFX 8 update 20. So you are probably using an earlier version. Update to the latest JavaFX version and it should recognize the method.

Related

Fix Androud glide issue, GlideApp errors in android studio

I have a java class in my app PostViewHolder and I am trying to load an image using Glide but I get error, I am not the original developer of the code, it appears it was developed 3 years ago and so i don't know how best to explain.
I have this code line in my PostViewHolder
Imageutil.loadImageCenterCrop(GlideApp.with(baseActivity), imageUrl, postImageView, width, height);
For this line, GlideApp.with(baseActivity) is underlined red with error saying Required type: GlideRequests, provided:.........
I tried to change it to Glide.with and it shows cannot resolve symbol 'Glide'
On my project Glide is extending a class to load image with GlideApp
#GlideModule
public class MyAppGlideModule extends AppGlideModule {
#Override
public void registerComponents(Context context, Glide glide, Registry registry)
{ registry.prepend(String.class ByteBuffer.class, new Base64ModelLoadeeFactory();}
}
I will appreciate any help to get rid of the error Required type:GlideRequests
How to make this code work Imageutil.loadImageCenterCrop(GlideApp.with(baseActivity), imageUrl, postImageView, width, height);
Short and simple way would be Glide.with(context).load(imgUrl).into(imgView)

How to create new skin for `DatePicker`, javafx

I want to create a new skin class for DatePicker. Following different instructions about how to do it, e.g guigarage the right way is to extend SkinBase and load new skin class by setting -fx-skin property to the skin class name, so i did, but I got this Error:
Exception in thread "JavaFX Application Thread" java.lang.ClassCastException: sample.myDatePickerSkin cannot be cast to com.sun.javafx.scene.control.skin.DatePickerSkin
at com.sun.javafx.scene.control.behavior.DatePickerBehavior.onAutoHide(DatePickerBehavior.java:103)
and if you look at DatePickerBehavior.java:103:
#Override public void onAutoHide() {
// when we click on some non-interactive part of the
// calendar - we do not want to hide.
DatePicker datePicker = (DatePicker)getControl();
DatePickerSkin cpSkin = (DatePickerSkin)datePicker.getSkin();
cpSkin.syncWithAutoUpdate();
// if the DatePicker is no longer showing, then invoke the super method
// to keep its show/hide state in sync.
if (!datePicker.isShowing()) super.onAutoHide();
}
So did I do anything wrong? or I should also write myDatePickerBehavior?
The official way to implement a Skin is to either
extend javafx.scene.control.SkinBase (since JavaFX 8.0)
or
implement Skin directly.
com.sun.javafx.scene‌​.control.skin.BaseSki‌​n is not a published API.
Please note that with Java SE 9 and Jigsaw, DatePickerSkin as well as the other default skins will become published APIs, AFAIK. Then it should be safe to extend them if it meets your requirements.
I should extend DatePickerSkin :
package sample;
import com.sun.javafx.scene.control.skin.DatePickerSkin;
import javafx.scene.control.DatePicker;
public class customDatePickerSkin extends DatePickerSkin {
public customDatePickerSkin(DatePicker datePicker) {
super(datePicker);
}
}

Manually Open custom inspector for serializable object

I have a window editor that holds nodes. I would like to open a custom inspector when one of these nodes is selected. The node class is a custom serializable class. Is this possible?.
It seems that custom inspectors can be created manually through the Editor.CreateEditor method but can't see how to let it appear docked like an usual inspector in the unity inspector window.
I would like to achieve the same behaviour that we have when we select a gameobject in sceneview that inmediately show properties for the object (Components, etc...) in the unity inspector.
Cheers
As I'm not sure what you're asking, here are multiple different solutions;
Selection
If you just want your nodes to become the focus of the hierarchy, then in your custom window's OnGUI method, use the code below;
[CustomEditor(typeof(NodeManager))]
public class NodeManager : EditorWindow
{
private static NodeManager window;
private Node[] m_nodes;
[MenuItem("Custom Windows/Node Inspector")]
public static void Init()
{
if(window == null)
window = GetWindow<NodeManager>("Node Manager", true, typeof(SceneView));
}
public void OnGUI()
{
m_nodes = GameObject.FindObjectsOfType<Node>();
foreach(Node node in m_nodes)
{
GUILayout.BeginHorizontal();
{
GUILayout.Label(node.name);
if (GUILayout.Button("Select"))
Selection.objects = new Object[] { node.gameObject };
}
GUILayout.EndHorizontal();
}
}
}
This adds a Button for each object in your custom window view, that will then select that object in the hierarchy.
Auto-Docking
I originally found the second response to this question, which goes into the details of parameters of the GetWindow method, and with this you can clearly see how to dock the window (I've converted it from JS to C# below).
(I looked fairly extensively in UnityEditor and UnityEditorInternal namespaces but couldn't find the Hierarchy or the Inspector).
GetWindow<T>(string title, bool focus, params System.Type[] desiredDockNextTo)
Which we can write for this example as;
EditorWindow.GetWindow<NodeInspector>("Node Test", true, typeof(SceneView));
This example docks the windows next to the SceneView window. This functionality can be combined with a custom inspector's OnInspectorGUI method, to automatically launch the custom node window, if it's not already open.
[CustomEditor(typeof(Node))]
public class NodeInspector : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
NodeManager.Init();
}
}
Sorry if this isn't what you are looking for, if it's not then please give more details and I will amend my answer to better suit the question.
Hope this helped.
Has a possibility, you can make a custom ScriptableObject and Custom Editor for It, and when open the node inspector, just find a instance of the scriptable object and use Selection.selectedObject = scriptableObject, and in the custom editor, make a static field called 'editor' to draw inside.
It will work.

Flex PlotChart zoom error in findDataPoints()

I came across this great tutorial on how to zoom into a chart by drawing a rectangle in a LineChart to zoom into it (http://blog.ninjacaptain.com/2010/03/flex-chart-zoom-window/) but i'm trying to apply it to a PlotChart instead and i'm having issues trying to get the DataTips showing with the following error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at mx.charts.series::PlotSeries/findDataPoints()[E:\dev\4.5.1\frameworks\projects\charts\src\mx\charts\series\PlotSeries.as:961]
at mx.charts.chartClasses::ChartBase/findDataPoints()[E:\dev\4.5.1\frameworks\projects\charts\src\mx\charts\chartClasses\ChartBase.as:2069]
at mx.charts.chartClasses::ChartBase/mouseClickHandler()[E:\dev\4.5.1\frameworks\projects\charts\src\mx\charts\chartClasses\ChartBase.as:4823]
The link mentioned about extending the LineChartSeries and override the findDataPoints() function, but after trying to doing the same for extending PlotSeries.as, sortOnXField seems to be undefined and I don't have access to the PlotSeries.as since it is in a swc.
Has anyone tried applying the following to a PlotChart instead and got the DataTips to show? What was the override function in the findDataPoints()?
Thanks
Some days ago I had the same problem with PieSeries.
I have not found yet why '_renderData.filteredCache' is null in 'filterDataPoints' function, but meanwhile I have resolved the problem extending PieSeries Class this way:
package com.eque.report.model {
import mx.charts.series.PieSeries;
public class MyPieSeries extends PieSeries {
public function MyPieSeries () {
super();
}
/**
* 'findDataPoints' function has been overriden in order to prevent
* '_renderData.filteredCache' is null.
*/
override public function findDataPoints(x:Number, y:Number, sensitivity:Number):Array {
if (renderData.filteredCache == null) {
renderData.filteredCache = [];
}
return super.findDataPoints(x, y, sensitivity);
}
}
}
I hope it could help you
If you're asking about how to solve the "filterDataPoints" issue in accessing chart points, you just have to create you own Series class, copy-paste the code from PlotSeries in it and change whatever fails on runtime. What kind of error do you get ?

Why is 'textField' not instantiated when I subclass TextArea in Flex?

I'm experimenting with TextArea and inheritance to implement some additional functionality on the protected textField property.
Unfortunately, when I create a new instance of the subclass, this property is set to null. I'm probably misunderstanding the way super() works, but I thought it would have been instantiated after the constructor finished.
Here's a small snippet of code which extends TextArea:
public final class ExtTextArea extends TextArea {
public function ExtTextArea() {
super();
}
public function testTextField():void {
if (textField == null)
Alert.show("null!");
}
}
}
The invoking code is simple:
var extTextArea:ExtTextArea = new ExtTextArea();
extTextArea.testTextField();
The Alert in ExtTestArea appears every time I run this code.
Why is this? Is there something more I need to do to access the textField property?
Since textField is "the internal UITextField that renders the text of this TextArea" I believe it will remain null until you add it to the display via .addChild(...). I ran a quick test to verify that once I've added it to the display, it is no longer null. You might want to add an event handler to the "creation complete" event and adjust it at that point (I think).
The Flex SDK comes with source code, so you can take a peek and see when this field is initialized. It is not initialized in the constrcutor, but you will see that a new TextField instantiated by createChildren(), which is called when the component is added to a layout container.

Resources