Esempio n. 1
0
  public void setEditorKitForContentType(final String type, final EditorKit kit) {
    if (type == null) {
      throw new NullPointerException(
          Messages.getString("swing.03", "Content type")); // $NON-NLS-1$ //$NON-NLS-2$
    }

    if (kit == null) {
      throw new NullPointerException(
          Messages.getString("swing.03", "Editor kit")); // $NON-NLS-1$ //$NON-NLS-2$
    }
    localContentTypes.put(type, kit);
  }
Esempio n. 2
0
  public static void registerEditorKitForContentType(
      final String type, final String editorKitName, final ClassLoader loader) {
    if (type == null) {
      throw new NullPointerException(
          Messages.getString("swing.03", "Content type")); // $NON-NLS-1$ //$NON-NLS-2$
    }

    if (editorKitName == null) {
      throw new NullPointerException(
          Messages.getString("swing.03", "Class name")); // $NON-NLS-1$ //$NON-NLS-2$
    }
    contentTypes.put(
        type,
        new ContentTypeRegistration(
            editorKitName,
            ((loader != null) ? loader : Thread.currentThread().getContextClassLoader())));
  }
Esempio n. 3
0
  public static String getEditorKitClassNameForContentType(final String type) {
    if (type == null) {
      throw new NullPointerException(
          Messages.getString("swing.03", "Content type")); // $NON-NLS-1$ //$NON-NLS-2$
    }
    ContentTypeRegistration registration = contentTypes.get(type);

    return ((registration != null) ? registration.className : null);
  }
Esempio n. 4
0
  public JEditorPane(final String type, final String text) {
    this();

    if (type == null) {
      throw new NullPointerException(
          Messages.getString("swing.03", "Content type")); // $NON-NLS-1$ //$NON-NLS-2$
    }
    setContentType(type);
    setText(text);
  }
Esempio n. 5
0
  public void setPage(final URL page) throws IOException {
    if (page == null) {
      throw new IOException(Messages.getString("swing.03", "Page")); // $NON-NLS-1$ //$NON-NLS-2$
    }

    String url = page.toString();
    String baseUrl = getBaseURL(url);
    Document oldDoc = getDocument();
    if (baseUrl != null
        && oldDoc != null
        && baseUrl.equals(oldDoc.getProperty(Document.StreamDescriptionProperty))) {

      scrollToReference(page.getRef());
      return;
    }
    InputStream stream = getStream(page);
    if (stream == null) {
      return;
    }
    Document newDoc = editorKit.createDefaultDocument();
    // Perhaps, it is reasonable only for HTMLDocument...
    if (newDoc instanceof HTMLDocument) {
      newDoc.putProperty(Document.StreamDescriptionProperty, baseUrl);
      newDoc.putProperty(StringConstants.IGNORE_CHARSET_DIRECTIVE, new Boolean(false));
      try {
        ((HTMLDocument) newDoc).setBase(new URL(baseUrl));
      } catch (IOException e) {
      }
    }
    // TODO Asynch loading doesn't work with completely.
    // Also page property change event is written incorrectly now
    // (at the asynchrounous loading), because loading may not be
    // completed.
    // int asynchronousLoadPriority = getAsynchronousLoadPriority(newDoc);
    int asynchronousLoadPriority = -1;
    if (asynchronousLoadPriority >= 0) {
      setDocument(newDoc);
      AsynchLoad newThread = new AsynchLoad(asynchronousLoadPriority, stream, page);
      newThread.start();
      if (newThread.successfulLoading) {
        changePage(page);
      }
    } else {
      try {
        documentLoading(stream, newDoc, page);
        stream.close();
        setDocument(newDoc);
        changePage(page);
      } catch (IOException e) {
      }
    }
  }
Esempio n. 6
0
 public static void installProperty(
     final JComponent c, final String propertyName, final Object propertyValue) {
   if (c.installablePropertiesExcluded.contains(propertyName)) {
     return;
   }
   Method setter = getSetter(propertyName, c.getClass());
   if (setter == null) {
     throw new IllegalArgumentException(
         Messages.getString("swing.51") + propertyName); // $NON-NLS-1$
   }
   try {
     setter.invoke(c, new Object[] {propertyValue});
   } catch (IllegalArgumentException e) {
     throw new ClassCastException();
   } catch (IllegalAccessException e) {
     throw new IllegalArgumentException(
         Messages.getString("swing.51") + propertyName); // $NON-NLS-1$
   } catch (InvocationTargetException e) {
     throw new IllegalArgumentException(
         Messages.getString("swing.51") + propertyName); // $NON-NLS-1$
   }
   c.installablePropertiesExcluded.remove(propertyName);
 }
  public Object stringToValue(final String string) throws ParseException {
    if (string == null) {
      return null;
    }
    Object result = null;
    if (getValueClass() == null) {
      result = format != null ? format.parseObject(string) : string;
    } else {
      result = super.stringToValue(string);
    }

    if (!checkRange(result)) {
      throw new ParseException(Messages.getString("swing.8F"), 0); // $NON-NLS-1$
    }
    return result;
  }
Esempio n. 8
0
  public final void setContentType(String type) {
    if (type == null) {
      throw new NullPointerException(
          Messages.getString("swing.03", "Content type")); // $NON-NLS-1$ //$NON-NLS-2$
    }
    int comma = type.indexOf(';');

    if (comma >= 0) {
      type = type.substring(0, comma);
    }
    type = type.trim().toLowerCase();

    if (!contentTypes.containsKey(type)) {
      type = PLAIN_CONTENT_TYPE;
    }

    if (changeEditorKit(type)) {
      EditorKit kit = getEditorKitForContentType(type);
      updateEditorKit((kit != null) ? kit : new PlainEditorKit());
      updateDocument(editorKit);
    }
  }
 public static void convertPointFromScreen(final Point point, final Component component) {
   if (component == null) {
     throw new NullPointerException(Messages.getString("swing.62")); // $NON-NLS-1$
   }
   translateRelatedPoint(point, component, -1, false);
 }