jdk/src/share/classes/javax/swing/JEditorPane.java
changeset 1301 15e81207e1f2
parent 715 f16baef3a20e
child 3737 83fb4621a129
equal deleted inserted replaced
1300:e7bbe37ce03a 1301:15e81207e1f2
   317      * @return all of the <code>HyperLinkListener</code>s added or an empty
   317      * @return all of the <code>HyperLinkListener</code>s added or an empty
   318      *         array if no listeners have been added
   318      *         array if no listeners have been added
   319      * @since 1.4
   319      * @since 1.4
   320      */
   320      */
   321     public synchronized HyperlinkListener[] getHyperlinkListeners() {
   321     public synchronized HyperlinkListener[] getHyperlinkListeners() {
   322         return (HyperlinkListener[])listenerList.getListeners(
   322         return listenerList.getListeners(javax.swing.event.HyperlinkListener.class);
   323                 HyperlinkListener.class);
       
   324     }
   323     }
   325 
   324 
   326     /**
   325     /**
   327      * Notifies all listeners that have registered interest for
   326      * Notifies all listeners that have registered interest for
   328      * notification on this event type.  This is normally called
   327      * notification on this event type.  This is normally called
   490     private Document initializeModel(EditorKit kit, URL page) {
   489     private Document initializeModel(EditorKit kit, URL page) {
   491         Document doc = kit.createDefaultDocument();
   490         Document doc = kit.createDefaultDocument();
   492         if (pageProperties != null) {
   491         if (pageProperties != null) {
   493             // transfer properties discovered in stream to the
   492             // transfer properties discovered in stream to the
   494             // document property collection.
   493             // document property collection.
   495             for (Enumeration e = pageProperties.keys(); e.hasMoreElements() ;) {
   494             for (Enumeration<String> e = pageProperties.keys(); e.hasMoreElements() ;) {
   496                 Object key = e.nextElement();
   495                 String key = e.nextElement();
   497                 doc.putProperty(key, pageProperties.get(key));
   496                 doc.putProperty(key, pageProperties.get(key));
   498             }
   497             }
   499             pageProperties.clear();
   498             pageProperties.clear();
   500         }
   499         }
   501         if (doc.getProperty(Document.StreamDescriptionProperty) == null) {
   500         if (doc.getProperty(Document.StreamDescriptionProperty) == null) {
   773     /**
   772     /**
   774      * Handle URL connection properties (most notably, content type).
   773      * Handle URL connection properties (most notably, content type).
   775      */
   774      */
   776     private void handleConnectionProperties(URLConnection conn) {
   775     private void handleConnectionProperties(URLConnection conn) {
   777         if (pageProperties == null) {
   776         if (pageProperties == null) {
   778             pageProperties = new Hashtable();
   777             pageProperties = new Hashtable<String, Object>();
   779         }
   778         }
   780         String type = conn.getContentType();
   779         String type = conn.getContentType();
   781         if (type != null) {
   780         if (type != null) {
   782             setContentType(type);
   781             setContentType(type);
   783             pageProperties.put("content-type", type);
   782             pageProperties.put("content-type", type);
   987     /**
   986     /**
   988      * This method gets the charset information specified as part
   987      * This method gets the charset information specified as part
   989      * of the content type in the http header information.
   988      * of the content type in the http header information.
   990      */
   989      */
   991     private void setCharsetFromContentTypeParameters(String paramlist) {
   990     private void setCharsetFromContentTypeParameters(String paramlist) {
   992         String charset = null;
   991         String charset;
   993         try {
   992         try {
   994             // paramlist is handed to us with a leading ';', strip it.
   993             // paramlist is handed to us with a leading ';', strip it.
   995             int semi = paramlist.indexOf(';');
   994             int semi = paramlist.indexOf(';');
   996             if (semi > -1 && semi < paramlist.length()-1) {
   995             if (semi > -1 && semi < paramlist.length()-1) {
   997                 paramlist = paramlist.substring(semi + 1);
   996                 paramlist = paramlist.substring(semi + 1);
  1078      * @param type the non-<code>null</code> content type
  1077      * @param type the non-<code>null</code> content type
  1079      * @return the editor kit
  1078      * @return the editor kit
  1080      */
  1079      */
  1081     public EditorKit getEditorKitForContentType(String type) {
  1080     public EditorKit getEditorKitForContentType(String type) {
  1082         if (typeHandlers == null) {
  1081         if (typeHandlers == null) {
  1083             typeHandlers = new Hashtable(3);
  1082             typeHandlers = new Hashtable<String, EditorKit>(3);
  1084         }
  1083         }
  1085         EditorKit k = (EditorKit) typeHandlers.get(type);
  1084         EditorKit k = typeHandlers.get(type);
  1086         if (k == null) {
  1085         if (k == null) {
  1087             k = createEditorKitForContentType(type);
  1086             k = createEditorKitForContentType(type);
  1088             if (k != null) {
  1087             if (k != null) {
  1089                 setEditorKitForContentType(type, k);
  1088                 setEditorKitForContentType(type, k);
  1090             }
  1089             }
  1104      * @param type the non-<code>null</code> content type
  1103      * @param type the non-<code>null</code> content type
  1105      * @param k the editor kit to be set
  1104      * @param k the editor kit to be set
  1106      */
  1105      */
  1107     public void setEditorKitForContentType(String type, EditorKit k) {
  1106     public void setEditorKitForContentType(String type, EditorKit k) {
  1108         if (typeHandlers == null) {
  1107         if (typeHandlers == null) {
  1109             typeHandlers = new Hashtable(3);
  1108             typeHandlers = new Hashtable<String, EditorKit>(3);
  1110         }
  1109         }
  1111         typeHandlers.put(type, k);
  1110         typeHandlers.put(type, k);
  1112     }
  1111     }
  1113 
  1112 
  1114     /**
  1113     /**
  1174      * @param type the content type
  1173      * @param type the content type
  1175      * @return the editor kit, or <code>null</code> if there is nothing
  1174      * @return the editor kit, or <code>null</code> if there is nothing
  1176      *   registered for the given type
  1175      *   registered for the given type
  1177      */
  1176      */
  1178     public static EditorKit createEditorKitForContentType(String type) {
  1177     public static EditorKit createEditorKitForContentType(String type) {
  1179         EditorKit k = null;
  1178         Hashtable<String, EditorKit> kitRegistry = getKitRegisty();
  1180         Hashtable kitRegistry = getKitRegisty();
  1179         EditorKit k = kitRegistry.get(type);
  1181         k = (EditorKit) kitRegistry.get(type);
       
  1182         if (k == null) {
  1180         if (k == null) {
  1183             // try to dynamically load the support
  1181             // try to dynamically load the support
  1184             String classname = (String) getKitTypeRegistry().get(type);
  1182             String classname = getKitTypeRegistry().get(type);
  1185             ClassLoader loader = (ClassLoader) getKitLoaderRegistry().get(type);
  1183             ClassLoader loader = getKitLoaderRegistry().get(type);
  1186             try {
  1184             try {
  1187                 Class c;
  1185                 Class c;
  1188                 if (loader != null) {
  1186                 if (loader != null) {
  1189                     c = loader.loadClass(classname);
  1187                     c = loader.loadClass(classname);
  1190                 } else {
  1188                 } else {
  1250      * @param type  the non-<code>null</code> content type
  1248      * @param type  the non-<code>null</code> content type
  1251      *
  1249      *
  1252      * @since 1.3
  1250      * @since 1.3
  1253      */
  1251      */
  1254     public static String getEditorKitClassNameForContentType(String type) {
  1252     public static String getEditorKitClassNameForContentType(String type) {
  1255         return (String)getKitTypeRegistry().get(type);
  1253         return getKitTypeRegistry().get(type);
  1256     }
  1254     }
  1257 
  1255 
  1258     private static Hashtable getKitTypeRegistry() {
  1256     private static Hashtable<String, String> getKitTypeRegistry() {
  1259         loadDefaultKitsIfNecessary();
  1257         loadDefaultKitsIfNecessary();
  1260         return (Hashtable)SwingUtilities.appContextGet(kitTypeRegistryKey);
  1258         return (Hashtable)SwingUtilities.appContextGet(kitTypeRegistryKey);
  1261     }
  1259     }
  1262 
  1260 
  1263     private static Hashtable getKitLoaderRegistry() {
  1261     private static Hashtable<String, ClassLoader> getKitLoaderRegistry() {
  1264         loadDefaultKitsIfNecessary();
  1262         loadDefaultKitsIfNecessary();
  1265         return (Hashtable)SwingUtilities.appContextGet(kitLoaderRegistryKey);
  1263         return (Hashtable)SwingUtilities.appContextGet(kitLoaderRegistryKey);
  1266     }
  1264     }
  1267 
  1265 
  1268     private static Hashtable getKitRegisty() {
  1266     private static Hashtable<String, EditorKit> getKitRegisty() {
  1269         Hashtable ht = (Hashtable)SwingUtilities.appContextGet(kitRegistryKey);
  1267         Hashtable ht = (Hashtable)SwingUtilities.appContextGet(kitRegistryKey);
  1270         if (ht == null) {
  1268         if (ht == null) {
  1271             ht = new Hashtable(3);
  1269             ht = new Hashtable(3);
  1272             SwingUtilities.appContextPut(kitRegistryKey, ht);
  1270             SwingUtilities.appContextPut(kitRegistryKey, ht);
  1273         }
  1271         }
  1510      * Current content binding of the editor.
  1508      * Current content binding of the editor.
  1511      */
  1509      */
  1512     private EditorKit kit;
  1510     private EditorKit kit;
  1513     private boolean isUserSetEditorKit;
  1511     private boolean isUserSetEditorKit;
  1514 
  1512 
  1515     private Hashtable pageProperties;
  1513     private Hashtable<String, Object> pageProperties;
  1516 
  1514 
  1517     /** Should be kept in sync with javax.swing.text.html.FormView counterpart. */
  1515     /** Should be kept in sync with javax.swing.text.html.FormView counterpart. */
  1518     final static String PostDataProperty = "javax.swing.JEditorPane.postdata";
  1516     final static String PostDataProperty = "javax.swing.JEditorPane.postdata";
  1519 
  1517 
  1520     /**
  1518     /**
  1521      * Table of registered type handlers for this editor.
  1519      * Table of registered type handlers for this editor.
  1522      */
  1520      */
  1523     private Hashtable typeHandlers;
  1521     private Hashtable<String, EditorKit> typeHandlers;
  1524 
  1522 
  1525     /*
  1523     /*
  1526      * Private AppContext keys for this class's static variables.
  1524      * Private AppContext keys for this class's static variables.
  1527      */
  1525      */
  1528     private static final Object kitRegistryKey =
  1526     private static final Object kitRegistryKey =
  1911             public int getEndIndex() {
  1909             public int getEndIndex() {
  1912                 return element.getEndOffset();
  1910                 return element.getEndOffset();
  1913             }
  1911             }
  1914         }
  1912         }
  1915 
  1913 
  1916         private class LinkVector extends Vector {
  1914         private class LinkVector extends Vector<HTMLLink> {
  1917             public int baseElementIndex(Element e) {
  1915             public int baseElementIndex(Element e) {
  1918                 HTMLLink l;
  1916                 HTMLLink l;
  1919                 for (int i = 0; i < elementCount; i++) {
  1917                 for (int i = 0; i < elementCount; i++) {
  1920                     l = (HTMLLink) elementAt(i);
  1918                     l = elementAt(i);
  1921                     if (l.element == e) {
  1919                     if (l.element == e) {
  1922                         return i;
  1920                         return i;
  1923                     }
  1921                     }
  1924                 }
  1922                 }
  1925                 return -1;
  1923                 return -1;
  2027         public AccessibleHyperlink getLink(int linkIndex) {
  2025         public AccessibleHyperlink getLink(int linkIndex) {
  2028             if (linksValid == false) {
  2026             if (linksValid == false) {
  2029                 buildLinkTable();
  2027                 buildLinkTable();
  2030             }
  2028             }
  2031             if (linkIndex >= 0 && linkIndex < hyperlinks.size()) {
  2029             if (linkIndex >= 0 && linkIndex < hyperlinks.size()) {
  2032                 return (AccessibleHyperlink) hyperlinks.elementAt(linkIndex);
  2030                 return hyperlinks.elementAt(linkIndex);
  2033             } else {
  2031             } else {
  2034                 return null;
  2032                 return null;
  2035             }
  2033             }
  2036         }
  2034         }
  2037 
  2035