diff options
Diffstat (limited to 'dozentenmodul/src')
12 files changed, 90 insertions, 165 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java index 9d385555..a3f09c0a 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/App.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/App.java @@ -1,22 +1,14 @@ package org.openslx.dozmod; -import java.awt.AWTEvent; -import java.awt.Font; -import java.awt.Toolkit; -import java.awt.event.AWTEventListener; -import java.awt.event.ContainerEvent; import java.io.File; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; -import java.util.HashSet; import java.util.Locale; -import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.zip.Deflater; import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; import javax.swing.UIManager; import org.apache.logging.log4j.Level; @@ -209,9 +201,6 @@ public class App { System.setProperty("awt.useSystemAAFontSettings", "on"); System.setProperty("swing.aatext", "true"); - // Adjust font size - adjustFontSize(Config.getFontScaling()); - // Set up connection to master server final String host; int port; @@ -306,74 +295,6 @@ public class App { } } - private static void adjustFontSize(int percent) { - if (percent == 100 || percent <= 0 || percent > 1000) - return; - final float scaling = 0.01f * (float) percent; - int size = determineDefaultFontSize(UIManager.getLookAndFeelDefaults()); - if (size == -1) { - size = determineDefaultFontSize(UIManager.getDefaults()); - } - if (size == -1) { - size = 12; - } - final float defaultSize = size; - Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { - @Override - public void eventDispatched(AWTEvent event) { - if (event instanceof ContainerEvent) { - ContainerEvent containerEvent = (ContainerEvent) event; - if (containerEvent.getID() == ContainerEvent.COMPONENT_ADDED) { - Font font = containerEvent.getChild().getFont(); - // Do not update font in tables and ComboBoxes on every renderer call to prevent weirdness. - // This prevents multiple instances of fonts being scaled multiple times. - if (containerEvent.getChild().getName() != null && - (containerEvent.getChild().getName().toLowerCase().contains("render") || - (containerEvent.getChild().getName().toLowerCase().contains("combo")))){ - return; - } - if (font != null && font.getSize2D() <= defaultSize) { - containerEvent.getChild().setFont( - new Font(font.getName(), font.getStyle(), Math.round(font.getSize2D() - * scaling))); - } - } - } - } - }, AWTEvent.COMPONENT_EVENT_MASK | AWTEvent.CONTAINER_EVENT_MASK); - Font tbFont = UIManager.getFont("TitledBorder.font"); - if (tbFont != null) { - UIManager.put("TitledBorder.font", tbFont.deriveFont(tbFont.getSize2D() * scaling)); - } - } - - private static int determineDefaultFontSize(UIDefaults defaults) { - if (defaults == null) - return -1; - int sizes[] = new int[100]; - Set<Object> keys = new HashSet<>(defaults.keySet()); - for (Object key : keys) { - if (key == null) - continue; - Object value = defaults.get(key); - if (value == null) - continue; - if (value instanceof Font) { - Font font = (Font) value; - if (font.getSize() > 0 && font.getSize() < sizes.length) { - sizes[font.getSize()]++; - } - } - } - int best = -1; - for (int index = 0; index < sizes.length; ++index) { - if (best == -1 || sizes[best] < sizes[index]) { - best = index; - } - } - return sizes[best]; - } - /** * Blocks as long as initialization is still going on. Currently this is * just the proxy setup, so this should be used before any network diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java index 4fa43a51..a3998e35 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/Config.java @@ -35,12 +35,6 @@ public class Config { } /** - * Constants for font scaling boundaries - */ - public static final int FONT_SCALING_MIN = 100; - public static final int FONT_SCALING_MAX = 300; - - /** * Out property holder with all the setting keys */ private static final Properties prop = new Properties(); @@ -381,32 +375,6 @@ public class Config { } /** - * Sets the scaling for font rendering (in percent, 100% = no scaling) - * - * @param percent to set the font scaling to - */ - public static void setFontScaling(int percent) { - setInteger("gui.fontscaling", percent); - } - - /** - * Get scaling for font rendering (in percent, 100% = no scaling) - * If the saved value is not within the declared boundary, it will be - * reseted to 100. - * - * @return the saved value of 'gui.fontscaling' if within boundaries, 100 - * otherwise - */ - public static int getFontScaling() { - int savedFontScaling = getInteger("gui.fontscaling", 100); - if (savedFontScaling < FONT_SCALING_MIN || savedFontScaling > FONT_SCALING_MAX) { - setFontScaling(100); - return 100; - } - return savedFontScaling; - } - - /** * Set number of connections to establish per transfer */ public static void setTransferConnectionCount(int count) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java index 1d1dd90e..0b1a5b48 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/Gui.java @@ -31,7 +31,6 @@ import javax.swing.text.html.HTMLDocument; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.util.DesktopEnvironment; import org.openslx.dozmod.util.ResourceLoader; @@ -133,20 +132,14 @@ public class Gui { } /** - * Gets the given dimension scaled to the saved scaling factor - * - * @param width starting width to scale - * @param height starting height to scale - * @return scaled dimension + * This is a no-op since we rely on native scaling now (Java 9+) */ public static Dimension getScaledDimension(int width, int height) { - int scale = Config.getFontScaling(); - return new Dimension(width * scale / 100, height * scale / 100); + return new Dimension(width, height); } /** - * Load given icon resource, optionally scaling it while taking - * the user's zoom factor into account. + * Load given icon resource, optionally scaling it. * * @param path resource path * @param description resource description @@ -155,8 +148,7 @@ public class Gui { * @return scaled icon, if too large, otherwise the unmodified icon */ public static Icon getScaledIconResource(String path, String description, int maxHeight, Component context) { - int height = maxHeight * Config.getFontScaling() / 100; - return ResourceLoader.getIcon(path, description, height, context); + return ResourceLoader.getIcon(path, description, maxHeight, context); } /** diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/QLabel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/QLabel.java index 527c0954..c44eb077 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/QLabel.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/QLabel.java @@ -1,6 +1,12 @@ package org.openslx.dozmod.gui.control; +import java.awt.Component; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + import javax.swing.Icon; +import javax.swing.JComponent; import javax.swing.JLabel; public class QLabel extends JLabel { @@ -8,7 +14,10 @@ public class QLabel extends JLabel { private static final long serialVersionUID = -2454459023556745689L; public QLabel(String text, Icon icon, int horizontalAlignment) { - super(text, icon, horizontalAlignment); + super(text, icon == null ? null : new ScaledIcon(icon), horizontalAlignment); + if (this.getIcon() != null) { + ((ScaledIcon)this.getIcon()).setParent(this); + } putClientProperty("html.disable", Boolean.TRUE); putClientProperty("html", null); } @@ -33,4 +42,51 @@ public class QLabel extends JLabel { this("", null, LEADING); } -} + private static class ScaledIcon implements Icon { + private final Icon delegate; + private JComponent c; + private double scaleX, scaleY; + + ScaledIcon(Icon delegate) { + this.delegate = delegate; + } + + public void setParent(QLabel qLabel) { + this.c = qLabel; + } + + private void updateScalingData() { + // Re-read this every time, to hopefully account for multi-screen setups + // with different scaling per screen. + AffineTransform tx = c.getGraphicsConfiguration().getDefaultTransform(); + scaleX = 1 / tx.getScaleX(); + scaleY = 1 / tx.getScaleY(); + } + + @Override + public int getIconWidth() { + updateScalingData(); + return (int) Math.round(delegate.getIconWidth() * scaleX); + } + + @Override + public int getIconHeight() { + updateScalingData(); + return (int) Math.round(delegate.getIconHeight() * scaleY); + } + + @Override + public void paintIcon(Component c, Graphics g, int x, int y) { + updateScalingData(); + Graphics2D g2 = (Graphics2D) g.create(); + try { + g2.translate(x, y); + g2.scale(scaleX, scaleY); + delegate.paintIcon(c, g2, 0, 0); + } finally { + g2.dispose(); + } + } + } + +}
\ No newline at end of file diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java index 81049906..79070fb2 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java @@ -20,7 +20,6 @@ import javax.swing.table.TableColumn; import javax.swing.table.TableColumnModel; import javax.swing.table.TableRowSorter; -import org.openslx.dozmod.Config; import org.openslx.dozmod.gui.helper.TableColumnAdjuster; public abstract class ListTable<T> extends JTable { @@ -76,7 +75,6 @@ public abstract class ListTable<T> extends JTable { this.setDefaultEditor(Boolean.class, getDefaultEditor(Boolean.class)); this.setRowSelectionAllowed(true); this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - this.setRowHeight(this.getRowHeight() * Config.getFontScaling() / 100); this.setOpaque(false); sorter.addRowSorterListener(new RowSorterListener() { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java index 3003624c..64bd7a05 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ConfigWindow.java @@ -85,10 +85,6 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti } }; - // -- FONT CONFIG -- - // set font scaling as saved in config - sldFontSize.setValue(Config.getFontScaling()); - sldFontSize.addChangeListener(changeListener); // -- Look And Feel -- for (Enumeration<AbstractButton> btn = btnGroupLookAndFeel.getElements(); btn.hasMoreElements();) { final JRadioButton b = (JRadioButton) btn.nextElement(); @@ -176,7 +172,6 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti boolean changed = false; // first check our initial state ProxyMode initMode = Config.getProxyMode(); - int fontScaling = Config.getFontScaling(); Language newLanguage = (Language)cboLanguage.getSelectedItem(); // now check if the buttons represent another state @@ -186,8 +181,6 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti changed = true; } else if (chkSendMeMail.isEnabled() && chkSendMeMail.isSelected() != userConfig.emailNotifications) { changed = true; - } else if ((int) sldFontSize.getValue() != fontScaling) { - changed = true; } else if ((int) sldConnections.getValue() != Config.getTransferConnectionCount()) { changed = true; } else if (!selectedLookAndFeel.getToolTipText().equals(Config.getLookAndFeel())) { @@ -243,10 +236,6 @@ public class ConfigWindow extends ConfigWindowLayout implements UiFeedback, Acti Config.setProxyMode(selectedMode); } - // save font scaling to config - int newFontScaling = (int) sldFontSize.getValue(); - restartRequired = restartRequired || Config.getFontScaling() != newFontScaling; - Config.setFontScaling(newFontScaling); // transfers Config.setTransferConnectionCount((int) sldConnections.getValue()); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java index 432654f7..c0a9ef0b 100755 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ConfigWindowLayout.java @@ -4,7 +4,19 @@ import java.awt.BorderLayout; import java.awt.Insets; import java.awt.Window; -import javax.swing.*; +import javax.swing.BorderFactory; +import javax.swing.Box; +import javax.swing.BoxLayout; +import javax.swing.ButtonGroup; +import javax.swing.DefaultBoundedRangeModel; +import javax.swing.DefaultComboBoxModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JDialog; +import javax.swing.JPanel; +import javax.swing.JRadioButton; +import javax.swing.JSlider; +import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; import org.openslx.dozmod.Branding; @@ -30,7 +42,6 @@ public class ConfigWindowLayout extends JDialog { protected final JRadioButton btnProxyHttp = null; protected final JCheckBox chkSendMeMail; protected final QLabel lblYourAddress; - protected final JSlider sldFontSize; protected final JSlider sldConnections; protected ButtonGroup btnGroupLookAndFeel = null; protected ButtonGroup btnGroupTransferEnc = null; @@ -94,16 +105,6 @@ public class ConfigWindowLayout extends JDialog { false, true)) .expand(true, false) .fill(true, false); - UIManager.put("Slider.paintValue", false); - sldFontSize = new JSlider(JSlider.HORIZONTAL); - sldFontSize.setModel(new DefaultBoundedRangeModel(100, 0, Config.FONT_SCALING_MIN, - Config.FONT_SCALING_MAX)); - sldFontSize.setMinorTickSpacing(5); - sldFontSize.setMajorTickSpacing(25); - sldFontSize.setSnapToTicks(true); - sldFontSize.setPaintTicks(true); - sldFontSize.setPaintLabels(true); - grid.add(sldFontSize).fill(true, false).expand(true, false); // look and feel grid.add(new WordWrapLabel(I18n.WINDOW_LAYOUT.getString("Config.Label.lookAndFeel.text"), diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java index c65e7a53..97595834 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LoginWindowLayout.java @@ -1,7 +1,9 @@ package org.openslx.dozmod.gui.window.layout; import java.awt.Frame; +import java.awt.GraphicsConfiguration; import java.awt.Rectangle; +import java.awt.geom.AffineTransform; import javax.swing.Box; import javax.swing.BoxLayout; @@ -180,7 +182,6 @@ public abstract class LoginWindowLayout extends JDialog { grid.nextRow(); // --- Browser-based login - grid.add(txtUrl, 4).expand(true, false).fill(true, false); grid.nextRow(); grid.add(lblError, 4).expand(true, false).fill(true, false); @@ -228,11 +229,12 @@ public abstract class LoginWindowLayout extends JDialog { private ImageIcon getScaledLogo() { try { ImageIcon image = ResourceLoader.getIcon("/img/service-logo.png"); - Rectangle screenSize = Gui.getMonitorFromRectangle(getBounds(), true) - .getDefaultConfiguration() - .getBounds(); - float scaleX = (float) screenSize.width / (float) image.getIconWidth(); - float scaleY = (float) screenSize.height / (float) image.getIconHeight(); + GraphicsConfiguration config = Gui.getMonitorFromRectangle(getBounds(), true) + .getDefaultConfiguration(); + Rectangle screenSize = config.getBounds(); + AffineTransform tx = config.getDefaultTransform(); + float scaleX = (float) tx.getScaleX() * (float) screenSize.width / (float) image.getIconWidth(); + float scaleY = (float) tx.getScaleY() * (float) screenSize.height / (float) image.getIconHeight(); final float scaling; if (scaleX < scaleY) { scaling = scaleX / 2; diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java index a6e932cc..943fbdbd 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/ResourceLoader.java @@ -25,7 +25,6 @@ import org.apache.commons.io.IOUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.openslx.dozmod.Branding; -import org.openslx.dozmod.Config; /** * Helper class for loading resources. @@ -72,11 +71,7 @@ public class ResourceLoader } else { try { ImageIcon icon = new ImageIcon(url); - float scalingFactor = Config.getFontScaling() / (float)100; - return new ImageIcon( - icon.getImage().getScaledInstance(Math.round(icon.getIconWidth() * scalingFactor), - Math.round(icon.getIconHeight() * scalingFactor), java.awt.Image.SCALE_SMOOTH), - description); + return icon; // Success ^^ } catch ( Exception e ) { LOGGER.error( "Resource not loadable: " + path ); diff --git a/dozentenmodul/src/main/properties/i18n/window_layout.properties b/dozentenmodul/src/main/properties/i18n/window_layout.properties index eb78a489..51b07493 100644 --- a/dozentenmodul/src/main/properties/i18n/window_layout.properties +++ b/dozentenmodul/src/main/properties/i18n/window_layout.properties @@ -16,7 +16,8 @@ Config.Label.proxyConfig.text=Proxy server Config.RadioButton.proxyNone.text=Do not use a proxy Config.RadioButton.proxyAuto.text=Automatically search for proxy Config.Label.fontConfig.text=Font size (%) -Config.Label.fontConfigInfo.text=This function is experimental. Display errors may occur. +Config.Label.fontConfigInfo.text=For UI/Font scaling, we now rely on native support in Java 9 or later.\n \ + The UI will automatically scale according to your OS settings. Config.Label.lookAndFeel.text=LookAndFeel Config.Label.lookAndFeelInfo.text=Here you can change the display of the interface \ between different ''LookAndFeels''. diff --git a/dozentenmodul/src/main/properties/i18n/window_layout_de_DE.properties b/dozentenmodul/src/main/properties/i18n/window_layout_de_DE.properties index 8d544eea..9764fe12 100644 --- a/dozentenmodul/src/main/properties/i18n/window_layout_de_DE.properties +++ b/dozentenmodul/src/main/properties/i18n/window_layout_de_DE.properties @@ -16,7 +16,8 @@ Config.Label.proxyConfig.text=Proxyserver Config.RadioButton.proxyNone.text=Keinen Proxy verwenden Config.RadioButton.proxyAuto.text=Automatisch nach Proxy suchen Config.Label.fontConfig.text=Schriftgröße (%) -Config.Label.fontConfigInfo.text=Diese Funktion ist experimentell. Es kann zu Anzeigefehlern kommen. +Config.Label.fontConfigInfo.text=Für die UI-/Schriftskalierung wird nun die native Unterstützung in Java 9 oder\n \ + neuer genutzt. Die UI skaliert automatisch gemäß Ihren Betriebssystem-Einstellungen. Config.Label.lookAndFeel.text=LookAndFeel Config.Label.lookAndFeelInfo.text=Hier können Sie die Darstellung der Oberfläche zwischen unterschiedlichen \ ''LookAndFeels'' umstellen. diff --git a/dozentenmodul/src/main/properties/i18n/window_layout_tr_TR.properties b/dozentenmodul/src/main/properties/i18n/window_layout_tr_TR.properties index d144bf1d..43a5d3fd 100644 --- a/dozentenmodul/src/main/properties/i18n/window_layout_tr_TR.properties +++ b/dozentenmodul/src/main/properties/i18n/window_layout_tr_TR.properties @@ -16,7 +16,8 @@ Config.Label.proxyConfig.text=Ara sunucu Config.RadioButton.proxyNone.text=Ara sunucu kullanma Config.RadioButton.proxyAuto.text=Ara sunucu ayarlarını otomatik olarak algıla Config.Label.fontConfig.text=Yazı boyutu (%) -Config.Label.fontConfigInfo.text=Bu işlev henüz test aşamasındadır. Görüntüleme hataları oluşabilir. +Config.Label.fontConfigInfo.text=UI/yazı tipi ölçeklendirmesi için artık Java 9 veya üzerindeki yerel desteğe\n \ + dayanıyoruz. Arayüz, işletim sistemi ayarlarınıza göre otomatik olarak ölçeklenir. Config.Label.lookAndFeel.text=LookAndFeel Config.Label.lookAndFeelInfo.text=Burada, arayüz görünümünü değiştirmek için birbirinden farklı ''LookAndFeels'' \ temaları arasında seçim yapabilirsiniz. |
