~philho/+junk/JavaFX

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
import javafx.stage.*; // Stage, StageStyle, Screen, Alert...
import javafx.scene.*; // Scene, Node, CustomNode, Group, Cursor, Parent

import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.paint.*; // Color, LinearGradient, RadialGradient...
import javafx.scene.shape.*; // Line, Rectangle, Circle, Ellipse...
import javafx.scene.text.*; // Text, Font...
import javafx.scene.transform.*; // Transform, Translate, Rotate, Scale...
import javafx.scene.effect.*; // Blend, Reflection, DisplacementMap, XxxBlur, XxxShadow...
import javafx.scene.input.*; // KeyCode, KeyEvent, MouseButton, MouseEvent
import javafx.scene.control.*; // Button, CheckBox, ListView, ProgressBar, RadioButton, TextBox...
import javafx.scene.layout.*; // HBox, VBox, Flow, LayoutInfo...

import javafx.animation.*; // Timeline, KeyFrame, KeyValue...
import javafx.animation.transition.*; // AnimationPath, Transition, XxxTransition, OrientationType

import javafx.async.*; // Task, RunnableFuture, JavaTaskBase

import javafx.data.pull.PullParser;
import javafx.data.pull.Event;
import javafx.data.xml.XMLConstants;
import javafx.data.xml.QName;

import javafx.geometry.*; // Bounds, BoundingBox, Point2D, Rectangle2D...
import javafx.fxd.*; // Duplicator, FXDnode, FXDContent, FXDLoader
import javafx.data.Pair;
import javafx.io.Resource;
import javafx.io.Storage;
import javafx.io.http.*; // HttpHeader, HttpRequest, HttpStatus, URLConverter

import javafx.lang.*; // Duration, FX...
import javafx.util.*; // Bits, Math, Sequences, Properties...
import javafx.date.DateTime;

import java.util.Locale;
import java.util.ArrayList;
import java.lang.System;
import java.lang.Exception;
import java.io.*;

/*
var filePath = "D:/Documents/Images/References/coins.jpg";
var image = Image
{
    url: "file:///{filePath}";
    height: 400, preserveRatio: true
    backgroundLoading: true
    placeholder: Image
    {
        url: "D:/Documents/Images/Animations/aniswirl.gif"
    }
}

var scene: Scene;
Stage
{
    title: "Forum Test"
    scene: scene = Scene
    {
        width: 500
        height: 500
        fill: Color.LAVENDER
        content:
        [
            ImageView
            {
                image: image
                x: 50, y: 50
            }
        ]
    }
}
sidehatch.SideHatch.activate();
*/

/*
import javax.help.*;
import java.net.URL;

var scene: Scene;
Stage
{
    title: "Forum Test"
    scene: scene = Scene
    {
        width: 500
        height: 500
        fill: Color.LAVENDER
        content:
        [
            Ellipse
            {
                fill: Color.GREEN
                centerX: 50, centerY: 50
                radiusX: 80, radiusY: 50
            }
            Button
            {
                translateX: 20
                translateY: 40
                text: "Help"
                action: function (): Void
                {
                    JHelp helpViewer = null;
                    try
                    {
                        // Get the classloader of this class.
                        ClassLoader cl = getClass().getClassLoader();
                        URL url = HelpSet.findHelpSet(cl, "jhelpset.hs");
                        // Create a new JHelp object with a new HelpSet.
                        helpViewer = new JHelp(new HelpSet(cl, url));
                        // Set the initial entry point in the table of contents.
                        helpViewer.setCurrentID("Simple.Introduction");
                    }
                    catch (Exception e)
                    {
                        println("API Help Set not found");
                    }
                }
            }
        ]
    }
}

static public HelpBroker startJavaHelp()
{
    HelpBroker hb = null ;
    URL url = null;
    String helpHS = "help/help.hs";
//~ 	ClassLoader cl = ecowand.Main.class.getClassLoader();
    ClassLoader cl = getClass().getClassLoader();
    try
    {
        url = HelpSet.findHelpSet(cl, helpHS);
        HelpSet hs = new HelpSet(cl, url);
        hb = hs.createHelpBroker();
    }
    catch(Exception e)
    {
        e.printStackTrace();
        System.out.println("Url error here " + url);
    }
    return hb;
}
*/

class ChatList extends CustomNode {
    // The data to list
    public var data: Object[];
    // The nodes used to display data (only enough for the currently visible part)
    var nodes: Node[];
    var scrollBar: ScrolLBar;

    public var width = 100.0;
    public var height = 100.0;
    public var itemHeight = 10.0;

    // Number of visible items in the list
    var visibleCount: Integer = bind ((height / itemHeight) as Integer) + 1;
    var currentStartItem = 0;
    var yoff = 0.0;

    public var scrollValue = 0.0 on replace { adjust(); }

    // Provide this function to create nodes in the list
    // Called when scrolling to create nodes as they are displayed
    public var createItemNode: function(obj: Object, bounds: Bounds): Node;

    public function update(): Void
    {
        regen(0, visibleCount);
    }

    function adjust(): Void {
        // There is a bug in v.1.2 scroll bar: min is set to 0 but scrollValue can go negative...
        var visibleStart = scrollValue;
        if (scrollValue < 0) visibleStart = 0;
        var startItem = (visibleStart / itemHeight) as Integer;
        yoff = -(visibleStart mod itemHeight);
        println("{visibleStart} {startItem} {yoff}");
        if (startItem != currentStartItem) {
            currentStartItem = startItem;
            regen(startItem, startItem + visibleCount);
        }
    }

    function regen(start: Integer, end: Integer): Void {
        def bds = BoundingBox { width: width, height: itemHeight };
        nodes = for (i in [start .. end]) {
            var nd = createItemNode(data[i], bds);
            nd.translateY = (indexof i) * itemHeight;
            nd; // To add to nodes sequence
        }
    }

    override public function create(): Node {
        Group {
            content: Group { content: bind nodes, translateY: bind yoff }
            clip: Rectangle { width: bind width, height: bind height }
        }
    }

    init {
        scrollBar = ScrollBar {
            min: 0, max: bind (elements.size() - 1) * itemHeight
            vertical: true
            height: bind height
            value: bind scrollValue with inverse
            unitIncrement: itemHeight / 2
        }
        update();
    }

}

class Item {
    public var username = "foo";
    public var message = "bar";
}

function customView(obj: Object, bounds: Bounds): Node {
    var item = obj as Item;
    return Group {
        content: [
            Rectangle {
                width: bounds.width, height: bounds.height
                fill: LinearGradient { startX : 0.0, startY : 0.0, endX : 0.0, endY : 1.0
                        stops: [
                            Stop { color: Color.rgb(230,230,230), offset: 0.0 },
                            Stop { color: Color.rgb(210,210,210), offset: 1.0 },
                        ]
                }
            }
            Text { content: item.username, x: 10, y: 15, font: Font.font("Helvetica", 17) }
            Text { content: item.message,  x: 10, y: 26, font: Font.font("Helvetica", 11) }
        ]
    }
}
def ITEM_HEIGHT = 30;

class ChatDisplay extends CustomNode {

    var username = "TableScene.GetUserName()";
    var TextField = TextBox { translateY: 123, columns: 27, selectOnFocus: true }
    var chatList: ChatList;
    var elements: Item[];

    var scrollValue = 0.0;

    public function PutMessage(Message: String, UserName: String): Void {
        var buff = Item { message: Message, username: UserName };
        insert buff into elements;
        chatList.update();
//~ 		display();
    }

    public function display(): Void {
        println("-----");
        for(i in [0 ..< sizeof elements]){
            println("{i} {elements[i].message}");
        }
    }

    public override function create(): Node {
        return Group {
            content: [
               Rectangle { width: 298, height: 148, fill: Color.ORANGE },
               TextField,
               Button { translateY: 125, translateX: 242, text: "Send", action: function() {
//~                           TableScene.SendMessage(TextField.text, username);
PutMessage(TextField.text, "Some Person");
               }},
               Button {translateY: 125, translateX: 301, text: "Exit", action: function() {
//~                           TableScene.DelateClient(username);
display();
               }},
               chatList = ChatList {
                    translateX: 0
                    translateY: 0
                    data: bind elements
                    width: 280 height: 120
                    itemHeight: ITEM_HEIGHT
                    createItemNode: customView
                }
            ]
        }
    }
}

var scene: Scene;
var cd = ChatDisplay {};
cd.PutMessage("This is a message", "Zielony");
Stage
{
    title: "Forum Test"
    scene: scene = Scene
    {
        width: 500
        height: 500
        content:
        [
            cd
        ]
    }
}