Skip to content

Commit a10aaba

Browse files
committed
update last update.. before gradle update
1 parent fd5184a commit a10aaba

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

src/com/gn/GNAvatarView.java

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222
import javafx.beans.property.SimpleDoubleProperty;
2323
import javafx.beans.property.SimpleObjectProperty;
2424
import javafx.beans.value.ChangeListener;
25-
import javafx.beans.value.ObservableValue;
2625
import javafx.geometry.Bounds;
2726
import javafx.scene.image.Image;
28-
import javafx.scene.layout.Region;
27+
import javafx.scene.layout.*;
2928
import javafx.scene.paint.Color;
3029
import javafx.scene.paint.ImagePattern;
3130
import javafx.scene.paint.Paint;
@@ -41,31 +40,32 @@
4140
*
4241
*/
4342
@DefaultProperty("image")
43+
@SuppressWarnings("unused")
4444
public class GNAvatarView extends Region {
4545

46-
private double prefWidth = 200D;
47-
private double prefHeight = 200D;
46+
private final Circle circle = new Circle();
47+
private final Rectangle rectangle = new Rectangle();
4848

49-
private Circle circle = new Circle();
50-
private Rectangle rectangle = new Rectangle();
49+
private final ObjectProperty<Image> image = new SimpleObjectProperty<>(this, "image");
50+
private final ObjectProperty<ImagePattern> imagePattern = new SimpleObjectProperty<>(this, "imagePattern");
51+
private final ObjectProperty<AvatarType> type = new SimpleObjectProperty<>(this, "avatarType");
52+
private final ObjectProperty<Paint> stroke = new SimpleObjectProperty<>(this, "stroke");
53+
private final DoubleProperty strokeWidth = new SimpleDoubleProperty(this, "strokeWidth");
5154

52-
private ObjectProperty<Image> image = new SimpleObjectProperty<>(this, "image");
53-
private ObjectProperty<ImagePattern> imagePattern = new SimpleObjectProperty<>(this, "imagePattern");
54-
private ObjectProperty<AvatarType> type = new SimpleObjectProperty<>(this, "avatarType");
55-
private ObjectProperty<Paint> stroke = new SimpleObjectProperty<>(this, "stroke");
56-
private DoubleProperty strokeWidth = new SimpleDoubleProperty(this, "strokeWidth");
55+
private String nameImage;
56+
private String path;
5757

58-
private ChangeListener<Bounds> circleListener = (observable, oldValue, newValue) -> {
58+
private final ChangeListener<Bounds> circleListener = (observable, oldValue, newValue) -> {
5959
double width = newValue.getWidth() / 2;
6060
double height = newValue.getHeight() / 2;
61-
double size = width < height ? width : height;
61+
double size = Math.min(width, height);
6262

6363
circle.setRadius(size - (getStrokeWidth() / 2));
6464
circle.setCenterY(height);
6565
circle.setCenterX(width);
6666
};
6767

68-
private ChangeListener<Bounds> rectListener = (observable, oldValue, newValue) -> {
68+
private final ChangeListener<Bounds> rectListener = (observable, oldValue, newValue) -> {
6969
double width = newValue.getWidth() ;
7070
double height = newValue.getHeight();
7171

@@ -83,31 +83,47 @@ public class GNAvatarView extends Region {
8383
rectangle.setY( (newValue.getHeight() / 2) - (rectangle.getHeight() / 2));
8484
};
8585

86+
8687
public GNAvatarView() {
8788
this(null);
8889
}
8990

90-
public GNAvatarView(Image image){
91+
public GNAvatarView(String path){
92+
this(path, Region.USE_COMPUTED_SIZE, Region.USE_COMPUTED_SIZE);
93+
}
94+
95+
public GNAvatarView(double width, double height){
96+
this(null, width, height);
97+
}
98+
99+
public GNAvatarView(String path, double width, double height) {
100+
101+
this.getStyleClass().add("gn-avatar-view");
91102

92103
registerListeners();
93104
registerBinds();
94105

95-
setType(AvatarType.CIRCLE);
96-
setPrefSize(prefWidth, prefHeight);
106+
setType(AvatarType.RECT);
107+
setPrefSize(width, height);
97108

98109
setStrokeWidth(2);
99110
setStroke(Color.WHITE);
100111

101-
if(image != null) this.imagePattern.set(new ImagePattern(image));
112+
// this.setBorder(new Border(new BorderStroke(Color.RED, BorderStrokeStyle.DASHED, CornerRadii.EMPTY, BorderWidths.DEFAULT)));
113+
114+
if(path != null) this.imagePattern.set(new ImagePattern(new Image(path)));
102115
}
103116

104117
private void registerBinds(){
105118
circle.fillProperty().bind(imagePattern);
106119
circle.strokeProperty().bind(stroke);
107120
circle.strokeWidthProperty().bind(strokeWidth);
121+
108122
rectangle.fillProperty().bind(imagePattern);
109123
rectangle.strokeProperty().bind(stroke);
124+
double prefHeight = 200D;
110125
rectangle.setHeight(prefHeight);
126+
double prefWidth = 200D;
111127
rectangle.setWidth(prefWidth);
112128
rectangle.strokeWidthProperty().bind(strokeWidth);
113129
rectangle.setArcHeight(20D);

src/com/gn/Main.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ public class Main extends Application {
1313
public void start(Stage primaryStage) throws Exception{
1414
Image image = new Image(getClass().getResource("smile.jpg").toExternalForm());
1515
primaryStage.setTitle("Hello World");
16-
primaryStage.setScene(new Scene(new GNAvatarView(image), 300, 275));
16+
17+
GNAvatarView avatarView = new GNAvatarView("/com/gn/smile.jpg", 1000,300);
18+
// GNAvatarView avatarView = new GNAvatarView();
19+
// avatarView.setImage(new Image(getClass().getResource("/com/gn/SimpleLightGreen.jpg").toExternalForm()));
20+
21+
primaryStage.setScene(new Scene(avatarView));
1722
primaryStage.show();
1823
}
1924

0 commit comments

Comments
 (0)