public void setBackground(Color color) { super.setBackground(color); background = color; if (text != null) text.setBackground(color); if (list != null) list.setBackground(color); if (icon != null) icon.setBackground(color); if (arrow != null) arrow.setBackground(color); }
void createPopup(String[] items, int selectionIndex) { // create shell and list popup = new AlphaDialog(getShell(), SWT.NO_TRIM | SWT.ON_TOP | SWT.BORDER); popup.setBackgroundMode(SWT.INHERIT_DEFAULT); Color borderColor = ColorCache.getInstance().getColor(200, 200, 200); popup.setBackground(borderColor); GridLayout gridLayout = new GridLayout(2, false); gridLayout.marginHeight = 0; gridLayout.marginBottom = 1; gridLayout.marginTop = 0; gridLayout.marginLeft = 0; gridLayout.marginRight = 0; gridLayout.horizontalSpacing = 0; gridLayout.verticalSpacing = 0; gridLayout.marginWidth = 0; popup.getPopup().setLayout(gridLayout); int style = getStyle(); int listStyle = SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER; if ((style & SWT.FLAT) != 0) listStyle |= SWT.FLAT; if ((style & SWT.RIGHT_TO_LEFT) != 0) listStyle |= SWT.RIGHT_TO_LEFT; if ((style & SWT.LEFT_TO_RIGHT) != 0) listStyle |= SWT.LEFT_TO_RIGHT; list = new List(popup.getPopup(), listStyle); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 2; list.setLayoutData(gridData); list.addMouseListener( new MouseAdapter() { public void mouseDown(MouseEvent e) { if (e.button == 3) { text.getMenu().setVisible(true); } if (list.isFocusControl()) return; text.forceFocus(); list.setFocus(); } }); if (font != null) list.setFont(font); if (foreground != null) list.setForeground(foreground); if (background != null) list.setBackground(background); int[] popupEvents = {SWT.Close, SWT.Paint, SWT.Deactivate}; for (int i = 0; i < popupEvents.length; i++) popup.getPopup().addListener(popupEvents[i], listener); int[] listEvents = { SWT.MouseUp, SWT.Selection, SWT.Traverse, SWT.KeyDown, SWT.KeyUp, SWT.FocusIn, SWT.Dispose }; for (int i = 0; i < listEvents.length; i++) list.addListener(listEvents[i], listener); if (items != null) list.setItems(items); if (selectionIndex != -1) list.setSelection(selectionIndex); }