mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
avoid having the keyboard focus jump around when the window is resized
This commit is contained in:
@@ -300,6 +300,11 @@ public final class DragCell extends JPanel implements ILocalRepaint {
|
|||||||
* @param doc0   {@link forge.gui.framework.IVDoc} tab document.
|
* @param doc0   {@link forge.gui.framework.IVDoc} tab document.
|
||||||
*/
|
*/
|
||||||
public void setSelected(final IVDoc<? extends ICDoc> doc0) {
|
public void setSelected(final IVDoc<? extends ICDoc> doc0) {
|
||||||
|
if (null != doc0 && docSelected == doc0) {
|
||||||
|
// already selected
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
docSelected = null;
|
docSelected = null;
|
||||||
pnlBody.removeAll();
|
pnlBody.removeAll();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package forge.gui.framework;
|
package forge.gui.framework;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
@@ -10,8 +11,10 @@ import java.awt.event.MouseListener;
|
|||||||
import java.awt.event.MouseMotionAdapter;
|
import java.awt.event.MouseMotionAdapter;
|
||||||
import java.awt.event.MouseMotionListener;
|
import java.awt.event.MouseMotionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
@@ -106,7 +109,6 @@ public final class SResizingUtil {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/** */
|
|
||||||
public static void resizeWindow() {
|
public static void resizeWindow() {
|
||||||
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
|
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
|
||||||
final JPanel pnlContent = FView.SINGLETON_INSTANCE.getPnlContent();
|
final JPanel pnlContent = FView.SINGLETON_INSTANCE.getPnlContent();
|
||||||
@@ -122,6 +124,11 @@ public final class SResizingUtil {
|
|||||||
double roughVal = 0;
|
double roughVal = 0;
|
||||||
int smoothVal = 0;
|
int smoothVal = 0;
|
||||||
|
|
||||||
|
Set<Component> existingComponents = new HashSet<Component>();
|
||||||
|
for (Component c : pnlContent.getComponents()) {
|
||||||
|
existingComponents.add(c);
|
||||||
|
}
|
||||||
|
|
||||||
// This is the core of the pixel-perfect layout. To avoid <20>1 px errors on borders
|
// This is the core of the pixel-perfect layout. To avoid <20>1 px errors on borders
|
||||||
// from rounding individual panels, the intermediate values (exactly accurate, in %)
|
// from rounding individual panels, the intermediate values (exactly accurate, in %)
|
||||||
// for width and height are rounded based on comparison to other panels in the
|
// for width and height are rounded based on comparison to other panels in the
|
||||||
@@ -151,8 +158,13 @@ public final class SResizingUtil {
|
|||||||
// X and Y coordinate can be rounded as usual.
|
// X and Y coordinate can be rounded as usual.
|
||||||
cellA.setSmoothX((int) Math.round(cellA.getRoughX() * w));
|
cellA.setSmoothX((int) Math.round(cellA.getRoughX() * w));
|
||||||
cellA.setSmoothY((int) Math.round(cellA.getRoughY() * h));
|
cellA.setSmoothY((int) Math.round(cellA.getRoughY() * h));
|
||||||
|
|
||||||
|
// only add component if not already in container; otherwise the keyboard focus
|
||||||
|
// jumps around to the most recenly added component
|
||||||
|
if (!existingComponents.contains(cellA)) {
|
||||||
pnlContent.add(cellA);
|
pnlContent.add(cellA);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Lock in final bounds and build heads.
|
// Lock in final bounds and build heads.
|
||||||
for (final DragCell t : cells) {
|
for (final DragCell t : cells) {
|
||||||
|
|||||||
Reference in New Issue
Block a user