mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-28 07:55:49 +00:00
127 lines
3.5 KiB
Java
127 lines
3.5 KiB
Java
package mcp.mobius.opis.swing.panels;
|
|
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
|
|
import mcp.mobius.opis.data.holders.basetypes.SerialDouble;
|
|
import mcp.mobius.opis.data.holders.stats.StatAbstract;
|
|
import mcp.mobius.opis.data.holders.stats.StatsTickHandler;
|
|
import mcp.mobius.opis.network.enums.AccessLevel;
|
|
import mcp.mobius.opis.network.enums.Message;
|
|
import mcp.mobius.opis.network.packets.client.Packet_ReqData;
|
|
import mcp.mobius.opis.network.packets.server.NetDataRaw;
|
|
import mcp.mobius.opis.swing.actions.ActionRunOpis;
|
|
import mcp.mobius.opis.swing.widgets.JButtonAccess;
|
|
import mcp.mobius.opis.swing.widgets.JPanelMsgHandler;
|
|
import mcp.mobius.opis.swing.widgets.JTableStats;
|
|
import net.miginfocom.swing.MigLayout;
|
|
|
|
import javax.swing.JButton;
|
|
import javax.swing.JScrollPane;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JTable;
|
|
import javax.swing.ListSelectionModel;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.table.DefaultTableCellRenderer;
|
|
import javax.swing.table.DefaultTableModel;
|
|
|
|
import cpw.mods.fml.common.network.PacketDispatcher;
|
|
|
|
public class PanelTimingHandlers extends JPanelMsgHandler{
|
|
private JButtonAccess btnRun;
|
|
private JLabel lblSummary;
|
|
|
|
/**
|
|
* Create the panel.
|
|
*/
|
|
public PanelTimingHandlers() {
|
|
setLayout(new MigLayout("", "[grow][]", "[][grow][]"));
|
|
|
|
btnRun = new JButtonAccess("Run Opis", AccessLevel.PRIVILEGED);
|
|
add(btnRun, "cell 1 0");
|
|
btnRun.addActionListener(new ActionRunOpis());
|
|
|
|
JScrollPane scrollPane = new JScrollPane();
|
|
|
|
add(scrollPane, "cell 0 1 2 1,grow");
|
|
|
|
table = new JTableStats();
|
|
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
|
table.setModel(new DefaultTableModel(
|
|
new Object[][] {
|
|
},
|
|
new String[] {
|
|
"Name", "Update Time"
|
|
}
|
|
) {
|
|
Class[] columnTypes = new Class[] {
|
|
String.class, StatAbstract.class
|
|
};
|
|
boolean[] columnEditables = new boolean[] {
|
|
false, false
|
|
};
|
|
@Override
|
|
public Class getColumnClass(int columnIndex) {
|
|
return columnTypes[columnIndex];
|
|
}
|
|
});
|
|
table.setAutoCreateRowSorter(true);
|
|
scrollPane.setViewportView(table);
|
|
|
|
lblSummary = new JLabel("TmpText");
|
|
add(lblSummary, "cell 0 2 2 1,alignx center");
|
|
|
|
DefaultTableCellRenderer centerRenderer = new DefaultTableCellRenderer();
|
|
centerRenderer.setHorizontalAlignment( SwingConstants.CENTER );
|
|
|
|
for (int i = 0; i < table.getColumnCount(); i++)
|
|
table.getColumnModel().getColumn(i).setCellRenderer(centerRenderer);
|
|
|
|
}
|
|
|
|
public JButton getBtnRun() {return btnRun;}
|
|
public JLabel getLblSummary(){return lblSummary;}
|
|
|
|
@Override
|
|
public boolean handleMessage(Message msg, NetDataRaw rawdata) {
|
|
switch(msg){
|
|
case LIST_TIMING_HANDLERS:{
|
|
|
|
((JTableStats)this.getTable()).setStatistics(rawdata.array);
|
|
|
|
DefaultTableModel model = (DefaultTableModel)table.getModel();
|
|
int row = this.updateData(table, model, StatsTickHandler.class);
|
|
|
|
for (Object o : rawdata.array){
|
|
StatsTickHandler stat = (StatsTickHandler)o;
|
|
model.addRow(new Object[] {stat.getName(), stat});
|
|
}
|
|
|
|
this.dataUpdated(table, model, row);
|
|
|
|
break;
|
|
}
|
|
case VALUE_TIMING_HANDLERS:{
|
|
this.getLblSummary().setText(String.format("Total update time : %.3f µs", ((SerialDouble)rawdata.value).value));
|
|
break;
|
|
}
|
|
case STATUS_START:{
|
|
this.getBtnRun().setText("Running...");
|
|
break;
|
|
}
|
|
case STATUS_STOP:{
|
|
this.getBtnRun().setText("Run Opis");
|
|
break;
|
|
}
|
|
case STATUS_RUNNING:{
|
|
this.getBtnRun().setText("Running...");
|
|
break;
|
|
}
|
|
default:
|
|
return false;
|
|
|
|
}
|
|
return true;
|
|
}
|
|
}
|