aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/gui/customcontrols/SIPCommToolBar.java
blob: 1968a57e5e07608052e79d51dd92caefcc8f501d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
package net.java.sip.communicator.impl.gui.customcontrols;

import java.awt.*;
import java.awt.image.*;

import javax.swing.*;

import net.java.sip.communicator.impl.gui.lookandfeel.*;
import net.java.sip.communicator.impl.gui.utils.*;

/**
 * The SIPCommToolBar is a <tt>JToolBar</tt>, which has its own drag icon
 * and separator. The drag icon is shown in the beginning of the toolbar,
 * before any of the containing toolbar buttons. It allows to drag the toolbar
 * out of the container, where it is added and show it in a separate window.
 * The separator is a line that could be added between two buttons. This way
 * the developer could visually group buttons with similar functionality.
 *
 * @author Yana Stamcheva
 */
public class SIPCommToolBar
    extends JToolBar
{
    private static final long serialVersionUID = 0L;

    /**
     * Creates an instance of <tt>SIPCommToolBar</tt>.
     */
    public SIPCommToolBar() {
        this.add(Box.createRigidArea(new Dimension(4, 4)));
    }

    /**
     * Adds a separator to this toolbar. The separator is added after
     * the last component in the toolbar.
     */
    public void addSeparator() {
        JToolBar.Separator s = new JToolBar.Separator(new Dimension(8, 22));
        s.setUI(new SIPCommToolBarSeparatorUI());

        if (getOrientation() == VERTICAL) {
            s.setOrientation(JSeparator.HORIZONTAL);
        } else {
            s.setOrientation(JSeparator.VERTICAL);
        }

        add(s);
    }

    /**
     * Overrides the <code>paintBorder</code> method of <tt>JToolBar</tt>
     * to paint the drag icon in the beginning of the toolbar.
     */
    protected void paintBorder(Graphics g) {

        Graphics2D g2 = (Graphics2D) g;

        BufferedImage dragImage = ImageLoader
                .getImage(ImageLoader.TOOLBAR_DRAG_ICON);

        g2.drawImage(dragImage, 0, (this.getHeight() - dragImage
                .getHeight(null)) / 2 - 2, null);
    }
}