Example usage for javax.swing DefaultListModel DefaultListModel

List of usage examples for javax.swing DefaultListModel DefaultListModel

Introduction

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

Prototype

DefaultListModel

Source Link

Usage

From source file:maltcms.ui.nb.pipelineRunner.ui.PipelineRunnerTopComponent.java

public void setProcessRunning(MaltcmsLocalHostExecution p) {
    if (dlm2 == null) {
        dlm2 = new DefaultListModel();
        runningProcessList.setModel(dlm2);
    }// w ww .ja v a 2s.  c o m
    dlm.removeElement(p);
    dlm2.add(0, p);
    if (!dlm2.isEmpty()) {
        runningProcessList.setSelectedIndex(0);
    }
}

From source file:edu.ku.brc.specify.config.init.secwiz.UserPanel.java

/**
 * /* www  .  j  a  v  a 2 s  .co m*/
 */
protected void createUI() {
    dbList = new JList(new DefaultListModel());
    otherDBList = new JList(new DefaultListModel());

    userModel = new UserTableModel(null);
    userTable = new JTable(userModel);

    CellConstraints cc = new CellConstraints();

    saveBtn = UIHelper.createButton("Save");
    mkKeysBtn = UIHelper.createButton("Make Keys");
    copyKeyBtn = UIHelper.createButton("Copy Master Key");
    sendKeysBtn = UIHelper.createButton("Send Keys");
    showKeysBtn = UIHelper.createButton("Show Summary");
    printKeysBtn = UIHelper.createButton("Print");
    btns = new JButton[] { saveBtn, sendKeysBtn, copyKeyBtn, showKeysBtn, printKeysBtn };

    String colDef = UIHelper.createDuplicateJGoodiesDef("p", "8px", btns.length);
    PanelBuilder btnPB = new PanelBuilder(new FormLayout("f:p:g," + colDef, "p"));
    int x = 2;
    for (JButton b : btns) {
        btnPB.add(b, cc.xy(x, 1));
        x += 2;
    }
    saveBtn.setEnabled(false);
    copyKeyBtn.setEnabled(false);

    label = UIHelper.createLabel("", SwingConstants.CENTER);

    gainAccessBtn = UIHelper.createIconBtn("Unmap", "", null);
    loseAccessBtn = UIHelper.createIconBtn("Map", "", null);

    PanelBuilder bpb = new PanelBuilder(new FormLayout("p", "f:p:g,p,8px,p,f:p:g"));
    bpb.add(gainAccessBtn, cc.xy(1, 2));
    bpb.add(loseAccessBtn, cc.xy(1, 4));

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

    tpb.add(UIHelper.createI18NLabel("MSTR_HAS_PERM", SwingConstants.CENTER), cc.xy(1, 1));
    tpb.add(otherDBLbl = UIHelper.createI18NLabel("MSTR_HAS_NOPERM", SwingConstants.CENTER), cc.xy(5, 1));

    tpb.add(dbScrollPane = UIHelper.createScrollPane(dbList), cc.xy(1, 3));
    tpb.add(bpb.getPanel(), cc.xy(3, 3));
    tpb.add(odbScrollPane = UIHelper.createScrollPane(otherDBList), cc.xy(5, 3));

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

    sendKeysBtn.setVisible(false);

    int y = 1;
    pb.add(tpb.getPanel(), cc.xyw(1, y, 2));
    y += 2;
    y += 2;
    pb.add(label, cc.xyw(1, y, 2));
    y += 2;
    pb.add(userScrollPane = UIHelper.createScrollPane(userTable), cc.xyw(1, y, 2));
    y += 2;
    pb.add(btnPB.getPanel(), cc.xy(2, y));
    y += 2;
    pb.addSeparator("", cc.xyw(1, y, 2));
    y += 2;

    dbList.setVisibleRowCount(8);
    otherDBList.setVisibleRowCount(8);

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            Dimension size = userTable.getPreferredScrollableViewportSize();
            size.height = 10 * userTable.getRowHeight();
            userTable.setPreferredScrollableViewportSize(size);
        }
    });

    updateBtnUI(false);

    dbList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                loadData(false);

                gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1);
                loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1);
            }
        }
    });

    userTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                doUserSelected();
            }
        }
    });

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

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

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

    copyKeyBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int inx = userTable.getSelectedRow();
            if (inx > -1) {
                String masterKey = userModel.getUserData().get(inx).getMasterKey();
                UIHelper.setTextToClipboard(masterKey);
            }
        }
    });

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

    printKeysBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            printUserData();
        }
    });
    gainAccessBtn.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changeMasterAccess(true);
        }
    });

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

    otherDBList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                otherDBName = (String) otherDBList.getSelectedValue();
                gainAccessBtn.setEnabled(otherDBList.getSelectedIndex() > -1);
                loseAccessBtn.setEnabled(dbList.getSelectedIndex() > -1);
            }
        }
    });

}

From source file:edu.ku.brc.specify.plugins.TaxonLabelFormatting.java

@Override
public void initialize(Properties propertiesArg, boolean isViewModeArg) {
    super.initialize(propertiesArg, isViewModeArg);

    String plName = "TaxonLabelFormatter";
    PickListDBAdapterIFace adapter = PickListDBAdapterFactory.getInstance().create(plName, false);
    if (adapter == null || adapter.getPickList() == null) {
        throw new RuntimeException("PickList Adapter [" + plName + "] cannot be null!");
    }//from ww  w.jav  a 2  s . c o m
    formatCBX = new ValComboBox(adapter);
    formatCBX.getComboBox().addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doFormatting();
        }
    });
    formatCBX.getComboBox().addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            doFormatting();
        }
    });

    newAgentBtn = createButton(""); // Label set when new Resource Bundle is installed (below)
    searchPanel = new DBObjSearchPanel("Search", "AgentNameSearch", "AgentNameSearch",
            "edu.ku.brc.specify.datamodel.Agent", "agentId", SwingConstants.BOTTOM);
    searchPanel.getScrollPane().setMinimumSize(new Dimension(100, 200));
    searchPanel.getScrollPane().setPreferredSize(new Dimension(100, 150));
    ((FormViewObj) searchPanel.getForm()).getPanel().setBorder(null);

    try {
        UIRegistry.loadAndPushResourceBundle("specify_plugins");

        newAgentBtn.setText(getResourceString("NewAgent"));

        authorsList = new JList(new DefaultListModel());
        authorsList.setVisibleRowCount(10);
        authorsList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    Object selObj = authorsList.getSelectedValue();
                    if (selObj != null) {

                    }
                    updateEnabledState();
                }
            }
        });
        JScrollPane scrollPane = new JScrollPane(authorsList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

        mapToBtn = createIconBtn("Map", "ADD_AUTHOR_NAME_TT", new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                Object agent = searchPanel.getSelectedObject();
                ((DefaultListModel) authorsList.getModel()).addElement(agent);
                doFormatting();
            }
        });
        unmapBtn = createIconBtn("Unmap", "REMOVE_AUTHOR_NAME_TT", new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                int index = authorsList.getSelectedIndex();
                if (index > -1) {
                    DefaultListModel model = (DefaultListModel) authorsList.getModel();
                    model.remove(index);
                    updateEnabledState();
                    doFormatting();
                }
            }
        });

        upBtn = createIconBtn("ReorderUp", "MOVE_AUTHOR_NAME_UP", new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                DefaultListModel model = (DefaultListModel) authorsList.getModel();
                int index = authorsList.getSelectedIndex();
                Object item = authorsList.getSelectedValue();
                model.remove(index);
                model.insertElementAt(item, index - 1);
                authorsList.setSelectedIndex(index - 1);
                updateEnabledState();
            }
        });
        downBtn = createIconBtn("ReorderDown", "MOVE_AUTHOR_NAME_DOWN", new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                DefaultListModel model = (DefaultListModel) authorsList.getModel();
                int index = authorsList.getSelectedIndex();
                Object item = authorsList.getSelectedValue();
                model.remove(index);
                model.insertElementAt(item, index + 1);
                authorsList.setSelectedIndex(index + 1);
                updateEnabledState();
            }
        });

        PanelBuilder bldr = new PanelBuilder(new FormLayout("p, 5px, p, 5px, f:p:g, 2px, p",
                "p, 4px, p, 2px, f:p:g, 4px, p, 4px, p, 2px, p, 2px, p, 2px, p"), this);
        CellConstraints cc = new CellConstraints();

        PanelBuilder upDownPanel = new PanelBuilder(new FormLayout("p", "p, 2px, p, f:p:g"));
        upDownPanel.add(upBtn, cc.xy(1, 1));
        upDownPanel.add(downBtn, cc.xy(1, 3));

        PanelBuilder middlePanel = new PanelBuilder(new FormLayout("c:p:g", "f:p:g, p, 2px, p, f:p:g"));
        middlePanel.add(mapToBtn, cc.xy(1, 2));
        middlePanel.add(unmapBtn, cc.xy(1, 4));

        PanelBuilder rwPanel = new PanelBuilder(new FormLayout("p, 2px, f:p:g", "p"));
        refWorkLabel = createLabel(getResourceString("NONE"));
        rwPanel.add(createI18NFormLabel("REFERENCEWORK"), cc.xy(1, 1));
        rwPanel.add(refWorkLabel, cc.xy(3, 1));

        int y = 1;

        bldr.add(rwPanel.getPanel(), cc.xywh(1, y, 7, 1));
        y += 2;

        bldr.add(searchPanel, cc.xywh(1, y, 1, 3));
        bldr.addSeparator(getResourceString("Authors"), cc.xy(5, y));
        y += 2;

        bldr.add(middlePanel.getPanel(), cc.xy(3, y));
        bldr.add(scrollPane, cc.xywh(5, y, 1, 3));
        bldr.add(upDownPanel.getPanel(), cc.xy(7, y));
        y += 2;

        PanelBuilder newAgentPanel = new PanelBuilder(new FormLayout("f:p:g,p", "p"));
        newAgentPanel.add(newAgentBtn, cc.xy(2, 1));

        bldr.add(newAgentPanel.getPanel(), cc.xy(1, y));
        y += 2;

        JLabel fmtLabel = createLabel(getResourceString("LABELFORMAT"));
        bldr.add(fmtLabel, cc.xy(1, y));
        y += 2;
        bldr.add(formatCBX, cc.xywh(1, y, 7, 1));
        y += 2;

        Font plain = fmtLabel.getFont();
        specialLabel = new SpecialLabel(plain, new Font(plain.getName(), Font.ITALIC, plain.getSize()));
        specialLabel.setBorder(BorderFactory.createLineBorder(Color.LIGHT_GRAY));
        bldr.add(createLabel(getResourceString("SAMPLEOUTPUT") + ":"), cc.xywh(1, y, 7, 1));
        y += 2;
        bldr.add(specialLabel, cc.xywh(1, y, 7, 1));

        searchPanel.setOKBtn(mapToBtn);
    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(TaxonLabelFormatting.class, ex);
        log.error(ex);
        ex.printStackTrace();
    }
    UIRegistry.popResourceBundle();
}

From source file:gtu._work.etc._3DSMovieRenamer.java

private void initGUI() {
    try {/*from  w ww .j a v a  2s .c om*/
        final SwingActionUtil swingUtil = (SwingActionUtil) SwingActionUtil.newInstance(this);

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("3DS Rename");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("vid list", null, jPanel1, null);
                {
                    openDir = new JButton();
                    jPanel1.add(openDir, BorderLayout.NORTH);
                    openDir.setText("open dir");
                    openDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("openDir.actionPerformed", evt);
                        }
                    });
                }
                {
                    ListModel vidListModel = new DefaultListModel();
                    vidList = new JList();
                    jPanel1.add(vidList, BorderLayout.CENTER);
                    vidList.setModel(vidListModel);
                    vidList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            swingUtil.invokeAction("vidList.mouseClicked", evt);
                        }
                    });
                    vidList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            swingUtil.invokeAction("vidList.keyPressed", evt);
                        }
                    });
                }
                {
                    jPanel3 = new JPanel();
                    jPanel1.add(jPanel3, BorderLayout.SOUTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(445, 34));
                    {
                        renameText = new JTextField();
                        jPanel3.add(renameText);
                        renameText.setPreferredSize(new java.awt.Dimension(187, 24));
                    }
                    {
                        renameBtn = new JButton();
                        jPanel3.add(renameBtn);
                        renameBtn.setText("rename");
                        renameBtn.setPreferredSize(new java.awt.Dimension(106, 24));
                        renameBtn.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("renameBtn.mouseClicked", evt);
                            }
                        });
                    }
                    {
                        forceChange = new JCheckBox();
                        jPanel3.add(forceChange);
                        forceChange.setText("force");
                        forceChange.setPreferredSize(new java.awt.Dimension(64, 21));
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("copy", null, jPanel2, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel2.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        ListModel copyToListModel = new DefaultListModel();
                        copyToList = new JList();
                        jScrollPane1.setViewportView(copyToList);
                        copyToList.setModel(copyToListModel);
                        copyToList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("copyToList.mouseClicked", evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("BT Movie", null, jPanel4, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel4.add(jScrollPane2, BorderLayout.WEST);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(254, 355));
                    {
                        btDirTree = new JTree();
                        jScrollPane2.setViewportView(btDirTree);
                        btDirTree.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        btDirTree.addPropertyChangeListener(new PropertyChangeListener() {
                            public void propertyChange(PropertyChangeEvent evt) {
                                swingUtil.invokeAction(evt);
                            }
                        });
                        JTreeUtil.newInstance(btDirTree).fileSystem(DEFAULT_BT_DIR);
                    }
                }
                {
                    jPanel5 = new JPanel();
                    BorderLayout jPanel5Layout = new BorderLayout();
                    jPanel5.setLayout(jPanel5Layout);
                    jPanel4.add(jPanel5, BorderLayout.CENTER);
                    {
                        jScrollPane3 = new JScrollPane();
                        jPanel5.add(jScrollPane3, BorderLayout.CENTER);
                        jScrollPane3.setPreferredSize(new java.awt.Dimension(427, 355));
                        {
                            DefaultListModel btMovListModel = new DefaultListModel();
                            btMovList = new JList();
                            jScrollPane3.setViewportView(btMovList);
                            btMovList.setModel(btMovListModel);
                            btMovList.addMouseListener(new MouseAdapter() {
                                public void mouseClicked(MouseEvent evt) {
                                    swingUtil.invokeAction(evt);
                                }
                            });
                            btMovList.addKeyListener(new KeyAdapter() {
                                public void keyPressed(KeyEvent evt) {
                                    JListUtil.newInstance(btMovList).defaultJListKeyPressed(evt);
                                }
                            });
                        }
                    }
                }
            }
            {
                jPanel6 = new JPanel();
                FlowLayout jPanel6Layout = new FlowLayout();
                jTabbedPane1.addTab("common", null, jPanel6, null);
                jPanel6.setLayout(jPanel6Layout);
                {
                    execute3dsVidTransfer = new JButton();
                    jPanel6.add(execute3dsVidTransfer);
                    execute3dsVidTransfer.setText("execute 3ds video transfer");
                    execute3dsVidTransfer.setPreferredSize(new java.awt.Dimension(207, 42));
                    execute3dsVidTransfer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            String bat = "C:/apps/_movie/3DSVideov1.00/3DS Video.exe";
                            try {
                                Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", bat));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
                {
                    openMovieAppDir = new JButton();
                    jPanel6.add(openMovieAppDir);
                    openMovieAppDir.setText("open movie app dir");
                    openMovieAppDir.setPreferredSize(new java.awt.Dimension(207, 42));
                    openMovieAppDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                Desktop.getDesktop().open(new File("C:/apps/_movie"));
                            } catch (IOException e) {
                                JCommonUtil.handleException(e);
                            }
                        }
                    });
                }
            }
            {
                jPanel7 = new JPanel();
                BorderLayout jPanel7Layout = new BorderLayout();
                jTabbedPane1.addTab("fake rename", null, jPanel7, null);
                jPanel7.setLayout(jPanel7Layout);
                {
                    openFakeRenameDir = new JButton();
                    jPanel7.add(openFakeRenameDir, BorderLayout.NORTH);
                    openFakeRenameDir.setText("open dir");
                    openFakeRenameDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JCommonUtil._jFileChooser_selectDirectoryOnly();
                            if (file != null) {
                                DefaultListModel model = new DefaultListModel();
                                for (File f : file.listFiles()) {
                                    model.addElement(f);
                                }
                                openFakeRenameDirList.setModel(model);
                            }
                        }
                    });
                }
                {
                    DefaultListModel openFakeRenameDirListModel = new DefaultListModel();
                    openFakeRenameDirList = new JList();
                    jPanel7.add(openFakeRenameDirList, BorderLayout.CENTER);
                    openFakeRenameDirList.setModel(openFakeRenameDirListModel);
                    openFakeRenameDirList.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            File file = (File) JListUtil.getLeadSelectionObject(openFakeRenameDirList);
                            try {
                                Process process = Runtime.getRuntime()
                                        .exec(String.format("cmd /c call \"%s\"", file));
                                InputStream ins = process.getInputStream();
                                while (ins.read() != -1) {
                                    //TODO
                                }
                                ins.close();
                                System.out.println("done...");
                            } catch (IOException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                    openFakeRenameDirList.addKeyListener(new KeyAdapter() {
                        public void keyPressed(KeyEvent evt) {
                            JListUtil.newInstance(openFakeRenameDirList).defaultJListKeyPressed(evt);
                        }
                    });
                }
                {
                    jPanel8 = new JPanel();
                    jPanel7.add(jPanel8, BorderLayout.SOUTH);
                    jPanel8.setPreferredSize(new java.awt.Dimension(681, 43));
                    {
                        openFakeRenameDir_newName = new JTextField();
                        jPanel8.add(openFakeRenameDir_newName);
                        openFakeRenameDir_newName.setPreferredSize(new java.awt.Dimension(287, 27));
                    }
                    {
                        fakeRenameExecute = new JButton();
                        jPanel8.add(fakeRenameExecute);
                        fakeRenameExecute.setText("execute");
                        fakeRenameExecute.setPreferredSize(new java.awt.Dimension(95, 27));
                        fakeRenameExecute.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                DefaultListModel model = (DefaultListModel) openFakeRenameDirList.getModel();
                                //TODO
                            }
                        });
                    }
                }
            }

            swingUtil.addAction("copyToList.mouseClicked", new Action() {
                public void action(EventObject evt) throws Exception {
                    try {
                        if (((MouseEvent) evt).getButton() == 3) {
                            JMenuItem reloadMenu = new JMenuItem();
                            reloadMenu.setText("reload SD card directory");
                            reloadMenu.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    DefaultListModel copyToListModel = new DefaultListModel();
                                    for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                                        public boolean accept(File paramFile, String paramString) {
                                            if (paramFile.isDirectory()
                                                    && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                                return true;
                                            }
                                            return false;
                                        }
                                    })) {
                                        copyToListModel.addElement(f);
                                    }
                                    copyToList.setModel(copyToListModel);
                                }
                            });
                            JMenuItem copyAllToMenu = new JMenuItem();
                            {
                                copyAllToMenu.setText(
                                        String.format("move %d vids to...", vidList.getModel().getSize()));
                                final File toDir = (File) JListUtil.getLeadSelectionObject(copyToList);
                                if (toDir == null || !toDir.exists() || !toDir.isDirectory()) {
                                    copyAllToMenu.setEnabled(false);
                                }
                                if (vidList.getModel().getSize() == 0) {
                                    copyAllToMenu.setText("copy no file...");
                                    copyAllToMenu.setEnabled(false);
                                }
                                copyAllToMenu.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        DefaultListModel model = JListUtil.newInstance(vidList).getModel();
                                        if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil
                                                .newInstance().iconWaringMessage().confirmButtonYesNo()
                                                .showConfirmDialog("are you sure copy files : "
                                                        + model.getSize() + "\n to dir : " + toDir,
                                                        "COPY VIDS")) {
                                            return;
                                        }
                                        for (int ii = 0; ii < model.getSize(); ii++) {
                                            File src = (File) model.getElementAt(ii);
                                            src.renameTo(new File(toDir, src.getName()));
                                        }
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("copy completed!", "SUCCESS");
                                        loadDirVids();
                                    }
                                });
                            }

                            JPopupMenuUtil.newInstance(copyToList).applyEvent((MouseEvent) evt)
                                    .addJMenuItem(reloadMenu, copyAllToMenu).show();
                        }
                    } catch (Exception ex) {
                        JCommonUtil.handleException(ex);
                    }
                }
            });
            swingUtil.addAction("openDir.actionPerformed", new Action() {
                public void action(EventObject evt) throws Exception {
                    File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                            .getApproveSelectedFile();
                    if (file == null) {
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("dir not corrent!, set desktop", getTitle());
                        loadDir = FileUtil.DESKTOP_DIR;
                    } else {
                        loadDir = file;
                    }
                    loadDirVids();
                }
            });
            swingUtil.addAction("vidList.mouseClicked", new Action() {
                //                    final String player = "C:/Program Files (x86)/GRETECH/GomPlayer/GOM.EXE";

                public void action(EventObject evt) throws Exception {
                    int pos = -1;
                    if ((pos = vidList.getLeadSelectionIndex()) == -1) {
                        return;
                    }
                    MouseEvent mevt = (MouseEvent) evt;

                    final File selectItem = (File) vidList.getModel().getElementAt(pos);

                    List<JMenuItem> menuList = new ArrayList<JMenuItem>();
                    JMenuItem simpleRenamer = new JMenuItem();
                    final String simpleRenamePrefix = RandomUtil.upperCase(3);
                    simpleRenamer.setText("Rename : " + simpleRenamePrefix);
                    simpleRenamer.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent paramActionEvent) {
                            String value = StringUtils.defaultString(JOptionPaneUtil.newInstance()
                                    .showInputDialog("3 char prefix?", "AVI PREFIX"), simpleRenamePrefix);
                            if (value != null && value.matches("[a-zA-Z]{3}")) {
                                selectItem.renameTo(getNewFile(selectItem.getParentFile(), value));
                                loadDirVids();
                            } else {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("prefix is not correct!", "ERROR");
                            }
                        }
                    });
                    menuList.add(simpleRenamer);
                    if (load3DSDir == null) {
                        reload3DSDir();
                        if (load3DSDir == null) {
                            JMenuItem disable = new JMenuItem();
                            disable.setText("MOVE : SD card is not set!");
                            disable.setEnabled(false);
                            menuList.add(disable);
                        }
                    } else {
                        for (final File f : load3DSDir.listFiles(new FilenameFilter() {
                            public boolean accept(File paramFile, String paramString) {
                                if (paramFile.isDirectory() && paramString.matches(CUSTOM_3DS_DIR_PATTERN)) {
                                    return true;
                                }
                                return false;
                            }
                        })) {
                            JMenuItem copyTo = new JMenuItem();
                            copyTo.setText("MOVE : " + f.getName());
                            copyTo.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil
                                            .newInstance().iconQuestionMessage().confirmButtonYesNo()
                                            .showConfirmDialog(//
                                                    "are you sure move file\n" + //
                                    selectItem + "\n" + //
                                    "to\n" + //
                                    "dir : " + f + "  ??"//
                                    , "COPY FILE")) {

                                        File copyToNewDirFile = new File(f, selectItem.getName());
                                        if (copyToNewDirFile.exists()) {
                                            JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                                    "target dir file already exist!, need rename!",
                                                    "FILE ALREADY EXIST");
                                            return;
                                        }
                                        selectItem.renameTo(copyToNewDirFile);
                                        loadDirVids();

                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("move completed!", "MOVE FILE");
                                    }
                                }
                            });
                            menuList.add(copyTo);
                        }
                    }
                    JPopupMenuUtil.newInstance(vidList).applyEvent(mevt)
                            .addJMenuItem(menuList.toArray(new JMenuItem[menuList.size()])).show();

                    if (mevt.getClickCount() != 2) {
                        return;
                    }
                    String clkItemPath = selectItem.getAbsolutePath();
                    String command = "cmd /c call \"" + clkItemPath + "\"";
                    System.out.println(command);
                    Runtime.getRuntime().exec(command);
                }
            });
            swingUtil.addAction("vidList.keyPressed", new Action() {
                public void action(EventObject evt) throws Exception {
                    JListUtil.newInstance(vidList).defaultJListKeyPressed(evt);
                }
            });
            swingUtil.addAction("renameBtn.mouseClicked", new Action() {

                Pattern aviNamePattern = Pattern.compile("^([a-zA-Z]{3})_\\d{4}\\.[aA][vV][iI]$");

                public void action(EventObject evt) throws Exception {
                    String name = StringUtils.defaultIfEmpty(renameText.getText(), RandomUtil.upperCase(3));
                    System.out.println("name = " + name + ", force : " + forceChange.isSelected());
                    if (!name.matches("[a-zA-Z]{3}")) {
                        renameText.setText("");
                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                .showMessageDialog("rename must eng 3 char!", "ERROR");
                        return;
                    }
                    DefaultListModel model = (DefaultListModel) vidList.getModel();
                    boolean matchOk = false;
                    if (model.size() != 0) {
                        File oldFile = null;
                        Matcher matcher = null;
                        for (int ii = 0; ii < model.getSize(); ii++) {
                            oldFile = (File) model.getElementAt(ii);

                            if (!oldFile.exists()) {
                                JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(
                                        "file not exeist : \n" + oldFile.getAbsolutePath(), getTitle());
                                return;
                            }
                            matcher = aviNamePattern.matcher(oldFile.getName());
                            matchOk = matcher.find();
                            System.out.println("matchOk = " + matchOk);
                            if (matchOk && !forceChange.isSelected()) {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), matcher.group(1)));
                            } else {
                                oldFile.renameTo(getNewFile(oldFile.getParentFile(), name));
                            }
                        }
                        JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog("success!",
                                getTitle());
                    }
                    loadDirVids();
                }
            });

            ToolTipManager.sharedInstance().setInitialDelay(0);
            swingUtil.addAction(btMovList, MouseEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    final File file = (File) JListUtil.getLeadSelectionObject(btMovList);
                    if (JMouseEventUtil.buttonLeftClick(1, evt)) {
                        btMovList.setToolTipText(
                                DateFormatUtils.format(file.lastModified(), "yyyy/MM/dd HH:mm:ss") + " length:"
                                        + (file.length() / 1024) + "k");
                    }

                    final Object[] objects = btMovList.getSelectedValues();
                    JPopupMenuUtil.newInstance(btMovList).applyEvent(evt)//
                            .addJMenuItem("move out", (objects != null && objects.length > 0),
                                    new ActionListener() {
                                        public void actionPerformed(ActionEvent paramActionEvent) {
                                            List<File> list = new ArrayList<File>();
                                            for (Object val : objects) {
                                                list.add((File) val);
                                            }
                                            if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure move file from\n" + list.toString().replace(',', '\n')
                                                            + "\nto\n" + DEFAULT_BT_DIR,
                                                    "MOVE")) {
                                                return;
                                            }
                                            StringBuilder sb = new StringBuilder();
                                            File moveTo = null;
                                            for (File file : list) {
                                                sb.append((file.renameTo(
                                                        moveTo = new File(DEFAULT_BT_DIR, file.getName()))
                                                        && moveTo.exists()) ? "" : file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() == 0 ? "move success!" : "move failed!\n" + sb);
                                        }
                                    })
                            .addJMenuItem("delete this", file.exists(), new ActionListener() {
                                public void actionPerformed(ActionEvent paramActionEvent) {
                                    if (!JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                            "sure delete file \n" + file, "DELETE")) {
                                        return;
                                    }
                                    boolean result = file.delete();
                                    System.out.println("!!!!!" + result + "..." + file.exists());
                                    JCommonUtil._jOptionPane_showMessageDialog_info(
                                            result ? "delete success!" : "delete failed!");
                                }
                            }).show();

                    if (JMouseEventUtil.buttonLeftClick(2, evt)) {
                        Runtime.getRuntime().exec(String.format("cmd /c call \"%s\"", file));
                    }
                }
            });
            swingUtil.addAction(btDirTree, MouseEvent.class, new Action() {

                File getSingleFile() {
                    return ((JFile) JTreeUtil.newInstance(btDirTree).getSelectItem().getUserObject()).getFile();
                }

                public void action(EventObject evt) throws Exception {
                    int selectCount = btDirTree.getSelectionModel().getSelectionCount();
                    if (selectCount == 1) {
                        final File file = getSingleFile();
                        JPopupMenuUtil.newInstance(btDirTree).applyEvent(evt).addJMenuItem("delete this",
                                selectCount == 1 && file.exists(), new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        if (file.isFile()) {
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete FILE : \n" + file, "WARNING")) {
                                                file.delete();
                                                JCommonUtil._jOptionPane_showMessageDialog_info(
                                                        (file.exists() ? "delete failed!" : "delete success!"));
                                            }
                                        }
                                        if (file.isDirectory()) {
                                            StringBuilder sb = new StringBuilder();
                                            if (JCommonUtil._JOptionPane_showConfirmDialog_yesNoOption(
                                                    "sure delete DIR : \n" + file, "WARNING")) {
                                                List<Boolean> delL = new ArrayList<Boolean>();
                                                for (File f : file.listFiles()) {
                                                    if (fileExtensionPattern.matcher(f.getName()).find()
                                                            || f.length() > 1000000L) {
                                                        if (!JCommonUtil
                                                                ._JOptionPane_showConfirmDialog_yesNoOption(
                                                                        "delete this : \n" + f,
                                                                        "CHECK AGAIN")) {
                                                            continue;
                                                        }
                                                        delL.add(f.delete());
                                                    }
                                                    delL.add(f.delete());
                                                }
                                                for (File f : file.listFiles()) {
                                                    if (f.exists()) {
                                                        sb.append(f + "\n");
                                                    }
                                                }
                                                System.out.println("delL.contains(false)==================>"
                                                        + delL.contains(false));
                                            }
                                            if (!file.delete()) {
                                                sb.append(file + "\n");
                                            }
                                            JCommonUtil._jOptionPane_showMessageDialog_info(
                                                    sb.length() > 0 ? "delete failed!\nlist:\n" + sb
                                                            : "delete success!");
                                            if (sb.length() == 0) {
                                                DefaultMutableTreeNode node = JTreeUtil.newInstance(btDirTree)
                                                        .getSelectItem();
                                                System.out.println(
                                                        JTreeUtil.newInstance(btDirTree).removeNode(node));
                                            }
                                        }
                                    }
                                }).addJMenuItem("open dir", new ActionListener() {
                                    public void actionPerformed(ActionEvent paramActionEvent) {
                                        File openTarget = file;
                                        if (file.isFile()) {
                                            openTarget = file.getParentFile();
                                        }
                                        try {
                                            Desktop.getDesktop().open(openTarget);
                                        } catch (IOException e) {
                                            JCommonUtil.handleException(e);
                                        }
                                    }
                                }).show();
                    }
                }
            });
            swingUtil.addAction(btDirTree, PropertyChangeEvent.class, new Action() {
                public void action(EventObject evt) throws Exception {
                    List<File> list = new ArrayList<File>();
                    for (DefaultMutableTreeNode node : JTreeUtil.newInstance(btDirTree).getSelectItems()) {
                        JFile jfile = (JFile) node.getUserObject();
                        if (jfile.getFile().isDirectory()) {
                            for (File f : jfile.getFile().listFiles(new FilenameFilter() {
                                public boolean accept(File paramFile, String paramString) {
                                    return fileExtensionPattern.matcher(paramString).find();
                                }
                            })) {
                                System.out.println(f.getName() + "...." + f.length());
                                list.add(f);
                            }
                        }
                    }
                    Collections.sort(list, new Comparator<File>() {
                        public int compare(File paramT1, File paramT2) {
                            return paramT1.lastModified() > paramT2.lastModified() ? -1 : 1;
                        }
                    });
                    btMovList.setModel(JListUtil.createModel(list.iterator()));
                }
            });
        }
        this.setSize(702, 422);

        loadDirVids();
        reload3DSDir();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:au.org.ala.delta.intkey.ui.OpenDataSetDialog.java

public OpenDataSetDialog(Frame owner, List<Pair<String, String>> datasetIndexData, File startBrowseDirectory) {
    super(owner, true);
    setPreferredSize(new Dimension(450, 300));

    ActionMap actionMap = Application.getInstance().getContext().getActionMap(this);
    ResourceMap resourceMap = Application.getInstance().getContext().getResourceMap(OpenDataSetDialog.class);
    resourceMap.injectFields(this);

    setTitle(title);/*from  w w  w  .j a va  2 s  .  c om*/

    _selectedDatasetPath = null;

    _pnlList = new JPanel();
    _pnlList.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(_pnlList, BorderLayout.CENTER);
    _pnlList.setLayout(new BorderLayout(0, 0));

    _lblSelectByTitle = new JLabel(selectByTitleCaption);
    _pnlList.add(_lblSelectByTitle, BorderLayout.NORTH);

    _sclPnList = new JScrollPane();
    _pnlList.add(_sclPnList, BorderLayout.CENTER);

    _listDatasetIndex = new JList();
    _sclPnList.setViewportView(_listDatasetIndex);

    _pnlBottom = new JPanel();
    _pnlBottom.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(_pnlBottom, BorderLayout.SOUTH);
    _pnlBottom.setLayout(new BorderLayout(0, 0));

    _lblSelectByFileName = new JLabel(selectByFileCaption);
    _pnlBottom.add(_lblSelectByFileName, BorderLayout.NORTH);

    _pnlButtons = new JPanel();
    _pnlButtons.setBorder(new EmptyBorder(10, 0, 0, 0));
    _pnlBottom.add(_pnlButtons, BorderLayout.SOUTH);

    _btnOK = new JButton();
    _btnOK.setAction(actionMap.get("OpenDataSetDialog_OK"));
    _pnlButtons.add(_btnOK);

    _btnCancel = new JButton();
    _btnCancel.setAction(actionMap.get("OpenDataSetDialog_Cancel"));
    _pnlButtons.add(_btnCancel);

    _btnHelp = new JButton();
    _btnHelp.setAction(actionMap.get("OpenDataSetDialog_Help"));
    _pnlButtons.add(_btnHelp);

    _pnlFile = new JPanel();
    _pnlBottom.add(_pnlFile, BorderLayout.CENTER);
    _pnlFile.setLayout(new BorderLayout(0, 0));

    _txtFldFileName = new JTextField();
    _pnlFile.add(_txtFldFileName, BorderLayout.CENTER);
    _txtFldFileName.setColumns(10);
    _txtFldFileName.addKeyListener(new KeyListener() {

        @Override
        public void keyTyped(KeyEvent e) {
            // Clear any selected item in the list of the text field is
            // modified.
            _listDatasetIndex.clearSelection();
        }

        @Override
        public void keyReleased(KeyEvent e) {
            // do nothing
        }

        @Override
        public void keyPressed(KeyEvent e) {
            // do nothing

        }
    });

    _btnBrowse = new JButton();
    _btnBrowse.setAction(actionMap.get("OpenDataSetDialog_Browse"));
    _pnlFile.add(_btnBrowse, BorderLayout.EAST);

    DefaultListModel model = new DefaultListModel();

    for (Pair<String, String> datasetInfo : datasetIndexData) {
        model.addElement(datasetInfo);
    }

    _listDatasetIndex.setModel(model);
    _listDatasetIndex.setCellRenderer(new DatasetIndexCellRenderer());

    _listDatasetIndex.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            // Clear any filename in the text field if an item is selected
            // from the text box.
            _txtFldFileName.setText(null);
        }
    });

    _startBrowseDirectory = startBrowseDirectory;
}

From source file:Assignment2.FarmManagementGUI.java

public void addField() {
    if ((!farmList.isSelectionEmpty()) && (!farmList.isSelectionEmpty())) {
        fieldCoords = new DefaultListModel();
        farmCoordList.setModel(fieldCoords);
        addToFarm = selectedFarm;//  w w w . j a  va  2 s. com
        addFieldDialog.setVisible(true);
    } else {
        //show error
    }
}

From source file:de.tor.tribes.ui.views.DSWorkbenchAttackFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    AttackTableTab activeTab = getActiveTab();
    int idx = jAttackTabPane.getSelectedIndex();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("TimeChange")) {
            activeTab.fireChangeTimeEvent();
        } else if (e.getActionCommand().equals("UnitChange")) {
            activeTab.fireChangeUnitEvent();
        } else if (e.getActionCommand().equals("Recolor")) {
            activeTab.updateSortHighlighter();
        } else if (e.getActionCommand().equals("ExportScript")) {
            activeTab.fireExportScriptEvent();
        } else if (e.getActionCommand().equals("Copy")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("BBCopy")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        } else if (e.getActionCommand().equals("Cut")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD);
            jAttackTabPane.setSelectedIndex(idx);
        } else if (e.getActionCommand().equals("Paste")) {
            activeTab.transferSelection(AttackTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD);
            jAttackTabPane.setSelectedIndex(idx);
        } else if (e.getActionCommand().equals("Delete")) {
            activeTab.deleteSelection(true);
        } else if (e.getActionCommand().equals("Find")) {
            BufferedImage back = ImageUtils.createCompatibleBufferedImage(3, 3, BufferedImage.TRANSLUCENT);
            Graphics g = back.getGraphics();
            g.setColor(new Color(120, 120, 120, 120));
            g.fillRect(0, 0, back.getWidth(), back.getHeight());
            g.setColor(new Color(120, 120, 120));
            g.drawLine(0, 0, 3, 3);/* w  w w.  j  a v a 2s.  c o m*/
            g.dispose();
            TexturePaint paint = new TexturePaint(back,
                    new Rectangle2D.Double(0, 0, back.getWidth(), back.getHeight()));

            jxSearchPane.setBackgroundPainter(new MattePainter(paint));
            DefaultListModel model = new DefaultListModel();

            for (int i = 0; i < activeTab.getAttackTable().getColumnCount(); i++) {
                TableColumnExt col = activeTab.getAttackTable().getColumnExt(i);
                if (col.isVisible()) {
                    if (!col.getTitle().equals("Einheit") && !col.getTitle().equals("Typ")
                            && !col.getTitle().equals("Sonstiges") && !col.getTitle().equals("Abschickzeit")
                            && !col.getTitle().equals("Ankunftzeit") && !col.getTitle().equals("Verbleibend")) {
                        model.addElement(col.getTitle());
                    }
                }
            }
            jXColumnList.setModel(model);
            jXColumnList.setSelectedIndex(0);
            jxSearchPane.setVisible(true);
        }
    }
}

From source file:br.ufrgs.enq.jcosmo.ui.COSMOSACDialog.java

public COSMOSACDialog() {
    super("JCOSMO Simple");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    db = COSMOSACDataBase.getInstance();

    COSMOSAC models[] = new COSMOSAC[5];
    models[0] = new COSMOSAC();
    models[1] = new COSMOPAC();
    models[2] = new COSMOSAC_SVP();
    models[3] = new COSMOSAC_G();
    models[4] = new PCMSAC();
    modelBox = new JComboBox(models);
    modelBox.addActionListener(this);

    JPanel north = new JPanel(new GridLayout(0, 2));
    add(north, BorderLayout.NORTH);
    JPanel northAba1 = new JPanel(new GridLayout(0, 4));
    JPanel northAba2 = new JPanel(new GridLayout(0, 2));

    //Where the GUI is created:
    JMenuBar menuBar;//from  ww  w. j a va  2s  . co  m
    JMenu file, help;
    JMenuItem menuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    // the file menu
    file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);
    menuBar.add(file);
    menuItem = new JMenuItem("Quit", KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    menuItem.setActionCommand(QUIT);
    menuItem.addActionListener(this);
    file.add(menuItem);

    // the help menu
    help = new JMenu("Help");
    file.setMnemonic(KeyEvent.VK_H);
    menuBar.add(help);
    menuItem = new JMenuItem("About", KeyEvent.VK_A);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    menuItem.setActionCommand(ABOUT);
    menuItem.addActionListener(this);
    help.add(menuItem);

    setJMenuBar(menuBar);

    listModel = new DefaultListModel();
    list = new JList(listModel);
    list.setBorder(BorderFactory.createTitledBorder("compounds"));
    list.setVisibleRowCount(2);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton addButton = new JButton("Add");
    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new AddCompoundDialog(COSMOSACDialog.this);
        }
    });

    removeButton = new JButton("Remove");
    removeButton.addActionListener(this);
    visibRemove(false);

    JButton calcButton = new JButton("Calculate");
    calcButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rebuildChart();
            rebuildSigmaProfiles();
        }
    });

    JButton refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rebuildSigmaProfiles();
        }
    });

    ignoreSGButton = new JCheckBox("Ignore SG");
    ignoreSGButton.setToolTipText("Toogles the ignore flag for the Staverman-Guggenheim term");
    ignoreSGButton.addActionListener(this);

    JPanel but = new JPanel(new GridLayout(0, 1));
    but.add(addButton, BorderLayout.EAST);
    but.add(removeButton, BorderLayout.EAST);
    but.add(modelBox);
    north.add(listScrollPane);
    north.add(but);

    northAba1.add(new JLabel("Temperature [K]"));
    northAba1.add(temperature = new JTextField(10));
    temperature.setText("298");

    northAba1.add(new JLabel("Sigma HB"));
    northAba1.add(sigmaHB = new JTextField(10));
    northAba1.add(new JLabel("Sigma HB2"));
    northAba1.add(sigmaHB2 = new JTextField(10));
    northAba1.add(new JLabel("Sigma HB3"));
    northAba1.add(sigmaHB3 = new JTextField(10));

    northAba1.add(new JLabel("Charge HB"));
    northAba1.add(chargeHB = new JTextField(10));

    northAba1.add(new JLabel("Sigma Disp"));
    northAba1.add(sigmaDisp = new JTextField(10));
    northAba1.add(new JLabel("Charge Disp"));
    northAba1.add(chargeDisp = new JTextField(10));

    northAba1.add(new JLabel("Beta"));
    northAba1.add(beta = new JTextField(10));
    northAba1.add(new JLabel("fpol"));
    northAba1.add(fpol = new JTextField(10));
    northAba1.add(new JLabel("Anorm"));
    northAba1.add(anorm = new JTextField(10));

    northAba1.add(ignoreSGButton);
    northAba1.add(calcButton);
    northAba2.add(new JLabel(""));
    northAba2.add(refreshButton);

    //      chart = new JLineChart();
    //      add(chart, BorderLayout.CENTER);
    //      chart.setTitle("Gamma Plot");
    //      chart.setSubtitle("");
    //      chart.setXAxisLabel("Mole Fraction, x_1");
    //      chart.setYAxisLabel("ln gamma, gE/RT");
    //      chart.setSource(getTitle());
    //      chart.setLegendPosition(LegendPosition.BOTTOM);
    //      chart.setShapesVisible(true);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction, x_1", "ln gamma, gE/RT", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setAutoRange(false);
    plot.getDomainAxis().setRange(new Range(0.0, 1.0));

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setUseFillPaint(true);
    r.setBaseFillPaint(Color.white);
    r.setBaseShapesVisible(true);

    JFreeChart sigmaProfileChart = ChartFactory.createXYLineChart(null, "sigma", "P^x", null,
            PlotOrientation.VERTICAL, true, true, false);
    sigmaProfilePlot = sigmaProfileChart.getXYPlot();
    sigmaProfilePlot.getDomainAxis().setAutoRange(false);
    sigmaProfilePlot.getDomainAxis().setRange(new Range(-0.025, 0.025));

    //      sigmaProfilePlot.setBackgroundPaint(Color.lightGray);
    //      sigmaProfilePlot.setDomainGridlinePaint(Color.white);
    //      sigmaProfilePlot.setRangeGridlinePaint(Color.white);

    JFreeChart chartSegGamma = ChartFactory.createXYLineChart(null, "sigma", "Segment Gamma", null,
            PlotOrientation.VERTICAL, true, true, false);
    plotSegGamma = (XYPlot) chartSegGamma.getPlot();

    JPanel south = new JPanel();
    south.setLayout(new FlowLayout());
    south.add(new JLabel("<html>ln &gamma;<sup>&infin;</sup><sub>1</sub>:</html>"));
    south.add(lnGammaInf1Label = new JLabel());
    south.add(new JLabel("<html>ln &gamma;<sup>&infin;</sup><sub>2</sub>:</html>"));
    south.add(lnGammaInf2Label = new JLabel());
    south.add(Box.createHorizontalStrut(20));
    south.add(new JLabel("<html>&gamma;<sup>&infin;</sup><sub>1</sub>:</html>"));
    south.add(gammaInf1Label = new JLabel());
    south.add(new JLabel("<html>&gamma;<sup>&infin;</sup><sub>2</sub>:</html>"));
    south.add(gammaInf2Label = new JLabel());

    JPanel aba1 = new JPanel(new BorderLayout());
    aba1.add(northAba1, BorderLayout.NORTH);
    JPanel chartsPanel = new JPanel(new GridLayout(0, 2));
    aba1.add(chartsPanel, BorderLayout.CENTER);
    chartsPanel.add(new ChartPanel(chart));
    chartsPanel.add(new ChartPanel(chartSegGamma));
    aba1.add(south, BorderLayout.SOUTH);

    JPanel aba2 = new JPanel(new BorderLayout());
    aba2.add(northAba2, BorderLayout.NORTH);
    aba2.add(chartPanel = new ChartPanel(sigmaProfileChart), BorderLayout.CENTER);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("gamma", aba1);
    tabbedPane.addTab("sigma", aba2);
    add(tabbedPane, BorderLayout.CENTER);

    //      cosmosac.setAEffPrime(6.596176570595075);
    //      cosmosac.setCoord(11.614599507917934);
    //      cosmosac.setVnorm(56.36966406129967);
    //      cosmosac.setAnorm(41.56058649432742);
    //      cosmosac.setCHB(65330.19484947528);
    //      cosmosac.setSigmaHB(0.008292411048046008);

    //Display the window.
    setSize(800, 600);
    setLocationRelativeTo(null);
    modelBox.setSelectedIndex(0);
    setVisible(true);

    // test for a mixture
    //      addList("WATER");
    //      addList("H3O+1");
    //      addList("OH-1");
    //      addList("CL-1");
    //      addList("OXYGEN");
    //      addList("sec-butylamine");
    //      addList("hydrogen-fluoride");
    //      addList("ACETONE");
    //      addList("METHANOL");
    //      addList("ACETONE.opt");
    //      addList("METHANOL.opt");
    //      addList("METHYL-ETHYL-KETONE");
    //      addList("ETHANOL");
    //      addList("N-HEPTANE");
    //      addList("PROPIONIC-ACID");
    //      addList("EMIM");
    //      addList("NTF2");
    //      addList("DCA");
    //      addList("N-OCTANE");
    addList("ETHYLENE CARBONATE");
    addList("BENZENE");
    addList("TOLUENE");
    removeButton.setEnabled(true);
}

From source file:edu.ucla.stat.SOCR.analyses.gui.AnovaTwoWay.java

protected void setMappingPanel() {
    listIndex = new int[dataTable.getColumnCount()];
    for (int j = 0; j < listIndex.length; j++)
        listIndex[j] = 1;//from www.java 2s.  c  o m

    bPanel = new JPanel(new BorderLayout());
    bPanel.add(mappingPanel, BorderLayout.CENTER);
    mappingPanel.add(mappingInnerPanel, BorderLayout.CENTER);

    addButton1.addActionListener(this);
    addButton2.addActionListener(this);
    removeButton1.addActionListener(this);
    removeButton2.addActionListener(this);

    lModel1 = new DefaultListModel();
    lModel2 = new DefaultListModel();
    lModel3 = new DefaultListModel();

    int cellWidth = 10;

    listAdded = new JList(lModel1);
    listAdded.setSelectedIndex(0);
    listDepRemoved = new JList(lModel2);
    listIndepRemoved = new JList(lModel3);

    paintTable(listIndex);
    listAdded.setFixedCellWidth(cellWidth);
    listDepRemoved.setFixedCellWidth(cellWidth);
    listIndepRemoved.setFixedCellWidth(cellWidth);
    dependentPane = new JScrollPane(listDepRemoved);
    FIRST_BUTTON_LABEL = "DEPENDENT";
    SECOND_BUTTON_LABEL = "INDEPENDENT";
    depLabel = new JLabel(FIRST_BUTTON_LABEL);
    indLabel = new JLabel(SECOND_BUTTON_LABEL);
    tools1.add(depLabel);
    tools2.add(indLabel);

    tools1.add(addButton1);
    tools1.add(removeButton1);
    tools2.add(addButton2);
    tools2.add(removeButton2);

    tools1.setFloatable(false);
    tools2.setFloatable(false);

    //
    JPanel choicesPanel = new JPanel();
    choicesPanel.setLayout(new BoxLayout(choicesPanel, BoxLayout.Y_AXIS));
    interactionOnSwitch = new JRadioButton("On");
    interactionOnSwitch.addActionListener(this);
    interactionOnSwitch.setActionCommand(INTERACTIONON);
    interactionOnSwitch.setSelected(false);
    interactionOn = false;

    interactionOffSwitch = new JRadioButton("Off");
    interactionOffSwitch.addActionListener(this);
    interactionOffSwitch.setActionCommand(INTERACTIONOFF);
    interactionOffSwitch.setSelected(true);

    ButtonGroup group = new ButtonGroup();
    group.add(interactionOnSwitch);
    group.add(interactionOffSwitch);
    choicesPanel.add(new JLabel("Turn the interaction:"));
    choicesPanel.add(interactionOnSwitch);
    choicesPanel.add(interactionOffSwitch);
    choicesPanel.setPreferredSize(new Dimension(200, 100));

    JPanel emptyPanel = new JPanel();
    //mappingInnerPanel.setBackground(Color.RED);
    mappingInnerPanel.add(new JScrollPane(listAdded));
    mappingInnerPanel.add(tools1);
    mappingInnerPanel.add(dependentPane);
    // mappingInnerPanel.add(emptyPanel);
    mappingInnerPanel.add(choicesPanel);
    mappingInnerPanel.add(tools2);
    mappingInnerPanel.add(new JScrollPane(listIndepRemoved));
    //listIndepRemoved.setBackground(Color.GREEN);
}

From source file:net.sourceforge.doddle_owl.ui.InputDocumentSelectionPanel.java

public InputDocumentSelectionPanel(InputTermSelectionPanel iwsPanel, DODDLEProject p) {
    project = p;/*from   w w w .  j  av a2  s  .  co  m*/
    inputTermSelectionPanel = iwsPanel;
    termInfoMap = new HashMap<String, TermInfo>();
    stopWordSet = new HashSet<String>();
    docList = new JList(new DefaultListModel());
    docList.addListSelectionListener(this);
    JScrollPane docListScroll = new JScrollPane(docList);
    inputDocList = new JList(new DefaultListModel());
    inputDocList.addListSelectionListener(this);
    JScrollPane inputDocListScroll = new JScrollPane(inputDocList);

    DefaultComboBoxModel docLangBoxModel = new DefaultComboBoxModel(new Object[] { "en", "ja" });
    docLangBox = new JComboBox(docLangBoxModel);
    docLangBox.addActionListener(this);
    addDocButton = new JButton(new AddDocAction(Translator.getTerm("AddDocumentButton")));
    removeDocButton = new JButton(new RemoveDocAction(Translator.getTerm("RemoveDocumentButton")));
    DefaultComboBoxModel inputDocLangBoxModel = new DefaultComboBoxModel(new Object[] { "en", "ja" });
    inputDocLangBox = new JComboBox(inputDocLangBoxModel);
    inputDocLangBox.addActionListener(this);
    addInputDocButton = new JButton(new AddInputDocAction(Translator.getTerm("AddInputDocumentButton")));
    removeInputDocButton = new JButton(
            new RemoveInputDocAction(Translator.getTerm("RemoveInputDocumentButton")));

    inputDocArea = new JTextArea();
    inputDocArea.setLineWrap(true);
    JScrollPane inputDocAreaScroll = new JScrollPane(inputDocArea);

    JPanel docButtonPanel = new JPanel();
    docButtonPanel.setLayout(new BorderLayout());
    docButtonPanel.setLayout(new GridLayout(1, 3));
    docButtonPanel.add(docLangBox);
    docButtonPanel.add(addDocButton);
    docButtonPanel.add(removeDocButton);
    JPanel docPanel = new JPanel();
    docPanel.setLayout(new BorderLayout());
    docPanel.add(docListScroll, BorderLayout.CENTER);
    docPanel.add(docButtonPanel, BorderLayout.SOUTH);

    punctuationField = new JTextField(10);
    punctuationField.setText(PUNCTUATION_CHARS);
    setPunctuationButton = new JButton(Translator.getTerm("SetPunctuationCharacterButton"));
    setPunctuationButton.addActionListener(this);

    JPanel punctuationPanel = new JPanel();
    punctuationPanel.add(punctuationField);
    punctuationPanel.add(setPunctuationButton);

    JPanel inputDocButtonPanel = new JPanel();
    inputDocButtonPanel.setLayout(new GridLayout(1, 3));
    inputDocButtonPanel.add(inputDocLangBox);
    inputDocButtonPanel.add(addInputDocButton);
    inputDocButtonPanel.add(removeInputDocButton);

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new BorderLayout());
    southPanel.add(inputDocButtonPanel, BorderLayout.WEST);
    southPanel.add(punctuationPanel, BorderLayout.EAST);

    JPanel inputDocPanel = new JPanel();
    inputDocPanel.setLayout(new BorderLayout());
    inputDocPanel.add(inputDocListScroll, BorderLayout.CENTER);
    inputDocPanel.add(southPanel, BorderLayout.SOUTH);

    termExtractionButton = new JButton(Translator.getTerm("InputTermExtractionButton"),
            Utils.getImageIcon("input_term_selection.png"));
    termExtractionButton.addActionListener(this);

    genSenCheckBox = new JCheckBox(Translator.getTerm("GensenCheckBox"));
    genSenCheckBox.setSelected(false);
    cabochaCheckBox = new JCheckBox(Translator.getTerm("CabochaCheckBox"));
    cabochaCheckBox.setSelected(true);
    showImportanceCheckBox = new JCheckBox("??");
    nounCheckBox = new JCheckBox(Translator.getTerm("NounCheckBox"));
    nounCheckBox.setSelected(true);
    verbCheckBox = new JCheckBox(Translator.getTerm("VerbCheckBox"));
    verbCheckBox.setSelected(false);
    otherCheckBox = new JCheckBox(Translator.getTerm("OtherPOSCheckBox"));
    oneWordCheckBox = new JCheckBox(Translator.getTerm("OneCharacterCheckBox"));

    JPanel morphemeAnalysisPanel = new JPanel();
    morphemeAnalysisPanel.add(genSenCheckBox);
    morphemeAnalysisPanel.add(cabochaCheckBox);
    morphemeAnalysisPanel.add(nounCheckBox);
    morphemeAnalysisPanel.add(verbCheckBox);
    morphemeAnalysisPanel.add(otherCheckBox);
    morphemeAnalysisPanel.add(oneWordCheckBox);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());
    buttonPanel.add(morphemeAnalysisPanel, BorderLayout.WEST);
    buttonPanel.add(termExtractionButton, BorderLayout.EAST);

    mainViews = new View[2];
    ViewMap viewMap = new ViewMap();
    // mainViews[0] = new View(Translator.getTerm("DocumentList"), null,
    // docPanel);
    mainViews[0] = new View(Translator.getTerm("InputDocumentList"), null, inputDocPanel);
    mainViews[1] = new View(Translator.getTerm("InputDocumentArea"), null, inputDocAreaScroll);

    for (int i = 0; i < mainViews.length; i++) {
        viewMap.addView(i, mainViews[i]);
    }
    rootWindow = Utils.createDODDLERootWindow(viewMap);
    setLayout(new BorderLayout());
    add(rootWindow, BorderLayout.CENTER);
    add(buttonPanel, BorderLayout.SOUTH);
}