use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class TablePanel method paintComponent.
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Dimension sz = getSize();
int top = Math.max(0, (sz.height - tableHeight) / 2);
int left = Math.max(0, (sz.width - tableWidth) / 2);
Model model = getModel();
if (model == null)
return;
Selection sel = model.getSelection();
int columns = sel.size();
if (columns == 0) {
g.setFont(BODY_FONT);
GraphicsUtil.drawCenteredText(g, Strings.get("tableEmptyMessage"), sz.width / 2, sz.height / 2);
return;
}
g.setColor(Color.GRAY);
int lineY = top + cellHeight + HEADER_SEP / 2;
g.drawLine(left, lineY, left + tableWidth, lineY);
g.setColor(Color.BLACK);
g.setFont(HEAD_FONT);
FontMetrics headerMetric = g.getFontMetrics();
int x = left;
int y = top + headerMetric.getAscent() + 1;
for (int i = 0; i < columns; i++) {
x = paintHeader(sel.get(i).toShortString(), x, y, g, headerMetric);
}
g.setFont(BODY_FONT);
FontMetrics bodyMetric = g.getFontMetrics();
Rectangle clip = g.getClipBounds();
int firstRow = Math.max(0, (clip.y - y) / cellHeight - 1);
int lastRow = Math.min(rowCount, 2 + (clip.y + clip.height - y) / cellHeight);
int y0 = top + cellHeight + HEADER_SEP;
x = left;
for (int col = 0; col < columns; col++) {
SelectionItem item = sel.get(col);
ValueLog log = model.getValueLog(item);
int radix = item.getRadix();
int offs = rowCount - log.size();
y = y0 + Math.max(offs, firstRow) * cellHeight;
for (int row = Math.max(offs, firstRow); row < lastRow; row++) {
Value val = log.get(row - offs);
String label = val.toDisplayString(radix);
int width = bodyMetric.stringWidth(label);
g.drawString(label, x + (cellWidth - width) / 2, y + bodyMetric.getAscent());
y += cellHeight;
}
x += cellWidth + COLUMN_SEP;
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Pin method propagate.
@Override
public void propagate(InstanceState state) {
PinAttributes attrs = (PinAttributes) state.getAttributeSet();
PinState q = getState(state);
if (attrs.type == EndData.OUTPUT_ONLY) {
Value found = state.getPortValue(0);
q.intendedValue = found;
q.foundValue = found;
state.setPort(0, Value.createUnknown(attrs.width), 1);
} else {
Value found = state.getPortValue(0);
Value toSend = q.intendedValue;
Object pull = attrs.pull;
Value pullTo = null;
if (pull == PULL_DOWN) {
pullTo = Value.FALSE;
} else if (pull == PULL_UP) {
pullTo = Value.TRUE;
} else if (!attrs.threeState && !state.isCircuitRoot()) {
pullTo = Value.FALSE;
}
if (pullTo != null) {
toSend = pull2(toSend, attrs.width, pullTo);
if (state.isCircuitRoot()) {
q.intendedValue = toSend;
}
}
q.foundValue = found;
if (!toSend.equals(found)) {
// ignore if no change
state.setPort(0, toSend, 1);
}
}
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Pin method getState.
private static PinState getState(InstanceState state) {
PinAttributes attrs = (PinAttributes) state.getAttributeSet();
BitWidth width = attrs.width;
PinState ret = (PinState) state.getData();
if (ret == null) {
Value val = attrs.threeState ? Value.UNKNOWN : Value.FALSE;
if (width.getWidth() > 1) {
Value[] arr = new Value[width.getWidth()];
java.util.Arrays.fill(arr, val);
val = Value.create(arr);
}
ret = new PinState(val, val);
state.setData(ret);
}
if (ret.intendedValue.getWidth() != width.getWidth()) {
ret.intendedValue = ret.intendedValue.extendWidth(width.getWidth(), attrs.threeState ? Value.UNKNOWN : Value.FALSE);
}
if (ret.foundValue.getWidth() != width.getWidth()) {
ret.foundValue = ret.foundValue.extendWidth(width.getWidth(), Value.UNKNOWN);
}
return ret;
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class Probe method paintInstance.
@Override
public void paintInstance(InstancePainter painter) {
Value value = getValue(painter);
Graphics g = painter.getGraphics();
// intentionally with no graphics
Bounds bds = painter.getBounds();
// object - we don't want label
// included
int x = bds.getX();
int y = bds.getY();
Color back = new Color(0xff, 0xf0, 0x99);
if (value.getWidth() <= 1) {
g.setColor(back);
g.fillOval(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2);
g.setColor(Color.lightGray);
g.drawOval(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2);
} else {
g.setColor(back);
g.fillRoundRect(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2, 20, 20);
g.setColor(Color.lightGray);
g.drawRoundRect(x + 1, y + 1, bds.getWidth() - 2, bds.getHeight() - 2, 20, 20);
}
g.setColor(Color.GRAY);
painter.drawLabel();
g.setColor(Color.DARK_GRAY);
if (!painter.getShowState()) {
if (value.getWidth() > 0) {
GraphicsUtil.drawCenteredText(g, "x" + value.getWidth(), bds.getX() + bds.getWidth() / 2, bds.getY() + bds.getHeight() / 2);
}
} else {
paintValue(painter, value);
}
painter.drawPorts();
}
use of com.cburch.logisim.data.Value in project logisim-evolution by reds-heig.
the class PullResistor method paintGhost.
@Override
public void paintGhost(InstancePainter painter) {
Value pull = getPullValue(painter.getAttributeSet());
paintBase(painter, pull, null, null);
}
Aggregations