Skip to content

Commit

Permalink
#4 Swing UI - retire legacy JTreeTable
Browse files Browse the repository at this point in the history
  • Loading branch information
amosshi committed Sep 22, 2019
1 parent 5f340a3 commit 72c8d55
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 1,575 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,27 @@
*/
package org.freeinternals.biv;

import java.awt.Component;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import org.freeinternals.commonlib.core.FileFormat;
import org.freeinternals.biv.plugin.PluginManager;
import org.freeinternals.commonlib.ui.JBinaryViewer;
import org.freeinternals.commonlib.ui.UITool;
import org.freeinternals.commonlib.ui.JPanelForTree;
import org.freeinternals.commonlib.ui.JTreeCellRenderer;
import org.freeinternals.commonlib.ui.JTreeNodeFileComponent;
import org.freeinternals.commonlib.core.FileFormatException;

Expand All @@ -47,9 +48,9 @@ public class JSplitPaneFile extends JSplitPane {
*
* @param file
* @param frame
* @throws FileFormatException
* @throws FileFormatException
*/
public JSplitPaneFile(final File file, final JFrame frame) throws FileFormatException, Throwable{
public JSplitPaneFile(final File file, final JFrame frame) throws FileFormatException, Throwable {
this.file = PluginManager.getFile(file);
this.topLevelFrame = frame;
this.createAndShowGUI();
Expand All @@ -63,14 +64,39 @@ private void createAndShowGUI() {
this.file.fileName));
this.file.generateTreeNode(root);
final JTree tree = new JTree(new DefaultTreeModel(root));
tree.setCellRenderer(new JTreeCellRenderer());
tree.addTreeSelectionListener(new TreeSelectionListener() {

tree.setCellRenderer(new DefaultTreeCellRenderer() {

@Override
public void valueChanged(final javax.swing.event.TreeSelectionEvent evt) {
treeSelectionChanged(evt);
public Component getTreeCellRendererComponent(final JTree tree, final Object value,
final boolean sel, final boolean expanded, final boolean leaf, final int row,
final boolean hasFocus) {

super.getTreeCellRendererComponent(tree, value,
sel, expanded, leaf, row,
hasFocus);

if (value instanceof DefaultMutableTreeNode) {
if (((DefaultMutableTreeNode) value).getUserObject() instanceof JTreeNodeFileComponent) {
JTreeNodeFileComponent fileComp = (JTreeNodeFileComponent) ((DefaultMutableTreeNode) value).getUserObject();
final Icon icon = fileComp.getIcon();
if (icon != null) {
this.setIcon(icon);
}

if (fileComp.isDetailAvailable()) {
this.setText("<html><font color=blue><u>" + fileComp.getText());
} else {
this.setText(fileComp.getText());
}
}
}

return this;
}
});

tree.addTreeSelectionListener(this::treeSelectionChanged);
tree.addMouseListener(new MouseAdapter() {

@Override
Expand All @@ -91,7 +117,6 @@ public void mousePressed(MouseEvent e) {
}
});


final JPanelForTree panel = new JPanelForTree(tree, this.topLevelFrame);

final JTabbedPane tabbedPane = new JTabbedPane();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package org.freeinternals.commonlib.ui;

import java.awt.BorderLayout;
import java.awt.Component;
import java.io.InputStream;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
Expand Down

This file was deleted.

Loading

0 comments on commit 72c8d55

Please sign in to comment.