Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NomadGUI
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Instrument Control
NomadGUI
Commits
8f6da0a9
Commit
8f6da0a9
authored
5 months ago
by
helene ortiz
Browse files
Options
Downloads
Patches
Plain Diff
test dpi
parent
c82e5807
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/fr/ill/ics/client/view/test/TestDPI.java
+124
-0
124 additions, 0 deletions
src/main/java/fr/ill/ics/client/view/test/TestDPI.java
with
124 additions
and
0 deletions
src/main/java/fr/ill/ics/client/view/test/TestDPI.java
0 → 100644
+
124
−
0
View file @
8f6da0a9
package
fr.ill.ics.client.view.test
;
import
org.eclipse.swt.SWT
;
import
org.eclipse.swt.graphics.GC
;
import
org.eclipse.swt.graphics.Point
;
import
org.eclipse.swt.layout.FillLayout
;
import
org.eclipse.swt.layout.GridData
;
import
org.eclipse.swt.layout.GridLayout
;
import
org.eclipse.swt.widgets.Composite
;
import
org.eclipse.swt.widgets.Control
;
import
org.eclipse.swt.widgets.Display
;
import
org.eclipse.swt.widgets.Label
;
import
org.eclipse.swt.widgets.Shell
;
import
org.eclipse.swt.widgets.Text
;
import
fr.ill.ics.client.view.factory.swt.SWTFontFactory
;
public
class
TestDPI
{
private
Display
display
;
public
static
void
main
(
String
[]
args
)
{
TestDPI
moi
=
new
TestDPI
();
moi
.
run
();
}
private
void
run
()
{
display
=
new
Display
();
final
Shell
shell
=
new
Shell
(
display
,
SWT
.
SHELL_TRIM
);
shell
.
setLayout
(
new
FillLayout
());
final
Composite
composite
=
new
Composite
(
shell
,
SWT
.
BORDER
);
composite
.
setLayout
(
new
GridLayout
(
2
,
false
));
Label
label
=
new
Label
(
composite
,
SWT
.
NONE
);
SWTFontFactory
.
getInstance
().
init
(
display
);
label
.
setFont
(
SWTFontFactory
.
getStandardFont
());
label
.
setText
(
"Label"
);
label
.
setLayoutData
(
getSizedGridData
(
label
,
10
,
false
,
"Label"
));
label
.
setBackground
(
display
.
getSystemColor
(
SWT
.
COLOR_CYAN
));
Text
text
=
new
Text
(
composite
,
SWT
.
NONE
);
text
.
setFont
(
SWTFontFactory
.
getStandardFont
());
text
.
setText
(
"Text"
);
text
.
setTextLimit
(
10
);
//text.setLayoutData(getSizedGridData(label, 10, false, "Text"));
text
.
setBackground
(
display
.
getSystemColor
(
SWT
.
COLOR_CYAN
));
System
.
out
.
println
(
getSizedGridData
(
text
,
10
,
false
,
"Text"
).
widthHint
);
System
.
out
.
println
(
getGridData
(
text
,
10
).
widthHint
);
text
.
setLayoutData
(
getGridData
(
text
,
10
));
// shell.pack();
shell
.
setSize
(
200
,
200
);
shell
.
open
();
while
(!
shell
.
isDisposed
())
{
if
(!
display
.
readAndDispatch
())
display
.
sleep
();
}
display
.
dispose
();
}
public
GridData
getSizedGridData
(
Control
control
,
int
maxLength
,
boolean
isNumeric
,
String
who
)
{
GridData
gridData
=
new
GridData
();
gridData
.
grabExcessVerticalSpace
=
true
;
gridData
.
verticalAlignment
=
GridData
.
CENTER
;
GC
gc
=
new
GC
(
display
);
gc
.
setFont
(
control
.
getFont
());
// H.ORTIZ: "h" replaced by "X" (for some strings "h" was not large enough...)
/* Extent for all letters (lower and upper cases):
i j l 3
f r t 4
s z 5
a b c d e g h k n o p q u v x y 6
w 8
m 10
I J 3
E F L P S T Y 6
A B C K N R U V X Z 7
D G H O Q 8
M 9
W 10
*/
Point
extent
=
gc
.
textExtent
(
"H"
);
System
.
out
.
println
(
"Width for "
+
who
+
" = "
+
extent
.
x
)
;
// H.ORTIZ: Not longer used: generates problem for property with large content (see for example table_step from startmono controller)
// Avoid to have Text too large by limitating width to 400 pixels
//gridData.widthHint = Math.min(maxLength * extent.x, TEXT_MAX_WIDTH);
gridData
.
widthHint
=
maxLength
*
extent
.
x
;
gc
.
dispose
();
return
gridData
;
}
private
GridData
getGridData
(
Control
control
,
int
maxLength
)
{
GC
gc
=
new
GC
(
control
);
Point
dpi
=
display
.
getDPI
();
int
extentX
=
gc
.
textExtent
(
"H"
).
x
*
maxLength
;
int
textWidth
=
extentX
*
dpi
.
x
/
79
;
gc
.
dispose
();
GridData
gridData
=
new
GridData
();
gridData
.
grabExcessVerticalSpace
=
true
;
gridData
.
verticalAlignment
=
GridData
.
CENTER
;
gridData
.
widthHint
=
textWidth
;
return
gridData
;
// Définir la largeur du champ texte
//textField.setSize(textWidth + 20, textField.getSize().y); // +20 pour une marge
}
}
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