java - JavaFX - Draw Popup where mouse is? -
i have following class extends popup
:
package application; import java.io.file; import java.util.hashmap; import java.util.map; import javafx.animation.keyframe; import javafx.animation.keyvalue; import javafx.animation.timeline; import javafx.beans.property.booleanproperty; import javafx.beans.property.readonlybooleanproperty; import javafx.beans.property.simplebooleanproperty; import javafx.collections.observablelist; import javafx.geometry.insets; import javafx.geometry.pos; import javafx.scene.node; import javafx.scene.control.label; import javafx.scene.image.image; import javafx.scene.image.imageview; import javafx.scene.layout.vbox; import javafx.scene.paint.color; import javafx.stage.popup; import javafx.util.duration; import logic.item; import logic.itemquality; import logic.manager; /** * frame displays item, ideally used * when user hovers on given element. * frame's labels made * diablo 2-esque ends creating nice * looking frame fades in , out on use. * @author kevin * */ class itemframe_animated extends popup { private final booleanproperty hiding; itemframe_animated(item reference) { vbox frame = new vbox(); frame.setalignment(pos.center); frame.setpadding(new insets(10)); frame.setspacing(4); color titlecolor = reference.getquality().getcolor(); // item has surname, such 'engima'. if (!reference.getspecialname().isempty()) { label surname = new label(reference.getspecialname()); surname.settextfill(titlecolor); frame.getchildren().add(surname); } // base name, such 'long bow'. label basename = new label(reference.getidentifier()); // 1 special case if quality runeword, item's base needs gray. basename.settextfill((reference.getquality() == itemquality.runeword) ? itemquality.base_modified.getcolor() : titlecolor); frame.getchildren().add(basename); // if item has level. if (reference.getlevel() > 0) { label level = new label("required level: " + reference.getlevel()); // level white colored. level.settextfill(itemquality.base.getcolor()); frame.getchildren().add(level); } // add affixes. (string : reference.getaffixes()) { label affix = new label(i); // affixes blue colored. affix.settextfill(itemquality.magic.getcolor()); frame.getchildren().add(affix); } if (reference.getsockets() > 0) { label sockets = new label("socketed: (" + reference.getsockets() + ")"); sockets.settextfill(itemquality.base_modified.getcolor()); frame.getchildren().add(sockets); } // change font of every label. (node : frame.getchildren()) { i.getstyleclass().clear(); ((label) i).setfont(gui.diablofont); } // add item's picture frame. string path = "./res/images/" + manager.itemdatabase.get(reference.getidentifier()).getimageurl().hashcode() + ".jpg"; imageview itemimage = new imageview(new image(new file(path).touri().tostring())); frame.getchildren().add(itemimage); // set content of page vbox. getcontent().add(frame); frame.setstyle("-fx-background-color: #020202;"); // don't allow popup closed. sethideonescape(false); setwidth(400); setheight(500); this.hiding = new simplebooleanproperty(this, "hiding", false); } public readonlybooleanproperty hidingproperty() { return hiding; } public boolean ishiding() { return hiding.get(); } @override public void hide() { // if window not in process of being hidden... if (!hiding.get()) { // inform popup attempting hide. hiding.set(true); // grab nodes in popup , track opacities. final observablelist<node> nodes = this.getcontent(); final map<node, double> opacities = new hashmap<node, double>(); keyvalue[] keyvalues = new keyvalue[nodes.size()]; (int = 0; < keyvalues.length; i++) { // set keyvalues each node. node node = nodes.get(i); opacities.put(node, node.getopacity()); keyvalues[i] = new keyvalue(nodes.get(i).opacityproperty(), 0); } keyframe frame = new keyframe(duration.seconds(1), keyvalues); timeline timeline = new timeline(frame); timeline.setonfinished(e -> { // no longer hiding frame. hiding.set(false); itemframe_animated.super.hide(); (node node : nodes) { node.setopacity(opacities.get(node)); } }); // play animation. timeline.play(); } } }
honestly code isn't important, trust me displays popup when user hovers on 1 of item
objects, so:
this popup window opened right in middle of screen. if move window, popup open in same location. need popup window somehow open under mouse pointer. know tooltip
has functionality (allegedly) i've committed designing popup
window has many of design goals.
is possible have popup
window show in location?
thank you.
couldn't find answer did:
@override public void show() { point mouselocation = mouseinfo.getpointerinfo().getlocation(); setx(mouselocation.getx()); sety(mouselocation.gety()); super.show(); }
there's better solution that's think of.
Comments
Post a Comment