66import javafx .geometry .Insets ;
77import javafx .geometry .Pos ;
88import javafx .geometry .VPos ;
9+ import javafx .scene .effect .BlendMode ;
910import javafx .scene .layout .*;
10- import javafx .scene .paint .Color ;
11- import javafx .scene .paint .CycleMethod ;
12- import javafx .scene .paint .LinearGradient ;
13- import javafx .scene .paint .Stop ;
11+ import javafx .scene .paint .*;
1412import javafx .scene .text .Font ;
1513
1614import java .util .ArrayList ;
1715import java .util .List ;
1816
19- public class SpectralView extends GridPane {
17+ public class SpectralView extends HBox {
2018 private final List <FrequencyView > frequencyViewList = new ArrayList <>();
2119 private final Color backgroundColor = Color .TRANSPARENT ;
2220 private final Background background = new Background (new BackgroundFill (backgroundColor , CornerRadii .EMPTY , Insets .EMPTY ));
@@ -46,10 +44,6 @@ public void configure() {
4644 CornerRadii .EMPTY , new BorderWidths (1 ), Insets .EMPTY )));
4745 }
4846
49- RowConstraints rowConstraintsAmplitudes = new RowConstraints ();
50- rowConstraintsAmplitudes .setVgrow (Priority .NEVER );
51- this .getRowConstraints ().add (rowConstraintsAmplitudes );
52-
5347 this .heightProperty ().addListener ((observable , oldValue , newValue ) -> {
5448 AppConfig .maxBarHeight = newValue .intValue () - AppConfig .hzLabelHeight ;
5549 });
@@ -79,9 +73,9 @@ public void updateState(List<FrequencyBar> frequencyBarList) {
7973 }
8074
8175 private void updateBars (List <FrequencyBar > frequencyBarList ) {
82- this .setHgap (AppConfig .barGap );
76+ this .setSpacing (AppConfig .barGap );
8377
84- double rectangleWidth = (this .getWidth () / (frequencyViewList .size () + 1 ) - AppConfig .barGap );
78+ double rectangleWidth = (this .getWidth () / (frequencyViewList .size ()) - ( AppConfig .barGap * 2 ) );
8579
8680 for (int i = 0 ; i < frequencyViewList .size (); i ++) {
8781 FrequencyView frequencyView = frequencyViewList .get (i );
@@ -102,6 +96,7 @@ private void updateBars(List<FrequencyBar> frequencyBarList) {
10296 frequencyView .getShadow ().setWidth (rectangleWidth );
10397 } else {
10498 frequencyView .getShadow ().setHeight (0 );
99+ frequencyView .getShadow ().setWidth (rectangleWidth );
105100 }
106101
107102 frequencyView .getRectangle ().setFill (frequencyBar .getColor ());
@@ -125,17 +120,14 @@ private void createBars(List<FrequencyBar> frequencyBarList) {
125120
126121 VBox amplitudeVBox = new VBox ();
127122 amplitudeVBox .setAlignment (Pos .BOTTOM_CENTER );
123+ amplitudeVBox .setSpacing (-2 );
128124 amplitudeVBox .getChildren ().add (frequencyView .getShadow ());
129125 amplitudeVBox .getChildren ().add (frequencyView .getRectangle ());
130- this . add (amplitudeVBox , i , 0 );
126+ amplitudeVBox . getChildren (). add (frequencyView . getHzLabel () );
131127
132- VBox hzVBox = new VBox ();
133- hzVBox .setAlignment (Pos .BOTTOM_CENTER );
134- hzVBox .getChildren ().add (frequencyView .getHzLabel ());
135- this .add (hzVBox , i , 1 );
128+ this .getChildren ().add (amplitudeVBox );
136129
137- GridPane .setValignment (frequencyView .getRectangle (), VPos .BOTTOM );
138- GridPane .setHalignment (frequencyView .getHzLabel (), HPos .CENTER );
130+ HBox .setMargin (this , Insets .EMPTY );
139131 }
140132 }
141133}
0 commit comments