From c2a515c774f11ae56a3450839c4e02da2a8d7563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Wed, 24 Jul 2024 13:15:18 +0200 Subject: [PATCH] feat: add option to set initial mode --- examples/generic_editor/demo.html | 50 +++- examples/generic_editor/demo/demo.ts | 4 +- lib/canvas_editor/create_editor.js | 16 +- .../research/gwt/gui/generic/JSCheckBox.java | 6 +- .../gwt/gui/generic/JSClipboardHandler.java | 14 +- .../research/gwt/gui/generic/JSComboBox.java | 16 +- .../research/gwt/gui/generic/JSComponent.java | 24 +- .../research/gwt/gui/generic/JSDialog.java | 32 +- .../gwt/gui/generic/JSDrawContext.java | 121 ++++---- .../gwt/gui/generic/JSEditorArea.java | 281 +++++++++--------- .../gwt/gui/generic/JSEditorToolbar.java | 138 ++++----- .../gwt/gui/generic/JSKeyHandler.java | 9 +- .../research/gwt/gui/generic/JSLabel.java | 4 +- .../gwt/gui/generic/JSMouseHandler.java | 9 +- .../research/gwt/gui/generic/JSPolygon.java | 6 +- .../research/gwt/gui/generic/JSRectangle.java | 6 +- .../research/gwt/gui/generic/JSTextField.java | 4 +- .../research/gwt/gui/generic/JSUIHelper.java | 8 +- types.d.ts | 7 + 19 files changed, 404 insertions(+), 351 deletions(-) diff --git a/examples/generic_editor/demo.html b/examples/generic_editor/demo.html index ba6220f5..a7773ce3 100644 --- a/examples/generic_editor/demo.html +++ b/examples/generic_editor/demo.html @@ -7,21 +7,39 @@ -
- - - -
-
-
-
-
-
Change count
-
-
ID Code
-
-
Molfile
-
-
+

Demo - Generic editor

+
+
+ + + +
+
+
+
Change count
+
+
ID Code
+
+
Molfile
+
+
+
diff --git a/examples/generic_editor/demo/demo.ts b/examples/generic_editor/demo/demo.ts index 182df257..6335c78c 100644 --- a/examples/generic_editor/demo/demo.ts +++ b/examples/generic_editor/demo/demo.ts @@ -173,7 +173,9 @@ const molfileDiv = document.getElementById('molfile') as HTMLElement; let changeCount = 0; const editorElement = document.getElementById('editor') as HTMLElement; -const editor = new CanvasEditor(editorElement); +const editor = new CanvasEditor(editorElement, { + initialMode: 'molecule', +}); editor.setOnChangeListener(({ type, isUserEvent }) => { if (isUserEvent && type === 'molecule') { diff --git a/lib/canvas_editor/create_editor.js b/lib/canvas_editor/create_editor.js index fef34acb..664c8d27 100644 --- a/lib/canvas_editor/create_editor.js +++ b/lib/canvas_editor/create_editor.js @@ -13,7 +13,7 @@ function createEditor( JavaEditorToolbar, JavaUIHelper, ) { - const { readOnly = false } = options; + const { readOnly = false, initialMode = 'molecule' } = options; const rootElement = document.createElement('div'); Object.assign(rootElement.style, { @@ -56,6 +56,7 @@ function createEditor( const uiHelper = new JavaUIHelper(new UIHelper(editorCanvas, JavaEditorArea)); const editorArea = new JavaEditorArea( + computeMode(initialMode, JavaEditorArea), new EditorArea(editorCanvas, onChange), uiHelper, ); @@ -110,4 +111,17 @@ function createEditor( return { editorArea, toolbar, uiHelper, destroy }; } +function computeMode(initialMode, JavaEditorArea) { + switch (initialMode) { + case 'molecule': + return 0; + case 'reaction': + return ( + JavaEditorArea.MODE_REACTION | JavaEditorArea.MODE_MULTIPLE_FRAGMENTS + ); + default: + throw new Error(`Invalid initial mode: ${initialMode}`); + } +} + module.exports = createEditor; diff --git a/src/com/actelion/research/gwt/gui/generic/JSCheckBox.java b/src/com/actelion/research/gwt/gui/generic/JSCheckBox.java index 54f2f76d..e856b71a 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSCheckBox.java +++ b/src/com/actelion/research/gwt/gui/generic/JSCheckBox.java @@ -1,6 +1,6 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericCheckBox; import com.google.gwt.core.client.JavaScriptObject; public class JSCheckBox extends JSComponent implements GenericCheckBox { @@ -9,14 +9,14 @@ public JSCheckBox(JavaScriptObject jsCheckBox) { } @Override - public native boolean isSelected() + public native boolean isSelected() /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSCheckBox::getJsComponent()(); return component.isSelected(); }-*/; @Override - public native void setSelected(boolean b) + public native void setSelected(boolean b) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSCheckBox::getJsComponent()(); return component.setSelected(b); diff --git a/src/com/actelion/research/gwt/gui/generic/JSClipboardHandler.java b/src/com/actelion/research/gwt/gui/generic/JSClipboardHandler.java index 8be00ac0..3121cfee 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSClipboardHandler.java +++ b/src/com/actelion/research/gwt/gui/generic/JSClipboardHandler.java @@ -1,15 +1,15 @@ package com.actelion.research.gwt.gui.generic; -import java.util.ArrayList; - import com.actelion.research.chem.MolfileParser; import com.actelion.research.chem.StereoMolecule; import com.actelion.research.chem.reaction.Reaction; import com.actelion.research.gui.clipboard.IClipboardHandler; import com.google.gwt.core.client.JavaScriptObject; +import java.util.ArrayList; + public class JSClipboardHandler implements IClipboardHandler { - private JavaScriptObject mJsHandler; + private JavaScriptObject mJsHandler; public JSClipboardHandler(JavaScriptObject jsHandler) { mJsHandler = jsHandler; @@ -51,11 +51,11 @@ public Reaction pasteReaction() { public boolean copyMolecule(String molfile) { Object test = null; System.out.println("test: " + test.toString()); - StereoMolecule m = new StereoMolecule(); - MolfileParser p = new MolfileParser(); - p.parse(m, molfile); + StereoMolecule m = new StereoMolecule(); + MolfileParser p = new MolfileParser(); + p.parse(m, molfile); return copyMolecule(m); - } + } public native boolean copyMolecule(StereoMolecule mol) /*-{ diff --git a/src/com/actelion/research/gwt/gui/generic/JSComboBox.java b/src/com/actelion/research/gwt/gui/generic/JSComboBox.java index 43335b65..4fb1f049 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSComboBox.java +++ b/src/com/actelion/research/gwt/gui/generic/JSComboBox.java @@ -1,6 +1,6 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericComboBox; import com.google.gwt.core.client.JavaScriptObject; public class JSComboBox extends JSComponent implements GenericComboBox { @@ -9,49 +9,49 @@ public JSComboBox(JavaScriptObject jsComboBox) { } @Override - public native void addItem(String item) + public native void addItem(String item) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComboBox::getJsComponent()(); return component.addItem(item); }-*/; @Override - public native void removeAllItems() + public native void removeAllItems() /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComboBox::getJsComponent()(); return component.removeAllItems(); }-*/; @Override - public native int getSelectedIndex() + public native int getSelectedIndex() /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComboBox::getJsComponent()(); return component.getSelectedIndex(); }-*/; @Override - public native String getSelectedItem() + public native String getSelectedItem() /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComboBox::getJsComponent()(); return component.getSelectedItem(); }-*/; @Override - public native void setSelectedIndex(int index) + public native void setSelectedIndex(int index) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComboBox::getJsComponent()(); return component.setSelectedIndex(index); }-*/; @Override - public native void setSelectedItem(String item) + public native void setSelectedItem(String item) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComboBox::getJsComponent()(); return component.setSelectedItem(item); }-*/; @Override - public native void setEditable(boolean b) + public native void setEditable(boolean b) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComboBox::getJsComponent()(); return component.setEditable(b); diff --git a/src/com/actelion/research/gwt/gui/generic/JSComponent.java b/src/com/actelion/research/gwt/gui/generic/JSComponent.java index edaefb06..3b9f64f6 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSComponent.java +++ b/src/com/actelion/research/gwt/gui/generic/JSComponent.java @@ -1,17 +1,19 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericActionEvent; +import com.actelion.research.gui.generic.GenericComponent; +import com.actelion.research.gui.generic.GenericEventListener; import com.google.gwt.core.client.JavaScriptObject; import java.util.ArrayList; public class JSComponent implements GenericComponent { private JavaScriptObject mJsComponent; - private ArrayList> mConsumerList; + private ArrayList> mConsumerList; public JSComponent(JavaScriptObject jsComponent) { mJsComponent = jsComponent; - mConsumerList = new ArrayList<>(); + mConsumerList = new ArrayList<>(); setEventHandler(jsComponent); } @@ -32,26 +34,26 @@ public JavaScriptObject getJsComponent() { } @Override - public native void setEnabled(boolean b) + public native void setEnabled(boolean b) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSComponent::getJsComponent()(); return component.setEnabled(b); }-*/; @Override - public void addEventConsumer(GenericEventListener consumer) { - mConsumerList.add(consumer); + public void addEventConsumer(GenericEventListener consumer) { + mConsumerList.add(consumer); } @Override - public void removeEventConsumer(GenericEventListener consumer) { - mConsumerList.remove(consumer); + public void removeEventConsumer(GenericEventListener consumer) { + mConsumerList.remove(consumer); } @Override - public void fireEvent(GenericActionEvent event) { - for (GenericEventListener consumer:mConsumerList) { - consumer.eventHappened(event); + public void fireEvent(GenericActionEvent event) { + for (GenericEventListener consumer:mConsumerList) { + consumer.eventHappened(event); } } } diff --git a/src/com/actelion/research/gwt/gui/generic/JSDialog.java b/src/com/actelion/research/gwt/gui/generic/JSDialog.java index 87adb790..586e8cf9 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSDialog.java +++ b/src/com/actelion/research/gwt/gui/generic/JSDialog.java @@ -20,28 +20,28 @@ private JavaScriptObject getJsDialog() { @Override public native void setLayout(int[] hLayout, int[] vLayout) /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); - return dialog.setLayout(hLayout, vLayout); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + return jsDialog.setLayout(hLayout, vLayout); }-*/; @Override public native void add(GenericComponent c, int x, int y) /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); - return dialog.add(c, x, y); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + return jsDialog.add(c, x, y); }-*/; @Override public native void add(GenericComponent c, int x1, int y1, int x2, int y2) /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); - return dialog.add(c, x1, y1, x2, y2); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + return jsDialog.add(c, x1, y1, x2, y2); }-*/; @Override public native GenericCheckBox createCheckBox(String text) /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); var checkBox = dialog.createCheckBox(text); return @com.actelion.research.gwt.gui.generic.JSCheckBox::new(Lcom/google/gwt/core/client/JavaScriptObject;)(checkBox); }-*/; @@ -49,23 +49,23 @@ public native GenericCheckBox createCheckBox(String text) @Override public native GenericComboBox createComboBox() /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); var comboBox = dialog.createComboBox(); return @com.actelion.research.gwt.gui.generic.JSComboBox::new(Lcom/google/gwt/core/client/JavaScriptObject;)(comboBox); }-*/; @Override - public native GenericLabel createLabel(String text) + public native GenericLabel createLabel(String text) /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); var label = dialog.createLabel(text); return @com.actelion.research.gwt.gui.generic.JSLabel::new(Lcom/google/gwt/core/client/JavaScriptObject;)(label); }-*/; @Override - public native GenericTextField createTextField(int width, int height) + public native GenericTextField createTextField(int width, int height) /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); var textField = dialog.createTextField(width, height); return @com.actelion.research.gwt.gui.generic.JSTextField::new(Lcom/google/gwt/core/client/JavaScriptObject;)(textField); }-*/; @@ -74,7 +74,7 @@ public native GenericTextField createTextField(int width, int height) public native void setEventConsumer(GenericEventListener consumer) /*-{ this.@com.actelion.research.gwt.gui.generic.JSDialog::mConsumer = consumer; - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); var that = this; var jsConsumer = { fireOk: function ok() { @@ -90,21 +90,21 @@ public native void setEventConsumer(GenericEventListener con @Override public native void showDialog() /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); dialog.showDialog(); }-*/; @Override public native void disposeDialog() /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); dialog.disposeDialog(); }-*/; @Override public native void showMessage(String message) /*-{ - var dialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); + var jsDialog = this.@com.actelion.research.gwt.gui.generic.JSDialog::getJsDialog()(); dialog.showMessage(message); }-*/; diff --git a/src/com/actelion/research/gwt/gui/generic/JSDrawContext.java b/src/com/actelion/research/gwt/gui/generic/JSDrawContext.java index 8a5f75b9..b7dbf284 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSDrawContext.java +++ b/src/com/actelion/research/gwt/gui/generic/JSDrawContext.java @@ -1,29 +1,32 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericDrawContext; +import com.actelion.research.gui.generic.GenericImage; +import com.actelion.research.gui.generic.GenericPolygon; +import com.actelion.research.gui.generic.GenericRectangle; import com.google.gwt.core.client.JavaScriptObject; public class JSDrawContext implements GenericDrawContext { - private JavaScriptObject mJsContext; + private JavaScriptObject mJsContext; - public JSDrawContext(JavaScriptObject jsContext) { - mJsContext = jsContext; - } + public JSDrawContext(JavaScriptObject jsContext) { + mJsContext = jsContext; + } - private JavaScriptObject getJsContext() { - return mJsContext; - } + private JavaScriptObject getJsContext() { + return mJsContext; + } public native void clearRect(double x, double y, double w, double h) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.clearRect(x, y, w, h); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.clearRect(x, y, w, h); }-*/; @Override public native GenericImage createARGBImage(int width, int height) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); var image = ctx.createARGBImage(width, height); return @com.actelion.research.gwt.gui.generic.JSImage::new(Lcom/google/gwt/core/client/JavaScriptObject;)(image); }-*/; @@ -31,53 +34,53 @@ public native GenericImage createARGBImage(int width, int height) @Override public native void drawCenteredString(double x, double y, String s) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.drawCenteredString(x, y, s); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.drawCenteredString(x, y, s); }-*/; @Override public native void drawCircle(double x, double y, double d) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.drawCircle(x, y, d); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.drawCircle(x, y, d); }-*/; @Override public native void drawDottedLine(double x1, double y1, double x2, double y2) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.drawDottedLine(x1, y1, x2, y2); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.drawDottedLine(x1, y1, x2, y2); }-*/; @Override public native void drawImage(GenericImage image, double x, double y) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); var jsImage = image.@com.actelion.research.gui.generic.GenericImage::get()(); - return ctx.drawImage(jsImage, x, y); + return jsContext.drawImage(jsImage, x, y); }-*/; @Override public native void drawImage(GenericImage image, double sx, double sy, double dx, double dy, double w, double h) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); var jsImage = image.@com.actelion.research.gui.generic.GenericImage::get()(); - return ctx.drawImage(jsImage, sx, sy, dx, dy, w, h); + return jsContext.drawImage(jsImage, sx, sy, dx, dy, w, h); }-*/; @Override public native void drawImage(GenericImage image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); var jsImage = image.@com.actelion.research.gui.generic.GenericImage::get()(); - return ctx.drawImage(jsImage, sx, sy, sw, sh, dx, dy, dw, dh); + return jsContext.drawImage(jsImage, sx, sy, sw, sh, dx, dy, dw, dh); }-*/; @Override public native void drawLine(double x1, double y1, double x2, double y2) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.drawLine(x1, y1, x2, y2); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.drawLine(x1, y1, x2, y2); }-*/; @Override @@ -87,29 +90,29 @@ public void drawPolygon(GenericPolygon p) { public native void drawPolygon(JSPolygon jsPolygon) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.drawPolygon(jsPolygon); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.drawPolygon(jsPolygon); }-*/; @Override public native void drawRectangle(double x, double y, double w, double h) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.drawRectangle(x, y, w, h); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.drawRectangle(x, y, w, h); }-*/; @Override public native void drawString(double x, double y, String s) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.drawString(x, y, s); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.drawString(x, y, s); }-*/; @Override public native void fillCircle(double x, double y, double d) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.fillCircle(x, y, d); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.fillCircle(x, y, d); }-*/; @Override @@ -119,22 +122,22 @@ public void fillPolygon(GenericPolygon p) { public native void fillPolygon(JSPolygon jsPolygon) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.fillPolygon(jsPolygon); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.fillPolygon(jsPolygon); }-*/; @Override public native void fillRectangle(double x, double y, double w, double h) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.fillRectangle(x, y, w, h); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.fillRectangle(x, y, w, h); }-*/; @Override public native int getBackgroundRGB() /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.getBackgroundRGB(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.getBackgroundRGB(); }-*/; @Override @@ -146,71 +149,71 @@ public GenericRectangle getBounds(String s) { public native GenericRectangle getBounds(String s, JSRectangle jsRect) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.getBounds(s, jsRect); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.getBounds(s, jsRect); }-*/; @Override public native int getFontSize() /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.getFontSize(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.getFontSize(); }-*/; @Override public native int getForegroundRGB() /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.getForegroundRGB(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.getForegroundRGB(); }-*/; @Override public native float getLineWidth() /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.getLineWidth(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.getLineWidth(); }-*/; @Override public native int getRGB() /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.getRGB(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.getRGB(); }-*/; @Override public native int getSelectionBackgroundRGB() /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.getSelectionBackgroundRGB(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.getSelectionBackgroundRGB(); }-*/; @Override public native boolean isDarkBackground() /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.isDarkBackground(); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.isDarkBackground(); }-*/; @Override public native void setFont(int size, boolean isBold, boolean isItalic) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.setFont(size, isBold, isItalic); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.setFont(size, isBold, isItalic); }-*/; @Override public native void setLineWidth(float lineWidth) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.setLineWidth(lineWidth); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.setLineWidth(lineWidth); }-*/; @Override public native void setRGB(int rgb) /*-{ - var ctx = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); - return ctx.setRGB(rgb); + var jsContext = this.@com.actelion.research.gwt.gui.generic.JSDrawContext::getJsContext()(); + return jsContext.setRGB(rgb); }-*/; } diff --git a/src/com/actelion/research/gwt/gui/generic/JSEditorArea.java b/src/com/actelion/research/gwt/gui/generic/JSEditorArea.java index fcf82d26..b75ab095 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSEditorArea.java +++ b/src/com/actelion/research/gwt/gui/generic/JSEditorArea.java @@ -13,169 +13,174 @@ @JsType(name = "GenericEditorArea") public class JSEditorArea implements GenericCanvas { - private GenericEditorArea mDrawArea; - private JavaScriptObject mOptions; - private JSMouseHandler mMouseHandler; - private JSKeyHandler mKeyHandler; - - public static final int EDITOR_EVENT_MOLECULE_CHANGED = EditorEvent.WHAT_MOLECULE_CHANGED; - public static final int EDITOR_EVENT_SELECTION_CHANGED = EditorEvent.WHAT_SELECTION_CHANGED; - public static final int EDITOR_EVENT_HIGHLIGHT_ATOM_CHANGED = EditorEvent.WHAT_HILITE_ATOM_CHANGED; - public static final int EDITOR_EVENT_HIGHLIGHT_BOND_CHANGED = EditorEvent.WHAT_HILITE_BOND_CHANGED; - - public static final int MOUSE_EVENT_PRESSED = GenericMouseEvent.MOUSE_PRESSED; - public static final int MOUSE_EVENT_RELEASED = GenericMouseEvent.MOUSE_RELEASED; - public static final int MOUSE_EVENT_CLICKED = GenericMouseEvent.MOUSE_CLICKED; - public static final int MOUSE_EVENT_ENTERED = GenericMouseEvent.MOUSE_ENTERED; - public static final int MOUSE_EVENT_EXITED = GenericMouseEvent.MOUSE_EXITED; - public static final int MOUSE_EVENT_MOVED = GenericMouseEvent.MOUSE_MOVED; - public static final int MOUSE_EVENT_DRAGGED = GenericMouseEvent.MOUSE_DRAGGED; - - public static final int KEY_CTRL = GenericKeyEvent.KEY_CTRL; - public static final int KEY_ALT = GenericKeyEvent.KEY_ALT; - public static final int KEY_SHIFT = GenericKeyEvent.KEY_SHIFT; - public static final int KEY_DELETE = GenericKeyEvent.KEY_DELETE; - public static final int KEY_BACK_SPACE = GenericKeyEvent.KEY_BACK_SPACE; - public static final int KEY_HELP = GenericKeyEvent.KEY_HELP; - public static final int KEY_ESCAPE = GenericKeyEvent.KEY_ESCAPE; - - public static final int KEY_EVENT_PRESSED = GenericKeyEvent.KEY_PRESSED; - public static final int KEY_EVENT_RELEASED = GenericKeyEvent.KEY_RELEASED; - - public static final int cChainCursor = GenericCursorHelper.cChainCursor; - public static final int cDeleteCursor = GenericCursorHelper.cDeleteCursor; - public static final int cHandCursor = GenericCursorHelper.cHandCursor; - public static final int cHandPlusCursor = GenericCursorHelper.cHandPlusCursor; - public static final int cFistCursor = GenericCursorHelper.cFistCursor; - public static final int cLassoCursor = GenericCursorHelper.cLassoCursor; - public static final int cLassoPlusCursor = GenericCursorHelper.cLassoPlusCursor; - public static final int cSelectRectCursor = GenericCursorHelper.cSelectRectCursor; - public static final int cSelectRectPlusCursor = GenericCursorHelper.cSelectRectPlusCursor; - public static final int cZoomCursor = GenericCursorHelper.cZoomCursor; - public static final int cInvisibleCursor = GenericCursorHelper.cInvisibleCursor; - public static final int cPointerCursor = GenericCursorHelper.cPointerCursor; - public static final int cTextCursor = GenericCursorHelper.cTextCursor; - public static final int cPointedHandCursor = GenericCursorHelper.cPointedHandCursor; - public static final int[][] IMAGE_DATA_16 = GenericCursorHelper.IMAGE_DATA_16; - public static final int[] HOTSPOT_16 = GenericCursorHelper.HOTSPOT_16; - public static final int[] HOTSPOT_32 = GenericCursorHelper.HOTSPOT_32; - public static final String[] IMAGE_NAME_32 = GenericCursorHelper.IMAGE_NAME_32; - - public static final int TableLayoutPreferred = (int)TableLayout.PREFERRED; - public static final int TableLayoutFill = (int)TableLayout.FILL; - - public JSEditorArea(JavaScriptObject options, JSUIHelper uiHelper) { - mDrawArea = new GenericEditorArea(new StereoMolecule(), 0, uiHelper, this); - mDrawArea.addDrawAreaListener(new GenericEventListener() { - @Override - public void eventHappened(EditorEvent e) { - callJsEventListener(e.getWhat(), e.isUserChange()); - } - }); - mOptions = options; - - mMouseHandler = new JSMouseHandler(mDrawArea); - mMouseHandler.addListener(mDrawArea); - - mKeyHandler = new JSKeyHandler(mDrawArea); - mKeyHandler.addListener(mDrawArea); - - JavaScriptObject clipboardHandler = getClipboardHandler(); - mDrawArea.setClipboardHandler(new JSClipboardHandler(clipboardHandler)); - } - - public void setMolecule(JSMolecule molecule) { - mDrawArea.setMolecule(molecule.getStereoMolecule()); - } - - public JSMolecule getMolecule() { - return new JSMolecule(mDrawArea.getMolecule()); - } - - public void setReaction(JSReaction reaction) { - mDrawArea.setReaction(reaction.getReaction()); - } - - public JSReaction getReaction() { - return new JSReaction(mDrawArea.getReaction()); - } + private GenericEditorArea mDrawArea; + private JavaScriptObject mJsObject; + private JSMouseHandler mMouseHandler; + private JSKeyHandler mKeyHandler; + + public static final int MODE_MULTIPLE_FRAGMENTS = GenericEditorArea.MODE_MULTIPLE_FRAGMENTS; + public static final int MODE_MARKUSH_STRUCTURE = GenericEditorArea.MODE_MARKUSH_STRUCTURE; + public static final int MODE_REACTION = GenericEditorArea.MODE_REACTION; + public static final int MODE_DRAWING_OBJECTS = GenericEditorArea.MODE_DRAWING_OBJECTS; + + public static final int EDITOR_EVENT_MOLECULE_CHANGED = EditorEvent.WHAT_MOLECULE_CHANGED; + public static final int EDITOR_EVENT_SELECTION_CHANGED = EditorEvent.WHAT_SELECTION_CHANGED; + public static final int EDITOR_EVENT_HIGHLIGHT_ATOM_CHANGED = EditorEvent.WHAT_HILITE_ATOM_CHANGED; + public static final int EDITOR_EVENT_HIGHLIGHT_BOND_CHANGED = EditorEvent.WHAT_HILITE_BOND_CHANGED; + + public static final int MOUSE_EVENT_PRESSED = GenericMouseEvent.MOUSE_PRESSED; + public static final int MOUSE_EVENT_RELEASED = GenericMouseEvent.MOUSE_RELEASED; + public static final int MOUSE_EVENT_CLICKED = GenericMouseEvent.MOUSE_CLICKED; + public static final int MOUSE_EVENT_ENTERED = GenericMouseEvent.MOUSE_ENTERED; + public static final int MOUSE_EVENT_EXITED = GenericMouseEvent.MOUSE_EXITED; + public static final int MOUSE_EVENT_MOVED = GenericMouseEvent.MOUSE_MOVED; + public static final int MOUSE_EVENT_DRAGGED = GenericMouseEvent.MOUSE_DRAGGED; + + public static final int KEY_CTRL = GenericKeyEvent.KEY_CTRL; + public static final int KEY_ALT = GenericKeyEvent.KEY_ALT; + public static final int KEY_SHIFT = GenericKeyEvent.KEY_SHIFT; + public static final int KEY_DELETE = GenericKeyEvent.KEY_DELETE; + public static final int KEY_BACK_SPACE = GenericKeyEvent.KEY_BACK_SPACE; + public static final int KEY_HELP = GenericKeyEvent.KEY_HELP; + public static final int KEY_ESCAPE = GenericKeyEvent.KEY_ESCAPE; + + public static final int KEY_EVENT_PRESSED = GenericKeyEvent.KEY_PRESSED; + public static final int KEY_EVENT_RELEASED = GenericKeyEvent.KEY_RELEASED; + + public static final int cChainCursor = GenericCursorHelper.cChainCursor; + public static final int cDeleteCursor = GenericCursorHelper.cDeleteCursor; + public static final int cHandCursor = GenericCursorHelper.cHandCursor; + public static final int cHandPlusCursor = GenericCursorHelper.cHandPlusCursor; + public static final int cFistCursor = GenericCursorHelper.cFistCursor; + public static final int cLassoCursor = GenericCursorHelper.cLassoCursor; + public static final int cLassoPlusCursor = GenericCursorHelper.cLassoPlusCursor; + public static final int cSelectRectCursor = GenericCursorHelper.cSelectRectCursor; + public static final int cSelectRectPlusCursor = GenericCursorHelper.cSelectRectPlusCursor; + public static final int cZoomCursor = GenericCursorHelper.cZoomCursor; + public static final int cInvisibleCursor = GenericCursorHelper.cInvisibleCursor; + public static final int cPointerCursor = GenericCursorHelper.cPointerCursor; + public static final int cTextCursor = GenericCursorHelper.cTextCursor; + public static final int cPointedHandCursor = GenericCursorHelper.cPointedHandCursor; + public static final int[][] IMAGE_DATA_16 = GenericCursorHelper.IMAGE_DATA_16; + public static final int[] HOTSPOT_16 = GenericCursorHelper.HOTSPOT_16; + public static final int[] HOTSPOT_32 = GenericCursorHelper.HOTSPOT_32; + public static final String[] IMAGE_NAME_32 = GenericCursorHelper.IMAGE_NAME_32; + + public static final int TableLayoutPreferred = (int)TableLayout.PREFERRED; + public static final int TableLayoutFill = (int)TableLayout.FILL; + + public JSEditorArea(int mode, JavaScriptObject jsObject, JSUIHelper uiHelper) { + mDrawArea = new GenericEditorArea(new StereoMolecule(), mode, uiHelper, this); + mDrawArea.addDrawAreaListener(new GenericEventListener() { + @Override + public void eventHappened(EditorEvent e) { + callJsEventListener(e.getWhat(), e.isUserChange()); + } + }); + mJsObject = jsObject; + + mMouseHandler = new JSMouseHandler(mDrawArea); + mMouseHandler.addListener(mDrawArea); + + mKeyHandler = new JSKeyHandler(mDrawArea); + mKeyHandler.addListener(mDrawArea); + + JavaScriptObject clipboardHandler = getClipboardHandler(); + mDrawArea.setClipboardHandler(new JSClipboardHandler(clipboardHandler)); + } + + public void setMolecule(JSMolecule molecule) { + mDrawArea.setMolecule(molecule.getStereoMolecule()); + } + + public JSMolecule getMolecule() { + return new JSMolecule(mDrawArea.getMolecule()); + } + + public void setReaction(JSReaction reaction) { + mDrawArea.setReaction(reaction.getReaction()); + } + + public JSReaction getReaction() { + return new JSReaction(mDrawArea.getReaction()); + } - private native JavaScriptObject getClipboardHandler() + private native JavaScriptObject getClipboardHandler() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getOptions()(); - return options.getClipboardHandler(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getJsObject()(); + return jsObject.getClipboardHandler(); }-*/; private native JavaScriptObject callJsEventListener(int what, boolean isUserChange) /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getOptions()(); - return options.onChange(what, isUserChange); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getJsObject()(); + return jsObject.onChange(what, isUserChange); }-*/; - public void draw() { - mDrawArea.paintContent(getDrawContext()); - } + public void draw() { + mDrawArea.paintContent(getDrawContext()); + } - public GenericEditorArea getGenericEditorArea() { - return mDrawArea; - } + public GenericEditorArea getGenericEditorArea() { + return mDrawArea; + } - public void fireMouseEvent(int what, int button, int clickCount, int x, int y, boolean shiftDown, boolean ctrlDown, boolean altDown, boolean isPopupTrigger) { - GenericMouseEvent gme = new GenericMouseEvent(what, button, clickCount, x, y, shiftDown, ctrlDown, altDown, isPopupTrigger, mDrawArea); - mMouseHandler.fireEvent(gme); - } + public void fireMouseEvent(int what, int button, int clickCount, int x, int y, boolean shiftDown, boolean ctrlDown, boolean altDown, boolean isPopupTrigger) { + GenericMouseEvent gme = new GenericMouseEvent(what, button, clickCount, x, y, shiftDown, ctrlDown, altDown, isPopupTrigger, mDrawArea); + mMouseHandler.fireEvent(gme); + } - public void fireKeyEvent(int what, int key, boolean isAltDown, boolean isCtrlDown, boolean isShiftDown, boolean isMenuShortcut) { - GenericKeyEvent gke = new GenericKeyEvent(what, key, isAltDown, isCtrlDown, isShiftDown, isMenuShortcut, mDrawArea); - mKeyHandler.fireEvent(gke); - } + public void fireKeyEvent(int what, int key, boolean isAltDown, boolean isCtrlDown, boolean isShiftDown, boolean isMenuShortcut) { + GenericKeyEvent gke = new GenericKeyEvent(what, key, isAltDown, isCtrlDown, isShiftDown, isMenuShortcut, mDrawArea); + mKeyHandler.fireEvent(gke); + } - public void toolChanged(int newTool) { - mDrawArea.toolChanged(newTool); - } + public void toolChanged(int newTool) { + mDrawArea.toolChanged(newTool); + } - private JavaScriptObject getOptions() { - return mOptions; - } + private JavaScriptObject getJsObject() { + return mJsObject; + } - @Override - @JsIgnore - public native int getBackgroundRGB() + @Override + @JsIgnore + public native int getBackgroundRGB() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getOptions()(); - return options.getBackgroundRGB(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getJsObject()(); + return jsObject.getBackgroundRGB(); }-*/; - @Override - @JsIgnore - public native double getCanvasHeight() + @Override + @JsIgnore + public native double getCanvasHeight() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getOptions()(); - return options.getCanvasHeight(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getJsObject()(); + return jsObject.getCanvasHeight(); }-*/; - @Override - @JsIgnore - public native double getCanvasWidth() + @Override + @JsIgnore + public native double getCanvasWidth() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getOptions()(); - return options.getCanvasWidth(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getJsObject()(); + return jsObject.getCanvasWidth(); }-*/; - @Override - @JsIgnore - public GenericDrawContext getDrawContext() { - return new JSDrawContext(getDrawContextFromOptions()); - } + @Override + @JsIgnore + public GenericDrawContext getDrawContext() { + return new JSDrawContext(getDrawContextFromJsObject()); + } - private native JavaScriptObject getDrawContextFromOptions() + private native JavaScriptObject getDrawContextFromJsObject() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getOptions()(); - return options.getDrawContext(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorArea::getJsObject()(); + return jsObject.getDrawContext(); }-*/; - @Override - public void repaint() { - draw(); - } + @Override + public void repaint() { + draw(); + } } diff --git a/src/com/actelion/research/gwt/gui/generic/JSEditorToolbar.java b/src/com/actelion/research/gwt/gui/generic/JSEditorToolbar.java index 0e62e553..3c40ede5 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSEditorToolbar.java +++ b/src/com/actelion/research/gwt/gui/generic/JSEditorToolbar.java @@ -9,89 +9,89 @@ @JsType(name = "GenericEditorToolbar") public class JSEditorToolbar implements GenericCanvas { - private GenericEditorToolbar mGenericToolbar; - private JavaScriptObject mOptions; - private JSMouseHandler mMouseHandler; - - public JSEditorToolbar(JSEditorArea jsEditorArea, JavaScriptObject options) { - mGenericToolbar = new GenericEditorToolbar(this, jsEditorArea.getGenericEditorArea()); - mOptions = options; - - mMouseHandler = new JSMouseHandler(mGenericToolbar); - mMouseHandler.addListener(mGenericToolbar); - - setDimensions(mGenericToolbar.getWidth(), mGenericToolbar.getHeight()); - draw(); - } - - public int getWidth() { - return mGenericToolbar.getWidth(); - } - - public int getHeight() { - return mGenericToolbar.getHeight(); - } - - public void draw() { - JSDrawContext ctx = getDrawContext(); - ctx.clearRect(0, 0, getWidth(), getHeight()); - mGenericToolbar.paintContent(getDrawContext()); - } - - public void fireMouseEvent(int what, int button, int clickCount, int x, int y, boolean shiftDown, boolean ctrlDown, boolean altDown, boolean isPopupTrigger) { - GenericMouseEvent gme = new GenericMouseEvent(what, button, clickCount, x, y, shiftDown, ctrlDown, altDown, isPopupTrigger, mGenericToolbar); - mMouseHandler.fireEvent(gme); - } - - private JavaScriptObject getOptions() { - return mOptions; - } - - public native void setDimensions(int width, int height) + private GenericEditorToolbar mGenericToolbar; + private JavaScriptObject mJsObject; + private JSMouseHandler mMouseHandler; + + public JSEditorToolbar(JSEditorArea jsEditorArea, JavaScriptObject jsObject) { + mGenericToolbar = new GenericEditorToolbar(this, jsEditorArea.getGenericEditorArea()); + mJsObject = jsObject; + + mMouseHandler = new JSMouseHandler(mGenericToolbar); + mMouseHandler.addListener(mGenericToolbar); + + setDimensions(mGenericToolbar.getWidth(), mGenericToolbar.getHeight()); + draw(); + } + + public int getWidth() { + return mGenericToolbar.getWidth(); + } + + public int getHeight() { + return mGenericToolbar.getHeight(); + } + + public void draw() { + JSDrawContext ctx = getDrawContext(); + ctx.clearRect(0, 0, getWidth(), getHeight()); + mGenericToolbar.paintContent(getDrawContext()); + } + + public void fireMouseEvent(int what, int button, int clickCount, int x, int y, boolean shiftDown, boolean ctrlDown, boolean altDown, boolean isPopupTrigger) { + GenericMouseEvent gme = new GenericMouseEvent(what, button, clickCount, x, y, shiftDown, ctrlDown, altDown, isPopupTrigger, mGenericToolbar); + mMouseHandler.fireEvent(gme); + } + + private JavaScriptObject getJsObject() { + return mJsObject; + } + + public native void setDimensions(int width, int height) /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getOptions()(); - return options.setDimensions(width, height); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getJsObject()(); + return jsObject.setDimensions(width, height); }-*/; - @Override - @JsIgnore - public native int getBackgroundRGB() + @Override + @JsIgnore + public native int getBackgroundRGB() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getOptions()(); - return options.getBackgroundRGB(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getJsObject()(); + return jsObject.getBackgroundRGB(); }-*/; - @Override - @JsIgnore - public native double getCanvasHeight() + @Override + @JsIgnore + public native double getCanvasHeight() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getOptions()(); - return options.getCanvasHeight(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getJsObject()(); + return jsObject.getCanvasHeight(); }-*/; - @Override - @JsIgnore - public native double getCanvasWidth() + @Override + @JsIgnore + public native double getCanvasWidth() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getOptions()(); - return options.getCanvasWidth(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getJsObject()(); + return jsObject.getCanvasWidth(); }-*/; - @Override - @JsIgnore - public JSDrawContext getDrawContext() { - return new JSDrawContext(getDrawContextFromOptions()); - } + @Override + @JsIgnore + public JSDrawContext getDrawContext() { + return new JSDrawContext(getDrawContextFromJsObject()); + } - private native JavaScriptObject getDrawContextFromOptions() + private native JavaScriptObject getDrawContextFromJsObject() /*-{ - var options = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getOptions()(); - return options.getDrawContext(); + var jsObject = this.@com.actelion.research.gwt.gui.generic.JSEditorToolbar::getJsObject()(); + return jsObject.getDrawContext(); }-*/; - @Override - @JsIgnore - public void repaint() { - draw(); - } + @Override + @JsIgnore + public void repaint() { + draw(); + } } diff --git a/src/com/actelion/research/gwt/gui/generic/JSKeyHandler.java b/src/com/actelion/research/gwt/gui/generic/JSKeyHandler.java index ffa79bc5..c73d78b8 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSKeyHandler.java +++ b/src/com/actelion/research/gwt/gui/generic/JSKeyHandler.java @@ -1,9 +1,10 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericEventHandler; +import com.actelion.research.gui.generic.GenericKeyEvent; public class JSKeyHandler extends GenericEventHandler { - public JSKeyHandler(Object source) { - super(source); - } + public JSKeyHandler(Object source) { + super(source); + } } diff --git a/src/com/actelion/research/gwt/gui/generic/JSLabel.java b/src/com/actelion/research/gwt/gui/generic/JSLabel.java index 81517813..32656944 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSLabel.java +++ b/src/com/actelion/research/gwt/gui/generic/JSLabel.java @@ -1,6 +1,6 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericLabel; import com.google.gwt.core.client.JavaScriptObject; public class JSLabel extends JSComponent implements GenericLabel { @@ -9,7 +9,7 @@ public JSLabel(JavaScriptObject jsLabel) { } @Override - public native void setText(String text) + public native void setText(String text) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSLabel::getJsComponent()(); return component.setText(text); diff --git a/src/com/actelion/research/gwt/gui/generic/JSMouseHandler.java b/src/com/actelion/research/gwt/gui/generic/JSMouseHandler.java index 5b8e4f0d..d51cdc00 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSMouseHandler.java +++ b/src/com/actelion/research/gwt/gui/generic/JSMouseHandler.java @@ -1,9 +1,10 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericEventHandler; +import com.actelion.research.gui.generic.GenericMouseEvent; public class JSMouseHandler extends GenericEventHandler { - public JSMouseHandler(Object source) { - super(source); - } + public JSMouseHandler(Object source) { + super(source); + } } diff --git a/src/com/actelion/research/gwt/gui/generic/JSPolygon.java b/src/com/actelion/research/gwt/gui/generic/JSPolygon.java index 87903005..36120094 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSPolygon.java +++ b/src/com/actelion/research/gwt/gui/generic/JSPolygon.java @@ -1,14 +1,14 @@ package com.actelion.research.gwt.gui.generic; import com.actelion.research.gui.generic.GenericPolygon; - -import jsinterop.annotations.*; +import jsinterop.annotations.JsIgnore; +import jsinterop.annotations.JsType; @JsType(name = "Polygon") public class JSPolygon { private GenericPolygon mPolygon; - @JsIgnore + @JsIgnore JSPolygon(GenericPolygon polygon) { mPolygon = polygon; } diff --git a/src/com/actelion/research/gwt/gui/generic/JSRectangle.java b/src/com/actelion/research/gwt/gui/generic/JSRectangle.java index cb1f6a97..a20237ff 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSRectangle.java +++ b/src/com/actelion/research/gwt/gui/generic/JSRectangle.java @@ -1,8 +1,8 @@ package com.actelion.research.gwt.gui.generic; import com.actelion.research.gui.generic.GenericRectangle; - -import jsinterop.annotations.*; +import jsinterop.annotations.JsIgnore; +import jsinterop.annotations.JsType; @JsType(name = "Rectangle") public class JSRectangle { @@ -12,7 +12,7 @@ public class JSRectangle { mRectangle = new GenericRectangle(); } - public void set(double x, double y, double w, double h) { + public void set(double x, double y, double w, double h) { mRectangle.set(x, y, w, h); } diff --git a/src/com/actelion/research/gwt/gui/generic/JSTextField.java b/src/com/actelion/research/gwt/gui/generic/JSTextField.java index 06340a24..729366de 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSTextField.java +++ b/src/com/actelion/research/gwt/gui/generic/JSTextField.java @@ -1,6 +1,6 @@ package com.actelion.research.gwt.gui.generic; -import com.actelion.research.gui.generic.*; +import com.actelion.research.gui.generic.GenericTextField; import com.google.gwt.core.client.JavaScriptObject; public class JSTextField extends JSComponent implements GenericTextField { @@ -16,7 +16,7 @@ public native String getText() }-*/; @Override - public native void setText(String text) + public native void setText(String text) /*-{ var component = this.@com.actelion.research.gwt.gui.generic.JSTextField::getJsComponent()(); return component.setText(text); diff --git a/src/com/actelion/research/gwt/gui/generic/JSUIHelper.java b/src/com/actelion/research/gwt/gui/generic/JSUIHelper.java index 48897969..1e3ec5be 100644 --- a/src/com/actelion/research/gwt/gui/generic/JSUIHelper.java +++ b/src/com/actelion/research/gwt/gui/generic/JSUIHelper.java @@ -18,8 +18,8 @@ public JSUIHelper(JavaScriptObject jsObject) { } private JavaScriptObject getJsObject() { - return mJsObject; - } + return mJsObject; + } private native void registerToJs() /*-{ @@ -27,8 +27,8 @@ private native void registerToJs() jsObject.register(this); }-*/; - public void setEditorArea(JSEditorArea mEditorArea) { - this.mEditorArea = mEditorArea; + public void setEditorArea(JSEditorArea editorArea) { + mEditorArea = editorArea; } @Override diff --git a/types.d.ts b/types.d.ts index 1c386e0f..49567877 100644 --- a/types.d.ts +++ b/types.d.ts @@ -3706,12 +3706,19 @@ export interface OnChangeEvent { export type OnChangeListenerCallback = (event: OnChangeEvent) => void; +export type CanvasEditorMode = 'molecule' | 'reaction'; + export interface CanvasEditorOptions { /** * No toolbar and user interactions are ignored. * @default false */ readOnly?: boolean; + /** + * Mode in which the editor will be initialized. + * @default 'molecule' + */ + initialMode?: CanvasEditorMode; } export declare class CanvasEditor {