subclass

Subclassing UINavigationBar in Swift

两盒软妹~` 提交于 2019-12-05 15:36:59
I'm trying to create a custom UINavigationBar class and then use the Storyboard to set it as the class of my UINavigationController 's NavigationBar. Here's the code of my UINavigationBar class: class CustomNavBar: UINavigationBar { override func drawRect(rect: CGRect) { super.drawRect(rect) // Drawing code self.backgroundColor = UIColor.orangeColor() let myLabel = UILabel(frame: CGRect(x: 0, y: 4, width: 600, height: 36)) myLabel.backgroundColor = UIColor.purpleColor() myLabel.textColor = UIColor.yellowColor() myLabel.text = "Custom NavBar!" self.addSubview(myLabel) } } Then, in Interface

Cocoa: Stopping the field editor from auto-completing on space key

风格不统一 提交于 2019-12-05 14:19:59
I have a custom view with several NSTextField controls for which I want to supply custom auto-completions and I have successfully implemented all that using the NSTextFieldDelegate Protocol. The auto-completions are full names or place names, depending on which text field is being edited. The issue is that the auto-completions almost always contain a space character and so if the user is typing something that matches a suggestion, but doesn't want to accept that suggestion, the field editor will accept the suggestion when user presses the space key. I want the field editor to accept the

How to “hide” superclass methods in a subclass

半世苍凉 提交于 2019-12-05 08:46:57
I basically want to create a subclass that "hides" methods on the superclass so that they don't show up in a dir() or hasattr() call and the users can't call them (at least not through any of the normal channels). I would also like to do this with the least amount of "magic" possible. Thanks. Overriding the __dir__ and __getattribute__ method respectively should do the trick. This is the pretty much the canonical way to do this kind of stuff in Python. Although whether you should be actually doing this is entirely a different matter. See Python docs on Customizing Attribute Access Use __dir__

Subclass NSProgressIndicator

元气小坏坏 提交于 2019-12-05 08:35:34
i like to subclass a NSProgressIndicator. I've used this code and i set the Subclass in the Interface Builder: - (void)drawRect:(NSRect)dirtyRect { NSRect rect = NSInsetRect([self bounds], 1.0, 1.0); CGFloat radius = rect.size.height / 2; NSBezierPath *bz = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius]; [bz setLineWidth:2.0]; [[NSColor blackColor] set]; [bz stroke]; rect = NSInsetRect(rect, 2.0, 2.0); radius = rect.size.height / 2; bz = [NSBezierPath bezierPathWithRoundedRect:rect xRadius:radius yRadius:radius]; [bz setLineWidth:1.0]; [bz addClip]; rect.size.width

How to count the number of CRTP subclasses of a template class?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-05 08:27:57
Does anyone know of a method to use CRTP to count the number of subclasses of an object? Suppose we had a setup similar to the following one: template <typename T> class Object { .... }; const unsigned int ObjectSubClassCount = ...; class Subobject : public Object<SubObject> { .... }; class Second : public Object<Second> { .... }; and so on, such that, using TMP, we might have a constant ( ObjectSubClassCount ) that represents the total number of subclasses? Does anyone know a way to do this? Edit: I am wanting to use the result as a template parameter later on, so I need it to be done with

Cloning subclasses in Java

妖精的绣舞 提交于 2019-12-05 08:06:09
I need to clone a subclass in Java, but at the point in the code where this happens, I won't know the subclass type, only the super class. What's the best design pattern for doing this? Example: class Foo { String myFoo; public Foo(){} public Foo(Foo old) { this.myFoo = old.myFoo; } } class Bar extends Foo { String myBar; public Bar(){} public Bar(Bar old) { super(old); // copies myFoo this.myBar = old.myBar; } } class Copier { Foo foo; public Foo makeCopy(Foo oldFoo) { // this doesn't work if oldFoo is actually an // instance of Bar, because myBar is not copied Foo newFoo = new Foo(oldFoo);

Java Static Variables and inheritance and Memory

萝らか妹 提交于 2019-12-05 07:17:36
I know that if I have multiple instance of the same class all of them are gonna share the same class variables, so the static properties of the class will use a fixed amount of memory no matter how many instance of the class I have. My question is: If I have a couple subclasses inheriting some static field from their superclass, will they share the class variables or not? And if not, what is the best practice/pattern to make sure they share the same class variables? If I have a couple subclasses inheriting some static field from their superclass, will they share the class variables or not? Yes

Subclass a ParentForm WndProc from a Control

六眼飞鱼酱① 提交于 2019-12-05 02:06:31
问题 I am integrating a customized MenuStrip control into another .NET application. The MenuStrip works fine except for a focus issue. If the form hosting the MenuStrip is not focused, the user is required to click twice - once to activate the form and another time to select the menu items. The host form is a part of the separate .NET application which I cannot modify. I can only modify my control's source code. I found a solution at the WinForm level which overrides the Form WndProc method,

Shortcut for subclassing in Scala without repeating constructor arguments?

做~自己de王妃 提交于 2019-12-05 00:50:55
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) { // Implementation } class TestView(writer: XMLStreamWriter) extends View(writer) { // Implementation } Most subclasses of View are not going to take different constructor arguments. I would like to be able to write something like this: class TestView extends View { // Implementation } Is there some shortcut to write subclasses so that you don't have to explicitly define the constructor args and pass them to the superclass (so that I don't have to re-write all my subclasses if I change the signature of

SPARQL: Get all the entities of subclasses of a certain class

ε祈祈猫儿з 提交于 2019-12-05 00:44:18
I've to get all the instances of a class C and subclasses (direct or indirect) of C, in SPARQL. I can get all the direct subclasses of C in this way: SELECT ?entity WHERE { ?subclass rdfs:subClassOf :C . ?entity rdf:type ?subclass . } But I can't get the instances of an indirect subclass and neither any instance of C. As I know (I've pre-calculated them) all the subclasses (direct and indirect of C), and I can build a dynamic query, is it possible build a query like the following one? SELECT ?entity WHERE { ?entity rdf:type in <list>. } Thanks to everyone. EDIT: I've just solved it, even if in