Example usage for javax.swing.table DefaultTableModel DefaultTableModel

List of usage examples for javax.swing.table DefaultTableModel DefaultTableModel

Introduction

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

Prototype

public DefaultTableModel() 

Source Link

Document

Constructs a default DefaultTableModel which is a table of zero columns and zero rows.

Usage

From source file:ExtendedDnDDemo.java

private JPanel createTable() {
    DefaultTableModel model = new DefaultTableModel();

    model.addColumn("Column 0");
    model.addColumn("Column 1");
    model.addColumn("Column 2");
    model.addColumn("Column 3");

    model.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" });
    model.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" });
    model.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" });
    model.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" });

    JTable table = new JTable(model);
    table.getTableHeader().setReorderingAllowed(false);
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    JScrollPane scrollPane = new JScrollPane(table);
    scrollPane.setPreferredSize(new Dimension(400, 100));

    table.setDragEnabled(true);/*from w  w w . j  a va  2s.  c  o  m*/
    table.setTransferHandler(new TableTransferHandler());

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(scrollPane, BorderLayout.CENTER);
    panel.setBorder(BorderFactory.createTitledBorder("Table"));
    return panel;
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java

/**
 * Reset on cancel.
 */
public void resetOnCancel() {
    dataTable.setModel(new DefaultTableModel());
}

From source file:com.smanempat.controller.ControllerClassification.java

private void showXLS(JTextField txtFileDirectory, JTable tablePreview)
        throws FileNotFoundException, IOException {
    DefaultTableModel tableModel = new DefaultTableModel();
    File fileName = new File(txtFileDirectory.getText());
    FileInputStream inputStream = new FileInputStream(fileName);
    HSSFWorkbook workBook = new HSSFWorkbook(inputStream);
    HSSFSheet sheet = workBook.getSheetAt(0);

    int rowValue = sheet.getLastRowNum() + 1;
    int colValue = sheet.getRow(0).getLastCellNum();
    String[][] data = new String[rowValue][colValue];
    String[] colName = new String[colValue];
    for (int i = 0; i < rowValue; i++) {
        HSSFRow row = sheet.getRow(i);/*from   w w  w .ja  v  a2  s.c  o m*/
        for (int j = 0; j < colValue; j++) {
            HSSFCell cell = row.getCell(j);
            int type = cell.getCellType();
            Object returnCellValue = null;
            if (type == 0) {
                returnCellValue = cell.getNumericCellValue();
            } else if (type == 1) {
                returnCellValue = cell.getStringCellValue();
            }

            data[i][j] = returnCellValue.toString();
        }
    }

    for (int i = 0; i < colValue; i++) {
        colName[i] = data[0][i];
    }

    tableModel = new DefaultTableModel(data, colName);
    tablePreview.setModel(tableModel);
    tableModel.removeRow(0);
}

From source file:DatabaseBrowser.java

protected void refreshTable() {
    String catalog = (catalogBox.isEnabled() ? catalogBox.getSelectedItem().toString() : null);
    String schema = (schemaBox.isEnabled() ? schemaBox.getSelectedItem().toString() : null);
    String tableName = (String) tableBox.getSelectedItem();
    if (tableName == null) {
        table.setModel(new DefaultTableModel());
        return;/*from w  ww.  j a v  a  2 s.c  o m*/
    }
    String selectTable = (schema == null ? "" : schema + ".") + tableName;
    if (selectTable.indexOf(' ') > 0) {
        selectTable = "\"" + selectTable + "\"";
    }
    try {
        Statement stmt = connection.createStatement();
        ResultSet rset = stmt.executeQuery("SELECT * FROM " + selectTable);
        table.setModel(new ResultSetTableModel(rset));
    } catch (Exception e) {
    }
}

From source file:com.clough.android.adbv.view.MainFrame.java

public MainFrame() {
    initComponents();//from   ww  w .j a  va  2  s .c o  m
    setIconImage(ValueHolder.Icons.APPLICATION.getImage());
    setExtendedState(JFrame.MAXIMIZED_BOTH);

    Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
    double windowWidth = screenDimension.getWidth();
    double windowHeight = screenDimension.getHeight();
    int frameWidth = (int) (windowWidth * (3d / 4d));
    int frameHeight = (int) (windowHeight * (3d / 4d));
    setMinimumSize(new Dimension(frameWidth, frameHeight));
    setLocation((int) ((windowWidth - frameWidth) / 2d), (int) ((windowHeight - frameHeight) / 2d));

    int deviderSize = (int) (frameWidth * (1d / 100d));

    int deviderLocationForSpliter0 = (int) (frameWidth / 5d);
    splitPane0.setDividerLocation(deviderLocationForSpliter0);

    int deviderLocationForSpliter1 = (int) (frameWidth * (6d / 7d));
    splitPane1.setDividerLocation(deviderLocationForSpliter1);

    int subDeviderLocation = (int) (frameHeight / 6d);
    splitPane2.setDividerLocation(subDeviderLocation);

    queryHistoryContainerPanel.setMinimumSize(new Dimension(deviderLocationForSpliter0, 0));
    queryRootConatinerPanel.setMinimumSize(new Dimension(0, subDeviderLocation));

    queryingTextArea.requestFocus();

    resultTable.setModel(new DefaultTableModel() {

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

    });

    defaultTableModel = (DefaultTableModel) resultTable.getModel();
    resultTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    tableColumnAdjuster = new TableColumnAdjuster(resultTable);

    historyContainingPanel.setLayout(new GridLayout(0, 1));

}

From source file:org.apache.taverna.activities.xpath.ui.contextualview.XPathActivityMainContextualView.java

@Override
public JComponent getMainFrame() {
    jpMainPanel = new JPanel(new GridBagLayout());
    jpMainPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 2, 4, 2),
            BorderFactory.createEmptyBorder()));

    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.WEST;
    c.weighty = 0;/*  w w w. j  ava  2 s  .c o  m*/

    // --- XPath Expression ---

    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(5, 5, 5, 5);
    JLabel jlXPathExpression = new JLabel("XPath Expression:");
    jlXPathExpression.setFont(jlXPathExpression.getFont().deriveFont(Font.BOLD));
    jpMainPanel.add(jlXPathExpression, c);

    c.gridx++;
    c.weightx = 1.0;
    tfXPathExpression = new JTextField();
    tfXPathExpression.setEditable(false);
    jpMainPanel.add(tfXPathExpression, c);

    // --- Label to Show/Hide Mapping Table ---

    final JLabel jlShowHideNamespaceMappings = new JLabel("Show namespace mappings...");
    jlShowHideNamespaceMappings.setForeground(Color.BLUE);
    jlShowHideNamespaceMappings.setCursor(new Cursor(Cursor.HAND_CURSOR));
    jlShowHideNamespaceMappings.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            spXPathNamespaceMappings.setVisible(!spXPathNamespaceMappings.isVisible());
            jlShowHideNamespaceMappings.setText(
                    (spXPathNamespaceMappings.isVisible() ? "Hide" : "Show") + " namespace mappings...");
            thisContextualView.revalidate();
        }
    });

    c.gridx = 0;
    c.gridy++;
    c.gridwidth = 2;
    c.weightx = 1.0;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    jpMainPanel.add(jlShowHideNamespaceMappings, c);

    // --- Namespace Mapping Table ---

    xpathNamespaceMappingsTableModel = new DefaultTableModel() {
        /**
         * No cells should be editable
         */
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return (false);
        }
    };
    xpathNamespaceMappingsTableModel.addColumn("Namespace Prefix");
    xpathNamespaceMappingsTableModel.addColumn("Namespace URI");

    jtXPathNamespaceMappings = new JTable();
    jtXPathNamespaceMappings.setModel(xpathNamespaceMappingsTableModel);
    jtXPathNamespaceMappings.setPreferredScrollableViewportSize(new Dimension(200, 90));
    // TODO - next line is to be enabled when Taverna is migrated to Java
    // 1.6; for now it's fine to run without this
    // jtXPathNamespaceMappings.setFillsViewportHeight(true); // makes sure
    // that when the dedicated area is larger than the table, the latter is
    // stretched vertically to fill the empty space

    jtXPathNamespaceMappings.getColumnModel().getColumn(0).setPreferredWidth(20); // set
    // relative
    // sizes of
    // columns
    jtXPathNamespaceMappings.getColumnModel().getColumn(1).setPreferredWidth(300);

    c.gridy++;
    spXPathNamespaceMappings = new JScrollPane(jtXPathNamespaceMappings);
    spXPathNamespaceMappings.setVisible(false);
    jpMainPanel.add(spXPathNamespaceMappings, c);

    // populate the view with values
    refreshView();

    return jpMainPanel;
}

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

private void initGUI() {
    try {/*from   www  .j a  v  a  2  s.com*/
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        this.setFocusable(false);
        this.setTitle("SVN lastest commit wather");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("svn dir", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        TableModel svnTableModel = new DefaultTableModel();
                        svnTable = new JTable();
                        jScrollPane1.setViewportView(svnTable);
                        svnTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                try {
                                    if (evt.getButton() == 3) {
                                        final List<File> list = new ArrayList<File>();
                                        SvnFile svnFile = null;
                                        final StringBuilder sb = new StringBuilder();
                                        for (int row : svnTable.getSelectedRows()) {
                                            svnFile = (SvnFile) svnTable.getModel().getValueAt(
                                                    svnTable.getRowSorter().convertRowIndexToModel(row),
                                                    SvnTableColumn.SVN_FILE.pos);
                                            list.add(svnFile.file);
                                            sb.append(svnFile.file.getName() + ",");
                                        }
                                        if (sb.length() > 200) {
                                            sb.delete(200, sb.length() - 1);
                                        }
                                        JMenuItem copySelectedMeun = new JMenuItem();
                                        copySelectedMeun.setText("copy selected file : " + list.size());
                                        copySelectedMeun.addActionListener(new ActionListener() {
                                            public void actionPerformed(ActionEvent e) {
                                                if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil
                                                        .newInstance().iconPlainMessage().confirmButtonYesNo()
                                                        .showConfirmDialog(
                                                                "are you sure copy files :\n" + sb + "\n???",
                                                                "COPY SELECTED FILE : " + list.size())) {
                                                    return;
                                                }
                                                final File copyToDir = JFileChooserUtil.newInstance()
                                                        .selectDirectoryOnly().showOpenDialog()
                                                        .getApproveSelectedFile();
                                                if (copyToDir == null) {
                                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                                            .showMessageDialog("dir folder is not correct!",
                                                                    "ERROR");
                                                    return;
                                                }
                                                new Thread(Thread.currentThread().getThreadGroup(),
                                                        new Runnable() {
                                                            public void run() {
                                                                StringBuilder errMsg = new StringBuilder();
                                                                int errCount = 0;
                                                                for (File f : list) {
                                                                    try {
                                                                        FileUtil.copyFile(f, new File(copyToDir,
                                                                                f.getName()));
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                        errCount++;
                                                                        errMsg.append(f + "\n");
                                                                    }
                                                                }

                                                                JOptionPaneUtil.newInstance().iconPlainMessage()
                                                                        .showMessageDialog(
                                                                                "copy completed!\nerror : "
                                                                                        + errCount
                                                                                        + "\nerror list : \n"
                                                                                        + errMsg,
                                                                                "COMPLETED");
                                                            }
                                                        }, "copySelectedFiles_" + hashCode()).start();
                                            }
                                        });

                                        JMenuItem copySelectedOringTreeMeun = new JMenuItem();
                                        copySelectedOringTreeMeun
                                                .setText("copy selected file (orign tree): " + list.size());
                                        copySelectedOringTreeMeun.addActionListener(new ActionListener() {
                                            public void actionPerformed(ActionEvent e) {
                                                if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil
                                                        .newInstance().iconPlainMessage().confirmButtonYesNo()
                                                        .showConfirmDialog(
                                                                "are you sure copy files :\n" + sb + "\n???",
                                                                "COPY SELECTED FILE : " + list.size())) {
                                                    return;
                                                }
                                                final File copyToDir = JFileChooserUtil.newInstance()
                                                        .selectDirectoryOnly().showOpenDialog()
                                                        .getApproveSelectedFile();
                                                if (copyToDir == null) {
                                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                                            .showMessageDialog("dir folder is not correct!",
                                                                    "ERROR");
                                                    return;
                                                }
                                                new Thread(Thread.currentThread().getThreadGroup(),
                                                        new Runnable() {
                                                            public void run() {
                                                                File srcBaseDir = FileUtil
                                                                        .exportReceiveBaseDir(list);
                                                                int cutLength = 0;
                                                                if (srcBaseDir != null) {
                                                                    cutLength = srcBaseDir.getAbsolutePath()
                                                                            .length();
                                                                }

                                                                StringBuilder errMsg = new StringBuilder();
                                                                int errCount = 0;
                                                                File newFile = null;
                                                                for (File f : list) {
                                                                    try {
                                                                        newFile = new File(copyToDir + "/"
                                                                                + f.getAbsolutePath()
                                                                                        .substring(cutLength),
                                                                                f.getName());
                                                                        newFile.getParentFile().mkdirs();
                                                                        FileUtil.copyFile(f, newFile);
                                                                    } catch (IOException e) {
                                                                        e.printStackTrace();
                                                                        errCount++;
                                                                        errMsg.append(f + "\n");
                                                                    }
                                                                }

                                                                JOptionPaneUtil.newInstance().iconPlainMessage()
                                                                        .showMessageDialog(
                                                                                "copy completed!\nerror : "
                                                                                        + errCount
                                                                                        + "\nerror list : \n"
                                                                                        + errMsg,
                                                                                "COMPLETED");
                                                            }
                                                        }, "copySelectedFiles_orignTree_" + hashCode()).start();
                                            }
                                        });

                                        JPopupMenuUtil.newInstance(svnTable).applyEvent(evt)
                                                .addJMenuItem(copySelectedMeun, copySelectedOringTreeMeun)
                                                .show();
                                    }

                                    if (!JMouseEventUtil.buttonLeftClick(2, evt)) {
                                        return;
                                    }
                                    int row = JTableUtil.newInstance(svnTable).getSelectedRow();
                                    SvnFile svnFile = (SvnFile) svnTable.getModel().getValueAt(row,
                                            SvnTableColumn.SVN_FILE.pos);
                                    String command = String.format("cmd /c call \"%s\"", svnFile.file);
                                    System.out.println(command);
                                    try {
                                        Runtime.getRuntime().exec(command);
                                    } catch (IOException e) {
                                        e.printStackTrace();
                                    }
                                } catch (Exception ex) {
                                    JCommonUtil.handleException(ex);
                                }
                            }
                        });
                        svnTable.setModel(svnTableModel);
                        JTableUtil.defaultSetting(svnTable);
                    }
                }
                {
                    jPanel3 = new JPanel();
                    jPanel1.add(jPanel3, BorderLayout.NORTH);
                    jPanel3.setPreferredSize(new java.awt.Dimension(379, 35));
                    {
                        filterText = new JTextField();
                        jPanel3.add(filterText);
                        filterText.setPreferredSize(new java.awt.Dimension(258, 24));
                        filterText.getDocument()
                                .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
                                    public void process(DocumentEvent event) {
                                        try {
                                            String scanText = JCommonUtil.getDocumentText(event);
                                            reloadSvnTable(scanText, _defaultScanProcess);
                                        } catch (Exception ex) {
                                            JCommonUtil.handleException(ex);
                                        }
                                    }
                                }));
                    }
                    {
                        choiceSvnDir = new JButton();
                        jPanel3.add(choiceSvnDir);
                        choiceSvnDir.setText("choice svn dir");
                        choiceSvnDir.setPreferredSize(new java.awt.Dimension(154, 24));
                        choiceSvnDir.addActionListener(new ActionListener() {

                            Pattern svnOutputPattern = Pattern
                                    .compile("\\s*(\\d*)\\s+(\\d+)\\s+(\\w+)\\s+([\\S]+)");

                            public void actionPerformed(ActionEvent evt) {
                                try {
                                    System.out.println("choiceSvnDir.actionPerformed, event=" + evt);
                                    final File svnDir = JFileChooserUtil.newInstance().selectDirectoryOnly()
                                            .showOpenDialog().getApproveSelectedFile();
                                    if (svnDir == null) {
                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("dir is not correct!", "ERROR");
                                        return;
                                    }
                                    Thread thread = new Thread(Thread.currentThread().getThreadGroup(),
                                            new Runnable() {
                                                public void run() {
                                                    long startTime = System.currentTimeMillis();
                                                    String command = String
                                                            .format("cmd /c svn status -v \"%s\"", svnDir);
                                                    Matcher matcher = null;
                                                    try {
                                                        long projectLastestVersion = 0;
                                                        SvnFile svnFile = null;
                                                        Process process = Runtime.getRuntime().exec(command);
                                                        BufferedReader reader = new BufferedReader(
                                                                new InputStreamReader(process.getInputStream(),
                                                                        "BIG5"));
                                                        for (String line = null; (line = reader
                                                                .readLine()) != null;) {
                                                            matcher = svnOutputPattern.matcher(line);
                                                            if (matcher.find()) {
                                                                try {
                                                                    if (StringUtils
                                                                            .isNotBlank(matcher.group(1))) {
                                                                        projectLastestVersion = Math.max(
                                                                                projectLastestVersion,
                                                                                Long.parseLong(
                                                                                        matcher.group(1)));
                                                                    }
                                                                    svnFile = new SvnFile();
                                                                    svnFile.lastestVersion = Long
                                                                            .parseLong(matcher.group(2));
                                                                    svnFile.author = matcher.group(3);
                                                                    svnFile.filePath = matcher.group(4);
                                                                    svnFile.file = new File(svnFile.filePath);
                                                                    svnFile.fileName = svnFile.file.getName();
                                                                    svnFileSet.add(svnFile);
                                                                    authorSet.add(svnFile.author);
                                                                    String extension = null;
                                                                    if (svnFile.file.isFile()
                                                                            && (extension = getExtension(
                                                                                    svnFile.fileName)) != null) {
                                                                        fileExtenstionSet.add(extension);
                                                                    }
                                                                } catch (Exception ex) {
                                                                    ex.printStackTrace();
                                                                }
                                                            } else {
                                                                System.out.println("ignore : " + line);
                                                            }
                                                        }
                                                        reader.close();
                                                        lastestVersion = projectLastestVersion;
                                                        projectName = svnDir.getName();
                                                        resetUiAndShowMessage(startTime, projectName,
                                                                projectLastestVersion);
                                                    } catch (IOException e) {
                                                        JCommonUtil.handleException(e);
                                                    }
                                                }
                                            }, "loadSvnLastest_" + this.hashCode());
                                    thread.setDaemon(true);
                                    thread.start();
                                    setTitle("sweeping...");
                                } catch (Exception ex) {
                                    JCommonUtil.handleException(ex);
                                }
                            }

                            String getExtension(String name) {
                                int pos = -1;
                                if ((pos = name.lastIndexOf(".")) != -1) {
                                    return name.substring(pos).toLowerCase();
                                }
                                return null;
                            }
                        });
                    }
                    {
                        jLabel1 = new JLabel();
                        jPanel3.add(jLabel1);
                        jLabel1.setText("match :");
                        jLabel1.setPreferredSize(new java.awt.Dimension(56, 22));
                    }
                    {
                        matchCount = new JLabel();
                        jPanel3.add(matchCount);
                        matchCount.setPreferredSize(new java.awt.Dimension(82, 22));
                    }
                }
            }
            {
                jPanel2 = new JPanel();
                FlowLayout jPanel2Layout = new FlowLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("config", null, jPanel2, null);
                {
                    DefaultComboBoxModel authorComboBoxModel = new DefaultComboBoxModel();
                    authorComboBox = new JComboBox();
                    jPanel2.add(authorComboBox);
                    authorComboBox.setModel(authorComboBoxModel);
                    authorComboBox.setPreferredSize(new java.awt.Dimension(260, 24));
                    authorComboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                Object author = authorComboBox.getSelectedItem();
                                if (author instanceof Map.Entry) {
                                    Map.Entry<?, ?> entry = (Map.Entry<?, ?>) author;
                                    reloadSvnTable((String) entry.getKey(), _authorScanProcess);
                                } else {
                                    reloadSvnTable((String) author, _authorScanProcess);
                                }
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                            }
                        }
                    });
                }
                {
                    ComboBoxModel jComboBox1Model = new DefaultComboBoxModel();
                    fileExtensionComboBox = new JComboBox();
                    jPanel2.add(fileExtensionComboBox);
                    fileExtensionComboBox.setModel(jComboBox1Model);
                    fileExtensionComboBox.setPreferredSize(new java.awt.Dimension(186, 24));
                    fileExtensionComboBox.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                String extension = (String) fileExtensionComboBox.getSelectedItem();
                                reloadSvnTable(extension, _fileExtensionScanProcess);
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                            }
                        }
                    });
                }
                {
                    jScrollPane2 = new JScrollPane();
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(130, 200));
                    jPanel2.add(jScrollPane2);
                    {
                        DefaultListModel model = new DefaultListModel();
                        fileExtensionFilter = new JList();
                        jScrollPane2.setViewportView(fileExtensionFilter);
                        fileExtensionFilter.setModel(model);
                        fileExtensionFilter.addListSelectionListener(new ListSelectionListener() {
                            public void valueChanged(ListSelectionEvent evt) {
                                try {
                                    System.out
                                            .println(Arrays.toString(fileExtensionFilter.getSelectedValues()));
                                    String extensionStr = "";
                                    StringBuilder sb = new StringBuilder();
                                    for (Object val : fileExtensionFilter.getSelectedValues()) {
                                        sb.append(val + ",");
                                    }
                                    extensionStr = (sb.length() > 0 ? sb.deleteCharAt(sb.length() - 1) : sb)
                                            .toString();
                                    System.out.format("extensionStr = [%s]\n", extensionStr);
                                    multiExtendsionFilter.setName(extensionStr);
                                } catch (Exception ex) {
                                    JCommonUtil.handleException(ex);
                                }
                            }
                        });
                    }
                }
                {
                    multiExtendsionFilter = new JButton();
                    jPanel2.add(multiExtendsionFilter);
                    multiExtendsionFilter.setText("multi extension filter");
                    multiExtendsionFilter.setPreferredSize(new java.awt.Dimension(166, 34));
                    multiExtendsionFilter.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                reloadSvnTable(multiExtendsionFilter.getName(), _fileExtensionMultiScanProcess);
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                            }
                        }
                    });
                }
                {
                    loadAuthorReference = new JButton();
                    jPanel2.add(loadAuthorReference);
                    loadAuthorReference.setText("load author reference");
                    loadAuthorReference.setPreferredSize(new java.awt.Dimension(188, 35));
                    loadAuthorReference.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                authorProps.load(new FileInputStream(file));
                                reloadAuthorComboBox();
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                            }
                        }
                    });
                }
                {
                    saveCurrentData = new JButton();
                    jPanel2.add(saveCurrentData);
                    saveCurrentData.setText("save current data");
                    saveCurrentData.setPreferredSize(new java.awt.Dimension(166, 34));
                    saveCurrentData.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                File saveDataConfig = new File(jarExistLocation, getSaveCurrentDataFileName());
                                ObjectOutputStream writer = new ObjectOutputStream(
                                        new FileOutputStream(saveDataConfig));
                                writer.writeObject(projectName);
                                writer.writeObject(authorSet);
                                writer.writeObject(fileExtenstionSet);
                                writer.writeObject(svnFileSet);
                                writer.writeObject(authorProps);
                                writer.writeObject(lastestVersion);
                                writer.flush();
                                writer.close();

                                JOptionPaneUtil.newInstance().iconInformationMessage()
                                        .showMessageDialog("current project : " + projectName
                                                + " save completed! \n" + saveDataConfig, "SUCCESS");
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                            }
                        }
                    });
                }
                {
                    loadDataFromFile = new JButton();
                    jPanel2.add(loadDataFromFile);
                    loadDataFromFile.setText("load data cfg");
                    loadDataFromFile.setPreferredSize(new java.awt.Dimension(165, 35));
                    loadDataFromFile.addActionListener(new ActionListener() {
                        @SuppressWarnings("unchecked")
                        public void actionPerformed(ActionEvent evt) {
                            try {
                                File file = JFileChooserUtil.newInstance().selectFileOnly()
                                        .addAcceptFile(".cfg", ".cfg").showOpenDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                long startTime = System.currentTimeMillis();
                                ObjectInputStream input = new ObjectInputStream(new FileInputStream(file));
                                projectName = (String) input.readObject();
                                authorSet = (Set<String>) input.readObject();
                                fileExtenstionSet = (Set<String>) input.readObject();
                                svnFileSet = (Set<SvnFile>) input.readObject();
                                authorProps = (Properties) input.readObject();
                                lastestVersion = (Long) input.readObject();
                                input.close();

                                resetUiAndShowMessage(startTime, projectName, lastestVersion);
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                            }
                        }
                    });
                }
            }
        }
        pack();
        this.setSize(726, 459);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.smanempat.controller.ControllerClassification.java

private void showXLSX(JTextField txtFileDirectory, JTable tablePreview)
        throws FileNotFoundException, IOException {
    DefaultTableModel tableModel = new DefaultTableModel();
    File fileName = new File(txtFileDirectory.getText());
    FileInputStream inputStream = new FileInputStream(fileName);
    XSSFWorkbook workbook = new XSSFWorkbook(inputStream);
    XSSFSheet sheet = workbook.getSheetAt(0);

    int rowValue = sheet.getLastRowNum() + 1;
    int colValue = sheet.getRow(0).getLastCellNum();
    String[][] data = new String[rowValue][colValue];
    String[] colName = new String[colValue];
    for (int i = 0; i < rowValue; i++) {
        XSSFRow row = sheet.getRow(i);/*  w  w w . j  a v  a  2  s. c o m*/
        for (int j = 0; j < colValue; j++) {
            XSSFCell cell = row.getCell(j);
            int type = cell.getCellType();
            Object returnCellValue = null;
            if (type == 0) {
                returnCellValue = cell.getNumericCellValue();
            } else if (type == 1) {
                returnCellValue = cell.getStringCellValue();
            }

            data[i][j] = returnCellValue.toString();
        }
    }

    for (int i = 0; i < colValue; i++) {
        colName[i] = data[0][i];
    }

    tableModel = new DefaultTableModel(data, colName);
    tablePreview.setModel(tableModel);
    tableModel.removeRow(0);
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java

protected JPanel getSeriesPanel(final JDialog dialog, ChartMouseEvent event) {
    MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset();
    MotionBubbleRenderer renderer = (MotionBubbleRenderer) event.getChart().getXYPlot().getRenderer();
    MotionTableModel model = dataset.getTableModel();
    DefaultTableModel tModel = new DefaultTableModel();
    ArrayList<Integer> visibleSeries = renderer.getVisibleSeries();
    ArrayList<String> rowIds = new ArrayList<String>();

    int columnCount = model.getColumnCount();
    int r = 0;/*from ww  w .j a  v  a2 s  .c  om*/

    for (int c = 0; c < columnCount; c++) {
        tModel.addColumn(model.getColumnName(c));
    }

    Iterator<Integer> itr = visibleSeries.iterator();

    while (itr.hasNext()) {
        ArrayList<Integer> rows = model.getKeyMap().get(dataset.getSeriesKey(itr.next()));

        Iterator<Integer> rItr = rows.iterator();

        while (rItr.hasNext()) {
            int row = rItr.next();

            tModel.addRow(new Object[0]);
            rowIds.add(new String(row + ":"));

            for (int c = 0; c < columnCount; c++) {
                tModel.setValueAt(model.getValueAt(row, c), r, c);
            }

            r++;
        }
    }

    return getPanel(dialog, tModel, rowIds);
}

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDoseResponseController.java

/**
 * Reset views on cancel//from  w  w w  .j  a  va  2 s.  c  o  m
 */
@Override
public void resetOnCancel() {
    super.resetOnCancel();
    dRAnalysisGroup = null;
    dRInputController.onCancel();
    //remove tables, graphs and subpanels
    dRInputController.getdRInputPanel().getSlopesTable().setModel(new DefaultTableModel());
    dRInitialController.getInitialChartPanel().setChart(null);
    dRNormalizedController.getNormalizedChartPanel().setChart(null);
    dRResultsController.getDupeInitialChartPanel().setChart(null);
    dRResultsController.getDupeNormalizedChartPanel().setChart(null);
    //set view back to first one
    dRPanel.getInputDRButton().setSelected(true);
    dRPanel.revalidate();
    dRPanel.repaint();
}