diff options
Diffstat (limited to 'source/com/c2kernel/gui/EntityDetails.java')
| -rwxr-xr-x | source/com/c2kernel/gui/EntityDetails.java | 223 |
1 files changed, 223 insertions, 0 deletions
diff --git a/source/com/c2kernel/gui/EntityDetails.java b/source/com/c2kernel/gui/EntityDetails.java new file mode 100755 index 0000000..b6c5245 --- /dev/null +++ b/source/com/c2kernel/gui/EntityDetails.java @@ -0,0 +1,223 @@ +package com.c2kernel.gui;
+
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTabbedPane;
+import javax.swing.SwingConstants;
+import javax.swing.event.ChangeListener;
+import com.c2kernel.gui.data.NodeEntity;
+import com.c2kernel.gui.tabs.EntityTabPane;
+import com.c2kernel.utils.Language;
+import com.c2kernel.utils.Logger;
+import com.c2kernel.utils.Resource;
+
+/**
+ * The tab pane for each viewed item
+ * @version $Revision: 1.38 $ $Date: 2005/06/27 15:16:14 $
+ * @author $Author: abranson $
+ */
+public class EntityDetails extends JPanel implements ChangeListener, Runnable {
+ protected JTabbedPane myTabbedPane = new JTabbedPane(SwingConstants.BOTTOM);
+ protected JPanel itemTitlePanel;
+ private EntityTabManager desktopManager;
+ protected NodeEntity myEntity;
+ protected HashMap childPanes = new HashMap();
+ protected String startTab;
+ protected String startCommand = null;
+ protected boolean initialized = false;
+
+ public EntityDetails(NodeEntity thisItem) {
+ super();
+ startTab = MainFrame.getPref("DefaultStartTab", "Properties");
+ myEntity = thisItem;
+ }
+
+ public void run() {
+ Thread.currentThread().setName("Entity Pane Builder");
+ EntityTabPane componentToAdd = null;
+ setLayout(new BorderLayout());
+ itemTitlePanel = getItemTitlePanel();
+ add(itemTitlePanel, BorderLayout.NORTH);
+ add(myTabbedPane);
+
+ // decide which tabs to create
+ ArrayList requiredTabs = myEntity.getTabs();
+
+ for (Iterator en = requiredTabs.iterator(); en.hasNext();) {
+ String tabName = (String)en.next();
+ if (tabName != null) {
+ //create class instances and initialise
+ Class myClass = null;
+ //look up the required TabbedPane
+ try {
+ myClass = Class.forName(this.getClass().getPackage().getName() + ".tabs." + tabName + "Pane");
+ Logger.msg(2, "ItemDetails.<init> - Creating ItemTabPane instance: " +
+ this.getClass().getPackage().getName() + ".tabs." + tabName + "Pane");
+ componentToAdd = (EntityTabPane)myClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ Logger.msg(2, "ItemDetails.<init> - No specialist tab found for " + tabName + ". Using default.");
+ } catch (InstantiationException e) {
+ Logger.msg(0, "ItemDetails.<init> - Instantiation Error! " + e);
+ } catch (IllegalAccessException e) {
+ Logger.msg(0, "ItemDetails.<init> - Illegal Method Access Error! Class was probably not a ItemTabPane: " + e);
+ }
+ if (componentToAdd == null) componentToAdd = new EntityTabPane(tabName, null);
+ componentToAdd.setParent(this);
+
+ //adds the component to the panel
+ childPanes.put(componentToAdd, new Boolean(false));
+
+ int placement = myTabbedPane.getTabCount();
+ if (tabName.equals("Properties")) // must be first
+ placement = 0;
+ myTabbedPane.insertTab(componentToAdd.getTabName(), null, componentToAdd, null, placement);
+ }
+ }
+ initialized = true;
+ if (!(requiredTabs.contains(startTab))) {
+ startTab = "Properties";
+ startCommand = null;
+ }
+ runCommand(Language.translate(startTab), startCommand);
+ myTabbedPane.setVisible(true);
+ myTabbedPane.addChangeListener(this);
+ validate();
+
+ }
+
+ public void stateChanged(javax.swing.event.ChangeEvent p1) {
+ initialisePane((EntityTabPane)myTabbedPane.getSelectedComponent());
+ }
+
+ public void initialisePane(EntityTabPane pane) {
+ Boolean isInit = (Boolean)childPanes.get(pane);
+ if (isInit.booleanValue() == false) {
+ Logger.msg(4,"Initialising "+pane.getTabName());
+ pane.initForEntity(myEntity);
+ childPanes.put(pane, new Boolean(true));
+ validate();
+ }
+ }
+
+ public EntityTabManager getDesktopManager() {
+ return desktopManager;
+ }
+
+ public void setDesktopManager(EntityTabManager newDesktopManager) {
+ desktopManager = newDesktopManager;
+ }
+
+ public JPanel getItemTitlePanel() {
+ JPanel titlePanel = new JPanel();
+ JComponent current;
+ // Use gridbag layout for title
+ GridBagLayout gridbag = new GridBagLayout();
+ GridBagConstraints c = new GridBagConstraints();
+ titlePanel.setLayout(gridbag);
+ // Place Item Icon
+ c.gridx = 0;
+ c.gridy = 0;
+ c.gridheight = GridBagConstraints.REMAINDER;
+ c.anchor = GridBagConstraints.NORTH;
+ c.ipadx = 5;
+ c.ipady = 5;
+ current = new JLabel(Resource.getImageResource("typeicons/"+myEntity.getIconName()+"_32.png"));
+ gridbag.setConstraints(current, c);
+ titlePanel.add(current);
+ // Place Name/ID Label
+ current = new JLabel(myEntity.getName() + " (" + myEntity.getSysKey() + ")");
+ c.gridx = 1; c.gridy = 0; c.gridheight = 1;
+ c.anchor = GridBagConstraints.NORTH; c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 1.0; c.ipadx = 2; c.ipady = 2;
+ current.setFont(new Font("Helvetica", Font.PLAIN, 18));
+ gridbag.setConstraints(current, c);
+ titlePanel.add(current);
+ // Place Type Label
+ current = new JLabel(myEntity.getType());
+ c.gridx = 1; c.gridy = 2; c.gridheight = 1;
+ c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx = 1.0;
+ current.setFont(new Font("Helvetica", Font.PLAIN, 12));
+ gridbag.setConstraints(current, c);
+ titlePanel.add(current);
+ return titlePanel;
+ }
+
+ public void discardTabs() {
+ myTabbedPane.removeChangeListener(this);
+ myTabbedPane.removeAll();
+ for (Iterator iter = childPanes.keySet().iterator(); iter.hasNext();) {
+ EntityTabPane element = (EntityTabPane)iter.next();
+ element.destroy();
+ iter.remove();
+ }
+ }
+
+ public int getSysKey()
+ {
+ return myEntity.getSysKey();
+ }
+
+ public void closeTab() {
+ desktopManager.remove(myEntity.getSysKey());
+ Logger.msg(5,"Remove master Tab :"+myEntity.getType()+ " SysKey "+myEntity.getSysKey());
+ myEntity.getEntity().dumpSubscriptions(0);
+ }
+
+ public void actionPerformed(ActionEvent e) {
+ if (e.getActionCommand().equals("close"))
+ closeTab();
+ }
+
+ public void runCommand(String tab, String command) {
+ if (initialized) {
+ int tabIndex = findTab(tab);
+ Logger.msg(3, "Running command "+tab+" "+command+" ("+tabIndex+")");
+ if (tabIndex == -1) {
+ Logger.error("Tab "+tab+" not found for command "+command);
+ return;
+ }
+ EntityTabPane startPane = (EntityTabPane)myTabbedPane.getComponentAt(tabIndex);
+ myTabbedPane.setSelectedIndex(tabIndex);
+ initialisePane(startPane);
+ if (command!= null) startPane.runCommand(command);
+ }
+ else
+ {
+ Logger.msg(3, "Storing command "+tab+" "+command+" until initialised.");
+ startTab = tab;
+ startCommand = command;
+ }
+ }
+
+ protected int findTab(String tabName) {
+ for (int i=0; i< myTabbedPane.getTabCount(); i++) {
+ EntityTabPane thisPane = (EntityTabPane)myTabbedPane.getComponentAt(i);
+ if (thisPane.getTabName().equals(tabName))
+ return i;
+ }
+ return -1;
+ }
+
+
+ public void refresh()
+ {
+ }
+ /**
+ *
+ */
+ protected void finalize() throws Throwable {
+ Logger.msg(7, "EntityDetails "+myEntity.getSysKey()+" reaped");
+ super.finalize();
+ }
+
+}
\ No newline at end of file |
