📄 lwcanvas.java
字号:
/**
* Caption: Zaval Light-Weight Visual Components Library
* $Revision: 2.79 $
* $Date: 2003/08/22 11:24:16 $
*
* @author: Andrei Vishnevsky
* @version: 3.50
*
* Zaval Light-Weight Visual Components Library (LwVCL) is a pure Java
* alternative to humble AWT-based and SWING-based GUI interfaces for
* wide ranges of platforms, including J2SE, PersonalJava and J2ME.
*
* Designed as light-weight but, alternatively to Swing, built separately
* from AWT (not on top of the java.awt library like Swing), the LwVCL is
* the good alternative to highly performant, memory-efficient, flexible
* GUI solution for embedded, stand-alone and applet applications.
*
* For more info on this product read Zaval Light-Weight Visual Components Library Tutorial
* (It comes within this package).
* The latest product version is always available from the product's homepage:
* http://www.zaval.org/products/lwvcl/
* and from the SourceForge:
* http://sourceforge.net/projects/zaval0003/
*
* Contacts:
* Support : support@zaval.org
* Change Requests : change-request@zaval.org
* Feedback : feedback@zaval.org
* Other : info@zaval.org
*
* Copyright (C) 2001-2003 Zaval Creative Engineering Group (http://www.zaval.org)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* (version 2) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
package org.zaval.lw;import java.awt.*;import org.zaval.lw.event.*;import org.zaval.util.*;/** * This is basic implemenation of the light weight component interface that should be used * to develop own light weight component. As rule when you develop a lightweight components * it is necessary to pass through following steps: * <ul> * <li> * Inherit the class for your lightweight component. * </li> * <li> * Implement necessary events listeners interfaces, to have ability handling * required lightweight events. * </li> * <li> * Override (if it is necessary) <code>paint</code> method to define the component face. * </li> * <li> * Override (if it is necessary) <code>update</code> method to define the component * background. * </li> * <li> * Override (if it is necessary) <code>recalc</code> method to calculate the component * metrics. For example, you can calculate "pure" preferred size inside the method or * some metrical characteristics that are used to calculate the preferred size. * </li> * <li> * Override (if it is necessary) <code>calcPreferredSize</code> method to define "pure" * preferred size of the component face. * </li> * </ul> */public class LwCanvasextends org.zaval.util.ValidationObjectimplements LwComponent{ private Color back; protected long insets; protected short bits = DEFAULT_BITS; protected int x, y, width, height, psWidth = -1, psHeight = -1; /** * The component parent. */ protected LwComponent parent; /** * The component view manager. */ protected LwViewMan skins; /** * Calculates and returns the insets of this component. Take care that insets for lightweight * components differ from Java AWT components. The lightweight insets * defines indents from "left", "top", "right" and "bottom" of the component view. * Don't override the method. If you want to define insets use <code>setInsets</code> * method. * @return the insets of this component. */ public /*C#virtual*/ Insets getInsets() { return getInsets(this); } public int getX() { return x; } public int getY() { return y; } public int getWidth() { return width; } public int getHeight() { return height; } /** * Sets the specified insets for the component. * @param <code>top</code> the top indent. * @param <code>left</code> the left indent. * @param <code>bottom</code> the bottom indent. * @param <code>right</code> the right indent. */ public void setInsets (int top, int left, int bottom, int right) { Insets i1 = getInsets(); if (!(new Insets (top, left, bottom, right)).equals(i1)) { insets = (top & 0xFFFF) + ((left & 0xFFFF) << 16); long l = (bottom & 0xFFFF) + ((right & 0xFFFF) << 16); insets += (l << 32); vrp(); } } /** * Returns a size of this component. The size is reperesented with * <code>java.awt.Dimension</code> class. * @return a <code>Dimension</code> object that indicates the * size of this component. */ public Dimension getSize() { return new Dimension(width, height); } /** * Returns the bounding rectangle of the visible part for the component. * @return a visible part bounding rectangle. */ public /*C#virtual*/ Rectangle getVisiblePart() { if (isVisible()) { //??? if (parent == null) return new Rectangle (0, 0, width, height); Rectangle pr = parent.getVisiblePart(); if (pr != null) pr = MathBox.intersection(pr.x, pr.y, pr.width, pr.height, x, y, width, height); if (pr != null && pr.width > 0 && pr.height > 0) { pr.x -= x; pr.y -= y; return pr; } } return null; } /** * Sets the lightweight parent of this component. It is supposed that the parent implements * LwContainer interface. The method is provided for lightweight core usage to support components * hierarchy, not for applications that base on the library. * Don't touch the method. * @param <code>o</code> the parent component of this lightweight component. */ public void setLwParent(LwComponent o) { if (o != parent) { parent = o; invalidate(); } } /** * Gets the location of this component point specifying the component top-left corner. * The location is relative to the parent component coordinate space. * @return an instance of <code>Point</code> representing the top-left corner * of the component bounds in the coordinate space of the component parent. */ public Point getLocation() { return new Point(x, y); } /** * Gets the background color of this lightweight component. * @return a componen background color. */ public Color getBackground() { return back == null?LwToolkit.BACK_COLOR:back; } /** * Determines if this component is visible. The component is visible * if the visibility flag is true. * @return <code>true</code> if the component is visible; * <code>false</code> otherwise. */ public /*C#virtual*/ boolean isVisible() { return MathBox.checkBit(bits, VISIBLE_BIT); } /** * Shows or hides this lightweight component depending on the value of parameter * <code>b</code>. The method performs appropriate LwComponentEvent. * @param <code>b</code> if it is <code>true</code>, shows this component; * otherwise, hides this component. */ public /*C#virtual*/ void setVisible(boolean b) { if (MathBox.checkBit(bits, VISIBLE_BIT) != b) { bits = MathBox.getBits(bits, VISIBLE_BIT, b); invalidate(); if (b) { LwEventManager.manager.perform(new LwComponentEvent(this, LwComponentEvent.COMP_SHOWN)); repaint(); } else { LwEventManager.manager.perform(new LwComponentEvent(this, LwComponentEvent.COMP_HIDDEN)); if (parent != null) parent.repaint(x, y, width, height); } } } /** * Determines whether this component is enabled. If the method returns * <code>true</code> than the component is enabled and can participate in event * handling and performing processes. Components are enabled initially by default. * A component can be enabled or disabled by calling its <code>setEnabled</code> * method. * @return <code>true</code> if the component is enabled; <code>false</code> otherwise. */ public /*C#virtual*/ boolean isEnabled() { return MathBox.checkBit(bits, ENABLE_BIT) && (parent == null || parent.isEnabled()); } /** * Enables or disables this component. An enabled component can participate * in events handling and performing processes. Component is enabled initially * by default. The method performs appropriate LwComponentEvent. * @param <code>b</code> if <code>true</code>, this component is * enabled; otherwise this component is disabled. */ public /*C#virtual*/ void setEnabled(boolean b) { if (MathBox.checkBit(bits, ENABLE_BIT) != b) { bits = MathBox.getBits(bits, ENABLE_BIT, b); if (b) LwEventManager.manager.perform(new LwComponentEvent(this, LwComponentEvent.COMP_ENABLED )); else LwEventManager.manager.perform(new LwComponentEvent(this, LwComponentEvent.COMP_DISABLED)); repaint(); } } /** * Sets the background color of this component. The color is used to fill the component * background in case if it is not transparent. * @param <code>c</code> the color to become this component background color. Use <code>null</code> * as the color value to set the background to the default color value. */ public /*C#virtual*/ void setBackground(Color c) { if (c != back && (c == null || !c.equals(back))) { back = c; repaint(); } } /** * Invalidates this component. The parent will be invalidated with this component too. */ public /*C#override*/ void invalidate() { if (parent != null) parent.invalidate(); super.invalidate(); } /** * Validates this component. The method initiates validation process only if it is necessary. * It means that you don't need to care about frequency the method executing. The method executes * <code>recalc</code> method to calculate the component metrics if it is necessary. So, * override the method (<code>recalc</code> method) to calculate some metrical characteristics * to minimize the computation time. */ public /*C#override*/ void validate() { if (isVisible()) { if (skins != null) skins.validate(); super.validate(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -