Java Code Examples for org.eclipse.swt.widgets.Control#setBounds()

The following examples show how to use org.eclipse.swt.widgets.Control#setBounds() . 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: CompositeTable.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private void resizePrototypeObjects(Control[] finalChildren) {
    // Now actually resize the children
    int top = 0;
    int width = getSize().x;
    for (int i = 0; i < finalChildren.length; ++i) {
        Control control = finalChildren[i];
        
        int height = control.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
        control.setBounds(0, top, width, height);
        
        top += height;
    }
}
 
Example 2
Source File: TimeSlice.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
protected void layout(Composite composite, boolean flushCache) {
	Point parentSize = composite.getSize();
	Control[] children = composite.getChildren();

	// layout 0th control
	Integer preferredWidth = (Integer) children[0].getLayoutData();
	if (preferredWidth == null) {
		preferredWidth = new Integer(children[0].computeSize(
				SWT.DEFAULT, SWT.DEFAULT).x);
	}
	children[0].setBounds(0, 0, preferredWidth.intValue(), parentSize.y);

	// layout the rest of the controls
	int controlWidth = 0;
	int extraWidth = 0;
	if (children.length >= 2) {
		controlWidth = (parentSize.x - preferredWidth.intValue())
				/ (children.length - 1);
		extraWidth = (parentSize.x - preferredWidth.intValue())
				% (children.length - 1);
	}
	int leftPosition = preferredWidth.intValue();

	for (int i = 1; i < children.length; i++) {
		Control control = children[i];
		int width = controlWidth;
		if (extraWidth > 0) {
			++width;
			--extraWidth;
		}
		control.setBounds(leftPosition, 0, width, parentSize.y);
		leftPosition += width;
	}
}
 
Example 3
Source File: GridRowLayout.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
protected void setBounds(Widget columnObject, int left, int top, int width, int height) {
    Control control = (Control) columnObject;
    control.setBounds(left, top, width, height);
}
 
Example 4
Source File: CTreeEditor.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void layout() {
	if (tree.isDisposed()) return;
	if (item == null || item.isDisposed()) return;	
	int columnCount = tree.getColumnCount();
	if (columnCount == 0 && column != 0) return;
	if (columnCount > 0 && (column < 0 || column >= columnCount)) return;
	Control editor = getEditor();
	if(editor == null || editor.isDisposed()) return;

	Rectangle cell = item.getCell(column).getBounds();
	Rectangle ca = item.getCell(column).getClientArea();
	cell.x += ca.x;
	cell.width = ca.width - 1;
	cell.y += 1;
	cell.height -= 2;
	int bwidth = getEditor().getBorderWidth();
	cell.x -= bwidth;
	cell.y -= bwidth;
	cell.width -= 2*bwidth;
	cell.height -= 2*bwidth;
	Image[] images = ((CTreeCell) item.getCell(column)).getImages();
	if(images.length > 0) {
		Image img = images[images.length-1];
		Rectangle rect = img == null ? new Rectangle(cell.x,cell.y,0,0) : img.getBounds();
		cell.x = rect.x + rect.width;
		cell.width -= rect.width;
	}
	Rectangle area = tree.getClientArea();
	if (cell.x < area.x + area.width) {
		if (cell.x + cell.width > area.x + area.width) {
			cell.width = area.x + area.width - cell.x;
		}
	}
	Rectangle editorRect = new Rectangle(cell.x, cell.y, minimumWidth, minimumHeight);

	if (grabHorizontal) {
		if (tree.getColumnCount() == 0) {
			// Bounds of tree item only include the text area - stretch out to include 
			// entire client area
			cell.width = area.x + area.width - cell.x;
		}
		editorRect.width = Math.max(cell.width, minimumWidth);
	}

	if (grabVertical) {
		editorRect.height = Math.max(cell.height, minimumHeight);
	}

	if (horizontalAlignment == SWT.RIGHT) {
		editorRect.x += cell.width - editorRect.width;
	} else if (horizontalAlignment == SWT.LEFT) {
		// do nothing - cell.x is the right answer
	} else { // default is CENTER
		editorRect.x += (cell.width - editorRect.width)/2;
	}
	// don't let the editor overlap with the +/- of the tree
	editorRect.x = Math.max(cell.x, editorRect.x);

	if (verticalAlignment == SWT.BOTTOM) {
		editorRect.y += cell.height - editorRect.height;
	} else if (verticalAlignment == SWT.TOP) {
		// do nothing - cell.y is the right answer
	} else { // default is CENTER
		editorRect.y += (cell.height - editorRect.height)/2;
	}

	if(editor == null || editor.isDisposed()) return;
	boolean hadFocus = editor.getVisible () && editor.isFocusControl();
	// this doesn't work because
	// resizing the column takes the focus away
	// before we get here
	editor.setBounds (editorRect);
	if(hadFocus) {
		if (editor == null || editor.isDisposed()) return;
		editor.setFocus ();
	}

	editor.moveAbove(null);
}
 
Example 5
Source File: XViewerEditAdapter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
boolean handleEditEvent(Event event) {
   if (klickedColumn == null || klickedCell == null) {
      return false;
   }

   final Control c;
   try {
      XViewerColumn xColumn =
         xv.getXViewerFactory().getDefaultXViewerColumn(((XViewerColumn) klickedColumn.getData()).getId());
      if (xColumn instanceof ExtendedViewerColumn) {
         ExtendedViewerColumn extendedColumn = (ExtendedViewerColumn) xColumn;
         CellEditDescriptor ced = extendedColumn.getCellEditDescriptorMap().get(klickedCell.getElement().getClass());
         if (ced != null) {
            if (ced.getControl() == null) {
               return false;
            }
            if (ced.getAction() != null && !ced.getAction().isEnabled()) {
               return false;
            }
            if (!converter.isValid(ced, klickedCell.getElement())) {
               return false;
            }
            c = factory.createControl(ced, xv);
            if (c == null) {
               return false;
            }
         } else {
            return false;
         }
      } else {
         return false;
      }

      if (((TreeItem) event.item) != null) {
         Listener myListener = e-> {
               switch (e.type) {
                  case SWT.FocusOut:
                     // set new value
                     getInput(c);
                     c.dispose();
                     break;
                  case SWT.Verify:
                     c.setBounds(klickedCell.getBounds());
                     break;
                  case SWT.Traverse:
                     boolean neighbor = false;
                     switch (e.detail) {
                        case SWT.TRAVERSE_RETURN:
                           // set new value
                           getInput(c);
                           //$FALL-THROUGH$
                        case SWT.TRAVERSE_ESCAPE:
                           c.dispose();
                           e.doit = false;
                           break;
                        case SWT.TRAVERSE_TAB_NEXT:
                           getInput(c);
                           neighbor = getNeighbor(ViewerCell.RIGHT, true);
                           e.doit = false;
                           c.dispose();
                           Event eN = new Event();
                           eN.type = SWT.Selection;
                           eN.widget = xv.getTree();
                           if (neighbor) {
                              eN.item = klickedCell.getItem();
                           }
                           doHandleEvent(eN);
                           break;
                        case SWT.TRAVERSE_TAB_PREVIOUS:
                           getInput(c);
                           neighbor = getNeighbor(ViewerCell.LEFT, true);
                           e.doit = false;
                           c.dispose();
                           Event eP = new Event();
                           eP.type = SWT.Selection;
                           eP.widget = xv.getTree();
                           if (neighbor) {
                              eP.item = klickedCell.getItem();
                           }
                           doHandleEvent(eP);
                           break;
                     }
               }
         };
         c.addListener(SWT.FocusOut, myListener);
         c.addListener(SWT.Traverse, myListener);
         c.addListener(SWT.Verify, myListener);
         // set old value
         setInput(c);
         c.setFocus();
         return true;
      }
   } catch (Exception ex) {
      return false;
   }
   return false;
}
 
Example 6
Source File: InlineCellEditController.java    From translationstudio8 with GNU General Public License v2.0 4 votes vote down vote up
public static boolean editCellInline(LayerCell cell, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
	try {
		ActiveCellEditor.commit();

		final List<String> configLabels = cell.getConfigLabels().getLabels();
		Rectangle cellBounds = cell.getBounds();

		ILayer layer = cell.getLayer();

		int columnPosition = layer.getColumnPositionByX(cellBounds.x);
		int columnIndex = layer.getColumnIndexByPosition(columnPosition);
		int rowPosition = layer.getRowPositionByY(cellBounds.y);
		int rowIndex = layer.getRowIndexByPosition(rowPosition);

		boolean editable = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, configLabels).isEditable(columnIndex, rowIndex);
		if (!editable) {
			return false;
		}

		ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
		IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
		IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
		IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);

		ICellEditHandler editHandler = new SingleEditHandler(
				cellEditor,
				layer,
				columnPosition,
				rowPosition);

		final Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));

		Object originalCanonicalValue = cell.getDataValue();

		ActiveCellEditor.activate(cellEditor, parent, originalCanonicalValue, initialEditValue, displayConverter, cellStyle, dataValidator, editHandler, columnPosition, rowPosition, columnIndex, rowIndex);
		Control editorControl = ActiveCellEditor.getControl();

		if (editorControl != null) {
			editorControl.setBounds(editorBounds);
			ILayerListener layerListener = layerListenerMap.get(layer);
			if (layerListener == null) {
				layerListener = new InlineCellEditLayerListener(layer);
				layerListenerMap.put(layer, layerListener);

				layer.addLayerListener(layerListener);
			}
		}
	} catch (Exception e) {
		if(cell == null){
			System.err.println("Cell being edited is no longer available. " + "Character: " + initialEditValue);
		} else {
			System.err.println("Error while editing cell (inline): " + "Cell: " + cell + "; Character: " + initialEditValue);
			e.printStackTrace(System.err);
		}
	}

	return true;
}
 
Example 7
Source File: InlineCellEditController.java    From tmxeditor8 with GNU General Public License v2.0 4 votes vote down vote up
public static boolean editCellInline(LayerCell cell, Character initialEditValue, Composite parent, IConfigRegistry configRegistry) {
	try {
		ActiveCellEditor.commit();

		final List<String> configLabels = cell.getConfigLabels().getLabels();
		Rectangle cellBounds = cell.getBounds();

		ILayer layer = cell.getLayer();

		int columnPosition = layer.getColumnPositionByX(cellBounds.x);
		int columnIndex = layer.getColumnIndexByPosition(columnPosition);
		int rowPosition = layer.getRowPositionByY(cellBounds.y);
		int rowIndex = layer.getRowIndexByPosition(rowPosition);

		boolean editable = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, DisplayMode.EDIT, configLabels).isEditable(columnIndex, rowIndex);
		if (!editable) {
			return false;
		}

		ICellEditor cellEditor = configRegistry.getConfigAttribute(EditConfigAttributes.CELL_EDITOR, DisplayMode.EDIT, configLabels);
		IDisplayConverter displayConverter = configRegistry.getConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, DisplayMode.EDIT, configLabels);
		IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.EDIT, configLabels);
		IDataValidator dataValidator = configRegistry.getConfigAttribute(EditConfigAttributes.DATA_VALIDATOR, DisplayMode.EDIT, configLabels);

		ICellEditHandler editHandler = new SingleEditHandler(
				cellEditor,
				layer,
				columnPosition,
				rowPosition);

		final Rectangle editorBounds = layer.getLayerPainter().adjustCellBounds(new Rectangle(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height));

		Object originalCanonicalValue = cell.getDataValue();

		ActiveCellEditor.activate(cellEditor, parent, originalCanonicalValue, initialEditValue, displayConverter, cellStyle, dataValidator, editHandler, columnPosition, rowPosition, columnIndex, rowIndex);
		Control editorControl = ActiveCellEditor.getControl();

		if (editorControl != null) {
			editorControl.setBounds(editorBounds);
			ILayerListener layerListener = layerListenerMap.get(layer);
			if (layerListener == null) {
				layerListener = new InlineCellEditLayerListener(layer);
				layerListenerMap.put(layer, layerListener);

				layer.addLayerListener(layerListener);
			}
		}
	} catch (Exception e) {
		if(cell == null){
			System.err.println("Cell being edited is no longer available. " + "Character: " + initialEditValue);
		} else {
			System.err.println("Error while editing cell (inline): " + "Cell: " + cell + "; Character: " + initialEditValue);
			e.printStackTrace(System.err);
		}
	}

	return true;
}
 
Example 8
Source File: PGroupStackPresentation.java    From nebula with Eclipse Public License 2.0 3 votes vote down vote up
private void resizeSelectedPart()
{
    IPresentablePart part = getSite().getSelectedPart();
    
    if (part == null) return;
    
    Control partTB = part.getToolBar();
    
    Rectangle bounds = group.getClientArea();        
    
    Point partTBSize = new Point(0,0);
    if (partTB != null)
    {
        partTBSize = partTB.computeSize(bounds.width,SWT.DEFAULT);
   
        Rectangle tbBounds = new Rectangle(0,0,bounds.width,partTBSize.y);
        
        tbBounds = group.getDisplay().map(group.getChildren()[0], partTB.getParent(), tbBounds);
        
        partTB.setBounds(tbBounds);
        
        bounds.y += tbBounds.height;
        bounds.height -= tbBounds.height;        
    }
    
    bounds = group.getDisplay().map(group, partParent, bounds);

    part.setBounds(bounds);
}
 
Example 9
Source File: ExpandBarStandaloneStackPresentation.java    From nebula with Eclipse Public License 2.0 3 votes vote down vote up
private void resizeSelectedPart()
{
    IPresentablePart part = getSite().getSelectedPart();
    
    if (part == null) return;
    
    Control partTB = part.getToolBar();
    
    Rectangle bounds = eBarItem.getControl().getBounds();        
    
    Point partTBSize = new Point(0,0);
    if (partTB != null)
    {
        partTBSize = partTB.computeSize(bounds.width,SWT.DEFAULT);
   
        Rectangle tbBounds = new Rectangle(0,0,bounds.width,partTBSize.y);
        
        tbBounds = eBar.getDisplay().map(eBarItem.getControl(), partTB.getParent(), tbBounds);
        
        partTB.setBounds(tbBounds);
        
        bounds.y += tbBounds.height;
        bounds.height -= tbBounds.height;        
    }
    
    bounds = eBar.getDisplay().map(eBar, partParent, bounds);

    part.setBounds(bounds);
}
 
Example 10
Source File: EmptyStandaloneStackPresentation.java    From nebula with Eclipse Public License 2.0 3 votes vote down vote up
/** 
 * {@inheritDoc}
 */
@Override
public void setBounds(Rectangle bounds)
{
    borderComposite.setBounds(bounds);
    
    Rectangle clientArea = borderComposite.getClientArea();
    
    IPresentablePart part = getSite().getSelectedPart();
    
    if (part == null) return;
    
    Control partTB = part.getToolBar();
    
    Rectangle tbBounds = new Rectangle(0,0,0,0);
    
    if (partTB != null)
    {
        Point size = partTB.computeSize(clientArea.width, SWT.DEFAULT);
        
        tbBounds.width = size.x;
        tbBounds.height = Math.min(size.y, clientArea.height);

        tbBounds = borderComposite.getDisplay().map(borderComposite, partTB.getParent(), tbBounds);
        
        partTB.setBounds(tbBounds);
        
        clientArea.y += tbBounds.height;
        clientArea.height -= tbBounds.height;  
    }
    
    clientArea = borderComposite.getDisplay().map(borderComposite, partParent, clientArea);

    part.setBounds(clientArea);
}
 
Example 11
Source File: TSWizardDialog.java    From translationstudio8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Lays outs the page according to this layout.
 * 
 * @param w
 *            the control
 */
public void layoutPage(Control w) {
	w.setBounds(getClientArea(w.getParent()));
}
 
Example 12
Source File: TSWizardDialog.java    From tmxeditor8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Lays outs the page according to this layout.
 * 
 * @param w
 *            the control
 */
public void layoutPage(Control w) {
	w.setBounds(getClientArea(w.getParent()));
}