Hi,
I am using the javahexeditor as eclipse plugin. After resizing the view with the hexeditor an additional columns showing up (see the screenshot). A user can click on the righmost column (green bordered on the screenshot) and produce an exception. This only produces an error in the eclipse error log, but when a user than clicks on one of the hex values an error dialog pops up.
In this gif you can see how to reproduce the issue: https://1drv.ms/u/s!AhiI0xDdcEFsgdJozgtMaf2a49N5TA?e=4JHn3i
The incorrect layout shows up after the layout()-call in HexTexts.java on line 2098.
layout(new Control[] { header1Text, styledText, styledText1, styledText2 }, SWT.DEFER);
This is the exception after clicking in the rightmost column.
java.lang.IllegalArgumentException: Parameter start must not be negative, specified value is -1 at net.sourceforge.javahexeditor.BinaryContent$RangeSelection.<init>(BinaryContent.java:65) at net.sourceforge.javahexeditor.HexTexts.getSelection(HexTexts.java:1277) at net.sourceforge.javahexeditor.Manager.isTextSelected(Manager.java:559) at net.sourceforge.javahexeditor.plugin.editors.HexEditor.updateActionsStatus(HexEditor.java:480) at net.sourceforge.javahexeditor.plugin.editors.HexEditor$2.handleEvent(HexEditor.java:225) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4221) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1037) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1046) at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:760) at net.sourceforge.javahexeditor.HexTexts$MyMouseAdapter.mouseDown(HexTexts.java:377) at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:196) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89) at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4221) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1037) at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4038) at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3638) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1157) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046) at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155) at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:657) at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338) at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:556) at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:153) at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:150) at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:401) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:657) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:594) at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
I have been investigating the problem for the last few days, but have not been able to find any hot lead.
This are the steps to reproduce the error
1. Open a file in the hexeditor
2. click into the hex values or ascii values area.
3. change the size of the view the editor is shown in. This triggers the controlResized-event which contains the updateTextmertics() with the layout().
4. the superflous column should now show up.
5. click in the rightmost column (there are no hex values shown. You can see the area when selecting a textblock over multiple lines.)
6. Take a look into the error log, the exception should be shown there.
Note: Does not occur in 4.7.x but in 4.16.x. Will have to setup a 4.16 SDK environement to verify.
I can produce the error on Version:
- 2020-09 M2 (4.17.0 M2) Build id: 20200806-2245 This is the latest Eclipse IDE
- 2019-09 4.13.0.v20190916-1045
Fix part 1: Handle clicks outside of text area gracefully.
Commit e63a3486a09031c4155f37ce6c616eb91181d05f.
Last edit: Peter Dell 2020-08-09
Hello Thorben,
Fix part 2: https://sourceforge.net/p/javahexeditor/git/ci/123bbf3e745d7e612aed07791a2aa80f38131cb7/
I have reworked the whole handling of size/layout/drawing of the styled text fields.
Here is looks now OK in both standalone and plugin versions.
It would be great if you could have a look and test it a little.
Latest builds are uploaded.
Please regards, Peter.
Hi Peter,
Wow :) thanks a lot. I spend much time on trying to solve this but did not get it.
I tested it and it works fine. No nasty error anymore when clicking in the rightmost area of the ascii text.
The problem is not fixed, it's just better handled (is enough), but do you have an idea where the error could be. I'd go back to it then?
One thing I found, but is no major problem. See the Screenshot in the attachments.
Thanks again. This has solved the last problem that prevented the migration of the hex editors in JCrypTool.
Best regards,
Thorben
I took the layout apart and wondered why there are these superfluous columns. Do you have any ideas?
Do you really have the latest version?
I have changed the PaintListener to draw a wide border between the styledText1 & 2.
That is required, because the line selection/block selection extends to the full character width.
This is how is looks on my side.
Interestingly the problem does not occur at all in the standalone version for me.
But I also did'nt find the root cause, but adapted the layout instead,
Maybe it has to do with the width of the styledText 1.
I should probably be 3*myBytePerLine-1 characters, because the last space it not required to eb drawn,
Last edit: Peter Dell 2020-08-11
Hi Peter,
I use the latest version, but I changed the wider borders back to the character width to be able to see the borders of the styled texts. Else they would be hidden by the borders painted by the paint listenern.
I changed the width of styledText1 and styledText2:
and
Now it works fine, see the screenshot
I will adapt the code and create a Merge Request via git.
I tried to push the code via git, but got an error. Therefore the old style: In the attachements is the adjusted code.
I tested the standalone and the eclipse version, both work fine now.
Excellent, that is a much better solution now. It's great to have somebody with such a good SWT knowledge. Merged and site updated. So it finally pays off that I've spent 2 day on the the build scripts and process.
Regarding pull requests: I've not yet done that with git, so attachements are just fine for me.