Search in sources :

Example 71 with ControlListener

use of org.eclipse.swt.events.ControlListener in project netxms by netxms.

the class MainWindow method createContents.

/**
 * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
 */
@Override
protected Control createContents(Composite parent) {
    Font font = ThemeEngine.getFont("TopMenu");
    windowContent = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    layout.numColumns = verticalLayout ? 2 : 1;
    windowContent.setLayout(layout);
    Composite menuArea = new Composite(windowContent, SWT.NONE);
    layout = new GridLayout();
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = verticalLayout ? 1 : 2;
    menuArea.setLayout(layout);
    GridData gd = new GridData();
    if (verticalLayout) {
        gd.grabExcessVerticalSpace = true;
        gd.verticalAlignment = SWT.FILL;
        gd.verticalSpan = 2;
    } else {
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
    }
    menuArea.setLayoutData(gd);
    Label appLogo = new Label(menuArea, SWT.CENTER);
    appLogo.setImage(ResourceManager.getImage("icons/app_logo.png"));
    appLogo.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    mainMenu = new ToolBar(menuArea, SWT.FLAT | SWT.WRAP | SWT.RIGHT | (verticalLayout ? SWT.VERTICAL : SWT.HORIZONTAL));
    mainMenu.setFont(font);
    gd = new GridData();
    if (verticalLayout) {
        gd.grabExcessVerticalSpace = true;
        gd.verticalAlignment = SWT.FILL;
    } else {
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.FILL;
    }
    mainMenu.setLayoutData(gd);
    toolsMenu = new ToolBar(menuArea, SWT.FLAT | SWT.WRAP | SWT.RIGHT | (verticalLayout ? SWT.VERTICAL : SWT.HORIZONTAL));
    toolsMenu.setFont(font);
    ToolItem userMenu = new ToolItem(toolsMenu, SWT.PUSH);
    userMenu.setImage(ResourceManager.getImage("icons/user-menu.png"));
    NXCSession session = Registry.getSession();
    if (verticalLayout)
        userMenu.setToolTipText(session.getUserName() + "@" + session.getServerName());
    else
        userMenu.setText(session.getUserName() + "@" + session.getServerName());
    userMenu.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            Rectangle bounds = userMenu.getBounds();
            showUserMenu(toolsMenu.toDisplay(verticalLayout ? new Point(bounds.x + bounds.width + 2, bounds.y) : new Point(bounds.x, bounds.y + bounds.height + 2)));
        }
    });
    ToolItem appPreferencesMenu = new ToolItem(toolsMenu, SWT.PUSH);
    appPreferencesMenu.setImage(ResourceManager.getImage("icons/preferences.png"));
    appPreferencesMenu.setToolTipText("Console preferences");
    appPreferencesMenu.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showPreferences();
        }
    });
    messageArea = new MessageArea(windowContent, SWT.NONE);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    messageArea.setLayoutData(gd);
    perspectiveArea = new Composite(windowContent, SWT.NONE);
    gd = new GridData();
    gd.grabExcessHorizontalSpace = true;
    gd.grabExcessVerticalSpace = true;
    gd.horizontalAlignment = SWT.FILL;
    gd.verticalAlignment = SWT.FILL;
    perspectiveArea.setLayoutData(gd);
    perspectiveArea.addControlListener(new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            resizePerspectiveAreaContent();
        }

        @Override
        public void controlMoved(ControlEvent e) {
        }
    });
    setupPerspectiveSwitcher();
    final Display display = parent.getDisplay();
    display.addFilter(SWT.KeyDown, new Listener() {

        @Override
        public void handleEvent(Event e) {
            if (// Only process keystrokes directed to this window
            getShell() == display.getActiveShell())
                processKeyDownEvent(e.stateMask, e.keyCode);
        }
    });
    switchToPerspective("Pinboard");
    switchToPerspective(PreferenceStore.getInstance().getAsString("MainWindow.CurrentPerspective"));
    String motd = session.getMessageOfTheDay();
    if ((motd != null) && !motd.isEmpty())
        addMessage(MessageArea.INFORMATION, session.getMessageOfTheDay());
    return windowContent;
}
Also used : MessageArea(org.netxms.nxmc.base.widgets.MessageArea) NXCSession(org.netxms.client.NXCSession) DisposeListener(org.eclipse.swt.events.DisposeListener) ControlListener(org.eclipse.swt.events.ControlListener) Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) ToolBar(org.eclipse.swt.widgets.ToolBar) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlListener(org.eclipse.swt.events.ControlListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ControlEvent(org.eclipse.swt.events.ControlEvent) ToolItem(org.eclipse.swt.widgets.ToolItem) Display(org.eclipse.swt.widgets.Display)

Example 72 with ControlListener

use of org.eclipse.swt.events.ControlListener in project janrufmonitor by tbrandt77.

the class AbstractApplication method configureShell.

protected void configureShell(Shell shell) {
    super.configureShell(shell);
    shell.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
            internalSavePosition(e.display.getActiveShell());
            storeConfiguration();
        }

        public void controlResized(ControlEvent e) {
            internalSavePosition(e.display.getActiveShell());
            storeConfiguration();
        }
    });
    boolean isMaximized = (this.getConfiguration().getProperty(CFG_MAXIMIZED, "false").equalsIgnoreCase("true") ? true : false);
    if (isMaximized) {
        shell.setMaximized(true);
    } else {
        shell.setMaximized(false);
        shell.setBounds(Integer.parseInt(this.getConfiguration().getProperty(CFG_POSITION_X, "0")), Integer.parseInt(this.getConfiguration().getProperty(CFG_POSITION_Y, "0")), Integer.parseInt(this.getConfiguration().getProperty(CFG_WIDTH, "800")), Integer.parseInt(this.getConfiguration().getProperty(CFG_HEIGHT, "600")));
    }
    shell.setText(this.getI18nManager().getString(this.getNamespace(), "title", "label", this.getLanguage()));
    shell.setImage(this.getIcon());
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Example 73 with ControlListener

use of org.eclipse.swt.events.ControlListener in project eclipse.platform.swt by eclipse-platform.

the class Test_org_eclipse_swt_widgets_Control method test_addControlListenerControlMovedAdapterLorg_eclipse_swt_events_ControlListener.

@Test
public void test_addControlListenerControlMovedAdapterLorg_eclipse_swt_events_ControlListener() {
    ControlListener listener = ControlListener.controlMovedAdapter(e -> eventOccurred = true);
    control.addControlListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.Move, new Event());
    assertTrue(eventOccurred);
    eventOccurred = false;
    control.notifyListeners(SWT.Resize, new Event());
    assertFalse(eventOccurred);
    control.removeControlListener(listener);
    eventOccurred = false;
    control.notifyListeners(SWT.Move, new Event());
    assertFalse(eventOccurred);
    control.notifyListeners(SWT.Resize, new Event());
    assertFalse(eventOccurred);
}
Also used : ControlListener(org.eclipse.swt.events.ControlListener) FocusEvent(org.eclipse.swt.events.FocusEvent) Event(org.eclipse.swt.widgets.Event) ControlEvent(org.eclipse.swt.events.ControlEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) Test(org.junit.Test)

Example 74 with ControlListener

use of org.eclipse.swt.events.ControlListener in project eclipse.platform.swt by eclipse-platform.

the class Bug97863_TableColumnDragging method main.

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setBounds(10, 10, 400, 400);
    final Table tree = new Table(shell, SWT.NONE);
    tree.setBounds(10, 10, 300, 300);
    tree.setHeaderVisible(true);
    ControlListener controlListener = new ControlListener() {

        @Override
        public void controlResized(ControlEvent e) {
            System.out.println("column resized: " + e.widget);
        }

        @Override
        public void controlMoved(ControlEvent e) {
            System.out.println("column moved: " + e.widget);
        }
    };
    TableColumn column = new TableColumn(tree, SWT.NONE);
    column.setWidth(50);
    column.setText("col 0");
    column.setMoveable(true);
    column.addControlListener(controlListener);
    column = new TableColumn(tree, SWT.NONE);
    column.setWidth(50);
    column.setText("col 1");
    column.setMoveable(true);
    column.addControlListener(controlListener);
    column = new TableColumn(tree, SWT.NONE);
    column.setWidth(50);
    column.setText("col 2");
    column.setMoveable(true);
    column.addControlListener(controlListener);
    column = new TableColumn(tree, SWT.NONE);
    column.setWidth(50);
    column.setText("col 3");
    column.setMoveable(true);
    column.addControlListener(controlListener);
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}
Also used : Shell(org.eclipse.swt.widgets.Shell) Table(org.eclipse.swt.widgets.Table) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) Display(org.eclipse.swt.widgets.Display)

Example 75 with ControlListener

use of org.eclipse.swt.events.ControlListener in project eclipse.pde by eclipse-pde.

the class RepositoryReferenceSection method createClient.

@Override
protected void createClient(Section section, FormToolkit toolkit) {
    fModel = (ISiteModel) getPage().getModel();
    fModel.addModelChangedListener(this);
    section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
    GridData sectionData = new GridData(GridData.FILL_BOTH);
    sectionData.verticalSpan = 2;
    section.setLayoutData(sectionData);
    Composite container = createClientContainer(section, 2, toolkit);
    createViewerPartControl(container, SWT.MULTI | SWT.FULL_SELECTION, 2, toolkit);
    container.setLayoutData(new GridData(GridData.FILL_BOTH));
    TablePart tablePart = getTablePart();
    fRepositoryTable = tablePart.getTableViewer();
    final Table table = fRepositoryTable.getTable();
    final TableColumn locationColumn = new TableColumn(table, SWT.LEFT);
    locationColumn.setText(PDEUIMessages.UpdatesSection_LocationColumn);
    locationColumn.setWidth(240);
    final TableColumn enabledColumn = new TableColumn(table, SWT.LEFT);
    enabledColumn.setText(PDEUIMessages.UpdatesSection_EnabledColumn);
    enabledColumn.setWidth(120);
    GridData data = (GridData) tablePart.getControl().getLayoutData();
    data.minimumWidth = 200;
    tablePart.setButtonEnabled(0, isEditable());
    tablePart.setButtonEnabled(1, isEditable());
    table.setHeaderVisible(true);
    toolkit.paintBordersFor(container);
    table.addControlListener(new ControlListener() {

        @Override
        public void controlMoved(ControlEvent e) {
        }

        @Override
        public void controlResized(ControlEvent e) {
            int size = table.getSize().x;
            locationColumn.setWidth(size / 6 * 5);
            enabledColumn.setWidth(size / 6 * 1);
        }
    });
    fRepositoryTable.setLabelProvider(new LabelProvider());
    fRepositoryTable.setContentProvider(new ContentProvider());
    fRepositoryTable.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            IRepositoryReference r1 = (IRepositoryReference) e1;
            IRepositoryReference r2 = (IRepositoryReference) e2;
            return super.compare(viewer, r1.getURL(), r2.getURL());
        }
    });
    fRepositoryTable.setInput(getSite());
    createEditors();
    section.setClient(container);
    section.setText(PDEUIMessages.RepositorySection_title);
    section.setDescription(PDEUIMessages.RepositorySection_description);
}
Also used : TablePart(org.eclipse.pde.internal.ui.parts.TablePart) GridData(org.eclipse.swt.layout.GridData) ControlListener(org.eclipse.swt.events.ControlListener) ControlEvent(org.eclipse.swt.events.ControlEvent)

Aggregations

ControlListener (org.eclipse.swt.events.ControlListener)87 ControlEvent (org.eclipse.swt.events.ControlEvent)82 GridData (org.eclipse.swt.layout.GridData)31 FocusEvent (org.eclipse.swt.events.FocusEvent)19 Composite (org.eclipse.swt.widgets.Composite)19 Test (org.junit.Test)19 MouseEvent (org.eclipse.swt.events.MouseEvent)18 Point (org.eclipse.swt.graphics.Point)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 KeyEvent (org.eclipse.swt.events.KeyEvent)16 ArrayList (java.util.ArrayList)14 SelectionEvent (org.eclipse.swt.events.SelectionEvent)14 DisposeEvent (org.eclipse.swt.events.DisposeEvent)13 Control (org.eclipse.swt.widgets.Control)13 Event (org.eclipse.swt.widgets.Event)13 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)11 DisposeListener (org.eclipse.swt.events.DisposeListener)11 FocusListener (org.eclipse.swt.events.FocusListener)11 Listener (org.eclipse.swt.widgets.Listener)10 ModifyEvent (org.eclipse.swt.events.ModifyEvent)9