diff options
| author | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-25 15:37:57 +0900 |
|---|---|---|
| committer | syeyoung <42869671+cyoung06@users.noreply.github.com> | 2020-11-25 15:37:57 +0900 |
| commit | 81a315f025f361d1155305e55dfee29308a74ed3 (patch) | |
| tree | 9be59a599ef9821ca9e66005207cee32022e5a4f /src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements | |
| parent | a49e2c1970f6f77079a860dd5e92741251f41c9c (diff) | |
| download | Skyblock-Dungeons-Guide-81a315f025f361d1155305e55dfee29308a74ed3.tar.gz Skyblock-Dungeons-Guide-81a315f025f361d1155305e55dfee29308a74ed3.tar.bz2 Skyblock-Dungeons-Guide-81a315f025f361d1155305e55dfee29308a74ed3.zip | |
room processor stuff
Diffstat (limited to 'src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements')
| -rw-r--r-- | src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MStringSelectionButton.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MStringSelectionButton.java b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MStringSelectionButton.java new file mode 100644 index 00000000..7e9e42cb --- /dev/null +++ b/src/main/java/kr/syeyoung/dungeonsguide/roomedit/elements/MStringSelectionButton.java @@ -0,0 +1,69 @@ +package kr.syeyoung.dungeonsguide.roomedit.elements; + +import kr.syeyoung.dungeonsguide.roomedit.MPanel; +import lombok.Getter; +import lombok.Setter; + +import java.awt.*; +import java.util.List; + +@Getter +@Setter +public class MStringSelectionButton extends MPanel { + + private List<String> possible; + private int selectedIndex; + + private MButton dec; + private MButton inc; + private MLabel selected; + + @Getter + @Setter + private Runnable onUpdate; + + public MStringSelectionButton(final List<String> possible) { + this.possible = possible; + selectedIndex = 0; + + dec = new MButton(); dec.setText("<"); add(dec); + inc = new MButton(); inc.setText(">"); add(inc); + selected = new MLabel(); updateSelected(); add(selected); + + dec.setOnActionPerformed(new Runnable() { + @Override + public void run() { + selectedIndex++; + if (selectedIndex >= possible.size()) selectedIndex = 0; + updateSelected(); + onUpdate.run(); + } + }); + inc.setOnActionPerformed(new Runnable() { + @Override + public void run() { + selectedIndex --; + if (selectedIndex < 0) selectedIndex = possible.size() - 1; + updateSelected(); + onUpdate.run(); + } + }); + } + + public String getSelected() { + if (possible.size() == 0) return null; + return possible.get(selectedIndex); + } + + private void updateSelected() { + if (possible.size() == 0) selected.setText("-Empty-"); + else selected.setText(possible.get(selectedIndex)); + } + + @Override + public void onBoundsUpdate() { + dec.setBounds(new Rectangle(0,0,bounds.height, bounds.height)); + inc.setBounds(new Rectangle(bounds.width - bounds.height, 0, bounds.height, bounds.height)); + selected.setBounds(new Rectangle(bounds.height, 0, bounds.width - bounds.height - bounds.height, bounds.height)); + } +} |
