mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Improve appearance of FDialogs
Make CardListViewer use FDialog and display on screen
This commit is contained in:
@@ -19,26 +19,24 @@
|
||||
package forge.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowFocusListener;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.AbstractListModel;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import forge.gui.toolbox.FButton;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.item.PaperCard;
|
||||
import forge.view.FDialog;
|
||||
|
||||
/**
|
||||
* A simple class that shows a list of cards in a dialog with preview in its
|
||||
@@ -47,26 +45,17 @@ import forge.item.PaperCard;
|
||||
* @author Forge
|
||||
* @version $Id: ListChooser.java 9708 2011-08-09 19:34:12Z jendave $
|
||||
*/
|
||||
public class CardListViewer {
|
||||
@SuppressWarnings("serial")
|
||||
public class CardListViewer extends FDialog {
|
||||
|
||||
// Data and number of choices for the list
|
||||
private final List<PaperCard> list;
|
||||
|
||||
// Decoration
|
||||
private final String title;
|
||||
|
||||
// Flag: was the dialog already shown?
|
||||
private boolean called;
|
||||
// initialized before; listeners may be added to it
|
||||
private final JList<PaperCard> jList;
|
||||
private final CardDetailPanel detail;
|
||||
private final CardPicturePanel picture;
|
||||
|
||||
// Temporarily stored for event handlers during show
|
||||
private JDialog dialog;
|
||||
private final JOptionPane optionPane;
|
||||
private final Action ok;
|
||||
|
||||
/**
|
||||
* Instantiates a new card list viewer.
|
||||
*
|
||||
@@ -106,53 +95,36 @@ public class CardListViewer {
|
||||
* the dialog icon
|
||||
*/
|
||||
public CardListViewer(final String title, final String message, final List<PaperCard> list, final Icon dialogIcon) {
|
||||
this.title = title;
|
||||
this.list = Collections.unmodifiableList(list);
|
||||
this.jList = new JList<PaperCard>(new ChooserListModel());
|
||||
this.detail = new CardDetailPanel(null);
|
||||
this.picture = new CardPicturePanel();
|
||||
this.ok = new CloseAction(JOptionPane.OK_OPTION, "OK");
|
||||
this.picture.setOpaque(false);
|
||||
|
||||
final Object[] options = new Object[] { new JButton(this.ok) };
|
||||
this.setTitle(title);
|
||||
this.setSize(720, 360);
|
||||
this.addWindowFocusListener(new CardListFocuser());
|
||||
|
||||
final JPanel threeCols = new JPanel();
|
||||
threeCols.add(new JScrollPane(this.jList));
|
||||
threeCols.add(this.picture);
|
||||
threeCols.add(this.detail);
|
||||
threeCols.setLayout(new java.awt.GridLayout(1, 3, 6, 0));
|
||||
FButton btnOK = new FButton("OK");
|
||||
btnOK.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
CardListViewer.this.processWindowEvent(new WindowEvent(CardListViewer.this, WindowEvent.WINDOW_CLOSING));
|
||||
}
|
||||
});
|
||||
|
||||
this.optionPane = new JOptionPane(new Object[] { message, threeCols }, JOptionPane.INFORMATION_MESSAGE,
|
||||
JOptionPane.DEFAULT_OPTION, dialogIcon, options, options[0]);
|
||||
this.add(new FLabel.Builder().text(message).build(), "cell 0 0, spanx 3, gapbottom 4");
|
||||
this.add(new JScrollPane(this.jList), "cell 0 1, w 225, growy, pushy, ax c");
|
||||
this.add(this.picture, "cell 1 1, w 225, growy, pushy, ax c");
|
||||
this.add(this.detail, "cell 2 1, w 225, growy, pushy, ax c");
|
||||
this.add(btnOK, "cell 1 2, w 150, h 26, ax c, gaptop 6");
|
||||
|
||||
// selection is here
|
||||
this.jList.getSelectionModel().addListSelectionListener(new SelListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the dialog and returns after the dialog was closed.
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
public synchronized boolean show() {
|
||||
if (this.called) {
|
||||
throw new IllegalStateException("Already shown");
|
||||
}
|
||||
this.jList.setSelectedIndex(0);
|
||||
|
||||
this.dialog = this.optionPane.createDialog(JOptionPane.getRootFrame(), this.title);
|
||||
this.dialog.setSize(720, 360);
|
||||
this.dialog.addWindowFocusListener(new CardListFocuser());
|
||||
this.dialog.setLocationRelativeTo(null);
|
||||
this.dialog.setVisible(true);
|
||||
this.dialog.toFront();
|
||||
|
||||
this.dialog.dispose();
|
||||
this.called = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
private class ChooserListModel extends AbstractListModel<PaperCard> {
|
||||
|
||||
private static final long serialVersionUID = 3871965346333840556L;
|
||||
|
||||
@Override
|
||||
@@ -166,24 +138,7 @@ public class CardListViewer {
|
||||
}
|
||||
}
|
||||
|
||||
private class CloseAction extends AbstractAction {
|
||||
|
||||
private static final long serialVersionUID = -8426767786083886936L;
|
||||
private final int value;
|
||||
|
||||
public CloseAction(final int value, final String label) {
|
||||
super(label);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
CardListViewer.this.optionPane.setValue(this.value);
|
||||
}
|
||||
}
|
||||
|
||||
private class CardListFocuser implements WindowFocusListener {
|
||||
|
||||
@Override
|
||||
public void windowGainedFocus(final WindowEvent e) {
|
||||
CardListViewer.this.jList.grabFocus();
|
||||
@@ -195,7 +150,6 @@ public class CardListViewer {
|
||||
}
|
||||
|
||||
private class SelListener implements ListSelectionListener {
|
||||
|
||||
@Override
|
||||
public void valueChanged(final ListSelectionEvent e) {
|
||||
final int row = CardListViewer.this.jList.getSelectedIndex();
|
||||
@@ -206,8 +160,5 @@ public class CardListViewer {
|
||||
CardListViewer.this.picture.setCard(cp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package forge.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -15,7 +13,7 @@ import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.ListDataEvent;
|
||||
@@ -31,9 +29,9 @@ import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FList;
|
||||
import forge.gui.toolbox.FPanel;
|
||||
import forge.gui.toolbox.FScrollPane;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.view.FDialog;
|
||||
|
||||
// An input box for handling the order of choices.
|
||||
// Left box has the original choices
|
||||
@@ -46,7 +44,7 @@ import forge.item.IPaperCard;
|
||||
// Single ok button, disabled until left box has specified number of items remaining
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class DualListBox<T> extends FPanel {
|
||||
public class DualListBox<T> extends FDialog {
|
||||
private final FList<T> sourceList;
|
||||
private final UnsortedListModel<T> sourceListModel;
|
||||
|
||||
@@ -75,11 +73,6 @@ public class DualListBox<T> extends FPanel {
|
||||
destListModel = new UnsortedListModel<T>();
|
||||
destList = new FList<T>(destListModel);
|
||||
|
||||
setPreferredSize(new Dimension(650, 300));
|
||||
setLayout(new GridLayout(0, 3));
|
||||
this.skin.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME));
|
||||
this.skin.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
|
||||
final Runnable onAdd = new Runnable() {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
@@ -153,14 +146,15 @@ public class DualListBox<T> extends FPanel {
|
||||
|
||||
FPanel leftPanel = new FPanel(new BorderLayout());
|
||||
selectOrder = new FLabel.Builder().text("Select Order:").build();
|
||||
leftPanel.setSize(300, 300);
|
||||
leftPanel.add(selectOrder, BorderLayout.NORTH);
|
||||
leftPanel.add(new FScrollPane(sourceList), BorderLayout.CENTER);
|
||||
leftPanel.add(okButton, BorderLayout.SOUTH);
|
||||
|
||||
FPanel centerPanel = new FPanel(new GridLayout(6, 1));
|
||||
centerPanel.setSize(50, this.getHeight());
|
||||
centerPanel.add(new FPanel()); // empty panel to take up the first slot
|
||||
centerPanel.setBorderToggle(false);
|
||||
JPanel emptyPanel = new JPanel();
|
||||
emptyPanel.setOpaque(false);
|
||||
centerPanel.add(emptyPanel); // empty panel to take up the first slot
|
||||
centerPanel.add(addButton);
|
||||
centerPanel.add(addAllButton);
|
||||
centerPanel.add(removeButton);
|
||||
@@ -169,14 +163,13 @@ public class DualListBox<T> extends FPanel {
|
||||
orderedLabel = new FLabel.Builder().build();
|
||||
|
||||
FPanel rightPanel = new FPanel(new BorderLayout());
|
||||
rightPanel.setSize(300, 300);
|
||||
rightPanel.add(orderedLabel, BorderLayout.NORTH);
|
||||
rightPanel.add(new FScrollPane(destList), BorderLayout.CENTER);
|
||||
rightPanel.add(autoButton, BorderLayout.SOUTH);
|
||||
|
||||
add(leftPanel);
|
||||
add(centerPanel);
|
||||
add(rightPanel);
|
||||
add(leftPanel, "w 250, h 300");
|
||||
add(centerPanel, "w 100, h 300");
|
||||
add(rightPanel, "w 250, h 300");
|
||||
|
||||
_addListListeners(sourceList);
|
||||
_addListListeners(destList);
|
||||
@@ -467,9 +460,5 @@ public class DualListBox<T> extends FPanel {
|
||||
|
||||
private void _finish() {
|
||||
this.setVisible(false);
|
||||
|
||||
Container grandpa = this.getParent().getParent();
|
||||
JDialog dialog = (JDialog) grandpa.getParent();
|
||||
dialog.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import forge.Singletons;
|
||||
import forge.game.card.Card;
|
||||
import forge.gui.match.CMatchUI;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.view.FDialog;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
@@ -186,21 +185,18 @@ public class GuiChoose {
|
||||
|
||||
dual.setSideboardMode(sideboardingMode);
|
||||
|
||||
final FDialog dialog = new FDialog();
|
||||
dialog.setTitle(title);
|
||||
dialog.setContentPane(dual);
|
||||
dialog.setSize(dual.getPreferredSize());
|
||||
dialog.pack();
|
||||
dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
dual.setTitle(title);
|
||||
dual.pack();
|
||||
dual.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
if (referenceCard != null) {
|
||||
CMatchUI.SINGLETON_INSTANCE.setCard(referenceCard);
|
||||
// MARKED FOR UPDATE
|
||||
}
|
||||
dialog.setVisible(true);
|
||||
|
||||
dual.setVisible(true);
|
||||
|
||||
List<T> objects = dual.getOrderedList();
|
||||
|
||||
dialog.dispose();
|
||||
|
||||
dual.dispose();
|
||||
GuiUtils.clearPanelSelections();
|
||||
return objects;
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ public class ImportDialog {
|
||||
@Override public void run() {
|
||||
// bring up a file open dialog and, if the OK button is selected, apply the filename
|
||||
// to the import source text field
|
||||
if (JFileChooser.APPROVE_OPTION == _fileChooser.showOpenDialog(null)) {
|
||||
if (JFileChooser.APPROVE_OPTION == _fileChooser.showOpenDialog(JOptionPane.getRootFrame())) {
|
||||
File f = _fileChooser.getSelectedFile();
|
||||
if (!f.canRead()) {
|
||||
JOptionPane.showMessageDialog(txfSrc, "Cannot access selected directory (Permission denied).");
|
||||
|
||||
@@ -26,9 +26,7 @@ import java.util.Calendar;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JEditorPane;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.BadLocationException;
|
||||
@@ -37,7 +35,6 @@ import javax.swing.text.ElementIterator;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
@@ -48,9 +45,10 @@ import forge.gui.deckeditor.controllers.ACEditorBase;
|
||||
import forge.gui.toolbox.FButton;
|
||||
import forge.gui.toolbox.FCheckBox;
|
||||
import forge.gui.toolbox.FComboBoxWrapper;
|
||||
import forge.gui.toolbox.FHtmlViewer;
|
||||
import forge.gui.toolbox.FLabel;
|
||||
import forge.gui.toolbox.FPanel;
|
||||
import forge.gui.toolbox.FScrollPane;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FTextArea;
|
||||
import forge.item.PaperCard;
|
||||
import forge.item.InventoryItem;
|
||||
@@ -90,7 +88,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
+ "<p>Sideboard recognition is supported. Make sure that the sideboard cards are listed after a line that contains the word 'Sideboard'</p>"
|
||||
+ "</html>";
|
||||
|
||||
private final JEditorPane htmlOutput = new JEditorPane("text/html", DeckImport.HTML_WELCOME_TEXT);
|
||||
private final FHtmlViewer htmlOutput = new FHtmlViewer(DeckImport.HTML_WELCOME_TEXT);
|
||||
private final FScrollPane scrollInput = new FScrollPane(this.txtInput);
|
||||
private final FScrollPane scrollOutput = new FScrollPane(this.htmlOutput);
|
||||
private final FLabel summaryMain = new FLabel.Builder().text("Imported deck summary will appear here").build();
|
||||
@@ -99,7 +97,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
private final FButton cmdCancel = new FButton("Cancel");
|
||||
private final FCheckBox newEditionCheck = new FCheckBox("Import latest version of card", true);
|
||||
private final FCheckBox dateTimeCheck = new FCheckBox("Use only sets released before:", false);
|
||||
|
||||
|
||||
private final FComboBoxWrapper<String> monthDropdown = new FComboBoxWrapper<>();
|
||||
private final FComboBoxWrapper<Integer> yearDropdown = new FComboBoxWrapper<>();
|
||||
|
||||
@@ -117,44 +115,36 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
public DeckImport(final ACEditorBase<TItem, TModel> g) {
|
||||
this.host = g;
|
||||
|
||||
final int wWidth = 600;
|
||||
final int wWidth = 700;
|
||||
final int wHeight = 600;
|
||||
|
||||
this.setPreferredSize(new java.awt.Dimension(wWidth, wHeight));
|
||||
this.setSize(wWidth, wHeight);
|
||||
this.setResizable(false);
|
||||
this.setTitle("Deck Importer");
|
||||
|
||||
FPanel fp = new FPanel(new MigLayout("fill"));
|
||||
this.add(fp);
|
||||
|
||||
txtInput.setFocusable(true);
|
||||
txtInput.setEditable(true);
|
||||
|
||||
this.htmlOutput.setEditable(false);
|
||||
|
||||
this.scrollInput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist"));
|
||||
this.scrollOutput.setBorder(new TitledBorder(BorderFactory.createEtchedBorder(),
|
||||
"Expect the recognized lines to appear"));
|
||||
FSkin.SkinColor foreColor = FSkin.getColor(FSkin.Colors.CLR_TEXT);
|
||||
FSkin.get(this.scrollInput).setBorder(new FSkin.TitledSkinBorder(BorderFactory.createEtchedBorder(), "Paste or type a decklist", foreColor));
|
||||
FSkin.get(this.scrollOutput).setBorder(new FSkin.TitledSkinBorder(BorderFactory.createEtchedBorder(), "Expect the recognized lines to appear", foreColor));
|
||||
this.scrollInput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
|
||||
this.scrollOutput.setViewportBorder(BorderFactory.createLoweredBevelBorder());
|
||||
|
||||
|
||||
fp.add(this.scrollInput, "cell 0 0, w 50%, growy, pushy");
|
||||
fp.add(this.newEditionCheck, "cell 0 1, w 50%, ax c");
|
||||
fp.add(this.dateTimeCheck, "cell 0 2, w 50%, ax c");
|
||||
this.add(this.scrollInput, "cell 0 0, w 50%, growy, pushy");
|
||||
this.add(this.newEditionCheck, "cell 0 1, w 50%, ax c");
|
||||
this.add(this.dateTimeCheck, "cell 0 2, w 50%, ax c");
|
||||
|
||||
fp.add(monthDropdown.getComponent(), "cell 0 3, w 20%, ax r, split 2");
|
||||
fp.add(yearDropdown.getComponent(), "w 15%, pad 0 0 0 -10");
|
||||
this.add(monthDropdown.getComponent(), "cell 0 3, w 20%, ax left, split 2, pad 0 4 0 0");
|
||||
this.add(yearDropdown.getComponent(), "w 15%");
|
||||
fillDateDropdowns();
|
||||
|
||||
fp.add(this.scrollOutput, "cell 1 0, w 50%, growy, pushy");
|
||||
fp.add(this.summaryMain, "cell 1 1, label");
|
||||
fp.add(this.summarySide, "cell 1 2, label");
|
||||
|
||||
fp.add(this.cmdAccept, "cell 1 3, split 2, w 140, align c, h 26, pad 0 0 0 -20");
|
||||
fp.add(this.cmdCancel, "w 120, h 26");
|
||||
this.add(this.scrollOutput, "cell 1 0, w 50%, growy, pushy");
|
||||
this.add(this.summaryMain, "cell 1 1, label");
|
||||
this.add(this.summarySide, "cell 1 2, label");
|
||||
|
||||
this.add(this.cmdAccept, "cell 1 3, split 2, w 150, align r, h 26");
|
||||
this.add(this.cmdCancel, "w 150, h 26");
|
||||
|
||||
this.cmdCancel.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
@@ -189,7 +179,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
}
|
||||
};
|
||||
this.dateTimeCheck.addActionListener(updateDateCheck);
|
||||
|
||||
|
||||
ActionListener reparse = new ActionListener() {
|
||||
@Override public void actionPerformed(ActionEvent e) { parseAndDisplay(); }
|
||||
};
|
||||
@@ -221,11 +211,11 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
this.tokens.clear();
|
||||
final ElementIterator it = new ElementIterator(this.txtInput.getDocument().getDefaultRootElement());
|
||||
Element e;
|
||||
|
||||
|
||||
DeckRecognizer recognizer = new DeckRecognizer(newEditionCheck.isSelected(), Singletons.getMagicDb().getCommonCards());
|
||||
if(dateTimeCheck.isSelected())
|
||||
recognizer.setDateConstraint(monthDropdown.getSelectedIndex(), yearDropdown.getSelectedItem());
|
||||
|
||||
|
||||
while ((e = it.next()) != null) {
|
||||
if (!e.isLeaf()) {
|
||||
continue;
|
||||
@@ -235,7 +225,8 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
try {
|
||||
final String line = this.txtInput.getText(rangeStart, rangeEnd - rangeStart);
|
||||
this.tokens.add(recognizer.recognizeLine(line));
|
||||
} catch (final BadLocationException ex) {
|
||||
}
|
||||
catch (final BadLocationException ex) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -269,10 +260,8 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
idx = 1;
|
||||
}
|
||||
}
|
||||
this.summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0],
|
||||
cardsUnknown[0]));
|
||||
this.summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1],
|
||||
cardsUnknown[1]));
|
||||
this.summaryMain.setText(String.format("Main: %d cards recognized, %d unknown cards", cardsOk[0], cardsUnknown[0]));
|
||||
this.summarySide.setText(String.format("Sideboard: %d cards recognized, %d unknown cards", cardsOk[1], cardsUnknown[1]));
|
||||
this.cmdAccept.setEnabled(cardsOk[0] > 0);
|
||||
}
|
||||
|
||||
@@ -290,7 +279,8 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
final PaperCard crd = t.getCard();
|
||||
if (isMain) {
|
||||
result.getMain().add(crd, t.getNumber());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
result.getOrCreate(DeckSection.Sideboard).add(crd, t.getNumber());
|
||||
}
|
||||
}
|
||||
@@ -302,7 +292,7 @@ public class DeckImport<TItem extends InventoryItem, TModel extends DeckBase> ex
|
||||
displayTokens();
|
||||
updateSummaries();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The Class OnChangeTextUpdate.
|
||||
*/
|
||||
|
||||
@@ -335,7 +335,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
|
||||
itemsToAdd.addAllFlat(newCards);
|
||||
|
||||
final CardListViewer c = new CardListViewer(booster.getName(), "You have found the following cards inside:", newCards);
|
||||
c.show();
|
||||
c.setVisible(true);
|
||||
c.dispose();
|
||||
}
|
||||
}
|
||||
else if (item instanceof PreconDeck) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package forge.gui.toolbox;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Graphics;
|
||||
@@ -35,6 +36,7 @@ import javax.swing.SwingConstants;
|
||||
|
||||
import forge.Command;
|
||||
import forge.gui.framework.ILocalRepaint;
|
||||
import forge.gui.toolbox.FSkin.SkinColor;
|
||||
import forge.gui.toolbox.FSkin.SkinImage;
|
||||
|
||||
/**
|
||||
@@ -58,7 +60,8 @@ public class FPanel extends JPanel implements ILocalRepaint {
|
||||
private boolean foregroundStretch = false;
|
||||
private Image foregroundImage = null;
|
||||
private Image backgroundTexture = null;
|
||||
private FSkin.SkinColor borderColor = FSkin.getColor(FSkin.Colors.CLR_BORDERS);
|
||||
private Color backgroundTextureOverlay = null;
|
||||
private SkinColor borderColor = FSkin.getColor(FSkin.Colors.CLR_BORDERS);
|
||||
private boolean borderToggle = true;
|
||||
private int cornerDiameter = 20;
|
||||
private int foregroundAlign = SwingConstants.CENTER;
|
||||
@@ -214,6 +217,17 @@ public class FPanel extends JPanel implements ILocalRepaint {
|
||||
skin.setBackgroundTexture(skinImage);
|
||||
}
|
||||
|
||||
/** @param clr0   {@link java.awt.Color} */
|
||||
public void setBackgroundTextureOverlay(final Color color) {
|
||||
skin.resetBackgroundTexture(); //must reset if non-skin color set
|
||||
this.backgroundTextureOverlay = color;
|
||||
}
|
||||
|
||||
/** @param clr0   {@link forge.gui.toolbox.FSkin.SkinColor} */
|
||||
public void setBackgroundTextureOverlay(final SkinColor skinColor) {
|
||||
skin.setBackgroundTextureOverlay(skinColor);
|
||||
}
|
||||
|
||||
/** @param bool0   boolean */
|
||||
public void setBorderToggle(final boolean bool0) {
|
||||
this.borderToggle = bool0;
|
||||
@@ -297,6 +311,11 @@ public class FPanel extends JPanel implements ILocalRepaint {
|
||||
this.tempY = 0;
|
||||
}
|
||||
this.tempX = 0;
|
||||
|
||||
if (this.backgroundTextureOverlay != null) {
|
||||
g2d0.setColor(this.backgroundTextureOverlay);
|
||||
g2d0.fillRect(0, 0, this.pnlW, this.pnlH);
|
||||
}
|
||||
}
|
||||
|
||||
private void drawForegroundScaled(final Graphics2D g2d0) {
|
||||
|
||||
@@ -403,7 +403,7 @@ public class FScrollPanel extends JScrollPane {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//relay certain methods to the inner panel if it has been initialized
|
||||
@Override
|
||||
public Component add(Component comp) {
|
||||
|
||||
@@ -52,6 +52,7 @@ import javax.swing.UIManager;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.border.TitledBorder;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
@@ -444,6 +445,7 @@ public enum FSkin {
|
||||
private static HashMap<FPanel, FPanelSkin> skins = new HashMap<FPanel, FPanelSkin>();
|
||||
|
||||
private SkinImage foregroundImage, backgroundTexture;
|
||||
private SkinColor backgroundTextureOverlay;
|
||||
|
||||
private FPanelSkin(T comp0) {
|
||||
super(comp0);
|
||||
@@ -469,6 +471,16 @@ public enum FSkin {
|
||||
this.backgroundTexture = null;
|
||||
}
|
||||
|
||||
public void setBackgroundTextureOverlay(SkinColor skinColor) {
|
||||
this.comp.setBackgroundTextureOverlay(skinColor.color); //must call this first since it will call resetBackgroundTexture
|
||||
this.backgroundTextureOverlay = skinColor;
|
||||
this.needRepaintOnReapply = true; //background texture drawn during paint
|
||||
}
|
||||
|
||||
public void resetBackgroundTextureOverlay() {
|
||||
this.backgroundTextureOverlay = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reapply() {
|
||||
if (this.foregroundImage != null) {
|
||||
@@ -477,6 +489,9 @@ public enum FSkin {
|
||||
if (this.backgroundTexture != null) {
|
||||
this.setBackgroundTexture(this.backgroundTexture); //use skin function so backgroundTexture field retained
|
||||
}
|
||||
if (this.backgroundTextureOverlay != null) { //use skin function so backgroundTextureOverlay field retained
|
||||
this.setBackgroundTextureOverlay(this.backgroundTextureOverlay);
|
||||
}
|
||||
super.reapply();
|
||||
}
|
||||
}
|
||||
@@ -793,6 +808,35 @@ public enum FSkin {
|
||||
return BorderFactory.createCompoundBorder(outBorder, inBorder);
|
||||
}
|
||||
}
|
||||
public static class TitledSkinBorder extends SkinBorder {
|
||||
private final SkinColor foreColor;
|
||||
private final String title;
|
||||
private Border insideBorder;
|
||||
private SkinBorder insideSkinBorder;
|
||||
|
||||
public TitledSkinBorder(Border insideBorder0, String title0, SkinColor foreColor0) {
|
||||
this.insideBorder = insideBorder0;
|
||||
this.title = title0;
|
||||
this.foreColor = foreColor0;
|
||||
}
|
||||
|
||||
public TitledSkinBorder(SkinBorder insideSkinBorder0, String title0, SkinColor foreColor0) {
|
||||
this.insideSkinBorder = insideSkinBorder0;
|
||||
this.title = title0;
|
||||
this.foreColor = foreColor0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Border createBorder() {
|
||||
Border inBorder = this.insideBorder;
|
||||
if (this.insideSkinBorder != null) {
|
||||
inBorder = this.insideSkinBorder.createBorder();
|
||||
}
|
||||
TitledBorder border = new TitledBorder(inBorder, this.title);
|
||||
border.setTitleColor(foreColor.color);
|
||||
return border;
|
||||
}
|
||||
}
|
||||
|
||||
public enum Colors implements SkinProp {
|
||||
CLR_THEME (new int[] {70, 10}),
|
||||
|
||||
@@ -201,7 +201,8 @@ public class QuestUtilUnlockSets {
|
||||
|
||||
qData.getCards().addAllCards(cardsWon);
|
||||
final CardListViewer cardView = new CardListViewer(unlockedSet.getName(), "You get the following bonus cards:", cardsWon);
|
||||
cardView.show();
|
||||
cardView.setVisible(true);
|
||||
cardView.dispose();
|
||||
qData.save();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
package forge.view;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.PopupMenu;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.gui.SOverlayUtils;
|
||||
import forge.gui.toolbox.FPanel;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FSkin.Colors;
|
||||
import forge.gui.toolbox.FSkin.CompoundSkinBorder;
|
||||
import forge.gui.toolbox.FSkin.LineSkinBorder;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class FDialog extends JDialog implements ITitleBarOwner {
|
||||
private static final int borderThickness = 3;
|
||||
private static final FSkin.SkinColor borderColor = FSkin.getColor(FSkin.Colors.CLR_BORDERS);
|
||||
private static final int cornerDiameter = 20;
|
||||
|
||||
private FSkin.WindowSkin<FDialog> skin = FSkin.get(this);
|
||||
private Point locBeforeMove;
|
||||
private Point mouseDownLoc;
|
||||
private final FTitleBar titleBar;
|
||||
private final FPanel innerPanel;
|
||||
|
||||
public FDialog() {
|
||||
this(true);
|
||||
@@ -31,19 +39,56 @@ public class FDialog extends JDialog implements ITitleBarOwner {
|
||||
public FDialog(boolean modal0) {
|
||||
super(JOptionPane.getRootFrame(), modal0);
|
||||
this.setUndecorated(true);
|
||||
FSkin.get(this).setIconImage(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FAVICON)); //use Forge icon by default
|
||||
titleBar = new FTitleBar(this);
|
||||
titleBar.setVisible(true);
|
||||
skin.setIconImage(FSkin.getIcon(FSkin.InterfaceIcons.ICO_FAVICON)); //use Forge icon by default
|
||||
|
||||
this.innerPanel = new FPanel(new MigLayout("insets dialog, gap 0, center, fill"));
|
||||
this.innerPanel.setBackgroundTexture(FSkin.getIcon(FSkin.Backgrounds.BG_TEXTURE));
|
||||
this.innerPanel.setBackgroundTextureOverlay(FSkin.getColor(FSkin.Colors.CLR_THEME)); //use theme color as overlay to reduce background texture opacity
|
||||
this.innerPanel.setBorderToggle(false);
|
||||
this.innerPanel.setOpaque(false);
|
||||
super.setContentPane(this.innerPanel);
|
||||
|
||||
this.titleBar = new FTitleBar(this);
|
||||
this.titleBar.setVisible(true);
|
||||
addMoveSupport();
|
||||
FSkin.get(getRootPane()).setBorder(new CompoundSkinBorder(
|
||||
BorderFactory.createLineBorder(Color.BLACK, 1),
|
||||
new LineSkinBorder(FSkin.getColor(Colors.CLR_BORDERS), borderThickness - 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
//set rounded rectangle shape for dialog
|
||||
int width = this.getWidth();
|
||||
int height = this.getHeight();
|
||||
int arc = cornerDiameter - 4; //leave room for border aliasing
|
||||
this.setShape(new RoundRectangle2D.Float(0, 0, width, height, arc, arc));
|
||||
|
||||
super.paint(g);
|
||||
|
||||
//draw rounded border
|
||||
final Graphics2D g2d = (Graphics2D) g.create();
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
skin.setGraphicsColor(g2d, borderColor);
|
||||
g2d.drawRoundRect(0, 0, width - 1, height - 1, cornerDiameter, cornerDiameter);
|
||||
g2d.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
setVisible(false); //ensure overlay hidden when disposing
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVisible(boolean visible) {
|
||||
if (this.isVisible() == visible) { return; }
|
||||
|
||||
if (visible) {
|
||||
setLocationRelativeTo(JOptionPane.getRootFrame());
|
||||
if (isModal()) {
|
||||
SOverlayUtils.showOverlay();
|
||||
}
|
||||
}
|
||||
else if (isModal()) {
|
||||
SOverlayUtils.hideOverlay();
|
||||
}
|
||||
super.setVisible(visible);
|
||||
}
|
||||
@@ -64,6 +109,66 @@ public class FDialog extends JDialog implements ITitleBarOwner {
|
||||
}
|
||||
}
|
||||
|
||||
//relay certain methods to the inner panel if it has been initialized
|
||||
@Override
|
||||
public void setContentPane(Container contentPane) {
|
||||
if (innerPanel != null) {
|
||||
innerPanel.add(contentPane, "w 100%!, h 100%!");
|
||||
}
|
||||
super.setContentPane(contentPane);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component add(Component comp) {
|
||||
if (innerPanel != null) {
|
||||
return innerPanel.add(comp);
|
||||
}
|
||||
return super.add(comp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(PopupMenu popup) {
|
||||
if (innerPanel != null) {
|
||||
innerPanel.add(popup);
|
||||
return;
|
||||
}
|
||||
super.add(popup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Component comp, Object constraints) {
|
||||
if (innerPanel != null) {
|
||||
innerPanel.add(comp, constraints);
|
||||
return;
|
||||
}
|
||||
super.add(comp, constraints);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component add(Component comp, int index) {
|
||||
if (innerPanel != null) {
|
||||
return innerPanel.add(comp, index);
|
||||
}
|
||||
return super.add(comp, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Component comp, Object constraints, int index) {
|
||||
if (innerPanel != null) {
|
||||
innerPanel.add(comp, constraints, index);
|
||||
return;
|
||||
}
|
||||
super.add(comp, constraints, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Component add(String name, Component comp) {
|
||||
if (innerPanel != null) {
|
||||
return innerPanel.add(name, comp);
|
||||
}
|
||||
return super.add(name, comp);
|
||||
}
|
||||
|
||||
private void addMoveSupport() {
|
||||
this.titleBar.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
|
||||
@@ -56,6 +56,7 @@ public class FNavigationBar extends FTitleBarBase {
|
||||
|
||||
public FNavigationBar(FFrame f) {
|
||||
super(f);
|
||||
skin.setMatteBorder(0, 0, 2, 0, bottomEdgeColor);
|
||||
this.setLocation(0, -visibleHeight); //hide by default
|
||||
this.setPreferredSize(new Dimension(this.owner.getWidth(), visibleHeight));
|
||||
btnForge.setFocusable(false);
|
||||
|
||||
@@ -12,6 +12,7 @@ public class FTitleBar extends FTitleBarBase {
|
||||
|
||||
public FTitleBar(ITitleBarOwner owner0) {
|
||||
super(owner0);
|
||||
skin.setMatteBorder(0, 0, 1, 0, bottomEdgeColor);
|
||||
owner0.setJMenuBar(this);
|
||||
setTitle(owner0.getTitle()); //set default title based on frame title
|
||||
setIconImage(owner0.getIconImage()); //set default icon image based on frame icon image
|
||||
@@ -22,7 +23,7 @@ public class FTitleBar extends FTitleBarBase {
|
||||
@Override
|
||||
protected void addControls() {
|
||||
add(lblTitle);
|
||||
layout.putConstraint(SpringLayout.WEST, lblTitle, 1, SpringLayout.WEST, this);
|
||||
layout.putConstraint(SpringLayout.WEST, lblTitle, 5, SpringLayout.WEST, this);
|
||||
layout.putConstraint(SpringLayout.SOUTH, lblTitle, -5, SpringLayout.SOUTH, this);
|
||||
super.addControls();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package forge.view;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
@@ -49,15 +50,14 @@ public abstract class FTitleBarBase extends JMenuBar {
|
||||
setVisible(false); //start out hidden unless frame chooses to show title bar
|
||||
setLayout(this.layout);
|
||||
skin.setBackground(backColor);
|
||||
skin.setMatteBorder(0, 0, 2, 0, bottomEdgeColor);
|
||||
}
|
||||
|
||||
protected void addControls() {
|
||||
add(btnClose);
|
||||
layout.putConstraint(SpringLayout.EAST, btnClose, 0, SpringLayout.EAST, this);
|
||||
layout.putConstraint(SpringLayout.SOUTH, btnClose, 0, SpringLayout.SOUTH, this);
|
||||
|
||||
if (owner instanceof FFrame) { //only support buttons besides Close for frames
|
||||
add(btnClose);
|
||||
layout.putConstraint(SpringLayout.EAST, btnClose, 0, SpringLayout.EAST, this);
|
||||
layout.putConstraint(SpringLayout.SOUTH, btnClose, 0, SpringLayout.SOUTH, this);
|
||||
|
||||
add(btnMaximize);
|
||||
layout.putConstraint(SpringLayout.EAST, btnMaximize, 0, SpringLayout.WEST, btnClose);
|
||||
layout.putConstraint(SpringLayout.SOUTH, btnMaximize, 0, SpringLayout.SOUTH, btnClose);
|
||||
@@ -74,6 +74,11 @@ public abstract class FTitleBarBase extends JMenuBar {
|
||||
layout.putConstraint(SpringLayout.EAST, btnLockTitleBar, 0, SpringLayout.WEST, btnMinimize);
|
||||
layout.putConstraint(SpringLayout.SOUTH, btnLockTitleBar, 0, SpringLayout.SOUTH, btnMinimize);
|
||||
}
|
||||
else {
|
||||
add(btnClose);
|
||||
layout.putConstraint(SpringLayout.EAST, btnClose, -1, SpringLayout.EAST, this);
|
||||
layout.putConstraint(SpringLayout.SOUTH, btnClose, 0, SpringLayout.SOUTH, this);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void setTitle(String title);
|
||||
@@ -172,8 +177,13 @@ public abstract class FTitleBarBase extends JMenuBar {
|
||||
|
||||
@Override
|
||||
public void repaintSelf() {
|
||||
final Dimension d = this.getSize();
|
||||
repaint(0, 0, d.width, d.height);
|
||||
final Container window = FTitleBarBase.this.getParent().getParent().getParent();
|
||||
if (window instanceof FDialog) { //prevent hover effect coverring up rounded border
|
||||
window.repaint(this.getX(), this.getY(), this.getWidth(), this.getHeight());
|
||||
}
|
||||
else {
|
||||
repaint(0, 0, this.getWidth(), this.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isToggled() { //virtual method to override in extended classes
|
||||
|
||||
Reference in New Issue
Block a user