Skip to content

Commit

Permalink
#9 Class format - UI icon and desc
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Aug 30, 2021
1 parent f8a0826 commit 5c9dba7
Show file tree
Hide file tree
Showing 60 changed files with 526 additions and 147 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* JTreeJPEGFile.java September 01, 2010, 23:57
* GenerateTreeNode.java September 01, 2010, 23:57
*
* Copyright 2010, FreeInternals.org. All rights reserved.
* Use is subject to license terms.
Expand All @@ -20,6 +20,6 @@ public interface GenerateTreeNode {
*
* @param parentNode Parent tree node
*/
void generateTreeNode(DefaultMutableTreeNode parentNode);
void generateTreeNode(final DefaultMutableTreeNode parentNode);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* GenerateTreeNodeFileFormat.java August 29, 2021, 23:44
*
* Copyright 2021, FreeInternals.org. All rights reserved.
* Use is subject to license terms.
*/
package org.freeinternals.commonlib.ui;

import java.util.ResourceBundle;
import javax.swing.Icon;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;

/**
* Interface for generating children tree nodes.
*
* @author Amos Shi
*/
public interface GenerateTreeNodeFileFormat {

void generateTreeNode(final DefaultMutableTreeNode parentNode, FileFormat fileFormat);

/**
* Get the messages resource of current file format.
*
* @return {@link ResourceBundle} for messages, or <code>null</code> if not
* exist
*/
ResourceBundle getMessages();

default DefaultMutableTreeNode addNode(DefaultMutableTreeNode parentNode, int startPos, int len, String fieldName, Object value, String msgkey, Icon icon) {
JTreeNodeFileComponent fileComp = new JTreeNodeFileComponent(
startPos,
len,
fieldName + ": " + value.toString()
);
if (msgkey != null) {
fileComp.setDescription(getMessages().getString(msgkey));
}
fileComp.setIcon(icon);

DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileComp);
parentNode.add(node);
return node;
}
}
10 changes: 10 additions & 0 deletions CommonLib/src/main/java/org/freeinternals/commonlib/ui/UITool.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,16 @@ public static Icon icon4Method() {
return icon("/image/icons8-mechanistic-analysis-16.png");
}

/**
* Icon for Name.
*
* @return Icon for Name
* @see <a href="https://icons8.com/icon/zbNHwSyrej7I/name-tag">Name Tag</a> icon by <a href="https://icons8.com">Icons8</a>
*/
public static Icon icon4Name() {
return icon("/image/icons8-name-tag-16.png");
}

/**
* Icon for Offset / Location / Index.
*
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@

import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.ui.GenerateTreeNodeFileFormat;

/**
* Interface for generating tree node for {@link ClassFile}.
*
* @author Amos Shi
*/
public interface GenerateTreeNodeClassFile {
public interface GenerateTreeNodeClassFile extends GenerateTreeNodeFileFormat {

ResourceBundle MESSAGES = ResourceBundle.getBundle(GenerateTreeNodeClassFile.class.getPackageName() + ".MessagesBundle", Locale.ROOT);

void generateTreeNode(final DefaultMutableTreeNode parentNode, ClassFile classFile);

@Override
default ResourceBundle getMessages() {
return MESSAGES;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -60,14 +61,14 @@ public class AnnotationDefault_attribute extends attribute_info {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
DefaultMutableTreeNode defaultValueNode = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 6,
this.getLength() - 6,
"default_value"
));
parentNode.add(defaultValueNode);
Annotation.generateSubnode(defaultValueNode, this.default_value, classFile);

Annotation.generateSubnode(defaultValueNode, this.default_value, (ClassFile)classFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileComponent;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.FileFormatException;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
Expand Down Expand Up @@ -81,7 +82,7 @@ public class BootstrapMethods_attribute extends attribute_info {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, final FileFormat classFile) {
int startPosMoving = this.getStartPos();

parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
Expand All @@ -105,7 +106,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile
String.format("bootstrap_method %d", i + 1)
));
bootstrapMethodsNode.add(bootstrapMethod);
this.generateSubnode(bootstrapMethod, m, classFile);
this.generateSubnode(bootstrapMethod, m, (ClassFile)classFile);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.core.FileFormatException;
import org.freeinternals.format.classfile.ClassFile;
import org.freeinternals.format.classfile.u2;

/**
Expand Down Expand Up @@ -54,7 +54,7 @@ public class Bridge_attribute extends attribute_info {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
// Nothing to add
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -68,7 +69,7 @@ public class Classes_attribute extends attribute_info {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
int startPosMoving = super.startPos + 6;

parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
Expand All @@ -91,7 +92,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
numbersNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPosMoving + i * u2.LENGTH,
u2.LENGTH,
"class " + (i + 1) + ": " + classIndex + " - " + classFile.getCPDescription(classIndex)
"class " + (i + 1) + ": " + classIndex + " - " + ((ClassFile)classFile).getCPDescription(classIndex)
)));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.List;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileComponent;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -145,7 +146,7 @@ public ExceptionTable getExceptionTable(final int index) {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, final FileFormat classFile) {
int i;
final int codeLength = this.code_length.value;
DefaultMutableTreeNode treeNodeExceptionTable;
Expand Down Expand Up @@ -196,7 +197,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile
et.getLength(),
String.format("exception_table [%d]", i)
));
this.generateSubnode(treeNodeExceptionTableItem, et, classFile);
this.generateSubnode(treeNodeExceptionTableItem, et, (ClassFile)classFile);
treeNodeExceptionTable.add(treeNodeExceptionTableItem);
}

Expand Down Expand Up @@ -230,7 +231,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile
attr.getLength(),
(i + 1) + ". " + attr.getName()
));
attribute_info.generateTreeNode(treeNodeAttributeItem, attr, classFile);
attribute_info.generateTreeNode(treeNodeAttributeItem, attr, (ClassFile)classFile);

treeNodeAttribute.add(treeNodeAttributeItem);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -61,12 +62,12 @@ public class ConstantValue_attribute extends attribute_info {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
int index = this.constantvalue_index.value;
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
super.startPos + 6,
2,
"constantvalue_index: " + index + " - " + classFile.getCPDescription(index)
"constantvalue_index: " + index + " - " + ((ClassFile)classFile).getCPDescription(index)
)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.core.FileFormatException;
import org.freeinternals.format.classfile.ClassFile;
import org.freeinternals.format.classfile.u2;

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ public class Deprecated_attribute extends attribute_info {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
// Nothing to add
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -63,7 +64,8 @@ public class EnclosingMethod_attribute extends attribute_info {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) {
ClassFile classFile = (ClassFile) format;
int startPosMoving = super.startPos + 6;
parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPosMoving,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -95,7 +96,7 @@ public int getExceptionIndexTableItem(final int index) {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
int i;
final int numOfExceptions = this.number_of_exceptions.value;
DefaultMutableTreeNode treeNodeExceptions;
Expand All @@ -116,7 +117,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classF
treeNodeExceptions.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
startPos + 10 + i * 2,
2,
String.format("exception_index_table[%d]: cp_index=%d - %s", i, cpIndex, classFile.getCPDescription(cpIndex))
String.format("exception_index_table[%d]: cp_index=%d - %s", i, cpIndex, ((ClassFile)classFile).getCPDescription(cpIndex))
)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.BytesTool;
import org.freeinternals.commonlib.core.FileComponent;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -87,7 +88,7 @@ public Class getClass(final int index) {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, final FileFormat classFile) {
int i;
final int numOfClasses = this.number_of_classes.value;
DefaultMutableTreeNode treeNodeInnerClass;
Expand All @@ -111,7 +112,7 @@ public void generateTreeNode(DefaultMutableTreeNode parentNode, final ClassFile
treeNodeInnerClassItem = new DefaultMutableTreeNode(new JTreeNodeFileComponent(
cls.getStartPos(),
cls.getLength(),
String.format("class %d: %s", i + 1, classFile.getCPDescription(cls.inner_class_info_index.value))
String.format("class %d: %s", i + 1, ((ClassFile)classFile).getCPDescription(cls.inner_class_info_index.value))
));
cls.generateTreeNode(treeNodeInnerClassItem, classFile);
treeNodeInnerClass.add(treeNodeInnerClassItem);
Expand Down Expand Up @@ -187,7 +188,8 @@ public String getModifiers() {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat format) {
ClassFile classFile = (ClassFile) format;
final int startPosMoving = this.getStartPos();

int cpIndex = this.inner_class_info_index.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.IOException;
import javax.swing.tree.DefaultMutableTreeNode;
import org.freeinternals.commonlib.core.FileComponent;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.commonlib.core.PosDataInputStream;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;
Expand Down Expand Up @@ -81,7 +82,7 @@ public LineNumberTable getLineNumberTable(final int index) {
}

@Override
public void generateTreeNode(DefaultMutableTreeNode parentNode, ClassFile classFile) {
public void generateTreeNode(DefaultMutableTreeNode parentNode, FileFormat classFile) {
final int lnt_length = this.line_number_table_length.value;

parentNode.add(new DefaultMutableTreeNode(new JTreeNodeFileComponent(
Expand Down
Loading

0 comments on commit 5c9dba7

Please sign in to comment.