-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hotribao
committed
Oct 30, 2009
1 parent
4a8c4e6
commit dadabca
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
painless-gridbag/src/main/java/org/painlessgridbag/LayoutUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2009 Ho Tri Bao | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.painlessgridbag; | ||
|
||
import java.awt.GridBagConstraints; | ||
|
||
import javax.swing.JButton; | ||
import javax.swing.JPanel; | ||
|
||
import org.painlessgridbag.engine.IGridCell; | ||
|
||
/** | ||
* | ||
* @author Ho Tri Bao | ||
* | ||
*/ | ||
public final class LayoutUtils { | ||
|
||
private LayoutUtils() { | ||
} | ||
|
||
public static void addButtonPanel(final PainlessGridBag containterGbl, | ||
final JButton... buttons) { | ||
// create button panel | ||
JPanel pnlButton = new JPanel(); | ||
PainlessGridBag gbl = new PainlessGridBag(pnlButton, false); | ||
IGridCell gridCell = gbl.row(); | ||
for (JButton button : buttons) { | ||
gridCell = gridCell.cell(button); | ||
gbl.constraints(button).anchor = GridBagConstraints.EAST; | ||
} | ||
gbl.done(); | ||
|
||
// add the panel to the container | ||
containterGbl.row().cellXRemainder(pnlButton); | ||
containterGbl.constraints(pnlButton).anchor = GridBagConstraints.CENTER; | ||
containterGbl.constraints(pnlButton).insets.bottom = 5; | ||
} | ||
|
||
public static void addButtonPanel(final PainlessGridBag containterGbl, | ||
final JButton[] leftBtns, final JButton[] rightBtns) { | ||
PainlessGridbagConfiguration config = new PainlessGridbagConfiguration(); | ||
config.setLastRowBottomSpacing(0); | ||
|
||
JPanel pnlButton = new JPanel(); | ||
PainlessGridBag gbl = new PainlessGridBag(pnlButton, config, false); | ||
IGridCell gridCell = gbl.row(); | ||
|
||
if (leftBtns != null) { | ||
for (JButton button : leftBtns) { | ||
gridCell = gridCell.cell(button); | ||
gbl.constraints(button).anchor = GridBagConstraints.EAST; | ||
} | ||
} | ||
gridCell.cell(new JPanel()).fillX(); | ||
if (rightBtns != null) { | ||
for (JButton button : rightBtns) { | ||
gridCell = gridCell.cell(button); | ||
gbl.constraints(button).anchor = GridBagConstraints.WEST; | ||
} | ||
} | ||
gbl.done(); | ||
|
||
containterGbl.row().cellXRemainder(pnlButton).fillX(); | ||
containterGbl.constraints(pnlButton).anchor = GridBagConstraints.CENTER; | ||
containterGbl.constraints(pnlButton).insets.bottom = 5; | ||
} | ||
} |