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

SNMP编程

开发平台:

C/C++

  1. /* $Id: AdventSasDemo.java,v 1.3 2002/09/09 05:50:39 parasuraman Exp $ */
  2. /*
  3.  * @(#)AdventSasDemo.java
  4.  * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the associated COPYRIGHTS file for more details.
  6.  */
  7. import java.awt.*;
  8. import java.awt.event.*;
  9. import java.util.*;
  10. import java.io.*;
  11. import java.applet.Applet;
  12. import com.adventnet.snmp.snmp2.*;
  13. public class AdventSasDemo extends Applet implements ActionListener {
  14. /** Some of the widgets in the main applet window. */
  15.   TextField host,community,setvalue, currentDir,resultArea;
  16.   java.awt.List childList,listDir;
  17.   CreateDirDialog dirDialog;
  18.   SaveFileDialog saveDialog;
  19.   AppendFileDialog appendDialog;
  20.   String htmlDir;
  21.     
  22. /** The frame extention class we've created for SNMP operations */
  23.   SasClientFunction scFrame;
  24. /** The fonts to be used */
  25.     Font font = new Font("Helvetica",Font.PLAIN,12);
  26.     Font fontb = new Font("Helvetica",Font.BOLD,12);
  27.     Font fontc = new Font("Courier",Font.PLAIN,12);
  28. /** The applets init method sets up the GUI */
  29.   public void init() {
  30.     setFont(font);
  31.     setBackground(Color.lightGray);
  32.     GridBagLayout gridbag = new GridBagLayout();
  33.     GridBagConstraints c = new GridBagConstraints();  
  34.     setLayout(gridbag);
  35.     c.fill = GridBagConstraints.BOTH;
  36.     c.weightx = 1.0;
  37.     c.insets = new Insets(0,0,3,0);
  38.     
  39.     c.gridwidth = 1;
  40.     Label label = new Label("Current Directory");
  41.     label.setFont(fontb);
  42.     gridbag.setConstraints(label,c);
  43.     add(label);
  44.     c.gridwidth = GridBagConstraints.REMAINDER;
  45.     currentDir = new TextField();
  46.     currentDir.setEditable(false);
  47.     gridbag.setConstraints(currentDir,c);
  48.     add(currentDir);
  49.     c.gridwidth = 1;
  50.     label = new Label("Directories");
  51.     label.setFont(fontb);
  52.     gridbag.setConstraints(label,c);
  53.     add(label);
  54.     c.gridwidth = 1;
  55. c.gridwidth = GridBagConstraints.REMAINDER;
  56.     label = new Label("Files");
  57. label.setFont(fontb);
  58.     gridbag.setConstraints(label,c);
  59.     add(label);
  60.     c.weighty = 1.0;
  61.     c.gridheight = 12;
  62.     c.gridwidth = 1;
  63.     listDir = new java.awt.List(12, false);
  64.     listDir.setFont(fontb);
  65.     listDir.setBackground(Color.lightGray);
  66. listDir.addActionListener(this);
  67.     gridbag.setConstraints(listDir,c);
  68.     add(listDir);
  69.         
  70.     c.gridwidth = 1;
  71.     c.gridwidth = GridBagConstraints.REMAINDER;
  72.     childList = new java.awt.List(12, false);
  73.     childList.setFont(fontb);
  74.     childList.setBackground(Color.lightGray);
  75.     gridbag.setConstraints(childList,c);
  76.     add(childList);
  77.  
  78.     resultArea = new TextField("AdventNet SAS Demo");
  79.     c.fill = GridBagConstraints.HORIZONTAL;
  80.     c.anchor = GridBagConstraints.NORTH;
  81.     resultArea.setEditable(false);
  82.     resultArea.setFont(fontc);
  83.     gridbag.setConstraints(resultArea,c);
  84.     add(resultArea);
  85.             
  86. // ButtonPanel is a panel sub-class we've defined for a row of buttons
  87.     c.weighty = 0.0;
  88.     c.gridheight = 1;
  89.     String buttons[] = {"CreateDir", "DeleteDir", "SaveFile", "AppendFile", "DeleteFile"};
  90.     ButtonPanel bp = new ButtonPanel(buttons);
  91. bp.setFont(fontb);
  92. Button[] butts = bp.getButtons();
  93. for (int i=0;i<butts.length;i++) butts[i].addActionListener(this);
  94.     gridbag.setConstraints(bp,c);
  95.     add(bp);
  96.     scFrame = new SasClientFunction(this);
  97.     htmlDir = getPrevDir(this.getDocumentBase().getFile());
  98. scFrame.listFiles(htmlDir);
  99.     // We need a dialog for create directory
  100.     // We'll use the CreatDirDialog class - although it's really a frame.
  101.     dirDialog = new CreateDirDialog("Create Directory",true,"Enter Directory Name","",30);
  102.     // pass the snmpFrame object to the dialog
  103.     // since it needs to call the createDir method
  104.     dirDialog.sframe= scFrame;// = new CreateDirDialog("Create Directory",true,"Enter Directory Name","",30);
  105.     
  106.     saveDialog = new SaveFileDialog();
  107.     // pass the snmpFrame object to the dialog
  108.     // since it needs to call the saveFile method
  109.     saveDialog.sframe = scFrame;
  110.     appendDialog = new AppendFileDialog();
  111.     // pass the snmpFrame object to the dialog
  112.     // since it needs to call the appendFile method
  113.     appendDialog.sframe = scFrame;
  114.   } // end of constructor
  115. /** Actions for each of the buttons, choice, and list */
  116.   public void actionPerformed(ActionEvent e) {
  117. resultArea.setText("");
  118. if (e.getActionCommand().equals("SaveFile")) saveDialog.show();
  119.     else if (e.getActionCommand().equals("AppendFile")) appendDialog.show();
  120.     else if (e.getActionCommand().equals("DeleteFile")) scFrame.deleteFile(childList.getSelectedItem());
  121.     else if (e.getActionCommand().equals("CreateDir")) dirDialog.show();
  122.     else if (e.getActionCommand().equals("DeleteDir")) scFrame.deleteDir();
  123.     else scFrame.downTree(e.getActionCommand());
  124.   }
  125.     
  126.   String getPrevDir(String dir) {
  127.     if(dir.endsWith("/"))
  128.       dir = dir.substring(0,dir.length()-1);
  129.     int index = dir.lastIndexOf("/");
  130.     return (dir.substring(0,index+1));
  131.   }
  132. /** The stop method needed to stop any threads, etc. */
  133.   public void stop() {
  134.     if (scFrame == null) return;
  135.     if (scFrame.sasclient == null) return;
  136.     scFrame.sasclient.stop();
  137.       
  138.   }
  139.   
  140. /** To provide applet information */
  141.   public String getAppletInfo() {
  142.     return("SAS Demo from AdventNet,Inc.");
  143.   }
  144. }