public void refresh() { try { DecimalFormat df = new DecimalFormat("#.00"); ArrayList<BankAccountVO> vos = bankAccountBLService.getBankAccountList(); // defaultTableModel.getDataVector().clear(); Vector<Vector> data = new Vector<Vector>(); for (BankAccountVO vo : vos) { String acc = vo.getAccountUser(); BigDecimal balance = vo.getBalance(); Vector<Object> item = new Vector<Object>(); item.add(acc); item.add(df.format(balance)); data.add(item); // defaultTableModel.addRow(data); } defaultTableModel.setDataVector(data, names); table.revalidate(); table.updateUI(); } catch (RemoteException e) { new TranslucentFrame(this, MessageType.RMI_LAG, Color.ORANGE); } catch (SQLException e) { System.out.println(e.getMessage()); } }
@Test public void should_return_JTableHeader_in_JTable() { JTableHeader expected = table.getTableHeader(); table.startRecording(); assertThat(JTableHeaderQuery.tableHeader(table)).isSameAs(expected); table.requireInvoked("getTableHeader"); }
private void refreshList() { if (isBLInited()) { defaultTableModel.getDataVector().clear(); try { ArrayList<PayReceiptVO> payReceiptVOs = payReceiptBLService.getListByState(ReceiptState.SUBMITTED); ArrayList<TransferReceiptVO> transferReceiptVOs = transferReceiptBLService.getListByState(ReceiptState.SUBMITTED); Vector<Vector> data = new Vector<Vector>(); for (PayReceiptVO vo : payReceiptVOs) { Vector<Object> item = new Vector<Object>(); item.add(vo.getId()); item.add("付款单"); item.add(vo.print()); data.add(item); } for (TransferReceiptVO vo : transferReceiptVOs) { Vector<Object> item = new Vector<Object>(); item.add(vo.getTransferID()); item.add("中转单"); item.add(vo.print()); data.add(item); } defaultTableModel.setDataVector(data, names); table.revalidate(); table.updateUI(); } catch (RemoteException e) { new TranslucentFrame(this, MessageType.RMI_LAG, Color.ORANGE); } catch (SQLException e) { System.out.println(e.getMessage()); } } else { initBL(); } }
public static void main(String[] args) { MyTable t = new MyTable(); t.add('a', "Andrew"); t.add('w', "Willie"); t.add('b', "Billy"); System.out.println(t); System.out.println(t.get('w')); }
public SpreadsheetKeyListener(Application app, MyTable table) { this.app = app; this.kernel = app.getKernel(); this.table = table; this.view = table.getView(); this.model = (DefaultTableModel) table.getModel(); this.editor = table.editor; }
public void commitChanges() throws IOException, RuntimeException { Throwable t = null; RandomAccessFile dataFile = null; try { try { dataFile = new RandomAccessFile(filePath, "rw"); } catch (FileNotFoundException e) { throw new RuntimeException(filePath + " can't get access to file", e); } if (data == null || data.isEmpty()) { closeDataFile(dataFile); Shell sh = new Shell(tablePath, false); if (sh.rm(filePath) != Shell.ExitCode.OK) { throw new RuntimeException(filePath + " can't delete file"); } exists = false; return; } int offset = 0; Set<Map.Entry<String, Storeable>> mySet = data.entrySet(); for (Map.Entry<String, Storeable> myEntry : mySet) { offset += getLength(myEntry.getKey()) + 1 + 4; } int currOffset = offset; dataFile.setLength(0); dataFile.seek(0); for (Map.Entry<String, Storeable> myEntry : mySet) { dataFile.write(myEntry.getKey().getBytes()); dataFile.writeByte(0); dataFile.writeInt(currOffset); currOffset += getLength(table.getProvider().serialize(table, myEntry.getValue())); } for (Map.Entry<String, Storeable> myEntry : mySet) { dataFile.write(table.getProvider().serialize(table, myEntry.getValue()).getBytes()); } } catch (RuntimeException e5) { t = e5; throw e5; } finally { try { closeDataFile(dataFile); } catch (Throwable e6) { if (t != null) { t.addSuppressed(e6); } } } }
public DataBase(MyTable myTable, int numbDir, int numbFile) throws RuntimeException, ParseException { table = myTable; tablePath = table.getTablePath(); ndir = numbDir; nfile = numbFile; filePath = tablePath + File.separator + getFileName(ndir, nfile); File tmpFile = new File(filePath); RandomAccessFile dataFile = null; if (tmpFile.exists()) { try { dataFile = new RandomAccessFile(filePath, "r"); exists = true; load(dataFile); } catch (FileNotFoundException e1) { throw new RuntimeException(filePath + ": can't find file", e1); } catch (IOException e3) { throw new RuntimeException(filePath + ": error in loading file", e3); } finally { try { closeDataFile(dataFile); } catch (Throwable e5) { // } } } }
private void initUI() { names = new Vector<String>(); names.add("单号"); names.add("单据类型"); names.add("单据简述"); defaultTableModel = new EditableTableModel(names, 0); table = new MyTable(defaultTableModel); table.getColumnModel().getColumn(2).setPreferredWidth(300); // 设置单据简述一列较宽 table.getColumnModel().getColumn(0).setWidth(50); table.getColumnModel().getColumn(1).setWidth(50); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); // 设置可多选 this.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(10, 10, 10, 10); gbc.anchor = GridBagConstraints.EAST; gbc.weightx = gbc.weighty = 1.0; gbc.gridx = gbc.gridy = 0; gbc.gridwidth = 3; this.add(new JScrollPane(table), gbc); gbc.weightx = gbc.weighty = 0.0; gbc.fill = GridBagConstraints.NONE; gbc.gridwidth = 1; gbc.gridy++; this.add(approvebt, gbc); gbc.gridx++; this.add(disappbt, gbc); gbc.gridx++; this.add(refreshbt, gbc); this.setOpaque(false); this.setBorder( BorderFactory.createTitledBorder( BorderFactory.createBevelBorder(ALLBITS), "审批单据", TitledBorder.LEFT, TitledBorder.TOP, new Font("", Font.BOLD, 25))); }
public void actionPerformed(ActionEvent e) { if (e.getSource() == addbt) { if (bankAccountBLService != null) { JDialog dialog = new JDialog(parent, "新建银行账户", true); dialog .getContentPane() .add(new BankAccountAddPanel(parent, dialog, this, bankAccountBLService)); dialog.setLocationRelativeTo(parent); dialog.setLocation(dialog.getX() / 2, dialog.getY() / 2); dialog.pack(); dialog.setVisible(true); } else { initBL(); } } else if (e.getSource() == deletebt) { int row = table.getSelectedRow(); if (row >= 0) { if (bankAccountBLService != null) { String account = (String) table.getValueAt(row, 0); try { bankAccountBLService.deleteBankAccount(account); refresh(); new TranslucentFrame(this, MessageType.DELETE_SUCCESS, Color.GREEN); } catch (RemoteException e1) { new TranslucentFrame(this, MessageType.RMI_LAG, Color.ORANGE); } catch (SQLException e1) { System.out.println(e1.getMessage()); } } else { initBL(); } } } else if (e.getSource() == refreshbt) { refresh(); new TranslucentFrame(this, "刷新成功", Color.GREEN); } }
public void load(RandomAccessFile dataFile) throws RuntimeException, IOException, ParseException { try { if (dataFile.length() == 0) { return; } long currPtr = 0; long firstOffset = 0; long newOffset = 0; long nextOffset = 0; String keyFirst = ""; String keySecond = ""; String value; dataFile.seek(currPtr); keyFirst = getKeyFromFile(dataFile); newOffset = dataFile.readInt(); currPtr = dataFile.getFilePointer(); checkOffset(newOffset, currPtr, dataFile); firstOffset = newOffset; do { dataFile.seek(currPtr); if (currPtr < firstOffset) { keySecond = getKeyFromFile(dataFile); nextOffset = dataFile.readInt(); currPtr = dataFile.getFilePointer(); checkOffset(nextOffset, currPtr, dataFile); } else if (currPtr == firstOffset) { nextOffset = dataFile.length(); currPtr++; } if (nextOffset < newOffset) { IOException e1 = new IOException(); throw e1; } dataFile.seek(newOffset); value = getValueFromFile(nextOffset, dataFile); MyStoreable val; try { val = (MyStoreable) table.getProvider().deserialize(table, value); } catch (ParseException e) { throw new ParseException( filePath + " can't deserialize values from file " + e.getMessage(), e.getErrorOffset()); } data.put(keyFirst, val); // table.getHashMap().put(keyFirst, val);*/ keyFirst = keySecond; newOffset = nextOffset; } while (currPtr <= firstOffset); hasChanged = true; } catch (IOException e1) { throw new IOException(filePath + " can't read values from file", e1); } catch (OutOfMemoryError e2) { throw new RuntimeException(filePath + " can't read values from file: out of memory", e2); } }
public void letterOrDigitTyped() { table.setAllowEditing(true); table.repaint(); // G.Sturr 2009-10-10: cleanup when keypress edit begins // check if cell fixed Object o = model.getValueAt(table.getSelectedRow(), table.getSelectedColumn()); if (o != null && o instanceof GeoElement) { GeoElement geo = (GeoElement) o; if (geo.isFixed()) return; } model.setValueAt(null, table.getSelectedRow(), table.getSelectedColumn()); table.editCellAt(table.getSelectedRow(), table.getSelectedColumn()); // workaround, see // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4192625 final JTextComponent f = (JTextComponent) table.getEditorComponent(); f.requestFocus(); f.getCaret().setVisible(true); // workaround for Mac OS X 10.5 problem (first character typed deleted) if (Application.MAC_OS) SwingUtilities.invokeLater( new Runnable() { public void run() { f.setSelectionStart(1); f.setSelectionEnd(1); } }); table.setAllowEditing(false); }
public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); // Application.debug(keyCode+""); // boolean shiftDown = e.isShiftDown(); boolean altDown = e.isAltDown(); boolean ctrlDown = Application.isControlDown(e) // Windows ctrl/Mac Meta || e.isControlDown(); // Fudge (Mac ctrl key) int row = table.getSelectedRow(); int column = table.getSelectedColumn(); switch (keyCode) { case KeyEvent.VK_UP: if (Application.isControlDown(e)) { if (model.getValueAt(row, column) != null) { // move to top of current "block" // if shift pressed, select cells too while (row > 0 && model.getValueAt(row - 1, column) != null) row--; table.changeSelection(row, column, false, e.isShiftDown()); } else { // move up to next defined cell while (row > 0 && model.getValueAt(row - 1, column) == null) row--; table.changeSelection(Math.max(0, row - 1), column, false, false); } e.consume(); } // copy description into input bar when a cell is entered // GeoElement geo = (GeoElement) getModel().getValueAt(table.getSelectedRow() - 1, // table.getSelectedColumn()); // if (geo != null) { // AlgebraInput ai = (AlgebraInput)(app.getGuiManager().getAlgebraInput()); // ai.setString(geo); // } break; case KeyEvent.VK_LEFT: if (Application.isControlDown(e)) { if (model.getValueAt(row, column) != null) { // move to left of current "block" // if shift pressed, select cells too while (column > 0 && model.getValueAt(row, column - 1) != null) column--; table.changeSelection(row, column, false, e.isShiftDown()); } else { // move left to next defined cell while (column > 0 && model.getValueAt(row, column - 1) == null) column--; table.changeSelection(row, Math.max(0, column - 1), false, false); } e.consume(); } // // copy description into input bar when a cell is entered // geo = (GeoElement) getModel().getValueAt(table.getSelectedRow(), // table.getSelectedColumn() - 1); // if (geo != null) { // AlgebraInput ai = (AlgebraInput)(app.getGuiManager().getAlgebraInput()); // ai.setString(geo); // } break; case KeyEvent.VK_DOWN: // auto increase spreadsheet size when you go off the bottom if (table.getSelectedRow() + 1 == table.getRowCount() && table.getSelectedRow() < Kernel.MAX_SPREADSHEET_ROWS) { model.setRowCount(table.getRowCount() + 1); // getView().getRowHeader().revalidate(); //G.STURR 2010-1-9 } else if (Application.isControlDown(e)) { if (model.getValueAt(row, column) != null) { // move to bottom of current "block" // if shift pressed, select cells too while (row < table.getRowCount() - 1 && model.getValueAt(row + 1, column) != null) row++; table.changeSelection(row, column, false, e.isShiftDown()); } else { // move down to next selected cell while (row < table.getRowCount() - 1 && model.getValueAt(row + 1, column) == null) row++; table.changeSelection(Math.min(table.getRowCount() - 1, row + 1), column, false, false); } e.consume(); } // // copy description into input bar when a cell is entered // geo = (GeoElement) getModel().getValueAt(table.getSelectedRow()+1, // table.getSelectedColumn()); // if (geo != null) { // AlgebraInput ai = (AlgebraInput)(app.getGuiManager().getAlgebraInput()); // ai.setString(geo); // } break; case KeyEvent.VK_HOME: // if shift pressed, select cells too if (Application.isControlDown(e)) { // move to top left of spreadsheet table.changeSelection(0, 0, false, e.isShiftDown()); } else { // move to left of current row table.changeSelection(row, 0, false, e.isShiftDown()); } e.consume(); break; case KeyEvent.VK_END: // move to bottom right of spreadsheet // if shift pressed, select cells too // find rectangle that will contain all cells for (int c = 0; c < table.getColumnCount(); c++) for (int r = 0; r < table.getRowCount(); r++) if ((r > row || c > column) && model.getValueAt(r, c) != null) { if (r > row) row = r; if (c > column) column = c; } table.changeSelection(row, column, false, e.isShiftDown()); e.consume(); break; case KeyEvent.VK_RIGHT: // auto increase spreadsheet size when you go off the right if (table.getSelectedColumn() + 1 == table.getColumnCount() && table.getSelectedColumn() < Kernel.MAX_SPREADSHEET_COLUMNS) { table.setMyColumnCount(table.getColumnCount() + 1); view.getColumnHeader().revalidate(); // these two lines are a workaround for Java 6 // (Java bug?) table.changeSelection(row, column + 1, false, false); e.consume(); } else if (Application.isControlDown(e)) { if (model.getValueAt(row, column) != null) { // move to bottom of current "block" // if shift pressed, select cells too while (column < table.getColumnCount() - 1 && model.getValueAt(row, column + 1) != null) column++; table.changeSelection(row, column, false, e.isShiftDown()); } else { // move right to next defined cell while (column < table.getColumnCount() - 1 && model.getValueAt(row, column + 1) == null) column++; table.changeSelection( row, Math.min(table.getColumnCount() - 1, column + 1), false, false); } e.consume(); } // // copy description into input bar when a cell is entered // geo = (GeoElement) getModel().getValueAt(table.getSelectedRow(), // table.getSelectedColumn() + 1); // if (geo != null) { // AlgebraInput ai = (AlgebraInput)(app.getGuiManager().getAlgebraInput()); // ai.setString(geo); // } break; case KeyEvent.VK_SHIFT: case KeyEvent.VK_CONTROL: case KeyEvent.VK_ALT: case KeyEvent.VK_META: // MAC_OS Meta e.consume(); // stops editing start break; case KeyEvent.VK_F9: kernel.updateConstruction(); e.consume(); // stops editing start break; case KeyEvent.VK_R: if (Application.isControlDown(e)) { kernel.updateConstruction(); e.consume(); } else letterOrDigitTyped(); break; // needs to be here to stop keypress starting a cell edit after the undo case KeyEvent.VK_Z: // undo if (ctrlDown) { // Application.debug("undo"); app.getGuiManager().undo(); e.consume(); } else letterOrDigitTyped(); break; // needs to be here to stop keypress starting a cell edit after the redo case KeyEvent.VK_Y: // redo if (ctrlDown) { // Application.debug("redo"); app.getGuiManager().redo(); e.consume(); } else letterOrDigitTyped(); break; case KeyEvent.VK_C: case KeyEvent.VK_V: case KeyEvent.VK_X: case KeyEvent.VK_DELETE: case KeyEvent.VK_BACK_SPACE: if (!editor.isEditing()) { if (Character.isLetterOrDigit(e.getKeyChar()) && !editor.isEditing() && !(ctrlDown || e.isAltDown())) { letterOrDigitTyped(); } else if (ctrlDown) { e.consume(); if (keyCode == KeyEvent.VK_C) { table.copy(altDown); } else if (keyCode == KeyEvent.VK_V) { boolean storeUndo = table.paste(); view.getRowHeader().revalidate(); if (storeUndo) app.storeUndoInfo(); } else if (keyCode == KeyEvent.VK_X) { boolean storeUndo = table.cut(); if (storeUndo) app.storeUndoInfo(); } } if (keyCode == KeyEvent.VK_DELETE || keyCode == KeyEvent.VK_BACK_SPACE) { e.consume(); // Application.debug("deleting..."); boolean storeUndo = table.delete(); if (storeUndo) app.storeUndoInfo(); } return; } break; // case KeyEvent.VK_ENTER: case KeyEvent.VK_F2: if (!editor.isEditing()) { table.setAllowEditing(true); table.editCellAt(table.getSelectedRow(), table.getSelectedColumn()); final JTextComponent f = (JTextComponent) table.getEditorComponent(); f.requestFocus(); f.getCaret().setVisible(true); table.setAllowEditing(false); } e.consume(); break; case KeyEvent.VK_ENTER: if (MyCellEditor.tabReturnCol > -1) { table.changeSelection(row, MyCellEditor.tabReturnCol, false, false); MyCellEditor.tabReturnCol = -1; } // fall through case KeyEvent.VK_PAGE_DOWN: case KeyEvent.VK_PAGE_UP: // stop cell being erased before moving break; // stop TAB erasing cell before moving case KeyEvent.VK_TAB: // disable shift-tab in column A if (table.getSelectedColumn() == 0 && e.isShiftDown()) e.consume(); break; case KeyEvent.VK_A: if (Application.isControlDown(e)) { // select all cells row = 0; column = 0; // find rectangle that will contain all defined cells for (int c = 0; c < table.getColumnCount(); c++) for (int r = 0; r < table.getRowCount(); r++) if ((r > row || c > column) && model.getValueAt(r, c) != null) { if (r > row) row = r; if (c > column) column = c; } table.changeSelection(0, 0, false, false); table.changeSelection(row, column, false, true); e.consume(); } // no break, fall through default: if (!Character.isIdentifierIgnorable(e.getKeyChar()) && !editor.isEditing() && !(ctrlDown || e.isAltDown())) { letterOrDigitTyped(); } else e.consume(); break; } /* if (keyCode >= 37 && keyCode <= 40) { if (editor.isEditing()) return; } for (int i = 0; i < defaultKeyListeners.length; ++ i) { if (e.isConsumed()) break; defaultKeyListeners[i].keyPressed(e); } */ }
public void actionPerformed(ActionEvent e) { if (e.getSource() == approvebt) { int[] rows = table.getSelectedRows(); if (rows.length <= 0) { new TranslucentFrame(this, "请选择要审批的单据(按住ctrl可多选)", Color.RED); } else { // 选择了行 if (isBLInited()) { for (int i : rows) { String id = (String) table.getValueAt(i, 0); String receiptType = (String) table.getValueAt(i, 1); try { if (receiptType.equals("付款单")) { payReceiptBLService.updateState(id, ReceiptState.APPROVED); } else if (receiptType.equals("中转单")) { transferReceiptBLService.updateState(id, ReceiptState.APPROVED); } } catch (RemoteException e1) { new TranslucentFrame(this, MessageType.RMI_LAG, Color.ORANGE); } catch (SQLException e1) { System.out.println(e1.getMessage()); } } refreshList(); new TranslucentFrame(this, "审批成功", Color.GREEN); } else { initBL(); } } } else if (e.getSource() == disappbt) { int[] rows = table.getSelectedRows(); if (rows.length <= 0) { new TranslucentFrame(this, "请选择要审批的单据(按住ctrl可多选)", Color.RED); } else { // 选择了行 if (isBLInited()) { for (int i : rows) { String id = (String) table.getValueAt(i, 0); String receiptType = (String) table.getValueAt(i, 1); try { if (receiptType.equals("付款单")) { payReceiptBLService.updateState(id, ReceiptState.UNAPPROVED); } else if (receiptType.equals("中转单")) { transferReceiptBLService.updateState(id, ReceiptState.UNAPPROVED); } } catch (RemoteException e1) { new TranslucentFrame(this, MessageType.RMI_LAG, Color.ORANGE); } catch (SQLException e1) { System.out.println(e1.getMessage()); } } refreshList(); new TranslucentFrame(this, "审批成功", Color.GREEN); } else { initBL(); } } } else if (e.getSource() == refreshbt) { refreshList(); new TranslucentFrame(this, "刷新成功", Color.GREEN); } }