From 5da85b079afaad0ca22ef96a7688b35f7086ce04 Mon Sep 17 00:00:00 2001 From: drdev Date: Sun, 28 Jul 2013 00:50:38 +0000 Subject: [PATCH] Save and restore selected tab for each pane Avoid refreshing entire Deck Editor when opening a deck --- CHANGES.txt | 11 ++- src/main/java/forge/control/FControl.java | 2 + .../java/forge/gui/framework/SLayoutIO.java | 70 +++++++++++++------ .../forge/gui/framework/SRearrangingUtil.java | 12 +++- 4 files changed, 65 insertions(+), 30 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 2517c417a38..9f1622b474d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,14 +8,13 @@ Forge Beta: 07-##-2013 ver 1.4.4 Release Notes ------------- --All Decks updates- -Can double click row for deck to open it (in addition to clicking edit icon) -Fixed bug where hover effect didn't work the first time hovering over a row that had just been deselected - - --Improvements to color/card Type filters +- Deck Editor and General UI improvements - You can now right-click on a color filter button to show only cards of that color, filtering out all other colors. Similar with card type filter buttons. +Can double click row for deck to open it (in addition to clicking edit icon) +The selected tab on each draggable pane will now be remembered between sessions +Fixed bug where hover effect didn't work the first time hovering over a row that had just been deselected Fixed bug where middle and right clicking buttons did the same behavior as left clicking, and fixed bug where clicking multiple buttons quickly (such as filters) while moving the mouse around would result in clicks not registering sometimes. +Fixed bug where entire Deck Editor would refresh when opening a deck (causing Card Catalog to flicker) - Card Zoomer - diff --git a/src/main/java/forge/control/FControl.java b/src/main/java/forge/control/FControl.java index bb7ea1ef320..ad0001ca2d2 100644 --- a/src/main/java/forge/control/FControl.java +++ b/src/main/java/forge/control/FControl.java @@ -205,6 +205,8 @@ public enum FControl { * Switches between display states in top level JFrame. */ public void changeState(Screens screen) { + if (this.state == screen) { return; } + clearChildren(JLayeredPane.DEFAULT_LAYER); this.state = screen; diff --git a/src/main/java/forge/gui/framework/SLayoutIO.java b/src/main/java/forge/gui/framework/SLayoutIO.java index f3b478595de..c3bd02258cb 100644 --- a/src/main/java/forge/gui/framework/SLayoutIO.java +++ b/src/main/java/forge/gui/framework/SLayoutIO.java @@ -46,6 +46,7 @@ public final class SLayoutIO { public final static String y = "y"; public final static String w = "w"; public final static String h = "h"; + public final static String sel = "sel"; public final static String doc = "doc"; } @@ -113,10 +114,13 @@ public final class SLayoutIO { writer.add(TAB); writer.add(EF.createStartElement("", "", "cell")); - writer.add(EF.createAttribute(Property.x.toString(), String.valueOf(Math.rint(bounds.getX() * 100000) / 100000))); - writer.add(EF.createAttribute(Property.y.toString(), String.valueOf(Math.rint(bounds.getY() * 100000) / 100000))); - writer.add(EF.createAttribute(Property.w.toString(), String.valueOf(Math.rint(bounds.getW() * 100000) / 100000))); - writer.add(EF.createAttribute(Property.h.toString(), String.valueOf(Math.rint(bounds.getH() * 100000) / 100000))); + writer.add(EF.createAttribute(Property.x, String.valueOf(Math.rint(bounds.getX() * 100000) / 100000))); + writer.add(EF.createAttribute(Property.y, String.valueOf(Math.rint(bounds.getY() * 100000) / 100000))); + writer.add(EF.createAttribute(Property.w, String.valueOf(Math.rint(bounds.getW() * 100000) / 100000))); + writer.add(EF.createAttribute(Property.h, String.valueOf(Math.rint(bounds.getH() * 100000) / 100000))); + if (cell.getSelected() != null) { + writer.add(EF.createAttribute(Property.sel, cell.getSelected().getDocumentID().toString())); + } writer.add(NEWLINE); for (final IVDoc vDoc : cell.getDocs()) { @@ -157,7 +161,7 @@ public final class SLayoutIO { view.removeAllDragCells(); // Read a model for new layout - MapOfLists model = null; + MapOfLists model = null; boolean usedCustomPrefsFile = false; @@ -206,38 +210,60 @@ public final class SLayoutIO { // Apply new layout - DragCell cell = null; - for(Entry> kv : model.entrySet()) { - cell = new DragCell(); - cell.setRoughBounds(kv.getKey()); + for(Entry> kv : model.entrySet()) { + LayoutInfo layoutInfo = kv.getKey(); + DragCell cell = new DragCell(); + cell.setRoughBounds(layoutInfo.getBounds()); FView.SINGLETON_INSTANCE.addDragCell(cell); for(EDocID edoc : kv.getValue()) { try { -// System.out.println(String.format("adding doc %s -> %s", edoc, edoc.getDoc())); + //System.out.println(String.format("adding doc %s -> %s", edoc, edoc.getDoc())); cell.addDoc(edoc.getDoc()); - } catch (IllegalArgumentException e) { + } + catch (IllegalArgumentException e) { System.err.println("Failed to get doc for " + edoc); } - } - + if (layoutInfo.getSelectedId() != null) { + cell.setSelected(layoutInfo.getSelectedId().getDoc()); + } } // Rough bounds are all in place; resize the window. SResizingUtil.resizeWindow(); } - private static MapOfLists readLayout(final XMLEventReader reader) throws XMLStreamException + private static class LayoutInfo + { + private final RectangleOfDouble bounds; + private final EDocID selectedId; + + public LayoutInfo(RectangleOfDouble bounds0, EDocID selectedId0) { + this.bounds = bounds0; + this.selectedId = selectedId0; + } + + public RectangleOfDouble getBounds() { + return this.bounds; + } + + public EDocID getSelectedId() { + return this.selectedId; + } + } + + private static MapOfLists readLayout(final XMLEventReader reader) throws XMLStreamException { XMLEvent event; StartElement element; Iterator attributes; Attribute attribute; + EDocID selectedId = null; double x0 = 0, y0 = 0, w0 = 0, h0 = 0; - MapOfLists model = new HashMapOfLists(CollectionSuppliers.arrayLists()); + MapOfLists model = new HashMapOfLists(CollectionSuppliers.arrayLists()); - RectangleOfDouble currentKey = null; + LayoutInfo currentKey = null; while (null != reader && reader.hasNext()) { event = reader.nextEvent(); @@ -248,15 +274,15 @@ public final class SLayoutIO { attributes = element.getAttributes(); while (attributes.hasNext()) { attribute = (Attribute) attributes.next(); - double val = Double.parseDouble(attribute.getValue()); String atrName = attribute.getName().toString(); - if (atrName.equals(Property.x)) x0 = val; - else if (atrName.equals(Property.y)) y0 = val; - else if (atrName.equals(Property.w)) w0 = val; - else if (atrName.equals(Property.h)) h0 = val; + if (atrName.equals(Property.x)) x0 = Double.parseDouble(attribute.getValue()); + else if (atrName.equals(Property.y)) y0 = Double.parseDouble(attribute.getValue()); + else if (atrName.equals(Property.w)) w0 = Double.parseDouble(attribute.getValue()); + else if (atrName.equals(Property.h)) h0 = Double.parseDouble(attribute.getValue()); + else if (atrName.equals(Property.sel)) selectedId = EDocID.valueOf(attribute.getValue()); } - currentKey = new RectangleOfDouble(x0, y0, w0, h0); + currentKey = new LayoutInfo(new RectangleOfDouble(x0, y0, w0, h0), selectedId); } else if (element.getName().getLocalPart().equals(Property.doc)) { event = reader.nextEvent(); diff --git a/src/main/java/forge/gui/framework/SRearrangingUtil.java b/src/main/java/forge/gui/framework/SRearrangingUtil.java index 05e483b19e8..5f6e7cd63e5 100644 --- a/src/main/java/forge/gui/framework/SRearrangingUtil.java +++ b/src/main/java/forge/gui/framework/SRearrangingUtil.java @@ -229,8 +229,15 @@ public final class SRearrangingUtil { pnlPreview.setBounds(0, 0, 0, 0); // Source and target are the same? - if (dropzone.equals(Dropzone.NONE)) { return; } - if (cellTarget.equals(cellSrc) && cellSrc.getDocs().size() == 1) { return; } + if (dropzone.equals(Dropzone.NONE) || (cellTarget.equals(cellSrc) && cellSrc.getDocs().size() == 1)) + { + if (srcSelectedDoc != cellSrc.getSelected()) + { + SLayoutIO.saveLayout(null); //still need to save layout if selection changed + } + srcSelectedDoc = null; + return; + } // Prep vals for possible resize tempX = cellTarget.getX(); @@ -300,6 +307,7 @@ public final class SRearrangingUtil { cellTarget.updateRoughBounds(); cellSrc.setSelected(srcSelectedDoc); + srcSelectedDoc = null; cellSrc.refresh(); cellTarget.refresh(); cellNew.validate();