private void initComponents()

in taverna-contextual-views-impl/src/main/java/org/apache/taverna/workbench/ui/views/contextualviews/merge/MergeConfigurationView.java [93:240]


	private void initComponents() {
        getContentPane().setLayout(new BorderLayout());

		JPanel listPanel = new JPanel();
		listPanel.setLayout(new BorderLayout());
		listPanel.setBorder(new CompoundBorder(new EmptyBorder(10, 10, 10, 10),
				new EtchedBorder()));

		JLabel title = new JLabel(TITLE);
		title.setBorder(new EmptyBorder(5, 5, 5, 5));
		listPanel.add(title, NORTH);

		list = new JList<>(labelListModel);
		list.setSelectionMode(SINGLE_SELECTION);
		list.setVisibleRowCount(-1);
		list.addListSelectionListener(new ListSelectionListener() {
			/**
			 * Enable and disable up and down buttons based on which item in the
			 * list is selected
			 */
			@Override
			public void valueChanged(ListSelectionEvent e) {
				int index = list.getSelectedIndex();
				if ((index == -1) || (index == 0 && labelListModel.size() == 0)) {
					// nothing selected or only one item in the list
					upButton.setEnabled(false);
					downButton.setEnabled(false);
				} else {
					upButton.setEnabled(index > 0);
					downButton.setEnabled(index < labelListModel.size() - 1);
				}
			}
		});

		final JScrollPane listScroller = new JScrollPane(list);
		listScroller.setBorder(new EmptyBorder(5, 5, 5, 5));
		listScroller.setBackground(listPanel.getBackground());
		listScroller.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_ALWAYS);
		listScroller.setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
		// Set the size of scroll pane to make all list items visible
		FontMetrics fm = listScroller.getFontMetrics(this.getFont());
		int listScrollerHeight = fm.getHeight() * labelListModel.size() + 75; //+75 just in case
		listScroller.setPreferredSize(new Dimension(listScroller
				.getPreferredSize().width, max(listScrollerHeight,
				listScroller.getPreferredSize().height)));
		listPanel.add(listScroller, BorderLayout.CENTER);

		JPanel upDownButtonPanel = new JPanel();
		upDownButtonPanel.setLayout(new BoxLayout(upDownButtonPanel, Y_AXIS));
		upDownButtonPanel.setBorder(new EmptyBorder(5, 5, 5, 5));

		upButton = new JButton(new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int index = list.getSelectedIndex();
				if (index != -1) {
					// Swap the labels
					String label = (String) labelListModel.elementAt(index);
					labelListModel.set(index, labelListModel.get(index - 1));
					labelListModel.set(index - 1, label);
					// Swap the dataLinks
					DataLink dataLink = reorderedDataLinks.get(index);
					reorderedDataLinks.set(index,
							reorderedDataLinks.get(index - 1));
					reorderedDataLinks.set(index - 1, dataLink);
					// Make the pushed item selected
					list.setSelectedIndex(index - 1);
					// Refresh the list
					listScroller.repaint();
					listScroller.revalidate();
				}
			}
		});
		upButton.setIcon(upArrowIcon);
		upButton.setText("Up");
	    // Place text to the right of icon, vertically centered
		upButton.setVerticalTextPosition(CENTER);
		upButton.setHorizontalTextPosition(RIGHT);
		// Set the horizontal alignment of the icon and text
		upButton.setHorizontalAlignment(LEFT);
		upButton.setEnabled(false);
		upDownButtonPanel.add(upButton);

		downButton = new JButton(new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent e) {
				int index = list.getSelectedIndex();
				if (index != -1) {
					// Swap the labels
					String label = (String) labelListModel.elementAt(index);
					labelListModel.set(index, labelListModel.get(index + 1));
					labelListModel.set(index + 1, label);
					// Swap the dataLinks
					DataLink dataLink = reorderedDataLinks.get(index);
					reorderedDataLinks.set(index,
							reorderedDataLinks.get(index + 1));
					reorderedDataLinks.set(index + 1, dataLink);
					// Make the pushed item selected
					list.setSelectedIndex(index + 1);
					// Refresh the list
					list.repaint();
					listScroller.revalidate();
				}
			}
		});
		downButton.setIcon(downArrowIcon);
		downButton.setText("Down");
	    // Place text to the right of icon, vertically centered
		downButton.setVerticalTextPosition(CENTER);
		downButton.setHorizontalTextPosition(RIGHT);
		// Set the horizontal alignment of the icon and text
		downButton.setHorizontalAlignment(LEFT);
		downButton.setEnabled(false);
		// set the up button to be of the same size as down button
		upButton.setPreferredSize(downButton.getPreferredSize());
		upButton.setMaximumSize(downButton.getPreferredSize());
		upButton.setMinimumSize(downButton.getPreferredSize());
		upDownButtonPanel.add(downButton);

		listPanel.add(upDownButtonPanel, EAST);

		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));

		JButton jbOK = new JButton("OK");
		jbOK.addActionListener(new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new MergeConfigurationAction(dataLinks, reorderedDataLinks,
						editManager, selectionManager).actionPerformed(e);
				closeDialog();
			}
		});

		JButton jbCancel = new JButton("Cancel");
		jbCancel.addActionListener(new AbstractAction() {
			@Override
			public void actionPerformed(ActionEvent e) {
				closeDialog();
			}
		});

        buttonPanel.add(jbOK);
        buttonPanel.add(jbCancel);

        getContentPane().add(listPanel, BorderLayout.CENTER);
        getContentPane().add(buttonPanel, SOUTH);
        pack();
	}