KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > SOFA > SOFAnet > Browser > NetNodeBrowser


1 /*
2  * NetNodeBrowser.java
3  *
4  * Created on 10. květen 2004, 17:07
5  */

6
7 package SOFA.SOFAnet.Browser;
8
9 import javax.swing.*;
10 import java.awt.*;
11
12 import SOFA.SOFAnet.Admin.RMI.RMIAdminInterface;
13
14 import java.net.InetAddress JavaDoc;
15 import java.net.MalformedURLException JavaDoc;
16 import java.net.UnknownHostException JavaDoc;
17 import java.rmi.Naming JavaDoc;
18 import java.rmi.NotBoundException JavaDoc;
19 import java.rmi.RemoteException JavaDoc;
20 import SOFA.SOFAnet.Repository.NodeInfo;
21 import SOFA.Util.VMProperties;
22
23 /**
24  *
25  * @author Ladislav Sobr
26  */

27 public class NetNodeBrowser extends JFrame
28 {
29   private RMIAdminInterface admin;
30   private String JavaDoc nodeName;
31   
32   private JPanel jBinLicPanel;
33   private JPanel jOpsPanel;
34   private JPanel jOffersPanel;
35   private JPanel jLocalInfosPanel;
36   private JPanel jTRPanel;
37   private JPanel jInputTriggersPanel;
38   private JPanel jOutputTriggersPanel;
39   private JPanel jContractsPanel;
40   private JTabbedPane jTabbedPane;
41   
42   /** Creates new form NetNodeBrowser */
43   public NetNodeBrowser(String JavaDoc nodeName)
44   {
45     this.nodeName = nodeName;
46     
47     initNodeConnection();
48     initComponents();
49   }
50   
51   private void initNodeConnection()
52   {
53     nodeName = nodeName.trim();
54     if (!nodeName.toLowerCase().startsWith("sofa://")) nodeName = "sofa://" + nodeName;
55
56     NodeInfo nodeInfo = new NodeInfo();
57     try
58     {
59       nodeInfo.setNodeName(nodeName);
60     }
61     catch (NodeInfo.InvalidNodeNameException e)
62     {
63       JOptionPane.showMessageDialog(this, "Invalid name of SOFAnet node.\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
64       System.exit(1);
65     }
66     
67     try
68     {
69       admin = (RMIAdminInterface)Naming.lookup("rmi://" + nodeInfo.getAddressAndPort() + "/SOFAnet/RMIAdminServer");
70     }
71     catch (NotBoundException JavaDoc e)
72     {
73       JOptionPane.showMessageDialog(this, "Cannot connect to SOFAnet node.\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
74       System.exit(1);
75     }
76     catch (MalformedURLException JavaDoc e)
77     {
78       JOptionPane.showMessageDialog(this, "Cannot connect to SOFAnet node.\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
79       System.exit(1);
80     }
81     catch (RemoteException JavaDoc e)
82     {
83       JOptionPane.showMessageDialog(this, "Cannot connect to SOFAnet node.\n" + e, "Error", JOptionPane.ERROR_MESSAGE);
84       System.exit(1);
85     }
86   }
87   
88   private void initComponents()
89   {
90     jTabbedPane = new JTabbedPane();
91     jOpsPanel = new OperationsPanel(admin);
92     jBinLicPanel = new BinBundlesAndLicencesPanel(admin);
93     jOffersPanel = new BundleOffersPanel(admin);
94     jLocalInfosPanel = new LocalInfosPanel(admin);
95     jTRPanel = new TRPanel(admin);
96     jInputTriggersPanel = new InputTriggersPanel(admin);
97     jOutputTriggersPanel = new OutputTriggersPanel(admin);
98     jContractsPanel = new ContractsPanel(admin);
99
100     setTitle("SOFAnet Node Browser [" + nodeName + "]");
101     
102     addWindowListener(new java.awt.event.WindowAdapter JavaDoc()
103     {
104       public void windowClosing(java.awt.event.WindowEvent JavaDoc evt)
105       {
106         exitForm(evt);
107       }
108     });
109
110     jTabbedPane.addTab("Operations", jOpsPanel);
111     jTabbedPane.addTab("Binary Bundles and Licences", jBinLicPanel);
112     jTabbedPane.addTab("Bundle Offers", jOffersPanel);
113     jTabbedPane.addTab("Local Infos", jLocalInfosPanel);
114     jTabbedPane.addTab("TR", jTRPanel);
115     jTabbedPane.addTab("Input Triggers", jInputTriggersPanel);
116     jTabbedPane.addTab("Output Triggers", jOutputTriggersPanel);
117     jTabbedPane.addTab("Contracts", jContractsPanel);
118
119     getContentPane().add(jTabbedPane, java.awt.BorderLayout.CENTER);
120
121     pack();
122     
123     setLocationRelativeTo(null);
124   }
125   
126   
127   /** Exit the Application */
128   private void exitForm(java.awt.event.WindowEvent JavaDoc evt)
129   {
130     System.exit(0);
131   }
132   
133   /**
134    * @param args the command line arguments
135    */

136   public static void main(String JavaDoc args[])
137   {
138     String JavaDoc nodeName = "";
139     if (args.length == 0 || args[0].trim().length() == 0)
140     {
141       try
142       {
143         nodeName = InetAddress.getLocalHost().getHostName();
144       }
145       catch (UnknownHostException JavaDoc e)
146       {
147         System.err.println("Missing name of SOFAnet node and can't get the host name.");
148         System.exit(1);
149       }
150       
151       String JavaDoc rmiPort = System.getProperty(VMProperties.RMI_PORT, null);
152       
153       if (rmiPort != null) nodeName += ":" + rmiPort;
154       System.out.println("Missing name of SOFAnet node, using '" + nodeName + "'");
155     }
156     else nodeName = args[0];
157     
158     try
159     {
160       UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
161     }
162     catch (Exception JavaDoc e)
163     {
164     }
165     
166     new NetNodeBrowser(nodeName).show();
167   }
168   
169 }
170
Popular Tags