/Volumes/Plantain/MyDocuments/Projects/MacTrek/MacTrek/App/JTrekController.m

00001 //
00002 //  JTrekController.m
00003 //  MacTrek
00004 //
00005 //  Created by Aqua on 02/05/2006.
00006 //  Copyright 2006 __MyCompanyName__. All rights reserved.
00007 //
00008 
00009 #import "JTrekController.h"
00010 
00011 
00012 @implementation JTrekController
00013 
00014 
00015 - (id) init {
00016     self = [super init];
00017     if (self != nil) {
00018         jtrek = nil;
00019     }
00020     return self;
00021 }
00022 
00023 - (id)initWithTextView:(NSTextView *) destination {
00024     self = [self init];
00025     logDestination = destination;
00026     return self;
00027 }
00028 
00029 // overwrite master
00030 - (void)startClientAt:(NSString *)server port:(int)port {
00031 
00032         // demo
00033         [self startJTrekAt:server port:port];
00034 
00035 }
00036 
00037 - (void)startJTrekAt:(NSString *)server port:(int)port {
00038     
00039     if (jtrek != nil) {
00040         // still running? stop the server with restart, this will
00041         // start the server again after it is properly stoped
00042         [self stopJTrek];
00043         [self startJTrekAt:server port:port];
00044     } else {
00045         // clean start
00046         NSString *pathToResources = [[NSBundle mainBundle] resourcePath];
00047         NSString *pathToJTrek = [NSString stringWithFormat:@"%@/jtrek.jar", pathToResources];
00048         jtrek = [[TaskWrapper alloc] initWithController:self 
00049                                               arguments:[NSArray arrayWithObjects: @"/usr/bin/java", @"-classpath",
00050                                                   pathToJTrek, @"jtrek/Main", @"-h", server, @"-p",
00051                                                   [NSString stringWithFormat:@"%d", port], nil]]; 
00052         [jtrek startProcess];
00053     }
00054 }
00055 
00056 - (void) stopJTrek {
00057     if (jtrek != nil) {
00058         [jtrek stopProcess];
00059         [jtrek release];
00060         jtrek = nil;
00061     }
00062 }
00063 
00064 - (void)appendOutput:(NSString *)output fromTask:(id) task {
00065      
00066     if (logDestination != nil) {
00067         [logDestination setEditable:YES];
00068         [logDestination insertText: output];
00069         [logDestination setEditable:NO];
00070     } else {
00071         NSLog([NSString stringWithFormat: @"JTrekController.appendOutput %@", output]);
00072     }
00073     
00074 }
00075 
00076 - (void)processStarted:(id)task {
00077     NSLog(@"JTrekController.processStarted");
00078 }
00079 
00080 - (void)processFinished:(id)task {
00081     NSLog(@"JTrekController.processFinished:  done");
00082 }
00083 
00084 @end

Generated on Fri Jul 28 19:15:14 2006 for MacTrek by  doxygen 1.4.7