Changeset 4353 in josm for trunk/src


Ignore:
Timestamp:
2011-08-27T13:57:45+02:00 (13 years ago)
Author:
stoecker
Message:

see #6731 - introduce better layout function for ToggleDialogs, changed author and relation dialog

Location:
trunk/src/org/openstreetmap/josm/gui/dialogs
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/RelationListDialog.java

    r4223 r4353  
    1212import java.awt.event.MouseEvent;
    1313import java.util.ArrayList;
     14import java.util.Arrays;
    1415import java.util.Collection;
    1516import java.util.Collections;
     
    2324import javax.swing.DefaultListSelectionModel;
    2425import javax.swing.JList;
    25 import javax.swing.JPanel;
    2626import javax.swing.JPopupMenu;
    27 import javax.swing.JScrollPane;
    2827import javax.swing.KeyStroke;
    2928import javax.swing.ListSelectionModel;
     
    106105        displaylist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    107106        displaylist.addMouseListener(new MouseEventHandler());
    108         add(new JScrollPane(displaylist), BorderLayout.CENTER);
    109 
    110         // create the panel with buttons
    111         //
    112         JPanel tp = getButtonPanel(5);
     107
    113108        // the new action
    114109        //
    115110        newAction = new NewAction();
    116         tp.add(new SideButton(newAction, false));
    117111
    118112        // the edit action
     
    120114        editAction = new EditAction();
    121115        displaylist.addListSelectionListener(editAction);
    122         tp.add(new SideButton(editAction, false));
    123116
    124117        // the duplicate action
     
    126119        DuplicateAction duplicateAction = new DuplicateAction();
    127120        displaylist.addListSelectionListener(duplicateAction);
    128         tp.add(new SideButton(duplicateAction, false));
    129121
    130122        // the delete action
     
    132124        deleteAction = new DeleteAction();
    133125        displaylist.addListSelectionListener(deleteAction);
    134         tp.add(new SideButton(deleteAction, false));
    135126
    136127        // the select action
     
    138129        SelectAction selectAction = new SelectAction(false);
    139130        displaylist.addListSelectionListener(selectAction);
    140         tp.add(new SideButton(selectAction, false));
    141 
    142         add(tp, BorderLayout.SOUTH);
     131
     132        createLayout(displaylist, true, Arrays.asList(new SideButton[] {
     133            new SideButton(newAction, false),
     134            new SideButton(editAction, false),
     135            new SideButton(duplicateAction, false),
     136            new SideButton(deleteAction, false),
     137            new SideButton(selectAction, false)
     138        }));
    143139
    144140        // activate DEL in the list of relations
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ToggleDialog.java

    r3598 r4353  
    2222import java.awt.event.WindowEvent;
    2323
     24import java.util.Collection;
     25
    2426import javax.swing.AbstractAction;
    2527import javax.swing.BorderFactory;
     
    3032import javax.swing.JLabel;
    3133import javax.swing.JOptionPane;
     34import javax.swing.JScrollPane;
    3235import javax.swing.JPanel;
    3336import javax.swing.JToggleButton;
     
    3942import org.openstreetmap.josm.gui.help.Helpful;
    4043import org.openstreetmap.josm.gui.util.RedirectInputMap;
     44import org.openstreetmap.josm.gui.SideButton;
    4145import org.openstreetmap.josm.tools.GBC;
    4246import org.openstreetmap.josm.tools.ImageProvider;
     
    116120        String helpId = "Dialog/"+getClass().getName().substring(getClass().getName().lastIndexOf('.')+1);
    117121        toggleAction.putValue("help", helpId.substring(0, helpId.length()-6));
    118 
    119         setLayout(new BorderLayout());
    120122
    121123        /** show the minimize button */
     
    654656    }
    655657
     658    /* use createLayout() instead of self-constructed dialogs */
     659    @Deprecated
    656660    protected JPanel getButtonPanel(int columns) {
    657661        JPanel pnl = new JPanel();
     
    660664        return pnl;
    661665    }
     666
     667    protected void createLayout(Component data, boolean scroll, Collection<SideButton> buttons) {
     668        if(scroll)
     669            add(new JScrollPane(data), BorderLayout.CENTER);
     670        else
     671            add(data, BorderLayout.CENTER);
     672        if(buttons != null && buttons.size() != 0) {
     673            JPanel buttonsPanel = new JPanel();
     674            buttonsPanel.setLayout(Main.pref.getBoolean("dialog.align.left", false)
     675                ? new FlowLayout(FlowLayout.LEFT) : new GridLayout(1,buttons.size()));
     676            for(SideButton button : buttons)
     677                buttonsPanel.add(button);
     678            add(buttonsPanel, BorderLayout.SOUTH);
     679        }
     680    }
    662681}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r4078 r4353  
    1515import java.text.NumberFormat;
    1616import java.util.ArrayList;
     17import java.util.Arrays;
    1718import java.util.Collection;
    1819import java.util.Collections;
     
    2930import javax.swing.JLabel;
    3031import javax.swing.JOptionPane;
    31 import javax.swing.JPanel;
    32 import javax.swing.JScrollPane;
    3332import javax.swing.JTable;
    3433import javax.swing.ListSelectionModel;
     
    8786    }
    8887
    89     protected JPanel buildButtonRow() {
    90         JPanel pnl = getButtonPanel(2);
    91 
    92         // -- select users primitives action
    93         //
    94         selectionUsersPrimitivesAction = new SelectUsersPrimitivesAction();
    95         userTable.getSelectionModel().addListSelectionListener(selectionUsersPrimitivesAction);
    96         pnl.add(new SideButton(selectionUsersPrimitivesAction));
    97 
    98         // -- info action
    99         //
    100         showUserInfoAction = new ShowUserInfoAction();
    101         userTable.getSelectionModel().addListSelectionListener(showUserInfoAction);
    102         pnl.add(new SideButton(showUserInfoAction));
    103 
    104         // -- load relicensing info action
    105         loadRelicensingInformationAction = new LoadRelicensingInformationAction();
    106         pnl.add(new SideButton(loadRelicensingInformationAction));
    107         return pnl;
    108     }
    109 
    11088    protected void build() {
    111         JPanel pnl = new JPanel();
    112         pnl.setLayout(new BorderLayout());
    11389        model = new UserTableModel();
    11490        userTable = new JTable(model);
    11591        userTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
     92        userTable.addMouseListener(new DoubleClickAdapter());
    11693        TableColumnModel columnModel = userTable.getColumnModel();
    11794        columnModel.getColumn(3).setPreferredWidth(20);
     
    125102            };
    126103        });
    127         pnl.add(new JScrollPane(userTable), BorderLayout.CENTER);
    128 
    129         // -- the button row
    130         pnl.add(buildButtonRow(), BorderLayout.SOUTH);
    131         userTable.addMouseListener(new DoubleClickAdapter());
    132         add(pnl, BorderLayout.CENTER);
     104
     105        // -- select users primitives action
     106        //
     107        selectionUsersPrimitivesAction = new SelectUsersPrimitivesAction();
     108        userTable.getSelectionModel().addListSelectionListener(selectionUsersPrimitivesAction);
     109
     110        // -- info action
     111        //
     112        showUserInfoAction = new ShowUserInfoAction();
     113        userTable.getSelectionModel().addListSelectionListener(showUserInfoAction);
     114
     115        // -- load relicensing info action
     116        loadRelicensingInformationAction = new LoadRelicensingInformationAction();
     117
     118        createLayout(userTable, true, Arrays.asList(new SideButton[] {
     119            new SideButton(selectionUsersPrimitivesAction),
     120            new SideButton(showUserInfoAction),
     121            new SideButton(loadRelicensingInformationAction)
     122        }));
    133123    }
    134124
Note: See TracChangeset for help on using the changeset viewer.