View Javadoc

1   package com.melloware.jukes.gui.view.dialogs;
2   
3   import java.awt.Color;
4   import java.awt.Dimension;
5   import java.awt.Image;
6   
7   import javax.swing.Icon;
8   import javax.swing.ImageIcon;
9   import javax.swing.JComponent;
10  import javax.swing.JLabel;
11  import javax.swing.JPanel;
12  import javax.swing.JTextArea;
13  import javax.swing.JToolBar;
14  
15  import com.jgoodies.forms.layout.CellConstraints;
16  import com.jgoodies.forms.layout.FormLayout;
17  import com.jgoodies.uif.action.ActionManager;
18  import com.jgoodies.uif.builder.ToolBarBuilder;
19  import com.jgoodies.uif.component.ToolBarButton;
20  import com.jgoodies.uifextras.panel.GradientBackgroundPanel;
21  import com.jgoodies.uifextras.util.UIFactory;
22  import com.melloware.jukes.gui.tool.Actions;
23  import com.melloware.jukes.gui.tool.Resources;
24  import com.melloware.jukes.gui.view.component.ComponentFactory;
25  
26  /**AZ 2009
27   * The custom header for the Track add dialog with toolbar.
28   * <p>
29   * Copyright (c) 1999-2007 Melloware, Inc. <http://www.melloware.com>
30   * @author Emil A. Lefkof III <info@melloware.com>
31   * @version 4.0
32   */
33  public final class TrackAddHeaderPanel
34      extends GradientBackgroundPanel {
35  
36      public static final int DEFAULT_HEIGHT = 70;
37      private TrackAddDialog owner;
38      private final int height;
39      private JLabel iconLabel;
40      private JLabel titleLabel;
41      private JTextArea descriptionArea;
42  
43      /**
44       * Constructs a <code>HeaderPanel</code> for the given title,
45       * description, and icon.
46       */
47      public TrackAddHeaderPanel(TrackAddDialog owner, String title, String description, Icon icon) {
48          this(owner, title, description, icon, DEFAULT_HEIGHT);
49      }
50  
51      /**
52       * Constructs a <code>HeaderPanel</code> for the given title,
53       * description, icon, and panel height.
54       */
55      public TrackAddHeaderPanel(TrackAddDialog owner, String title, String description, Icon icon, int height) {
56          super(true);
57          this.owner = owner;
58          this.height = height;
59          initComponents();
60          build();
61          setTitle(title);
62          setDescription(description);
63          setIcon(icon);
64      }
65  
66  
67      /**
68       * Returns the description text.
69       */
70      public String getDescription() {
71          return descriptionArea.getText();
72      }
73  
74      /**
75       * Returns the icon.
76       */
77      public Icon getIcon() {
78          return iconLabel.getIcon();
79      }
80  
81      /**
82       * Returns the title text.
83       */
84      public String getTitle() {
85          return titleLabel.getText();
86      }
87  
88      /**
89       * Sets the description text.
90       */
91      public void setDescription(String description) {
92          descriptionArea.setText(description);
93      }
94  
95      /**
96       * Sets the icon.
97       */
98      public void setIcon(Icon icon) {
99          if (null == icon) {
100             iconLabel.setIcon(null);
101             return;
102         }
103         if ((icon.getIconWidth() > 20) || !(icon instanceof ImageIcon)) {
104             iconLabel.setIcon(icon);
105             return;
106         }
107         Image image = ((ImageIcon)icon).getImage();
108         int newWidth = 2 * icon.getIconWidth();
109         int newHeight = 2 * icon.getIconHeight();
110         image = image.getScaledInstance(newWidth, newHeight, 0);
111         iconLabel.setIcon(new ImageIcon(image));
112     }
113 
114 
115     /**
116      * Sets the title text.
117      */
118     public void setTitle(String title) {
119         titleLabel.setText(title);
120     }
121 
122     /**
123      * Builds and answers the panel's bottom component, a separator by default.
124      */
125     protected JComponent buildBottomComponent() {
126         final ToolBarBuilder toolBar = new ToolBarBuilder("DiscToolBar");
127         toolBar.addGap(2);
128         ToolBarButton button = null;
129         ActionManager.get(Actions.DISC_WEB_ID).setEnabled(true);
130         ActionManager.get(Actions.DISC_COVER_ID).setEnabled(true);
131         ActionManager.get(Actions.FILE_RENAME_ID).setEnabled(true);
132         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_WEB_ID);
133         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
134         toolBar.add(button);
135         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_COVER_ID);
136         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
137         toolBar.add(button);
138         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.FILE_RENAME_ID);
139         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
140         toolBar.add(button);
141         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_TITLECASE_ID);
142         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
143         toolBar.add(button);
144         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_RESET_FROM_FILENAME_ID);
145         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
146         toolBar.add(button);
147         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_RESET_NUMBERS_ID);
148         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
149         toolBar.add(button);
150         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_COMMENTS_ID);
151         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
152         toolBar.add(button);
153         
154         final JToolBar bar = toolBar.getToolBar();
155         bar.setOpaque(false);
156         return bar;
157     }
158 
159     /**
160      * Builds and answers the panel's center component.
161      */
162     protected JComponent buildCenterComponent() {
163         FormLayout fl = new FormLayout("7dlu, 9dlu, left:pref, 14dlu:grow, pref, 4dlu",
164                                        "7dlu, pref, 2dlu, pref, 0:grow");
165         JPanel panel = new JPanel(fl);
166         Dimension size = new Dimension(300, height);
167         panel.setMinimumSize(size);
168         panel.setPreferredSize(size);
169         panel.setOpaque(false);
170 
171         CellConstraints cc = new CellConstraints();
172         panel.add(titleLabel, cc.xywh(2, 2, 2, 1));
173         panel.add(descriptionArea, cc.xy(3, 4));
174         panel.add(iconLabel, cc.xywh(5, 1, 1, 5));
175 
176         return panel;
177     }
178 
179     /**
180      * Builds the panel.
181      */
182     private void build() {
183         FormLayout fl = new FormLayout("pref:grow", "pref, pref");
184         setLayout(fl);
185         CellConstraints cc = new CellConstraints();
186         add(buildCenterComponent(), cc.xy(1, 1));
187         add(buildBottomComponent(), cc.xy(1, 2));
188     }
189 
190     /**
191      * Creates and configures the UI components.
192      */
193     private void initComponents() {
194         titleLabel = UIFactory.createBoldLabel("", 0, Color.black);
195         descriptionArea = UIFactory.createMultilineLabel("");
196         descriptionArea.setForeground(Color.black);
197         iconLabel = new JLabel();
198     }
199 
200 }