Example usage for java.awt Rectangle Rectangle

List of usage examples for java.awt Rectangle Rectangle

Introduction

In this page you can find the example usage for java.awt Rectangle Rectangle.

Prototype

public Rectangle(int x, int y, int width, int height) 

Source Link

Document

Constructs a new Rectangle whose upper-left corner is specified as (x,y) and whose width and height are specified by the arguments of the same name.

Usage

From source file:com.htmlhifive.pitalium.image.model.RectangleArea.java

/**
 * ???????{@link Rectangle}?????//from  w  w  w . j a  v  a2 s .  c  o  m
 * 
 * @return ???????{@link Rectangle}
 */
public Rectangle toRectangle() {
    RectangleArea rect = round();
    return new Rectangle((int) rect.x, (int) rect.y, (int) rect.width, (int) rect.height);
}

From source file:org.esa.beam.visat.toolviews.stat.XYImagePlot.java

final Rectangle getImageSourceArea() {
    Assert.notNull(image);// w w w .  ja  v a2  s.c om
    Assert.notNull(imageDataBounds);
    final ValueAxis xAxis = getDomainAxis();
    final ValueAxis yAxis = getRangeAxis();
    final double scaleX = image.getWidth() / imageDataBounds.getWidth();
    final double scaleY = image.getHeight() / imageDataBounds.getHeight();
    final int x = crop(scaleX * (xAxis.getLowerBound() - imageDataBounds.getMinX()), 0, image.getWidth() - 1);
    final int y = crop(scaleY * (imageDataBounds.getMaxY() - yAxis.getUpperBound()), 0, image.getHeight() - 1);
    final int w = crop(scaleX * (xAxis.getUpperBound() - xAxis.getLowerBound()), 1, image.getWidth());
    final int h = crop(scaleY * (yAxis.getUpperBound() - yAxis.getLowerBound()), 1, image.getHeight());
    return new Rectangle(x, y, w, h);
}

From source file:com.funambol.admin.settings.panels.EditConsoleAppender.java

/**
 * Create the panel/*from w w  w. j a va2  s. c  o  m*/
 * @throws Exception if error occures during creation of the panel.
 */
private void init() throws Exception {

    final int h = 18;
    final int x1 = 15;
    final int x2 = 150;
    final int w1 = 100;
    final int w2 = 310;

    int y = 40;
    int dy = 25;

    setLayout(null);
    setName(Bundle.getMessage(Bundle.EDIT_CONSOLE_APPENDER_PANEL_NAME));

    panelNameLabel.setText(Bundle.getMessage(Bundle.EDIT_CONSOLE_APPENDER_PANEL_NAME));
    panelNameLabel.setBounds(new Rectangle(14, 5, 245, 28));
    panelNameLabel.setAlignmentX(SwingConstants.CENTER);
    panelNameLabel.setBorder(new TitledBorder(""));

    nameLabel.setText(Bundle.getMessage(Bundle.LABEL_APPENDER_NAME) + " :");
    nameLabel.setBounds(new Rectangle(x1, y, w1, h));
    nameLabel2.setBounds(new Rectangle(x2, y, w2, h));

    y += dy;

    conversionPatternLabel.setText(Bundle.getMessage(Bundle.LABEL_PATTERN_LAYOUT) + " :");
    conversionPatternLabel.setBounds(new Rectangle(x1, y, w1, h));
    conversionPattern.setBounds(new Rectangle(x2, y, w2, h));

    y += dy;
    y += dy;

    confirmButton.setText(Bundle.getMessage(Bundle.LABEL_BUTTON_SAVE));
    confirmButton.setBounds(new Rectangle(401, y, 60, 25));

    confirmButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                EditConsoleAppender.this.actionPerformed(new ActionEvent(EditConsoleAppender.this,
                        ACTION_EVENT_UPDATE, event.getActionCommand()));
            } catch (Exception e) {
                notifyError(new AdminException(e.getMessage()));
            }
        }
    });

    add(panelNameLabel, null);
    add(nameLabel, null);
    add(nameLabel2, null);
    add(conversionPatternLabel, null);
    add(conversionPattern, null);
    add(confirmButton, null);

    GuiFactory.setDefaultFont(this);
    panelNameLabel.setFont(GuiFactory.titlePanelFont);

}

From source file:gdsc.smlm.ij.plugins.EMGainAnalysis.java

public void run(ImageProcessor ip) {
    // Calculate the histogram
    final int[] h = (simulate) ? simulateHistogram(usePDF ? 0 : 1) : buildHistogram(imp);

    // We need > 10^7 pixels from flat white-light images under constant exposure ...
    final int size = getSize(h);
    if (imp != null) {
        Roi roi = imp.getRoi();//from   ww w. j  a  v a 2s  . c om
        Rectangle bounds;
        if (roi == null)
            bounds = new Rectangle(0, 0, imp.getWidth(), imp.getHeight());
        else
            bounds = roi.getBounds();
        Utils.log("Analysing %s [x=%d,y=%d,width=%d,height=%d]", imp.getTitle(), bounds.x, bounds.y,
                bounds.width, bounds.height);
    }
    Utils.log("Histogram contains %d pixels", size);
    if (size < MINIMUM_PIXELS)
        Utils.log("WARNING : Recommend at least %d pixels (%sx more)", MINIMUM_PIXELS,
                Utils.rounded((double) MINIMUM_PIXELS / size));

    fit(h);
}

From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartSvgRenderer.java

byte[] renderJFreeChart(JFreeChart chart, float width, float height, boolean naked, Date fromDate, Date toDate)
        throws IOException {
    String svgNamespaceUri = SVGDOMImplementation.SVG_NAMESPACE_URI;
    Document doc = SVGDOMImplementation.getDOMImplementation().createDocument(svgNamespaceUri, "svg", null);

    String generatedText = "Generated "
            + DateUtils.formatAsStringToLong(new Date(), UserContext.getCurrentLocale()) + " by "
            + MessageAccess.getStringOrNull("global.applicationname", UserContext.getCurrentLocale()) + " "
            + properties.getBuildId();//from   ww  w. j  a  v  a  2 s . co  m
    String drawingInfo = MessageAccess.getStringOrNull("graphicalExport.timeline.drawInfo",
            UserContext.getCurrentLocale()) + ": "
            + DateUtils.formatAsString(fromDate, UserContext.getCurrentLocale()) + " -> "
            + DateUtils.formatAsString(toDate, UserContext.getCurrentLocale());

    SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc);
    ctx.setComment(generatedText);
    SVGGraphics2D svgGraphics = new SVGGraphics2D(ctx, false);

    if (!naked) {
        //Render the chart to the SVG graphics object
        chart.draw(svgGraphics, new Rectangle(20, 20, Math.round(width - MARGIN), Math.round(height - MARGIN)));

        //Add logo and generated text
        int widthIntForLogo = Math.round(width + 40 - MARGIN);
        int heightIntForLogo = Math.round(height - MARGIN + 20);

        int xLogoUpperRightCorner[] = { widthIntForLogo - 40, widthIntForLogo, widthIntForLogo,
                widthIntForLogo - 8, widthIntForLogo - 8, widthIntForLogo - 40 };
        int yLogoUpperRightCorner[] = { MARGIN_TOP, MARGIN_TOP, MARGIN_TOP + 40, MARGIN_TOP + 40,
                MARGIN_TOP + 8, MARGIN_TOP + 8 };

        GeneralPath logoUpperRightCorner = new GeneralPath();
        logoUpperRightCorner.moveTo(xLogoUpperRightCorner[0], yLogoUpperRightCorner[0]);
        for (int i = 1; i < xLogoUpperRightCorner.length; i++) {
            logoUpperRightCorner.lineTo(xLogoUpperRightCorner[i], yLogoUpperRightCorner[i]);
        }
        logoUpperRightCorner.closePath();
        svgGraphics.setColor(Color.decode(COLOR_LOGO));
        svgGraphics.fill(logoUpperRightCorner);
        svgGraphics.draw(logoUpperRightCorner);

        int xLogoLowerLeftCorner[] = { MARGIN_LEFT, MARGIN_LEFT + 8, MARGIN_LEFT + 8, MARGIN_LEFT + 40,
                MARGIN_LEFT + 40, MARGIN_LEFT };
        int yLogoLowerLeftCorner[] = { heightIntForLogo, heightIntForLogo, heightIntForLogo + 32,
                heightIntForLogo + 32, heightIntForLogo + 40, heightIntForLogo + 40 };

        GeneralPath logoLowerLeftCorner = new GeneralPath();
        logoLowerLeftCorner.moveTo(xLogoLowerLeftCorner[0], yLogoLowerLeftCorner[0]);
        for (int i = 1; i < xLogoLowerLeftCorner.length; i++) {
            logoLowerLeftCorner.lineTo(xLogoLowerLeftCorner[i], yLogoLowerLeftCorner[i]);
        }
        logoLowerLeftCorner.closePath();
        svgGraphics.setColor(Color.BLACK);
        svgGraphics.fill(logoLowerLeftCorner);
        svgGraphics.draw(logoLowerLeftCorner);

        Font f = new Font(null, Font.ITALIC, 12);
        svgGraphics.setFont(f);
        FontMetrics fontMetrics = svgGraphics.getFontMetrics(f);
        int charsWidthInfo = fontMetrics.stringWidth(drawingInfo);
        svgGraphics.drawString(drawingInfo, width - MARGIN - charsWidthInfo,
                height - MARGIN + MARGIN_DOWN_GENERATED_TEXT);
        int charsWidth = fontMetrics.stringWidth(generatedText);
        svgGraphics.drawString(generatedText, width - MARGIN - charsWidth,
                height - MARGIN + MARGIN_DOWN_GENERATED_TEXT + 20);

    } else {
        chart.draw(svgGraphics,
                new Rectangle(20, 20, Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN),
                        Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN)));
    }

    svgGraphics.setSVGCanvasSize(new Dimension((int) width, (int) height));

    //Convert the SVGGraphics2D object to SVG XML 
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Writer out = new OutputStreamWriter(baos, "UTF-8");
    svgGraphics.stream(out, true);
    byte[] originalSvgXml = baos.toByteArray();

    //    return originalSvgXml;
    return addAdditionalAttributes(originalSvgXml);
}

From source file:edu.uchc.octane.ParticleAnalysis.java

/**
 * Analyze the image/*from   w w  w.  j  a v  a2s.  c o  m*/
 * @param ip The image to be analyzed
 * @param mask A rectangle of region of interest
 * @param threshold Lowest intensity to be analyzed
 * @param noise The noise threshold of the watershed algorithm
 * @throws InterruptedException
 */
public void process(ImageProcessor ip, Rectangle mask, int threshold, int noise) throws InterruptedException {

    int border = 1;

    if (g_ != null) {

        //         g_.setImageData(ip, isZeroBg_);

        border = g_.getWindowSize();
    }

    width_ = ip.getWidth();
    height_ = ip.getHeight();

    int[] offsets = { -width_, -width_ + 1, +1, +width_ + 1, +width_, +width_ - 1, -1, -width_ - 1 };

    Rectangle bbox = new Rectangle(border, border, width_ - 2 * border, height_ - 2 * border);
    bbox = bbox.intersection(mask);

    ArrayList<Pixel> pixels = new ArrayList<Pixel>();

    for (int y = bbox.y; y < bbox.y + bbox.height; y++) {
        for (int x = bbox.x; x < bbox.x + bbox.width; x++) {
            int v = ip.get(x, y);
            if (v > threshold) {
                pixels.add(new Pixel(x, y, v));
            }
        }
    }
    Collections.sort(pixels);

    nParticles_ = 0;
    x_ = new double[pixels.size()];
    y_ = new double[pixels.size()];
    z_ = new double[pixels.size()];
    h_ = new double[pixels.size()];
    e_ = new double[pixels.size()];

    FloodState floodState = new FloodState(width_, height_);
    floodState.floodBorders(bbox);

    int idxList, lenList;
    int[] listOfIndexes = new int[width_ * height_];

    for (Pixel p : pixels) {

        if (Thread.interrupted()) {
            throw (new InterruptedException());
        }

        int index = p.x + width_ * p.y;

        if (floodState.isProcessed(index)) {
            continue;
        }

        int v = p.value;
        boolean isMax = true;

        idxList = 0;
        lenList = 1;

        listOfIndexes[0] = index;

        floodState.flood(index);

        do {
            index = listOfIndexes[idxList];
            for (int d = 0; d < 8; d++) { // analyze all neighbors (in 8 directions) at the same level

                int index2 = index + offsets[d];

                if (floodState.isProcessed(index2)) { //conflict
                    isMax = false;
                    break;
                }

                if (!floodState.isFlooded(index2)) {
                    int v2 = ip.get(index2);
                    if (v2 >= v - noise) {
                        listOfIndexes[lenList++] = index2;
                        floodState.flood(index2);
                    }
                }
            }
        } while (++idxList < lenList);

        for (idxList = 0; idxList < lenList; idxList++) {
            floodState.process(listOfIndexes[idxList]);
        }

        if (isMax) {

            if (g_ != null) {

                g_.setInitialCoordinates(p.x, p.y);

                try {

                    double[] result = g_.fit();

                    if (result == null) {
                        continue;
                    }

                    double h = g_.getH();
                    if (h < noise || h < getHeightMin() || h > getHeightMax()) {
                        continue;
                    }

                    double e = g_.getE();
                    if (e < getFittingQualityMin()) {
                        continue;
                    }

                    x_[nParticles_] = g_.getX();
                    y_[nParticles_] = g_.getY();
                    z_[nParticles_] = g_.getZ();
                    h_[nParticles_] = h;
                    e_[nParticles_] = e;
                    nParticles_++;
                } catch (MathIllegalStateException e) {
                    //failed fitting
                    continue;
                }
            } else {

                x_[nParticles_] = (double) p.x;
                y_[nParticles_] = (double) p.y;
                h_[nParticles_] = (double) p.value;
                nParticles_++;

            }
        }
    }
}

From source file:com.funambol.json.admin.NoteSyncSourceAdminPanel.java

/**
 * Create the panel/*from w w w .  j ava 2  s .co  m*/
 * @throws Exception if error occures during creation of the panel
 */
private void init() {
    // set layout
    this.setLayout(null);
    // set properties of label, position and border
    //  referred to the title of the panel
    titledBorder = new TitledBorder("");
    panelName.setFont(titlePanelFont);
    panelName.setText(getPanelName());
    panelName.setBounds(new Rectangle(14, 5, 316, 28));
    panelName.setAlignmentX(SwingConstants.CENTER);
    panelName.setBorder(titledBorder);

    final int LABEL_X = 14;
    final int VALUE_X = 170;
    int y = 60;
    final int GAP_X = 150;
    final int GAP_Y = 30;

    sourceUriLabel.setText("Source URI: ");
    sourceUriLabel.setFont(defaultFont);
    sourceUriLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    sourceUriValue.setFont(defaultFont);
    sourceUriValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));

    y += GAP_Y; // New line

    nameLabel.setText("Name: ");
    nameLabel.setFont(defaultFont);
    nameLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    nameValue.setFont(defaultFont);
    nameValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));
    y += GAP_Y; // New line

    typeLabel.setText("Client Type: ");
    typeLabel.setFont(defaultFont);
    typeLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    typeCombo.setFont(defaultFont);
    typeCombo.setBounds(new Rectangle(VALUE_X, y, 350, 18));

    y += GAP_Y; // New line
    int x = LABEL_X;

    confirmButton.setFont(defaultFont);
    confirmButton.setText("Add");
    confirmButton.setBounds(VALUE_X, y, 70, 25);

    // What happens when the confirmButton is pressed?
    confirmButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                if (getState() == STATE_INSERT) {
                    NoteSyncSourceAdminPanel.this.actionPerformed(new ActionEvent(NoteSyncSourceAdminPanel.this,
                            ACTION_EVENT_INSERT, event.getActionCommand()));
                } else {
                    NoteSyncSourceAdminPanel.this.actionPerformed(new ActionEvent(NoteSyncSourceAdminPanel.this,
                            ACTION_EVENT_UPDATE, event.getActionCommand()));
                }
            } catch (Exception e) {
                notifyError(new AdminException(e.getMessage(), e));
            }
        }
    });

    // Adds all components to the panel
    this.add(panelName, null);
    this.add(nameLabel, null);
    this.add(sourceUriLabel, null);
    this.add(sourceUriValue, null);
    this.add(nameValue, null);
    this.add(typeLabel, null);
    this.add(typeCombo, null);
    this.add(confirmButton, null);

}

From source file:com.funambol.foundation.admin.FileSystemSyncSourceConfigPanel.java

/**
 * Create the panel/*  ww  w  .j  a  va 2s .  co m*/
 * @throws Exception if error occures during creation of the panel
 */

private void init() {
    // set layout
    this.setLayout(null);

    // set properties of label, position and border
    //  referred to the title of the panel
    titledBorder1 = new TitledBorder("");

    panelName.setFont(titlePanelFont);
    panelName.setText("Edit File System SyncSource");
    panelName.setBounds(new Rectangle(14, 5, 316, 28));
    panelName.setAlignmentX(SwingConstants.CENTER);
    panelName.setBorder(titledBorder1);

    int y = 60;
    int dy = 30;

    sourceUriLabel.setText("Source URI: ");
    sourceUriLabel.setFont(defaultFont);
    sourceUriLabel.setBounds(new Rectangle(14, y, 150, 18));
    sourceUriValue.setFont(defaultFont);
    sourceUriValue.setBounds(new Rectangle(170, y, 350, 18));

    y += dy;

    nameLabel.setText("Name: ");
    nameLabel.setFont(defaultFont);
    nameLabel.setBounds(new Rectangle(14, y, 150, 18));
    nameValue.setFont(defaultFont);
    nameValue.setBounds(new Rectangle(170, y, 350, 18));

    y += dy;

    directoryLabel.setText("Source Directory: ");
    directoryLabel.setFont(defaultFont);
    directoryLabel.setBounds(new Rectangle(14, y, 150, 18));
    directoryValue.setFont(defaultFont);
    directoryValue.setBounds(new Rectangle(170, y, 350, 18));

    y += dy;

    infoTypesLabel.setText("Supported types: ");
    infoTypesLabel.setFont(defaultFont);
    infoTypesLabel.setBounds(new Rectangle(14, y, 150, 18));
    infoTypesValue.setFont(defaultFont);
    infoTypesValue.setBounds(new Rectangle(170, y, 350, 18));

    y += dy;

    infoVersionsLabel.setText("Supported versions: ");
    infoVersionsLabel.setFont(defaultFont);
    infoVersionsLabel.setBounds(new Rectangle(14, y, 150, 18));
    infoVersionsValue.setFont(defaultFont);
    infoVersionsValue.setBounds(new Rectangle(170, y, 350, 18));

    y += dy;

    multiUserLabel.setText("MultiUser: ");
    multiUserLabel.setFont(defaultFont);
    multiUserLabel.setBounds(new Rectangle(14, y, 150, 18));
    multiUserValue.setSelected(false);
    multiUserValue.setBounds(167, y, 50, 25);

    y += dy;
    y += dy;

    confirmButton.setFont(defaultFont);
    confirmButton.setText("Add");
    confirmButton.setBounds(170, y, 70, 25);

    confirmButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                if (getState() == STATE_INSERT) {
                    FileSystemSyncSourceConfigPanel.this
                            .actionPerformed(new ActionEvent(FileSystemSyncSourceConfigPanel.this,
                                    ACTION_EVENT_INSERT, event.getActionCommand()));
                } else {
                    FileSystemSyncSourceConfigPanel.this
                            .actionPerformed(new ActionEvent(FileSystemSyncSourceConfigPanel.this,
                                    ACTION_EVENT_UPDATE, event.getActionCommand()));
                }
            } catch (Exception e) {
                notifyError(new AdminException(e.getMessage()));
            }
        }
    });

    // add all components to the panel
    this.add(panelName, null);
    this.add(sourceUriLabel, null);
    this.add(sourceUriValue, null);
    this.add(nameLabel, null);
    this.add(nameValue, null);
    this.add(directoryLabel, null);
    this.add(directoryValue, null);
    this.add(infoTypesLabel, null);
    this.add(infoTypesValue, null);
    this.add(infoVersionsLabel, null);
    this.add(infoVersionsValue, null);
    this.add(multiUserLabel, null);
    this.add(multiUserValue, null);
    this.add(confirmButton, null);

}

From source file:knop.psfj.BeadAveragerSubPixel.java

@Override
public ImagePlus averageBead(ArrayList<BeadFrame> list) {

    ImagePlus result = null;/*  w ww  .j a va  2 s. c o  m*/
    int extensionFactor = 10;
    int addedPixel = 3;
    PerfectCropper cropperX = null;
    PerfectCropper cropperY = null;
    PerfectCropper cropperZ = null;
    setTotalBeads(list.size());

    list = filter(list);

    int idealRange = (2 * addedPixel * extensionFactor);

    int fovWidth = list.get(0).getSource().getImageWidth();
    int fovHeight = list.get(0).getSource().getImageHeight();

    for (BeadFrame frame : list) {
        ExtendedBeadFrame extendedFrame = new ExtendedBeadFrame(frame, extensionFactor, addedPixel);

        int x = extendedFrame.boundaries.x;
        int y = extendedFrame.boundaries.y;
        int x2 = x + extendedFrame.boundaries.width;
        int y2 = y + extendedFrame.boundaries.height;

        // if the extended frame is out of the field of view, it,s not
        // taken into account
        if (x < 0 || y < 0 || x2 > fovWidth || y2 > fovHeight) {
            incrementFilteredOutBeadCount();
            continue;
        }
        extendedFrameList.add(extendedFrame);

        if (cropperX == null) {
            cropperX = new PerfectCropper(extendedFrame.getExtendedWidth(),
                    extendedFrame.getExtendedWidth() - idealRange);
            cropperY = new PerfectCropper(extendedFrame.getExtendedHeight(),
                    extendedFrame.getExtendedHeight() - idealRange);
            cropperZ = new PerfectCropper(extendedFrame.getExtendedDepth(), -1);
        }

        cropperX.addCenter(extendedFrame.getCentroidXAsInt());
        cropperY.addCenter(extendedFrame.getCentroidYAsInt());
        cropperZ.addCenter(extendedFrame.getCentroidZAsInt());

    }

    cropperX.calculateCommonRange();
    cropperY.calculateCommonRange();
    cropperZ.calculateCommonRange();

    ArrayList<ImageStack> centeredStacks = new ArrayList<ImageStack>();

    ImageStack averageStack = null;
    updateProgress(1, extendedFrameList.size());
    int p = 1;
    int max = extendedFrameList.size();
    // for each extended frame
    for (ExtendedBeadFrame extFrame : extendedFrameList) {

        // we get the extended frame
        ImageStack croppedStack = extFrame.getExtendedStack();

        // we calculate the boundaries of the ROI using the PerfectCropper
        // object
        // (it centers the center around the centroid).
        int x = cropperX.getBoundaryLeft(extFrame.getCentroidXAsInt());
        int w = cropperX.getBoundaryRight(extFrame.getCentroidXAsInt()) - x;

        int y = cropperY.getBoundaryLeft(extFrame.getCentroidYAsInt());
        int h = cropperY.getBoundaryRight(extFrame.getCentroidYAsInt()) - y;

        // StackProcessor processor = new StackProcessor(croppedStack);
        // the stack is cropped in X and Y
        croppedStack = ImageProcessorUtils.crop(croppedStack, new Rectangle(x, y, w, h));

        System.out.println(String.format("Cropped zone : (%d,%d) : %d x %d, max : %d\nfrom %d to %d", x, y, w,
                h, extFrame.getExtendedWidth(), cropperZ.getBoundaryLeft(extFrame.getCentroidZAsInt()),
                cropperZ.getBoundaryRight(extFrame.getCentroidZAsInt())));
        System.out.println(String.format("Effective Cropped zone : (%d,%d) : %d x %d,\nfrom %d to %d", x, y,
                croppedStack.getWidth(), croppedStack.getHeight(),
                cropperZ.getBoundaryLeft(extFrame.getCentroidZAsInt()),
                cropperZ.getBoundaryRight(extFrame.getCentroidZAsInt())));

        // then the stack is cropped in Z
        int originalStackSize = croppedStack.getSize();
        for (int i = cropperZ.getBoundaryRight(extFrame.getCentroidZAsInt()); i != originalStackSize; i++) {
            croppedStack.deleteLastSlice();
        }

        for (int i = 0; i != cropperZ.getBoundaryLeft(extFrame.getCentroidZAsInt()); i++) {
            croppedStack.deleteSlice(1);
        }
        System.out.println("stack size : " + croppedStack.getSize());
        // then the cropped stack is added to the future average stack
        if (averageStack == null) {
            averageStack = new ImageStack(croppedStack.getWidth(), croppedStack.getHeight());
            for (int i = 0; i != croppedStack.getSize(); i++) {
                averageStack.addSlice(croppedStack.getProcessor(i + 1).convertToFloat());
            }

        } else {
            addStack(croppedStack, averageStack);
        }
        updateProgress(p++, max + 10);
        if (p % 8 == 0)
            System.gc();

        // centeredStacks.add(croppedStack);

    }
    updateProgress(max + 2, max + 10);
    System.out.println("averaging endend. dviding by " + extendedFrameList.size());
    // the average stack is divided by the number of used stack
    for (int i = 0; i != averageStack.getSize(); i++) {
        averageStack.getProcessor(i + 1).multiply(1.0 / extendedFrameList.size());
    }

    System.out.println("stacling stack x y and z");
    // ImageStack averageStack = averageStacks(centeredStacks);
    ImagePlus averageStackImagePlus = new ImagePlus("Averaged Bead", averageStack);
    Scale scaler = new Scale();
    Image wrapper = Image.wrap(averageStackImagePlus);

    updateProgress(max + 5, max + 10);
    wrapper = scaler.run(wrapper, 1.0 / extensionFactor, 1.0 / extensionFactor, 1.0 / extensionFactor, 1.0, 1.0,
            Scale.LINEAR);
    updateProgress(max + 9, max + 10);
    System.gc();
    System.out.println(" the end");
    System.out.println(wrapper.imageplus());

    updateProgress(0, 7);
    return wrapper.imageplus();
}

From source file:com.borqs.sync.server.contact.admin.ContactSyncSourceAdminPanel.java

/**
 * Create the panel/*  www . ja  va  2s. c om*/
 * @throws Exception if error occures during creation of the panel
 */
private void init() {
    // set layout
    this.setLayout(null);
    // set properties of label, position and border
    //  referred to the title of the panel
    titledBorder = new TitledBorder("");
    panelName.setFont(titlePanelFont);
    panelName.setText(getPanelName());
    panelName.setBounds(new Rectangle(14, 5, 316, 28));
    panelName.setAlignmentX(SwingConstants.CENTER);
    panelName.setBorder(titledBorder);

    final int LABEL_X = 14;
    final int VALUE_X = 170;
    int y = 60;
    final int GAP_X = 150;
    final int GAP_Y = 30;

    sourceUriLabel.setText("Source URI: ");
    sourceUriLabel.setFont(defaultFont);
    sourceUriLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    sourceUriValue.setFont(defaultFont);
    sourceUriValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));

    y += GAP_Y; // New line

    nameLabel.setText("Name: ");
    nameLabel.setFont(defaultFont);
    nameLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    nameValue.setFont(defaultFont);
    nameValue.setBounds(new Rectangle(VALUE_X, y, 350, 18));
    y += GAP_Y; // New line

    typeLabel.setText("Client Type: ");
    typeLabel.setFont(defaultFont);
    typeLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    typeCombo.setFont(defaultFont);
    typeCombo.setBounds(new Rectangle(VALUE_X, y, 350, 18));
    y += GAP_Y; // New line

    datastoretypeLabel.setText("Datastore Type: ");
    datastoretypeLabel.setFont(defaultFont);
    datastoretypeLabel.setBounds(new Rectangle(LABEL_X, y, 150, 18));
    datastoretypeCombo.setFont(defaultFont);
    datastoretypeCombo.setBounds(new Rectangle(VALUE_X, y, 350, 18));

    y += GAP_Y; // New line
    int x = LABEL_X;

    confirmButton.setFont(defaultFont);
    confirmButton.setText("Add");
    confirmButton.setBounds(VALUE_X, y, 70, 25);

    // What happens when the confirmButton is pressed?
    confirmButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            try {
                validateValues();
                getValues();
                if (getState() == STATE_INSERT) {
                    ContactSyncSourceAdminPanel.this.actionPerformed(new ActionEvent(
                            ContactSyncSourceAdminPanel.this, ACTION_EVENT_INSERT, event.getActionCommand()));
                } else {
                    ContactSyncSourceAdminPanel.this.actionPerformed(new ActionEvent(
                            ContactSyncSourceAdminPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand()));
                }
            } catch (Exception e) {
                notifyError(new AdminException(e.getMessage(), e));
            }
        }
    });

    // Adds all components to the panel
    this.add(panelName, null);
    this.add(nameLabel, null);
    this.add(sourceUriLabel, null);
    this.add(sourceUriValue, null);
    this.add(nameValue, null);
    this.add(typeLabel, null);
    this.add(typeCombo, null);
    this.add(confirmButton, null);
    this.add(datastoretypeLabel, null);
    this.add(datastoretypeCombo, null);

}