2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.ui
;
21 public class CommandButtonGroup
extends JPanel
{
22 public static final int LEFT
= 1;
23 public static final int RIGHT
= 2;
24 private int myPreferredH
= 0;
25 private int myPreferredW
= 0;
28 public CommandButtonGroup() {
29 this(BoxLayout
.X_AXIS
);
33 * Creates new <code>CommandButtonGroup</code> panel with specified orientation.
34 * @param axis possible values of this parameter are defined in <code>BoxLayout</code>
35 * @see javax.swing.BoxLayout#X_AXIS
36 * @see javax.swing.BoxLayout#Y_AXIS
38 public CommandButtonGroup(int axis
) {
40 setLayout(new BoxLayout(this, axis
));
41 //setBorder(new EmptyBorder(5, 5, 5, 5));
42 if (axis
== BoxLayout
.X_AXIS
){
43 add(Box
.createHorizontalGlue());
46 //add(Box.createVerticalGlue());
50 public void addButton(AbstractButton button
) {
51 addButton(button
, RIGHT
);
54 public void addButton(AbstractButton button
, int position
) {
55 if (LEFT
== position
){
57 if (myAxis
== BoxLayout
.X_AXIS
){
58 add(Box
.createHorizontalStrut(5), 1);
61 add(Box
.createVerticalStrut(5), 1);
65 if (myAxis
== BoxLayout
.X_AXIS
){
66 add(Box
.createHorizontalStrut(5));
69 add(Box
.createVerticalStrut(5));
73 Dimension prefSize
= button
.getPreferredSize();
74 if (prefSize
.height
> myPreferredH
){
75 myPreferredH
= prefSize
.height
;
77 if (prefSize
.width
> myPreferredW
){
78 myPreferredW
= prefSize
.width
;
83 private void updateButtonSizes() {
84 Dimension dim
= new Dimension(myPreferredW
, myPreferredH
);
85 Component
[] components
= getComponents();
86 if (components
== null) return;
87 for(int i
= 0; i
< components
.length
; i
++){
88 if (components
[i
] instanceof AbstractButton
){
89 AbstractButton button
= (AbstractButton
)components
[i
];
90 button
.setPreferredSize(dim
);
91 button
.setMaximumSize(dim
);
92 button
.setMinimumSize(dim
);