00001 package DisplayGUI;
00002 import java.awt.event.*;
00003 import javax.swing.*;
00004 import javax.swing.tree.*;
00005 import java.awt.*;
00006
00007
00008 public class ISTree extends JFrame implements ActionListener, displayParams {
00009 gui guiControl;
00010 JButton closeButton, refreshButton;
00011
00012 protected JTree trISServers;
00013 JMenu popupOptionMenu;
00014
00015 protected DefaultMutableTreeNode rootNode;
00016
00017 public ISTree(gui parent, DefaultMutableTreeNode top) {
00018 super("Information Service Status");
00019 guiControl=parent;
00020
00021
00022 JPanel pane = new JPanel();
00023 pane.setLayout(new BoxLayout(pane,BoxLayout.Y_AXIS));
00024
00025 popupOptionMenu = getTreeOptionMenu();
00026
00027
00028 trISServers = new javax.swing.JTree();
00029 trISServers.setEditable(false);
00030 trISServers.setBorder(new javax.swing.border.EtchedBorder());
00031 JScrollPane scrollPane = new JScrollPane(trISServers);
00032 scrollPane.setPreferredSize(new java.awt.Dimension(300,300));
00033 pane.add(Box.createRigidArea(new Dimension(0,5)));
00034 pane.add(scrollPane);
00035
00036 pane.add(Box.createRigidArea(new Dimension(0,5)));
00037
00038 JPanel buttonPane = new JPanel();
00039 buttonPane.setLayout(new BoxLayout(buttonPane,BoxLayout.X_AXIS));
00040
00041 closeButton = new JButton("Close");
00042 refreshButton = new JButton("Refresh");
00043 closeButton.setEnabled(true);
00044 closeButton.addActionListener(this);
00045 refreshButton.setEnabled(true);
00046 refreshButton.addActionListener(this);
00047
00048 buttonPane.add(refreshButton);
00049 buttonPane.add(Box.createHorizontalGlue());
00050 buttonPane.add(closeButton);
00051
00052 pane.add(buttonPane);
00053 pane.setToolTipText("Keyboard Options:\nALT_DELETE to delete the selection(s)\nALT_V to view the IS data");
00054
00055 trISServers.addMouseListener(new isTreeMouseAdapter());
00056
00057 setContentPane(pane);
00058 pack();
00059
00060 setTree(top);
00061 }
00062
00063
00064
00065
00066 public Insets getInsets() {
00067 return new Insets(20,20,20,20);
00068 }
00069
00070
00071
00072
00073
00074
00075 public void actionPerformed(ActionEvent evt) {
00076 Object source = evt.getSource();
00077
00078
00079
00080 if(source==closeButton) setVisible(false);
00081 else setTree(guiControl.isInterface.getISTree());
00082
00083 }
00084
00085
00086 public void setTree(DefaultMutableTreeNode top) {
00087
00088 trISServers.setModel(new DefaultTreeModel(top));
00089 setVisible(true);
00090
00091 }
00092
00093 private JMenu getTreeOptionMenu() {
00094 JMenu thisMenu = new JMenu("TreeOptions");
00095 thisMenu.setFont(menuFont);
00096 JMenuItem item1 = new JMenuItem("Delete selection(s)");
00097 JMenuItem item2 = new JMenuItem("View Selection");
00098 JMenuItem item3 = new JMenuItem("Plot Data");
00099 item1.setFont(menuFont);
00100 item2.setFont(menuFont);
00101 item3.setFont(menuFont);
00102 thisMenu.add(item1);
00103 thisMenu.add(item2);
00104 thisMenu.add(item3);
00105 item1.addActionListener(new java.awt.event.ActionListener() {
00106 public void actionPerformed(java.awt.event.ActionEvent evt) {
00107 TreePath[] paths;
00108 if((paths = trISServers.getSelectionPaths())==null) return;
00109 GuiComponents.System.ISInterface is = GuiComponents.System.ISInterface.getInstance();
00110 for (int i=paths.length-1; i>=0; i--) {
00111 DefaultMutableTreeNode hist = (DefaultMutableTreeNode)paths[i].getLastPathComponent();
00112
00113 ((DefaultTreeModel)trISServers.getModel()).removeNodeFromParent(hist);
00114 System.out.println(is.remove(hist.toString()));
00115 }
00116 }
00117 });
00118 item2.addActionListener(new java.awt.event.ActionListener() {
00119 public void actionPerformed(java.awt.event.ActionEvent evt) {
00120 TreePath path = trISServers.getSelectionPath();
00121 if(path==null) return;
00122 guiControl.isInterface.viewISData(path.getLastPathComponent().toString());
00123 }
00124 });
00125 item3.addActionListener(new java.awt.event.ActionListener() {
00126 public void actionPerformed(java.awt.event.ActionEvent evt) {
00127 TreePath path = trISServers.getSelectionPath();
00128 if(path==null) return;
00129 String objectName = path.getLastPathComponent().toString();
00130 if(objectName.startsWith("Sct")) guiControl.isInterface.launchExternalViewer(objectName);
00131 else javax.swing.JOptionPane.showMessageDialog(null,"Can only plot Sct Data objects!");
00132 }
00133 });
00134 return thisMenu;
00135 }
00136
00137 class isTreeMouseAdapter extends java.awt.event.MouseAdapter {
00138 public void mouseClicked(java.awt.event.MouseEvent e) {
00139 switch(e.getModifiers()) {
00140 case java.awt.event.InputEvent.BUTTON2_MASK:
00141 case java.awt.event.InputEvent.BUTTON3_MASK:
00142 TreePath[] existingSelections = trISServers.getSelectionPaths();
00143 TreePath selPath = trISServers.getPathForLocation(e.getX(), e.getY());
00144 if(selPath!=null && (existingSelections==null || existingSelections.length<2)) trISServers.setSelectionPath(selPath);
00145 existingSelections = trISServers.getSelectionPaths();
00146 if(existingSelections==null) return;
00147 JPopupMenu pMenu = popupOptionMenu.getPopupMenu();
00148 pMenu.show(e.getComponent(),e.getX(),e.getY());
00149 pMenu.setInvoker(popupOptionMenu);
00150 break;
00151 default:
00152 }
00153 }
00154 }
00155
00156
00157 }