public void goTo(int where) { try { if (where < 1) { return; } if (where > db.getRecordCount()) { return; } db.gotoRecord(where); crl.setText("Record " + db.getCurrentRecordNumber()); delCB.setState(db.deleted()); Field f; LogicalField lf; Checkbox c; TextField t; int i; for (i = 1; i <= db.getFieldCount(); i++) { f = db.getField(i); if (f.isMemoField()) { } else if (f.getType() == 'L') { lf = (LogicalField) f; c = (Checkbox) fldObjects.elementAt(i - 1); c.setState(lf.getBoolean()); } else { t = (TextField) fldObjects.elementAt(i - 1); t.setText(f.get().trim()); } } Next.setEnabled(!(db.getCurrentRecordNumber() == db.getRecordCount())); nextRecord.setEnabled(!(db.getCurrentRecordNumber() == db.getRecordCount())); Prev.setEnabled(!(db.getCurrentRecordNumber() == 1)); prevRecord.setEnabled(!(db.getCurrentRecordNumber() == 1)); firstRecord.setEnabled(db.getRecordCount() > 0); lastRecord.setEnabled(db.getRecordCount() > 0); SBrecpos.setValues(db.getCurrentRecordNumber(), 1, 0, db.getRecordCount()); } // try catch (Exception e1) { System.out.println(e1); System.exit(2); } }
public void setFields() { Field f; LogicalField lf; Checkbox c; TextField t; int i; try { for (i = 1; i <= db.getFieldCount(); i++) { f = db.getField(i); if (f.isMemoField() || f.isPictureField()) { } else if (f.isLogicalField()) { lf = (LogicalField) f; c = (Checkbox) fldObjects.elementAt(i - 1); lf.put(c.getState()); } else { t = (TextField) fldObjects.elementAt(i - 1); f.put(t.getText()); } } } catch (Exception e1) { System.out.println(e1); } }
public void actionPerformed(ActionEvent event) { if (event.getSource() == firstRecord) { goTo(1); return; } if (event.getSource() == lastRecord) { goTo(db.getRecordCount()); return; } if (event.getSource() == Next || event.getSource() == nextRecord) { if (db.getCurrentRecordNumber() < db.getRecordCount()) { goTo(db.getCurrentRecordNumber() + 1); } return; } if (event.getSource() == Prev || event.getSource() == prevRecord) { if (db.getCurrentRecordNumber() > 1) { goTo(db.getCurrentRecordNumber() - 1); } return; } if (event.getSource() == Add || event.getSource() == addRecord) { addRec(); return; } if (event.getSource() == Update || event.getSource() == updateRecord) { updateRec(); return; } if (event.getSource() == Clear || event.getSource() == clearRecord) { clearFields(); return; } if (event.getSource() == opener) { FileDialog fd = new FileDialog(this, "dbfShow", FileDialog.LOAD); fd.setFile("*.DBF"); fd.pack(); fd.setVisible(true); String DBFname = fd.getFile(); String dirname = fd.getDirectory(); if (DBFname == null) { return; } if (DBFname.length() < 1) { return; } String dbname = new String(dirname + DBFname); try { setupDBFields(dbname); } catch (Exception e1) { System.out.println(e1); System.exit(4); } pack(); setVisible(true); return; } if (event.getSource() == packer) { packer.setEnabled(false); try { db.pack(); trl.setText(" of " + db.getRecordCount()); } catch (Exception e1) { e1.printStackTrace(); } if (db.getRecordCount() == 0) { Update.setEnabled(false); Next.setEnabled(false); updateRecord.setEnabled(false); nextRecord.setEnabled(false); SBrecpos.setValues(0, 1, 0, 0); } else { goTo(1); } packer.setEnabled(true); return; } if (event.getSource() == quiter) { System.exit(0); return; } if (event.getSource() instanceof Button) { int i; Field f; for (i = 1; i <= db.getFieldCount(); i++) { try { f = db.getField(i); if (f.isMemoField()) { if (event.getActionCommand().equals(f.getName())) { md = new memoDialog(this, f); md.setVisible(true); return; } } } catch (Exception e1) { System.out.println(e1); } } } }
public void setupDBFields(String dbname) throws Exception { viewPane.setLayout(null); Dimension dimView = sp.getSize(); int height = 0, width = 50; viewPane.removeAll(); db = new DBF(dbname); setTitle(dbname); gb = new GridBagLayout(); gbc = new GridBagConstraints(); viewPane.setLayout(gb); int i, j; fldObjects = new Vector(db.getFieldCount()); for (i = 1; i <= db.getFieldCount(); i++) { j = i - 1; f = db.getField(i); if (f.isMemoField() || f.isPictureField()) { b = new Button(db.getField(i).getName()); b.addActionListener(this); addComponent( viewPane, b, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); fldObjects.addElement(b); } else if (f.getType() == 'L') { c = new Checkbox(db.getField(i).getName(), true); addComponent( viewPane, c, 1, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); fldObjects.addElement(c); } else { l = new Label(db.getField(i).getName(), Label.RIGHT); addComponent( viewPane, l, 0, j, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); int ln = f.getLength(); if (ln > 100) { ln = 100; } t = new TextField(db.getField(i).getName(), ln); if (width < ln * 10) { width = ln * 10; } addComponent( viewPane, t, 1, j, ln, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); fldObjects.addElement(t); t.setEditable(true); } height += 10; } crl.setText("Record " + db.getCurrentRecordNumber()); trl.setText(" of " + db.getRecordCount()); SBrecpos.setMaximum(db.getRecordCount()); addComponent(viewPane, crl, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent(viewPane, trl, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); i++; addComponent( viewPane, SBrecpos, 0, i, 2, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, delCB, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); i++; addComponent( viewPane, Prev, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, Next, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); i++; addComponent(viewPane, Add, 0, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, Update, 1, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); addComponent( viewPane, Clear, 2, i, 1, 1, GridBagConstraints.HORIZONTAL, GridBagConstraints.EAST); Prev.setEnabled(false); prevRecord.setEnabled(false); if (db.getRecordCount() == 0) { Update.setEnabled(false); updateRecord.setEnabled(false); Next.setEnabled(false); nextRecord.setEnabled(false); } dimView.setSize(width + 150, height + 150); sp.setSize(dimView); goTo(1); }
public void clearFields() { Field f; Checkbox c; TextField t; int i; for (i = 1; i <= db.getFieldCount(); i++) { try { f = db.getField(i); if (f.isMemoField()) { f.put(""); } else if (f.getType() == 'L') { c = (Checkbox) fldObjects.elementAt(i - 1); c.setState(false); } else { t = (TextField) fldObjects.elementAt(i - 1); t.setText(""); } } catch (Exception e1) { System.out.println(e1); System.exit(3); } } }