CorbaDemo.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:20k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /* $Id: CorbaDemo.src,v 1.3 2002/09/09 05:45:01 tonyjpaul Exp $ */
  2. /*
  3.  * @(#)CorbaDemo.java
  4.  * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the COPYRIGHTS file for more 
  6.  */
  7. import javax.swing.*;
  8. import com.adventnet.snmp.corba.*;
  9. import org.omg.CosNaming.*;
  10. import org.omg.CORBA.*;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. import javax.swing.border.*;
  14. public class CorbaDemo extends JFrame implements ActionListener, ItemListener{
  15. JTextField hosttext = null;
  16. JTextField communitytext = null;
  17. JTextField wcommunitytext = null;
  18. JTextField porttext = null;
  19. JComboBox versionChoice = null;
  20. JTextField oidtext = null;
  21. JTextField usernametext = null;
  22. JTextField contextidtext= null;
  23. JTextField contextnametext = null;
  24. JTextField privpasswordtext = null;
  25. JTextField authpasswordtext = null;
  26. JButton browseBut = null;
  27. JComboBox secChoice = null;
  28. JComboBox authprotocolChoice = null;
  29. JTextArea resulttext = null;
  30. JLabel statuslabel = null;
  31. JComboBox operationChoice = null;
  32. JButton resultBut = null;
  33. JButton loadBut = null;
  34. JTextField mibtext = null;
  35. JTextField maxreptext = null;
  36. JTextField settext = null;
  37. FileDialog localFd = null;
  38. String []versioncontents = {"v1","v2c","v3"};
  39. String []seccontents = {"noAuth,NoPriv","Auth,NoPriv","Auth,Priv"};
  40. String []authprotocolcontents = {"MD5","SHA"};
  41. String []operationcontents = {"GET","GETNEXT","GET_BULK","TABLE","SET"};
  42. int VERSION1 = 0;
  43. int VERSION2C = 1;
  44. int VERSION3 = 3;
  45. int GET = 0;
  46. int GETNEXT = 1;
  47. int SET = 2;
  48. int GET_BULK = 3;
  49. int TABLE = 4;
  50. int version = VERSION1;
  51. int operation = GET; 
  52. String authpassword = "";
  53. String privpassword = "";
  54. int authprotocol = 21;
  55. com.adventnet.snmp.corba.SnmpTarget target = null;
  56. com.adventnet.snmp.corba.SnmpFactory f = null;
  57. org.omg.CORBA.ORB orb = null;
  58. boolean loading = false;
  59. public CorbaDemo(String args[]) {
  60. this.args = args;
  61. setTitle("AdventNet SNMP CORBA Demo");
  62. JPanel panel = new JPanel();
  63. setPanel(panel);
  64. GridBagLayout l = new GridBagLayout();
  65. GridBagConstraints c = new GridBagConstraints();
  66. getContentPane().setLayout(l);
  67. c.fill = GridBagConstraints.BOTH;
  68. c.gridwidth = 1;
  69. c.weightx = 1;
  70. c.weighty = 1;
  71. c.gridwidth = 0;
  72. l.setConstraints(panel,c);
  73. getContentPane().add(panel);
  74. setVisible(true);
  75. setSize(700,450);
  76. try{
  77. resulttext.setText("Initializing the ORB");
  78. orb = org.omg.CORBA.ORB.init(args,null);
  79. org.omg.CORBA.Object obj = orb.resolve_initial_references("NameService");
  80. resulttext.setText("Resolved initial references");
  81. NamingContext ncRef = NamingContextHelper.narrow(obj);
  82. NameComponent nc = new NameComponent( "AdventnetSnmpFactory","");
  83. NameComponent [] path = {nc};
  84. f = com.adventnet.snmp.corba.SnmpFactoryHelper.narrow( ncRef.resolve(path));
  85. resulttext.setText("Got the SnmpFactory");
  86. //com.adventnet.snmp.corba.SnmpTarget target = f.createTarget();
  87. target = f.createTarget();
  88. resulttext.setText("Got the SnmpTarget");
  89. resultBut.setActionCommand("Result");
  90. versionChoice.setActionCommand("Version");
  91. operationChoice.setActionCommand("Operation");
  92. loadBut.setActionCommand("Load"); 
  93. browseBut.setActionCommand("Browse");
  94. secChoice.setActionCommand("SecLevel");
  95. authprotocolChoice.setActionCommand("AuthProtocol");
  96. secChoice.addItemListener(this);
  97. resultBut.addActionListener(this);
  98. versionChoice.addItemListener(this);
  99. operationChoice.addItemListener(this);
  100. loadBut.addActionListener(this); 
  101. browseBut.addActionListener(this);
  102. WindowListener wl = new WindowAdapter() {
  103. public void windowClosing(WindowEvent e) {
  104. f.destroyTarget(target.getName());
  105. target = null;
  106. f = null;
  107. System.exit(0);
  108. }
  109. };      
  110. addWindowListener(wl);
  111. authprotocolChoice.addItemListener(this);
  112. } catch(Exception e) {
  113. resulttext.setText("Exception:"+e.toString());
  114. }
  115. }
  116. String args[] = null;
  117. public static void main(String args [] ) {
  118. new CorbaDemo(args);
  119. }
  120. private void setPanel(JPanel panel) {
  121. JPanel p0 = new JPanel();
  122. JPanel p1 = new JPanel();
  123. JPanel p2 = new JPanel();
  124. JPanel p3 = new JPanel();
  125. JPanel p4 = new JPanel();
  126. JPanel p5 = new JPanel();
  127. GridBagLayout l = new GridBagLayout();
  128. GridBagConstraints c = new GridBagConstraints();
  129. GridBagLayout l0 = new GridBagLayout();
  130. GridBagConstraints c0 = new GridBagConstraints();
  131. GridBagLayout l1 = new GridBagLayout();
  132. GridBagConstraints c1 = new GridBagConstraints();
  133. GridBagLayout l2 = new GridBagLayout();
  134. GridBagConstraints c2 = new GridBagConstraints();
  135. GridBagLayout l3 = new GridBagLayout();
  136. GridBagConstraints c3 = new GridBagConstraints();
  137. GridBagLayout l4 = new GridBagLayout();
  138. GridBagConstraints c4 = new GridBagConstraints();
  139. GridBagLayout l5 = new GridBagLayout();
  140. GridBagConstraints c5 = new GridBagConstraints();
  141. panel.setLayout(l);
  142. p0.setLayout(l0);
  143. p1.setLayout(l1);
  144. p2.setLayout(l2);
  145. p3.setLayout(l3);
  146. p4.setLayout(l4);
  147. p4.setLayout(l5);
  148. JLabel hostlabel = new JLabel("Host");
  149. hosttext = new JTextField("localhost");
  150. c1.gridwidth = 1;
  151. c1.weightx = 1;
  152. c1.gridx = 0;
  153. c1.fill = GridBagConstraints.HORIZONTAL;
  154. l1.setConstraints(hostlabel,c1);
  155. c1.gridx = 1;
  156. c1.insets = new Insets(0,0,0,50);
  157. l1.setConstraints(hosttext,c1);
  158. JLabel communitylabel = new JLabel("Community");
  159. communitytext = new JTextField("public");
  160. c1.gridx = 2;
  161. c1.weightx = 0;
  162. c1.insets = new Insets(0,0,0,0);
  163. l1.setConstraints(communitylabel,c1);
  164. c1.gridx = 3;
  165. c1.weightx = 1;
  166. l1.setConstraints(communitytext,c1);
  167. JLabel portlabel = new JLabel("Port");
  168. porttext = new JTextField("161");
  169. c1.weightx = 0;
  170. c1.gridx = 4;
  171. c1.insets = new Insets(0,0,0,0);
  172. l1.setConstraints(portlabel,c1);
  173. c1.insets = new Insets(0,0,0,0);
  174. c1.weightx = 1;
  175. c1.gridx = 5;
  176. l1.setConstraints(porttext,c1);
  177. p1.add(hostlabel);
  178. p1.add(hosttext);
  179. p1.add(communitylabel);
  180. p1.add(communitytext);
  181. p1.add(portlabel);
  182. p1.add(porttext);
  183. c1.gridy = 1;
  184. JLabel oidlabel = new JLabel("Object ID");
  185. oidtext = new JTextField("1.5.0",20);
  186. c1.gridx = 0;
  187. c1.weightx = 0;
  188. l1.setConstraints(oidlabel,c1);
  189. c1.gridx = 1;
  190. c1.weightx = 1;
  191. c1.insets = new Insets(0,0,0,0);
  192. l1.setConstraints(oidtext,c1);
  193. JLabel wcommunitylabel = new JLabel("WriteComm");
  194. wcommunitytext = new JTextField();
  195. c1.gridx = 2;
  196. c1.weightx = 0;
  197. c1.insets = new Insets(0,0,0,0);
  198. l1.setConstraints(wcommunitylabel,c1);
  199. c1.gridx = 3;
  200. c1.weightx = 1;
  201. l1.setConstraints(wcommunitytext,c1);
  202. JLabel versionlabel = new JLabel("Version");
  203. versionChoice = new JComboBox();
  204. c1.gridx = 4;
  205. c1.weightx = 0;
  206. c1.insets = new Insets(0,0,0,0);
  207. l1.setConstraints(versionlabel,c1);
  208. c1.insets = new Insets(0,0,0,0);
  209. c1.gridx = 5;
  210. c1.weightx = 1;
  211. l1.setConstraints(versionChoice,c1);
  212. p1.add(oidlabel);
  213. p1.add(oidtext);
  214. p1.add(wcommunitylabel);
  215. p1.add(wcommunitytext);
  216. p1.add(versionlabel);
  217. p1.add(versionChoice);
  218. loadBut = new JButton("load mibs");
  219. browseBut = new JButton("browse mibfile");
  220. mibtext = new JTextField("../../mibs/RFC1213-MIB");
  221. c2.gridwidth = 1;
  222. c2.fill = GridBagConstraints.NONE;
  223. c2.weightx = 0;
  224. c2.gridx = 0;
  225. c2.insets = new Insets(0,0,0,10);
  226. l2.setConstraints(browseBut,c2);
  227. c2.gridx = 1;
  228. c2.weightx = 1;
  229. c2.insets = new Insets(0,0,0,0);
  230. c2.fill = GridBagConstraints.HORIZONTAL;
  231. l2.setConstraints(mibtext,c2);
  232. c2.gridx = 2;
  233. c2.weightx = 0;
  234. c2.fill = GridBagConstraints.NONE;
  235. c2.insets = new Insets(0,10,0,10);
  236. l2.setConstraints(loadBut,c2);
  237. JLabel usernamelabel = new JLabel("UserName");
  238. usernametext = new JTextField();
  239. c2.gridx = 3;
  240. c2.insets = new Insets(0,0,0,0);
  241. l2.setConstraints(usernamelabel,c2);
  242. c2.fill = GridBagConstraints.HORIZONTAL;
  243. c2.gridx = 4;
  244. c2.weightx = 1;
  245. l2.setConstraints(usernametext,c2);
  246. p2.add(browseBut);
  247. p2.add(mibtext);
  248. p2.add(loadBut);
  249. p2.add(usernamelabel);
  250. p2.add(usernametext);
  251. JLabel contextidlabel = new JLabel("Context ID");
  252. contextidtext = new JTextField();
  253. JLabel contextnamelabel = new JLabel("Context Name");
  254. contextnametext = new JTextField();
  255. JLabel seclabel = new JLabel("Security Level");
  256. secChoice = new JComboBox();
  257. JLabel authprotocollabel = new JLabel("AuthProtocol");
  258. authprotocolChoice = new JComboBox();
  259. JLabel authpasswordlabel = new JLabel("Auth Password");
  260. authpasswordtext = new JPasswordField();
  261. JLabel privpasswordlabel = new JLabel("Priv Password");
  262. privpasswordtext = new JPasswordField();
  263. c3.gridwidth = 1;
  264. c3.fill = GridBagConstraints.HORIZONTAL;
  265. c3.weightx = 1;
  266. c3.gridx = 0;
  267. l3.setConstraints(contextidlabel,c3);
  268. c3.gridx = 1;
  269. l3.setConstraints(contextidtext,c3);
  270. c3.gridx = 2;
  271. l3.setConstraints(contextnamelabel,c3);
  272. c3.gridx = 3;
  273. l3.setConstraints(contextnametext,c3);
  274. c3.gridy = 1;
  275. c3.gridx = 0;
  276. l3.setConstraints(seclabel,c3);
  277. c3.gridx = 1;
  278. l3.setConstraints(secChoice,c3);
  279. c3.gridx = 2;
  280. l3.setConstraints(authprotocollabel,c3);
  281. c3.gridx = 3;
  282. l3.setConstraints(authprotocolChoice,c3);
  283. c3.gridy = 2;
  284. c3.gridx = 0;
  285. l3.setConstraints(authpasswordlabel,c3);
  286. c3.gridx = 1;
  287. l3.setConstraints(authpasswordtext,c3);
  288. c3.gridx = 2;
  289. l3.setConstraints(privpasswordlabel,c3);
  290. c3.gridx = 3;
  291. l3.setConstraints(privpasswordtext,c3);
  292. p3.add(contextidlabel);
  293. p3.add(contextidtext);
  294. p3.add(contextnamelabel);
  295. p3.add(contextnametext);
  296. p3.add(seclabel);
  297. p3.add(secChoice);
  298. p3.add(authprotocollabel);
  299. p3.add(authprotocolChoice);
  300. p3.add(authpasswordlabel);
  301. p3.add(authpasswordtext);
  302. p3.add(privpasswordlabel);
  303. p3.add(privpasswordtext);
  304. JLabel maxreplabel = new JLabel("Max-Repeatitions");
  305. maxreptext = new JTextField("50",3);
  306. JLabel setlabel = new JLabel("Set Value");
  307. settext = new JTextField(10);
  308. settext.setEditable(false);
  309. resultBut = new JButton("Click to GET");
  310. operationChoice = new JComboBox();
  311. c4.gridwidth = 1;
  312. c4.weightx = 1;
  313. c4.gridy = 0;
  314. c4.fill = GridBagConstraints.HORIZONTAL;
  315. l.setConstraints(maxreplabel,c4);
  316. c4.gridx = 1;
  317. l.setConstraints(maxreptext,c4);
  318. c4.gridx = 2;
  319. c4.insets = new Insets(0,3,0,0);
  320. l.setConstraints(setlabel,c4);
  321. c4.gridx = 3;
  322. c4.insets = new Insets(0,0,0,4);
  323. l.setConstraints(settext,c4);
  324. c4.gridx = 4;
  325. l.setConstraints(operationChoice,c4);
  326. c4.gridx = 5;
  327. l.setConstraints(maxreplabel,c4);
  328. p4.add(maxreplabel);
  329. p4.add(maxreptext);
  330. p4.add(setlabel);
  331. p4.add(settext);
  332. p4.add(operationChoice);
  333. p4.add(resultBut);
  334. c.gridy = 0;
  335. c.gridwidth = 0;
  336. c.fill = GridBagConstraints.BOTH;
  337. c.weightx = 1;
  338. c.weighty = 1;
  339. c.insets = new Insets(0,0,20,0);
  340. l.setConstraints(p0,c);
  341. c.gridy = 1;
  342. c.insets = new Insets(0,0,20,0);
  343. l.setConstraints(p1,c);
  344. c.gridy = 2;
  345. c.insets = new Insets(0,0,20,0);
  346. l.setConstraints(p2,c);
  347. c.gridy = 3;
  348. c.insets = new Insets(0,0,20,0);
  349. l.setConstraints(p3,c);
  350. c.gridy = 4;
  351. c.insets = new Insets(0,0,20,0);
  352. l.setConstraints(p4,c);
  353. c.gridy = 5;
  354. c.insets = new Insets(0,0,0,0);
  355. l.setConstraints(p5,c);
  356. panel.add(p0);
  357. panel.add(p1);
  358. panel.add(p2);
  359. panel.add(p3);
  360. panel.add(p4);
  361. panel.add(p5);
  362. JLabel title = new JLabel("AdventNet SNMP CORBA Demo");
  363. title.setOpaque(true);
  364. title.setBackground(Color.pink);
  365. p0.add(title);
  366. c5.fill = GridBagConstraints.HORIZONTAL;
  367. c5.gridwidth = 1;
  368. c5.weightx = 1;
  369. resulttext = new JTextArea(1,50);
  370. resulttext.setEditable(false);
  371. JScrollPane pan = new JScrollPane(resulttext);
  372. resulttext.setLineWrap(true);
  373. l5.setConstraints(resulttext,c5);
  374. p5.add(pan);
  375. panel.setBorder(BorderFactory.createTitledBorder( new EtchedBorder(Color.white, Color.gray), "")); 
  376. p5.setBorder(BorderFactory.createTitledBorder( new EtchedBorder(Color.white, Color.gray), "")); 
  377. setComboBoxModel(versionChoice,versioncontents);
  378. setComboBoxModel(secChoice,seccontents);
  379. setComboBoxModel(authprotocolChoice,authprotocolcontents);
  380. contextidtext.setEnabled(false);
  381. contextnametext.setEnabled(false);
  382. usernametext.setEnabled(false);
  383. secChoice.setEnabled(false);
  384. authprotocolChoice.setEnabled(false);
  385. authpasswordtext.setEnabled(false);
  386. privpasswordtext.setEnabled(false);
  387. setComboBoxModel(operationChoice,operationcontents);
  388. }
  389. private void setComboBoxModel(JComboBox c,String [] str) {
  390. for(int i=0;i<str.length;i++)
  391. c.addItem(str[i]);
  392. }
  393. public void actionPerformed(ActionEvent e) {
  394. if(e.getActionCommand().equals("Result")){
  395. resulttext.setText("");
  396. if (hosttext.getText().equals("")) {
  397. resulttext.setText("Host Field is empty");
  398. return;
  399. }
  400. else
  401. if( operation == GET || operation == GETNEXT 
  402. || operation == GET_BULK 
  403. || operation == SET)
  404. target.setTargetHost(hosttext.getText());
  405. if (oidtext.getText().equals("")) {
  406. resulttext.setText("Object ID Field is empty");
  407. return;
  408. }
  409. else
  410. if( operation == GET || operation == GETNEXT 
  411. || operation == GET_BULK 
  412. || operation == SET)
  413. target.setObjectID(oidtext.getText());
  414. if( operation == GET || operation == GETNEXT 
  415. || operation == GET_BULK 
  416. || operation == SET)
  417. target.setCommunity(communitytext.getText());
  418. try{
  419. if (!porttext.getText().equals(""))
  420. if( operation == GET || operation == GETNEXT 
  421. || operation == GET_BULK 
  422. || operation == SET)
  423. target.setTargetPort(Integer.parseInt(porttext.getText()));
  424. } catch(NumberFormatException nfe) {
  425. resulttext.setText("Numberformat Exception :"+nfe.toString());
  426. return;
  427. }
  428. if( operation == GET || operation == GETNEXT 
  429. || operation == GET_BULK 
  430. || operation == SET)
  431. {
  432. if (versionChoice.getSelectedItem().toString().equals("v1"))
  433. target.setSnmpVersion(0);
  434. else if (versionChoice.getSelectedItem().toString().equals("v2c"))
  435. target.setSnmpVersion(1);
  436. else if (versionChoice.getSelectedItem().toString().equals("v3")) {
  437. target.setSnmpVersion(3);
  438. target.setContextName(contextnametext.getText());
  439. target.setContextID(contextidtext.getText());
  440. if (usernametext.getText().equals("")) {
  441. resulttext.setText("UserName Field is empty");
  442. return;
  443. }
  444. else
  445. target.setPrincipal(usernametext.getText());
  446. target.setAuthProtocol(authprotocol);
  447. target.setAuthPassword(authpasswordtext.getText());
  448. target.setPrivPassword(privpasswordtext.getText());
  449. }
  450. }
  451. if ( operation == GET) {
  452. try{
  453. String result = target.snmpGet();
  454. if (result != null)
  455. resulttext.setText(result);
  456. else {
  457. resulttext.setText("Response is null");
  458. return;
  459. }
  460. }catch(Exception gete){
  461. resulttext.setText("Error :"+gete.toString());
  462. return;
  463. }
  464. }
  465. else if ( operation == GETNEXT) {
  466. try{
  467. String result = target.snmpGetNext();
  468. if (result != null)
  469. resulttext.setText(result);
  470. else {
  471. resulttext.setText("Response is null");
  472. return;
  473. }
  474. }catch(Exception gete){
  475. resulttext.setText("Error :"+gete.toString());
  476. return;
  477. }
  478. }
  479. else if ( operation == TABLE) {
  480. try{
  481. CorbaTableUi t = new CorbaTableUi(args, versionChoice.getSelectedItem().toString(), hosttext.getText(), communitytext.getText(), porttext.getText(), null, null, usernametext.getText(), authprotocolChoice.getSelectedItem().toString(), authpasswordtext.getText(), privpasswordtext.getText(), contextidtext.getText(), contextnametext.getText(), mibtext.getText(), oidtext.getText());
  482. }catch(Exception eee){
  483. System.out.println("Error in creating table "+eee.toString());
  484. }
  485. }
  486. else if ( operation == SET) {
  487. try {
  488. if (!wcommunitytext.getText().equals("")) 
  489. target.setWriteCommunity(wcommunitytext.getText());
  490. String result = target.snmpSet(settext.getText());
  491. if( result != null)
  492. resulttext.setText(result);
  493. else {
  494. resulttext.setText("Response is null");
  495. return;
  496. }
  497. }catch(Exception se) {
  498. resulttext.setText("Exception in setting :"+se.toString());
  499. }
  500. }
  501. else if ( operation == GET_BULK && version > VERSION1) {
  502. try{
  503. if (maxreptext.getText().equals("")) {
  504. resulttext.setText("Max-Rep Field is empty");
  505. return;
  506. }
  507. else
  508. target.setMaxRepetitions(Integer.parseInt(maxreptext.getText()));
  509. } catch(NumberFormatException nfe) {
  510. resulttext.setText("Numberformat Exception :"+nfe.toString());
  511. }
  512. try{
  513. String[][] resultstr =  target.snmpGetBulkList();
  514. resulttext.setText("");
  515. if (resultstr == null)
  516. {
  517. resulttext.setText("Response is null");
  518. return;
  519. }
  520. for(int i=0;i<resultstr[0].length;i++)
  521. resulttext.append(resultstr[0][i]+"n");
  522. }catch(Exception gete){
  523. resulttext.setText("Error :"+gete.toString());
  524. return;
  525. }
  526. }
  527. }
  528. else if(e.getActionCommand().equals("Load")){
  529. try{
  530. target.loadMibs(mibtext.getText());
  531. }catch(Exception ee) {
  532. resulttext.setText("Exception in loading Mibs : "+ee.toString());
  533. }
  534. }
  535. else if(e.getActionCommand().equals("Browse")){
  536. if (loading) return;
  537. loading = true;
  538. if(localFd == null) {
  539. JFrame frm =(JFrame)SwingUtilities.getAncestorOfClass(java.awt.Frame.class,browseBut);  
  540. localFd = new FileDialog(frm, "Config Load Dialog", FileDialog.LOAD);
  541. localFd.setSize(700,300);
  542. //Utils.centerWindow(localFd);
  543. }
  544. localFd.show();
  545. String dir = localFd.getDirectory();
  546. String file = localFd.getFile();
  547. if((dir != null)&&(file != null))
  548. {
  549. String mibname = dir + file;
  550. mibname = mibname.trim();
  551. if(mibname.indexOf(" ")>=0) {
  552. mibname = """+mibname+""";
  553. }
  554. mibtext.setText(mibname);
  555. }              
  556. loading = false;
  557. }
  558. }
  559. public void itemStateChanged(ItemEvent e) {
  560. if(((JComboBox)e.getSource()).getActionCommand().equals("Version")){
  561. contextidtext.setEnabled(false);
  562. contextnametext.setEnabled(false);
  563. usernametext.setEnabled(false);
  564. secChoice.setEnabled(false);
  565. authprotocolChoice.setEnabled(false);
  566. authpasswordtext.setEnabled(false);
  567. privpasswordtext.setEnabled(false);
  568. communitytext.setEnabled(true);
  569. if (e.getItem().toString().equals("v1")){
  570. version = VERSION1;
  571. }
  572. else if (e.getItem().toString().equals("v2c")){
  573. version = VERSION2C;
  574. }
  575. else if (e.getItem().toString().equals("v3")) {
  576. version = VERSION3;
  577. contextidtext.setEnabled(true);
  578. contextnametext.setEnabled(true);
  579. usernametext.setEnabled(true);
  580. secChoice.setEnabled(true);
  581. secChoice.setSelectedItem("noAuth,NoPriv");
  582. }
  583. communitytext.setEnabled(false);
  584. }
  585. else if(((JComboBox)e.getSource()).getActionCommand().equals("SecLevel")){
  586. authprotocolChoice.setEnabled(false);
  587. authpasswordtext.setEnabled(false);
  588. privpasswordtext.setEnabled(false);
  589. if (e.getItem().toString().equals("Auth,NoPriv")) {
  590. authprotocolChoice.setEnabled(true);
  591. authpasswordtext.setEnabled(true);
  592. privpasswordtext.setText("");
  593. }
  594. else if (e.getItem().toString().equals("Auth,Priv")) {
  595. privpasswordtext.setEnabled(true);
  596. authprotocolChoice.setEnabled(true);
  597. authpasswordtext.setEnabled(true);
  598. }
  599. else {
  600. authpasswordtext.setText("");
  601. privpasswordtext.setText("");
  602. }
  603. }
  604. else if(((JComboBox)e.getSource()).getActionCommand().equals("AuthProtocol")){
  605. if (e.getItem().toString().equals("MD5"))
  606. authprotocol = 21;
  607. else if (e.getItem().toString().equals("SHA"))
  608. authprotocol = 22;
  609. }
  610. else if(((JComboBox)e.getSource()).getActionCommand().equals("Operation")){
  611. settext.setEditable(false);
  612. resultBut.setText("Click to "+e.getItem().toString());
  613. if (e.getItem().toString().equals("GET"))
  614. operation = GET;
  615. else if (e.getItem().toString().equals("GETNEXT"))
  616. operation = GETNEXT;
  617. else if (e.getItem().toString().equals("GET_BULK"))
  618. operation = GET_BULK;
  619. else if (e.getItem().toString().equals("TABLE"))
  620. operation = TABLE;
  621. else if (e.getItem().toString().equals("SET")){
  622. operation = SET;
  623. settext.setEditable(true);
  624. }
  625. }
  626. }
  627. }