示例#1
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();
    }
  }
 /**
  * @param baseURL may be <code>null</code>
  * @see PropertyPanel.PropertyField#setText
  */
 void setText(String text, String baseURL, DocumentListener documentListener) {
   //
   textComponent.getDocument().removeDocumentListener(documentListener);
   //
   if (editorType == EDITOR_TYPE_STYLED) {
     //
     // --- set content type ---
     ((JEditorPane) textComponent).setContentType("text/html");
     //
     // --- set base URL ---
     try {
       // Note: baseURL is null if no baseURL is set for the corresponding property
       // Note: baseURL is empty if corporate baseURL is used but not set
       if (baseURL != null && !baseURL.equals("")) {
         ((HTMLDocument) textComponent.getDocument()).setBase(new URL(baseURL));
       }
     } catch (MalformedURLException mue) {
       System.out.println("*** TextEditorPanel.setText(): invalid base URL: " + mue);
     }
     //
     // --- set text ---
     try {
       if (text.length() <= 59) { // ### 59 <html><head></head><body></body></html> + whitespace
         text = "<html><body><p></p></body></html>";
       }
       textComponent.setText(text);
       textComponent.setCaretPosition(0);
     } catch (Throwable e) {
       textComponent.setText(
           "<html><body><font color=#FF0000>Page can't be displayed</font></body></html>");
       System.out.println("*** TextEditorPanel.setText(): error while HTML rendering: " + e);
     }
   } else {
     textComponent.setText(text);
     textComponent.setCaretPosition(0);
   }
   //
   textComponent.getDocument().addDocumentListener(documentListener);
 }
 // Create a Transferable implementation that contains the selected text.
 protected Transferable createTransferable(JComponent c) {
   if (c != textComponent) { // ###
     System.out.println("*** createTransferable(): c=" + c);
   }
   source = (JTextComponent) c;
   int start = source.getSelectionStart();
   int end = source.getSelectionEnd();
   Document doc = source.getDocument();
   if (start == end) {
     return null;
   }
   try {
     p0 = doc.createPosition(start);
     p1 = doc.createPosition(end);
     System.out.println(">>> createTransferable(): p0=" + p0 + ", p1=" + p1);
   } catch (BadLocationException e) {
     System.out.println(
         "*** createTransferable(): "
             + "Can't create position - unable to remove text from source.");
   }
   shouldRemove = true;
   String data = source.getSelectedText();
   return new StringSelection(data);
 }