Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adjust brightness of color for selected row.

  • Loading branch information...
commit ff956f53579f0ea86682badcc66149a48bbc4f52 1 parent 2a5d451
@mmower authored
Showing with 46 additions and 0 deletions.
  1. +46 −0 LogDocument.m
  2. BIN  ticked_checkbox.png
View
46 LogDocument.m
@@ -17,13 +17,44 @@
static NSString *RemoveToolbarItemIdentifier = @"spike.toolbar.remove";
static NSString *SearchToolbarItemIdentifier = @"spike.toolbar.search";
+float adjusted_brightness( float brightness ) {
+ brightness *= 1.5;
+ if( brightness > 1.0 ) {
+ brightness = 1.0;
+ }
+ return brightness;
+}
+
+static NSMutableDictionary *HTTPMethodColors;
+
@interface LogDocument (PrivateMethods)
++ (NSColor *)colorForHTTPMethod:(NSString *)method;
- (void)parseLogFile:(NSData *)data;
- (NSData *)gunzipedDataFromData:(NSData *)compressedData;
@end
@implementation LogDocument
++ (void)initialize {
+ if( !HTTPMethodColors ) {
+ HTTPMethodColors = [NSMutableDictionary dictionaryWithCapacity:4];
+
+ [HTTPMethodColors setObject:[NSColor colorWithDeviceRed:(20.0/255) green:(128.0/255) blue:(65.0/255) alpha:1.0] forKey:@"GET"];
+ [HTTPMethodColors setObject:[NSColor blueColor] forKey:@"PUT"];
+ [HTTPMethodColors setObject:[NSColor blueColor] forKey:@"POST"];
+ [HTTPMethodColors setObject:[NSColor redColor] forKey:@"DELETE"];
+ }
+}
+
++ (NSColor *)colorForHTTPMethod:(NSString *)method {
+ NSColor *color = [HTTPMethodColors objectForKey:[method uppercaseString]];
+ if( color ) {
+ return color;
+ } else {
+ return [NSColor controlTextColor];
+ }
+}
+
- (void)makeWindowControllers {
NSWindowController *documentController = [[NSWindowController alloc] initWithWindowNibName:@"LogDocument" owner:self];
[self addWindowController:documentController];
@@ -78,6 +109,21 @@ - (NSToolbarItem *)toolbar:(NSToolbar *)aToolbar itemForItemIdentifier:(NSString
}
+#pragma mark NSTableView delegate implementations
+
+- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex {
+ if( [[tableColumn identifier] isEqualToString:@"method"] ) {
+ NSColor *color = [[self class] colorForHTTPMethod:[cell stringValue]];
+ if( rowIndex == [tableView selectedRow] ) {
+ color = [NSColor colorWithDeviceHue:[color hueComponent] saturation:[color saturationComponent] brightness:adjusted_brightness([color brightnessComponent]) alpha:1.0];
+ }
+ [cell setTextColor:color];
+ } else if( [cell respondsToSelector:@selector(setTextColor:)]) {
+ [cell setTextColor:[NSColor controlTextColor]];
+ }
+}
+
+
#pragma mark Actions
- (IBAction)removeSimilarRequests:(id)sender {
View
BIN  ticked_checkbox.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Please sign in to comment.
Something went wrong with that request. Please try again.