Example usage for javax.swing JList JList

List of usage examples for javax.swing JList JList

Introduction

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

Prototype

public JList(final Vector<? extends E> listData) 

Source Link

Document

Constructs a JList that displays the elements in the specified Vector.

Usage

From source file:BRHInit.java

public void showVPSPrompt(JSONArray vps) throws Exception {
    vps_list = vps;/*from  w ww .j  a  va2s.  co m*/

    if (vps_list_window == null) {
        vps_list_window = new JFrame("BRH Console");
        vps_list_window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JPanel top_panel = new JPanel();
        vps_list_window.getContentPane().add(top_panel);

        top_panel.setLayout(new BoxLayout(top_panel, BoxLayout.Y_AXIS));
        top_panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        Vector values = new Vector();
        for (int idx = 0; idx < vps_list.length(); ++idx) {
            JSONArray row = vps_list.getJSONArray(idx);
            values.addElement(row.getString(1));
        }

        vps_list_box = new JList(values);
        top_panel.add(new JScrollPane(vps_list_box));

        vps_list_box.setVisibleRowCount(10);

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

        JPanel col_panel = new JPanel();
        p.add(col_panel);
        col_panel.setLayout(new BoxLayout(col_panel, BoxLayout.Y_AXIS));

        col_panel.add(new JLabel("email"));
        col_panel.add(Box.createRigidArea(new Dimension(0, 5)));
        col_panel.add(new JLabel("password"));

        p.add(Box.createRigidArea(new Dimension(5, 0)));

        col_panel = new JPanel();
        p.add(col_panel);
        col_panel.setLayout(new BoxLayout(col_panel, BoxLayout.Y_AXIS));

        col_panel.add(email = new JTextField(20));
        col_panel.add(Box.createRigidArea(new Dimension(0, 5)));
        col_panel.add(password = new JPasswordField());

        top_panel.add(Box.createRigidArea(new Dimension(0, 10)));

        p = new JPanel();
        top_panel.add(p);
        p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));

        p.add(Box.createHorizontalGlue());
        p.add(vps_list_ok = new JButton("OK"));
        p.add(Box.createRigidArea(new Dimension(5, 0)));
        p.add(vps_list_cancel = new JButton("Cancel"));
        p.add(Box.createHorizontalGlue());

        vps_list_ok.addActionListener(this);
        vps_list_cancel.addActionListener(this);

        vps_list_window.pack();
    }

    vps_list_window.setVisible(true);
}

From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java

/**
 * //from   w w  w .ja va2 s.c  om
 */
protected void createUI() {
    CellConstraints cc = new CellConstraints();
    PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,p:g", "p,2px,f:p:g,4px,p,2px,p,10px,p"));

    missingFieldsList = new JList(new DefaultListModel());

    formsTable = new JTable(new FormCellModel(forms));
    formsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (formsTable.getSelectedRow() > -1) {
                formSelected();
            }
        }
    });

    fieldsTable = new JTable(fieldsTableModel = new FieldCellModel());

    TableColumn col = fieldsTable.getColumnModel().getColumn(1);
    col.setCellEditor(sp6FieldEditor = new Sp6FieldComboBoxEditor());

    // If the cell should appear like a combobox in its
    // non-editing state, also set the combobox renderer
    //col.setCellRenderer(sp6FieldRenderer = new Sp6FieldComboBoxRenderer());

    calcColumnWidths(formsTable);

    PanelBuilder pbBtn = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g", "p"));
    reportBtn = createButton("Create Form Images");
    showBtn = createButton("Show");
    schemaBtn = createButton("Schema");
    dataCheckerBtn = createButton("Check For Nulls");
    pbBtn.add(reportBtn, cc.xy(2, 1));
    pbBtn.add(schemaBtn, cc.xy(4, 1));
    pbBtn.add(showBtn, cc.xy(6, 1));
    pbBtn.add(dataCheckerBtn, cc.xy(8, 1));

    pb.add(createLabel("Forms", SwingConstants.CENTER), cc.xy(1, 1));
    pb.add(createLabel("Missing Fields", SwingConstants.CENTER), cc.xy(3, 1));

    pb.add(createScrollPane(formsTable), cc.xy(1, 3));
    pb.add(createScrollPane(missingFieldsList), cc.xy(3, 3));

    pb.add(createLabel("Form Fields", SwingConstants.CENTER), cc.xyw(1, 5, 3));
    pb.add(createScrollPane(fieldsTable), cc.xyw(1, 7, 3));

    pb.add(pbBtn.getPanel(), cc.xyw(1, 9, 3));
    pb.setDefaultDialogBorder();

    setContentPane(new JScrollPane(pb.getPanel()));

    showBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showForm();
        }
    });
    reportBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doCreateFormImages();
        }
    });
    schemaBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSchema();
        }
    });

    dataCheckerBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            TableDataChecker tdc = new TableDataChecker(DBConnection.getInstance().createConnection());
            tdc.doCheckDB();
        }
    });

}

From source file:org.gumtree.vis.plot1d.Plot1DChartEditor.java

private JPanel createHelpPanel(JFreeChart chart) {
    JPanel wrap = new JPanel(new GridLayout(1, 1));

    JPanel helpPanel = new JPanel(new GridLayout(1, 1));
    helpPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    //       helpPanel.setBorder(BorderFactory.createTitledBorder(
    //            BorderFactory.createEtchedBorder(), "Help Topics"));

    SpringLayout spring = new SpringLayout();
    JPanel inner = new JPanel(spring);
    inner.setBorder(BorderFactory.createEmptyBorder());

    final IHelpProvider provider = new Plot1DHelpProvider();
    final JList list = new JList(provider.getHelpMap().keySet().toArray());
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    //      list.setBorder(BorderFactory.createEtchedBorder());
    JScrollPane listPane1 = new JScrollPane(list);
    inner.add(listPane1);/*from www  .ja  v a 2 s  . c o  m*/
    listPane1.setMaximumSize(new Dimension(140, 0));
    listPane1.setMinimumSize(new Dimension(70, 0));
    //      JPanel contentPanel = new JPanel(new GridLayout(2, 1));
    //      inner.add(list);
    final JTextField keyField = new JTextField();
    keyField.setMaximumSize(new Dimension(400, 20));
    keyField.setEditable(false);
    //      keyField.setMaximumSize();
    //      keyArea.setLineWrap(true);
    //      keyArea.setWrapStyleWord(true);
    //      keyArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(keyField);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    final JTextArea helpArea = new JTextArea();
    JScrollPane areaPane = new JScrollPane(helpArea);
    helpArea.setEditable(false);
    helpArea.setLineWrap(true);
    helpArea.setWrapStyleWord(true);
    //      helpArea.setBorder(BorderFactory.createEtchedBorder());
    inner.add(areaPane);
    //      contentPanel.add(new JLabel());
    //      contentPanel.add(new JLabel());
    //      inner.add(contentPanel);
    spring.putConstraint(SpringLayout.WEST, listPane1, 2, SpringLayout.WEST, inner);
    spring.putConstraint(SpringLayout.NORTH, listPane1, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.WEST, keyField, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, keyField, 2, SpringLayout.NORTH, inner);
    spring.putConstraint(SpringLayout.EAST, inner, 2, SpringLayout.EAST, keyField);
    spring.putConstraint(SpringLayout.WEST, areaPane, 4, SpringLayout.EAST, listPane1);
    spring.putConstraint(SpringLayout.NORTH, areaPane, 4, SpringLayout.SOUTH, keyField);
    spring.putConstraint(SpringLayout.EAST, areaPane, -2, SpringLayout.EAST, inner);
    spring.putConstraint(SpringLayout.SOUTH, inner, 2, SpringLayout.SOUTH, areaPane);
    spring.putConstraint(SpringLayout.SOUTH, listPane1, -2, SpringLayout.SOUTH, inner);

    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            Object[] selected = list.getSelectedValues();
            if (selected.length >= 0) {
                HelpObject help = provider.getHelpMap().get(selected[0]);
                if (help != null) {
                    keyField.setText(help.getKey());
                    helpArea.setText(help.getDiscription());
                }
            }
        }
    });

    helpPanel.add(inner, BorderLayout.NORTH);
    wrap.setName("Help");

    wrap.add(helpPanel, BorderLayout.NORTH);
    return wrap;

}

From source file:ca.sqlpower.wabit.swingui.enterprise.UserPanel.java

public UserPanel(User baseUser) {
    final MessageDigest digester;
    try {/* w  w  w .  j av  a  2 s  . c o  m*/
        digester = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e1) {
        throw new RuntimeException(e1);
    }
    this.user = baseUser;
    this.workspace = (WabitWorkspace) this.user.getParent();

    this.loginTextField = new JTextField();
    this.loginTextField.setText(user.getName());
    this.loginLabel = new JLabel("User name");
    this.loginTextField.getDocument().addDocumentListener(new DocumentListener() {

        public void textChanged(DocumentEvent e) {
            user.setName(loginTextField.getText());
        }

        public void changedUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void insertUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void removeUpdate(DocumentEvent e) {
            textChanged(e);
        }
    });

    this.passwordTextField = new JPasswordField();
    this.passwordLabel = new JLabel("Password");
    this.passwordTextField.getDocument().addDocumentListener(new DocumentListener() {
        public void textChanged(DocumentEvent e) {
            try {
                String pass = new String(passwordTextField.getPassword());
                String encoded = new String(Hex.encodeHex(digester.digest(pass.getBytes("UTF-8"))));
                user.setPassword(encoded);
            } catch (UnsupportedEncodingException e1) {
                throw new RuntimeException(e1);
            }
        }

        public void changedUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void insertUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void removeUpdate(DocumentEvent e) {
            textChanged(e);
        }
    });

    this.fullNameTextField = new JTextField();
    this.fullNameTextField.setText(user.getFullName());
    this.fullNameLabel = new JLabel("Full name");
    this.fullNameTextField.getDocument().addDocumentListener(new DocumentListener() {

        public void textChanged(DocumentEvent e) {
            user.setFullName(fullNameTextField.getText());
        }

        public void changedUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void insertUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void removeUpdate(DocumentEvent e) {
            textChanged(e);
        }
    });

    this.emailTextField = new JTextField();
    this.emailTextField.setText(user.getEmail());
    this.emailLabel = new JLabel("Email");
    this.emailTextField.getDocument().addDocumentListener(new DocumentListener() {

        public void textChanged(DocumentEvent e) {
            user.setEmail(emailTextField.getText());
        }

        public void changedUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void insertUpdate(DocumentEvent e) {
            textChanged(e);
        }

        public void removeUpdate(DocumentEvent e) {
            textChanged(e);
        }
    });

    this.availableGroupsLabel = new JLabel("Available Groups");
    this.availableGroupsListModel = new GroupsListModel(user, workspace, false);
    this.availableGroupsList = new JList(this.availableGroupsListModel);
    this.availableGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.availableGroupsList.setCellRenderer(new DefaultListCellRenderer() {
        final JTree dummyTree = new JTree();
        final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer();

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0,
                    cellHasFocus);
        }
    });
    this.availableGroupsScrollPane = new JScrollPane(this.availableGroupsList);

    this.currentGroupsLabel = new JLabel("Current Memberships");
    this.currentGroupsListModel = new GroupsListModel(user, workspace, true);
    this.currentGroupsList = new JList(this.currentGroupsListModel);
    this.currentGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.currentGroupsList.setCellRenderer(new DefaultListCellRenderer() {
        final JTree dummyTree = new JTree();
        final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer();

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0,
                    cellHasFocus);
        }
    });
    this.groupsLabel = new JLabel("Edit user memberships");
    this.currentGroupsScrollPane = new JScrollPane(this.currentGroupsList);

    this.addButton = new JButton(">");
    this.addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object[] selection = availableGroupsList.getSelectedValues();
            if (selection.length == 0) {
                return;
            }
            try {
                workspace.begin("Add user to groups");
                for (Object object : selection) {
                    ((Group) object).addMember(new GroupMember(user));
                }
            } finally {
                workspace.commit();
            }
        }
    });

    this.removeButton = new JButton("<");
    this.removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object[] selection = currentGroupsList.getSelectedValues();
            if (selection.length == 0) {
                return;
            }
            try {
                workspace.begin("Remove user from groups");
                Map<Group, GroupMember> toRemove = new ArrayMap<Group, GroupMember>();
                for (Object object : selection) {
                    for (GroupMember membership : ((Group) object).getChildren(GroupMember.class)) {
                        if (membership.getUser().getUUID().equals(user.getUUID())) {
                            toRemove.put((Group) object, membership);
                        }
                    }
                }
                for (Entry<Group, GroupMember> entry : toRemove.entrySet()) {
                    entry.getKey().removeMember(entry.getValue());
                }
            } finally {
                workspace.commit();
            }
        }
    });

    Action deleteAction = new DeleteFromTreeAction(this.workspace, this.user, this.panel,
            this.workspace.getSession().getContext());
    this.toolbarBuilder.add(deleteAction, "Delete this user", WabitIcons.DELETE_ICON_32);

    // Panel building time
    JPanel namePassPanel = new JPanel(new MigLayout());
    namePassPanel.add(this.loginLabel, "align right, gaptop 20");
    namePassPanel.add(this.loginTextField, "span, wrap, wmin 600");
    namePassPanel.add(this.passwordLabel, "align right");
    namePassPanel.add(this.passwordTextField, "span, wrap, wmin 600");
    namePassPanel.add(this.fullNameLabel, "align right, gaptop 20");
    namePassPanel.add(this.fullNameTextField, "span, wrap, wmin 600");
    namePassPanel.add(this.emailLabel, "align right");
    namePassPanel.add(this.emailTextField, "span, wrap, wmin 600");
    this.panel.add(namePassPanel, "north");

    this.panel.add(this.groupsLabel, "span, wrap, gaptop 20, align center");

    JPanel buttonsPanel = new JPanel(new MigLayout());
    buttonsPanel.add(this.addButton, "wrap");
    buttonsPanel.add(this.removeButton);
    JPanel availablePanel = new JPanel(new MigLayout());
    availablePanel.add(this.availableGroupsLabel, "wrap, align center");
    availablePanel.add(this.availableGroupsScrollPane, "wmin 300");
    JPanel currentPanel = new JPanel(new MigLayout());
    currentPanel.add(this.currentGroupsLabel, "wrap, align center");
    currentPanel.add(this.currentGroupsScrollPane, "wmin 300");
    this.panel.add(availablePanel);
    this.panel.add(buttonsPanel, "shrink, span 1 2");
    this.panel.add(currentPanel);
}

From source file:edu.ku.brc.specify.utilapps.RegisterApp.java

/**
 * /* ww  w  .j  a  v  a 2 s  . c o m*/
 */
protected void createUI() {
    JTabbedPane tabbedPane = new JTabbedPane();

    rp = new RegProcessor();
    rp.processSQL();

    tree = new JTree(rp.getRoot(INCL_ANON));
    propsTable = new JTable();

    tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
        @Override
        public void valueChanged(TreeSelectionEvent e) {
            fillPropsTable();
        }
    });
    tree.setCellRenderer(new MyTreeCellRenderer());

    Component topComp = UIHelper.createScrollPane(tree);
    Component botComp = UIHelper.createScrollPane(propsTable);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp);

    splitPane.setDividerLocation(0.5);
    splitPane.setOneTouchExpandable(true);

    splitPane.setLastDividerLocation(300);
    Dimension minimumSize = new Dimension(200, 400);
    topComp.setMinimumSize(minimumSize);
    botComp.setMinimumSize(minimumSize);

    tabbedPane.add("Registration", splitPane);

    final List<Pair<String, String>> trackDescPairs = rp.getTrackKeyDescPairs();
    Vector<String> trkItems = new Vector<String>();
    for (Pair<String, String> p : trackDescPairs) {
        trkItems.add(p.second);
    }

    //Collections.sort(trkItems);
    final JList list = new JList(trkItems);
    //pb.add(UIHelper.createScrollPane(list), cc.xy(1, 1));
    list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int inx = list.getSelectedIndex();
                if (inx > -1) {
                    fillUsageItemsList(trackDescPairs.get(inx).first);
                }
            }
        }
    });

    tabbedPane.add("Reg Stats", getStatsPane("Registration", rp.getRegNumHash().values(), "register"));

    DefaultListModel model = new DefaultListModel();
    trackItemsList = new JList(model);

    topComp = UIHelper.createScrollPane(list);
    botComp = UIHelper.createScrollPane(trackItemsList);
    splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topComp, botComp);
    splitPane.setDividerLocation(0.5);
    splitPane.setOneTouchExpandable(true);

    topComp.setMinimumSize(minimumSize);
    botComp.setMinimumSize(minimumSize);

    splitPane.setDividerLocation(0.5);
    trackUsageHash = rp.getTrackCatsHash();
    tabbedPane.add("Usage Tracking", splitPane);

    tabbedPane.add("User Stats", getStatsPane("Tracking", rp.getTrackIdHash().values(), "track"));

    add(tabbedPane, BorderLayout.CENTER);
}

From source file:edu.ku.brc.specify.tasks.subpane.lm.LifeMapperPane.java

/**
 * Creates the UI.//  ww  w.jav  a2 s  .  c  om
 */
@SuppressWarnings("unchecked")
protected void createUI() {
    currentSize = getCurrentSizeSquare();

    searchText = createTextField(25);
    searchSciNameBtn = createI18NButton("LM_SEARCH");
    list = new JList(listModel);
    imgDisplay = new ImageDisplay(IMG_WIDTH, IMG_HEIGHT, false, true);

    imgDisplay.setChangeListener(this);

    wwPanel = new WorldWindPanel(false);
    wwPanel.setPreferredSize(new Dimension(currentSize, currentSize));
    wwPanel.setZoomInMeters(600000.0);

    imgDisplay.setDoShowText(false);

    searchMyDataBtn = createI18NButton("LM_SRCH_SP_DATA");
    myDataTF = UIHelper.createTextField();

    CellConstraints cc = new CellConstraints();

    PanelBuilder pb1 = new PanelBuilder(new FormLayout("p,2px,f:p:g,2px,p", "p"));
    pb1.add(createI18NFormLabel("LM_SRCH_COL"), cc.xy(1, 1));
    pb1.add(searchText, cc.xy(3, 1));
    pb1.add(searchSciNameBtn, cc.xy(5, 1));

    PanelBuilder myPB = new PanelBuilder(new FormLayout("f:p:g,p", "p,2px,p,2px,p"));
    mySepComp = myPB.addSeparator(getResourceString("LM_MYDATA_TITLE"), cc.xyw(1, 1, 2));
    myPB.add(myDataTF, cc.xyw(1, 3, 2));
    myPB.add(searchMyDataBtn, cc.xy(2, 5));

    PanelBuilder pb2 = new PanelBuilder(new FormLayout("MAX(p;300px),2px,f:p:g", "f:p:g,20px,p"));
    pb2.add(createScrollPane(list), cc.xy(1, 1));
    pb2.add(myPB.getPanel(), cc.xy(1, 3));

    PanelBuilder pb3 = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g", "f:p:g,p,4px,p,f:p:g"));
    pb3.add(createI18NLabel("LM_WRLD_OVRVW", SwingConstants.CENTER), cc.xy(2, 2));
    pb3.add(imgDisplay, cc.xy(2, 4));

    PanelBuilder pb4 = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g", "f:p:g,p,4px,p,f:p:g"));
    pb4.add(createI18NLabel("LM_INTRACT_VW", SwingConstants.CENTER), cc.xy(2, 2));
    pb4.add(wwPanel, cc.xy(2, 4));

    PanelBuilder pb5 = new PanelBuilder(new FormLayout("f:p:g", "f:p:g,p,f:p:g"));
    pb5.add(pb3.getPanel(), cc.xy(1, 1));
    pb5.add(pb4.getPanel(), cc.xy(1, 3));

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,8px,f:p:g", "p,8px,f:p:g"), this);
    pb.add(pb1.getPanel(), cc.xyw(1, 1, 3));
    pb.add(pb2.getPanel(), cc.xy(1, 3));
    pb.add(pb5.getPanel(), cc.xy(3, 3));

    updateMyDataUIState(false);

    searchText.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                searchSciNameBtn.doClick();
            }
        }
    });

    myDataTF.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                searchMyDataBtn.doClick();
            }
        }
    });

    list.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                if (list.getSelectedIndex() == -1) {
                    wwPanel.reset();
                    imgDisplay.setImage(blueMarble);

                } else {
                    SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() {
                        @Override
                        protected Boolean doInBackground() throws Exception {
                            if (doResetWWPanel) {
                                wwPanel.reset();
                            }
                            doSearchOccur();
                            return null;
                        }

                        @Override
                        protected void done() {
                            imgDisplay.repaint();
                        }
                    };
                    worker.execute();
                }
            }
        }
    });

    searchMyDataBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    doSearchSpecifyData(myDataTF.getText().trim());
                }
            });

        }
    });

    searchSciNameBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doSearchGenusSpecies();
        }
    });

    blueMarbleListener = new BufferedImageFetcherIFace() {
        @Override
        public void imageFetched(BufferedImage image) {
            blueMarble = image;
            imgDisplay.setImage(blueMarble);
        }

        @Override
        public void error() {
            blueMarbleTries++;
            if (blueMarbleTries < 5) {
                blueMarbleRetry();
            }
        }
    };

    blueMarbleURL = BG_URL + String.format("WIDTH=%d&HEIGHT=%d", IMG_WIDTH, IMG_HEIGHT);

    pointsMapImageListener = new BufferedImageFetcherIFace() {
        @Override
        public void imageFetched(final BufferedImage image) {
            if (renderImage == null) {
                renderImage = new BufferedImage(IMG_WIDTH, IMG_HEIGHT, BufferedImage.TYPE_INT_ARGB);
            }
            Graphics2D g2d = renderImage.createGraphics();
            if (g2d != null) {
                g2d.fillRect(0, 0, IMG_WIDTH, IMG_HEIGHT);
                if (blueMarble != null) {
                    g2d.drawImage(blueMarble, 0, 0, null);
                }
                if (image != null) {
                    g2d.drawImage(image, 0, 0, null);
                }
                g2d.dispose();

                imgDisplay.setImage(renderImage);
            }
        }

        @Override
        public void error() {
        }
    };
    blueMarbleRetry();
}

From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java

/**
 * Creates the UI.//from  www.j  av  a 2s .  com
 */
protected void createUI() {
    CellConstraints cc = new CellConstraints();

    lineLayer = new RenderableLayer();

    upBtn = UIHelper.createIconBtn("Green Arrow Up", "", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            moveItems(recSetList, botIdHash, dbObjList, topIdHash);
        }
    });

    dwnBtn = UIHelper.createIconBtn("Green Arrow Down", "", new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            moveItems(dbObjList, topIdHash, recSetList, botIdHash);

            boolean hasItems = recSetList.getModel().getSize() > 0;
            rsBtn.setEnabled(hasItems);
            fmBtn.setEnabled(hasItems);

        }
    });

    selectAllBtn = UIHelper.createI18NButton("SELECTALL");
    selectAllBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dbObjList.clearSelection();
            dbObjList.getSelectionModel().setSelectionInterval(0, dbObjList.getModel().getSize());
        }
    });
    deselectAllBtn = UIHelper.createI18NButton("DESELECTALL");
    deselectAllBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dbObjList.clearSelection();
        }
    });

    PanelBuilder upDwnPB = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g,p,10px,p,f:p:g,p,f:p:g", "p"));
    //upDwnPB.add(selectAllBtn,   cc.xy(2,1));
    upDwnPB.add(dwnBtn, cc.xy(4, 1));
    upDwnPB.add(upBtn, cc.xy(6, 1));
    //upDwnPB.add(deselectAllBtn, cc.xy(7,1));

    dbObjList = new JList(new DefaultListModel());
    dbObjList.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    //wpList.setCellRenderer(new WPListCellRenderer());
    dbObjList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            upBtn.setEnabled(false);
            dwnBtn.setEnabled(dbObjList.getSelectedIndex() != -1);
        }
    });

    recSetList = new JList(new DefaultListModel());
    recSetList.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    //trkList.setCellRenderer(new TrkListCellRenderer());
    recSetList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            boolean isSel = recSetList.getSelectedIndex() != -1;
            dwnBtn.setEnabled(false);
            upBtn.setEnabled(isSel);
        }
    });

    rsBtn = UIHelper.createIconBtn("Record_Set", IconManager.IconSize.Std24, "", null);
    fmBtn = UIHelper.createIconBtn("FormEdit", IconManager.IconSize.Std24, "", null);
    PanelBuilder toolsBtnPB = new PanelBuilder(new FormLayout("f:p:g,2px,p,2px,p", "p"));
    toolsBtnPB.add(fmBtn, cc.xy(3, 1));
    toolsBtnPB.add(rsBtn, cc.xy(5, 1));

    PanelBuilder leftPB = new PanelBuilder(
            new FormLayout("min(p;250px),10px,f:p:g", "p,2px,f:p:g, 4px,p,4px, p,2px,f:p:g, 2px,p"));

    int y = 1;
    leftPB.add(topLbl = UIHelper.createLabel("Available Points"), cc.xy(1, y));
    y += 2; // I18N
    leftPB.add(UIHelper.createScrollPane(dbObjList, true), cc.xy(1, y));
    y += 2;

    leftPB.add(upDwnPB.getPanel(), cc.xy(1, y));
    y += 2;

    leftPB.add(UIHelper.createLabel("Selected Objects"), cc.xy(1, y));
    y += 2;
    leftPB.add(UIHelper.createScrollPane(recSetList, true), cc.xy(1, y));
    y += 2;

    leftPB.add(toolsBtnPB.getPanel(), cc.xy(1, y));
    y += 2;

    wwPanel = new WorldWindPanel();
    wwPanel.setPreferredSize(new Dimension(MAP_WIDTH, MAP_HEIGHT));
    wwPanel.getWorld().addSelectListener(new ClickAndGoSelectListener(wwPanel.getWorld(), MarkerLayer.class));
    //wwPanel.getWorld().addSelectListener(getWWSelectListener());
    //wwPanel.getWorld().getInputHandler().addMouseListener(getWWMouseAdapter());

    PanelBuilder rightPB = new PanelBuilder(new FormLayout("f:p:g", "f:p:g"));

    // ZZZ lineBuilder = new LineBuilder(wwPanel.getWorld(), lineLayer, polyline);
    rightPB.add(wwPanel, cc.xy(1, 1));
    y += 2;

    polyline.setAntiAliasHint(Polyline.ANTIALIAS_NICEST);
    polyline.setLineWidth(1.5);
    polyline.setFollowTerrain(true);

    startBtn = UIHelper.createI18NButton("Start");
    endBtn = UIHelper.createI18NButton("End");
    searchBtn = UIHelper.createI18NButton("SEARCH");
    clearAllBtn = UIHelper.createI18NButton("Clear All");
    clearSearchBtn = UIHelper.createI18NButton("Clear Search");

    typeCBX = UIHelper.createComboBox(TABLE_INFO);

    PanelBuilder btnPB = new PanelBuilder(
            new FormLayout("f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g", "p"));
    btnPB.add(typeCBX, cc.xy(2, 1));
    btnPB.add(startBtn, cc.xy(4, 1));
    btnPB.add(endBtn, cc.xy(6, 1));
    btnPB.add(searchBtn, cc.xy(8, 1));
    btnPB.add(clearSearchBtn, cc.xy(10, 1));
    btnPB.add(clearAllBtn, cc.xy(12, 1));

    PanelBuilder pb = new PanelBuilder(new FormLayout("p,10px,f:p:g", "f:p:g, 4px, p"), this);

    pb.add(leftPB.getPanel(), cc.xy(1, 1));
    pb.add(rightPB.getPanel(), cc.xy(3, 1));
    pb.add(btnPB.getPanel(), cc.xyw(1, 3, 3));
    pb.setDefaultDialogBorder();

    startBtn.setEnabled(true);
    endBtn.setEnabled(false);
    searchBtn.setEnabled(false);
    clearAllBtn.setEnabled(false);
    clearSearchBtn.setEnabled(false);

    rsBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            RecordSetIFace rs = createRecordSet();
            if (rs != null) {
                CommandDispatcher.dispatch(new CommandAction(RecordSetTask.RECORD_SET, "Save", null, null, rs));
            }
        }
    });

    fmBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            RecordSetIFace rs = createRecordSet();
            if (rs != null) {
                CommandDispatcher
                        .dispatch(new CommandAction(DataEntryTask.DATA_ENTRY, DataEntryTask.EDIT_DATA, rs));
            }
        }
    });

    searchBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                doSearch();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    });

    startBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (true) {
                //doSearch();
                //return;
            }
            /*
            double lat = 37.24517;
            double lon = -100.99083;
                    
            double[] p = new double[] {-100.90805562872109,37.24714676134192,
                                    -101.1442623355922,37.15441022126542,
                                    -100.78757107464702,37.1712467680786,
                                    -100.90570697458969,37.24401619379327,
                                    -100.90805562872109,37.24714676134192};
            ArrayList<Position> list = new ArrayList<Position>();
            for (int i=0;i<p.length;i++)
            {
            Position pos = Position.fromDegrees(p[i+1], p[i], 0);
            list.add(pos);
            i++;
            }
            polygon = new Polyline(list);
            polygon.setClosed(true);
                    
            Position pos = Position.fromDegrees(lat, lon, 0.0);
            System.out.println("isLocationInside: "+GeometryMath.isLocationInside(pos, polygon.getPositions()));
            */

            //polygonWWPoints.clear();
            isCreatingPolygon = true;
            searchBtn.setEnabled(false);
            endBtn.setEnabled(true);
            startBtn.setEnabled(false);
            // ZZZ lineBuilder.setArmed(true);
        }
    });

    endBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            polyline.setClosed(true);
            isCreatingPolygon = false;
            searchBtn.setEnabled(true);
            endBtn.setEnabled(false);
            startBtn.setEnabled(false);
            searchBtn.setEnabled(true);
            clearAllBtn.setEnabled(true);
            clearSearchBtn.setEnabled(true);

            //polygonWWPoints.add(polygonWWPoints.get(0));
            //createPolyline();

            // ZZZ lineBuilder.setArmed(false);

        }
    });

    clearAllBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doClearAll(true);
        }
    });

    clearSearchBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doClearAll(false);
        }
    });

    typeCBX.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doPickedNewObjType();
        }
    });

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            typeCBX.setSelectedIndex(0);
        }
    });
}

From source file:LocationSensitiveDemo.java

public LocationSensitiveDemo() {
    super("Location Sensitive Drag and Drop Demo");

    treeModel = getDefaultTreeModel();/*from   w  w  w. jav  a  2  s. com*/
    tree = new JTree(treeModel);
    tree.setBorder(BorderFactory.createEmptyBorder(2, 4, 2, 4));
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    tree.setDropMode(DropMode.ON);
    namesPath = tree.getPathForRow(2);
    tree.expandRow(2);
    tree.expandRow(1);
    tree.setRowHeight(0);

    tree.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // for the demo, we'll only support drops (not clipboard paste)
            if (!info.isDrop()) {
                return false;
            }

            String item = (String) indicateCombo.getSelectedItem();

            if (item.equals("Always")) {
                info.setShowDropLocation(true);
            } else if (item.equals("Never")) {
                info.setShowDropLocation(false);
            }

            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            // fetch the drop location
            JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();

            TreePath path = dl.getPath();

            // we don't support invalid paths or descendants of the names folder
            if (path == null || namesPath.isDescendant(path)) {
                return false;
            }

            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            // if we can't handle the import, say so
            if (!canImport(info)) {
                return false;
            }

            // fetch the drop location
            JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();

            // fetch the path and child index from the drop location
            TreePath path = dl.getPath();
            int childIndex = dl.getChildIndex();

            // fetch the data and bail if this fails
            String data;
            try {
                data = (String) info.getTransferable().getTransferData(DataFlavor.stringFlavor);
            } catch (UnsupportedFlavorException e) {
                return false;
            } catch (IOException e) {
                return false;
            }

            // if child index is -1, the drop was on top of the path, so we'll
            // treat it as inserting at the end of that path's list of children
            if (childIndex == -1) {
                childIndex = tree.getModel().getChildCount(path.getLastPathComponent());
            }

            // create a new node to represent the data and insert it into the model
            DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(data);
            DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) path.getLastPathComponent();
            treeModel.insertNodeInto(newNode, parentNode, childIndex);

            // make the new node visible and scroll so that it's visible
            tree.makeVisible(path.pathByAddingChild(newNode));
            tree.scrollRectToVisible(tree.getPathBounds(path.pathByAddingChild(newNode)));

            // demo stuff - remove for blog
            model.removeAllElements();
            model.insertElementAt("String " + (++count), 0);
            // end demo stuff

            return true;
        }
    });

    JList dragFrom = new JList(model);
    dragFrom.setFocusable(false);
    dragFrom.setPrototypeCellValue("String 0123456789");
    model.insertElementAt("String " + count, 0);
    dragFrom.setDragEnabled(true);
    dragFrom.setBorder(BorderFactory.createLoweredBevelBorder());

    JPanel p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    JPanel wrap = new JPanel();
    wrap.add(new JLabel("Drag from here:"));
    wrap.add(dragFrom);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.NORTH);

    getContentPane().add(new JScrollPane(tree), BorderLayout.CENTER);
    indicateCombo = new JComboBox(new String[] { "Default", "Always", "Never" });
    indicateCombo.setSelectedItem("INSERT");

    p = new JPanel();
    p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
    wrap = new JPanel();
    wrap.add(new JLabel("Show drop location:"));
    wrap.add(indicateCombo);
    p.add(Box.createHorizontalStrut(4));
    p.add(Box.createGlue());
    p.add(wrap);
    p.add(Box.createGlue());
    p.add(Box.createHorizontalStrut(4));
    getContentPane().add(p, BorderLayout.SOUTH);

    getContentPane().setPreferredSize(new Dimension(400, 450));
}

From source file:net.rptools.maptool.client.MapTool.java

/**
 * Same as {@link #showMessage(String, String, int, Object...)} except that
 * <code>messages</code> is stored into a JList and that component is then
 * used as the content of the dialog box. This allows multiple strings to be
 * displayed in a manner consistent with other message dialogs.
 * /*from  www. j ava 2s . c om*/
 * @param messages
 *            the Objects (normally strings) to put in the body of the
 *            dialog; no properties file lookup is performed!
 * @param titleKey
 *            the key in the properties file to use when creating the title
 *            of the dialog window (formatted using <code>params</code>)
 * @param messageType
 *            one of <code>JOptionPane.ERROR_MESSAGE</code>,
 *            <code>JOptionPane.WARNING_MESSAGE</code>,
 *            <code>JOptionPane.INFORMATION_MESSAGE</code>
 * @param params
 *            optional parameters to use when formatting the title text from
 *            the properties file
 */
public static void showMessage(Object[] messages, String titleKey, int messageType, Object... params) {
    String title = I18N.getText(titleKey, params);
    JList list = new JList(messages);
    JOptionPane.showMessageDialog(clientFrame, list, title, messageType);
}

From source file:com.eviware.soapui.impl.wsdl.panels.mock.WsdlMockServiceDesktopPanel.java

protected JComponent buildOperationList() {
    operationList = new JList(new OperationListModel());
    operationList.addMouseListener(new ModelItemListMouseListener() {
        private ActionList defaultActions;

        protected ActionList getDefaultActions() {
            if (defaultActions == null) {
                defaultActions = new DefaultActionList();
                defaultActions.addAction(SwingActionDelegate.createDelegate(
                        AddNewMockOperationAction.SOAPUI_ACTION_ID, getModelItem(), null, null));
            }/*from  w ww .j  a  va2  s . c om*/

            return defaultActions;
        }
    });
    operationList.setCellRenderer(new OperationListCellRenderer());
    operationList.addKeyListener(new ModelItemListKeyListener() {

        @Override
        public ModelItem getModelItemAt(int ix) {
            return getModelItem().getMockOperationAt(ix);
        }
    });

    JScrollPane scrollPane = new JScrollPane(operationList);
    return UISupport.buildPanelWithToolbar(buildMockOperationListToolbar(), scrollPane);
}