@Override
  protected Transferable createTransferable(JComponent c) {
    JTextPane aTextPane = (JTextPane) c;

    HTMLEditorKit kit = ((HTMLEditorKit) aTextPane.getEditorKit());
    StyledDocument sdoc = aTextPane.getStyledDocument();
    int sel_start = aTextPane.getSelectionStart();
    int sel_end = aTextPane.getSelectionEnd();

    int i = sel_start;
    StringBuilder output = new StringBuilder();
    while (i < sel_end) {
      Element e = sdoc.getCharacterElement(i);
      Object nameAttr = e.getAttributes().getAttribute(StyleConstants.NameAttribute);
      int start = e.getStartOffset(), end = e.getEndOffset();
      if (nameAttr == HTML.Tag.BR) {
        output.append("\n");
      } else if (nameAttr == HTML.Tag.CONTENT) {
        if (start < sel_start) {
          start = sel_start;
        }
        if (end > sel_end) {
          end = sel_end;
        }
        try {
          String str = sdoc.getText(start, end - start);
          output.append(str);
        } catch (BadLocationException ble) {
          Debug.error(me + "Copy-paste problem!\n%s", ble.getMessage());
        }
      }
      i = end;
    }
    return new StringSelection(output.toString());
  }
  private void _applyFontStyleForSelection(Font font) {
    StyledDocument doc = mTextEditor.getStyledDocument();
    MutableAttributeSet attrs = mTextEditor.getInputAttributes();
    StyleConstants.setFontFamily(attrs, font.getFamily());
    StyleConstants.setFontSize(attrs, font.getSize());
    StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0));
    StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0));
    StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0));

    int start = mTextEditor.getSelectionStart();
    int end = mTextEditor.getSelectionEnd();
    doc.setCharacterAttributes(start, (end - start), attrs, false);
  }
示例#3
0
 @Override
 protected void exportDone(JComponent source, Transferable data, int action) {
   if (action == TransferHandler.MOVE) {
     JTextPane aTextPane = (JTextPane) source;
     int sel_start = aTextPane.getSelectionStart();
     int sel_end = aTextPane.getSelectionEnd();
     Document doc = aTextPane.getDocument();
     try {
       doc.remove(sel_start, sel_end - sel_start);
     } catch (BadLocationException e) {
       Debug.error(me + "exportDone: Problem while trying to remove text\n%s", e.getMessage());
     }
   }
 }
示例#4
0
 private static boolean checkPane(final JTextPane pane) {
   final int startIdx = pane.getSelectionStart();
   final int endIdx = pane.getSelectionEnd();
   if (endIdx > 0) {
     comment(pane, startIdx, endIdx);
   } else {
     final String text = pane.getText();
     if (text.length() == 0) {
       return false;
     }
     comment(pane, startIdx, endIdx);
   }
   return true;
 }
示例#5
0
    @Override
    protected Transferable createTransferable(JComponent c) {
      JTextPane aTextPane = (JTextPane) c;

      SikuliEditorKit kit = ((SikuliEditorKit) aTextPane.getEditorKit());
      Document doc = aTextPane.getDocument();
      int sel_start = aTextPane.getSelectionStart();
      int sel_end = aTextPane.getSelectionEnd();

      StringWriter writer = new StringWriter();
      try {
        _copiedImgs.clear();
        kit.write(writer, doc, sel_start, sel_end - sel_start, _copiedImgs);
        return new StringSelection(writer.toString());
      } catch (Exception e) {
        Debug.error(me + "createTransferable: Problem creating text to copy\n%s", e.getMessage());
      }
      return null;
    }
  public SequenceViewPartExport(SequenceView sv, JTextPane jtp) {
    initComponents();
    _sv = sv;
    //        addWindowListener(new WindowAdapter(){
    //        @Override
    //        public void windowClosing(WindowEvent we){
    //            ClothoDialogBox db = new ClothoDialogBox("Clotho: Exit Check", "Are you sure you
    // want to close the packager?");
    //
    //            if(db.show_optionDialog(javax.swing.JOptionPane.YES_NO_OPTION,
    // javax.swing.JOptionPane.QUESTION_MESSAGE) == javax.swing.JOptionPane.YES_OPTION)
    //                dispose();
    //            }
    //        });
    dataTextPane.setText(jtp.getText());
    if (jtp.getSelectedText() != null) {
      intervalRadioButton.setSelected(true);
      fromTextField.setText(Integer.toString(jtp.getSelectionStart()));
      fromTextField.getDocument().addDocumentListener(new SelectionListener());
      toTextField.setText(Integer.toString(jtp.getSelectionEnd()));
      toTextField.getDocument().addDocumentListener(new SelectionListener());
      try {
        //                dataTextPane.grabFocus();
        dataTextPane.select(jtp.getSelectionStart(), jtp.getSelectionEnd());
        dataTextPane
            .getHighlighter()
            .addHighlight(
                jtp.getSelectionStart(),
                jtp.getSelectionEnd(),
                new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(
                    dataTextPane.getSelectionColor()));
      } catch (Exception e) {
      }
    } else {
      try {
        //                dataTextPane.grabFocus();
        dataTextPane.selectAll();
        dataTextPane
            .getHighlighter()
            .addHighlight(
                0,
                dataTextPane.getText().length(),
                new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(
                    dataTextPane.getSelectionColor()));
      } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
      }
      fromTextField.setText("0");
      toTextField.setText(Integer.toString(jtp.getText().length()));
      wsRadioButton.setSelected(true);
      try {
        dataTextPane
            .getHighlighter()
            .addHighlight(
                0,
                dataTextPane.getText().length(),
                new javax.swing.text.DefaultHighlighter.DefaultHighlightPainter(
                    dataTextPane.getSelectionColor()));
        dataTextPane.grabFocus();
        dataTextPane.selectAll();
      } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
      }
    }
    ArrayList<ObjLink> collectionLinks = Collector.getAllLinksOf(ObjType.COLLECTION);
    collectionComboBox.removeAllItems();
    for (ObjLink oj : collectionLinks) {
      collectionComboBox.addItem(oj);
    }
    collectionComboBox.setSelectedIndex(-1);
    formatComboBox.removeAllItems();
    ArrayList<ObjLink> formatLinks = Collector.getAllLinksOf(ObjType.FORMAT);
    for (ObjLink oj : formatLinks) {
      formatComboBox.addItem(oj);
    }
    formatComboBox.setSelectedIndex(-1);
    objectTypeComboBox.removeAllItems();
    objectTypeComboBox.addItem("Feature");
    objectTypeComboBox.addItem("Oligo");
    objectTypeComboBox.addItem("Part");
    objectTypeComboBox.addItem("Vector");
    objectTypeComboBox.setSelectedIndex(-1);
    formatComboBox.setEnabled(false);
    formatLabel.setEnabled(false);

    this.setVisible(true);
  }