Example usage for javax.swing JList setLayoutOrientation

List of usage examples for javax.swing JList setLayoutOrientation

Introduction

In this page you can find the example usage for javax.swing JList setLayoutOrientation.

Prototype

@BeanProperty(visualUpdate = true, enumerationValues = { "JList.VERTICAL", "JList.HORIZONTAL_WRAP",
        "JList.VERTICAL_WRAP" }, description = "Defines the way list cells are layed out.")
public void setLayoutOrientation(int layoutOrientation) 

Source Link

Document

Defines the way list cells are layed out.

Usage

From source file:org.apache.oodt.cas.workflow.gui.perspective.view.impl.DefaultPropView.java

@Override
public void refreshView(final ViewState state) {
    this.removeAll();

    tableMenu = new JPopupMenu("TableMenu");
    this.add(tableMenu);
    override = new JMenuItem(OVERRIDE);
    override.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
            String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
            Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
            if (staticMet == null) {
                staticMet = new Metadata();
            }//w  w w . j  a v a 2s  .  co  m
            if (e.getActionCommand().equals(OVERRIDE)) {
                if (!staticMet.containsKey(key)) {
                    staticMet.addMetadata(key, (String) DefaultPropView.this.table.getValueAt(row, 2));
                    String envReplace = (String) DefaultPropView.this.table.getValueAt(row, 3);
                    if (Boolean.valueOf(envReplace)) {
                        staticMet.addMetadata(key + "/envReplace", envReplace);
                    }
                    state.getSelected().getModel().setStaticMetadata(staticMet);
                    DefaultPropView.this.notifyListeners();
                }
            }
        }
    });
    delete = new JMenuItem(DELETE);
    delete.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            int row = DefaultPropView.this.table.getSelectedRow();// rowAtPoint(DefaultPropView.this.table.getMousePosition());
            String key = getKey((String) DefaultPropView.this.table.getValueAt(row, 1), state);
            Metadata staticMet = state.getSelected().getModel().getStaticMetadata();
            if (staticMet == null) {
                staticMet = new Metadata();
            }
            staticMet.removeMetadata(key);
            staticMet.removeMetadata(key + "/envReplace");
            state.getSelected().getModel().setStaticMetadata(staticMet);
            DefaultPropView.this.notifyListeners();
        }

    });
    tableMenu.add(override);
    tableMenu.add(delete);

    if (state.getSelected() != null) {
        JPanel masterPanel = new JPanel();
        masterPanel.setLayout(new BoxLayout(masterPanel, BoxLayout.Y_AXIS));
        masterPanel.add(this.getModelIdPanel(state.getSelected(), state));
        masterPanel.add(this.getModelNamePanel(state.getSelected(), state));
        if (!state.getSelected().getModel().isParentType()) {
            masterPanel.add(this.getInstanceClassPanel(state.getSelected(), state));
        }
        masterPanel.add(this.getExecutionTypePanel(state.getSelected(), state));
        masterPanel.add(this.getPriorityPanel(state));
        masterPanel.add(this.getExecusedIds(state.getSelected()));
        if (state.getSelected().getModel().getExecutionType().equals("condition")) {
            masterPanel.add(this.getTimeout(state.getSelected(), state));
            masterPanel.add(this.getOptional(state.getSelected(), state));
        }
        JScrollPane scrollPane = new JScrollPane(table = this.createTable(state),
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.getHorizontalScrollBar().setUnitIncrement(10);
        scrollPane.getVerticalScrollBar().setUnitIncrement(10);
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());
        panel.setBorder(new EtchedBorder());
        final JLabel metLabel = new JLabel("Static Metadata");
        metLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        final JLabel extendsLabel = new JLabel("<extends>");
        extendsLabel.setFont(new Font("Serif", Font.PLAIN, 10));
        extendsLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        extendsLabel.addMouseListener(new MouseListener() {

            private JScrollPane availableScroller;
            private JScrollPane mineScroller;
            private JList mineList;
            private JList availableList;
            private DefaultListModel mineModel;
            private DefaultListModel availableModel;

            public void mouseClicked(MouseEvent e) {
                final JPopupMenu popup = new JPopupMenu();
                popup.setLayout(new BorderLayout());

                JPanel main = new JPanel();
                main.setLayout(new BoxLayout(main, BoxLayout.X_AXIS));

                JPanel mine = new JPanel();
                mine.setBorder(new EtchedBorder());
                mine.setLayout(new BorderLayout());
                JLabel mineLabel = new JLabel("Mine");
                mineScroller = new JScrollPane(mineList = createJList(mineModel = new DefaultListModel(),
                        state.getSelected().getModel().getExtendsConfig()));
                mineScroller.setPreferredSize(new Dimension(250, 80));
                mine.add(mineLabel, BorderLayout.NORTH);
                mine.add(mineScroller, BorderLayout.CENTER);

                JPanel available = new JPanel();
                available.setBorder(new EtchedBorder());
                available.setLayout(new BorderLayout());
                JLabel availableLabel = new JLabel("Available");
                Vector<String> availableGroups = new Vector<String>(state.getGlobalConfigGroups().keySet());
                availableGroups.removeAll(state.getSelected().getModel().getExtendsConfig());
                availableScroller = new JScrollPane(availableList = this
                        .createJList(availableModel = new DefaultListModel(), availableGroups));
                availableScroller.setPreferredSize(new Dimension(250, 80));
                available.add(availableLabel, BorderLayout.NORTH);
                available.add(availableScroller, BorderLayout.CENTER);

                JPanel buttons = new JPanel();
                buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS));
                JButton addButton = new JButton("<---");
                addButton.addMouseListener(new MouseListener() {

                    public void mouseClicked(MouseEvent e) {
                        String selected = availableList.getSelectedValue().toString();
                        Vector<String> extendsConfig = new Vector<String>(
                                state.getSelected().getModel().getExtendsConfig());
                        extendsConfig.add(selected);
                        state.getSelected().getModel().setExtendsConfig(extendsConfig);
                        availableModel.remove(availableList.getSelectedIndex());
                        mineModel.addElement(selected);
                        popup.revalidate();
                        DefaultPropView.this.notifyListeners();
                    }

                    public void mouseEntered(MouseEvent e) {
                    }

                    public void mouseExited(MouseEvent e) {
                    }

                    public void mousePressed(MouseEvent e) {
                    }

                    public void mouseReleased(MouseEvent e) {
                    }

                });
                JButton removeButton = new JButton("--->");
                removeButton.addMouseListener(new MouseListener() {

                    public void mouseClicked(MouseEvent e) {
                        String selected = mineList.getSelectedValue().toString();
                        Vector<String> extendsConfig = new Vector<String>(
                                state.getSelected().getModel().getExtendsConfig());
                        extendsConfig.remove(selected);
                        state.getSelected().getModel().setExtendsConfig(extendsConfig);
                        mineModel.remove(mineList.getSelectedIndex());
                        availableModel.addElement(selected);
                        popup.revalidate();
                        DefaultPropView.this.notifyListeners();
                    }

                    public void mouseEntered(MouseEvent e) {
                    }

                    public void mouseExited(MouseEvent e) {
                    }

                    public void mousePressed(MouseEvent e) {
                    }

                    public void mouseReleased(MouseEvent e) {
                    }

                });
                buttons.add(addButton);
                buttons.add(removeButton);

                main.add(mine);
                main.add(buttons);
                main.add(available);
                popup.add(main, BorderLayout.CENTER);
                popup.show(extendsLabel, e.getX(), e.getY());
            }

            public void mouseEntered(MouseEvent e) {
                extendsLabel.setForeground(Color.blue);
            }

            public void mouseExited(MouseEvent e) {
                extendsLabel.setForeground(Color.black);
            }

            public void mousePressed(MouseEvent e) {
            }

            public void mouseReleased(MouseEvent e) {
            }

            private JList createJList(DefaultListModel model, final List<String> list) {
                for (String value : list) {
                    model.addElement(value);
                }
                JList jList = new JList(model);
                jList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
                jList.setLayoutOrientation(JList.VERTICAL);
                return jList;
            }
        });
        JLabel metGroupLabel = new JLabel("(Sub-Group: "
                + (state.getCurrentMetGroup() != null ? state.getCurrentMetGroup() : "<base>") + ")");
        metGroupLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
        JPanel labelPanel = new JPanel();
        labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
        JPanel top = new JPanel();
        top.setLayout(new BoxLayout(top, BoxLayout.Y_AXIS));
        top.add(extendsLabel);
        top.add(metLabel);
        labelPanel.add(top);
        labelPanel.add(metGroupLabel);
        panel.add(labelPanel, BorderLayout.NORTH);
        panel.add(scrollPane, BorderLayout.CENTER);
        masterPanel.add(panel);
        this.add(masterPanel);
    } else {
        this.add(new JPanel());
    }
    this.revalidate();
}