⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oyoahajava1paintutilities.java

📁 java 开源,Swing外观:JGoodies look & feel. ... JGoodies look&feels让你的Swing 应用程序与applets看起来更漂亮.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
  public void paintAScrollMosaic(Graphics g, Component c, int x, int y, int width, int height, Image i, int decalX, int decalY)
  {
    try
    {
      Shape s = normalizeClip(g, x, y, width, height);

      int w=i.getWidth(c);
      int h=i.getHeight(c);

      Point p = getAPosition(c);
      p.x+=decalX;
      p.y+=decalY;

      if(p.x<0)
      p.x =-p.x;
      
      if(p.y<0)
      p.y =-p.y;
           
      int x0 =(x/w*w-(p.x%w));
      int y0 =(y/h*h-(p.y%h));
           
      for(int y1=y0; y1<y+height; y1+=h)
      {
        for(int x1=x0; x1<x+width; x1+=w)
        {
            g.drawImage(i,x1,y1,c);
        }
      }    

      g.setClip(s);
    }
    catch(Exception ex)
    {

    }
  }

  /**
  *
  */
  public void paintAImageAt(Graphics g, Component c, int x, int y, int width, int height, Image i, int pos)
  {
    try
    {
      paintAImageAt(g, c, x, y, width, height, i, pos, i.getWidth(c), i.getHeight(c));
    }
    catch(Exception e)
    {

    }
  }

  /**
  *
  */
  public void paintAImageAt(Graphics g, Component c, int x, int y, int width, int height, Image i, int pos, int w, int h)
  {
    try
    {
      if(!c.isShowing())
      return;

      Component root = SwingUtilities.getRoot(c);

      if(root instanceof JFrame)
      {
        root = ((JFrame)root).getContentPane();
      }
      else
      if(root instanceof JWindow)
      {
        root = ((JWindow)root).getContentPane();
      }
      else
      if(root instanceof JApplet)
      {
        root = ((JApplet)root).getContentPane();
      }

      Rectangle rectangle = OyoahaUtilities.getFullRect(root);

      Point origin = root.getLocationOnScreen();
      Point current = c.getLocationOnScreen();

      rectangle.x = origin.x-current.x;
      rectangle.y = origin.y-current.y;

      int x1=rectangle.x+(rectangle.width-w)/2;
      int y1=rectangle.y+(rectangle.height-h)/2;
      int w1=rectangle.x+(rectangle.width-w);
      int h1=rectangle.y+(rectangle.height-h);

      switch(pos)
      {
        case OyoahaUtilities.CENTER:
        if(intersects(x, y, width, height, x1, y1, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,x1,y1,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.TOP:
        if(intersects(x, y, width, height, x1, rectangle.y, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,x1,rectangle.y,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.TOPLEFT:
        if(intersects(x, y, width, height, rectangle.x, rectangle.y, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,rectangle.x,rectangle.y,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.LEFT:
        if(intersects(x, y, width, height, rectangle.x, y1, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,rectangle.x,y1,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.LEFTBOTTOM:
        if(intersects(x, y, width, height, rectangle.x, h1, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,rectangle.x,h1,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.BOTTOM:
        if(intersects(x, y, width, height, x1, h1, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,x1,h1,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.BOTTOMRIGHT:
        if(intersects(x, y, width, height, w1, h1, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,w1,h1,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.RIGHT:
        if(intersects(x, y, width, height, w1, y1, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,w1,y1,c);
          g.setClip(s);
        }
        break;
        case OyoahaUtilities.RIGHTTOP:
        if(intersects(x, y, width, height, w1, rectangle.y, w, h))
        {
          Shape s = normalizeClip(g, x, y, width, height);
          g.drawImage(i,w1,rectangle.y,c);
          g.setClip(s);
        }
        break;
      }
    }
    catch(Exception ex)
    {

    }
  }

  /**
  *
  */
  public void paintAScaling(Graphics g, Component c, int x, int y, int width, int height, Image i)
  {
    try
    {
      if(!c.isShowing())
      return;

      Component root = SwingUtilities.getRoot(c);

      if(root instanceof JFrame)
      {
        root = ((JFrame)root).getContentPane();
      }
      else
      if(root instanceof JWindow)
      {
        root = ((JWindow)root).getContentPane();
      }
      else
      if(root instanceof JApplet)
      {
        root = ((JApplet)root).getContentPane();
      }

      Rectangle r = OyoahaUtilities.getFullRect(root);

      Point origin = root.getLocationOnScreen();
      Point current = c.getLocationOnScreen();

      r.x = origin.x-current.x;
      r.y = origin.y-current.y;

//--------

      Shape s = normalizeClip(g, x, y, width, height);
      g.drawImage(i,r.x,r.y,r.width,r.height,c);
      g.setClip(s);
    }
    catch(Exception ex)
    {

    }
  }
  
  /**
  *
  */
  public void paintAGradient(Graphics g, Component c, int x, int y, int width, int height, Color color1, Color color2, boolean horizontal, boolean vertical, int state)
  {
  
  }

//- - - - - -

  /**
  *
  */
  public void paintRMosaic(Graphics g, Component c, int x, int y, int width, int height, Image i)
  {
    Shape s = normalizeClip(g, x, y, width, height);

    int w=i.getWidth(c);
    int h=i.getHeight(c);
    int x0=x/w*w;
    int y0=y/h*h;

    for(int y1=y0; y1<y+height; y1+=h)
    for(int x1=x0; x1<x+width; x1+=w)
    g.drawImage(i,x1,y1,c);

    g.setClip(s);
  }

  /**
  *
  */
  public void paintRScrollMosaic(Graphics g, Component c, int x, int y, int width, int height, Image i, int decalX, int decalY)
  {
    Shape s = normalizeClip(g, x, y, width, height);

    int w=i.getWidth(c);
    int h=i.getHeight(c);

    int x0=(x/w*w-(decalX%w));
    int y0=(y/h*h-(decalY%h));

    for(int y1=y0; y1<y+height; y1+=h)
    for(int x1=x0; x1<x+width; x1+=w)
    g.drawImage(i,x1,y1,c);

    g.setClip(s);
  }

  /**
  *
  */
  public void paintRImageAt(Graphics g, Component c, int x, int y, int width, int height, Image i, int pos)
  {
    Shape s = normalizeClip(g, x, y, width, height);

    int x1=x+(width-i.getWidth(c))/2;
    int y1=y+(height-i.getHeight(c))/2;
    int w1=x+(width-i.getWidth(c));
    int h1=y+(height-i.getHeight(c));

    switch(pos)
    {
      case OyoahaUtilities.CENTER:
      g.drawImage(i,x1,y1,c);
      break;
      case OyoahaUtilities.TOP:
      g.drawImage(i,x1,y,c);
      break;
      case OyoahaUtilities.TOPLEFT:
      g.drawImage(i,x,y,c);
      break;
      case OyoahaUtilities.LEFT:
      g.drawImage(i,x,y1,c);
      break;
      case OyoahaUtilities.LEFTBOTTOM:
      g.drawImage(i,x,h1,c);
      break;
      case OyoahaUtilities.BOTTOM:
      g.drawImage(i,x1,h1,c);
      break;
      case OyoahaUtilities.BOTTOMRIGHT:
      g.drawImage(i,w1,h1,c);
      break;
      case OyoahaUtilities.RIGHT:
      g.drawImage(i,w1,y1,c);
      break;
      case OyoahaUtilities.RIGHTTOP:
      g.drawImage(i,w1,y,c);
      break;
    }

    g.setClip(s);
  }

  /**
  *
  */
  public void paintRScaling(Graphics g, Component c, int x, int y, int width, int height, Image i)
  {
    Shape s = normalizeClip(g, x, y, width, height);
    g.drawImage(i,x,y,width,height,c);
    g.setClip(s);
  }

//- - - - - -
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -