-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyButton.java
More file actions
260 lines (213 loc) · 8.58 KB
/
Copy pathMyButton.java
File metadata and controls
260 lines (213 loc) · 8.58 KB
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
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import javax.script.Bindings;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.sun.glass.ui.CommonDialogs.ExtensionFilter;
import javafx.application.Application;
import javafx.scene.*;
import javafx.scene.control.ToggleButton;
import javafx.scene.effect.GaussianBlur;
import javafx.scene.effect.Glow;
import javafx.scene.layout.StackPaneBuilder;
import javafx.stage.Stage;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.Scene;
import javafx.scene.layout.GridPane;
import javafx.scene.control.Button;
import javafx.stage.FileChooser;
import javafx.stage.DirectoryChooser;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
* @author zizhao zhang ,Yijing Li
* @pid: A92121287, A99108545
* @compile: javac MyButton.java
* @run: java Button
* MyButton class includes all the methods initialized and all the actions
* triggered by the buttons:
* upload:
*
* the button allows users to choose a picture image file within
* the local library,where contains all the proper sized images.and
* display the image onto the screen on the "phone"; once the image
* is uploaded successfully, the image should be blurred,fuzzy,and
* unclear so that users are unable to visualize the desired pictures
* at first
*
* edit:
*
* the button is designed to let the users to visualize the images more
* clear and direct by hitting the button edit, the users can adjust
* the position of the image around to the best visual position by
* dragging the mouse to pull the picture on the phone screen,
* meanwhile, hitting the edit button, the color of the images become
* more and more clear and brighter immediately as the more times users
* hitting the button edit.
*
* like:
*
* the button allows users to show interest to the image shown on the screen
* if the button like is hit, the blurriness of the pictures will be eased
* and decrease; picture becomes more and more clear
*
*
* dislike:
*
* the button dislike allows to show dislike to the image shown on the
* screen; if the button is hit, the blurriness of the pictures will be
* increased; picture becomes more and more blurred
*
*/
//method extends from button class
public class MyButton extends Button {
//integers to classify the functions of the buttons
public static final int BUTTON_UPLOAD = 0;
public static final int BUTTON_LIKE = 1;
public static final int BUTTON_DISLIKE = 2;
public static final int BUTTON_EDIT = 3;
//declared as global variable for the use of parameter
private Image buttonImg;//pictures passes into the button
private int buttonFunction;//switch case number identifier
//integer that counts the number of likes for tracking
private static int counterLike = 0;
private static int BlurrIndex=5;// the default index of the blurry filter
private static double filterIndex= 2.0;//the initial index for the filter
private static int midWidth = 4;//midsize of the width of the scene
private static int midHeight=4;//midsize of the height of the scene
/**
* create the buttons
* passes into the image for the buttons
* classify the functions for the buttons
* @param Image buttonImg: The images passes into the buttons
* @param int buttonFunction: the integer for classifying the functions
* @param likeNshow mainController: the parameter referring back to
* the main method.
*/
public MyButton(Image buttonImg, int buttonFunction,
likeNshow mainController){
super();//call super constructor
this.buttonImg= buttonImg;//passes in the image
this.buttonFunction = buttonFunction;
//assign the graphics to the button
this.setGraphic(new ImageView(buttonImg));
//mouse event handler for the functions of uploading
//and displaying the images
this.setOnMouseClicked(new EventHandler<MouseEvent>(){
@Override
public void handle(MouseEvent event) {
switch(buttonFunction){
//case 1: upload
case MyButton.BUTTON_UPLOAD:
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("select an image");
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("All Images", "*.*"),
new FileChooser.ExtensionFilter("JPG", "*.jpg"),
new FileChooser.ExtensionFilter("GIF", "*.gif"),
new FileChooser.ExtensionFilter("BMP", "*.bmp"),
new FileChooser.ExtensionFilter("PNG", "*.png")
);
//filtering the type of the file selected
//restriction are all pictures
//local variable file
File file;
file = fileChooser.showOpenDialog(mainController.stage);
String filePath;
filePath= file.getPath();//opening the file
Image base;//setting images
base= new Image("file:"+filePath);
mainController.IM = new ImageView(base);
mainController.pane.add(mainController.IM,midWidth,midHeight);
//always places the image onto the middle of the phone
System.out.println(mainController.IM.fitHeightProperty());
System.out.println(mainController.IM.fitHeightProperty());
//applying the algorithm of gaussianblurr to make the
//image fuzzy
GaussianBlur gaussianBlur1 = new GaussianBlur();
//apply the blurry filter
mainController.IM.setEffect(gaussianBlur1);
break;
//case 2: like button
case MyButton.BUTTON_LIKE:
counterLike=counterLike - 1;
System.out.println(counterLike);//show the index of the counterlike
//manipulating the depth of the blurring filter
//more clicked more clear
GaussianBlur gaussianBlur = new GaussianBlur(BlurrIndex*counterLike);
mainController.IM.setEffect(gaussianBlur);
break;
//case 3: dislike button
case MyButton.BUTTON_DISLIKE:
counterLike=counterLike + 1;
System.out.println(counterLike);//show the index of the counterlike
//manipulating the depth of the blurring filter
//more clicked more blurred
GaussianBlur Blur = new GaussianBlur(BlurrIndex*counterLike);
mainController.IM.setEffect(Blur);
break;
//case 4: edit button
case MyButton.BUTTON_EDIT:
//apply the affect of glow filter
//as the clicking number goes up, the effect increases instantly
//the filter allows the user to adjust the depth of the color of the
//imageview
//the more times user click on the edit button,the brighter it is.
filterIndex= filterIndex-0.02 ;
mainController.IM.setEffect(new Glow(filterIndex));
//adding the onMouseDrag method into the function of edit for
//users to find the best position of placing the images
mainController.IM.setOnMousePressed(new EventHandler<MouseEvent>() {
public void handle(final MouseEvent mouseEvent) {
mainController.imgX = mouseEvent.getX();
mainController.imgY = mouseEvent.getY();
mainController.initTranslateX = mainController.IM.getTranslateX();
mainController.initTranslateY = mainController.IM.getTranslateY();
}
});
//matching the position of the imageview on the grind pane with
//the position of the mouse
mainController.IM.setOnMouseDragged(new EventHandler<MouseEvent>() {
public void handle(final MouseEvent mouseEvent) {
mainController.IM.setTranslateX(mainController.initTranslateX
+ mouseEvent.getX()- mainController.imgX);
mainController.IM.setTranslateY(mainController.initTranslateY
+ mouseEvent.getY()- mainController.imgY);
mainController.initTranslateX = mainController.IM.getTranslateX();
mainController.initTranslateY = mainController.IM.getTranslateY();
}
});
break;
}
}
});
}
}