Can't get mouse event from any other javafx 8 node after getting MOUSE_PRESSED event from one node - mouseevent

I'm creating rich text component with selection capabilities for JavaFX project and facing some difficulties.
I'm trying to catch on which TextFlow object user presses mouse button and on which another TextFlow he releases it. But after MOUSE_PRESSED event i can interact only with that TextFlow, who fired it, until i release the mouse.
Here is similar example with Labels:
package sample;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Main extends Application {
#Override
public void start(Stage primaryStage) throws Exception{
AnchorPane root = new AnchorPane();
primaryStage.setTitle("Events Problem Example");
primaryStage.setScene(new Scene(root, 800, 600));
VBox mainVB = new VBox();
root.getChildren().add(mainVB);
//########## Code is here:
for (int i = 0; i < 5; i++) {
final Label label = new Label("labelâ„–"+i);
mainVB.getChildren().addAll(label);
label.setOnMouseEntered(mouseEvent -> System.out.println("entering " + label.getText()));
label.setOnMousePressed(mouseEvent -> System.out.println("press mouse button on " + label.getText()));
label.setOnMouseReleased(mouseEvent -> System.out.println("release mouse button on " + label.getText()));
}
//########################
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Try to move mouse over different Labels and watch messages in command line. After that press and hold mouse primary button on any Label and move it again. You'll see that no other Labels will fire any event until you releases the button.
I spend some time searching for the solution but got nothing.
I also tried to manually fire MOUSE_RELEASED for corresponding Label but it didn't help also.
Appreciate your support.

The documentation for MouseEvent details three different modes for handling mouse drag. In the default mode ("simple press-drag-release gesture"), as you've observed, mouse events are delivered only to the node on which the gesture originated.
In "full press-drag-release gesture" mode, MouseDragEvents are delivered to other nodes during the drag. This is the mode you need, and you activate it by calling startFullDrag on the originating node.
(The third mode is "drag-and-drop" gesture, which is for transferring data between nodes and is typically supported by the underlying platform, so you can drag and drop between your JavaFX application and other applications, as well as within the application.)
Try the following code for your event handlers:
label.setOnDragDetected(mouseEvent -> label.startFullDrag());
label.setOnMouseDragEntered(mouseEvent -> System.out.println("entering " + label.getText()));
label.setOnMouseDragReleased(mouseEvent -> System.out.println("release mouse button on " + label.getText()));

Related

Libgdx Dialog buttons cannot be clicked

I have trouble properly implementing a dialog. It does not recognize button clicks - even the button down animation does not happen. However, it does recognize key presses (e.g. enter or esc in my case). Dialog does appear to be on top of the stage objects, so I'm confused why it isn't registering my clicks.
I have an InputMultiplexer with processors InputHandler class (implements InputProcessor) and stage, in that order:
InputMultiplexer im = new InputMultiplexer();
im.addProcessor(new InputHandler(stage));
im.addProcessor(stage);//trying to make dialog work by doing this
Gdx.input.setInputProcessor(im);
Here's my showDialog method defined in stage:
public void showDialog() {
Dialog dialog = new Dialog("Quit?", skin) {
#Override
protected void result(Object object) {
boolean exit = (Boolean) object;
if (exit) {
Gdx.app.exit();
} else {
remove();
}
}
};
dialog.button("Yes", true);
dialog.button("No", false);
dialog.key(Input.Keys.ENTER, true);
dialog.key(Input.Keys.ESCAPE, false);
dialog.show(this);
}
The showDialog() method is called from InputHandler when it recognizes that the game is over (I have it set so that the game state is checked and updated on touch up, since it's a touch based game). My understanding is that since the multiplexer receives false return from the InputHandler methods when the game is over, it then goes to the stage for input, which seems to be working only when I use key presses on the dialog, i.e. enter quits the game, esc removes the dialog, but clicking the buttons do nothing.
Here is my Screen's render function in case it's relevant:
#Override
public void render(float delta) {
Gdx.gl.glClearColor(1,1,1,1);
Gdx.graphics.getGL20().glEnable(GL20.GL_BLEND);
Gdx.graphics.getGL20().glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT | (Gdx.graphics.getBufferFormat().coverageSampling?GL20.GL_COVERAGE_BUFFER_BIT_NV:0));
stage.act();
stage.getCamera().update();
stage.draw();
}

Modeless dialog created by modal dialog in Compact Framework

I am working on a Compact Framework application. This particular hardware implementation has a touchscreen, but its Soft Input Panel has buttons that are simply too small to be useful. There are more than one form where typed input is required, so I created a form with buttons laid out like a keypad. The forms that use this "keypad" form are modal dialogs. When a dialog requiring this "keypad" loads, I load the "keypad" form as modeless:
private void CardInputForm_Load(object sender, EventArgs e)
{
...
keypadForm = new KeypadForm();
keypadForm.Owner = this;
keypadForm.SetCallback(keyHandler);
keypadForm.Show();
}
The SetCallback method tells the "keypad" form where to send the keystrokes (as a Delegate).
The problem I'm having is that the modeless "keypad" form does not take input. It is displayed as I expect, but I get a beep when I press any of its buttons, and its caption is grayed-out. It seems like the modal dialog is blocking it.
I've read other posts on this forum that says modal dialogs can create & use modeless dialogs. Can anyone shed light on this situation? Is there a problem with my implementation?
I found the answer: Set the keypad form's Parent property, not its Owner property, to the form instance wanting the keystrokes. The keypad dialog's title bar stays grayed out, but the form is active.
private void CardInputForm_Load(object sender, EventArgs e)
{
// (do other work)
keypadForm = new KeypadForm();
keypadForm.Parent = this;
keypadForm.Top = 190; // set as appropriate
keypadForm.Show();
}
Be sure to clean up when done with the parent form. This can be in the parent's Closing or Closed events.
private void CardInputForm_Closing(object sender, CancelEventArgs e)
{
// (do other work)
keypadForm.Close();
keypadForm.Dispose();
}
There are two panels on the keypad form, one with numerals and one with letters and punctuation that I want. There is also an area not on a panel that is common to both, containing buttons for clear, backspace, enter/OK, and cancel. Each panel has a button to hide itself and unhide its counterpart ('ABC', '123', for example). I have all the buttons for input on the keypadForm fire a common event. All it does is send the button instance to the parent. The parent is responsible for determining what action or keystroke is desired. In my case I named the buttons "btnA", "btnB", "btn0", "btn1", "btnCancel", etc. For keystrokes, the parent form takes the last character of the name to determine what key is desired. This is a bit messy but it works. Any form wishing to use the keypad form inherits from a base class, defining a method for callback.
public partial class TimeClockBase : Form
{
public TimeClockBase()
{
InitializeComponent();
}
// (other implementation-specific base class functionality)
public virtual void KeyCallback(Button button)
{
}
}
The click event on the keypad form looks like this.
private void btnKey_Click(object sender, EventArgs e)
{
// play click sound if supported
(Parent as TimeClockBase).KeyCallback(sender as Button);
}
The method in the parent form looks like this.
public override void KeyCallback(Button button)
{
switch (button.Name)
{
case "btnCancel":
// setting result will cause form to close
DialogResult = DialogResult.Cancel;
break;
case "btnClear":
txtCardID.Text = string.Empty;
break;
// (handle other cases)
}
}

Eclipse Plug-in:Focus lost after activating a view via (controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE));

I have a view which is initialised via OleControlSite and invoked via OleAutomation. It is actually a media player which I call in a view after user right clicks the file and calls Play in the context menu. Whenever I play a file by first right clicking and calling Play, it plays absolutely fine. The problem is when user displays the view before doing a right click(Window->Show View->Other->MyView) and then tries to do a right click and Play, at this point of time ISelection returns null and hence nothing plays.
IWorkbenchPage iwPage=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ISelection selection=iwPage.getSelection();
The problem is the selections somehow loses focus if the view has been invoked in the fashion described.
This is how the view is initialised when the plugin is loaded
public void createPartControl(Composite parent) {
frame = new OleFrame(parent, SWT.APPLICATION_MODAL);
// OleControlSite controlSite;
try {
controlSite = new OleControlSite(frame, SWT.APPLICATION_MODAL,"WMPlayer.OCX.7");
controlSite.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);
oleAutomation = new OleAutomation(controlSite);
makeActions();
fillActionBars();
} catch (SWTException ex) {
MessageBox box = new MessageBox(getSite().getShell(),SWT.ICON_INFORMATION);
box.setMessage("Failed to Initialise Media Player.");
box.setText("Error");
box.open();
ex.printStackTrace();
return;
}
}
Is there a way where we can force the focus to the Project Explorer where the current file is selected ?

Dynamic JFrame in java

I have a project and I need to know how to adding a component in a JFrame when pressing a JButton.
I have added a panel into panel by this code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
colorPanel color0=new colorPanel();
color0.setBounds(5,150+nb,300,120);
color0.setLayout(new FlowLayout());
this.getContentPane().add(color0);
this.validate();
System.out.println("add couleur:"+nb);
nb+=50;
}
It works but the problem is that the component is deleted when I maximize or minimize the JFrame.
Thanks.
When you resize your Jframe, a repaint() & paint() methods are called which probably erases your component.

SCSF: display view from another view against button click

i am facing one problem in SCSF.
I have two workspaces
MdiWorkspace
DeckWorkspace
i have two views in a module
Viewer (display in mdiworkspace)
Property Viewer (in deckworkspace)
in Viewer i have a button in toolbar whose purpose is to display PropertyViewer (another View).
how can i display this PropertyViewer in deckworkspace agaist button click event.
NOTE: i am not using Command[CommandName].AddInvoker(control, "click:) and CommandHandler
I'm going to assume your toolbar sits in a SmartPart that implements the MVP pattern. Have the button click event handler in the SmartPart fire an event that its presenter will handle. Your presenter code would look like this:
// Presenter code
protected override void OnViewSet()
{
this.View.ToolbarButtonClick += View_ToolbarButtonClick;
}
public void View_ToolbarButtonClick(object sender, EventArgs e)
{
// remove the handler so the property viewer
// will only be added the first time
this.View.OnToolbarButtonClick -= View_ToolbarButtonClick;
var propertyView = new PropertyViewer();
this.WorkItem.Workspaces[WorkspaceNames.MyDeckWorkspace].Show(propertyView);
}