Sunday, November 30, 2008

Import a CD into iTunes when Artist, Album, and Track Info is Missing

Every now and then, when I buy a new CD and import the music into iTunes, the artist, album, and track names don't come with the music. Instead I would get something like unknown artist, unknown album, and track 01, track2, track 3, etc after the import. Of course, when I search my library for my new music, it cannot find it, which is very irritating. After much googling and trial and error, I eventually figured out how to import the CD and add all the information so that the music shows up in iTunes with all of the important information. I thought since it was difficult for me to figure out how to do it, I would make this post to help other people. The trick is actually quite simple...



Step 1: Insert the CD. iTunes should display all the tracks (Track 01, Track 02...) and the duration of each. Highlight all the tracks by typing CTRL+A or command+A on a Mac.


Step 2: Add the album information. With all the tracks highlighted, choose on File--->"Get Info" or command+I on a Mac. This brings up a dialog box in which you can add the artist and album information as well as the year, genre, and album artwork if you want. After you type in all the information, click "OK". When viewing the track list, the new information should be displayed next to all the tracks.



Step 3: Enter the track names. Highlight the first track and choose File--->"Get Info" or command+I on a Mac. This brings up a dialog box in which you can add the track names one by one. I usually find the track names for the album somewhere online, so I don't have to type them all, but rather just copy and paste them. So copy the first track name from a website, and paste it in the "Name" text box. Don't click OK quite yet. Instead click "Next" and then enter the second track name, clicking "Next" until you fill in all the names. Finally click OK after all the track names have been entered.


Step 4: Choose the file type that the music should be converted to during the import. I usually choose the MP3 format. Go to the iTunes preferences, and under the "General" tab, click "Import Settings...". A dialog box will pop up. Choose "MP3 Encoder" next to "Import Using:". Choose the quality you'd like. Also, if the CD didn't show up in iTunes when you inserted it, make sure "Show CD" is selected in this dialog box.


Step 5: Import the CD. By now, all the information about the CD has been entered, and you can import the tracks. In the bottom right hand corner of the iTunes window click on "Import CD".


Step 6: After the CD is imported, you can verify that the CD and all the correct information has been saved in your file system properly. By default, the music will be imported in the iTunes folder usually in the My Music folder on your hard drive. Doing a search in iTunes should also bring up your newly imported music!


Piece of cake!

Please comment if you found this useful or if something is inaccurate. :)

Friday, November 21, 2008

How to Add an Amazon Widget to Your Blog to Make Some Extra Cash

Amazon.com allows you to place customizable product advertising widgets on your website or blog, and in return splits the profits with you any time someone clicks on your widget and buys something within 24 hours. There are a million ways to earn revenue from your website or blog, but most of them can be quite annoying and spammy in my opinion. Flashy animated banner ads or the ones that grow in size and cover up what you're trying to read are the worst, while textual Google AdSense ads, and relevant Amazon product ads, while still advertisements, are the least obtrusive. Amazon gives you 4% of the product's price as a referral fee once the item is ordered and shipped, and the bonus increases the more items you refer to Amazon. Anyway, why not earn a couple bucks from the effort it takes to post helpful information on your website? I think people are willing to put up with a bit of advertising if the content of the website or blog is substantial.

What I like about the Amazon widgets is that they are customizable and can contain products relevant to your blog post. While it's an advertisement, I feel placing an
Amazon widget on a relevant blog post can also be seen as a service for the people looking for a quick link to buy that product from a trusted vendor.

The appearance of the widgets can be customized to match the look and feel of your website. There are also many different types of widgets you can use, giving you several choices. I discovered the Amazon widgets on someone else's blog, but it took me forever to figure out how to put them on my own blog. In this article I hope to save some of you the time it took me to get Amazon widgets on your website!

Step 1: First off, here are four different examples of widgets. There are a bunch of different ones available in addition to this.

Search Box Link:




Deals:




MP3 Clips:




My Favorites:



The My Favorites widget is the only one I really use on my blog. I embed it in the text of some of my articles so that the recommendation for the product is right where the product is talked about in most cases. Since I have been a customer of Amazon.com for quite a while now, I can feel guilt free when sending readers of my blog to their website because I know it's a reputable company.

Step 2: To get an Amazon widget for yourself, just click on the "Get Widget" button on the My Favorites widget above. This will take you to the Amazon.com Associates Central website where you can sign up for an associates account and start building your own widgets and get the code to embed in your website. Doing so is pretty easy after you have an account. Just for the sake of completeness, I'll show you how easy it is to build a My Favorites widget and embed it in your blog.

Step 3: After logged into your Amazon associates account, click on the "Widgets" tab and click "Add to Your Webpage" for the "My Favorites" widget.


Step 4: Search for the type of product you would like to advertise and add one or more. I just typed "widget" because this article is about Amazon widgets. Click "Add Product" for the products you like and they will show up in the right hand column. You can remove them and/or sort the order. When you're done, click "Next Step". You can always add or remove products later, even without re-embedding the widget code in your website.



Step 5: Customize the visual display of your widget. Give it a title, choose whether or not to randomly shuffle the products, and choose colors, etc. If you want to add more columns, you might have to change the width of the widget first in units of pixels. When you are done customizing it, click "Add to My Webpage".


Step 6: Add the widget code to your webpage. Click "Copy" in the small box that popped up to copy the HTML code that defines your new widget. This code will need to be pasted into your webpage.


Step 7: Paste your widget HTML code into your webpage. With a blogger blog you have to click on the "Edit HTML" tab and paste your code there where ever you want the widget to appear between the article text.

Piece of cake!

See also: Add an HTML Footer to Every Post of Your Blogger Blog
and Place an Inline Link to an Amazon Product with Your Associates ID



Monday, November 10, 2008

Eclipse RCP Tutorial Table of Contents

Following is a list of the Eclipse RCP tutorials found on this blog (obscuredclarity.blogspot.com). More articles will be added so please bookmark or subscribe to the RSS feed. Please leave a short comment if you find anything inaccurate with any of the tutorials. I would also love to know if this was useful to you or if you'd like to see a tutorial on something in particular that you're having problems with. Thanks! :)

1. Using Eclipse for RCP Application Development
2. Hello World with Eclipse RCP - Your First Application
3. Adding a View to an Eclipse RCP Application
4. Add an Icon to an Eclipse RCP Application View
5. Add a Menu to an Eclipse RCP Application
6. Verify User Intent Before Closing an Eclipse RCP Application
7. Add Nested Menu Items to an Eclipse RCP Application
8. Add a Custom Menu Action to an Eclipse RCP Application
9. Add an Image to an Eclipse RCP Application
10. Import and Export an Eclipse RCP Application Project
11. Updating a Widget in an Eclipse RCP Application from a Worker Thread
12. Animation in Eclipse RCP Applications - A Bouncing Ball
13. Add a Toolbar to a View in an Eclipse RCP Application
14. Add a Menu to a View in an Eclipse RCP Application
15. Using Simple JFace Message Boxes in an Eclipse RCP Application

These Eclipse RCP tutorial examples were done on a Mac, but should be identical for a Windows or Linux machine. The only difference is the look of Eclipse and your application.

Saturday, November 8, 2008

Adding a View to an Eclipse RCP Application

As shown in the article Hello World with Eclipse RCP - Your First Application, it is quite simple to create and run your own very basic Java RCP application using Eclipse. This article shows you how to add a "View" to your application. Part of learning how to create RCP applications using Eclipse is to learn the terminology people use. A view is the part of your application where you put things like tables, buttons, combo boxes, labels, charts, etc. - all the graphical interfaces that a user will interact with when using your application. These visible units of interaction are called "widgets" and Eclipse provides us with many customizable widgets in the SWT and JFACE libraries.

When an RCP application starts up, a string of events occurs under the hood that generates a stand-alone window containing all your customized widgets that give your program its unique look and functionality. At the top of the hierarchy is the Application class and contains the application's main method (actually called "start()"). In the start() method, a single Workbench object is created, which is a behind-the-scenes class controlling your RCP application. The Workbench in turn contains one or more WorkbenchWindow objects, which are the visible windows making up your program. In most cases you just have one WorkbenchWindow. A WorkbenchWindow in turn contains a menu (optional), a toolbar (optional), and/or one or more Perspective objects. In most cases you just have one Perspective. A Perspective in turn contains one Editor object and/or one or more View objects. View objects in turn contain one or more Widgets, which are the finest grain visible units of the RCP application. As a visual example of all this, look at the following BitTorrent application called Vuze (aka Azureus). You see a WorkbenchWindow with a menu, a toolbar, and two views called "My Torrents" and "Statistics". The "Statistics" view contains Tab widgets which in turn contain other widgets.





As a review, the hierarchy is like this:

Application
|
Workbench
|
WorkbenchWindow(s)
|
Perspective(s) Menu Toolbar
|
View(s) Editor
|
SWT and/or JFace Widget(s)

When Eclipse set up a HelloWorld RCP application for you with a wizard described here, it generated an Application, a Workbench, and a WorkbenchWindow with a Perspective. This article shows how to build off of that, by adding a View with a Label widget containing some text to the View. Let's get to it...

Step 0: Create a HelloWorld RCP application.

Step 1: Add the "views" extension point to your RCP project. Click on the "Extensions" tab along the bottom of the view in Eclipse that shows all the properties for your RCP project. If you don't see that view, double-click on "MANIFEST.MF" in the "META-INF" folder in your project folder in the Package Explorer. Here, you need to add an extension point to your application. Click "Add..." and a dialog box will pop up for selecting a new extension point. Scroll down and find the extension point called "org.eclipse.ui.views", select it and click "Finish".


Step 2: Add a View to your RCP project. You should now see the org.eclispe.ui.views extension added to the "All Extensions" list for your project. Right-click on "org.eclispe.ui.views" and select New --> view.


Step 3: Set the properties of the View. Make sure the View is highlighted in the All Extensions list. To the right you will be able to set some properties of the view. For right now, just the first two properties need to be set. In this example an id of com.blogspot.eclipsercptutorials.mainView and a name of MainView.


Step 4: Generate the view's class. In the properties list click on the "class" link. This will bring up a wizard. Leave everything at the default values but give it a name that matches the name you entered in the name property before. Click "Finish".

Step 5: Add some code to the MainView class that you generated earlier. You need to make sure a "public static final String" field called ID is defined and set equal to the id that you set in the view's properties editor. Also, in createPartControl() add two lines of code that creates a Label widget and set it's text. You may find that when you add the Label code you get an error "Label cannot be resolved to a type". This is because you haven't added an import statement yet above the class definition. The import statements tell the compiler what classes your class will be using. If you ever get an error like that, you can click on the class name, i.e. "Label", in your code and type ctrl+m (windows or Linux) or command+m (Mac). Make sure to always choose the SWT version of the widget and not the Swing or other type of class with the same name.

package com.blogspot.obscuredclarity.addview;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.part.ViewPart;

public class MainView extends ViewPart {

public static final String ID = "com.blogspot.eclipsercptutorials.mainView"; // the ID needs to match the id set in the view's properties

public MainView() { }

public void createPartControl(Composite parent) {

Label label = new Label(parent, SWT.None); //new up a Label widget
label.setText("  All this program does is display this text in a view."); //set the label's text

}

public void setFocus() { }

}


Step 6: Add the view to the application's perspective. Remember how when you used the wizard in Eclipse to create a standalone HelloWrold application and it generated a perspective for you automatically? And remember that views are children of perspectives? The Perspective class in your project should look similar to the following if you want it to add your new view. Open Perspective.java and add the two lines of code shown below in the createInitialLayout method.

package com.blogspot.obscuredclarity.addview;

import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

public class Perspective implements IPerspectiveFactory {

public void createInitialLayout(IPageLayout layout) {

layout.addStandaloneView(MainView.ID, false, IPageLayout.LEFT, 1.0f, layout.getEditorArea());
layout.setEditorAreaVisible(false); //hide the editor in the perspective
}
}


Step 7: Run your application. Congrats, you now have an Eclipse RCP application with a view! The view gives you a place to add more widgets and add funtionality to your program. The next things you'll want to add to your program are things like a menu, an editor, more views, status bars, a toolbar, and widgets.




Next ---> Add an Icon to an Eclipse RCP Application View
<--- Previous - Hello World with Eclipse RCP - Your First Application
Also see: Eclipse RCP Tutorial Table of Contents

Friday, November 7, 2008

Hello World with Eclipse RCP - Your First Application

As discussed in the article Using Eclipse for RCP Application Development, Eclipse is free and open-source software that people use to develop Java-based programs called Rich Client Platform (RCP) applications. Using a computer with any operating system (I happen to be using Mac OSX), you can use Eclipse to create an advanced program that can be deployed on Mac, Linux, and/or Windows OS. In this article, I will show how easy it is to get started using Eclipse and make your very own application even if you never wrote a line of code in your life. The program is going to be the classic "Hello World" application that programmers often write as their first program when trying out a new coding language or Integrated Development Environment (IDE). Before following along you'll need to have Eclipse and the Java Runtime Environment (JRE) installed as described here.



Step 1: Launch Eclipse and choose a "workspace". The workspace is where all the files needed for the application, either generated by Eclipse or written by you, will be located. The location I chose for my workspace is in a folder called "workspace" located in the directory that my Eclipse IDE folder resides. Once your application is created, you can navigate to that folder on your hard drive and actually find the files there.
Step 2: Launch the new project wizard in Eclipse. Select "File" from the menu, choose "New" and click "Project".

Step 3: When the new project wizard launches, select "Plugin Project" and click "Next".

Step 4: Enter a Project name and click "Next". The nomenclature that Java developers use is [top-level domain.your personal or company's domain name.project or application name]. So for me I entered com.timmolter.helloWorld. The reason for this is to avoid projects with the same name existing elsewhere in the world. If you named your project HelloWorld, there is a chance that there will be other projects out there named the exact same thing, which is bad. Sometimes people share their projects with the world, and having a unique project naming system keeps things in order. The point is to have a unique name that no one else will use.





Step 5: Choose "Yes" for "Would you like to create a rich client application?" and click "Next".

Step 6: Select the "Hello RCP" template and click "Finish".

Step 7: You may be asked if you want to use the Plug-in Development perspective. Choose Yes. This just specifies how you want the Eclipse IDE to be laid out when working on RCP applications.

Step 8: The new project wizard has created a project for you with all the necessary files and settings to make it an RCP Application. On the left side of the IDE you will see a view called "Package Explorer" which contains your new Hello World application files. These files shown in the view match what is found in your workspace folder, which you set up earlier. Navigate to your workspace folder and you should see your new project there.

Step 9: Launch your Hello World application. To do this, you need to be looking at the "Overview" shown in the center view above. This should have been the default thing displayed, but if it is not, just double-click on "MANIFEST.MF" in the "META-INF" folder in your new project folder in the Package Explorer view. On the "Overview" tab, click on the link called "Launch an Eclipse Application" in the "Testing" area. A small window should pop up with "Hello RCP" written at the top. Congrats, you just created and ran your first Eclipse RCP application!


After you close the program, feel free to look around the Overview of your project and also the "src" folder that is part of your project. The "src" folder is where the code that defines your program resides. There should be a package named the same as your project containing a handful of .java files. If you double-click on any of the .java files, they will open up in an editor view in the center of the Eclipse IDE. You may find it satisfying to open up ApplicationWorkbenchWindowAdvisor.java and change the title of your application in the preWindowOpen() method, by changing the "Hello RCP" string to something different and re-running the application.

While the Hello World program is quiet boring, it is nonetheless the first step in creating a real application that actually does something useful.

Next ---> Adding a View to an Eclipse RCP Application
<--- Previous - Using Eclipse for RCP Application Development

Also see: Eclipse RCP Tutorial Table of Contents

Tuesday, November 4, 2008

Using Eclipse for RCP Application Development

Eclipse is free and open-source software that people mainly use to write Java code and develop Java-based programs called Rich Client Platform (RCP) applications. Eclipse is an excellent, if not the best, Integrated Development Environment (IDE) for Java development. The goal of this article it to help anyone who is interested in creating computer applications, even if they never wrote a single line of code in their life before, to decide if Eclipse is right for them.

One popular RCP application created with Eclipse is Vuze, formerly known as Azureus, a BitTorrent client shown at right. A Rich Client Application can be a full-blown program with a menu bar, icons, toolbars, status bars, etc. It can have tabs, tables, buttons, charts, text boxes, wizards, preferences, dialog boxes, and more. It can be multi-threaded and there are virtually no limitations to your creativity. You could create your own version of Photoshop or just simple a program that plays your favorite song when you open it up. Anything is possible.

If you ever used Microsoft's Visual Studio for developing Windows applications with C#, Eclipse is like Java's version of an application used to develop other applications. I started using Microsoft Visual Studio back in 2005, but have since switched to Eclipse. Eclipse matches my programming philosophy and meets my needs much better than VS for the following reasons.
  • With Eclipse, you can develop your application once, and create exports for Windows, Mac, and Linux no matter what operating system (OS) you use as your development computer.
  • I found that creating an exported product with icons and everything to be much easier and intuitive with Eclipse.
  • Eclipse is free and open-source. Microsoft makes you pay for the IDE if you want the full-blown professional version. I like open-source.
I also think VS has its strengths over Eclipse:
  • The learning curve in creating your first application is much steeper with Eclipse. Getting used to the Eclipse IDE can be frustrating because it has many quirks, that until you figure out, you may spend a lot of time banging your head against the wall. I also found the classes used to simplify the layout of your GUI widgets (i.e. buttons, text boxes, graphics) were better designed in VS.
  • Online documentation and available quality books is much better for VS and programming Windows applications in C#.
All in all, I'm very glad I took the plunge and learned how to use Eclipse to develop RCP applications, and I don't miss VS at all. Some people argue that Java is slow, but I personally believe that is wrong. I've run my own similar C# and Java applications on a Windows system and I can't tell a difference. Java on a Mac and Linux is also very fast.

Another observation that I made is that an Eclipse RCP run on a Windows box will be slower than the same exact application run on a Mac or Linux machine with similar specs. After converting a Windows computer to a Linux computer, the application ran twice as fast and caught up to my other Mac and Linux machines. That's not saying Java is slow on Windows, just that Mac and Linux may be superior operating systems for Java applications. But in most cases, the difference will be negligible. The beauty of Eclipse is that you can choose whatever OS you like!

I want to write about my experience with Eclipse and help others avoid some of the frustrations I had getting started. It's my way of giving back to the people involved in making Eclipse possible because I've used it and enjoyed it a lot. So go ahead and download Eclipse and get started on your applications.


You'll want to download "Eclipse for RCP/Plug-in Developers", unzip it, and place it in an easy to access location in your file system. You can double click the Eclipse IDE launcher icon to open up Eclipse. Also make sure your computer has the Java JRE (Java 5 JRE or above) installed. If you have a Mac or a PC running Ubuntu (not sure about other Linux distros), it will already be installed. I like to make a shortcut on my desktop or drag the launcher icon to the dock (Mac).


You should be greeted with a splash screen as Eclipse loads...


and then the Welcome Page.



Next---> Hello World with Eclipse RCP - Your First Application
Also see: Eclipse RCP Tutorial Table of Contents

Monday, November 3, 2008

Electrostatic-Discharge ESD Explained

In response to a previous blog entry entitled 500GB MacBook Harddrive Upgrade for Under $100, a reader asked about Electrostatic-Discharge (ESD). In particular, he asked, "Would using simple gloves (like you use in labs and hospitals) be enough to prevent frying any electrical component of the computer's innards [when replacing a hard drive]?" Because ESD is a major concern for people handling electronics, whether it's building your own computer or replacing a hard drive, I think the topic warrants a bit of explanation given its importance. If you understand what ESD is, it's a no brainer on how to prevent it.



ESD is unwanted electric current flowing from one location to another. Examples are lightning, getting a shock by a door knob or another person, or zapping your electronics with your finger. Even a few millivolts can cause enough current to fry a transistor somewhere (and there are millions of them in a computer) if it's not designed to handle it. In the case of electronics, you want to prevent undesired flow of current by making yourself be at the exact same voltage potential as the electronics, which is 0 Volts. Wearing hospital gloves won't do that for you. What they will do for you is decrease the chance that current will flow from you to the electronics because it acts as an electrical insulator. But different gloves have different insulating properties, and you can build up different voltage potentials, which are factors in whether or not ESD will occur.

The point of touching the ground with your finger, which I recommended doing before touching raw electronics, is to ground your body (make your electrical potential 0 Volts). The earth is at 0 Volts for all practical purposes. "Ground" in electrical circuits always means 0 Volts. That way if you are at 0 Volts and the electronics are at 0 Volts, there is zero electrical potential between you and the object and it's impossible for any electric current to flow. In fact if you wore lab gloves and touched ground it could prevent a proper grounding because it would insulate you from the earth and not discharge that potential. Your best bet in preventing ESD it to touch the ground or something "electrically connected" to it with an ungloved finger. If you really want to be safe, buy a wrist strap and use it properly.

For someone else's explanation go here.