Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BigDataViewer_Core_Extension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioinformaticDataCompression
BigDataViewer_Core_Extension
Commits
791f824f
Commit
791f824f
authored
Sep 23, 2019
by
Tobias Pietzsch
Browse files
Options
Downloads
Patches
Plain Diff
Improve BrightnessDialog.ColorIcon and move to separate class
parent
af3a19e2
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/bdv/tools/brightness/BrightnessDialog.java
+13
-59
13 additions, 59 deletions
src/main/java/bdv/tools/brightness/BrightnessDialog.java
src/main/java/bdv/tools/brightness/ColorIcon.java
+99
-0
99 additions, 0 deletions
src/main/java/bdv/tools/brightness/ColorIcon.java
with
112 additions
and
59 deletions
src/main/java/bdv/tools/brightness/BrightnessDialog.java
+
13
−
59
View file @
791f824f
...
...
@@ -31,13 +31,9 @@ package bdv.tools.brightness;
import
java.awt.BorderLayout
;
import
java.awt.Color
;
import
java.awt.Component
;
import
java.awt.Container
;
import
java.awt.Dimension
;
import
java.awt.Frame
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.RenderingHints
;
import
java.awt.Window
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
...
...
@@ -52,7 +48,6 @@ import javax.swing.Action;
import
javax.swing.ActionMap
;
import
javax.swing.BorderFactory
;
import
javax.swing.BoxLayout
;
import
javax.swing.Icon
;
import
javax.swing.InputMap
;
import
javax.swing.JButton
;
import
javax.swing.JCheckBox
;
...
...
@@ -131,42 +126,6 @@ public class BrightnessDialog extends JDialog
setDefaultCloseOperation
(
WindowConstants
.
HIDE_ON_CLOSE
);
}
/**
* Adapted from http://stackoverflow.com/a/3072979/230513
*/
private
static
class
ColorIcon
implements
Icon
{
private
final
int
size
=
16
;
private
final
Color
color
;
public
ColorIcon
(
final
Color
color
)
{
this
.
color
=
color
;
}
@Override
public
void
paintIcon
(
final
Component
c
,
final
Graphics
g
,
final
int
x
,
final
int
y
)
{
final
Graphics2D
g2d
=
(
Graphics2D
)
g
;
g2d
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
g2d
.
setColor
(
color
);
g2d
.
fillOval
(
x
,
y
,
size
,
size
);
}
@Override
public
int
getIconWidth
()
{
return
size
;
}
@Override
public
int
getIconHeight
()
{
return
size
;
}
}
public
static
class
ColorsPanel
extends
JPanel
{
private
final
SetupAssignments
setupAssignments
;
...
...
@@ -196,11 +155,7 @@ public class BrightnessDialog extends JDialog
for
(
final
ConverterSetup
setup
:
setupAssignments
.
getConverterSetups
()
)
{
final
JButton
button
=
new
JButton
(
new
ColorIcon
(
getColor
(
setup
)
)
);
button
.
addActionListener
(
new
ActionListener
()
{
@Override
public
void
actionPerformed
(
final
ActionEvent
e
)
{
button
.
addActionListener
(
e
->
{
colorChooser
.
setColor
(
getColor
(
setup
)
);
final
JDialog
d
=
JColorChooser
.
createDialog
(
button
,
"Choose a color"
,
true
,
colorChooser
,
new
ActionListener
()
{
...
...
@@ -216,7 +171,6 @@ public class BrightnessDialog extends JDialog
}
},
null
);
d
.
setVisible
(
true
);
}
}
);
button
.
setEnabled
(
setup
.
supportsColor
()
);
buttons
.
add
(
button
);
...
...
@@ -237,7 +191,7 @@ public class BrightnessDialog extends JDialog
return
new
Color
(
value
);
}
else
return
n
ew
Color
(
0xFFBBBBBB
)
;
return
n
ull
;
}
private
static
void
setColor
(
final
ConverterSetup
setup
,
final
Color
color
)
...
...
This diff is collapsed.
Click to expand it.
src/main/java/bdv/tools/brightness/ColorIcon.java
0 → 100644
+
99
−
0
View file @
791f824f
package
bdv.tools.brightness
;
import
java.awt.Color
;
import
java.awt.Component
;
import
java.awt.Graphics
;
import
java.awt.Graphics2D
;
import
java.awt.RenderingHints
;
import
javax.swing.Icon
;
/**
* Adapted from http://stackoverflow.com/a/3072979/230513
*/
public
class
ColorIcon
implements
Icon
{
private
final
int
width
;
private
final
int
height
;
private
final
boolean
drawAsCircle
;
private
final
int
arcWidth
;
private
final
int
arcHeight
;
private
final
Color
color
;
private
final
int
size
;
// == min(width, height)
private
int
ox
;
private
int
oy
;
public
ColorIcon
(
final
Color
color
)
{
this
(
color
,
16
,
16
,
true
);
}
public
ColorIcon
(
final
Color
color
,
final
int
width
,
final
int
height
,
final
boolean
drawAsCircle
)
{
this
(
color
,
width
,
height
,
drawAsCircle
,
3
,
3
);
}
public
ColorIcon
(
final
Color
color
,
final
int
width
,
final
int
height
,
final
int
arcWidth
,
final
int
arcHeight
)
{
this
(
color
,
width
,
height
,
false
,
arcWidth
,
arcHeight
);
}
private
ColorIcon
(
final
Color
color
,
final
int
width
,
final
int
height
,
final
boolean
drawAsCircle
,
final
int
arcWidth
,
final
int
arcHeight
)
{
this
.
color
=
color
;
this
.
width
=
width
;
this
.
height
=
height
;
this
.
drawAsCircle
=
drawAsCircle
;
this
.
arcWidth
=
arcWidth
;
this
.
arcHeight
=
arcHeight
;
size
=
Math
.
min
(
width
,
height
);
ox
=
(
width
-
size
)
/
2
;
oy
=
(
height
-
size
)
/
2
;
}
@Override
public
void
paintIcon
(
final
Component
c
,
final
Graphics
g
,
final
int
x
,
final
int
y
)
{
final
Graphics2D
g2d
=
(
Graphics2D
)
g
;
g2d
.
setRenderingHint
(
RenderingHints
.
KEY_ANTIALIASING
,
RenderingHints
.
VALUE_ANTIALIAS_ON
);
final
int
x0
=
x
+
ox
;
final
int
y0
=
y
+
oy
;
if
(
color
==
null
)
{
g2d
.
setColor
(
new
Color
(
0xffbcbc
)
);
g2d
.
fillArc
(
x0
,
y0
,
size
,
size
,
0
,
120
);
g2d
.
setColor
(
new
Color
(
0xbcffbc
)
);
g2d
.
fillArc
(
x0
,
y0
,
size
,
size
,
120
,
120
);
g2d
.
setColor
(
new
Color
(
0xbcbcff
)
);
g2d
.
fillArc
(
x0
,
y0
,
size
,
size
,
240
,
120
);
}
else
{
g2d
.
setColor
(
color
);
if
(
drawAsCircle
)
g2d
.
fillOval
(
x0
,
y0
,
size
,
size
);
else
g2d
.
fillRoundRect
(
x
,
y
,
width
,
height
,
arcWidth
,
arcHeight
);
}
}
@Override
public
int
getIconWidth
()
{
return
width
;
}
@Override
public
int
getIconHeight
()
{
return
height
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment