Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Scale Bar
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Project 'bia/scale-bar' was moved to 'bia/icy/extensions/scale-bar'. Please update any links and bookmarks that may still have the old path.
Show more breadcrumbs
Bioimage Analysis
Icy
Extensions
Scale Bar
Compare revisions
92bb720400dc59bc54a1282de6b687b41cf23b9e to 35c22ca31e8cb655cf0ee1554befdb0ff2cc0813
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
bia/icy/extensions/scale-bar
Select target project
No results found
35c22ca31e8cb655cf0ee1554befdb0ff2cc0813
Select Git revision
Branches
icy-3.0.0
master
Tags
v3.3.1
v4.0.0-a.1
v4.0.0-a.2
Swap
Target
bia/icy/extensions/scale-bar
Select target project
bia/icy/extensions/scale-bar
1 result
92bb720400dc59bc54a1282de6b687b41cf23b9e
Select Git revision
Branches
icy-3.0.0
master
Tags
v3.3.1
v4.0.0-a.1
v4.0.0-a.2
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (2)
Better position logic, fixed text shadow and position on zoomed image display
· 4f8c8444
Stéphane DALLONGEVILLE
authored
2 years ago
4f8c8444
updated version
· 35c22ca3
Stéphane DALLONGEVILLE
authored
2 years ago
35c22ca3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pom.xml
+1
-1
1 addition, 1 deletion
pom.xml
src/main/java/plugins/tprovoost/scale/ScaleBarOverlay.java
+53
-30
53 additions, 30 deletions
src/main/java/plugins/tprovoost/scale/ScaleBarOverlay.java
with
54 additions
and
31 deletions
pom.xml
View file @
35c22ca3
...
...
@@ -11,7 +11,7 @@
<!-- Project Information -->
<artifactId>
scale-bar
</artifactId>
<version>
3.3.
0
</version>
<version>
3.3.
1
</version>
<packaging>
jar
</packaging>
...
...
This diff is collapsed.
Click to expand it.
src/main/java/plugins/tprovoost/scale/ScaleBarOverlay.java
View file @
35c22ca3
...
...
@@ -7,7 +7,6 @@ import java.awt.Graphics2D;
import
java.awt.GridBagConstraints
;
import
java.awt.GridBagLayout
;
import
java.awt.Insets
;
import
java.awt.Rectangle
;
import
java.awt.RenderingHints
;
import
java.awt.geom.Line2D
;
import
java.awt.geom.Rectangle2D
;
...
...
@@ -21,6 +20,7 @@ import icy.math.MathUtil;
import
icy.math.UnitUtil
;
import
icy.math.UnitUtil.UnitPrefix
;
import
icy.painter.Overlay
;
import
icy.preferences.GeneralPreferences
;
import
icy.preferences.XMLPreferences
;
import
icy.sequence.Sequence
;
import
icy.system.thread.ThreadUtil
;
...
...
@@ -274,12 +274,12 @@ public class ScaleBarOverlay extends Overlay
else
if
(
g
==
null
||
!(
canvas
instanceof
IcyCanvas2D
))
return
;
final
IcyCanvas2D
c2
=
(
IcyCanvas2D
)
canvas
;
final
Graphics2D
g2
=
(
Graphics2D
)
g
.
create
();
final
IcyCanvas2D
canvas2d
=
(
IcyCanvas2D
)
canvas
;
if
(
autoSize
.
getValue
())
{
int
sizeW
=
Math
.
min
(
c
2
.
getCanvasSizeX
()
/
4
,
Math
.
max
(
c
2
.
getCanvasSizeX
()
/
7
,
120
));
int
sizeW
=
Math
.
min
(
c
anvas
.
getCanvasSizeX
()
/
4
,
Math
.
max
(
c
anvas
.
getCanvasSizeX
()
/
7
,
120
));
// sequence.getSizeX() / 7;
// don't draw a scale bar larger than the image itself
...
...
@@ -298,30 +298,32 @@ public class ScaleBarOverlay extends Overlay
String
text
=
size
.
getValue
()
+
" "
+
unit
.
getValue
();
double
length
=
UnitUtil
.
getValueInUnit
(
size
.
getValue
(),
unit
.
getValue
().
asUnitPrefix
(),
UnitPrefix
.
MICRO
)
/
sequence
.
getPixelSizeX
();
float
finalThickness
=
this
.
thickness
.
getValue
().
floatValue
();
double
borderDist
=
20
;
double
sizeX
,
sizeY
;
final
double
unit
;
final
double
sizeX
,
sizeY
;
// image relative
if
(
location
.
getValue
().
isRelativeToImage
())
{
// adjust thickness
finalThickness
=
(
float
)
c2
.
canvasToImageLogDeltaX
((
int
)
finalThickness
);
borderDist
=
canvas
.
canvasToImageDeltaX
((
int
)
borderDist
);
unit
=
canvas
.
canvasToImageDeltaX
(
1
);
sizeX
=
canvas
.
getImageSizeX
();
sizeY
=
canvas
.
getImageSizeY
();
}
// viewer relative
else
{
// adjust length
length
=
canvas
.
imageToCanvasDeltaX
(
length
);
unit
=
1
d
;
sizeX
=
canvas
.
getCanvasSizeX
();
sizeY
=
canvas
.
getCanvasSizeY
();
// adjust length
length
=
canvas
.
imageToCanvasDeltaX
(
length
);
// need to reserve transform
g2
.
transform
(
c
2
.
getInverseTransform
());
g2
.
transform
(
c
anvas2d
.
getInverseTransform
());
}
final
float
finalThickness
=
(
float
)
(
thickness
.
getValue
().
doubleValue
()
*
unit
);
final
float
fontSize
=
(
float
)
((
GeneralPreferences
.
getGuiFontSize
()
+
2
)
*
unit
);
final
double
borderDist
=
20
d
*
unit
;
// prepare rendering
g2
.
setRenderingHint
(
RenderingHints
.
KEY_RENDERING
,
RenderingHints
.
VALUE_RENDER_QUALITY
);
g2
.
setStroke
(
new
BasicStroke
(
finalThickness
,
BasicStroke
.
CAP_BUTT
,
BasicStroke
.
JOIN_MITER
));
...
...
@@ -332,7 +334,7 @@ public class ScaleBarOverlay extends Overlay
if
(
showText
.
getValue
())
{
// set graphics font
g2
.
setFont
(
g2
.
getFont
().
deriveFont
(
Font
.
BOLD
,
(
finalThickness
*
3
)
));
g2
.
setFont
(
g2
.
getFont
().
deriveFont
(
Font
.
BOLD
,
fontSize
));
// get text bounds
textBnds
=
GraphicsUtil
.
getStringBounds
(
g2
,
text
);
}
...
...
@@ -343,28 +345,28 @@ public class ScaleBarOverlay extends Overlay
case
IMAGE_BOTTOM_LEFT:
line
.
x1
=
borderDist
;
line
.
x2
=
line
.
x1
+
length
;
line
.
y1
=
sizeY
-
(
textBnds
.
getHeight
()
+
(
borderDist
/
4
));
line
.
y1
=
sizeY
-
(
textBnds
.
getHeight
()
+
(
borderDist
/
2
d
));
break
;
case
VIEWER_BOTTOM_RIGHT:
case
IMAGE_BOTTOM_RIGHT:
line
.
x1
=
sizeX
-
borderDist
;
line
.
x2
=
line
.
x1
-
length
;
line
.
y1
=
sizeY
-
(
textBnds
.
getHeight
()
+
(
borderDist
/
4
));
line
.
y1
=
sizeY
-
(
textBnds
.
getHeight
()
+
(
borderDist
/
2
d
));
break
;
case
VIEWER_TOP_LEFT:
case
IMAGE_TOP_LEFT:
line
.
x1
=
borderDist
;
line
.
x2
=
line
.
x1
+
length
;
line
.
y1
=
borderDist
;
line
.
y1
=
borderDist
/
2
d
;
break
;
case
VIEWER_TOP_RIGHT:
case
IMAGE_TOP_RIGHT:
line
.
x1
=
sizeX
-
borderDist
;
line
.
x2
=
line
.
x1
-
length
;
line
.
y1
=
borderDist
;
line
.
y1
=
borderDist
/
2
d
;
break
;
}
...
...
@@ -379,12 +381,12 @@ public class ScaleBarOverlay extends Overlay
g2
.
setColor
(
Color
.
white
);
// base bounds
final
Rectangle
rect
=
line
.
getBounds
();
final
Rectangle
2D
rect
=
line
.
getBounds
2D
();
// give margins
ShapeUtil
.
enlarge
(
rect
,
8
,
8
,
true
);
ShapeUtil
.
enlarge
(
rect
,
8
d
*
unit
,
8
d
*
unit
,
true
);
// draw text ? enlarge using text bounds
if
(
showText
.
getValue
().
booleanValue
())
rect
.
h
eight
+
=
textBnds
.
getHeight
();
rect
.
setRect
(
rect
.
getX
(),
rect
.
getY
(),
rect
.
getWidth
(),
rect
.
getH
eight
()
+
textBnds
.
getHeight
()
)
;
g2
.
fill
(
rect
);
}
...
...
@@ -396,15 +398,15 @@ public class ScaleBarOverlay extends Overlay
else
g2
.
setColor
(
Color
.
lightGray
);
line
.
x1
+=
1
;
line
.
y1
+=
1
;
line
.
x2
+=
1
;
line
.
y2
+=
1
;
line
.
x1
+=
unit
;
line
.
y1
+=
unit
;
line
.
x2
+=
unit
;
line
.
y2
+=
unit
;
g2
.
draw
(
line
);
line
.
x1
-=
1
;
line
.
y1
-=
1
;
line
.
x2
-=
1
;
line
.
y2
-=
1
;
line
.
x1
-=
unit
;
line
.
y1
-=
unit
;
line
.
x2
-=
unit
;
line
.
y2
-=
unit
;
}
// draw scale bar line
...
...
@@ -413,8 +415,29 @@ public class ScaleBarOverlay extends Overlay
// draw text
if
(
showText
.
getValue
().
booleanValue
())
GraphicsUtil
.
drawHCenteredString
(
g2
,
text
,
(
int
)
line
.
getBounds
().
getCenterX
(),
(
int
)
(
line
.
getBounds
().
getCenterY
()
+
4
),
!
opaque
.
getValue
().
booleanValue
());
{
float
baseX
=
(
float
)
line
.
getBounds
().
getCenterX
();
float
baseY
=
(
float
)
(
line
.
getBounds
().
getCenterY
()
+
(
unit
*
4
d
));
final
float
x
=
(
float
)
(
baseX
-
(
textBnds
.
getWidth
()
/
2
d
));
final
float
y
=
(
float
)
(
baseY
-
textBnds
.
getY
());
// need to draw text shadow first
if
(!
opaque
.
getValue
().
booleanValue
())
{
if
(
ColorUtil
.
getLuminance
(
color
.
getValue
())
>
128
)
g2
.
setColor
(
Color
.
darkGray
);
else
g2
.
setColor
(
Color
.
lightGray
);
// draw text in shadow
g2
.
drawString
(
text
,
(
float
)
(
x
+
unit
),
(
float
)
(
y
+
unit
));
// restore color
g2
.
setColor
(
color
.
getValue
());
}
// draw text
g2
.
drawString
(
text
,
x
,
y
);
}
g2
.
dispose
();
}
...
...
This diff is collapsed.
Click to expand it.