[Solved] RSyntxTextArea loading dark.xml theme not working

Questions on using RSyntaxTextArea should go here.

Moderator: robert

[Solved] RSyntxTextArea loading dark.xml theme not working

Postby OreoProphet » Wed Jun 18, 2014 7:39 am

Hello,

When I try to implement the standard dark.xml theme into my RSYntaxTextArea I get this error:
Code: Select all
java.io.IOException: Stream closed
   at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:151)
   at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
   at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
   at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2871)
   at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:699)
   at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
   at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
   at org.fife.ui.rsyntaxtextarea.Theme$XmlHandler.load(Theme.java:437)
   at org.fife.ui.rsyntaxtextarea.Theme.load(Theme.java:216)
   at net.AlexAdams.SimplyHTML.editor.Editor.<init>(Editor.java:129)
   at net.AlexAdams.SimplyHTML.editor.Editor$3.run(Editor.java:503)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
   at java.awt.EventQueue.access$200(EventQueue.java:103)
   at java.awt.EventQueue$3.run(EventQueue.java:694)
   at java.awt.EventQueue$3.run(EventQueue.java:692)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
java.io.IOException: java.io.IOException: Stream closed
   at org.fife.ui.rsyntaxtextarea.Theme$XmlHandler.load(Theme.java:440)
   at org.fife.ui.rsyntaxtextarea.Theme.load(Theme.java:216)
   at net.AlexAdams.SimplyHTML.editor.Editor.<init>(Editor.java:129)
   at net.AlexAdams.SimplyHTML.editor.Editor$3.run(Editor.java:503)
   at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
   at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
   at java.awt.EventQueue.access$200(EventQueue.java:103)
   at java.awt.EventQueue$3.run(EventQueue.java:694)
   at java.awt.EventQueue$3.run(EventQueue.java:692)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
   at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
   at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
   at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
   at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

I'm implementing it like the it tells me to:

java code:

try {
Theme theme = Theme.load(getClass().getResourceAsStream("/dark.xml"));
theme.apply(codeArea);
} catch (IOException e1) {
e1.printStackTrace();
}

Please help
Last edited by OreoProphet on Fri Jun 27, 2014 8:01 am, edited 1 time in total.
OreoProphet
 
Posts: 5
Joined: Wed Jun 18, 2014 7:30 am

Re: RSyntxTextArea loading dark.xml theme not working

Postby robert » Thu Jun 19, 2014 3:09 am

The error message isn't clear here, but this is most likely because:

Code: Select all
Theme.load(getClass().getResourceAsStream("/dark.xml"))


is returning null.
User avatar
robert
 
Posts: 802
Joined: Sat May 10, 2008 5:16 pm

Re: RSyntxTextArea loading dark.xml theme not working

Postby OreoProphet » Thu Jun 19, 2014 5:45 am

Yeah I saw that on another post but I don't know how to correct that.
OreoProphet
 
Posts: 5
Joined: Wed Jun 18, 2014 7:30 am

Re: RSyntxTextArea loading dark.xml theme not working

Postby Blogghete » Thu Jun 19, 2014 7:59 am

OreoProphet wrote:Yeah I saw that on another post but I don't know how to correct that.


Hi OreoProphet,
you can try this..

Source code of the class ApplicationMenuBar.java:
Code: Select all
import java.awt.event.KeyEvent;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.UIManager;

...
...
...

/**
 *
 *
 * @author Blogghete
 *
 */
public class ApplicationMenuBar extends JMenuBar {

    ...
    ...
    ...

    public ApplicationMenuBar() {
        JMenu menu;
        JMenu subMenu;
       
        ...
        ...
        ...
       
        menu = new JMenu(ApplicationFrame.LAF_MENU_LABEL); // The Look And Feel menu
        add(menu);
        ButtonGroup buttonGroupEditorTheme = new ButtonGroup();
        subMenu = new JMenu("Editor Theme");

        addThemeItem("Dark", "/res/themes/dark.xml", buttonGroupEditorTheme,
                subMenu);

        ...
        ...
        ...
    }

    ...
    ...
    ...

    private void setMnemonics(MenuElement menuElement) {
        Set<Character> used = new HashSet<Character>();
        MenuElement[] subElements = menuElement.getSubElements();
        for (MenuElement subElement : subElements) {
            AbstractButton item = (AbstractButton) subElement;
            char[] chars = item.getText().toCharArray();
            for (char aChar : chars) {
                if (used.add(aChar)) {
                    item.setMnemonic(aChar);
                    break;
                }
            }
            if (item instanceof JMenu) {
                setMnemonics(((JMenu) item).getPopupMenu());
            }
        }
    }
   
    ...
    ...
    ...

    private void addThemeItem(String name, String themeXml, ButtonGroup bg,
            JMenu menu, boolean isSelected) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(new ThemeAction(
                name, themeXml));
        bg.add(item);
        item.setSelected(isSelected);
        menu.add(item);
    }

    private void addThemeItem(String name, String themeXml, ButtonGroup bg,
            JMenu menu) {
        addThemeItem(name, themeXml, bg, menu, false);
    }

    ...
    ...
    ...

}


Source code of the class ThemeAction.java:
Code: Select all
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.InputStream;

...
...
...

/**
 *
 *
 * @author Blogghete
 *
 */
public class ThemeAction extends CustomAction {

    private static final long serialVersionUID = <BIGINT>L;

    private String xml;

    public ThemeAction(String name, String xml) {
        super(name);
        this.xml = xml;
        setEnabled(true);
    }

    @Override
    public void actionPerformed(final ActionEvent e) {
        performThreaded(e);
    }
   
    @Override
    protected void performThreaded(ActionEvent e) throws Exception {
        RSyntaxTextArea textArea = ApplicationFrame.getInstance()
                .getTextComponent();
        InputStream in = getClass().getResourceAsStream(xml);
        try {
            Theme theme = Theme.load(in);
            theme.apply(textArea);
            ApplicationFrame.getInstance().getApplicationMenuBar()
                    .refreshEditOptions();
        } catch (IOException ioe) {
            ExceptionDialog.notifyException(ioe);
        }
    }
}


Best regards,
Blogghete.
Blogghete
 
Posts: 10
Joined: Wed May 29, 2013 3:25 pm

Re: RSyntxTextArea loading dark.xml theme not working

Postby OreoProphet » Mon Jun 23, 2014 6:08 am

Blogghete wrote:
OreoProphet wrote:Yeah I saw that on another post but I don't know how to correct that.


Hi OreoProphet,
you can try this..

Source code of the class ApplicationMenuBar.java:
Code: Select all
import java.awt.event.KeyEvent;
import java.util.HashSet;
import java.util.Set;
import java.util.Vector;

import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.KeyStroke;
import javax.swing.MenuElement;
import javax.swing.UIManager;

...
...
...

/**
 *
 *
 * @author Blogghete
 *
 */
public class ApplicationMenuBar extends JMenuBar {

    ...
    ...
    ...

    public ApplicationMenuBar() {
        JMenu menu;
        JMenu subMenu;
       
        ...
        ...
        ...
       
        menu = new JMenu(ApplicationFrame.LAF_MENU_LABEL); // The Look And Feel menu
        add(menu);
        ButtonGroup buttonGroupEditorTheme = new ButtonGroup();
        subMenu = new JMenu("Editor Theme");

        addThemeItem("Dark", "/res/themes/dark.xml", buttonGroupEditorTheme,
                subMenu);

        ...
        ...
        ...
    }

    ...
    ...
    ...

    private void setMnemonics(MenuElement menuElement) {
        Set<Character> used = new HashSet<Character>();
        MenuElement[] subElements = menuElement.getSubElements();
        for (MenuElement subElement : subElements) {
            AbstractButton item = (AbstractButton) subElement;
            char[] chars = item.getText().toCharArray();
            for (char aChar : chars) {
                if (used.add(aChar)) {
                    item.setMnemonic(aChar);
                    break;
                }
            }
            if (item instanceof JMenu) {
                setMnemonics(((JMenu) item).getPopupMenu());
            }
        }
    }
   
    ...
    ...
    ...

    private void addThemeItem(String name, String themeXml, ButtonGroup bg,
            JMenu menu, boolean isSelected) {
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(new ThemeAction(
                name, themeXml));
        bg.add(item);
        item.setSelected(isSelected);
        menu.add(item);
    }

    private void addThemeItem(String name, String themeXml, ButtonGroup bg,
            JMenu menu) {
        addThemeItem(name, themeXml, bg, menu, false);
    }

    ...
    ...
    ...

}


Source code of the class ThemeAction.java:
Code: Select all
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.io.InputStream;

...
...
...

/**
 *
 *
 * @author Blogghete
 *
 */
public class ThemeAction extends CustomAction {

    private static final long serialVersionUID = <BIGINT>L;

    private String xml;

    public ThemeAction(String name, String xml) {
        super(name);
        this.xml = xml;
        setEnabled(true);
    }

    @Override
    public void actionPerformed(final ActionEvent e) {
        performThreaded(e);
    }
   
    @Override
    protected void performThreaded(ActionEvent e) throws Exception {
        RSyntaxTextArea textArea = ApplicationFrame.getInstance()
                .getTextComponent();
        InputStream in = getClass().getResourceAsStream(xml);
        try {
            Theme theme = Theme.load(in);
            theme.apply(textArea);
            ApplicationFrame.getInstance().getApplicationMenuBar()
                    .refreshEditOptions();
        } catch (IOException ioe) {
            ExceptionDialog.notifyException(ioe);
        }
    }
}


Best regards,
Blogghete.


Sorry for the late reply. I've tried both those methods and they didn't work I get this in Eclipse: "ExceptionDialog cannot be resolved" and "ApplicationFrame cannot be resolved". I'm using Java 1.7
I've tried using this method again:
Code: Select all
/** Auto Theme (dark.xml) **/
      try {
         Theme theme = Theme.load(getClass().getResourceAsStream("/themes/dark.xml"));
          theme.apply(textArea);
       } catch (IOException ioe) {
          ioe.printStackTrace();
       }

I get this new error about Stream close
Code: Select all
java.io.IOException: Stream closed
   at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:151)
   at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
   at java.io.BufferedInputStream.read(BufferedInputStream.java:254)
   at com.sun.org.apache.xerces.internal.impl.XMLEntityManager$RewindableInputStream.read(XMLEntityManager.java:2871)
   at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:699)
   at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:189)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:812)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
   at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
   at org.fife.ui.rsyntaxtextarea.Theme$XmlHandler.load(Theme.java:468)
   at org.fife.ui.rsyntaxtextarea.Theme.load(Theme.java:237)
   at AlexAdams.SimplyHTML.MainFrame.init(MainFrame.java:78)
   at sun.applet.AppletPanel.run(AppletPanel.java:435)
   at java.lang.Thread.run(Thread.java:744)
java.io.IOException: java.io.IOException: Stream closed
   at org.fife.ui.rsyntaxtextarea.Theme$XmlHandler.load(Theme.java:471)
   at org.fife.ui.rsyntaxtextarea.Theme.load(Theme.java:237)
   at AlexAdams.SimplyHTML.MainFrame.init(MainFrame.java:78)
   at sun.applet.AppletPanel.run(AppletPanel.java:435)
   at java.lang.Thread.run(Thread.java:744)
OreoProphet
 
Posts: 5
Joined: Wed Jun 18, 2014 7:30 am

Re: RSyntxTextArea loading dark.xml theme not working

Postby robert » Tue Jun 24, 2014 2:21 am

It simply means that the resource wasn't found. Things to verify:

  • You have a file named "dark.xml" in your project, in a folder named "themes". Note that the theme XML files are not included in the main rsyntaxtextarea.jar file; you must copy them out of the source zip or repository and include them in your project yourself.
  • When referencing the resource as you are doing it (getClass().getResourceAsStream("/themes/dark.xml")), make sure that "themes/dark.xml" is at the root of your classpath; that is, in a folder at the same root level as your class files, or in a jar at the root level.

Good luck!
User avatar
robert
 
Posts: 802
Joined: Sat May 10, 2008 5:16 pm

Re: RSyntxTextArea loading dark.xml theme not working

Postby OreoProphet » Tue Jun 24, 2014 7:31 am

robert wrote:It simply means that the resource wasn't found. Things to verify:

  • You have a file named "dark.xml" in your project, in a folder named "themes". Note that the theme XML files are not included in the main rsyntaxtextarea.jar file; you must copy them out of the source zip or repository and include them in your project yourself.
  • When referencing the resource as you are doing it (getClass().getResourceAsStream("/themes/dark.xml")), make sure that "themes/dark.xml" is at the root of your classpath; that is, in a folder at the same root level as your class files, or in a jar at the root level.

Good luck!


Thank you Robert. I used this to find where my program is looking for the theme:

java code:

System.out.println(new File(".").getAbsolutePath());

It seams like it now knows where the file is although I get this error now:
Code: Select all
org.xml.sax.SAXParseException; lineNumber: 16; columnNumber: 63; Attribute "useFG" must be declared for element type "selection".
   at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
   at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
   at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
   at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
   at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
   at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(XMLDTDValidator.java:1253)
   at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(XMLDTDValidator.java:1917)
   at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:763)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1350)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2778)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
   at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
   at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
   at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
   at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
   at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
   at org.fife.ui.rsyntaxtextarea.Theme$XmlHandler.load(Theme.java:468)
   at org.fife.ui.rsyntaxtextarea.Theme.load(Theme.java:237)
   at AlexAdams.SimplyHTML.MainFrame.loadDefaultTheme(MainFrame.java:141)
   at AlexAdams.SimplyHTML.MainFrame.init(MainFrame.java:77)
   at sun.applet.AppletPanel.run(AppletPanel.java:435)
   at java.lang.Thread.run(Thread.java:744)


Thank you for helping me out :D
OreoProphet
 
Posts: 5
Joined: Wed Jun 18, 2014 7:30 am

Re: RSyntxTextArea loading dark.xml theme not working

Postby robert » Thu Jun 26, 2014 2:55 am

It looks like you're using a theme XML file that is valid in 2.5.3+ (not yet released) but not in 2.5.2 (or earlier), and you're using a 2.5.2 (or earlier) RSyntaxTextArea jar/source.

The "useFG" attribute was added to the DTD in late March, to support the typical text component selection rendering behavior of differently-colored-text-in-a-selection. Previously, RSTA did not do this (the selection color was rendered "beneath" the syntax highlighted token text), but after this change, it supported both behaviors. To support this behavior, new attributes were added to the theme XML that won't validate in the DTD used by previous releases.

Your options are:

1. Simply remove the "useFG='...'" attribute from the XML (and any other errors you find).
2. Check out the latest source from Git, build and use that, and keep the theme XML as-is.

This will of course also be resolved when 2.5.3 is released (hopefully soon!).
User avatar
robert
 
Posts: 802
Joined: Sat May 10, 2008 5:16 pm

Re: RSyntxTextArea loading dark.xml theme not working

Postby OreoProphet » Fri Jun 27, 2014 8:01 am

robert wrote:It looks like you're using a theme XML file that is valid in 2.5.3+ (not yet released) but not in 2.5.2 (or earlier), and you're using a 2.5.2 (or earlier) RSyntaxTextArea jar/source.

The "useFG" attribute was added to the DTD in late March, to support the typical text component selection rendering behavior of differently-colored-text-in-a-selection. Previously, RSTA did not do this (the selection color was rendered "beneath" the syntax highlighted token text), but after this change, it supported both behaviors. To support this behavior, new attributes were added to the theme XML that won't validate in the DTD used by previous releases.

Your options are:

1. Simply remove the "useFG='...'" attribute from the XML (and any other errors you find).
2. Check out the latest source from Git, build and use that, and keep the theme XML as-is.

This will of course also be resolved when 2.5.3 is released (hopefully soon!).


Thank you Robert I removed the "useFG='..." but I still got an error so I tried back tracking to version 2.5.0 and that got rid of the error and the themes are working fine now. Thanks for all the Help! :D :D :D ps: I was running 2.5.2 before
OreoProphet
 
Posts: 5
Joined: Wed Jun 18, 2014 7:30 am


Return to Help

Who is online

Users browsing this forum: No registered users and 4 guests

cron