Java UI markup alternative to HTML? - java

I'm trying to use Java to develop a piece of software, but I've run into the issue of UI elements parsing HTML beyond the way I want them to.
The Java JEditorPane seems to be only able to be marked up by HTML or something that is essentially HTML underneath. I want the user to be able to type and see HTML tags, not have them formatted into markup, but still have something like the tags colored red and standard text not.
Is there a method of marking up Java's UIs without HTML? (I don't mind using an extra library, but if it can be avoided that'd be great.)

I haven't used it, but RSyntaxTextArea seems to achieve what you want. The intro says
RSyntaxTextArea is a syntax highlighting text component for Java
Swing.
and
Syntax highlighting for over 30 programming languages
Example usage and source code at github.

Related

How to use Markdown with links in JSF?

I am developing an JSF web application and would like to introduce a lot of documentation to be visible directly in the web application. Technically I would like to use Markdown language and made already first experimence with.
I am currently playing around with flexmark Java library to render e. g. HTML strings from a markdown document. Also this seems to work fine. But what to do with links to other md files?
If I do have my markdown part: See also [here](Background.md)
Then this will be rendered correct to HTML with a link like: See also here.
But how should I tell my web server to react on this link and update the document part of the page with the rendered md file?
I would need to manually find such links in the generated HTML and change them to a kind of JavaScript call, telling my server to render the panel using the other md file.
Or should I create an IFrame so that within this frame, I could follow the link to e. g. a web servlet, rendering the md files to new HTML?
But this all feels a bit clumbsy to me. Am I missing a more easy solution?
Ok, no other answers, so I answer on my own.
The comment about primefaces extension with localized is interesting, but too far away from my focus and some features did not really match to my requirements.
Therefore I stayed with a pure markdown library and made the rest on my own.
With the links it was much more easy than expected! Within JavaScript you can very easily detect all links of the page (document.links), iterate over them and just set an onclick function (see here).

SQL Syntax highligther in Java

I am looking some good Sql Syntax highlighter which will easily integrated with Component based(JSF,ZK ) framework. Any idea which will be best for me i tried Codeirror but binding is not working. Any one suggest some other which will easily integrated. I do not want to open output in JFrame or Applet its should be in Browser
Using prettify is a good solution, but this is a JavaScript library working client-side in the browser.
If you want to send your source code (java, sql, python, bash, html, xml, css, javascript...) prepared server-side as HTML code with span tags to color the text (i.e. syntax highligthing) in pure Java, you can use java-prettify. This is a port of the Javascript lib in java.
I have explained how you can use the parser to produce highligthed HTML code here: use the parser to create HTML. Have a look at the code in the java class PrettifyToHtml and at the example.

Is there any way I can use HTML and CSS for my UI in a Java app?

I'm making a game in java. Is there any way I can create HTML widgets for use in the game as the UI? It'd be great if I could attach some event handlers to the controls and fully use CSS, too.
You can use HTML and CSS for your game, but you'll need a servlet to handle requests.
Event handlers may be written in JavaScript, but they'll ultimately have to communicate with a server on the back end.
I know that this doesn't really anwer your question, but there is a library called Amino, that allowes you to use CSS to skin GUI components. That might grant you at least part of your wish.
"If there is a will there is a way"
If you're using raw Java instead of a framework that might give you some ready-made widgets, I believe you'll have to handle the HTML rendering yourself.
In Swing, one would look up class javax.swing.text.html.HTMLEditorKit for understanding how Java's JEditorPane renders basic HTML + CSS (the inner class HTMLFactory is particularly interesting as it creates the views that will render each HTML element). Perhaps this won't help you much, but maybe this would be a starting point.
Stanislav Lapitsky has done of a lot of work in Swing-HTML and gives tools that help you understand how to deal with HTML rendering. Check it out:
http://java-sl.com/about_author.html

Lua Syntax Highlighting in Java

I'm using Java Swing to develop an application and I want to use Lua as an embedded scripting language. For that I need to create a text component that would provide syntax highlighting and automatically organize the code by adding tabs and so on.
Is there a library or resource that I could use in order to achieve this?
Here is an example of what I want to do: http://openendedgroup.com/field/attachment/wiki/OverviewBanners2/p2.png
Thanks,
Code formatting (indentation) and Syntax Highlighting are two different pairs of shoes! For formatting you also need a relative complete parser, while for syntax highlighting you can simply tokenize your input and colorize it.
I believe there are extensible highlighters out there, but you will need something like the ANTLR parser if you need to format your code.

What is the best way to screen scrape poorly formed XHTML pages for a java app

I want to be able to grab content from web pages, especially the tags and the content within them. I have tried XQuery and XPath but they don't seem to work for malformed XHTML and REGEX is just a pain.
Is there a better solution. Ideally I would like to be able to ask for all the links and get back an array of URLs, or ask for the text of the links and get back an array of Strings with the text of the links, or ask for all the bold text etc.
Run the XHTML through something like JTidy, which should give you back valid XML.
You may want to look at Watij. I have only used its Ruby cousin, Watir, but with it I was able to load a webpage and request all URLs of the page in exactly the manner you describe.
It was very easy to work with - it literally fires up a webbrowser and gives you back information in nice forms. IE support seemed best, but at least with Watir Firefox was also supported.
I had some problems with JTidy back in the day. I think it was related to tags that weren't closed that made JTidy fail. I don't know if thats fixed now. I ended up using something that was a wrapper around TagSoup, although I don't remember the exact project's name. Theres also HTMLCleaner.
I've used http://htmlparser.sourceforge.net/. It can parse poorly formed html and allows data extraction quite easily.

Categories