How to enable/disable SWT Text WRAP in runtime - java

I have a SWT button (with SWT.CHECK flag) and SWT Text.
Upon pressed, SWT button should enable/disable the wrapping of the SWT text.
I am aware that text wrapping capability is specified in the constructor as follow:
new Text(parent, SWT.WRAP)
But I couldn't find a method such as setWrap(false) to programmatically enable/disable it in runtime.
Is there a way to do this in SWT?
Or the only solution is to dispose the old text, and create a new one with different flag?

In general SWT styles can't be changed and this is the case for the Wrap style of the Text control.
The StyledText control does have a setWordWrap(boolean) method, you should be able to use that.

Related

SWT CCombo not responding correctly to accessibility events (Screen Reader)

I've created a CCombo object. I've added an AccessibilityControlListener and overridden the getRole(AccessibleControlEvent e) method. The code inside the method is
e.detail = ACC.ROLE_COMBOBOX;
But the screen reader(JAWS) still reads the CCombo as edit read only. But it should read combo box since i've overridden the default role. But it dosen't seem to work. Furthermore, the CCombo object doesn't even respond to the overridden accessiblitylistener or accessibilitycontrollistener methods.
(this is not exactly an answer, but the comment field ran out of space)
Other than most SWT widgets, CCombo isn't a native widget. Instead it is composed of other (native) widgets, namely a Text, a Button and a List. Apparently, not all accessibility events are overridden or redirected to the right widget.
The SWT Bugzilla lists several issues with CCombo and accessibility (search for 'ccombo accessibility'). Looking a the age and activity of the bugs it seems unlikely that they will be fixed anytime soon.
You might be better off using the (native) Combo widget if that's an option for you.
Depending on how desperate you need a fix, you could also write your own CCombo and fix the accessibility issues there. Of course only if all CCombos are created by your code.
Knowing the internal structure of the widget, you could also attach appropriate accessibility listeners to the respective children (Text, Button, List) if that's enough to fix your issues.

Finish input into JEditorPane on ENTER

I am using a JEditorPane as a component to show code. The JEditorPane resides in my custom PropertyEditorSupport for my Netbeans Platform app and is show in an OutlineView and the Properties window.
I've already limited the JEditorPane to be one line only, using a DocumentFilter. However I am not able to rebuild the funcionality a JTextField has, to finish input into the component by hitting the ENTER key.
I have already thought about adding a KeyListener event to my JEditorPane but am not sure what to do in case of the event. Is there a method to be called to "finish input of text"?
I am using a JEditorPane as a component to show code.
I've already limited the JEditorPane to be one line only
Those two statements seems to contradict one another. Usually codes consists of multiple lines, not one line.
In any case if you are simply display text then I would use a JTextPane as it supports text attributes. A JEditorPane is used to display HTML.
I have already thought about adding a KeyListener event
Don't use a KeyListener. Swing was designed to be used with Key Bindings. Basically you create an Action (in your case you would extend TextAction) and you bind the Action to a KeyStroke. Check out Key Bindings which contains more information as well as a link to the Swing tutorial on How to Use Key Bindings.

ColumnViewerTooltipSupport in SWT

What is the exact use of ColumnViewerTooltipSupport? I know that it provides tooltip support for ColumnViewers but does it mean that it provides tooltip for treeViewers? How can I use this feature to provide tooltip support individually different tooltips for my each tree item when the mouse hovers over each item? Do I require a MouseListener for this or does the ColumnViewerTooltipSupport class provide it by default? Can someone please help me out here as I'm relatively new to SWT concepts.
My tooltip has multiple lines, How can I wrap the text and display it neatly? It seems like ColumnViewerToolTipSupport class does not wrap the tooltip text if the text is too long. I would like to use a tooltip window with a vertical scroll bar just like the InformationControl Windows in eclipse? If something like eclipse is not possible then just a tooltip window with wrapped up text.
Please show me an example snippet?
ColumnViewerToolTipSupport adds support for individual tooltips to TableViewer and TreeViewer (and other ColumnViewers), you enable this using:
ColumnViewerToolTipSupport.enableFor(viewer);
The support expects that the label provider(s) for the viewer are based on CellLabelProvider (or one of its subclasses).
CellLabelProvider has getToolTipImage, getToolTipText, getToolTipBackgroundColor, getToolTipForegroundColor, getToolTipFont and getToolTipShift methods that you can override to control the tooltips.
Note: All this is JFace code not pure SWT

Is it possible to prevent dragging the shell in SWT for Mac OS when using Shell.getToolBar()?

It is possible to place any type of custom control into the shell's trim area in SWT using Shell.getToolBar() introduced in SWT 3.7. One needs to create a ToolItem with SWT.SEPARATOR style and assign it a custom control. My "custom control" is the entire tool bar area including some Composite based custom widgets.
See this bug comment for what I have done roughly:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=222859#c124
The problem is that the user may drag the shell by clicking into an "empty" area of the unified tool bar. And it appears my custom control is regarded as "empty space". One of my controls supports drag&drop. However, when it's placed in the unified tool bar area, dragging drags the shell, not the widget contents that are supposed to be draggable. Actually, both happens at the same time. So all I would need is to somehow stop the event from being processed any further. Attaching a Listener for SWT.MouseDown to my custom control and setting event.doit to false doesn't work.

SWT: How to recreate a default context menu for text fields

I need to add some items to the default context menu of a text control in SWT, but already found out I cannot modify this menu and have to create a new one from scratch.
But how do I emulate the default functions Undo, Cut, Copy, Paste, Delete? Do I really have to re-implement all this Clipboard stuff for myself? And I don't even know how to access the Undo history of the control. Is there some maybe dirty hack to emulate the key codes that achieve the functionality?
The StyledText has built-in support for Cut, Copy & Paste:
StyledText editor = new StyledText(...);
editor.invokeAction(ST.CUT);
editor.invokeAction(ST.COPY);
editor.invokeAction(ST.PASTE);
As for the Undo operation, I'm afraid you'll have to implement it yourself. SWT doesn't have anything useful here, AFAIK. Here's a good start if you want to do it yourself: SWT Undo Redo.
I already found out that I can use the functions cut(), copy() and paste() on a Text control. Sadly, undo() is not available.
I now emulate undo by sending CTRL-Z (CTRL-Y on your US-Keyboard) to the app.

Categories

Resources