Skip to content

Commit

Permalink
Get rid of customjfx hack
Browse files Browse the repository at this point in the history
Big step towards jdk9 compatibility
No longer needed
CodeArea still does not work
  • Loading branch information
Siedlerchr committed Feb 26, 2018
1 parent 7af1f13 commit cec8d2c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 66 deletions.
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

0 comments on commit cec8d2c

Please sign in to comment.