The Artima Developer Community
Sponsored Link

Agile Buzz Forum
How To Create A Custom Widget - Artist

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
How To Create A Custom Widget - Artist Posted: Aug 11, 2004 2:49 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: How To Create A Custom Widget - Artist
Feed Title: Pollock
Feed URL: http://www.cincomsmalltalk.com/rssBlog/pollock-rss.xml
Feed Description: Pollock - the next VW GUI
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Pollock

Advertisement

We have our pane, but if you try to execute "Calendar new", you'll get nothing but an exception saying "My subclass should have overridden one of my messages." That message is #artistClass. All panes have a hand full of methods that they are required to implement. If you have read my earlier postings on the general design of Pollock, each Pane has an Artist, which is where all drawing code resides, an Agent, which is where keystroke, mouse and other localized behavior code resides, and a Frame, which is in charge of laying out the pane in it's enclosing pane.

Today, we add our CalendarArtist.


Where To Subclass A New Artist

Just like the Pane, there are five standard places that one can add an Artist subclass.

The first and most general is as a subclass of AbstractArtist. This is where you add an Artist that has no generic common features with other Artists. It is the "Roll Your Own" spot in the Artist hierarchy. Examples of existing subclasses of AbstractArtist are the DividerArtist and the ResizingSplitterArtist.

If you wish your widget to be able to surround itself with one of the standard borders (line, ridged, raised, lowered or etched), then you'll want to subclass your Artist from ArtistWithBorder. This artist has all the general support for being able to draw one of the standard borders around your widget. Examples of existing subclasses of ArtistWithBorder are ButtonArtist, DisplayImageArtist and SingleLineLabelArtist.

If you are creating a pane which is a subclass of EditingPane, you should probably subclass from EditingArtist. It has all the drawing support for text display, insertion point and selection display. Of course, InputFieldArtist and TextEditArtist are subclasses of this class.

If you are creating a pane which is a subclass of EnumerationPane, you should probably subclass from EnumerationArtist. It has all the drawing support for displaying items in a list, displaying scrolled items in that list as well as various selection schemes such as checked vs highlight.

Finally, we come to the artist we'll be subclassing from: ActionDisplayArtist. This class has the rather unique behavior of knowing how to draw it's main component as well as it's "Display" component. Additionally, being that it manages the display of two widgets, it also has a unique capability to allow the managing of foreground and background colors for both the Display part and the Action part.

You might notice that there is no specific artist that has a correlation to the ComponentPane. This is because in Artist terms, the behavior of sub-panes in terms of drawing is simple... just paint yourself, then tell subpanes to paint themselves. We'll see this much later as we write the actual code that does the drawing of our Calendar.


CalendarArtist

As before, first we write a couple of tests before we write the "code":

	testCalendarArtistClassExistence
		self should: [#{Smalltalk.Pollock.CalendarArtist} ifDefinedDo: [:value | true] elseDo: [false]].

testCalendarArtistClassHierarchy self should: [#{Smalltalk.Pollock.CalendarArtist} ifDefinedDo: [:value | value superclass = ActionDisplayArtist] elseDo: [false]].

If we run these, they fail. So now we create our class:

	Smalltalk.Pollock defineClass: #CalendarArtist
		superclass: #{Pollock.ActionDisplayArtist}
		indexedType: #none
		private: false
		instanceVariableNames: ''
		classInstanceVariableNames: ''
		imports: ''
		category: 'Pollock-Calendar'

Now if we run our tests, they succeed!

We then go back to where we started today's post, and add our own #artistClass method, answering our new CalendarArtist:

	artistClass
		^CalendarArtist

The above is published as version 1.2 in the Package named "Pollock-Calendar" on the Cincom public repository.

If we now execute "Calendar new"...

Well, we still get an exception saying "My subclass should have overridden one of my messages." However, if we look further, we find that this exception is for #agentClass. As with the Artist and Pane, there are places in the Agent hierarchy we can place our Agent subclass. Unlike them, there is an existing Agent subclass we can use directly, without having to subclass... but we'll get into all that next time.


And So It Goes
Sames

Read: How To Create A Custom Widget - Artist

Topic: Re: Switching to a platform of love Previous Topic   Next Topic Topic: VW on OS X

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use