📄 zbookview.java
字号:
/*
* Copyright 2002 EZCell , Inc. All rights reserved.
* Version 1.0.
* Author W.John
*/
package ezcell;
import javax.swing.text.JTextComponent;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import javax.swing.JComponent;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
/**
* Used to hold all sheets of a book except page header and footer
*
*/
public class ZBookView extends JTabbedPane implements ZBookStateListener {
/**
* The value is set in constructor, it keeps alive with me,
*/
private ZBookState bookState;
/**
* To listen to title change of any sheet ,If change occurs, change that tab's title contains the sheet,
* An instance be created in constructor. When setBookState or sheetAdded, hook this listener to them.
*/
ZSheetStateListener listener;
/**
* put your documentation comment here
* @param ZBookState bookState
*/
public ZBookView(ZBookState bookState) {
listener = new ZSheetStateAdapter() {
/**
* listen to whether any sheet title been changed, in that case , change tabs's title as well
* @param sheetState ,indicates where the change from
*/
public void sheetPropertyChanged(ZSheetState sheetState) {
int i = indexOfComponent(getComponent(sheetState));
if (sheetState.getSheet().getTitle().equals(getTitleAt(i))) {
return;
}
setTitleAt(i, sheetState.getSheet().getTitle());
}
};
setTabPlacement(JTabbedPane.BOTTOM);
bookState.addListener(this);
setBookState(bookState);
this.addComponentListener(new ComponentAdapter() {
/**
* put your documentation comment here
* @param componentEvent
*/
public void componentShown(ComponentEvent componentEvent) {
fireStateChanged();
}
});
this.addFocusListener(new FocusAdapter() {
/**
* put your documentation comment here
* @param e
*/
public void focusGained(FocusEvent e) {
((JComponent) getSelectedComponent()).requestFocus();
}
});
}
/**
* Query the sheetState in the selected tab . if tabs is empty, return null
* @return
*/
public ZSheetState getActiveSheetState() {
ZSheetView view = (ZSheetView) getSelectedComponent();
if (view == null) {
return null;
}
return view.getSheetState();
}
/**
* find a tab by a ZSheetState
* @param sheetState
* @return
*/
public ZSheetView getComponent(ZSheetState sheetState) {
for (int i = 0; i < this.getComponentCount(); i++)
if (((ZSheetView) getComponent(i)).getSheetState() == sheetState) {
return (ZSheetView) getComponent(i);
}
return null;
}
/**
* Make any tab's scroll bars visible or invisible.
* @param visible
*/
public void setScrollbarVisible(boolean visible) {
for (int i = 0; i < this.getComponentCount(); i++) {
ZSheetView view = (ZSheetView) this.getComponent(i);
view.setScrollbarVisible(visible);
}
}
/**
* put your documentation comment here
* @param e
*/
public void activeCellChanged(ChangeEvent e) {
}
/**
* put your documentation comment here
* @param e
*/
public void activeChanged(ChangeEvent e) {
ZBookState bookState = (ZBookState) e.getSource();
ZSheetView view = (ZSheetView) getSelectedComponent();
if (view == null) {
return;
}
ZSheetState sheetState = view.getSheetState();
if (bookState.getActive() == sheetState) {
return;
}
view = getComponent(bookState.getActive());
if (view != null) {
setSelectedComponent(view);
}
}
/**
* put your documentation comment here
* @param e
*/
public void bookChanged(ChangeEvent e) {
setBookState((ZBookState) e.getSource());
}
/**
* put your documentation comment here
* @param e
*/
public void footerAdded(ChangeEvent e) {
}
/**
* put your documentation comment here
* @param e
*/
public void footerRemoved(ChangeEvent e) {
}
/**
* put your documentation comment here
* @param e
*/
public void headerAdded(ChangeEvent e) {
}
/**
* put your documentation comment here
* @param e
*/
public void headerRemoved(ChangeEvent e) {
}
/**
* put your documentation comment here
* @param e
*/
public void pageFormatChanged(ChangeEvent e) {
}
/**
* put your documentation comment here
* @param e
* @param sheetState
*/
public void sheetAdded(ChangeEvent e, ZSheetState sheetState) {
ZSheetView view = new ZSheetView(sheetState);
add(sheetState.getSheet().getTitle(), view);
sheetState.addListener(listener);
}
/**
* put your documentation comment here
* @param e
* @param sheetState
*/
public void sheetRemoved(ChangeEvent e, ZSheetState sheetState) {
remove(indexOfComponent(getComponent(sheetState)));
}
/**
* put your documentation comment here
* @param bookState
*/
private void setBookState(ZBookState bookState) {
removeAll();
this.bookState = bookState;
int size = bookState.getCount();
for (int i = 0; i < size; i++) {
ZSheetState sheetState = bookState.getSheetState(i);
sheetState.addListener(listener);
ZSheetView view = new ZSheetView(sheetState);
add(sheetState.getSheet().getTitle(), view);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -