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

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

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 {
                     74:   NSRange myRange = NSMakeRange([[textViewOut textStorage] length],0);
                     75:   // NSLog(@"<MyOutputWindowController> outputStringToOutputWindow\n");
                     76:   [textViewOut replaceCharactersInRange: myRange withString: msg];
                     77:   [textViewOut scrollRangeToVisible: NSMakeRange([[textViewOut textStorage] length],0)];
                     78: }
                     79:
                     80: -(void)printErrorMessageToOutputWindow:(NSString *)msg {
                     81:   int oldEnd;
                     82:   int newEnd;
                     83:   oldEnd = [[textViewOut textStorage] length];
                     84:   NSRange myRange = NSMakeRange(oldEnd,0);
                     85:   [textViewOut replaceCharactersInRange: myRange withString: msg];
                     86:   newEnd = [[textViewOut textStorage] length];
                     87:   [textViewOut setTextColor: [NSColor redColor] range: NSMakeRange(oldEnd,newEnd-oldEnd)];
                     88:   [textViewOut scrollRangeToVisible: NSMakeRange(newEnd,0)];
                     89: }
                     90:
                     91: -(void)clearOutputWindow {
                     92:   NSRange myRange = NSMakeRange(0,[[textViewOut textStorage] length]);
                     93:   [textViewOut replaceCharactersInRange: myRange withString: @""];
                     94: }
                     95: -(void)changeWindowTitle: (NSString *)msg {
                     96:   NSLog(@"title=%@\n",[window title]);
                     97:   // [window setTitle: msg];  it does not work. Why?
                     98: }
                     99: -(void)showUp {
                    100:   if (displayed == 0) {
                    101:     [self showWindow: nil];
                    102:        displayed = 1;
                    103:        [self changeWindowTitle: [[NSString stringWithFormat: @"OutputView %d",winNo] retain]];
                    104:   }
                    105: }
                    106:
                    107: -(void) printDocument: (id) sender {
                    108:    [textViewOut print: sender];
                    109: }
                    110:
                    111:
                    112: @end

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