Intro to Java Adapter Pattern

Programming, Tutorial 2 Comments »
This entry is part 11 of 13 in the series Intro to Java

In the last lesson we looked at patterns in general and why we might want to use them. So here is our first pattern. We are well on our way to creating a common language with which to talk design.

One of the reasons I picked this pattern to start with, is that it is very easy to understand. It models real word situations very well, and that is what OO design is supposed to do right, model real world objects?

The Adapter in the Physical World

The concept of an Adapter is easy to understand. It does just what it is named to do. It adapts one object to that of another. Take the wall plug. It has three rectangular holes set at angles to fit the plug. It does? In Europe it does. We are traveling and need to plug our laptop into the wall. What do we use? An adapter.

The Adapter in the Software World

The idea is not so different in the software world. When you want to connect one class to another class that was not designed to fit together, you need an adapter class. Let’s look at an Java example to see how we can adapt one class to another.
Read the rest of this entry »

Intro to Java Patterns

Programming, Tutorial No Comments »
This entry is part 10 of 13 in the series Intro to Java

Patterns are a very important part of Java. They allow us to speak a common language. The names can be misused, and thrown around by people trying to sound important, but they really do help us to be able to communicate ideas between us.

It does take some Java knowledge to be able to read, use and apply patterns, but I think we have seen enough Java and OO principles to start looking at patterns. It is good to start hearing about and seeing different patterns at any level of Java programming.

So what is a pattern? In the physical world, it would be a series of steps taken over and over again that could be written down and repeated. In the software world, it is not really a set of steps, but a software solution that people apply over and over again in their coding. Experienced developers have put these solutions together, and given their pattern a name. By looking at and studying patterns, we can take advantage of the experience of others, and learn from their solutions. One interesting thing about patterns, is that they don’t need to be language specific. If you learn about the Adapter or the Command pattern, you can apply that pattern to PHP, Ruby, or Java.
Read the rest of this entry »

Intro to Java Reflection

Programming, Tutorial No Comments »
This entry is part 6 of 13 in the series Intro to Java

Reflection is a very interesting part of Java. It is sometimes considered an advanced topic, but I think it is worth exploring here. There are several practical applications for using reflection, and we will look at a few here.

Sun Trails

Index: http://java.sun.com/docs/books/tutorial/index.html
Link into the Reflections Trail: http://java.sun.com/docs/books/tutorial/reflect/index.html

What is reflection?

Reflection is a little like cheating. It allows you to get access to classes and its methods and variables without accessing them the normal way. We don’t use the new operator to create an instance, and by using reflection we can get access even to private variables and methods. For this reason, we should be careful about using reflection. It is a powerful way of writing programs, but be sure not to overuse it.
Read the rest of this entry »

How to use Thickbox

Programming, Tutorial 5 Comments »

I have had a lot of hits on my How to use Lytebox post, and I thought I might continue it as a series and do something on another of the light box clones. It also looks like lytebox has been discontinued by the author. I have started to use Thickbox. Why you ask? It uses jQuery, and I am starting to really like that library. One of the things that drew me to lytebox was that it had no dependencies. But now, more sites require javascript anyway, and my library of choice is jQuery. So, if I am using jQuery, why not the Thickbox plugin?

If you are not sure about this library, check out this matrix that lists just about every light box type javascript library around.

Read the rest of this entry »

Intro to Java Abstract Classes

Programming, Tutorial No Comments »
This entry is part 5 of 13 in the series Intro to Java

Abstract classes are an interesting piece of Java. They can’t be used on their own, and they have a unique place in our code. They are often confused with interfaces, but they provide a great way to prevent code duplication and ensure consistent structures when building an application.

 In this tutorial we want to look at what Abstract classes are and when to use them. We will take a look at the previous Interfaces lesson and see how we could refactor our code from that lesson to use an Abstract class.
Read the rest of this entry »

Whitney Jumping Poster

Photo Shoot, Tutorial 2 Comments »

I was shooting at my studio class and noticed that some people were taking pictures of Whitney jumping. Whitney leads her cheer group, so she is a natural at this kind of thing. We weren’t really set up for this kind of shoot. We were doing head shots before.

Jumping as shot We had a gray muslin background, and the background light was too low and not configured correctly. I would have rathered it had a regular reflector pointing higher at the background. The background wasn’t really high enough either. To change the angle, I stood on a riser, and held my camera above my head. This way I wouldn’t have Whitney’s hands above the background.

We had to photogenics strobes in softboxes at 45deg to her that we had set up for portraits before. They still seemed to cover her well enough.

So I thought that I had a pretty good shot, but I wanted to so something with it. I didn’t like the background, and I needed a way to hide the light, so I decided to cut her out of the background.

This was harder than I thought. Well, actually just time consuming. The quick selection tool was horrible. It kept selecting parts of her. I then tried the magic wand. That was a little better, but there was still much to do. I then spent quite a bit of time with the other selection tools adding and subtracting from my selection.

Jumping on White Once I had her selected, I feathered the edge a few pixels, and then coppied her onto a blank layer. Another layer with a fill of white, and we were almost done.

When I looked at the edges of her legs, there was a bit of a grey line beside her jeans that didn’t look right. I replaced that grey with white. That looked much better.

Then I had an issue with her hair. I managed to “erase” some of her hair (actually did it with a mask) on the right side of her head. But, I am still not sure what to do about the grey that is still between her hair on the left side of her hair. I am sure that would show if printed.

Jumping Cheezy Poster So that wasn’t too bad, and was really what I had started out to do, but now that I had her seperated from the background, could I put her on a different background?

I looked through some older images and found one that was mostly clouds and sky. I then created another image with this sky, and added Whitney in as another layer. Because she was feathered when I cut her out, she placed pretty well on top.

Then, I expanded the canvas to give lots of space around the image. I added a drop shadow to the cloud layer and added the text at the bottom.

Voila. Cheezy poster.

Photoshop Photo Retouching

Photography, Tutorial 1 Comment »

I am not a pro at this. I would like to be more proficient, so last night I took it upon my self to have a go at retouching a photo. Not just the tweaking of exposure or a curves layer, but what could we do to the photo that a typical model might have done. So, here is the before picture.

portrait before¬†I thought this wasn’t too bad a picture, other than beeing a little dark. I fixed that with a curves layer. I chose the lighten preset. I don’t think I even tweaked it.

What I really wanted to do was things like smoothing the skin, whitening the teeth, and lightening the eyes.

First off, I thought that her skin was pretty good, but I knew that she had complained about not smiling too much because she didn’t want lines in the photos. He she has a nice smile. We can fix the little lines.

First, I selected the healing brush. There were a couple of little marks on her face that I wanted to deal with first. CTRL-click near the mark, then click on the mark it’s self. Done.

Next, the skin smoothing. First I created a new layer by copying the background layer. (Command-J) Then I went to the filters menu, and picked gaussian blur. I set this to 20%. The whole picture looks blurry, but that’s OK, we will apply this to only part of the picture. First lower the opacity of the layer to around 40%. You can adjust this later when we are done. What we need now is a layer mask. Add one to our new layer, then click the white layer mask, and fill it with black Command-Delete. Now the blur should be gone. We will now “paint” it back where we want it. Select a soft brush, that is not too big. You may want to zoom in on the picture. You can change the brush size with [ and ] on the keyboard. Now paint over the skin you want to smooth. Do not get the eyes or mouth. When you are done, play with the opacity of the layer until it looks how you want it.

portrait after¬†You can flatten the layers. Now to the teeth. Her teeth are fairly white – better than mine! Select an area of her mouth, making sure to get all the teeth, but some of her mouth is just fine.

After, create a new adjustment¬†layer for hue/saturation. When that dialog appears, click on the “Edit” dropdown and select Yellows. We are going to remove any yellow cast. Move the saturation slider all the way to the left. Yellow be gone. Now you can move the lightness slider to the right a little. Not too much. They need to stay natural.

If you have a lightened ring around the lips, we will need to fix that. The process is similar to that of the skin. We need to fill the layer mask with black. Click on the mask, Command-Delete to fill with black, and all our work will be un done. Now paint with white in a soft brush before just over her teeth.  Tada! You can flatten the image when done.

Only thing left is her eyes. First was the little bit of red eye. I selected the red eye tool, and clicked on the center of her eyes. Easy. Next was to whiten her eyes. I created a new copy of the background layer again, but this time I picked Screen for the blending mode. The picture immediately got ugly. That’s OK. Once again, create a layer mask, fill it with black. Then zoom in really close to her eyes. You will need a very fine brush to do this. Paint the whites part of her eyes. If you make a mistake, select a black foreground color, and “erase” your mistake. Sometimes this is the easier way to do it. After you are done, zoom out. Her eyes will look scary. You need to adjust the opacity of this layer downward. Move this until they look normal, but brighter. Select/un select the layer to see the before/after of this effect.

There you have it. I probably should have sharpened it too, but I was so proud of myself that I completely forgot. Oh well…

Intro to Java Interfaces

Programming, Tutorial No Comments »
This entry is part 4 of 13 in the series Intro to Java

Interfaces are a very important part of Java. They can also be quite confusing. In this lesson, we want to take a look at Interfaces, what they are, their relationship to classes, and how and why we use them.

Sun Trails

Index: http://java.sun.com/docs/books/tutorial/index.html

Link into Object Oriented Programming Concepts Trail: (interfaces) http://java.sun.com/docs/books/tutorial/java/concepts/interface.html

What is an Interface?

I think of an interface as like a contract. If you want to fulfill a contract, you have certain obligations to fulfill. The same for a Java contract (interface). An interface defines a set of obligations that an implementing class needs to provide. The obligations are nothing more than method signatures. No code, just the signatures. The class that implements the interface provides the code.

The other thing an interface does, is it allows different classes to appear similar, at least in so far as they implement the interface. As you will see, a Bird, a Fish, and a Mammal are not the same, but if they all implement the Animal interface, then we can treat them all like Animals.

Read the rest of this entry »

How to use Lytebox

Programming, Tutorial 21 Comments »

Note: lytebox appears to be discontinued by the author. See also Thickbox.

I was recently asked how to use lytebox in a gallery. The instructions at lyteboxes web page has several examples, but I guess they can seem a little overwhelming for some people, so I put together as basic an example as I could think of. It looks like this.

In this example, we are only dealing with useing lytebox with images in gallerys. There are lots of ways to use this library, and you can check his web page for the other options.

First, in order to use this library you need to get some files moved over. There are three things you need:

  1. lytebox.js
  2. lytebox.css
  3. images folder

These files need to be placed in the folder where your html file is going to be. So, for our example, this is what I have :

  1. index.html
  2. lytebox.js
  3. lytebox.css
  4. gallery.css
  5. images (folder)
  6. pictures (folder)

index.html is the gallery html file that has the thumbnails and pulls everything together. gallery.css is a css file to style our little gallery just a bit. You don’t need this file at all. The pictures folder is where I have all my images. You can organize your images how you would like.

Ok, lets look that what index.html looks like. The first thing you need to do is put some code in the <head> tag. This is to tell the browser where the lytebox css and js files are.

1
2
<script type="text/javascript" language="javascript" src="lytebox.js"></script>
<link rel="stylesheet" href="lytebox.css" type="text/css" media="screen" />

Then you need to create the links in the body of your document. I have chosen to link thumbnails to larger size images. Here is the code to one image:

1
<a href="pictures/Erie Night.jpg" rel="lytebox[gallery1]" title="Erie Night"><img src="pictures/Erie Night thumb.jpg"></a>

So, the path to the thumbnail is in the img tag. That is what shows up first. Then, in the a tag, you add the rel attribute. This is not really standard html. Html is not using the rel attribute, so lytebox has decided to use the attribute to signal it that you are linking the image within the href of the a tag through lytebox. This all happens in the background when your document loads, the lytebox.js file scans your document looking for these rel attributes, and adds some code to make it all work.

Also, look at the this: rel=”lytebox[gallery1]“. To make this work, you only need to say rel=”lytebox”. We put “gallery1″ inside the [] to link all these images together. This way lytebox knows to link these images together with “next” and “previous” buttons when the larger image comes up. In the example that I have here, I have two gallery’s, “gallery1″ and “gallery2″ so you can see how they work. One gallery per line.

Simple? Ok, so here is all the code in our example. I have here the code for the index.html and the gallery.css file. I have not listed the lytebox code. You can download that here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<html>
<head>
	<title>Lytebox Example</title>
	<script type="text/javascript" language="javascript" src="lytebox.js"></script>
	<link rel="stylesheet" href="lytebox.css" type="text/css" media="screen" />
	<link rel="stylesheet" href="gallery.css" type="text/css" media="screen" />
</head>
<body>
	<h1>Lytebox Example Gallery</h1>
	<a href="pictures/Erie Night.jpg" rel="lytebox[gallery1]" title="Erie Night"><img src="pictures/Erie Night thumb.jpg"></a>
	<a href="pictures/Field of Grass.jpg" rel="lytebox[gallery1]" title="Field of Grass"><img src="pictures/Field of Grass thumb.jpg"></a>
	<a href="pictures/Gentle Evening.jpg" rel="lytebox[gallery1]" title="Gentle Evening"><img src="pictures/Gentle Evening thumb.jpg"></a>
	<a href="pictures/Reflected Cloud.jpg" rel="lytebox[gallery1]" title="Reflected Cloud"><img src="pictures/Reflected Cloud thumb.jpg"></a>
	<br />
	<a href="pictures/Montana Cabin.jpg" rel="lytebox[gallery2]" title="Montana Cabin"><img src="pictures/Montana Cabin thumb.jpg"></a>
	<a href="pictures/Montana Road.jpg" rel="lytebox[gallery2]" title="Montana Road"><img src="pictures/Montana Road thumb.jpg"></a>
	<a href="pictures/Montana Sunset.jpg" rel="lytebox[gallery2]" title="Montana Sunset"><img src="pictures/Montana Sunset thumb.jpg"></a>
	<a href="pictures/Spoon and Cherry.jpg" rel="lytebox[gallery2]" title="Spoon and Cherry"><img src="pictures/Spoon and Cherry thumb.jpg"></a>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
body {
	background-color: black;
	text-align: center;
}
h1 {
	color: white;
	font-family: sans-serif;
}
img {
	border: solid 1px gray;
}
img:hover {
	border: solid 1px white;
	/* doesn't work in ie */
}

Check out the finished gallery here.

Intro To Java Classes Revisited

Programming, Tutorial No Comments »
This entry is part 3 of 13 in the series Intro to Java

This lesson will look more at class concepts in Java: Extending, overriding, composition, and inner classes. It was created as a lesson for a class room setting. I have converted it to a post here.

Is a Class just a Class?

I recently heard that the classic contractor response to a question is “Well, it depends.” That might just apply here. There are several different types of classes. There are regular classes, like we have been using, there are inner classes, and there are anonymous inner classes. In all cases though, they behave just the same. They still need to be instantiated, and they still contain variables and methods. What we will look at here is what those different types are, and when you might use them.

To do this, we will once again revisit the Robot. This time we will be adding a head that rotates to the Robot. We will look at placing the code directly into the Robot without using another class, using an inner class to Robot, and using containment to hold another class.

Before we get to that, lets revisit the parent/child relationship that exists when a class is extended and how casting works. Then we will get to the RobotHead.
Sun Trails Index: http://java.sun.com/docs/books/tutorial/index.html
Link into Objects and Classes Trail: (nested classes) http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html

Read the rest of this entry »

Powered by Wordpress
Entries RSS Comments RSS Log in