Skip to content

Commit

Permalink
Fix for NPE on image list
Browse files Browse the repository at this point in the history
  • Loading branch information
cwisniew committed May 29, 2023
1 parent 85a1481 commit 66d9e36
Show file tree
Hide file tree
Showing 2 changed files with 1,396 additions and 738 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public class TokenBarController
ItemListener,
ChangeListener {

/** a bit of a hack to map i18n strings to values, but it works until we replace the dialog. */
private final Map<String, String> sidesMap = new HashMap<>();
/** a bit of a hack to map i18n strings to values, but it works until we replace the dialog. */
private final Map<String, String> typesMap = new HashMap<>();

/** Panel containing the campaign properties form panel */
private final AbeillePanel formPanel;

Expand Down Expand Up @@ -255,14 +260,18 @@ public TokenBarController(AbeillePanel panel) {
var typeComboBox = panel.getComboBox(TYPE);
typeComboBox.setModel(new DefaultComboBoxModel());
for (var type : types) {
typeComboBox.addItem(I18N.getText(type));
var i18n = I18N.getText(type);
typeComboBox.addItem(i18n);
typesMap.put(i18n, type);
}
typeComboBox.addActionListener(this);

var sideComboBox = panel.getComboBox(SIDE);
sideComboBox.setModel(new DefaultComboBoxModel());
for (var side : sides) {
var i18n = I18N.getText(side);
sideComboBox.addItem(I18N.getText(side));
sidesMap.put(i18n, side);
}

panel.getSpinner(THICKNESS).setModel(new SpinnerNumberModel(5, 2, 10, 1));
Expand All @@ -271,6 +280,7 @@ public TokenBarController(AbeillePanel panel) {
panel.getSpinner(OPACITY).setModel(new SpinnerNumberModel(100, 1, 100, 5));
panel.getList(BARS).setCellRenderer(renderer);
panel.getList(BARS).addListSelectionListener(this);
panel.getList(IMAGES).setModel(new DefaultListModel<MD5Key>());
panel.getList(IMAGES).setCellRenderer(new ImageListRenderer());
panel.getList(IMAGES).addListSelectionListener(this);
panel.getTextComponent(NAME).getDocument().addDocumentListener(this);
Expand Down Expand Up @@ -741,7 +751,8 @@ public BarTokenOverlay createTokenOverlay(BarTokenOverlay updatedOverlay) {
Side.valueOf(((String) formPanel.getComboBox(SIDE).getSelectedItem()).toUpperCase());

BarTokenOverlay to = null;
if (overlay.equals("SOLID_BAR")) {
String type = typesMap.get(overlay);
if (type.equals("SOLID_BAR")) {
to = new DrawnBarTokenOverlay(name, color, thickness);
} else if (overlay.equals("TWO_TONE_BAR")) {
to = new TwoToneBarTokenOverlay(name, color, bgColor, thickness);
Expand All @@ -754,11 +765,11 @@ public BarTokenOverlay createTokenOverlay(BarTokenOverlay updatedOverlay) {
model.copyInto(assetIds);

// Create the bars
if (overlay.equals("TWO_IMAGES_BAR")) {
if (type.equals("TWO_IMAGES_BAR")) {
to = new TwoImageBarTokenOverlay(name, assetIds[1], assetIds[0]);
} else if (overlay.equals("SINGLE_IMAGE_BAR")) {
} else if (type.equals("SINGLE_IMAGE_BAR")) {
to = new SingleImageBarTokenOverlay(name, assetIds[0]);
} else if (overlay.equals("MULTIPLE_IMAGES_BAR")) {
} else if (type.equals("MULTIPLE_IMAGES_BAR")) {
to = new MultipleImageBarTokenOverlay(name, assetIds);
} // endif
} // endif
Expand Down
Loading

0 comments on commit 66d9e36

Please sign in to comment.