// Initializes this component. private void jbInit() { segmentTable.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) { segmentTable_focusGained(e); } public void focusLost(FocusEvent e) { segmentTable_focusLost(e); } }); segmentTable.setTableHeader(null); scrollPane = new JScrollPane(segmentTable); scrollPane.setMinimumSize(new Dimension(getTableWidth(), 0)); setLayout(new BorderLayout(0, 0)); determineColumnWidth(); nameLbl.setPreferredSize(new Dimension(getTableWidth(), 25)); nameLbl.setMinimumSize(new Dimension(getTableWidth(), 0)); nameLbl.setFont(Utilities.labelsFont); segmentTable.setFont(Utilities.valueFont); setBorder(BorderFactory.createEtchedBorder()); setMinimumSize(new Dimension(getTableWidth(), 0)); this.add(nameLbl, BorderLayout.NORTH); this.add(scrollPane, BorderLayout.CENTER); }
/** Returns the coordinates of the top left corner of the value at the given index. */ public Point getCoordinates(int index) { JScrollBar bar = scrollPane.getVerticalScrollBar(); Rectangle r = segmentTable.getCellRect(index, 1, true); segmentTable.scrollRectToVisible(r); setTopLevelLocation(); return new Point( (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY())); }
// Determines the width of each column in the table. protected void determineColumnWidth() { if (segmentTable.getColumnCount() == 2) { TableColumn column = null; for (int i = 0; i < 2; i++) { column = segmentTable.getColumnModel().getColumn(i); if (i == 0) { column.setPreferredWidth(30); } else { column.setPreferredWidth(100); } } } }
/** Constructs a new MemorySegmentComponent. */ public MemorySegmentComponent() { dataFormat = Format.DEC_FORMAT; listeners = new Vector(); errorEventListeners = new Vector(); highlightIndex = new Vector(); segmentTable = new JTable(getTableModel()); segmentTable.setDefaultRenderer(segmentTable.getColumnClass(0), getCellRenderer()); startEnabling = -1; endEnabling = -1; JTextField tf = new JTextField(); tf.setFont(Utilities.bigBoldValueFont); tf.setBorder(null); DefaultCellEditor editor = new DefaultCellEditor(tf); segmentTable.getColumnModel().getColumn(getColumnValue()).setCellEditor(editor); jbInit(); }
/** The action of the table loosing the focus. */ public void segmentTable_focusLost(FocusEvent e) { segmentTable.clearSelection(); }
/** The action of the table gaining the focus. */ public void segmentTable_focusGained(FocusEvent e) { segmentTable.clearSelection(); notifyListeners(); }
/** Sets the number of visible rows. */ public void setVisibleRows(int num) { int tableHeight = num * segmentTable.getRowHeight(); scrollPane.setSize(getTableWidth(), tableHeight + 3); setPreferredSize(new Dimension(getTableWidth(), tableHeight + 30)); setSize(getTableWidth(), tableHeight + 30); }
/** Hides all selections. */ public void hideSelect() { segmentTable.clearSelection(); }
/** Called when revalidate is required. */ public void revalidateChange() { segmentTable.revalidate(); repaint(); }
/** Resets the contents of this MemorySegmentComponent. */ public void reset() { segmentTable.clearSelection(); hideFlash(); hideHighlight(); }
/** Sets the start address. */ public void setStartAddress(int index) { startAddress = index; segmentTable.revalidate(); }
/** * Sets the starting address with the given address. This should display the relevant memory * segment (the data should be taken from the main memory gui). */ public void setValueAt(int index, short value) { Rectangle r = segmentTable.getCellRect(index, 0, true); segmentTable.scrollRectToVisible(r); repaint(); }