multiple images in 1 image view

Im working on something that is going to give a visual representation based on values that the user enters.

I have 2 fields, Horizontal and Vertical. When a customer puts in a number into the fields I want a image view to show the values by showing thumbnails.

Example, if user puts a 3 in the Horizontal and 2 in the vertical. I would like for 1 little image to be repeated 3 times across, and 2 times down.

Is there a good way about doing this?

Hello,

Try with a NSMatrix: you can insert or remove rows and columns, and display your thumbnails in image cells.

Regards,

fiz, thanks for the reply. Im not very familiar with NSMatrix except for the fact that can be used radio buttons. What would I use to say set the matrix to have 3 columns and 3 rows ? Im hoping if I start out easy like that I can learn how to make this dynamic on my own.

Here is an older post from rdelmar (who taught me a lot about NSMatrix). You can use it as a start. The basic idea is as follows:

First, you define a cell prototype (button, image, etc.) and you use this cell to initialize the matrix. Once the matrix (a descendant of NSView) is created, you place it in a superView (eg the content view of a window).

There are many posts on the NSMatrix - you can use the search function of macscripters.

And of course dive into the documentation :wink:

script NullMatrixAppDelegate
   property parent : class "NSObject"
   property mat : missing value --the matrix
   property cView : missing value --IBOutlet for the window's content view
   
   on applicationWillFinishLaunching_(aNotification)
       set myCell to current application's NSButtonCell's alloc()'s init()
       myCell's setTitle_(missing value)
       myCell's setBordered_(0)
       myCell's setBackgroundColor_(current application's NSColor's whiteColor())
       myCell's setBezelStyle_(current application's NSSmallSquareBezelStyle)
       
       set mat to current application's NSMatrix's alloc()'s initWithFrame_mode_prototype_numberOfRows_numberOfColumns_({{30, 30}, {400, 400}}, 1, myCell, 64, 64)
       --mat's setAutosizesCells_(1) --Makes the cells fill the whole frame of the matrix set in the init method
       mat's setCellSize_({8, 8}) --Not needed if you use the method above
       mat's sizeToCells() --Sizes the Matrix to fit the cells. The size of the matrix in the init method is ignored
       mat's setTarget_(me)
       mat's setAction_("click")
       mat's setBackgroundColor_(current application's NSColor's lightGrayColor())
       mat's setDrawsBackground_(1)
       cView's addSubview_(mat)
   end applicationWillFinishLaunching_
   
   on click()
mat's selectedCell()'s setBackgroundColor_(current application's NSColor's redColor())
   end click
   
end script

Regards,

Thanks for the code, I pretty much have it working but I am still trying to understand. So in this code is where the matrix is being created correct? You are not placing anykind of matrix in your IB xib?

OK, hopefully my last question (for this project). I have the matrix working great. Thanks Guys :slight_smile:

But I am looking to trigger this matrix when somebody tabs out of a specific text field. I know how to trigger this when a button is clicked, but im not sure what the terminology is for when somebody hits the tab out of a field.

If you can just tell me what to look for I will be happy to read up on it.

Thanks

petekin,

If you have not yet found it by yourself, you should:

a) declare your text field to “Send on end editing” in IB
b) set the delegate of the text field to your script, in IB too
c) write the handler controlTextDidChange_(aNotification) in your main script to handle the notification sent by the text field.

Regards,

Fiz, im hoping you can help me with this like you did before. I have a new app that is going to use the matrix to allow somebody to drag and drop a file into the matrix. I am looking to have only the filename populate each cell of the matrix.

Right now I have the matrix being created when from applicationWillFinishLaunching (Im using the example code above). But im not sure how to bring in the file names from a drag and drop from the finder of files.

I was also wondering if when the matrix cells are populated, is it possible to click and drag to swap positions inside the matrix?

Could you provide a PIC of your app so I can follow not only the code but what are your objectives.

t.

I think it would be a good idea to give us a better idea of what you want to do with this project. I don’t think that moving cells around in a matrix with dragging will be an easy thing to do. The drag and drop of the file isn’t too difficult, but requires that you subclass NSMatrix and implement some of the dragging destination protocol methods. Why do you want to move the cells around? Is that really important to what you need? Also, what do you want to do with this matrix of file names once you have it? Will the user be able to click on cells and open the files, for instance?

Ric

After Edit: As I think about this some more, it wouldn’t be that hard to move the file names around – you wouldn’t actually be moving the cells around, just switching titles between the button where you drag from to the button you drop on. There’s also no need to create the matrix in code, like above, just make it in IB.