Exemplo n.º 1
0
  protected void save(String text) {
    String title = "Save " + textType + " File";
    TextFileFilter fileFilter = getTextFileFilter(textType);
    chooser.setFileFilter(fileFilter);

    if (chooser.showSaveDialog(editor.getFrame()) == JFileChooser.APPROVE_OPTION) {
      String name = chooser.getSelectedFile().toString();
      if (!name.endsWith(fileFilter.getExtension())) {
        name = name + "." + fileFilter.getExtension();
      }
      try {
        editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        FileOutputStream fos = new FileOutputStream(new File(name));
        fos.write(text.getBytes());
        fos.close();
        JOptionPane.showMessageDialog(
            editor.getFrame(),
            textType + " saved successfully to " + name,
            title,
            JOptionPane.INFORMATION_MESSAGE);
      } catch (Exception ex) {
        Logger.getLogger(FileMenuAction.class.getName()).log(Level.SEVERE, null, ex);
        ExceptionHandler.handleException(ex);
        return;
      } finally {
        editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
    }
  }
Exemplo n.º 2
0
  public void actionPerformed(ActionEvent e) {
    String title = textType;
    if (actionType == COPY_ACTION_TYPE) {
      title = "Copy " + textType;
    } else if (actionType == SHOW_ACTION_TYPE) {
      title = "Show " + textType;
    } else if (actionType == SAVE_ACTION_TYPE) {
      title = "Save " + textType;
    }
    String notation = editor.getNotation();
    if (null == notation || notation.trim().length() == 0) {
      JOptionPane.showMessageDialog(
          editor.getFrame(), "Structure is empty!", title, JOptionPane.WARNING_MESSAGE);
      return;
    }

    try {
      editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      String text = "";
      if (textType.equals(NOTATION_TEXT_TYPE)) {
        text = notation;
      } else if (textType.equals(SMILES_TEXT_TYPE)) {
        String smiles = ComplexNotationParser.getComplexPolymerSMILES(notation);
        Molecule mol = StructureParser.getMolecule(smiles);
        mol.dearomatize();
        mol.clean(2, null);
        text = mol.exportToFormat("smiles");
      } else if (textType.equals(PDB_TEXT_TYPE)) {
        new PDBFileGenerator(editor, notation, this).execute();
      } else if (textType.equals(MOLFILE_TEXT_TYPE)) {
        String smiles = ComplexNotationParser.getComplexPolymerSMILES(notation);
        Molecule mol = StructureParser.getMolecule(smiles);
        mol.dearomatize();
        mol.clean(2, null);
        text = mol.exportToFormat("mol");
      } else {
        throw new UnsupportedOperationException("Unsupported operation type :" + textType);
      }

      if (!textType.equals(PDB_TEXT_TYPE)) {
        processResult(text);
      }

    } catch (Exception ex) {
      Logger.getLogger(ShowMolecularStructureAction.class.getName())
          .log(Level.WARNING, ShowMolecularStructureAction.class.getName(), ex);
      ExceptionHandler.handleException(ex);
    } finally {
      if (!textType.equals(PDB_TEXT_TYPE)) {
        editor.getFrame().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
    }
  }
Exemplo n.º 3
0
 public TextMenuAction(MacromoleculeEditor editor, String textType, int actionType) {
   super(textType);
   this.editor = editor;
   this.textType = textType;
   this.actionType = actionType;
   viewer = TextViewer.getInstance(editor.getFrame());
 }