Merge pull request #993 from SiboVG/issue-989
[fixes #989 & #992] Fix 3D view going blank + high CPU usage
This commit is contained in:
commit
4d8e4be604
@ -5,38 +5,49 @@ import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public class SelectColorButton extends JButton {
|
||||
public SelectColorButton() {
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorButton(Icon icon) {
|
||||
super(icon);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorButton(String text) {
|
||||
super(text);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorButton(Action a) {
|
||||
super(a);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorButton(String text, Icon icon) {
|
||||
super(text, icon);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (getModel().isArmed()) {
|
||||
setForeground(UIManager.getColor("Button.selectForeground"));
|
||||
}
|
||||
else {
|
||||
setForeground(UIManager.getColor("Button.foreground"));
|
||||
}
|
||||
super.paint(g);
|
||||
private void addChangeListenerSelectColor() {
|
||||
if (UIManager.getColor("Button.selectForeground") == null
|
||||
|| UIManager.getColor("Button.foreground") == null)
|
||||
return;
|
||||
addChangeListener(new ChangeListener() {
|
||||
@Override
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
if (getModel().isArmed()) {
|
||||
setForeground(UIManager.getColor("Button.selectForeground"));
|
||||
}
|
||||
else {
|
||||
setForeground(UIManager.getColor("Button.foreground"));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,8 @@ import javax.swing.JToggleButton;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.UIManager;
|
||||
import java.awt.Graphics;
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
|
||||
/**
|
||||
* This class is a replacement for the standard JToggleButton. Its purpose is to be able
|
||||
@ -15,43 +16,78 @@ import java.awt.Graphics;
|
||||
public class SelectColorToggleButton extends JToggleButton {
|
||||
public SelectColorToggleButton(Action a) {
|
||||
super(a);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorToggleButton(String text) {
|
||||
super(text);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorToggleButton() {
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorToggleButton(Icon icon) {
|
||||
super(icon);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorToggleButton(Icon icon, boolean selected) {
|
||||
super(icon, selected);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorToggleButton(String text, boolean selected) {
|
||||
super(text, selected);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorToggleButton(String text, Icon icon) {
|
||||
super(text, icon);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
public SelectColorToggleButton(String text, Icon icon, boolean selected) {
|
||||
super(text, icon, selected);
|
||||
addChangeListenerSelectColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
if (isSelected()) {
|
||||
setForeground(UIManager.getColor("ToggleButton.selectForeground"));
|
||||
}
|
||||
else {
|
||||
setForeground(UIManager.getColor("ToggleButton.foreground"));
|
||||
}
|
||||
super.paint(g);
|
||||
/**
|
||||
* This method sets the foreground color of the button. If the button is selected, then the selectForeground is used.
|
||||
* If the frame that the button is in goes out of focus or if the button is unselected, then the foreground is used.
|
||||
*
|
||||
* This is to fix an issue on OSX devices where the foreground color would be black on blue (hardly readable)
|
||||
*/
|
||||
private void addChangeListenerSelectColor() {
|
||||
if (UIManager.getColor("ToggleButton.selectForeground") == null
|
||||
|| UIManager.getColor("ToggleButton.foreground") == null)
|
||||
return;
|
||||
|
||||
// Case: frame goes out of focus
|
||||
addPropertyChangeListener("Frame.active", new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (isSelected() && (boolean)evt.getNewValue()) {
|
||||
setForeground(UIManager.getColor("ToggleButton.selectForeground"));
|
||||
}
|
||||
else {
|
||||
setForeground(UIManager.getColor("ToggleButton.foreground"));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Case: button is clicked
|
||||
addPropertyChangeListener("ancestor", new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if (isSelected()) {
|
||||
setForeground(UIManager.getColor("ToggleButton.selectForeground"));
|
||||
}
|
||||
else {
|
||||
setForeground(UIManager.getColor("ToggleButton.foreground"));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user