Example usage for java.awt Frame getLocation

List of usage examples for java.awt Frame getLocation

Introduction

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

Prototype

public Point getLocation() 

Source Link

Document

Gets the location of this component in the form of a point specifying the component's top-left corner.

Usage

From source file:FontChooser.java

public static Font showDialog(Frame parent, String title, Font font) {
    FontChooser dialog = new FontChooser(parent, true, font);

    Point p1 = parent.getLocation();
    Dimension d1 = parent.getSize();
    Dimension d2 = dialog.getSize();

    int x = p1.x + (d1.width - d2.width) / 2;
    int y = p1.y + (d1.height - d2.height) / 2;

    if (x < 0) {
        x = 0;/*from   w w w .ja  va2 s . com*/
    }
    if (y < 0) {
        y = 0;
    }

    if (title != null) {
        dialog.setTitle(title);
    }
    dialog.setLocation(x, y);
    dialog.setVisible(true);

    Font newfont = null;
    if (dialog.ok) {
        newfont = dialog.getCurrentFont();
    }

    dialog.dispose();
    return newfont;
}

From source file:net.chaosserver.timelord.swingui.PreviousDayPanel.java

/**
 * Listens for action from this panel. If the pick date button is choosen
 * displays a Calendar allowing a user to select a date for display.
 *
 * @param evt the event triggering things
 *///from  www  .  j  a  v  a  2  s . co  m
public void actionPerformed(ActionEvent evt) {
    if (ACTION_PICK_DAY.equals(evt.getActionCommand())) {
        Frame ownerFrame = (Frame) SwingUtilities.getAncestorOfClass(Frame.class, this);
        JCalendarDialog calendarDialog = new JCalendarDialog(ownerFrame, getDisplayDate());

        calendarDialog.pack();

        Point ownerFrameLocation = ownerFrame.getLocation();
        ownerFrameLocation.setLocation(ownerFrameLocation.getX() + LayoutConstants.CHILD_FRAME_X_OFFSET,
                ownerFrameLocation.getY() + LayoutConstants.CHILD_FRAME_Y_OFFSET);

        calendarDialog.setLocation(ownerFrameLocation);
        calendarDialog.setVisible(true);

        Date choosenDate = calendarDialog.getChoosenDate();

        if (choosenDate != null) {
            setDisplayDate(choosenDate);
        }
    }
}

From source file:gdsc.smlm.ij.plugins.pcpalm.PCPALMAnalysis.java

/**
 * Perform the PC Analysis//w w w . ja  v a 2  s.  com
 * 
 * @param molecules
 */
private void analyse(ArrayList<Molecule> molecules) {
    // Check if the plots are currently shown
    String spatialPlotTitle = TITLE + " molecules/um^2";
    String frequencyDomainTitle = TITLE + " g(r)";

    boolean noPlots;
    String topPlotTitle;

    long start = System.nanoTime();
    if (spatialDomain) {
        // -----------------
        // Analysis in the spatial domain
        // -----------------

        log("---");
        log("Spatial domain analysis");
        log("Computing density histogram");

        // Compute all-vs-all distance matrix.
        // Create histogram of distances at different radii.
        final int nBins = (int) (correlationDistance / correlationInterval) + 1;
        final double maxDistance2 = correlationDistance * correlationDistance;
        int[] H = new int[nBins];

        // TODO - Update this using a grid with a resolution of maxDistance to increase speed
        // by only comparing to neighbours within range.

        // An all-vs-all analysis does not account for a border. 
        // A simple solution is to only process molecules within the border but compare them 
        // to all molecules within the region. Thus every molecule has a complete circle of the max 
        // radius around them to use:
        // ----------------------
        // |                    |
        // |   --------------   |
        // |   |  Within    |   |
        // |   |  Border    |   |
        // |   |            |   |
        // |   --------------   |
        // |      Region        |
        // ----------------------
        // If the fraction of points within the correlation distance of the edge is low then this 
        // will not make much difference. 

        final double boundaryMinx = (useBorder) ? minx + correlationDistance : minx;
        final double boundaryMaxx = (useBorder) ? maxx - correlationDistance : maxx;
        final double boundaryMiny = (useBorder) ? miny + correlationDistance : miny;
        final double boundaryMaxy = (useBorder) ? maxy - correlationDistance : maxy;

        int N = 0;
        if (boundaryMaxx <= boundaryMinx || boundaryMaxy <= boundaryMiny) {
            log("ERROR: 'Use border' option of %s nm is not possible: Width = %s nm, Height = %s nm",
                    Utils.rounded(correlationDistance, 4), Utils.rounded(maxx - minx, 3),
                    Utils.rounded(maxy - miny, 3));
            return;
        } else {
            for (int i = molecules.size(); i-- > 0;) {
                final Molecule m = molecules.get(i);
                // Optionally ignore molecules that are near the edge of the boundary
                if (useBorder && (m.x < boundaryMinx || m.x > boundaryMaxx || m.y < boundaryMiny
                        || m.y > boundaryMaxy))
                    continue;
                N++;

                for (int j = molecules.size(); j-- > 0;) {
                    if (i == j)
                        continue;

                    double d = m.distance2(molecules.get(j));
                    if (d < maxDistance2) {
                        H[(int) (Math.sqrt(d) / correlationInterval)]++;
                    }
                }
            }
        }

        double[] r = new double[nBins + 1];
        for (int i = 0; i <= nBins; i++)
            r[i] = i * correlationInterval;
        double[] pcf = new double[nBins];
        if (N > 0) {
            // Note: Convert nm^2 to um^2
            final double N_pi = N * Math.PI / 1000000.0;
            for (int i = 0; i < nBins; i++) {
                // Pair-correlation is the count at the given distance divided by N and the area at distance ri:
                // H(r_i) / (N x (pi x (r_i+1)^2 - pi x r_i^2))
                pcf[i] = H[i] / (N_pi * (r[i + 1] * r[i + 1] - r[i] * r[i]));
            }
        }

        // The final bin may be empty if the correlation interval was a factor of the correlation distance
        if (pcf[pcf.length - 1] == 0) {
            r = Arrays.copyOf(r, nBins - 1);
            pcf = Arrays.copyOf(pcf, nBins - 1);
        } else {
            r = Arrays.copyOf(r, nBins);
        }

        double[][] gr = new double[][] { r, pcf, null };

        CorrelationResult result = new CorrelationResult(results.size() + 1,
                PCPALMMolecules.results.getSource(), boundaryMinx, boundaryMiny, boundaryMaxx, boundaryMaxy, N,
                correlationInterval, 0, false, gr, true);
        results.add(result);

        noPlots = WindowManager.getFrame(spatialPlotTitle) == null;
        topPlotTitle = frequencyDomainTitle;

        plotCorrelation(gr, 0, spatialPlotTitle, "molecules/um^2", true, false);
    } else {
        // -----------------
        // Image correlation in the Frequency Domain
        // -----------------
        log("Frequency domain analysis");

        // Create a binary image for the molecules

        ImageProcessor im = PCPALMMolecules.drawImage(molecules, minx, miny, maxx, maxy, nmPerPixel, true,
                binaryImage);
        log("Image scale = %.2f nm/pixel : %d x %d pixels", nmPerPixel, im.getWidth(), im.getHeight());

        // Apply a window function to the image to reduce FFT edge artifacts.
        if (applyWindow) {
            im = applyWindow(im, imageWindow);
        }

        if (showHighResolutionImage) {
            PCPALMMolecules.displayImage(PCPALMMolecules.results.getName() + " "
                    + ((binaryImage) ? "Binary" : "Count") + " Image (high res)", im, nmPerPixel);
        }

        // Create weight image (including windowing)
        ImageProcessor w = createWeightImage(im, applyWindow);

        // Store the area of the image in um^2
        weightedAreaInPx = areaInPx = im.getWidth() * im.getHeight();
        if (applyWindow) {
            weightedAreaInPx *= w.getStatistics().mean;
        }
        area = areaInPx * nmPerPixel * nmPerPixel / 1e6;
        weightedArea = weightedAreaInPx * nmPerPixel * nmPerPixel / 1e6;
        noOfMolecules = molecules.size();

        // Pad the images to the largest scale being investigated by the correlation function.
        // Original Sengupta paper uses 800nm for the padding size.
        // Limit to within 80% of the minimum dimension of the image.
        double maxRadius = correlationDistance / nmPerPixel;
        int imageSize = FastMath.min(im.getWidth(), im.getHeight());
        if (imageSize < 1.25 * maxRadius)
            maxRadius = imageSize / 1.25;
        int pad = (int) Math.round(maxRadius);
        log("Analysing up to %.0f nm = %d pixels", maxRadius * nmPerPixel, pad);
        im = padImage(im, pad);
        w = padImage(w, pad);

        //      // Used for debugging
        //      {
        //         ImageProcessor w2 = w.duplicate();
        //         w2.setMinAndMax(0, 1);
        //         PCPALMMolecules.displayImage(PCPALMMolecules.results.getName() + " Binary Image Mask", w2, nmPerPixel);
        //      }

        final double peakDensity = getDensity(im);

        // Create 2D auto-correlation
        double[][] gr;
        try {
            // Use the FFT library as it is multi-threaded. This may not be in the user's path.
            gr = computeAutoCorrelationCurveFFT(im, w, pad, nmPerPixel, peakDensity);
        } catch (Exception e) {
            // Default to the ImageJ built-in FHT
            gr = computeAutoCorrelationCurveFHT(im, w, pad, nmPerPixel, peakDensity);
        }
        if (gr == null)
            return;

        // Add the g(r) curve to the results
        addResult(peakDensity, gr);

        noPlots = WindowManager.getFrame(frequencyDomainTitle) == null;
        topPlotTitle = spatialPlotTitle;

        // Do not plot r=0 value on the curve
        plotCorrelation(gr, 1, frequencyDomainTitle, "g(r)", false, showErrorBars);
    }

    if (noPlots) {
        // Position the plot underneath the other one
        Frame f1 = WindowManager.getFrame(topPlotTitle);
        if (f1 != null) {
            String bottomPlotTitle = (topPlotTitle.equals(spatialPlotTitle) ? frequencyDomainTitle
                    : spatialPlotTitle);
            Frame f2 = WindowManager.getFrame(bottomPlotTitle);
            if (f2 != null)
                f2.setLocation(f2.getLocation().x, f2.getLocation().y + f1.getHeight());
        }
    }

    log("%s domain analysis computed in %s ms", (spatialDomain) ? "Spatial" : "Frequency",
            Utils.rounded((System.nanoTime() - start) * 1e-6, 4));
    log("---");
}

From source file:com.jcraft.weirdx.XWindow.java

private void addComponentListener(java.awt.Frame foo) {
    final java.awt.Frame frame = foo;
    frame.addComponentListener(new java.awt.event.ComponentAdapter() {
        public void componentResized(java.awt.event.ComponentEvent e) {
            if (parent == null)
                return;
            Rectangle rectangle = frame.getBounds();
            if (rectangle.width == 0 || rectangle.height == 0)
                return;
            if (frame_width != rectangle.width || frame_height != rectangle.height) {
                Insets insets = frame.getInsets();
                synchronized (XWindow.LOCK) {
                    try {
                        Point point = frame.getLocation();
                        int ww = rectangle.width - insets.left - insets.right - borderWidth * 2;
                        int hh = rectangle.height - insets.top - insets.bottom - borderWidth * 2;
                        if (ww > 0 && hh > 0) {
                            ddxwindow.setSize(ww, hh);
                            frame.pack();
                            Event event = new Event();
                            event.mkConfigureNotify(id, id, (rectangle.x + insets.left),
                                    (rectangle.y + insets.top), ww, hh, borderWidth,
                                    (attr & (1 << 16)) != 0 ? 1 : 0);
                            sendEvent(event, 1, null);
                            frame_x = rectangle.x;
                            frame_y = rectangle.y;
                            frame_width = rectangle.width;
                            frame_height = rectangle.height;
                        }/*from   ww w. j a va 2  s  .  co  m*/
                    } catch (Exception ee) {
                        LOG.error(ee);
                    }
                }
            }
        }
    });
}

From source file:proci.gui.Importa.java

/** Creates new form Importa */
public Importa(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();/*from w w w  .j  a va  2  s  . c o m*/
    Dimension frmSize = parent.getSize();
    Point loc = parent.getLocation();
    this.setSize(IMPO_WIDTH, IMPO_HEIGHT);
    this.setLocation((frmSize.width - IMPO_WIDTH) / 2 + loc.x, (frmSize.height - IMPO_HEIGHT) / 2 + loc.y);
    jepData.setEditable(false);
    jepData.setContentType("text/html");
    String text = "<html><body><font face='verdana,arial' size=+1><p align='center'>Importazione</p></font>"
            + "<p><font color='red'>ATTENZIONE:</font> I dati presenti in archivio verranno eliminati!!</p>"
            + "<p><font color='red'>ATTENZIONE:</font> L'operazione di import/export non  reversibile. Usare "
            + "la funzione di backup per copiare dati tra diverse istanze della procedura!</p>";
    jepData.setText(text);
}

From source file:util.ui.UiUtilities.java

/**
 * Centers a window to its parent frame and shows it.
 * <p>/*  w w  w  . j  a va2s .  c om*/
 * If the window has no parent frame it will be centered to the screen.
 *
 * @param win
 *          The window to center and show.
 */
public static void centerAndShow(Window win) {
    Dimension wD = win.getSize();
    Dimension frameD;
    Point framePos;
    Frame frame = JOptionPane.getFrameForComponent(win);

    // Should this window be centered to its parent frame?
    boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing();

    // Center to parent frame or to screen
    if (centerToParentFrame) {
        frameD = frame.getSize();
        framePos = frame.getLocation();
    } else {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        // dual head, use first screen
        if (ge.getScreenDevices().length > 1) {
            try {
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                GraphicsConfiguration config = gd.getConfigurations()[0];
                frameD = config.getBounds().getSize();
                framePos = config.getBounds().getLocation();
            } catch (RuntimeException e) {
                frameD = Toolkit.getDefaultToolkit().getScreenSize();
                framePos = new Point(0, 0);
            }
        }
        // single screen only
        else {
            frameD = Toolkit.getDefaultToolkit().getScreenSize();
            framePos = new Point(0, 0);
        }
    }

    Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2,
            framePos.y + (frameD.height - wD.height) / 2);
    wPos.x = Math.max(0, wPos.x); // Make x > 0
    wPos.y = Math.max(0, wPos.y); // Make y > 0
    win.setLocation(wPos);
    win.setVisible(true);
}