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

📄 lwtoolkit.java

📁 Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java alternative to humble AWT-based
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 /**  * Returns an absolute location for the given relative location of the component.  * The absolute location is calculated relatively a native component where the  * light weight component is resided.  * @param <code>x</code> the x coordinate relatively the component.  * @param <code>y</code> the y coordinate relatively the component.  * @param <code>c</code> the lightweight component.  * @return an absolute location.  */  public static Point getAbsLocation(int x, int y, LwComponent c)  {    LwComponent p = null;    while ((p = c.getLwParent()) != null)    {      x += c.getX();      y += c.getY();      c = p;    }    return new Point (x, y);  } /**  * Returns an absolute location of the component.  * The absolute location is calculated relatively a native component where the  * light weight component is resided.  * @param <code>c</code> the lightweight component.  * @return an absolute location of the component.  */  public static Point getAbsLocation(LwComponent c) {    return getAbsLocation(0, 0, c);  } /**  * Returns a relative location for the specified absolute location relatively the light weight component.  * @param <code>x</code> the x coordinate relatively a native where the component is resided.  * @param <code>y</code> the y coordinate relatively a native where the component is resided.  * @param <code>c</code> the lightweight component.  * @return a relative location.  */  public static Point getRelLocation(int x, int y, LwComponent c) {    return getRelLocation(x, y, getDesktop(c), c);  } /**  * Returns a relative location for the specified target location relatively the light weight component.  * @param <code>x</code> the x coordinate relatively the target component where the component  * is resided.  * @param <code>y</code> the y coordinate relatively the target component where the component  * is resided.  * @param <code>target</code> the target lightweight component.  * @param <code>c</code> the lightweight component.  * @return a relative location.  */  public static Point getRelLocation(int x, int y, LwComponent target, LwComponent c)  {    while (c != target)    {      x -= c.getX();      y -= c.getY();      c = c.getLwParent();    }    return new Point(x, y);  } /**  * Gets the size of the screen.  * @return a size of the screen.  */  public static Dimension getScreenSize () {    return tool.getScreenSize ();  } /**  * Gets a graphics context for the specified lightweight component.  * @param <code>c</code> the lightweight component.  * @return a graphics context.  */  public static Graphics getGraphics(LwComponent c) {    return getGraphics(c, 0, 0, c.getWidth(), c.getHeight());  } /**  * Gets a graphics context for the specified area of the lightweight component.  * The method calculates clip area as intersecation the area bounds and a visible  * part of the component.  * @param <code>c</code> the lightweight component.  * @param <code>x</code> the x coordinate of the component area.  * @param <code>y</code> the y coordinate of the component area.  * @param <code>w</code> the width of the component area.  * @param <code>h</code> the height of the component area.  * @return a graphics context.  */  public static Graphics getGraphics(LwComponent c, int x, int y, int w, int h)  {    LwDesktop nc = getDesktop(c);    if (nc == null) return null;    Rectangle vp = c.getVisiblePart();    if (vp == null) return null;    Graphics  gr = nc.getGraphics();    if (gr == null) return null;    Point     l  = getAbsLocation(c);    gr.clipRect(vp.x + l.x + x, vp.y + l.y + y, vp.width , vp.height);    gr.translate(l.x, l.y);    return gr;  } /**  * Calculates and gets a maximal preferred size among visible children of the specified  * container.  * @param <code>target</code> the container.  * @return a maximal preferred size.  */  public static Dimension getMaxPreferredSize(LayoutContainer target)  {     int maxWidth = 0, maxHeight = 0;     for (int i=0; i<target.count(); i++)     {       Layoutable l = target.get(i);       if (l.isVisible())       {         Dimension ps = l.getPreferredSize();         if (ps.width  > maxWidth ) maxWidth = ps.width;         if (ps.height > maxHeight) maxHeight = ps.height;       }     }     return new Dimension(maxWidth, maxHeight);  } /**  * Calculates and gets origin for the specified area of the component. The origin is  * calculated as a location of the component view to have the specified area inside  * a visible part of the component.  * @param <code>x</code> the x coordinate of the component area.  * @param <code>y</code> the y coordinate of the component area.  * @param <code>w</code> the width of the component area.  * @param <code>h</code> the height of the component area.  * @param <code>target</code> the component.  * @return an origin of the component.  */  public static Point calcOrigin (int x, int y, int w, int h, LwComponent target) {    Point origin = target.getOrigin();    return calcOrigin (x, y, w, h, origin==null?0:origin.x, origin==null?0:origin.y, target);  } /**  * Calculates and gets origin for the specified area of the component relatively the specified  * previous origin. The origin is calculated as a location of the component view to have the  * specified area inside a visible part of the component.  * @param <code>x</code> the x coordinate of the component area.  * @param <code>y</code> the y coordinate of the component area.  * @param <code>w</code> the width of the component area.  * @param <code>h</code> the height of the component area.  * @param <code>px</code> the x coordinate of the previous origin.  * @param <code>py</code> the y coordinate of the previous origin.  * @param <code>target</code> the component.  * @return an origin of the component.  */  public static Point calcOrigin (int x, int y, int w, int h, int px, int py, LwComponent target) {    return calcOrigin (x, y, w, h, px, py, target, target.getInsets());  } /**  * Calculates and gets origin for the specified area of the component relatively the specified  * previous origin. The origin is calculated as a location of the component view to have the  * specified area inside a visible part of the component.  * @param <code>x</code> the x coordinate of the component area.  * @param <code>y</code> the y coordinate of the component area.  * @param <code>w</code> the width of the component area.  * @param <code>h</code> the height of the component area.  * @param <code>px</code> the x coordinate of the previous origin.  * @param <code>py</code> the y coordinate of the previous origin.  * @param <code>target</code> the component.  * @param <code>i</code> the insets.  * @return an origin of the component.  */  public static Point calcOrigin (int x, int y, int w, int h, int px, int py, LwComponent target, Insets i)  {     int dw = target.getWidth(), dh = target.getHeight();     if (dw > 0 && dh > 0)     {       if (dw - i.left - i.right >= w)       {         int xx = x + px;         if (xx < i.left) px += (i.left - xx);         else         {           xx += w;           if (xx > dw - i.right) px -= (xx - dw + i.right);         }       }       if (dh - i.top - i.bottom >= h)       {         int yy = y + py;         if (yy < i.top) py += (i.top - yy);         else         {           yy += h;           if (yy > dh - i.bottom) py -= (yy - dh + i.bottom);         }       }       return new Point(px, py);     }     else return new Point();  } /**  * Draws marker for the specified rectangular area, the given background and foreground  * colors.  * @param <code>g</code> the specified graphics context.  * @param <code>x</code> the x coordinate of the top-left corner of the rectangular area.  * @param <code>y</code> the y coordinate of the top-left corner of the rectangular area.  * @param <code>w</code> the width of the rectangular area.  * @param <code>h</code> the height of the rectangular area.  * @param <code>bg</code> the background color.  * @param <code>fc</code> the foreground color.  */  public static void drawMarker(Graphics g, int x, int y, int w, int h, Color bg, Color fc)  {    try {      g.setXORMode(bg);      g.setColor(fc);      g.fillRect(x, y, w, h);    }    finally {      g.setPaintMode();    }  } /**  * Draws line using XOR mode.  * @param <code>target</code> the specified component.  * @param <code>x1</code> the first x coordinate of the line.  * @param <code>y1</code> the first y coordinate of the line.  * @param <code>x2</code> the second x coordinate of the line.  * @param <code>y2</code> the second y coordinate of the line.  */  public static void drawXORLine (LwComponent target, int x1, int y1, int x2, int y2)  {     Graphics g = LwToolkit.getDesktop(target).getGraphics();     try {       Point p = LwToolkit.getAbsLocation(target);       g.setXORMode(Color.white);       g.setColor  (Color.black);       g.drawLine  (p.x + x1, p.y + y1, p.x + x2, p.y + y2);     }     finally {       if (g != null) g.dispose();     }  } /**  * Draws rectangle using XOR mode.  * @param <code>target</code> the specified component.  * @param <code>x</code> the top-left corner x coordinate of the rectangle.  * @param <code>y</code> the top-left corner y coordinate of the rectangle.  * @param <code>w</code> the rectangle width.  * @param <code>h</code> the rectangle height.  */  public static void drawXORRect (LwComponent target, int x, int y, int w, int h)  {     Graphics g = LwToolkit.getDesktop(target).getGraphics();     try {       Point p = LwToolkit.getAbsLocation(target);       g.setXORMode(Color.white);       g.setColor  (Color.black);       g.drawRect  (p.x + x, p.y + y, w, h);     }     finally {       if (g != null) g.dispose();     }  } /**  * Fills the rectangle using XOR mode.  * @param <code>target</code> the specified component.  * @param <code>x</code> the top-left corner x coordinate of the rectangle.  * @param <code>y</code> the top-left corner y coordinate of the rectangle.  * @param <code>w</code> the rectangle width.  * @param <code>h</code> the rectangle height.  */  public static void fillXORRect (LwComponent target, int x, int y, int w, int h)  {     Graphics g = LwToolkit.getDesktop(target).getGraphics();     try {       Point p = LwToolkit.getAbsLocation(target);       g.setXORMode(Color.white);       g.setColor  (Color.black);       g.fillRect  (p.x + x, p.y + y, w, h);     }     finally {       if (g != null) g.dispose();     }  } /**  * Don't touch the method it will be redesigned in the further version.  */  public static boolean isActionMask(int mask) {    return mask == 0 || ((mask & java.awt.event.InputEvent.BUTTON1_MASK) >  0&&                         (mask & java.awt.event.InputEvent.BUTTON3_MASK) == 0  );  }}

⌨️ 快捷键说明

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