AdventSasDemo.java.txt
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:5k
- /* $Id: AdventSasDemo.java,v 1.3 2002/09/09 05:50:39 parasuraman Exp $ */
- /*
- * @(#)AdventSasDemo.java
- * Copyright (c) 1996-2003 AdventNet, Inc. All Rights Reserved.
- * Please read the associated COPYRIGHTS file for more details.
- */
- import java.awt.*;
- import java.awt.event.*;
- import java.util.*;
- import java.io.*;
- import java.applet.Applet;
- import com.adventnet.snmp.snmp2.*;
- public class AdventSasDemo extends Applet implements ActionListener {
- /** Some of the widgets in the main applet window. */
- TextField host,community,setvalue, currentDir,resultArea;
- java.awt.List childList,listDir;
- CreateDirDialog dirDialog;
- SaveFileDialog saveDialog;
- AppendFileDialog appendDialog;
- String htmlDir;
-
- /** The frame extention class we've created for SNMP operations */
- SasClientFunction scFrame;
- /** The fonts to be used */
- Font font = new Font("Helvetica",Font.PLAIN,12);
- Font fontb = new Font("Helvetica",Font.BOLD,12);
- Font fontc = new Font("Courier",Font.PLAIN,12);
- /** The applets init method sets up the GUI */
- public void init() {
- setFont(font);
- setBackground(Color.lightGray);
- GridBagLayout gridbag = new GridBagLayout();
- GridBagConstraints c = new GridBagConstraints();
- setLayout(gridbag);
- c.fill = GridBagConstraints.BOTH;
- c.weightx = 1.0;
- c.insets = new Insets(0,0,3,0);
-
- c.gridwidth = 1;
- Label label = new Label("Current Directory");
- label.setFont(fontb);
- gridbag.setConstraints(label,c);
- add(label);
- c.gridwidth = GridBagConstraints.REMAINDER;
- currentDir = new TextField();
- currentDir.setEditable(false);
- gridbag.setConstraints(currentDir,c);
- add(currentDir);
- c.gridwidth = 1;
- label = new Label("Directories");
- label.setFont(fontb);
- gridbag.setConstraints(label,c);
- add(label);
- c.gridwidth = 1;
- c.gridwidth = GridBagConstraints.REMAINDER;
- label = new Label("Files");
- label.setFont(fontb);
- gridbag.setConstraints(label,c);
- add(label);
- c.weighty = 1.0;
- c.gridheight = 12;
- c.gridwidth = 1;
- listDir = new java.awt.List(12, false);
- listDir.setFont(fontb);
- listDir.setBackground(Color.lightGray);
- listDir.addActionListener(this);
- gridbag.setConstraints(listDir,c);
- add(listDir);
-
- c.gridwidth = 1;
- c.gridwidth = GridBagConstraints.REMAINDER;
- childList = new java.awt.List(12, false);
- childList.setFont(fontb);
- childList.setBackground(Color.lightGray);
- gridbag.setConstraints(childList,c);
- add(childList);
-
- resultArea = new TextField("AdventNet SAS Demo");
- c.fill = GridBagConstraints.HORIZONTAL;
- c.anchor = GridBagConstraints.NORTH;
- resultArea.setEditable(false);
- resultArea.setFont(fontc);
- gridbag.setConstraints(resultArea,c);
- add(resultArea);
-
- // ButtonPanel is a panel sub-class we've defined for a row of buttons
- c.weighty = 0.0;
- c.gridheight = 1;
- String buttons[] = {"CreateDir", "DeleteDir", "SaveFile", "AppendFile", "DeleteFile"};
- ButtonPanel bp = new ButtonPanel(buttons);
- bp.setFont(fontb);
- Button[] butts = bp.getButtons();
- for (int i=0;i<butts.length;i++) butts[i].addActionListener(this);
- gridbag.setConstraints(bp,c);
- add(bp);
- scFrame = new SasClientFunction(this);
- htmlDir = getPrevDir(this.getDocumentBase().getFile());
- scFrame.listFiles(htmlDir);
- // We need a dialog for create directory
- // We'll use the CreatDirDialog class - although it's really a frame.
- dirDialog = new CreateDirDialog("Create Directory",true,"Enter Directory Name","",30);
- // pass the snmpFrame object to the dialog
- // since it needs to call the createDir method
- dirDialog.sframe= scFrame;// = new CreateDirDialog("Create Directory",true,"Enter Directory Name","",30);
-
- saveDialog = new SaveFileDialog();
- // pass the snmpFrame object to the dialog
- // since it needs to call the saveFile method
- saveDialog.sframe = scFrame;
- appendDialog = new AppendFileDialog();
- // pass the snmpFrame object to the dialog
- // since it needs to call the appendFile method
- appendDialog.sframe = scFrame;
- } // end of constructor
- /** Actions for each of the buttons, choice, and list */
- public void actionPerformed(ActionEvent e) {
- resultArea.setText("");
- if (e.getActionCommand().equals("SaveFile")) saveDialog.show();
- else if (e.getActionCommand().equals("AppendFile")) appendDialog.show();
- else if (e.getActionCommand().equals("DeleteFile")) scFrame.deleteFile(childList.getSelectedItem());
- else if (e.getActionCommand().equals("CreateDir")) dirDialog.show();
- else if (e.getActionCommand().equals("DeleteDir")) scFrame.deleteDir();
- else scFrame.downTree(e.getActionCommand());
- }
-
- String getPrevDir(String dir) {
- if(dir.endsWith("/"))
- dir = dir.substring(0,dir.length()-1);
- int index = dir.lastIndexOf("/");
- return (dir.substring(0,index+1));
- }
- /** The stop method needed to stop any threads, etc. */
- public void stop() {
- if (scFrame == null) return;
- if (scFrame.sasclient == null) return;
- scFrame.sasclient.stop();
-
- }
-
- /** To provide applet information */
- public String getAppletInfo() {
- return("SAS Demo from AdventNet,Inc.");
- }
- }