📄 lwcanvas.java
字号:
/** * Sets a new location for this component. The top-left corner of * the new location is specified by the <code>x</code> and <code>y</code> * parameters in the coordinate space of this component parent. * @param <code>xx</code> the <i>x</i>-coordinate of the new location * top-left corner in the parent coordinate space. * @param <code>yy</code> The <i>y</i>-coordinate of the new location * top-left corner in the parent coordinate space. */ public void setLocation (int xx, int yy) { if (xx != x || y != yy) { int ox = x; int oy = y; x = xx; y = yy; if (parent != null) parent.repaint(Math.min(x, ox), Math.min(y, oy), width + Math.abs(x - ox), height + Math.abs(y - oy)); } } /** * Sets the specified size for this component. * @param <code>w</code> the width of this component. * @param <code>h</code> the height of this component. */ public void setSize (int w, int h) { if (w != width || h != height) { int mw = Math.max (w, width); int mh = Math.max (h, height); width = w; height = h; invalidate(); repaint(0, 0, mw, mh); } } /** * Gets the bounds of this component. The bounds is represented with * <code>java.awt.Rectangle</code> class. * @return a rectangle indicating this component bounds. */ public Rectangle getBounds() { return new Rectangle (x, y, width, height); } /** * Determines if the component or an immediate child component contains the * (xx, yy) location in its visible part and if so, returns the component. * @param <code>xx</code> the x coordinate. * @param <code>yy</code> the y coordinate. * @return the component or sub-component that contains the (x, y) location; * <code>null</code> if the location doesn't belong to visible part of * this component. */ public /*C#virtual*/ LwComponent getLwComponentAt(int xx, int yy) { Rectangle r = getVisiblePart(); return r != null && r.contains(xx, yy)?this:null; } /** * Gets the lightweight parent of this component. It is supposed that the parent implements * LwContainer interface. * @return a parent container of this component. */ public /*C#virtual*/ LwComponent getLwParent() { return parent; } /** * Invoked with <code>validate</code> method only if the component is not valid. * The method shoud be overrided to calculate metrical characteristics of the component to * minimize computation time of the preferred size for the component. For example, you can * calculate a preferred size inside the method and just return it by * <code>calcPreferredSize</code> method. */ protected /*C#override*/ void recalc() {} /** * Performs repainting process of this component. The method causes * calling of <code>update</code> and than <code> paint </code> methods. * The method bases on appropriate method of LwPaintManager. */ public /*C#virtual*/ void repaint() { LwPaintManager.manager.repaint(this); } /** * Performs repainting process of the specified rectangle. The method causes * calling of <code>update</code> and than <code> paint </code> methods. * The method bases on appropriate method of LwPaintManager. * @param <code>x</code> the <i>x</i> coordinate. * @param <code>y</code> the <i>y</i> coordinate. * @param <code>w</code> the width. * @param <code>h</code> the height. */ public /*C#virtual*/ void repaint(int x, int y, int w, int h) { LwPaintManager.manager.repaint(this, x, y, w, h); } /** * Updates this component. The calling of the method precedes * the calling of <code>paint</code> method and it is performed with * <code>repaint</code> method. The method can be used to fill the drawable * component with the background color if the component is opaque. * In the implementation light weight component is updated (using the background * color) with LwPaintManager, so it is not necessary to care about it. * <p> * You can use the method to define own background pattern. * @param <code>g</code> the specified context to be used for updating. */ public /*C#virtual*/ void update(Graphics g){} /** * Paints this component. You can use the method to define a face of the * component * @param <code>g</code> the graphics context to be used for painting. */ public /*C#virtual*/ void paint (Graphics g){} /** * Gets the preferred size of this component. The method computes the preferred size as * a sum of the component insets (returned with <code>getInsets</code> method) and * a "pure" preferred size (returned with <code>calcPreferredSize</code> method). * You should not override the method, use <code>calcPreferredSize</code> method to * define the "pure" preferred size of this component. * @return a dimension object indicating this component preferred size. */ public /*C#virtual*/ Dimension getPreferredSize () { validate(); return getPreferredSize(this); } /** * Returns a view manager of the component. The view manager can be <code>null</code>. * The input argument <code>autoCreate</code> defines if the view manager has to be created * automatically in a case if it has not been determined before. It means, if the argument is * <code>true</code> and the view manager is <code>null</code>, than the component will * try to create and initialize its view manager by a default view manager. If the argument * is <code>false</code> than the method returns the component view manager as is. * @param <code>autoCreate</code> the flag defines if the view manager should be created * automatically. * @return a view manager for the component. */ public LwViewMan getViewMan (boolean autoCreate) { if (skins == null && autoCreate) { skins = new LwViewMan(); skins.setParent(this); } return skins; } /** * Sets the specified view manager for the component. * @param <code>man</code> the view manager to set for the component. */ public void setViewMan(LwViewMan man) { if (man != skins) { skins = man; if (skins != null) skins.setParent(this); viewManChanged(); vrp(); } } /** * Returns a string representation of the object. * @return a string representation of this instance. */ public String toString () { return "[(" + x + "," + y + ") " + width + " " + height + "] valid=" + isValid() + ",op=" + isOpaque() + ",vis=" + isVisible(); } /** * Gets the "pure" preferred size for this component. The method should be overrided to define * the component preferred size. Don't use insets to calculate the preferred size, the insets * will be added with <code>getPreferredSize</code> method. * @return a "pure" preferred size. */ protected /*C#virtual*/ Dimension calcPreferredSize() { return new Dimension(LwToolkit.PS_SIZE); } public /*C#virtual*/ boolean canHaveFocus() { return false; } /** * Tests if the component is a focus owner. The method uses current LwFocusManager manager * to define a focus owner. * @return <code>true</code> if the component is a focus owner; otherwise * <code>false</code> */ public boolean hasFocus() { return LwFocusManager.manager.hasFocus(this); } /** * Requests focus for this component. The method uses current LwFocusManager manager * to request a focus. The component can be a focus owner if it implements LwFocusListener * interface. */ public void requestFocus() { LwFocusManager.manager.requestFocus(this); } /** * Sets the opaque of this component. Use <code> false </code> * argument value to make a transparent component from this component. * The painting process will not use <code>update</code> method and the background view * for a transparent component. * @param <code>b</code> the opaque flag. */ public /*C#virtual*/ void setOpaque(boolean b) { if (b != MathBox.checkBit(bits, OPAQUE_BIT)) { bits = MathBox.getBits(bits, OPAQUE_BIT, b); repaint(); } } /** * Gets the opaque of this component. If the method returns * <code>false</code> than the component is transparent, in this case * <code>update</code> method has not be called during painting process and LwPaintManager * doesn't clear the component with the background color. * @return <code>true</code> if the component is opaque; otherwise * <code>false</code>. */ public boolean isOpaque() { return MathBox.checkBit(bits, OPAQUE_BIT); } /** * Sets the specified preferred size for the component. Using the method it is * possible to fix the preferred size with the given width and height. In this case * <code>getPreferredSize</code> method returns the fixed size. * @param <code>w</code> the width to be used as the preferred size width. * If the width is less zero than the width will be calculated basing on the component * insets and the returned by <code>calcPreferredSize</code> width. * @param <code>h</code> the height to be used as the preferred size height. * If the height is less zero than the height will be calculated basing on the component * insets and the returned by <code>calcPreferredSize</code> height. */ public void setPSSize (int w, int h) { if (w != psWidth || h != psHeight) { psWidth = w; psHeight = h; vrp(); } } /** * Returns an origin of the component. The origin defines an offset of the component view * relatively the component point of origin. The origin can be used to scroll the component * view. The default origin value is <code>null</code>, in this case the origin is (0, 0). * @return an origin of the component. */ public /*C#virtual*/ Point getOrigin () { return null; } /** * Invoked whenever the view manager has been changed. The method can be overrided to listen * when the view manager is re-set. */ protected /*C#virtual*/ void viewManChanged() {} /** * Invalidates and then repaints the component. */ protected void vrp() { invalidate(); repaint(); } private static Dimension getPreferredSize (LwCanvas c) { Dimension d = null; if (c.psWidth >= 0 && c.psHeight >= 0) d = new Dimension(c.psWidth, c.psHeight); else { d = c.calcPreferredSize(); if (c.skins != null) d = MathBox.max (d, c.skins.getPreferredSize()); if (c.psWidth >= 0) d.width = c.psWidth; if (c.psHeight >= 0) d.height = c.psHeight; } Insets i = c.getInsets(); d.width += (i.left + i.right); d.height += (i.top + i.bottom); return d; } private static final Insets getInsets(LwCanvas c) /*java*/ /*C#private static Insets getInsets(LwCanvas c)*/ { Insets i = new Insets((int)(c.insets & 0xFFFF), (int)((c.insets >> 16) & 0xFFFF), (int)((c.insets >> 32) & 0xFFFF), (int)((c.insets >> 48) & 0xFFFF)); return (c.skins != null)?MathBox.max(c.skins.getInsets(), i):i; } private static short VISIBLE_BIT = 1; private static short ENABLE_BIT = 2; private static short OPAQUE_BIT = 4; private static short DEFAULT_BITS = 7;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -