private void openAddressBook() {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);

    fileDialog.setFilterExtensions(new String[] {"*.messages;", "*.*"});
    fileDialog.setFilterNames(
        new String[] {
          resMessages.getString("Book_filter_name") + " (*.messages)",
          resMessages.getString("All_filter_name") + " (*.*)"
        });
    String name = fileDialog.open();
    openAddressBook(name);
  }
Пример #2
0
  private void openFileMenuItemWidgetSelected(SelectionEvent evt) {
    FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
    String filename = dialog.open();
    if (filename != null) {
      getShell().setText(filename);
      File file = new File(filename);
      XML.load(file);
      try {
        XML.Match();
        setStatus(XML.Output);
      } catch (JDOMException e) {

        e.printStackTrace();
      }
    }
  }
Пример #3
0
  //    public static final String showElementTreeAction = "showElementTree";
  // -------------------------------------------------------------
  public void openFile(String currDirStr, String currFileStr) {

    if (fileDialog == null) {
      fileDialog = new FileDialog(this);
    }
    fileDialog.setMode(FileDialog.LOAD);
    if (!(currDirStr.equals(""))) {
      fileDialog.setDirectory(currDirStr);
    }
    if (!(currFileStr.equals(""))) {
      fileDialog.setFile(currFileStr);
    }
    fileDialog.show();

    String file = fileDialog.getFile(); // cancel pushed
    if (file == null) {
      return;
    }
    String directory = fileDialog.getDirectory();
    File f = new File(directory, file);
    if (f.exists()) {
      Document oldDoc = getEditor().getDocument();
      if (oldDoc != null)
        // oldDoc.removeUndoableEditListener(undoHandler);
        /*
          if (elementTreePanel != null) {
          elementTreePanel.setEditor(null);
          }
        */
        getEditor().setDocument(new PlainDocument());
      fileDialog.setTitle(file);
      Thread loader = new FileLoader(f, editor1.getDocument());
      loader.start();
    }
  }
Пример #4
0
  protected void doExportData() {
    FileDialog dialog = new FileDialog(this, "Export Data File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      Writer writer = null;
      try {
        writer = new PrintWriter(file);
        treesPanel.writeDataFile(writer);
        writer.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing data file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
Пример #5
0
  private void doExportTimeTree() {
    FileDialog dialog = new FileDialog(this, "Export Time Tree File...", FileDialog.SAVE);

    dialog.setVisible(true);
    if (dialog.getFile() != null) {
      File file = new File(dialog.getDirectory(), dialog.getFile());

      PrintStream ps = null;
      try {
        ps = new PrintStream(file);
        writeTimeTreeFile(ps);
        ps.close();
      } catch (IOException ioe) {
        JOptionPane.showMessageDialog(
            this,
            "Error writing tree file: " + ioe.getMessage(),
            "Export Error",
            JOptionPane.ERROR_MESSAGE);
      }
    }
  }
Пример #6
0
  private boolean saveAs() {

    FileDialog saveDialog = new FileDialog(shell, SWT.SAVE);
    saveDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"});
    saveDialog.setFilterNames(new String[] {"Address Books (*.adr)", "All Files "});

    saveDialog.open();
    String name = saveDialog.getFileName();

    if (name.equals("")) return false;

    if (name.indexOf(".adr") != name.length() - 4) {
      name += ".adr";
    }

    File file = new File(saveDialog.getFilterPath(), name);
    if (file.exists()) {
      MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.YES | SWT.NO);
      box.setText(resAddressBook.getString("Save_as_title"));
      box.setMessage(
          resAddressBook.getString("File")
              + file.getName()
              + " "
              + resAddressBook.getString("Query_overwrite"));
      if (box.open() != SWT.YES) {
        return false;
      }
    }
    this.file = file;
    return save();
  }
Пример #7
0
  /** Handle ItemEvents. */
  public void itemStateChanged(ItemEvent e) {

    final String dialog_title = ResourceHandler.getMessage("template_dialog.title");

    Component target = (Component) e.getSource();

    if (target == recursiveCheckBox) {
      converter.setRecurse(recursiveCheckBox.isSelected());
    } else if (target == staticVersioningRadioButton || target == dynamicVersioningRadioButton) {
      converter.setStaticVersioning(staticVersioningRadioButton.isSelected());
    } else if (target == templateCh
        && (e.getStateChange() == e.SELECTED)) { // Process only when item is Selected

      // Get the current template selection
      String choiceStr = (String) templateCh.getSelectedItem();

      // If the user chooses 'other', display a file dialog to allow
      // them to select a template file.
      if (choiceStr.equals(TemplateFileChoice.OTHER_STR)) {
        String templatePath = null;
        FileDialog fd = new FileDialog(this, dialog_title, FileDialog.LOAD);
        fd.show();

        // Capture the path entered, if any.
        if (fd.getDirectory() != null && fd.getFile() != null) {
          templatePath = fd.getDirectory() + fd.getFile();
        }

        // If the template file is valid add it and select it.
        if (templatePath != null && setTemplateFile(templatePath)) {
          if (!templateCh.testIfInList(templatePath)) {
            templateCh.addItem(templatePath);
          }
          templateCh.select(templatePath);
        } else {
          templateCh.select(templateCh.getPreviousSelection());
        }
        fd.dispose();
      } else {
        templateCh.select(choiceStr);
      }
    }
  }
  /**
   * Method declaration
   *
   * @param ev
   */
  public void actionPerformed(ActionEvent ev) {

    String s = ev.getActionCommand();

    if (s == null) {
      if (ev.getSource() instanceof MenuItem) {
        MenuItem i;

        s = ((MenuItem) ev.getSource()).getLabel();
      }
    }

    if (s.equals("Execute")) {
      execute();
    } else if (s.equals("Exit")) {
      windowClosing(null);
    } else if (s.equals("Transfer")) {
      Transfer.work(null);
    } else if (s.equals("Dump")) {
      Transfer.work(new String[] {"-d"});

      /* NB - 26052002 Restore is not implemented yet in the transfer tool */
      /*
              } else if (s.equals("Restore")) {
                  Transfer.work(new String[]{"-r"});
      */
    } else if (s.equals("Logging on")) {
      jdbcSystem.setLogToSystem(true);
    } else if (s.equals("Logging off")) {
      jdbcSystem.setLogToSystem(false);
    } else if (s.equals("Refresh Tree")) {
      refreshTree();
    } else if (s.startsWith("#")) {
      int i = Integer.parseInt(s.substring(1));

      txtCommand.setText(sRecent[i]);
    } else if (s.equals("Connect...")) {
      connect(ConnectionDialog.createConnection(fMain, "Connect"));
      refreshTree();
    } else if (s.equals("Results in Grid")) {
      iResult = 0;

      pResult.removeAll();
      pResult.add("Center", gResult);
      pResult.doLayout();
    } else if (s.equals("Open Script...")) {
      FileDialog f = new FileDialog(fMain, "Open Script", FileDialog.LOAD);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        txtCommand.setText(DatabaseManagerCommon.readFile(f.getDirectory() + file));
      }
    } else if (s.equals("Save Script...")) {
      FileDialog f = new FileDialog(fMain, "Save Script", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtCommand.getText());
      }
    } else if (s.equals("Save Result...")) {
      FileDialog f = new FileDialog(fMain, "Save Result", FileDialog.SAVE);

      // (ulrivo): set default directory if set from command line
      if (defDirectory != null) {
        f.setDirectory(defDirectory);
      }

      f.show();

      String file = f.getFile();

      if (file != null) {
        showResultInText();
        DatabaseManagerCommon.writeFile(f.getDirectory() + file, txtResult.getText());
      }
    } else if (s.equals("Results in Text")) {
      iResult = 1;

      pResult.removeAll();
      pResult.add("Center", txtResult);
      pResult.doLayout();
      showResultInText();
    } else if (s.equals("AutoCommit on")) {
      try {
        cConn.setAutoCommit(true);
      } catch (SQLException e) {
      }
    } else if (s.equals("AutoCommit off")) {
      try {
        cConn.setAutoCommit(false);
      } catch (SQLException e) {
      }
    } else if (s.equals("Enlarge Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width += 20;

      tTree.setMinimumSize(d);
      fMain.pack();
    } else if (s.equals("Shrink Tree")) {
      Dimension d = tTree.getMinimumSize();

      d.width -= 20;

      if (d.width >= 0) {
        tTree.setMinimumSize(d);
      }

      fMain.pack();
    } else if (s.equals("Enlarge Command")) {
      txtCommand.setRows(txtCommand.getRows() + 1);
      fMain.pack();
    } else if (s.equals("Shrink Command")) {
      int i = txtCommand.getRows() - 1;

      txtCommand.setRows(i < 1 ? 1 : i);
      fMain.pack();
    } else if (s.equals("Commit")) {
      try {
        cConn.commit();
      } catch (SQLException e) {
      }
    } else if (s.equals("Insert test data")) {
      insertTestData();
    } else if (s.equals("Rollback")) {
      try {
        cConn.rollback();
      } catch (SQLException e) {
      }
    } else if (s.equals("Disable MaxRows")) {
      try {
        sStatement.setMaxRows(0);
      } catch (SQLException e) {
      }
    } else if (s.equals("Set MaxRows to 100")) {
      try {
        sStatement.setMaxRows(100);
      } catch (SQLException e) {
      }
    } else if (s.equals("SELECT")) {
      showHelp(DatabaseManagerCommon.selectHelp);
    } else if (s.equals("INSERT")) {
      showHelp(DatabaseManagerCommon.insertHelp);
    } else if (s.equals("UPDATE")) {
      showHelp(DatabaseManagerCommon.updateHelp);
    } else if (s.equals("DELETE")) {
      showHelp(DatabaseManagerCommon.deleteHelp);
    } else if (s.equals("CREATE TABLE")) {
      showHelp(DatabaseManagerCommon.createTableHelp);
    } else if (s.equals("DROP TABLE")) {
      showHelp(DatabaseManagerCommon.dropTableHelp);
    } else if (s.equals("CREATE INDEX")) {
      showHelp(DatabaseManagerCommon.createIndexHelp);
    } else if (s.equals("DROP INDEX")) {
      showHelp(DatabaseManagerCommon.dropIndexHelp);
    } else if (s.equals("CHECKPOINT")) {
      showHelp(DatabaseManagerCommon.checkpointHelp);
    } else if (s.equals("SCRIPT")) {
      showHelp(DatabaseManagerCommon.scriptHelp);
    } else if (s.equals("SHUTDOWN")) {
      showHelp(DatabaseManagerCommon.shutdownHelp);
    } else if (s.equals("SET")) {
      showHelp(DatabaseManagerCommon.setHelp);
    } else if (s.equals("Test Script")) {
      showHelp(DatabaseManagerCommon.testHelp);
    }
  }
Пример #9
0
  /** Construct the TV object - that is, the main GUI for the program */
  public TV(JFrame f, TD mod) {
    super();
    frm = f;
    theTD = mod;
    JButton b;

    // Build the GUI

    toolBar = new JToolBar();
    toolBar.setFloatable(false);
    toolBar.getAccessibleContext().setAccessibleName("File Toolbar");
    toolBar.addSeparator();
    b = addTool(toolBar, "Cut");
    b = addTool(toolBar, "Copy");
    b = addTool(toolBar, "Paste");
    toolBar.addSeparator();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.FALSE);

    // The Slider
    numSlider = new JSlider(JSlider.HORIZONTAL, 1, 40, 1);
    numSlider.setPaintTicks(true);
    numSlider.setPaintLabels(false);
    numSlider.setMajorTickSpacing(10);
    numSlider.setMinorTickSpacing(2);
    numSlider.setExtent(1);
    numSlider.addChangeListener(
        new ChangeListener() {
          public void stateChanged(ChangeEvent ce) {
            // System.out.println("CHANGE: " + ce);
            setQNumber(((JSlider) (ce.getSource())).getValue());
          }
        });
    numSlider.setToolTipText("Slide to select question by number");
    toolBar.add(numSlider);

    // The Question# textfield
    toolBar.add(numTF = new JTextField("01"));
    numTF.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String num = ((JTextField) e.getSource()).getText();
            int n = Integer.parseInt(num.trim());
            setQNumber(n);
          }
        });
    numTF.setToolTipText("Type number to select question by number");

    // The First Button
    b = addTool(toolBar, "First");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setQNumber(1);
          }
        });

    // The Previous Button
    b = addTool(toolBar, "Previous");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (getQNumber() <= 1) return;
            setQNumber(getQNumber() - 1);
          }
        });

    // The Next Button
    b = addTool(toolBar, "Next");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (getQNumber() >= getNumQuestions()) return;
            setQNumber(getQNumber() + 1);
          }
        });

    // The "Last" Button
    b = addTool(toolBar, "Last");
    b.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            setQNumber(getNumQuestions());
          }
        });

    add(BorderLayout.NORTH, toolBar);

    // Rest is a panel to hold the questions, one at a time.
    questionsPanel = new JPanel();
    questionsPanel.setLayout(myCardLayout = new CardLayout());

    add(BorderLayout.SOUTH, questionsPanel);

    fc = new FileDialog(frm);
    fc.setFilenameFilter(
        new FilenameFilter() {
          public boolean accept(File ff, String fname) {
            // System.out.println("accept("+fname+")");
            // XXX TODO list of extentions, from properties.
            return fname.endsWith(".xam");
          }
        });
    TV.centre(fc);
  }
Пример #10
0
  private void openAddressBook() {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);

    fileDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"});
    fileDialog.setFilterNames(
        new String[] {
          resAddressBook.getString("Book_filter_name") + " (*.adr)",
          resAddressBook.getString("All_filter_name") + " (*.*)"
        });
    String name = fileDialog.open();

    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resAddressBook.getString("File")
              + file.getName()
              + " "
              + resAddressBook.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resAddressBook.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    int writeIndex = 0;
    for (int i = 0; i < data.length; i++) {
      String[] line = decodeLine(data[i]);
      if (line != null) tableInfo[writeIndex++] = line;
    }
    if (writeIndex != data.length) {
      String[][] result = new String[writeIndex][table.getColumnCount()];
      System.arraycopy(tableInfo, 0, result, 0, writeIndex);
      tableInfo = result;
    }
    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName());
    isModified = false;
    this.file = file;
  }
Пример #11
0
  paintboard1(String s) {
    super(s);
    addMouseMotionListener(this);
    addMouseListener(this);

    paintInfo = new Vector();

    /* 各工具按钮及选择项 */
    // 颜色选择
    ColChoice = new Choice();
    ColChoice.add("black");
    ColChoice.add("red");
    ColChoice.add("blue");
    ColChoice.add("green");
    ColChoice.addItemListener(this);
    // 画笔大小选择
    SizeChoice = new Choice();
    SizeChoice.add("1");
    SizeChoice.add("3");
    SizeChoice.add("5");
    SizeChoice.add("7");
    SizeChoice.add("9");
    SizeChoice.addItemListener(this);
    // 橡皮大小选择
    EraserChoice = new Choice();
    EraserChoice.add("5");
    EraserChoice.add("9");
    EraserChoice.add("13");
    EraserChoice.add("17");
    EraserChoice.addItemListener(this);
    // //////////////////////////////////////////////////
    toolPanel = new Panel();

    clear = new Button("清除");
    eraser = new Button("橡皮");
    pen = new Button("画笔");
    drLine = new Button("画直线");
    drCircle = new Button("画圆形");
    drRect = new Button("画矩形");

    openPic = new Button("打开图画");
    savePic = new Button("保存图画");

    colchooser = new Button("显示调色板");

    // 各组件事件监听
    clear.addActionListener(this);
    eraser.addActionListener(this);
    pen.addActionListener(this);
    drLine.addActionListener(this);
    drCircle.addActionListener(this);
    drRect.addActionListener(this);
    openPic.addActionListener(this);
    savePic.addActionListener(this);
    colchooser.addActionListener(this);

    颜色 = new Label("画笔颜色", Label.CENTER);
    大小B = new Label("画笔大小", Label.CENTER);
    大小E = new Label("橡皮大小", Label.CENTER);
    // 面板添加组件
    toolPanel.add(openPic);
    toolPanel.add(savePic);

    toolPanel.add(pen);
    toolPanel.add(drLine);
    toolPanel.add(drCircle);
    toolPanel.add(drRect);

    toolPanel.add(颜色);
    toolPanel.add(ColChoice);
    toolPanel.add(大小B);
    toolPanel.add(SizeChoice);
    toolPanel.add(colchooser);

    toolPanel.add(eraser);
    toolPanel.add(大小E);
    toolPanel.add(EraserChoice);

    toolPanel.add(clear);
    // 工具面板到APPLET面板
    add(toolPanel, BorderLayout.NORTH);

    setBounds(230, 50, 900, 650);
    setVisible(true);
    validate();
    // dialog for save and load

    openPicture = new FileDialog(this, "打开图画", FileDialog.LOAD);
    openPicture.setVisible(false);
    savePicture = new FileDialog(this, "保存图画", FileDialog.SAVE);
    savePicture.setVisible(false);

    openPicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            openPicture.setVisible(false);
          }
        });

    savePicture.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            savePicture.setVisible(false);
          }
        });

    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
          }
        });
  }
Пример #12
0
  public void actionPerformed(ActionEvent e) {
    System.out.println("actionPerformed");
    if (e.getSource() == pen) // 画笔
    {
      System.out.println("pen");
      toolFlag = 0;
    }

    if (e.getSource() == eraser) // 橡皮
    {
      System.out.println("eraser");
      toolFlag = 1;
    }

    if (e.getSource() == clear) // 清除
    {
      System.out.println("clear");
      toolFlag = 2;
      paintInfo.removeAllElements();
      repaint();
    }

    if (e.getSource() == drLine) // 画线
    {
      System.out.println("drLine");
      toolFlag = 3;
    }

    if (e.getSource() == drCircle) // 画圆
    {
      System.out.println("drCircle");
      toolFlag = 4;
    }

    if (e.getSource() == drRect) // 画矩形
    {
      System.out.println("drRect");
      toolFlag = 5;
    }

    if (e.getSource() == colchooser) // 调色板
    {
      System.out.println("colchooser");
      Color newColor = JColorChooser.showDialog(this, "我的调色板", c);
      c = newColor;
    }

    if (e.getSource() == openPic) // 打开图画
    {

      openPicture.setVisible(true);

      if (openPicture.getFile() != null) {
        int tempflag;
        tempflag = toolFlag;
        toolFlag = 2;
        repaint();

        try {
          paintInfo.removeAllElements();
          File filein = new File(openPicture.getDirectory(), openPicture.getFile());
          picIn = new FileInputStream(filein);
          VIn = new ObjectInputStream(picIn);
          paintInfo = (Vector) VIn.readObject();
          VIn.close();
          repaint();
          toolFlag = tempflag;

        } catch (ClassNotFoundException IOe2) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read object");
        } catch (IOException IOe) {
          repaint();
          toolFlag = tempflag;
          System.out.println("can not read file");
        }
      }
    }

    if (e.getSource() == savePic) // 保存图画
    {
      savePicture.setVisible(true);
      try {
        File fileout = new File(savePicture.getDirectory(), savePicture.getFile());
        picOut = new FileOutputStream(fileout);
        VOut = new ObjectOutputStream(picOut);
        VOut.writeObject(paintInfo);
        VOut.close();
      } catch (IOException IOe) {
        System.out.println("can not write object");
      }
    }
  }