Skip to content

Commit b5e47eb

Browse files
committed
Refactor icon classes hierarchy
1 parent 136fc89 commit b5e47eb

17 files changed

Lines changed: 111 additions & 60 deletions

File tree

shellfx-core/src/main/java/com/techsenger/shellfx/core/menu/manager/IconUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
package com.techsenger.shellfx.core.menu.manager;
1818

1919
import com.techsenger.shellfx.material.icon.FontIconView;
20-
import com.techsenger.shellfx.material.icon.GenericFontIcon;
21-
import com.techsenger.shellfx.material.icon.GenericImageIcon;
2220
import com.techsenger.shellfx.material.icon.Icon;
2321
import com.techsenger.shellfx.material.icon.IconViewBox;
2422
import com.techsenger.shellfx.material.icon.ImageIconView;
2523
import javafx.scene.control.MenuItem;
24+
import com.techsenger.shellfx.material.icon.FontIcon;
25+
import com.techsenger.shellfx.material.icon.ImageIcon;
2626

2727
/**
2828
*
@@ -36,9 +36,9 @@ static void setIcon(MenuItem item, Icon<?> icon) {
3636
return;
3737
}
3838
if (graphic instanceof ImageIconView view) {
39-
view.setIcon((GenericImageIcon<?>) icon);
39+
view.setIcon((ImageIcon<?>) icon);
4040
} else if (graphic instanceof FontIconView view) {
41-
view.setIcon((GenericFontIcon<?>) icon);
41+
view.setIcon((FontIcon<?>) icon);
4242
} else if (graphic instanceof IconViewBox box) {
4343
box.setIcon(icon);
4444
}

shellfx-demo/src/main/java/com/techsenger/shellfx/demo/browser/BrowserMainTabFxView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.techsenger.shellfx.layout.dockhost.DockHostFxView;
2424
import com.techsenger.shellfx.layout.dockhost.TabDockFxView;
2525
import com.techsenger.shellfx.layout.dockhost.UtilityDockContainerFxView;
26-
import com.techsenger.shellfx.material.icon.FontIcon;
26+
import com.techsenger.shellfx.material.icon.PlainFontIcon;
2727
import com.techsenger.shellfx.material.icon.FontIconView;
2828
import com.techsenger.shellfx.material.style.StyleClasses;
2929
import javafx.geometry.Insets;
@@ -102,9 +102,9 @@ protected Composer createComposer() {
102102
@Override
103103
protected void build() {
104104
super.build();
105-
var removeButton = new Button(null, new FontIconView(new FontIcon(983924)));
105+
var removeButton = new Button(null, new FontIconView(new PlainFontIcon(983924)));
106106
removeButton.getStyleClass().addAll(StyleClasses.ICON_BUTTON, StyleClasses.SIZE_L);
107-
var addButton = new Button(null, new FontIconView(new FontIcon(984085)));
107+
var addButton = new Button(null, new FontIconView(new PlainFontIcon(984085)));
108108
addButton.getStyleClass().addAll(StyleClasses.ICON_BUTTON, StyleClasses.SIZE_L);
109109
addButton.setOnAction((e) -> {
110110
removeButton.setVisible(!removeButton.isVisible());

shellfx-demo/src/main/java/com/techsenger/shellfx/demo/settings/SettingsDialogPresenter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.techsenger.shellfx.core.settings.AppearanceSettings;
2424
import com.techsenger.shellfx.core.settings.Density;
2525
import com.techsenger.shellfx.demo.DemoComponents;
26-
import com.techsenger.shellfx.material.icon.FontIcon;
26+
import com.techsenger.shellfx.material.icon.PlainFontIcon;
2727
import com.techsenger.shellfx.material.theme.Theme;
2828
import java.util.function.Consumer;
2929

@@ -66,7 +66,7 @@ public void prepareToClose(Consumer<ClosePreparationResult> resultCallback) {
6666
protected void postInitialize() {
6767
super.postInitialize();
6868
setTitle("Settings");
69-
setIcon(new FontIcon(0xF08BB));
69+
setIcon(new PlainFontIcon(0xF08BB));
7070
setWidth(500);
7171
setResizable(false);
7272
setSelectedTheme(settings.getTheme());

shellfx-dialogs/src/main/java/com/techsenger/shellfx/dialogs/file/FileChooserDialogFxView.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import com.techsenger.shellfx.dialogs.style.DialogIcons;
2828
import com.techsenger.shellfx.material.button.ResultButton;
2929
import com.techsenger.shellfx.material.icon.FontIconView;
30-
import com.techsenger.shellfx.material.icon.GenericFontIcon;
3130
import com.techsenger.shellfx.material.list.TextFieldColumnListCell;
3231
import com.techsenger.shellfx.material.style.Spacing;
3332
import com.techsenger.shellfx.material.style.StyleClasses;
@@ -69,6 +68,7 @@
6968
import javafx.scene.layout.Region;
7069
import javafx.scene.layout.VBox;
7170
import javafx.util.StringConverter;
71+
import com.techsenger.shellfx.material.icon.FontIcon;
7272

7373
/**
7474
* There two modes - details and list. As both modes require sorting we use table and its sorting in both modes. But
@@ -227,7 +227,7 @@ protected void updateItem(T item, boolean empty) {
227227

228228
private AppearanceSettings settings;
229229

230-
private Function<T, GenericFontIcon<?>> iconProvider =
230+
private Function<T, FontIcon<?>> iconProvider =
231231
(f) -> f.isDirectory() ? DialogIcons.DIRECTORY : DialogIcons.FILE;
232232

233233
public FileChooserDialogFxView() {
@@ -359,11 +359,11 @@ public void setExtensionFilter(ExtensionFilter filter) {
359359
this.filterComboBox.getSelectionModel().select(filter);
360360
}
361361

362-
public Function<T, GenericFontIcon<?>> getIconProvider() {
362+
public Function<T, FontIcon<?>> getIconProvider() {
363363
return iconProvider;
364364
}
365365

366-
public void setIconProvider(Function<T, GenericFontIcon<?>> iconProvider) {
366+
public void setIconProvider(Function<T, FontIcon<?>> iconProvider) {
367367
this.iconProvider = iconProvider;
368368
}
369369

shellfx-material/src/main/java/com/techsenger/shellfx/material/icon/GenericImageIcon.java renamed to shellfx-material/src/main/java/com/techsenger/shellfx/material/icon/AbstractFontIcon.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*
2121
* @author Pavel Castornii
2222
*/
23-
public interface GenericImageIcon<T> extends Icon<T> {
23+
public abstract class AbstractFontIcon<T> extends AbstractIcon<T> implements FontIcon<T> {
2424

25+
public AbstractFontIcon(T content) {
26+
super(content);
27+
}
2528
}

shellfx-material/src/main/java/com/techsenger/shellfx/material/icon/AbstractIcon.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
*
2121
* @author Pavel Castornii
2222
*/
23-
abstract class AbstractIcon<T> implements Icon<T> {
23+
public abstract class AbstractIcon<T> implements Icon<T> {
2424

2525
private final T content;
2626

27-
AbstractIcon(T content) {
27+
public AbstractIcon(T content) {
2828
this.content = content;
2929
}
3030

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2024-2026 Pavel Castornii.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.techsenger.shellfx.material.icon;
18+
19+
/**
20+
*
21+
* @author Pavel Castornii
22+
*/
23+
public abstract class AbstractImageIcon<T> extends AbstractIcon<T> implements ImageIcon<T> {
24+
25+
public AbstractImageIcon(T content) {
26+
super(content);
27+
}
28+
}

shellfx-material/src/main/java/com/techsenger/shellfx/material/icon/FontIcon.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@
1717
package com.techsenger.shellfx.material.icon;
1818

1919
/**
20-
* Font icon has either a codePoint or styleClass. This icon will be displayed in {@link FontIconView}.
2120
*
2221
* @author Pavel Castornii
2322
*/
24-
public final class FontIcon extends AbstractIcon<Integer> implements GenericFontIcon<Integer> {
23+
public interface FontIcon<T> extends Icon<T> {
2524

26-
public FontIcon(Integer content) {
27-
super(content);
28-
}
2925
}

shellfx-material/src/main/java/com/techsenger/shellfx/material/icon/FontIconView.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ private static final class Css {
5757
private final StyleableIntegerProperty codePoint =
5858
new SimpleStyleableIntegerProperty(Css.CODE_POINT, this, "codePoint");
5959

60-
private final ObjectProperty<GenericFontIcon<?>> icon = new SimpleObjectProperty<>();
60+
private final ObjectProperty<FontIcon<?>> icon = new SimpleObjectProperty<>();
6161

62-
public FontIconView(GenericFontIcon<?> icon) {
62+
public FontIconView(FontIcon<?> icon) {
6363
this();
6464
setIcon(icon);
6565
}
@@ -76,19 +76,17 @@ public FontIconView() {
7676
});
7777
this.icon.addListener((ov, oldV, newV) -> {
7878
if (oldV != null) {
79-
if (oldV instanceof StyleFontIcon) {
80-
var i = (StyleFontIcon) oldV;
81-
getStyleClass().remove(i.getContent());
79+
if (oldV instanceof StyleFontIcon sfi) {
80+
getStyleClass().remove(sfi.getContent());
8281
} else {
8382
setCodePoint(0);
8483
}
8584
}
8685
if (newV != null) {
87-
if (newV instanceof StyleFontIcon) {
88-
var i = (StyleFontIcon) newV;
89-
getStyleClass().add(i.getContent());
86+
if (newV instanceof StyleFontIcon sfi) {
87+
getStyleClass().add(sfi.getContent());
9088
} else {
91-
var i = (FontIcon) newV;
89+
var i = (PlainFontIcon) newV;
9290
setCodePoint(i.getContent());
9391
}
9492
}
@@ -112,15 +110,15 @@ public void setCodePoint(int codePoint) {
112110
this.codePoint.set(codePoint);
113111
}
114112

115-
public ObjectProperty<GenericFontIcon<?>> iconProperty() {
113+
public ObjectProperty<FontIcon<?>> iconProperty() {
116114
return this.icon;
117115
}
118116

119-
public GenericFontIcon<?> getIcon() {
117+
public FontIcon<?> getIcon() {
120118
return this.icon.get();
121119
}
122120

123-
public void setIcon(GenericFontIcon<?> icon) {
121+
public void setIcon(FontIcon<?> icon) {
124122
this.icon.set(icon);
125123
}
126124
}

shellfx-material/src/main/java/com/techsenger/shellfx/material/icon/IconViewBox.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ public IconViewBox(Icon<?> i) {
4646
icon.addListener((ov, oldV, newV) -> {
4747
getChildren().clear();
4848
if (newV != null) {
49-
if (newV instanceof GenericFontIcon) {
50-
var view = new FontIconView((GenericFontIcon) newV);
49+
if (newV instanceof FontIcon fi) {
50+
var view = new FontIconView(fi);
5151
getChildren().add(view);
52-
} else if (newV instanceof GenericImageIcon) {
53-
var view = new ImageIconView((GenericImageIcon) newV);
52+
} else if (newV instanceof ImageIcon ii) {
53+
var view = new ImageIconView(ii);
5454
getChildren().add(view);
5555
} else {
5656
throw new AssertionError();

0 commit comments

Comments
 (0)