Pro JavaFX Platform Chap1. Ex3.

2009년 8월 6일 목요일

Audio Config

image

------------------------------------------------------------MODEL

package projavafx.audioconfig.model;

/**
* The model class that the AudioConfigMain.fx script uses
*/
public class AudioConfigModel {
/**
* The minimum audio volume in decibels
*/
public def minDecibels:Number = 0;

/**
* The maximum audio volume in decibels
*/
public def maxDecibels:Number = 160;

/**
* The selected audio volume in decibels
*/
public var selectedDecibels:Number;

/**
* Indicates whether audio is muted
*/
public var muting:Boolean; // false is default for Boolean

/**
* List of some musical genres
*/
public def genres = [
"Chamber",
"Country",
"Cowbell",
"Metal",
"Polka",
"Rock"
];

/**
* Index of the selected genre
*/
public var selectedGenreIndex:Integer on replace {
if (genres[selectedGenreIndex] == "Chamber") {
selectedDecibels = 80;
}
else if (genres[selectedGenreIndex] == "Country") {
selectedDecibels = 100;
}
else if (genres[selectedGenreIndex] == "Cowbell") {
selectedDecibels = 150;
}
else if (genres[selectedGenreIndex] == "Metal") {
selectedDecibels = 140;
}
else if (genres[selectedGenreIndex] == "Polka") {
selectedDecibels = 120;
}
else if (genres[selectedGenreIndex] == "Rock") {
selectedDecibels = 130;
}
};
}

------------------------------------------------------------UI

package projavafx.audioconfig.ui;

import javafx.ext.swing.SwingComboBox;
import javafx.ext.swing.SwingComboBoxItem;
import javafx.scene.*;
import javafx.scene.control.Slider;
import javafx.scene.control.CheckBox;
import javafx.scene.paint.*;
import javafx.scene.shape.*;
import javafx.scene.text.*;
import javafx.stage.Stage;
import projavafx.audioconfig.model.AudioConfigModel;

Stage {
def acModel = AudioConfigModel {
selectedDecibels: 35
}
title: "Audio Configuration"
scene: Scene {
content: [
Rectangle {
// No need to assign 0 to x and y, because 0 is the default
width: 320
height: 45
fill: LinearGradient {
// No need to assign 0 to startX and startY, because 0 is default
endX: 0.0
endY: 1.0
stops: [
Stop {
color: Color.web("0xAEBBCC")
offset: 0.0
},
Stop {
color: Color.web("0x6D84A3")
offset: 1.0
}
]
}
},
Text {
layoutX: 65
layoutY: 12
textOrigin: TextOrigin.TOP
fill: Color.WHITE
content: "Audio Configuration"
font: Font.font("SansSerif", FontWeight.BOLD, 20)
},
Rectangle {
x: 0 // 0 is default, so assigning here just for clarity
y: 43
width: 320
height: 300
fill: Color.rgb(199, 206, 213)
},
Rectangle {
x: 9
y: 54
width: 300
height: 130
arcWidth: 20
arcHeight: 20
fill: Color.WHITE
stroke: Color.color(0.66, 0.67, 0.69)
},
Text {
layoutX: 18
layoutY: 69
textOrigin: TextOrigin.TOP
fill: Color.web("0x131021")
content: bind "{%1.0f acModel.selectedDecibels} dB"
font: Font.font("SansSerif", FontWeight.BOLD, 18)
},
Slider {
layoutX: 135
layoutY: 69
width: 162
disable: bind acModel.muting
min: bind acModel.minDecibels
max: bind acModel.maxDecibels
value: bind acModel.selectedDecibels with inverse
},
Line {
startX: 9
startY: 97
endX: 309
endY: 97
stroke: Color.color(0.66, 0.67, 0.69)
},
Text {
layoutX: 18
layoutY: 113
textOrigin: TextOrigin.TOP
fill: Color.web("0x131021")
content: "Muting"
font: Font.font("SansSerif", FontWeight.BOLD, 18)
},
CheckBox {
layoutX: 280
layoutY: 113
selected: bind acModel.muting with inverse
},
Line {
startX: 9
startY: 141
endX: 309
endY: 141
stroke: Color.color(0.66, 0.67, 0.69)
},
Text {
layoutX: 18
layoutY: 157
textOrigin: TextOrigin.TOP
fill: Color.web("0x131021")
content: "Genre"
font: Font.font("SansSerif", FontWeight.BOLD, 18)
},
SwingComboBox {
layoutX: 204
layoutY: 148
width: 93
items: bind for (genre in acModel.genres) {
SwingComboBoxItem {
text: genre
}
}
selectedIndex: bind acModel.selectedGenreIndex with inverse
}
]
}
}

0 개의 댓글: