Set StyledText in SWT ExpandItem Title/Text - swt

everyone. In an ExpandItem in SWT, Java you're able to set the title or header text of the ExpandItem by using the built-in method ExpandItem.setText(String text). This only supports String as input. I want to be able to use StyledText as title/header text of the ExpandItem. Is there a way to implement something like:
ExpandItem.setStyledText(StyledText text)
If not, what are my options? My main goal is to be able to change font style of the title/header text of ExpandItem. That's why I need StyledText.

Related

Change font face/size of the top GTKWindow?

I'm trying to use .NET Core GTK. For WinForms, we can select the form, and then click the Font property to change the font face or size within the Form designer. If we change the top form's font, it is applied to all the child controls on the form.
I wanted to do similar thing in Glade, but I cannot find a "Font" GUI in any of the attribute tabs.
Is this possible with GTK#?
If so, can it be done within Glade?
If the answer to 2 is no, can it be done in the code?
Yes this is possible in both GTK and Glade, although some code will be required to change all the forms font.
In GTK you will be using the GtkFontChooserWidget. This should let you choose between fonts.
In Glade, when you are using the attributes tab you are able to change font size with the Scale attribute. I haven't yet figured out how to change the actual font through those attributes yet. Thankfully there is a workaround. Instead of using Attributes, use Markup. Markup works just fine for both font size and font style.
Markup Example
<span font='36' face='Georgia'>Markup</span>
Assuming you are using a GtkComboBoxText to list possible fonts and button for selecting, you would just need a handler that would go through each of the labels and change the font to the designated one.
def when_visible(window):
"""
This is where per-window initialization takes place.
Values to be displayed are populated into their widgets.
"""
global FONT_FACE
name = Gtk.Buildable.get_name(window) # Window currently on
if 'font_select_screen' = name:
font = BUILDER.get_object('fontEntryCombo')
FONT_FACE = font.get_active_text()
elif 'random_screen' = name:
label1_text = "<span font='36' face='{}'>Label</span>".format(FONT_FACE)
label1 = BUILDER.get_object('label1')
label1.set_markup(label1_text)

Java StyledText control with IDocument support

My intention is to code a NASTRAN text editor (plain text editor, eclipse pure E4 RCP application).
NASTRAN is an engineering structural analysis application.
Simplifying, NASTRAN uses text cards of 8-characters-width per field and up to 10 fields per card (line).
See figure with the work done so far
The main feature of this Editor is to show plain text (fixed pitch font) with colored columns background, so it can be easy to distinguish different fields in each row.
I have used a StyledText control which provides methods to change background:
styledText.setBackgroundImage(backgroundImage);
How can I use IDocument interface with StyledText so It can provide me support for:
text manipulation
positions
partitions
line information
etc...
Other text controls (TextViewer, SourceViewer) provide setDocument(IDocument) method to load and manipulate text data
--org.eclipse.jface.text.TextViewer
|
--org.eclipse.jface.text.source.SourceViewer
But StyledText extends SWT Canvas and does not provide methods to set the imput documents
--org.eclipse.swt.custom.StyledText
Alternative approach could be how can I change background in a SourceViewer control so I can have columns of different colors.
Thanks in advance
TextViewer and SourceViewer are wrappers for StyledText and provide the code to deal with the IDocument interface so you should use one of those.
You can call the getTextWidget() method of the viewer to get access to the StyledText control they are using.
Thanks greg-449 for your answer, problem solved.
I had not a clear understanding of the concept of a class wrapping another class. So I tried first to create a StyledText object.
Now it is clear
I have attached below how I proceeded: creating a SourceViewer control and then, obtaining the StyledText wrapped.
So I could set the background image for the control
public class NastranEditor {
public StyledText st = null;
public SourceViewer sv = null;
private Image backgroundImage;//The image to appear at the backgroud
//....
#PostConstruct
public void postConstruct(Composite parent){
IVerticalRuler ruler = new VerticalRuler(20);
sv = new SourceViewer(parent, ruler, SWT.MULTI | SWT.V_SCROLL);
st = sv.getTextWidget();
st.setBackgroundImage(backgroundImage);
//....
}
//....
}

GWT Read-only TextArea will not resize

GWT newbie here. I have found that when I make a TextArea read-only useful features such as dynamic expansion and even word-wrapping stops working. My intention was to move a string from one text area, append it some way to some more strings, and then add this string into my read-only TextArea. I have doing something like this:
// Temporarily enable the field to set the value of the TextArea
logTextArea.setEnabled(true);
String remarks = // my string to add into the box
if (remarks.length() > 0) {
logTextArea.setEnabled.setValue(remarks);
}
// set read-only again
logTextArea.setEnabled.setEnabled(false);
I also have to work out how many lines I now span and explicitly set the height of the box (via setVisibleLines()). I have now found that it does not word-wrap, so I've had to add some more horrible bodge-code to further split up this string.
So I'm writing code to emulate functionality that comes for free on a normal writable TextArea. Has anyone else found this issue after setting a text-field read-only? Is there another widget I could possibly use to display a list of read-only strings that will auto resize and auto wrap for me?
Many thanks for your time,
tom
Text Area is fine for re-sizing and auto word wrap, even you have your text
area as read only.
Tested now by creating a test project for gwt and it is working fine.
Also Word Wrap is the default behavior of Text area if you want to turn it off then you need to explicitly do this "getElement().setAttribute("wrap","off");

How can I create a read-only SWT text that is impossible to select? (by keybord and mouse)

How can I create a read-only SWT text that is impossible to select? (by keyboard and mouse)
for example:
Text text = new Text(shell, SWT.BORDER | SWT.READ_ONLY);
text.append("text text text text text text text text text text text text text ");
text.setSelection(10, 60); // If only I could write here something that could turn the text impossible to select, just like if it were a label.
Use a Label instead. Or use Text's setEnabled and setEditable methods.
In case Enablad property using you can`t copy text from it.
I advise to make tihs. You can create yor own widjet that contain two text box. We may name it OurTextBox. The First created as usaly, second as readonly (with SWT.READONLY flag). You may use StackLayout for layout. Then you should define some properties and methods.
Main of this:
SetText(); getText();
SetReadonly();
When SetReadonly is invoked you can show one of two internal TextBox.
Unfortunately, this is the only solution to dynamically ReadOnly

How do you change the mouse over highlighting?

In GWT, I am using CellTable.
When you mouse over the CellTable it highlights each row.
How do change the behavior of the highlighting from the mouse over? Specifically:
change the color of highlighting
disable/enable
make it highlight only the specific grid item at your cursor (instead of the entire row)
( The current hack I have is to create a bunch of 1 column wide CellTables and add them to a VerticalPanel layout... creating the illusion that there is one CellTable and it highlights each grid according to your cursor. Is this bad? Why? performance? )
You will notice the CellTable uses a ResourceBundle, which means all the css styles get obfuscated ... this makes it more difficult to override styles.
The CellTable constructor will actually allow you to override the default ResourceBundle. So first, you need to create your own resource bundle like this:
public interface CellTableResources extends Resources {
public CellTableResources INSTANCE =
GWT.create(CellTableResources.class);
/**
* The styles used in this widget.
*/
#Source("CellTable.css")
CellTable.Style cellTableStyle();
}
Then you need to create your own CSS file. I recommend copying the CellTable style directly into your project and use that as a starting point. You can find it here:
http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/cellview/client/CellTable.css
Make sure the style is injected first, and then you just feed it into the CellTable's constructor like this:
CellTableResources.INSTANCE.cellTableStyle().ensureInjected();
myCellTable = new CellTable<T>(Integer.MAX_VALUE,CellTableResources.INSTANCE);
Specifically, you'll want to tweak these styles:
cellTableKeyboardSelectedRow
cellTableKeyboardSelectedRowCell
cellTableSelectedRow
cellTableSelectedRowCell
cellTableKeyboardSelectedCell
It is important to note that the cell table differentiates between the 'selected row' and the 'keyboard selected row'. The selected row is the actual row selected (ie via SelectionModel). The keyboard selected row refers to what is highlighted when the user is pressing the up / down key, but does not mean the row is actually selected (if that makes sense).
I'll just add for number 2) on your list, you can simply do
cellList.setSkipRowHoverStyleUpdate(true)
That completely disables highlighting. There are also two more setSkip-functions on CellList related to hovering.
CellTable can be styled via CSS: How do I style a gwt 2.1 CellTables headers?
To disable highlighting just set the hover CSS property to nothing.
Possibly - try tweaking the .cellTableSelectedRow and .cellTableSelectedRowCell.
Here is the original CellTable.css: http://www.google.com/codesearch/p?hl=en#A1edwVHBClQ/user/src/com/google/gwt/user/cellview/client/CellTable.css&q=cellTableLastColumn&d=8