PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/Debug/AppKit/rhino.platform/CPAlert.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 149 lines | 148 code | 1 blank | 0 comment | 0 complexity | 5fdf35665471c53401ae2bd45cfe745e MD5 | raw file
  1I;21;Foundation/CPObject.jI;21;Foundation/CPString.jI;22;AppKit/CPApplication.jI;17;AppKit/CPButton.jI;16;AppKit/CPColor.jI;15;AppKit/CPFont.jI;16;AppKit/CPImage.jI;20;AppKit/CPImageView.jI;16;AppKit/CPPanel.jI;20;AppKit/CPTextField.jc;7353;
  2CPWarningAlertStyle = 0;
  3CPInformationalAlertStyle = 1;
  4CPCriticalAlertStyle = 2;
  5var CPAlertWarningImage,
  6    CPAlertInformationImage,
  7    CPAlertErrorImage;
  8{var the_class = objj_allocateClassPair(CPObject, "CPAlert"),
  9meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_alertPanel"), new objj_ivar("_messageLabel"), new objj_ivar("_alertImageView"), new objj_ivar("_alertStyle"), new objj_ivar("_windowTitle"), new objj_ivar("_windowStyle"), new objj_ivar("_buttonCount"), new objj_ivar("_buttons"), new objj_ivar("_delegate")]);
 10objj_registerClassPair(the_class);
 11objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 12class_addMethods(the_class, [new objj_method(sel_getUid("init"), function $CPAlert__init(self, _cmd)
 13{ with(self)
 14{
 15    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
 16    if (self)
 17    {
 18        _buttonCount = 0;
 19        _buttons = objj_msgSend(CPArray, "array");
 20        _alertStyle = CPWarningAlertStyle;
 21        _messageLabel = objj_msgSend(objj_msgSend(CPTextField, "alloc"), "initWithFrame:", CGRectMake(57.0, 10.0, 220.0, 80.0));
 22        objj_msgSend(_messageLabel, "setFont:", objj_msgSend(CPFont, "systemFontOfSize:", 12.0));
 23        objj_msgSend(_messageLabel, "setLineBreakMode:", CPLineBreakByWordWrapping);
 24        objj_msgSend(_messageLabel, "setAlignment:", CPJustifiedTextAlignment);
 25        _alertImageView = objj_msgSend(objj_msgSend(CPImageView, "alloc"), "initWithFrame:", CGRectMake(15.0, 12.0, 32.0, 32.0));
 26        objj_msgSend(self, "setWindowStyle:", nil);
 27    }
 28    return self;
 29}
 30}), new objj_method(sel_getUid("setWindowStyle:"), function $CPAlert__setWindowStyle_(self, _cmd, styleMask)
 31{ with(self)
 32{
 33    _windowStyle = styleMask;
 34    _alertPanel = objj_msgSend(objj_msgSend(CPPanel, "alloc"), "initWithContentRect:styleMask:", CGRectMake(0.0, 0.0, 300.0, 130.0), styleMask ? styleMask | CPTitledWindowMask : CPTitledWindowMask);
 35    objj_msgSend(_alertPanel, "setFloatingPanel:", YES);
 36    objj_msgSend(_alertPanel, "center");
 37    objj_msgSend(_messageLabel, "setTextColor:", (styleMask == CPHUDBackgroundWindowMask) ? objj_msgSend(CPColor, "whiteColor") : objj_msgSend(CPColor, "blackColor"));
 38    var count = objj_msgSend(_buttons, "count");
 39    for(var i=0; i < count; i++)
 40    {
 41        var button = _buttons[i];
 42        objj_msgSend(button, "setFrameSize:", CGSizeMake(objj_msgSend(button, "frame").size.width, (styleMask == CPHUDBackgroundWindowMask) ? 20.0 : 24.0));
 43        objj_msgSend(button, "setBezelStyle:", (styleMask == CPHUDBackgroundWindowMask) ? CPHUDBezelStyle : CPRoundedBezelStyle);
 44        objj_msgSend(objj_msgSend(_alertPanel, "contentView"), "addSubview:", button);
 45    }
 46    objj_msgSend(objj_msgSend(_alertPanel, "contentView"), "addSubview:", _messageLabel);
 47    objj_msgSend(objj_msgSend(_alertPanel, "contentView"), "addSubview:", _alertImageView);
 48}
 49}), new objj_method(sel_getUid("setTitle:"), function $CPAlert__setTitle_(self, _cmd, aTitle)
 50{ with(self)
 51{
 52    _windowTitle = aTitle;
 53}
 54}), new objj_method(sel_getUid("title"), function $CPAlert__title(self, _cmd)
 55{ with(self)
 56{
 57    return _windowTitle;
 58}
 59}), new objj_method(sel_getUid("windowStyle"), function $CPAlert__windowStyle(self, _cmd)
 60{ with(self)
 61{
 62    return _windowStyle;
 63}
 64}), new objj_method(sel_getUid("setDelegate:"), function $CPAlert__setDelegate_(self, _cmd, delegate)
 65{ with(self)
 66{
 67    _delegate = delegate;
 68}
 69}), new objj_method(sel_getUid("delegate"), function $CPAlert__delegate(self, _cmd)
 70{ with(self)
 71{
 72    return _delegate;
 73}
 74}), new objj_method(sel_getUid("setAlertStyle:"), function $CPAlert__setAlertStyle_(self, _cmd, style)
 75{ with(self)
 76{
 77    _alertStyle = style;
 78}
 79}), new objj_method(sel_getUid("alertStyle"), function $CPAlert__alertStyle(self, _cmd)
 80{ with(self)
 81{
 82    return _alertStyle;
 83}
 84}), new objj_method(sel_getUid("setMessageText:"), function $CPAlert__setMessageText_(self, _cmd, messageText)
 85{ with(self)
 86{
 87    objj_msgSend(_messageLabel, "setStringValue:", messageText);
 88}
 89}), new objj_method(sel_getUid("messageText"), function $CPAlert__messageText(self, _cmd)
 90{ with(self)
 91{
 92    return objj_msgSend(_messageLabel, "stringValue");
 93}
 94}), new objj_method(sel_getUid("addButtonWithTitle:"), function $CPAlert__addButtonWithTitle_(self, _cmd, title)
 95{ with(self)
 96{
 97    var button = objj_msgSend(objj_msgSend(CPButton, "alloc"), "initWithFrame:", CGRectMake(200.0 - (_buttonCount * 90.0), 98.0, 80.0, (_windowStyle == CPHUDBackgroundWindowMask) ? 20.0 : 24.0));
 98    objj_msgSend(button, "setTitle:", title);
 99    objj_msgSend(button, "setTarget:", self);
100    objj_msgSend(button, "setTag:", _buttonCount);
101    objj_msgSend(button, "setAction:", sel_getUid("_notifyDelegate:"));
102    objj_msgSend(button, "setBezelStyle:", (_windowStyle == CPHUDBackgroundWindowMask) ? CPHUDBezelStyle : CPRoundRectBezelStyle);
103    objj_msgSend(objj_msgSend(_alertPanel, "contentView"), "addSubview:", button);
104    if (_buttonCount == 0)
105        objj_msgSend(_alertPanel, "setDefaultButton:", button);
106    _buttonCount++;
107    objj_msgSend(_buttons, "addObject:", button);
108}
109}), new objj_method(sel_getUid("runModal"), function $CPAlert__runModal(self, _cmd)
110{ with(self)
111{
112    var theTitle;
113    switch (_alertStyle)
114    {
115        case CPWarningAlertStyle: objj_msgSend(_alertImageView, "setImage:", CPAlertWarningImage);
116                                        theTitle = "Warning";
117                                        break;
118        case CPInformationalAlertStyle: objj_msgSend(_alertImageView, "setImage:", CPAlertInformationImage);
119                                        theTitle = "Information";
120                                        break;
121        case CPCriticalAlertStyle: objj_msgSend(_alertImageView, "setImage:", CPAlertErrorImage);
122                                        theTitle = "Error";
123                                        break;
124    }
125    objj_msgSend(_alertPanel, "setTitle:", _windowTitle ? _windowTitle : theTitle);
126    objj_msgSend(CPApp, "runModalForWindow:", _alertPanel);
127}
128}), new objj_method(sel_getUid("_notifyDelegate:"), function $CPAlert___notifyDelegate_(self, _cmd, button)
129{ with(self)
130{
131    if (_delegate && objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("alertDidEnd:returnCode:")))
132        objj_msgSend(_delegate, "alertDidEnd:returnCode:", self, objj_msgSend(button, "tag"));
133    objj_msgSend(CPApp, "abortModal");
134    objj_msgSend(_alertPanel, "close");
135}
136})]);
137class_addMethods(meta_class, [new objj_method(sel_getUid("initialize"), function $CPAlert__initialize(self, _cmd)
138{ with(self)
139{
140    if (self != CPAlert)
141        return;
142    var bundle = objj_msgSend(CPBundle, "bundleForClass:", objj_msgSend(self, "class"));
143    CPAlertWarningImage = objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPAlert/dialog-warning.png"), CGSizeMake(32.0, 32.0));
144    CPAlertInformationImage = objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPAlert/dialog-information.png"), CGSizeMake(32.0, 32.0));
145    CPAlertErrorImage = objj_msgSend(objj_msgSend(CPImage, "alloc"), "initWithContentsOfFile:size:", objj_msgSend(bundle, "pathForResource:", "CPAlert/dialog-error.png"), CGSizeMake(32.0, 32.0));
146}
147})]);
148}
149