├── .gitignore ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── github │ │ └── danfickle │ │ └── jbootstrap │ │ └── jbootstraplplusf │ │ ├── JBootstrapButtonUI.java │ │ ├── JBootstrapFactory.java │ │ ├── JBootstrapLF.java │ │ ├── JBootstrapLabelUI.java │ │ ├── JBootstrapTextField.java │ │ ├── JBootstrapTextFieldUI.java │ │ ├── StyleButton.java │ │ ├── StyleLabel.java │ │ └── StyleUtil.java └── resources │ └── dialog-information.png └── test └── java └── com └── github └── danfickle └── jbootstrap └── jbootstraplplusf ├── ButtonTest.java ├── LabelTest.java └── TextFieldTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | drop 3 | www/webstart/*.jar 4 | .gradle 5 | .idea 6 | *.iml 7 | *.iws 8 | *.ipr 9 | .classpath 10 | .project 11 | .settings 12 | target/ 13 | *~ 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![ScreenShot](https://raw.github.com/danfickle/java-bootstrap-laf/gh-pages/buttons-screenshot.png) 2 | 3 | [More screenshots](http://danfickle.github.io/java-bootstrap-laf/) 4 | 5 | [Jump to main source](/src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf) 6 | 7 | Implemented 8 | ----------- 9 | + Text fields (JTextField) 10 | + Styled text (JLabel) 11 | + Badges (JLabel) 12 | + Labels (JLabel) 13 | + Buttons (JButton) 14 | 15 | Contributing 16 | ------------ 17 | Pull requests and issues are very welcome. 18 | 19 | Acknowledgements 20 | ---------------- 21 | [Insubstantial Project](https://github.com/Insubstantial/insubstantial) 22 | [MetroLAF](https://github.com/cdavoren/MetroLAF) 23 | 24 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.github.danfickle.jbootstrap 6 | jbootstraplplusf 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | jbootstraplplusf 11 | http://maven.apache.org 12 | 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | 20 | org.apache.maven.plugins 21 | maven-compiler-plugin 22 | 3.1 23 | 24 | 1.7 25 | 1.7 26 | true 27 | true 28 | true 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/JBootstrapButtonUI.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.*; 4 | import java.awt.geom.AffineTransform; 5 | import java.beans.PropertyChangeEvent; 6 | import java.beans.PropertyChangeListener; 7 | import java.util.EnumSet; 8 | 9 | import javax.swing.*; 10 | import javax.swing.border.AbstractBorder; 11 | import javax.swing.border.Border; 12 | import javax.swing.plaf.ComponentUI; 13 | import javax.swing.plaf.basic.*; 14 | import javax.swing.text.View; 15 | 16 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleButton.BtnBaseStyle; 17 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleUtil.BorderSide; 18 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleUtil.ComponentState; 19 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleUtil.StyleQuad; 20 | 21 | public class JBootstrapButtonUI extends BasicButtonUI implements PropertyChangeListener 22 | { 23 | private final AbstractButton button; 24 | private BtnBaseStyle baseStyle; 25 | 26 | private Rectangle viewRect = new Rectangle(); 27 | private Rectangle iconRect = new Rectangle(); 28 | private Rectangle textRect = new Rectangle(); 29 | 30 | private EnumSet state = EnumSet.noneOf(ComponentState.class); 31 | 32 | public static ComponentUI createUI(JComponent comp) 33 | { 34 | return new JBootstrapButtonUI((AbstractButton) comp); 35 | } 36 | 37 | private JBootstrapButtonUI(AbstractButton button) 38 | { 39 | this.button = button; 40 | } 41 | 42 | private boolean isJBootstrapButton(AbstractButton b) 43 | { 44 | String clss = (String) b.getClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS); 45 | return clss != null; 46 | } 47 | 48 | @Override 49 | protected void installDefaults(AbstractButton b) 50 | { 51 | super.installDefaults(b); 52 | 53 | if (!isJBootstrapButton(b)) 54 | return; 55 | 56 | installMyDefaults(b); 57 | } 58 | 59 | private void installMyDefaults(AbstractButton b) 60 | { 61 | b.setFont(baseStyle.getFont()); 62 | b.setBorder(getButtonBorder(b, baseStyle)); 63 | b.setBackground(null); 64 | b.setForeground(baseStyle.getTextColor()); 65 | b.setOpaque(false); 66 | b.setFocusable(true); 67 | b.setRequestFocusEnabled(true); 68 | b.setRolloverEnabled(true); 69 | } 70 | 71 | @Override 72 | protected void uninstallDefaults(AbstractButton b) 73 | { 74 | super.uninstallDefaults(b); 75 | 76 | if (!isJBootstrapButton(b)) 77 | return; 78 | 79 | b.setBorder(null); 80 | b.setOpaque(true); 81 | b.setFont(null); 82 | b.setBackground(null); 83 | b.setForeground(null); 84 | } 85 | 86 | @Override 87 | protected void installListeners(AbstractButton b) 88 | { 89 | super.installListeners(b); 90 | b.addPropertyChangeListener(this); 91 | } 92 | 93 | @Override 94 | protected void uninstallListeners(AbstractButton b) 95 | { 96 | b.removePropertyChangeListener(this); 97 | super.uninstallListeners(b); 98 | } 99 | 100 | private Border getButtonBorder(final AbstractButton button, final BtnBaseStyle style) 101 | { 102 | return new AbstractBorder() 103 | { 104 | private static final long serialVersionUID = 1L; 105 | 106 | @Override 107 | public Insets getBorderInsets(Component c) 108 | { 109 | int left = style.getMargin().getLeft() + style.getFocusPadding().getLeft() + style.getPadding().getLeft(); 110 | int right = style.getMargin().getRight() + style.getFocusPadding().getRight() + style.getPadding().getRight(); 111 | int top = style.getMargin().getTop() + style.getFocusPadding().getTop() + style.getPadding().getTop(); 112 | int bottom = style.getMargin().getBottom() + style.getFocusPadding().getBottom() + style.getPadding().getTop(); 113 | 114 | return new Insets(top, left, bottom, right); 115 | } 116 | 117 | @Override 118 | public boolean isBorderOpaque() 119 | { 120 | return false; 121 | } 122 | 123 | @Override 124 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) 125 | { 126 | Graphics2D g2d = (Graphics2D) g.create(); 127 | 128 | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 129 | 130 | drawRoundedBorder(g2d, 131 | x + style.getFocusPadding().getLeft(), 132 | y + style.getFocusPadding().getTop(), 133 | width - style.getFocusPadding().getLeft() - style.getFocusPadding().getRight(), 134 | height - style.getFocusPadding().getTop() - style.getFocusPadding().getBottom(), 135 | style.getBorderColor(), 136 | (int) (getCornerRadius() * style.getBorderArcSize()), 137 | !state.contains(ComponentState.ACTIVE)); 138 | 139 | g2d.dispose(); 140 | } 141 | }; 142 | } 143 | 144 | private static void drawRoundedBorder(Graphics2D g2, int x, int y, int w, int h, 145 | StyleQuad borderColor, int arc, boolean boxShadow) 146 | { 147 | g2.setStroke(new BasicStroke(0.5f)); 148 | 149 | drawBorder(g2, arc, x, y, w, h, borderColor.getTop(), BorderSide.TOP); 150 | drawBorder(g2, arc, x, y, w, h, borderColor.getBottom(), BorderSide.BOTTOM); 151 | drawBorder(g2, arc, x, y, w, h, borderColor.getLeft(), BorderSide.LEFT); 152 | drawBorder(g2, arc, x, y, w, h, borderColor.getRight(), BorderSide.RIGHT); 153 | 154 | if (boxShadow) 155 | { 156 | drawBorder(g2, arc, x, y + 2, w, 1, BtnBaseStyle.BOX_SHADOW_COLOR, BorderSide.TOP); 157 | } 158 | 159 | g2.setColor(borderColor.getTop()); 160 | g2.setClip(x, y, w, arc); 161 | g2.drawRoundRect(x, y, w - 1, h - 1, arc, arc); 162 | g2.drawRoundRect(x, y, w - 1, h - 1, arc, arc); 163 | 164 | g2.setColor(borderColor.getBottom()); 165 | g2.setClip(x, y + h - arc, w, arc); 166 | g2.drawRoundRect(x, y, w - 1, h - 1, arc, arc); 167 | g2.drawRoundRect(x, y, w - 1, h - 1, arc, arc); 168 | } 169 | 170 | static void drawFocusRing(Graphics2D g2, int width, int height) 171 | { 172 | Stroke bs = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10.0f, new float[] { 0f, 3f }, 10.0f); 173 | g2.setStroke(bs); 174 | g2.setColor(Color.BLACK); 175 | g2.drawRect(0, 0, width - 1, height - 1); 176 | } 177 | 178 | static void drawBorder(Graphics2D g2, int arc, int xxx, int yyy, int width, int height, Color color, BorderSide border) 179 | { 180 | int x, y, x2, y2; 181 | 182 | if (border == BorderSide.LEFT) 183 | { 184 | x = xxx; 185 | x2 = xxx; 186 | y = arc + yyy; 187 | y2 = height - arc + yyy; 188 | } 189 | else if (border == BorderSide.RIGHT) 190 | { 191 | x = width + xxx - 1; 192 | x2 = width + xxx - 1; 193 | y = arc + yyy; 194 | y2 = height - arc + yyy; 195 | } 196 | else if (border == BorderSide.BOTTOM) 197 | { 198 | x = arc + xxx; 199 | x2 = width - arc + xxx; 200 | y = height + yyy - 1; 201 | y2 = height + yyy - 1; 202 | } 203 | else //if (border == BorderSide.TOP) 204 | { 205 | x = arc + xxx; 206 | x2 = width - arc + xxx; 207 | y = yyy; 208 | y2 = yyy; 209 | } 210 | 211 | g2.setColor(color); 212 | g2.drawLine(x, y, x2, y2); 213 | } 214 | 215 | public static float getClassicButtonCornerRadius(int fontSize) 216 | { 217 | return StyleUtil.getAdjustedSize(fontSize, 2, 6, 1, false); 218 | } 219 | 220 | private void paintBackground(AbstractButton b, Graphics2D g2d, BtnBaseStyle style, int x, int y, int width, int height) 221 | { 222 | if (!style.getGradient().isSolid()) 223 | { 224 | LinearGradientPaint gradient = new LinearGradientPaint(x, y, x, y + height, 225 | new float[] { 0.0f, 1.0f }, 226 | new Color[] { style.getGradient().getStart(), style.getGradient().getEnd() }); 227 | 228 | g2d.setPaint(gradient); 229 | } 230 | else 231 | { 232 | g2d.setColor(style.getGradient().getStart()); 233 | } 234 | 235 | g2d.fillRoundRect(x, y, width, height, (int) (getCornerRadius() * style.getBorderArcSize()), 236 | (int) (getCornerRadius() * style.getBorderArcSize())); 237 | 238 | if (state.contains(ComponentState.DISABLED)) 239 | { 240 | g2d.setColor(BtnBaseStyle.DISABLED_COLOR); 241 | 242 | g2d.fillRoundRect(x, y, width, height, (int) (getCornerRadius() * style.getBorderArcSize()), 243 | (int) (getCornerRadius() * style.getBorderArcSize())); 244 | } 245 | } 246 | 247 | @Override 248 | public void paint(Graphics g, JComponent c) 249 | { 250 | final AbstractButton b = (AbstractButton) c; 251 | 252 | if (!isJBootstrapButton(b)) 253 | { 254 | super.paint(g, c); 255 | return; 256 | } 257 | 258 | ButtonModel m = b.getModel(); 259 | 260 | state.clear(); 261 | 262 | if (m.isPressed() || m.isArmed()) 263 | state.add(ComponentState.ACTIVE); 264 | 265 | if (!m.isEnabled()) 266 | state.add(ComponentState.DISABLED); 267 | 268 | if (m.isRollover()) 269 | state.add(ComponentState.HOVER); 270 | 271 | if (b.hasFocus()) 272 | state.add(ComponentState.FOCUSED); 273 | 274 | BtnBaseStyle style = StyleButton.applyStyles((String) b.getClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS), state); 275 | 276 | FontMetrics fm = g.getFontMetrics(); 277 | 278 | Insets i = c.getInsets(); 279 | 280 | viewRect.x = i.left; 281 | viewRect.y = i.top; 282 | viewRect.width = b.getWidth() - (i.right + viewRect.x); 283 | viewRect.height = b.getHeight() - (i.bottom + viewRect.y); 284 | 285 | textRect.x = textRect.y = textRect.width = textRect.height = 0; 286 | iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0; 287 | 288 | Font f = c.getFont(); 289 | 290 | // layout the text and icon 291 | String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), b.getIcon(), 292 | b.getVerticalAlignment(), b.getHorizontalAlignment(), 293 | b.getVerticalTextPosition(), b.getHorizontalTextPosition(), 294 | viewRect, iconRect, textRect, 295 | b.getText() == null ? 0 : b.getIconTextGap()); 296 | 297 | Graphics2D g2d = (Graphics2D) g.create(); 298 | 299 | View v = (View) c.getClientProperty(BasicHTML.propertyKey); 300 | g2d.setFont(f); 301 | 302 | paintBackground(b, g2d, style, 303 | style.getFocusPadding().getLeft(), 304 | style.getFocusPadding().getTop(), 305 | b.getWidth() - style.getFocusPadding().getLeft() - style.getFocusPadding().getRight(), 306 | b.getHeight() - style.getFocusPadding().getTop() - style.getFocusPadding().getBottom()); 307 | 308 | if (v != null) 309 | v.paint(g2d, textRect); 310 | else 311 | paintButtonText(g2d, b, textRect, text, style); 312 | 313 | // Paint the Icon 314 | if (b.getIcon() != null) 315 | paintIcon(g2d, c, iconRect); 316 | 317 | if (b.isFocusPainted() && state.contains(ComponentState.FOCUSED)) 318 | drawFocusRing(g2d, b.getWidth(), b.getHeight()); 319 | } 320 | 321 | @Override 322 | public Dimension getPreferredSize(JComponent c) 323 | { 324 | AbstractButton button = (AbstractButton) c; 325 | 326 | if (!isJBootstrapButton(button)) 327 | return super.getPreferredSize(c); 328 | 329 | // fix for defect 263 330 | Dimension superPref = super.getPreferredSize(button); 331 | if (superPref == null) 332 | return null; 333 | 334 | Dimension result = getPreferredSize(button, superPref); 335 | return result; 336 | } 337 | 338 | private static int getMinButtonWidth(int fontSize) 339 | { 340 | return 5 * fontSize + 12; 341 | } 342 | 343 | private Dimension getPreferredSize(AbstractButton button, Dimension uiPreferredSize) 344 | { 345 | Dimension result; 346 | boolean toTweakWidth = false; 347 | boolean toTweakHeight = false; 348 | 349 | Icon icon = button.getIcon(); 350 | boolean hasIcon = (icon != null); 351 | boolean hasText = (button.getText() != null && !button.getText().isEmpty()); 352 | Insets margin = button.getMargin(); 353 | 354 | result = uiPreferredSize; 355 | 356 | if (hasText) 357 | { 358 | int baseWidth = uiPreferredSize.width; 359 | 360 | baseWidth = Math.max(baseWidth, getMinButtonWidth(baseStyle.getFont().getSize() - 12)); 361 | 362 | result = new Dimension(baseWidth, uiPreferredSize.height); 363 | 364 | int baseHeight = result.height + baseStyle.getFocusPadding().getTop() + baseStyle.getFocusPadding().getBottom(); 365 | 366 | result = new Dimension(result.width, baseHeight); 367 | } 368 | 369 | int iconPaddingWidth = 6 + 2 * 1 + baseStyle.getFocusPadding().getLeft() + baseStyle.getFocusPadding().getRight(); 370 | int iconPaddingHeight = 6 + baseStyle.getFocusPadding().getBottom() + baseStyle.getFocusPadding().getTop(); 371 | 372 | if (margin != null) 373 | { 374 | iconPaddingWidth = Math.max(iconPaddingWidth, margin.left + margin.right); 375 | iconPaddingHeight = Math.max(iconPaddingHeight, margin.top + margin.bottom); 376 | } 377 | 378 | if (hasIcon) 379 | { 380 | // check the icon height 381 | int iconHeight = icon.getIconHeight(); 382 | 383 | if (iconHeight > (result.getHeight() - iconPaddingHeight)) 384 | { 385 | result = new Dimension(result.width, iconHeight); 386 | toTweakHeight = true; 387 | } 388 | 389 | int iconWidth = icon.getIconWidth(); 390 | 391 | if (iconWidth > (result.getWidth() - iconPaddingWidth)) { 392 | result = new Dimension(iconWidth, result.height); 393 | toTweakWidth = true; 394 | } 395 | } 396 | 397 | if (toTweakWidth) { 398 | result = new Dimension(result.width + iconPaddingWidth, result.height); 399 | } 400 | if (toTweakHeight) { 401 | result = new Dimension(result.width, result.height + iconPaddingHeight); 402 | } 403 | 404 | return result; 405 | } 406 | 407 | private float getCornerRadius() 408 | { 409 | return StyleUtil.getAdjustedSize(baseStyle.getFont().getSize(), 2, 6, 1, false); 410 | } 411 | 412 | @Override 413 | public boolean contains(JComponent c, int x, int y) { 414 | // TODO: More accurate test. 415 | return super.contains(c, x, y); 416 | } 417 | 418 | @Override 419 | protected void paintIcon(Graphics g, JComponent c, Rectangle iconRect) 420 | { 421 | Graphics2D graphics = (Graphics2D) g.create(); 422 | AbstractButton b = (AbstractButton) c; 423 | Icon icon = b.getIcon(); 424 | icon.paintIcon(b, graphics, iconRect.x, iconRect.y); 425 | graphics.dispose(); 426 | } 427 | 428 | private void paintButtonText(Graphics g, AbstractButton button, 429 | Rectangle textRect, String text, BtnBaseStyle style) 430 | { 431 | paintText(g, button, textRect, text, button.getDisplayedMnemonicIndex(), style.getFont(), style.getTextColor(), null, null); 432 | } 433 | 434 | private static void paintText(Graphics g, JComponent comp, Rectangle textRect, 435 | String text, int mnemonicIndex, Font font, Color color, Rectangle clip, 436 | AffineTransform transform) 437 | { 438 | if ((text == null) || (text.isEmpty())) 439 | return; 440 | 441 | Graphics2D g2d = (Graphics2D) g.create(); 442 | 443 | g2d.setFont(font); 444 | g2d.setColor(color); 445 | // fix for issue 420 - call clip() instead of setClip() to 446 | // respect the currently set clip shape 447 | if (clip != null) 448 | g2d.clip(clip); 449 | if (transform != null) 450 | g2d.transform(transform); 451 | BasicGraphicsUtils.drawStringUnderlineCharAt(g2d, text, mnemonicIndex, 452 | textRect.x, textRect.y + g2d.getFontMetrics().getAscent()); 453 | g2d.dispose(); 454 | } 455 | 456 | @Override 457 | public void update(Graphics g, JComponent c) 458 | { 459 | this.paint(g, c); 460 | } 461 | 462 | @Override 463 | public void propertyChange(PropertyChangeEvent evt) 464 | { 465 | if (!evt.getPropertyName().equals(JBootstrapLF.JBOOTSTRAP_CLASS)) 466 | return; 467 | 468 | String clss = (String) button.getClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS); 469 | 470 | if (clss != null) 471 | { 472 | this.baseStyle = StyleButton.applyStyles(clss, state); 473 | 474 | SwingUtilities.invokeLater(new Runnable() 475 | { 476 | @Override 477 | public void run() 478 | { 479 | installMyDefaults(button); 480 | button.repaint(); 481 | } 482 | }); 483 | } 484 | } 485 | } 486 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/JBootstrapFactory.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | import java.util.regex.Pattern; 5 | 6 | import javax.swing.JButton; 7 | import javax.swing.JLabel; 8 | 9 | import com.github.danfickle.jbootstrap.jbootstraplplusf.JBootstrapTextField.JBootstrapTextFieldType; 10 | 11 | public class JBootstrapFactory 12 | { 13 | public static enum JBootstrapLabelType 14 | { 15 | DEFAULT("label"), 16 | INFO("label label-info"), 17 | SUCCESS("label label-success"), 18 | WARNING("label label-warning"), 19 | IMPORTANT("label label-important"), 20 | INVERSE("label label-inverse"); 21 | 22 | final String cls; 23 | 24 | private JBootstrapLabelType(String clz) 25 | { 26 | cls = clz; 27 | } 28 | } 29 | 30 | public static enum JBootstrapBadgeType 31 | { 32 | DEFAULT("badge"), 33 | INFO("badge badge-info"), 34 | SUCCESS("badge badge-success"), 35 | WARNING("badge badge-warning"), 36 | IMPORTANT("badge badge-important"), 37 | INVERSE("badge badge-inverse"); 38 | 39 | final String cls; 40 | 41 | private JBootstrapBadgeType(String clz) 42 | { 43 | cls = clz; 44 | } 45 | } 46 | 47 | public static enum JBootstrapTextType 48 | { 49 | DEFAULT(Color.BLACK, "black"), 50 | INFO(new Color(0x3A87AD), "#3A87AD"), 51 | SUCCESS(new Color(0x468847), "#468847"), 52 | WARNING(new Color(0xC09853), "#C09853"), 53 | ERROR(new Color(0xB94A48), "#B94A48"); 54 | 55 | final Color clr; 56 | final String hClr; 57 | 58 | private JBootstrapTextType(Color clz, String htmlColor) 59 | { 60 | clr = clz; 61 | hClr = htmlColor; 62 | } 63 | } 64 | 65 | public static enum JBootstrapButtonType 66 | { 67 | DEFAULT("btn"), 68 | INFO("btn btn-info"), 69 | SUCCESS("btn btn-success"), 70 | WARNING("btn btn-warning"), 71 | DANGER("btn btn-danger"), 72 | INVERSE("btn btn-inverse"), 73 | PRIMARY("btn btn-primary"); 74 | 75 | final String cls; 76 | 77 | private JBootstrapButtonType(String clz) 78 | { 79 | cls = clz; 80 | } 81 | } 82 | 83 | public static enum JBootstrapButtonSize 84 | { 85 | DEFAULT("btn-default"), 86 | MINI("btn-mini"), 87 | SMALL("btn-small"), 88 | LARGE("btn-large"); 89 | 90 | final String cls; 91 | 92 | private JBootstrapButtonSize(String clz) 93 | { 94 | cls = clz; 95 | } 96 | } 97 | 98 | public static JLabel createLabel(String text, JBootstrapLabelType type) 99 | { 100 | JLabel lbl = new JLabel(text); 101 | lbl.putClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS, type.cls); 102 | return lbl; 103 | } 104 | 105 | public static JLabel createBadge(String text, JBootstrapBadgeType type) 106 | { 107 | JLabel lbl = new JLabel(text); 108 | lbl.putClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS, type.cls); 109 | return lbl; 110 | } 111 | 112 | public static JLabel createText(String text, JBootstrapTextType type) 113 | { 114 | JLabel lbl = new JLabel(text); 115 | lbl.setBackground(Color.WHITE); 116 | lbl.setForeground(type.clr); 117 | return lbl; 118 | } 119 | 120 | /** 121 | * WARNING: Remember to resize when window, frame, etc is resized. 122 | */ 123 | public static JLabel createWrappedText(String text, JBootstrapTextType type, int pxWidth) 124 | { 125 | JLabel lbl = new JLabel("" + text.replaceAll(Pattern.quote("<"), "<").replaceAll(Pattern.quote(">"), ">") + ""); 126 | lbl.setBackground(Color.WHITE); 127 | return lbl; 128 | } 129 | 130 | public static JButton createButton(String text, JBootstrapButtonType type, JBootstrapButtonSize sz) 131 | { 132 | JButton btn = new JButton(text); 133 | btn.putClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS, type.cls + " " + sz.cls); 134 | return btn; 135 | } 136 | 137 | public static JBootstrapTextField createTextField(int cols, String placeholder, JBootstrapTextFieldType tp) 138 | { 139 | JBootstrapTextField txt = new JBootstrapTextField(); 140 | txt.setPlaceholder(placeholder); 141 | txt.setType(tp); 142 | txt.setColumns(cols); 143 | return txt; 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/JBootstrapLF.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import javax.swing.UIDefaults; 4 | import javax.swing.plaf.basic.BasicLookAndFeel; 5 | 6 | @SuppressWarnings("serial") 7 | public class JBootstrapLF extends BasicLookAndFeel 8 | { 9 | public static final String JBOOTSTRAP_CLASS = "jbootstrap-class"; 10 | 11 | @Override 12 | public String getDescription() { 13 | // TODO Auto-generated method stub 14 | return "Swing Look and Feel based on Twitter Bootstrap"; 15 | } 16 | 17 | @Override 18 | public String getID() { 19 | return "JBootstrap"; 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return "JBootstrap"; 25 | } 26 | 27 | @Override 28 | public boolean isNativeLookAndFeel() { 29 | return false; 30 | } 31 | 32 | @Override 33 | public boolean isSupportedLookAndFeel() { 34 | return true; 35 | } 36 | 37 | @Override 38 | protected void initClassDefaults(UIDefaults table) { 39 | super.initClassDefaults(table); 40 | StyleButton.registerStyles(); 41 | StyleLabel.registerStyles(); 42 | 43 | table.put("ButtonUI", JBootstrapButtonUI.class.getCanonicalName()); 44 | table.put("LabelUI", JBootstrapLabelUI.class.getCanonicalName()); 45 | table.put("TextFieldUI", JBootstrapTextFieldUI.class.getCanonicalName()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/JBootstrapLabelUI.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.awt.Graphics; 6 | import java.awt.Graphics2D; 7 | import java.awt.Insets; 8 | import java.awt.RenderingHints; 9 | import java.beans.PropertyChangeEvent; 10 | import java.beans.PropertyChangeListener; 11 | import javax.swing.JComponent; 12 | import javax.swing.JLabel; 13 | import javax.swing.SwingUtilities; 14 | import javax.swing.border.EmptyBorder; 15 | import javax.swing.plaf.ComponentUI; 16 | import javax.swing.plaf.UIResource; 17 | import javax.swing.plaf.basic.BasicLabelUI; 18 | 19 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleLabel.LabelBaseStyle; 20 | 21 | public class JBootstrapLabelUI extends BasicLabelUI implements PropertyChangeListener 22 | { 23 | private LabelBaseStyle baseStyle; 24 | private final JLabel lbl; 25 | 26 | public static ComponentUI createUI(JComponent comp) 27 | { 28 | return new JBootstrapLabelUI((JLabel) comp); 29 | } 30 | 31 | private boolean isJBootstrapLabel(JLabel b) 32 | { 33 | String clss = (String) b.getClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS); 34 | 35 | if (baseStyle == null && clss != null) 36 | baseStyle = StyleLabel.applyStyles(clss); 37 | 38 | return clss != null; 39 | } 40 | 41 | private JBootstrapLabelUI(JLabel lbl) 42 | { 43 | this.lbl = lbl; 44 | } 45 | 46 | @Override 47 | protected void uninstallDefaults(JLabel c) 48 | { 49 | if (lbl.getBorder() != null) 50 | lbl.setBorder(null); 51 | 52 | if ((lbl.getForeground() instanceof UIResource)) 53 | lbl.setForeground(null); 54 | 55 | if ((lbl.getFont() instanceof UIResource)) 56 | lbl.setFont(null); 57 | 58 | if ((lbl.getBackground() instanceof UIResource)) 59 | lbl.setBackground(null); 60 | } 61 | 62 | @Override 63 | protected void installDefaults(JLabel b) 64 | { 65 | if (isJBootstrapLabel(b)) 66 | installMyDefaults(); 67 | } 68 | 69 | private void installMyDefaults() 70 | { 71 | lbl.setBorder(new EmptyBorder(new Insets(4, 4, 4, 4))); 72 | lbl.setForeground(baseStyle.getTextColor()); 73 | lbl.setFont(baseStyle.getFont()); 74 | lbl.setBackground(baseStyle.getBackgroundColor()); 75 | lbl.repaint(); 76 | } 77 | 78 | @Override 79 | protected void installListeners(JLabel c) 80 | { 81 | c.addPropertyChangeListener(this); 82 | } 83 | 84 | @Override 85 | protected void uninstallListeners(JLabel c) 86 | { 87 | c.removePropertyChangeListener(this); 88 | } 89 | 90 | @Override 91 | public void propertyChange(PropertyChangeEvent evt) 92 | { 93 | if (!evt.getPropertyName().equals(JBootstrapLF.JBOOTSTRAP_CLASS)) 94 | return; 95 | 96 | String clss = (String) lbl.getClientProperty(JBootstrapLF.JBOOTSTRAP_CLASS); 97 | 98 | if (clss != null) 99 | { 100 | this.baseStyle = StyleLabel.applyStyles(clss); 101 | 102 | SwingUtilities.invokeLater(new Runnable() 103 | { 104 | @Override 105 | public void run() 106 | { 107 | installMyDefaults(); 108 | } 109 | }); 110 | } 111 | } 112 | 113 | @Override 114 | public void paint(Graphics g, JComponent c) 115 | { 116 | ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 117 | 118 | if (!isJBootstrapLabel((JLabel) c)) 119 | { 120 | super.paint(g, c); 121 | return; 122 | } 123 | 124 | Graphics2D g2 = (Graphics2D) g.create(); 125 | Color bgSaved = c.getBackground(); 126 | 127 | //g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 128 | paintBackground((JLabel) c, g2, 0, 0, c.getWidth(), c.getHeight()); 129 | 130 | c.setBackground(null); 131 | super.paint(g2, c); 132 | c.setBackground(bgSaved); 133 | } 134 | 135 | private void paintBackground(JLabel b, Graphics2D g2d, int x, int y, int width, int height) 136 | { 137 | g2d.setColor(b.getBackground()); 138 | g2d.fillRoundRect(x, y, width, height, (int) (getCornerRadius(b.getFont()) * baseStyle.getBorderArcSize()), 139 | (int) (getCornerRadius(b.getFont()) * baseStyle.getBorderArcSize())); 140 | } 141 | 142 | private float getCornerRadius(Font f) 143 | { 144 | return StyleUtil.getAdjustedSize(f.getSize(), 2, 6, 1, false); 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/JBootstrapTextField.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | 5 | import javax.swing.JTextField; 6 | 7 | public class JBootstrapTextField extends JTextField 8 | { 9 | private static final long serialVersionUID = 1L; 10 | 11 | private JBootstrapTextFieldType tp = JBootstrapTextFieldType.DEFAULT; 12 | private String ph; 13 | private boolean search; 14 | 15 | public static enum JBootstrapTextFieldType 16 | { 17 | DEFAULT(new Color(0xCCCCCC), new Color(82, 168, 236, 200)), 18 | WARNING(new Color(0xC09853), new Color(0xC0, 0x98, 0x53, 200)), 19 | SUCCESS(new Color(0x468847), new Color(0x46, 0x88, 0x47, 200)), 20 | INFO(new Color(0x3A87AD), new Color(0x3A, 0x87, 0xAD, 200)), 21 | DANGER(new Color(0xB94A48), new Color(0xB9, 0x4A, 0x48, 200)); 22 | 23 | final Color clr; 24 | final Color box; 25 | 26 | JBootstrapTextFieldType(Color c, Color d) 27 | { 28 | clr = c; 29 | box = d; 30 | } 31 | } 32 | 33 | public void setType(JBootstrapTextFieldType type) 34 | { 35 | tp = type; 36 | repaint(); 37 | } 38 | 39 | public void setPlaceholder(String placeholder) 40 | { 41 | ph = placeholder; 42 | repaint(); 43 | } 44 | 45 | public JBootstrapTextFieldType getType() 46 | { 47 | return tp; 48 | } 49 | 50 | public String getPlaceholder() 51 | { 52 | return ph; 53 | } 54 | 55 | /** 56 | * Adds an extra rounded border. 57 | */ 58 | public void setSearch(boolean isSearch) 59 | { 60 | search = isSearch; 61 | repaint(); 62 | } 63 | 64 | public boolean isSearch() 65 | { 66 | return search; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/JBootstrapTextFieldUI.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.BasicStroke; 4 | import java.awt.Color; 5 | import java.awt.Component; 6 | import java.awt.Font; 7 | import java.awt.Graphics; 8 | import java.awt.Graphics2D; 9 | import java.awt.Insets; 10 | import java.awt.RenderingHints; 11 | import java.awt.Shape; 12 | import java.awt.event.FocusEvent; 13 | import java.awt.event.FocusListener; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | import javax.swing.JComponent; 18 | import javax.swing.JLabel; 19 | import javax.swing.JTextField; 20 | import javax.swing.SwingUtilities; 21 | import javax.swing.border.AbstractBorder; 22 | import javax.swing.plaf.ComponentUI; 23 | import javax.swing.plaf.basic.BasicTextFieldUI; 24 | import javax.swing.text.BadLocationException; 25 | import javax.swing.text.DefaultHighlighter; 26 | import javax.swing.text.Highlighter; 27 | import javax.swing.text.Highlighter.Highlight; 28 | import javax.swing.text.JTextComponent; 29 | import javax.swing.text.Highlighter.HighlightPainter; 30 | 31 | public class JBootstrapTextFieldUI extends BasicTextFieldUI implements FocusListener 32 | { 33 | private final JTextField txt; 34 | 35 | public static ComponentUI createUI(JComponent c) 36 | { 37 | return new JBootstrapTextFieldUI((JTextField) c); 38 | } 39 | 40 | private JBootstrapTextFieldUI(JTextField t) 41 | { 42 | txt = t; 43 | } 44 | 45 | @Override 46 | protected void installDefaults() 47 | { 48 | super.installDefaults(); 49 | if (txt instanceof JBootstrapTextField) 50 | installMyDefaults(); 51 | } 52 | 53 | @Override 54 | protected void uninstallDefaults() 55 | { 56 | txt.setBorder(null); 57 | super.uninstallDefaults(); 58 | } 59 | 60 | @Override 61 | protected void installListeners() 62 | { 63 | super.installListeners(); 64 | txt.addFocusListener(this); 65 | } 66 | 67 | @Override 68 | protected void uninstallListeners() 69 | { 70 | txt.removeFocusListener(this); 71 | super.uninstallListeners(); 72 | } 73 | 74 | private void installMyDefaults() 75 | { 76 | txt.setBorder(new MyBorder()); 77 | txt.setHighlighter(new MyHl()); 78 | } 79 | 80 | private static class HL implements Highlight 81 | { 82 | int end; 83 | int start; 84 | HighlightPainter p; 85 | 86 | HL(int s, int e, HighlightPainter pp) 87 | { 88 | start = s; 89 | end = e; 90 | p = pp; 91 | } 92 | 93 | @Override 94 | public int getEndOffset() 95 | { 96 | return end; 97 | } 98 | 99 | @Override 100 | public HighlightPainter getPainter() 101 | { 102 | return p; 103 | } 104 | 105 | @Override 106 | public int getStartOffset() 107 | { 108 | return start; 109 | } 110 | 111 | @Override 112 | public boolean equals(Object obj) 113 | { 114 | if (!(obj instanceof HL)) 115 | return false; 116 | 117 | HL b = (HL) obj; 118 | 119 | return start == b.start && end == b.end && p.equals(b.p); 120 | } 121 | } 122 | 123 | static class MyHl implements Highlighter 124 | { 125 | private JTextComponent t; 126 | private final List hls = new ArrayList(1); 127 | private static final HighlightPainter hlp = new DefaultHighlighter.DefaultHighlightPainter(new Color(0xFF9238)); 128 | 129 | @Override 130 | public void install(JTextComponent c) 131 | { 132 | t = c; 133 | } 134 | 135 | @Override 136 | public Object addHighlight(final int p0, final int p1, final HighlightPainter p) 137 | throws BadLocationException 138 | { 139 | HL h = new HL(p0, p1, p); 140 | hls.add(h); 141 | t.repaint(); 142 | return h; 143 | } 144 | 145 | @Override 146 | public void paint(Graphics g) 147 | { 148 | if (hls.isEmpty()) 149 | return; 150 | 151 | Shape bounds = t.getBounds(); 152 | 153 | for (Highlight hl : hls) 154 | { 155 | hlp.paint(g, hl.getStartOffset(), hl.getEndOffset(), bounds, t); 156 | } 157 | } 158 | 159 | @Override 160 | public void changeHighlight(Object tag, int p0, int p1) 161 | throws BadLocationException 162 | { 163 | ((HL) tag).end = p1; 164 | ((HL) tag).start = p0; 165 | t.repaint(); 166 | } 167 | 168 | @Override 169 | public Highlight[] getHighlights() 170 | { 171 | return hls.toArray(new Highlight[hls.size()]); 172 | } 173 | 174 | @Override 175 | public void deinstall(JTextComponent c) { } 176 | 177 | @Override 178 | public void removeAllHighlights() 179 | { 180 | hls.clear(); 181 | t.repaint(); 182 | } 183 | 184 | @Override 185 | public void removeHighlight(Object tag) 186 | { 187 | hls.remove(tag); 188 | t.repaint(); 189 | } 190 | } 191 | 192 | private class MyBorder extends AbstractBorder 193 | { 194 | private static final long serialVersionUID = 1L; 195 | 196 | @Override 197 | public boolean isBorderOpaque() 198 | { 199 | return false; 200 | } 201 | 202 | @Override 203 | public Insets getBorderInsets(Component c) 204 | { 205 | return new Insets(8, 12, 8, 12); 206 | } 207 | 208 | @Override 209 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) 210 | { 211 | Graphics2D g2d = (Graphics2D) g.create(); 212 | 213 | g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 214 | 215 | drawRoundedBorder(g2d, 216 | x + 1, 217 | y + 1, 218 | width - 4, 219 | height - 4, 220 | ((JBootstrapTextField) txt).getType().clr, 221 | (int) (getCornerRadius() * (((JBootstrapTextField) txt).isSearch() ? 9 : 4)), 222 | txt.hasFocus(), ((JBootstrapTextField) txt).getType().box); 223 | 224 | g2d.dispose(); 225 | } 226 | } 227 | 228 | private static void drawRoundedBorder(Graphics2D g2, int x, int y, int w, int h, 229 | Color borderColor, int arc, boolean boxShadow, Color boxShadowColor) 230 | { 231 | if (boxShadow) 232 | { 233 | g2.setStroke(new BasicStroke(1.2f)); 234 | g2.setColor(boxShadowColor); 235 | g2.drawRoundRect(x + 3, y + 3, w - 6, h - 6, arc, arc); 236 | 237 | g2.setColor(new Color(boxShadowColor.getRed(), boxShadowColor.getGreen(), boxShadowColor.getBlue(), 80)); 238 | g2.drawRoundRect(x + 2, y + 2, w - 4, h - 4, arc, arc); 239 | 240 | g2.setColor(new Color(boxShadowColor.getRed(), boxShadowColor.getGreen(), boxShadowColor.getBlue(), 40)); 241 | g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, arc, arc); 242 | 243 | g2.setColor(new Color(boxShadowColor.getRed(), boxShadowColor.getGreen(), boxShadowColor.getBlue(), 20)); 244 | g2.drawRoundRect(x, y, w - 1, h - 1, arc, arc); 245 | } 246 | else 247 | { 248 | g2.setStroke(new BasicStroke(1.0f)); 249 | g2.setColor(borderColor); 250 | g2.drawRoundRect(x + 1, y + 1, w - 2, h - 2, arc, arc); 251 | } 252 | } 253 | 254 | @Override 255 | protected void paintBackground(Graphics g) 256 | { 257 | super.paintBackground(g); 258 | 259 | Insets s = txt.getInsets(); 260 | 261 | if (txt instanceof JBootstrapTextField && txt.getText().isEmpty() && !txt.hasFocus()) 262 | { 263 | JLabel lbl = new JLabel(" " + ((JBootstrapTextField) txt).getPlaceholder()); 264 | lbl.setFont(new Font(txt.getFont().getFontName(), Font.ITALIC, txt.getFont().getSize() - 1)); 265 | lbl.setForeground(Color.gray); 266 | lbl.setBackground(txt.getBackground()); 267 | 268 | SwingUtilities.paintComponent(g, lbl, txt, s.left, s.top, txt.getWidth() - s.left - s.right, txt.getHeight() - s.top - s.bottom); 269 | } 270 | } 271 | 272 | private float getCornerRadius() 273 | { 274 | return StyleUtil.getAdjustedSize(txt.getFont().getSize(), 2, 6, 1, false); 275 | } 276 | 277 | @Override 278 | public void focusGained(FocusEvent e) 279 | { 280 | txt.repaint(); 281 | } 282 | 283 | @Override 284 | public void focusLost(FocusEvent e) 285 | { 286 | txt.repaint(); 287 | } 288 | } 289 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/StyleButton.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Font; 4 | import java.awt.Color; 5 | import java.util.EnumSet; 6 | import java.util.HashMap; 7 | import java.util.Map; 8 | 9 | import javax.swing.plaf.ColorUIResource; 10 | import javax.swing.plaf.FontUIResource; 11 | 12 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleUtil.ComponentState; 13 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleUtil.StyleQuad; 14 | import com.github.danfickle.jbootstrap.jbootstraplplusf.StyleUtil.StyleSimpleGradient; 15 | 16 | class StyleButton 17 | { 18 | static class BtnBaseStyle 19 | { 20 | protected StyleSimpleGradient gradient; 21 | protected float borderArcSize; 22 | protected FontUIResource font; 23 | protected ColorUIResource textColor; 24 | protected StyleQuad borderColor; 25 | protected StyleQuad padding; 26 | protected StyleQuad margin; 27 | protected StyleQuad focusPadding; 28 | 29 | protected static final Color ALPHA1 = new Color(0, 0, 0, 0.1f); 30 | protected static final Color ALPHA2 = new Color(0, 0, 0, 0.25f); 31 | protected static final Color BOX_SHADOW_COLOR = new Color(1, 1, 1, 0.2f); 32 | protected static final Color DISABLED_COLOR = new Color(1, 1, 1, 0.35f); 33 | 34 | StyleSimpleGradient getGradient() 35 | { 36 | return this.gradient; 37 | } 38 | 39 | float getBorderArcSize() 40 | { 41 | return this.borderArcSize; 42 | } 43 | 44 | Font getFont() 45 | { 46 | return this.font; 47 | } 48 | 49 | Color getTextColor() 50 | { 51 | return this.textColor; 52 | } 53 | 54 | StyleQuad getBorderColor() 55 | { 56 | return this.borderColor; 57 | } 58 | 59 | StyleQuad getPadding() 60 | { 61 | return this.padding; 62 | } 63 | 64 | StyleQuad getMargin() 65 | { 66 | return this.margin; 67 | } 68 | 69 | StyleQuad getFocusPadding() 70 | { 71 | return this.focusPadding; 72 | } 73 | 74 | void applyTo(BtnBaseStyle btn) { }; 75 | } 76 | 77 | private static class BtnDefaultStyle extends BtnBaseStyle 78 | { 79 | private static final StyleSimpleGradient GRADIENT = 80 | new StyleSimpleGradient(Color.white, new ColorUIResource(0xE6, 0xE6, 0xE6)); 81 | 82 | private static final StyleQuad BORDER_COLOR = 83 | new StyleQuad(ALPHA1, new Color(0xB3, 0xB3, 0xB3), ALPHA2, ALPHA1); 84 | 85 | private static final StyleQuad PADDING = new StyleQuad(3, 5, 3, 5); 86 | 87 | private static final StyleQuad MARGIN = new StyleQuad(2, 2, 2, 2); 88 | 89 | private static final StyleQuad FOCUS_PADDING = new StyleQuad(3, 3, 3, 3); 90 | 91 | private static final ColorUIResource TEXT_COLOR = new ColorUIResource(0x33, 0x33, 0x33); 92 | 93 | private static final FontUIResource BTN_FONT = new FontUIResource(Font.SANS_SERIF, Font.PLAIN, StyleUtil.getComponentFontSize(12)); 94 | 95 | static void apply(BtnBaseStyle override) 96 | { 97 | override.gradient = GRADIENT; 98 | override.borderColor = BORDER_COLOR; 99 | override.textColor = TEXT_COLOR; 100 | override.padding = PADDING; 101 | override.margin = MARGIN; 102 | override.font = BTN_FONT; 103 | override.borderArcSize = 4.0f; 104 | override.focusPadding = FOCUS_PADDING; 105 | } 106 | 107 | static String appliesTo() 108 | { 109 | return "btn"; 110 | } 111 | 112 | @Override 113 | void applyTo(BtnBaseStyle btn) 114 | { 115 | apply(btn); 116 | } 117 | } 118 | 119 | private static class BtnPrimaryStyle extends BtnBaseStyle 120 | { 121 | private static final StyleSimpleGradient GRADIENT = 122 | new StyleSimpleGradient(new Color(0x00, 0x88, 0xCC), new Color(0x00, 0x44, 0xCC)); 123 | 124 | private static final StyleQuad BORDER_COLOR = 125 | new StyleQuad(ALPHA1, ALPHA1, ALPHA2, ALPHA1); 126 | 127 | static void apply(BtnBaseStyle override) 128 | { 129 | override.textColor = new ColorUIResource(Color.WHITE); 130 | override.gradient = GRADIENT; 131 | override.borderColor = BORDER_COLOR; 132 | } 133 | 134 | static String appliesTo() 135 | { 136 | return "btn-primary"; 137 | } 138 | 139 | @Override 140 | void applyTo(BtnBaseStyle btn) 141 | { 142 | apply(btn); 143 | } 144 | } 145 | 146 | private static class BtnInfoStyle extends BtnBaseStyle 147 | { 148 | private static final StyleSimpleGradient GRADIENT = 149 | new StyleSimpleGradient(new Color(0x5BC0DE), new Color(0x2F96B4)); 150 | 151 | private static final StyleQuad BORDER_COLOR = 152 | new StyleQuad(ALPHA1, ALPHA1, ALPHA2, ALPHA1); 153 | 154 | static void apply(BtnBaseStyle override) 155 | { 156 | override.textColor = new ColorUIResource(Color.WHITE); 157 | override.gradient = GRADIENT; 158 | override.borderColor = BORDER_COLOR; 159 | } 160 | 161 | static String appliesTo() 162 | { 163 | return "btn-info"; 164 | } 165 | 166 | @Override 167 | void applyTo(BtnBaseStyle btn) 168 | { 169 | apply(btn); 170 | } 171 | } 172 | 173 | private static class BtnSuccessStyle extends BtnBaseStyle 174 | { 175 | private static final StyleSimpleGradient GRADIENT = 176 | new StyleSimpleGradient(new Color(0x62C462), new Color(0x51A351)); 177 | 178 | private static final StyleQuad BORDER_COLOR = 179 | new StyleQuad(ALPHA1, ALPHA1, ALPHA2, ALPHA1); 180 | 181 | static void apply(BtnBaseStyle override) 182 | { 183 | override.textColor = new ColorUIResource(Color.WHITE); 184 | override.gradient = GRADIENT; 185 | override.borderColor = BORDER_COLOR; 186 | } 187 | 188 | static String appliesTo() 189 | { 190 | return "btn-success"; 191 | } 192 | 193 | @Override 194 | void applyTo(BtnBaseStyle btn) 195 | { 196 | apply(btn); 197 | } 198 | } 199 | 200 | private static class BtnWarningStyle extends BtnBaseStyle 201 | { 202 | private static final StyleSimpleGradient GRADIENT = 203 | new StyleSimpleGradient(new Color(0xFBB450), new Color(0xF89406)); 204 | 205 | private static final StyleQuad BORDER_COLOR = 206 | new StyleQuad(ALPHA1, ALPHA1, ALPHA2, ALPHA1); 207 | 208 | static void apply(BtnBaseStyle override) 209 | { 210 | override.textColor = new ColorUIResource(Color.WHITE); 211 | override.gradient = GRADIENT; 212 | override.borderColor = BORDER_COLOR; 213 | } 214 | 215 | static String appliesTo() 216 | { 217 | return "btn-warning"; 218 | } 219 | 220 | @Override 221 | void applyTo(BtnBaseStyle btn) 222 | { 223 | apply(btn); 224 | } 225 | } 226 | 227 | private static class BtnInverseStyle extends BtnBaseStyle 228 | { 229 | private static final StyleSimpleGradient GRADIENT = 230 | new StyleSimpleGradient(new Color(0x444444), new Color(0x222222)); 231 | 232 | private static final StyleQuad BORDER_COLOR = 233 | new StyleQuad(ALPHA1, ALPHA1, ALPHA2, ALPHA1); 234 | 235 | static void apply(BtnBaseStyle override) 236 | { 237 | override.textColor = new ColorUIResource(Color.WHITE); 238 | override.gradient = GRADIENT; 239 | override.borderColor = BORDER_COLOR; 240 | } 241 | 242 | static String appliesTo() 243 | { 244 | return "btn-inverse"; 245 | } 246 | 247 | @Override 248 | void applyTo(BtnBaseStyle btn) 249 | { 250 | apply(btn); 251 | } 252 | } 253 | private static class BtnDangerStyle extends BtnBaseStyle 254 | { 255 | private static final StyleSimpleGradient GRADIENT = 256 | new StyleSimpleGradient(new Color(0xEE5F5B), new Color(0xBD362F)); 257 | 258 | private static final StyleQuad BORDER_COLOR = 259 | new StyleQuad(ALPHA1, ALPHA1, ALPHA2, ALPHA1); 260 | 261 | static void apply(BtnBaseStyle override) 262 | { 263 | override.textColor = new ColorUIResource(Color.WHITE); 264 | override.gradient = GRADIENT; 265 | override.borderColor = BORDER_COLOR; 266 | } 267 | 268 | static String appliesTo() 269 | { 270 | return "btn-danger"; 271 | } 272 | 273 | @Override 274 | void applyTo(BtnBaseStyle btn) 275 | { 276 | apply(btn); 277 | } 278 | } 279 | 280 | private static class BtnDangerHoverStyle extends BtnBaseStyle 281 | { 282 | private static final StyleSimpleGradient GRADIENT = 283 | new StyleSimpleGradient(new Color(0xBD362F), null); 284 | 285 | void apply(BtnBaseStyle override) 286 | { 287 | override.gradient = GRADIENT; 288 | } 289 | 290 | static String appliesTo() 291 | { 292 | return "btn-danger:hover"; 293 | } 294 | 295 | @Override 296 | void applyTo(BtnBaseStyle btn) 297 | { 298 | apply(btn); 299 | } 300 | } 301 | 302 | private static class BtnDefaultHoverStyle extends BtnBaseStyle 303 | { 304 | private static final StyleSimpleGradient GRADIENT = 305 | new StyleSimpleGradient(new Color(0xE6E6E6), null); 306 | 307 | void apply(BtnBaseStyle override) 308 | { 309 | override.gradient = GRADIENT; 310 | } 311 | 312 | static String appliesTo() 313 | { 314 | return "btn:hover"; 315 | } 316 | 317 | @Override 318 | void applyTo(BtnBaseStyle btn) 319 | { 320 | apply(btn); 321 | } 322 | } 323 | 324 | private static class BtnInfoHoverStyle extends BtnBaseStyle 325 | { 326 | private static final StyleSimpleGradient GRADIENT = 327 | new StyleSimpleGradient(new Color(0x2F96B4), null); 328 | 329 | void apply(BtnBaseStyle override) 330 | { 331 | override.gradient = GRADIENT; 332 | } 333 | 334 | static String appliesTo() 335 | { 336 | return "btn-info:hover"; 337 | } 338 | 339 | @Override 340 | void applyTo(BtnBaseStyle btn) 341 | { 342 | apply(btn); 343 | } 344 | } 345 | 346 | private static class BtnSuccessHoverStyle extends BtnBaseStyle 347 | { 348 | private static final StyleSimpleGradient GRADIENT = 349 | new StyleSimpleGradient(new Color(0x51A351), null); 350 | 351 | void apply(BtnBaseStyle override) 352 | { 353 | override.gradient = GRADIENT; 354 | } 355 | 356 | static String appliesTo() 357 | { 358 | return "btn-success:hover"; 359 | } 360 | 361 | @Override 362 | void applyTo(BtnBaseStyle btn) 363 | { 364 | apply(btn); 365 | } 366 | } 367 | 368 | private static class BtnWarningHoverStyle extends BtnBaseStyle 369 | { 370 | private static final StyleSimpleGradient GRADIENT = 371 | new StyleSimpleGradient(new Color(0xF89406), null); 372 | 373 | void apply(BtnBaseStyle override) 374 | { 375 | override.gradient = GRADIENT; 376 | } 377 | 378 | static String appliesTo() 379 | { 380 | return "btn-warning:hover"; 381 | } 382 | 383 | @Override 384 | void applyTo(BtnBaseStyle btn) 385 | { 386 | apply(btn); 387 | } 388 | } 389 | 390 | private static class BtnInverseHoverStyle extends BtnBaseStyle 391 | { 392 | private static final StyleSimpleGradient GRADIENT = 393 | new StyleSimpleGradient(new Color(0x222222), null); 394 | 395 | void apply(BtnBaseStyle override) 396 | { 397 | override.gradient = GRADIENT; 398 | } 399 | 400 | static String appliesTo() 401 | { 402 | return "btn-inverse:hover"; 403 | } 404 | 405 | @Override 406 | void applyTo(BtnBaseStyle btn) 407 | { 408 | apply(btn); 409 | } 410 | } 411 | 412 | private static class BtnPrimaryHoverStyle extends BtnBaseStyle 413 | { 414 | private static final StyleSimpleGradient GRADIENT = 415 | new StyleSimpleGradient(new Color(0x0044CC), null); 416 | 417 | void apply(BtnBaseStyle override) 418 | { 419 | override.gradient = GRADIENT; 420 | } 421 | 422 | static String appliesTo() 423 | { 424 | return "btn-primary:hover"; 425 | } 426 | 427 | @Override 428 | void applyTo(BtnBaseStyle btn) 429 | { 430 | apply(btn); 431 | } 432 | } 433 | 434 | private static class BtnMiniStyle extends BtnBaseStyle 435 | { 436 | private static final StyleQuad PADDING = new StyleQuad(1, 1, 1, 1); 437 | private static final StyleQuad MARGIN = new StyleQuad(0, 0, 0, 0); 438 | private static final FontUIResource FONT = new FontUIResource(Font.SANS_SERIF, Font.PLAIN, StyleUtil.getComponentFontSize(9)); 439 | 440 | void apply(BtnBaseStyle override) 441 | { 442 | override.padding = PADDING; 443 | override.margin = MARGIN; 444 | override.font = FONT; 445 | } 446 | 447 | static String appliesTo() 448 | { 449 | return "btn-mini"; 450 | } 451 | 452 | @Override 453 | void applyTo(BtnBaseStyle btn) 454 | { 455 | apply(btn); 456 | } 457 | } 458 | 459 | private static class BtnSmallStyle extends BtnBaseStyle 460 | { 461 | private static final StyleQuad PADDING = new StyleQuad(1, 1, 1, 1); 462 | private static final StyleQuad MARGIN = new StyleQuad(1, 1, 1, 1); 463 | private static final FontUIResource FONT = new FontUIResource(Font.SANS_SERIF, Font.PLAIN, StyleUtil.getComponentFontSize(11)); 464 | 465 | void apply(BtnBaseStyle override) 466 | { 467 | override.padding = PADDING; 468 | override.margin = MARGIN; 469 | override.font = FONT; 470 | } 471 | 472 | static String appliesTo() 473 | { 474 | return "btn-small"; 475 | } 476 | 477 | @Override 478 | void applyTo(BtnBaseStyle btn) 479 | { 480 | apply(btn); 481 | } 482 | } 483 | 484 | private static class BtnLargeStyle extends BtnBaseStyle 485 | { 486 | private static final StyleQuad PADDING = new StyleQuad(5, 5, 5, 5); 487 | private static final StyleQuad MARGIN = new StyleQuad(3, 3, 3, 3); 488 | private static final FontUIResource FONT = new FontUIResource(Font.SANS_SERIF, Font.PLAIN, StyleUtil.getComponentFontSize(14)); 489 | 490 | void apply(BtnBaseStyle override) 491 | { 492 | override.padding = PADDING; 493 | override.margin = MARGIN; 494 | override.font = FONT; 495 | } 496 | 497 | static String appliesTo() 498 | { 499 | return "btn-large"; 500 | } 501 | 502 | @Override 503 | void applyTo(BtnBaseStyle btn) 504 | { 505 | apply(btn); 506 | } 507 | } 508 | 509 | private static Map styleMap = new HashMap(); 510 | 511 | static void registerStyles() 512 | { 513 | styleMap.clear(); 514 | styleMap.put(BtnDefaultStyle.appliesTo(), new BtnDefaultStyle()); 515 | styleMap.put(BtnPrimaryStyle.appliesTo(), new BtnPrimaryStyle()); 516 | styleMap.put(BtnInfoStyle.appliesTo(), new BtnInfoStyle()); 517 | styleMap.put(BtnWarningStyle.appliesTo(), new BtnWarningStyle()); 518 | styleMap.put(BtnSuccessStyle.appliesTo(), new BtnSuccessStyle()); 519 | styleMap.put(BtnInverseStyle.appliesTo(), new BtnInverseStyle()); 520 | styleMap.put(BtnDangerStyle.appliesTo(), new BtnDangerStyle()); 521 | 522 | styleMap.put(BtnDangerHoverStyle.appliesTo(), new BtnDangerHoverStyle()); 523 | styleMap.put(BtnPrimaryHoverStyle.appliesTo(), new BtnPrimaryHoverStyle()); 524 | styleMap.put(BtnInfoHoverStyle.appliesTo(), new BtnInfoHoverStyle()); 525 | styleMap.put(BtnSuccessHoverStyle.appliesTo(), new BtnSuccessHoverStyle()); 526 | styleMap.put(BtnInverseHoverStyle.appliesTo(), new BtnInverseHoverStyle()); 527 | styleMap.put(BtnWarningHoverStyle.appliesTo(), new BtnWarningHoverStyle()); 528 | styleMap.put(BtnDefaultHoverStyle.appliesTo(), new BtnDefaultHoverStyle()); 529 | 530 | styleMap.put(BtnMiniStyle.appliesTo(), new BtnMiniStyle()); 531 | styleMap.put(BtnSmallStyle.appliesTo(), new BtnSmallStyle()); 532 | styleMap.put(BtnLargeStyle.appliesTo(), new BtnLargeStyle()); 533 | } 534 | 535 | private static BtnBaseStyle getStyle(String clz) 536 | { 537 | return styleMap.get(clz); 538 | } 539 | 540 | static BtnBaseStyle applyStyles(String clss, EnumSet state) 541 | { 542 | String[] clsz = clss.split("\\s+"); 543 | 544 | BtnBaseStyle over = new BtnBaseStyle(); 545 | 546 | for (String clsItem : clsz) 547 | { 548 | BtnBaseStyle base = StyleButton.getStyle(clsItem); 549 | 550 | if (base != null) 551 | { 552 | base.applyTo(over); 553 | } 554 | } 555 | 556 | applyExtra(over, clss, state); 557 | 558 | return over; 559 | } 560 | 561 | static void applyExtra(BtnBaseStyle over, String clss, EnumSet state) 562 | { 563 | String[] split = clss.split("\\s+"); 564 | for (ComponentState st : state) 565 | { 566 | for (String cls : split) 567 | { 568 | BtnBaseStyle base = StyleButton.getStyle(cls + ':' + st.name); 569 | 570 | if (base != null) 571 | base.applyTo(over); 572 | } 573 | } 574 | } 575 | } 576 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/StyleLabel.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | import java.awt.Font; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import javax.swing.plaf.ColorUIResource; 9 | import javax.swing.plaf.FontUIResource; 10 | 11 | class StyleLabel 12 | { 13 | static class LabelBaseStyle 14 | { 15 | protected ColorUIResource backgroundColor; 16 | protected ColorUIResource textColor; 17 | protected FontUIResource font; 18 | protected float borderArcSize; 19 | 20 | Color getBackgroundColor() 21 | { 22 | return backgroundColor; 23 | } 24 | 25 | Color getTextColor() 26 | { 27 | return textColor; 28 | } 29 | 30 | Font getFont() 31 | { 32 | return font; 33 | } 34 | 35 | float getBorderArcSize() 36 | { 37 | return borderArcSize; 38 | } 39 | 40 | void applyTo(LabelBaseStyle btn) {} 41 | } 42 | 43 | static class LabelDefaultStyle extends LabelBaseStyle 44 | { 45 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x999999); 46 | private static ColorUIResource TEXT_COLOR = new ColorUIResource(Color.WHITE); 47 | private static FontUIResource FONT = new FontUIResource(Font.SANS_SERIF, Font.BOLD, StyleUtil.getComponentFontSize(9)); 48 | 49 | @Override 50 | void applyTo(LabelBaseStyle lbl) 51 | { 52 | lbl.backgroundColor = BACKGROUND_COLOR; 53 | lbl.textColor = TEXT_COLOR; 54 | lbl.font = FONT; 55 | lbl.borderArcSize = 3; 56 | } 57 | 58 | static String appliesTo() 59 | { 60 | return "label"; 61 | } 62 | } 63 | 64 | static class LabelInfoStyle extends LabelBaseStyle 65 | { 66 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x3A87AD); 67 | 68 | @Override 69 | void applyTo(LabelBaseStyle lbl) 70 | { 71 | lbl.backgroundColor = BACKGROUND_COLOR; 72 | } 73 | 74 | static String appliesTo() 75 | { 76 | return "label-info"; 77 | } 78 | } 79 | 80 | static class LabelWarningStyle extends LabelBaseStyle 81 | { 82 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0xF89406); 83 | 84 | @Override 85 | void applyTo(LabelBaseStyle lbl) 86 | { 87 | lbl.backgroundColor = BACKGROUND_COLOR; 88 | } 89 | 90 | static String appliesTo() 91 | { 92 | return "label-warning"; 93 | } 94 | } 95 | 96 | static class LabelImportantStyle extends LabelBaseStyle 97 | { 98 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0xB94A48); 99 | 100 | @Override 101 | void applyTo(LabelBaseStyle lbl) 102 | { 103 | lbl.backgroundColor = BACKGROUND_COLOR; 104 | } 105 | 106 | static String appliesTo() 107 | { 108 | return "label-important"; 109 | } 110 | } 111 | 112 | static class LabelInverseStyle extends LabelBaseStyle 113 | { 114 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x333333); 115 | 116 | @Override 117 | void applyTo(LabelBaseStyle lbl) 118 | { 119 | lbl.backgroundColor = BACKGROUND_COLOR; 120 | } 121 | 122 | static String appliesTo() 123 | { 124 | return "label-inverse"; 125 | } 126 | } 127 | 128 | static class LabelSuccessStyle extends LabelBaseStyle 129 | { 130 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x468847); 131 | 132 | @Override 133 | void applyTo(LabelBaseStyle lbl) 134 | { 135 | lbl.backgroundColor = BACKGROUND_COLOR; 136 | } 137 | 138 | static String appliesTo() 139 | { 140 | return "label-success"; 141 | } 142 | } 143 | 144 | static class BadgeDefaultStyle extends LabelBaseStyle 145 | { 146 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x999999); 147 | private static ColorUIResource TEXT_COLOR = new ColorUIResource(Color.WHITE); 148 | private static FontUIResource FONT = new FontUIResource(Font.SANS_SERIF, Font.BOLD, StyleUtil.getComponentFontSize(9)); 149 | 150 | @Override 151 | void applyTo(LabelBaseStyle lbl) 152 | { 153 | lbl.backgroundColor = BACKGROUND_COLOR; 154 | lbl.textColor = TEXT_COLOR; 155 | lbl.font = FONT; 156 | lbl.borderArcSize = 8; 157 | } 158 | 159 | static String appliesTo() 160 | { 161 | return "badge"; 162 | } 163 | } 164 | 165 | static class BadgeInfoStyle extends LabelBaseStyle 166 | { 167 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x3A87AD); 168 | 169 | @Override 170 | void applyTo(LabelBaseStyle lbl) 171 | { 172 | lbl.backgroundColor = BACKGROUND_COLOR; 173 | } 174 | 175 | static String appliesTo() 176 | { 177 | return "badge-info"; 178 | } 179 | } 180 | 181 | static class BadgeWarningStyle extends LabelBaseStyle 182 | { 183 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0xF89406); 184 | 185 | @Override 186 | void applyTo(LabelBaseStyle lbl) 187 | { 188 | lbl.backgroundColor = BACKGROUND_COLOR; 189 | } 190 | 191 | static String appliesTo() 192 | { 193 | return "badge-warning"; 194 | } 195 | } 196 | 197 | static class BadgeImportantStyle extends LabelBaseStyle 198 | { 199 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0xB94A48); 200 | 201 | @Override 202 | void applyTo(LabelBaseStyle lbl) 203 | { 204 | lbl.backgroundColor = BACKGROUND_COLOR; 205 | } 206 | 207 | static String appliesTo() 208 | { 209 | return "badge-important"; 210 | } 211 | } 212 | 213 | static class BadgeInverseStyle extends LabelBaseStyle 214 | { 215 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x333333); 216 | 217 | @Override 218 | void applyTo(LabelBaseStyle lbl) 219 | { 220 | lbl.backgroundColor = BACKGROUND_COLOR; 221 | } 222 | 223 | static String appliesTo() 224 | { 225 | return "badge-inverse"; 226 | } 227 | } 228 | 229 | static class BadgeSuccessStyle extends LabelBaseStyle 230 | { 231 | private static ColorUIResource BACKGROUND_COLOR = new ColorUIResource(0x468847); 232 | 233 | @Override 234 | void applyTo(LabelBaseStyle lbl) 235 | { 236 | lbl.backgroundColor = BACKGROUND_COLOR; 237 | } 238 | 239 | static String appliesTo() 240 | { 241 | return "badge-success"; 242 | } 243 | } 244 | 245 | 246 | private static Map styleMap = new HashMap(); 247 | 248 | static void registerStyles() 249 | { 250 | styleMap.clear(); 251 | styleMap.put(LabelDefaultStyle.appliesTo(), new LabelDefaultStyle()); 252 | styleMap.put(LabelInfoStyle.appliesTo(), new LabelInfoStyle()); 253 | styleMap.put(LabelSuccessStyle.appliesTo(), new LabelSuccessStyle()); 254 | styleMap.put(LabelWarningStyle.appliesTo(), new LabelWarningStyle()); 255 | styleMap.put(LabelImportantStyle.appliesTo(), new LabelImportantStyle()); 256 | styleMap.put(LabelInverseStyle.appliesTo(), new LabelInverseStyle()); 257 | 258 | styleMap.put(BadgeDefaultStyle.appliesTo(), new BadgeDefaultStyle()); 259 | styleMap.put(BadgeInfoStyle.appliesTo(), new BadgeInfoStyle()); 260 | styleMap.put(BadgeSuccessStyle.appliesTo(), new BadgeSuccessStyle()); 261 | styleMap.put(BadgeWarningStyle.appliesTo(), new BadgeWarningStyle()); 262 | styleMap.put(BadgeImportantStyle.appliesTo(), new BadgeImportantStyle()); 263 | styleMap.put(BadgeInverseStyle.appliesTo(), new BadgeInverseStyle()); 264 | } 265 | 266 | private static LabelBaseStyle getStyle(String clz) 267 | { 268 | return styleMap.get(clz); 269 | } 270 | 271 | static LabelBaseStyle applyStyles(String clss) 272 | { 273 | String[] clsz = clss.split("\\s+"); 274 | 275 | LabelBaseStyle over = new LabelBaseStyle(); 276 | 277 | for (String clsItem : clsz) 278 | { 279 | LabelBaseStyle base = getStyle(clsItem); 280 | 281 | if (base != null) 282 | { 283 | base.applyTo(over); 284 | } 285 | } 286 | 287 | return over; 288 | } 289 | } 290 | -------------------------------------------------------------------------------- /src/main/java/com/github/danfickle/jbootstrap/jbootstraplplusf/StyleUtil.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | import java.awt.Toolkit; 5 | 6 | class StyleUtil 7 | { 8 | enum ComponentState 9 | { 10 | HOVER("hover"), 11 | ACTIVE("active"), 12 | DISABLED("disabled"), 13 | FOCUSED("focus"); 14 | 15 | final String name; 16 | 17 | private ComponentState(String display) 18 | { 19 | this.name = display; 20 | } 21 | } 22 | 23 | 24 | static class StyleSimpleGradient 25 | { 26 | private final Color start; 27 | private final Color end; 28 | 29 | StyleSimpleGradient(Color start, Color end) 30 | { 31 | this.start = start; 32 | this.end = end; 33 | } 34 | 35 | Color getStart() 36 | { 37 | return this.start; 38 | } 39 | 40 | Color getEnd() 41 | { 42 | return this.end; 43 | } 44 | 45 | boolean isSolid() 46 | { 47 | return this.end == null || this.start.equals(this.end); 48 | } 49 | } 50 | 51 | static class StyleQuad 52 | { 53 | private final T top; 54 | private final T bottom; 55 | private final T left; 56 | private final T right; 57 | 58 | StyleQuad(T top, T right, T bottom, T left) 59 | { 60 | this.top = top; 61 | this.right = right; 62 | this.bottom = bottom; 63 | this.left = left; 64 | } 65 | 66 | T getTop() 67 | { 68 | return this.top; 69 | } 70 | 71 | T getRight() 72 | { 73 | return this.right; 74 | } 75 | 76 | T getBottom() 77 | { 78 | return this.bottom; 79 | } 80 | 81 | T getLeft() 82 | { 83 | return this.left; 84 | } 85 | } 86 | 87 | enum BorderSide 88 | { 89 | TOP, LEFT, RIGHT, BOTTOM; 90 | } 91 | 92 | static int getComponentFontSize(int ptSize) 93 | { 94 | // TODO: Headless. 95 | int screenRes = Toolkit.getDefaultToolkit().getScreenResolution(); 96 | int fontSize = (int) Math.round(ptSize * screenRes / 72.0); 97 | return fontSize; 98 | } 99 | 100 | /** 101 | * Gets the adjusted size. The basic functionality of this method is as 102 | * follows: 103 | * 104 | *
    105 | *
  • The baseSize parameter specifies the base value
  • 106 | *
  • The forEachBase and toAdjustBy specify how 107 | * to adjust the resulting value based on the passed fontSize.
  • 108 | *
109 | * 110 | * For example, if you want base value to be 1.2 pixels, and have it grow by 111 | * 0.1 pixel for every additional pixel in the font size, call this method 112 | * with the following values: 113 | * 114 | *
    115 | *
  • baseSize = 1.2
  • 116 | *
  • forEachBase = 1
  • 117 | *
  • toAdjustBy = 0.1
  • 118 | *
119 | * 120 | * @param fontSize 121 | * Font size. 122 | * @param baseSize 123 | * The base value. 124 | * @param forEachBase 125 | * Base units for computing the adjustment. 126 | * @param toAdjustBy 127 | * Adjustment amount for computing the adjustment. 128 | * @return Adjusted size. 129 | */ 130 | static float getAdjustedSize(int fontSize, float baseSize, int forEachBase, float toAdjustBy) 131 | { 132 | int delta = fontSize - 11; 133 | 134 | if (delta <= 0) 135 | return baseSize; 136 | 137 | return baseSize + delta * toAdjustBy / forEachBase; 138 | } 139 | 140 | /** 141 | * Gets the adjusted size. The basic functionality of this method is as 142 | * follows: 143 | * 144 | *
    145 | *
  • The baseSize parameter specifies the base value
  • 146 | *
  • The forEachBase and toAdjustBy specify how 147 | * to adjust the resulting value based on the passed fontSize.
  • 148 | *
149 | * 150 | * For example, if you want base value to be 4 pixels, and have it grow by 1 151 | * pixel for every 3 additional pixels in the font size, call this method 152 | * with the following values: 153 | * 154 | *
    155 | *
  • baseSize = 4
  • 156 | *
  • forEachBase = 3
  • 157 | *
  • toAdjustBy = 1
  • 158 | *
159 | * 160 | * @param fontSize 161 | * Font size. 162 | * @param baseSize 163 | * The base value. 164 | * @param forEachBase 165 | * Base units for computing the adjustment. 166 | * @param toAdjustBy 167 | * Adjustment amount for computing the adjustment. 168 | * @param toRoundAsEven 169 | * If true, the final value will be rounded down to 170 | * the closest even value. 171 | * @return Adjusted size. 172 | */ 173 | public static int getAdjustedSize(int fontSize, int baseSize, 174 | int forEachBase, int toAdjustBy, boolean toRoundAsEven) 175 | { 176 | int delta = fontSize - 11; 177 | 178 | if (delta <= 0) 179 | return baseSize; 180 | 181 | int result = baseSize + delta * toAdjustBy / forEachBase; 182 | 183 | if (toRoundAsEven && (result % 2 != 0)) 184 | result--; 185 | 186 | return result; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /src/main/resources/dialog-information.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/danfickle/java-bootstrap-laf/ec4f039cbeae791458f1790a0ef61351347980c2/src/main/resources/dialog-information.png -------------------------------------------------------------------------------- /src/test/java/com/github/danfickle/jbootstrap/jbootstraplplusf/ButtonTest.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | import java.awt.Dimension; 5 | import java.awt.FlowLayout; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | 9 | import javax.swing.ImageIcon; 10 | import javax.swing.JButton; 11 | import javax.swing.JFrame; 12 | import javax.swing.JPanel; 13 | import javax.swing.SwingUtilities; 14 | import javax.swing.UIManager; 15 | 16 | import com.github.danfickle.jbootstrap.jbootstraplplusf.JBootstrapFactory.JBootstrapButtonSize; 17 | import com.github.danfickle.jbootstrap.jbootstraplplusf.JBootstrapFactory.JBootstrapButtonType; 18 | 19 | public class ButtonTest 20 | { 21 | public static void main(String...strings) 22 | { 23 | JBootstrapLF lf = new JBootstrapLF(); 24 | 25 | UIManager.LookAndFeelInfo lfInfo = new UIManager.LookAndFeelInfo(lf.getName(), lf.getClass().getName()); 26 | UIManager.installLookAndFeel(lfInfo); 27 | try { 28 | UIManager.setLookAndFeel(lf.getClass().getCanonicalName()); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | 33 | SwingUtilities.invokeLater( new Runnable() { 34 | 35 | @Override 36 | public void run() { 37 | JPanel comp = new JPanel(new FlowLayout()); 38 | comp.setPreferredSize(new Dimension(500, 400)); 39 | comp.setBackground(Color.white); 40 | 41 | JButton btn = JBootstrapFactory.createButton("btn", JBootstrapButtonType.DEFAULT, JBootstrapButtonSize.DEFAULT); 42 | comp.add(btn); 43 | 44 | btn = JBootstrapFactory.createButton("btn btn-primary", JBootstrapButtonType.PRIMARY, JBootstrapButtonSize.DEFAULT); 45 | comp.add(btn); 46 | 47 | btn = JBootstrapFactory.createButton("btn btn-warning", JBootstrapButtonType.WARNING, JBootstrapButtonSize.DEFAULT); 48 | comp.add(btn); 49 | 50 | btn = JBootstrapFactory.createButton("btn btn-danger", JBootstrapButtonType.DANGER, JBootstrapButtonSize.DEFAULT); 51 | comp.add(btn); 52 | 53 | btn = JBootstrapFactory.createButton("btn btn-info", JBootstrapButtonType.INFO, JBootstrapButtonSize.DEFAULT); 54 | comp.add(btn); 55 | 56 | btn = JBootstrapFactory.createButton("btn btn-inverse", JBootstrapButtonType.INVERSE, JBootstrapButtonSize.DEFAULT); 57 | comp.add(btn); 58 | 59 | btn = JBootstrapFactory.createButton("btn btn-success", JBootstrapButtonType.SUCCESS, JBootstrapButtonSize.DEFAULT); 60 | comp.add(btn); 61 | 62 | btn = JBootstrapFactory.createButton("btn btn-primary btn-mini", JBootstrapButtonType.PRIMARY, JBootstrapButtonSize.MINI); 63 | comp.add(btn); 64 | 65 | btn = JBootstrapFactory.createButton("btn btn-primary btn-small", JBootstrapButtonType.PRIMARY, JBootstrapButtonSize.SMALL); 66 | comp.add(btn); 67 | 68 | btn = JBootstrapFactory.createButton("btn btn-primary btn-default (disabled)", JBootstrapButtonType.PRIMARY, JBootstrapButtonSize.DEFAULT); 69 | btn.setEnabled(false); 70 | comp.add(btn); 71 | 72 | btn = JBootstrapFactory.createButton("btn btn-primary btn-large", JBootstrapButtonType.PRIMARY, JBootstrapButtonSize.LARGE); 73 | comp.add(btn); 74 | 75 | btn = JBootstrapFactory.createButton("btn btn-success btn-large (with icon)", JBootstrapButtonType.SUCCESS, JBootstrapButtonSize.LARGE); 76 | btn.setIcon(new ImageIcon(getClass().getResource("/dialog-information.png"))); 77 | 78 | btn.getModel().addActionListener(new ActionListener() 79 | { 80 | @Override 81 | public void actionPerformed(ActionEvent arg0) 82 | { 83 | System.out.println("button works"); 84 | } 85 | }); 86 | 87 | comp.add(btn); 88 | 89 | btn = new JButton("plain button"); 90 | comp.add(btn); 91 | 92 | JFrame frame = new JFrame("Test"); 93 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 94 | frame.getContentPane().add(comp); 95 | frame.pack(); 96 | frame.setVisible(true); 97 | } 98 | } ); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/test/java/com/github/danfickle/jbootstrap/jbootstraplplusf/LabelTest.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | import java.awt.Dimension; 5 | import java.awt.FlowLayout; 6 | 7 | import javax.swing.ImageIcon; 8 | import javax.swing.JFrame; 9 | import javax.swing.JLabel; 10 | import javax.swing.JPanel; 11 | import javax.swing.SwingUtilities; 12 | import javax.swing.UIManager; 13 | 14 | import com.github.danfickle.jbootstrap.jbootstraplplusf.JBootstrapFactory.JBootstrapBadgeType; 15 | import com.github.danfickle.jbootstrap.jbootstraplplusf.JBootstrapFactory.JBootstrapLabelType; 16 | import com.github.danfickle.jbootstrap.jbootstraplplusf.JBootstrapFactory.JBootstrapTextType; 17 | 18 | public class LabelTest 19 | { 20 | public static void main(String...strings) 21 | { 22 | JBootstrapLF lf = new JBootstrapLF(); 23 | 24 | UIManager.LookAndFeelInfo lfInfo = new UIManager.LookAndFeelInfo(lf.getName(), lf.getClass().getName()); 25 | UIManager.installLookAndFeel(lfInfo); 26 | try { 27 | UIManager.setLookAndFeel(lf.getClass().getCanonicalName()); 28 | } catch (Exception e) { 29 | e.printStackTrace(); 30 | } 31 | 32 | SwingUtilities.invokeLater( new Runnable() { 33 | 34 | @Override 35 | public void run() { 36 | JPanel comp = new JPanel(new FlowLayout()); 37 | comp.setPreferredSize(new Dimension(500, 400)); 38 | comp.setBackground(Color.white); 39 | 40 | JLabel lbl = JBootstrapFactory.createLabel("label", JBootstrapLabelType.DEFAULT); 41 | comp.add(lbl); 42 | 43 | lbl = JBootstrapFactory.createLabel("label label-info", JBootstrapLabelType.INFO); 44 | comp.add(lbl); 45 | 46 | lbl = JBootstrapFactory.createLabel("label label-success", JBootstrapLabelType.SUCCESS); 47 | comp.add(lbl); 48 | 49 | lbl = JBootstrapFactory.createLabel("label label-warning", JBootstrapLabelType.WARNING); 50 | comp.add(lbl); 51 | 52 | lbl = JBootstrapFactory.createLabel("label label-important", JBootstrapLabelType.IMPORTANT); 53 | comp.add(lbl); 54 | 55 | lbl = JBootstrapFactory.createLabel("label label-inverse", JBootstrapLabelType.INVERSE); 56 | comp.add(lbl); 57 | 58 | lbl = JBootstrapFactory.createBadge("badge badge-info", JBootstrapBadgeType.INFO); 59 | comp.add(lbl); 60 | 61 | lbl = JBootstrapFactory.createBadge("badge badge-success", JBootstrapBadgeType.SUCCESS); 62 | comp.add(lbl); 63 | 64 | lbl = JBootstrapFactory.createBadge("badge badge-warning", JBootstrapBadgeType.WARNING); 65 | comp.add(lbl); 66 | 67 | lbl = JBootstrapFactory.createBadge("badge badge-inverse", JBootstrapBadgeType.INVERSE); 68 | comp.add(lbl); 69 | 70 | lbl = JBootstrapFactory.createBadge("badge badge-important", JBootstrapBadgeType.IMPORTANT); 71 | comp.add(lbl); 72 | 73 | lbl = JBootstrapFactory.createBadge("badge (with icon)", JBootstrapBadgeType.DEFAULT); 74 | lbl.setIcon(new ImageIcon(getClass().getResource("/dialog-information.png"))); 75 | comp.add(lbl); 76 | 77 | lbl = new JLabel("plain label"); 78 | comp.add(lbl); 79 | 80 | lbl = JBootstrapFactory.createText("default", JBootstrapTextType.DEFAULT); 81 | comp.add(lbl); 82 | 83 | lbl = JBootstrapFactory.createText("info", JBootstrapTextType.INFO); 84 | comp.add(lbl); 85 | 86 | lbl = JBootstrapFactory.createText("warning", JBootstrapTextType.WARNING); 87 | comp.add(lbl); 88 | 89 | lbl = JBootstrapFactory.createText("error", JBootstrapTextType.ERROR); 90 | comp.add(lbl); 91 | 92 | lbl = JBootstrapFactory.createWrappedText("This is some really long text " + 93 | "This is some really long text " + 94 | "This is some really long text " + 95 | "This is some really long text " + 96 | "This is some really long text " + 97 | "This is some really long text " + 98 | "This is some really long text " + 99 | "This is some really long text " + 100 | "This is some really long text ", JBootstrapTextType.SUCCESS, 450); 101 | comp.add(lbl); 102 | 103 | JFrame frame = new JFrame("Test"); 104 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 105 | frame.getContentPane().add(comp); 106 | frame.pack(); 107 | frame.setVisible(true); 108 | } 109 | } ); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/test/java/com/github/danfickle/jbootstrap/jbootstraplplusf/TextFieldTest.java: -------------------------------------------------------------------------------- 1 | package com.github.danfickle.jbootstrap.jbootstraplplusf; 2 | 3 | import java.awt.Color; 4 | import java.awt.Dimension; 5 | import java.awt.FlowLayout; 6 | 7 | import javax.swing.JFrame; 8 | import javax.swing.JPanel; 9 | import javax.swing.JPasswordField; 10 | import javax.swing.JTextField; 11 | import javax.swing.SwingUtilities; 12 | import javax.swing.UIManager; 13 | 14 | import com.github.danfickle.jbootstrap.jbootstraplplusf.JBootstrapTextField.JBootstrapTextFieldType; 15 | 16 | public class TextFieldTest 17 | { 18 | public static void main(String...strings) 19 | { 20 | JBootstrapLF lf = new JBootstrapLF(); 21 | 22 | UIManager.LookAndFeelInfo lfInfo = new UIManager.LookAndFeelInfo(lf.getName(), lf.getClass().getName()); 23 | UIManager.installLookAndFeel(lfInfo); 24 | try { 25 | UIManager.setLookAndFeel(lf.getClass().getCanonicalName()); 26 | } catch (Exception e) { 27 | e.printStackTrace(); 28 | } 29 | 30 | SwingUtilities.invokeLater( new Runnable() { 31 | 32 | @Override 33 | public void run() { 34 | JPanel comp = new JPanel(new FlowLayout()); 35 | comp.setPreferredSize(new Dimension(500, 400)); 36 | comp.setBackground(Color.white); 37 | 38 | JBootstrapTextField txt = JBootstrapFactory.createTextField(15, "default", JBootstrapTextFieldType.DEFAULT); 39 | txt.setText("default text"); 40 | comp.add(txt); 41 | 42 | txt = JBootstrapFactory.createTextField(15, "danger", JBootstrapTextFieldType.DANGER); 43 | comp.add(txt); 44 | 45 | txt = JBootstrapFactory.createTextField(15, "warning", JBootstrapTextFieldType.WARNING); 46 | comp.add(txt); 47 | 48 | txt = JBootstrapFactory.createTextField(15, "info", JBootstrapTextFieldType.INFO); 49 | comp.add(txt); 50 | 51 | txt = JBootstrapFactory.createTextField(15, "success search", JBootstrapTextFieldType.SUCCESS); 52 | txt.setSearch(true); 53 | comp.add(txt); 54 | 55 | JTextField txt2 = new JTextField(10); 56 | txt2.setText("plain"); 57 | comp.add(txt2); 58 | 59 | JPasswordField psw = new JPasswordField(10); 60 | comp.add(psw); 61 | 62 | JFrame frame = new JFrame("Test"); 63 | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 64 | frame.getContentPane().add(comp); 65 | frame.pack(); 66 | frame.setVisible(true); 67 | } 68 | } ); 69 | } 70 | } 71 | --------------------------------------------------------------------------------