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

File: [local] / OpenXM / src / cfep / MyOutputWindowController.m (download)

Revision 1.4, Sun Mar 12 07:09:51 2006 UTC (18 years, 2 months ago) by takayama
Branch: MAIN
CVS Tags: R_1_3_1-2, RELEASE_1_3_1_13b, RELEASE_1_2_3_12, HEAD, DEB_REL_1_2_3-9
Changes since 1.3: +1 -1 lines

cfep version 1.1 is ready.

//
//  MyOutputWindowController.m
//  cfep
//
//  Created by nobuki on 06/01/25.
//  Copyright 2006 __MyCompanyName__. All rights reserved.
//

#import "MyOutputWindowController.h"
#import "MyDocument.h"

@implementation MyOutputWindowController

+(MyOutputWindowController *) sharedMyOutputWindowController: (MyDocument *) sender action: (enum actionType) act {
  static NSMutableDictionary * sharedMOWC;  // class variable.
  MyOutputWindowController *owin;
  if (sharedMOWC == nil) {
    sharedMOWC = [NSMutableDictionary dictionaryWithCapacity: 1024]; //BUG. finite number.
	[sharedMOWC retain];
  }
  if (act == FIND) {
	owin = [sharedMOWC objectForKey: [sender getMyDocumentKey]];
	if (owin != nil) return owin;
    owin = [[MyOutputWindowController allocWithZone:[MyOutputWindowController zone]] init];
	[owin retain];
	NSLog(@"MyOutputWindowController. new owc is created.\n");
	[sharedMOWC setObject: owin forKey: [sender getMyDocumentKey]];
	return owin;
  }else{ // REMOVE
	owin = [sharedMOWC objectForKey: [sender getMyDocumentKey]];
    if (!owin) [sharedMOWC removeObjectForKey: [sender getMyDocumentKey]];
	// [owin autorelease];
	return owin;
  }
}

+(MyOutputWindowController *) sharedMyOutputWindowController: (MyDocument *)sender {
   return [self sharedMyOutputWindowController: sender action: FIND];
}


-(id) init {
  static int serial;
  self = [self initWithWindowNibName: @"MyOutputWindow"];
  if (self) [self setWindowFrameAutosaveName: @"cfep Output View"];
  winNo = serial++;
  return self;
}

-(void) windowDidLoad {
  [super windowDidLoad];
  // [textViewOut retain]; ?
}

-(void) dealloc {
  NSLog(@"dealloc of MyOutputWindowController instance.\n");
  [[NSNotificationCenter defaultCenter] removeObserver: self];
  [super dealloc];
}

-(void) closeMyOutputWindow: (MyDocument *) md {
  NSLog(@"closeMyOutputWindow. \n");
  [MyOutputWindowController sharedMyOutputWindowController: md action: REMOVE];
  removable = 1;
  [self close];
}

-(BOOL) windowShouldClose: (NSWindow *)sender {  // book. p.149   Delegate outlet of Window should me File's owner.
   if (removable) return [super windowShouldClose: sender];
   return NO;
}

-(void)outputStringToOutputWindow:(NSString *)msg {
  [self outputStringToOutputWindow: msg withColor: [NSColor blackColor]];
}
-(void)outputStringToOutputWindow:(NSString *)msg withColor: (NSColor *) color {
  int oldEnd, newEnd;
  NSRange myRange = NSMakeRange([[textViewOut textStorage] length],0);
  oldEnd = myRange.location;
  // NSLog(@"<MyOutputWindowController> outputStringToOutputWindow\n");  
  [textViewOut replaceCharactersInRange: myRange withString: msg];
  myRange = NSMakeRange([[textViewOut textStorage] length],0);
  newEnd = myRange.location;
  [textViewOut setTextColor: color range: NSMakeRange(oldEnd,newEnd-oldEnd)];
  [textViewOut scrollRangeToVisible: myRange];
}

-(void)insertText: (id) text {
  NSRange myRange = NSMakeRange([[textViewOut textStorage] length],0);
  [textViewOut setSelectedRange: myRange]; // goto the end of output window.
  [textViewOut insertText: text];
  [textViewOut scrollRangeToVisible: NSMakeRange([[textViewOut textStorage] length],0)];
}

-(void)printErrorMessageToOutputWindow:(NSString *)msg {
  int oldEnd;
  int newEnd;
  oldEnd = [[textViewOut textStorage] length];
  NSRange myRange = NSMakeRange(oldEnd,0);
  [textViewOut replaceCharactersInRange: myRange withString: msg];
  newEnd = [[textViewOut textStorage] length];
  [textViewOut setTextColor: [NSColor redColor] range: NSMakeRange(oldEnd,newEnd-oldEnd)];
  [textViewOut scrollRangeToVisible: NSMakeRange(newEnd,0)];
}

-(void)clearOutputWindow {
  NSRange myRange = NSMakeRange(0,[[textViewOut textStorage] length]);
  [textViewOut replaceCharactersInRange: myRange withString: @""];
} 
-(void)changeWindowTitle: (NSString *)msg {
  NSLog(@"title=%@\n",[window title]);
  // [window setTitle: msg];  it does not work. Why?
}
-(void)showUp {
  if (displayed == 0) { 
    [self showWindow: nil]; 
	displayed = 1;
	[self changeWindowTitle: [[NSString stringWithFormat: @"OutputView %d",winNo] retain]];
  }
}

-(void) printDocument: (id) sender {
   [textViewOut print: sender];
}


@end