/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.model.control;
import java.awt.Dimension;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import com.jstatcom.component.CardDisplayPanel;
import com.jstatcom.model.JSCTypes;
import com.jstatcom.model.Symbol;
/**
* A frame that holds the symbol table tree and the symbol display.
*
* @author Markus Kraetzig
*/
public class SymbolFrame extends JFrame {
private javax.swing.JSplitPane jSplitPane = null;
private javax.swing.JScrollPane jScrollPane = null;
private SymbolTree symbolTree = SymbolTree.getInstance();
private javax.swing.JPanel jPanel = null;
private javax.swing.JPanel topPanel = null;
private com.jstatcom.component.CardDisplayPanel cardDisplayPanel = null;
private javax.swing.JLabel nameLabel = null;
private javax.swing.JLabel jLabel = null;
private javax.swing.JLabel jLabel1 = null;
private javax.swing.JLabel typeLabel = null;
private javax.swing.JScrollPane jScrollPane1 = null;
private javax.swing.JTextArea jTextArea = null;
private final Map symbolPanelMap = new HashMap();
private SymbolPanel defaultSymbolPanel;
/**
* Creates SymbolFrame.
*/
public SymbolFrame() {
super("Symbol Control");
initialize();
}
/**
* Sets the panel to be displayed for a certain data type. If a selected
* type is not yet associated with a symbol panel, the default symbol panel
* is used.
*
* @param type
* the data type that the panel should display
* @param panel
* the SymbolPanel for the given type
* @throws IllegalArgumentException
* if (type == null || panel == null)
*/
public final void addSymbolPanel(JSCTypes type, SymbolPanel panel) {
if (type == null || panel == null)
throw new IllegalArgumentException("Argument was null.");
symbolPanelMap.put(type, panel);
}
/**
* Runs init tasks.
*/
private void initialize() {
this.setContentPane(getJSplitPane());
setSize(600, 400);
URL url = getClass().getResource("/images/scontrol.gif");
if (url != null)
setIconImage(new ImageIcon(url).getImage());
defaultSymbolPanel = new DefaultSymbolPanel();
// not shown to attach listener immediately
getCardDisplayPanel().showCard(defaultSymbolPanel);
// listens to changes in tree selection
symbolTree.addTreeSelectionListener(new TreeSelectionListener() {
private Symbol currentSymbol = null;
public void valueChanged(TreeSelectionEvent evt) {
Object item = evt.getPath().getLastPathComponent();
if (item instanceof SymbolTreeNode) {
Symbol symbol = ((SymbolTreeNode) item).symbol;
getNameLabel().setText(symbol.NAME);
getTypeLabel().setText(symbol.type + "");
getDescriptionArea().setText(symbol.getDescription());
getDescriptionArea().setCaretPosition(0);
if (symbolPanelMap.containsKey(symbol.type)) {
SymbolPanel sPanel = symbolPanelMap.get(symbol.type);
if (currentSymbol != null)
currentSymbol.removeSymbolListener(sPanel);
currentSymbol = symbol;
currentSymbol.addSymbolListener(sPanel);
sPanel.setSymbol(symbol);
getCardDisplayPanel().showCard(sPanel);
} else {
if (currentSymbol != null)
currentSymbol
.removeSymbolListener(defaultSymbolPanel);
currentSymbol = symbol;
currentSymbol.addSymbolListener(defaultSymbolPanel);
defaultSymbolPanel.setSymbol(symbol);
getCardDisplayPanel().showCard(defaultSymbolPanel);
}
}
}
});
addSymbolPanel(JSCTypes.NARRAY, new JSCNArrayPanel());
addSymbolPanel(JSCTypes.SARRAY, new JSCSArrayPanel());
}
/**
* This method initializes jSplitPane
*
* @return javax.swing.JSplitPane
*/
private javax.swing.JSplitPane getJSplitPane() {
if (jSplitPane == null) {
jSplitPane = new javax.swing.JSplitPane();
jSplitPane.setLeftComponent(getJScrollPane());
jSplitPane.setRightComponent(getJPanel());
}
return jSplitPane;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private javax.swing.JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new javax.swing.JScrollPane();
jScrollPane.setViewportView(symbolTree);
jScrollPane.setPreferredSize(new java.awt.Dimension(150, 363));
jScrollPane.setMinimumSize(new Dimension(100, 300));
}
return jScrollPane;
}
/**
* This method initializes jPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJPanel() {
if (jPanel == null) {
jPanel = new javax.swing.JPanel();
jPanel.setLayout(new java.awt.BorderLayout());
jPanel.add(getTopPanel(), java.awt.BorderLayout.NORTH);
jPanel.add(getCardDisplayPanel(), java.awt.BorderLayout.CENTER);
jPanel.setMinimumSize(new Dimension(300, 300));
}
return jPanel;
}
/**
* This method initializes topPanel
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getTopPanel() {
if (topPanel == null) {
topPanel = new javax.swing.JPanel();
java.awt.GridBagConstraints consGridBagConstraints3 = new java.awt.GridBagConstraints();
java.awt.GridBagConstraints consGridBagConstraints4 = new java.awt.GridBagConstraints();
java.awt.GridBagConstraints consGridBagConstraints5 = new java.awt.GridBagConstraints();
java.awt.GridBagConstraints consGridBagConstraints2 = new java.awt.GridBagConstraints();
java.awt.GridBagConstraints consGridBagConstraints7 = new java.awt.GridBagConstraints();
consGridBagConstraints7.fill = java.awt.GridBagConstraints.BOTH;
consGridBagConstraints7.weighty = 1.0;
consGridBagConstraints7.weightx = 1.0;
consGridBagConstraints7.gridy = 2;
consGridBagConstraints7.gridx = 0;
consGridBagConstraints7.insets = new java.awt.Insets(0, 0, 0, 0);
consGridBagConstraints7.gridwidth = 2;
consGridBagConstraints3.gridy = 0;
consGridBagConstraints3.gridx = 0;
consGridBagConstraints3.fill = java.awt.GridBagConstraints.HORIZONTAL;
consGridBagConstraints4.gridy = 1;
consGridBagConstraints4.gridx = 0;
consGridBagConstraints4.fill = java.awt.GridBagConstraints.HORIZONTAL;
consGridBagConstraints5.gridy = 1;
consGridBagConstraints5.gridx = 1;
consGridBagConstraints5.fill = java.awt.GridBagConstraints.HORIZONTAL;
consGridBagConstraints2.gridy = 0;
consGridBagConstraints2.gridx = 1;
consGridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
consGridBagConstraints2.insets = new java.awt.Insets(2, 0, 0, 5);
consGridBagConstraints5.insets = new java.awt.Insets(2, 0, 0, 5);
consGridBagConstraints3.insets = new java.awt.Insets(2, 5, 0, 0);
consGridBagConstraints4.insets = new java.awt.Insets(2, 5, 0, 0);
topPanel.setLayout(new java.awt.GridBagLayout());
topPanel.add(getNameLabel(), consGridBagConstraints2);
topPanel.add(getJLabel(), consGridBagConstraints3);
topPanel.add(getJLabel1(), consGridBagConstraints4);
topPanel.add(getTypeLabel(), consGridBagConstraints5);
topPanel.add(getJScrollPane1(), consGridBagConstraints7);
topPanel.setPreferredSize(new java.awt.Dimension(10, 130));
topPanel.setMinimumSize(new java.awt.Dimension(10, 130));
topPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
}
return topPanel;
}
/**
* This method initializes cardDisplayPanel
*
* @return com.jstatcom.component.CardDisplayPanel
*/
private com.jstatcom.component.CardDisplayPanel getCardDisplayPanel() {
if (cardDisplayPanel == null) {
cardDisplayPanel = new CardDisplayPanel();
}
return cardDisplayPanel;
}
/**
* This method initializes nameLabel
*
* @return javax.swing.JLabel
*/
private javax.swing.JLabel getNameLabel() {
if (nameLabel == null) {
nameLabel = new javax.swing.JLabel();
nameLabel.setText("");
nameLabel.setPreferredSize(new java.awt.Dimension(77, 20));
}
return nameLabel;
}
/**
* This method initializes jLabel
*
* @return javax.swing.JLabel
*/
private javax.swing.JLabel getJLabel() {
if (jLabel == null) {
jLabel = new javax.swing.JLabel();
jLabel.setText("Name");
jLabel.setPreferredSize(new java.awt.Dimension(60, 20));
jLabel.setMinimumSize(new java.awt.Dimension(60, 20));
}
return jLabel;
}
/**
* This method initializes jLabel1
*
* @return javax.swing.JLabel
*/
private javax.swing.JLabel getJLabel1() {
if (jLabel1 == null) {
jLabel1 = new javax.swing.JLabel();
jLabel1.setText("Type");
jLabel1.setPreferredSize(new java.awt.Dimension(38, 20));
jLabel1.setMinimumSize(new java.awt.Dimension(70, 20));
}
return jLabel1;
}
/**
* This method initializes typeLabel
*
* @return javax.swing.JLabel
*/
private javax.swing.JLabel getTypeLabel() {
if (typeLabel == null) {
typeLabel = new javax.swing.JLabel();
typeLabel.setText("");
typeLabel.setPreferredSize(new java.awt.Dimension(38, 20));
}
return typeLabel;
}
/**
* This method initializes jScrollPane1
*
* @return javax.swing.JScrollPane
*/
private javax.swing.JScrollPane getJScrollPane1() {
if (jScrollPane1 == null) {
jScrollPane1 = new javax.swing.JScrollPane();
jScrollPane1.setViewportView(getDescriptionArea());
jScrollPane1.setBorder(new TitledBorder(new BevelBorder(
BevelBorder.LOWERED), "Description", TitledBorder.RIGHT,
TitledBorder.TOP));
jScrollPane1.setPreferredSize(new java.awt.Dimension(13, 80));
jScrollPane1.setMinimumSize(new java.awt.Dimension(22, 80));
}
return jScrollPane1;
}
/**
* This method initializes jTextArea
*
* @return javax.swing.JTextArea
*/
private javax.swing.JTextArea getDescriptionArea() {
if (jTextArea == null) {
jTextArea = new javax.swing.JTextArea();
jTextArea.setEditable(false);
jTextArea.setMargin(new java.awt.Insets(2, 5, 2, 5));
}
return jTextArea;
}
/**
* Sets whether data in the symbol control should be editable. This method
* delegates to the setSymbolEditable methods of all
* registered SymbolPanel instances. How this property takes
* effect is handled by the respective symbol panels.
*
* @param editable
* true if editable, false is
* default
*/
public void setDataEditable(boolean editable) {
for (SymbolPanel val : symbolPanelMap.values())
val.setSymbolEditable(editable);
}
}
Ads help maintain this website.