View Javadoc
1 /*** 2 * $Header: /cvsroot/ebxmlrr/jaxr/src/com/sun/xml/registry/client/browser/CardManagerPanel.java,v 1.3 2003/08/25 03:03:01 farrukh_najmi Exp $ 3 * 4 * 5 */ 6 package com.sun.xml.registry.client.browser; 7 8 import java.awt.*; 9 import java.awt.event.*; 10 import java.net.*; 11 import java.io.*; 12 import java.util.*; 13 import java.beans.*; 14 import javax.swing.*; 15 import javax.xml.registry.*; 16 import javax.xml.registry.infomodel.*; 17 18 import com.sun.xml.registry.client.browser.conf.bindings.*; 19 import com.sun.xml.registry.client.browser.conf.bindings.types.*; 20 //import org.oasis.ebxml.registry.bindings.rim.*; 21 22 /*** 23 * A panel that serves as a manager for a card panel. 24 * It provides toggle buttons to control which card in card panel is showing. 25 * 26 * @author <a href="mailto:Farrukh.Najmi@Sun.COM">Farrukh S. Najmi</a> 27 */ 28 public class CardManagerPanel extends JBPanel { 29 30 private GridBagConstraints c = new GridBagConstraints(); 31 private CardLayout cardLayout = null; 32 33 protected JPanel selectorPanel = null; 34 protected JPanel cardsPanel = null; 35 protected String[] cards = null; 36 protected JPanel[] cardPanels = null; 37 38 ButtonGroup buttonGroup = null; 39 HashMap cardToButtonMap = new HashMap(); 40 41 protected CardManagerPanel() { 42 } 43 44 public CardManagerPanel(String[] cards, JPanel[] cardPanels) { 45 super(); 46 47 this.cards = cards; 48 this.cardPanels = cardPanels; 49 50 GridBagLayout gbl = new GridBagLayout(); 51 setLayout(gbl); 52 53 //The upper panel with radio buttons to select a card in card layout 54 selectorPanel = createSelectorPanel(); 55 c.gridx = 0; 56 c.gridy = 0; 57 c.gridwidth = 1; 58 c.gridheight = 1; 59 c.weightx = 0.0; 60 c.weighty = 0.0; 61 c.fill = GridBagConstraints.NONE; 62 c.anchor = GridBagConstraints.NORTH; 63 c.insets = new Insets(4, 4, 0, 4); 64 gbl.setConstraints(selectorPanel, c); 65 add(selectorPanel); 66 67 //Next is the panel containing all the cards 68 cardsPanel = createCardsPanel(); 69 c.gridx = 0; 70 c.gridy = 1; 71 c.gridwidth = 1; 72 c.gridheight = 1; 73 c.weightx = 0.5; 74 c.weighty = 0.5; 75 c.fill = GridBagConstraints.BOTH; 76 c.anchor = GridBagConstraints.NORTH; 77 c.insets = new Insets(4, 4, 0, 4); 78 gbl.setConstraints(cardsPanel, c); 79 add(cardsPanel); 80 81 } 82 83 private JPanel createSelectorPanel() { 84 //It just has radio buttons that select from among throws cards 85 JPanel selectorPanel = new JPanel(); 86 buttonGroup = new ButtonGroup(); 87 88 for (int i=0; i<cards.length; i++) { 89 final String card = cards[i]; 90 JRadioButton radioButton = new JRadioButton(card); 91 if (i==0) { 92 radioButton.setSelected(true); 93 } 94 95 radioButton.addActionListener(new ActionListener() { 96 public void actionPerformed(ActionEvent e) { 97 showCardAction(card); 98 } 99 }); 100 buttonGroup.add(radioButton); 101 selectorPanel.add(radioButton); 102 cardToButtonMap.put(card, radioButton); 103 } 104 105 return selectorPanel; 106 } 107 108 public void showCard(String card) { 109 JRadioButton radioButton = (JRadioButton)cardToButtonMap.get(card); 110 radioButton.doClick(); 111 } 112 113 protected void showCardAction(String card) { 114 cardLayout.show(cardsPanel, card); 115 } 116 117 private JPanel createCardsPanel() { 118 JPanel cardsPanel = new JPanel(); 119 cardLayout = new CardLayout(); 120 cardsPanel.setLayout(cardLayout); 121 122 for (int i=0; i<cardPanels.length; i++) { 123 cardsPanel.add(cardPanels[i], cards[i]); 124 } 125 126 return cardsPanel; 127 } 128 129 130 } 131 132 133 134

This page was automatically generated by Maven