cleanup
[fedora-idea.git] / platform / platform-api / src / com / intellij / ui / CommandButtonGroup.java
blobfc7e0c30b0643692f631ce4d806ffea606138cdd
1 /*
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;
18 import javax.swing.*;
19 import java.awt.*;
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;
26 private int myAxis;
28 public CommandButtonGroup() {
29 this(BoxLayout.X_AXIS);
32 /**
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) {
39 myAxis = 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());
45 else{
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){
56 add(button, 0);
57 if (myAxis == BoxLayout.X_AXIS){
58 add(Box.createHorizontalStrut(5), 1);
60 else{
61 add(Box.createVerticalStrut(5), 1);
64 else{
65 if (myAxis == BoxLayout.X_AXIS){
66 add(Box.createHorizontalStrut(5));
68 else{
69 add(Box.createVerticalStrut(5));
71 add(button);
73 Dimension prefSize = button.getPreferredSize();
74 if (prefSize.height > myPreferredH){
75 myPreferredH = prefSize.height;
77 if (prefSize.width > myPreferredW){
78 myPreferredW = prefSize.width;
80 updateButtonSizes();
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);