001: package org.columba.core.gui.search;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Color;
005: import java.awt.Component;
006: import java.awt.Graphics;
007: import java.awt.Insets;
008:
009: import javax.swing.Action;
010: import javax.swing.BorderFactory;
011: import javax.swing.JLabel;
012: import javax.swing.JPanel;
013: import javax.swing.UIManager;
014: import javax.swing.border.Border;
015: import javax.swing.border.CompoundBorder;
016:
017: import org.columba.core.gui.frame.api.IComponentBox;
018: import org.jdesktop.swingx.JXCollapsiblePane;
019: import org.jdesktop.swingx.JXHyperlink;
020:
021: public class ComponentBoxContainer extends JPanel {
022:
023: private final static Color borderColor2 = UIManager
024: .getColor("controlShadow");
025: private final static Color borderColor1 = UIManager
026: .getColor("controlHighlight");
027:
028: private JXHyperlink link;
029:
030: private JXCollapsiblePane collapsible;
031:
032: private IComponentBox compBox;
033:
034: public ComponentBoxContainer(IComponentBox compBox) {
035: this .compBox = compBox;
036:
037: collapsible = new JXCollapsiblePane();
038: collapsible.add(compBox.getView());
039: collapsible.setCollapsed(true);
040:
041: Action toggleAction = collapsible.getActionMap().get(
042: JXCollapsiblePane.TOGGLE_ACTION);
043: // use the collapse/expand icons from the JTree UI
044: toggleAction.putValue(JXCollapsiblePane.COLLAPSE_ICON,
045: UIManager.getIcon("Tree.expandedIcon"));
046: toggleAction.putValue(JXCollapsiblePane.EXPAND_ICON, UIManager
047: .getIcon("Tree.collapsedIcon"));
048: link = new JXHyperlink(toggleAction);
049:
050: link.setText(compBox.getName());
051: link.setToolTipText(compBox.getDescription());
052:
053: link.setOpaque(true);
054: link.setFocusPainted(false);
055:
056: link.setUnclickedColor(UIManager.getColor("Label.foreground"));
057: link.setClickedColor(UIManager.getColor("Label.foreground"));
058:
059: Border border1 = new CompoundBorder(new SeparatorBorder(),
060: BorderFactory.createEmptyBorder(2, 4, 2, 4));
061:
062: // Border border = new CompoundBorder(BorderFactory.createEmptyBorder(2,
063: // 4, 2, 4), border1);
064:
065: JLabel iconLabel = new JLabel();
066: iconLabel.setIcon(compBox.getIcon());
067: //iconLabel.setOpaque(true);
068: iconLabel
069: .setBorder(BorderFactory.createEmptyBorder(1, 2, 1, 6));
070:
071: JPanel top = new JPanel();
072: top.setBorder(border1);
073: top.setLayout(new BorderLayout());
074: //top.setOpaque(true);
075:
076: top.add(iconLabel, BorderLayout.WEST);
077: top.add(link, BorderLayout.CENTER);
078:
079: setLayout(new BorderLayout());
080:
081: add(top, BorderLayout.NORTH);
082: add(collapsible, BorderLayout.CENTER);
083: }
084:
085: /**
086: * The border between the stack components. It separates each component with
087: * a fine line border.
088: */
089: class SeparatorBorder implements Border {
090:
091: boolean isFirst(Component c) {
092: return c.getParent() == null
093: || c.getParent().getComponent(0) == c;
094: }
095:
096: public Insets getBorderInsets(Component c) {
097: // if the collapsible is collapsed, we do not want its border to be
098: // painted.
099: if (c instanceof JXCollapsiblePane) {
100: if (((JXCollapsiblePane) c).isCollapsed()) {
101: return new Insets(0, 0, 0, 0);
102: }
103: }
104: return new Insets(isFirst(c) ? 4 : 1, 0, 1, 0);
105: }
106:
107: public boolean isBorderOpaque() {
108: return true;
109: }
110:
111: public void paintBorder(Component c, Graphics g, int x, int y,
112: int width, int height) {
113: g.setColor(borderColor1);
114: if (isFirst(c)) {
115: g.drawLine(x, y + 2, x + width, y + 2);
116: }
117: // g.setColor(borderColor2);
118: // g.drawLine(x, y + height - 1, x + width, y + height - 1);
119: }
120: }
121: }
|