Skip to content

Commit d561b70

Browse files
convert GradientToolbar to Java, removing Xtend dependencies
1 parent a05f01c commit d561b70

File tree

1 file changed

+53
-63
lines changed

1 file changed

+53
-63
lines changed
Lines changed: 53 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Copyright 2019 Philipp Salvisberg <philipp.salvisberg@trivadis.com>
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,81 +15,71 @@
1515
*/
1616
package org.utplsql.sqldev.ui.runner;
1717

18-
import com.google.common.base.Objects;
1918
import java.awt.Color;
2019
import java.awt.GradientPaint;
2120
import java.awt.Graphics;
2221
import java.awt.Graphics2D;
2322
import java.awt.Insets;
23+
2424
import javax.swing.JToolBar;
2525
import javax.swing.LookAndFeel;
2626
import javax.swing.UIManager;
2727
import javax.swing.border.BevelBorder;
2828
import javax.swing.border.EmptyBorder;
2929

30-
@SuppressWarnings("all")
3130
public class GradientToolbar extends JToolBar {
32-
private boolean isOracleLookAndFeel() {
33-
LookAndFeel _lookAndFeel = UIManager.getLookAndFeel();
34-
String _name = null;
35-
if (_lookAndFeel!=null) {
36-
_name=_lookAndFeel.getName();
37-
}
38-
final String laf = _name;
39-
boolean _equals = Objects.equal(laf, "Oracle Look and Feel version 2");
40-
if (_equals) {
41-
return true;
42-
} else {
43-
return false;
31+
private static final long serialVersionUID = 6128707792081725058L;
32+
33+
private boolean isOracleLookAndFeel() {
34+
LookAndFeel laf = UIManager.getLookAndFeel();
35+
final String lafName = laf != null ? laf.getName() : null;
36+
return "Oracle Look and Feel version 2".equals(lafName);
4437
}
45-
}
46-
47-
public GradientToolbar() {
48-
super();
49-
boolean _isOracleLookAndFeel = this.isOracleLookAndFeel();
50-
if (_isOracleLookAndFeel) {
51-
Insets _insets = new Insets(2, 2, 2, 2);
52-
EmptyBorder _emptyBorder = new EmptyBorder(_insets);
53-
this.setBorder(_emptyBorder);
54-
} else {
55-
BevelBorder _bevelBorder = new BevelBorder(BevelBorder.RAISED);
56-
this.setBorder(_bevelBorder);
38+
39+
public GradientToolbar() {
40+
super();
41+
if (isOracleLookAndFeel()) {
42+
setBorder(new EmptyBorder(new Insets(2, 2, 2, 2))); // insets: top, left, bottom, right
43+
} else {
44+
setBorder(new BevelBorder(BevelBorder.RAISED));
45+
}
5746
}
58-
}
59-
60-
@Override
61-
public void paintComponent(final Graphics g) {
62-
boolean _isOracleLookAndFeel = this.isOracleLookAndFeel();
63-
if (_isOracleLookAndFeel) {
64-
boolean _isOpaque = this.isOpaque();
65-
boolean _not = (!_isOpaque);
66-
if (_not) {
67-
super.paintComponent(g);
68-
return;
69-
}
70-
final Graphics2D g2d = ((Graphics2D) g);
71-
final int w = this.getWidth();
72-
int _height = this.getHeight();
73-
final int h = (_height - 1);
74-
int _height_1 = this.getHeight();
75-
final int h2 = (_height_1 / 2);
76-
final Color colorTop = new Color(237, 237, 237);
77-
final Color colorMiddle = new Color(244, 244, 244);
78-
final Color colorBottom = new Color(254, 254, 254);
79-
final Color colorBottomLine = Color.LIGHT_GRAY;
80-
final GradientPaint gp1 = new GradientPaint(0, 0, colorTop, 0, h2, colorMiddle);
81-
g2d.setPaint(gp1);
82-
g2d.fillRect(0, 0, w, h2);
83-
final GradientPaint gp2 = new GradientPaint(0, h2, colorMiddle, 0, h, colorBottom);
84-
g2d.setPaint(gp2);
85-
g2d.fillRect(0, h2, w, h);
86-
g2d.setPaint(colorBottomLine);
87-
g2d.fillRect(0, h, w, (h + 1));
88-
this.setOpaque(false);
89-
super.paintComponent(g);
90-
this.setOpaque(true);
91-
} else {
92-
super.paintComponent(g);
47+
48+
@Override
49+
public void paintComponent(final Graphics g) {
50+
if (isOracleLookAndFeel()) {
51+
// emulate Oracle toolbar
52+
// 1. default for non-opaque components
53+
if (!isOpaque()) {
54+
super.paintComponent(g);
55+
return;
56+
}
57+
58+
// 2. paint gradient background from top to bottom with separator line at the bottom
59+
final Graphics2D g2d = ((Graphics2D) g);
60+
final int w = getWidth();
61+
final int h = (getHeight() - 1);
62+
final int h2 = (getHeight() / 2);
63+
final Color colorTop = new Color(237, 237, 237);
64+
final Color colorMiddle = new Color(244, 244, 244);
65+
final Color colorBottom = new Color(254, 254, 254);
66+
final Color colorBottomLine = Color.LIGHT_GRAY;
67+
final GradientPaint gp1 = new GradientPaint(0, 0, colorTop, 0, h2, colorMiddle);
68+
g2d.setPaint(gp1);
69+
g2d.fillRect(0, 0, w, h2);
70+
final GradientPaint gp2 = new GradientPaint(0, h2, colorMiddle, 0, h, colorBottom);
71+
g2d.setPaint(gp2);
72+
g2d.fillRect(0, h2, w, h);
73+
g2d.setPaint(colorBottomLine);
74+
g2d.fillRect(0, h, w, (h + 1));
75+
76+
// 3. do rest, changing opaque to ensure background is not overwritten
77+
setOpaque(false);
78+
super.paintComponent(g);
79+
setOpaque(true);
80+
} else {
81+
// default logic
82+
super.paintComponent(g);
83+
}
9384
}
94-
}
9585
}

0 commit comments

Comments
 (0)