Beispiel #1
0
  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);
    }
  }
Beispiel #2
0
 public void addRec() {
   try {
     setFields();
     db.write();
     goTo(db.getRecordCount());
     delCB.setState(false);
     trl.setText(" of " + db.getRecordCount());
   } // try
   catch (Exception e1) {
     System.out.println(e1);
     System.exit(1);
   }
   Update.setEnabled(true);
   updateRecord.setEnabled(true);
 }
Beispiel #3
0
  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);
        }
      }
    }
  }
Beispiel #4
0
  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 DaylightTracker2() {
    // This code is automatically generated by Visual Cafe when you add
    // components to the visual environment. It instantiates and initializes
    // the components. To modify the code, only use code syntax that matches
    // what Visual Cafe can generate, or Visual Cafe may be unable to back
    // parse your Java file into its visual environment.
    // {{INIT_CONTROLS
    getContentPane().setLayout(new BorderLayout());
    setSize(560, 300);
    setTitle("Day and Night");
    // }}

    // setResizable(false);

    JPanel theRealBasePanel = new JPanel();
    theRealBasePanel.setLayout(new MultiCompBorderLayout());
    getContentPane().add(theRealBasePanel);

    MenuBar theMenuBar = new MenuBar();
    setMenuBar(theMenuBar);

    theMenuBar.add(fileMenu = new Menu("File"));
    fileMenu.add(file_quitItem = new MenuItem("Quit"));

    theMenuBar.add(editMenu = new Menu("Edit"));
    editMenu.add(edit_undoItem = new MenuItem("Undo"));
    edit_undoItem.setEnabled(false);
    editMenu.add(new MenuItem("-"));
    editMenu.add(edit_cutItem = new MenuItem("Cut"));
    edit_cutItem.setEnabled(false);
    editMenu.add(edit_copyItem = new MenuItem("Copy"));
    edit_copyItem.setEnabled(false);
    editMenu.add(edit_pasteItem = new MenuItem("Paste"));
    edit_pasteItem.setEnabled(false);
    editMenu.add(edit_clearItem = new MenuItem("Clear"));
    edit_clearItem.setEnabled(false);
    editMenu.add(new MenuItem("-"));
    editMenu.add(edit_prefsItem = new MenuItem("Preferences..."));

    theMenuBar.add(layersMenu = new Menu("Layers"));

    theMenuBar.setHelpMenu(helpMenu = new Menu("Help"));
    helpMenu.add(help_aboutItem = new MenuItem("About JSunTool..."));

    allMapLayers.addElement(new OverlayedTimeLayer());
    allMapLayers.addElement(new NightDay());
    allMapLayers.addElement(new GeographicalMap());
    allMapLayers.addElement(new TopographicalMap());

    menuMapLayers = new CheckboxMenuItem[allMapLayers.size()];

    CheckboxMenuActionListener theCheckboxMenuActionListener = new CheckboxMenuActionListener();

    for (int i = 0; i < allMapLayers.size(); i++) {

      visibleMapLayers.addElement(allMapLayers.elementAt(i));
      theRealBasePanel.add((Component) (visibleMapLayers.elementAt(i)));

      // CheckboxMenuItem tempMenuItem
      menuMapLayers[i] =
          new CheckboxMenuItem(((MapLayer) (allMapLayers.elementAt(i))).getShortName(), true);
      menuMapLayers[i].setActionCommand(new String("MapLayer." + i));
      menuMapLayers[i].addItemListener(theCheckboxMenuActionListener);
      layersMenu.add(menuMapLayers[i]);
    }

    // {{INIT_MENUS
    // }}

    // {{REGISTER_LISTENERS
    SymWindow aSymWindow = new SymWindow();
    this.addWindowListener(aSymWindow);
    // }}

    // Timer theTimer = new Timer ( 1800000, new TimerActionListener() );
    //		Timer theTimer = new Timer ( 1000, new TimerActionListener() );
    //		theTimer.start();
    (new Thread(this)).start();

    MenuActionListener theMenuActionListener = new MenuActionListener();
    file_quitItem.addActionListener(theMenuActionListener);
    help_aboutItem.addActionListener(theMenuActionListener);
  }