1 7 8 package org.jdesktop.jdnc; 9 10 import java.awt.Dimension ; 11 12 import java.net.URL ; 13 import java.net.MalformedURLException ; 14 15 import javax.swing.JPanel ; 16 import javax.swing.JEditorPane ; 17 import javax.swing.JScrollPane ; 18 19 import org.jdesktop.swing.Application; 20 import org.jdesktop.swing.JXEditorPane; 21 22 import org.jdesktop.swing.actions.ActionManager; 23 24 38 public class JNEditor extends JNComponent { 39 40 private JXEditorPane editor; 41 private String inputURL; 42 private boolean readonly; 43 private static final String DEFAULT_TYPE = "text/plain"; 44 45 private String type = DEFAULT_TYPE; 46 47 public JNEditor() { 48 editor = new JXEditorPane("text/html", ""); 49 setComponent(editor); 51 add(new JScrollPane (editor)); 52 } 53 54 public JXEditorPane getEditor() { 55 return editor; 56 } 57 58 public void setReadOnly(boolean ro) { 59 this.readonly = ro; 60 editor.setEditable(!readonly); 61 } 62 63 public boolean isReadOnly() { 64 return readonly; 65 } 66 67 70 public void setInputURL(String inputURL) { 71 if (editor != null && inputURL != null) { 72 URL url = Application.getURL(inputURL, this); 73 if (url != null) { 74 setInputURL(url); 75 } 76 } 77 } 78 79 public void setInputURL(URL url) { 80 if (editor != null && url != null) { 81 this.inputURL = url.toString(); 82 try { 83 editor.setPage(url); 84 } catch (Exception ex) { 85 System.out.println("Error Setting page url: " + url); 86 ex.printStackTrace(); 87 } 88 } 89 } 90 91 92 public String getInputURL() { 93 return inputURL; 94 } 95 96 public void setDocumentType(String type) { 98 if (!"text/html".equals(type)) { 99 type = DEFAULT_TYPE; 100 } 101 if (type == null || "".equals(type)) { 102 type = DEFAULT_TYPE; 103 } 104 this.type = type; 105 106 editor.setContentType(type); 107 } 108 109 public String getDocumentType() { 110 return type; 111 } 112 113 private static final Dimension MAX_SIZE = new Dimension (400, 300); 116 117 public Dimension getPreferredSize() { 118 return MAX_SIZE; 119 } 120 } 121 | Popular Tags |