use of com.cburch.logisim.file.LoadedLibrary in project logisim-evolution by reds-heig.
the class RegTabContent method fillArray.
/**
* This function will clear and fill the registers tab and refresh their
* value. It will start by iterate over all circuits of the current project
* to register all the "Register" components (providing their attributes are
* correctly set). It will then fill the panel with each register found,
* including their current value.
*/
private void fillArray() {
int y = 0;
MyLabel col1 = new MyLabel("Circuit", Font.ITALIC | Font.BOLD);
MyLabel col2 = new MyLabel("Reg name", Font.BOLD);
MyLabel col3 = new MyLabel("Value", Font.BOLD);
registers.clear();
panel.removeAll();
for (Circuit circ : proj.getLogisimFile().getCircuits()) {
getAllRegisters(circ);
}
if (proj.getLogisimFile().getLibrary("prodis_v1.3") instanceof LoadedLibrary) {
if (((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase() instanceof LogisimFile) {
for (Circuit circ : ((LogisimFile) ((LoadedLibrary) proj.getLogisimFile().getLibrary("prodis_v1.3")).getBase()).getCircuits()) {
getAllRegisters(circ);
}
}
}
col1.setColor(Color.LIGHT_GRAY);
col2.setColor(Color.LIGHT_GRAY);
col3.setColor(Color.LIGHT_GRAY);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.FIRST_LINE_START;
c.ipady = 2;
c.weighty = 0;
c.gridy = y;
c.gridx = 0;
c.weightx = 0.3;
panel.add(col1, c);
c.gridx++;
c.weightx = 0.5;
panel.add(col2, c);
c.gridx++;
c.weightx = 0.2;
panel.add(col3, c);
y++;
if (!registers.isEmpty()) {
Object[] objArr = registers.keySet().toArray();
Arrays.sort(objArr);
for (Object name : objArr) {
c.gridy = y;
c.gridx = 0;
String circuitName = name.toString().split("/")[0];
panel.add(new MyLabel(circuitName, Font.ITALIC, true), c);
c.gridx++;
String registerName = name.toString().split("/")[1];
panel.add(new MyLabel(registerName), c);
c.gridx++;
Component selReg = registers.get(name.toString());
CircuitState mainCircState = proj.getCircuitState();
while (mainCircState.getParentState() != null) {
// Get the main
// circuit
mainCircState = mainCircState.getParentState();
}
Value val = findVal(mainCircState, circuitName, selReg.getEnd(0).getLocation());
if (val != null) {
panel.add(new MyLabel(val.toHexString()), c);
} else {
panel.add(new MyLabel("-"), c);
}
y++;
}
}
c.weighty = 1;
c.gridy++;
c.gridx = 0;
c.weightx = 1;
panel.add(new MyLabel(""), c);
panel.validate();
}
Aggregations