frame.setLocation(frame.getLocation().x + me.getX() - pX, frame.getLocation().y + me.getY() - pY); public void mouseDragged(MouseEvent me) { frame.setLocation(frame.getLocation().x + me.getX() - pX, frame.getLocation().y + me.getY() - pY);
private void sort(CardPanel card, JPanel container, boolean sortSource) { java.util.List<CardPanel> cards = new ArrayList<>(); for (Component component : container.getComponents()) { if (component instanceof CardPanel) { if (!component.equals(card)) { if (!cardPanels.contains(component)) { component.setLocation(component.getLocation().x, component.getLocation().y + GO_DOWN_ON_DRAG_Y_OFFSET); } cardPanels.add((CardPanel) component); } else if (!startedDragging) { component.setLocation(component.getLocation().x, component.getLocation().y - GO_UP_ON_DRAG_Y_OFFSET); } cards.add((CardPanel) component); } } sortLayout(cards, card, sortSource); }
@Override public void componentMoved(ComponentEvent ce) { mw.settings.getVisualizerWindowSettings().xLocation = ce.getComponent().getLocation().x; mw.settings.getVisualizerWindowSettings().yLocation = ce.getComponent().getLocation().y; }
private void definePosition(MageCard card) { int dx = 0; for (Component comp : cardArea.getComponents()) { if (!comp.equals(card)) { dx = Math.max(dx, (int) comp.getLocation().getX()); } } dx += ((CardPanel) card).getCardWidth() + GAP_X; card.setLocation(dx, (int) card.getLocation().getY()); }
@Override public void componentMoved(ComponentEvent ce) { mw.settings.getMainWindowSettings().xLocation = ce.getComponent().getLocation().x; mw.settings.getMainWindowSettings().yLocation = ce.getComponent().getLocation().y; }
@Override public void mousePressed(MouseEvent e, TransferData data) { data.component.requestFocusInWindow(); // for some reason sometime mouseRelease happens before numerous Mouse_Dragged events // that results in not finished dragging clearDragging(this.prevCardPanel); isDragging = false; startedDragging = false; prevCardPanel = null; cardPanels.clear(); Point mouse = new Point(e.getX(), e.getY()); SwingUtilities.convertPointToScreen(mouse, data.component); initialMousePos = new Point((int) mouse.getX(), (int) mouse.getY()); initialCardPos = data.component.getLocation(); // Closes popup & enlarged view if a card/Permanent is selected hideTooltipPopup(); }
private void layoutCards() { java.util.List<CardPanel> cardsToLayout = new ArrayList<>(); // get all the card panels for (Component component : cardArea.getComponents()) { if (component instanceof CardPanel) { cardsToLayout.add((CardPanel) component); } } // sort the cards cardsToLayout.sort((cp1, cp2) -> Integer.valueOf(cp1.getLocation().x).compareTo(cp2.getLocation().x)); // relocate the cards int dx = 0; for (Component component : cardsToLayout) { component.setLocation(dx, Math.max(component.getLocation().y, minOffsetY)); dx += ((CardPanel) component).getCardWidth() + GAP_X; } }
@Override public void componentMoved(ComponentEvent ce) { mw.backend.getSettings().getMainWindowSettings().xLocation = ce.getComponent().getLocation().x; mw.backend.getSettings().getMainWindowSettings().yLocation = ce.getComponent().getLocation().y; }
private void clearDragging(CardPanel card) { if (this.startedDragging && prevCardPanel != null && card != null) { for (Component component : card.getCardArea().getComponents()) { if (component instanceof CardPanel) { if (cardPanels.contains(component)) { component.setLocation(component.getLocation().x, component.getLocation().y - GO_DOWN_ON_DRAG_Y_OFFSET); } } } card.setLocation(card.getLocation().x, card.getLocation().y + GO_UP_ON_DRAG_Y_OFFSET); sort(card, card.getCardArea(), true); cardPanels.clear(); } prevCardPanel = null; }
if (continuousLayout == true) { Dimension d = getSize(); Point splitterPos = splitter.getLocation(); e.translatePoint(splitterPos.x, splitterPos.y);
private void sortLayout(List<CardPanel> cards, CardPanel source, boolean includeSource) { source.getLocation().x -= COMPARE_GAP_X; // this creates nice effect cards.sort((cp1, cp2) -> Integer.valueOf(cp1.getLocation().x).compareTo(cp2.getLocation().x)); int dx = 0; boolean createdGapForSource = false; for (Component component : cards) { if (!includeSource) { if (!component.equals(source)) { component.setLocation(dx, component.getLocation().y); dx += ((CardPanel) component).getCardWidth() + GAP_X; // once dx is bigger than source's x position // we need to create a gap for the source card // but only once if (!createdGapForSource && (dx + COMPARE_GAP_X) > source.getLocation().x) { createdGapForSource = true; dx += ((CardPanel) component).getCardWidth() + GAP_X; } } } else { component.setLocation(dx, component.getLocation().y); dx += ((CardPanel) component).getCardWidth() + GAP_X; } } }
Point parentLocation = c.getParent().getLocation(); xAdjustment = parentLocation.x - e.getX(); yAdjustment = parentLocation.y - e.getY();
label.setText(p.draggingLabel.getText()); window.pack(); Point pt = p.draggingLabel.getLocation(); SwingUtilities.convertPointToScreen(pt, p); window.setLocation(pt);
final Point p1 = componentOld.getLocation(); final Point p2 = new Point(0, 0); if (slideType == LEFT) {
location = ((Visual) destination).getActualLocation(); }else{ location = destination.getLocation();
private boolean isVisible(Component comp, Rectangle rect) { if (rect == null) { rect = toolbar.getVisibleRect(); } return comp.getLocation().x + comp.getWidth() <= rect.getWidth(); }
public static Point getPositionRelativeTo(Component root, Component comp) { if (comp.equals(root)) { return new Point(0,0); } Point pos = comp.getLocation(); Point parentOff = getPositionRelativeTo(root, comp.getParent()); return new Point(pos.x + parentOff.x, pos.y + parentOff.y); }
public static void center(Component component, Component component1) { if (component1 == null) { center(component); } else { center(component, component1.getLocation(), component1.getSize()); } }
@Override public void componentMoved(ComponentEvent e) { if (!target.isGuiActive()) return; Point np = e.getComponent().getLocation(); if (np.x == last_known_location.x && np.y == last_known_location.y) return; last_known_location = np; target.notifyMoved(); }
public void relocate(Component c) { if (c.getX()<0 || c.getY()<0) { Point t = c.getLocation(); if (t.x<0) t.x=0; if (t.y<0) t.y=0; c.setLocation(t); invalidate(); } } }