java.awt.Window#validate ( )源码实例Demo

下面列出了java.awt.Window#validate ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: littleluck   文件: WindowMouseHandler.java
public void mouseReleased(MouseEvent e)
{
    Window window = (Window) e.getSource();
    
    if (dragCursor != 0 && window != null && !window.isValid())
    {
        // Some Window systems validate as you resize, others won't,
        // thus the check for validity before repainting.
        window.validate();
        
        if(window instanceof JFrame)
        {
            ((JFrame)window).getRootPane().repaint();
        }
    }
    
    // 松开鼠标时重置状态
    isMovingWindow = false;

    dragCursor = 0;
}
 
源代码2 项目: FancyBing   文件: Session.java
private void setSizeChecked(Window window, int width, int height)
{
    Dimension screenSize = getScreenSize();
    width = Math.min(width, screenSize.width);
    height = Math.min(height, screenSize.height);
    window.setSize(width, height);
    window.validate();
}
 
源代码3 项目: lizzie   文件: LizziePane.java
public void mouseDragged(MouseEvent e) {
  Window w = (Window) e.getSource();
  Point pt = e.getPoint();

  if (isMovingWindow) {
    Point eventLocationOnScreen = e.getLocationOnScreen();
    w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY);
  } else if (dragCursor != 0) {
    Rectangle r = w.getBounds();
    Rectangle startBounds = new Rectangle(r);
    Dimension min = w.getMinimumSize();

    switch (dragCursor) {
      case Cursor.E_RESIZE_CURSOR:
        adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
        break;
      case Cursor.S_RESIZE_CURSOR:
        adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      case Cursor.N_RESIZE_CURSOR:
        adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
        break;
      case Cursor.W_RESIZE_CURSOR:
        adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
        break;
      case Cursor.NE_RESIZE_CURSOR:
        adjust(
            r,
            min,
            0,
            pt.y - dragOffsetY,
            pt.x + (dragWidth - dragOffsetX) - r.width,
            -(pt.y - dragOffsetY));
        break;
      case Cursor.SE_RESIZE_CURSOR:
        adjust(
            r,
            min,
            0,
            0,
            pt.x + (dragWidth - dragOffsetX) - r.width,
            pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      case Cursor.NW_RESIZE_CURSOR:
        adjust(
            r,
            min,
            pt.x - dragOffsetX,
            pt.y - dragOffsetY,
            -(pt.x - dragOffsetX),
            -(pt.y - dragOffsetY));
        break;
      case Cursor.SW_RESIZE_CURSOR:
        adjust(
            r,
            min,
            pt.x - dragOffsetX,
            0,
            -(pt.x - dragOffsetX),
            pt.y + (dragHeight - dragOffsetY) - r.height);
        break;
      default:
        break;
    }
    if (!r.equals(startBounds)) {
      w.setBounds(r);
      // Defer repaint/validate on mouseReleased unless dynamic
      // layout is active.
      if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
        w.validate();
        getRootPane().repaint();
      }
    }
  }
}
 
源代码4 项目: gcs   文件: WindowUtils.java
/**
 * Forces the specified window onscreen.
 *
 * @param window The window to force onscreen.
 */
public static void forceOnScreen(Window window) {
    Rectangle maxBounds = getMaximumWindowBounds(window);
    Rectangle bounds    = window.getBounds();
    Point     location  = new Point(bounds.x, bounds.y);
    Dimension size      = window.getMinimumSize();

    if (bounds.width < size.width) {
        bounds.width = size.width;
    }
    if (bounds.height < size.height) {
        bounds.height = size.height;
    }

    if (bounds.x < maxBounds.x) {
        bounds.x = maxBounds.x;
    } else if (bounds.x >= maxBounds.x + maxBounds.width) {
        bounds.x = maxBounds.x + maxBounds.width - 1;
    }

    if (bounds.x + bounds.width >= maxBounds.x + maxBounds.width) {
        bounds.x = maxBounds.x + maxBounds.width - bounds.width;
        if (bounds.x < maxBounds.x) {
            bounds.x = maxBounds.x;
            bounds.width = maxBounds.width;
        }
    }

    if (bounds.y < maxBounds.y) {
        bounds.y = maxBounds.y;
    } else if (bounds.y >= maxBounds.y + maxBounds.height) {
        bounds.y = maxBounds.y + maxBounds.height - 1;
    }

    if (bounds.y + bounds.height >= maxBounds.y + maxBounds.height) {
        bounds.y = maxBounds.y + maxBounds.height - bounds.height;
        if (bounds.y < maxBounds.y) {
            bounds.y = maxBounds.y;
            bounds.height = maxBounds.height;
        }
    }

    if (location.x != bounds.x || location.y != bounds.y) {
        window.setBounds(bounds);
    } else {
        window.setSize(bounds.width, bounds.height);
    }
    window.validate();
}
 
源代码5 项目: seaglass   文件: SeaGlassRootPaneUI.java
/**
 * @see java.awt.event.MouseMotionListener#mouseDragged(java.awt.event.MouseEvent)
 */
public void mouseDragged(MouseEvent ev) {
    Window w  = (Window) ev.getSource();
    Point  pt = ev.getPoint();

    if (isMovingWindow) {
        Point eventLocationOnScreen = ev.getLocationOnScreen();

        w.setLocation(eventLocationOnScreen.x - dragOffsetX, eventLocationOnScreen.y - dragOffsetY);
    } else if (dragCursor != 0) {
        Rectangle r           = w.getBounds();
        Rectangle startBounds = new Rectangle(r);
        Dimension min         = w.getMinimumSize();

        switch (dragCursor) {

        case Cursor.E_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);
            break;

        case Cursor.S_RESIZE_CURSOR:
            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        case Cursor.N_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));
            break;

        case Cursor.W_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);
            break;

        case Cursor.NE_RESIZE_CURSOR:
            adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX) - r.width, -(pt.y - dragOffsetY));
            break;

        case Cursor.SE_RESIZE_CURSOR:
            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        case Cursor.NW_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY, -(pt.x - dragOffsetX), -(pt.y - dragOffsetY));
            break;

        case Cursor.SW_RESIZE_CURSOR:
            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), pt.y + (dragHeight - dragOffsetY) - r.height);
            break;

        default:
            break;
        }

        if (!r.equals(startBounds)) {
            w.setBounds(r);
            // Defer repaint/validate on mouseReleased unless dynamic
            // layout is active.
            if (Toolkit.getDefaultToolkit().isDynamicLayoutActive()) {
                w.validate();
                getRootPane().repaint();
            }
        }
    }
}
 
源代码6 项目: tn5250j   文件: TN5250jSplashScreen.java
/**
    * Creates the Splash screen window and configures it.
    */
   protected void initialize(ImageIcon iimage) {

      image = iimage.getImage();
      // if no image, return
      if (image == null) {
         throw new IllegalArgumentException("Image specified is invalid.");
      }
//      System.out.println(" here in splash ");

      MediaTracker tracker = new MediaTracker(this);
      tracker.addImage(image,0);

      try {
         tracker.waitForAll();
      }
      catch(Exception e) {
         System.out.println(e.getMessage());
      }

      // create dialog window
      f = new Frame();
      dialog = new Window(f);
      dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      Dimension s = new Dimension(image.getWidth(this) + 2,
         image.getHeight(this) + 2);
      setSize(s);
      dialog.setLayout(new BorderLayout());
      dialog.setSize(s);

      dialog.add(this,BorderLayout.CENTER);
      dialog.pack();

      // position splash screen
      Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
      int x = (screen.width - s.width)/2;
      if (x < 0) {
         x = 0;
      }

      int y = (screen.height - s.height)/2;
      if (y < 0) {
         y = 0;
      }

      dialog.setLocation(x, y);
      dialog.validate();

   }
 
源代码7 项目: RipplePower   文件: RPSplash.java
public RPSplash(Color progressBarColour, String imageResourcePath, String buildString, Color buildTextColour,
		int buildLabelX, int buildLabelY, String versionNumber, Color versionTextColour, int versionLabelX,
		int versionLabelY, boolean autonClose, final Updateable update) {

	this.buildTextColour = buildTextColour;
	this.buildLabelX = buildLabelX;
	this.buildLabelY = buildLabelY;
	this.versionTextColour = versionTextColour;
	this.versionLabelX = versionLabelX;
	this.versionLabelY = versionLabelY;

	progressColour = progressBarColour;
	setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	setBackground(Color.white);

	gradientColour = UIRes.getBrighter(progressBarColour, 0.75);

	Font font = new Font(Font.SANS_SERIF, Font.PLAIN, 11);
	setFont(font);
	fontMetrics = getFontMetrics(font);

	image = LImage.createImage(imageResourcePath).getBufferedImage();

	if (buildString != null) {
		build = buildString;
	}
	if (versionNumber != null) {
		version = versionNumber;
	}

	Dimension size = new Dimension(image.getWidth(this), image.getHeight(this));
	window = new Window(new Frame());
	window.setSize(size);
	window.setLayout(new BorderLayout());
	window.add(BorderLayout.CENTER, this);
	window.setLocation(UIRes.getPointToCenter(window, size));
	window.validate();
	window.setVisible(true);

	if (autonClose) {
		Updateable call = new Updateable() {
			@Override
			public void action(Object o) {
				for (; progress < 10;) {
					process();
					try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
					}
				}
				RPSplash.this.dispose();
				if (update != null) {
					update.action(progress);
				}
			}
		};
		LSystem.postThread(call);
	}
}
 
源代码8 项目: dagger-intellij-plugin   文件: ShowUsagesAction.java
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();
}
 
源代码9 项目: otto-intellij-plugin   文件: ShowUsagesAction.java
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();
}
 
源代码10 项目: littleluck   文件: WindowMouseHandler.java
public void updateBound(Point pt, Window w)
{
    Rectangle r = w.getBounds();
    Rectangle startBounds = new Rectangle(r);
    Dimension min = w.getMinimumSize();

    switch (dragCursor)
    {
        case Cursor.E_RESIZE_CURSOR:

            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width, 0);

            break;

        case Cursor.S_RESIZE_CURSOR:

            adjust(r, min, 0, 0, 0, pt.y + (dragHeight - dragOffsetY) - r.height);

            break;

        case Cursor.N_RESIZE_CURSOR:

            adjust(r, min, 0, pt.y - dragOffsetY, 0, -(pt.y - dragOffsetY));

            break;

        case Cursor.W_RESIZE_CURSOR:

            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX), 0);

            break;

        case Cursor.NE_RESIZE_CURSOR:

            adjust(r, min, 0, pt.y - dragOffsetY, pt.x + (dragWidth - dragOffsetX)
                    - r.width, -(pt.y - dragOffsetY));
            break;
        case Cursor.SE_RESIZE_CURSOR:

            adjust(r, min, 0, 0, pt.x + (dragWidth - dragOffsetX) - r.width,
                    pt.y + (dragHeight - dragOffsetY) - r.height);

            break;

        case Cursor.NW_RESIZE_CURSOR:

            adjust(r, min, pt.x - dragOffsetX, pt.y - dragOffsetY,
                    -(pt.x - dragOffsetX), -(pt.y - dragOffsetY));

            break;

        case Cursor.SW_RESIZE_CURSOR:

            adjust(r, min, pt.x - dragOffsetX, 0, -(pt.x - dragOffsetX),
                    pt.y + (dragHeight - dragOffsetY) - r.height);

            break;

        default:

            break;
    }

    if(!r.equals(startBounds))
    {
        w.setBounds(r);

        if (Toolkit.getDefaultToolkit().isDynamicLayoutActive())
        {
            w.validate();
            w.repaint();
        }
    }
}