Source Code Cross Referenced for DwSnmpMibOutputHandler.java in  » Net » JMIBBrowser » com » dwipal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » JMIBBrowser » com.dwipal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.dwipal;
002:
003:        import javax.swing.*;
004:        import java.io.*;
005:        import java.util.*;
006:
007:        public class DwSnmpMibOutputHandler {
008:
009:            JTextArea outputText;
010:            JTextArea outputError;
011:            boolean doLog = false;
012:            boolean autoScroll = true;
013:            static BufferedWriter outfile;
014:
015:            DwSnmpMibOutputHandler() {
016:            }
017:
018:            public void setAutoScroll(boolean as) {
019:                autoScroll = as;
020:            }
021:
022:            public void setOutput(JTextArea o) {
023:                outputText = o;
024:
025:            }
026:
027:            public void setOutputError(JTextArea e) {
028:                outputError = e;
029:            }
030:
031:            void showErrorMessage(String s) {
032:                JOptionPane.showMessageDialog(outputText, s, "Mib Browser",
033:                        JOptionPane.OK_OPTION);
034:            }
035:
036:            public void setLogging(boolean log) {
037:
038:                try {
039:                    if (log == true) {
040:                        String strFileName = getLogFileName();
041:                        outfile = new BufferedWriter(new FileWriter(
042:                                strFileName, true));
043:                        outfile
044:                                .write("\n**********************************************************\n");
045:                        outfile.write("MIB Browser Started at : " + new Date());
046:                        outfile
047:                                .write("\n**********************************************************\n");
048:                        System.out.println("Output log file: " + strFileName);
049:                        this .doLog = true;
050:
051:                        java.util.Timer tmr = new java.util.Timer(true);
052:                        class SnmpTimerTask extends java.util.TimerTask {
053:                            public void run() {
054:                                try {
055:                                    outfile.flush();
056:                                } catch (Exception e) {
057:                                    System.out
058:                                            .println("Error in writing to log file: "
059:                                                    + e);
060:                                }
061:                            }
062:                        }
063:                        ;
064:                        long lFlushTime = getFlushTime();
065:                        System.out.println("Log will be refreshed every "
066:                                + lFlushTime / 1000 + " seconds.");
067:                        tmr.schedule(new SnmpTimerTask(), lFlushTime,
068:                                lFlushTime);
069:
070:                        Thread thrdFlush = new Thread(new Runnable() {
071:                            public void run() {
072:                                try {
073:                                    System.out.println("Have a nice day !!");
074:                                    outfile
075:                                            .write("\n**********************************************************\n");
076:                                    outfile.write("MIB Browser Stopped at : "
077:                                            + new Date());
078:                                    outfile
079:                                            .write("\n**********************************************************\n");
080:                                    outfile.flush();
081:                                    outfile.close();
082:                                } catch (Exception e) {
083:                                    System.out
084:                                            .println("Error while writing to log file: "
085:                                                    + e);
086:                                }
087:                            }
088:                        });
089:                        Runtime.getRuntime().addShutdownHook(thrdFlush);
090:
091:                    } else
092:                        outfile.close();
093:                } catch (Exception e) {
094:                    System.out.println("Error : Cannot log" + e.toString());
095:                    //	doLog=false;
096:                    return;
097:                }
098:                doLog = true;
099:            }
100:
101:            private String getLogFileName() {
102:                String strFileName = System.getProperty("logfilename");
103:                if (strFileName == null) {
104:                    strFileName = "mibbrowser.log";
105:                }
106:                return strFileName;
107:            }
108:
109:            private long getFlushTime() {
110:                long lTime = 0;
111:                String strTime = System.getProperty("logrefreshtime");
112:                if (strTime != null) {
113:                    try {
114:                        lTime = Long.parseLong(strTime);
115:                        lTime = lTime * 1000;
116:                    } catch (Exception e) {
117:                        System.out
118:                                .println("Invalid value for log refresh time. default will be used.");
119:                    }
120:                }
121:
122:                if (lTime < 1000) { // minimum must be 1 second.
123:                    lTime = 60 * 1000; // default is 1 minute.
124:                }
125:                return lTime;
126:            }
127:
128:            public void println(String s) {
129:                if (outputText != null) {
130:                    outputText.append("\n" + s);
131:                    if (autoScroll == true)
132:                        outputText.setCaretPosition(outputText.getDocument()
133:                                .getLength() - 1);
134:                }
135:                //else System.out.println(s);
136:                try {//if(doLog==true)
137:                    {
138:                        outfile.write(s + "\n");
139:                    }
140:                } catch (Exception e) {
141:                    System.out.println(e.toString());
142:                }
143:            }
144:
145:            public void print(String s) {
146:                if (outputText != null) {
147:                    outputText.append(s);
148:                    if (autoScroll == true)
149:                        outputText.setCaretPosition(outputText.getDocument()
150:                                .getLength() - 1);
151:                } else
152:                    System.out.println(s);
153:                try {//if(doLog==true)
154:                    outfile.write(s);
155:                } catch (Exception e) {
156:                    System.out.println(e.toString());
157:                }
158:
159:            }
160:
161:            public void printError(String e) {
162:                if (outputError != null)
163:                    outputError.append("\n" + e);
164:                else
165:                    System.err.println(e);
166:                try {//if(doLog==true)
167:                    outfile.write("\n" + e + "\n");
168:                } catch (Exception ex) {
169:                    System.out.println(e.toString());
170:                }
171:
172:            }
173:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.