Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove customjfx #3779

Merged
merged 5 commits into from
Mar 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed lib/customjfx-1.0.0.jar
Binary file not shown.
65 changes: 3 additions & 62 deletions src/main/java/org/jabref/gui/customjfx/CustomJFXPanel.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,15 @@
package org.jabref.gui.customjfx;

import java.awt.event.InputMethodEvent;
import java.lang.reflect.Field;

import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;

import org.jabref.gui.AbstractView;
import org.jabref.gui.customjfx.support.InputMethodSupport;
import org.jabref.gui.util.DefaultTaskExecutor;
import org.jabref.logic.util.OS;

import com.sun.javafx.embed.EmbeddedSceneInterface;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/***
* WARNING: THIS IS A CUSTOM HACK TO PREVENT A BUG WITH ACCENTED CHARACTERS PRODUCING AN NPE IN LINUX </br>
* So far the bug has only been resolved in openjfx10: <a href="https://bugs.openjdk.java.net/browse/JDK-8185792">https://bugs.openjdk.java.net/browse/JDK-8185792</a>
*
/**
* Remove as soon as possible
*/
public class CustomJFXPanel extends JFXPanel {

private static final Logger LOGGER = LoggerFactory.getLogger(CustomJFXPanel.class);
private Field scenePeerField = null;

private CustomJFXPanel() {
super();
try {
scenePeerField = this.getClass().getSuperclass().getDeclaredField("scenePeer");
scenePeerField.setAccessible(true);
} catch (NoSuchFieldException | SecurityException e) {
LOGGER.error("Could not access scenePeer Field", e);

}
}

public static JFXPanel create() {
return OS.LINUX ? new CustomJFXPanel() : new JFXPanel();
}
public class CustomJFXPanel {

public static JFXPanel wrap(Scene scene) {
JFXPanel container = new JFXPanel();
Expand All @@ -47,34 +18,4 @@ public static JFXPanel wrap(Scene scene) {
return container;
}

@Override
protected void processInputMethodEvent(InputMethodEvent e) {
if (e.getID() == InputMethodEvent.INPUT_METHOD_TEXT_CHANGED) {
sendInputMethodEventToFX(e);
}

}

private void sendInputMethodEventToFX(InputMethodEvent e) {
String t = InputMethodSupport.getTextForEvent(e);

int insertionIndex = 0;
if (e.getCaret() != null) {
insertionIndex = e.getCaret().getInsertionIndex();
}

EmbeddedSceneInterface myScencePeer = null;
try {
//the variable must be named different to the original, otherwise reflection does not find the right ones
myScencePeer = (EmbeddedSceneInterface) scenePeerField.get(this);
} catch (IllegalArgumentException | IllegalAccessException ex) {
LOGGER.error("Could not access scenePeer Field", ex);
}

myScencePeer.inputMethodEvent(
javafx.scene.input.InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
InputMethodSupport.inputMethodEventComposed(t, e.getCommittedCharacterCount()),
t.substring(0, e.getCommittedCharacterCount()),
insertionIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@
import javax.swing.table.TableColumnModel;

import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;

import org.jabref.Globals;
import org.jabref.gui.IconTheme;
import org.jabref.gui.JabRefDialog;
import org.jabref.gui.JabRefFrame;
import org.jabref.gui.PreviewPanel;
import org.jabref.gui.customjfx.CustomJFXPanel;
import org.jabref.gui.desktop.JabRefDesktop;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;
Expand Down Expand Up @@ -156,7 +153,7 @@ private void init() {
builder.add(new JScrollPane(table)).xyw(1, 3, 5);
builder.add(addButton).xy(3, 5);
builder.add(removeButton).xy(5, 5);
JFXPanel container = CustomJFXPanel.wrap(new Scene(preview));
JFXPanel container = new JFXPanel();
builder.add(container).xyw(1, 7, 5);
builder.padding("5dlu, 5dlu, 5dlu, 5dlu");

Expand Down