当前位置: 首页>>代码示例>>Java>>正文


Java Label.getStyle方法代码示例

本文整理汇总了Java中com.codename1.ui.Label.getStyle方法的典型用法代码示例。如果您正苦于以下问题:Java Label.getStyle方法的具体用法?Java Label.getStyle怎么用?Java Label.getStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.codename1.ui.Label的用法示例。


在下文中一共展示了Label.getStyle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawLabelString

import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
 * Implements the drawString for the text component and adjust the valign
 * assuming the icon is in one of the sides
 */
private int drawLabelString(Graphics g, Label l, String text, int x, int y, int textSpaceW) {
    Style style = l.getStyle();

    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();
    //g.pushClip();
    g.clipRect(x, cy, textSpaceW, ch);

    if (l.isTickerRunning()) {
        Font font = style.getFont();
        if (l.getShiftText() > 0) {
            if (l.getShiftText() > textSpaceW) {
                l.setShiftText(x - l.getX() - l.getStringWidth(font));
            }
        } else if (l.getShiftText() + l.getStringWidth(font) < 0) {
            l.setShiftText(textSpaceW);
        }
    }
    int drawnW = drawLabelText(g, l, text, x, y, textSpaceW);

    g.setClip(cx, cy, cw, ch);
    //g.popClip();

    return drawnW;
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:32,代码来源:DefaultLookAndFeel.java

示例2: drawLabelString

import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
 * Implements the drawString for the text component and adjust the valign
 * assuming the icon is in one of the sides
 */
private int drawLabelString(Graphics g, Label l, String text, int x, int y, int textSpaceW) {
    Style style = l.getStyle();

    int cx = g.getClipX();
    int cy = g.getClipY();
    int cw = g.getClipWidth();
    int ch = g.getClipHeight();
    //g.pushClip();
    g.clipRect(x, cy, textSpaceW, ch);

    if (l.isTickerRunning()) {
        if (l.getShiftText() > 0) {
            if (l.getShiftText() > textSpaceW) {
                l.setShiftText(x - l.getX() - style.getFont().stringWidth(text));
            }
        } else if (l.getShiftText() + style.getFont().stringWidth(text) < 0) {
            l.setShiftText(textSpaceW);
        }
    }
    int drawnW = drawLabelText(g, l, text, x, y, textSpaceW);

    g.setClip(cx, cy, cw, ch);
    //g.popClip();

    return drawnW;
}
 
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:DefaultLookAndFeel.java

示例3: getPreferredSize

import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
private Dimension getPreferredSize(Label l, Image[] icons, Image stateImage) {
    int prefW = 0;
    int prefH = 0;

    Style style = l.getStyle();
    int gap = l.getGap();
    int ilen = icons.length;
    for (int i = 0; i < ilen; i++) {
        Image icon = icons[i];
        if (icon != null) {
            prefW = Math.max(prefW, icon.getWidth());
            prefH = Math.max(prefH, icon.getHeight());
        }
    }
    String text = l.getText();
    Font font = style.getFont();
    if (font == null) {
        System.out.println("Missing font for " + l);
        font = Font.getDefaultFont();
    }
    if (text != null && text.length() > 0) {
        //add the text size
        switch (l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += font.stringWidth(text);
                prefH = Math.max(prefH, font.getHeight());
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefW = Math.max(prefW, font.stringWidth(text));
                prefH += font.getHeight();
                break;
        }
    }
    //add the state image(relevant for CheckBox\RadioButton)
    if (stateImage != null) {
        prefW += (stateImage.getWidth() + gap);
        prefH = Math.max(prefH, stateImage.getHeight());
    }


    if (icons[0] != null && text != null && text.length() > 0) {
        switch (l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += gap;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefH += gap;
                break;
        }
    }

    if(l.isShowEvenIfBlank()) {
        prefH += style.getVerticalPadding();
        prefW += style.getHorizontalPadding();
    } else {
        if (prefH != 0) {
            prefH += style.getVerticalPadding();
        }
        if (prefW != 0) {
            prefW += style.getHorizontalPadding();
        }
    }

    if(style.getBorder() != null) {
        prefW = Math.max(style.getBorder().getMinimumWidth(), prefW);
        prefH = Math.max(style.getBorder().getMinimumHeight(), prefH);
    } 
    if(isBackgroundImageDetermineSize() && style.getBgImage() != null) {
        prefW = Math.max(style.getBgImage().getWidth(), prefW);
        prefH = Math.max(style.getBgImage().getHeight(), prefH);
    }

    return new Dimension(prefW, prefH);
}
 
开发者ID:codenameone,项目名称:CodenameOne,代码行数:82,代码来源:DefaultLookAndFeel.java

示例4: getPreferredSize

import com.codename1.ui.Label; //导入方法依赖的package包/类
/**
 * @inheritDoc
 */
private Dimension getPreferredSize(Label l, Image[] icons, Image stateImage) {
    int prefW = 0;
    int prefH = 0;

    Style style = l.getStyle();
    int gap = l.getGap();
    for (int i = 0; i < icons.length; i++) {
        Image icon = icons[i];
        if (icon != null) {
            prefW = Math.max(prefW, icon.getWidth());
            prefH = Math.max(prefH, icon.getHeight());
        }
    }
    String text = l.getText();
    Font font = style.getFont();
    if (font == null) {
        System.out.println("Missing font for " + l);
        font = Font.getDefaultFont();
    }
    if (text != null && text.length() > 0) {
        //add the text size
        switch (l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += font.stringWidth(text);
                prefH = Math.max(prefH, font.getHeight());
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefW = Math.max(prefW, font.stringWidth(text));
                prefH += font.getHeight();
                break;
        }
    }
    //add the state image(relevant for CheckBox\RadioButton)
    if (stateImage != null) {
        prefW += (stateImage.getWidth() + gap);
        prefH = Math.max(prefH, stateImage.getHeight());
    }


    if (icons[0] != null && text != null && text.length() > 0) {
        switch (l.getTextPosition()) {
            case Label.LEFT:
            case Label.RIGHT:
                prefW += gap;
                break;
            case Label.BOTTOM:
            case Label.TOP:
                prefH += gap;
                break;
        }
    }

    if (prefH != 0) {
        prefH += (style.getPadding(false, Component.TOP) + style.getPadding(false, Component.BOTTOM));
    }
    if (prefW != 0) {
        prefW += (style.getPadding(l.isRTL(), Component.RIGHT) + style.getPadding(l.isRTL(), Component.LEFT));
    }

    if(style.getBorder() != null) {
        prefW = Math.max(style.getBorder().getMinimumWidth(), prefW);
        prefH = Math.max(style.getBorder().getMinimumHeight(), prefH);
    } 
    if(isBackgroundImageDetermineSize() && style.getBgImage() != null) {
        prefW = Math.max(style.getBgImage().getWidth(), prefW);
        prefH = Math.max(style.getBgImage().getHeight(), prefH);
    }

    return new Dimension(prefW, prefH);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:76,代码来源:DefaultLookAndFeel.java


注:本文中的com.codename1.ui.Label.getStyle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。