View Javadoc

1   /***
2    * 
3    */
4   package org.telscenter.pas.steps;
5   
6   import info.clearthought.layout.TableLayout;
7   import info.clearthought.layout.TableLayoutConstants;
8   
9   import java.awt.BorderLayout;
10  import java.awt.Color;
11  import java.awt.FlowLayout;
12  import java.awt.Font;
13  import java.awt.event.ActionEvent;
14  import java.awt.event.ComponentEvent;
15  import java.awt.event.ComponentListener;
16  import java.awt.event.MouseEvent;
17  import java.awt.event.MouseListener;
18  import java.beans.XMLDecoder;
19  import java.beans.XMLEncoder;
20  import java.io.ByteArrayInputStream;
21  import java.io.ByteArrayOutputStream;
22  import java.io.InputStream;
23  import java.net.MalformedURLException;
24  import java.net.URL;
25  import java.util.HashMap;
26  import java.util.Iterator;
27  import java.util.Set;
28  
29  import javax.swing.AbstractAction;
30  import javax.swing.Action;
31  import javax.swing.BorderFactory;
32  import javax.swing.BoxLayout;
33  import javax.swing.ImageIcon;
34  import javax.swing.JButton;
35  import javax.swing.JComponent;
36  import javax.swing.JLabel;
37  import javax.swing.JPanel;
38  import javax.swing.JScrollPane;
39  import javax.swing.JTextArea;
40  import javax.swing.JTextField;
41  import javax.swing.JToolBar;
42  import javax.swing.ScrollPaneConstants;
43  import javax.swing.SwingConstants;
44  import javax.swing.UIManager;
45  import javax.swing.border.Border;
46  import javax.swing.border.CompoundBorder;
47  
48  import org.apache.commons.io.IOUtils;
49  import org.telscenter.pas.common.ui.CommonUI;
50  import org.telscenter.pas.common.ui.ISelectable;
51  import org.telscenter.pas.common.ui.button.GradientButton;
52  import org.telscenter.pas.common.ui.panel.CardPanel;
53  import org.telscenter.pas.common.ui.panel.SimpleGradientPanel;
54  import org.telscenter.pas.common.ui.text.CurrentLineHighlighter;
55  import org.telscenter.pas.steps.domain.BookmarkDAO;
56  import org.telscenter.pas.ui.icons.PasCommonIconProvider;
57  import org.telscenter.pas.ui.util.PasColors;
58  import org.xhtmlrenderer.simple.FSScrollPane;
59  import org.xhtmlrenderer.simple.XHTMLPanel;
60  
61  /***
62   * @author aperritano
63   * 
64   */
65  public class BookmarkUI extends BrowseWebUI {
66  
67  	protected ImageIcon toggleIconOff = new ImageIcon(PasCommonIconProvider
68  			.getImage("toggleViewOff.png"));
69  
70  	protected ImageIcon toggleIconOn = new ImageIcon(PasCommonIconProvider
71  			.getImage("toggleViewOn.png"));
72  
73  	protected ImageIcon instructTextActive = new ImageIcon(
74  			PasCommonIconProvider.getImage("instructTextActive.png"));
75  
76  	protected ImageIcon addBookmarkViewActive = new ImageIcon(
77  			PasCommonIconProvider.getImage("addBookmarkViewActive.png"));
78  
79  	protected ImageIcon showAllBookmarksViewActive = new ImageIcon(
80  			PasCommonIconProvider.getImage("showAllBookmarksViewActive.png"));
81  
82  	protected ImageIcon addBookmarkActive = new ImageIcon(PasCommonIconProvider
83  			.getImage("addBookmarkActive.png"));
84  
85  	protected ImageIcon addBookmarkRollover = new ImageIcon(
86  			PasCommonIconProvider.getImage("addBookmarkRollover.png"));
87  
88  	protected ImageIcon setUrlActive = new ImageIcon(PasCommonIconProvider
89  			.getImage("setUrlActive.png"));
90  
91  	protected ImageIcon setUrlRollover = new ImageIcon(PasCommonIconProvider
92  			.getImage("setUrlRollover.png"));
93  
94  	protected ImageIcon deleteActive = new ImageIcon(PasCommonIconProvider
95  			.getImage("deleteActive.png"));
96  
97  	protected ImageIcon deleteRollover = new ImageIcon(PasCommonIconProvider
98  			.getImage("setUrlRollover.png"));
99  
100 	protected JToolBar bookmarkManagementToolbar;
101 
102 	protected int dividerLocation = 200;
103 
104 	protected CardPanel topCardPanel;
105 
106 	protected static final String INSTRUCTIONAL_TEXT_PAGE = "INSTRUCTIONAL_TEXT_PAGE";
107 
108 	protected static final String ADD_BOOKMARK_PAGE = "ADD_BOOKMARK_PAGE";
109 
110 	protected static final String ALL_BOOKMARKS_PAGE = "ALL_BOOKMARKS_PAGE";
111 
112 	protected static final String WEB_PAGE = "WEB_PAGE";
113 
114 	private boolean compactView = false;
115 
116 	protected Font labelFont;
117 
118 	protected HashMap<BookmarkDAO, JPanel> bookmarksToPanels = new HashMap<BookmarkDAO, JPanel>();
119 
120 	protected HashMap<JButton, BookmarkDAO> bookmarksToButtons = new HashMap<JButton, BookmarkDAO>();
121 
122 	protected JTextField nameText;
123 
124 	protected JTextField urlText;
125 
126 	protected JTextArea remarksTextArea;
127 
128 	protected JPanel allBookmarkPanel;
129 
130 	protected Bookmark bookmark;
131 
132 	protected boolean hasNoEntries = true;
133 
134 	protected JPanel addBookmarkPanel;
135 
136 	protected JComponent instructionalPanel;
137 
138 	private GradientButton toggleViewButton;
139 
140 	private GradientButton addBookmarkButton;
141 
142 	private GradientButton instructionTextButton;
143 
144 	private GradientButton showAllBookmarksButton;
145 
146 	private CardPanel bottomCardPanel;
147 
148 	/***
149 	 * @param bookmark
150 	 */
151 	public BookmarkUI(Bookmark bookmark) {
152 
153 		super(bookmark);
154 		this.bookmark = bookmark;
155 		initBookmarkUI();
156 	}
157 
158 	protected void initBookmarkUI() {
159 
160 		// add bookmarks button to the left side
161 
162 		// create right side
163 
164 		bookmarkManagementToolbar = createBookmarkManagementToolbar();
165 
166 		JPanel comboPanel = new JPanel(new BorderLayout(0, 0));
167 		comboPanel.add(bookmarkManagementToolbar, BorderLayout.WEST);
168 		comboPanel.add(toggleViewButton, BorderLayout.EAST);
169 		comboPanel.setOpaque(false);
170 
171 		browserToolbarPanel.add(comboPanel, BorderLayout.EAST);
172 		browserToolbarPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0,
173 				0));
174 		splitPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
175 		// init the cardpanel
176 
177 		labelFont = UIManager.getFont("Label.font").deriveFont(Font.BOLD, 11f);
178 
179 		instructionalPanel = createInstructionTextPanel();
180 
181 		addBookmarkPanel = this.createAddBookmarkPanel(null);
182 
183 		// the card panel
184 		topCardPanel = new CardPanel();
185 		topCardPanel.add(instructionalPanel, INSTRUCTIONAL_TEXT_PAGE);
186 		topCardPanel.add(addBookmarkPanel, ADD_BOOKMARK_PAGE);
187 
188 		splitPane.setTopComponent(topCardPanel);
189 
190 		bottomCardPanel = new CardPanel();
191 		bottomCardPanel.add(splitPane.getBottomComponent(), WEB_PAGE);
192 
193 		allBookmarkPanel = new JPanel();
194 		allBookmarkPanel.setLayout(new BoxLayout(allBookmarkPanel,
195 				BoxLayout.Y_AXIS));
196 
197 		if (bookmark.getWorkSock().size() <= 0) {
198 			this.addToAllBookMarksPanel(null);
199 		} else {
200 
201 			for (Iterator<String> iter = bookmark.getWorkSock().iterator(); iter
202 					.hasNext();) {
203 				String bookmarkString = iter.next();
204 				hasNoEntries = false;
205 				this.addToAllBookMarksPanel(this.makeBookmarkDAO(bookmarkString));
206 			}// for
207 
208 		}// if
209 
210 		JScrollPane scroller = new JScrollPane(allBookmarkPanel);
211 		scroller
212 				.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
213 		scroller
214 				.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
215 		scroller.setBorder(BorderFactory.createEmptyBorder());
216 		scroller.getVerticalScrollBar().setValue(
217 				scroller.getVerticalScrollBar().getMaximum());
218 		scroller.setOpaque(false);
219 
220 		bottomCardPanel.add(scroller, ALL_BOOKMARKS_PAGE);
221 
222 		splitPane.setBottomComponent(bottomCardPanel);
223 
224 		splitPane.setDividerLocation(100);
225 
226 		compactView = false;
227 		// addBookmarkPanel = this.createAddBookmarkPanel(null);
228 	}
229 
230 	/***
231 	 * @param bookmarkString
232 	 */
233 	protected BookmarkDAO makeBookmarkDAO(String bookmarkString) {
234 		ByteArrayInputStream ba = new ByteArrayInputStream(bookmarkString
235 				.getBytes());
236 		XMLDecoder decoder = new XMLDecoder(ba);
237 		BookmarkDAO dao = (BookmarkDAO) decoder.readObject();
238 		return dao;
239 	}
240 
241 	protected JPanel createAddBookmarkPanel(BookmarkDAO dao) {
242 
243 		final JPanel formPanel = new JPanel();
244 		// formPanel.setDirection(PasGroupButtonPanel.VERTICAL);
245 		// formPanel.setStartColor(PasColors.bookmarkBackgroundColor);
246 		// formPanel.setEndColor(PasColors.bookmarkBackgroundColor);
247 		// formPanel.setSelected(false);
248 
249 		// formPanel.setBackground(PasColors.bookmarkBackgroundColor);
250 
251 		final double pref = TableLayoutConstants.PREFERRED;
252 		final double fill = TableLayoutConstants.FILL;
253 		final double vSpace = 5;
254 		final double hSpace = 6;
255 		final double size[][] = { { pref, hSpace, fill, hSpace, pref // rt
256 				},
257 
258 				{ pref, vSpace, pref, vSpace, pref, vSpace }
259 
260 		};
261 		formPanel.setLayout(new TableLayout(size));
262 		formPanel.setOpaque(false);
263 		// formPanel.setBorder(CommonUI.create4PEmptyBorder());
264 		int length = 42;
265 		createBookmarkNamePanel(formPanel, dao, length);
266 		createBookmarkURLPanel(formPanel, dao, length);
267 		createBookmarkRemarksPanel(formPanel, dao, length);
268 		if (dao != null)
269 			createDeleteButton(formPanel, dao);
270 
271 		JPanel mPanel = new JPanel(new BorderLayout(0, 0));
272 		// formPanel.setStartColor(PasColors.bookmarkBackgroundColor);
273 		// formPanel.setEndColor(PasColors.bookmarkBackgroundColor);
274 		mPanel.add(formPanel, BorderLayout.CENTER);
275 
276 		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 1, 0));
277 		// add bookmark
278 		JButton addBookmarkButton = new JButton();
279 		addBookmarkButton.setAction(addBookmarkAction);
280 		addBookmarkButton.setIcon(addBookmarkActive);
281 		addBookmarkButton.setRolloverIcon(addBookmarkRollover);
282 
283 		addBookmarkButton.setText("Add Bookmark");
284 		CommonUI.makeEnhancedButton(addBookmarkButton);
285 		addBookmarkButton.setFont(labelFont);
286 
287 		JButton setCurrentURLButton = new JButton();
288 		setCurrentURLButton.setAction(setUrlAction);
289 		setCurrentURLButton.setIcon(setUrlActive);
290 		setCurrentURLButton.setRolloverIcon(setUrlRollover);
291 
292 		setCurrentURLButton.setText("Set Current URL");
293 		CommonUI.makeEnhancedButton(setCurrentURLButton);
294 		setCurrentURLButton.setFont(labelFont);
295 
296 		buttonPanel.add(setCurrentURLButton);
297 		buttonPanel.add(addBookmarkButton);
298 		buttonPanel.setOpaque(false);
299 		buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 4, 2));
300 
301 		if (dao == null) {
302 			mPanel.add(buttonPanel, BorderLayout.SOUTH);
303 		}
304 		mPanel.setBackground(PasColors.bookmarkBackgroundColor);
305 		CompoundBorder cp = BorderFactory.createCompoundBorder(BorderFactory
306 				.createEmptyBorder(2, 2, 2, 2), BorderFactory.createLineBorder(
307 				PasColors.bookmarkBBackgroundColor, 1));
308 
309 		mPanel.setBorder(cp);
310 		// BookmarkPanelListener pb = new BookmarkPanelListener(mPanel);
311 		// mPanel.addMouseListener(pb);
312 		//		
313 		return mPanel;
314 	}
315 
316 	protected JComponent createInstructionTextPanel() {
317 
318 		final XHTMLPanel panel = new XHTMLPanel();
319 		panel.setFont(labelFont);
320 
321 		//panel.setAntiAliased(true);
322 		panel.setFontScalingFactor(3f);
323 		panel.setOpaque(false);
324 		panel.addComponentListener(new ComponentListener() {
325 
326 			public void componentHidden(ComponentEvent e) {
327 				// TODO Auto-generated method stub
328 
329 			}
330 
331 			public void componentMoved(ComponentEvent e) {
332 				// TODO Auto-generated method stub
333 
334 			}
335 
336 			public void componentResized(ComponentEvent e) {
337 				panel.relayout();
338 
339 			}
340 
341 			public void componentShown(ComponentEvent e) {
342 				// TODO Auto-generated method stub
343 
344 			}
345 		});
346 
347 		InputStream stream = IOUtils.toInputStream(bookmark
348 				.getInstructionalText());
349 		try {
350 			panel.setDocument(stream, null);
351 		} catch (Exception e) {
352 			e.printStackTrace();
353 		} finally {
354 			IOUtils.closeQuietly(stream);
355 		}
356 
357 		FSScrollPane scroll = new FSScrollPane(panel);
358 		scroll
359 				.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
360 		scroll
361 				.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
362 
363 		// panel.setBackground(PasColors.bookmarkBackgroundColor);
364 		// panel.setOpaque(false);
365 		CompoundBorder cp = BorderFactory.createCompoundBorder(BorderFactory
366 				.createEmptyBorder(2, 2, 2, 2), BorderFactory.createLineBorder(
367 				PasColors.bookmarkBBackgroundColor, 1));
368 
369 		JPanel mainPanel = new JPanel(new BorderLayout(0, 0));
370 		mainPanel.setBorder(cp);
371 		mainPanel.setBackground(PasColors.bookmarkBackgroundColor);
372 
373 		JPanel t = new JPanel(new BorderLayout(0, 0));
374 		t.setBackground(panel.getBackground());
375 		t.add(panel, BorderLayout.CENTER);
376 
377 		mainPanel.add(t, BorderLayout.CENTER);
378 
379 		return mainPanel;
380 	}
381 
382 	/***
383 	 * 
384 	 */
385 	protected void removeAllBookmarkPanelEntries() {
386 		allBookmarkPanel.removeAll();
387 	}
388 
389 	/***
390 	 * @param dao
391 	 */
392 	protected void addToAllBookMarksPanel(BookmarkDAO dao) {
393 		if (hasNoEntries) {
394 
395 			JPanel blankPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
396 
397 			blankPanel.setBackground(PasColors.bookmarkBackgroundColor);
398 			CompoundBorder cp = BorderFactory.createCompoundBorder(
399 					BorderFactory.createEmptyBorder(2, 2, 2, 2), BorderFactory
400 							.createLineBorder(
401 									PasColors.bookmarkBBackgroundColor, 1));
402 
403 			blankPanel.setBorder(cp);
404 
405 			JLabel label = new JLabel("There are no saved bookmarks");
406 			label.setOpaque(false);
407 			label.setForeground(Color.white);
408 
409 			label.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
410 			blankPanel.add(label);
411 
412 			allBookmarkPanel.add(blankPanel);
413 			return;
414 		}// if
415 		JPanel daoPanel = createAddBookmarkPanel(dao);
416 		bookmarksToPanels.put(dao, daoPanel);
417 		allBookmarkPanel.add(daoPanel);
418 
419 	}
420 
421 	protected void createDeleteButton(final JPanel formPanel, BookmarkDAO dao) {
422 		JButton deleteButton = new JButton();
423 
424 		deleteButton.setAction(deleteBookmarkAction);
425 		deleteButton.setIcon(deleteActive);
426 		deleteButton.setRolloverIcon(deleteRollover);
427 		deleteButton.setToolTipText("Delete Bookmark");
428 		CommonUI.makeButtonTransparent(deleteButton);
429 		deleteButton.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
430 
431 		bookmarksToButtons.put(deleteButton, dao);
432 		formPanel.add(deleteButton, "4,0");
433 	}
434 
435 	protected void createBookmarkNamePanel(final JPanel formPanel,
436 			BookmarkDAO dao, int i) {
437 
438 		final JLabel nameLabel = new JLabel("Name:");
439 		nameLabel.setFont(labelFont);
440 		nameLabel.setForeground(Color.white);
441 
442 		nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
443 		nameLabel.setOpaque(false);
444 		formPanel.add(nameLabel, "0,0");
445 		nameText = new JTextField();
446 		nameText.setFont(labelFont);
447 		nameText.requestFocus();
448 		nameText.setColumns(i);
449 		if (dao != null) {
450 
451 			nameText.setText(dao.getName());
452 			nameText.setEditable(false);
453 			// nameText.setBackground(PasColors.bookmarkBackgroundColor);
454 			nameText.setOpaque(false);
455 			nameText.setForeground(Color.white);
456 			nameText.setFont(labelFont);
457 			nameText.setBorder(BorderFactory.createEmptyBorder());
458 		}// if
459 		formPanel.add(nameText, "2,0");
460 		formPanel.setMaximumSize(formPanel.getPreferredSize());
461 	}
462 
463 	protected void createBookmarkURLPanel(final JPanel formPanel,
464 			BookmarkDAO dao, int i) {
465 
466 		final JLabel urlLabel = new JLabel("Location (URL):");
467 		urlLabel.setFont(labelFont);
468 		urlLabel.setForeground(Color.white);
469 		urlLabel.setHorizontalAlignment(SwingConstants.LEFT);
470 		urlLabel.setOpaque(false);
471 		formPanel.add(urlLabel, "0,2");
472 		urlText = new JTextField();
473 		urlText.requestFocus();
474 		urlText.setColumns(i);
475 		urlText.setFont(labelFont);
476 		if (dao != null) {
477 			urlText.setText(dao.getUrl().toString());
478 			urlText.setEditable(false);
479 			urlText.setForeground(Color.white);
480 			urlText.setOpaque(false);
481 			urlText.setFont(labelFont);
482 			urlText.setBorder(BorderFactory.createEmptyBorder());
483 		}// if
484 		formPanel.add(urlText, "2,2");
485 		formPanel.setMaximumSize(formPanel.getPreferredSize());
486 	}
487 
488 	protected void createBookmarkRemarksPanel(final JPanel formPanel,
489 			BookmarkDAO dao, int i) {
490 
491 		final JLabel remarksLabel = new JLabel("Remarks:");
492 		remarksLabel.setFont(labelFont);
493 		remarksLabel.setForeground(Color.white);
494 		remarksLabel.setHorizontalAlignment(SwingConstants.LEFT);
495 		remarksLabel.setVerticalTextPosition(SwingConstants.NORTH);
496 		remarksLabel.setOpaque(false);
497 		formPanel.add(remarksLabel, "0,4,l,t"); //$NON-NLS-1$
498 		remarksTextArea = new JTextArea();
499 		remarksTextArea.setFont(labelFont);
500 		remarksTextArea.setWrapStyleWord(true);
501 		remarksTextArea.setLineWrap(true);
502 		remarksTextArea.setEditable(true);
503 		remarksTextArea.setColumns(i);
504 		remarksTextArea.setOpaque(true);
505 		remarksTextArea.setRows(3);
506 
507 		final JScrollPane sp = new JScrollPane(remarksTextArea);
508 		sp
509 				.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
510 		sp
511 				.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
512 		// sp.setPreferredSize(new Dimension(150, 150));
513 		sp.setBorder(CommonUI.createEtchedBorder());
514 
515 		if (dao != null) {
516 			remarksTextArea.setText(dao.getRemarks());
517 			remarksTextArea.setRows(3);
518 			remarksTextArea.setEditable(false);
519 			// remarksTextArea.setOpaque(false);
520 			remarksTextArea.setForeground(Color.white);
521 			remarksTextArea.setBackground(PasColors.bookmarkBackgroundColor);
522 			remarksTextArea.setFont(labelFont);
523 			remarksTextArea.setBorder(BorderFactory.createEmptyBorder());
524 			sp.setBorder(BorderFactory.createEmptyBorder());
525 		} else {
526 			CurrentLineHighlighter.install(remarksTextArea);
527 		}
528 
529 		formPanel.add(sp, "2,4"); //$NON-NLS-1$
530 		formPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
531 	}
532 
533 	/***
534 	 * @return the compactView
535 	 */
536 	public boolean isCompactView() {
537 		return compactView;
538 	}
539 
540 	/***
541 	 * @param compactView
542 	 *            the compactView to set
543 	 */
544 	public void setCompactView(boolean compactView) {
545 		this.compactView = compactView;
546 	}
547 
548 	protected void populateBookmarkPanel() {
549 		nameText.setText(bookmark.getBrowser().getPageTitle());
550 		urlText.setText(bookmark.getBrowser().getUrl().toString());
551 	}
552 
553 	protected JToolBar createBookmarkManagementToolbar() {
554 
555 		bookmarkManagementToolbar = new JToolBar();
556 		bookmarkManagementToolbar.setFloatable(false);
557 		bookmarkManagementToolbar.setRollover(true);
558 		bookmarkManagementToolbar.setBorder(BorderFactory.createEmptyBorder(2,
559 				2, 2, 2));
560 
561 		addBookmarkButton = new GradientButton(
562 				PasColors.bookmarkBackgroundColor,
563 				PasColors.bookmarkBackgroundColor);
564 
565 		Font sFont = addBookmarkButton.getFont().deriveFont(9f);
566 		addBookmarkButton.setAction(showBookmarkCreatePanelAciton);
567 		addBookmarkButton.setIcon(addBookmarkViewActive);
568 		addBookmarkButton.setText("Add Bookmark");
569 		addBookmarkButton.setFont(sFont);
570 		addBookmarkButton.setForeground(Color.white);
571 		addBookmarkButton.setToolTipText("Add Bookmark");
572 		CommonUI.makeButtonTransparent(addBookmarkButton);
573 		addBookmarkButton
574 				.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
575 
576 		instructionTextButton = new GradientButton(
577 				PasColors.bookmarkBackgroundColor,
578 				PasColors.bookmarkBackgroundColor);
579 		instructionTextButton.setAction(instructionAction);
580 		instructionTextButton.setIcon(instructTextActive);
581 		instructionTextButton.setText("Goals");
582 		instructionTextButton.setFont(sFont);
583 		instructionTextButton.setForeground(Color.white);
584 		instructionTextButton.setToolTipText("My Goals");
585 		CommonUI.makeButtonTransparent(instructionTextButton);
586 		instructionTextButton.setBorder(BorderFactory.createEmptyBorder(2, 2,
587 				2, 2));
588 
589 		showAllBookmarksButton = new GradientButton(
590 				PasColors.bookmarkBackgroundColor,
591 				PasColors.bookmarkBackgroundColor);
592 		showAllBookmarksButton.setAction(showAllBookmarksAction);
593 		showAllBookmarksButton.setIcon(showAllBookmarksViewActive);
594 		showAllBookmarksButton.setText("Show All Bookmarks");
595 		showAllBookmarksButton.setFont(sFont);
596 		showAllBookmarksButton.setForeground(Color.white);
597 		CommonUI.makeButtonTransparent(showAllBookmarksButton);
598 		showAllBookmarksButton.setBorder(BorderFactory.createEmptyBorder(2, 2,
599 				2, 2));
600 		showAllBookmarksButton.setToolTipText("Show All Bookmarks");
601 
602 		toggleViewButton = new GradientButton(
603 				PasColors.bookmarkBackgroundColor,
604 				PasColors.bookmarkBackgroundColor);
605 		toggleViewButton.setAction(toggleViewAction);
606 		toggleViewButton.setIcon(toggleIconOff);
607 		toggleViewButton.setText("Browse");
608 		toggleViewButton.setFont(sFont);
609 		toggleViewButton.setForeground(Color.white);
610 		CommonUI.makeButtonTransparent(toggleViewButton);
611 		toggleViewButton.setToolTipText("Browse Internet");
612 
613 		toggleViewButton.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
614 
615 		bookmarkManagementToolbar.add(instructionTextButton);
616 		bookmarkManagementToolbar.add(addBookmarkButton);
617 		bookmarkManagementToolbar.add(showAllBookmarksButton);
618 
619 		bookmarkManagementToolbar.add(toggleViewButton);
620 		bookmarkManagementToolbar.setOpaque(false);
621 
622 		return bookmarkManagementToolbar;
623 	}
624 
625 	protected Action addBookmarkAction = new AbstractAction(null) {
626 		public void actionPerformed(ActionEvent e) {
627 			BookmarkDAO dao = new BookmarkDAO();
628 
629 			if (nameText.getText() == null)
630 				dao.setName("untitled");
631 			else
632 				dao.setName(nameText.getText());
633 
634 			if (remarksTextArea.getText() == null)
635 				dao.setRemarks("No remarks given");
636 			else
637 				dao.setRemarks(remarksTextArea.getText());
638 
639 			try {
640 
641 				if (urlText.getText() == null)
642 					dao.setUrl(new URL("http://www.yahoo.com").toString());
643 				else
644 					dao.setUrl(urlText.getText());
645 
646 			} catch (MalformedURLException e1) {
647 				e1.printStackTrace();
648 			}
649 
650 			if (hasNoEntries) {
651 				removeAllBookmarkPanelEntries();
652 				hasNoEntries = false;
653 			}
654 
655 			addToAllBookMarksPanel(dao);
656 			saveToRim(dao);
657 		}
658 	};
659 
660 	protected Action setUrlAction = new AbstractAction(null) {
661 		public void actionPerformed(ActionEvent e) {
662 			populateBookmarkPanel();
663 		}
664 	};
665 
666 	protected Action showBookmarkCreatePanelAciton = new AbstractAction(null) {
667 		public void actionPerformed(ActionEvent e) {
668 			showCard(ADD_BOOKMARK_PAGE);
669 			populateBookmarkPanel();
670 			bottomCardPanel.showCard(WEB_PAGE);
671 			addBookmarkButton.setColor1(Color.white);
672 
673 			// reset the other buttons
674 			toggleViewButton.setColor1(PasColors.bookmarkBackgroundColor);
675 			instructionTextButton.setColor1(PasColors.bookmarkBackgroundColor);
676 			showAllBookmarksButton.setColor1(PasColors.bookmarkBackgroundColor);
677 		}
678 	};
679 
680 	protected Action toggleViewAction = new AbstractAction(null) {
681 		public void actionPerformed(ActionEvent e) {
682 			if (!isCompactView())
683 				splitPane.setDividerLocation(0);
684 			bottomCardPanel.showCard(WEB_PAGE);
685 
686 			toggleViewButton.setColor1(Color.white);
687 
688 			// reset the other buttons
689 			addBookmarkButton.setColor1(PasColors.bookmarkBackgroundColor);
690 			instructionTextButton.setColor1(PasColors.bookmarkBackgroundColor);
691 			showAllBookmarksButton.setColor1(PasColors.bookmarkBackgroundColor);
692 
693 		}
694 	};
695 
696 	protected Action instructionAction = new AbstractAction(null) {
697 		public void actionPerformed(ActionEvent e) {
698 			showCard(INSTRUCTIONAL_TEXT_PAGE);
699 			bottomCardPanel.showCard(WEB_PAGE);
700 
701 			instructionTextButton.setColor1(Color.white);
702 
703 			// reset the other buttons
704 			toggleViewButton.setColor1(PasColors.bookmarkBackgroundColor);
705 			addBookmarkButton.setColor1(PasColors.bookmarkBackgroundColor);
706 			showAllBookmarksButton.setColor1(PasColors.bookmarkBackgroundColor);
707 
708 		}
709 	};
710 
711 	protected Action showAllBookmarksAction = new AbstractAction(null) {
712 		public void actionPerformed(ActionEvent e) {
713 			showCard(ADD_BOOKMARK_PAGE);
714 			splitPane.setDividerLocation(0);
715 			bottomCardPanel.showCard(ALL_BOOKMARKS_PAGE);
716 
717 			showAllBookmarksButton.setColor1(Color.white);
718 
719 			// reset the other buttons
720 			toggleViewButton.setColor1(PasColors.bookmarkBackgroundColor);
721 			instructionTextButton.setColor1(PasColors.bookmarkBackgroundColor);
722 			addBookmarkButton.setColor1(PasColors.bookmarkBackgroundColor);
723 		}
724 	};
725 
726 	protected Action deleteBookmarkAction = new AbstractAction(null) {
727 		public void actionPerformed(ActionEvent e) {
728 			JButton button = (JButton) e.getSource();
729 
730 			BookmarkDAO dao = bookmarksToButtons.get(button);
731 
732 			JPanel panel = bookmarksToPanels.get(dao);
733 
734 			allBookmarkPanel.remove(panel);
735 			allBookmarkPanel.revalidate();
736 		}
737 	};
738 
739 	protected Border selectedLineBorder = BorderFactory.createCompoundBorder(
740 			BorderFactory.createEmptyBorder(2, 2, 2, 2), BorderFactory
741 					.createLineBorder(Color.red, 1));
742 
743 	protected Border nonSelectedLineBorder = BorderFactory
744 			.createCompoundBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2),
745 					BorderFactory.createLineBorder(Color.green, 1));
746 
747 	protected void showCard(String pageName) {
748 		JComponent card = (JComponent) topCardPanel.getCard(pageName);
749 		splitPane.setDividerLocation(card.getPreferredSize().height);
750 		topCardPanel.showCard(pageName);
751 	}
752 
753 	/***
754 	 * @param dao
755 	 */
756 	protected void saveToRim(BookmarkDAO dao) {
757 		System.out.println("BookmarkUI.saveToRim()");
758 		bookmark.getWorkSock().add(createSockString(dao));
759 
760 		//System.out.println("sock: " + bookmark.getWorkSock().toString());
761 
762 	}
763 
764 	/***
765 	 * @param dao
766 	 * @return
767 	 */
768 	protected String createSockString(BookmarkDAO dao) {
769 
770 		ByteArrayOutputStream streamOut = new ByteArrayOutputStream();
771 		XMLEncoder xmlCreater = new XMLEncoder(streamOut);
772 		xmlCreater.writeObject(dao);
773 		xmlCreater.close();
774 		return streamOut.toString();
775 
776 		//		
777 		// StringBuffer buff = new StringBuffer();
778 		// buff.append("[[").append(dao.getName()).append("]][[").append(dao.getUrl().toString()).append("]][[").append(dao.getRemarks()).append("]]");
779 		// return buff.toString();
780 	}
781 
782 	protected void makePanelSelected(JPanel panel) {
783 		// panel.setSelected(true);
784 		// panel.setStartColor(PasColors.bookmarkSelectionStartColor);
785 		// panel.setEndColor(PasColors.bookmarkSelectionEndColor);
786 		panel.setBorder(selectedLineBorder);
787 	}
788 
789 	protected void makePanelNonSelected(JPanel panel) {
790 		// panel.setSelected(false);
791 		// panel.setStartColor(PasColors.bookmarkNonSelectionColor);
792 		// panel.setEndColor(PasColors.bookmarkNonSelectionColor);
793 		panel.setBorder(nonSelectedLineBorder);
794 	}
795 
796 	protected void makePanelRollover(JPanel panel) {
797 		// panel.setStartColor(PasColors.bookmarkRolloverStartColor);
798 		// panel.setEndColor(PasColors.bookmarkRolloverEndColor);
799 		panel.setBorder(selectedLineBorder);
800 	}
801 
802 	protected void makePanelNonRollover(JPanel panel) {
803 		// panel.setStartColor(PasColors.bookmarkNonSelectionColor);
804 		// panel.setEndColor(PasColors.bookmarkNonSelectionColor);
805 		panel.setBorder(nonSelectedLineBorder);
806 	}
807 
808 	protected class BookmarkPanelListener implements MouseListener {
809 
810 		protected JPanel panel;
811 
812 		/***
813 		 * @param backgroundGradientPanel
814 		 */
815 		public BookmarkPanelListener(JPanel panel) {
816 			this.panel = panel;
817 		}
818 
819 		public void mouseClicked(MouseEvent e) {
820 
821 			// adjustPanelSelection(panel);
822 
823 		}
824 
825 		public void mouseEntered(MouseEvent e) {
826 			System.out.println("BookmarkPanelListener.mouseEntered()");
827 			makePanelRollover(panel);
828 		}
829 
830 		public void mouseExited(MouseEvent e) {
831 			System.out.println("BookmarkPanelListener.mouseExited()");
832 			makePanelNonRollover(panel);
833 		}
834 
835 		public void mousePressed(MouseEvent e) {
836 		}
837 
838 		public void mouseReleased(MouseEvent e) {
839 		}
840 	}
841 
842 	protected void adjustPanelSelection(BookmarkPanel panel) {
843 
844 		Set<BookmarkDAO> set = bookmarksToPanels.keySet();
845 
846 		for (Iterator<BookmarkDAO> iterator = set.iterator(); iterator.hasNext();) {
847 			BookmarkDAO doa = iterator.next();
848 
849 			BookmarkPanel sp = (BookmarkPanel) bookmarksToPanels.get(doa);
850 
851 			if (panel.equals(sp)) {
852 				makePanelSelected(panel);
853 			} else {
854 				makePanelNonSelected(sp);
855 			}// if
856 		}// for
857 
858 	}
859 
860 	public class BookmarkPanel extends SimpleGradientPanel implements
861 			ISelectable {
862 
863 		private boolean selected;
864 
865 		/***
866 		 * 
867 		 */
868 		public BookmarkPanel() {
869 			init();
870 		}
871 
872 		/***
873 		 * @param layout
874 		 */
875 		public BookmarkPanel(BorderLayout layout) {
876 			super(layout);
877 		}
878 
879 		public void init() {
880 			this.setLayout(new BorderLayout(0, 0));
881 		}
882 
883 		public boolean isSelected() {
884 			return selected;
885 		}
886 
887 		public void setSelected(boolean selected) {
888 			this.selected = selected;
889 		}
890 
891 	}
892 
893 }