UI: added set search button in new tournament dialog

This commit is contained in:
Oleg Agafonov 2018-01-01 18:02:20 +04:00
parent 78d036b6bb
commit 56d214f0b2

View file

@ -47,6 +47,7 @@ import mage.cards.repository.ExpansionRepository;
import mage.client.MageFrame;
import mage.client.SessionHandler;
import mage.client.table.TournamentPlayerPanel;
import mage.client.util.gui.FastSearchUtil;
import mage.constants.MatchTimeLimit;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
@ -76,7 +77,7 @@ public class NewTournamentDialog extends MageDialog {
private RandomPacksSelectorDialog randomPackSelector;
private JTextArea txtRandomPacks;
private final List<TournamentPlayerPanel> players = new ArrayList<>();
private final List<JComboBox> packs = new ArrayList<>();
private final List<JPanel> packPanels = new ArrayList<>();
private static final int CONSTRUCTION_TIME_MIN = 6;
private static final int CONSTRUCTION_TIME_MAX = 30;
private boolean isRandom = false;
@ -586,8 +587,13 @@ public class NewTournamentDialog extends MageDialog {
tOptions.getLimitedOptions().getSetCodes().addAll(selected);
}
} else {
for (JComboBox pack : packs) {
tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) pack.getSelectedItem()).getCode());
for (JPanel panel : packPanels) {
JComboBox combo = findComboInComponent(panel);
if(combo != null) {
tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) combo.getSelectedItem()).getCode());
}else{
logger.error("Can't find combo component in " + panel.toString());
}
}
}
tOptions.getMatchOptions().setDeckType("Limited");
@ -884,35 +890,89 @@ public class NewTournamentDialog extends MageDialog {
}
private void createPacks(int numPacks) {
while (packs.size() > numPacks) {
pnlPacks.remove(packs.get(packs.size() - 1));
packs.remove(packs.size() - 1);
while (packPanels.size() > numPacks) {
pnlPacks.remove(packPanels.get(packPanels.size() - 1));
packPanels.remove(packPanels.size() - 1);
}
while (packs.size() < numPacks) {
while (packPanels.size() < numPacks) {
// SELECT PACK
// panel
JPanel setPanel = new JPanel();
setPanel.setLayout(new javax.swing.BoxLayout(setPanel, javax.swing.BoxLayout.LINE_AXIS));
setPanel.setOpaque(false);
//setPanel.setPreferredSize(new Dimension(200, 25));
//setPanel.setMaximumSize(new Dimension(200, 25));
pnlPacks.add(setPanel);
packPanels.add(setPanel); // for later access
// combo set
JComboBox pack = new JComboBox();
pack = new JComboBox();
pack.setModel(new DefaultComboBoxModel(ExpansionRepository.instance.getWithBoostersSortedByReleaseDate()));
pnlPacks.add(pack);
packs.add(pack);
pack.addActionListener(evt -> packActionPerformed(evt));
pack.setAlignmentX(0.0F);
pack.setMinimumSize(new Dimension(50, 25));
pack.setPreferredSize(new Dimension(50, 25));
pack.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));
setPanel.add(pack);
// search button
JButton searchButton = new JButton();
searchButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/buttons/search_24.png")));
searchButton.setToolTipText("Search and select from list");
searchButton.setAlignmentX(1.0F);
searchButton.setMinimumSize(new java.awt.Dimension(24, 24));
searchButton.setPreferredSize(new java.awt.Dimension(32, 32));
searchButton.setMaximumSize(new java.awt.Dimension(32, 32));
searchButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
// search combo box near button (must be only one combo in panel)
JButton button = (JButton)evt.getSource();
JComboBox combo = findComboInComponent(button.getParent());
if (combo != null) {
FastSearchUtil.showFastSearchForStringComboBox(combo, "Select value");
}
}
});
setPanel.add(searchButton);
}
this.pack();
this.revalidate();
this.repaint();
}
private void packActionPerformed(java.awt.event.ActionEvent evt) {
boolean start = false;
int selectedIndex = 0;
for (JComboBox pack : packs) {
if (!start) {
if (evt.getSource().equals(pack)) {
start = true;
selectedIndex = pack.getSelectedIndex();
}
} else {
pack.setSelectedIndex(selectedIndex);
private JComboBox findComboInComponent(Container panel){
// search combo box near button (must be only one combo in panel)
JComboBox combo = null;
for(Component comp: panel.getComponents()){
if (comp instanceof JComboBox){
combo = (JComboBox)comp;
break;
}
}
return combo;
}
private void packActionPerformed(java.awt.event.ActionEvent evt) {
// fill all bottom combobox with same value
JComboBox curentCombo = (JComboBox)evt.getSource();
int newValue = curentCombo.getSelectedIndex();
// search start index
int startIndex = 0;
for(int i = 0; i < packPanels.size(); i++){
JComboBox pack = findComboInComponent(packPanels.get(i));
if (pack.equals(curentCombo)){
startIndex = i + 1;
break;
}
}
// change all from start index
for(int i = startIndex; i < packPanels.size(); i++){
JComboBox pack = findComboInComponent(packPanels.get(i));
pack.setSelectedIndex(newValue);
}
}
private void createPlayers(int numPlayers) {
@ -1054,16 +1114,22 @@ public class NewTournamentDialog extends MageDialog {
int packNumber = 0;
for (String pack : packsArray) {
packNumber++;
if (this.packs.size() >= packNumber - 1) {
JComboBox comboBox = this.packs.get(packNumber - 1);
ComboBoxModel model = comboBox.getModel();
int size = model.getSize();
for (int i = 0; i < size; i++) {
ExpansionInfo element = (ExpansionInfo) model.getElementAt(i);
if (element.getCode().equals(pack.trim())) {
comboBox.setSelectedIndex(i);
break;
if (this.packPanels.size() >= packNumber - 1) {
JPanel panel = packPanels.get(packNumber - 1);
JComboBox comboBox = findComboInComponent(panel);
if (comboBox != null) {
ComboBoxModel model = comboBox.getModel();
int size = model.getSize();
for (int i = 0; i < size; i++) {
ExpansionInfo element = (ExpansionInfo) model.getElementAt(i);
if (element.getCode().equals(pack.trim())) {
comboBox.setSelectedIndex(i);
break;
}
}
}else{
logger.error("Can't find combo component in " + panel.toString());
}
}