avoid having the keyboard focus jump around when the window is resized

This commit is contained in:
myk
2013-02-17 21:20:19 +00:00
parent bda84323d5
commit 0788fefd2e
2 changed files with 19 additions and 2 deletions

View File

@@ -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();

View File

@@ -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();
@@ -122,6 +124,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 %)
// 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.
cellA.setSmoothX((int) Math.round(cellA.getRoughX() * w));
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);
}
}
// Lock in final bounds and build heads.
for (final DragCell t : cells) {