package com.ericsson.tic.vi; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JButton; import javax.swing.JCheckBox; import java.awt.BorderLayout; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.Insets; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import java.awt.FlowLayout; import javax.swing.JComboBox; import javax.swing.DefaultComboBoxModel; /** * The DataListPanel and DataPanel combine to create lists of * categories/views etc. * * @see CardPanel * @see DataListPanel * @author Sami Matilainen * @version 1.0 (2008-12-04) */ public class DataPanel extends JPanel implements ActionListener { /** Subpanel used for layout. */ public JPanel eastPanel, centerPanel, westPanel; /** Subpanel used for layout. */ public JPanel topPanel, settingsPanel, buttonsPanel; /** Subpanel used for layout. */ public JPanel leftPanel, rightPanel; /** Enable check box. */ public JCheckBox enableBox; /** A fold button. */ public JButton foldButton; /** A brushing button. */ public JButton brushingButton; /** A title. */ public JLabel title; /** TinyPanel used for layout. */ public JPanel tinyPanel; /** True if the panel is folded. */ public boolean isFolded; /** A button used for choosing color. */ public ColorChooserButton colorButton; /** A text label. */ public String labelText; /** The parent DataListPanel of this DataPanel. */ public DataListPanel parent; /** The type of this DataPanel. Defined in CardPanel. */ public int type; /** Comboboxes used for choosing datasets in the view list. */ public JComboBox nodeComboBox, relsComboBox; /** Comboboxes used for choosing datasets in the view list. */ public JComboBox[] barsComboBox, histComboBox; /** A view panel. */ public ViewPanel view; /** * Creates a DataPanel. * * @param labelText The title of this panel. * @param parent The parent DataListPanel of this panel. * @param view An associated ViewPanel. */ public DataPanel(String labelText, DataListPanel parent, ViewPanel view) { this.view = view; Color c = new Color(1.0f, 1.0f, 1.0f); this.setup(labelText, c, parent); } /** * Creates a DataPanel. * * @param labelText The title of this panel. * @param parent The parent DataListPanel of this panel. */ public DataPanel(String labelText, DataListPanel parent) { Color c = new Color(1.0f, 1.0f, 1.0f); this.setup(labelText, c, parent); } /** * Creates a DataPanel. * * @param labelText The title of this panel. * @param parent The parent DataListPanel of this panel. * @param c A default color for a colorChooserButton. */ public DataPanel(String labelText, Color c, DataListPanel parent) { this.setup(labelText, c, parent); } /** * Sets up the panel. * * @param labelText The title of this panel. * @param parent The parent DataListPanel of this panel. * @param c A default color for a colorChooserButton. */ public void setup(String labelText, Color c, DataListPanel parent) { this.type = parent.type; this.setLayout(new BorderLayout()); this.setBorder(new LineBorder(Color.GRAY, 1)); this.labelText = labelText; this.parent = parent; isFolded = true; topPanel = new JPanel(); if (type == CardPanel.CATEGORY) { categorySettings(); } else if (type == CardPanel.NODE) { nodeSettings(); } else if (type == CardPanel.REL) { relationSettings(); } else if (type == CardPanel.VIEW) { viewSettings(); } tinyPanel = new JPanel(); tinyPanel.setSize(1,1); leftPanel = new JPanel(); rightPanel = new JPanel(); rightPanel.setLayout(new BorderLayout()); topPanel.setLayout(new BorderLayout()); foldButton = new JButton("", VI.leftArrowIcon); foldButton.addActionListener(this); foldButton.setActionCommand(labelText + " fold"); foldButton.setMargin(new Insets(0, 0, 0, 0)); foldButton.setFocusPainted(false); foldButton.setBorderPainted(false); foldButton.setContentAreaFilled(false); title = new JLabel(labelText); enableBox = new JCheckBox(""); //checkBox.addItemListener(this); enableBox.setSelected(true); brushingButton = new JButton("", VI.brushOffIcon); //brushingButton.setMargin(new Insets(0, 0, 0, 0)); //brushingButton.setFocusPainted(false); //brushingButton.setBorderPainted(false); //brushingButton.setContentAreaFilled(false); colorButton = new ColorChooserButton(c); //resetButton.addActionListener(listener); //colorButton.setActionCommand("color"); //colorButton.setMnemonic(KeyEvent.VK_R); leftPanel.add(foldButton, BorderLayout.WEST); //leftPanel.add(enableBox, BorderLayout.CENTER); if (type == CardPanel.CATEGORY) { leftPanel.add(brushingButton, BorderLayout.EAST); rightPanel.add(colorButton, BorderLayout.WEST); } topPanel.add(leftPanel, BorderLayout.WEST); topPanel.add(title, BorderLayout.CENTER); topPanel.add(rightPanel, BorderLayout.EAST); this.add(topPanel, BorderLayout.NORTH); } /** * Creates the content in the category settings panel. */ public void categorySettings() { settingsPanel = new JPanel(); settingsPanel.add(new JLabel("settings (removed)")); settingsPanel.setBorder(new LineBorder(Color.GRAY, 1)); } /** * Creates the content in the view settings panel. */ public void viewSettings() { //setComboBoxIndexes(); settingsPanel = new JPanel(); settingsPanel.setLayout(new BoxLayout(settingsPanel, BoxLayout.PAGE_AXIS)); settingsPanel.setBorder(new LineBorder(Color.GRAY, 1)); JPanel empty = new JPanel(); empty.setSize(90, 90); JPanel node = new JPanel(new BorderLayout(10, 10)); JPanel rels = new JPanel(new BorderLayout(10, 10)); JPanel bar = new JPanel(new BorderLayout(10, 10)); JPanel his = new JPanel(new BorderLayout(10, 10)); JPanel[] bars = new JPanel[VI.nodeTypeArr.length-1]; JPanel[] hist = new JPanel[VI.nodeTypeArr.length-1]; for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { bars[i] = new JPanel(new BorderLayout(10, 10)); hist[i] = new JPanel(new BorderLayout(10, 10)); } node.add(new JLabel(" Nodes"), BorderLayout.WEST); rels.add(new JLabel(" Links"), BorderLayout.WEST); bar.add(new JPanel(), BorderLayout.NORTH); his.add(new JPanel(), BorderLayout.NORTH); bar.add(new JPanel(), BorderLayout.SOUTH); his.add(new JPanel(), BorderLayout.SOUTH); bar.add(new JLabel(" Bars:"), BorderLayout.WEST); his.add(new JLabel(" Label histograms:"), BorderLayout.WEST); nodeComboBox = new JComboBox(VI.nodeSingularDataStrings); relsComboBox = new JComboBox(VI.relsDataStrings); nodeComboBox.setPrototypeDisplayValue("WWWWWW"); relsComboBox.setPrototypeDisplayValue("WWWWWW"); nodeComboBox.setSelectedIndex(view.nodeSelectedIndex); relsComboBox.setSelectedIndex(view.relSelectedIndex); nodeComboBox.addActionListener(this); nodeComboBox.setActionCommand(labelText + " node"); relsComboBox.addActionListener(this); relsComboBox.setActionCommand(labelText + " rels"); node.add(nodeComboBox, BorderLayout.EAST); rels.add(relsComboBox, BorderLayout.EAST); barsComboBox = new JComboBox[VI.nodeTypeArr.length-1]; histComboBox = new JComboBox[VI.nodeTypeArr.length-1]; for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { barsComboBox[i] = new JComboBox(VI.nodeMultiDataStrings); barsComboBox[i].setSelectedIndex(view.barsSelectedIndex[i]); barsComboBox[i].setPrototypeDisplayValue("WWWWWW"); barsComboBox[i].addActionListener(this); barsComboBox[i].setActionCommand(labelText + " bars " + i); bars[i].add(new JLabel(" " + VI.nodeTypeArr[i+1].name), BorderLayout.CENTER); bars[i].add(barsComboBox[i], BorderLayout.EAST); } for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { histComboBox[i] = new JComboBox(VI.nodeMultiDataStrings); histComboBox[i].setSelectedIndex(view.histSelectedIndex[i]); histComboBox[i].setPrototypeDisplayValue("WWWWWW"); histComboBox[i].addActionListener(this); histComboBox[i].setActionCommand(labelText + " hist " + i); hist[i].add(new JLabel(" " + VI.nodeTypeArr[i+1].name), BorderLayout.CENTER); hist[i].add(histComboBox[i], BorderLayout.EAST); } settingsPanel.add(node); settingsPanel.add(rels); settingsPanel.add(bar); for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { settingsPanel.add(bars[i]); } settingsPanel.add(his); for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { settingsPanel.add(hist[i]); } } /** * Creates the content in the node settings panel. */ public void nodeSettings() { } /** * Creates the content in the relations settings panel. */ public void relationSettings() { } /** * Folds the panel. */ public void fold() { foldButton.setIcon(VI.leftArrowIcon); this.setBorder(new LineBorder(Color.GRAY, 1)); this.remove(settingsPanel); this.validate(); this.revalidate(); parent.validate(); } /** * Unfolds the panel. */ public void unfold() { foldButton.setIcon(VI.downArrowIcon); this.setBorder(new LineBorder(Color.BLACK, 1)); if (type == CardPanel.CATEGORY) { categorySettings(); } else if (type == CardPanel.NODE) { nodeSettings(); } else if (type == CardPanel.REL) { relationSettings(); } else if (type == CardPanel.VIEW) { viewSettings(); } this.add(settingsPanel, BorderLayout.CENTER); this.validate(); parent.validate(); } /** * Sets the selected index of the comboboxes for the combo boxes * @deprecated */ public void setComboBoxIndexes() { view.nodeSelectedIndex = 0; view.relSelectedIndex = 0; view.barsSelectedIndex = new int[VI.nodeTypeArr.length-1]; view.histSelectedIndex = new int[VI.nodeTypeArr.length-1]; for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { view.barsSelectedIndex[i] = 0; //view.barData[i]; view.histSelectedIndex[i] = 0; //view.histData[i]; } if (view != null) { for (int i = 0; i < VI.nodeSingularData.length; i++) { if (VI.nodeSingularData[i].id == view.nodeData-1) { view.nodeSelectedIndex = i; } } } if (view != null) { for (int i = 0; i < VI.relsData.length; i++) { if (VI.relsData[i].id == view.relData-1) { view.relSelectedIndex = i; } } } for (int j = 0; j < VI.nodeTypeArr.length-1; j++) { if (view != null) { for (int i = 0; i < VI.nodeMultiData.length; i++) { if (VI.nodeMultiData[i].id == view.barData[j]-1) { view.barsSelectedIndex[j] = i; } } } } for (int j = 0; j < VI.nodeTypeArr.length-1; j++) { if (view != null) { for (int i = 0; i < VI.nodeMultiData.length; i++) { if (VI.nodeMultiData[i].id == view.histData[j]-1) { view.histSelectedIndex[j] = i; } } } } } /** * Called when an ActionEvent is triggered. * * @param e The ActionEvent which triggered the event. */ public void actionPerformed(ActionEvent e) { if ((labelText + " fold").equals(e.getActionCommand())) { if (this.isFolded) { this.unfold(); } else { this.fold(); } this.isFolded = !this.isFolded; } else if ((labelText + " node").equals(e.getActionCommand())) { view.nodeData = VI.nodeSingularData[nodeComboBox.getSelectedIndex()].id; view.nodeSelectedIndex = nodeComboBox.getSelectedIndex(); } else if ((labelText + " rels").equals(e.getActionCommand())) { view.relData = VI.relsData[relsComboBox.getSelectedIndex()].id; view.relSelectedIndex = relsComboBox.getSelectedIndex(); } else { for (int i = 0; i < VI.nodeTypeArr.length-1; i++) { if ((labelText + " bars " + i).equals(e.getActionCommand())) { view.barData[i] = VI.nodeMultiData[barsComboBox[i].getSelectedIndex()].id; view.barsSelectedIndex[i] = barsComboBox[i].getSelectedIndex(); } else if ((labelText + " hist " + i).equals(e.getActionCommand())) { view.histData[i] = VI.nodeMultiData[histComboBox[i].getSelectedIndex()].id; view.histSelectedIndex[i] = histComboBox[i].getSelectedIndex(); } } } } }