package com.apple.laf;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.plaf.basic.BasicComboPopup;
import sun.lwawt.macosx.CPlatformWindow;
class extends BasicComboPopup {
static final int = 6;
static final int = 6;
static final int = 5;
protected Component ;
protected Component ;
protected boolean = false;
public (final JComboBox cBox) {
super(cBox);
}
@Override
protected void () {
super.configurePopup();
setBorderPainted(false);
setBorder(null);
updateContents(false);
putClientProperty(CPlatformWindow.WINDOW_FADE_OUT, new Integer(150));
}
public void (final boolean remove) {
isPopDown = isPopdown();
if (isPopDown) {
if (remove) {
if (topStrut != null) {
this.remove(topStrut);
}
if (bottomStrut != null) {
this.remove(bottomStrut);
}
} else {
add(scroller);
}
} else {
if (topStrut == null) {
topStrut = Box.createVerticalStrut(4);
bottomStrut = Box.createVerticalStrut(4);
}
if (remove) remove(scroller);
this.add(topStrut);
this.add(scroller);
this.add(bottomStrut);
}
}
protected Dimension (final int maxRowCount) {
final int currentElementCount = comboBox.getModel().getSize();
final int rowCount = Math.min(maxRowCount, currentElementCount);
final Dimension popupSize = new Dimension();
final ListCellRenderer renderer = list.getCellRenderer();
for (int i = 0; i < rowCount; i++) {
final Object value = list.getModel().getElementAt(i);
final Component c = renderer.getListCellRendererComponent(list, value, i, false, false);
final Dimension prefSize = c.getPreferredSize();
popupSize.height += prefSize.height;
popupSize.width = Math.max(prefSize.width, popupSize.width);
}
popupSize.width += 10;
return popupSize;
}
protected boolean () {
return comboBox.getItemCount() > comboBox.getMaximumRowCount();
}
protected boolean () {
return shouldScroll() || AquaComboBoxUI.isPopdown(comboBox);
}
@Override
public void () {
final int startItemCount = comboBox.getItemCount();
final Rectangle popupBounds = adjustPopupAndGetBounds();
if (popupBounds == null) return;
comboBox.firePopupMenuWillBecomeVisible();
show(comboBox, popupBounds.x, popupBounds.y);
final int afterShowItemCount = comboBox.getItemCount();
if (afterShowItemCount == 0) {
hide();
return;
}
if (startItemCount != afterShowItemCount) {
final Rectangle newBounds = adjustPopupAndGetBounds();
list.setSize(newBounds.width, newBounds.height);
pack();
final Point newLoc = comboBox.getLocationOnScreen();
setLocation(newLoc.x + newBounds.x, newLoc.y + newBounds.y);
}
list.requestFocusInWindow();
}
@Override
protected JList () {
return new JList(comboBox.getModel()) {
@Override
public void (MouseEvent e) {
if (e.isMetaDown()) {
e = new MouseEvent((Component)e.getSource(), e.getID(), e.getWhen(), e.getModifiers() ^ InputEvent.META_MASK, e.getX(), e.getY(), e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), MouseEvent.NOBUTTON);
}
super.processMouseEvent(e);
}
};
}
protected Rectangle adjustPopupAndGetBounds() {
if (isPopDown != isPopdown()) {
updateContents(true);
}
final Dimension popupSize = getBestPopupSizeForRowCount(comboBox.getMaximumRowCount());
final Rectangle popupBounds = computePopupBounds(0, comboBox.getBounds().height, popupSize.width, popupSize.height);
if (popupBounds == null) return null;
final Dimension realPopupSize = popupBounds.getSize();
scroller.setMaximumSize(realPopupSize);
scroller.setPreferredSize(realPopupSize);
scroller.setMinimumSize(realPopupSize);
list.invalidate();
final int selectedIndex = comboBox.getSelectedIndex();
if (selectedIndex == -1) {
list.clearSelection();
} else {
list.setSelectedIndex(selectedIndex);
}
list.ensureIndexIsVisible(list.getSelectedIndex());
return popupBounds;
}
Rectangle (final Point p) {
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final GraphicsDevice[] gs = ge.getScreenDevices();
final Rectangle comboBoxBounds = comboBox.getBounds();
if (gs.length == 1) {
final Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
if ((p.x + comboBoxBounds.width < 0) || (p.y + comboBoxBounds.height < 0) || (p.x > scrSize.width) || (p.y > scrSize.height)) {
return null;
}
return new Rectangle(0, 22, scrSize.width, scrSize.height - 22);
}
for (final GraphicsDevice gd : gs) {
final GraphicsConfiguration[] gc = gd.getConfigurations();
for (final GraphicsConfiguration element0 : gc) {
final Rectangle gcBounds = element0.getBounds();
if (gcBounds.contains(p)) return gcBounds;
}
}
comboBoxBounds.setLocation(p);
for (final GraphicsDevice gd : gs) {
final GraphicsConfiguration[] gc = gd.getConfigurations();
for (final GraphicsConfiguration element0 : gc) {
final Rectangle gcBounds = element0.getBounds();
if (gcBounds.intersects(comboBoxBounds)) return gcBounds;
}
}
return null;
}
@Override
protected Rectangle (int px, int py, int pw, int ph) {
final int itemCount = comboBox.getModel().getSize();
final boolean isPopdown = isPopdown();
final boolean isTableCellEditor = AquaComboBoxUI.isTableCellEditor(comboBox);
if (isPopdown && !isTableCellEditor) {
py = Math.min((py / 2) + 9, py);
}
final Point p = new Point(0, 0);
SwingUtilities.convertPointToScreen(p, comboBox);
final Rectangle scrBounds = getBestScreenBounds(p);
if (scrBounds == null) return super.computePopupBounds(px, py, pw, ph);
final Insets comboBoxInsets = comboBox.getInsets();
final Rectangle comboBoxBounds = comboBox.getBounds();
if (shouldScroll()) {
pw += 15;
}
if (isPopdown) {
pw += 4;
}
final int minWidth = comboBoxBounds.width - (comboBoxInsets.left + comboBoxInsets.right);
pw = Math.max(minWidth, pw);
final boolean leftToRight = AquaUtils.isLeftToRight(comboBox);
if (leftToRight) {
px += comboBoxInsets.left;
if (!isPopDown) px -= FOCUS_RING_PAD_LEFT;
} else {
px = comboBoxBounds.width - pw - comboBoxInsets.right;
if (!isPopDown) px += FOCUS_RING_PAD_RIGHT;
}
py -= (comboBoxInsets.bottom);
p.x += px;
p.y += py;
if (p.x < scrBounds.x) px -= (p.x + scrBounds.x);
if (p.y < scrBounds.y) py -= (p.y + scrBounds.y);
final Point top = new Point(0, 0);
SwingUtilities.convertPointFromScreen(top, comboBox);
final int maxWidth = Math.min(scrBounds.width, top.x + scrBounds.x + scrBounds.width) - 2;
pw = Math.min(maxWidth, pw);
if (pw < minWidth) {
px -= (minWidth - pw);
pw = minWidth;
}
if (!isPopdown) {
pw -= 6;
return computePopupBoundsForMenu(px, py, pw, ph, itemCount, scrBounds);
}
if (!isTableCellEditor) {
pw -= (FOCUS_RING_PAD_LEFT + FOCUS_RING_PAD_RIGHT);
if (leftToRight) {
px += FOCUS_RING_PAD_LEFT;
}
}
final Rectangle r = new Rectangle(px, py, pw, ph);
if (r.y + r.height < top.y + scrBounds.y + scrBounds.height) return r;
return new Rectangle(px, -r.height + comboBoxInsets.top, r.width, r.height);
}
protected Rectangle (final int px, final int py, final int pw, final int ph, final int itemCount, final Rectangle scrBounds) {
int elementSize = 0;
if (list != null && itemCount > 0) {
final Rectangle cellBounds = list.getCellBounds(0, 0);
if (cellBounds != null) elementSize = cellBounds.height;
}
int offsetIndex = comboBox.getSelectedIndex();
if (offsetIndex < 0) offsetIndex = 0;
list.setSelectedIndex(offsetIndex);
final int selectedLocation = elementSize * offsetIndex;
final Point top = new Point(0, scrBounds.y);
final Point bottom = new Point(0, scrBounds.y + scrBounds.height - 20);
SwingUtilities.convertPointFromScreen(top, comboBox);
SwingUtilities.convertPointFromScreen(bottom, comboBox);
final Rectangle popupBounds = new Rectangle(px, py, pw, ph);
final int theRest = ph - selectedLocation;
final boolean extendsOffscreenAtTop = selectedLocation > -top.y;
final boolean extendsOffscreenAtBottom = theRest > bottom.y;
if (extendsOffscreenAtTop) {
popupBounds.y = top.y + 1;
popupBounds.y = (popupBounds.y / elementSize) * elementSize;
} else if (extendsOffscreenAtBottom) {
popupBounds.y = bottom.y - popupBounds.height;
} else {
popupBounds.y = -selectedLocation;
}
final int height = comboBox.getHeight();
final Insets insets = comboBox.getInsets();
final int buttonSize = height - (insets.top + insets.bottom);
final int diff = (buttonSize - elementSize) / 2 + insets.top;
popupBounds.y += diff - FOCUS_RING_PAD_BOTTOM;
return popupBounds;
}
}