Permalink
Browse files

Initial revision

  • Loading branch information...
jaz303 committed Apr 4, 2012
1 parent 1ccc0d3 commit c58c6e03aeb29f67fef1aada4df51ee3362c5dc6
@@ -13,6 +13,8 @@
96D7ACC2152CB953002945F0 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 96D7ACC0152CB953002945F0 /* Credits.rtf */; };
96D7ACC5152CB953002945F0 /* OFTAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 96D7ACC4152CB953002945F0 /* OFTAppDelegate.m */; };
96D7ACC8152CB954002945F0 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 96D7ACC6152CB954002945F0 /* MainMenu.xib */; };
+ 96D7ACD0152CB9E7002945F0 /* JFImageSavePanel.m in Sources */ = {isa = PBXBuildFile; fileRef = 96D7ACCF152CB9E7002945F0 /* JFImageSavePanel.m */; };
+ 96D7ACD2152CBB6E002945F0 /* JFImageSavePanelAccessoryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 96D7ACD1152CBB6E002945F0 /* JFImageSavePanelAccessoryView.xib */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -21,14 +23,17 @@
96D7ACB4152CB953002945F0 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
96D7ACB5152CB953002945F0 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = System/Library/Frameworks/CoreData.framework; sourceTree = SDKROOT; };
96D7ACB6152CB953002945F0 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
- 96D7ACB9152CB953002945F0 /* JFImageSavePanel-Info.plist */ = {isa = PBXFileReference; path = "JFImageSavePanel-Info.plist"; sourceTree = "<group>"; };
+ 96D7ACB9152CB953002945F0 /* JFImageSavePanel-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "JFImageSavePanel-Info.plist"; sourceTree = "<group>"; };
96D7ACBB152CB953002945F0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
96D7ACBD152CB953002945F0 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
- 96D7ACBF152CB953002945F0 /* JFImageSavePanel-Prefix.pch */ = {isa = PBXFileReference; path = "JFImageSavePanel-Prefix.pch"; sourceTree = "<group>"; };
+ 96D7ACBF152CB953002945F0 /* JFImageSavePanel-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "JFImageSavePanel-Prefix.pch"; sourceTree = "<group>"; };
96D7ACC1152CB953002945F0 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; name = en; path = en.lproj/Credits.rtf; sourceTree = "<group>"; };
- 96D7ACC3152CB953002945F0 /* OFTAppDelegate.h */ = {isa = PBXFileReference; path = OFTAppDelegate.h; sourceTree = "<group>"; };
- 96D7ACC4152CB953002945F0 /* OFTAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OFTAppDelegate.m; sourceTree = "<group>"; };
+ 96D7ACC3152CB953002945F0 /* OFTAppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = OFTAppDelegate.h; path = JFImageSavePanel/OFTAppDelegate.h; sourceTree = "<group>"; };
+ 96D7ACC4152CB953002945F0 /* OFTAppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = OFTAppDelegate.m; path = JFImageSavePanel/OFTAppDelegate.m; sourceTree = "<group>"; };
96D7ACC7152CB954002945F0 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/MainMenu.xib; sourceTree = "<group>"; };
+ 96D7ACCE152CB9E7002945F0 /* JFImageSavePanel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JFImageSavePanel.h; sourceTree = "<group>"; };
+ 96D7ACCF152CB9E7002945F0 /* JFImageSavePanel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = JFImageSavePanel.m; sourceTree = "<group>"; };
+ 96D7ACD1152CBB6E002945F0 /* JFImageSavePanelAccessoryView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = JFImageSavePanelAccessoryView.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -46,6 +51,7 @@
96D7ACA2152CB953002945F0 = {
isa = PBXGroup;
children = (
+ 96D7ACD3152CDF24002945F0 /* Test */,
96D7ACB7152CB953002945F0 /* JFImageSavePanel */,
96D7ACB0152CB953002945F0 /* Frameworks */,
96D7ACAE152CB953002945F0 /* Products */,
@@ -82,10 +88,9 @@
96D7ACB7152CB953002945F0 /* JFImageSavePanel */ = {
isa = PBXGroup;
children = (
- 96D7ACC3152CB953002945F0 /* OFTAppDelegate.h */,
- 96D7ACC4152CB953002945F0 /* OFTAppDelegate.m */,
- 96D7ACC6152CB954002945F0 /* MainMenu.xib */,
- 96D7ACB8152CB953002945F0 /* Supporting Files */,
+ 96D7ACCE152CB9E7002945F0 /* JFImageSavePanel.h */,
+ 96D7ACCF152CB9E7002945F0 /* JFImageSavePanel.m */,
+ 96D7ACD1152CBB6E002945F0 /* JFImageSavePanelAccessoryView.xib */,
);
path = JFImageSavePanel;
sourceTree = "<group>";
@@ -100,6 +105,18 @@
96D7ACC0152CB953002945F0 /* Credits.rtf */,
);
name = "Supporting Files";
+ path = JFImageSavePanel;
+ sourceTree = "<group>";
+ };
+ 96D7ACD3152CDF24002945F0 /* Test */ = {
+ isa = PBXGroup;
+ children = (
+ 96D7ACB8152CB953002945F0 /* Supporting Files */,
+ 96D7ACC3152CB953002945F0 /* OFTAppDelegate.h */,
+ 96D7ACC4152CB953002945F0 /* OFTAppDelegate.m */,
+ 96D7ACC6152CB954002945F0 /* MainMenu.xib */,
+ );
+ name = Test;
sourceTree = "<group>";
};
/* End PBXGroup section */
@@ -155,6 +172,7 @@
96D7ACBC152CB953002945F0 /* InfoPlist.strings in Resources */,
96D7ACC2152CB953002945F0 /* Credits.rtf in Resources */,
96D7ACC8152CB954002945F0 /* MainMenu.xib in Resources */,
+ 96D7ACD2152CBB6E002945F0 /* JFImageSavePanelAccessoryView.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -167,6 +185,7 @@
files = (
96D7ACBE152CB953002945F0 /* main.m in Sources */,
96D7ACC5152CB953002945F0 /* OFTAppDelegate.m in Sources */,
+ 96D7ACD0152CB9E7002945F0 /* JFImageSavePanel.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -195,6 +214,7 @@
96D7ACC7152CB954002945F0 /* en */,
);
name = MainMenu.xib;
+ path = JFImageSavePanel;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Scheme
+ version = "1.3">
+ <BuildAction
+ parallelizeBuildables = "YES"
+ buildImplicitDependencies = "YES">
+ <BuildActionEntries>
+ <BuildActionEntry
+ buildForTesting = "YES"
+ buildForRunning = "YES"
+ buildForProfiling = "YES"
+ buildForArchiving = "YES"
+ buildForAnalyzing = "YES">
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "96D7ACAC152CB953002945F0"
+ BuildableName = "JFImageSavePanel.app"
+ BlueprintName = "JFImageSavePanel"
+ ReferencedContainer = "container:JFImageSavePanel.xcodeproj">
+ </BuildableReference>
+ </BuildActionEntry>
+ </BuildActionEntries>
+ </BuildAction>
+ <TestAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ buildConfiguration = "Debug">
+ <Testables>
+ </Testables>
+ <MacroExpansion>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "96D7ACAC152CB953002945F0"
+ BuildableName = "JFImageSavePanel.app"
+ BlueprintName = "JFImageSavePanel"
+ ReferencedContainer = "container:JFImageSavePanel.xcodeproj">
+ </BuildableReference>
+ </MacroExpansion>
+ </TestAction>
+ <LaunchAction
+ selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
+ selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
+ launchStyle = "0"
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Debug"
+ debugDocumentVersioning = "YES"
+ allowLocationSimulation = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "96D7ACAC152CB953002945F0"
+ BuildableName = "JFImageSavePanel.app"
+ BlueprintName = "JFImageSavePanel"
+ ReferencedContainer = "container:JFImageSavePanel.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ <AdditionalOptions>
+ </AdditionalOptions>
+ </LaunchAction>
+ <ProfileAction
+ shouldUseLaunchSchemeArgsEnv = "YES"
+ savedToolIdentifier = ""
+ useCustomWorkingDirectory = "NO"
+ buildConfiguration = "Release"
+ debugDocumentVersioning = "YES">
+ <BuildableProductRunnable>
+ <BuildableReference
+ BuildableIdentifier = "primary"
+ BlueprintIdentifier = "96D7ACAC152CB953002945F0"
+ BuildableName = "JFImageSavePanel.app"
+ BlueprintName = "JFImageSavePanel"
+ ReferencedContainer = "container:JFImageSavePanel.xcodeproj">
+ </BuildableReference>
+ </BuildableProductRunnable>
+ </ProfileAction>
+ <AnalyzeAction
+ buildConfiguration = "Debug">
+ </AnalyzeAction>
+ <ArchiveAction
+ buildConfiguration = "Release"
+ revealArchiveInOrganizer = "YES">
+ </ArchiveAction>
+</Scheme>
@@ -0,0 +1,22 @@
+<?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>SchemeUserState</key>
+ <dict>
+ <key>JFImageSavePanel.xcscheme</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>0</integer>
+ </dict>
+ </dict>
+ <key>SuppressBuildableAutocreation</key>
+ <dict>
+ <key>96D7ACAC152CB953002945F0</key>
+ <dict>
+ <key>primary</key>
+ <true/>
+ </dict>
+ </dict>
+</dict>
+</plist>
@@ -0,0 +1,14 @@
+#import <Foundation/Foundation.h>
+
+@interface JFImageSavePanel : NSObject
+{
+}
+
+@property (retain,nonatomic) NSString *title;
+@property (assign,nonatomic) const CFStringRef imageType;
+
++ (JFImageSavePanel *)savePanel;
+
+- (NSInteger)runModalForImage:(NSImage *)image error:(NSError **)error;
+
+@end
@@ -0,0 +1,153 @@
+#import "JFImageSavePanel.h"
+
+@interface JFImageSavePanel ()
+@property (retain) NSSavePanel *savePanel;
+@property (assign) IBOutlet NSView *accessoryView;
+@property (assign) IBOutlet NSPopUpButton *fileTypes;
+@property (assign) IBOutlet NSSlider *compressionFactor;
+
+- (void)configureSavePanel;
+- (void)fileTypeChanged:(id)sender;
+- (void)saveImage:(NSImage *)image;
+
+@end
+
+@implementation JFImageSavePanel
+
+@synthesize title, imageType;
+@synthesize savePanel, accessoryView, fileTypes, compressionFactor;
+
++ (JFImageSavePanel *)savePanel
+{
+ JFImageSavePanel *panel = [[JFImageSavePanel alloc] init];
+ return [panel autorelease];
+}
+
+- (id)init
+{
+ self = [super init];
+ if (self) {
+
+ self.title = @"Save Image";
+ self.imageType = kUTTypePNG;
+
+ self.savePanel = [NSSavePanel savePanel];
+
+ NSNib *accessoryNib = [[NSNib alloc] initWithNibNamed:@"JFImageSavePanelAccessoryView" bundle:nil];
+ [accessoryNib instantiateNibWithOwner:self topLevelObjects:nil];
+
+ [self.fileTypes setTarget:self];
+ [self.fileTypes setAction:@selector(fileTypeChanged:)];
+
+ [accessoryNib release];
+
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ self.title = nil;
+
+ self.savePanel = nil;
+
+ [self.accessoryView release];
+}
+
+- (NSInteger)runModalForImage:(NSImage *)image error:(NSError **)error
+{
+ [self configureSavePanel];
+ NSInteger result = [self.savePanel runModal];
+
+ if (result == NSFileHandlingPanelOKButton) {
+ [self saveImage:image];
+ }
+
+ return result;
+}
+
+- (void)configureSavePanel
+{
+ [self.savePanel setAccessoryView:self.accessoryView];
+
+ [self.savePanel setCanCreateDirectories:YES];
+ [self.savePanel setCanSelectHiddenExtension:YES];
+ [self.savePanel setExtensionHidden:NO];
+ [self.savePanel setAllowsOtherFileTypes:YES];
+
+ [self.savePanel setTitle:self.title];
+
+ if (UTTypeEqual(self.imageType, kUTTypeJPEG)) {
+ [self.fileTypes selectItemAtIndex:0];
+ } else if (UTTypeEqual(self.imageType, kUTTypePNG)) {
+ [self.fileTypes selectItemAtIndex:1];
+ } else if (UTTypeEqual(self.imageType, kUTTypeTIFF)) {
+ [self.fileTypes selectItemAtIndex:2];
+ }
+
+ [self fileTypeChanged:nil];
+
+}
+
+- (void)fileTypeChanged:(id)sender
+{
+ switch ([self.fileTypes indexOfSelectedItem]) {
+ case 0:
+ {
+ self.imageType = kUTTypeJPEG;
+ [self.compressionFactor setEnabled:YES];
+ [self.savePanel setAllowedFileTypes:[NSArray arrayWithObjects:(NSString*)kUTTypeJPEG, nil]];
+ break;
+ }
+ case 1:
+ {
+ self.imageType = kUTTypePNG;
+ [self.compressionFactor setEnabled:NO];
+ [self.savePanel setAllowedFileTypes:[NSArray arrayWithObjects:(NSString*)kUTTypePNG, nil]];
+ break;
+ }
+ case 2:
+ {
+ self.imageType = kUTTypeTIFF;
+ [self.compressionFactor setEnabled:NO];
+ [self.savePanel setAllowedFileTypes:[NSArray arrayWithObjects:(NSString*)kUTTypeTIFF, nil]];
+ break;
+ }
+ }
+
+ NSString *name = [self.savePanel nameFieldStringValue];
+ NSString *nameWithoutExtension = [name stringByDeletingPathExtension];
+
+ if (![name isEqualToString:nameWithoutExtension]) {
+ NSString *correctExtension = (NSString *) UTTypeCopyPreferredTagWithClass(self.imageType, kUTTagClassFilenameExtension);
+ name = [nameWithoutExtension stringByAppendingPathExtension:correctExtension];
+ [self.savePanel setNameFieldStringValue:name];
+ }
+}
+
+- (void)saveImage:(NSImage *)image
+{
+ NSData *outData = nil;
+
+ if (UTTypeEqual(self.imageType, kUTTypeJPEG)) {
+ CGFloat compression = [self.compressionFactor floatValue] / 100.0f;
+ outData = [NSBitmapImageRep representationOfImageRepsInArray:[image representations]
+ usingType:NSJPEGFileType
+ properties:[NSDictionary dictionaryWithObjectsAndKeys:
+ [NSNumber numberWithFloat:compression], NSImageCompressionFactor, nil]];
+ } else if (UTTypeEqual(self.imageType, kUTTypePNG)) {
+ outData = [NSBitmapImageRep representationOfImageRepsInArray:[image representations]
+ usingType:NSPNGFileType
+ properties:nil];
+ } else if (UTTypeEqual(self.imageType, kUTTypeTIFF)) {
+ outData = [NSBitmapImageRep representationOfImageRepsInArray:[image representations]
+ usingType:NSTIFFFileType
+ properties:nil];
+ }
+
+ if (outData) {
+ [outData writeToURL:[savePanel URL] atomically:YES];
+ }
+}
+
+@end
Oops, something went wrong.

0 comments on commit c58c6e0

Please sign in to comment.