diff --git a/projects/robodj/build.xml b/projects/robodj/build.xml index 599c721f..601aed20 100644 --- a/projects/robodj/build.xml +++ b/projects/robodj/build.xml @@ -29,8 +29,8 @@ - + diff --git a/projects/robodj/src/java/robodj/chooser/ChooserFrame.java b/projects/robodj/src/java/robodj/chooser/ChooserFrame.java index f9c1a600..f24325c6 100644 --- a/projects/robodj/src/java/robodj/chooser/ChooserFrame.java +++ b/projects/robodj/src/java/robodj/chooser/ChooserFrame.java @@ -1,11 +1,12 @@ // -// $Id: ChooserFrame.java,v 1.8 2002/03/03 17:21:46 mdb Exp $ +// $Id: ChooserFrame.java,v 1.9 2002/03/03 20:56:12 mdb Exp $ package robodj.chooser; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; + import javax.swing.*; import com.samskivert.swing.*; @@ -16,6 +17,7 @@ import com.samskivert.swing.util.TaskMaster; import robodj.Log; import robodj.Version; import robodj.repository.*; +import robodj.util.ButtonUtil; import robodj.util.ServerControl.PlayingListener; public class ChooserFrame extends JFrame @@ -58,11 +60,20 @@ public class ChooserFrame extends JFrame JPanel cbar = new JPanel(bgl); // add some fake control buttons for now - cbar.add(createControlButton("Back", "back")); - cbar.add(_stop = createControlButton("Stop", "stop")); - cbar.add(_pause = createControlButton("Pause", "pause")); - cbar.add(createControlButton("Skip", "skip")); - cbar.add(createControlButton("Exit", "exit")); + cbar.add(ButtonUtil.createControlButton( + BACK_TIP, "back", BACK_ICON_PATH, this, true)); + _stop = ButtonUtil.createControlButton( + STOP_TIP, "stop", STOP_ICON_PATH, this, true); + cbar.add(_stop); + _pauseIcon = ButtonUtil.getIcon(PAUSE_ICON_PATH); + _playIcon = ButtonUtil.getIcon(PLAY_ICON_PATH); + _pause = ButtonUtil.createControlButton( + "", "pause", _pauseIcon, this, true); + cbar.add(_pause); + cbar.add(ButtonUtil.createControlButton( + SKIP_TIP, "skip", SKIP_ICON_PATH, this, true)); + cbar.add(ButtonUtil.createControlButton( + EXIT_TIP, "exit", EXIT_ICON_PATH, this, true)); // stick it into the frame top.add(cbar, GroupLayout.FIXED); @@ -78,14 +89,6 @@ public class ChooserFrame extends JFrame TaskMaster.invokeMethodTask("refreshPlaying", Chooser.scontrol, this); } - protected JButton createControlButton (String label, String action) - { - JButton cbut = new JButton(label); - cbut.setActionCommand(action); - cbut.addActionListener(this); - return cbut; - } - public void actionPerformed (ActionEvent e) { String cmd = e.getActionCommand(); @@ -133,12 +136,14 @@ public class ChooserFrame extends JFrame public void playingUpdated (int songid, boolean paused) { if (songid == -1 || paused) { - _pause.setLabel("Play"); + _pause.setToolTipText(PLAY_TIP); _pause.setActionCommand("play"); + _pause.setIcon(_playIcon); } else { - _pause.setLabel("Pause"); + _pause.setToolTipText(PAUSE_TIP); _pause.setActionCommand("pause"); + _pause.setIcon(_pauseIcon); } _stop.setEnabled(songid != -1); @@ -149,4 +154,26 @@ public class ChooserFrame extends JFrame /** A reference to the stop button. */ protected JButton _stop; + + // used when toggling between play and pause + protected ImageIcon _playIcon; + protected ImageIcon _pauseIcon; + + // icon paths + protected static final String ICON_ROOT = "/robodj/chooser/images/"; + protected static final String PLAY_ICON_PATH = ICON_ROOT + "play.png"; + protected static final String PAUSE_ICON_PATH = ICON_ROOT + "pause.png"; + protected static final String STOP_ICON_PATH = ICON_ROOT + "stop.png"; + protected static final String SKIP_ICON_PATH = ICON_ROOT + "skip.png"; + protected static final String BACK_ICON_PATH = ICON_ROOT + "back.png"; + protected static final String EXIT_ICON_PATH = ICON_ROOT + "exit.png"; + + // button tips + protected static final String PLAY_TIP = "Play"; + protected static final String PAUSE_TIP = + "Pause the currently playing song"; + protected static final String STOP_TIP = "Stop the currently playing song"; + protected static final String SKIP_TIP = "Skip to the next song"; + protected static final String BACK_TIP = "Skip to the previous song"; + protected static final String EXIT_TIP = "Exit"; } diff --git a/projects/robodj/src/java/robodj/chooser/EntryList.java b/projects/robodj/src/java/robodj/chooser/EntryList.java index 02eddd73..f2b10f70 100644 --- a/projects/robodj/src/java/robodj/chooser/EntryList.java +++ b/projects/robodj/src/java/robodj/chooser/EntryList.java @@ -1,5 +1,5 @@ // -// $Id: EntryList.java,v 1.11 2002/02/28 16:32:45 mdb Exp $ +// $Id: EntryList.java,v 1.12 2002/03/03 20:56:12 mdb Exp $ package robodj.chooser; @@ -18,37 +18,39 @@ import com.samskivert.swing.util.*; import robodj.Log; import robodj.repository.*; +import robodj.util.ButtonUtil; -public abstract class EntryList extends JPanel +public abstract class EntryList extends JScrollPane implements TaskObserver, ActionListener, AncestorListener { public EntryList () { - GroupLayout gl = new VGroupLayout(GroupLayout.STRETCH); - gl.setOffAxisPolicy(GroupLayout.STRETCH); - setLayout(gl); - // create the pane that will hold the buttons - gl = new VGroupLayout(GroupLayout.NONE); + GroupLayout gl = new VGroupLayout(GroupLayout.NONE); + gl.setOffAxisPolicy(GroupLayout.STRETCH); gl.setJustification(GroupLayout.TOP); - _bpanel = new ScrollablePanel(); + gl.setGap(2); + _bpanel = new ScrollablePanel() { + // make the playlist fit the width of the scrolling viewport + public boolean getScrollableTracksViewportWidth () { + return true; + } + }; _bpanel.setLayout(gl); // give ourselves a wee bit of a border _bpanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - // put it into a scrolling pane - _scroller = new JScrollPane(_bpanel); - add(_scroller); - - // add our navigation button - _upbut = new JButton("Up"); - _upbut.setActionCommand("up"); - _upbut.addActionListener(this); - add(_upbut, GroupLayout.FIXED); + // set our viewport view + setViewportView(_bpanel); // use a special font for our name buttons - _nameFont = new Font("Helvetica", Font.PLAIN, 10); + _titleFont = new Font("Helvetica", Font.BOLD, 14); + _nameFont = new Font("Helvetica", Font.PLAIN, 12); + + // create our icons + _browseIcon = ButtonUtil.getIcon(BROWSE_ICON_PATH); + _playIcon = ButtonUtil.getIcon(PLAY_ICON_PATH); // listen to ancestor events addAncestorListener(this); @@ -131,17 +133,9 @@ public abstract class EntryList extends JPanel */ protected void populateEntries (Entry[] entries) { - // disable the up button because we're at the top level - _upbut.setEnabled(false); - // clear out any existing children _bpanel.removeAll(); - // adjust our layout policy - GroupLayout gl = (GroupLayout)_bpanel.getLayout(); - gl.setOffAxisPolicy(GroupLayout.EQUALIZE); - gl.setOffAxisJustification(GroupLayout.LEFT); - // sort our entries Comparator ecomp = new Comparator() { public int compare (Object o1, Object o2) { @@ -165,26 +159,30 @@ public abstract class EntryList extends JPanel } // create a browse and a play button - JPanel hpanel = new JPanel(); - gl = new HGroupLayout(GroupLayout.NONE); + GroupLayout gl = new HGroupLayout(GroupLayout.NONE); gl.setOffAxisPolicy(GroupLayout.STRETCH); gl.setJustification(GroupLayout.LEFT); - hpanel.setLayout(gl); - + JPanel hpanel = new JPanel(gl); JButton button; - button = new JButton(entries[i].title); - button.setFont(_nameFont); - button.setActionCommand("browse"); - button.addActionListener(this); - button.putClientProperty("entry", entries[i]); - button.setToolTipText("Entry ID: " + entries[i].entryid); - hpanel.add(button); - button = new JButton("Play"); - button.setActionCommand("playall"); - button.addActionListener(this); + // add a browse button + button = ButtonUtil.createControlButton( + BROWSE_ENTRY_TIP, "browse", _browseIcon, this, true); button.putClientProperty("entry", entries[i]); - hpanel.add(button); + hpanel.add(button, GroupLayout.FIXED); + + // add a play all button + button = ButtonUtil.createControlButton( + PLAY_ENTRY_TIP, "playall", _playIcon, this, true); + button.putClientProperty("entry", entries[i]); + hpanel.add(button, GroupLayout.FIXED); + + // add the entry title + JLabel entryLabel = new JLabel(entries[i].title); + entryLabel.setFont(_nameFont); + entryLabel.setToolTipText(entries[i].title + + " (" + entries[i].entryid + ")"); + hpanel.add(entryLabel); _bpanel.add(hpanel); } @@ -211,21 +209,33 @@ public abstract class EntryList extends JPanel protected void populateSong (Entry entry) { - // enable the up button because we're looking at a song - _upbut.setEnabled(true); - // clear out any existing children _bpanel.removeAll(); - // adjust our layout policy - ((GroupLayout)_bpanel.getLayout()).setOffAxisPolicy( - GroupLayout.NONE); + GroupLayout gl = new HGroupLayout(HGroupLayout.STRETCH); + gl.setJustification(GroupLayout.LEFT); + JPanel header = new JPanel(gl); - // create a combo box and accoutrements for selecting the category - JPanel catPanel = new JPanel(new HGroupLayout(GroupLayout.STRETCH)); - JLabel catLabel = new JLabel("Set category"); + // add the album title + JLabel label = new JLabel(entry.title); + label.setToolTipText(entry.title); + label.setFont(_titleFont); + header.add(label); + + // add a button for getting the heck out of here + JButton upbtn = ButtonUtil.createControlButton( + UP_TIP, "up", ButtonUtil.getIcon(UP_ICON_PATH), this, true); + header.add(upbtn, GroupLayout.FIXED); + + // create an edit button + JButton ebtn = ButtonUtil.createControlButton( + EDIT_TIP, "edit", ButtonUtil.getIcon(EDIT_ICON_PATH), this, true); + header.add(ebtn, GroupLayout.FIXED); + + // add a combo box for categorizing JComboBox catcombo = new JComboBox(ModelUtil.catBoxNames(Chooser.model)); + header.add(catcombo, GroupLayout.FIXED); // configure the combo box catcombo.addActionListener(this); @@ -234,20 +244,7 @@ public abstract class EntryList extends JPanel int catidx = ModelUtil.getCategoryIndex(Chooser.model, catid); catcombo.setSelectedIndex(catidx+1); - // create an edit button - JButton ebtn = new JButton("Edit entry"); - ebtn.setActionCommand("edit"); - ebtn.addActionListener(this); - - // wire it all up - catPanel.add(catLabel, GroupLayout.FIXED); - catPanel.add(catcombo); - catPanel.add(ebtn, GroupLayout.FIXED); - _bpanel.add(catPanel, GroupLayout.FIXED); - - // add a label for the title - JLabel label = new JLabel(entry.title); - _bpanel.add(label); + _bpanel.add(header, GroupLayout.FIXED); // sort the songs by position Comparator scomp = new Comparator() { @@ -263,13 +260,23 @@ public abstract class EntryList extends JPanel // and add buttons for every song for (int i = 0; i < entry.songs.length; i++) { - JButton button = new JButton(entry.songs[i].title); - button.setFont(_nameFont); - button.setActionCommand("play"); - button.addActionListener(this); - button.setHorizontalAlignment(JButton.LEFT); + gl = new HGroupLayout(GroupLayout.NONE); + gl.setJustification(GroupLayout.LEFT); + JPanel hpanel = new JPanel(gl); + + // add a button for playing the song + JButton button = ButtonUtil.createControlButton( + PLAY_SONG_TIP, "play", _playIcon, this, true); button.putClientProperty("song", entry.songs[i]); - _bpanel.add(button); + hpanel.add(button, GroupLayout.FIXED); + + // add the song title + JLabel trackLabel = new JLabel(entry.songs[i].title); + trackLabel.setFont(_nameFont); + trackLabel.setToolTipText(entry.songs[i].title); + hpanel.add(trackLabel); + + _bpanel.add(hpanel); } // reset our scroll position so that we're displaying the top of @@ -278,12 +285,12 @@ public abstract class EntryList extends JPanel // we've removed and added components so we need to revalidate revalidate(); + repaint(); } protected void clearScrollPosition () { - BoundedRangeModel model = - _scroller.getVerticalScrollBar().getModel(); + BoundedRangeModel model = getVerticalScrollBar().getModel(); model.setValue(model.getMinimum()); } @@ -326,7 +333,7 @@ public abstract class EntryList extends JPanel TaskMaster.invokeMethodTask("recategorizeEntry", this, this); } else { - System.out.println("Unknown action event: " + cmd); + Log.warning("Unknown action event: " + cmd); } } @@ -338,6 +345,7 @@ public abstract class EntryList extends JPanel // we need to revalidate the component because we added a child revalidate(); + repaint(); // start up the task that reads the CD info from the database TaskMaster.invokeMethodTask("readEntries", this, this); @@ -354,14 +362,31 @@ public abstract class EntryList extends JPanel // nothing doing } - protected JScrollPane _scroller; protected JPanel _bpanel; - protected JButton _upbut; protected Entry[] _entries; - protected Entry _entry; protected int _newcatid; + protected Font _titleFont; protected Font _nameFont; + protected ImageIcon _playIcon; + protected ImageIcon _browseIcon; + + protected static final String PLAY_ENTRY_TIP = + "Append this album to the playlist"; + protected static final String PLAY_SONG_TIP = + "Append this song to the playlist"; + protected static final String BROWSE_ENTRY_TIP = + "Browse the songs in this album"; + protected static final String UP_TIP = + "Back up to albums listing"; + protected static final String EDIT_TIP = + "Edit the album information"; + + protected static final String ICON_ROOT = "/robodj/chooser/images/"; + protected static final String PLAY_ICON_PATH = ICON_ROOT + "play.png"; + protected static final String BROWSE_ICON_PATH = ICON_ROOT + "browse.png"; + protected static final String UP_ICON_PATH = ICON_ROOT + "up.png"; + protected static final String EDIT_ICON_PATH = ICON_ROOT + "edit.png"; } diff --git a/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java b/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java index 6cde24a0..6333469b 100644 --- a/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java +++ b/projects/robodj/src/java/robodj/chooser/PlaylistPanel.java @@ -1,5 +1,5 @@ // -// $Id: PlaylistPanel.java,v 1.12 2002/03/03 17:21:46 mdb Exp $ +// $Id: PlaylistPanel.java,v 1.13 2002/03/03 20:56:12 mdb Exp $ package robodj.chooser; @@ -18,6 +18,7 @@ import com.samskivert.util.StringUtil; import robodj.Log; import robodj.repository.*; +import robodj.util.ButtonUtil; import robodj.util.ServerControl.PlayingListener; public class PlaylistPanel extends JPanel @@ -32,6 +33,7 @@ public class PlaylistPanel extends JPanel // create the pane that will hold the buttons gl = new VGroupLayout(GroupLayout.NONE); gl.setJustification(GroupLayout.TOP); + gl.setGap(2); _bpanel = new SmartPanel(); _bpanel.setLayout(gl); @@ -47,12 +49,20 @@ public class PlaylistPanel extends JPanel JPanel cbar = new JPanel(bgl); // add our control buttons - cbar.add(_clearbut = createControlButton("Clear", "clear")); - cbar.add(createControlButton("Refresh", "refresh")); + _clearbut = ButtonUtil.createControlButton( + CLEAR_TIP, "clear", CLEAR_ICON_PATH, this); + cbar.add(_clearbut); + cbar.add(ButtonUtil.createControlButton( + REFRESH_TIP, "refresh", REFRESH_ICON_PATH, this)); add(cbar, GroupLayout.FIXED); // use a special font for our name buttons - _nameFont = new Font("Helvetica", Font.PLAIN, 10); + _nameFont = new Font("Helvetica", Font.PLAIN, 12); + + // create our icons + _skiptoIcon = ButtonUtil.getIcon(SKIPTO_ICON_PATH); + _removeSongIcon = ButtonUtil.getIcon(REMOVE_SONG_ICON_PATH); + _removeEntryIcon = ButtonUtil.getIcon(REMOVE_ENTRY_ICON_PATH); // add ourselves as a playing listener Chooser.scontrol.addPlayingListener(this); @@ -61,14 +71,6 @@ public class PlaylistPanel extends JPanel refreshPlaylist(); } - protected JButton createControlButton (String label, String action) - { - JButton cbut = new JButton(label); - cbut.setActionCommand(action); - cbut.addActionListener(this); - return cbut; - } - public void actionPerformed (ActionEvent e) { String cmd = e.getActionCommand(); @@ -264,7 +266,8 @@ public class PlaylistPanel extends JPanel JLabel label = new JLabel(entry.entry.title + " - " + entry.entry.artist); tpanel.add(label); - tpanel.add(newButton("Remove", "remove_all", entry)); + tpanel.add(newButton(REMOVE_ENTRY_TIP, "remove_all", + _removeEntryIcon, entry)); _bpanel.add(tpanel); } @@ -276,15 +279,17 @@ public class PlaylistPanel extends JPanel gl.setJustification(GroupLayout.LEFT); hpanel.setLayout(gl); + hpanel.add(newButton(SKIPTO_TIP, "skipto", _skiptoIcon, entry)); + hpanel.add(newButton(REMOVE_SONG_TIP, "remove", + _removeSongIcon, entry)); + entry.label = new JLabel(entry.song.title); entry.label.setForeground((entry.song.songid == _playid) ? Color.red : Color.black); entry.label.setFont(_nameFont); + entry.label.setToolTipText(entry.song.title); hpanel.add(entry.label); - hpanel.add(newButton("Skip to", "skipto", entry)); - hpanel.add(newButton("Remove", "remove", entry)); - // let the bpanel know that we want to scroll the active track // label into place once we're all laid out if (entry.song.songid == _playid) { @@ -304,13 +309,11 @@ public class PlaylistPanel extends JPanel _bpanel.revalidate(); } - protected JButton newButton (String label, String command, - Object clientProperty) + protected JButton newButton (String tooltip, String command, + ImageIcon icon, Object clientProperty) { - JButton button = new JButton(label); - button.setFont(_nameFont); - button.setActionCommand(command); - button.addActionListener(this); + JButton button = ButtonUtil.createControlButton( + tooltip, command, icon, this, true); button.putClientProperty("entry", clientProperty); return button; } @@ -387,6 +390,12 @@ public class PlaylistPanel extends JPanel } } + // make the playlist fit the width of the scrolling viewport + public boolean getScrollableTracksViewportWidth () + { + return true; + } + protected JComponent _target; } @@ -398,4 +407,28 @@ public class PlaylistPanel extends JPanel protected int _oldid = -1; protected Font _nameFont; + + protected ImageIcon _skiptoIcon; + protected ImageIcon _removeSongIcon; + protected ImageIcon _removeEntryIcon; + + // icon paths + protected static final String ICON_ROOT = "/robodj/chooser/images/"; + protected static final String REFRESH_ICON_PATH = ICON_ROOT + "refresh.png"; + protected static final String CLEAR_ICON_PATH = ICON_ROOT + "clear.png"; + protected static final String SKIPTO_ICON_PATH = ICON_ROOT + "skip.png"; + protected static final String REMOVE_ENTRY_ICON_PATH = + ICON_ROOT + "remove_entry.png"; + protected static final String REMOVE_SONG_ICON_PATH = + ICON_ROOT + "remove_song.png"; + + // button tips + protected static final String REFRESH_TIP = "Refresh the playlist"; + protected static final String CLEAR_TIP = + "Clear all songs from the playlist"; + protected static final String SKIPTO_TIP = "Skip to this song"; + protected static final String REMOVE_ENTRY_TIP = + "Remove all songs in this entry from the playlist"; + protected static final String REMOVE_SONG_TIP = + "Remove this song from the playlist"; } diff --git a/projects/robodj/src/java/robodj/chooser/SearchPanel.java b/projects/robodj/src/java/robodj/chooser/SearchPanel.java index 030bb19b..dde5f9fd 100644 --- a/projects/robodj/src/java/robodj/chooser/SearchPanel.java +++ b/projects/robodj/src/java/robodj/chooser/SearchPanel.java @@ -1,5 +1,5 @@ // -// $Id: SearchPanel.java,v 1.2 2002/02/22 07:55:49 mdb Exp $ +// $Id: SearchPanel.java,v 1.3 2002/03/03 20:56:12 mdb Exp $ package robodj.chooser; @@ -63,6 +63,11 @@ public class SearchPanel extends JPanel // create and add a query entry list for the query _qlist = new QueryEntryList(_query); add(_qlist); + + // we need to revalidate ourselves and repaint because we've + // added a component + revalidate(); + repaint(); } } diff --git a/projects/robodj/src/java/robodj/chooser/images/back.png b/projects/robodj/src/java/robodj/chooser/images/back.png new file mode 100644 index 00000000..5f563a51 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/back.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/browse.png b/projects/robodj/src/java/robodj/chooser/images/browse.png new file mode 100644 index 00000000..622b95a4 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/browse.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/clear.png b/projects/robodj/src/java/robodj/chooser/images/clear.png new file mode 100644 index 00000000..f36a1664 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/clear.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/edit.png b/projects/robodj/src/java/robodj/chooser/images/edit.png new file mode 100644 index 00000000..b72489fe Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/edit.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/exit.png b/projects/robodj/src/java/robodj/chooser/images/exit.png new file mode 100644 index 00000000..56f9de3a Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/exit.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/pause.png b/projects/robodj/src/java/robodj/chooser/images/pause.png new file mode 100644 index 00000000..4b132c04 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/pause.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/play.png b/projects/robodj/src/java/robodj/chooser/images/play.png new file mode 100644 index 00000000..7ebcb184 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/play.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/refresh.png b/projects/robodj/src/java/robodj/chooser/images/refresh.png new file mode 100644 index 00000000..cc33100a Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/refresh.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/remove_entry.png b/projects/robodj/src/java/robodj/chooser/images/remove_entry.png new file mode 100644 index 00000000..3937c377 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/remove_entry.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/remove_song.png b/projects/robodj/src/java/robodj/chooser/images/remove_song.png new file mode 100644 index 00000000..c35b67a5 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/remove_song.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/skip.png b/projects/robodj/src/java/robodj/chooser/images/skip.png new file mode 100644 index 00000000..5e3d7959 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/skip.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/stop.png b/projects/robodj/src/java/robodj/chooser/images/stop.png new file mode 100644 index 00000000..6234e569 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/stop.png differ diff --git a/projects/robodj/src/java/robodj/chooser/images/up.png b/projects/robodj/src/java/robodj/chooser/images/up.png new file mode 100644 index 00000000..03033bd4 Binary files /dev/null and b/projects/robodj/src/java/robodj/chooser/images/up.png differ diff --git a/projects/robodj/src/java/robodj/util/ButtonUtil.java b/projects/robodj/src/java/robodj/util/ButtonUtil.java new file mode 100644 index 00000000..563c2a4f --- /dev/null +++ b/projects/robodj/src/java/robodj/util/ButtonUtil.java @@ -0,0 +1,78 @@ +// +// $Id: ButtonUtil.java,v 1.1 2002/03/03 20:56:12 mdb Exp $ + +package robodj.util; + +import java.awt.Image; +import java.awt.event.ActionListener; + +import java.io.IOException; +import java.io.InputStream; + +import javax.imageio.ImageIO; + +import javax.swing.BorderFactory; +import javax.swing.ImageIcon; +import javax.swing.JButton; + +import robodj.Log; + +/** + * Routines for creating buttons with icon images. + */ +public class ButtonUtil +{ + public static ImageIcon getIcon (String iconPath) + { + try { + InputStream imgin = ButtonUtil.class.getResourceAsStream(iconPath); + if (imgin != null) { + Image image = ImageIO.read(imgin); + return new ImageIcon(image); + } + + } catch (IOException ioe) { + Log.warning("Unable to load icon [path=" + iconPath + + ", error=" + ioe + "]."); + + } catch (Exception e) { + Log.warning("Error loading icon [path=" + iconPath + "]."); + Log.logStackTrace(e); + } + return null; + } + + public static JButton createControlButton ( + String tooltip, String action, String iconPath, ActionListener al) + { + return createControlButton(tooltip, action, iconPath, al, false); + } + + public static JButton createControlButton ( + String tooltip, String action, String iconPath, + ActionListener al, boolean borderless) + { + return createControlButton( + tooltip, action, getIcon(iconPath), al, borderless); + } + + public static JButton createControlButton ( + String tooltip, String action, ImageIcon icon, ActionListener al) + { + return createControlButton(tooltip, action, icon, al, false); + } + + public static JButton createControlButton ( + String tooltip, String action, ImageIcon icon, + ActionListener al, boolean borderless) + { + JButton cbut = new JButton(icon); + cbut.setActionCommand(action); + cbut.addActionListener(al); + cbut.setToolTipText(tooltip); + // clear out that annoying fat border that swing uses + cbut.setBorder(borderless ? BorderFactory.createEmptyBorder() : + BorderFactory.createEtchedBorder()); + return cbut; + } +}