Changeset 1191 in josm for trunk/src/org


Ignore:
Timestamp:
2008-12-30T00:55:23+01:00 (15 years ago)
Author:
stoecker
Message:

fixed bug #1654. Patch by Henrik Niehaus

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java

    r1188 r1191  
    66
    77import java.awt.Dimension;
    8 import java.awt.Graphics;
     8import java.awt.GridBagConstraints;
    99import java.awt.GridBagLayout;
     10import java.awt.Insets;
     11import java.awt.Rectangle;
    1012import java.awt.event.ActionEvent;
    1113import java.awt.event.ActionListener;
     
    2830import javax.swing.AbstractAction;
    2931import javax.swing.BorderFactory;
    30 import javax.swing.Box;
    31 import javax.swing.BoxLayout;
    3232import javax.swing.DefaultListModel;
    3333import javax.swing.JButton;
    3434import javax.swing.JCheckBox;
     35import javax.swing.JEditorPane;
    3536import javax.swing.JLabel;
    3637import javax.swing.JList;
     
    3839import javax.swing.JPanel;
    3940import javax.swing.JScrollPane;
     41import javax.swing.Scrollable;
     42import javax.swing.UIManager;
     43import javax.swing.event.HyperlinkEvent;
     44import javax.swing.event.HyperlinkListener;
     45import javax.swing.event.HyperlinkEvent.EventType;
    4046
    4147import org.openstreetmap.josm.Main;
     
    4551import org.openstreetmap.josm.plugins.PluginProxy;
    4652import org.openstreetmap.josm.tools.GBC;
     53import org.openstreetmap.josm.tools.OpenBrowser;
    4754import org.openstreetmap.josm.tools.XmlObjectParser.Uniform;
    4855
     
    8289    private Map<String, PluginDescription> availablePlugins;
    8390    private JPanel plugin;
    84     private class MyBox extends Box {
    85         int lastwidth;
    86         int offset = 40;
    87         public MyBox()
    88         {
    89             super(BoxLayout.Y_AXIS);
    90         }
    91         public int myGetWidth()
    92         {
    93             int w = plugin.getWidth()-offset;
    94             if(w <= 0) w = 450;
    95             lastwidth = w;
    96             return w;
    97         }
    98         public void paint(Graphics g)
    99         {
    100             if(lastwidth != plugin.getWidth()-offset)
    101                 refreshPluginPanel(gui);
    102             super.paint(g);
    103         }
    104     }
    105     private MyBox pluginPanel = new MyBox();
     91    private JPanel pluginPanel = new NoHorizontalScrollPanel(new GridBagLayout());
    10692    private PreferenceDialog gui;
     93    private JScrollPane pluginPane;
    10794
    10895    public void addGui(final PreferenceDialog gui) {
    10996        this.gui = gui;
    11097        plugin = gui.createPreferenceTab("plugin", tr("Plugins"), tr("Configure available plugins."), false);
    111         JScrollPane pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
     98        pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    11299        pluginPane.setBorder(null);
    113100        plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH));
     
    239226
    240227        pluginPanel.removeAll();
    241         int width = pluginPanel.myGetWidth();
    242 
     228
     229        GridBagConstraints gbc = new GridBagConstraints();
     230        gbc.gridx = 0;
     231        gbc.anchor = GridBagConstraints.NORTHWEST;
     232
     233        int row = 0;
    243234        for (final PluginDescription plugin : availablePlugins.values()) {
    244235            boolean enabled = (enabledPlugins != null) && enabledPlugins.contains(plugin.name);
     
    264255                    tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion),
    265256                    pluginMap.get(plugin.name));
    266             pluginPanel.add(pluginCheck);
    267 
    268             pluginCheck.setToolTipText(plugin.resource != null ? "" + plugin.resource : tr("Plugin bundled with JOSM"));
    269             JLabel label = new JLabel("<html><i>" + (plugin.description == null ? tr("no description available") : plugin.description) + "</i></html>");
    270             label.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0));
    271             label.setMaximumSize(new Dimension(width, 1000));
    272             pluginPanel.add(label);
    273             pluginPanel.add(Box.createVerticalStrut(5));
     257            gbc.gridy = row++;
     258            gbc.insets = new Insets(5,5,0,5);
     259            gbc.weighty = 0.1;
     260            gbc.fill = GridBagConstraints.NONE;
     261            pluginPanel.add(pluginCheck, gbc);
     262
     263            pluginCheck.setToolTipText(plugin.resource != null ? ""+plugin.resource : tr("Plugin bundled with JOSM"));
     264
     265            JEditorPane description = new JEditorPane();
     266            description.setContentType("text/html");
     267            description.setEditable(false);
     268            description.setText("<html><i>"+(plugin.description==null?tr("no description available"):plugin.description)+"</i></html>");
     269            description.setBorder(BorderFactory.createEmptyBorder(0,20,0,0));
     270            description.setBackground(UIManager.getColor("Panel.background"));
     271            description.addHyperlinkListener(new HyperlinkListener() {
     272                public void hyperlinkUpdate(HyperlinkEvent e) {
     273                    if(e.getEventType() == EventType.ACTIVATED) {
     274                        OpenBrowser.displayUrl(e.getURL().toString());
     275                    }
     276                }
     277            });
     278
     279            gbc.gridy = row++;
     280            gbc.insets = new Insets(3,5,5,5);
     281            gbc.weighty = 0.9;
     282            gbc.weightx = 1.0;
     283            gbc.anchor = GridBagConstraints.WEST;
     284            gbc.fill = GridBagConstraints.HORIZONTAL;
     285            pluginPanel.add(description, gbc);
    274286
    275287            pluginCheck.addActionListener(new ActionListener(){
     
    382394        return Main.pref.putCollection("plugins", plugins);
    383395    }
     396   
     397    class NoHorizontalScrollPanel extends JPanel implements Scrollable {
     398        public NoHorizontalScrollPanel(GridBagLayout gridBagLayout) {
     399            super(gridBagLayout);
     400        }
     401
     402        public Dimension getPreferredScrollableViewportSize() {
     403            return super.getPreferredSize();
     404        }
     405
     406        public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
     407            return 30;
     408        }
     409
     410        public boolean getScrollableTracksViewportHeight() {
     411            return false;
     412        }
     413
     414        public boolean getScrollableTracksViewportWidth() {
     415            return true;
     416        }
     417
     418        public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
     419            return 10;
     420        }
     421    }
    384422}
Note: See TracChangeset for help on using the changeset viewer.