UI: improved add lands dialog (centered window, hotkeys to close/add);

This commit is contained in:
Oleg Agafonov 2019-03-23 15:43:34 +04:00
parent 1942cd0dec
commit 66403cbdbb
2 changed files with 166 additions and 156 deletions

View file

@ -51,9 +51,9 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="btnAdd" min="-2" max="-2" attributes="0"/>
<Component id="btnOK" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" pref="100" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="ckbFullArtLands" min="-2" max="-2" attributes="0"/>
@ -103,10 +103,12 @@
<Component id="panelSet" min="-2" pref="23" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="lblForestIcon" alignment="0" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="lblForest" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="spnForest" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="lblForestIcon" alignment="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
@ -150,8 +152,8 @@
</Group>
<EmptySpace type="separate" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnAdd" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnOK" alignment="3" min="-2" pref="30" max="-2" attributes="0"/>
<Component id="btnCancel" alignment="3" min="-2" pref="30" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -161,7 +163,7 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="lblLandSet">
<Properties>
<Property name="text" type="java.lang.String" value="Set:"/>
<Property name="text" type="java.lang.String" value="From set:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lblForest">
@ -304,20 +306,20 @@
</Component>
<Component class="javax.swing.JButton" name="btnAutoAdd">
<Properties>
<Property name="text" type="java.lang.String" value="Suggest"/>
<Property name="text" type="java.lang.String" value="Suggest lands"/>
<Property name="toolTipText" type="java.lang.String" value="&lt;HTML&gt;Propose related to the mana costs of the cards in the deck&lt;br&gt;&#xa;the number of lands to add to get to the set deck size."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAutoAddActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnAdd">
<Component class="javax.swing.JButton" name="btnOK">
<Properties>
<Property name="text" type="java.lang.String" value="Add"/>
<Property name="text" type="java.lang.String" value="Add lands"/>
<Property name="toolTipText" type="java.lang.String" value="Add the selected number of basic lands to the deck."/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnAddActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnOKActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnCancel">
@ -366,7 +368,7 @@
</Container>
<Component class="javax.swing.JCheckBox" name="ckbFullArtLands">
<Properties>
<Property name="text" type="java.lang.String" value="Only use full art lands"/>
<Property name="text" type="java.lang.String" value="Only full art lands"/>
<Property name="toolTipText" type="java.lang.String" value="For example, lands from ZEN/UST/HOU"/>
</Properties>
</Component>

View file

@ -1,23 +1,10 @@
package mage.client.dialog;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JLayeredPane;
import mage.Mana;
import mage.cards.Card;
import mage.cards.FrameStyle;
import mage.cards.decks.Deck;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
import mage.cards.repository.*;
import mage.client.MageFrame;
import mage.client.constants.Constants.DeckEditorMode;
import mage.client.util.gui.FastSearchUtil;
@ -26,8 +13,15 @@ import mage.util.RandomUtil;
import org.apache.log4j.Logger;
import org.mage.card.arcane.ManaSymbols;
import javax.swing.*;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class AddLandDialog extends MageDialog {
@ -38,9 +32,6 @@ public class AddLandDialog extends MageDialog {
private static final int DEFAULT_SEALED_DECK_CARD_NUMBER = 40;
/**
* Creates new form AddLandDialog
*/
public AddLandDialog() {
initComponents();
this.setModal(true);
@ -100,12 +91,6 @@ public class AddLandDialog extends MageDialog {
}
// windows settings
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
spnDeckSize.setValue(DEFAULT_SEALED_DECK_CARD_NUMBER);
BufferedImage image = ManaSymbols.getSizedManaSymbol("G", 15);
if (image != null) {
@ -128,6 +113,19 @@ public class AddLandDialog extends MageDialog {
lblSwampIcon.setIcon(new ImageIcon(image));
}
getRootPane().setDefaultButton(btnOK);
this.makeWindowCentered();
// windows settings
if (this.isModal()) {
MageFrame.getDesktop().add(this, JLayeredPane.MODAL_LAYER);
} else {
MageFrame.getDesktop().add(this, JLayeredPane.PALETTE_LAYER);
}
// Close on "ESC"
registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
this.setVisible(true);
}
@ -178,6 +176,27 @@ public class AddLandDialog extends MageDialog {
}
}
private void onCancel() {
this.removeDialog();
}
private void onOK() {
int nForest = ((Number) spnForest.getValue()).intValue();
int nIsland = ((Number) spnIsland.getValue()).intValue();
int nMountain = ((Number) spnMountain.getValue()).intValue();
int nPlains = ((Number) spnPlains.getValue()).intValue();
int nSwamp = ((Number) spnSwamp.getValue()).intValue();
boolean useFullArt = ckbFullArtLands.isSelected();
addLands("Forest", nForest, useFullArt);
addLands("Island", nIsland, useFullArt);
addLands("Mountain", nMountain, useFullArt);
addLands("Plains", nPlains, useFullArt);
addLands("Swamp", nSwamp, useFullArt);
this.removeDialog();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
@ -208,7 +227,7 @@ public class AddLandDialog extends MageDialog {
lblDeckSize = new javax.swing.JLabel();
spnDeckSize = new javax.swing.JSpinner();
btnAutoAdd = new javax.swing.JButton();
btnAdd = new javax.swing.JButton();
btnOK = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
panelSet = new javax.swing.JPanel();
cbLandSet = new javax.swing.JComboBox();
@ -221,7 +240,7 @@ public class AddLandDialog extends MageDialog {
setTitle("Add Land");
lblLandSet.setText("Set:");
lblLandSet.setText("From set:");
lblForest.setText("Forest:");
@ -268,7 +287,7 @@ public class AddLandDialog extends MageDialog {
spnDeckSize.setModel(new javax.swing.SpinnerNumberModel(0, 0, null, 1));
btnAutoAdd.setText("Suggest");
btnAutoAdd.setText("Suggest lands");
btnAutoAdd.setToolTipText("<HTML>Propose related to the mana costs of the cards in the deck<br>\nthe number of lands to add to get to the set deck size.");
btnAutoAdd.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -276,11 +295,11 @@ public class AddLandDialog extends MageDialog {
}
});
btnAdd.setText("Add");
btnAdd.setToolTipText("Add the selected number of basic lands to the deck.");
btnAdd.addActionListener(new java.awt.event.ActionListener() {
btnOK.setText("Add lands");
btnOK.setToolTipText("Add the selected number of basic lands to the deck.");
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnAddActionPerformed(evt);
btnOKActionPerformed(evt);
}
});
@ -293,7 +312,7 @@ public class AddLandDialog extends MageDialog {
panelSet.setLayout(new javax.swing.BoxLayout(panelSet, javax.swing.BoxLayout.LINE_AXIS));
cbLandSet.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
cbLandSet.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Item 1", "Item 2", "Item 3", "Item 4"}));
cbLandSet.setMinimumSize(new java.awt.Dimension(20, 20));
panelSet.add(cbLandSet);
@ -308,7 +327,7 @@ public class AddLandDialog extends MageDialog {
});
panelSet.add(btnSetFastSearch);
ckbFullArtLands.setText("Only use full art lands");
ckbFullArtLands.setText("Only full art lands");
ckbFullArtLands.setToolTipText("For example, lands from ZEN/UST/HOU");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
@ -330,9 +349,9 @@ public class AddLandDialog extends MageDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(btnAdd)
.addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(ckbFullArtLands)
.addComponent(panelSet, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
@ -370,10 +389,11 @@ public class AddLandDialog extends MageDialog {
.addComponent(lblLandSet)
.addComponent(panelSet, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblForestIcon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblForest)
.addComponent(spnForest, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(lblForestIcon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(spnForest, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
@ -407,8 +427,8 @@ public class AddLandDialog extends MageDialog {
.addComponent(spnDeckSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnAdd)
.addComponent(btnCancel))
.addComponent(btnOK, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
@ -416,24 +436,12 @@ public class AddLandDialog extends MageDialog {
}// </editor-fold>//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
this.removeDialog();
onCancel();
}//GEN-LAST:event_btnCancelActionPerformed
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
int nForest = ((Number) spnForest.getValue()).intValue();
int nIsland = ((Number) spnIsland.getValue()).intValue();
int nMountain = ((Number) spnMountain.getValue()).intValue();
int nPlains = ((Number) spnPlains.getValue()).intValue();
int nSwamp = ((Number) spnSwamp.getValue()).intValue();
boolean useFullArt = ckbFullArtLands.isSelected();
addLands("Forest", nForest, useFullArt);
addLands("Island", nIsland, useFullArt);
addLands("Mountain", nMountain, useFullArt);
addLands("Plains", nPlains, useFullArt);
addLands("Swamp", nSwamp, useFullArt);
this.removeDialog();
}//GEN-LAST:event_btnAddActionPerformed
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed
onOK();
}//GEN-LAST:event_btnOKActionPerformed
private void btnAutoAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutoAddActionPerformed
autoAddLands();
@ -484,9 +492,9 @@ public class AddLandDialog extends MageDialog {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAdd;
private javax.swing.JButton btnAutoAdd;
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOK;
private javax.swing.JButton btnSetFastSearch;
private javax.swing.JComboBox cbLandSet;
private javax.swing.JCheckBox ckbFullArtLands;