I want to build an notepad-style application on android that will have syntax highlighting. But when I search around the web, I find the syntax highlighting can be done only through use of an awt class. How could I syntax highlight in maybe a custom EditText or TextView view? I know that the release of a syntax highlighter is sort of anticipated, so I want to add my syntax highlighter on the market.
Take a look at the android.text namespace. Specifically, you'll want either an Editable or a Spannable as your text format instead of strings. The android.text.style namespace has the various kinds of markup you can apply to spans of text.
If someone know Russian, you can read my article about this topic here. Anyway there picture and code snippets that can give you a direction. If you want to check out result, it can be found here
Related
I prefer Eclipse, but I'd love to know if there is any IDE anywhere that can detect, and offers syntax highlighting for, the negation operator (!). It's a critical thing, but it's often lost between long method names and an open parenthesis.
Well, from the Preferences->Java->Editor->Syntax Coloring dialog, you can change the font and colors for operators which include ! to be whatever color, bold, italic, strikethrough, underline you want. I'm not sure if you can just do ! though.
Thanks to #Techrocket9's comments in #dkatzel's answer, I eventually found my way to wiki articles on how to create an editor and providing coloring for custom syntax rules. These two articles have enough related information that I can begin trying my hand at creating a plugin. If anyone has experience in this, feel free to add to this community wiki answer. Otherwise, I'll update this when I have something.
I have a TextBox in a GWT app I'm building that's used for advanced searched. I'm trying to find a way to use syntax highlighting for certain characters sequences (e.g. the string #title, or just #T) in the search string, but I can't find anything about how to allow for coloring of individual symbols. I suppose I need something more complex than just a TextBox but I'm not sure what to use. Would it perhaps be possible to do with a single-line, stripped down RichTextBox, or is there a better way?
You cannot do it with an input. Use a FlowPanel (or simply a div element), and set ContentEditable on it. Most browsers support it now. Then you can insert regular HTML tags (bold, span) inside the text on KeyUpEvent, and you can style the spans anyway you like.
I'm looking for a way to provide 'text folding' capabilities to a swing JTextArea or JTextPane
More specifically, I want to add a block of data in a text component and I want the component to display only some header line. Then the user can unfold the block by clicking some icon. This is just like the code folding feature in most IDE.
I've found ->some sample code<- after some thorough search, but the mechanisms used here are quite obscure to me and it stops working when I try to remove text from the document.
Maybe using XML as input could be a lead ?
This one how to add collapsible area
http://java-sl.com/collapse_area.html
This one how to represent XML
http://java-sl.com/xml_editor_kit.html
I would start by looking at the NetBeans API: http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-fold/overview-summary.html
If you were to do it yourself, you'd need to provide a Document implementation that makes the JTextComponent think that pieces are being added or removed, then attach click events that tell the document to update itself. A lot of work.
Visually, it may also be better to use JEditorPane, but that's probably more work.
Recently, I program for the Android platform. I have a question about the text.
Is there any way to display the text without using the XML?
I also want the text to be able to show in each class.
If you're asking if you can replace the text of anything programatically, yes you can. Usually, you have a setText method you can use for that. I'd advise you to read the tutorial and the javadoc to know more about this.
I have a simple question really: SWT documentation says that if you're using styledText, you either implements its API or you implement LineStyleListener.
So, If I do use LineStyleListener, how can I still control the representation of specific characters in the editor widget? It seems that implementing LineStyleListener only provides coloring of the whole line at a time.
Thanks
With the LineStyleListener you can still add styles for single characters by modifying the provided StyleRange array. It is called LineStyleListener only because you get the text by lines.
For explanations how to use this, see here or here.