package com.drawbridge.utils;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.SwingUtilities;
import com.drawbridge.vl.BlockWrapper;
public class Palette extends JPanel
{
private static final long serialVersionUID = -6150156093785960443L;
public JTabbedPane mTabbedPane;
public Palette() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run()
{
setLayout(new BorderLayout());
mTabbedPane = new JTabbedPane();
mTabbedPane.setTabPlacement(JTabbedPane.TOP);
mTabbedPane.setTabLayoutPolicy(JTabbedPane.WRAP_TAB_LAYOUT);
mTabbedPane.setBackground(Color.white);
add(mTabbedPane, BorderLayout.CENTER);
}
});
}
public void addPaletteTab(final String name, final JComponent[] components)
{
for (int i = 0; i < mTabbedPane.getTabCount(); i++)
{
if (mTabbedPane.getTitleAt(i).equals(name))
{
throw new RuntimeException("Could not add tab because of duplicate names!");
}
}
JPanel mInternalJPanel = new JPanel();
GridBagLayout gbLayout = new GridBagLayout();
double[] colWeights = new double[components.length];
for (int i = 0; i < colWeights.length; i++)
{
colWeights[i] = 1;
}
gbLayout.columnWeights = colWeights;
mInternalJPanel.setLayout(gbLayout);
for (int i = 0; i < components.length; i++)
{
BlockWrapper newComponent = new BlockWrapper(components[i], true);
mInternalJPanel.add(newComponent, new GridBagConstraints());
}
JScrollPane mScrollPane = new JScrollPane(mInternalJPanel);
mScrollPane.setBorder(null);
mScrollPane.setOpaque(false);
mScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
mScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
mTabbedPane.addTab(name, null, mScrollPane, "No tips here please!");
mTabbedPane.insertTab(name, null, mScrollPane, "", mTabbedPane.getTabCount());
mTabbedPane.setOpaque(false);
}
}