001    /////////////////////////////////////////////////
002    // This file is part of Sears project.
003    // Subtitle Editor And Re-Synch
004    // A tool to easily modify and resynch movies subtitles.
005    /////////////////////////////////////////////////
006    //This program is free software; 
007    //you can redistribute it and/or modify it under the terms 
008    //of the GNU General Public License 
009    //as published by the Free Software Foundation; 
010    //either version 2 of the License, or (at your option) any later version.
011    /////////////////////////////////////////////////
012    //Sears project is available under sourceforge
013    // at adress: http://sourceforge.net/projects/sears/
014    //Copyright (C) 2005 Booba Skaya
015    //Mail: booba.skaya@gmail.com
016    ////////////////////////////////////////////////
017    
018    
019    package sears.tools;
020    
021    /**
022     * Class Trace.
023     * <br><b>Summary:</b><br>
024     * A class to show soft traces.
025     */
026    public class Trace {
027        public static final int ERROR_PRIORITY = 0;
028    
029        public static final int WARNING_PRIORITY = 1;
030    
031        public static final int MESSAGE_PRIORITY = 2;
032    
033        public static final int METHOD_PRIORITY = 3;
034    
035        public static final int ALGO_PRIORITY = 4;
036    
037        public static int DISPLAY_TRACE_LEVEL = 1;
038    
039        /**
040         * Constructor Trace.
041         * <br><b>Summary:</b><br>
042         * Constructor of the class.
043         */
044        public Trace() {
045        }
046    
047        /**
048         * Method trace.
049         * <br><b>Summary:</b><br>
050         * Display a message using a priority level.
051         * @param message       The message to display.
052         * @param level         The message level.
053         */
054        public static void trace(String message, int level) {
055            if (level <= DISPLAY_TRACE_LEVEL) {
056                String messageToDisplay = "";
057                switch (level) {
058                    case ERROR_PRIORITY:
059                        messageToDisplay += "[ERR] ";
060                        break;
061                    case WARNING_PRIORITY:
062                        messageToDisplay += "[WAR] ";
063                        break;
064                    case MESSAGE_PRIORITY:
065                        messageToDisplay += "[MES] ";
066                        break;
067                    case METHOD_PRIORITY:
068                        messageToDisplay += "[MET] ";
069                        break;
070                    case ALGO_PRIORITY:
071                        messageToDisplay += "[ALG] ";
072                        break;
073                    default:
074                        messageToDisplay += "[MES] ";
075                }
076                messageToDisplay += (String) message;
077                System.out.println(messageToDisplay);
078            }
079        }
080    
081        /**
082         * Method trace.
083         * <br><b>Summary:</b><br>
084         * Trace a message with default priority level: MESSAGE_PRIORITY
085         * @param message   The message to trace.
086         */
087        public static void trace(String message) {
088            trace(message, MESSAGE_PRIORITY);
089        }
090        
091        /**
092         * Method trace.
093         * <br><b>Summary:</b><br>
094         * Trace a message with Warning priority level.
095         * @param message   The message to trace.
096         */
097        public static void warning(String message){
098            trace(message, WARNING_PRIORITY);
099        }
100        
101        /**
102         * Method trace.
103         * <br><b>Summary:</b><br>
104         * Trace a message with error priority level.
105         * @param message   The message to trace.
106         */
107        public static void error(String message){
108            trace(message, ERROR_PRIORITY);
109        }
110    }