use of com.cburch.logisim.analyze.model.TruthTable in project logisim-evolution by reds-heig.
the class KarnaughMapPanel method getRow.
public int getRow(MouseEvent event) {
TruthTable table = model.getTruthTable();
int inputs = table.getInputColumnCount();
if (inputs >= ROW_VARS.length)
return -1;
int left = computeMargin(getWidth(), tableWidth);
int top = computeMargin(getHeight(), tableHeight);
int x = event.getX() - left - headHeight - 11;
int y = event.getY() - top - headHeight - 11;
if (x < 0 || y < 0)
return -1;
int row = y / cellHeight;
int col = x / cellWidth;
int rows = 1 << ROW_VARS[inputs];
int cols = 1 << COL_VARS[inputs];
if (row >= rows || col >= cols)
return -1;
return getTableRow(row, col, rows, cols);
}
use of com.cburch.logisim.analyze.model.TruthTable in project logisim-evolution by reds-heig.
the class KarnaughMapPanel method getToolTipText.
@Override
public String getToolTipText(MouseEvent event) {
TruthTable table = model.getTruthTable();
int row = getRow(event);
int col = getOutputColumn(event);
Entry entry = table.getOutputEntry(row, col);
return entry.getErrorMessage();
}
use of com.cburch.logisim.analyze.model.TruthTable in project logisim-evolution by reds-heig.
the class TableTabCaret method setCursor.
private void setCursor(int row, int col, boolean keepMark) {
TruthTable model = table.getTruthTable();
int rows = model.getRowCount();
int cols = model.getInputColumnCount() + model.getOutputColumnCount();
if (row < 0)
row = 0;
if (col < 0)
col = 0;
if (row >= rows)
row = rows - 1;
if (col >= cols)
col = cols - 1;
if (row == cursorRow && col == cursorCol && (keepMark || (row == markRow && col == markCol))) {
// nothing is changing, so do nothing
;
} else if (!keepMark && markRow == cursorRow && markCol == cursorCol) {
int oldRow = cursorRow;
int oldCol = cursorCol;
cursorRow = row;
cursorCol = col;
markRow = row;
markCol = col;
expose(oldRow, oldCol);
expose(cursorRow, cursorCol);
} else {
int r0 = Math.min(row, Math.min(cursorRow, markRow));
int r1 = Math.max(row, Math.max(cursorRow, markRow));
int c0 = Math.min(col, Math.min(cursorCol, markCol));
int c1 = Math.max(col, Math.max(cursorCol, markCol));
cursorRow = row;
cursorCol = col;
if (!keepMark) {
markRow = row;
markCol = col;
}
int x0 = table.getX(c0);
int x1 = table.getX(c1) + table.getCellWidth();
int y0 = table.getY(r0);
int y1 = table.getY(r1) + table.getCellHeight();
table.repaint(x0 - 2, y0 - 2, (x1 - x0) + 4, (y1 - y0) + 4);
}
int cx = table.getX(cursorCol);
int cy = table.getY(cursorRow);
int cw = table.getCellWidth();
int ch = table.getCellHeight();
if (cursorRow == 0) {
ch += cy;
cy = 0;
}
table.scrollRectToVisible(new Rectangle(cx, cy, cw, ch));
}
use of com.cburch.logisim.analyze.model.TruthTable in project logisim-evolution by reds-heig.
the class TableTabClip method copy.
public void copy() {
TableTabCaret caret = table.getCaret();
int c0 = caret.getCursorCol();
int r0 = caret.getCursorRow();
int c1 = caret.getMarkCol();
int r1 = caret.getMarkRow();
if (c1 < c0) {
int t = c0;
c0 = c1;
c1 = t;
}
if (r1 < r0) {
int t = r0;
r0 = r1;
r1 = t;
}
TruthTable t = table.getTruthTable();
int inputs = t.getInputColumnCount();
String[] header = new String[c1 - c0 + 1];
for (int c = c0; c <= c1; c++) {
if (c < inputs) {
header[c - c0] = t.getInputHeader(c);
} else {
header[c - c0] = t.getOutputHeader(c - inputs);
}
}
String[][] contents = new String[r1 - r0 + 1][c1 - c0 + 1];
for (int r = r0; r <= r1; r++) {
for (int c = c0; c <= c1; c++) {
if (c < inputs) {
contents[r - r0][c - c0] = t.getInputEntry(r, c).getDescription();
} else {
contents[r - r0][c - c0] = t.getOutputEntry(r, c - inputs).getDescription();
}
}
}
Clipboard clip = table.getToolkit().getSystemClipboard();
clip.setContents(new Data(header, contents), this);
}
use of com.cburch.logisim.analyze.model.TruthTable in project logisim-evolution by reds-heig.
the class TruthTableMouseListener method mouseReleased.
public void mouseReleased(MouseEvent event) {
TruthTablePanel source = (TruthTablePanel) event.getSource();
TruthTable model = source.getTruthTable();
int cols = model.getInputColumnCount() + model.getOutputColumnCount();
int rows = model.getRowCount();
if (cellX < 0 || cellY < 0 || cellX >= cols || cellY >= rows)
return;
int x = source.getOutputColumn(event);
int y = source.getRow(event);
TruthTable table = source.getTruthTable();
if (x == cellX && y == cellY) {
table.setOutputEntry(y, x, newValue);
}
source.setEntryProvisional(cellY, cellX, null);
cellX = -1;
cellY = -1;
}
Aggregations