use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class Label method shouldTickerStart.
/**
* Returns true if a ticker should be started since there is no room to show
* the text in the label.
*
* @return true if a ticker should start running
*/
public boolean shouldTickerStart() {
if (!tickerEnabled) {
return false;
}
Style style = getStyle();
int txtW = style.getFont().stringWidth(getText());
int textSpaceW = getAvaliableSpaceForText();
return txtW > textSpaceW && textSpaceW > 0;
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class CSSEngine method setWrapRecursive.
/**
* Sets this element and all children to have wrapped text.
* In cases where text is already wrapped no change will be made.
* This will work only in FIXED_WIDTH mode (Checked before called)
* Technically all this logic can be found in HTMLComponent.showText, but since we don't want to get into
* the context of this element (i.e. what was the indentation, alignment etc.), we use this algorithm.
*
* @param element The element to apply text wrapping on
* @param htmlC The HTMLComponent
*/
private void setWrapRecursive(HTMLElement element, HTMLComponent htmlC) {
if (element.isTextElement()) {
String text = element.getText();
final Vector ui = element.getUi();
if ((text != null) && (ui != null) && (ui.size() == 1)) {
// If it's already wrapped, no need to process
final Vector words = htmlC.getWords(text, Component.LEFT, false);
final Label label = (Label) ui.elementAt(0);
setWrapText(label, words, element, htmlC);
}
}
for (int i = 0; i < element.getNumChildren(); i++) {
setWrapRecursive((HTMLElement) element.getChildAt(i), htmlC);
}
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class CSSEngine method setWrapText.
/**
* Replaces an unwrapped text with a wrapped version, while copying the style of the original text.
*
* @param label The current label that contains the unwrapped text
* @param words A vector containing one word of the text (without white spaces) in each element
* @param element The text element
*/
private void setWrapText(Label label, Vector words, HTMLElement element, HTMLComponent htmlC) {
Style selectedStyle = label.getSelectedStyle();
Style unselectedStyle = label.getUnselectedStyle();
Vector ui = new Vector();
label.setText((String) words.elementAt(0) + ' ');
HTMLLink link = null;
if (label instanceof HTMLLink) {
link = (HTMLLink) label;
}
ui.addElement(label);
for (int i = 1; i < words.size(); i++) {
Label word = null;
if (link != null) {
word = new HTMLLink((String) words.elementAt(i) + ' ', link.link, htmlC, link, link.linkVisited);
} else {
word = new Label((String) words.elementAt(i) + ' ');
}
word.setSelectedStyle(selectedStyle);
word.setUnselectedStyle(unselectedStyle);
label.getParent().addComponent(word);
ui.addElement(word);
}
element.setAssociatedComponents(ui);
label.getParent().revalidate();
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class CSSEngine method setNowrapRecursive.
/**
* Sets this element and all children to have unwrapped text.
* In cases where text is already unwrapped no change will be made.
* This will work only in FIXED_WIDTH mode (Checked before called)
* Technically a lot of this logic can be found in HTMLComponent, but since we don't want to get into
* the context of this element (i.e. what was the indentation, alignment etc.), we use this algorithm.
*
* @param element The element to apply text wrapping on
*/
private void setNowrapRecursive(final HTMLElement element) {
// if (element.getId()==HTMLElement.TAG_TEXT) {
if (element.isTextElement()) {
// String text=element.getAttributeById(HTMLElement.ATTR_TITLE);
String text = element.getText();
final Vector ui = element.getUi();
if ((text != null) && (ui != null) && (ui.size() > 1)) {
// If it's just one word or already no-wrapped, no need to process
String word = "";
String newText = "";
for (int c = 0; c < text.length(); c++) {
char ch = text.charAt(c);
if ((ch == ' ') || (ch == 10) || (ch == 13) || (ch == '\t') || (ch == '\n')) {
if (!word.equals("")) {
newText += word + " ";
word = "";
}
} else {
word += ch;
}
}
if (!word.equals("")) {
newText += word + " ";
}
final Label label = (Label) ui.elementAt(0);
setNowrapText(label, ui, newText, element);
}
}
for (int i = 0; i < element.getNumChildren(); i++) {
setNowrapRecursive((HTMLElement) element.getChildAt(i));
}
// If children elements' UI was changed, we need to recalc the UI of the parent
element.recalcUi();
}
use of com.codename1.ui.Label in project CodenameOne by codenameone.
the class TextArea method calcPreferredSize.
/**
* {@inheritDoc}
*/
protected Dimension calcPreferredSize() {
if (shouldShowHint()) {
Label l = getHintLabelImpl();
if (l != null) {
Dimension d1 = getUIManager().getLookAndFeel().getTextAreaSize(this, true);
Dimension d2 = l.getPreferredSize();
return new Dimension(Math.max(d1.getWidth(), d2.getWidth()), Math.max(d1.getHeight(), d2.getHeight()));
}
}
return getUIManager().getLookAndFeel().getTextAreaSize(this, true);
}
Aggregations