Skip to content

Commit 3607f0f

Browse files
committed
Update UILoader.
1 parent 1a3d2f5 commit 3607f0f

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

sierra/src/main/java/org/httprpc/sierra/UILoader.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ void declareAttributeList(String tag, Class<?> type, Writer writer) throws IOExc
295295
private Map<String, Field> fields = new HashMap<>();
296296
private Map<String, ButtonGroup> groups = new HashMap<>();
297297

298+
private Map<String, Icon> icons = new HashMap<>();
299+
private Map<String, Image> images = new HashMap<>();
300+
298301
private Deque<JComponent> components = new LinkedList<>();
299302

300303
private JComponent root = null;
@@ -338,7 +341,6 @@ void declareAttributeList(String tag, Class<?> type, Writer writer) throws IOExc
338341
private static final String REVERT = "revert";
339342
private static final String PERSIST = "persist";
340343

341-
342344
private static Map<String, Class<?>> types = new HashMap<>();
343345
private static Map<String, Supplier<? extends JComponent>> suppliers = new HashMap<>();
344346

@@ -752,19 +754,23 @@ private String getText(String value) {
752754
}
753755

754756
private Icon getIcon(String value) {
755-
if (value.endsWith(".svg")) {
756-
return new FlatSVGIcon(owner.getClass().getResource(value));
757-
} else {
758-
throw new UnsupportedOperationException("Unsupported icon type.");
759-
}
757+
return icons.computeIfAbsent(value, key -> {
758+
if (value.endsWith(".svg")) {
759+
return new FlatSVGIcon(owner.getClass().getResource(value));
760+
} else {
761+
throw new UnsupportedOperationException("Unsupported icon type.");
762+
}
763+
});
760764
}
761765

762766
private Image getImage(String value) {
763-
try {
764-
return ImageIO.read(owner.getClass().getResource(value));
765-
} catch (IOException exception) {
766-
throw new UnsupportedOperationException(exception);
767-
}
767+
return images.computeIfAbsent(value, key -> {
768+
try {
769+
return ImageIO.read(owner.getClass().getResource(value));
770+
} catch (IOException exception) {
771+
throw new UnsupportedOperationException(exception);
772+
}
773+
});
768774
}
769775

770776
private void processEndElement() {

0 commit comments

Comments
 (0)