segphault (owner)

Revisions

gist: 32851 Download_button fork
public
Description:
A Twitter search tool written in JavaFX
Public Clone URL: git://gist.github.com/32851.git
Embed All Files: show embed
Main.fx #
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
/*
 * Main.fx
 *
 * Created on Dec 5, 2008, 11:27:35 AM
 */
 
package testapplication;
 
import javafx.scene.*;
import javafx.scene.image.*;
import javafx.scene.layout.*;
import javafx.scene.effect.*;
import javafx.stage.*;
import javafx.ext.swing.SwingButton;
import javafx.scene.text.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.async.RemoteTextDocument;
import org.json.JSONObject;
import testapplication.Message;
 
/**
 * @author Ryan Paul
 */
 
var vb:VBox;
 
Stage {
  title: "Application title"
  width: 430 height: 500
  
  onClose: function() {
    java.lang.System.exit(0);
  }
  
  scene: Scene {content: [
    ImageView { image: Image { url: "{__DIR__}fyre.png" } },
    vb = VBox {
      spacing: 5
      content: [
        Group {content: [
          Rectangle { width: 430 height: 40 fill: Color.rgb(114, 159, 207) }
          Rectangle {
            width: 430 height: 40
            fill: LinearGradient {
              startX: 0 startY: 0 endX: 0 endY: 1
              stops: [
                Stop { offset: 0.0 color: Color { opacity: 0.10 }},
                Stop { offset: 0.05 color: Color { red:1 green:1 blue:1 opacity: 0.45 }}
                Stop { offset: 0.2 color: Color { red:1 green:1 blue:1 opacity: 0.50 }}
                Stop { offset: 0.4 color: Color { red:1 green:1 blue:1 opacity: 0.25 }}
                Stop { offset: 0.6 color: Color { red:1 green:1 blue:1 opacity: 0.0 }}
                Stop { offset: 0.9 color: Color { red:1 green:1 blue:1 opacity: 0.10 }}
                Stop { offset: 1.0 color: Color { red:1 green:1 blue:1 opacity: 0.50 }}
            ]}
          }
          Text {
            content: "Twitter Watch"
            x: 10 y: 25 font: Font.font("Calibri", FontWeight.BOLD, 24) fill: Color.WHITE;
            effect: DropShadow { offsetX: 1 offsetY: 1 radius: 4 color: Color.BLACK }
          }
        ]}
      ]
    }
  ]}
}
 
function addMessages(query, box:VBox, count) {
  var twitterData:RemoteTextDocument = RemoteTextDocument {
    url: "http://search.twitter.com/search.json?q={query}&rpp={count}"
    onDone: function (finished) {
      var data = new JSONObject(twitterData.document).getJSONArray("results");
      for (i in [0..data.length()]) {
        var j = data.getJSONObject(i);
          insert Message {
            username: j.getString("from_user")
            text: j.getString("text");
            picture: j.getString("profile_image_url")
          } into box.content;
      }
    }
  }
}
 
addMessages("query string", vb, 5);
 
Message.fx #
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
/*
 * Test.fx
 *
 * Created on Dec 5, 2008, 11:44:39 AM
 */
 
package testapplication;
 
import javafx.scene.*;
import javafx.scene.effect.*;
import javafx.scene.text.*;
import javafx.scene.image.*;
import javafx.scene.paint.*;
import javafx.scene.layout.*;
import javafx.scene.shape.*;
import javafx.scene.control.*;
import javafx.stage.*;
 
/**
 * @author Ryan Paul
 */
 
public class Message extends CustomNode {
  public var username:String;
  public var text:String;
  public var picture:String;
  public override function create(): Node {
    return Group {
      content: [
        Rectangle {
          opacity: 0.85
          arcHeight: 20 arcWidth: 20
          width: 400 height: 90 x: 10
          fill: LinearGradient {
            startX: 0 startY: 0 endX: 0 endY: 1
            stops: [
              Stop { offset: 0.1 color: Color.rgb(114, 159, 207) },
              Stop { offset: 1.0 color: Color.rgb(65, 92, 120) }
            ]
          }
        },
        ImageView {
          image: Image { url: picture }
          x: 20 y: 10 effect: Reflection { topOffset: 0 fraction: 0.5 }
        },
        VBox {
          spacing: 5
          content: [
            Text {
              content: username
              x: 80 y: 20 font: Font.font("Calibri", FontWeight.BOLD, 18) fill: Color.WHITE;
              effect: DropShadow { offsetX: 1 offsetY: 1 radius: 4 color: Color.BLACK }
            },
            Text {
              content: text
              x: 80 y: 10 font: Font.font("Calibri", 14) fill: Color.WHITE;
              effect: DropShadow { offsetX: 1 offsetY: 1 radius: 1 color: Color.BLACK }
              wrappingWidth: 320
            }
          ]
        }
      ]
    }
  }
}