mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
GT-3197 - Call Trees - fixed bugs: multiple icons appearing in the
toolbar; custom icons were not rendering in the help content
This commit is contained in:
parent
2ce191d865
commit
ea8e2a81c6
5 changed files with 203 additions and 57 deletions
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
package docking.help;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.*;
|
||||
|
@ -24,6 +25,7 @@ import java.util.List;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.event.HyperlinkEvent;
|
||||
import javax.swing.event.HyperlinkListener;
|
||||
|
@ -378,10 +380,68 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
|
|||
*/
|
||||
private class GHelpImageView extends ImageView {
|
||||
|
||||
/*
|
||||
* Unusual Code Alert!
|
||||
* This class exists to enable our help system to find custom icons defined in source
|
||||
* code. The default behavior herein is to supply a URL to the base class to load. This
|
||||
* works fine.
|
||||
*
|
||||
* There is another use case where we wish to have the base class load an image of our
|
||||
* choosing. Why? Well, we modify, in memory, some icons we use. We do this for things
|
||||
* like overlays and rotations.
|
||||
*
|
||||
* In order to have our base class use the image that we want (and not the one
|
||||
* it loads via a URL), we have to play a small game. We have to allow the base class
|
||||
* to load the image it wants, which is done asynchronously. If we install our custom
|
||||
* image during that process, the loading will throw away the image and not render
|
||||
* anything.
|
||||
*
|
||||
* To get the base class to use our image, we override getImage(). However, we should
|
||||
* only return our image when the base class is finished loaded. (See the base class'
|
||||
* paint() method for why we need to do this.)
|
||||
*
|
||||
* Note: if we start seeing unusual behavior, like images not rendering, or any size
|
||||
* issues, then we can revert this code.
|
||||
*/
|
||||
private Image image;
|
||||
private float spanX;
|
||||
private float spanY;
|
||||
|
||||
public GHelpImageView(Element elem) {
|
||||
super(elem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage() {
|
||||
Image superImage = super.getImage();
|
||||
if (image == null) {
|
||||
// no custom image
|
||||
return superImage;
|
||||
}
|
||||
|
||||
if (isLoading()) {
|
||||
return superImage;
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
private boolean isLoading() {
|
||||
return spanX < 1 || spanY < 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPreferredSpan(int axis) {
|
||||
float span = super.getPreferredSpan(axis);
|
||||
if (axis == View.X_AXIS) {
|
||||
spanX = span;
|
||||
}
|
||||
else {
|
||||
spanY = span;
|
||||
}
|
||||
return span;
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL getImageURL() {
|
||||
|
||||
|
@ -407,6 +467,9 @@ public class GHelpHTMLEditorKit extends HTMLEditorKit {
|
|||
return null;
|
||||
}
|
||||
|
||||
ImageIcon imageIcon = iconProvider.getIcon();
|
||||
this.image = imageIcon.getImage();
|
||||
|
||||
URL url = iconProvider.getOrCreateUrl();
|
||||
return url;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue