/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Sun Microsystems nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package podcastfeedviewer;
import javafx.scene.CustomNode;
import javafx.scene.paint.Color;
import javafx.scene.Node;
import javafx.scene.Group;
import javafx.scene.layout.HBox;
import javafx.scene.text.Text;
import javafx.scene.text.Font;
import javafx.scene.shape.Rectangle;
import javafx.scene.layout.VBox;
import javafx.scene.input.MouseEvent;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;
import javafx.util.Sequences;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.TextBox;
import javafx.animation.Timeline;
import javafx.animation.KeyFrame;
import javafx.animation.Interpolator;
import podcastfeedviewer.PodcastParser;
import podcastfeedviewer.PersistenceHandler;
public class LocationControll extends CustomNode {
public var width = 640.0;
public var height = 50.0;
public-read var location:String;
public function setText(text:String){
textBox.text = text;
textBox.commit();
}
var textBox:TextBox = TextBox {
translateX: bind (Main.iconSize + Main.gap)
translateY: bind (5 * Main.widthRatio1)
width : bind Main.textBoxSize
height: bind (Main.iconSize - 5*Main.heightRatio1)
font: Font {
size: (24 * Main.widthRatio1) as Integer
}
editable:false
text: ""
action: function(){
textBox.editable = false;
textBox.commit();
location = textBox.text;
Main.location = location.trim();
Main.log("Start clicked - Location changed {location}");
}
}
var leftArrow:ImageView =
ImageView{
fitHeight:bind Main.iconSize
fitWidth:bind Main.iconSize
image:Image{
url:"{__DIR__}resources/arrow_left.png"
}
onMousePressed: function(e:MouseEvent){
if ( sizeof Main.locations == 0){
textBox.text = "";
location = "";
Main.location = "";
return;
}
var index = Sequences.indexOf(Main.locations,location);
if ( index == 0){
index = sizeof Main.locations - 1;
}else index --;
Main.location = Main.locations[index];
setText(Main.locations[index]);
location =Main.location;
Main.log("Left arrow clicked - {location}");
}
}
var rightArrow:ImageView =
ImageView{
translateX: bind (Main.iconSize + Main.gap + Main.textBoxSize + Main.gap);
fitHeight:bind Main.iconSize
fitWidth:bind Main.iconSize
image:Image{
url:"{__DIR__}resources/arrow_right.png"
}
onMousePressed: function(e:MouseEvent){
if ( sizeof Main.locations == 0){
setText("");
location = "";
return;
}
var index = Sequences.indexOf(Main.locations,location);
if ( index == (sizeof Main.locations - 1) or index < 0 ){
index = 0;
}else {index ++;}
Main.location = Main.locations[index];
setText(Main.locations[index]);
location =Main.location;
Main.log("Righ arrow clicked - {location}");
}
}
var plus:ImageView =
ImageView{
translateX:bind (Main.iconSize + Main.gap + Main.textBoxSize + Main.gap + Main.iconSize + Main.gap + Main.iconSize + Main.gap);
fitHeight:bind Main.iconSize
fitWidth:bind Main.iconSize
image:Image{
url:"{__DIR__}resources/feed_plus.PNG"
}
onMousePressed: function(e:MouseEvent){
textBox.editable = true;
setText("");
Main.log("Add clicked");
}
}
var start:ImageView =
ImageView{
translateX: bind (Main.iconSize + Main.gap + Main.textBoxSize + Main.gap + Main.iconSize +Main.gap);
fitHeight:bind Main.iconSize
fitWidth:bind Main.iconSize
image:Image{
url:"{__DIR__}resources/start.PNG"
}
onMousePressed: function(e:MouseEvent){
textBox.editable = false;
textBox.commit();
location = textBox.text;
Main.location = location.trim();
Main.log("Start clicked - Location changed {location}");
}
}
var remove:ImageView =
ImageView{
translateX: bind (4*Main.iconSize + 5*Main.gap + Main.textBoxSize );
fitHeight:bind Main.iconSize
fitWidth:bind Main.iconSize
image:Image{
url:"{__DIR__}resources/remove.png"
}
onMousePressed: function(e:MouseEvent){
textBox.editable = false;
PodcastParser.removePodcast(location);
PersistenceHandler.store(Main.locations);
if ( sizeof Main.locations > 0 ){
setText(Main.locations[0]);
location = Main.locations[0];
Main.location = Main.locations[0];
}else {
setText("");
location = "";
Main.location = "";
}
}
}
public override function create(): Node {
return Group {
content: [
leftArrow,
TooltipNode {
sourceNode:leftArrow
tooltip:" Previous Feed"
width:120
},
textBox,
TooltipNode {
sourceNode:textBox
tooltip:" Clik on Add to change feed"
width:140
},
rightArrow,
TooltipNode {
sourceNode:rightArrow
tooltip:"Next Feed"
width:50
},
plus,
TooltipNode {
sourceNode: plus
tooltip:"Add a new podcast feed"
width :120
},
start,
TooltipNode {
sourceNode:start
tooltip:"Start polling"
width:60
},
remove,
TooltipNode {
sourceNode:remove
tooltip:"Remove the Feed from list"
width:160
}
]
};
}
}
function run(){
Stage {
title: "Location Tool bar Test"
scene: Scene {
width: 500
height: 200
content: [ LocationControll{} ]
}
}
}