mirror of
https://github.com/GTNewHorizons/Opis.git
synced 2026-11-21 20:52:14 +00:00
First shoot at Swing.
This commit is contained in:
1 parent
ab7823230a
commit
f5243d02c3
10 files changed
+380
-54
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package mcp.mobius.opis.data.client;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import mcp.mobius.opis.gui.swing.SwingUI;
|
||||
|
||||
public class DataCache {
|
||||
|
||||
private static DataCache _instance = new DataCache();
|
||||
public static DataCache instance() { return _instance; };
|
||||
|
||||
private HashMap<String, Integer> amountEntities = new HashMap<String, Integer>();
|
||||
|
||||
public void setAmountEntities(HashMap<String, Integer> stats){
|
||||
this.amountEntities = stats;
|
||||
|
||||
DefaultTableModel model = new DefaultTableModel(
|
||||
new Object[][] {
|
||||
{null, null},
|
||||
},
|
||||
new String[] {
|
||||
"Type", "Amount"
|
||||
}
|
||||
) {
|
||||
Class[] columnTypes = new Class[] {
|
||||
String.class, Integer.class
|
||||
};
|
||||
public Class getColumnClass(int columnIndex) {
|
||||
return columnTypes[columnIndex];
|
||||
}
|
||||
};
|
||||
|
||||
for (int i = 0; i < model.getRowCount(); i++)
|
||||
model.removeRow(i);
|
||||
|
||||
int totalEntities = 0;
|
||||
|
||||
for (String type : DataCache.instance().getAmountEntities().keySet()){
|
||||
model.addRow(new Object[] {type, DataCache.instance().getAmountEntities().get(type)});
|
||||
totalEntities += DataCache.instance().getAmountEntities().get(type);
|
||||
}
|
||||
|
||||
SwingUI.instance().getTableEntityList().setModel(model);
|
||||
SwingUI.instance().getLabelAmountValue().setText(String.valueOf(totalEntities));
|
||||
model.fireTableDataChanged();
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getAmountEntities(){
|
||||
return this.amountEntities;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user