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.PropertyChangeEvent;
import java.beans.PropertyChangeListener; import java.beans.PropertyChangeListener;
import java.util.Collection; import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.stream.Stream;
import javax.swing.BorderFactory; import javax.swing.BorderFactory;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException; import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.FontUIResource;
import org.netbeans.spi.sendopts.OptionProcessor; import org.netbeans.spi.sendopts.OptionProcessor;
import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI; import org.netbeans.swing.tabcontrol.plaf.DefaultTabbedContainerUI;
import org.openide.modules.ModuleInstall; import org.openide.modules.ModuleInstall;
@ -52,6 +55,40 @@ public class Installer extends ModuleInstall {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(Installer.class.getName()); private static final Logger logger = Logger.getLogger(Installer.class.getName());
private static Installer instance; 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() { public synchronized static Installer getDefault() {
if (null == instance) { if (null == instance) {
@ -129,6 +166,11 @@ public class Installer extends ModuleInstall {
UIManager.put("OptionPane.questionIcon", questionIcon); UIManager.put("OptionPane.questionIcon", questionIcon);
UIManager.put("OptionPane.informationIcon", informationIcon); 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 if (System.getProperty("os.name").toLowerCase().contains("mac")) { //NON-NLS
setUnixLookAndFeel(); setUnixLookAndFeel();
setModuleSettings("false"); setModuleSettings("false");

View File

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