Java Code Examples for org.eclipse.swt.widgets.Composite#addControlListener()

The following examples show how to use org.eclipse.swt.widgets.Composite#addControlListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmptyTablePlaceholder.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Constructor EmptyTablePlaceholder.  Construct an EmptyTablePlaceholder control.
 * 
 * @param parent The parent control
 * @param style Style bits.  These are the same as what Canvas accepts.
 */
public EmptyTablePlaceholder(Composite parent, int style) {
	super(parent, style);
	parentTable = (InternalCompositeTable) parent.getParent().getParent();
	
	parent.addControlListener(controlListener);
	
	addTraverseListener(traverseListener);
	addFocusListener(focusListener);
	addKeyListener(keyListener);
	addPaintListener(paintListener);
	addDisposeListener(disposeListener);
	
	RED = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
	setBackground(getParent().getBackground());
	
	resize();
}
 
Example 2
Source File: DisplayOverlay.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public DisplayOverlay(final LayeredDisplayView view, final Composite c,
		final IOverlayProvider<OverlayInfo> provider) {
	this.createExtraInfo = provider != null;
	this.view = view;
	final IPartService ps = ((IWorkbenchPart) view).getSite().getService(IPartService.class);
	ps.addPartListener(pl2);
	referenceComposite = c;
	// parentShell = c.getShell();
	popup = new Shell(c.getShell(), SWT.NO_TRIM | SWT.NO_FOCUS);
	popup.setAlpha(140);
	final FillLayout layout = new FillLayout();
	layout.type = SWT.VERTICAL;
	layout.spacing = 10;
	popup.setLayout(layout);
	popup.setBackground(IGamaColors.BLACK.color());
	createPopupControl();
	popup.setAlpha(140);
	popup.layout();
	c.getShell().addShellListener(listener);
	// parentShell.addControlListener(listener);
	c.addControlListener(listener);
	if (provider != null) {
		provider.setTarget(new ThreadedOverlayUpdater(this), view.getDisplaySurface());
	}
	// if (GamaPreferences.Displays.CORE_SHOW_FPS.getValue()) {
	timer.schedule(new FPSTask(), 0, 1000);
	// }
}
 
Example 3
Source File: ComponentResponsiveLayout.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Primary will be shown as long as width and height are within the given bounds,
 * otherwise the composite will switch to the secondary control
 * 
 * @param parent
 * @param minWidth
 * @param minHeight
 */
public ComponentResponsiveLayout(final Composite parent, 
                                 final int minWidth, 
                                 final int minHeight,
                                 final Control primary,
                                 final Control secondary) {
    final StackLayout layout = new StackLayout();
    parent.setLayout (layout);
    layout.topControl = primary;
    parent.layout();
    parent.addControlListener(new ControlAdapter(){

        @Override
        public void controlResized(ControlEvent arg0) {

            if (parent.getSize().x < minWidth || parent.getSize().y < minHeight) {
                if (layout.topControl != secondary) {
                    layout.topControl = secondary;
                    parent.layout();
                }
            } else {
                if (layout.topControl != primary) {
                    layout.topControl = primary;
                    parent.layout();
                }
            }
        }
    });
}
 
Example 4
Source File: TimeGraphLegend.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates a states group
 *
 * @param composite
 *            the parent composite
 * @since 3.3
 */
private void addStateGroups(Composite composite) {

    StateItem[] stateTable = fProvider.getStateTable();
    if (stateTable == null) {
        return;
    }
    List<StateItem> stateItems = Arrays.asList(stateTable);
    Collection<StateItem> linkStates = Collections2.filter(stateItems, TimeGraphLegend::isLinkState);

    ScrolledComposite sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    sc.setLayout(GridLayoutFactory.swtDefaults().margins(200, 0).create());

    Composite innerComposite = new Composite(sc, SWT.NONE);
    fInnerComposite = innerComposite;
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    innerComposite.setLayoutData(gd);
    innerComposite.setLayout(new GridLayout());
    innerComposite.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            /*
             * Find the highest number of columns that fits in the new width
             */
            Point size = innerComposite.getSize();
            List<GridLayout> gridLayouts = getGridLayouts(innerComposite);
            Point minSize = new Point(0, 0);
            for (int columns = 8; columns > 0; columns--) {
                final int numColumns = columns;
                gridLayouts.forEach(gl -> gl.numColumns = numColumns);
                minSize = innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
                if (minSize.x <= size.x) {
                    break;
                }
            }
            sc.setMinSize(0, minSize.y);
        }
    });

    sc.setContent(innerComposite);

    createStatesGroup(innerComposite);
    createLinkGroup(linkStates, innerComposite);

    sc.setMinSize(0, innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
}
 
Example 5
Source File: ExtractMethodComposite.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
private Composite createArgumentsTable(Composite parent) {
    final Composite argumentsComposite = new Composite(parent, SWT.NONE);
    FormLayout compositeLayout = new FormLayout();
    GridData compositeLData = new GridData(GridData.FILL_BOTH);

    argumentsComposite.setLayoutData(compositeLData);
    argumentsComposite.setLayout(compositeLayout);

    argumentsTable = new Table(argumentsComposite, SWT.BORDER | SWT.FULL_SELECTION);

    FormData tableLData = new FormData();
    tableLData.bottom = new FormAttachment(1000, 1000, 0);
    tableLData.left = new FormAttachment(0, 1000, 0);
    tableLData.right = new FormAttachment(1000, 1000, -80);
    tableLData.top = new FormAttachment(0, 1000, 4);
    argumentsTable.setLayoutData(tableLData);

    argumentsTable.setHeaderVisible(true);
    argumentsTable.setLinesVisible(true);

    nameColumn = new TableColumn(argumentsTable, SWT.NONE);
    nameColumn.setText(Messages.extractMethodArgumentName);

    createArgumentsButton(argumentsComposite);
    argumentsComposite.addControlListener(new ControlAdapter() {
        @Override
        public void controlResized(ControlEvent e) {
            Rectangle area = argumentsTable.getClientArea();
            Point preferredSize = argumentsTable.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            int width = area.width - 2 * argumentsTable.getBorderWidth();
            if (preferredSize.y > area.height + argumentsTable.getHeaderHeight()) {
                Point vBarSize = argumentsTable.getVerticalBar().getSize();
                width -= vBarSize.x;
            }
            Point oldSize = argumentsTable.getSize();
            if (oldSize.x > area.width) {
                nameColumn.setWidth(width);
                argumentsTable.setSize(area.width, area.height);
            } else {
                argumentsTable.setSize(area.width, area.height);
                nameColumn.setWidth(width);
            }
        }
    });
    argumentsComposite.notifyListeners(SWT.CONTROL, new Event());

    return argumentsComposite;
}