?? basicoutlookbarui.java
字號:
TabButton button = (TabButton)tabToButton.get(removedTab);
tabPane.remove(button);
buttonToTab.remove(button);
tabToButton.remove(removedTab);
}
/**
* Called whenever a property of a tab is changed
*
* @param index
*/
protected void updateTabButtonAt(int index) {
TabButton button = buttonForTab(index);
button.setText(tabPane.getTitleAt(index));
button.setIcon(tabPane.getIconAt(index));
button.setDisabledIcon(tabPane.getDisabledIconAt(index));
Color background = tabPane.getBackgroundAt(index);
if (background == null) {
background = (Color)button.getClientProperty(BUTTON_ORIGINAL_BACKGROUND);
}
button.setBackground(background);
Color foreground = tabPane.getForegroundAt(index);
if (foreground == null) {
foreground = (Color)button.getClientProperty(BUTTON_ORIGINAL_FOREGROUND);
}
button.setForeground(foreground);
button.setToolTipText(tabPane.getToolTipTextAt(index));
button
.setDisplayedMnemonicIndex(tabPane.getDisplayedMnemonicIndexAt(index));
button.setMnemonic(tabPane.getMnemonicAt(index));
button.setEnabled(tabPane.isEnabledAt(index));
button.setHorizontalAlignment(((JOutlookBar)tabPane).getAlignmentAt(index));
}
protected TabButton buttonForTab(int index) {
Component component = tabPane.getComponentAt(index);
return (TabButton)tabToButton.get(component);
}
class PropertyChangeHandler implements PropertyChangeListener {
public void propertyChange(PropertyChangeEvent e) {
//JTabbedPane pane = (JTabbedPane)e.getSource();
String name = e.getPropertyName();
if ("tabPropertyChangedAtIndex".equals(name)) {
int index = ((Integer)e.getNewValue()).intValue();
updateTabButtonAt(index);
} else if ("tabPlacement".equals(name)) {
updateTabLayoutOrientation();
}
}
}
protected void updateTabLayoutOrientation() {
TabLayout layout = (TabLayout)tabPane.getLayout();
int placement = tabPane.getTabPlacement();
if (placement == JTabbedPane.TOP || placement == JTabbedPane.BOTTOM) {
layout.setOrientation(PercentLayout.HORIZONTAL);
} else {
layout.setOrientation(PercentLayout.VERTICAL);
}
}
/**
* Manages tabs being added or removed
*/
class ContainerTabHandler extends ContainerAdapter {
public void componentAdded(ContainerEvent e) {
if (!(e.getChild() instanceof UIResource)) {
Component newTab = e.getChild();
tabAdded(newTab);
}
}
public void componentRemoved(ContainerEvent e) {
if (!(e.getChild() instanceof UIResource)) {
Component oldTab = e.getChild();
tabRemoved(oldTab);
}
}
}
/**
* Layout for the tabs, buttons get preferred size, tabs get all
*/
protected class TabLayout extends PercentLayout {
public void addLayoutComponent(Component component, Object constraints) {
if (constraints == null) {
if (component instanceof TabButton) {
super.addLayoutComponent(component, "");
} else {
super.addLayoutComponent(component, "100%");
}
} else {
super.addLayoutComponent(component, constraints);
}
}
public void setLayoutConstraints(Container parent) {
Component[] components = parent.getComponents();
for (int i = 0, c = components.length; i < c; i++) {
if (!(components[i] instanceof TabButton)) {
super.addLayoutComponent(components[i], "100%");
}
}
}
public void layoutContainer(Container parent) {
int selectedIndex = tabPane.getSelectedIndex();
Component visibleComponent = getVisibleComponent();
if (selectedIndex < 0) {
if (visibleComponent != null) {
// The last tab was removed, so remove the component
setVisibleComponent(null);
}
} else {
Component selectedComponent = tabPane.getComponentAt(selectedIndex);
boolean shouldChangeFocus = false;
// In order to allow programs to use a single component
// as the display for multiple tabs, we will not change
// the visible compnent if the currently selected tab
// has a null component. This is a bit dicey, as we don't
// explicitly state we support this in the spec, but since
// programs are now depending on this, we're making it work.
//
if (selectedComponent != null) {
if (selectedComponent != visibleComponent && visibleComponent != null) {
// get the current focus owner
Component currentFocusOwner = KeyboardFocusManager
.getCurrentKeyboardFocusManager().getFocusOwner();
// check if currentFocusOwner is a descendant of visibleComponent
if (currentFocusOwner != null
&& SwingUtilities.isDescendingFrom(currentFocusOwner,
visibleComponent)) {
shouldChangeFocus = true;
}
}
setVisibleComponent(selectedComponent);
// make sure only the selected component is visible
Component[] components = parent.getComponents();
for (int i = 0; i < components.length; i++) {
if (!(components[i] instanceof UIResource)
&& components[i].isVisible()
&& components[i] != selectedComponent) {
components[i].setVisible(false);
setConstraint(components[i], "*");
}
}
if (BasicOutlookBarUI.this.nextVisibleComponent != null) {
BasicOutlookBarUI.this.nextVisibleComponent.setVisible(true);
}
}
super.layoutContainer(parent);
if (shouldChangeFocus) {
if (!requestFocusForVisibleComponent0()) {
tabPane.requestFocus();
}
}
}
}
}
// PENDING(fred) JDK 1.5 may have this method from superclass
protected boolean requestFocusForVisibleComponent0() {
Component visibleComponent = getVisibleComponent();
if (visibleComponent.isFocusable()) {
visibleComponent.requestFocus();
return true;
} else if (visibleComponent instanceof JComponent) {
if (((JComponent)visibleComponent).requestDefaultFocus()) { return true; }
}
return false;
}
protected static class TabButton extends JButton implements UIResource {
public TabButton() {}
public TabButton(ButtonUI ui) {
setUI(ui);
}
}
//
//
//
/**
* Overriden to return an empty adapter, the default listener was
* just implementing the tab selection mechanism
*/
protected MouseListener createMouseListener() {
return new MouseAdapter() {};
}
/**
* Wraps any component in a Scrollable JPanel so it can work
* correctly within a viewport
*/
private static class ScrollableJPanel extends JPanel implements Scrollable {
public ScrollableJPanel(Component component) {
setLayout(new BorderLayout(0, 0));
add("Center", component);
setOpaque(false);
}
public int getScrollableUnitIncrement(Rectangle visibleRect,
int orientation, int direction) {
return 16;
}
public Dimension getPreferredScrollableViewportSize() {
return (super.getPreferredSize());
}
public int getScrollableBlockIncrement(Rectangle visibleRect,
int orientation, int direction) {
return 16;
}
public boolean getScrollableTracksViewportWidth() {
return true;
}
public boolean getScrollableTracksViewportHeight() {
return false;
}
}
//
// Override all paint methods of the BasicTabbedPaneUI to do nothing
//
public void paint(Graphics g, JComponent c) {}
protected void paintContentBorder(Graphics g, int tabPlacement,
int selectedIndex) {}
protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {}
protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {}
protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {}
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
int selectedIndex, int x, int y, int w, int h) {}
protected void paintFocusIndicator(Graphics g, int tabPlacement,
Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect,
boolean isSelected) {}
protected void paintIcon(Graphics g, int tabPlacement, int tabIndex,
Icon icon, Rectangle iconRect, boolean isSelected) {}
protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects,
int tabIndex, Rectangle iconRect, Rectangle textRect) {}
protected void paintTabArea(Graphics g, int tabPlacement, int selectedIndex) {}
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex,
int x, int y, int w, int h, boolean isSelected) {}
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex,
int x, int y, int w, int h, boolean isSelected) {}
protected void paintText(Graphics g, int tabPlacement, Font font,
FontMetrics metrics, int tabIndex, String title, Rectangle textRect,
boolean isSelected) {}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -