mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18: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.
|
||||
*/
|
||||
public void setSelected(final IVDoc<? extends ICDoc> doc0) {
|
||||
if (null != doc0 && docSelected == doc0) {
|
||||
// already selected
|
||||
return;
|
||||
}
|
||||
|
||||
docSelected = null;
|
||||
pnlBody.removeAll();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge.gui.framework;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
@@ -10,8 +11,10 @@ import java.awt.event.MouseListener;
|
||||
import java.awt.event.MouseMotionAdapter;
|
||||
import java.awt.event.MouseMotionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
@@ -106,7 +109,6 @@ public final class SResizingUtil {
|
||||
}
|
||||
};
|
||||
|
||||
/** */
|
||||
public static void resizeWindow() {
|
||||
final List<DragCell> cells = FView.SINGLETON_INSTANCE.getDragCells();
|
||||
final JPanel pnlContent = FView.SINGLETON_INSTANCE.getPnlContent();
|
||||
@@ -121,6 +123,11 @@ public final class SResizingUtil {
|
||||
|
||||
double roughVal = 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
|
||||
// from rounding individual panels, the intermediate values (exactly accurate, in %)
|
||||
@@ -151,7 +158,12 @@ public final class SResizingUtil {
|
||||
// X and Y coordinate can be rounded as usual.
|
||||
cellA.setSmoothX((int) Math.round(cellA.getRoughX() * w));
|
||||
cellA.setSmoothY((int) Math.round(cellA.getRoughY() * h));
|
||||
pnlContent.add(cellA);
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
// Lock in final bounds and build heads.
|
||||
|
||||
Reference in New Issue
Block a user