| 1 | |
package org.jtheque.utils.ui; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
import javax.swing.Action; |
| 20 | |
import javax.swing.Box; |
| 21 | |
import javax.swing.JButton; |
| 22 | |
import javax.swing.JPanel; |
| 23 | |
import java.awt.Color; |
| 24 | |
import java.awt.Component; |
| 25 | |
import java.awt.GridBagConstraints; |
| 26 | |
import java.awt.GridBagLayout; |
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
public final class LinedButtonBarBuilder { |
| 34 | |
private final JPanel panel; |
| 35 | |
private final GridBagUtils gbc; |
| 36 | |
|
| 37 | |
private final int[] column; |
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
public LinedButtonBarBuilder(int lines) { |
| 45 | 0 | super(); |
| 46 | |
|
| 47 | 0 | column = new int[lines]; |
| 48 | |
|
| 49 | 0 | panel = new JPanel(new GridBagLayout()); |
| 50 | 0 | panel.setBackground(Color.white); |
| 51 | |
|
| 52 | 0 | gbc = new GridBagUtils(); |
| 53 | 0 | gbc.setDefaultInsets(2, 2, 2, 2); |
| 54 | |
|
| 55 | 0 | for (int i = 0; i < lines; i++) { |
| 56 | 0 | panel.add(Box.createHorizontalGlue(), gbc.gbcSet(column[i], i, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START, 1.0, 1.0)); |
| 57 | 0 | column[i]++; |
| 58 | |
} |
| 59 | 0 | } |
| 60 | |
|
| 61 | |
|
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | |
private void addAction(Action action, int line) { |
| 68 | 0 | int lineIndex = line - 1; |
| 69 | |
|
| 70 | 0 | panel.add(new JButton(action), gbc.gbcSet(column[lineIndex], lineIndex, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START)); |
| 71 | 0 | column[lineIndex]++; |
| 72 | 0 | } |
| 73 | |
|
| 74 | |
|
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | |
|
| 80 | |
public void addActions(int line, Action... actions) { |
| 81 | 0 | for (Action action : actions) { |
| 82 | 0 | addAction(action, line); |
| 83 | |
} |
| 84 | 0 | } |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
public Component getPanel() { |
| 92 | 0 | return panel; |
| 93 | |
} |
| 94 | |
} |