Ticket #8334: 8334.patch
File 8334.patch, 8.2 KB (added by , 12 years ago) |
---|
-
core/src/org/openstreetmap/josm/Main.java
4 4 5 5 import java.awt.BorderLayout; 6 6 import java.awt.Component; 7 import java.awt.Font; 7 8 import java.awt.GridBagConstraints; 8 9 import java.awt.GridBagLayout; 9 10 import java.awt.Window; … … 20 21 import java.util.ArrayList; 21 22 import java.util.Arrays; 22 23 import java.util.Collection; 24 import java.util.Enumeration; 23 25 import java.util.Iterator; 24 26 import java.util.List; 25 27 import java.util.Map; … … 39 41 import javax.swing.JTextArea; 40 42 import javax.swing.KeyStroke; 41 43 import javax.swing.UIManager; 44 import javax.swing.plaf.FontUIResource; 42 45 43 46 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 44 47 import org.openstreetmap.josm.actions.JosmAction; … … 515 518 menu.redo.setEnabled(redoSize > 0); 516 519 } 517 520 }; 521 522 protected static void setUIFont(FontUIResource f) { 523 Enumeration<?> keys = UIManager.getDefaults().keys(); 524 while (keys.hasMoreElements()) { 525 Object key = keys.nextElement(); 526 Object value = UIManager.get(key); 527 if (value != null && value instanceof FontUIResource) { 528 UIManager.put(key, f); 529 } 530 } 531 } 518 532 519 533 /** 520 534 * Should be called before the main constructor to setup some parameter stuff … … 537 551 System.out.println("Look and Feel not supported: " + laf); 538 552 Main.pref.put("laf", defaultlaf); 539 553 } 554 String fontName = Main.pref.get("font"); 555 if (fontName != null) { 556 Font font = Font.decode(fontName); 557 if (font != null) { 558 setUIFont(new FontUIResource(font)); 559 } else { 560 System.out.println("Font not found: " + fontName); 561 } 562 } 540 563 toolbar = new ToolbarPreferences(); 541 564 contentPanePrivate.updateUI(); 542 565 panel.updateUI(); -
core/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java
4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 6 import java.awt.Component; 7 import java.awt.Font; 7 8 import java.awt.GridBagLayout; 8 9 9 10 import javax.swing.BorderFactory; … … 25 26 import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane; 26 27 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 27 28 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 29 import org.openstreetmap.josm.gui.widgets.FontChooser; 28 30 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 29 31 import org.openstreetmap.josm.tools.GBC; 30 32 … … 40 42 * ComboBox with all look and feels. 41 43 */ 42 44 private JosmComboBox lafCombo; 45 private FontChooser fontCombo; 43 46 public JPanel panel; 44 47 private JCheckBox showSplashScreen = new JCheckBox(tr("Show splash screen at startup")); 45 48 private JCheckBox showID = new JCheckBox(tr("Show object ID in selection lists")); … … 49 52 50 53 public void addGui(PreferenceTabbedPane gui) { 51 54 lafCombo = new JosmComboBox(UIManager.getInstalledLookAndFeels()); 55 fontCombo = new FontChooser(); 52 56 53 57 // let's try to load additional LookAndFeels and put them into the list 54 58 try { … … 70 74 break; 71 75 } 72 76 } 77 78 String font = Main.pref.get("font"); 79 if (font != null) { 80 for (int i = 1; i < fontCombo.getItemCount(); ++i) { 81 if (((Font)fontCombo.getItemAt(i)).getFontName().equals(font)) { 82 fontCombo.setSelectedIndex(i); 83 break; 84 } 85 } 86 } 73 87 74 88 final ListCellRenderer oldRenderer = lafCombo.getRenderer(); 75 89 lafCombo.setRenderer(new DefaultListCellRenderer(){ … … 113 127 panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 114 128 panel.add(lafCombo, GBC.eol().fill(GBC.HORIZONTAL)); 115 129 130 addExpertComponent(new JLabel(tr("Font")), GBC.std().insets(20, 0, 0, 0)); 131 addExpertComponent(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 132 addExpertComponent(fontCombo, GBC.eol().fill(GBC.HORIZONTAL)); 133 116 134 JScrollPane scrollpane = new JScrollPane(panel); 117 135 scrollpane.setBorder(BorderFactory.createEmptyBorder( 0, 0, 0, 0 )); 118 136 gui.getDisplayPreference().addSubTab(this, tr("Look and Feel"), scrollpane); 119 137 } 138 139 private void addExpertComponent(Component c, GBC constraints) { 140 ExpertToggleAction.addVisibilitySwitcher(c); 141 panel.add(c, constraints); 142 } 120 143 121 144 public boolean ok() { 122 145 boolean mod = false; … … 125 148 Main.pref.put("osm-primitives.localize-name", showLocalizedName.isSelected()); 126 149 Main.pref.put("modeless", modeless.isSelected()); 127 150 Main.pref.put("dialog.dynamic.buttons", dynamicButtons.isSelected()); 151 mod |= Main.pref.put("font", fontCombo.getSelectedFont() != null ? fontCombo.getSelectedFont().getFontName() : null); 128 152 mod |= Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName()); 129 153 return mod; 130 154 } -
core/src/org/openstreetmap/josm/gui/widgets/FontChooser.java
1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.gui.widgets; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 import java.awt.Component; 7 import java.awt.Font; 8 import java.awt.GraphicsEnvironment; 9 import java.util.Arrays; 10 import java.util.Comparator; 11 12 import javax.swing.DefaultListCellRenderer; 13 import javax.swing.JComboBox; 14 import javax.swing.JList; 15 import javax.swing.ListCellRenderer; 16 17 /** 18 * A Combobox that displays the available fonts in their own font. 19 * @since 5664 20 */ 21 public class FontChooser extends JComboBox { 22 23 /** 24 * Constructor 25 */ 26 public FontChooser() { 27 28 final Font[] fonts = GraphicsEnvironment 29 .getLocalGraphicsEnvironment() 30 .getAllFonts(); 31 32 Arrays.sort(fonts, new Comparator<Font>() { 33 @Override 34 public int compare(Font f1, Font f2) { 35 return f1.getName().compareTo(f2.getName()); 36 } 37 }); 38 39 addItem(null); 40 41 for (Font font : fonts) { 42 if (font.canDisplayUpTo(font.getName()) == -1) { 43 addItem(font); 44 } 45 } 46 47 setRenderer(new FontCellRenderer()); 48 } 49 50 private static class FontCellRenderer implements ListCellRenderer { 51 52 protected DefaultListCellRenderer renderer = new DefaultListCellRenderer(); 53 54 @Override 55 public Component getListCellRendererComponent(JList list, Object value, 56 int index, boolean isSelected, boolean cellHasFocus) { 57 Font font = (Font) value; 58 final Component result = renderer.getListCellRendererComponent(list, 59 font == null ? tr("Default (Auto determined)") : font.getName(), 60 index, isSelected, cellHasFocus); 61 if (font != null && result != null) { 62 result.setFont(font.deriveFont(result.getFont().getSize2D())); 63 } 64 return result; 65 } 66 } 67 68 /** 69 * Get the selected font, or null if the default font (first choice) has been selected. 70 * @return The selected font, or null if the default font (first choice) has been selected. 71 */ 72 public final Font getSelectedFont() { 73 return (Font) getSelectedItem(); 74 } 75 }