Updated MechanicalNodeFrame to extends FrameNodeDebug
This commit is contained in:
parent
7468a38b8a
commit
2a884fabc8
4 changed files with 177 additions and 164 deletions
|
@ -1,126 +1,33 @@
|
||||||
package resonantinduction.mechanical.energy.grid;
|
package resonantinduction.mechanical.energy.grid;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Frame;
|
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.Label;
|
import java.awt.Label;
|
||||||
import java.awt.Panel;
|
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 java.util.Map.Entry;
|
||||||
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
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;
|
import resonantinduction.core.debug.UpdatedLabel;
|
||||||
|
|
||||||
/** Java GUI used to help debug gear information
|
/** Java GUI used to help debug gear information
|
||||||
*
|
*
|
||||||
* @author Darkguardsman */
|
* @author Darkguardsman */
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class MechanicalNodeFrame extends Frame implements ActionListener
|
public class MechanicalNodeFrame extends FrameNodeDebug
|
||||||
{
|
{
|
||||||
List<UpdatedLabel> dataLabels = new ArrayList<UpdatedLabel>();
|
Label[] connections;
|
||||||
Label[] connections = new Label[10];
|
|
||||||
|
|
||||||
long tick = 0;
|
public MechanicalNodeFrame(INodeProvider node)
|
||||||
private PartMechanical partMechanical = null;
|
|
||||||
private TileMechanical tileMechanical = null;
|
|
||||||
|
|
||||||
public MechanicalNodeFrame(TileMechanical tile)
|
|
||||||
{
|
{
|
||||||
this();
|
super(node, MechanicalNode.class);
|
||||||
this.tileMechanical = tile;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MechanicalNodeFrame(PartMechanical part)
|
@Override
|
||||||
|
public void buildTop(Panel panel)
|
||||||
{
|
{
|
||||||
this();
|
panel.setLayout(new GridLayout(1, 2, 0, 0));
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public MechanicalNode getNode()
|
|
||||||
{
|
|
||||||
if(partMechanical != null)
|
|
||||||
{
|
|
||||||
return partMechanical.node;
|
|
||||||
}
|
|
||||||
return tileMechanical.mechanicalNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void createTopBar()
|
|
||||||
{
|
|
||||||
Panel panel = new Panel(new GridLayout(1, 2, 0, 0));
|
|
||||||
|
|
||||||
UpdatedLabel tickLabel = new UpdatedLabel("Node: ")
|
UpdatedLabel tickLabel = new UpdatedLabel("Node: ")
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -129,7 +36,6 @@ public class MechanicalNodeFrame extends Frame implements ActionListener
|
||||||
return super.buildLabel() + MechanicalNodeFrame.this.getNode();
|
return super.buildLabel() + MechanicalNodeFrame.this.getNode();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dataLabels.add(tickLabel);
|
|
||||||
panel.add(tickLabel);
|
panel.add(tickLabel);
|
||||||
|
|
||||||
UpdatedLabel xLabel = new UpdatedLabel("Parent: ")
|
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");
|
return super.buildLabel() + (MechanicalNodeFrame.this.getNode() != null ? MechanicalNodeFrame.this.getNode().getParent() : "null");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dataLabels.add(xLabel);
|
|
||||||
panel.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: ")
|
UpdatedLabel tickLabel = new UpdatedLabel("Tick: ")
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
|
@ -158,59 +61,96 @@ public class MechanicalNodeFrame extends Frame implements ActionListener
|
||||||
return super.buildLabel() + tick;
|
return super.buildLabel() + tick;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
dataLabels.add(tickLabel);
|
panel.add(tickLabel);
|
||||||
bottomPanel.add(tickLabel);
|
|
||||||
|
|
||||||
UpdatedLabel xLabel = new UpdatedLabel("X: ")
|
UpdatedLabel xLabel = new UpdatedLabel("X: ")
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public String buildLabel()
|
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);
|
panel.add(xLabel);
|
||||||
bottomPanel.add(xLabel);
|
|
||||||
|
|
||||||
UpdatedLabel yLabel = new UpdatedLabel("Y: ")
|
UpdatedLabel yLabel = new UpdatedLabel("Y: ")
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public String buildLabel()
|
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);
|
panel.add(yLabel);
|
||||||
dataLabels.add(yLabel);
|
|
||||||
|
|
||||||
UpdatedLabel zLabel = new UpdatedLabel("Z: ")
|
UpdatedLabel zLabel = new UpdatedLabel("Z: ")
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public String buildLabel()
|
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);
|
panel.add(zLabel);
|
||||||
dataLabels.add(zLabel);
|
|
||||||
|
|
||||||
add(bottomPanel, BorderLayout.SOUTH);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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()
|
public void update()
|
||||||
{
|
{
|
||||||
tick++;
|
super.update();
|
||||||
if (this.getNode() != null)
|
if (this.getNode() != null && connections != null)
|
||||||
{
|
{
|
||||||
for (UpdatedLabel label : dataLabels)
|
|
||||||
{
|
|
||||||
label.update();
|
|
||||||
}
|
|
||||||
int c = 0;
|
int c = 0;
|
||||||
for (Entry<MechanicalNode, ForgeDirection> entry : getNode().getConnections().entrySet())
|
for (Entry<MechanicalNode, ForgeDirection> entry : getNode().getConnections().entrySet())
|
||||||
{
|
{
|
||||||
if (entry.getKey() != null)
|
if (entry.getKey() != null && this.connections[c] != null)
|
||||||
{
|
{
|
||||||
this.connections[c].setText("Connection" + c + ": " + entry.getKey());
|
this.connections[c].setText("Connection" + c + ": " + entry.getKey());
|
||||||
c++;
|
c++;
|
||||||
|
@ -218,29 +158,20 @@ public class MechanicalNodeFrame extends Frame implements ActionListener
|
||||||
}
|
}
|
||||||
for (int i = c; i < connections.length; i++)
|
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
|
@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;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,19 +4,20 @@ import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Frame;
|
import java.awt.Frame;
|
||||||
import java.awt.Panel;
|
import java.awt.Panel;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import resonant.api.grid.INode;
|
|
||||||
|
|
||||||
|
/** @author Darkguardsman */
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class FrameDebug extends Frame
|
public class FrameDebug extends Frame
|
||||||
{
|
{
|
||||||
/** Linked tile */
|
/** Linked tile */
|
||||||
TileEntity tile = null;
|
TileEntity tile = null;
|
||||||
/** Linked node */
|
|
||||||
INode node = null;
|
|
||||||
/** Are we debugging a node */
|
|
||||||
boolean debugNode = false;
|
boolean debugNode = false;
|
||||||
|
protected long tick = 0;
|
||||||
|
|
||||||
public FrameDebug(TileEntity tile)
|
public FrameDebug(TileEntity tile)
|
||||||
{
|
{
|
||||||
|
@ -24,11 +25,6 @@ public class FrameDebug extends Frame
|
||||||
this.tile = tile;
|
this.tile = tile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FrameDebug(INode node)
|
|
||||||
{
|
|
||||||
this();
|
|
||||||
this.node = node;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected FrameDebug()
|
protected FrameDebug()
|
||||||
{
|
{
|
||||||
|
@ -43,6 +39,8 @@ public class FrameDebug extends Frame
|
||||||
UpdatePanel leftPanel = new UpdatePanel();
|
UpdatePanel leftPanel = new UpdatePanel();
|
||||||
UpdatePanel rightPanel = new UpdatePanel();
|
UpdatePanel rightPanel = new UpdatePanel();
|
||||||
|
|
||||||
|
setLayout(new BorderLayout());
|
||||||
|
|
||||||
buildTop(topPanel);
|
buildTop(topPanel);
|
||||||
buildBottom(botPanel);
|
buildBottom(botPanel);
|
||||||
buildLeft(leftPanel);
|
buildLeft(leftPanel);
|
||||||
|
@ -52,6 +50,17 @@ public class FrameDebug extends Frame
|
||||||
this.add(botPanel, BorderLayout.SOUTH);
|
this.add(botPanel, BorderLayout.SOUTH);
|
||||||
this.add(rightPanel, BorderLayout.EAST);
|
this.add(rightPanel, BorderLayout.EAST);
|
||||||
this.add(leftPanel, BorderLayout.WEST);
|
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 */
|
/** Top are of the Frame */
|
||||||
|
@ -81,12 +90,32 @@ public class FrameDebug extends Frame
|
||||||
/** Called each tick by the host of this GUI */
|
/** Called each tick by the host of this GUI */
|
||||||
public void update()
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<? extends INode> nodeClazz = null;
|
||||||
|
|
||||||
|
/** Are we debugging a node */
|
||||||
|
|
||||||
|
public FrameNodeDebug(TileEntity tile, Class<? extends INode> nodeClazz)
|
||||||
|
{
|
||||||
|
super(tile);
|
||||||
|
this.nodeClazz = nodeClazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FrameNodeDebug(INodeProvider node, Class<? extends INode> 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,17 +3,19 @@ package resonantinduction.core.debug;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Panel;
|
import java.awt.Panel;
|
||||||
|
|
||||||
|
|
||||||
|
/** @author Darkguardsman */
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class UpdatePanel extends Panel implements IUpdate
|
public class UpdatePanel extends Panel implements IUpdate
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue