001: /*
002: * Copyright (c) 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of JGoodies Karsten Lentzsch nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030:
031: package com.jgoodies.binding.tutorial.manager;
032:
033: import javax.swing.JButton;
034: import javax.swing.JComponent;
035: import javax.swing.JScrollPane;
036: import javax.swing.JTable;
037:
038: import com.jgoodies.binding.adapter.SingleListSelectionAdapter;
039: import com.jgoodies.binding.tutorial.TutorialUtils;
040: import com.jgoodies.forms.builder.PanelBuilder;
041: import com.jgoodies.forms.factories.ButtonBarFactory;
042: import com.jgoodies.forms.layout.CellConstraints;
043: import com.jgoodies.forms.layout.FormLayout;
044:
045: /**
046: * Builds a user interface for managing Albums using a table to display
047: * the Albums and buttons to add, edit, and delete the selected album.
048: * The models and Actions are provided by an underlying AlbumManagerModel.
049: *
050: * @author Karsten Lentzsch
051: * @version $Revision: 1.5 $
052: *
053: * @see AlbumManagerModel
054: * @see com.jgoodies.binding.PresentationModel
055: */
056:
057: public final class AlbumManagerView {
058:
059: /**
060: * Provides a list of Albums with selection and Action
061: * for operating on the managed Albums.
062: */
063: private final AlbumManagerModel albumManagerModel;
064:
065: private JTable albumTable;
066: private JButton newButton;
067: private JButton editButton;
068: private JButton deleteButton;
069:
070: // Instance Creation ******************************************************
071:
072: /**
073: * Constructs a list editor for editing the given list of albums.
074: *
075: * @param albumManagerModel the list of albums to edit
076: */
077: public AlbumManagerView(AlbumManagerModel albumManagerModel) {
078: this .albumManagerModel = albumManagerModel;
079: }
080:
081: // Component Creation and Initialization **********************************
082:
083: /**
084: * Creates and initializes the UI components.
085: */
086: private void initComponents() {
087: albumTable = new JTable();
088: albumTable.setModel(TutorialUtils
089: .createAlbumTableModel(albumManagerModel
090: .getAlbumSelection()));
091: albumTable.setSelectionModel(new SingleListSelectionAdapter(
092: albumManagerModel.getAlbumSelection()
093: .getSelectionIndexHolder()));
094:
095: newButton = new JButton(albumManagerModel.getNewAction());
096: editButton = new JButton(albumManagerModel.getEditAction());
097: deleteButton = new JButton(albumManagerModel.getDeleteAction());
098: }
099:
100: private void initEventHandling() {
101: albumTable.addMouseListener(albumManagerModel
102: .getDoubleClickHandler());
103: }
104:
105: // Building ***************************************************************
106:
107: /**
108: * Builds and returns the panel for the Album Manager View.
109: *
110: * @return the built panel
111: */
112: public JComponent buildPanel() {
113: initComponents();
114: initEventHandling();
115:
116: FormLayout layout = new FormLayout("fill:250dlu:grow",
117: "p, 1dlu, fill:200dlu, 6dlu, p");
118:
119: PanelBuilder builder = new PanelBuilder(layout);
120: builder.setDefaultDialogBorder();
121: CellConstraints cc = new CellConstraints();
122:
123: builder.addTitle("Albums", cc.xy(1, 1));
124: builder.add(new JScrollPane(albumTable), cc.xy(1, 3));
125: builder.add(buildButtonBar(), cc.xy(1, 5));
126:
127: return builder.getPanel();
128: }
129:
130: private JComponent buildButtonBar() {
131: return ButtonBarFactory.buildLeftAlignedBar(newButton,
132: editButton, deleteButton);
133: }
134:
135: }
|