public void mouseEnter(MouseEvent e) { if (entered == 0) { root.addPaintListener(painter); setBackground(root, ColorUtil.get(220, 220, 255)); } entered++; }
private static class SelectableMouseTrackListener implements MouseTrackListener { SelectableMouseTrackListener(Control root) { this.root = root; initialBg = root.getBackground(); root.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { SelectableMouseTrackListener.this.root = null; border = null; painter = null; initialBg = null; } }); } private Control root; private Color initialBg; private BorderStyle border = new BorderStyle.SimpleLine(ColorUtil.get(180, 180, 255), 1); private PaintListener painter = new PaintListener() { public void paintControl(PaintEvent e) { border.paint(e, 0); } }; private int entered = 0; public void mouseEnter(MouseEvent e) { if (entered == 0) { root.addPaintListener(painter); setBackground(root, ColorUtil.get(220, 220, 255)); } entered++; } public void mouseExit(MouseEvent e) { if (--entered == 0) { root.removePaintListener(painter); setBackground(root, initialBg); } } public void mouseHover(MouseEvent e) {} }
@Override protected Composite createControl(Composite container) { container.setBackground(ColorUtil.getWhite()); Composite panel = UIUtil.newGridComposite(container, 0, 0, 1); int lang = recent.get(0).getValue2(); Composite header = UIUtil.newGridComposite(panel, 2, 2, 2); UIUtil.gridDataHorizFill(header); UIUtil.newImage(header, EclipseImages.getImage(EclipsePlugin.ID, "cd-dvd.jpg")); text = new LCMLText(header, false, false); text.setText(_text[lang]); GridData gd = new GridData(); gd.widthHint = 350; text.setLayoutData(gd); Composite body = UIUtil.newGridComposite(panel, 2, 2, 3); UIUtil.gridDataHorizFill(body); labelDataBase = UIUtil.newLabel(body, _database[lang]); comboDataBase = new Combo(body, SWT.DROP_DOWN); for (Pair<String, Integer> p : recent) comboDataBase.add(p.getValue1()); comboDataBase.select(0); comboDataBase.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { refresh(true); } }); comboDataBase.addModifyListener( new ModifyListener() { public void modifyText(ModifyEvent e) { refresh(true); } }); comboDataBase.setLayoutData(UIUtil.gridDataHoriz(1, true)); buttonBrowse = UIUtil.newButton( body, _browse[lang], new Listener<Object>() { public void fire(Object event) { DirectoryDialog dlg = new DirectoryDialog(getShell()); String result = dlg.open(); if (result != null) { comboDataBase.setText(result); refresh(true); } } }, null); labelLanguage = UIUtil.newLabel(body, _language[lang]); comboLanguage = new Combo(body, SWT.DROP_DOWN | SWT.READ_ONLY); comboLanguage.add("English"); comboLanguage.add("Français"); comboLanguage.select(lang); comboLanguage.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { refresh(false); } }); UIUtil.newSeparator(panel, true, true); Composite footer = UIUtil.newGridComposite(panel, 2, 2, 2, 40, 0); gd = new GridData(); gd.horizontalAlignment = SWT.CENTER; footer.setLayoutData(gd); buttonOk = new Button(footer, SWT.PUSH); buttonOk.setText(_ok[lang]); buttonCancel = new Button(footer, SWT.PUSH); buttonCancel.setText(_cancel[lang]); buttonOk.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { selectedDir = comboDataBase.getText(); if (selectedDir.length() == 0) return; selectedLang = comboLanguage.getSelectionIndex(); if (selectedLang < 0) return; ok = true; close(); } }); buttonCancel.addSelectionListener( new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) {} public void widgetSelected(SelectionEvent e) { ok = false; close(); } }); return panel; }
private void setValid(boolean valid) { text.setBackground(valid ? ColorUtil.getWhite() : ColorUtil.getOrange()); }