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  /**
27   * The custom header for the Disc 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   * AZ Development 2010
34   */
35  public final class DiscAddHeaderPanel
36      extends GradientBackgroundPanel {
37  
38      public static final int DEFAULT_HEIGHT = 70;
39      private DiscAddDialog owner;
40      private final int height;
41      private JLabel iconLabel;
42      private JLabel titleLabel;
43      private JTextArea descriptionArea;
44  
45      /**
46       * Constructs a <code>HeaderPanel</code> for the given title,
47       * description, and icon.
48       */
49      public DiscAddHeaderPanel(DiscAddDialog owner, String title, String description, Icon icon) {
50          this(owner, title, description, icon, DEFAULT_HEIGHT);
51      }
52  
53      /**
54       * Constructs a <code>HeaderPanel</code> for the given title,
55       * description, icon, and panel height.
56       */
57      public DiscAddHeaderPanel(DiscAddDialog owner, String title, String description, Icon icon, int height) {
58          super(true);
59          this.owner = owner;
60          this.height = height;
61          initComponents();
62          build();
63          setTitle(title);
64          setDescription(description);
65          setIcon(icon);
66      }
67  
68  
69      /**
70       * Returns the description text.
71       */
72      public String getDescription() {
73          return descriptionArea.getText();
74      }
75  
76      /**
77       * Returns the icon.
78       */
79      public Icon getIcon() {
80          return iconLabel.getIcon();
81      }
82  
83      /**
84       * Returns the title text.
85       */
86      public String getTitle() {
87          return titleLabel.getText();
88      }
89  
90      /**
91       * Sets the description text.
92       */
93      public void setDescription(String description) {
94          descriptionArea.setText(description);
95      }
96  
97      /**
98       * Sets the icon.
99       */
100     public void setIcon(Icon icon) {
101         if (null == icon) {
102             iconLabel.setIcon(null);
103             return;
104         }
105         if ((icon.getIconWidth() > 20) || !(icon instanceof ImageIcon)) {
106             iconLabel.setIcon(icon);
107             return;
108         }
109         Image image = ((ImageIcon)icon).getImage();
110         int newWidth = 2 * icon.getIconWidth();
111         int newHeight = 2 * icon.getIconHeight();
112         image = image.getScaledInstance(newWidth, newHeight, 0);
113         iconLabel.setIcon(new ImageIcon(image));
114     }
115 
116 
117     /**
118      * Sets the title text.
119      */
120     public void setTitle(String title) {
121         titleLabel.setText(title);
122     }
123 
124     /**
125      * Builds and answers the panel's bottom component, a separator by default.
126      */
127     protected JComponent buildBottomComponent() {
128         final ToolBarBuilder toolBar = new ToolBarBuilder("DiscToolBar");
129         toolBar.addGap(2);
130         ToolBarButton button = null;
131         ActionManager.get(Actions.FREE_DB_ID).setEnabled(true);
132         ActionManager.get(Actions.DISC_WEB_ID).setEnabled(true);
133         ActionManager.get(Actions.DISC_COVER_ID).setEnabled(true);
134         ActionManager.get(Actions.FILE_RENAME_ID).setEnabled(true);
135         //AZ: Add FreeDB Search
136         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.FREE_DB_ID);
137         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
138         toolBar.add(button);
139         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_WEB_ID);
140         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
141         toolBar.add(button);
142         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_COVER_ID);
143         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
144         toolBar.add(button);
145         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.FILE_RENAME_ID);
146         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
147         toolBar.add(button);
148         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_TITLECASE_ID);
149         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
150         toolBar.add(button);
151         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_RESET_FROM_FILENAME_ID);
152         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
153         toolBar.add(button);
154         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_RESET_NUMBERS_ID);
155         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
156         toolBar.add(button);
157         button = (ToolBarButton)ComponentFactory.createToolBarButton(Actions.DISC_ADD_COMMENTS_ID);
158         button.putClientProperty(Resources.EDITOR_COMPONENT, this.owner);
159         toolBar.add(button);
160         
161         final JToolBar bar = toolBar.getToolBar();
162         bar.setOpaque(false);
163         return bar;
164     }
165 
166     /**
167      * Builds and answers the panel's center component.
168      */
169     protected JComponent buildCenterComponent() {
170         FormLayout fl = new FormLayout("7dlu, 9dlu, left:pref, 14dlu:grow, pref, 4dlu",
171                                        "7dlu, pref, 2dlu, pref, 0:grow");
172         JPanel panel = new JPanel(fl);
173         Dimension size = new Dimension(300, height);
174         panel.setMinimumSize(size);
175         panel.setPreferredSize(size);
176         panel.setOpaque(false);
177 
178         CellConstraints cc = new CellConstraints();
179         panel.add(titleLabel, cc.xywh(2, 2, 2, 1));
180         panel.add(descriptionArea, cc.xy(3, 4));
181         panel.add(iconLabel, cc.xywh(5, 1, 1, 5));
182 
183         return panel;
184     }
185 
186     /**
187      * Builds the panel.
188      */
189     private void build() {
190         FormLayout fl = new FormLayout("pref:grow", "pref, pref");
191         setLayout(fl);
192         CellConstraints cc = new CellConstraints();
193         add(buildCenterComponent(), cc.xy(1, 1));
194         add(buildBottomComponent(), cc.xy(1, 2));
195     }
196 
197     /**
198      * Creates and configures the UI components.
199      */
200     private void initComponents() {
201         titleLabel = UIFactory.createBoldLabel("", 0, Color.black);
202         descriptionArea = UIFactory.createMultilineLabel("");
203         descriptionArea.setForeground(Color.black);
204         iconLabel = new JLabel();
205     }
206 
207 }