Example usage for javax.swing JComponent getWidth

List of usage examples for javax.swing JComponent getWidth

Introduction

In this page you can find the example usage for javax.swing JComponent getWidth.

Prototype

@BeanProperty(bound = false)
public int getWidth() 

Source Link

Document

Returns the current width of this component.

Usage

From source file:org.freeplane.view.swing.map.ClickableImageCreator.java

private void createArea(final NodeModel node) {
    final NodeView nodeView = mapView.getNodeView(node);
    if (nodeView != null) {
        final AreaHolder holder = new AreaHolder();
        holder.title = TextController.getController().getShortText(node);
        holder.alt = TextController.getController().getShortText(node);
        holder.href = node.createID();//from  w  w w.  j  a v  a  2  s .c o  m
        final Point contentXY = mapView.getNodeContentLocation(nodeView);
        final JComponent content = nodeView.getContent();
        holder.coordinates.x = (int) (contentXY.x - innerBounds.getMinX());
        holder.coordinates.y = (int) (contentXY.y - innerBounds.getMinY());
        holder.coordinates.width = content.getWidth();
        holder.coordinates.height = content.getHeight();
        area.add(holder);
        for (final NodeModel child : mapView.getModeController().getMapController().childrenUnfolded(node)) {
            createArea(child);
        }
    }
}

From source file:org.openmicroscopy.shoola.agents.imviewer.view.ImViewerUI.java

/**
 * Sets the lens's visibility. If the lens hasn't previously created, 
 * we first create the lens./*  www.j a v a2  s .c  o m*/
 * 
 * @param b          Pass <code>true</code> to display the lens, 
 *                   <code>false</code> otherwise.
 * @param historyIndex   The index of the tab pane. 
 */
void setLensVisible(boolean b, int historyIndex) {
    boolean firstTime = false;
    if (lens == null) {
        if (b) {
            firstTime = true;
            lens = new LensComponent(this, ImViewerAgent.hasOpenGLSupport());
            lens.setImageName(model.getImageName());
            lens.setXYPixelMicron(model.getPixelsSizeX(), model.getPixelsSizeY());
            lens.addPropertyChangeListener(LensComponent.LENS_LOCATION_PROPERTY, controller);
        } else
            return;

    } else {
        Browser browser = model.getBrowser();
        JComponent c = lens.getLensUI();
        browser.removeComponent(c, ImViewer.VIEW_INDEX);
        browser.removeComponent(c, ImViewer.GRID_INDEX);
        browser.removeComponent(c, ImViewer.PROJECTION_INDEX);
    }
    if (!b) {
        lens.setVisible(b);
        repaint();
        return;
    }
    //depending on the previous selected tabbed pane, 
    //we reset the location of the lens

    int maxX = model.getMaxX();
    int maxY = model.getMaxY();
    float f = 1.0f;
    //BufferedImage img;
    int index = model.getTabbedIndex();

    JComponent c = lens.getLensUI();
    int width = c.getWidth();
    int height = c.getHeight();
    Point p = lens.getLensLocation();
    int lensX = p.x;
    int lensY = p.y;
    if (maxX < width || maxY < height)
        return;
    if (firstTime) {
        //firstTimeLensShown = false;
        int diffX = maxX - width;
        int diffY = maxY - height;
        lensX = diffX / 2;
        lensY = diffY / 2;
        if (lensX + width > maxX)
            lensX = diffX;
        if (lensY + height > maxY)
            lensY = diffY;
    } else {
        switch (historyIndex) {
        case ImViewer.GRID_INDEX:
            if (historyIndex != index) {
                Point point = model.getBrowser().isOnImageInGrid(lens.getLensScaledBounds());
                if (point == null) {
                    int diffX = maxX - width;
                    int diffY = maxY - height;
                    lensX = diffX / 2;
                    lensY = diffY / 2;
                    if (lensX + width > maxX)
                        lensX = diffX;
                    if (lensY + height > maxY)
                        lensY = diffY;
                } else {
                    double r = model.getBrowser().getRatio();
                    lensX = (int) (point.x / r);
                    lensY = (int) (point.y / r);
                }
            }
            break;
        case ImViewer.PROJECTION_INDEX:
        case ImViewer.VIEW_INDEX:
            if (index == ImViewer.GRID_INDEX) {
                double r = model.getBrowser().getRatio();
                lensX = (int) (lensX * r);
                lensY = (int) (lensY * r);
            }
        }
    }
    if (ImViewerAgent.hasOpenGLSupport()) {
        TextureData image;

        switch (index) {
        case ImViewer.VIEW_INDEX:
        default:
            f = (float) model.getZoomFactor();
            image = model.getImageAsTexture();
            //img = model.getOriginalImage();
            break;
        case ImViewer.PROJECTION_INDEX:
            f = (float) model.getZoomFactor();
            image = model.getProjectedImageAsTexture();
            //img = model.getProjectedImage();
            break;
        case ImViewer.GRID_INDEX:
            //img = model.getGridImage();
            image = null;
        }
        if (image != null)
            lens.resetLensAsTexture(image, f, lensX, lensY);
    } else {
        BufferedImage img;
        switch (index) {
        case ImViewer.VIEW_INDEX:
        default:
            f = (float) model.getZoomFactor();
            img = model.getOriginalImage();
            break;
        case ImViewer.PROJECTION_INDEX:
            f = (float) model.getZoomFactor();
            img = model.getProjectedImage();
            break;
        case ImViewer.GRID_INDEX:
            img = model.getGridImage();
        }
        if (img != null)
            lens.resetLens(img, f, lensX, lensY);
    }
    model.getBrowser().addComponent(c, index, true);
    scrollLens();
    UIUtilities.setLocationRelativeTo(this, lens.getZoomWindow());
    lens.setVisible(b);
    repaint();
}