📄 titledtab.java
字号:
alignment == Alignment.LEFT ?
JLabel.LEFT : alignment == Alignment.CENTER ? JLabel.CENTER : JLabel.RIGHT);
}
if (keySet.contains(TitledTabStateProperties.VERTICAL_ALIGNMENT)) {
Alignment alignment = (Alignment) ((ValueChange) m.get(TitledTabStateProperties.VERTICAL_ALIGNMENT)).getNewValue();
label.setVerticalAlignment(
alignment == Alignment.TOP ?
JLabel.TOP : alignment == Alignment.CENTER ? JLabel.CENTER : JLabel.BOTTOM);
}
if (keySet.contains(TitledTabStateProperties.TOOL_TIP_TEXT) || keySet.contains(
TitledTabStateProperties.TOOL_TIP_ENABLED)) {
toolTipText = stateProperties.getToolTipEnabled() ? stateProperties.getToolTipText() : null;
if (toolTipText != null && toolTipText.length() == 0)
toolTipText = null;
if (currentStatePanel == this)
eventPanel.setToolTipText(toolTipText);
}
if (keySet.contains(TitledTabStateProperties.DIRECTION) || keySet.contains(
TitledTabStateProperties.TITLE_COMPONENT_TEXT_RELATIVE_ALIGNMENT)
|| keySet.contains(TitledTabStateProperties.TITLE_COMPONENT_VISIBLE) || keySet.contains(
TitledTabStateProperties.TEXT_TITLE_COMPONENT_GAP)
|| keySet.contains(TitledTabStateProperties.ICON_VISIBLE) || keySet.contains(
TitledTabStateProperties.TEXT_VISIBLE)) {
label.setDirection(stateProperties.getDirection());
updateLayout(stateProperties, keySet.contains(TitledTabStateProperties.TITLE_COMPONENT_VISIBLE));
}
if (keySet.contains(TitledTabStateProperties.DIRECTION)) {
updateBorders = true;
}
}
m = (Map) changes.get(stateProperties.getComponentProperties().getMap());
if (m != null) {
Set keySet = m.keySet();
if (keySet.contains(ComponentProperties.FONT)) {
label.setFont((Font) ((ValueChange) m.get(ComponentProperties.FONT)).getNewValue());
}
if (keySet.contains(ComponentProperties.FOREGROUND_COLOR)) {
Color c = (Color) ((ValueChange) m.get(ComponentProperties.FOREGROUND_COLOR)).getNewValue();
label.setForeground(c);
setForeground(c);
}
if (keySet.contains(ComponentProperties.BACKGROUND_COLOR)) {
Color c = (Color) ((ValueChange) m.get(ComponentProperties.BACKGROUND_COLOR)).getNewValue();
panel.setBackground(c);
}
if (keySet.contains(ComponentProperties.INSETS) || keySet.contains(ComponentProperties.BORDER)) {
updateBorders = true;
}
}
m = (Map) changes.get(stateProperties.getShapedPanelProperties().getMap());
if (m != null) {
updateShapedPanel(stateProperties);
}
}
return updateBorders;
}
}
private TitledTabProperties properties = TitledTabProperties.getDefaultProperties();
private HoverListener hoverListener = properties.getHoverListener();
private class HoverablePanel extends SimplePanel implements Hoverable {
public HoverablePanel(LayoutManager l) {
super(l);
}
public void hoverEnter() {
if (hoverListener != null && getTabbedPanel() != null)
hoverListener.mouseEntered(new HoverEvent(TitledTab.this));
}
public void hoverExit() {
if (hoverListener != null)
hoverListener.mouseExited(new HoverEvent(TitledTab.this));
}
public boolean acceptHover(ArrayList enterableHoverables) {
return true;
}
}
private HoverablePanel eventPanel = new HoverablePanel(new BorderLayout()) {
public boolean contains(int x, int y) {
return getComponentCount() > 0 && getComponent(0).contains(x, y);
}
public boolean inside(int x, int y) {
return getComponentCount() > 0 && getComponent(0).inside(x, y);
}
};
public boolean contains(int x, int y) {
Point p = SwingUtilities.convertPoint(this, new Point(x, y), eventPanel);
return eventPanel.contains(p.x, p.y);
}
public boolean inside(int x, int y) {
Point p = SwingUtilities.convertPoint(this, new Point(x, y), eventPanel);
return eventPanel.inside(p.x, p.y);
}
private StatePanel normalStatePanel;
private StatePanel highlightedStatePanel;
private StatePanel disabledStatePanel;
private ArrayList mouseListeners;
private ArrayList mouseMotionListeners;
private StackableLayout layout;
private StatePanel currentStatePanel;
private FocusBorder focusBorder;
private Direction lastTabAreaOrientation = Direction.UP;
private PropertyMapTreeListener propertiesListener = new PropertyMapTreeListener() {
public void propertyValuesChanged(Map changes) {
doUpdateTab(changes);
}
};
private PropertyChangeListener tabbedPanelPropertiesListener = new PropertyChangeListener() {
public void propertyChanged(Property property, Object valueContainer, Object oldValue, Object newValue) {
updateTabAreaOrientation((Direction) newValue);
}
};
private FocusListener focusListener = new FocusListener() {
public void focusGained(FocusEvent e) {
if (properties.getFocusable())
repaint();
}
public void focusLost(FocusEvent e) {
if (properties.getFocusable())
repaint();
}
};
/**
* Constructs a TitledTab with a text, icon, content component and title component.
*
* @param text text or null for no text. The text will be applied to the
* normal state properties
* @param icon icon or null for no icon. The icon will be applied to the
* normal state properties
* @param contentComponent content component or null for no content component
* @param titleComponent title component or null for no title component. The title
* component will be applied to all the states
* @see net.infonode.tabbedpanel.TabFactory
*/
public TitledTab(String text, Icon icon, JComponent contentComponent, JComponent titleComponent) {
super(contentComponent);
super.setOpaque(false);
addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
repaint();
}
public void focusLost(FocusEvent e) {
repaint();
}
});
focusBorder = new FocusBorder(this);
normalStatePanel = new StatePanel(focusBorder);
highlightedStatePanel = new StatePanel(focusBorder);
disabledStatePanel = new StatePanel(focusBorder);
layout = new StackableLayout(this) {
public void layoutContainer(Container parent) {
super.layoutContainer(parent);
StatePanel visibleStatePanel = (StatePanel) getVisibleComponent();
visibleStatePanel.activateTitleComponent();
}
};
setLayout(layout);
add(normalStatePanel);
add(highlightedStatePanel);
add(disabledStatePanel);
setText(text);
setIcon(icon);
setTitleComponent(titleComponent);
eventPanel.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
updateFocus(TabSelectTrigger.MOUSE_PRESS);
}
public void mouseReleased(MouseEvent e) {
updateFocus(TabSelectTrigger.MOUSE_RELEASE);
}
private void updateFocus(TabSelectTrigger trigger) {
if (isEnabled() && properties.getFocusable() && getTabbedPanel() != null && getTabbedPanel().getProperties()
.getTabSelectTrigger() == trigger) {
Component focusedComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusedComponent instanceof TitledTab
&& ((TitledTab) focusedComponent).getTabbedPanel() == getTabbedPanel())
requestFocusInWindow();
else if (isSelected() || TabbedUtils.getParentTabbedPanel(focusedComponent) != getTabbedPanel())
requestFocusInWindow();
}
}
});
setEventComponent(eventPanel);
MouseListener mouseListener = new MouseListener() {
public void mouseClicked(MouseEvent e) {
if (mouseListeners != null) {
MouseEvent event = convertMouseEvent(e);
Object[] l = mouseListeners.toArray();
for (int i = 0; i < l.length; i++)
((MouseListener) l[i]).mouseClicked(event);
}
}
public void mousePressed(MouseEvent e) {
if (mouseListeners != null) {
MouseEvent event = convertMouseEvent(e);
Object[] l = mouseListeners.toArray();
for (int i = 0; i < l.length; i++)
((MouseListener) l[i]).mousePressed(event);
}
}
public void mouseReleased(MouseEvent e) {
if (mouseListeners != null) {
MouseEvent event = convertMouseEvent(e);
Object[] l = mouseListeners.toArray();
for (int i = 0; i < l.length; i++)
((MouseListener) l[i]).mouseReleased(event);
}
}
public void mouseEntered(MouseEvent e) {
if (mouseListeners != null) {
MouseEvent event = convertMouseEvent(e);
Object[] l = mouseListeners.toArray();
for (int i = 0; i < l.length; i++)
((MouseListener) l[i]).mouseEntered(event);
}
}
public void mouseExited(MouseEvent e) {
if (mouseListeners != null) {
MouseEvent event = convertMouseEvent(e);
Object[] l = mouseListeners.toArray();
for (int i = 0; i < l.length; i++)
((MouseListener) l[i]).mouseExited(event);
}
}
};
MouseMotionListener mouseMotionListener = new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {
if (mouseMotionListeners != null) {
MouseEvent event = convertMouseEvent(e);
Object[] l = mouseMotionListeners.toArray();
for (int i = 0; i < l.length; i++)
((MouseMotionListener) l[i]).mouseDragged(event);
}
}
public void mouseMoved(MouseEvent e) {
if (mouseMotionListeners != null) {
MouseEvent event = convertMouseEvent(e);
Object[] l = mouseMotionListeners.toArray();
for (int i = 0; i < l.length; i++)
((MouseMotionListener) l[i]).mouseMoved(event);
}
}
};
eventPanel.addMouseListener(mouseListener);
eventPanel.addMouseMotionListener(mouseMotionListener);
PropertyMapWeakListenerManager.addWeakTreeListener(properties.getMap(), propertiesListener);
addTabListener(new TabAdapter() {
public void tabAdded(TabEvent event) {
PropertyMapWeakListenerManager.addWeakPropertyChangeListener(getTabbedPanel().getProperties().getMap(),
TabbedPanelProperties.TAB_AREA_ORIENTATION,
tabbedPanelPropertiesListener);
updateTabAreaOrientation(getTabbedPanel().getProperties().getTabAreaOrientation());
}
public void tabRemoved(TabRemovedEvent event) {
PropertyMapWeakListenerManager.removeWeakPropertyChangeListener(
event.getTabbedPanel().getProperties().getMap(),
TabbedPanelProperties.TAB_AREA_ORIENTATION,
tabbedPanelPropertiesListener);
}
});
doUpdateTab(null);
updateCurrentStatePanel();
}
/**
* Gets the title component for the normal state
*
* @return title component or null if no title component
*/
public JComponent getNormalStateTitleComponent() {
return normalStatePanel.getTitleComponent();
}
/**
* Gets the title component for the highlighted state
*
* @return title component or null if no title component
*/
public JComponent getHighlightedStateTitleComponent() {
return highlightedStatePanel.getTitleComponent();
}
/**
* Gets the title component for the disabled state
*
* @return title component or null if no title component
*/
public JComponent getDisabledStateTitleComponent() {
return disabledStatePanel.getTitleComponent();
}
/**
* <p>Sets the title component.</p>
*
* <p>This method is a convenience method for setting the same title component for
* all states.</p>
*
* @param titleComponent the title component or null for no title component
*/
public void setTitleComponent(JComponent titleComponent) {
normalStatePanel.setTitleComponent(titleComponent, properties.getNormalProperties());
highlightedStatePanel.setTitleComponent(titleComponent, properties.getHighlightedProperties());
disabledStatePanel.setTitleComponent(titleComponent, properties.getDisabledProperties());
}
/**
* Sets the normal state title component
*
* @param titleComponent the title component or null for no title component
*/
public void setNormalStateTitleComponent(JComponent titleComponent) {
normalStatePanel.setTitleComponent(titleComponent, properties.getNormalProperties());
}
/**
* Sets the highlighted state title component
*
* @param titleComponent the title component or null for no title component
*/
public void setHighlightedStateTitleComponent(JComponent titleComponent) {
highlightedStatePanel.setTitleComponent(titleComponent, properties.getHighlightedProperties());
}
/**
* Sets the disabled state title component
*
* @param titleComponent the title component or null for no title component
*/
public void setDisabledStateTitleComponent(JComponent titleComponent) {
disabledStatePanel.setTitleComponent(titleComponent, properties.getDisabledProperties());
}
/**
* <p>Sets if this TitledTab should be highlighted or not.</p>
*
* <p><strong>Note:</strong> This will only have effect if this TitledTab
* is enabled and a member of a tabbed panel.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -