mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
CPByteCountFormatter, a complete implementation of NSByteCountFormatter, with test app
This commit is contained in:
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* CPByteCountFormatter.j
|
||||
* Foundation
|
||||
*
|
||||
* Created by Aparajita Fishman.
|
||||
* Copyright 2013, Cappuccino Foundation.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CPNumberFormatter.j"
|
||||
@import "CPString.j"
|
||||
|
||||
|
||||
// Allowed units
|
||||
CPByteCountFormatterUseDefault = 0;
|
||||
CPByteCountFormatterUseBytes = 1 << 0;
|
||||
CPByteCountFormatterUseKB = 1 << 1;
|
||||
CPByteCountFormatterUseMB = 1 << 2;
|
||||
CPByteCountFormatterUseGB = 1 << 3;
|
||||
CPByteCountFormatterUseTB = 1 << 4;
|
||||
CPByteCountFormatterUsePB = 1 << 5;
|
||||
CPByteCountFormatterUseAll = 0xFFFF;
|
||||
|
||||
// Note: The Cocoa documentation says File is binary, but in practice it's decimal
|
||||
CPByteCountFormatterCountStyleFile = 0;
|
||||
CPByteCountFormatterCountStyleMemory = 1;
|
||||
CPByteCountFormatterCountStyleDecimal = 2;
|
||||
CPByteCountFormatterCountStyleBinary = 3;
|
||||
|
||||
var CPByteCountFormatterUnits = [ @"bytes", @"KB", @"MB", @"GB", @"TB", @"PB" ];
|
||||
|
||||
|
||||
/*!
|
||||
@ingroup foundation
|
||||
@class CPByteCountFormatter
|
||||
|
||||
A complete implementation of NSByteCountFormatter. See
|
||||
https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSByteCountFormatter_Class/Reference/Reference.html
|
||||
*/
|
||||
@implementation CPByteCountFormatter : CPFormatter
|
||||
{
|
||||
int _countStyle;
|
||||
BOOL _allowsNonnumericFormatting;
|
||||
BOOL _includesActualByteCount;
|
||||
BOOL _includesCount;
|
||||
BOOL _includesUnit;
|
||||
BOOL _adaptive;
|
||||
BOOL _zeroPadsFractionDigits;
|
||||
int _allowedUnits;
|
||||
CPNumberFormatter _numberFormatter;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init])
|
||||
{
|
||||
_adaptive = YES;
|
||||
_allowedUnits = CPByteCountFormatterUseDefault;
|
||||
_allowsNonnumericFormatting = YES;
|
||||
_countStyle = CPByteCountFormatterCountStyleFile;
|
||||
_includesActualByteCount = NO;
|
||||
_includesCount = YES;
|
||||
_includesUnit = YES;
|
||||
_zeroPadsFractionDigits = NO;
|
||||
_numberFormatter = [CPNumberFormatter new];
|
||||
[_numberFormatter setNumberStyle:CPNumberFormatterDecimalStyle];
|
||||
[_numberFormatter setMinimumFractionDigits:0];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/*! @name Creating Strings from Byte Count */
|
||||
|
||||
+ (CPString)stringFromByteCount:(int)byteCount countStyle:(int)countStyle
|
||||
{
|
||||
var formatter = [CPByteCountFormatter new];
|
||||
|
||||
[formatter setCountStyle:countStyle];
|
||||
|
||||
return [formatter stringFromByteCount:byteCount];
|
||||
}
|
||||
|
||||
- (CPString)stringFromByteCount:(int)byteCount
|
||||
{
|
||||
var divisor,
|
||||
exponent = 0,
|
||||
unitIndex = ((_allowedUnits === 0) || (_allowedUnits & CPByteCountFormatterUseBytes)) ? 0 : -1,
|
||||
bytes = byteCount,
|
||||
unitBytes = bytes,
|
||||
unitCount = [CPByteCountFormatterUnits count];
|
||||
|
||||
if (_countStyle === CPByteCountFormatterCountStyleFile ||
|
||||
_countStyle === CPByteCountFormatterCountStyleDecimal)
|
||||
divisor = 1000;
|
||||
else
|
||||
divisor = 1024;
|
||||
|
||||
while ((bytes >= divisor) && (exponent < unitCount))
|
||||
{
|
||||
bytes /= divisor;
|
||||
++exponent;
|
||||
|
||||
// If there is a valid unit for this exponent,
|
||||
// update the unit we will use and the byte count for that unit
|
||||
if (_allowedUnits === 0 || (_allowedUnits & (1 << exponent)))
|
||||
{
|
||||
unitIndex = exponent;
|
||||
unitBytes = bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
If no allowed unit was found before bytes < divisor,
|
||||
keep dividing until we find an allowed unit. We can skip
|
||||
bytes, if that is allowed unit, unitIndex will be >= 0.
|
||||
*/
|
||||
if (unitIndex === -1)
|
||||
for (var i = 1; i < unitCount; ++i)
|
||||
{
|
||||
unitBytes /= divisor;
|
||||
|
||||
if ((_allowedUnits === 0) || (_allowedUnits & (1 << i)))
|
||||
{
|
||||
unitIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var minDigits = 0,
|
||||
maxDigits = CPDecimalNoScale;
|
||||
|
||||
// Fractional units get as many digits as they need
|
||||
if (unitBytes >= 1.0)
|
||||
{
|
||||
if (_adaptive)
|
||||
{
|
||||
// 0 fraction digits for bytes and K, 1 fraction digit for MB, 2 digits for GB and above
|
||||
var digits;
|
||||
|
||||
if (exponent <= 1)
|
||||
digits = 0;
|
||||
else if (exponent == 2)
|
||||
digits = 1;
|
||||
else
|
||||
digits = 2;
|
||||
|
||||
maxDigits = digits;
|
||||
|
||||
if (_zeroPadsFractionDigits)
|
||||
minDigits = digits;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_zeroPadsFractionDigits)
|
||||
minDigits = 2;
|
||||
|
||||
if (bytes >= 1)
|
||||
maxDigits = 2;
|
||||
}
|
||||
}
|
||||
|
||||
[_numberFormatter setMinimumFractionDigits:minDigits];
|
||||
[_numberFormatter setMaximumFractionDigits:maxDigits];
|
||||
|
||||
var parts = [];
|
||||
|
||||
if (_includesCount)
|
||||
{
|
||||
if (_allowsNonnumericFormatting && bytes === 0)
|
||||
[parts addObject:@"Zero"];
|
||||
else
|
||||
[parts addObject:[_numberFormatter stringFromNumber:unitBytes]];
|
||||
}
|
||||
|
||||
if (_includesUnit)
|
||||
[parts addObject:CPByteCountFormatterUnits[unitIndex]];
|
||||
|
||||
if ((unitIndex > 0) && _includesCount && _includesUnit && _includesActualByteCount)
|
||||
{
|
||||
[_numberFormatter setMaximumFractionDigits:0];
|
||||
[parts addObject:[CPString stringWithFormat:@"(%s bytes)", [_numberFormatter stringFromNumber:byteCount]]];
|
||||
}
|
||||
|
||||
var result = [parts componentsJoinedByString:@" "];
|
||||
|
||||
if (byteCount === 1)
|
||||
return [result stringByReplacingOccurrencesOfString:@"bytes" withString:@"byte"];
|
||||
else
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
Cocoa returns nil if anObject is not a number.
|
||||
*/
|
||||
- (CPString)stringForObjectValue:(id)anObject
|
||||
{
|
||||
if ([anObject isKindOfClass:CPNumber])
|
||||
return [self stringFromByteCount:anObject];
|
||||
else
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)getObjectValue:(id)anObject forString:(CPString)aString errorDescription:(CPString)anError
|
||||
{
|
||||
// Not implemented
|
||||
return NO;
|
||||
}
|
||||
|
||||
/*! @name Setting Formatting Styles */
|
||||
|
||||
- (int)countStyle
|
||||
{
|
||||
return _countStyle;
|
||||
}
|
||||
|
||||
- (void)setCountStyle:(int)style
|
||||
{
|
||||
_countStyle = style;
|
||||
}
|
||||
|
||||
- (BOOL)allowsNonnumericFormatting
|
||||
{
|
||||
return _allowsNonnumericFormatting;
|
||||
}
|
||||
|
||||
- (void)setAllowsNonnumericFormatting:(BOOL)shouldAllowNonnumericFormatting
|
||||
{
|
||||
_allowsNonnumericFormatting = shouldAllowNonnumericFormatting;
|
||||
}
|
||||
|
||||
- (BOOL)includesActualByteCount
|
||||
{
|
||||
return _includesActualByteCount;
|
||||
}
|
||||
|
||||
- (void)setIncludesActualByteCount:(BOOL)shouldIncludeActualByteCount
|
||||
{
|
||||
_includesActualByteCount = shouldIncludeActualByteCount;
|
||||
}
|
||||
|
||||
- (BOOL)isAdaptive
|
||||
{
|
||||
return _adaptive;
|
||||
}
|
||||
|
||||
- (void)setAdaptive:(BOOL)shouldBeAdaptive
|
||||
{
|
||||
_adaptive = shouldBeAdaptive;
|
||||
}
|
||||
|
||||
- (int)allowedUnits
|
||||
{
|
||||
return _allowedUnits;
|
||||
}
|
||||
|
||||
- (void)setAllowedUnits:(int)allowed
|
||||
{
|
||||
// CPByteCountFormatterUseDefault is equivalent to UseAll
|
||||
_allowedUnits = allowed ? allowed : CPByteCountFormatterUseAll;
|
||||
}
|
||||
|
||||
- (BOOL)includesCount
|
||||
{
|
||||
return _includesCount;
|
||||
}
|
||||
|
||||
- (void)setIncludesCount:(BOOL)shouldIncludeCount
|
||||
{
|
||||
_includesCount = shouldIncludeCount;
|
||||
}
|
||||
|
||||
- (BOOL)includesUnit
|
||||
{
|
||||
return _includesUnit;
|
||||
}
|
||||
|
||||
- (void)setIncludesUnit:(BOOL)shouldIncludeUnit
|
||||
{
|
||||
_includesUnit = shouldIncludeUnit;
|
||||
}
|
||||
|
||||
- (BOOL)zeroPadsFractionDigits
|
||||
{
|
||||
return _zeroPadsFractionDigits;
|
||||
}
|
||||
|
||||
- (void)setZeroPadsFractionDigits:(BOOL)shouldZeroPad
|
||||
{
|
||||
_zeroPadsFractionDigits = shouldZeroPad;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
var CPByteCountFormatterCountStyleKey = @"CPByteCountFormatterCountStyleKey",
|
||||
CPByteCountFormatterAllowsNonnumericFormattingKey = @"CPByteCountFormatterAllowsNonnumericFormattingKey",
|
||||
CPByteCountFormatterIncludesActualByteCountKey = @"CPByteCountFormatterIncludesActualByteCountKey",
|
||||
CPByteCountFormatterIncludesCountKey = @"CPByteCountFormatterIncludesCountKey",
|
||||
CPByteCountFormatterIncludesUnitKey = @"CPByteCountFormatterIncludesUnitKey",
|
||||
CPByteCountFormatterAdaptiveKey = @"CPByteCountFormatterAdaptiveKey",
|
||||
CPByteCountFormatterZeroPadsFractionDigitsKey = @"CPByteCountFormatterZeroPadsFractionDigitsKey",
|
||||
CPByteCountFormatterAllowedUnitsKey = @"CPByteCountFormatterAllowedUnitsKey";
|
||||
|
||||
@implementation CPByteCountFormatter (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super initWithCoder:aCoder];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_countStyle = [aCoder decodeIntForKey:CPByteCountFormatterCountStyleKey];
|
||||
_allowsNonnumericFormatting = [aCoder decodeBoolForKey:CPByteCountFormatterAllowsNonnumericFormattingKey];
|
||||
_includesActualByteCount = [aCoder decodeBoolForKey:CPByteCountFormatterIncludesActualByteCountKey];
|
||||
_includesCount = [aCoder decodeBoolForKey:CPByteCountFormatterIncludesCountKey];
|
||||
_includesUnit = [aCoder decodeBoolForKey:CPByteCountFormatterIncludesUnitKey];
|
||||
_adaptive = [aCoder decodeBoolForKey:CPByteCountFormatterAdaptiveKey];
|
||||
_zeroPadsFractionDigits = [aCoder decodeBoolForKey:CPByteCountFormatterZeroPadsFractionDigitsKey];
|
||||
_allowedUnits = [aCoder decodeIntForKey:CPByteCountFormatterAllowedUnitsKey];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[super encodeWithCoder:aCoder];
|
||||
|
||||
[aCoder encodeInt:_countStyle forKey:CPByteCountFormatterCountStyleKey];
|
||||
[aCoder encodeBool:_allowsNonnumericFormatting forKey:CPByteCountFormatterAllowsNonnumericFormattingKey];
|
||||
[aCoder encodeBool:_includesActualByteCount forKey:CPByteCountFormatterIncludesActualByteCountKey];
|
||||
[aCoder encodeBool:_includesCount forKey:CPByteCountFormatterIncludesCountKey];
|
||||
[aCoder encodeBool:_includesUnit forKey:CPByteCountFormatterIncludesUnitKey];
|
||||
[aCoder encodeBool:_adaptive forKey:CPByteCountFormatterAdaptiveKey];
|
||||
[aCoder encodeBool:_zeroPadsFractionDigits forKey:CPByteCountFormatterZeroPadsFractionDigitsKey];
|
||||
[aCoder encodeInt:_allowedUnits forKey:CPByteCountFormatterAllowedUnitsKey];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -23,6 +23,7 @@
|
||||
@import "_CGGeometry.j"
|
||||
@import "CPArray.j"
|
||||
@import "CPBundle.j"
|
||||
@import "CPByteCountFormatter.j"
|
||||
@import "CPCharacterSet.j"
|
||||
@import "CPCoder.j"
|
||||
@import "CPComparisonPredicate.j"
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* AppController.j
|
||||
* CPByteCountFormatter
|
||||
*
|
||||
* Created by You on February 10, 2013.
|
||||
* Copyright 2013, Your Company All rights reserved.
|
||||
*/
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
|
||||
|
||||
@implementation AppController : CPObject
|
||||
{
|
||||
@outlet CPWindow testWindow;
|
||||
@outlet CPTextField byteCount;
|
||||
@outlet CPTextField formattedByteCount;
|
||||
@outlet CPBox properties;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
{
|
||||
[byteCount setDelegate:self];
|
||||
[byteCount setStringValue:@"0"];
|
||||
[formattedByteCount setObjectValue:0];
|
||||
}
|
||||
|
||||
- (void)awakeFromCib
|
||||
{
|
||||
}
|
||||
|
||||
- (@action)propertyChanged:(id)sender
|
||||
{
|
||||
[formattedByteCount setObjectValue:[byteCount intValue]];
|
||||
}
|
||||
|
||||
- (@action)unitsChanged:(id)sender
|
||||
{
|
||||
var menu = sender,
|
||||
index = [menu indexOfSelectedItem],
|
||||
item = [menu itemAtIndex:index],
|
||||
itemState = [item state],
|
||||
units = 0,
|
||||
count = [menu numberOfItems];
|
||||
|
||||
if (index < 3)
|
||||
{
|
||||
for (var i = 0; i < count; ++i)
|
||||
[[menu itemAtIndex:i] setState:CPOffState];
|
||||
|
||||
[item setState:CPOnState];
|
||||
|
||||
if (index === 1)
|
||||
units = CPByteCountFormatterUseDefault;
|
||||
else
|
||||
units = CPByteCountFormatterUseAll;
|
||||
}
|
||||
else
|
||||
{
|
||||
[[menu itemAtIndex:1] setState:CPOffState];
|
||||
[[menu itemAtIndex:2] setState:CPOffState];
|
||||
|
||||
[item setState:itemState === CPOnState ? CPOffState : CPOnState];
|
||||
|
||||
for (var i = 3; i < count; ++i)
|
||||
if ([[menu itemAtIndex:i] state] === CPOnState)
|
||||
units |= 1 << (i - 3);
|
||||
|
||||
if (units === 0)
|
||||
[[menu itemAtIndex:1] setState:CPOnState];
|
||||
}
|
||||
|
||||
console.log("units: %d", units);
|
||||
[[formattedByteCount formatter] setAllowedUnits:units];
|
||||
[self propertyChanged:nil];
|
||||
}
|
||||
|
||||
- (void)controlTextDidChange:(CPNotification)aNotification
|
||||
{
|
||||
[self propertyChanged:nil];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Main cib file base name</key>
|
||||
<string>MainMenu.cib</string>
|
||||
<key>CPBundleName</key>
|
||||
<string>CPByteCountFormatter</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Jakefile
|
||||
* CPByteCountFormatter
|
||||
*
|
||||
* Created by You on February 10, 2013.
|
||||
* Copyright 2013, Your Company All rights reserved.
|
||||
*/
|
||||
|
||||
var ENV = require("system").env,
|
||||
FILE = require("file"),
|
||||
JAKE = require("jake"),
|
||||
task = JAKE.task,
|
||||
FileList = JAKE.FileList,
|
||||
app = require("cappuccino/jake").app,
|
||||
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
|
||||
OS = require("os");
|
||||
|
||||
app ("CPByteCountFormatter", function(task)
|
||||
{
|
||||
task.setBuildIntermediatesPath(FILE.join("Build", "CPByteCountFormatter.build", configuration));
|
||||
task.setBuildPath(FILE.join("Build", configuration));
|
||||
|
||||
task.setProductName("CPByteCountFormatter");
|
||||
task.setIdentifier("com.yourcompany.CPByteCountFormatter");
|
||||
task.setVersion("1.0");
|
||||
task.setAuthor("Your Company");
|
||||
task.setEmail("feedback @nospam@ yourcompany.com");
|
||||
task.setSummary("CPByteCountFormatter");
|
||||
task.setSources((new FileList("**/*.j")).exclude(FILE.join("Build", "**")));
|
||||
task.setResources(new FileList("Resources/**"));
|
||||
task.setIndexFilePath("index.html");
|
||||
task.setInfoPlistPath("Info.plist");
|
||||
task.setNib2CibFlags("-R Resources/");
|
||||
|
||||
if (configuration === "Debug")
|
||||
task.setCompilerFlags("-DDEBUG -g");
|
||||
else
|
||||
task.setCompilerFlags("-O");
|
||||
});
|
||||
|
||||
task ("default", ["CPByteCountFormatter"], function()
|
||||
{
|
||||
printResults(configuration);
|
||||
});
|
||||
|
||||
task ("build", ["default"]);
|
||||
|
||||
task ("debug", function()
|
||||
{
|
||||
ENV["CONFIGURATION"] = "Debug";
|
||||
JAKE.subjake(["."], "build", ENV);
|
||||
});
|
||||
|
||||
task ("release", function()
|
||||
{
|
||||
ENV["CONFIGURATION"] = "Release";
|
||||
JAKE.subjake(["."], "build", ENV);
|
||||
});
|
||||
|
||||
task ("run", ["debug"], function()
|
||||
{
|
||||
OS.system(["open", FILE.join("Build", "Debug", "CPByteCountFormatter", "index.html")]);
|
||||
});
|
||||
|
||||
task ("run-release", ["release"], function()
|
||||
{
|
||||
OS.system(["open", FILE.join("Build", "Release", "CPByteCountFormatter", "index.html")]);
|
||||
});
|
||||
|
||||
task ("deploy", ["release"], function()
|
||||
{
|
||||
FILE.mkdirs(FILE.join("Build", "Deployment", "CPByteCountFormatter"));
|
||||
OS.system(["press", "-f", FILE.join("Build", "Release", "CPByteCountFormatter"), FILE.join("Build", "Deployment", "CPByteCountFormatter")]);
|
||||
printResults("Deployment")
|
||||
});
|
||||
|
||||
task ("desktop", ["release"], function()
|
||||
{
|
||||
FILE.mkdirs(FILE.join("Build", "Desktop", "CPByteCountFormatter"));
|
||||
require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "CPByteCountFormatter"), FILE.join("Build", "Desktop", "CPByteCountFormatter", "CPByteCountFormatter.app"));
|
||||
printResults("Desktop")
|
||||
});
|
||||
|
||||
task ("run-desktop", ["desktop"], function()
|
||||
{
|
||||
OS.system([FILE.join("Build", "Desktop", "CPByteCountFormatter", "CPByteCountFormatter.app", "Contents", "MacOS", "NativeHost"), "-i"]);
|
||||
});
|
||||
|
||||
function printResults(configuration)
|
||||
{
|
||||
print("----------------------------");
|
||||
print(configuration+" app built at path: "+FILE.join("Build", configuration, "CPByteCountFormatter"));
|
||||
print("----------------------------");
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
@@ -0,0 +1,107 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<!--
|
||||
index-debug.html
|
||||
CPByteCountFormatter
|
||||
|
||||
Created by You on February 10, 2013.
|
||||
Copyright 2013, Your Company All rights reserved.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, chrome=1" />
|
||||
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||
|
||||
<link rel="apple-touch-icon" href="Resources/icon.png" />
|
||||
<link rel="apple-touch-startup-image" href="Resources/default.png" />
|
||||
|
||||
<title>CPByteCountFormatter</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
OBJJ_MAIN_FILE = "main.j";
|
||||
OBJJ_INCLUDE_PATHS = ["Frameworks/Debug", "Frameworks", "SomethingElse"];
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="Frameworks/Debug/Objective-J/Objective-J.js" charset="UTF-8"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
objj_msgSend_reset();
|
||||
|
||||
// DEBUG OPTIONS:
|
||||
|
||||
// Uncomment to enable printing of backtraces on exceptions:
|
||||
//objj_msgSend_decorate(objj_backtrace_decorator);
|
||||
|
||||
// Uncomment to supress exceptions that take place inside a message
|
||||
//objj_msgSend_decorate(objj_supress_exceptions_decorator)
|
||||
|
||||
// Uncomment to enable runtime type checking:
|
||||
//objj_msgSend_decorate(objj_typecheck_decorator);
|
||||
|
||||
// Uncomment (along with both above) to print backtraces on type check errors:
|
||||
//objj_typecheck_prints_backtrace = true;
|
||||
|
||||
// Uncomment to disable the default logger (CPLogConsole if window.console exists, CPLogPopup otherwise):
|
||||
//CPLogUnregister(CPLogDefault);
|
||||
|
||||
// Uncomment to enable a specific logger:
|
||||
//CPLogRegister(CPLogConsole);
|
||||
//CPLogRegister(CPLogPopup);
|
||||
|
||||
// Tag view DOM elements with a "data-cappuccino-view" attribute that contains
|
||||
// the class name of the view that created them. Comment this or set to false to disable.
|
||||
appkit_tag_dom_elements = true;
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
body{margin:0; padding:0;}
|
||||
#container {position: absolute; top:50%; left:50%;}
|
||||
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
|
||||
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
|
||||
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
|
||||
</style>
|
||||
|
||||
<!--[if lt IE 7]>
|
||||
<STYLE type="text/css">
|
||||
#container { position: relative; top: 50%; }
|
||||
#content { position: relative;}
|
||||
</STYLE>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
|
||||
<body style="">
|
||||
<div id="cappuccino-body">
|
||||
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
|
||||
<script type="text/javascript">
|
||||
document.write("<div id='container'><p id='content'>" +
|
||||
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
|
||||
"Loading CPByteCountFormatter...</p></div>");
|
||||
</script>
|
||||
|
||||
<noscript>
|
||||
<div id="container">
|
||||
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
|
||||
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
|
||||
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino-project.org/noscript">Show me how to enable JavaScript</a></p>
|
||||
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
|
||||
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
|
||||
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
|
||||
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
|
||||
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
|
||||
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
|
||||
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<!--
|
||||
index.html
|
||||
CPByteCountFormatter
|
||||
|
||||
Created by You on February 10, 2013.
|
||||
Copyright 2013, Your Company All rights reserved.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, chrome=1" />
|
||||
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||
|
||||
<link rel="apple-touch-icon" href="Resources/icon.png" />
|
||||
<link rel="apple-touch-startup-image" href="Resources/default.png" />
|
||||
|
||||
<title>CPByteCountFormatter</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
OBJJ_MAIN_FILE = "main.j";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="Frameworks/Objective-J/Objective-J.js" charset="UTF-8"></script>
|
||||
|
||||
<style type="text/css">
|
||||
body{margin:0; padding:0;}
|
||||
#container {position: absolute; top:50%; left:50%;}
|
||||
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
|
||||
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
|
||||
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
|
||||
</style>
|
||||
|
||||
<!--[if lt IE 7]>
|
||||
<STYLE type="text/css">
|
||||
#container { position: relative; top: 50%; }
|
||||
#content { position: relative;}
|
||||
</STYLE>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
|
||||
<body style="">
|
||||
<div id="cappuccino-body">
|
||||
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
|
||||
<script type="text/javascript">
|
||||
document.write("<div id='container'><p id='content'>" +
|
||||
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
|
||||
"Loading CPByteCountFormatter...</p></div>");
|
||||
</script>
|
||||
|
||||
<noscript>
|
||||
<div id="container">
|
||||
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
|
||||
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
|
||||
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino-project.org/noscript">Show me how to enable JavaScript</a></p>
|
||||
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
|
||||
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
|
||||
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
|
||||
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
|
||||
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
|
||||
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
|
||||
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* AppController.j
|
||||
* CPByteCountFormatter
|
||||
*
|
||||
* Created by You on February 10, 2013.
|
||||
* Copyright 2013, Your Company All rights reserved.
|
||||
*/
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
@import "AppController.j"
|
||||
|
||||
|
||||
function main(args, namedArgs)
|
||||
{
|
||||
CPApplicationMain(args, namedArgs);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* NSByteCountFormatter.j
|
||||
* nib2cib
|
||||
*
|
||||
* Created by Aparajita Fishman.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import <Foundation/CPByteCountFormatter.j>
|
||||
|
||||
|
||||
@implementation CPByteCountFormatter (NSCoding)
|
||||
|
||||
- (id)NS_initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_countStyle = [aCoder decodeIntForKey:@"NSKBSize"] || 0;
|
||||
_allowsNonnumericFormatting = ![aCoder containsValueForKey:@"NSNoNonnumeric"];
|
||||
_includesActualByteCount = [aCoder containsValueForKey:@"NSActual"];
|
||||
_includesCount = ![aCoder containsValueForKey:@"NSNoCount"];
|
||||
_includesUnit = ![aCoder containsValueForKey:@"NSNoUnit"];
|
||||
_adaptive = ![aCoder containsValueForKey:@"NSNoAdaptive"];
|
||||
_zeroPadsFractionDigits = [aCoder containsValueForKey:@"NSZeroPad"];
|
||||
_allowedUnits = [aCoder decodeIntForKey:@"NSUnits"] || 0;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSByteCountFormatter : CPByteCountFormatter
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
return [self NS_initWithCoder:aCoder];
|
||||
}
|
||||
|
||||
- (Class)classForKeyedArchiver
|
||||
{
|
||||
return [CPByteCountFormatter class];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
@import "NSArray.j"
|
||||
@import "NSAttributedString.j"
|
||||
@import "NSByteCountFormatter.j"
|
||||
@import "NSDateFormatter.j"
|
||||
@import "NSDictionary.j"
|
||||
@import "NSExpression.j"
|
||||
|
||||
Reference in New Issue
Block a user