Is there any way to include a Text Box inside a draw2d figure? (a code example would be nice)
Not easily, and if you're just using Draw2d without GEF, then I don't think it's possible.
With GEF, you can make use of a DirectEditManager in an Edit Part, and create an Edit Policy (extending DirectEditPolicy, installed with the key EditPolicy.DIRECT_EDIT_ROLE) to allow a direct edit to be performed on a figure.
You could create a figure which extends Label that is styled to look like a text box, and activate (by overriding performRequest in the Edit Part) editing upon selection.
This Schema Diagram example contains this type of functionality (and more importantly, the code!), although the figure used for edit (EditableLabel) isn't styled to look like a text box, and the activation itself is on double-click rather than selection.
It may point you in the right direction though.
Related
I'm currently implementing a simple text editor for personal purposes, something like quick notes. I will use it as my task planer. For this I need some specifical tags to be implemented. For example, lets say, I have 2 tasks for today and they look like this:
{Uni, 29.12.2015} do some homework {Uni, 29.12.2015} °
{Home, 29.12.2015} do some stuff here {Home, 29.12.2015} °
What I need now is, when clicking on the circle, the tags will dissapear and it will look like this:
do some homework °
do some stuff here °
By clicking on the circle again, the tags would appear again.
My question is, is it actually possible to implement this using java? I know how to show/hide text, but I don't know how to implement this "circle button functionality". I'm currently using swing library for main functionalities of my editor, but I'm not sure if I can make it work using this library. Is there some library that allows this? Unfortunately, google didn't bring me further. I would appreciate any help.
What I need now is, when clicking on the circle,
Swing text components support a viewToModel(...) method.
So you could add a MouseListener to the text area and get the character represented where the mouse was clicked. It the character is your special circle then you toggle the text.
I am currently writing on a Plugin that uses a view with a TreeViewer. The thing is, as content for my Nodes I get plain HTML. I would like to display the HTML styled or, if not possible, the simple plain text without any HTML. But the issue I run into is that the TreeViewer is not displaying enough text.
As you can see the HTML is not completly displayed and that everyting is only one line is not pretty aswell. I would like to have a box or something that can display the text (doesnt matter if the box does not support the HTML-styling, I can do this from hand).
Currently I'm using a LabelProvider that is returning the Text of a Node as string (and from what I can see this is the only possible Option with a LabelProvider).
As workaround I could only think of cutting the text into serval nodes but I would like to know if there are better options out there ;)
If it's your own LabelProvider, you can truncate or manipulate the text shown however you wish. Since it ultimately ends up as a native control, you're basically stuck with text label with a single image (plus whatever IColorLabelProvider offers) as long as you're using a tree control.
You could experiment with the Figures from the GEF project or the Nebula CompositeTable as alternatives.
you can use a editor to show the content, this would be appropriate with your requirement. View can also be think for it. tableviewer clould also be least choice. TreeViewer generaly use to deal with hierarchical data.
There are several label providers available in Eclipse in the org.eclipse.jface.viewers package. You can choose to implement your own or extend one of them to choose your need.
Looking at the image, I would recommend to display only few words in the tree and the entire content of the node could be in a different pane/tool tip.
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.
I am creating a SQL editor. I am using JTextPane for the editor. I want to implement AutoCompletion for table name etc. like Eclipse.
I think the appropriate class for displaying info on top of another component is JPopupMenu, which already handles layering correctly to display itself. JPopupMenu has a show() method that takes its 'parent' component as an argument, and it will show itself in that component's coordinate space. Since you want to display a selection of terms for the user to choose from, a menu seems appropriate.
To check for text changes, you'd add a DocumentListener to the document that's wrapped by the JTextPane; you can access it using getDocument().
To find out where the cursor (actually, the caret) is, you can use getCaretPosition(). That returns the caret's position within the text stream as an int. You can use modelToView() to translate that position to actual (x,y) coordinates. That in turn will tell you where to show your menu.
You can use addKeyListener() to catch keyboard events on your JTextPane, like hitting Ctrl-Space.
The combination of all that should allow you to do what you're looking to do.
You can also use http://fifesoft.com/autocomplete/. You can install it on any JTextComponent.
For things like this you probably should consider layered panes so your auto-complete suggestions appear in the correct place and z-order.
Furthermore you will have to look for changes in the JTextPane to know when the user is typing and you will need a parser that understands what is typed so you can offer the feature only at appropriate points.
It's not quite clear what exactly your problem is and what you got so far.
I achieved this by adding a key listener to the JTextPane and checking for CTRL + Space keystrokes. When the appropriate key combo was detected the listener went off and looked up the list of possible matches based on the characters directly to the left of the cursor at the time of the key press and found the best matches and displayed them to the user in a JPopup. If there was an exact match then it simply replaced the partial text with the match. If no matches were found an option was given to the user to add the text that they had already typed, edit it and record it into the list of acceptable data.
We use jide. They have a lot of components that help you do this kind of thing really easily
i want to write a text editor in java. i want it have a snippet feature similar to textmate. now i have no idea what to use as the main editor area. should i use some widget in swing?
great thanks.
Since a large part of the core added value of an editor such as textmate is the text editing view, if you were making a text editor you probably should implement the view from scratch ( JComponent and override drawing and event handling ).
If instead you want a feature rich text editing component for another project, then there's a Java binding http://sourceforge.net/projects/jintilla/ for the Scintilla editor, which is quite nice ( SciTE or Notepad++ use Scintilla ).
I think you are going to want to use JTextArea, and probably wrap it in a JScrollPane. You may want to look at JEdit, it is a text editor written in java, you can view the source and get some ideas from how they are doing things. The tricky part is going to be handling the formatting of snippet you are trying to create. JEdit has plugins for different languages, so I would definitely check that out for some ideas on how they handle things.
If I understand what you're wanting to do, you could use a JTextArea to accomplish this. I have a multithreaded text editor application I made that uses a JTextArea as the main editing area. It's nothing fancy but it was fun to make.