Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Codenameone 使用标签实例极慢地呈现彩色文本_Codenameone - Fatal编程技术网

Codenameone 使用标签实例极慢地呈现彩色文本

Codenameone 使用标签实例极慢地呈现彩色文本,codenameone,Codenameone,我试图通过将没有边距和填充的标签实例放入一个容器中来部分着色文本——通过测试,我意识到渲染的速度有多慢 现在我很好奇为什么会发生这种情况 我查看了模拟器的性能监视器,但不明白是什么原因导致了这种情况 代码如下: public class FormReSplit extends Form { Runnable runnableFilter; public FormReSplit() { super("FormReSplit", new BoxLayout(BoxL

我试图通过将没有边距和填充的标签实例放入一个容器中来部分着色文本——通过测试,我意识到渲染的速度有多慢

现在我很好奇为什么会发生这种情况

我查看了模拟器的性能监视器,但不明白是什么原因导致了这种情况

代码如下:

public class FormReSplit extends Form {
    Runnable runnableFilter;

    public FormReSplit() {
        super("FormReSplit", new BoxLayout(BoxLayout.Y_AXIS));
        setScrollableX(false);
        setScrollableY(false);
        String[] words = new RE(" ").split("Paddy Corcoran's wife was for several years afflicted with a disease that nobody could properly understand. Nobody could tell what the matter with her was. She lay a bedridden invalid, trying doctors and quacks of all sorts, sexes, and sizes, till Paddy at last had just one comfort: she wouldn't be long with him—long troubling him. The seventh year was on the point of closing, when, one harvest day, as she lay moaning over her hard condition. Then a little woman who was dressed in a neat red cloak, came in and sat down by the hearth, saying: \"Well, Kitty Corcoran, now you have been lying on your back for seven years, and just as far from being cured as ever. But you may be blamed for it.\" \"How is that?\" asked Kitty bewildered. \"You see, for the last seven years you have been annoying us, the good people, and since I have a regard for you, I have come to let you know why you have been sick so long. While you have been ill, your children has thrown your dirty water out of the door after dusk and before sunrise, just when we are passing your door, which we do twice a day. Now, if you avoid this, if you throw it out in a different place and at a different time, your disease will leave you, and you will be as well as ever before. If you don't follow this advice, why, remain as you are, and all the arts of man cannot cure you.\" She then bade her good-bye, and disappeared. Kitty, who was glad to be cured on such easy terms, at once complied with the injunction of the fairy; and next day she was in as good health as ever, enjoying life once again.");
        TextField textField = new TextField("e") {
            @Override
            public void setText(String aText) {
                boolean change = !getText().equals(aText);
                super.setText(aText);
                if (change) {
                    filter();
                }
            }
        };
        add(textField);
        Container container = new Container(new BoxLayout(BoxLayout.Y_AXIS));
        container.setName("matchingWords");
        container.setScrollableX(false);
        container.setScrollableY(true);
        add(container);
        runnableFilter = () -> {
            String matchcode = textField.getText();
            container.removeAll();
            int tally = 0;
            for (String word: words) {
                String[] parts = (null != matchcode && !matchcode.trim().equals(""))
                        ? new RE(matchcode).split(word)
                        : new String[] {word};
                if (parts.length > 1 || (parts.length == 1 && parts[0].length() < word.length())) {
                    int index = 0;
                    LinkedList<String> tokens = new LinkedList<>();
                    LinkedList<Boolean> matches = new LinkedList<>();
                    for (String part: parts) {
                        if (part.equals("")) {
                            continue;
                        }
                        int indexOf = word.indexOf(part, index);
                        if (indexOf > index) {
                            String matched = word.substring(index, indexOf);
                            if (!matches.isEmpty() && matches.getLast()) {
                                tokens.add(tokens.removeLast() + matched);
                            } else {
                                tokens.add(matched);
                                matches.add(true);
                            }
                            index = indexOf + part.length();
                        } else {
                            index += part.length();
                        }
                        tokens.add(part);
                        matches.add(false);
                    }
                    if (index < word.length()) {
                        String matched = word.substring(index, word.length());
                        if (!matches.isEmpty() && matches.getLast()) {
                            tokens.add(tokens.removeLast() + matched);
                        } else {
                            tokens.add(matched);
                            matches.add(true);
                        }
                    }
                    Container containerFlow = new Container(new FlowLayout());
                    containerFlow.setName("match" + tally++);
                    while (!tokens.isEmpty()) {
                        String token = tokens.pop();
                        Label labelMatched = new Label(token);
                        Style styleMatched = labelMatched.getAllStyles();
                        styleMatched.setMargin(0, 0, 0, 0);
                        styleMatched.setPadding(0, 0, 0, 0);
                        if (matches.pop()) {
                            styleMatched.setBgColor(0xffc0c0);
                            styleMatched.setFgColor(0xff0000);
                        } else {
                            styleMatched.setBgColor(0xf0f0f0);
                            styleMatched.setFgColor(0xc0c0c0);
                        }
                        styleMatched.setBgTransparency(255);
                        containerFlow.add(labelMatched);
                    }
                    container.add(containerFlow);
                }
            }
            container.animateLayout(400);
            textField.startEditingAsync();
        };
        filter();
    }

    protected void filter() {
        if (null != runnableFilter) {
            Display.getInstance().callSerially(runnableFilter);
        }
    }
}
公共类FormReSplit扩展了表单{
可运行的可运行过滤器;
公共表格{
超级(“FormReSplit”,新的BoxLayout(BoxLayout.Y_轴));
setScrollableX(假);
setScrollableY(假);
String[]words=new RE(“”)。拆分("帕迪·科科伦的妻子多年来一直患有一种没有人能完全理解的疾病。没有人知道她到底是怎么了。她躺在一个卧床不起的病人身上,尝试各种各样的医生和庸医,无论性别大小,直到帕迪最后只有一个安慰:她不会和他在一起太久,也不会长期困扰他一个收获的日子,她的耳朵快要关上了,她躺在地上呻吟着,这时一个穿着整洁的红色斗篷的小妇人进来,坐在壁炉旁,说:\“好吧,基蒂·科科伦,现在你已经仰卧七年了,而且还没有像以前一样痊愈。但是你可能会为此受到责备。”“怎么回事?”基蒂困惑地问你看,在过去的七年里,你一直在骚扰我们这些善良的人们,既然我对你很关心,我就来告诉你为什么你病了这么久。当你生病的时候,你的孩子们在傍晚和日出之前,就在我们经过你家门口的时候,把你的脏水扔出门外,我们每天都会这样做两次哦,如果你避免这样做,如果你在不同的时间、不同的地点把它扔掉,你的疾病就会离开你,你会和以前一样好。如果你不遵循这个建议,为什么,保持现状,人类所有的艺术都无法治愈你\“然后,她告别了,消失了。基蒂很高兴能以如此轻松的方式得到治愈,她立刻听从了仙女的命令;第二天,她身体和以前一样好,再次享受生活。”);
TextField TextField=新的TextField(“e”){
@凌驾
公共无效设置文本(字符串aText){
布尔更改=!getText().equals(aText);
super.setText(aText);
如果(更改){
过滤器();
}
}
};
添加(文本字段);
容器容器=新容器(新的BoxLayout(BoxLayout.Y_轴));
container.setName(“匹配词”);
容器。设置Crollablex(假);
容器。setScrollableY(真);
添加(容器);
runnableFilter=()->{
字符串matchcode=textField.getText();
container.removeAll();
整数=0;
for(字符串字:字){
字符串[]部分=(null!=matchcode&!matchcode.trim().equals(“”)
?新RE(匹配码)。拆分(字)
:新字符串[]{word};
如果(parts.length>1 | |(parts.length==1&&parts[0].length()index){
字符串匹配=字.子字符串(索引,indexOf);
如果(!matches.isEmpty()&&matches.getLast()){
tokens.add(tokens.removeLast()+匹配);
}否则{
代币。添加(匹配);
匹配。添加(true);
}
index=indexOf+part.length();
}否则{
索引+=零件长度();
}
代币。添加(部分);
匹配。添加(false);
}
if(索引