Java Code Examples for java.awt.Window#getLocation()

The following examples show how to use java.awt.Window#getLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Session.java    From FancyBing with GNU General Public License v3.0 6 votes vote down vote up
public void restoreLocation(Window window, Window owner, String name)
{
    int x = Integer.MIN_VALUE;
    int y = Integer.MIN_VALUE;
    Preferences prefs = getNode(name);
    if (prefs != null)
    {
        x = prefs.getInt("x", Integer.MIN_VALUE);
        y = prefs.getInt("y", Integer.MIN_VALUE);
    }
    if (x == Integer.MIN_VALUE || y == Integer.MIN_VALUE)
    {
        if (! window.isVisible())
            // use a platform-dependent default (setLocationByPlatform can
            // only be used, if window not already visible)
            window.setLocationByPlatform(true);
        return;
    }
    Point ownerLocation = owner.getLocation();
    setLocationChecked(window, x + ownerLocation.x,  y + ownerLocation.y);
}
 
Example 2
Source File: Session.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
public void saveLocation(Window window, String name)
{
    if (isFrameSpecialMode(window))
        return;
    Preferences prefs = createNode(name);
    if (prefs == null)
        return;
    Point location = window.getLocation();
    prefs.putInt("x", location.x);
    prefs.putInt("y", location.y);
}
 
Example 3
Source File: Session.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
public void saveLocation(Window window, Window owner, String name)
{
    if (isFrameSpecialMode(window))
        return;
    Preferences prefs = createNode(name);
    if (prefs == null)
        return;
    Point location = window.getLocation();
    Point ownerLocation = owner.getLocation();
    prefs.putInt("x", location.x - ownerLocation.x);
    prefs.putInt("y", location.y - ownerLocation.y);
}
 
Example 4
Source File: WindowDragger.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Translates a window, after possibly adjusting dx and dy for OS-based
 * restraints.
 */
protected static void translateWindow(int dx, int dy, Window window) {
	Point p = window.getLocation();
	p.x += dx;
	p.y += dy;
	if (JVM.isMac)
		p.y = Math.max(0, p.y);
	window.setLocation(p);
}
 
Example 5
Source File: FakeSheetWindowListener.java    From pumpernickel with MIT License 5 votes vote down vote up
public FakeSheetWindowListener(Window window1, Window window2,
		JComponent dialogAnchor, JComponent modalCover) {
	lastLocation = window1.getLocation();
	this.window1 = window1;
	this.window2 = window2;
	this.modalCover = modalCover;
	this.dialogAnchor = dialogAnchor;
}
 
Example 6
Source File: FakeSheetWindowListener.java    From pumpernickel with MIT License 5 votes vote down vote up
/** Translate a window (+dx, +dy) */
public static void translate(Window w, int dx, int dy) {
	Point p = w.getLocation();
	p.x += dx;
	p.y += dy;
	w.setLocation(p);
}
 
Example 7
Source File: PDialog.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * Sets window visibly to the right of the window handed in
 *
 * @param w window to set location relative to
 */
public void setBeside(final Window w) {
    final Window self = this;
    skipCenter = true;
    
    int x = w.getLocation().x + w.getWidth();
    int y = w.getLocation().y;

    self.setLocation(x, y);
}
 
Example 8
Source File: PFrame.java    From PolyGlot with MIT License 5 votes vote down vote up
/**
 * Sets window visibly to the right of the window handed in
 *
 * @param w window to set location relative to
 */
public void setBeside(final Window w) {
    int x = w.getLocation().x + w.getWidth();
    int y = w.getLocation().y;

    setLocation(x, y);
    ignoreCenter = true;
}
 
Example 9
Source File: ShowUsagesAction.java    From dagger-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void setSizeAndDimensions(@NotNull JTable table, @NotNull JBPopup popup,
    @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) {
  JComponent content = popup.getContent();
  Window window = SwingUtilities.windowForComponent(content);
  Dimension d = window.getSize();

  int width = calcMaxWidth(table);
  width = (int) Math.max(d.getWidth(), width);
  Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize();
  width = Math.max((int) headerSize.getWidth(), width);
  width = Math.max(myWidth, width);

  if (myWidth == -1) myWidth = width;
  int newWidth = Math.max(width, d.width + width - myWidth);

  myWidth = newWidth;

  int rowsToShow = Math.min(30, data.size());
  Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
  Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
  dimension = rectangle.getSize();
  Point location = window.getLocation();
  if (!location.equals(rectangle.getLocation())) {
    window.setLocation(rectangle.getLocation());
  }

  if (!data.isEmpty()) {
    TableScrollingUtil.ensureSelectionExists(table);
  }
  table.setSize(dimension);
  //table.setPreferredSize(dimension);
  //table.setMaximumSize(dimension);
  //table.setPreferredScrollableViewportSize(dimension);

  Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize();

  int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/;
  Dimension newDim = new Dimension(dimension.width, newHeight);
  window.setSize(newDim);
  window.setMinimumSize(newDim);
  window.setMaximumSize(newDim);

  window.validate();
  window.repaint();
  table.revalidate();
  table.repaint();
}
 
Example 10
Source File: ShowUsagesAction.java    From otto-intellij-plugin with Apache License 2.0 4 votes vote down vote up
private void setSizeAndDimensions(@NotNull JTable table,
    @NotNull JBPopup popup,
    @NotNull RelativePoint popupPosition,
    @NotNull List<UsageNode> data) {
  JComponent content = popup.getContent();
  Window window = SwingUtilities.windowForComponent(content);
  Dimension d = window.getSize();

  int width = calcMaxWidth(table);
  width = (int)Math.max(d.getWidth(), width);
  Dimension headerSize = ((AbstractPopup)popup).getHeaderPreferredSize();
  width = Math.max((int)headerSize.getWidth(), width);
  width = Math.max(myWidth, width);

  if (myWidth == -1) myWidth = width;
  int newWidth = Math.max(width, d.width + width - myWidth);

  myWidth = newWidth;

  int rowsToShow = Math.min(30, data.size());
  Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow);
  Rectangle rectangle = fitToScreen(dimension, popupPosition, table);
  dimension = rectangle.getSize();
  Point location = window.getLocation();
  if (!location.equals(rectangle.getLocation())) {
    window.setLocation(rectangle.getLocation());
  }

  if (!data.isEmpty()) {
    TableScrollingUtil.ensureSelectionExists(table);
  }
  table.setSize(dimension);
  //table.setPreferredSize(dimension);
  //table.setMaximumSize(dimension);
  //table.setPreferredScrollableViewportSize(dimension);


  Dimension footerSize = ((AbstractPopup)popup).getFooterPreferredSize();

  int newHeight = (int)(dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4/* invisible borders, margins etc*/;
  Dimension newDim = new Dimension(dimension.width, newHeight);
  window.setSize(newDim);
  window.setMinimumSize(newDim);
  window.setMaximumSize(newDim);

  window.validate();
  window.repaint();
  table.revalidate();
  table.repaint();
}