1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package org.openoffice.setup.PanelHelper;
25 
26 import java.awt.ComponentOrientation;
27 import java.awt.FlowLayout;
28 import javax.swing.Box;
29 import javax.swing.BoxLayout;
30 import javax.swing.JLabel;
31 import javax.swing.JPanel;
32 import javax.swing.JSeparator;
33 import org.openoffice.setup.InstallData;
34 
35 public class PanelTitle extends Box {
36 
37     private JLabel TitleLabel;
38 
PanelTitle()39     public PanelTitle() {
40          super(BoxLayout.PAGE_AXIS);
41     }
42 
PanelTitle(String title, String subtitle, int rows, int columns)43     public PanelTitle(String title, String subtitle, int rows, int columns) {
44         super(BoxLayout.PAGE_AXIS);
45         init(title, subtitle, rows, columns);
46     }
47 
PanelTitle(String title, String subtitle)48     public PanelTitle(String title, String subtitle) {
49         super(BoxLayout.PAGE_AXIS);
50         init(title, subtitle, 0, 0);
51     }
52 
PanelTitle(String title)53     public PanelTitle(String title) {
54         super (BoxLayout.PAGE_AXIS);
55         init(title, null, 0, 0);
56     }
57 
addVerticalStrut(int strut)58     public void addVerticalStrut(int strut) {
59         add(createVerticalStrut(strut));
60     }
61 
setTitle(String title)62     public void setTitle(String title) {
63         TitleLabel.setText(title);
64     }
65 
66     // public void setSubtitle(String subtitle) {
67     //     SubtitleLabel.setText(subtitle);
68     // }
69 
init(String title, String subtitle, int rows, int columns)70     private void init(String title, String subtitle, int rows, int columns) {
71 
72         InstallData data = InstallData.getInstance();
73 
74         TitleLabel = new JLabel(title);
75         TitleLabel.setFocusable(false);
76         JPanel TitlePanel = new JPanel();
77         if ( data.useRtl() ) {
78             TitlePanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
79             TitleLabel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
80         } else {
81             TitlePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
82         }
83         TitlePanel.add(TitleLabel);
84 
85         add(createVerticalStrut(10));
86         add(TitlePanel);
87         add(createVerticalStrut(10));
88         add(new JSeparator());
89         add(createVerticalStrut(20));
90 
91         if (subtitle != null) {
92             PanelLabel SubtitleLabel = null;
93             if ( rows > 0 ) {
94                 SubtitleLabel = new PanelLabel(subtitle, rows, columns );
95             } else {
96                 SubtitleLabel = new PanelLabel(subtitle);
97             }
98             SubtitleLabel.setFocusable(false);
99             // PanelLabel SubtitleLabel = new PanelLabel(subtitle, true);
100             JPanel SubtitlePanel = new JPanel();
101             if ( data.useRtl() ) {
102                 SubtitlePanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 0, 0));
103                 SubtitleLabel.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
104             } else {
105                 SubtitlePanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
106             }
107             SubtitlePanel.add(SubtitleLabel);
108 
109             add(SubtitlePanel);
110         }
111     }
112 }