java gwt draw horizontal line - java

How can I draw a horizontal line in java gwt, something similar to the '< hr >' tag in HTML? I tried it by using
com.google.gwt.user.client.Element bottomLine = DOM.createDiv();
but that somehow doesn't work in IE...

You can use the HTML widget to add whatever html you want inside your page
HTML html = new HTML("<hr style=\"width:100%;\" />")
rootPanel.add(html); // or add it inside another widget
Or you can use css on Panel and define the border-bottom property (if you have a panel that spans the entire page).

Document.get().createHRElement()?

Related

Display HTML text in SWT Label

I would like to display the HTML text in a Java SWT Label.
Below is my code for creating a label.
Label theLabel = new Label(controls,SWT.WRAP);
theLabel.setSize(100,500);
theLable.setText("<html><ol><li>Hello</li><li>welcome</li></ol></html>");
When I run the application as Eclipse Application I get the output as:
<html><ol><li>Hello</li><li>welcome</li></ol></html>
What is the mistake? Why I am not getting the html formatted output in my label? I am using Eclipse plugin with a view.
To show HTML with SWT you will have to use the Browser widget instead.
Browser browser = new Browser( parent, SWT.NONE );
browser.setText( "<html><ol><li>Hello</li><li>welcome</li></ol></html>" );
If you don't mind the extra dependency on org.eclipse.ui.forms you can also use FormText. But be aware that the control does only understand a subset of HTML (<p>, <b>, <li>, <img>, <br>, <span>) to render simple formatted text.

Wicket implementation of bootstrap-wysiwyg

Im trying to figure out how to create a wicket component wicket could represent a div that is then used by the Bootstrap-wyiswyg javascript. Once the page is submitted i want to be able to get the content of the div and have that represented on the server, in a IModel<String>.
The part im struggling with is getting the content from the div to the server-side. For instance if i used a textarea i would just have my component extends TextArea and that would do all of this for me. So really what im asking is whether there is a wicket component that i can add as a <div wicket:id="mycomponent"></div> but onsubmit populate the component's Model with the content of the div from the client-side. Or do I have to write all this code myself?
You can try adding a normal "wicket" textarea to your form (with display: none) and add a jQuery handler for the form's submit event that will do something like:
$('your-text-area-selector').html($('your-wysiwyg-div-selector').html());

How to add "..." ellipsis to lengthy text in a WebView?

I am using a WebView to align RTL text correctly.
Simply, I want to add "..." ellipsis when the text is lengthy.
Which is archived in a TextView using android:ellipsize="end"
Is there a way to achieve "..." ellipsis or to control the number of lines in a WebView?
Here is the code:
String header = "<html><head><meta http-equiv=\"Content-Type\" +" + "content=\"text/html; charset=UTF-8\" /></head>";
String dt = "<body dir=\"rtl\">" + o.get(p).getTitle() +"</body></html>";
webView.loadData(URLEncoder.encode(header + dt,"utf-8").replaceAll("\\+"," "), "text/html", "UTF-8");
You could parse the html and find out which is the last visible html element on the page. You could then use the following by appending the #ellipsis id to that element.
CSS Text Wrapping:
http://jsfiddle.net/6HcWM/
The problem will be finding the last visible html element as the screen size can vary, also the zoom level could presumably vary. I'm guessing that you'll need to append JavaScript to the html to discover this...
Maybe this would work:
How to tell if a DOM element is visible in the current viewport?
You have two simple options:
Use CSS and the text-overflow property on your HTML element: directions here.
If you need a bit better control where the ellipsis appears and have the means — include jQuery and a jQuery ellipsis plugin in your HTML via script tags: directions here.

How to add a webpage in a TabPanel in gwt?

I am not understanding how to add a webpage inside the tabbed panel so that when I select a tab the webpage should display in there. I am trying to use UiBinder in GWT.
I have 3 pages Page1.java, Page2.java and Page2.ui.xml.
Page1.java contains a TabPanel with 3 tab indexes, so on the index(0) of the tabPanel I want Page2.java to be displayed.
Any help appreciated. Thanks!
You just add widgets to the TabPanel in order of the tabs. So if you want to have the widget from Page2.java (which I am assuming is a Composite widget) to be displayed in the TabPanel with, say, a tab text of "Page 2" you would do the following (in Page1.java):
TabPanel panel = new TabPanel();
panel.add(new Page2(), "Page 2");
For more details and examples I recommend you read the documentation on the TabPanel.
It's also worth mentioning from the documentation:
This widget will only work in quirks mode. If your application is in Standards Mode, use TabLayoutPanel instead.
So if your host page declaration looks like this: <!DOCTYPE html> which means you are in Standards Mode, you should be using the TabLayoutPanel widget.
With the Ui Binder, you could do it like this:
<g:TabPanel>
<g:Tab text="Page 2">
<app:Page2 />
</g:Tab>
<g:Tab text="Page 3">
<app:Page3 />
</g:Tab>
</g:TabPanel>
Inside the tab panel you can place as many tabs as you want. Inside the tab you can place a widget, composite or some panel.
The <app:xxx> tag you define in the <ui:UiBinder> tag at the top of the zzz.ui.xml and could look like this: xmlns:app="urn:import:com.yourproject.package". So every class which lies in this package (and extends Composite (or similar)) can be used in the ui binder this way.
Also see the GWT documentation of the Ui Binder: http://code.google.com/webtoolkit/doc/2.2/DevGuideUiBinder.html

Change style of html links in TextViews after executing Html.fromHtml

I'm developing an android application. I retrieve some data that looks like this:
My Link to Google!</font></b>
I'm applying it to a TextView like this:
myTextView.setText(Html.fromHtml(myHtmlString));
The issue I encounter here is that Html.fromHtml seems to apply a general styling
to any and all links, which is to color them blue and underline them. I'd rather not have it do this, is there any simple solution to make it not stylize links(and therefore, I assume, "font color=whatever" would apply instead)? The behavior does not change if the HTML link tag is on the inside of font/style tags.
Use android:textColorLink attribute. I'm afraid it's the only way to change link color.
If you're sure that you have only one link in the text then you can do the following:
Spanned text = Html.fromHtml(myHtmlString);
ForegroundColorSpan spans[] = text.getSpans(0, text.length(),
ForegroundColorSpan.class);
if (spans.length > 0) {
myTextView.setLinkTextColor(spans[0].getForegroundColor());
}
myTextView.setText(text);

Categories

Resources