package com.ericsson.tic.vi; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import java.awt.BorderLayout; import java.awt.CardLayout; import java.awt.Dimension; import javax.swing.JComboBox; import java.io.File; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import java.io.IOException; /** * The card panel holds "cards" or subpanels of type DataListPanel. * * @see CardLayout * @author Sami Matilainen * @version 1.0 (2008-12-04) */ public class CardPanel extends JPanel implements ItemListener { /** A panel used for layout. */ private JPanel topPanel; /** A panel used for layout. */ private JPanel cardsPanel; /** A list panel. */ public DataListPanel categoriesCard, viewsCard; /** Placeholder panels. To be replaced by DataListPanels. */ public JPanel nodesCard, relationsCard; /** ID for the categories panel. */ public static final int CATEGORY = 0; /** ID for the nodes panel. */ public static final int NODE = 1; /** ID for the relations panel. */ public static final int REL = 2; /** ID for the view panel. */ public static final int VIEW = 3; /** * Creates a card panel. */ public CardPanel() { this.setLayout(new BorderLayout()); this.setPreferredSize(new Dimension(250, 250)); this.setMinimumSize(new Dimension(250, 250)); this.setMaximumSize(new Dimension(250, 250)); try { VI.leftArrowIcon = new ImageIcon(ImageIO.read(new File("images/leftArrow.gif"))); VI.downArrowIcon = new ImageIcon(ImageIO.read(new File("images/downArrow.gif"))); VI.brushOnIcon = new ImageIcon(ImageIO.read(new File("images/brushOn.png"))); VI.brushOffIcon = new ImageIcon(ImageIO.read(new File("images/brushOff.png"))); } catch (IOException e) { e.printStackTrace(); } topPanel = new JPanel(); // Nodes and Relations options panes removed as they are not currently used // String comboBoxItems[] = { "Categories", "Nodes", "Relations", "Views" }; String comboBoxItems[] = { "Categories", "Views" }; JComboBox cb = new JComboBox(comboBoxItems); cb.setEditable(false); cb.addItemListener(this); topPanel.add(cb); categoriesCard = new DataListPanel(CATEGORY); viewsCard = new DataListPanel(VIEW); //nodesCard = new JPanel(); //nodesCard.add(new JLabel("not implemented")); //relationsCard = new JPanel(); //relationsCard.add(new JLabel("not implemented")); cardsPanel = new JPanel(new CardLayout()); cardsPanel.add(categoriesCard, "Categories"); //cardsPanel.add(nodesCard, "Nodes"); //cardsPanel.add(relationsCard, "Relations"); cardsPanel.add(viewsCard, "Views"); this.add(topPanel, BorderLayout.NORTH); this.add(cardsPanel, BorderLayout.CENTER); } /** * Called when an ItemEvent is triggered. * * @param evt The ItemEvent which triggered the event. */ public void itemStateChanged(ItemEvent evt) { CardLayout cl = (CardLayout)(cardsPanel.getLayout()); cl.show(cardsPanel, (String)evt.getItem()); viewsCard.updateViewList(); } }