Ejemplo n.º 1
2
  @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());
  }
Ejemplo n.º 2
0
  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);
  }
Ejemplo n.º 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());
     }
   }
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
  public void printInputMsg(String name) {
    textPane.setEditable(true);
    if (lastEnd >= 0) {
      textPane.setSelectionStart(lastEnd);
      lastEnd = -1;
    } else textPane.setSelectionStart(textPane.getText().length());
    lastEnd = textPane.getSelectionStart();
    textPane.setSelectionEnd(textPane.getText().length());
    textPane.replaceSelection("");

    textPane.setSelectionStart(textPane.getText().length());
    textPane.setSelectionEnd(textPane.getText().length());
    textPane.setCharacterAttributes(textPane.getStyle("SystemMessage"), true);
    textPane.replaceSelection(name + "\u6b63\u5728\u8f38\u5165\u8a0a\u606f..");
    textPane.setEditable(false);
  }
Ejemplo n.º 6
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;
    }
Ejemplo n.º 7
0
 void insertMatchButton_actionPerformed(ActionEvent e) {
   String key = (String) matchComboBox.getSelectedItem();
   String format = (String) matchesKeys.get(key);
   if (key.equals(STRING_LITERAL)) {
     format =
         escapeReservedChars(
             (String)
                 JOptionPane.showInputDialog(
                     this,
                     "Enter the string you wish to match",
                     "String Literal Input",
                     JOptionPane.OK_CANCEL_OPTION));
     if (StringUtil.isNullString(format)) {
       return;
     }
   }
   if (selectedPane == 0) {
     insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
   } else {
     // add the combobox data value to the edit box
     int pos = formatTextArea.getCaretPosition();
     formatTextArea.insert(format, pos);
   }
 }
Ejemplo n.º 8
0
  public void actionPerformed(ActionEvent e) {
    JTextPane editor = (JTextPane) getEditor(e);
    int p0 = editor.getSelectionStart();
    StyledDocument doc = getStyledDocument(editor);
    Element paragraph = doc.getCharacterElement(p0);
    AttributeSet as = paragraph.getAttributes();

    family = StyleConstants.getFontFamily(as);
    fontSize = StyleConstants.getFontSize(as);

    formatText = new JDialog(new JFrame(), "Font and Size", true);
    formatText.getContentPane().setLayout(new BorderLayout());

    JPanel choosers = new JPanel();
    choosers.setLayout(new GridLayout(2, 1));

    JPanel fontFamilyPanel = new JPanel();
    fontFamilyPanel.add(new JLabel("Font"));

    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    String[] fontNames = ge.getAvailableFontFamilyNames();

    fontFamilyChooser = new JComboBox<String>();
    for (int i = 0; i < fontNames.length; i++) {
      fontFamilyChooser.addItem(fontNames[i]);
    }
    fontFamilyChooser.setSelectedItem(family);
    fontFamilyPanel.add(fontFamilyChooser);
    choosers.add(fontFamilyPanel);

    JPanel fontSizePanel = new JPanel();
    fontSizePanel.add(new JLabel("Size"));
    fontSizeChooser = new JComboBox<Float>();
    fontSizeChooser.setEditable(true);
    for (int size = 2; size <= 60; size += 2) {
      fontSizeChooser.addItem(new Float(size));
    }
    fontSizeChooser.setSelectedItem(new Float(fontSize));
    fontSizePanel.add(fontSizeChooser);
    choosers.add(fontSizePanel);

    JButton ok = new JButton("OK");
    ok.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            accept = true;
            formatText.dispose();
            family = (String) fontFamilyChooser.getSelectedItem();
            fontSize = Float.parseFloat(fontSizeChooser.getSelectedItem().toString());
          }
        });

    JButton cancel = new JButton("Cancel");
    cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            formatText.dispose();
          }
        });

    JPanel buttons = new JPanel();
    buttons.add(ok);
    buttons.add(cancel);
    formatText.getContentPane().add(choosers, BorderLayout.CENTER);
    formatText.getContentPane().add(buttons, BorderLayout.SOUTH);
    formatText.pack();
    formatText.setVisible(true);

    MutableAttributeSet attr = null;
    if (editor != null && accept) {
      attr = new SimpleAttributeSet();
      StyleConstants.setFontFamily(attr, family);
      StyleConstants.setFontSize(attr, (int) fontSize);
      setCharacterAttributes(editor, attr, false);
    }
  }
  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);
  }
Ejemplo n.º 10
0
  void insertButton_actionPerformed(ActionEvent e) {
    Object selected = paramComboBox.getSelectedItem();
    ConfigParamDescr descr;
    String key;
    int type = 0;
    String format = "";
    if (selected instanceof ConfigParamDescr) {
      descr = (ConfigParamDescr) selected;
      key = descr.getKey();
      type = descr.getType();
      switch (type) {
        case ConfigParamDescr.TYPE_STRING:
        case ConfigParamDescr.TYPE_URL:
        case ConfigParamDescr.TYPE_BOOLEAN:
          format = "%s";
          break;
        case ConfigParamDescr.TYPE_INT:
        case ConfigParamDescr.TYPE_LONG:
        case ConfigParamDescr.TYPE_POS_INT:
          NumericPaddingDialog dialog = new NumericPaddingDialog();
          Point pos = this.getLocationOnScreen();
          dialog.setLocation(pos.x, pos.y);
          dialog.pack();
          dialog.setVisible(true);
          StringBuilder fbuf = new StringBuilder("%");
          int width = dialog.getPaddingSize();
          boolean is_zero = dialog.useZero();
          if (width > 0) {
            fbuf.append(".");
            if (is_zero) {
              fbuf.append(0);
            }
            fbuf.append(width);
          }
          if (type == ConfigParamDescr.TYPE_LONG) {
            fbuf.append("ld");
          } else {
            fbuf.append("d");
          }
          format = fbuf.toString();
          break;
        case ConfigParamDescr.TYPE_YEAR:
          if (key.startsWith(DefinableArchivalUnit.PREFIX_AU_SHORT_YEAR)) {
            format = "%02d";
          } else {
            format = "%d";
          }
          break;
        case ConfigParamDescr.TYPE_RANGE:
        case ConfigParamDescr.TYPE_NUM_RANGE:
        case ConfigParamDescr.TYPE_SET:
          format = "%s";
          break;
      }
      if (selectedPane == 0) {
        insertParameter(descr, format, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        int pos = formatTextArea.getCaretPosition();
        formatTextArea.insert(format, pos);

        pos = parameterTextArea.getCaretPosition();
        parameterTextArea.insert(", " + key, pos);
      }
    } else {
      key = selected.toString();
      format =
          escapePrintfChars(
              (String)
                  JOptionPane.showInputDialog(
                      this,
                      "Enter the string you wish to input",
                      "String Literal Input",
                      JOptionPane.OK_CANCEL_OPTION));
      if (StringUtil.isNullString(format)) {
        return;
      }
      if (selectedPane == 0) {
        insertText(format, PLAIN_ATTR, editorPane.getSelectionStart());
      } else if (selectedPane == 1) {
        // add the combobox data value to the edit box
        formatTextArea.insert(format, formatTextArea.getCaretPosition());
      }
    }
  }