Changeset 5842 in josm


Ignore:
Timestamp:
2013-04-12T00:16:55+02:00 (12 years ago)
Author:
Don-vip
Message:

Upload dialog: allow plugins to add custom components

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/io/UploadDialog.java

    r5412 r5842  
    66
    77import java.awt.BorderLayout;
     8import java.awt.Component;
    89import java.awt.Dimension;
    910import java.awt.FlowLayout;
     11import java.awt.GridBagLayout;
    1012import java.awt.Image;
    1113import java.awt.event.ActionEvent;
     
    1517import java.beans.PropertyChangeEvent;
    1618import java.beans.PropertyChangeListener;
     19import java.util.ArrayList;
     20import java.util.Collection;
    1721import java.util.Collections;
    1822import java.util.List;
     
    4448import org.openstreetmap.josm.gui.help.HelpUtil;
    4549import org.openstreetmap.josm.io.OsmApi;
     50import org.openstreetmap.josm.tools.GBC;
    4651import org.openstreetmap.josm.tools.ImageProvider;
    4752import org.openstreetmap.josm.tools.InputMapUtils;
     
    5156 * This is a dialog for entering upload options like the parameters for
    5257 * the upload changeset and the strategy for opening/closing a changeset.
    53  *
     58 * 
    5459 */
    5560public class UploadDialog extends JDialog implements PropertyChangeListener, PreferenceChangedListener{
    5661    /**  the unique instance of the upload dialog */
    5762    static private UploadDialog uploadDialog;
     63
     64    /**
     65     * List of custom components that can be added by plugins at JOSM startup.
     66     */
     67    static private final Collection<Component> customComponents = new ArrayList<Component>();
    5868
    5969    /**
     
    95105     */
    96106    protected JPanel buildContentPanel() {
    97         JPanel pnl = new JPanel();
     107        JPanel pnl = new JPanel(new GridBagLayout());
    98108        pnl.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
    99         pnl.setLayout(new BorderLayout());
    100109
    101110        // the panel with the list of uploaded objects
    102111        //
    103         pnl.add(pnlUploadedObjects = new UploadedObjectsSummaryPanel(), BorderLayout.CENTER);
    104 
    105         // a tabbed pane with two configuration panels in the
    106         // lower half
     112        pnl.add(pnlUploadedObjects = new UploadedObjectsSummaryPanel(), GBC.eol().fill(GBC.BOTH));
     113       
     114        // Custom components
     115        for (Component c : customComponents) {
     116            pnl.add(c, GBC.eol().fill(GBC.HORIZONTAL));
     117        }
     118
     119        // a tabbed pane with configuration panels in the lower half
    107120        //
    108121        tpConfigPanels = new JTabbedPane() {
     
    114127            }
    115128        };
    116         tpConfigPanels.add(new JPanel());
    117         tpConfigPanels.add(new JPanel());
    118         tpConfigPanels.add(new JPanel());
    119         tpConfigPanels.add(new JPanel());
    120129
    121130        changesetCommentModel = new ChangesetCommentModel();
    122131
    123         tpConfigPanels.setComponentAt(0, pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel));
     132        tpConfigPanels.add(pnlBasicUploadSettings = new BasicUploadSettingsPanel(changesetCommentModel));
    124133        tpConfigPanels.setTitleAt(0, tr("Settings"));
    125134        tpConfigPanels.setToolTipTextAt(0, tr("Decide how to upload the data and which changeset to use"));
    126135
    127         tpConfigPanels.setComponentAt(1,pnlTagSettings = new TagSettingsPanel(changesetCommentModel));
     136        tpConfigPanels.add(pnlTagSettings = new TagSettingsPanel(changesetCommentModel));
    128137        tpConfigPanels.setTitleAt(1, tr("Tags of new changeset"));
    129138        tpConfigPanels.setToolTipTextAt(1, tr("Apply tags to the changeset data is uploaded to"));
    130139
    131         tpConfigPanels.setComponentAt(2,pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel));
     140        tpConfigPanels.add(pnlChangesetManagement = new ChangesetManagementPanel(changesetCommentModel));
    132141        tpConfigPanels.setTitleAt(2, tr("Changesets"));
    133142        tpConfigPanels.setToolTipTextAt(2, tr("Manage open changesets and select a changeset to upload to"));
    134143
    135         tpConfigPanels.setComponentAt(3, pnlUploadStrategySelectionPanel = new UploadStrategySelectionPanel());
     144        tpConfigPanels.add(pnlUploadStrategySelectionPanel = new UploadStrategySelectionPanel());
    136145        tpConfigPanels.setTitleAt(3, tr("Advanced"));
    137146        tpConfigPanels.setToolTipTextAt(3, tr("Configure advanced settings"));
    138147
    139         pnl.add(tpConfigPanels, BorderLayout.SOUTH);
     148        pnl.add(tpConfigPanels, GBC.eol().fill(GBC.HORIZONTAL));
    140149        return pnl;
    141150    }
     
    144153     * builds the panel with the OK and CANCEL buttons
    145154     *
    146      * @return
     155     * @return The panel with the OK and CANCEL buttons
    147156     */
    148157    protected JPanel buildActionPanel() {
     
    360369        }
    361370        super.setVisible(visible);
     371    }
     372   
     373    /**
     374     * Adds a custom component to this dialog.
     375     * Custom components added at JOSM startup are displayed between the objects list and the properties tab pane.
     376     * @param c The custom component to add. If {@code null}, this method does nothing.
     377     * @return {@code true} if the collection of custom components changed as a result of the call
     378     * @since 5842
     379     */
     380    public static boolean addCustomComponent(Component c) {
     381        if (c != null) {
     382            return customComponents.add(c);
     383        }
     384        return false;
    362385    }
    363386
Note: See TracChangeset for help on using the changeset viewer.