📄 lwnotebook.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 java.awt.event.*;import java.util.*;import org.zaval.lw.event.*;import org.zaval.misc.*;/** * This is notebook container. The main features of the container are shown in the list below: * <ul> * <li> * The page tabs can be laid out using "right", "left", "top" or "bottom" alignments. * Use <code>setTitleAlignment</code> to define the alignment. * The default tabs alignment is "top". * </li> * <li> * It is possible to use any views as tabs views. The appropriate tab view are passed * as argument of <code>addPage</code> method. The library provides standard * tab view - LwTabRender. * </li> * <li> * <code>add</code>, <code>insert</code>, <code>remove</code> methods can be used to change * the notebook pages components. * </li> * <li> * <code>enablePage</code>, <code>isPageEnabled</code> methods can be used to change * enabled state of the specified page. * </li> * <li> * The container implements and uses own layout manager, so it is undesirable * to use any other layout manager for the notebook container. * </li> * <li> * To listen when a page of the container has been selected use <code>addSelectionListener</code> * and <code>removeSelectionListener</code> methods. The selection event is represented by * the LwActionEvent. Use <code>getData</code> method of the event to get a page index that * has been selected. * </li> * </ul> * <p> * The sample below illustrates the notebook container usage: * <pre> * ... * LwNotebook n = new LwNotebook(); * n.addPage("Tab 1", new LwPanel()); * n.addPage("Tab 2", new LwPanel()); * n.addPage("Tab 3", new LwPanel()); * ... * </pre> */public class LwNotebookextends LwPanelimplements LwMouseListener, LwKeyListener, LwLayout, LwTitleInfo, LwFocusListener{ private Vector pages = new Vector(); private Rectangle tabArea; private int selectedIndex = -1, offX = 1, offY = 1, orient; private LwActionSupport support; /** * Constructs a notebook container using default (Alignment.TOP) tabs alignment. */ public LwNotebook() { this(Alignment.TOP); } /** * Constructs a notebook container using the specified tabs alignment. * @param <code>orient</code> the specified tabs alignement. */ public LwNotebook(int orient) { setTitleAlignment(orient); getViewMan(true).setBorder(new LwTitledBorder(LwBorder.RAISED)); } public /*C#override*/ boolean canHaveFocus() { return true; } /** * Gets the tabs alignment. * @return a tabs alignment. */ public int getTitleAlignment() { return orient; } /** * Sets the specified tabs alignment. The alignment can have one of following values: * Alignment.TOP Alignment.BOTTOM Alignment.LEFT Alignment.RIGHT, otherwise the * IllegalArgumentException will be thrown. * @param <code>o</code> the specified tabs alignement. */ public void setTitleAlignment(int o) { if (o != Alignment.TOP && o != Alignment.BOTTOM && o != Alignment.LEFT && o != Alignment.RIGHT) throw new IllegalArgumentException(); if (orient != o) { orient = o; vrp(); } } /** * Tests if the specified page is enabled or not. * @param <code>index</code> the specified page index. * @return <code>true</code> if the page is enaled;otherwise <code>false</code>. */ public boolean isPageEnabled (int index) { return ((LwComponent)get(index)).isEnabled(); } /** * Sets the given enabled state for the specified page. * @param <code>index</code> the specified page index. * @param <code>b</code> the given enabled state. */ public void enablePage (int index, boolean b) { LwComponent c = (LwComponent)get(index); if (c.isEnabled() != b) { c.setEnabled(b); if (!b && selectedIndex == index) select(-1); repaint(); } } /** * Adds the page with the specified title. The method uses default tab view to * render the page tab. * @param <code>title</code> the specified tab title. * @param <code>c</code> the specified page component. */ public void addPage (String title, LwComponent c) { addPage(new LwTabRender(title), c); } /** * Adds the specified component as the notebook page and sets the specified view as. * the tab view. * @param <code>v</code> the specified tab view. * @param <code>c</code> the specified page component. */ public void addPage (LwView v, LwComponent c) { pages.addElement(v); add (c); if (selectedIndex < 0) { int nxt = next(0, 1); if (nxt >= 0) select(nxt); } vrp(); } /** * Returns the tab view for the specified page. * @param <code>i</code> the specified page number. * @return a tab view. */ public LwView getPageView (int i) { return (LwView)pages.elementAt(i); } public /*C#override*/ void remove(int i) { if (selectedIndex == i) select(-1); pages.removeElementAt(i); super.remove(i); } public /*C#override*/ void removeAll() { if (selectedIndex >= 0) select(-1); pages.removeAllElements(); super.removeAll(); } /** * The method is overrided by the component for internal usage. Don't tuch the method. */ protected /*C#override*/ void recalc () { int maxW = 0, maxH = 0, w = 0, h = 0; tabArea = new Rectangle(); Insets ins = getInsets(); for (int i=0; i<pages.size(); i++) { LwView v = (LwView)pages.elementAt(i); Dimension ps = v.getPreferredSize(); if (maxW < ps.width ) maxW = ps.width; if (maxH < ps.height) maxH = ps.height; w += ps.width; h += ps.height; } if (orient == Alignment.LEFT || orient == Alignment.RIGHT) { tabArea.y = ins.top + offY; tabArea.width = maxW; tabArea.height = h; tabArea.x = (orient == Alignment.LEFT)?ins.left +offX:width - ins.right - offX - maxW; } else { tabArea.x = ins.left + offX; tabArea.width = w + ins.left; tabArea.height = maxH; tabArea.y = (orient == Alignment.TOP)?ins.top +offY:height - ins.bottom - offY - maxH; } super.recalc(); } /** * Gets the tab index for the tab that is selected at the moment. * @return a tab index. */ public int getSelectedIndex() { return selectedIndex; } /** * Paints this component. * @param <code>g</code> the graphics context to be used for painting. */ public /*C#override*/ void paint(Graphics g) { Rectangle clip = g.getClipBounds(); if (selectedIndex >= 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -