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:edu.ku.brc.specify.plugins.ipadexporter.ManageDataSetsDlg.java

@SuppressWarnings({ "unchecked" })
@Override//  w w  w . j ava2 s.co m
public void createUI() {
    loadAndPushResourceBundle(iPadDBExporterPlugin.RESOURCE_NAME);
    setTitle(getResourceString("MNG_DS"));
    try {
        ActionListener addUsrAction = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                addUserToDS();
            }
        };
        ActionListener delUsrAction = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                removeUserFromDS();
            }
        };
        ActionListener delDSAction = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                removeDS();
            }
        };
        CellConstraints cc = new CellConstraints();
        PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g", "p,2px,p,2px,p, 12px, p,2px,p,2px,p"));

        JLabel dsLabel = createI18NLabel("YOUR_DATASETS");
        dataSetList = new JList(dataSetModel = new DefaultListModel());
        JScrollPane dsSp = createScrollPane(dataSetList, true);
        dsEDAPanel = new EditDeleteAddPanel(null, delDSAction, null);

        JLabel usrLabel = createI18NLabel("USRS_PER_DATASETS");
        usrList = new JList(usrModel = new DefaultListModel());
        JScrollPane usrSp = createScrollPane(usrList, true);
        usrEDAPanel = new EditDeleteAddPanel(null, delUsrAction, addUsrAction);
        contentPanel = pb.getPanel();

        int y = 1;
        pb.add(dsLabel, cc.xy(1, y));
        y += 2;
        pb.add(dsSp, cc.xy(1, y));
        y += 2;
        pb.add(dsEDAPanel, cc.xy(1, y));
        y += 2;

        pb.add(usrLabel, cc.xy(1, y));
        y += 2;
        pb.add(usrSp, cc.xy(1, y));
        y += 2;
        pb.add(usrEDAPanel, cc.xy(1, y));
        y += 2;

        pb.setDefaultDialogBorder();

        loadDataSetsIntoJList();

        dataSetList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    loadUsersForDataSetsIntoJList();

                    boolean isSelected = dataSetList.getSelectedIndex() > -1;
                    if (isSelected) {
                        dsEDAPanel.getDelBtn().setEnabled(true);
                        usrEDAPanel.getAddBtn().setEnabled(true);
                    }
                    dsEDAPanel.getDelBtn().setEnabled(isSelected);
                    usrEDAPanel.getAddBtn().setEnabled(isSelected);
                }
            }
        });

        usrList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    boolean isSelected = usrList.getSelectedIndex() > -1;
                    if (isSelected) {
                        usrEDAPanel.getDelBtn().setEnabled(true);
                    }
                    usrEDAPanel.getDelBtn().setEnabled(isSelected);
                }
            }
        });

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        popResourceBundle();
    }
    super.createUI();
}

From source file:BasicDnD.java

public BasicDnD() {
    super(new BorderLayout());
    JPanel leftPanel = createVerticalBoxPanel();
    JPanel rightPanel = createVerticalBoxPanel();

    // Create a table model.
    DefaultTableModel tm = new DefaultTableModel();
    tm.addColumn("Column 0");
    tm.addColumn("Column 1");
    tm.addColumn("Column 2");
    tm.addColumn("Column 3");
    tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" });
    tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" });
    tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" });
    tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" });

    // LEFT COLUMN
    // Use the table model to create a table.
    table = new JTable(tm);
    leftPanel.add(createPanelForComponent(table, "JTable"));

    // Create a color chooser.
    colorChooser = new JColorChooser();
    leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser"));

    // RIGHT COLUMN
    // Create a textfield.
    textField = new JTextField(30);
    textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast");
    rightPanel.add(createPanelForComponent(textField, "JTextField"));

    // Create a scrolled text area.
    textArea = new JTextArea(5, 30);
    textArea.setText("Favorite shows:\nBuffy, Alias, Angel");
    JScrollPane scrollPane = new JScrollPane(textArea);
    rightPanel.add(createPanelForComponent(scrollPane, "JTextArea"));

    // Create a list model and a list.
    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("Martha Washington");
    listModel.addElement("Abigail Adams");
    listModel.addElement("Martha Randolph");
    listModel.addElement("Dolley Madison");
    listModel.addElement("Elizabeth Monroe");
    listModel.addElement("Louisa Adams");
    listModel.addElement("Emily Donelson");
    list = new JList(listModel);
    list.setVisibleRowCount(-1);//from  ww w .  j  ava  2s.c  om
    list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    list.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            if (dl.getIndex() == -1) {
                return false;
            }
            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            if (!info.isDrop()) {
                return false;
            }

            // Check for String flavor
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                displayDropLocation("List doesn't accept a drop of this type.");
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            DefaultListModel listModel = (DefaultListModel) list.getModel();
            int index = dl.getIndex();
            boolean insert = dl.isInsert();
            // Get the current string under the drop.
            String value = (String) listModel.getElementAt(index);

            // Get the string that is being dropped.
            Transferable t = info.getTransferable();
            String data;
            try {
                data = (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }

            // Display a dialog with the drop information.
            String dropValue = "\"" + data + "\" dropped ";
            if (dl.isInsert()) {
                if (dl.getIndex() == 0) {
                    displayDropLocation(dropValue + "at beginning of list");
                } else if (dl.getIndex() >= list.getModel().getSize()) {
                    displayDropLocation(dropValue + "at end of list");
                } else {
                    String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1);
                    String value2 = (String) list.getModel().getElementAt(dl.getIndex());
                    displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\"");
                }
            } else {
                displayDropLocation(dropValue + "on top of " + "\"" + value + "\"");
            }

            /**
             * This is commented out for the basicdemo.html tutorial page. * If you
             * add this code snippet back and delete the * "return false;" line, the
             * list will accept drops * of type string. // Perform the actual
             * import. if (insert) { listModel.add(index, data); } else {
             * listModel.set(index, data); } return true;
             */
            return false;
        }

        public int getSourceActions(JComponent c) {
            return COPY;
        }

        protected Transferable createTransferable(JComponent c) {
            JList list = (JList) c;
            Object[] values = list.getSelectedValues();

            StringBuffer buff = new StringBuffer();

            for (int i = 0; i < values.length; i++) {
                Object val = values[i];
                buff.append(val == null ? "" : val.toString());
                if (i != values.length - 1) {
                    buff.append("\n");
                }
            }
            return new StringSelection(buff.toString());
        }
    });
    list.setDropMode(DropMode.ON_OR_INSERT);

    JScrollPane listView = new JScrollPane(list);
    listView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(listView, "JList"));

    // Create a tree.
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia");
    DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon");
    rootNode.add(sharon);
    DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya");
    sharon.add(maya);
    DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya");
    sharon.add(anya);
    sharon.add(new DefaultMutableTreeNode("Bongo"));
    maya.add(new DefaultMutableTreeNode("Muffin"));
    anya.add(new DefaultMutableTreeNode("Winky"));
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(treeView, "JTree"));

    // Create the toggle button.
    toggleDnD = new JCheckBox("Turn on Drag and Drop");
    toggleDnD.setActionCommand("toggleDnD");
    toggleDnD.addActionListener(this);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
    splitPane.setOneTouchExpandable(true);

    add(splitPane, BorderLayout.CENTER);
    add(toggleDnD, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:ListInput.java

public void appendResultSet(ResultSet results, int index, boolean toTitleCase) {
    textfield.setText("");
    DefaultListModel model = new DefaultListModel();
    try {/*from   www. java2 s  .  c o m*/
        while (results.next()) {
            String str = results.getString(index);
            if (toTitleCase) {
                str = Character.toUpperCase(str.charAt(0)) + str.substring(1);
            }

            model.addElement(str);
        }
    } catch (SQLException ex) {
        System.err.println("appendResultSet: " + ex.toString());
    }
    list.setModel(model);
    if (model.getSize() > 0)
        list.setSelectedIndex(0);
}

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

public void addProcess(MaltcmsLocalHostExecution p) {
    if (dlm == null) {
        dlm = new DefaultListModel();
        processList.setModel(dlm);//from  ww  w .  j  a  v a  2 s  .  com
    }
    dlm.addElement(p);
    if (!dlm.isEmpty()) {
        processList.setSelectedIndex(dlm.size() - 1);
    }
}

From source file:de.tor.tribes.ui.algo.AttackTimePanel.java

public final void reset() {
    jSendTimeFrame.setMinimumValue(0);/* ww  w  . jav a2 s  . com*/
    jSendTimeFrame.setMaximumColor(Constants.DS_BACK_LIGHT);
    jSendTimeFrame.setMinimumColor(Constants.DS_BACK_LIGHT);
    jSendTimeFrame.setMaximumValue(24);
    jSendTimeFrame.setSegmentSize(1);
    jSendTimeFrame.setUnit("h");
    jSendTimeFrame.setBackground(getBackground());
    jSendTimeFrame.setDecimalFormater(new DecimalFormat("##"));
    DefaultListModel model = new DefaultListModel();
    model.addElement(new TimeSpanDivider());
    jTimeFrameList.setModel(model);
    jTimeFrameList.setCellRenderer(new TimeFrameListCellRenderer());
    Calendar c = Calendar.getInstance();
    minSendTimeField.setDate(c.getTime());
    c.setTimeInMillis(System.currentTimeMillis() + DateUtils.MILLIS_PER_HOUR);
    maxArriveTimeField.setDate(c.getTime());
    dateTimeField.setDate(c.getTime());
}

From source file:gtu._work.ui.JarFinderUI.java

private void initGUI() {
    try {/* w  w  w  . java 2 s .co m*/

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setTitle("Jar finder");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("src dir", null, jPanel1, null);
                {
                    openDir = new JButton();
                    jPanel1.add(openDir, BorderLayout.NORTH);
                    openDir.setText("open dir");
                    openDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jButton1ActionPerformed(evt);
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(406, 255));
                    {
                        DefaultListModel jList1Model = new DefaultListModel();
                        try {
                            prop.load(new FileInputStream(CONFIG_FILE));
                            for (Enumeration<?> enu = prop.keys(); enu.hasMoreElements();) {
                                File val = new File((String) enu.nextElement());
                                jList1Model.addElement(val);
                            }
                        } catch (Exception ex) {
                            JCommonUtil.handleException("??:" + CONFIG_FILE, ex);
                        }
                        jarFileDirs = new JList();
                        jScrollPane1.setViewportView(jarFileDirs);
                        jarFileDirs.setModel(jList1Model);
                        jarFileDirs.setPreferredSize(new java.awt.Dimension(406, 221));
                        jarFileDirs.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                if (!JListUtil.newInstance(jarFileDirs).isCorrectMouseClick(evt)) {
                                    return;
                                }
                                File file = (File) JListUtil.getLeadSelectionObject(jarFileDirs);
                                try {
                                    Desktop.getDesktop().open(file);
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                        jarFileDirs.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(jarFileDirs).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("result", null, jPanel2, null);
                {
                    jPanel3 = new JPanel();
                    BorderLayout jPanel3Layout = new BorderLayout();
                    jPanel3.setLayout(jPanel3Layout);
                    jPanel2.add(jPanel3, BorderLayout.NORTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(406, 26));
                    {
                        searchText = new JTextField();
                        jPanel3.add(searchText, BorderLayout.WEST);
                        searchText.setPreferredSize(new java.awt.Dimension(326, 26));
                    }
                    {
                        search = new JButton();
                        jPanel3.add(search, BorderLayout.CENTER);
                        search.setText("search");
                        search.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                jButton2ActionPerformed(evt);
                            }
                        });
                    }
                }
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(406, 231));
                    {
                        ListModel searchResultModel = new DefaultListModel();
                        searchResult = new JList();
                        jScrollPane2.setViewportView(searchResult);
                        searchResult.setModel(searchResultModel);
                        searchResult.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                jList1MouseClicked(evt);
                            }
                        });
                        searchResult.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(searchResult).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
                {
                    resetFinder = new JButton();
                    jPanel2.add(resetFinder, BorderLayout.SOUTH);
                    resetFinder.setText("reset finder");
                    resetFinder.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            jarfinder.clear();
                        }
                    });
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("copy to", null, jPanel4, null);
                {
                    copyToBtn = new JButton();
                    jPanel4.add(copyToBtn, BorderLayout.NORTH);
                    copyToBtn.setText("copy to");
                    copyToBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                                    .getApproveSelectedFile();
                            if (file == null) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("copy to dir undefined!", getTitle());
                                return;
                            } else {
                                copyToFile = file;
                            }
                        }
                    });
                }
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel4.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        DefaultListModel copyToListModel = new DefaultListModel();
                        copyToList = new JList();
                        jScrollPane3.setViewportView(copyToList);
                        copyToList.setModel(copyToListModel);
                        {
                            panel = new JPanel();
                            jTabbedPane1.addTab("config", null, panel, null);
                            panel.setLayout(new FormLayout(
                                    new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC,
                                            FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
                                            ColumnSpec.decode("default:grow"), },
                                    new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                                            FormFactory.DEFAULT_ROWSPEC, }));
                            {
                                lblNewLabel = new JLabel("JD Gui");
                                panel.add(lblNewLabel, "2, 2, right, default");
                            }
                            {
                                jdGuiText = new JTextField();
                                JCommonUtil.jTextFieldSetFilePathMouseEvent(jdGuiText, false);
                                panel.add(jdGuiText, "4, 2, fill, default");
                                jdGuiText.setColumns(10);
                            }
                            {
                                saveConfigBtn = new JButton("");
                                saveConfigBtn.addActionListener(new ActionListener() {
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            configBean.reflectSetConfig(JarFinderUI.this);
                                            configBean.store();
                                            JCommonUtil._jOptionPane_showMessageDialog_info("?!");
                                        } catch (Exception ex) {
                                            JCommonUtil.handleException(ex);
                                        }
                                    }
                                });
                                panel.add(saveConfigBtn, "2, 24");
                            }
                        }
                        copyToList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                // copyToFile
                                if (evt.getClickCount() != 2) {
                                    return;
                                }
                                if (copyToList.getLeadSelectionIndex() == -1) {
                                    return;
                                }
                                if (copyToFile == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("copy to dir undefined!", getTitle());
                                    return;
                                }
                                DefaultListModel model = (DefaultListModel) copyToList.getModel();
                                Object val = model.getElementAt(copyToList.getLeadSelectionIndex());
                                StringBuilder sb = new StringBuilder();
                                sb.append("?\n");
                                sb.append("file : " + val + "\n");
                                sb.append("copy to dir : " + copyToFile + "\n");
                                ComfirmDialogResult result = JOptionPaneUtil.newInstance().confirmButtonYesNo()
                                        .showConfirmDialog(sb, getTitle());
                                File srcFile = new File((String) val);
                                if (!srcFile.exists()) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog(srcFile + "  not found!", getTitle());
                                    return;
                                }
                                File copyDestFile = new File(copyToFile, srcFile.getName());
                                switch (result) {
                                case YES_OK_OPTION:
                                    System.out.println("yes..");
                                    try {
                                        FileUtil.copyFile(srcFile, copyDestFile);
                                    } catch (IOException e) {
                                        JCommonUtil.handleException(e.toString(), e);
                                    }
                                    if (srcFile != null && //
                                    copyDestFile != null && //
                                    srcFile.length() == copyDestFile.length()) {
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("success!\n" + copyDestFile, getTitle());
                                    } else {
                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("failed!\n" + copyDestFile, getTitle());
                                    }
                                    break;
                                case NO_OPTION:
                                    System.out.println("no..");
                                    break;
                                }
                            }
                        });
                    }
                }
            }

            jTabbedPane1.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent evt) {
                    copyToList.setModel(searchResult.getModel());
                }
            });
        }
        this.setSize(562, 407);

        JCommonUtil.frameCloseDo(this, new WindowAdapter() {
            public void windowClosing(WindowEvent paramWindowEvent) {
                if (CONFIG_FILE.exists()) {
                    DefaultListModel model = (DefaultListModel) jarFileDirs.getModel();
                    for (Enumeration<?> enu = model.elements(); enu.hasMoreElements();) {
                        Object obj = enu.nextElement();
                        prop.setProperty(((File) obj).getAbsolutePath(), "");
                    }
                    try {
                        prop.store(new FileOutputStream(CONFIG_FILE), "testtesttesttest");
                    } catch (Exception e) {
                        JCommonUtil.handleException("", e);
                    }
                }
                setVisible(false);
                dispose();
            }
        });

        {
            configBean.reflectInit(this);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

@Override
public void actionPerformed(ActionEvent e) {
    ReportTableTab activeTab = getActiveTab();
    if (e.getActionCommand() != null && activeTab != null) {
        if (e.getActionCommand().equals("Copy")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.COPY_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("BBCopy")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CLIPBOARD_BB);
        } else if (e.getActionCommand().equals("Cut")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.CUT_TO_INTERNAL_CLIPBOARD);
        } else if (e.getActionCommand().equals("Paste")) {
            activeTab.transferSelection(ReportTableTab.TRANSFER_TYPE.FROM_INTERNAL_CLIPBOARD);
        } 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  a2s  . 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.getReportTable().getColumnCount(); i++) {
                TableColumnExt col = activeTab.getReportTable().getColumnExt(i);
                if (col.isVisible()) {
                    if (!col.getTitle().equals("Status") && !col.getTitle().equals("Typ")
                            && !col.getTitle().equals("Sonstiges")) {
                        model.addElement(col.getTitle());
                    }
                }
            }
            jXColumnList.setModel(model);
            jXColumnList.setSelectedIndex(0);
            jxSearchPane.setVisible(true);
        }
    }
}

From source file:gtu._work.ui.CheckJavaClassPathUI.java

private void initGUI() {
    try {/* w  w  w .  jav  a  2s  .  co m*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        setTitle("??importjava");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("", null, jPanel1, null);
                {
                    classPathText = new JTextField();
                    jPanel1.add(classPathText, BorderLayout.NORTH);
                    classPathText.addMouseListener(new MouseAdapter() {
                        public void mouseClicked(MouseEvent evt) {
                            if (StringUtils.isNotBlank(classPathText.getText())) {
                                String text = classPathText.getText();
                                DefaultListModel model = (DefaultListModel) classPathList.getModel();
                                boolean findOk = false;
                                for (int ii = 0; ii < model.size(); ii++) {
                                    String val = (String) model.getElementAt(ii);
                                    if (StringUtils.equals(val, text)) {
                                        findOk = true;
                                    }
                                }
                                if (!findOk) {
                                    model.addElement(text);
                                }
                            }
                        }
                    });
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(492, 302));
                    {
                        DefaultListModel classPathListModel = new DefaultListModel();
                        classPathList = new JList();

                        Set<String> clzSet = new HashSet<String>();
                        for (Enumeration<?> enu = configBean.getConfigProp().keys(); enu.hasMoreElements();) {
                            String key = (String) enu.nextElement();
                            if (key.contains(CLASSNAME_KEY)) {
                                clzSet.add(configBean.getConfigProp().getProperty(key));
                            }
                        }
                        for (String clzName : clzSet) {
                            classPathListModel.addElement(clzName);
                        }

                        jScrollPane1.setViewportView(classPathList);
                        classPathList.setModel(classPathListModel);
                        classPathList.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                JListUtil.newInstance(classPathList).defaultJListKeyPressed(evt);
                            }
                        });
                    }
                }
                {
                    executeBtn = new JButton();
                    jPanel1.add(executeBtn, BorderLayout.WEST);
                    executeBtn.setText("\u57f7\u884c");
                    executeBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            executeBtnActionPerformed(evt);
                        }
                    });
                }
                {
                    srcPathText = new JTextField();
                    if (configBean.getConfigProp().containsKey(SRCPATHTEXT_KEY)) {
                        srcPathText.setText(configBean.getConfigProp().getProperty(SRCPATHTEXT_KEY));
                    }

                    jPanel1.add(srcPathText, BorderLayout.SOUTH);
                    JCommonUtil.jTextFieldSetFilePathMouseEvent(srcPathText, true);
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("log", null, jPanel2, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(530, 350));
                    {
                        logArea = new JTextArea();
                        jScrollPane2.setViewportView(logArea);
                    }
                }
            }
        }
        pack();
        this.setSize(551, 417);
    } catch (Exception e) {
        //add your error handling code here
        e.printStackTrace();
    }
}

From source file:Assignment2.FarmManagementGUI.java

public void addFarm() {
    farmCoords = new DefaultListModel();
    farmCoordList.setModel(farmCoords);
    setPoints.openMap();
    addFarmDialog.setVisible(true);
}

From source file:com.emental.mindraider.ui.dialogs.OpenConceptByTagJDialog.java

public OpenConceptByTagJDialog(String dialogTitle, String selectionLabel, String buttonLabel,
        boolean showCancel) {
    super(dialogTitle);

    JPanel framePanel = new JPanel();
    framePanel.setBorder(new EmptyBorder(5, 10, 0, 10));
    framePanel.setLayout(new BorderLayout());

    // NORTH panel
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new BorderLayout());
    northPanel.add(new JLabel(selectionLabel), BorderLayout.NORTH);

    final JTextField tagLabel = new JTextField(TEXTFIELD_WIDTH);

    // data//w w  w .  j  a v a2s. c om
    tags = MindRaider.tagCustodian.getAllTags();
    ;
    if (tags == null) {
        tagLabel.setEnabled(false);
    }
    tagLabel.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent keyEvent) {
            if (keyEvent.getKeyCode() == KeyEvent.VK_ENTER) {
                logger.debug("Openning selected tag...");
                openTagSearchDialog();
            }
        }

        public void keyReleased(KeyEvent keyEvent) {
            getListModel().clear();
            shownTags.clear();
            if (tagLabel.getText().length() > 0) {
                for (TagEntry tag : tags) {
                    if (tag.getTagLabel().toLowerCase().startsWith(tagLabel.getText().toLowerCase())) {
                        getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                        shownTags.add(tag);
                    }
                }
            } else {
                // show all tags
                for (TagEntry tag : tags) {
                    getListModel().addElement(tag.getTagLabel() + " (" + tag.getCardinality() + ")");
                    shownTags.add(tag);
                }
            }
        }

        public void keyTyped(KeyEvent keyEvent) {
        }
    });
    northPanel.add(tagLabel, BorderLayout.SOUTH);
    framePanel.add(northPanel, BorderLayout.NORTH);

    // CENTER panel
    JPanel centerPanel = new JPanel();
    centerPanel.setLayout(new BorderLayout());
    centerPanel.add(new JLabel(Messages.getString("OpenConceptByTagJDialog.matchingTags")), BorderLayout.NORTH);

    defaultListModel = new DefaultListModel();
    list = new JList(defaultListModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    // list.addListSelectionListener(this);
    list.setVisibleRowCount(15);
    JScrollPane listScrollPane = new JScrollPane(list);
    centerPanel.add(listScrollPane, BorderLayout.SOUTH);
    framePanel.add(centerPanel, BorderLayout.CENTER);

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton openButton = new JButton(buttonLabel);
    southPanel.add(openButton);
    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            openTagSearchDialog();
        }
    });

    if (showCancel) {
        JButton cancelButton = new JButton(Messages.getString("OpenNotebookJDialog.cancel"));
        southPanel.add(cancelButton);
        cancelButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                OpenConceptByTagJDialog.this.dispose();
            }
        });
    }

    framePanel.add(southPanel, BorderLayout.SOUTH);

    getContentPane().add(framePanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}