swing look and feel fix to be made more like jdk 8 for formatting concerns; image gallery infinite render fix

This commit is contained in:
Greg DiCristofaro 2022-11-17 10:06:00 -05:00
parent 0f6cefbcb5
commit c8e9febdb4
2 changed files with 72 additions and 25 deletions

View File

@ -23,16 +23,19 @@ import java.awt.Insets;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import java.util.logging.Level;
import java.util.stream.Stream;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.FontUIResource;
import org.netbeans.spi.sendopts.OptionProcessor;
import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;
import org.openide.modules.ModuleInstall;
@ -52,6 +55,40 @@ public class Installer extends ModuleInstall {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(Installer.class.getName());
private static Installer instance;
// taken from https://stackoverflow.com/questions/7434845/setting-the-default-font-of-swing-program
private static final String[] SWING_FONT_ITEMS = {"Button.font",
"ToggleButton.font",
"RadioButton.font",
"CheckBox.font",
"ColorChooser.font",
"ComboBox.font",
"Label.font",
"List.font",
"MenuBar.font",
"MenuItem.font",
"RadioButtonMenuItem.font",
"CheckBoxMenuItem.font",
"Menu.font",
"PopupMenu.font",
"OptionPane.font",
"Panel.font",
"ProgressBar.font",
"ScrollPane.font",
"Viewport.font",
"TabbedPane.font",
"Table.font",
"TableHeader.font",
"TextField.font",
"PasswordField.font",
"TextArea.font",
"TextPane.font",
"EditorPane.font",
"TitledBorder.font",
"ToolBar.font",
"ToolTip.font",
"Tree.font"};
private static final FontUIResource DEFAULT_FONT = new FontUIResource("Tahoma", Font.PLAIN, 12);
public synchronized static Installer getDefault() {
if (null == instance) {
@ -128,7 +165,12 @@ public class Installer extends ModuleInstall {
UIManager.put("OptionPane.warningIcon", warningIcon);
UIManager.put("OptionPane.questionIcon", questionIcon);
UIManager.put("OptionPane.informationIcon", informationIcon);
// set default font for all font items
for (String fontKey : SWING_FONT_ITEMS) {
UIManager.put(fontKey, DEFAULT_FONT);
}
if (System.getProperty("os.name").toLowerCase().contains("mac")) { //NON-NLS
setUnixLookAndFeel();
setModuleSettings("false");

View File

@ -48,6 +48,7 @@ import javafx.beans.property.ReadOnlyObjectWrapper;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
@ -241,6 +242,8 @@ public class GroupPane extends BorderPane {
*/
@ThreadConfined(type = ThreadType.JFX)
private final Map<Long, DrawableCell> cellMap = new HashMap<>();
private final InvalidationListener filesSyncListener = (observable) -> {
final String header = getHeaderString();
@ -594,10 +597,7 @@ public class GroupPane extends BorderPane {
slideShowToggle.setDisable(true);
groupLabel.setText("");
resetScrollBar();
if (false == Case.isCaseOpen()) {
cellMap.values().stream().forEach(DrawableCell::resetItem);
cellMap.clear();
}
cellMap.clear();
});
} else {
@ -659,41 +659,46 @@ public class GroupPane extends BorderPane {
}
}
private class DrawableCell extends GridCell<Long> {
private class DrawableCell extends GridCell<Long> implements AutoCloseable {
private final DrawableTile tile = new DrawableTile(GroupPane.this, controller);
protected final ChangeListener<Long> changeListener = (ObservableValue<? extends Long> observable, Long oldValue, Long newValue) -> {
if ((oldValue == null && newValue == null) || (oldValue != null && newValue != null && oldValue.equals(newValue))) {
// if no change, do nothing
return;
}
DrawableCell oldValueCell = oldValue == null ? null : cellMap.remove(oldValue);
if (oldValueCell != null) {
// remove change listener to get garbage collected
oldValueCell.itemProperty().removeListener(oldValueCell.changeListener);
}
if (newValue != null) {
cellMap.put(newValue, DrawableCell.this);
}
};
/**
* This stores the last non-null file id. So that only new file ids for
* this item are tracked. This prevents an infinite render loop. See
* https://github.com/controlsfx/controlsfx/issues/1241 for more
* information
*/
private Long oldItem = null;
DrawableCell() {
itemProperty().addListener(changeListener);
setGraphic(tile);
}
@Override
protected void updateItem(Long item, boolean empty) {
super.updateItem(item, empty);
tile.setFile(item);
if (item != null && oldItem != item) {
tile.setFile(item);
}
if (item != null) {
cellMap.put(item, this);
oldItem = item;
} else if (oldItem != null) {
cellMap.remove(oldItem);
}
}
void resetItem() {
tile.setFile(null);
}
@Override
public void close() throws Exception {
resetItem();
}
}
/**