• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Fwd: BiDirectional NSLevelIndicator
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Fwd: BiDirectional NSLevelIndicator


  • Subject: Fwd: BiDirectional NSLevelIndicator
  • From: email@hidden
  • Date: Sun, 19 Mar 2006 12:52:21 -0800

Fred Glover wrote:


I need a bi-directional NSLevelIndicator. That is, Zero would be in the center and positive values will extend the level to the right, negative values to the left and zero would have a single bar in the center.
I still need the Min, Max, Warning and Critical values, however, two independent sets, one for each side.


Think something like a voltmeter that can display either positive or negative from the center.
So far all I can work out is to build two indicators and run them independently. However, since I can't make the standard control increase from right to left I have to "flip" the negative side in code. Rather messy in IB


Very awkward.
Any ideas?

Use normal bindings, and bind also the critical and warning values to the model object (selection or arrangedObjects).
Have the critical and warning values change when the main level is set.
To get critical or warning at both ends, simply get an NSNumber that is the absolute
value of your critical level (say 10) then just take the sign of the base number (perhaps voltage or something), and return a new number based on that sign.
When the voltage goes further negative, once it crosses zero, the level indicator will get a negative value for the warning and critical values and vice versa for positive voltage.


So your model object can have 3 accessors.

voltage
calculatedCriticalValue
calculatedWarningValue

and two default (if you want a default value) values for the critical and warning, the could be settable in initialization or data model or even UI at some point.

Either set dependent keys (calculatedCriticalValue, calculatedWarningValue ) to change when voltage is changed or do it manually in
the voltage setter e.g [self didChangeValueForKey:@"calculatedWarningValue"] .....


When the voltage changed in your accesors, just do the following. (Not tested)

- (NSDecimalNumber *)calculatedCriticalValue
{
NSDecimalNumber *absoluteCritical = [self valueForKey:@"absoluteCriticalValue"]; //Always assuming critical is positive (it can be enforced in the UI or validation methods)
NSDecimalNumber *currentVoltage = [self valueForKey:@"voltage"];
NSDecimalNumber *minusOne = [NSDecimalNumber decimalNumberWithMantissa:1 exponent :1 isNegative:YES];


if ([[NSDecimalNumber zero] compare:currentVoltage] == NSOrderedDescending) //Below Zero Voltage, so return the critical as negative
{
return [absoluteCritical decimalNumberByMultiplyingBy:minusOne];
}


//The value is zero for voltage or voltage is above zero, so ciritcal's sign is practically irrelevant since its already positive
return absoluteCritical;
}


Do the same for warning value. I think it should work.
This shouldn't be too awkward I think??

What do you think?

Andre


Fred



Fred Glover
Machine Vision and Image Processing Engineering
Visicon Inc
www.visiconeng.com
Los Gatos, CA
408 354-0095

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


Andre email@hidden



Andre
email@hidden



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: [SOLVED] NSDictionary writeToFile without going to disk?
  • Next by Date: MVC, DBA, CoreData (was: CoreData : fundamental (or not) questions)
  • Previous by thread: BiDirectional NSLevelIndicator
  • Next by thread: Fwd: BiDirectional NSLevelIndicator
  • Index(es):
    • Date
    • Thread