-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NETBEANS-3592] Workarounds for JDK Windows LAF bugs on HiDPI screens #1777
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 0 additions & 135 deletions
135
platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/windows8/DPISafeBorder.java
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
platform/o.n.swing.plaf/src/org/netbeans/swing/plaf/windows8/DPIUnscaledBorder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.netbeans.swing.plaf.windows8; | ||
|
||
import java.awt.Component; | ||
import java.awt.Graphics; | ||
import java.awt.Graphics2D; | ||
import java.awt.Insets; | ||
import java.awt.geom.AffineTransform; | ||
import javax.swing.border.Border; | ||
import javax.swing.plaf.UIResource; | ||
|
||
// Must implement UIResource to work with JSpinner. | ||
/** | ||
* A delegating border which disregards border thickness DPI scaling for painting purposes. For | ||
* example, a border with a logical width of one pixel will be painted as one device pixel thick, | ||
* even on 200% DPI scaling. This is the behavior seen, for instance, in native text components on | ||
* Windows 10. This also avoids visual artifacts from rounding errors under non-integral DPI scaling | ||
* factors (e.g. 150%). | ||
* | ||
* <p>Insets reported by {@link #getBorderInsets(Component)} will still reflect the originally | ||
* specified values. | ||
*/ | ||
final class DPIUnscaledBorder implements Border, UIResource { | ||
private final Border delegate; | ||
|
||
public DPIUnscaledBorder(Border delegate) { | ||
if (delegate == null) { | ||
throw new NullPointerException(); | ||
} | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public void paintBorder(Component c, Graphics g0, int x, int y, int width, int height) { | ||
final Graphics2D g = (Graphics2D) g0; | ||
final AffineTransform oldTransform = g.getTransform(); | ||
g.translate(x, y); | ||
final AffineTransform tx = g.getTransform(); | ||
final int txType = tx.getType(); | ||
/* On fractional DPI scaling factors, such as 150%, a logical pixel position, e.g. (5,0), | ||
may end up being translated to a non-integral device pixel position, e.g. (7.5, 0). The same | ||
goes for border thicknesses, which are specified in logical pixels. In this method, we do | ||
all calculations and painting in device pixels, to avoid rounding errors causing visible | ||
artifacts. On screens without HiDPI scaling, logical pixel values and device pixel values | ||
are identical, and always integral (whole number) values. */ | ||
final int deviceWidth; | ||
final int deviceHeight; | ||
if (txType == AffineTransform.TYPE_UNIFORM_SCALE || | ||
txType == (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) | ||
{ | ||
// HiDPI scaling is active. | ||
double scale = tx.getScaleX(); | ||
/* To be completely safe from overpainting the previous adjacent component, we would | ||
probably need to round up here. But for borders to work properly on JTextField, we | ||
must round down. And it seems to work fine in the | ||
EDITOR_TAB_CONTENT_BORDER/VIEW_TAB_CONTENT_BORDER cases as well. */ | ||
int deviceX = (int) tx.getTranslateX(); | ||
int deviceY = (int) tx.getTranslateY(); | ||
/* Rounding down here should guarantee that we do not paint in an area that will be | ||
painted over by the next adjacent component. Rounding up, or to the nearest integer, | ||
is confirmed to cause problems. */ | ||
int deviceXend = (int) (tx.getTranslateX() + width * scale); | ||
int deviceYend = (int) (tx.getTranslateY() + height * scale); | ||
deviceWidth = deviceXend - deviceX; | ||
deviceHeight = deviceYend - deviceY; | ||
/* Deactivate the HiDPI scaling transform so we can do paint operations in the device | ||
pixel coordinate system instead of in the logical coordinate system. */ | ||
g.setTransform(new AffineTransform(1, 0, 0, 1, deviceX, deviceY)); | ||
} else { | ||
deviceWidth = width; | ||
deviceHeight = height; | ||
} | ||
delegate.paintBorder(c, g, 0, 0, deviceWidth, deviceHeight); | ||
g.setTransform(oldTransform); | ||
} | ||
|
||
@Override | ||
public Insets getBorderInsets(Component c) { | ||
return delegate.getBorderInsets(c); | ||
} | ||
|
||
@Override | ||
public boolean isBorderOpaque() { | ||
/* Since we do not widen borders under DPI scaling, we may not always fill in the entire | ||
designated logical area. */ | ||
return false; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Should add
// NOI18N
s to strings of the other files that are not expected translation as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.