forked from External/mage
Merge pull request #2846 from kubikrubikvkube/master
Singleton object should not have map with values that can't be GCed
This commit is contained in:
commit
20b24e3360
40 changed files with 289 additions and 263 deletions
|
|
@ -1443,7 +1443,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
((MagePane) component).changeGUISize();
|
||||
}
|
||||
}
|
||||
for (ChatPanelBasic chatPanel : getChatPanels().values()) {
|
||||
for (ChatPanelBasic chatPanel : CHATS.values()) {
|
||||
chatPanel.changeGUISize(GUISizeHelper.chatFont);
|
||||
}
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -1718,8 +1718,8 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
|
||||
private void updateCounts() {
|
||||
deckNameAndCountLabel.setText(role.getName() + " - " + allCards.size());
|
||||
creatureCountLabel.setText("" + creatureCounter.get());
|
||||
landCountLabel.setText("" + landCounter.get());
|
||||
creatureCountLabel.setText(String.valueOf(creatureCounter.get()));
|
||||
landCountLabel.setText(String.valueOf(landCounter.get()));
|
||||
for (CardType cardType : selectByTypeButtons.keySet()) {
|
||||
AbstractButton button = selectByTypeButtons.get(cardType);
|
||||
String text = cardType.toString();
|
||||
|
|
@ -2058,7 +2058,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
|||
if (stack.isEmpty()) {
|
||||
countLabel.setVisible(false);
|
||||
} else {
|
||||
countLabel.setText("" + stack.size());
|
||||
countLabel.setText(String.valueOf(stack.size()));
|
||||
countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - COUNT_LABEL_HEIGHT);
|
||||
countLabel.setSize(cardWidth, COUNT_LABEL_HEIGHT);
|
||||
countLabel.setVisible(true);
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ public class ChatPanelBasic extends javax.swing.JPanel {
|
|||
if (level.equals("0")) {
|
||||
return false;
|
||||
}
|
||||
message = "." + message + ".";
|
||||
message = '.' + message + '.';
|
||||
|
||||
message = message.toLowerCase();
|
||||
message = message.replaceAll("[a@]([s5][s5]+)", "axyx");
|
||||
|
|
@ -217,7 +217,7 @@ public class ChatPanelBasic extends javax.swing.JPanel {
|
|||
|
||||
if (level.equals("2")) {
|
||||
message = message.replaceAll("\\.", "");
|
||||
message = "." + message + ".";
|
||||
message = '.' + message + '.';
|
||||
matchPattern = profanity2Pattern.matcher(message);
|
||||
if (matchPattern.find()) {
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,9 @@ public class KeyBindButton extends JButton implements ActionListener {
|
|||
private void applyNewKeycode(int code) {
|
||||
preferences.getKeybindButtons().stream()
|
||||
.filter(b -> b != KeyBindButton.this)
|
||||
.filter(b -> b.getKeyCode() == code)
|
||||
.filter(b -> {
|
||||
return b.keyCode == code;
|
||||
})
|
||||
.forEach(b -> b.setKeyCode(0));
|
||||
|
||||
setKeyCode(code);
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ public class DialogManager extends JComponent implements MouseListener,
|
|||
synchronized (dialogManagers) {
|
||||
if (!dialogManagers.containsKey(gameId)) {
|
||||
DialogManager dialogManager = new DialogManager();
|
||||
dialogManager.setScreenWidth(768);
|
||||
dialogManager.setScreenHeight(1024);
|
||||
dialogManager.screen_width = 768;
|
||||
dialogManager.screen_height = 1024;
|
||||
dialogManager.setBounds(0, 0, 768, 1024);
|
||||
dialogManager.setVisible(false);
|
||||
dialogManagers.put(gameId, dialogManager);
|
||||
|
|
@ -96,8 +96,8 @@ public class DialogManager extends JComponent implements MouseListener,
|
|||
public static void updateParams(int width, int height, boolean isVisible) {
|
||||
synchronized (dialogManagers) {
|
||||
for (DialogManager dialogManager : dialogManagers.values()) {
|
||||
dialogManager.setScreenWidth(width);
|
||||
dialogManager.setScreenHeight(height);
|
||||
dialogManager.screen_width = width;
|
||||
dialogManager.screen_height = height;
|
||||
dialogManager.setBounds(0, 0, width, height);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,8 +141,7 @@ public class ChoiceDialog extends IDialogPanel {
|
|||
remove(toRemove.get(i));
|
||||
}
|
||||
|
||||
java.util.List<CardView> cardList = new ArrayList<CardView>();
|
||||
cardList.addAll(cards.values());
|
||||
java.util.List<CardView> cardList = new ArrayList<CardView>(cards.values());
|
||||
|
||||
int width = SettingsManager.getInstance().getCardSize().width;
|
||||
int height = SettingsManager.getInstance().getCardSize().height;
|
||||
|
|
|
|||
|
|
@ -346,7 +346,7 @@ public class DeckEditorPanel extends javax.swing.JPanel {
|
|||
if (card.getId().equals(cardView.getId())) {
|
||||
deck.getCards().remove(card);
|
||||
deck.getSideboard().add(card);
|
||||
cardSelector.loadSideboard(new ArrayList<>(deck.getSideboard()), getBigCard());
|
||||
cardSelector.loadSideboard(new ArrayList<>(deck.getSideboard()), this.bigCard);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -537,7 +537,7 @@ public class NewTournamentDialog extends MageDialog {
|
|||
tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
|
||||
if (tournamentType.isCubeBooster()) {
|
||||
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
|
||||
if (!(cubeFromDeckFilename.equals(""))) {
|
||||
if (!(cubeFromDeckFilename.isEmpty())) {
|
||||
Deck cubeFromDeck = new Deck();
|
||||
try {
|
||||
cubeFromDeck = Deck.load(DeckImporterUtil.importDeck(cubeFromDeckFilename), true, true);
|
||||
|
|
@ -828,8 +828,7 @@ public class NewTournamentDialog extends MageDialog {
|
|||
String randomPrefs = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TOURNAMENT_PACKS_RANDOM_DRAFT, "");
|
||||
if (!randomPrefs.isEmpty()) {
|
||||
txtRandomPacks.setText(randomPrefs);
|
||||
ArrayList<String> theList = new ArrayList<>();
|
||||
theList.addAll(Arrays.asList(randomPrefs.split(";")));
|
||||
ArrayList<String> theList = new ArrayList<>(Arrays.asList(randomPrefs.split(";")));
|
||||
randomPackSelector.setSelectedPacks(theList);
|
||||
} else {
|
||||
ExpansionInfo[] allExpansions = ExpansionRepository.instance.getWithBoostersSortedByReleaseDate();
|
||||
|
|
|
|||
|
|
@ -162,8 +162,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
if (s1 != s2) {
|
||||
changed = true;
|
||||
} else if (s1 > 0) {
|
||||
Set<UUID> attachmentIds = new HashSet<>();
|
||||
attachmentIds.addAll(permanent.getAttachments());
|
||||
Set<UUID> attachmentIds = new HashSet<>(permanent.getAttachments());
|
||||
for (MagePermanent magePermanent : oldMagePermanent.getLinks()) {
|
||||
if (!attachmentIds.contains(magePermanent.getOriginalPermanent().getId())) {
|
||||
// that means that the amount of attachments is the same
|
||||
|
|
|
|||
|
|
@ -533,7 +533,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
if (!SessionHandler.watchGame(gameId)) {
|
||||
removeGame();
|
||||
}
|
||||
for (PlayAreaPanel panel : getPlayers().values()) {
|
||||
for (PlayAreaPanel panel : players.values()) {
|
||||
panel.setPlayingMode(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -553,7 +553,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
if (!SessionHandler.startReplay(gameId)) {
|
||||
removeGame();
|
||||
}
|
||||
for (PlayAreaPanel panel : getPlayers().values()) {
|
||||
for (PlayAreaPanel panel : players.values()) {
|
||||
panel.setPlayingMode(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -815,7 +815,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
logger.warn(" uuid:" + player.getPlayerId());
|
||||
logger.warn(" players:");
|
||||
for (PlayAreaPanel p : players.values()) {
|
||||
logger.warn("" + p);
|
||||
logger.warn(String.valueOf(p));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ public class ButtonColumn extends AbstractCellEditor implements TableCellRendere
|
|||
if (table.getRowCount() > 0 && table.getRowCount() >= table.getEditingRow() && table.getEditingRow() >= 0) {
|
||||
int row = table.convertRowIndexToModel(table.getEditingRow());
|
||||
fireEditingStopped();
|
||||
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, "" + row);
|
||||
ActionEvent event = new ActionEvent(table, ActionEvent.ACTION_PERFORMED, String.valueOf(row));
|
||||
action.actionPerformed(event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,70 +68,70 @@ public class AudioManager {
|
|||
if (audioManager.nextPageClip == null) {
|
||||
audioManager.nextPageClip = new MageClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().nextPageClip);
|
||||
checkAndPlayClip(audioManager.nextPageClip);
|
||||
}
|
||||
|
||||
public static void playPrevPage() {
|
||||
if (audioManager.prevPageClip == null) {
|
||||
audioManager.prevPageClip = new MageClip(Constants.BASE_SOUND_PATH + "OnPrevPage.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().prevPageClip);
|
||||
checkAndPlayClip(audioManager.prevPageClip);
|
||||
}
|
||||
|
||||
public static void playAnotherTab() {
|
||||
if (audioManager.anotherTabClip == null) {
|
||||
audioManager.anotherTabClip = new MageClip(Constants.BASE_SOUND_PATH + "OnNextPage.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().anotherTabClip);
|
||||
checkAndPlayClip(audioManager.anotherTabClip);
|
||||
}
|
||||
|
||||
public static void playNextPhase() {
|
||||
if (audioManager.nextPhaseClip == null) {
|
||||
audioManager.nextPhaseClip = new MageClip(Constants.BASE_SOUND_PATH + "OnNextPhase.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().nextPhaseClip);
|
||||
checkAndPlayClip(audioManager.nextPhaseClip);
|
||||
}
|
||||
|
||||
public static void playEndTurn() {
|
||||
if (audioManager.endTurnClip == null) {
|
||||
audioManager.endTurnClip = new MageClip(Constants.BASE_SOUND_PATH + "OnEndTurn.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().endTurnClip);
|
||||
checkAndPlayClip(audioManager.endTurnClip);
|
||||
}
|
||||
|
||||
public static void playTapPermanent() {
|
||||
if (audioManager.tapPermanentClip == null) {
|
||||
audioManager.tapPermanentClip = new MageClip(Constants.BASE_SOUND_PATH + "OnTapPermanent.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().tapPermanentClip);
|
||||
checkAndPlayClip(audioManager.tapPermanentClip);
|
||||
}
|
||||
|
||||
public static void playSummon() {
|
||||
if (audioManager.summonClip == null) {
|
||||
audioManager.summonClip = new MageClip(Constants.BASE_SOUND_PATH + "OnSummon.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().summonClip);
|
||||
checkAndPlayClip(audioManager.summonClip);
|
||||
}
|
||||
|
||||
public static void playDiedCreature() {
|
||||
if (audioManager.diedCreatureClip == null) {
|
||||
audioManager.diedCreatureClip = new MageClip(Constants.BASE_SOUND_PATH + "OnSummon-.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().diedCreatureClip);
|
||||
checkAndPlayClip(audioManager.diedCreatureClip);
|
||||
}
|
||||
|
||||
public static void playDraw() {
|
||||
if (audioManager.drawClip == null) {
|
||||
audioManager.drawClip = new MageClip(Constants.BASE_SOUND_PATH + "OnDraw.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().drawClip);
|
||||
checkAndPlayClip(audioManager.drawClip);
|
||||
}
|
||||
|
||||
public static void playButtonOk() {
|
||||
if (audioManager.buttonOkClip == null) {
|
||||
audioManager.buttonOkClip = new MageClip(Constants.BASE_SOUND_PATH + "OnButtonOk.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().buttonOkClip);
|
||||
checkAndPlayClip(audioManager.buttonOkClip);
|
||||
}
|
||||
|
||||
public static void playButtonCancel() {
|
||||
|
|
@ -139,105 +139,105 @@ public class AudioManager {
|
|||
audioManager.buttonCancelClip = new MageClip(Constants.BASE_SOUND_PATH + "OnButtonCancel.wav", AudioGroup.SkipSounds);
|
||||
|
||||
}
|
||||
checkAndPlayClip(getManager().buttonCancelClip);
|
||||
checkAndPlayClip(audioManager.buttonCancelClip);
|
||||
}
|
||||
|
||||
public static void playAttack() {
|
||||
if (audioManager.attackClip == null) {
|
||||
audioManager.attackClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAttack.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().attackClip);
|
||||
checkAndPlayClip(audioManager.attackClip);
|
||||
}
|
||||
|
||||
public static void playBlock() {
|
||||
if (audioManager.blockClip == null) {
|
||||
audioManager.blockClip = new MageClip(Constants.BASE_SOUND_PATH + "OnBlock.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().blockClip);
|
||||
checkAndPlayClip(audioManager.blockClip);
|
||||
}
|
||||
|
||||
public static void playAddPermanent() {
|
||||
if (audioManager.addPermanentClip == null) {
|
||||
audioManager.addPermanentClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAddPermanent.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().addPermanentClip);
|
||||
checkAndPlayClip(audioManager.addPermanentClip);
|
||||
}
|
||||
|
||||
public static void playAddArtifact() {
|
||||
if (audioManager.addArtifactClip == null) {
|
||||
audioManager.addArtifactClip = new MageClip(Constants.BASE_SOUND_PATH + "OnAddArtifact.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().addArtifactClip);
|
||||
checkAndPlayClip(audioManager.addArtifactClip);
|
||||
}
|
||||
|
||||
public static void playStackNew() {
|
||||
if (audioManager.updateStackClip == null) {
|
||||
audioManager.updateStackClip = new MageClip(Constants.BASE_SOUND_PATH + "OnStackNew.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().updateStackClip);
|
||||
checkAndPlayClip(audioManager.updateStackClip);
|
||||
}
|
||||
|
||||
public static void playOnHover() {
|
||||
if (audioManager.onHover == null) {
|
||||
audioManager.onHover = new MageClip(Constants.BASE_SOUND_PATH + "OnHover.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().onHover);
|
||||
checkAndPlayClip(audioManager.onHover);
|
||||
}
|
||||
|
||||
public static void playOnCountdown1() {
|
||||
if (audioManager.onCountdown1 == null) {
|
||||
audioManager.onCountdown1 = new MageClip(Constants.BASE_SOUND_PATH + "OnCountdown1.wav", AudioGroup.DraftSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().onCountdown1);
|
||||
checkAndPlayClip(audioManager.onCountdown1);
|
||||
}
|
||||
|
||||
public static void playOnDraftSelect() {
|
||||
if (audioManager.onDraftSelect == null) {
|
||||
audioManager.onDraftSelect = new MageClip(Constants.BASE_SOUND_PATH + "OnDraftSelect.wav", AudioGroup.DraftSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().onDraftSelect);
|
||||
checkAndPlayClip(audioManager.onDraftSelect);
|
||||
}
|
||||
|
||||
public static void playOnSkipButton() {
|
||||
if (audioManager.onSkipButton == null) {
|
||||
audioManager.onSkipButton = new MageClip(Constants.BASE_SOUND_PATH + "OnSkipButton.wav", AudioGroup.SkipSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().onSkipButton);
|
||||
checkAndPlayClip(audioManager.onSkipButton);
|
||||
}
|
||||
|
||||
public static void playOnSkipButtonCancel() {
|
||||
if (audioManager.onSkipButtonCancel == null) {
|
||||
audioManager.onSkipButtonCancel = new MageClip(Constants.BASE_SOUND_PATH + "OnSkipButtonCancel.wav", AudioGroup.SkipSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().onSkipButtonCancel);
|
||||
checkAndPlayClip(audioManager.onSkipButtonCancel);
|
||||
}
|
||||
|
||||
public static void playPlayerJoinedTable() {
|
||||
if (audioManager.playerJoinedTable == null) {
|
||||
audioManager.playerJoinedTable = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerJoined.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerJoinedTable);
|
||||
checkAndPlayClip(audioManager.playerJoinedTable);
|
||||
}
|
||||
|
||||
public static void playYourGameStarted() {
|
||||
if (audioManager.yourGameStarted == null) {
|
||||
audioManager.yourGameStarted = new MageClip(Constants.BASE_SOUND_PATH + "OnGameStart.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().yourGameStarted);
|
||||
checkAndPlayClip(audioManager.yourGameStarted);
|
||||
}
|
||||
|
||||
public static void playTournamentStarted() {
|
||||
if (audioManager.tournamentStarted == null) {
|
||||
audioManager.tournamentStarted = new MageClip(Constants.BASE_SOUND_PATH + "OnTournamentStart.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().tournamentStarted);
|
||||
checkAndPlayClip(audioManager.tournamentStarted);
|
||||
}
|
||||
|
||||
public static void playPlayerWhispered() {
|
||||
if (audioManager.playerWhispered == null) {
|
||||
audioManager.playerWhispered = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerWhispered.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerWhispered);
|
||||
checkAndPlayClip(audioManager.playerWhispered);
|
||||
}
|
||||
|
||||
public static void playPlayerSubmittedDeck() {
|
||||
|
|
@ -245,14 +245,14 @@ public class AudioManager {
|
|||
audioManager.playerSubmittedDeck = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerSubmittedDeck.wav",
|
||||
AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerSubmittedDeck);
|
||||
checkAndPlayClip(audioManager.playerSubmittedDeck);
|
||||
}
|
||||
|
||||
public static void playPlayerLeft() {
|
||||
if (audioManager.playerLeft == null) {
|
||||
audioManager.playerLeft = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerLeft.wav", AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerLeft);
|
||||
checkAndPlayClip(audioManager.playerLeft);
|
||||
}
|
||||
|
||||
public static void playPlayerQuitTournament() {
|
||||
|
|
@ -260,21 +260,21 @@ public class AudioManager {
|
|||
audioManager.playerQuitTournament = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerQuitTournament.wav",
|
||||
AudioGroup.OtherSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerQuitTournament);
|
||||
checkAndPlayClip(audioManager.playerQuitTournament);
|
||||
}
|
||||
|
||||
public static void playPlayerLost() {
|
||||
if (audioManager.playerLost == null) {
|
||||
audioManager.playerLost = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerLost.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerLost);
|
||||
checkAndPlayClip(audioManager.playerLost);
|
||||
}
|
||||
|
||||
public static void playPlayerWon() {
|
||||
if (audioManager.playerWon == null) {
|
||||
audioManager.playerWon = new MageClip(Constants.BASE_SOUND_PATH + "OnPlayerWon.wav", AudioGroup.GameSounds);
|
||||
}
|
||||
checkAndPlayClip(getManager().playerWon);
|
||||
checkAndPlayClip(audioManager.playerWon);
|
||||
}
|
||||
|
||||
private static boolean audioGroupEnabled(AudioGroup audioGroup) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package mage.client.util.gui;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
|
|
@ -7,7 +9,7 @@ import java.util.List;
|
|||
|
||||
/**
|
||||
* Class for dealing with arrows in the game.
|
||||
*
|
||||
*
|
||||
* @author nantuko, noxx
|
||||
*/
|
||||
public class ArrowBuilder {
|
||||
|
|
@ -18,31 +20,25 @@ public class ArrowBuilder {
|
|||
instance = new ArrowBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores arrow panels per game
|
||||
*/
|
||||
private final Map<UUID, JPanel> arrowPanels = new HashMap<>();
|
||||
private final Map<UUID, Map<Type, List<Arrow>>> map = new MapMaker().weakKeys().weakValues().makeMap();
|
||||
/**
|
||||
* The top panel where arrow panels are added to.
|
||||
*/
|
||||
private JPanel arrowsManagerPanel;
|
||||
private int currentWidth;
|
||||
private int currentHeight;
|
||||
|
||||
public static ArrowBuilder getBuilder() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* The top panel where arrow panels are added to.
|
||||
*/
|
||||
private JPanel arrowsManagerPanel;
|
||||
|
||||
/**
|
||||
* Stores arrow panels per game
|
||||
*/
|
||||
private final Map<UUID, JPanel> arrowPanels = new HashMap<UUID, JPanel>();
|
||||
|
||||
private final Map<UUID, Map<Type, List<Arrow>>> map = new HashMap<UUID, Map<Type, java.util.List<Arrow>>>();
|
||||
|
||||
private int currentWidth;
|
||||
private int currentHeight;
|
||||
|
||||
public enum Type {
|
||||
PAIRED, SOURCE, TARGET, COMBAT, ENCHANT_PLAYERS
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the panel where all arrows are being drawn.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public JPanel getArrowsManagerPanel() {
|
||||
|
|
@ -58,7 +54,7 @@ public class ArrowBuilder {
|
|||
}
|
||||
return arrowsManagerPanel;
|
||||
}
|
||||
|
||||
|
||||
private JPanel getArrowsPanel(UUID gameId) {
|
||||
if (!arrowPanels.containsKey(gameId)) {
|
||||
JPanel arrowPanel = new JPanel();
|
||||
|
|
@ -73,20 +69,9 @@ public class ArrowBuilder {
|
|||
return arrowPanels.get(gameId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Not synchronized method for arrows panel.
|
||||
* Doesn't create JPanel in case the panel doesn't exist.
|
||||
* Works faster.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/*public JPanel getPanelRef() {
|
||||
return arrowsManagerPanel;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Adds new arrow.
|
||||
*
|
||||
*
|
||||
* @param startX
|
||||
* @param startY
|
||||
* @param endX
|
||||
|
|
@ -100,18 +85,25 @@ public class ArrowBuilder {
|
|||
arrow.setColor(color);
|
||||
arrow.setArrowLocation(startX, startY, endX, endY);
|
||||
arrow.setBounds(0, 0, Math.max(startX, endX) + 40, Math.max(startY, endY) + 30); // 30 is offset for arrow heads (being cut otherwise)
|
||||
|
||||
synchronized (map) {
|
||||
p.add(arrow);
|
||||
Map<Type, java.util.List<Arrow>> innerMap = map.computeIfAbsent(gameId, k -> new HashMap<Type, List<Arrow>>());
|
||||
java.util.List<Arrow> arrows = innerMap.computeIfAbsent(type, k -> new ArrayList<Arrow>());
|
||||
arrows.add(arrow);
|
||||
}
|
||||
|
||||
p.add(arrow);
|
||||
Map<Type, List<Arrow>> innerMap = map.computeIfAbsent(gameId, k -> new HashMap<>());
|
||||
List<Arrow> arrows = innerMap.computeIfAbsent(type, k -> new ArrayList<>());
|
||||
arrows.add(arrow);
|
||||
p.revalidate();
|
||||
p.repaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Not synchronized method for arrows panel.
|
||||
* Doesn't create JPanel in case the panel doesn't exist.
|
||||
* Works faster.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
/*public JPanel getPanelRef() {
|
||||
return arrowsManagerPanel;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Removes all arrows from the screen.
|
||||
*/
|
||||
|
|
@ -119,15 +111,13 @@ public class ArrowBuilder {
|
|||
if (map.containsKey(gameId)) {
|
||||
Map<Type, List<Arrow>> innerMap = map.get(gameId);
|
||||
JPanel p = getArrowsPanel(gameId);
|
||||
synchronized (map) {
|
||||
if (p != null && p.getComponentCount() > 0) {
|
||||
p.removeAll();
|
||||
p.revalidate();
|
||||
p.repaint();
|
||||
}
|
||||
innerMap.clear();
|
||||
map.remove(gameId);
|
||||
if (p != null && p.getComponentCount() > 0) {
|
||||
p.removeAll();
|
||||
p.revalidate();
|
||||
p.repaint();
|
||||
}
|
||||
innerMap.clear();
|
||||
map.remove(gameId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -137,18 +127,16 @@ public class ArrowBuilder {
|
|||
java.util.List<Arrow> arrows = innerMap.get(type);
|
||||
if (arrows != null && !arrows.isEmpty()) {
|
||||
JPanel p = getArrowsPanel(gameId);
|
||||
synchronized (map) {
|
||||
for (Arrow arrow : arrows) {
|
||||
p.remove(arrow);
|
||||
}
|
||||
innerMap.put(type, new ArrayList<Arrow>());
|
||||
for (Arrow arrow : arrows) {
|
||||
p.remove(arrow);
|
||||
}
|
||||
innerMap.put(type, new ArrayList<>());
|
||||
p.revalidate();
|
||||
p.repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setSize(int width, int height) {
|
||||
this.currentWidth = width;
|
||||
this.currentHeight = height;
|
||||
|
|
@ -173,4 +161,8 @@ public class ArrowBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
PAIRED, SOURCE, TARGET, COMBAT, ENCHANT_PLAYERS
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue