📄 lwnotebook.java
字号:
{ Rectangle r = getPageBounds(selectedIndex); if (orient == Alignment.LEFT || orient == Alignment.RIGHT) g.clipRect(r.x, 0, r.width, r.y); else g.clipRect(0, r.y, r.x, r.height); } for (int i=0; i<selectedIndex; i++) { Rectangle r = getPageBounds(i); LwView v = (LwView)pages.elementAt(i); v.paint(g, r.x, r.y, r.width, r.height, (Drawable)get(i)); } if (selectedIndex >= 0) { g.setClip(clip); Rectangle r = getPageBounds(selectedIndex); if (orient == Alignment.LEFT || orient == Alignment.RIGHT) g.clipRect(r.x, r.y + r.height, r.width, tabArea.height); else g.clipRect(r.x + r.width, r.y, tabArea.width, r.height); } for (int i=selectedIndex+1; i<pages.size(); i++) { Rectangle r = getPageBounds(i); LwView v = (LwView)pages.elementAt(i); v.paint(g, r.x, r.y, r.width, r.height, (Drawable)get(i)); } if (selectedIndex >= 0) { g.setClip(clip); Rectangle r = getPageBounds(selectedIndex); LwView v = (LwView)pages.elementAt(selectedIndex); v.paint(g, r.x, r.y, r.width, r.height, (Drawable)get(selectedIndex)); v.paint(g, r.x+1, r.y, r.width, r.height, (Drawable)get(selectedIndex)); if (hasFocus()) LwToolkit.drawDotRect(g, r.x + 3, r.y + 3, r.width - 6, r.height - 6); } } public void keyPressed (LwKeyEvent e) { if (selectedIndex != -1 && pages.size() > 0) { switch (e.getKeyCode()) { case KeyEvent.VK_UP : case KeyEvent.VK_LEFT : { int nxt = next (selectedIndex-1, -1); if (nxt >= 0) select(nxt); } break; case KeyEvent.VK_DOWN : case KeyEvent.VK_RIGHT: { int nxt = next (selectedIndex+1, 1); if (nxt >= 0) select(nxt); } break; } } } public void mousePressed (LwMouseEvent e) { if (LwToolkit.isActionMask(e.getMask())) { int index = getPageAt(e.getX(), e.getY()); if (index >= 0 && isPageEnabled(index)) select(index); } } public void keyReleased (LwKeyEvent e) {} public void keyTyped (LwKeyEvent e) {} public void mouseEntered (LwMouseEvent e) {} public void mouseExited (LwMouseEvent e) {} public void mouseClicked (LwMouseEvent e) {} public void mouseReleased(LwMouseEvent e) {} public void componentAdded (Object id, Layoutable lw, int index) {} public void componentRemoved (Layoutable lw, int index) {} public Dimension calcPreferredSize(LayoutContainer target) { Dimension max = LwToolkit.getMaxPreferredSize(target); if (orient == Alignment.BOTTOM || orient == Alignment.TOP) { max.width = Math.max (2*offX + max.width, 2*offX + tabArea.width); max.height += (offY + tabArea.height); } else { max.width += (offX + tabArea.width); max.height = Math.max (2*offY + max.height, 2*offY + tabArea.height); } return max; } public void layout(LayoutContainer target) { Insets targetInsets = target.getInsets(); for (int i=0; i<target.count(); i++) { LwComponent l = (LwComponent)target.get(i); if (isSelected(i)) { l.setVisible(true); if (orient == Alignment.TOP || orient == Alignment.BOTTOM) l.setSize(width - targetInsets.left - targetInsets.right, height - tabArea.height - targetInsets.top - targetInsets.bottom - offY); else l.setSize(width - tabArea.width - targetInsets.left - targetInsets.right - offX, height - targetInsets.top - targetInsets.bottom); switch (orient) { case Alignment.TOP : l.setLocation(targetInsets.left, tabArea.y + tabArea.height); break; case Alignment.BOTTOM : l.setLocation(targetInsets.left, targetInsets.top); break; case Alignment.LEFT : l.setLocation(tabArea.x + tabArea.width, targetInsets.top); break; case Alignment.RIGHT : l.setLocation(targetInsets.left, targetInsets.top); break; } } else l.setVisible(false); } } /** * Selects the tab by the specified index. Use <code>-1</code> index value to de-select * current selected tab, in this case no one tab will be selected. * @param <code>index</code> the specified item index. */ public void select(int index) { if (selectedIndex != index) { selectedIndex = index; perform(selectedIndex); vrp(); } } /** * Tests if the tab with the specified index is selected or not. * @return <code>true</code> if the tab with the specified index is selected; otherwise * <code>false</code>. */ public boolean isSelected(int i) { return i == selectedIndex; } /** * Adds the specified selection listener to receive selection events from this notebook container. * @param <code>l</code> the specified listener. */ public void addSelectionListener(LwActionListener l) { if(support == null) support = new LwActionSupport(); support.addListener(l); } /** * Removes the specified selection listener so it no longer receives selection events * from this notebook conatiner. * @param <code>l</code> the specified listener. */ public void removeSelectionListener(LwActionListener l) { if(support != null) support.removeListener(l); } public Rectangle getTitleBounds() { if (selectedIndex == -1) { if (orient == Alignment.LEFT ) return new Rectangle (0, 0, tabArea.width + tabArea.x, 0); if (orient == Alignment.TOP ) return new Rectangle (0, 0, 0, tabArea.height + tabArea.y); if (orient == Alignment.RIGHT ) return new Rectangle (tabArea.x, 0, tabArea.width, 0); if (orient == Alignment.BOTTOM) return new Rectangle (0, tabArea.y, 0, tabArea.height); return null; } else return getPageBounds(selectedIndex); } public void focusGained(LwFocusEvent e) { if (selectedIndex < 0) select(next(0, 1)); } public void focusLost(LwFocusEvent e) {} /** * Fires appropriate selection event for list of selection listeners. The method * performs LwActionEvent as the selection event where the <code>getData</code> method * returns the tab index that has been selected * @param <code>index</code> the tab index that has been selected. */ protected /*C#virtual*/ void perform(int index) { if (support != null) support.perform(new LwActionEvent(this, new Integer(index))); } /** * Gets the default layout manager that is set with the container during initialization. * The component defines itself as the default layout. Don't use any other layout for * the component, in this case the working of the component can be wrong. * @return a layout manager. */ protected /*C#override*/ LwLayout getDefaultLayout() { return this; } private Rectangle getPageBounds(int index) { Rectangle res = null; int x = 0, y = 0; for (int i=0; i<pages.size(); i++) { LwView v = (LwView)pages.elementAt(i); Dimension d = v.getPreferredSize(); if (index == i) { if (orient == Alignment.BOTTOM || orient == Alignment.TOP) res = new Rectangle(x + tabArea.x, tabArea.y, d.width, tabArea.height); else res = new Rectangle(tabArea.x, tabArea.y + y, tabArea.width, d.height); break; } x += d.width; y += d.height; } if (index == selectedIndex) { switch (orient) { case Alignment.LEFT : { res.x -= offX; res.y -= offY; res.width += offX; res.height += 2*offY; } break; case Alignment.RIGHT : { res.y -= offY; res.width += offX; res.height += 2*offY; } break; case Alignment.TOP : { res.x -= offX; res.y -= offY; res.width += 2*offX; res.height += offY; } break; case Alignment.BOTTOM : { res.x -= offX; res.width += 2*offX; res.height += offY; } break; } } return res; } private int getPageAt(int x, int y) { if (tabArea.contains(x, y)) for (int i=0; i<pages.size(); i++) if (getPageBounds(i).contains(x, y)) return i; return -1; } private int next (int page, int d) { for (;page>=0 && page < pages.size(); page+=d) if (isPageEnabled(page)) return page; return -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -