Package com.cburch.logisim.analyze.model

Examples of com.cburch.logisim.analyze.model.TruthTable


  int getMarkRow() { return markRow; }
  int getMarkCol() { return markCol; }
 
  void selectAll() {
    table.requestFocus();
    TruthTable model = table.getTruthTable();
    setCursor(model.getRowCount(), model.getInputColumnCount() + model.getOutputColumnCount(), false);
    setCursor(0, 0, true);
  }
View Full Code Here


    setCursor(model.getRowCount(), model.getInputColumnCount() + model.getOutputColumnCount(), false);
    setCursor(0, 0, true);
  }
 
  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;
   
View Full Code Here

      char c = e.getKeyChar();
      Entry newEntry = null;
      switch (c) {
      case ' ':
        if (cursorRow >= 0) {
          TruthTable model = table.getTruthTable();
          int inputs = model.getInputColumnCount();
          if (cursorCol >= inputs) {
            Entry cur = model.getOutputEntry(cursorRow, cursorCol - inputs);
            if (cur == Entry.ZERO) cur = Entry.ONE;
            else if (cur == Entry.ONE) cur = Entry.DONT_CARE;
            else cur = Entry.ZERO;
            model.setOutputEntry(cursorRow, cursorCol - inputs, cur);
          }
        }
        break;
      case '0':
        newEntry = Entry.ZERO;
        break;
      case '1':
        newEntry = Entry.ONE;
        break;
      case 'x':
        newEntry = Entry.DONT_CARE;
        break;
      case '\n':
        setCursor(cursorRow + 1, table.getTruthTable().getInputColumnCount(),
            (mask & InputEvent.SHIFT_MASK) != 0);
        break;
      case '\u0008': case '\u007f':
        setCursor(cursorRow, cursorCol - 1, (mask & InputEvent.SHIFT_MASK) != 0);
        break;
      default:
      }
      if (newEntry != null) {
        TruthTable model = table.getTruthTable();
        int inputs = model.getInputColumnCount();
        int outputs = model.getOutputColumnCount();
        if (cursorCol >= inputs) {
          model.setOutputEntry(cursorRow, cursorCol - inputs, newEntry);
          if (cursorCol >= inputs + outputs - 1) {
            setCursor(cursorRow + 1, inputs, false);
          } else {
            setCursor(cursorRow, cursorCol + 1, false);
          }
View Full Code Here

      }
    }
 
    public void keyPressed(KeyEvent e) {
      if (cursorRow < 0) return;
      TruthTable model = table.getTruthTable();
      int rows = model.getRowCount();
      int inputs = model.getInputColumnCount();
      int outputs = model.getOutputColumnCount();
      int cols = inputs + outputs;
      boolean shift = (e.getModifiers() & InputEvent.SHIFT_MASK) != 0;
      switch (e.getKeyCode()) {
      case KeyEvent.VK_UP:    setCursor(cursorRow - 1, cursorCol, shift); break;
      case KeyEvent.VK_LEFT:  setCursor(cursorRow, cursorCol - 1, shift); break;
View Full Code Here

    }

    public void cellsChanged(TruthTableEvent event) { }

    public void structureChanged(TruthTableEvent event) {
      TruthTable model = event.getSource();
      int inputs = model.getInputColumnCount();
      int outputs = model.getOutputColumnCount();
      int rows = model.getRowCount();
      int cols = inputs + outputs;
      boolean changed = false;
      if (cursorRow >= rows) { cursorRow = rows - 1; changed = true; }
      if (cursorCol >= cols) { cursorCol = cols - 1; changed = true; }
      if (markRow >= rows) { markRow = rows - 1; changed = true; }
View Full Code Here

  public TruthTable getTruthTable() {
    return model.getTruthTable();
  }
 
  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 - cellWidth;
    int y = event.getY() - top - headHeight - cellHeight;
View Full Code Here

    repaint();
  }
 
  @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();
  }
View Full Code Here

    repaint();
  }
 
  private void computePreferredSize() {
    Graphics g = getGraphics();
    TruthTable table = model.getTruthTable();
   
    String message = null;
    if (output == null) {
      message = Strings.get("karnaughNoOutputError");
    } else if (table.getInputColumnCount() > MAX_VARS) {
      message = Strings.get("karnaughTooManyInputsError");
    }
    if (message != null) {
      if (g == null) {
        tableHeight = 15;
        tableWidth = 100;
      } else {
        FontMetrics fm = g.getFontMetrics(BODY_FONT);
        tableHeight = fm.getHeight();
        tableWidth = fm.stringWidth(message);
      }
      setPreferredSize(new Dimension(tableWidth, tableHeight));
      repaint();
      return;
    }
   
    if (g == null) {
      headHeight = 16;
      cellHeight = 16;
      cellWidth = 24;
    } else {
      FontMetrics headFm = g.getFontMetrics(HEAD_FONT);
      headHeight = headFm.getHeight();
     
      FontMetrics fm = g.getFontMetrics(BODY_FONT);
      cellHeight = fm.getAscent() + CELL_VERT_SEP;
      cellWidth = fm.stringWidth("00") + CELL_HORZ_SEP;
    }
   
    int rows = 1 << ROW_VARS[table.getInputColumnCount()];
    int cols = 1 << COL_VARS[table.getInputColumnCount()];
    tableWidth = headHeight + cellWidth * (cols + 1);
    tableHeight = headHeight + cellHeight * (rows + 1);
    setPreferredSize(new Dimension(tableWidth, tableHeight));
    invalidate();
    repaint();
View Full Code Here

  @Override
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
   
    TruthTable table = model.getTruthTable();
    int inputCount = table.getInputColumnCount();
    Dimension sz = getSize();
    String message = null;
    if (output == null) {
      message = Strings.get("karnaughNoOutputError");
    } else if (inputCount > MAX_VARS) {
      message = Strings.get("karnaughTooManyInputsError");
    }
    if (message != null) {
      g.setFont(BODY_FONT);
      GraphicsUtil.drawCenteredText(g, message, sz.width / 2, sz.height / 2);
      return;
    }

    int left = computeMargin(sz.width, tableWidth);
    int top = computeMargin(sz.height, tableHeight);
    int x = left;
    int y = top;
    int rowVars = ROW_VARS[inputCount];
    int colVars = COL_VARS[inputCount];
    int rows = 1 << rowVars;
    int cols = 1 << colVars;
   
    g.setFont(HEAD_FONT);
    FontMetrics headFm = g.getFontMetrics();
    String rowHeader = header(0, rowVars);
    String colHeader = header(rowVars, rowVars + colVars);
    int xoffs = (tableWidth + headHeight + cellWidth - headFm.stringWidth(colHeader)) / 2;
    g.drawString(colHeader, x + xoffs, y + headFm.getAscent());
    int headerWidth = headFm.stringWidth(rowHeader);
    if (headerWidth <= headHeight) {
      int headX = x + (headHeight - headerWidth) / 2;
      int headY = y + (tableHeight + headHeight + cellHeight + headFm.getAscent()) / 2;
      g.drawString(rowHeader, headX, headY);
    } else if (g instanceof Graphics2D){
      Graphics2D g2 = (Graphics2D) g.create();
      int yoffs = (tableHeight + headHeight + cellHeight + headerWidth) / 2;
      int headX = x + headFm.getAscent();
      int headY = y + yoffs;
      g2.rotate(-Math.PI / 2.0);
      g2.drawString(rowHeader, -headY, headX);
      g2.dispose();
    }
   
    x += headHeight;
    y += headHeight;
    g.setFont(BODY_FONT);
    FontMetrics fm = g.getFontMetrics();
    int dy = (cellHeight + fm.getAscent()) / 2;
    for (int i = 0; i < cols; i++) {
      String label = label(i, cols);
      g.drawString(label,
        x + (i + 1) * cellWidth + (cellWidth - fm.stringWidth(label)) / 2,
        y + dy);
    }
    for (int i = 0; i < rows; i++) {
      String label = label(i, rows);
      g.drawString(label,
        x + (cellWidth - fm.stringWidth(label)) / 2,
        y + (i + 1) * cellHeight + dy);
    }
   
    int outputColumn = table.getOutputIndex(output);
    x += cellWidth;
    y += cellHeight;
    g.setColor(ERROR_COLOR);
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
        int row = getTableRow(i, j, rows, cols);
        Entry entry = table.getOutputEntry(row, outputColumn);
        if (provisionalValue != null && row == provisionalY
            && outputColumn == provisionalX) entry = provisionalValue;
        if (entry.isError()) {
          g.fillRect(x + j * cellWidth, y + i * cellHeight, cellWidth, cellHeight);
        }
      }
    }
   
    List<Implicant> implicants = model.getOutputExpressions().getMinimalImplicants(output);
    if (implicants != null) {
      int index = 0;
      for (Implicant imp : implicants) {
        g.setColor(IMP_COLORS[index % IMP_COLORS.length]);
        paintImplicant(g, imp, x, y, rows, cols);
        index++;
      }
    }
   
    g.setColor(Color.GRAY);
    if (cols > 1 || inputCount == 0) g.drawLine(x, y, left + tableWidth, y);
    if (rows > 1 || inputCount == 0) g.drawLine(x, y, x, top + tableHeight);
    if (outputColumn < 0) return;
   
    g.setColor(Color.BLACK);
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
        int row = getTableRow(i, j, rows, cols);
        if (provisionalValue != null && row == provisionalY
            && outputColumn == provisionalX) {
          String text = provisionalValue.getDescription();
          g.setColor(Color.GREEN);
          g.drawString(text,
              x + j * cellWidth + (cellWidth - fm.stringWidth(text)) / 2,
              y + i * cellHeight + dy);
          g.setColor(Color.BLACK);
        } else {
          Entry entry = table.getOutputEntry(row, outputColumn);
          String text = entry.getDescription();
          g.drawString(text,
              x + j * cellWidth + (cellWidth - fm.stringWidth(text)) / 2,
              y + i * cellHeight + dy);
        }
View Full Code Here

    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();
View Full Code Here

TOP

Related Classes of com.cburch.logisim.analyze.model.TruthTable

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.