words/src/main/java/org/apidesign/demo/words/DataModel.java
author Jaroslav Tulach <jtulach@netbeans.org>
Thu, 15 Aug 2013 13:17:54 +0200
changeset 46 009537e6ce80
parent 39 spinningcube/src/main/java/org/apidesign/demo/spinningcube/DataModel.java@43c71f709cc8
child 56 68cecf6c3113
permissions -rw-r--r--
Simpler animation demo that works on JDK7
jtulach@39
     1
/**
jtulach@39
     2
 * The MIT License (MIT)
jtulach@39
     3
 *
jtulach@39
     4
 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@39
     5
 *
jtulach@39
     6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
jtulach@39
     7
 * of this software and associated documentation files (the "Software"), to deal
jtulach@39
     8
 * in the Software without restriction, including without limitation the rights
jtulach@39
     9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jtulach@39
    10
 * copies of the Software, and to permit persons to whom the Software is
jtulach@39
    11
 * furnished to do so, subject to the following conditions:
jtulach@39
    12
 *
jtulach@39
    13
 * The above copyright notice and this permission notice shall be included in
jtulach@39
    14
 * all copies or substantial portions of the Software.
jtulach@39
    15
 *
jtulach@39
    16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jtulach@39
    17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jtulach@39
    18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
jtulach@39
    19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jtulach@39
    20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jtulach@39
    21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jtulach@39
    22
 * THE SOFTWARE.
jtulach@39
    23
 */
jtulach@46
    24
package org.apidesign.demo.words;
jtulach@39
    25
jtulach@39
    26
import net.java.html.json.ComputedProperty;
jtulach@46
    27
import net.java.html.json.Function;
jtulach@39
    28
import net.java.html.json.Model;
jtulach@39
    29
import net.java.html.json.Property;
jtulach@39
    30
jtulach@39
    31
/** Model with one message and cube with six sides.
jtulach@39
    32
 *
jtulach@39
    33
 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jtulach@39
    34
 */
jtulach@39
    35
@Model(className = "Data", properties = {
jtulach@39
    36
    @Property(name = "message", type = String.class),
jtulach@46
    37
    @Property(name = "on", type = boolean.class)
jtulach@39
    38
})
jtulach@39
    39
final class DataModel {
jtulach@39
    40
    @ComputedProperty static String[] sides(String message) {
jtulach@39
    41
        String[] arr = new String[6];
jtulach@39
    42
        String[] words = message == null ? new String[0] : message.split(" ", 6);
jtulach@39
    43
        for (int i = 0; i < 6; i++) {
jtulach@39
    44
            arr[i] = words.length > i ? words[i] : "!";
jtulach@39
    45
        }
jtulach@39
    46
        return arr;
jtulach@39
    47
    }
jtulach@46
    48
    
jtulach@46
    49
    @Function static void turnOn(Data model) {
jtulach@46
    50
        model.setOn(true);
jtulach@46
    51
    }
jtulach@46
    52
    @Function static void turnOff(Data model) {
jtulach@46
    53
        model.setOn(false);
jtulach@46
    54
    }
jtulach@39
    55
}