third attempt at a cross-platform algorithm for resizing popup panels

This commit is contained in:
myk
2013-02-12 18:16:46 +00:00
parent e3d25596c3
commit 8f50038a1d

View File

@@ -18,6 +18,7 @@
package forge.gui.deckeditor; package forge.gui.deckeditor;
import java.awt.Color; import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Point; import java.awt.Point;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
@@ -266,12 +267,26 @@ public enum CDeckEditorUI implements CardContainer {
this.tableView = tableView; this.tableView = tableView;
} }
private Component _getPopupRoot() {
Component root = SwingUtilities.getRoot(popupLabel);
if (null == root) {
// manually locate root ancestor (required on platforms that don't use a HeavyWeightWindow for the popup)
// note that this method does not work when SwingUtilities.getRoot() returns non-null since in that case
// this would return the application window root, not the popup root.
root = popupLabel;
while (null != root.getParent()) {
root = root.getParent();
}
}
return root;
}
private void _setPopupSize() { private void _setPopupSize() {
// resize popup to size of label (ensure there's room for the next character so the label // resize popup to size of label (ensure there's room for the next character so the label
// doesn't show '...' in the time between when we set the text and when we increase the size // doesn't show '...' in the time between when we set the text and when we increase the size
Dimension labelDimension = popupLabel.getPreferredSize(); Dimension labelDimension = popupLabel.getPreferredSize();
Dimension popupDimension = new Dimension(labelDimension.width + 12, labelDimension.height + 4); Dimension popupDimension = new Dimension(labelDimension.width + 12, labelDimension.height + 4);
SwingUtilities.getRoot(popupLabel).setSize(popupDimension); _getPopupRoot().setSize(popupDimension);
} }
private void _findNextMatch(int startIdx) { private void _findNextMatch(int startIdx) {
@@ -317,7 +332,7 @@ public enum CDeckEditorUI implements CardContainer {
PopupFactory factory = PopupFactory.getSharedInstance(); PopupFactory factory = PopupFactory.getSharedInstance();
Point tableLoc = tableView.getTable().getTableHeader().getLocationOnScreen(); Point tableLoc = tableView.getTable().getTableHeader().getLocationOnScreen();
popup = factory.getPopup(tableView.getTable(), popupLabel, tableLoc.x + 10, tableLoc.y + 10); popup = factory.getPopup(tableView.getTable(), popupLabel, tableLoc.x + 10, tableLoc.y + 10);
SwingUtilities.getRoot(popupLabel).setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE)); _getPopupRoot().setBackground(FSkin.getColor(FSkin.Colors.CLR_INACTIVE));
popupTimer = new Timer(5000, new ActionListener() { popupTimer = new Timer(5000, new ActionListener() {
@Override @Override