1// 2// PRFilterController.m 3// PRICE 4// Filter Controller 5// 6// Created by Riccardo Mottola on 2/19/10. 7// Copyright 2010-2011 Carduus. All rights reserved. 8// 9// This application is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. 10// This program 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 General Public License for more details. 11 12 13#import "PRFilterController.h" 14#import "PRImage.h" 15#import "PRFilter.h" 16#import "MyDocument.h" 17 18@implementation PRFilterController 19 20- (void)dealloc 21{ 22 [oldParameters release]; 23 [filter release]; 24 [super dealloc]; 25} 26 27/** generic action to be called when the filter parameters change 28 and update of the preview is desired */ 29- (IBAction)parametersChanged:(id)sender 30{ 31 NSArray *newParameters; 32 33 newParameters = [self encodeParameters]; 34 35 if (oldParameters && [newParameters isEqualToArray:oldParameters]) 36 return; 37 38 [newParameters retain]; 39 [oldParameters release]; 40 oldParameters = newParameters; 41 if ([previewController continuous]) 42 [previewController updatePreview:sender]; 43} 44 45 46/** method to encode the interface settings and pass them as an array to the filter 47 it needs to be sublcassed by each filter controller */ 48- (NSArray *)encodeParameters 49{ 50 return nil; 51} 52 53/** shows the filter panel */ 54- (IBAction)showFilter:(id)sender 55{ 56 previewController = [[NSApp delegate] previewController]; 57 [previewController setFilterController: self]; 58 [previewController cleanPreview:self]; 59 [previewController showPreview]; 60} 61 62/** method to hide the filter panel. This needs to be overridden. 63 This method gets invoked if necessary at the end of filterOk. 64 This method gets invoked on filterCancel */ 65- (void)closeFilterPanel 66{ 67 NSLog(@"closeFilterPanel: This method should be overridden."); 68} 69 70/** action invoked to run the filter */ 71- (IBAction)filterOK:(id)sender 72{ 73 [[[NSDocumentController sharedDocumentController] currentDocument] runFilter:filter with:[self encodeParameters]]; 74 75 if ([[NSApp delegate] prefClosePanels]) 76 { 77 [self closeFilterPanel]; 78 [previewController hidePreview]; 79 } 80} 81 82/** action invoked by cancelling the filter action */ 83- (IBAction)filterCancel:(id)sender 84{ 85 [self closeFilterPanel]; 86 [previewController hidePreview]; 87} 88 89- (PRImage *)filteredImage 90{ 91 PRImage *img; 92 93 img = [filter filterImage:[[[NSDocumentController sharedDocumentController] currentDocument] activeImage] with:[self encodeParameters] progressPanel:previewController]; 94 95 return img; 96} 97 98@end 99