Changeset 97

Show
Ignore:
Timestamp:
04/17/06 15:03:28 (3 years ago)
Author:
jlee
Message:

Added more logging and color support to the viewer

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/org/thestaticvoid/iriverter/Converter.java

    r96 r97  
    255255         
    256256        public void convertSingleVideo(SingleVideoInfo singleVideoInfo) { 
     257                Logger.logMessage("Single Video: " + singleVideoInfo.getInputVideo(), Logger.INFO); 
     258                 
    257259                progressDialogInfo.setInputVideo(new File(singleVideoInfo.getInputVideo()).getName()); 
    258                 progressDialogInfo.setOutputVideo(new File(singleVideoInfo.getInputVideo()).getName()); 
     260                progressDialogInfo.setOutputVideo(new File(singleVideoInfo.getOutputVideo()).getName()); 
    259261                progressDialogInfo.setStatus("Gathering information about the input video..."); 
    260262                 
    261263                MPlayerInfo info = new MPlayerInfo(singleVideoInfo.getInputVideo()); 
     264                if (!info.videoSupported()) { 
     265                        Logger.logMessage("Unsupported video", Logger.ERROR); 
     266                        return; 
     267                } 
    262268                 
    263269                List commandList = prepareBaseCommandList(singleVideoInfo.getInputVideo(), singleVideoInfo.getOutputVideo(), info); 
     
    274280        } 
    275281         
    276         public void convertDVD(DVDInfo dvdInfo) { 
     282        public void convertDVD(DVDInfo dvdInfo) {               
    277283                String inputVideo = "Title " + dvdInfo.getTitle() + " of the DVD at " + dvdInfo.getDrive(); 
    278284                 
     
    285291                } 
    286292                 
     293                Logger.logMessage("DVD: " + inputVideo, Logger.INFO); 
     294                 
    287295                progressDialogInfo.setInputVideo(inputVideo); 
    288296                progressDialogInfo.setOutputVideo(new File(dvdInfo.getOutputVideo()).getName()); 
     
    323331         
    324332        public void manuallySplitVideo(ManualSplitInfo manualSplitInfo) { 
     333                Logger.logMessage("Manual Split: " + manualSplitInfo.getVideo(), Logger.INFO); 
     334                 
    325335                String outputVideo = manualSplitInfo.getVideo().substring(0, manualSplitInfo.getVideo().lastIndexOf('.')) + ".part" + manualSplitInfo.getPart() + ".avi"; 
    326336                 
     
    358368                        tempFile.deleteOnExit(); 
    359369                         
     370                        Logger.logMessage("Join Videos: " + tempFile, Logger.INFO); 
     371                         
    360372                        progressDialogInfo.setOutputVideo(tempFile.getName()); 
    361373                        progressDialogInfo.setStatus("Concatenating videos to a temporary file..."); 
     
    373385                         
    374386                        if (!isCanceled) { 
     387                                Logger.logMessage("Writing header...", Logger.INFO); 
     388                                 
    375389                                progressDialogInfo.setInputVideo(tempFile.getName()); 
    376390                                progressDialogInfo.setOutputVideo(new File(joinVideosInfo.getOutputVideo()).getName()); 
     
    390404                for (int i = 0; i < command.length; i++) 
    391405                        commandStr += command[i] + " "; 
    392                 Logger.logMessage(commandStr); 
     406                Logger.logMessage(commandStr, Logger.INFO); 
    393407                 
    394408                try { 
  • trunk/src/org/thestaticvoid/iriverter/ConverterUI.java

    r96 r97  
    668668                try { 
    669669                        ConverterUI ui = new ConverterUI(); 
    670                 } catch (Exception e) { 
     670                } catch (Throwable e) { 
    671671                        String message = "An unhandled exception occured: " + e.getMessage() + "\n\n"; 
    672672                        StackTraceElement[] st = e.getStackTrace(); 
     
    674674                                message += st[i] + "\n"; 
    675675                         
     676                        Logger.logMessage(message, Logger.ERROR); 
     677                         
    676678                        MessageBox messageBox = new MessageBox(new Shell(Display.getDefault()), SWT.ICON_ERROR | SWT.OK); 
    677679                        messageBox.setText("Error"); 
  • trunk/src/org/thestaticvoid/iriverter/LogViewer.java

    r96 r97  
    11package org.thestaticvoid.iriverter; 
     2 
     3import java.util.*; 
    24 
    35import org.eclipse.swt.*; 
     
    68import org.eclipse.swt.graphics.*; 
    79import org.eclipse.swt.layout.*; 
     10import org.eclipse.swt.custom.*; 
    811 
    912public class LogViewer { 
    1013        private static LogViewer singleton; 
    1114        private Shell shell; 
    12         private Text text; 
     15        private StyledText text; 
     16        private java.util.List lineColors; 
    1317         
    1418        public LogViewer() { 
    1519                if (singleton != null) 
    1620                        return; 
     21                 
     22                lineColors = new ArrayList(); 
    1723                 
    1824                Display display = Display.getDefault(); 
     
    2228                shell.setLayout(new GridLayout()); 
    2329                 
    24                 text = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); 
    25                 text.setEditable(false); 
    26                 text.setText(Logger.getLogText()); 
     30                text = new StyledText(shell, SWT.BORDER | SWT.WRAP | SWT.V_SCROLL | SWT.READ_ONLY); 
    2731                text.setFont(new Font(display, new FontData("monospace", 10, SWT.NORMAL))); 
    2832                text.setLayoutData(new GridData(GridData.FILL_BOTH)); 
    2933                 
     34                String[] lines = Logger.getLogText().split("\n"); 
     35                for (int i = 0; i < lines.length; i++) 
     36                        logMessage(lines[i]); 
     37 
    3038                shell.open(); 
    3139                 
     
    4654        public void logMessage(final String message) { 
    4755                Display.getDefault().syncExec(new Runnable() { 
    48                         public void run() { 
     56                        public void run() {                             
    4957                                text.append(message + "\n"); 
     58                                text.setCaretOffset(text.getCharCount()); 
     59                                 
     60                                if (message.charAt(0) == Logger.PREFIX[Logger.INFO].charAt(0)) 
     61                                        lineColors.add(new Color(Display.getDefault(), 240, 255, 126)); // light yellow 
     62                                else if (message.charAt(0) == Logger.PREFIX[Logger.ERROR].charAt(0)) 
     63                                        lineColors.add(new Color(Display.getDefault(), 255, 137, 126)); // light red 
     64                                else if (message.charAt(0) == Logger.PREFIX[Logger.MPLAYER].charAt(0)) 
     65                                        lineColors.add(new Color(Display.getDefault(), 126, 160, 255)); // light blue 
     66                                else 
     67                                        lineColors.add(new Color(Display.getDefault(), 255, 255, 255)); // white 
     68                                 
     69                                for (int i = 0; i < lineColors.size(); i++) 
     70                                        text.setLineBackground(i, 1, (Color) lineColors.get(i)); 
    5071                        } 
    5172                }); 
     
    5677                        public void run() { 
    5778                                text.setText(""); 
     79                                lineColors.clear(); 
    5880                        } 
    5981                }); 
  • trunk/src/org/thestaticvoid/iriverter/Logger.java

    r96 r97  
    44 
    55public class Logger { 
     6        public static final int INFO = 0, ERROR = 1, MPLAYER = 2; 
     7        public static final String[] PREFIX = {"--- ", "!!! ", ">>> "}; 
     8                               
    69        private static PrintWriter output; 
    710         
     
    1720        } 
    1821         
    19         public static void logMessage(String message) { 
     22        public static void logMessage(String message, int type) { 
     23                String[] messageLines = message.split("\n"); 
     24                message = ""; 
     25                for (int i = 0; i < messageLines.length; i++) 
     26                        message += PREFIX[type] + messageLines[i] + (i == messageLines.length - 1 ? "" : "\n"); 
     27                 
    2028                System.out.println(message); 
    2129                 
  • trunk/src/org/thestaticvoid/iriverter/MPlayerInfo.java

    r96 r97  
    3636                                        while ((line = input.readLine()) != null) { 
    3737                                                mplayerOutput.append(line + "\n"); 
    38                                                 Logger.logMessage(line); 
     38                                                Logger.logMessage(line, Logger.MPLAYER); 
    3939                                        } 
    4040                                         
     
    5252                                        String line; 
    5353                                        while ((line = input.readLine()) != null) 
    54                                                 Logger.logMessage(line); 
     54                                                Logger.logMessage(line, Logger.MPLAYER); 
    5555                                         
    5656                                        input.close(); 
  • trunk/src/org/thestaticvoid/iriverter/MencoderStreamParser.java

    r96 r97  
    2828                        while ((inputLine = input.readLine()) != null) { 
    2929                                if (inputLine.indexOf("Pos:") == -1) 
    30                                         Logger.logMessage(inputLine); 
     30                                        Logger.logMessage(inputLine, Logger.MPLAYER); 
    3131                                 
    3232                                if (inputLine.indexOf("Video stream:") > -1) 
  • trunk/src/org/thestaticvoid/iriverter/ProgressDialog.java

    r32 r97  
    1313        private String syncInputVideo, syncOutputVideo, syncStatus; 
    1414        private int currentJob, totalJobs, syncPercentComplete; 
    15         private boolean syncSuccess; 
    1615         
    1716        public ProgressDialog(Shell parent, int style) { 
     
    101100        } 
    102101         
    103         public synchronized void complete(boolean success) { 
    104                 syncSuccess = success; 
    105                  
    106                 Display.getDefault().syncExec(new Runnable() { 
    107                         public void run() { 
    108                                 if (!syncSuccess) { 
     102        public synchronized void complete(final boolean success) {               
     103                Display.getDefault().syncExec(new Runnable() { 
     104                        public void run() { 
     105                                if (!success) { 
    109106                                        MessageBox dialog = new MessageBox(getParent().getShell(), SWT.ICON_ERROR); 
    110107                                        dialog.setText("There Was an Error While Converting");