| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| GridBagUtils |
|
| 1.0;1 |
| 1 | package org.jtheque.utils.ui; | |
| 2 | ||
| 3 | import java.awt.GridBagConstraints; | |
| 4 | import java.awt.Insets; | |
| 5 | ||
| 6 | /* | |
| 7 | * This file is part of JTheque. | |
| 8 | * | |
| 9 | * JTheque is free software: you can redistribute it and/or modify | |
| 10 | * it under the terms of the GNU General Public License as published by | |
| 11 | * the Free Software Foundation, either version 3 of the License. | |
| 12 | * | |
| 13 | * JTheque is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with JTheque. If not, see <http://www.gnu.org/licenses/>. | |
| 20 | */ | |
| 21 | ||
| 22 | /** | |
| 23 | * An utility class to make easier the UI development with GridBagLayout. | |
| 24 | * | |
| 25 | * @author Baptiste Wicht | |
| 26 | */ | |
| 27 | 0 | public final class GridBagUtils extends GridBagConstraints { |
| 28 | 0 | private Insets defaultInsets = new Insets(2, 2, 2, 2); |
| 29 | ||
| 30 | /** | |
| 31 | * Init the GridBagConstraints object. | |
| 32 | */ | |
| 33 | private void gbcInit() { | |
| 34 | 0 | gridx = 0; |
| 35 | 0 | gridy = 0; |
| 36 | 0 | gridwidth = 1; |
| 37 | 0 | gridheight = 1; |
| 38 | 0 | anchor = BASELINE_LEADING; |
| 39 | 0 | fill = NONE; |
| 40 | 0 | weightx = 0; |
| 41 | 0 | weighty = 0; |
| 42 | 0 | insets = defaultInsets; |
| 43 | 0 | ipadx = 0; |
| 44 | 0 | ipady = 0; |
| 45 | 0 | } |
| 46 | ||
| 47 | /** | |
| 48 | * Configure and return the GridBagConstraints object. | |
| 49 | * | |
| 50 | * @param x The x position of the component. | |
| 51 | * @param y The y position of the component. | |
| 52 | * @return The GridBagConstraints object. | |
| 53 | */ | |
| 54 | public GridBagConstraints gbcSet(int x, int y) { | |
| 55 | 0 | gbcInit(); |
| 56 | ||
| 57 | 0 | gridx = x; |
| 58 | 0 | gridy = y; |
| 59 | ||
| 60 | 0 | return this; |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * Configure and return the GridBagConstraints object. | |
| 65 | * | |
| 66 | * @param x The x position of the component. | |
| 67 | * @param y The y position of the component. | |
| 68 | * @param fill The fill constraints. | |
| 69 | * @return The GridBagConstraints object. | |
| 70 | */ | |
| 71 | public GridBagConstraints gbcSet(int x, int y, int fill) { | |
| 72 | 0 | gbcInit(); |
| 73 | ||
| 74 | 0 | gridx = x; |
| 75 | 0 | gridy = y; |
| 76 | 0 | this.fill = fill; |
| 77 | ||
| 78 | 0 | return this; |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Configure and return the GridBagConstraints object. | |
| 83 | * | |
| 84 | * @param x The x position of the component. | |
| 85 | * @param y The y position of the component. | |
| 86 | * @param fill The fill constraints. | |
| 87 | * @param anchor The anchor of the component. | |
| 88 | * @return The GridBagConstraints object. | |
| 89 | */ | |
| 90 | public GridBagConstraints gbcSet(int x, int y, int fill, int anchor) { | |
| 91 | 0 | gbcInit(); |
| 92 | ||
| 93 | 0 | gridx = x; |
| 94 | 0 | gridy = y; |
| 95 | 0 | this.fill = fill; |
| 96 | 0 | this.anchor = anchor; |
| 97 | ||
| 98 | 0 | return this; |
| 99 | } | |
| 100 | ||
| 101 | /** | |
| 102 | * Configure and return the GridBagConstraints object. | |
| 103 | * | |
| 104 | * @param x The x position of the component. | |
| 105 | * @param y The y position of the component. | |
| 106 | * @param fill The fill constraints. | |
| 107 | * @param anchor The anchor of the component. | |
| 108 | * @param width The col span. | |
| 109 | * @param height The row span. | |
| 110 | * @return The GridBagConstraints object. | |
| 111 | */ | |
| 112 | public GridBagConstraints gbcSet(int x, int y, int fill, int anchor, int width, int height) { | |
| 113 | 0 | gbcInit(); |
| 114 | ||
| 115 | 0 | gridx = x; |
| 116 | 0 | gridy = y; |
| 117 | 0 | this.fill = fill; |
| 118 | 0 | this.anchor = anchor; |
| 119 | 0 | gridwidth = width; |
| 120 | 0 | gridheight = height; |
| 121 | ||
| 122 | 0 | return this; |
| 123 | } | |
| 124 | ||
| 125 | /** | |
| 126 | * Configure and return the GridBagConstraints object. | |
| 127 | * | |
| 128 | * @param x The x position of the component. | |
| 129 | * @param y The y position of the component. | |
| 130 | * @param fill The fill constraints. | |
| 131 | * @param anchor The anchor of the component. | |
| 132 | * @param width The col span. | |
| 133 | * @param height The row span. | |
| 134 | * @param weightx The col fill weight. | |
| 135 | * @param weighty The row fill weight. | |
| 136 | * @return The GridBagConstraints object. | |
| 137 | */ | |
| 138 | public GridBagConstraints gbcSet(int x, int y, int fill, int anchor, int width, int height, double weightx, double weighty) { | |
| 139 | 0 | gbcInit(); |
| 140 | ||
| 141 | 0 | gridx = x; |
| 142 | 0 | gridy = y; |
| 143 | 0 | this.fill = fill; |
| 144 | 0 | this.anchor = anchor; |
| 145 | 0 | gridwidth = width; |
| 146 | 0 | gridheight = height; |
| 147 | 0 | this.weightx = weightx; |
| 148 | 0 | this.weighty = weighty; |
| 149 | ||
| 150 | 0 | return this; |
| 151 | } | |
| 152 | ||
| 153 | /** | |
| 154 | * Configure and return the GridBagConstraints object. | |
| 155 | * | |
| 156 | * @param x The x position of the component. | |
| 157 | * @param y The y position of the component. | |
| 158 | * @param fill The fill constraints. | |
| 159 | * @param anchor The anchor of the component. | |
| 160 | * @param width The col span. | |
| 161 | * @param height The row span. | |
| 162 | * @param weightx The col fill weight. | |
| 163 | * @param weighty The row fill weight. | |
| 164 | * @param ipadx The x internal padding width. | |
| 165 | * @param ipady The y internal padding height. | |
| 166 | * @return The <code>GridBagConstraints</code> object. | |
| 167 | */ | |
| 168 | public GridBagConstraints gbcSet(int x, int y, int fill, int anchor, int width, int height, double weightx, double weighty, int ipadx, int ipady) { | |
| 169 | 0 | gbcInit(); |
| 170 | ||
| 171 | 0 | gridx = x; |
| 172 | 0 | gridy = y; |
| 173 | 0 | this.fill = fill; |
| 174 | 0 | this.anchor = anchor; |
| 175 | 0 | gridwidth = width; |
| 176 | 0 | gridheight = height; |
| 177 | 0 | this.weightx = weightx; |
| 178 | 0 | this.weighty = weighty; |
| 179 | 0 | this.ipadx = ipadx; |
| 180 | 0 | this.ipady = ipady; |
| 181 | ||
| 182 | 0 | return this; |
| 183 | } | |
| 184 | ||
| 185 | /** | |
| 186 | * Configure and return the GridBagConstraints object. | |
| 187 | * | |
| 188 | * @param x The x position of the component. | |
| 189 | * @param y The y position of the component. | |
| 190 | * @param fill The fill constraints. | |
| 191 | * @param anchor The anchor of the component. | |
| 192 | * @param weightx The col fill weight. | |
| 193 | * @param weighty The row fill weight. | |
| 194 | * @return The <code>GridBagConstraints</code> object. | |
| 195 | */ | |
| 196 | public GridBagConstraints gbcSet(int x, int y, int fill, int anchor, double weightx, double weighty) { | |
| 197 | 0 | gbcInit(); |
| 198 | ||
| 199 | 0 | gridx = x; |
| 200 | 0 | gridy = y; |
| 201 | 0 | this.fill = fill; |
| 202 | 0 | this.anchor = anchor; |
| 203 | 0 | this.weightx = weightx; |
| 204 | 0 | this.weighty = weighty; |
| 205 | ||
| 206 | 0 | return this; |
| 207 | } | |
| 208 | ||
| 209 | /** | |
| 210 | * Set the default insets. | |
| 211 | * | |
| 212 | * @param defaultInsets The default insets. | |
| 213 | */ | |
| 214 | public void setDefaultInsets(Insets defaultInsets) { | |
| 215 | 0 | this.defaultInsets = defaultInsets; |
| 216 | 0 | } |
| 217 | ||
| 218 | /** | |
| 219 | * Set the default insets. | |
| 220 | * | |
| 221 | * @param top The top inset. | |
| 222 | * @param left The left inset. | |
| 223 | * @param bottom The bottom inset. | |
| 224 | * @param right The right inset. | |
| 225 | */ | |
| 226 | public void setDefaultInsets(int top, int left, int bottom, int right) { | |
| 227 | 0 | defaultInsets = new Insets(top, left, bottom, right); |
| 228 | 0 | } |
| 229 | } |