Updated SparkTabbedPane to handle tab placement variables from JTabbedPane.

git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@4552 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
Derek DeMoro
2006-07-18 23:51:19 +00:00
committed by derek
parent 8ad69e6952
commit 8f6ac1f416
6 changed files with 81 additions and 43 deletions

View File

@ -114,7 +114,7 @@ public final class MainWindow extends JFrame implements ActionListener {
this.setJMenuBar(mainWindowBar);
this.getContentPane().add(topBar, BorderLayout.NORTH);
setTitle(title);
setTitle(title + " - " + SparkManager.getSessionManager().getUsername());
setIconImage(icon.getImage());

View File

@ -31,6 +31,7 @@ import org.jivesoftware.spark.ui.conferences.Conferences;
import org.jivesoftware.spark.ui.status.StatusBar;
import org.jivesoftware.spark.util.SwingWorker;
import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.spark.component.tabbedPane.SparkTabbedPane;
import org.jivesoftware.sparkimpl.plugin.manager.Enterprise;
import org.jivesoftware.sparkimpl.plugin.transcripts.ChatTranscriptPlugin;
@ -70,7 +71,7 @@ import java.util.TimerTask;
* <li>Retrieve the ContactList.
*/
public class Workspace extends JPanel implements PacketListener {
private JTabbedPane workspacePane;
private SparkTabbedPane workspacePane;
private final StatusBar statusBox = new StatusBar();
private ContactList contactList;
private Conferences conferences;
@ -132,7 +133,7 @@ public class Workspace extends JPanel implements PacketListener {
});
// Initialize workspace pane, defaulting the tabs to the bottom.
workspacePane = new JTabbedPane(JTabbedPane.BOTTOM);
workspacePane = new SparkTabbedPane(JTabbedPane.BOTTOM);
//workspacePane.setBoldActiveTab(true);
//workspacePane.setHideOneTab(true);
@ -391,7 +392,7 @@ public class Workspace extends JPanel implements PacketListener {
*
* @return the workspace JideTabbedPane
*/
public JTabbedPane getWorkspacePane() {
public SparkTabbedPane getWorkspacePane() {
return workspacePane;
}

View File

@ -55,7 +55,7 @@ public class SparkTab extends TabPanel {
add(iconLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 2), 0, 0));
// add text label
add(textLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 2, 3, 2), 0, 0));
add(textLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 2, 3, 5), 0, 0));
// Set fonts
defaultFont = new Font("Dialog", Font.PLAIN, 11);
@ -64,7 +64,7 @@ public class SparkTab extends TabPanel {
public void addComponent(Component component) {
// add Component
add(component, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 2, 3, 2), 0, 0));
add(component, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 0, 3, 2), 0, 0));
}
public void addPop(JComponent comp) {

View File

@ -14,12 +14,6 @@ import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.component.RolloverButton;
import org.jivesoftware.spark.util.ModelUtil;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
@ -41,6 +35,13 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
/**
*
*/
@ -61,12 +62,24 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
private Map<Component, JFrame> framesMap = new HashMap<Component, JFrame>();
private int tabPlacement = JTabbedPane.TOP;
/**
* Listeners
*/
private List<SparkTabbedPaneListener> listeners = new ArrayList<SparkTabbedPaneListener>();
public SparkTabbedPane() {
createUI();
}
public SparkTabbedPane(int placement) {
this.tabPlacement = placement;
createUI();
}
private void createUI() {
setLayout(new BorderLayout());
tabs = new JPanel(new
@ -103,11 +116,18 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
final JPanel topPanel = new JPanel();
topPanel.setLayout(new GridBagLayout());
topPanel.add(tabs, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(5, 0, 0, 0), 0, 0));
topPanel.add(new JLabel(), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 0, 0, 0), 0, 0));
topPanel.add(new JLabel(), new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
topPanel.setOpaque(false);
// Add Tabs panel to top of panel.
if (tabPlacement == JTabbedPane.TOP) {
topPanel.add(tabs, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 0, 0), 0, 0));
add(topPanel, BorderLayout.NORTH);
}
else {
topPanel.add(tabs, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 2, 0), 0, 0));
add(topPanel, BorderLayout.SOUTH);
}
// Create mainPanel
mainPanel = new JPanel(new CardLayout());
@ -119,7 +139,7 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
closeInactiveButtonIcon = SparkRes.getImageIcon(SparkRes.CLOSE_WHITE_X_IMAGE);
closeActiveButtonIcon = SparkRes.getImageIcon(SparkRes.CLOSE_DARK_X_IMAGE);
setBackground(Color.white);
setOpaque(false);
tabs.setOpaque(false);
}
@ -132,6 +152,7 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
public SparkTab addTab(String text, Icon icon, final Component component) {
final SparkTab tab = new SparkTab(icon, text);
tab.setTabPlacement(tabPlacement);
//tabs.add(tab, new GridBagConstraints(tabs.getComponentCount(), 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 0, 0, 0), 0, 0));
tabs.add(tab);
@ -506,7 +527,7 @@ public class SparkTabbedPane extends JPanel implements MouseListener {
public static void main(String args[]) {
JFrame f = new JFrame();
SparkTabbedPane pane = new SparkTabbedPane();
SparkTabbedPane pane = new SparkTabbedPane(JTabbedPane.BOTTOM);
pane.setCloseButtonEnabled(true);
pane.setPopupAllowed(true);
for (int i = 0; i < 3; i++) {

View File

@ -15,12 +15,6 @@ import org.jivesoftware.Spark;
import org.jivesoftware.resource.Default;
import org.jivesoftware.spark.util.log.Log;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicPanelUI;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
@ -31,9 +25,20 @@ import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.util.StringTokenizer;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicPanelUI;
/**
* Represents a single instance of a Tab Paint Component.
*
* @author Derek DeMoro
*/
public class TabPanelUI extends BasicPanelUI {
private Color backgroundColor1 = Color.white;//new Color(235, 247, 223);
private Color backgroundColor2 = Color.white;//new Color(214, 219, 191);
private Color backgroundColor1 = new Color(0,0,0,0);
private Color backgroundColor2 = new Color(0,0,0,0);
private Color borderColor = new Color(86, 88, 72);
private Color borderColorAlpha1 = new Color(86, 88, 72, 100);
@ -59,8 +64,8 @@ public class TabPanelUI extends BasicPanelUI {
backgroundColor2 = getSelectedEndColor();
}
else {
backgroundColor1 = Color.white;
backgroundColor2 = Color.white;
backgroundColor1 = new Color(0, 0, 0, 0);
backgroundColor2 = new Color(0, 0, 0, 0);
}
this.selected = selected;
@ -83,6 +88,7 @@ public class TabPanelUI extends BasicPanelUI {
int y = vInsets.top;
int arc = 8;
Shape vButtonShape = new RoundRectangle2D.Double((double)x, (double)y, (double)w, (double)h, (double)arc, (double)arc);
Shape vOldClip = g.getClip();
@ -96,6 +102,8 @@ public class TabPanelUI extends BasicPanelUI {
GradientPaint vPaint = new GradientPaint(x, y, borderColor, x, y + h, borderHighlight);
g2d.setPaint(vPaint);
// Handle custom actions.
if (placement == JTabbedPane.TOP) {
if (selected) {
g2d.setColor(Color.lightGray);
g2d.drawRoundRect(x, y, w, h, arc, arc);
@ -107,11 +115,15 @@ public class TabPanelUI extends BasicPanelUI {
g2d.setClip(vOldClip);
g2d.setColor(borderColorAlpha2);
if (placement == JTabbedPane.TOP) {
g2d.setColor(backgroundColor2);
g2d.fillRect(x, h - 5, w, h);
}
else {
// Make straight line.
g2d.setColor(backgroundColor2);
g2d.fillRect(x, y, w, 4);
}
if (selected) {
@ -121,7 +133,6 @@ public class TabPanelUI extends BasicPanelUI {
g2d.setColor(Color.lightGray);
g2d.drawLine(w - 1, 4, w - 1, h - 4);
}
}
@ -176,7 +187,7 @@ public class TabPanelUI extends BasicPanelUI {
return color;
}
public void setPlacement(int placement){
public void setPlacement(int placement) {
this.placement = placement;
}
}

View File

@ -64,7 +64,9 @@ import java.util.List;
import java.util.Map;
/**
* Should be subclassed to track all available ChatRooms.
* Contains all <code>ChatRoom</code> objects within Spark.
*
* @author Derek DeMoro
*/
public class ChatContainer extends SparkTabbedPane implements MessageListener, ChangeListener {
/**
@ -113,6 +115,9 @@ public class ChatContainer extends SparkTabbedPane implements MessageListener, C
addKeyNavigation();
this.setFocusable(false);
setOpaque(true);
setBackground(Color.white);
}
/**