?? nsutil.java
字號:
package com.corba.mnq.ns;
import com.corba.mnq.tool.CorbaFacility;
import com.corba.mnq.ui.MNQMutableTreeNode;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeModel;
import java.io.FileInputStream;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
public class NSUtil {
public static JFrame frame = null;
public static JSplitPane splitPane = null;
private static NSHandler handler;
public static void init(JFrame f) {
if (frame != null)
return;
frame = f;
DefaultTreeModel treeModel = new DefaultTreeModel(new MNQMutableTreeNode("NsRoot"));
treeModel.setAsksAllowsChildren(false);
JTree tree = new JTree(treeModel);
tree.setRootVisible(false);
handler = new NSHandler(f, tree);
tree.addMouseListener(handler);
tree.addKeyListener(handler);
splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
JScrollPane treeScrollPane = new JScrollPane(tree);
splitPane.setTopComponent(treeScrollPane);
}
public static void reset() {
if (frame == null)
return;
JFileChooser dlg = new JFileChooser();
dlg.setDialogTitle("OpenNamingServiceIOR");
if (dlg.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
String fname = dlg.getSelectedFile().getPath();
connectNS(fname);
}
}
private static String getIorFromFile(String file) {
String ior = null;
try {
FileInputStream fis = new FileInputStream(file);
String str = "";
while (fis.available() != 0) {
byte[] bA = new byte[fis.available()];
int numRead = fis.read(bA);
System.out.println(numRead);
if (numRead > 0) {
str += new String(bA, 0, numRead);
}
// continue
}
ior = str;
fis.close();
// java.io.BufferedReader in =
// new java.io.BufferedReader(new java.io.FileReader( file
// ) );
// ior = in.readLine();
// while (ior.indexOf("IOR:") != 0)
// ior = in.readLine();
// in.close();
} catch (java.io.IOException io) {
io.printStackTrace();
}
return ior;
}
private static void connectNS(String iorfile) {
NamingContextExt rootContext = null;
try {
String ior = getIorFromFile(iorfile);
if (ior == null) {
JOptionPane.showMessageDialog(frame, "Invalid IOR file", "Operation tip",
JOptionPane.ERROR_MESSAGE);
}
rootContext = NamingContextExtHelper.narrow(CorbaFacility.orb.string_to_object(ior));
// org.omg.CORBA.Object obj =
// CorbaFacility.orb.string_to_object("corbaloc:ssliop:" +
// "1.2@140.231.249.169"
// + ":" + "2062" + "/StandardNS/NameServer-POA/_root");
// System.out.println(obj.toString());
// rootContext = NamingContextExtHelper.narrow(obj);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(frame, "Could not find name service", "Operation tip",
JOptionPane.ERROR_MESSAGE);
return;
}
if (rootContext == null) {
JOptionPane.showMessageDialog(frame, "Could not find name service", "Operation tip",
JOptionPane.ERROR_MESSAGE);
return;
}
NSTable nstab = new NSTable();
NSTree tree = new NSTree(nstab, rootContext, CorbaFacility.orb);
JScrollPane tableScrollPane = new JScrollPane(nstab);
JScrollPane treeScrollPane = new JScrollPane(tree);
splitPane.setTopComponent(treeScrollPane);
splitPane.setBottomComponent(tableScrollPane);
// splitPane.setDividerLocation(200);
// splitPane.setDividerSize(2);
// tree.update();
handler.reset(tree, nstab);
tree.addMouseListener(handler);
tree.addKeyListener(handler);
nstab.addMouseListener(handler);
nstab.addKeyListener(handler);
}
/**
* @param args
*/
public static void main_(String[] args) {
// TODO Auto-generated method stub
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -