[BACK]Return to MyOutputWindowController.m CVS log [TXT][DIR] Up to [local] / OpenXM / src / cfep

Annotation of OpenXM/src/cfep/MyOutputWindowController.m, Revision 1.3

1.1       takayama    1: //
                      2: //  MyOutputWindowController.m
                      3: //  cfep
                      4: //
                      5: //  Created by nobuki on 06/01/25.
                      6: //  Copyright 2006 __MyCompanyName__. All rights reserved.
                      7: //
                      8:
                      9: #import "MyOutputWindowController.h"
                     10: #import "MyDocument.h"
                     11:
                     12: @implementation MyOutputWindowController
                     13:
                     14: +(MyOutputWindowController *) sharedMyOutputWindowController: (MyDocument *) sender action: (enum actionType) act {
                     15:   static NSMutableDictionary * sharedMOWC;  // class variable.
                     16:   MyOutputWindowController *owin;
                     17:   if (sharedMOWC == nil) {
                     18:     sharedMOWC = [NSMutableDictionary dictionaryWithCapacity: 1024]; //BUG. finite number.
                     19:        [sharedMOWC retain];
                     20:   }
                     21:   if (act == FIND) {
                     22:        owin = [sharedMOWC objectForKey: [sender getMyDocumentKey]];
                     23:        if (owin != nil) return owin;
                     24:     owin = [[MyOutputWindowController allocWithZone:[MyOutputWindowController zone]] init];
                     25:        [owin retain];
                     26:        NSLog(@"MyOutputWindowController. new owc is created.\n");
                     27:        [sharedMOWC setObject: owin forKey: [sender getMyDocumentKey]];
                     28:        return owin;
                     29:   }else{ // REMOVE
                     30:        owin = [sharedMOWC objectForKey: [sender getMyDocumentKey]];
                     31:     if (!owin) [sharedMOWC removeObjectForKey: [sender getMyDocumentKey]];
                     32:        // [owin autorelease];
                     33:        return owin;
                     34:   }
                     35: }
                     36:
                     37: +(MyOutputWindowController *) sharedMyOutputWindowController: (MyDocument *)sender {
                     38:    return [self sharedMyOutputWindowController: sender action: FIND];
                     39: }
                     40:
                     41:
                     42: -(id) init {
                     43:   static int serial;
                     44:   self = [self initWithWindowNibName: @"MyOutputWindow"];
                     45:   if (self) [self setWindowFrameAutosaveName: @"cfep Output View"];
                     46:   winNo = serial++;
                     47:   return self;
                     48: }
                     49:
                     50: -(void) windowDidLoad {
                     51:   [super windowDidLoad];
                     52:   // [textViewOut retain]; ?
                     53: }
                     54:
                     55: -(void) dealloc {
                     56:   NSLog(@"dealloc of MyOutputWindowController instance.\n");
                     57:   [[NSNotificationCenter defaultCenter] removeObserver: self];
                     58:   [super dealloc];
                     59: }
                     60:
                     61: -(void) closeMyOutputWindow: (MyDocument *) md {
                     62:   NSLog(@"closeMyOutputWindow. \n");
                     63:   [MyOutputWindowController sharedMyOutputWindowController: md action: REMOVE];
                     64:   removable = 1;
                     65:   [self close];
                     66: }
                     67:
                     68: -(BOOL) windowShouldClose: (NSWindow *)sender {  // book. p.149   Delegate outlet of Window should me File's owner.
                     69:    if (removable) return [super windowShouldClose: sender];
                     70:    return NO;
                     71: }
                     72:
                     73: -(void)outputStringToOutputWindow:(NSString *)msg {
1.3     ! takayama   74:   [self outputStringToOutputWindow: msg withColor: [NSColor blackColor]];
        !            75: }
        !            76: -(void)outputStringToOutputWindow:(NSString *)msg withColor: (NSColor *) color {
        !            77:   int oldEnd, newEnd;
1.1       takayama   78:   NSRange myRange = NSMakeRange([[textViewOut textStorage] length],0);
1.3     ! takayama   79:   oldEnd = myRange.location;
1.1       takayama   80:   // NSLog(@"<MyOutputWindowController> outputStringToOutputWindow\n");
                     81:   [textViewOut replaceCharactersInRange: myRange withString: msg];
1.3     ! takayama   82:   myRange = NSMakeRange([[textViewOut textStorage] length],0);
        !            83:   newEnd = myRange.location;
        !            84:   [textViewOut setTextColor: color range: NSMakeRange(oldEnd,newEnd-oldEnd)];
        !            85:   [textViewOut scrollRangeToVisible: myRange];
1.1       takayama   86: }
1.3     ! takayama   87:
1.2       takayama   88: -(void)insertText: (id) text {
1.3     ! takayama   89:   NSRange myRange = NSMakeRange([[textViewOut textStorage] length],0);
        !            90:   [textViewOut replaceCharactersInRange: myRange withString: @""];  // goto the end of output window.
1.2       takayama   91:   [textViewOut insertText: text];
                     92:   [textViewOut scrollRangeToVisible: NSMakeRange([[textViewOut textStorage] length],0)];
                     93: }
1.1       takayama   94:
                     95: -(void)printErrorMessageToOutputWindow:(NSString *)msg {
                     96:   int oldEnd;
                     97:   int newEnd;
                     98:   oldEnd = [[textViewOut textStorage] length];
                     99:   NSRange myRange = NSMakeRange(oldEnd,0);
                    100:   [textViewOut replaceCharactersInRange: myRange withString: msg];
                    101:   newEnd = [[textViewOut textStorage] length];
                    102:   [textViewOut setTextColor: [NSColor redColor] range: NSMakeRange(oldEnd,newEnd-oldEnd)];
                    103:   [textViewOut scrollRangeToVisible: NSMakeRange(newEnd,0)];
                    104: }
                    105:
                    106: -(void)clearOutputWindow {
                    107:   NSRange myRange = NSMakeRange(0,[[textViewOut textStorage] length]);
                    108:   [textViewOut replaceCharactersInRange: myRange withString: @""];
                    109: }
                    110: -(void)changeWindowTitle: (NSString *)msg {
                    111:   NSLog(@"title=%@\n",[window title]);
                    112:   // [window setTitle: msg];  it does not work. Why?
                    113: }
                    114: -(void)showUp {
                    115:   if (displayed == 0) {
                    116:     [self showWindow: nil];
                    117:        displayed = 1;
                    118:        [self changeWindowTitle: [[NSString stringWithFormat: @"OutputView %d",winNo] retain]];
                    119:   }
                    120: }
                    121:
                    122: -(void) printDocument: (id) sender {
                    123:    [textViewOut print: sender];
                    124: }
                    125:
                    126:
                    127: @end

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>