From 2a884fabc89383b36aff1bba15ead1d0e09de19d Mon Sep 17 00:00:00 2001 From: Robert S Date: Thu, 12 Jun 2014 04:04:45 -0400 Subject: [PATCH] Updated MechanicalNodeFrame to extends FrameNodeDebug --- .../energy/grid/MechanicalNodeFrame.java | 229 ++++++------------ .../core/debug/FrameDebug.java | 53 +++- .../core/debug/FrameNodeDebug.java | 51 ++++ .../core/debug/UpdatePanel.java | 8 +- 4 files changed, 177 insertions(+), 164 deletions(-) create mode 100644 src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNodeFrame.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNodeFrame.java index 2a034db9d..1998ff6f5 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNodeFrame.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNodeFrame.java @@ -1,126 +1,33 @@ package resonantinduction.mechanical.energy.grid; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Frame; import java.awt.GridLayout; import java.awt.Label; import java.awt.Panel; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.ArrayList; -import java.util.List; import java.util.Map.Entry; import net.minecraftforge.common.ForgeDirection; +import resonant.api.grid.INode; +import resonant.api.grid.INodeProvider; +import resonantinduction.core.debug.FrameNodeDebug; import resonantinduction.core.debug.UpdatedLabel; /** Java GUI used to help debug gear information * * @author Darkguardsman */ @SuppressWarnings("serial") -public class MechanicalNodeFrame extends Frame implements ActionListener +public class MechanicalNodeFrame extends FrameNodeDebug { - List dataLabels = new ArrayList(); - Label[] connections = new Label[10]; + Label[] connections; - long tick = 0; - private PartMechanical partMechanical = null; - private TileMechanical tileMechanical = null; - - public MechanicalNodeFrame(TileMechanical tile) - { - this(); - this.tileMechanical = tile; - - } - - public MechanicalNodeFrame(PartMechanical part) + public MechanicalNodeFrame(INodeProvider node) { - this(); - this.partMechanical = part; - } - - protected MechanicalNodeFrame() - { - setLayout(new BorderLayout()); - setBackground(Color.LIGHT_GRAY); - this.createBottomBar(); - this.createTopBar(); - - //Middle bar - Panel middlePanel = new Panel(new GridLayout(3, 1, 0, 0)); - - UpdatedLabel velLabel = new UpdatedLabel("Vel: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + MechanicalNodeFrame.this.getNode().angularVelocity; - } - }; - dataLabels.add(velLabel); - middlePanel.add(velLabel); - - UpdatedLabel angleLabel = new UpdatedLabel("Angle: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + MechanicalNodeFrame.this.getNode().renderAngle; - } - }; - dataLabels.add(angleLabel); - middlePanel.add(angleLabel); - - UpdatedLabel torqueLabel = new UpdatedLabel("Torque: ") - { - @Override - public String buildLabel() - { - return super.buildLabel() + MechanicalNodeFrame.this.getNode().torque; - } - }; - dataLabels.add(torqueLabel); - middlePanel.add(torqueLabel); - - add(middlePanel, BorderLayout.WEST); - - Panel connectionPanel = new Panel(new GridLayout(this.connections.length / 2, 2, 0, 0)); - for (int i = 0; i < connections.length; i++) - { - this.connections[i] = new Label("Connection" + i + ": ----"); - connectionPanel.add(connections[i]); - } - add(connectionPanel, BorderLayout.EAST); - - //exit icon handler - addWindowListener(new WindowAdapter() - { - public void windowClosing(WindowEvent e) - { - Frame f = (Frame) e.getSource(); - f.setVisible(false); - f.dispose(); - } - }); + super(node, MechanicalNode.class); } - public MechanicalNode getNode() + @Override + public void buildTop(Panel panel) { - if(partMechanical != null) - { - return partMechanical.node; - } - return tileMechanical.mechanicalNode; - } - - public void createTopBar() - { - Panel panel = new Panel(new GridLayout(1, 2, 0, 0)); - + panel.setLayout(new GridLayout(1, 2, 0, 0)); UpdatedLabel tickLabel = new UpdatedLabel("Node: ") { @Override @@ -129,7 +36,6 @@ public class MechanicalNodeFrame extends Frame implements ActionListener return super.buildLabel() + MechanicalNodeFrame.this.getNode(); } }; - dataLabels.add(tickLabel); panel.add(tickLabel); UpdatedLabel xLabel = new UpdatedLabel("Parent: ") @@ -140,16 +46,13 @@ public class MechanicalNodeFrame extends Frame implements ActionListener return super.buildLabel() + (MechanicalNodeFrame.this.getNode() != null ? MechanicalNodeFrame.this.getNode().getParent() : "null"); } }; - dataLabels.add(xLabel); panel.add(xLabel); - - add(panel, BorderLayout.NORTH); } - public void createBottomBar() + @Override + public void buildBottom(Panel panel) { - Panel bottomPanel = new Panel(new GridLayout(1, 4, 0, 0)); - + panel.setLayout(new GridLayout(1, 4, 0, 0)); UpdatedLabel tickLabel = new UpdatedLabel("Tick: ") { @Override @@ -158,59 +61,96 @@ public class MechanicalNodeFrame extends Frame implements ActionListener return super.buildLabel() + tick; } }; - dataLabels.add(tickLabel); - bottomPanel.add(tickLabel); + panel.add(tickLabel); UpdatedLabel xLabel = new UpdatedLabel("X: ") { @Override public String buildLabel() { - return super.buildLabel() + MechanicalNodeFrame.this.getNode().x(); + return super.buildLabel() + (MechanicalNodeFrame.this.getNode() != null ? MechanicalNodeFrame.this.getNode().x() : 0); } }; - dataLabels.add(xLabel); - bottomPanel.add(xLabel); + panel.add(xLabel); UpdatedLabel yLabel = new UpdatedLabel("Y: ") { @Override public String buildLabel() { - return super.buildLabel() + MechanicalNodeFrame.this.getNode().y(); + return super.buildLabel() + (MechanicalNodeFrame.this.getNode() != null ? MechanicalNodeFrame.this.getNode().y() : 0); } }; - bottomPanel.add(yLabel); - dataLabels.add(yLabel); + panel.add(yLabel); UpdatedLabel zLabel = new UpdatedLabel("Z: ") { @Override public String buildLabel() { - return super.buildLabel() + MechanicalNodeFrame.this.getNode().z(); + return super.buildLabel() + (MechanicalNodeFrame.this.getNode() != null ? MechanicalNodeFrame.this.getNode().z() : 0); } }; - bottomPanel.add(zLabel); - dataLabels.add(zLabel); - - add(bottomPanel, BorderLayout.SOUTH); + panel.add(zLabel); } - /** Called each cpu cycle */ + @Override + public void buildRight(Panel panel) + { + connections = new Label[10]; + panel.setLayout(new GridLayout(5, 2, 0, 0)); + for (int i = 0; i < connections.length; i++) + { + this.connections[i] = new Label("Connection" + i + ": ----"); + panel.add(connections[i]); + } + } + + @Override + public void buildLeft(Panel panel) + { + panel.setLayout(new GridLayout(3, 1, 0, 0)); + UpdatedLabel velLabel = new UpdatedLabel("Vel: ") + { + @Override + public String buildLabel() + { + return super.buildLabel() + MechanicalNodeFrame.this.getNode().angularVelocity; + } + }; + panel.add(velLabel); + + UpdatedLabel angleLabel = new UpdatedLabel("Angle: ") + { + @Override + public String buildLabel() + { + return super.buildLabel() + MechanicalNodeFrame.this.getNode().renderAngle; + } + }; + panel.add(angleLabel); + + UpdatedLabel torqueLabel = new UpdatedLabel("Torque: ") + { + @Override + public String buildLabel() + { + return super.buildLabel() + MechanicalNodeFrame.this.getNode().torque; + } + }; + panel.add(torqueLabel); + } + + @Override public void update() { - tick++; - if (this.getNode() != null) + super.update(); + if (this.getNode() != null && connections != null) { - for (UpdatedLabel label : dataLabels) - { - label.update(); - } int c = 0; for (Entry entry : getNode().getConnections().entrySet()) { - if (entry.getKey() != null) + if (entry.getKey() != null && this.connections[c] != null) { this.connections[c].setText("Connection" + c + ": " + entry.getKey()); c++; @@ -218,29 +158,20 @@ public class MechanicalNodeFrame extends Frame implements ActionListener } for (int i = c; i < connections.length; i++) { - this.connections[i].setText("Connection" + i + ": NONE"); + if (this.connections[c] != null) + this.connections[i].setText("Connection" + i + ": NONE"); } } } - /** Shows the frame */ - public void showDebugFrame() - { - setTitle("Resonant Engine Debug Window"); - setBounds(200, 200, 450, 600); - setVisible(true); - } - - /** Hides the frame and tells it to die off */ - public void closeDebugFrame() - { - dispose(); - } - @Override - public void actionPerformed(ActionEvent arg0) + public MechanicalNode getNode() { - // TODO Auto-generated method stub - + INode node = super.getNode(); + if (node instanceof MechanicalNode) + { + return (MechanicalNode) node; + } + return null; } } \ No newline at end of file diff --git a/src/main/scala/resonantinduction/core/debug/FrameDebug.java b/src/main/scala/resonantinduction/core/debug/FrameDebug.java index 1f5b2b3c3..083e4774d 100644 --- a/src/main/scala/resonantinduction/core/debug/FrameDebug.java +++ b/src/main/scala/resonantinduction/core/debug/FrameDebug.java @@ -4,19 +4,20 @@ import java.awt.BorderLayout; import java.awt.Component; import java.awt.Frame; import java.awt.Panel; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; import net.minecraft.tileentity.TileEntity; -import resonant.api.grid.INode; +/** @author Darkguardsman */ @SuppressWarnings("serial") public class FrameDebug extends Frame { /** Linked tile */ TileEntity tile = null; - /** Linked node */ - INode node = null; - /** Are we debugging a node */ + boolean debugNode = false; + protected long tick = 0; public FrameDebug(TileEntity tile) { @@ -24,11 +25,6 @@ public class FrameDebug extends Frame this.tile = tile; } - public FrameDebug(INode node) - { - this(); - this.node = node; - } protected FrameDebug() { @@ -43,6 +39,8 @@ public class FrameDebug extends Frame UpdatePanel leftPanel = new UpdatePanel(); UpdatePanel rightPanel = new UpdatePanel(); + setLayout(new BorderLayout()); + buildTop(topPanel); buildBottom(botPanel); buildLeft(leftPanel); @@ -52,6 +50,17 @@ public class FrameDebug extends Frame this.add(botPanel, BorderLayout.SOUTH); this.add(rightPanel, BorderLayout.EAST); this.add(leftPanel, BorderLayout.WEST); + + //exit icon handler + addWindowListener(new WindowAdapter() + { + public void windowClosing(WindowEvent e) + { + Frame f = (Frame) e.getSource(); + f.setVisible(false); + f.dispose(); + } + }); } /** Top are of the Frame */ @@ -81,12 +90,32 @@ public class FrameDebug extends Frame /** Called each tick by the host of this GUI */ public void update() { - for(Component component : getComponents()) + tick++; + if (tick >= Long.MAX_VALUE) { - if(component instanceof IUpdate) + tick = 0; + } + + for (Component component : getComponents()) + { + if (component instanceof IUpdate) { - ((IUpdate)component).update(); + ((IUpdate) component).update(); } } + } + + /** Shows the frame */ + public void showDebugFrame() + { + setTitle("Resonant Engine Debug Window"); + setBounds(200, 200, 450, 600); + setVisible(true); + } + + /** Hides the frame and tells it to die off */ + public void closeDebugFrame() + { + dispose(); } } diff --git a/src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java b/src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java new file mode 100644 index 000000000..b9c65c658 --- /dev/null +++ b/src/main/scala/resonantinduction/core/debug/FrameNodeDebug.java @@ -0,0 +1,51 @@ +package resonantinduction.core.debug; + +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.ForgeDirection; +import resonant.api.grid.INode; +import resonant.api.grid.INodeProvider; + +/** @author Darkguardsman */ +@SuppressWarnings("serial") +public class FrameNodeDebug extends FrameDebug +{ + protected INodeProvider nodeProvider = null; + /** Linked node */ + protected INode node = null; + protected Class nodeClazz = null; + + /** Are we debugging a node */ + + public FrameNodeDebug(TileEntity tile, Class nodeClazz) + { + super(tile); + this.nodeClazz = nodeClazz; + } + + public FrameNodeDebug(INodeProvider node, Class nodeClazz) + { + super(); + this.nodeProvider = node; + this.nodeClazz = nodeClazz; + } + + public FrameNodeDebug(INode node) + { + super(); + this.node = node; + } + + /** Gets the node used for debug */ + public INode getNode() + { + if (tile instanceof INodeProvider && nodeClazz != null) + { + return ((INodeProvider) tile).getNode(nodeClazz, ForgeDirection.UNKNOWN); + } + else if (nodeProvider != null && nodeClazz != null) + { + return nodeProvider.getNode(nodeClazz, ForgeDirection.UNKNOWN); + } + return node; + } +} diff --git a/src/main/scala/resonantinduction/core/debug/UpdatePanel.java b/src/main/scala/resonantinduction/core/debug/UpdatePanel.java index 206d4eba2..be8040c20 100644 --- a/src/main/scala/resonantinduction/core/debug/UpdatePanel.java +++ b/src/main/scala/resonantinduction/core/debug/UpdatePanel.java @@ -3,17 +3,19 @@ package resonantinduction.core.debug; import java.awt.Component; import java.awt.Panel; + +/** @author Darkguardsman */ @SuppressWarnings("serial") public class UpdatePanel extends Panel implements IUpdate { @Override public void update() { - for(Component component : getComponents()) + for (Component component : getComponents()) { - if(component instanceof IUpdate) + if (component instanceof IUpdate) { - ((IUpdate)component).update(); + ((IUpdate) component).update(); } } }