Example usage for org.eclipse.swt.widgets ScrollBar setVisible

List of usage examples for org.eclipse.swt.widgets ScrollBar setVisible

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets ScrollBar setVisible.

Prototype

public void setVisible(boolean visible) 

Source Link

Document

Marks the receiver as visible if the argument is true, and marks it invisible otherwise.

Usage

From source file:org.eclipse.swt.examples.paint.PaintSurface.java

/**
 * Constructs a PaintSurface./* ww w  . ja va2 s  .  c  om*/
 * <p>
 * paintCanvas must have SWT.NO_REDRAW_RESIZE and SWT.NO_BACKGROUND styles,
 *     and may have SWT.V_SCROLL and/or SWT.H_SCROLL.
 * </p>
 * @param paintCanvas the Canvas object in which to render
 * @param paintStatus the PaintStatus object to use for providing user feedback
 * @param fillColor the color to fill the canvas with initially
 */
public PaintSurface(Canvas paintCanvas, Text statusText, Color fillColor) {
    this.paintCanvas = paintCanvas;
    this.statusText = statusText;
    clearStatus();

    /* Set up the drawing surface */
    Rectangle displayRect = paintCanvas.getDisplay().getClientArea();
    imageWidth = displayRect.width;
    imageHeight = displayRect.height;
    image = new Image(paintCanvas.getDisplay(), imageWidth, imageHeight);

    imageFDC.gc = new GC(image);
    imageFDC.gc.setBackground(fillColor);
    imageFDC.gc.fillRectangle(0, 0, imageWidth, imageHeight);
    displayFDC.gc = new GC(paintCanvas);

    /* Initialize the session */
    setPaintSession(null);

    /* Add our listeners */
    paintCanvas.addDisposeListener(e -> displayFDC.gc.dispose());
    paintCanvas.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDown(MouseEvent event) {
            processMouseEventCoordinates(event);
            if (paintSession != null)
                paintSession.mouseDown(event);
        }

        @Override
        public void mouseUp(MouseEvent event) {
            processMouseEventCoordinates(event);
            if (paintSession != null)
                paintSession.mouseUp(event);
        }

        @Override
        public void mouseDoubleClick(MouseEvent event) {
            processMouseEventCoordinates(event);
            if (paintSession != null)
                paintSession.mouseDoubleClick(event);
        }
    });
    paintCanvas.addMouseMoveListener(event -> {
        processMouseEventCoordinates(event);
        if (paintSession != null)
            paintSession.mouseMove(event);
    });
    paintCanvas.addPaintListener(event -> {
        if (rubberband.isEmpty()) {
            // Nothing to merge, so we just refresh
            event.gc.drawImage(image, displayFDC.xOffset + event.x, displayFDC.yOffset + event.y, event.width,
                    event.height, event.x, event.y, event.width, event.height);
        } else {
            /*
             * Avoid flicker when merging overlayed objects by constructing the image on
             * a backbuffer first, then blitting it to the screen.
             */
            // Check that the backbuffer is large enough
            if (paintImage != null) {
                Rectangle rect1 = paintImage.getBounds();
                if ((event.width + event.x > rect1.width) || (event.height + event.y > rect1.height)) {
                    paintFDC.gc.dispose();
                    paintImage.dispose();
                    paintImage = null;
                }
            }
            if (paintImage == null) {
                Display display = getDisplay();
                Rectangle rect2 = display.getClientArea();
                paintImage = new Image(display, Math.max(rect2.width, event.width + event.x),
                        Math.max(rect2.height, event.height + event.y));
                paintFDC.gc = new GC(paintImage);
            }
            // Setup clipping and the FDC
            Region clipRegion = new Region();
            event.gc.getClipping(clipRegion);
            paintFDC.gc.setClipping(clipRegion);
            clipRegion.dispose();

            paintFDC.xOffset = displayFDC.xOffset;
            paintFDC.yOffset = displayFDC.yOffset;
            paintFDC.xScale = displayFDC.xScale;
            paintFDC.yScale = displayFDC.yScale;

            // Merge the overlayed objects into the image, then blit
            paintFDC.gc.drawImage(image, displayFDC.xOffset + event.x, displayFDC.yOffset + event.y,
                    event.width, event.height, event.x, event.y, event.width, event.height);
            rubberband.draw(paintFDC);
            event.gc.drawImage(paintImage, event.x, event.y, event.width, event.height, event.x, event.y,
                    event.width, event.height);
        }
    });
    paintCanvas.addControlListener(ControlListener.controlResizedAdapter(e -> handleResize()));

    /* Set up the paint canvas scroll bars */
    ScrollBar horizontal = paintCanvas.getHorizontalBar();
    horizontal.setVisible(true);
    horizontal
            .addSelectionListener(widgetSelectedAdapter(event -> scrollHorizontally((ScrollBar) event.widget)));
    ScrollBar vertical = paintCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollVertically((ScrollBar) event.widget)));
    handleResize();
}

From source file:ImageAnalyzer.java

void createWidgets() {
    // Add the widgets to the shell in a grid layout.
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;/*from  w w w .ja  v  a 2  s . c o m*/
    layout.numColumns = 2;
    shell.setLayout(layout);

    // Separate the menu bar from the rest of the widgets.
    Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    separator.setLayoutData(gridData);

    // Add a composite to contain some control widgets across the top.
    Composite controls = new Composite(shell, SWT.NULL);
    RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 0;
    rowLayout.marginBottom = 5;
    rowLayout.spacing = 8;
    controls.setLayout(rowLayout);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    controls.setLayoutData(gridData);

    // Combo to change the background.
    Group group = new Group(controls, SWT.NULL);
    group.setLayout(new RowLayout());
    group.setText("Background");
    backgroundCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    backgroundCombo.setItems(new String[] { "None", "White", "Black", "Red", "Green", "Blue" });
    backgroundCombo.select(backgroundCombo.indexOf("White"));
    backgroundCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            changeBackground();
        }
    });

    // Combo to change the x scale.
    String[] values = { "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1", "1.1", "1.2", "1.3",
            "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2", "3", "4", "5", "6", "7", "8", "9", "10", };
    group = new Group(controls, SWT.NULL);
    group.setLayout(new RowLayout());
    group.setText("X_scale");
    scaleXCombo = new Combo(group, SWT.DROP_DOWN);
    for (int i = 0; i < values.length; i++) {
        scaleXCombo.add(values[i]);
    }
    scaleXCombo.select(scaleXCombo.indexOf("1"));
    scaleXCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            scaleX();
        }
    });

    // Combo to change the y scale.
    group = new Group(controls, SWT.NULL);
    group.setLayout(new RowLayout());
    group.setText("Y_scale");
    scaleYCombo = new Combo(group, SWT.DROP_DOWN);
    for (int i = 0; i < values.length; i++) {
        scaleYCombo.add(values[i]);
    }
    scaleYCombo.select(scaleYCombo.indexOf("1"));
    scaleYCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            scaleY();
        }
    });

    // Combo to change the alpha value.
    group = new Group(controls, SWT.NULL);
    group.setLayout(new RowLayout());
    group.setText("Alpha_K");
    alphaCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 0; i <= 255; i += 5) {
        alphaCombo.add(String.valueOf(i));
    }
    alphaCombo.select(alphaCombo.indexOf("255"));
    alphaCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            alpha();
        }
    });

    // Check box to request incremental display.
    group = new Group(controls, SWT.NULL);
    group.setLayout(new RowLayout());
    group.setText("Display");
    incrementalCheck = new Button(group, SWT.CHECK);
    incrementalCheck.setText("Incremental");
    incrementalCheck.setSelection(incremental);
    incrementalCheck.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            incremental = ((Button) event.widget).getSelection();
        }
    });

    // Check box to request transparent display.
    transparentCheck = new Button(group, SWT.CHECK);
    transparentCheck.setText("Transparent");
    transparentCheck.setSelection(transparent);
    transparentCheck.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            transparent = ((Button) event.widget).getSelection();
            if (image != null) {
                imageCanvas.redraw();
            }
        }
    });

    // Check box to request mask display.
    maskCheck = new Button(group, SWT.CHECK);
    maskCheck.setText("Mask");
    maskCheck.setSelection(showMask);
    maskCheck.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            showMask = ((Button) event.widget).getSelection();
            if (image != null) {
                imageCanvas.redraw();
            }
        }
    });

    // Check box to request background display.
    backgroundCheck = new Button(group, SWT.CHECK);
    backgroundCheck.setText("Background");
    backgroundCheck.setSelection(showBackground);
    backgroundCheck.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            showBackground = ((Button) event.widget).getSelection();
        }
    });

    // Group the animation buttons.
    group = new Group(controls, SWT.NULL);
    group.setLayout(new RowLayout());
    group.setText("Animation");

    // Push button to display the previous image in a multi-image file.
    previousButton = new Button(group, SWT.PUSH);
    previousButton.setText("Previous");
    previousButton.setEnabled(false);
    previousButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            previous();
        }
    });

    // Push button to display the next image in a multi-image file.
    nextButton = new Button(group, SWT.PUSH);
    nextButton.setText("Next");
    nextButton.setEnabled(false);
    nextButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            next();
        }
    });

    // Push button to toggle animation of a multi-image file.
    animateButton = new Button(group, SWT.PUSH);
    animateButton.setText("Animate");
    animateButton.setEnabled(false);
    animateButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            animate();
        }
    });

    // Label to show the image file type.
    typeLabel = new Label(shell, SWT.NULL);
    typeLabel.setText("Type_initial");
    typeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Canvas to show the image.
    imageCanvas = new Canvas(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE);
    imageCanvas.setBackground(whiteColor);
    imageCanvas.setCursor(crossCursor);
    gridData = new GridData();
    gridData.verticalSpan = 15;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    imageCanvas.setLayoutData(gridData);
    imageCanvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent event) {
            if (image != null)
                paintImage(event);
        }
    });
    imageCanvas.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent event) {
            if (image != null) {
                showColorAt(event.x, event.y);
            }
        }
    });

    // Set up the image canvas scroll bars.
    ScrollBar horizontal = imageCanvas.getHorizontalBar();
    horizontal.setVisible(true);
    horizontal.setMinimum(0);
    horizontal.setEnabled(false);
    horizontal.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            scrollHorizontally((ScrollBar) event.widget);
        }
    });
    ScrollBar vertical = imageCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.setMinimum(0);
    vertical.setEnabled(false);
    vertical.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            scrollVertically((ScrollBar) event.widget);
        }
    });

    // Label to show the image size.
    sizeLabel = new Label(shell, SWT.NULL);
    sizeLabel.setText("Size_initial");
    sizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image depth.
    depthLabel = new Label(shell, SWT.NULL);
    depthLabel.setText("Depth_initial");
    depthLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the transparent pixel.
    transparentPixelLabel = new Label(shell, SWT.NULL);
    transparentPixelLabel.setText("Transparent_pixel_initial");
    transparentPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the time to load.
    timeToLoadLabel = new Label(shell, SWT.NULL);
    timeToLoadLabel.setText("Time_to_load_initial");
    timeToLoadLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Separate the animation fields from the rest of the fields.
    separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the logical screen size for animation.
    screenSizeLabel = new Label(shell, SWT.NULL);
    screenSizeLabel.setText("Animation_size_initial");
    screenSizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the background pixel.
    backgroundPixelLabel = new Label(shell, SWT.NULL);
    backgroundPixelLabel.setText("Background_pixel_initial");
    backgroundPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image location (x, y).
    locationLabel = new Label(shell, SWT.NULL);
    locationLabel.setText("Image_location_initial");
    locationLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image disposal method.
    disposalMethodLabel = new Label(shell, SWT.NULL);
    disposalMethodLabel.setText("Disposal_initial");
    disposalMethodLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image delay time.
    delayTimeLabel = new Label(shell, SWT.NULL);
    delayTimeLabel.setText("Delay_initial");
    delayTimeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the background pixel.
    repeatCountLabel = new Label(shell, SWT.NULL);
    repeatCountLabel.setText("Repeats_initial");
    repeatCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Separate the animation fields from the palette.
    separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show if the image has a direct or indexed palette.
    paletteLabel = new Label(shell, SWT.NULL);
    paletteLabel.setText("Palette_initial");
    paletteLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Canvas to show the image's palette.
    paletteCanvas = new Canvas(shell, SWT.BORDER | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE);
    paletteCanvas.setFont(fixedWidthFont);
    paletteCanvas.getVerticalBar().setVisible(true);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    GC gc = new GC(paletteLabel);
    paletteWidth = gc.stringExtent("Max_length_string").x;
    gc.dispose();
    gridData.widthHint = paletteWidth;
    gridData.heightHint = 16 * 11; // show at least 16 colors
    paletteCanvas.setLayoutData(gridData);
    paletteCanvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent event) {
            if (image != null)
                paintPalette(event);
        }
    });

    // Set up the palette canvas scroll bar.
    vertical = paletteCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.setMinimum(0);
    vertical.setIncrement(10);
    vertical.setEnabled(false);
    vertical.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            scrollPalette((ScrollBar) event.widget);
        }
    });

    // Sash to see more of image or image data.
    sash = new Sash(shell, SWT.HORIZONTAL);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    sash.setLayoutData(gridData);
    sash.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            if (event.detail != SWT.DRAG) {
                ((GridData) paletteCanvas.getLayoutData()).heightHint = SWT.DEFAULT;
                Rectangle paletteCanvasBounds = paletteCanvas.getBounds();
                int minY = paletteCanvasBounds.y + 20;
                Rectangle dataLabelBounds = dataLabel.getBounds();
                int maxY = statusLabel.getBounds().y - dataLabelBounds.height - 20;
                if (event.y > minY && event.y < maxY) {
                    Rectangle oldSash = sash.getBounds();
                    sash.setBounds(event.x, event.y, event.width, event.height);
                    int diff = event.y - oldSash.y;
                    Rectangle bounds = imageCanvas.getBounds();
                    imageCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
                    bounds = paletteCanvasBounds;
                    paletteCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
                    bounds = dataLabelBounds;
                    dataLabel.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height);
                    bounds = dataText.getBounds();
                    dataText.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height - diff);
                    // shell.layout(true);
                }
            }
        }
    });

    // Label to show data-specific fields.
    dataLabel = new Label(shell, SWT.NULL);
    dataLabel.setText("Pixel_data_initial");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    dataLabel.setLayoutData(gridData);

    // Text to show a dump of the data.
    dataText = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    dataText.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    dataText.setFont(fixedWidthFont);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.heightHint = 128;
    gridData.grabExcessVerticalSpace = true;
    dataText.setLayoutData(gridData);
    dataText.addMouseListener(new MouseAdapter() {
        public void mouseDown(MouseEvent event) {
            if (image != null && event.button == 1) {
                showColorForData();
            }
        }
    });
    dataText.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent event) {
            if (image != null) {
                showColorForData();
            }
        }
    });

    // Label to show status and cursor location in image.
    statusLabel = new Label(shell, SWT.NULL);
    statusLabel.setText("");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    statusLabel.setLayoutData(gridData);
}

From source file:org.eclipse.swt.examples.imageanalyzer.ImageAnalyzer.java

void createWidgets() {
    // Add the widgets to the shell in a grid layout.
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;// w  ww  . j a v  a 2s .c om
    layout.numColumns = 2;
    shell.setLayout(layout);

    // Add a composite to contain some control widgets across the top.
    Composite controls = new Composite(shell, SWT.NONE);
    RowLayout rowLayout = new RowLayout();
    rowLayout.marginTop = 5;
    rowLayout.marginBottom = 5;
    rowLayout.spacing = 8;
    controls.setLayout(rowLayout);
    GridData gridData = new GridData();
    gridData.horizontalSpan = 2;
    controls.setLayoutData(gridData);

    // Combo to change the background.
    Group group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Background"));
    backgroundCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    backgroundCombo.setItems(bundle.getString("None"), bundle.getString("White"), bundle.getString("Black"),
            bundle.getString("Red"), bundle.getString("Green"), bundle.getString("Blue"));
    backgroundCombo.select(backgroundCombo.indexOf(bundle.getString("White")));
    backgroundCombo.addSelectionListener(widgetSelectedAdapter(event -> changeBackground()));

    // Combo to change the compression ratio.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new GridLayout(3, true));
    group.setText(bundle.getString("Save_group"));
    imageTypeCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    String[] types = { "JPEG", "PNG", "GIF", "ICO", "TIFF", "BMP" };
    for (String type : types) {
        imageTypeCombo.add(type);
    }
    imageTypeCombo.select(imageTypeCombo.indexOf("JPEG"));
    imageTypeCombo.addSelectionListener(widgetSelectedAdapter(event -> {
        int index = imageTypeCombo.getSelectionIndex();
        switch (index) {
        case 0:
            compressionCombo.setEnabled(true);
            compressionRatioLabel.setEnabled(true);
            if (compressionCombo.getItemCount() == 100)
                break;
            compressionCombo.removeAll();
            for (int i = 0; i < 100; i++) {
                compressionCombo.add(String.valueOf(i + 1));
            }
            compressionCombo.select(compressionCombo.indexOf("75"));
            break;
        case 1:
            compressionCombo.setEnabled(true);
            compressionRatioLabel.setEnabled(true);
            if (compressionCombo.getItemCount() == 10)
                break;
            compressionCombo.removeAll();
            for (int i = 0; i < 4; i++) {
                compressionCombo.add(String.valueOf(i));
            }
            compressionCombo.select(0);
            break;
        case 2:
        case 3:
        case 4:
        case 5:
            compressionCombo.setEnabled(false);
            compressionRatioLabel.setEnabled(false);
            break;
        }
    }));
    imageTypeCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    compressionRatioLabel = new Label(group, SWT.NONE);
    compressionRatioLabel.setText(bundle.getString("Compression"));
    compressionRatioLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    compressionCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 0; i < 100; i++) {
        compressionCombo.add(String.valueOf(i + 1));
    }
    compressionCombo.select(compressionCombo.indexOf("75"));
    compressionCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // Combo to change the x scale.
    String[] values = { "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1", "1.1", "1.2", "1.3",
            "1.4", "1.5", "1.6", "1.7", "1.8", "1.9", "2", "3", "4", "5", "6", "7", "8", "9", "10", };
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("X_scale"));
    scaleXCombo = new Combo(group, SWT.DROP_DOWN);
    for (String value : values) {
        scaleXCombo.add(value);
    }
    scaleXCombo.select(scaleXCombo.indexOf("1"));
    scaleXCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleX()));

    // Combo to change the y scale.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Y_scale"));
    scaleYCombo = new Combo(group, SWT.DROP_DOWN);
    for (String value : values) {
        scaleYCombo.add(value);
    }
    scaleYCombo.select(scaleYCombo.indexOf("1"));
    scaleYCombo.addSelectionListener(widgetSelectedAdapter(event -> scaleY()));

    // Combo to change the alpha value.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Alpha_K"));
    alphaCombo = new Combo(group, SWT.DROP_DOWN | SWT.READ_ONLY);
    for (int i = 0; i <= 255; i += 5) {
        alphaCombo.add(String.valueOf(i));
    }
    alphaCombo.select(alphaCombo.indexOf("255"));
    alphaCombo.addSelectionListener(widgetSelectedAdapter(event -> alpha()));

    // Check box to request incremental display.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Display"));
    incrementalCheck = new Button(group, SWT.CHECK);
    incrementalCheck.setText(bundle.getString("Incremental"));
    incrementalCheck.setSelection(incremental);
    incrementalCheck.addSelectionListener(
            widgetSelectedAdapter(event -> incremental = ((Button) event.widget).getSelection()));

    // Check box to request transparent display.
    transparentCheck = new Button(group, SWT.CHECK);
    transparentCheck.setText(bundle.getString("Transparent"));
    transparentCheck.setSelection(transparent);
    transparentCheck.addSelectionListener(widgetSelectedAdapter(event -> {
        transparent = ((Button) event.widget).getSelection();
        if (image != null) {
            imageCanvas.redraw();
        }
    }));

    // Check box to request mask display.
    maskCheck = new Button(group, SWT.CHECK);
    maskCheck.setText(bundle.getString("Mask"));
    maskCheck.setSelection(showMask);
    maskCheck.addSelectionListener(widgetSelectedAdapter(event -> {
        showMask = ((Button) event.widget).getSelection();
        if (image != null) {
            imageCanvas.redraw();
        }
    }));

    // Check box to request background display.
    backgroundCheck = new Button(group, SWT.CHECK);
    backgroundCheck.setText(bundle.getString("Background"));
    backgroundCheck.setSelection(showBackground);
    backgroundCheck.addSelectionListener(
            widgetSelectedAdapter(event -> showBackground = ((Button) event.widget).getSelection()));

    // Group the animation buttons.
    group = new Group(controls, SWT.NONE);
    group.setLayout(new RowLayout());
    group.setText(bundle.getString("Animation"));

    // Push button to display the previous image in a multi-image file.
    previousButton = new Button(group, SWT.PUSH);
    previousButton.setText(bundle.getString("Previous"));
    previousButton.setEnabled(false);
    previousButton.addSelectionListener(widgetSelectedAdapter(event -> previous()));

    // Push button to display the next image in a multi-image file.
    nextButton = new Button(group, SWT.PUSH);
    nextButton.setText(bundle.getString("Next"));
    nextButton.setEnabled(false);
    nextButton.addSelectionListener(widgetSelectedAdapter(event -> next()));

    // Push button to toggle animation of a multi-image file.
    animateButton = new Button(group, SWT.PUSH);
    animateButton.setText(bundle.getString("Animate"));
    animateButton.setEnabled(false);
    animateButton.addSelectionListener(widgetSelectedAdapter(event -> animate()));

    // Label to show the image file type.
    typeLabel = new Label(shell, SWT.NONE);
    typeLabel.setText(bundle.getString("Type_initial"));
    typeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Canvas to show the image.
    imageCanvas = new Canvas(shell, SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    imageCanvas.setBackground(whiteColor);
    imageCanvas.setCursor(crossCursor);
    gridData = new GridData();
    gridData.verticalSpan = 15;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    imageCanvas.setLayoutData(gridData);
    imageCanvas.addPaintListener(event -> {
        if (image == null) {
            Rectangle bounds = imageCanvas.getBounds();
            event.gc.fillRectangle(0, 0, bounds.width, bounds.height);
        } else {
            paintImage(event);
        }
    });
    imageCanvas.addMouseMoveListener(event -> {
        if (image != null) {
            showColorAt(event.x, event.y);
        }
    });

    // Set up the image canvas scroll bars.
    ScrollBar horizontal = imageCanvas.getHorizontalBar();
    horizontal.setVisible(true);
    horizontal.setMinimum(0);
    horizontal.setEnabled(false);
    horizontal
            .addSelectionListener(widgetSelectedAdapter(event -> scrollHorizontally((ScrollBar) event.widget)));
    ScrollBar vertical = imageCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.setMinimum(0);
    vertical.setEnabled(false);
    vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollVertically((ScrollBar) event.widget)));

    // Label to show the image size.
    sizeLabel = new Label(shell, SWT.NONE);
    sizeLabel.setText(bundle.getString("Size_initial"));
    sizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image depth.
    depthLabel = new Label(shell, SWT.NONE);
    depthLabel.setText(bundle.getString("Depth_initial"));
    depthLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the transparent pixel.
    transparentPixelLabel = new Label(shell, SWT.NONE);
    transparentPixelLabel.setText(bundle.getString("Transparent_pixel_initial"));
    transparentPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the time to load.
    timeToLoadLabel = new Label(shell, SWT.NONE);
    timeToLoadLabel.setText(bundle.getString("Time_to_load_initial"));
    timeToLoadLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Separate the animation fields from the rest of the fields.
    Label separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the logical screen size for animation.
    screenSizeLabel = new Label(shell, SWT.NONE);
    screenSizeLabel.setText(bundle.getString("Animation_size_initial"));
    screenSizeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the background pixel.
    backgroundPixelLabel = new Label(shell, SWT.NONE);
    backgroundPixelLabel.setText(bundle.getString("Background_pixel_initial"));
    backgroundPixelLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image location (x, y).
    locationLabel = new Label(shell, SWT.NONE);
    locationLabel.setText(bundle.getString("Image_location_initial"));
    locationLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image disposal method.
    disposalMethodLabel = new Label(shell, SWT.NONE);
    disposalMethodLabel.setText(bundle.getString("Disposal_initial"));
    disposalMethodLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the image delay time.
    delayTimeLabel = new Label(shell, SWT.NONE);
    delayTimeLabel.setText(bundle.getString("Delay_initial"));
    delayTimeLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show the background pixel.
    repeatCountLabel = new Label(shell, SWT.NONE);
    repeatCountLabel.setText(bundle.getString("Repeats_initial"));
    repeatCountLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Separate the animation fields from the palette.
    separator = new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Label to show if the image has a direct or indexed palette.
    paletteLabel = new Label(shell, SWT.NONE);
    paletteLabel.setText(bundle.getString("Palette_initial"));
    paletteLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    // Canvas to show the image's palette.
    paletteCanvas = new Canvas(shell, SWT.BORDER | SWT.V_SCROLL | SWT.NO_REDRAW_RESIZE);
    paletteCanvas.setFont(fixedWidthFont);
    paletteCanvas.getVerticalBar().setVisible(true);
    gridData = new GridData();
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    GC gc = new GC(paletteLabel);
    paletteWidth = gc.stringExtent(bundle.getString("Max_length_string")).x;
    gc.dispose();
    gridData.widthHint = paletteWidth;
    gridData.heightHint = 16 * 11; // show at least 16 colors
    paletteCanvas.setLayoutData(gridData);
    paletteCanvas.addPaintListener(event -> {
        if (image != null)
            paintPalette(event);
    });

    // Set up the palette canvas scroll bar.
    vertical = paletteCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.setMinimum(0);
    vertical.setIncrement(10);
    vertical.setEnabled(false);
    vertical.addSelectionListener(widgetSelectedAdapter(event -> scrollPalette((ScrollBar) event.widget)));

    // Sash to see more of image or image data.
    sash = new Sash(shell, SWT.HORIZONTAL);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    sash.setLayoutData(gridData);
    sash.addSelectionListener(widgetSelectedAdapter(event -> {
        if (event.detail != SWT.DRAG) {
            ((GridData) paletteCanvas.getLayoutData()).heightHint = SWT.DEFAULT;
            Rectangle paletteCanvasBounds = paletteCanvas.getBounds();
            int minY = paletteCanvasBounds.y + 20;
            Rectangle dataLabelBounds = dataLabel.getBounds();
            int maxY = statusLabel.getBounds().y - dataLabelBounds.height - 20;
            if (event.y > minY && event.y < maxY) {
                Rectangle oldSash = sash.getBounds();
                sash.setBounds(event.x, event.y, event.width, event.height);
                int diff = event.y - oldSash.y;
                Rectangle bounds = imageCanvas.getBounds();
                imageCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
                bounds = paletteCanvasBounds;
                paletteCanvas.setBounds(bounds.x, bounds.y, bounds.width, bounds.height + diff);
                bounds = dataLabelBounds;
                dataLabel.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height);
                bounds = dataText.getBounds();
                dataText.setBounds(bounds.x, bounds.y + diff, bounds.width, bounds.height - diff);
                //shell.layout(true);
            }
        }
    }));

    // Label to show data-specific fields.
    dataLabel = new Label(shell, SWT.NONE);
    dataLabel.setText(bundle.getString("Pixel_data_initial"));
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    dataLabel.setLayoutData(gridData);

    // Text to show a dump of the data.
    dataText = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL);
    dataText.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
    dataText.setFont(fixedWidthFont);
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    gridData.verticalAlignment = GridData.FILL;
    gridData.heightHint = 128;
    gridData.grabExcessVerticalSpace = true;
    dataText.setLayoutData(gridData);
    dataText.addMouseListener(MouseListener.mouseDownAdapter(event -> {
        if (image != null && event.button == 1) {
            showColorForData();
        }
    }));
    dataText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(KeyEvent event) {
            if (image != null) {
                showColorForData();
            }
        }
    });

    // Label to show status and cursor location in image.
    statusLabel = new Label(shell, SWT.NONE);
    statusLabel.setText("");
    gridData = new GridData();
    gridData.horizontalSpan = 2;
    gridData.horizontalAlignment = GridData.FILL;
    statusLabel.setLayoutData(gridData);
}

From source file:PaintExample.java

/**
 * Constructs a PaintSurface.//from   w w w  .  j  a  va2 s . c  o  m
 * <p>
 * paintCanvas must have SWT.NO_REDRAW_RESIZE and SWT.NO_BACKGROUND styles,
 *     and may have SWT.V_SCROLL and/or SWT.H_SCROLL.
 * </p>
 * @param paintCanvas the Canvas object in which to render
 * @param paintStatus the PaintStatus object to use for providing user feedback
 * @param fillColor the color to fill the canvas with initially
 */
public PaintSurface(Canvas paintCanvas, Text statusText, Color fillColor) {
    this.paintCanvas = paintCanvas;
    this.statusText = statusText;
    clearStatus();

    /* Set up the drawing surface */
    Rectangle displayRect = paintCanvas.getDisplay().getClientArea();
    imageWidth = displayRect.width;
    imageHeight = displayRect.height;
    image = new Image(paintCanvas.getDisplay(), imageWidth, imageHeight);

    imageFDC.gc = new GC(image);
    imageFDC.gc.setBackground(fillColor);
    imageFDC.gc.fillRectangle(0, 0, imageWidth, imageHeight);
    displayFDC.gc = new GC(paintCanvas);

    /* Initialize the session */
    setPaintSession(null);

    /* Add our listeners */
    paintCanvas.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            displayFDC.gc.dispose();
        }
    });
    paintCanvas.addMouseListener(new MouseAdapter() {
        public void mouseDown(MouseEvent event) {
            processMouseEventCoordinates(event);
            if (paintSession != null)
                paintSession.mouseDown(event);
        }

        public void mouseUp(MouseEvent event) {
            processMouseEventCoordinates(event);
            if (paintSession != null)
                paintSession.mouseUp(event);
        }

        public void mouseDoubleClick(MouseEvent event) {
            processMouseEventCoordinates(event);
            if (paintSession != null)
                paintSession.mouseDoubleClick(event);
        }
    });
    paintCanvas.addMouseMoveListener(new MouseMoveListener() {
        public void mouseMove(MouseEvent event) {
            processMouseEventCoordinates(event);
            if (paintSession != null)
                paintSession.mouseMove(event);
        }
    });
    paintCanvas.addPaintListener(new PaintListener() {
        public void paintControl(PaintEvent event) {
            if (rubberband.isEmpty()) {
                // Nothing to merge, so we just refresh
                event.gc.drawImage(image, displayFDC.xOffset + event.x, displayFDC.yOffset + event.y,
                        event.width, event.height, event.x, event.y, event.width, event.height);
            } else {
                /*
                 * Avoid flicker when merging overlayed objects by constructing the image on
                 * a backbuffer first, then blitting it to the screen.
                 */
                // Check that the backbuffer is large enough
                if (paintImage != null) {
                    Rectangle rect = paintImage.getBounds();
                    if ((event.width + event.x > rect.width) || (event.height + event.y > rect.height)) {
                        paintFDC.gc.dispose();
                        paintImage.dispose();
                        paintImage = null;
                    }
                }
                if (paintImage == null) {
                    Display display = getDisplay();
                    Rectangle rect = display.getClientArea();
                    paintImage = new Image(display, Math.max(rect.width, event.width + event.x),
                            Math.max(rect.height, event.height + event.y));
                    paintFDC.gc = new GC(paintImage);
                }
                // Setup clipping and the FDC
                Region clipRegion = new Region();
                event.gc.getClipping(clipRegion);
                paintFDC.gc.setClipping(clipRegion);
                clipRegion.dispose();

                paintFDC.xOffset = displayFDC.xOffset;
                paintFDC.yOffset = displayFDC.yOffset;
                paintFDC.xScale = displayFDC.xScale;
                paintFDC.yScale = displayFDC.yScale;

                // Merge the overlayed objects into the image, then blit
                paintFDC.gc.drawImage(image, displayFDC.xOffset + event.x, displayFDC.yOffset + event.y,
                        event.width, event.height, event.x, event.y, event.width, event.height);
                rubberband.draw(paintFDC);
                event.gc.drawImage(paintImage, event.x, event.y, event.width, event.height, event.x, event.y,
                        event.width, event.height);
            }
        }
    });
    paintCanvas.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent event) {
            handleResize();
        }
    });

    /* Set up the paint canvas scroll bars */
    ScrollBar horizontal = paintCanvas.getHorizontalBar();
    horizontal.setVisible(true);
    horizontal.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            scrollHorizontally((ScrollBar) event.widget);
        }
    });
    ScrollBar vertical = paintCanvas.getVerticalBar();
    vertical.setVisible(true);
    vertical.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            scrollVertically((ScrollBar) event.widget);
        }
    });
    handleResize();
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

/**
 * Removes all of the items from the receiver.
 *
 * @exception SWTException <ul>//from  w  w w. j  a v  a2  s.  c o m
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public void removeAll() {
    checkWidget();
    if (itemsCount == 0)
        return;
    setRedraw(false);

    setFocusItem(null, false);
    for (int i = 0; i < itemsCount; i++) {
        items[i].dispose(false);
    }
    items = new CTableItem[0];
    selectedItems = new CTableItem[0];
    int oldCount = itemsCount;
    itemsCount = topIndex = 0;
    anchorItem = lastClickedItem = null;
    lastSelectionEvent = null;

    int[] eventData = new int[5];
    eventData[0] = ACC.DELETE;
    eventData[1] = 0;
    eventData[2] = oldCount;
    eventData[3] = 0;
    eventData[4] = 0;
    getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);

    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        vBar.setMaximum(1);
        vBar.setVisible(false);
    }
    if (columns.length == 0) {
        horizontalOffset = 0;
        ScrollBar hBar = getHorizontalBar();
        if (hBar != null) {
            hBar.setMaximum(1);
            hBar.setVisible(false);
        }
    }

    setRedraw(true);
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

/**
 * Constructs a new instance of this class given its parent
 * and a style value describing its behavior and appearance.
 * <p>/*from  w  ww  . j a  va2  s. com*/
 * The style value is either one of the style constants defined in
 * class <code>SWT</code> which is applicable to instances of this
 * class, or must be built by <em>bitwise OR</em>'ing together
 * (that is, using the <code>int</code> "|" operator) two or more
 * of those <code>SWT</code> style constants. The class description
 * lists the style constants that are applicable to the class.
 * Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a composite control which will be the parent of the new instance (cannot be null)
 * @param style the style of control to construct
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
 * </ul>
 *
 * @see SWT#SINGLE
 * @see SWT#MULTI
 * @see SWT#CHECK
 * @see SWT#FULL_SELECTION
 * @see SWT#HIDE_SELECTION
 * @see SWT#VIRTUAL
 * @see SWT#NO_SCROLL
 * @see Widget#checkSubclass
 * @see Widget#getStyle
 */
public CTable(Composite parent, int style) {
    super(parent, checkStyle(style));
    this.display = parent.getDisplay();
    setForeground(null); /* set foreground and background to chosen default colors */
    setBackground(null);
    GC gc = new GC(this);
    fontHeight = gc.getFontMetrics().getHeight();
    gc.dispose();
    itemHeight = fontHeight + (2 * getCellPadding());
    initImages(display);
    checkboxBounds = getUncheckedImage().getBounds();
    arrowBounds = getArrowDownImage().getBounds();
    clientArea = getClientArea();

    Listener listener = event -> handleEvents(event);
    addListener(SWT.Paint, listener);
    addListener(SWT.MouseDown, listener);
    addListener(SWT.MouseUp, listener);
    addListener(SWT.MouseDoubleClick, listener);
    addListener(SWT.Dispose, listener);
    addListener(SWT.Resize, listener);
    addListener(SWT.KeyDown, listener);
    addListener(SWT.FocusOut, listener);
    addListener(SWT.FocusIn, listener);
    addListener(SWT.Traverse, listener);

    initAccessibility();

    header = new Canvas(this, SWT.NO_REDRAW_RESIZE | SWT.NO_FOCUS);
    header.setVisible(false);
    header.setBounds(0, 0, 0, fontHeight + 2 * getHeaderPadding());
    header.addListener(SWT.Paint, listener);
    header.addListener(SWT.MouseDown, listener);
    header.addListener(SWT.MouseUp, listener);
    header.addListener(SWT.MouseHover, listener);
    header.addListener(SWT.MouseDoubleClick, listener);
    header.addListener(SWT.MouseMove, listener);
    header.addListener(SWT.MouseExit, listener);
    header.addListener(SWT.MenuDetect, listener);

    toolTipListener = event -> {
        switch (event.type) {
        case SWT.MouseHover:
        case SWT.MouseMove:
            if (headerUpdateToolTip(event.x))
                break;
            // FALL THROUGH
        case SWT.MouseExit:
        case SWT.MouseDown:
            headerHideToolTip();
            break;
        }
    };

    ScrollBar hBar = getHorizontalBar();
    if (hBar != null) {
        hBar.setValues(0, 0, 1, 1, 1, 1);
        hBar.setVisible(false);
        hBar.addListener(SWT.Selection, listener);
    }
    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        vBar.setValues(0, 0, 1, 1, 1, 1);
        vBar.setVisible(false);
        vBar.addListener(SWT.Selection, listener);
    }
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void destroyItem(CTableColumn column) {
    headerHideToolTip();/*from w  w w.java2 s .co  m*/
    int index = column.getIndex();
    int orderedIndex = column.getOrderIndex();

    CTableColumn[] newColumns = new CTableColumn[columns.length - 1];
    System.arraycopy(columns, 0, newColumns, 0, index);
    System.arraycopy(columns, index + 1, newColumns, index, newColumns.length - index);
    columns = newColumns;

    if (orderedColumns != null) {
        if (columns.length < 2) {
            orderedColumns = null;
        } else {
            int removeIndex = column.getOrderIndex();
            CTableColumn[] newOrderedColumns = new CTableColumn[orderedColumns.length - 1];
            System.arraycopy(orderedColumns, 0, newOrderedColumns, 0, removeIndex);
            System.arraycopy(orderedColumns, removeIndex + 1, newOrderedColumns, removeIndex,
                    newOrderedColumns.length - removeIndex);
            orderedColumns = newOrderedColumns;
        }
    }

    /* ensure that column 0 always has left-alignment */
    if (index == 0 && columns.length > 0) {
        int style = columns[0].getStyle();
        style |= SWT.LEFT;
        style &= ~(SWT.CENTER | SWT.RIGHT);
        columns[0].setStyle(style);
    }

    /* allow all items to update their internal structures accordingly */
    for (int i = 0; i < itemsCount; i++) {
        items[i].removeColumn(column, index);
    }

    /* update horizontal scrollbar */
    int lastColumnIndex = columns.length - 1;
    if (lastColumnIndex < 0) { /* no more columns */
        updateHorizontalBar();
    } else {
        int newWidth = 0;
        for (CTableColumn column2 : columns) {
            newWidth += column2.width;
        }
        ScrollBar hBar = getHorizontalBar();
        if (hBar != null) {
            hBar.setMaximum(newWidth);
            hBar.setVisible(clientArea.width < newWidth);
        }
        int selection = hBar.getSelection();
        if (selection != horizontalOffset) {
            horizontalOffset = selection;
            redraw();
            if (header.isVisible() && drawCount <= 0)
                header.redraw();
        }
    }
    CTableColumn[] orderedColumns = getOrderedColumns();
    for (int i = orderedIndex; i < orderedColumns.length; i++) {
        if (!orderedColumns[i].isDisposed()) {
            orderedColumns[i].notifyListeners(SWT.Move, new Event());
        }
    }

    int[] eventData = new int[5];
    eventData[0] = ACC.DELETE;
    eventData[1] = 0;
    eventData[2] = 0;
    eventData[3] = index;
    eventData[4] = 1;
    getAccessible().sendEvent(ACC.EVENT_TABLE_CHANGED, eventData);

    if (sortColumn == column) {
        sortColumn = null;
    }
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

@Override
public void setFont(Font value) {
    checkWidget();/* ww  w.jav a2s  .  com*/
    Font oldFont = getFont();
    super.setFont(value);
    Font font = getFont();
    if (font.equals(oldFont))
        return;

    GC gc = new GC(this);

    /* recompute the receiver's cached font height and item height values */
    fontHeight = gc.getFontMetrics().getHeight();
    setItemHeight(Math.max(fontHeight, imageHeight) + 2 * getCellPadding());
    Point headerSize = header.getSize();
    int newHeaderHeight = Math.max(fontHeight, headerImageHeight) + 2 * getHeaderPadding();
    if (headerSize.y != newHeaderHeight) {
        header.setSize(headerSize.x, newHeaderHeight);
    }
    header.setFont(font);

    /*
     * Notify all columns and items of the font change so that elements that
     * use the receiver's font can recompute their cached string widths.
     */
    for (CTableColumn column : columns) {
        column.updateFont(gc);
    }
    for (int i = 0; i < itemsCount; i++) {
        items[i].updateFont(gc);
    }

    gc.dispose();

    if (drawCount <= 0 && header.isVisible())
        header.redraw();

    /* update scrollbars */
    if (columns.length == 0)
        updateHorizontalBar();
    ScrollBar vBar = getVerticalBar();
    if (vBar != null) {
        int thumb = (clientArea.height - getHeaderHeight()) / itemHeight;
        vBar.setThumb(thumb);
        vBar.setPageIncrement(thumb);
        topIndex = vBar.getSelection();
        vBar.setVisible(thumb < vBar.getMaximum());
    }
    redraw();
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void updateHorizontalBar(int newRightX, int rightXchange) {
    if (drawCount > 0)
        return;/*from   w  ww . j  a  v a  2s .  com*/
    ScrollBar hBar = getHorizontalBar();
    if (hBar == null)
        return;

    newRightX += horizontalOffset;
    int barMaximum = hBar.getMaximum();
    if (newRightX > barMaximum) { /* item has extended beyond previous maximum */
        hBar.setMaximum(newRightX);
        int clientAreaWidth = clientArea.width;
        int thumb = Math.min(newRightX, clientAreaWidth);
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
        hBar.setVisible(clientAreaWidth <= newRightX);
        return;
    }

    int previousRightX = newRightX - rightXchange;
    if (previousRightX != barMaximum) {
        /* this was not the rightmost item, so just check for client width change */
        int clientAreaWidth = clientArea.width;
        int thumb = Math.min(barMaximum, clientAreaWidth);
        hBar.setThumb(thumb);
        hBar.setPageIncrement(thumb);
        hBar.setVisible(clientAreaWidth <= barMaximum);
        return;
    }
    updateHorizontalBar(); /* must search for the new rightmost item */
}

From source file:org.eclipse.swt.examples.accessibility.CTable.java

void updateColumnWidth(CTableColumn column, int width) {
    headerHideToolTip();//from w  ww.ja  v a 2s.c o m
    int oldWidth = column.width;
    int columnX = column.getX();
    int x = columnX + oldWidth - 1; /* -1 ensures that grid line is included */

    update();
    GC gc = new GC(this);
    gc.copyArea(x, 0, clientArea.width - x, clientArea.height, columnX + width - 1,
            0); /* dest x -1 offsets x's -1 above */
    if (width > oldWidth) {
        /* column width grew */
        int change = width - oldWidth + 1; /* +1 offsets x's -1 above */
        /* -1/+1 below ensure that right bound of selection redraws correctly in column */
        redraw(x - 1, 0, change + 1, clientArea.height, false);
    } else {
        int change = oldWidth - width + 1; /* +1 offsets x's -1 above */
        redraw(clientArea.width - change, 0, change, clientArea.height, false);
    }
    /* the focus box must be repainted because its stipple may become shifted as a result of its new width */
    if (focusItem != null)
        redrawItem(focusItem.index, true);

    GC headerGC = new GC(header);
    if (drawCount <= 0 && header.getVisible()) {
        Rectangle headerBounds = header.getClientArea();
        header.update();
        x -= 1; /* -1 ensures that full header column separator is included */
        headerGC.copyArea(x, 0, headerBounds.width - x, headerBounds.height, columnX + width - 2,
                0); /* dest x -2 offsets x's -1s above */
        if (width > oldWidth) {
            /* column width grew */
            int change = width - oldWidth + 2; /* +2 offsets x's -1s above */
            header.redraw(x, 0, change, headerBounds.height, false);
        } else {
            int change = oldWidth - width + 2; /* +2 offsets x's -1s above */
            header.redraw(headerBounds.width - change, 0, change, headerBounds.height, false);
        }
    }

    column.width = width;

    /*
     * Notify column and all items of column width change so that display labels
     * can be recomputed if needed.
     */
    column.updateWidth(headerGC);
    headerGC.dispose();
    for (int i = 0; i < itemsCount; i++) {
        items[i].updateColumnWidth(column, gc);
    }
    gc.dispose();

    int maximum = 0;
    for (CTableColumn column2 : columns) {
        maximum += column2.width;
    }
    ScrollBar hBar = getHorizontalBar();
    if (hBar != null) {
        hBar.setMaximum(Math.max(1, maximum)); /* setting a value of 0 here is ignored */
        if (hBar.getThumb() != clientArea.width) {
            hBar.setThumb(clientArea.width);
            hBar.setPageIncrement(clientArea.width);
        }
        int oldHorizontalOffset = horizontalOffset; /* hBar.setVisible() can modify horizontalOffset */
        hBar.setVisible(clientArea.width < maximum);
        int selection = hBar.getSelection();
        if (selection != oldHorizontalOffset) {
            horizontalOffset = selection;
            redraw();
            if (drawCount <= 0 && header.getVisible())
                header.redraw();
        }
    }

    column.notifyListeners(SWT.Resize, new Event());
    CTableColumn[] orderedColumns = getOrderedColumns();
    for (int i = column.getOrderIndex() + 1; i < orderedColumns.length; i++) {
        if (!orderedColumns[i].isDisposed()) {
            orderedColumns[i].notifyListeners(SWT.Move, new Event());
        }
    }

    if (itemsCount == 0)
        redraw(); /* ensure that static focus rectangle updates properly */
}