From 42f89ac260d7c4ebd0b2d3a228d298e7ac8bb245 Mon Sep 17 00:00:00 2001 From: Jared Gould Date: Tue, 4 Jul 2006 18:36:32 +0000 Subject: [PATCH] Improved rom tree display -- still need to fix table name font git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@84 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d --- src/enginuity/swing/ECUEditorToolBar.java | 8 +- src/enginuity/swing/RomCellRenderer.java | 113 ++++++++++++++++++++++ src/enginuity/swing/RomTreeNode.java | 2 +- src/enginuity/swing/TableTreeNode.java | 3 +- 4 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 src/enginuity/swing/RomCellRenderer.java diff --git a/src/enginuity/swing/ECUEditorToolBar.java b/src/enginuity/swing/ECUEditorToolBar.java index 1641fd47..88061283 100644 --- a/src/enginuity/swing/ECUEditorToolBar.java +++ b/src/enginuity/swing/ECUEditorToolBar.java @@ -32,13 +32,13 @@ public class ECUEditorToolBar extends JToolBar implements ActionListener { this.add(refreshImage); openImage.setMaximumSize(new Dimension(58,50)); - openImage.setBorder(new LineBorder(new Color(150,150,150), 1)); + openImage.setBorder(new LineBorder(new Color(150,150,150), 0)); saveImage.setMaximumSize(new Dimension(50,50)); - saveImage.setBorder(new LineBorder(new Color(150,150,150), 1)); + saveImage.setBorder(new LineBorder(new Color(150,150,150), 0)); closeImage.setMaximumSize(new Dimension(50,50)); - closeImage.setBorder(new LineBorder(new Color(150,150,150), 1)); + closeImage.setBorder(new LineBorder(new Color(150,150,150), 0)); refreshImage.setMaximumSize(new Dimension(50,50)); - refreshImage.setBorder(new LineBorder(new Color(150,150,150), 1)); + refreshImage.setBorder(new LineBorder(new Color(150,150,150), 0)); updateButtons(); diff --git a/src/enginuity/swing/RomCellRenderer.java b/src/enginuity/swing/RomCellRenderer.java new file mode 100644 index 00000000..0ca1cf16 --- /dev/null +++ b/src/enginuity/swing/RomCellRenderer.java @@ -0,0 +1,113 @@ +package enginuity.swing; + +import enginuity.maps.Rom; +import enginuity.maps.Table; +import java.awt.Color; +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Font; +import java.awt.GridLayout; +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTree; +import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeCellRenderer; +import javax.swing.tree.TreeCellRenderer; + +public class RomCellRenderer implements TreeCellRenderer { + + JLabel fileName; + JLabel carInfo; + DefaultTreeCellRenderer defaultRenderer = new DefaultTreeCellRenderer(); + Color background = new Color(255,210,210); + + public RomCellRenderer() { + fileName = new JLabel(" "); + fileName.setFont(new Font("Tahoma", Font.BOLD, 11)); + fileName.setHorizontalAlignment(JLabel.CENTER); + + carInfo = new JLabel(" "); + carInfo.setFont(new Font("Tahoma", Font.PLAIN, 10)); + carInfo.setHorizontalAlignment(JLabel.CENTER); + + } + + public Component getTreeCellRendererComponent(JTree tree, Object value, + boolean selected, boolean expanded, boolean leaf, int row, + boolean hasFocus) { + + Component returnValue = null; + + if (value != null && value instanceof RomTreeNode) { + + Object userObject = ((DefaultMutableTreeNode)value).getUserObject(); + + if (userObject instanceof Rom) { + Rom rom = (Rom) userObject; + + if (expanded) fileName.setText("- " + rom.getFileName()); + else fileName.setText("+ " + rom.getFileName()); + + + carInfo.setText(rom.getRomIDString() + ", " + + rom.getRomID().getCaseId() + "; " + + rom.getRomID().getYear() + " " + + rom.getRomID().getMake() + " " + + rom.getRomID().getModel() + " " + + rom.getRomID().getSubModel() + ", " + + rom.getRomID().getTransmission() + ); + + JPanel renderer = new JPanel(new GridLayout(2,1)); + renderer.add(fileName); + renderer.add(carInfo); + renderer.setBorder(BorderFactory.createLineBorder(new Color(220,0,0))); + + renderer.setPreferredSize(new Dimension(tree.getParent().getWidth(), 30)); + renderer.setMaximumSize(new Dimension(tree.getParent().getWidth(), 30)); + renderer.setBackground(background); + renderer.setEnabled(tree.isEnabled()); + returnValue = renderer; + } + + } else if (value != null && value instanceof TableTreeNode) { + + Table table = (Table)((DefaultMutableTreeNode)value).getUserObject(); + JPanel renderer = new JPanel(new GridLayout(1,1)); + renderer.setBorder(BorderFactory.createLineBorder(Color.WHITE)); + JLabel tableName = new JLabel(""); + tableName.setFont(new Font("Tahoma", Font.PLAIN, 11)); + renderer.setBackground(Color.WHITE); + + // display icon + if (table.getType() == Table.TABLE_1D) { + tableName = new JLabel(table.getName(), new ImageIcon("./graphics/1d.gif"), JLabel.LEFT); + } else if (table.getType() == Table.TABLE_2D) { + tableName = new JLabel(table.getName(), new ImageIcon("./graphics/2d.gif"), JLabel.LEFT); + } else if (table.getType() == Table.TABLE_3D) { + tableName = new JLabel(table.getName(), new ImageIcon("./graphics/3d.gif"), JLabel.LEFT); + } else if (table.getType() == Table.TABLE_SWITCH) { + tableName = new JLabel(table.getName(), new ImageIcon("./graphics/switch.gif"), JLabel.LEFT); + } + + // set color + if (selected) { + renderer.setBackground(new Color(220,220,255)); + renderer.setBorder(BorderFactory.createLineBorder(new Color(0,0,225))); + } + + renderer.add(tableName); + returnValue = renderer; + } + + if (returnValue == null) { + returnValue = defaultRenderer.getTreeCellRendererComponent(tree, + value, selected, expanded, leaf, row, hasFocus); + } + + return returnValue; + + } +} \ No newline at end of file diff --git a/src/enginuity/swing/RomTreeNode.java b/src/enginuity/swing/RomTreeNode.java index dca7ffe2..8ddf00b5 100644 --- a/src/enginuity/swing/RomTreeNode.java +++ b/src/enginuity/swing/RomTreeNode.java @@ -32,7 +32,7 @@ public class RomTreeNode extends DefaultMutableTreeNode { if (getChildAt(j).toString().equals(table.getCategory())) { // add to appropriate category - TableTreeNode tableNode = new TableTreeNode(table); + TableTreeNode tableNode = new TableTreeNode(table); getChildAt(j).add(tableNode); categoryExists = true; break; diff --git a/src/enginuity/swing/TableTreeNode.java b/src/enginuity/swing/TableTreeNode.java index 63872a14..d9bc1c86 100644 --- a/src/enginuity/swing/TableTreeNode.java +++ b/src/enginuity/swing/TableTreeNode.java @@ -13,7 +13,8 @@ public class TableTreeNode extends DefaultMutableTreeNode { private TableFrame frame; public TableTreeNode(Table table) { - super(table.getName() + " (" + table.getType() + "D)"); + //super(table.getName() + " (" + table.getType() + "D)"); + super(table); this.table = table; this.frame = table.getFrame(); }