Changeset 5631 in josm for trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
- Timestamp:
- 2012-12-25T23:43:22+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java
r5463 r5631 57 57 import org.openstreetmap.josm.gui.help.HelpUtil; 58 58 import org.openstreetmap.josm.gui.help.Helpful; 59 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 60 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 61 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 62 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 59 63 import org.openstreetmap.josm.tools.Destroyable; 60 64 import org.openstreetmap.josm.tools.GBC; … … 139 143 */ 140 144 protected JCheckBoxMenuItem windowMenuItem; 145 146 /** 147 * The linked preferences class (optional). If set, accessible from the title bar with a dedicated button 148 */ 149 protected Class<? extends PreferenceSetting> preferenceClass; 141 150 142 151 /** … … 146 155 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight) { 147 156 this(name, iconName, tooltip, shortcut, preferredHeight, false); 157 } 158 /** 159 * Constructor 160 * (see below) 161 */ 162 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow) { 163 this(name, iconName, tooltip, shortcut, preferredHeight, defShow, null); 148 164 } 149 165 /** … … 156 172 * @param preferredHeight the preferred height for the dialog 157 173 * @param defShow if the dialog should be shown by default, if there is no preference 158 */ 159 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow) { 174 * @param prefClass the preferences settings class, or null if not applicable 175 */ 176 public ToggleDialog(String name, String iconName, String tooltip, Shortcut shortcut, int preferredHeight, boolean defShow, Class<? extends PreferenceSetting> prefClass) { 160 177 super(new BorderLayout()); 161 178 this.preferencePrefix = iconName; 162 179 this.name = name; 180 this.preferenceClass = prefClass; 163 181 164 182 /** Use the full width of the parent element */ … … 522 540 add(buttonsHide); 523 541 } 542 543 // show the pref button if applicable 544 if (preferenceClass != null) { 545 inIcon = ImageProvider.get("preference"); 546 smallIcon = new ImageIcon(inIcon.getImage().getScaledInstance(16 , 16, Image.SCALE_SMOOTH)); 547 JButton pref = new JButton(smallIcon); 548 pref.setToolTipText(tr("Open preferences for this panel")); 549 pref.setBorder(BorderFactory.createEmptyBorder()); 550 pref.addActionListener( 551 new ActionListener(){ 552 @SuppressWarnings("unchecked") 553 public void actionPerformed(ActionEvent e) { 554 final PreferenceDialog p = new PreferenceDialog(Main.parent); 555 if (TabPreferenceSetting.class.isAssignableFrom(preferenceClass)) { 556 p.selectPreferencesTabByClass((Class<? extends TabPreferenceSetting>) preferenceClass); 557 } else if (SubPreferenceSetting.class.isAssignableFrom(preferenceClass)) { 558 p.selectSubPreferencesTabByClass((Class<? extends SubPreferenceSetting>) preferenceClass); 559 } 560 p.setVisible(true); 561 } 562 } 563 ); 564 add(pref); 565 } 524 566 525 567 // show the sticky button
Note:
See TracChangeset
for help on using the changeset viewer.
