/* * $Id: StyleBarDemo.java,v 1.4 2003/03/20 05:27:39 zfq Exp $ * * Copyright (C) 2001-2003 Extreme Component, Inc. All rights reserved. * Use is subject to license terms. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import com.zfqjava.swing.JStyleBar; /** * JStyleBar Demo * * @author $Author: zfq $ * @version $Revision: 1.4 $ $Date: 2003/03/20 05:27:39 $ */ public class StyleBarDemo extends JPanel { private JStyleBar styleBar; public StyleBarDemo() { setLayout(new BorderLayout()); add(createCenterPanel(), BorderLayout.CENTER); add(createPropertyPanel(), BorderLayout.EAST); } private JPanel createCenterPanel() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); styleBar = createStyleBar(); panel.add(styleBar, BorderLayout.NORTH); return panel; } private JStyleBar createStyleBar() { JStyleBar styleBar = new JStyleBar(); return styleBar; } private JPanel createPropertyPanel() { JPanel panel = new JPanel(); Border titledBorder = new TitledBorder("Change Property"); Border emptyBorder = new EmptyBorder(12, 12, 12, 12); panel.setBorder(BorderFactory.createCompoundBorder(titledBorder, emptyBorder)); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); panel.setLayout(gridbag); c.weightx = 0.5; c.weighty = 0.5; c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(0, 0, 5, 0); JLabel label = new JLabel("For ContentType: "); addPanel(panel, c, label); Object[] headStyles = { "text/plain", "text/rtf" , "text/html" }; final JComboBox headStyleCB = new JComboBox(headStyles); headStyleCB.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object item = headStyleCB.getSelectedItem(); styleBar.putClientProperty("JStyleBar.forContentType", item); } }); label.setLabelFor(headStyleCB); c.gridwidth = GridBagConstraints.REMAINDER; addPanel(panel, c, headStyleCB); return panel; } private static void addPanel(Container container, GridBagConstraints c, Component component) { GridBagLayout gridbag = (GridBagLayout)container.getLayout(); gridbag.setConstraints(component, c); container.add(component); } public static void main(String[] args) { JFrame f = new JFrame("JStyleBar Demo"); DemoPanel demoPanel = new DemoPanel(); demoPanel.addDemo(new StyleBarDemo()); f.getContentPane().add(demoPanel); f.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE); f.pack(); centerOnScreen(f); f.show(); } public static void centerOnScreen(Window window) { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); window.setLocation((d.width - window.getWidth())/2, (d.height - window.getHeight())/2); } }