| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hivegui.dialog; |
| 16 | |
| 17 | import java.awt.Component; |
| 18 | import java.awt.GridBagConstraints; |
| 19 | import java.awt.GridBagLayout; |
| 20 | |
| 21 | import javax.swing.JComponent; |
| 22 | import javax.swing.JPanel; |
| 23 | |
| 24 | public class GridBagCommandPanelAdder extends AbstractCommandPanelAdder |
| 25 | { |
| 26 | public GridBagCommandPanelAdder() |
| 27 | { |
| 28 | super(GridBagLayout.class); |
| 29 | } |
| 30 | |
| 31 | @Override protected void addCommandPanel( JComponent container, |
| 32 | JPanel commands) |
| 33 | { |
| 34 | // Calculate the number of rows and columns |
| 35 | GridBagLayout layout = (GridBagLayout) container.getLayout(); |
| 36 | Component[] comps = container.getComponents(); |
| 37 | int cols = 0; |
| 38 | int rows = 0; |
| 39 | for (Component comp: comps) |
| 40 | { |
| 41 | GridBagConstraints constraints = layout.getConstraints(comp); |
| 42 | cols = Math.max(constraints.gridx + constraints.gridwidth, cols); |
| 43 | rows = Math.max(constraints.gridy + constraints.gridheight, rows); |
| 44 | } |
| 45 | |
| 46 | // Add one row |
| 47 | GridBagConstraints constraints = new GridBagConstraints(); |
| 48 | constraints.gridx = 0; |
| 49 | constraints.gridy = rows; |
| 50 | constraints.gridwidth = cols; |
| 51 | constraints.gridheight = 1; |
| 52 | constraints.anchor = GridBagConstraints.EAST; |
| 53 | constraints.fill = GridBagConstraints.NONE; |
| 54 | constraints.weightx = 0.0; |
| 55 | constraints.weighty = 0.0; |
| 56 | container.add(commands, constraints); |
| 57 | } |
| 58 | } |