use of mage.view.CardView in project mage by magefree.
the class SelectionBox method deselectAll.
/**
* Deselect all cards in this DragCardGrid
*/
public void deselectAll() {
for (List<List<CardView>> gridRow : cardGrid) {
for (List<CardView> stack : gridRow) {
for (CardView card : stack) {
if (card.isSelected()) {
card.setSelected(false);
cardViews.get(card.getId()).update(card);
}
}
}
}
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method layoutGrid.
/**
* Position all of the card views correctly
*/
private void layoutGrid() {
// Basic dimensions
int cardWidth = getCardWidth();
int cardHeight = getCardHeight();
int cardTopHeight = CardRenderer.getCardTopHeight(cardWidth);
// Layout one at a time
int layerIndex = 0;
int currentY = COUNT_LABEL_HEIGHT;
int maxWidth = 0;
for (int rowIndex = 0; rowIndex < cardGrid.size(); ++rowIndex) {
int rowMaxStackSize = 0;
List<List<CardView>> gridRow = cardGrid.get(rowIndex);
for (int colIndex = 0; colIndex < gridRow.size(); ++colIndex) {
List<CardView> stack = gridRow.get(colIndex);
// Stack count label
if (stackCountLabels.size() <= rowIndex) {
stackCountLabels.add(new ArrayList<>());
}
if (stackCountLabels.get(rowIndex).size() <= colIndex) {
// ENABLE cards auto-selection in the stack
if (this.countLabelListener == null) {
this.countLabelListener = new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
JLabel countLabel = (JLabel) e.getComponent();
List<CardView> cards = findCardStackByCountLabel(countLabel);
boolean selected = !cards.isEmpty() && cards.get(0).isSelected();
cards.forEach(card -> {
card.setSelected(!selected);
cardViews.get(card.getId()).update(card);
});
}
};
}
JLabel countLabel = DragCardGrid.createCountLabel(this.countLabelListener);
cardContent.add(countLabel, (Integer) 0);
stackCountLabels.get(rowIndex).add(countLabel);
}
JLabel countLabel = stackCountLabels.get(rowIndex).get(colIndex);
if (stack.isEmpty()) {
countLabel.setVisible(false);
} else {
String description = cardSort.getComparator().getCategoryName(stack.get(0));
DragCardGrid.updateCountLabel(countLabel, stack.size(), description);
countLabel.setLocation(GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex, currentY - COUNT_LABEL_HEIGHT);
countLabel.setSize(cardWidth, COUNT_LABEL_HEIGHT);
countLabel.setVisible(true);
}
// Max stack size
rowMaxStackSize = Math.max(rowMaxStackSize, stack.size());
// Layout cards in stack
for (int i = 0; i < stack.size(); ++i) {
CardView card = stack.get(i);
MageCard view = cardViews.get(card.getId());
int x = GRID_PADDING + (cardWidth + GRID_PADDING) * colIndex;
int y = currentY + i * cardTopHeight;
view.setCardBounds(x, y, cardWidth, cardHeight);
cardContent.setLayer(view, layerIndex++);
}
}
// Update the max stack size for this row and the max width
maxWidth = Math.max(maxWidth, GRID_PADDING + (GRID_PADDING + cardWidth) * gridRow.size());
maxStackSize.set(rowIndex, rowMaxStackSize);
currentY += (cardTopHeight * (rowMaxStackSize - 1) + cardHeight) + COUNT_LABEL_HEIGHT;
}
// Resize card container
cardContent.setPreferredSize(new Dimension(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING));
// cardContent.setSize(maxWidth, currentY - COUNT_LABEL_HEIGHT + GRID_PADDING);
}
use of mage.view.CardView in project mage by magefree.
the class SelectionBox method invertSelection.
private void invertSelection() {
Collection<CardView> toInvert = allCards;
for (DragCardGridListener l : listeners) {
l.invertCardSelection(toInvert);
for (CardView card : allCards) {
MageCard view = cardViews.get(card.getId());
view.update(card);
}
}
repaint();
}
use of mage.view.CardView in project mage by magefree.
the class ColorPane method addHyperlinkHandlers.
private void addHyperlinkHandlers() {
addHyperlinkListener(e -> ThreadUtils.threadPool2.submit(() -> {
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300) == 0) {
// if disabled
return;
}
// finds extra data in html element like object_id, alternative_name, etc
Map<String, String> extraData = new HashMap<>();
if (e.getSourceElement() instanceof HTMLDocument.RunElement) {
HTMLDocument.RunElement el = (HTMLDocument.RunElement) e.getSourceElement();
Enumeration attNames = el.getAttributeNames();
while (attNames.hasMoreElements()) {
Object attName = attNames.nextElement();
Object attValue = el.getAttribute(attName);
// custom attributes in SimpleAttributeSet element
if (attValue instanceof SimpleAttributeSet) {
SimpleAttributeSet attReal = (SimpleAttributeSet) attValue;
Enumeration attRealNames = attReal.getAttributeNames();
while (attRealNames.hasMoreElements()) {
Object attRealName = attRealNames.nextElement();
Object attRealValue = attReal.getAttribute(attRealName);
String name = attRealName.toString();
String value = attRealValue.toString();
extraData.put(name, value);
}
}
}
}
String cardName = e.getDescription().substring(1);
String alternativeName = CardUtil.urlDecode(extraData.getOrDefault("alternative_name", ""));
if (!alternativeName.isEmpty()) {
cardName = alternativeName;
}
if (e.getEventType() == EventType.ENTERED) {
CardView cardView = null;
// card
CardInfo card = CardRepository.instance.findCards(cardName).stream().findFirst().orElse(null);
if (card != null) {
cardView = new CardView(card.getMockCard());
}
// plane
if (cardView == null) {
Plane plane = Plane.createPlaneByFullName(cardName);
if (plane != null) {
cardView = new CardView(new PlaneView(plane));
}
}
if (cardView != null) {
cardInfo.init(cardView, this.bigCard, this.gameId);
cardInfo.setTooltipDelay(CHAT_TOOLTIP_DELAY_MS);
cardInfo.onMouseEntered(MouseInfo.getPointerInfo().getLocation());
cardInfo.onMouseMoved(MouseInfo.getPointerInfo().getLocation());
}
}
if (e.getEventType() == EventType.EXITED) {
cardInfo.onMouseExited();
}
}));
addMouseListener(new MouseAdapter() {
@Override
public void mouseExited(MouseEvent e) {
cardInfo.onMouseExited();
}
});
}
use of mage.view.CardView in project mage by magefree.
the class TableModel method setNumber.
public void setNumber(int index, int number) {
CardView card = view.get(index);
cardEventSource.fireEvent(card, ClientEventType.SET_NUMBER, number);
}
Aggregations