-
Notifications
You must be signed in to change notification settings - Fork 6
/
StageActivity.java
340 lines (305 loc) · 12.5 KB
/
StageActivity.java
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
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package potplayer;
import java.io.File;
import java.util.List;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Rectangle2D;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
import javafx.scene.control.Slider;
import javafx.scene.effect.ColorAdjust;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.layout.CornerRadii;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.stage.FileChooser;
import javafx.stage.Modality;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.WindowEvent;
import potplayer.PlayList;
import java.util.Map;
import potplayer.DisplayAreaSize;
import potplayer.PotPlayerConsts;
import potplayer.StageMaxMin;
public class StageActivity {
private double mouseX = 0.0;
private double mouseY = 0.0;
private double stageX = 0.0;
private double stageY = 0.0;
private boolean onAbove = false;
private boolean onBottom = false;
private boolean onLeft = false;
private boolean onRight = false;
private boolean onLAbove = false;
private boolean onLBottom = false;
private boolean onRAbove = false;
private boolean onRbottom = false;
private boolean stageResize = false;
public void adsorption(Stage beMoveStage) {
Map<String, Double> screen = DisplayAreaSize.screenSize();
double screenWidth = screen.get("width");
double screenHeight = screen.get("height");
double x = beMoveStage.getX();
double y = beMoveStage.getY();
double w = beMoveStage.getWidth();
double h = beMoveStage.getHeight();
final int adsorptionRange = PotPlayerConsts.ADSORPTION_RANGE;
int missionBoard = DisplayAreaSize.missionBoarHeight();
if ((y > 0) && (y < adsorptionRange)) {
// adsorption above
beMoveStage.setY(0);
}
if (((y + h) > (screenHeight - missionBoard - adsorptionRange)) && ((y + h) < (screenHeight - missionBoard))) {
// adsorption mission board above
beMoveStage.setY((screenHeight - missionBoard) - h);
}
if (((y + h) > (screenHeight - missionBoard + adsorptionRange)) && ((y + h) < screenHeight)) {
// adsorption bottom
beMoveStage.setY(screenHeight - h);
}
if ((x > 0) && (x < adsorptionRange)) {
// adsorption left
beMoveStage.setX(0);
}
if (((x + w) > (screenWidth - adsorptionRange)) && ((x + w) < screenWidth)) {
// adsorption right
beMoveStage.setX(screenWidth - w);
}
}
public void stageMove(Stage beMoveStage, Scene bePressedScene) {
// mouse pressed handle
bePressedScene.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
// sava when mouse click, mouse and stage on screen coordinate
mouseX = event.getScreenX();
mouseY = event.getScreenY();
stageX = beMoveStage.getX();
stageY = beMoveStage.getY();
StageMaxMin.saveDraggedMaxBeforeSize(beMoveStage.getX(), beMoveStage.getY(),
beMoveStage.getWidth(), beMoveStage.getHeight());
}
});
// mouse dragged handle
bePressedScene.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
if (stageResize == false) {
beMoveStage.setX(stageX + (event.getScreenX() - mouseX));
beMoveStage.setY(stageY + (event.getScreenY() - mouseY));
// System.out.println("Scene mouse pressed and move");
adsorption(beMoveStage);
PlayList.renewPlayListSize(beMoveStage.getX(), beMoveStage.getY(),
beMoveStage.getWidth(), beMoveStage.getHeight());
StageMaxMin.draggedMax(beMoveStage, event);
StageMaxMin.draggedMin(beMoveStage, event);
}
}
});
}
public void stageCloseAction(Stage beCloseStage) {
beCloseStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
System.out.println("Stage closed");
}
});
}
// VBox or Pane, because VBox is part of Pane
public void stageSizeChange(VBox vBox) {
vBox.heightProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("VBox height change" + newValue);
}
});
vBox.widthProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
System.out.println("VBox width change" + newValue);
}
});
}
// VBox or Pane, because VBox is part of Pane
public void stageResize(Stage stage, VBox vBox) {
vBox.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
double cursorX = event.getSceneX();
double cursorY = event.getSceneY();
double width = stage.getWidth();
double height = stage.getHeight();
Cursor cursorType = Cursor.DEFAULT;
final int resizeRange = 6;
/**
* Cursor Type
* Cursor.E_RESIZE, Cursor.W_RESIZE
* Cursor.S_RESIZE, Cursor.N_RESIZE
*
* Cursor.NE_RESIZE, Cursor.SE_RESIZE
* Cursor.NW_RESIZE, Cursor.SW_RESIZE
*
* Cursor.H_RESIZE, Cursor.V_RESIZE
*/
if (cursorX >= (width - resizeRange)) {
if (cursorY >= (height - resizeRange)) {
cursorType = Cursor.SE_RESIZE;
onRbottom = true;
} else if (cursorY <= resizeRange) {
cursorType = Cursor.NE_RESIZE;
onRAbove = true;
} else {
cursorType = Cursor.E_RESIZE;
onRight = true;
}
} else if (cursorX <= resizeRange) {
if (cursorY >= (height - resizeRange)) {
cursorType = Cursor.SW_RESIZE;
onLBottom = true;
} else if (cursorY <= resizeRange) {
cursorType = Cursor.NW_RESIZE;
onLAbove = true;
} else {
cursorType = Cursor.W_RESIZE;
onLeft = true;
}
} else if (cursorY <= resizeRange) {
cursorType = Cursor.N_RESIZE;
onAbove = true;
} else if (cursorY >= (height - resizeRange)) {
cursorType = Cursor.S_RESIZE;
onBottom = true;
}
vBox.setCursor(cursorType);
}
});
vBox.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
double mouseX = event.getScreenX();
double mouseY = event.getScreenY();
double cursorX = event.getSceneX();
double cursorY = event.getSceneY();
double stageX = stage.getX();
double stageY = stage.getY();
double stageWidth = stage.getWidth();
double stageHeight = stage.getHeight();
if (onAbove) {
stageResize = true;
stage.setY(mouseY);
if ((stageHeight - cursorY) <= PotPlayerConsts.PLAYER_MIN_H) {
stageHeight = PotPlayerConsts.PLAYER_MIN_H;
cursorY = 0;
}
stage.setHeight(stageHeight - cursorY);
}
if (onBottom) {
stageResize = true;
stageHeight = cursorY;
if (stageHeight <= PotPlayerConsts.PLAYER_MIN_H)
stageHeight = PotPlayerConsts.PLAYER_MIN_H;
stage.setHeight(stageHeight);
}
if (onLeft) {
stageResize = true;
stage.setX(mouseX);
if ((stageWidth - cursorX) <= PotPlayerConsts.PLAYER_MIN_W) {
stageWidth = PotPlayerConsts.PLAYER_MIN_W;
cursorX = 0;
}
stage.setWidth(stageWidth - cursorX);
}
if (onRight) {
stageResize = true;
stageWidth = cursorX;
if (stageWidth <= PotPlayerConsts.PLAYER_MIN_W)
stageWidth = PotPlayerConsts.PLAYER_MIN_W;
stage.setWidth(stageWidth);
}
if (onLAbove) {
stageResize = true;
stage.setX(mouseX);
stage.setY(mouseY);
if ((stageWidth - cursorX) <= PotPlayerConsts.PLAYER_MIN_W) {
stageWidth = PotPlayerConsts.PLAYER_MIN_W;
cursorX = 0;
}
if ((stageHeight - cursorY) <= PotPlayerConsts.PLAYER_MIN_H) {
stageHeight = PotPlayerConsts.PLAYER_MIN_H;
cursorY = 0;
}
stage.setWidth(stageWidth - cursorX);
stage.setHeight(stageHeight - cursorY);
}
if (onLBottom) {
stageResize = true;
stage.setX(mouseX);
stage.setWidth(stageWidth - cursorX);
stage.setHeight(cursorY);
}
if (onRAbove) {
stageResize = true;
stage.setY(mouseY);
stage.setWidth(cursorX);
stage.setHeight(stageHeight - cursorY);
}
if (onRbottom) {
stageResize = true;
stage.setWidth(cursorX);
stage.setHeight(cursorY);
}
PlayList.renewPlayListSize(stage.getX(), stage.getY(),
stage.getWidth(), stage.getHeight());
}
});
vBox.setOnMouseMoved(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
onAbove = false;
onBottom = false;
onLeft = false;
onRight = false;
onLAbove = false;
onLBottom = false;
onRAbove = false;
onRbottom = false;
stageResize = false;
Cursor cursorType = Cursor.DEFAULT;
vBox.setCursor(cursorType);
}
});
}
}