/** * Loads a theme. * * @param in The input stream to read from. This will be closed when this * method returns. * @param baseFont The default font to use for any "base font" properties * not specified in the theme XML. If this is <code>null</code>, * a default monospaced font will be used. * @return The theme. * @throws IOException If an IO error occurs. * @see #save(OutputStream) */ public static Theme load(InputStream in, Font baseFont) throws IOException { Theme theme = new Theme(baseFont); try (BufferedInputStream bin = new BufferedInputStream(in)) { XmlHandler.load(theme, bin); } return theme; }
/** * Copies the currently selected text to the system clipboard, with style * information from the specified theme. Does nothing for {@code null} or * empty selections. * * @param theme The theme to use for the color and font information. * This may be {@code null}, in which case this text area's * current styles are used. * @see #copyAsStyledText() */ public void copyAsStyledText(Theme theme) { // It's more performant to call the no-arg overload if (theme == null) { copyAsStyledText(); return; } Theme origTheme = new Theme(this); theme.apply(this); try { copyAsStyledText(); } finally { origTheme.apply(this); } }
@Test public void testSave() throws Exception { RSyntaxTextArea textArea1 = new RSyntaxTextArea( SyntaxConstants.SYNTAX_STYLE_PHP); RTextScrollPane sp1 = new RTextScrollPane(textArea1); Gutter gutter1 = sp1.getGutter(); initWithOddProperties(textArea1, gutter1); RSyntaxTextArea textArea2 = new RSyntaxTextArea( SyntaxConstants.SYNTAX_STYLE_PHP); RTextScrollPane sp2 = new RTextScrollPane(textArea2); Gutter gutter2 = sp2.getGutter(); assertAllThemePropertiesDifferent(textArea1, gutter1, textArea2, gutter2); Theme theme = new Theme(textArea1); ByteArrayOutputStream baos = new ByteArrayOutputStream(); theme.save(baos); String actual = new String(baos.toByteArray(), "UTF-8"); baos.close(); ByteArrayInputStream bin = new ByteArrayInputStream(actual.getBytes("UTF-8")); Theme theme2 = Theme.load(bin); bin.close(); theme2.apply(textArea2); assertEqualThemeProperties(textArea1, gutter1, textArea2, gutter2); }
/** * Loads a theme. * * @param in The input stream to read from. This will be closed when this * method returns. * @param baseFont The default font to use for any "base font" properties * not specified in the theme XML. If this is <code>null</code>, * a default monospaced font will be used. * @return The theme. * @throws IOException If an IO error occurs. * @see #save(OutputStream) */ public static Theme load(InputStream in, Font baseFont) throws IOException { Theme theme = new Theme(baseFont); try (BufferedInputStream bin = new BufferedInputStream(in)) { XmlHandler.load(theme, bin); } return theme; }
@Test public void testApply() { RSyntaxTextArea textArea1 = new RSyntaxTextArea( SyntaxConstants.SYNTAX_STYLE_PHP); RTextScrollPane sp1 = new RTextScrollPane(textArea1); Gutter gutter1 = sp1.getGutter(); initWithOddProperties(textArea1, gutter1); RSyntaxTextArea textArea2 = new RSyntaxTextArea( SyntaxConstants.SYNTAX_STYLE_PHP); RTextScrollPane sp2 = new RTextScrollPane(textArea2); Gutter gutter2 = sp2.getGutter(); assertAllThemePropertiesDifferent(textArea1, gutter1, textArea2, gutter2); Theme theme = new Theme(textArea1); theme.apply(textArea2); assertEqualThemeProperties(textArea1, gutter1, textArea2, gutter2); }
/** * Copies the currently selected text to the system clipboard, with style * information from the specified theme. Does nothing for {@code null} or * empty selections. * * @param theme The theme to use for the color and font information. * This may be {@code null}, in which case this text area's * current styles are used. * @see #copyAsStyledText() */ public void copyAsStyledText(Theme theme) { // It's more performant to call the no-arg overload if (theme == null) { copyAsStyledText(); return; } Theme origTheme = new Theme(this); theme.apply(this); try { copyAsStyledText(); } finally { origTheme.apply(this); } }