JDK 9 Compatible

This removes the sun package dependency
This commit is contained in:
Konloch 2021-07-11 07:37:05 -07:00
parent c2a9c0f51e
commit 46bee607aa
2 changed files with 58 additions and 7 deletions

View File

@ -1,7 +1,5 @@
package the.bytecode.club.bytecodeviewer.gui.resourcelist;
//TODO fix for Java 9+
import com.sun.java.swing.plaf.windows.WindowsTreeUI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
@ -29,6 +27,7 @@ import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import org.objectweb.asm.tree.ClassNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.resources.IconResources;
import the.bytecode.club.bytecodeviewer.translation.TranslatedStrings;
import the.bytecode.club.bytecodeviewer.translation.Translation;
import the.bytecode.club.bytecodeviewer.translation.components.TranslatedJCheckBox;
@ -87,17 +86,14 @@ public class ResourceListPane extends TranslatedVisibleComponent implements File
rightClickMenu.add(new ResourceListRightClickRemove(this, x, y, tree));
//TODO fix for Java 9+
// You can replace this with any Icon loaded from disk,
// they could be re-used for the plus and minus symbols on the resource list too
rightClickMenu.add(new AbstractAction("Expand", WindowsTreeUI.ExpandedIcon.createExpandedIcon()) {
rightClickMenu.add(new AbstractAction("Expand", IconResources.CollapsedIcon.createCollapsedIcon()) {
@Override
public void actionPerformed(ActionEvent e) {
TreePath selPath = ResourceListPane.this.tree.getPathForLocation(x, y);
expandAll(tree, Objects.requireNonNull(selPath), true);
}
});
rightClickMenu.add(new AbstractAction("Collapse", WindowsTreeUI.CollapsedIcon.createCollapsedIcon()) {
rightClickMenu.add(new AbstractAction("Collapse", IconResources.ExpandedIcon.createExpandedIcon()) {
@Override
public void actionPerformed(ActionEvent e) {
TreePath selPath = ResourceListPane.this.tree.getPathForLocation(x, y);

View File

@ -1,8 +1,10 @@
package the.bytecode.club.bytecodeviewer.resources;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -41,6 +43,9 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer;
public class IconResources
{
static protected final int HALF_SIZE = 4;
static protected final int SIZE = 9;
public static List<BufferedImage> iconList;
public static BufferedImage icon;
public static ImageIcon nextIcon;
@ -131,4 +136,54 @@ public class IconResources
return image;
}
/**
* The minus sign button icon
*/
public static class ExpandedIcon implements Icon, Serializable
{
static public Icon createExpandedIcon() {
return new ExpandedIcon();
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
Color backgroundColor = c.getBackground();
if(backgroundColor != null)
g.setColor(backgroundColor);
else
g.setColor(Color.white);
g.fillRect(x, y, SIZE-1, SIZE-1);
g.setColor(Color.gray);
g.drawRect(x, y, SIZE-1, SIZE-1);
g.setColor(Color.black);
g.drawLine(x + 2, y + HALF_SIZE, x + (SIZE - 3), y + HALF_SIZE);
}
public int getIconWidth() {
return SIZE;
}
public int getIconHeight() {
return SIZE;
}
}
/**
* The plus sign button icon
*/
public static class CollapsedIcon extends ExpandedIcon
{
static public Icon createCollapsedIcon() {
return new CollapsedIcon();
}
public void paintIcon(Component c, Graphics g, int x, int y)
{
super.paintIcon(c, g, x, y);
g.drawLine(x + HALF_SIZE, y + 2, x + HALF_SIZE, y + (SIZE - 3));
}
}
}