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:boundary.ReportProduce.java

private void setMusicianTbl(String session) {
    DefaultTableModel model = new DefaultTableModel();
    jTable3.setModel(model);/*from  w  w w. j  av a  2s .c  om*/
    model.addColumn("ID");
    model.addColumn("Instrument");
    for (Musician entry : ReportProduceControl.getMusicians(Integer.valueOf(session))) {
        model.addRow(new Object[] { entry.getFreelancerID(), entry.getType() });
    }
}

From source file:de.main.sessioncreator.DesktopApplication1View.java

private void showReportPanel() {
    sessionWizardMenuItem.setEnabled(true);
    reviewVieMenuItem.setEnabled(true);//from  w ww.  j a v  a  2s  .co  m
    sessionReportMenuItem.setEnabled(false);
    viewReviewsPanel.setVisible(false);
    mainPanel.validate();
    wizardPanel.setVisible(false);
    mainPanel.validate();
    reportOverviewTable.setVisible(false);
    reportPanel.setVisible(true);
    mainPanel.validate();
    this.getFrame().setTitle("SessionCreator - Report");
    //Backgroundprozess to fill data to the reportPanel
    class ReportData extends SwingWorker<DefaultTableModel, Void> {

        @Override
        protected DefaultTableModel doInBackground() throws Exception {
            rh.addReport(reportChartPanel);
            reportScrollPOverviewTabel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            reportScrollPOverviewTabel.setToolTipText("Please wait...");
            reportlblSum.setText("Sums of Charters done: <counting>");
            progressBar.setIndeterminate(true);
            progressBar.setVisible(true);
            model = new DefaultTableModel();
            reportOverviewTable.removeAll();
            model = rh.getTableModel();
            reportOverviewTable.setModel(model);
            reportOverviewTable.setVisible(true);

            String count = rh.getAllSessionCount(model);
            reportlblSum.setText("Sums of Charters done: " + count);
            String[] text = rh.getAllBugsAndIssues();
            reportlblBug.setText(text[0]);
            reportlblIssue.setText(text[1]);

            return model;
        }

        @Override
        protected void done() {
            try {
                reportScrollPOverviewTabel.setCursor(Cursor.getDefaultCursor());
                reportScrollPOverviewTabel.setToolTipText("");
                progressBar.setIndeterminate(false);
                progressBar.setVisible(false);
                reportScrollPOverviewTabel.setEnabled(true);
                reportOverviewTable.setFillsViewportHeight(true);
                reportOverviewTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
                TableRowSorter<DefaultTableModel> rowSorter = new TableRowSorter<DefaultTableModel>(model);
                reportOverviewTable.setRowSorter(rowSorter);
                rowSorter.setComparator(1, new Comparator<Integer>() {

                    @Override
                    public int compare(Integer int1, Integer int2) {
                        return int1.intValue() - int2.intValue();
                    }
                });
                TableColumn column = null;

                for (int i = 0; i < 2; i++) {
                    column = reportOverviewTable.getColumnModel().getColumn(i);
                    if (i == 1) {
                        column.setPreferredWidth(10); //third column is bigger
                        DefaultTableCellRenderer myRenderer = new DefaultTableCellRenderer();
                        //Textalignment in second column right
                        myRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
                        column.setCellRenderer(myRenderer);
                    } else {
                        column.setPreferredWidth(490);
                    }
                }

            } catch ( /* InterruptedException, ExecutionException */Exception e) {
            }
        }
    }
    new ReportData().execute();
}

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

private void initGUI() {
    try {//from  ww  w .ja v a 2s  . co  m
        BorderLayout thisLayout = new BorderLayout();
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(thisLayout);
        this.setTitle("save file to properties");
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("load", null, jPanel1, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel1.add(jScrollPane2, BorderLayout.CENTER);
                    {
                        textArea = new JTextArea();
                        jScrollPane2.setViewportView(textArea);
                    }
                }
                {
                    jPanel2 = new JPanel();
                    jPanel1.add(jPanel2, BorderLayout.NORTH);
                    jPanel2.setPreferredSize(new java.awt.Dimension(400, 40));
                    {
                        addPropsFile = new JButton();
                        jPanel2.add(addPropsFile);
                        addPropsFile.setText("load properties from file");
                        addPropsFile.setPreferredSize(new java.awt.Dimension(234, 30));
                        addPropsFile.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                try {
                                    props.load(new InputStreamReader(new FileInputStream(file),
                                            (String) openUnknowFilecharSet.getSelectedItem()));
                                    reloadPropertiesTable();
                                } catch (Exception e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                    {
                        openFile = new JButton();
                        jPanel2.add(openFile);
                        openFile.setText("open unknow file");
                        openFile.setPreferredSize(new java.awt.Dimension(204, 30));
                        openFile.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                try {
                                    String encode = (String) openUnknowFilecharSet.getSelectedItem();
                                    BufferedReader reader = new BufferedReader(
                                            new InputStreamReader(new FileInputStream(file), encode));
                                    StringBuilder sb = new StringBuilder();
                                    for (String line = null; (line = reader.readLine()) != null;) {
                                        sb.append(line + "\n");
                                    }
                                    reader.close();
                                    textArea.setText(textArea.getText() + "\n" + sb);
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                    {
                        ComboBoxModel openUnknowFilecharSetModel = new DefaultComboBoxModel(
                                new String[] { "BIG5", "UTF8" });
                        openUnknowFilecharSet = new JComboBox();
                        jPanel2.add(openUnknowFilecharSet);
                        openUnknowFilecharSet.setModel(openUnknowFilecharSetModel);
                        openUnknowFilecharSet.setPreferredSize(new java.awt.Dimension(73, 24));
                    }
                    {
                        appendTextAreaToProps = new JButton();
                        jPanel2.add(appendTextAreaToProps);
                        appendTextAreaToProps.setText("append textarea to properties");
                        appendTextAreaToProps.setPreferredSize(new java.awt.Dimension(227, 30));
                        appendTextAreaToProps.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                if (StringUtils.isBlank(textArea.getText())) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("textArea is empty", "ERROR");
                                    return;
                                }
                                try {
                                    BufferedReader reader = new BufferedReader(
                                            new StringReader(textArea.getText()));
                                    int pos = -1;
                                    String key = null;
                                    String value = null;
                                    for (String line = null; (line = reader.readLine()) != null;) {
                                        if ((pos = line.lastIndexOf("=")) != -1) {
                                            key = line.substring(0, pos);
                                            value = line.substring(pos + 1);
                                            props.put(key, value);
                                        }
                                    }
                                    reader.close();
                                    JOptionPaneUtil.newInstance().iconInformationMessage()
                                            .showMessageDialog("append success!", "SUCCESS");
                                    reloadPropertiesTable();
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("props edit", null, jPanel3, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel3.add(jScrollPane1, BorderLayout.CENTER);
                    jScrollPane1.setPreferredSize(new java.awt.Dimension(629, 361));
                    {
                        TableModel propsTableModel = new DefaultTableModel();
                        propsTable = new JTable();
                        jScrollPane1.setViewportView(propsTable);
                        propsTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                if (propsTable.getRowCount() == 0) {
                                    return;
                                }
                                int rowPos = JTableUtil.newInstance(propsTable).getSelectedRow();
                                Object key = propsTable.getValueAt(rowPos, 0);
                                Object value = propsTable.getValueAt(rowPos, 1);

                                JMenuItem insertRowItem = JTableUtil.newInstance(propsTable)
                                        .jMenuItem_addRow(false, null);
                                insertRowItem.setText("inert row...");

                                String rowInfo = "delete row : [" + key + "] = [" + value + "]";
                                JMenuItem delRowItem = JTableUtil.newInstance(propsTable)
                                        .jMenuItem_removeRow("are you sure remove row : \n" + rowInfo);
                                delRowItem.setText(rowInfo);

                                JPopupMenuUtil.newInstance(propsTable).applyEvent(evt)
                                        .addJMenuItem(insertRowItem, delRowItem).show();
                            }
                        });
                        propsTable.setModel(propsTableModel);
                        JTableUtil.defaultSetting(propsTable);
                    }
                }
                {
                    jPanel4 = new JPanel();
                    jPanel3.add(jPanel4, BorderLayout.SOUTH);
                    jPanel4.setPreferredSize(new java.awt.Dimension(629, 45));
                    {
                        clearProps = new JButton();
                        jPanel4.add(clearProps);
                        clearProps.setText("clear properties");
                        clearProps.setPreferredSize(new java.awt.Dimension(182, 36));
                        clearProps.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                props.clear();
                                reloadPropertiesTable();
                            }
                        });
                    }
                    {
                        savePropsToFile = new JButton();
                        jPanel4.add(savePropsToFile);
                        savePropsToFile.setText("save properties to file");
                        savePropsToFile.setPreferredSize(new java.awt.Dimension(182, 36));
                        savePropsToFile.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog()
                                        .getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("file is not correct!", "ERROR");
                                    return;
                                }
                                try {
                                    props.clear();
                                    DefaultTableModel model = (DefaultTableModel) propsTable.getModel();
                                    Object key = null;
                                    Object value = null;
                                    for (int ii = 0; ii < model.getRowCount(); ii++) {
                                        key = model.getValueAt(ii, 0);
                                        value = model.getValueAt(ii, 1);
                                        props.put(key, value);
                                    }
                                    props.store(new FileOutputStream(file),
                                            SaveFileToPropertiesUI.class.getSimpleName());
                                    JOptionPaneUtil.newInstance().iconInformationMessage()
                                            .showMessageDialog("save completed!\n" + file, "SUCCESS");
                                } catch (IOException e) {
                                    JCommonUtil.handleException(e);
                                }
                            }
                        });
                    }
                }
            }
        }
        pack();
        this.setSize(798, 505);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

@Override
protected void showAlternativeView() {
    final TableModel model;
    if (computedDatas != null && computedDatas.length > 0) {
        model = new ScatterPlotTableModel(getRasterName(), getCorrelativeDataName(), computedDatas);
    } else {//from  w w w.  j a  v  a 2  s .  co  m
        model = new DefaultTableModel();
    }
    final TableViewPagePanel alternativPanel = (TableViewPagePanel) getAlternativeView();
    alternativPanel.setModel(model);
    super.showAlternativeView();
}

From source file:gtu._work.mvn.MavenRepositoryUI.java

private void initGUI() {
    try {/*ww w  . jav a2 s.co m*/
        {
        }
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                scanList = new JList();
                jTabbedPane1.addTab("repository", null, jPanel1, null);
                {
                    scanText = new JTextField();
                    jPanel1.add(scanText, BorderLayout.NORTH);
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        ListModel scanListModel = new DefaultListModel();
                        jScrollPane1.setViewportView(scanList);
                        scanList.setModel(scanListModel);
                        scanList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                defaultJListClick(scanList, evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("repository only jar", null, jPanel4, null);
                jPanel4.setPreferredSize(new java.awt.Dimension(520, 298));
                {
                    scanText2 = new JTextField();
                    jPanel4.add(scanText2, BorderLayout.NORTH);
                }
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel4.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        scanList2 = new JList();
                        jScrollPane3.setViewportView(scanList2);
                        ListModel scanList2Model = new DefaultListModel();
                        scanList2.setModel(scanList2Model);
                        scanList2.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                defaultJListClick(scanList2, evt);
                            }
                        });
                    }
                }
                {
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("jar find", null, jPanel2, null);
                {
                    jarFindText = new JTextField();
                    jPanel2.add(jarFindText, BorderLayout.NORTH);
                }
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    {
                        ListModel jarFindListModel = new DefaultListModel();
                        jarFindList = new JList();
                        jScrollPane2.setViewportView(jarFindList);
                        jarFindList.setModel(jarFindListModel);
                        jarFindList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                defaultJListClick(jarFindList, evt);
                            }
                        });
                    }
                }
                {
                    jarFindExecute = new JButton();
                    jPanel2.add(jarFindExecute, BorderLayout.SOUTH);
                    jarFindExecute.setText("find");
                    jarFindExecute.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            String searchtext = jarFindText.getText();
                            if (StringUtils.isEmpty(searchtext) || searchtext.length() < 2) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("", "error");
                                return;
                            }
                            try {
                                DefaultListModel model = new DefaultListModel();
                                jarFindList.setModel(model);

                                searchtext = searchtext.trim();
                                searchtext = searchtext.replace('/', '.');
                                searchtext = searchtext.replace('\\', '.');

                                if (jarfinder == null) {
                                    jarfinder = JarFinder.newInstance();
                                } else {
                                    jarfinder.clear();
                                }

                                jarfinder.pattern(searchtext);

                                DefaultListModel scanModel = (DefaultListModel) scanList.getModel();
                                PomFile pomFile = null;
                                for (int ii = 0; ii < scanModel.getSize(); ii++) {
                                    pomFile = (PomFile) scanModel.getElementAt(ii);
                                    if (pomFile.jarFile == null) {
                                        continue;
                                    }
                                    jarfinder.setDir(pomFile.jarFile);
                                    if (!jarfinder.execute().isEmpty()) {
                                        model.addElement(pomFile);
                                    }
                                    jarfinder.getMap().clear();
                                }
                            } catch (Exception ex) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog(ex.getMessage(), "error");
                                ex.printStackTrace();
                            }
                        }
                    });
                }
            }
            {
                jPanel5 = new JPanel();
                BorderLayout jPanel5Layout = new BorderLayout();
                jTabbedPane1.addTab("detail", null, jPanel5, null);
                jPanel5.setLayout(jPanel5Layout);
                {
                    jScrollPane4 = new JScrollPane();
                    jPanel5.add(jScrollPane4, BorderLayout.CENTER);
                    {
                        TableModel scanTableModel = new DefaultTableModel();
                        scanTable = new JTable();
                        BorderLayout scanTableLayout = new BorderLayout();
                        scanTable.setLayout(scanTableLayout);
                        jScrollPane4.setViewportView(scanTable);
                        scanTable.setModel(scanTableModel);
                        JTableUtil.defaultSetting(scanTable);

                        scanTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                tableMouseClicked(scanTable, 0, evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                jTabbedPane1.addTab("config", null, jPanel3, null);
                GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3);
                jPanel3.setLayout(jPanel3Layout);
                {
                    copyToDir = new JButton();
                    copyToDir.setText("set copy to dir");
                    copyToDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                                    .getApproveSelectedFile();
                            if (file == null || !file.exists() || !file.isDirectory()) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("dir is not correct!, set default desktop", "error");
                                file = FileUtil.DESKTOP_DIR;
                            }
                            copyTo = file;
                            System.out.println("copyTo: " + copyTo);
                        }
                    });
                }
                {
                    resetM2Dir = new JButton();
                    resetM2Dir.setText("set .m2 dir");
                    resetM2Dir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                                    .getApproveSelectedFile();
                            if (file == null || !file.exists() || !file.isDirectory()) {
                                showErrorMsg();
                                repositoryDir = DEFAULT_REPOSITORY_DIR;
                                reloadRepositoryDir();
                                return;
                            }
                            File newRepository = new File(file, "repository");
                            File settings = new File(file, "settings.xml");
                            if (settings.exists() && settings.isFile() && newRepository.exists()
                                    && newRepository.isDirectory()) {
                                repositoryDir = newRepository;
                                reloadRepositoryDir();
                            } else {
                                showErrorMsg();
                            }
                        }

                        void showErrorMsg() {
                            JOptionPaneUtil.newInstance().iconErrorMessage()
                                    .showMessageDialog("dir is not correct!, set default .m2 dir", "error");
                        }
                    });
                }
                {
                    saveCurrentDataBtn = new JButton();
                    saveCurrentDataBtn.setText("save current data");
                    saveCurrentDataBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File cfgFile = new File(PropertiesUtil.getJarCurrentPath(MavenRepositoryUI.class),
                                    MavenRepositoryUI.class.getSimpleName() + "_" + DateFormatUtil
                                            .format(System.currentTimeMillis(), "yyyyMMdd_HHmmss") + ".cfg");
                            try {
                                ObjectOutputStream writer = new ObjectOutputStream(
                                        new FileOutputStream(cfgFile));
                                writer.writeObject(pomFileList);
                                writer.writeObject(pomFileJarList);
                                writer.writeObject(pomFileMap);
                                writer.flush();
                                writer.close();
                                JOptionPaneUtil.newInstance().iconInformationMessage()
                                        .showMessageDialog("save completed!\n" + cfgFile, "SUCCESS");
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                                ex.printStackTrace();
                            }
                        }
                    });
                }
                {
                    loadConfigDataBtn = new JButton();
                    loadConfigDataBtn.setText("load config data");
                    loadConfigDataBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File cfgFile = JFileChooserUtil.newInstance().selectFileOnly()
                                    .addAcceptFile("cfg", ".cfg").showOpenDialog().getApproveSelectedFile();
                            if (cfgFile == null) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("file is not correct!", "ERROR");
                                return;
                            }
                            try {
                                ObjectInputStream reader = new ObjectInputStream(new FileInputStream(cfgFile));
                                pomFileList = (Set<PomFile>) reader.readObject();
                                pomFileJarList = (Set<PomFile>) reader.readObject();
                                pomFileMap = (Map<DependencyKey, PomFile>) reader.readObject();
                                reader.close();
                                resetUIStatus();
                                JOptionPaneUtil.newInstance().iconInformationMessage()
                                        .showMessageDialog("load completed!\n" + cfgFile, "SUCCESS");
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                                ex.printStackTrace();
                            }
                        }
                    });

                }
                jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup().addContainerGap(24, 24)
                        .addGroup(jPanel3Layout.createParallelGroup()
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(loadConfigDataBtn,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(saveCurrentDataBtn,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(copyToDir,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(resetM2Dir,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(getJButton1(),
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(281, Short.MAX_VALUE));
                jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap(25, 25)
                        .addComponent(copyToDir, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
                        .addGap(22)
                        .addComponent(resetM2Dir, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
                        .addGap(24)
                        .addComponent(saveCurrentDataBtn, GroupLayout.PREFERRED_SIZE, 31,
                                GroupLayout.PREFERRED_SIZE)
                        .addGap(25)
                        .addComponent(loadConfigDataBtn, GroupLayout.PREFERRED_SIZE, 31,
                                GroupLayout.PREFERRED_SIZE)
                        .addGap(28)
                        .addComponent(getJButton1(), GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(34, Short.MAX_VALUE));
            }
            {
                jPanel6 = new JPanel();
                BorderLayout jPanel6Layout = new BorderLayout();
                jPanel6.setLayout(jPanel6Layout);
                jTabbedPane1.addTab("pom dency", null, jPanel6, null);
                {
                    openPom = new JButton();
                    jPanel6.add(openPom, BorderLayout.NORTH);
                    openPom.setText("open");
                    openPom.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectFileAndDirectory()
                                    .showDialog("?pom,pom").getApproveSelectedFile();
                            if (file == null) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("file is not correct!!", "ERROR");
                                return;
                            }
                            List<File> pomList = new ArrayList<File>();
                            if (file.isFile()
                                    && (file.getName().endsWith(".xml") || file.getName().endsWith(".pom"))) {
                                pomList.add(file);
                            } else {
                                FileUtil.searchFileMatchs(file, "pom.xml", pomList);
                            }
                            Set<PomFile> poms = loadPomList(pomList);
                            resetUIStatus();

                            Map<DependencyKey, PomFile> map = new HashMap<DependencyKey, PomFile>();
                            Set<LoadPomListDependency.DependencyKey> errorSet = new HashSet<LoadPomListDependency.DependencyKey>();
                            for (PomFile p : poms) {
                                openPomFetchDependency(p.pom, map, errorSet);
                            }

                            PomFile pfile = null;
                            DefaultTableModel model = JTableUtil.createModel(true, "groupId", "artifactId",
                                    "jar", "pomFile");
                            for (DependencyKey key : map.keySet()) {
                                pfile = map.get(key);
                                model.addRow(new Object[] { pfile.pom.groupId, pfile.pom.artifactId,
                                        (pfile.jarFile == null ? "" : pfile.jarFile.getName()), pfile });
                            }
                            for (LoadPomListDependency.DependencyKey key : errorSet) {
                                model.addRow(new Object[] { key.groupId, key.artifactId, "ERROR" });
                            }
                            pomDenpendencyTable.setModel(model);
                        }
                    });
                }
                {
                    jScrollPane5 = new JScrollPane();
                    jPanel6.add(jScrollPane5, BorderLayout.CENTER);
                    {
                        TableModel pomDenpendencyTableModel = new DefaultTableModel();
                        pomDenpendencyTable = new JTable();
                        jScrollPane5.setViewportView(pomDenpendencyTable);
                        pomDenpendencyTable.setModel(pomDenpendencyTableModel);
                        pomDenpendencyTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                tableMouseClicked(pomDenpendencyTable, 3, evt);
                            }
                        });
                        JTableUtil.defaultSetting(pomDenpendencyTable);
                    }
                }
                {
                    jPanel7 = new JPanel();
                    FlowLayout jPanel7Layout = new FlowLayout();
                    jPanel7Layout.setAlignOnBaseline(true);
                    jPanel6.add(jPanel7, BorderLayout.SOUTH);
                    jPanel7.setLayout(jPanel7Layout);
                    jPanel7.setPreferredSize(new java.awt.Dimension(520, 36));
                    {
                        clipboardListJar = new JButton();
                        jPanel7.add(clipboardListJar);
                        clipboardListJar.setText("jar list to clipboard");
                        clipboardListJar.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                List<File> list = fetchPomDependencyTableJarList();
                                StringBuilder sb = new StringBuilder();
                                for (File f : list) {
                                    sb.append(f + "\n");
                                }
                                ClipboardUtil.getInstance().setContents(sb);
                                JOptionPaneUtil.newInstance().iconInformationMessage()
                                        .showMessageDialog("clipboard set ok!", "SUCCESS");
                            }
                        });
                    }
                    {
                        pomOutputJarDir = new JButton();
                        jPanel7.add(pomOutputJarDir);
                        pomOutputJarDir.setText("set output jar dir");
                        pomOutputJarDir.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectDirectoryOnly()
                                        .showDialog("?Jar").getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("dir is not correct!!", "ERROR");
                                    return;
                                }
                                pomOutputJarDir_ = file;
                            }
                        });
                    }
                    {
                        exportListJar = new JButton();
                        jPanel7.add(exportListJar);
                        exportListJar.setText("export list jar");
                        exportListJar.setPreferredSize(new java.awt.Dimension(113, 24));
                        exportListJar.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                List<File> list = fetchPomDependencyTableJarList();
                                if (pomOutputJarDir_ == null || !pomOutputJarDir_.exists()
                                        || !pomOutputJarDir_.isDirectory()) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("output dir is not correct!!", "ERROR");
                                    return;
                                }
                                if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil
                                        .newInstance().confirmButtonYesNo().iconWaringMessage()
                                        .showConfirmDialog("are you sure copy list jar count:(" + list.size()
                                                + ") to\n" + pomOutputJarDir_, "WARN")) {
                                    StringBuilder sb = new StringBuilder();
                                    StringBuilder fsb = new StringBuilder();
                                    sb.append("total : " + list.size() + "\n");
                                    int ok = 0;
                                    int noOk = 0;
                                    for (File f : list) {
                                        try {
                                            FileUtil.copyFile(f, new File(pomOutputJarDir_, f.getName()));
                                            ok++;
                                        } catch (IOException e) {
                                            e.printStackTrace();
                                            noOk++;
                                            fsb.append(f + "\n");
                                        }
                                    }
                                    sb.append("success : " + ok + "\n");
                                    sb.append("failed : " + noOk + "\n");
                                    sb.append("Failed jar :\n");
                                    sb.append(fsb);

                                    JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(sb,
                                            "COPY RESULT");
                                }

                            }
                        });
                    }
                }
            }
        }
        this.setSize(541, 365);

        reloadRepositoryDir();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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

private void initGUI() {
    try {//  w  w  w .j  a va 2s . c o  m
        final SwingActionUtil swingUtil = SwingActionUtil.newInstance(this);

        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        this.setTitle("SVN BACKUP");
        this.setPreferredSize(new java.awt.Dimension(734, 442));
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            jTabbedPane1.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent evt) {
                    swingUtil.invokeAction("jTabbedPane1_changeEvent", evt);
                }
            });
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                jTabbedPane1.addTab("src text", null, jPanel1, null);
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        srcArea = new JTextArea();
                        jScrollPane1.setViewportView(srcArea);
                    }
                }
                {
                    loadSrcTextarea = new JButton();
                    jPanel1.add(loadSrcTextarea, BorderLayout.SOUTH);
                    loadSrcTextarea.setText("load src textarea");
                    loadSrcTextarea.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("loadSrcTextarea.actionPerformed", evt);
                        }
                    });
                }
                {
                    srcBaseDir = new JButton();
                    jPanel1.add(srcBaseDir, BorderLayout.NORTH);
                    srcBaseDir.setText("set src base dir");
                    srcBaseDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("srcBaseDir.actionPerformed", evt);
                        }
                    });
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("src list", null, jPanel2, null);
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    jScrollPane2.setPreferredSize(new java.awt.Dimension(531, 317));
                    {
                        ListModel srcListModel = new DefaultListModel();
                        srcList = new JList();
                        jScrollPane2.setViewportView(srcList);
                        srcList.setModel(srcListModel);
                        srcList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("srcList.mouseClicked", evt);
                            }
                        });
                        srcList.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                swingUtil.invokeAction("srcList.keyPressed", evt);
                            }
                        });
                    }
                }
                {
                    srcListQuery = new JTextField();
                    srcListQuery.getDocument()
                            .addDocumentListener(JCommonUtil.getDocumentListener(new HandleDocumentEvent() {
                                public void process(DocumentEvent event) {
                                    String scan = JCommonUtil.getDocumentText(event);
                                    DefaultListModel model = new DefaultListModel();
                                    Pattern pat = Pattern.compile(scan);
                                    for (LineParser line : copySrcListForQuerySet) {
                                        if (!line.file.exists()) {
                                            continue;
                                        }
                                        if (line.file.getAbsolutePath().contains(scan)) {
                                            model.addElement(line);
                                            continue;
                                        }
                                        try {
                                            if (pat.matcher(line.file.getAbsolutePath()).find()) {
                                                model.addElement(line);
                                                continue;
                                            }
                                        } catch (Exception ex) {
                                        }
                                    }
                                    srcList.setModel(model);
                                }
                            }));
                    jPanel2.add(srcListQuery, BorderLayout.NORTH);
                }
            }
            {
                jPanel3 = new JPanel();
                BorderLayout jPanel3Layout = new BorderLayout();
                jPanel3.setLayout(jPanel3Layout);
                jTabbedPane1.addTab("out list", null, jPanel3, null);
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel3.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        ListModel outPutListModel = new DefaultListModel();
                        outPutList = new JList();
                        jScrollPane3.setViewportView(outPutList);
                        outPutList.setModel(outPutListModel);
                        outPutList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("outPutList.mouseClicked", evt);
                            }
                        });
                        outPutList.addKeyListener(new KeyAdapter() {
                            public void keyPressed(KeyEvent evt) {
                                swingUtil.invokeAction("outPutList.keyPressed", evt);
                            }
                        });
                    }
                }
                {
                    outPutDir = new JButton();
                    jPanel3.add(outPutDir, BorderLayout.NORTH);
                    outPutDir.setText("set output dir");
                    outPutDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("outPutDir.actionPerformed", evt);
                        }
                    });
                }
                {
                    execute = new JButton();
                    jPanel3.add(execute, BorderLayout.SOUTH);
                    execute.setText("execute backup");
                    execute.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            swingUtil.invokeAction("execute.actionPerformed", evt);
                        }
                    });
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("compre", null, jPanel4, null);
                {
                    jScrollPane4 = new JScrollPane();
                    jPanel4.add(jScrollPane4, BorderLayout.CENTER);
                    jScrollPane4.setPreferredSize(new java.awt.Dimension(713, 339));
                    {
                        TableModel compareTableModel = new DefaultTableModel();
                        compareTable = new JTable();
                        jScrollPane4.setViewportView(compareTable);
                        compareTable.setModel(compareTableModel);
                        JTableUtil.defaultSetting(compareTable);
                        compareTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                swingUtil.invokeAction("compareTable.mouseClicked", evt);
                            }
                        });
                    }
                }
                {
                    jPanel5 = new JPanel();
                    jPanel4.add(jPanel5, BorderLayout.NORTH);
                    jPanel5.setPreferredSize(new java.awt.Dimension(713, 42));
                    {
                        openExternalSrcFolder = new JButton();
                        jPanel5.add(openExternalSrcFolder);
                        openExternalSrcFolder.setText("open external src folder");
                        openExternalSrcFolder.setPreferredSize(new java.awt.Dimension(280, 29));
                        openExternalSrcFolder.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                swingUtil.invokeAction("openExternalSrcFolder.actionPerformed", evt);
                            }
                        });
                    }
                    {
                        startCompareMatch = new JButton();
                        jPanel5.add(startCompareMatch);
                        startCompareMatch.setText("start compare source");
                        startCompareMatch.setPreferredSize(new java.awt.Dimension(280, 29));
                        startCompareMatch.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                swingUtil.invokeAction("startCompareMatch.actionPerformed", evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel6 = new JPanel();
                GroupLayout jPanel6Layout = new GroupLayout((JComponent) jPanel6);
                jPanel6.setLayout(jPanel6Layout);
                jTabbedPane1.addTab("configuration", null, jPanel6, null);
                {
                    DefaultComboBoxModel exportModeComboModel = new DefaultComboBoxModel();
                    for (ParseMode mode : ParseMode.values()) {
                        exportModeComboModel.addElement(mode);
                    }
                    exportModeCombo = new JComboBox();
                    exportModeCombo.setModel(exportModeComboModel);
                }
                jPanel6Layout.setHorizontalGroup(jPanel6Layout
                        .createSequentialGroup().addContainerGap(41, 41).addComponent(exportModeCombo,
                                GroupLayout.PREFERRED_SIZE, 167, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(505, Short.MAX_VALUE));
                jPanel6Layout
                        .setVerticalGroup(jPanel6Layout.createSequentialGroup().addContainerGap(30, 30)
                                .addComponent(exportModeCombo, GroupLayout.PREFERRED_SIZE,
                                        GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
                                .addContainerGap(321, Short.MAX_VALUE));
            }
            {
                jPanel7 = new JPanel();
                BorderLayout jPanel7Layout = new BorderLayout();
                jPanel7.setLayout(jPanel7Layout);
                jTabbedPane1.addTab("error log", null, jPanel7, null);
                {
                    jScrollPane5 = new JScrollPane();
                    jPanel7.add(jScrollPane5, BorderLayout.CENTER);
                    {
                        DefaultListModel errorLogListModel = new DefaultListModel();
                        errorLogList = new JList();
                        jScrollPane5.setViewportView(errorLogList);
                        errorLogList.setModel(errorLogListModel);
                    }
                }
            }
        }
        this.setSize(734, 442);

        swingUtil.addAction("openExternalSrcFolder.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                File dir = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                        .getApproveSelectedFile();
                if (dir == null) {
                    JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog("file is not correct!",
                            "ERROR");
                    return;
                }
                externalDir = dir;
            }
        });
        swingUtil.addAction("startCompareMatch.actionPerformed", new Action() {

            public void action(EventObject evt) throws Exception {
                Validate.notNull(manualBaseDir, "source folder not set!!");
                Validate.notNull(externalDir, "external folder not set!!");
                Validate.isTrue(!manualBaseDir.equals(externalDir), "source dir : " + manualBaseDir
                        + "\nexternal dir : " + externalDir + "\n cant be the same!!");

                List<File> externalSrcFolderList = new ArrayList<File>();
                FileUtil.searchFileMatchs(externalDir, ".*", externalSrcFolderList);
                System.out.println("externalSrcFolderList = " + externalSrcFolderList.size());

                List<File> manualBaseSourceList = new ArrayList<File>();
                FileUtil.searchFileMatchs(manualBaseDir, ".*", manualBaseSourceList);
                System.out.println("manualBaseSourceList = " + manualBaseSourceList.size());

                String cutExternalPath = FileUtil.exportReceiveBaseDir(externalSrcFolderList).getAbsolutePath();
                System.out.println("cutExternalPath = " + cutExternalPath);
                int cutExternalLength = cutExternalPath.length();

                List<CompareFile> _compareList = new ArrayList<CompareFile>();
                CompareFile compare = null;
                File mostCloseFile = null;
                List<File> searchMatchSrcList = new ArrayList<File>();
                for (File external : externalSrcFolderList) {
                    compare = new CompareFile();
                    compare.external = external;

                    searchMatchSrcList.clear();
                    mostCloseFile = new File(manualBaseDir,
                            external.getAbsolutePath().substring(cutExternalLength));
                    System.out.println(mostCloseFile.exists() + " == close file : " + mostCloseFile);
                    if (mostCloseFile.exists()) {
                        searchMatchSrcList.add(mostCloseFile);
                    } else {
                        for (File src : manualBaseSourceList) {
                            if (src.getName().equalsIgnoreCase(external.getName())) {
                                searchMatchSrcList.add(src);
                            }
                        }
                    }

                    System.out.println(external.getName() + " => match source : " + searchMatchSrcList.size());
                    compare.srcSet = new HashSet<File>(searchMatchSrcList);
                    _compareList.add(compare);
                }
                compareList = _compareList;
                reloadCompareTable();
            }
        });
        swingUtil.addAction("compareTable.mouseClicked", new Action() {
            String tortoiseMergeFormat = "cmd /c call TortoiseMerge /base:\"%s\" /theirs:\"%s\"";
            String openFileFormat = "cmd /c call \"%s\"";

            void openFile(File file) {
                String command = String.format(openFileFormat, file);
                System.out.println(command);
                try {
                    ProcessWatcher.newInstance(Runtime.getRuntime().exec(command)).getStreamSync();
                    System.out.println("do reload...");
                    reloadCompareTable();
                } catch (IOException e1) {
                    JCommonUtil.handleException(e1);
                }
            }

            public void action(EventObject evt) throws Exception {
                MouseEvent event = (MouseEvent) evt;

                int rowPos = JTableUtil.newInstance(compareTable).getSelectedRow();
                final File external = (File) JTableUtil.newInstance(compareTable).getModel().getValueAt(rowPos,
                        CompareTableIndex.EXTERNAL_FILE.pos);
                final File srcFile = (File) JTableUtil.newInstance(compareTable).getModel().getValueAt(rowPos,
                        CompareTableIndex.SOURCE_FILE.pos);

                System.out.println("external : " + external);
                System.out.println("srcFile : " + srcFile);

                if (JMouseEventUtil.buttonLeftClick(2, event)) {
                    String command = String.format(tortoiseMergeFormat, external, srcFile);
                    System.out.println(command);
                    Runtime.getRuntime().exec(command);
                }
                if (JMouseEventUtil.buttonRightClick(1, event)) {
                    JMenuItem showInfoMenu = new JMenuItem();
                    showInfoMenu.setText("information");
                    showInfoMenu.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            JOptionPaneUtil.newInstance().iconInformationMessage().showMessageDialog(//
                                    "source file : \n" + srcFile + "\n"
                                            + DateFormatUtils.format(srcFile.lastModified(),
                                                    "yyyy/MM/dd HH:mm:ss")
                                            + "\n" + "size : " + srcFile.length() / 1024 + "\n\n"
                                            + "external file : \n" + external + "\n"
                                            + DateFormatUtils.format(external.lastModified(),
                                                    "yyyy/MM/dd HH:mm:ss")
                                            + "\n" + "size : " + external.length() / 1024,
                                    "INFORMATION");
                        }
                    });
                    JMenuItem openFileMenu = new JMenuItem();
                    openFileMenu.setText("OPEN : source");
                    openFileMenu.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            openFile(srcFile);
                        }
                    });
                    JMenuItem openExternalMenu = new JMenuItem();
                    openExternalMenu.setText("OPEN : external");
                    openExternalMenu.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            openFile(external);
                        }
                    });
                    JMenuItem openPairlMenu = new JMenuItem();
                    openPairlMenu.setText("OPEN : all");
                    openPairlMenu.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            openFile(srcFile);
                            openFile(external);
                        }
                    });

                    JPopupMenuUtil.newInstance(compareTable).applyEvent(event)
                            .addJMenuItem(showInfoMenu, openFileMenu, openExternalMenu, openPairlMenu).show();
                }
            }
        });
        swingUtil.addAction("loadSrcTextarea.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                loadSrcTextarea();
            }
        });
        swingUtil.addAction("srcList.mouseClicked", new Action() {
            public void action(EventObject evt) throws Exception {
                if (JMouseEventUtil.buttonRightClick(1, evt)) {
                    JPopupMenuUtil.newInstance(srcList).applyEvent(evt)
                            .addJMenuItem("mark svn delete", new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION != JOptionPaneUtil
                                            .newInstance().confirmButtonYesNo().showConfirmDialog(
                                                    "are you sure, mark delete file : "
                                                            + srcList.getSelectedValues().length,
                                                    "SVN DELETE")) {
                                        return;
                                    }
                                    StringBuilder sb = new StringBuilder();
                                    Process process = null;
                                    InputStream in = null;
                                    for (Object obj : srcList.getSelectedValues()) {
                                        LineParser l = (LineParser) obj;
                                        String command = String.format("svn delete \"%s\"", l.file);
                                        System.out.println(command);
                                        try {
                                            process = Runtime.getRuntime().exec(command);
                                            in = process.getInputStream();
                                            for (; in.read() != -1;)
                                                ;
                                            if (l.file.exists()) {
                                                sb.append(l.file.getName() + "\n");
                                            }
                                        } catch (IOException e1) {
                                            e1.printStackTrace();
                                            sb.append(l.file.getName() + "\n");
                                        }
                                    }
                                    if (sb.length() > 0) {
                                        JOptionPaneUtil.newInstance().iconErrorMessage()
                                                .showMessageDialog("error : \n" + sb, "ERROR");
                                    } else {
                                        JOptionPaneUtil.newInstance().iconInformationMessage()
                                                .showMessageDialog("mark delete completed!!", "SUCCESS");
                                    }
                                    DefaultListModel model = (DefaultListModel) srcList.getModel();
                                    for (int ii = 0; ii < model.getSize(); ii++) {
                                        LineParser l = (LineParser) model.getElementAt(ii);
                                        if (!l.file.exists()) {
                                            model.remove(ii);
                                            ii--;
                                        }
                                    }
                                }
                            }).show();
                }

                if (!JListUtil.newInstance(srcList).isCorrectMouseClick(evt)) {
                    return;
                }
                LineParser lineParser = (LineParser) JListUtil.getLeadSelectionObject(srcList);
                if (lineParser == null) {
                    return;
                }
                Runtime.getRuntime().exec("cmd /c call \"" + lineParser.file + "\"");
            }
        });
        swingUtil.addAction("srcList.keyPressed", new Action() {
            public void action(EventObject evt) throws Exception {
                JListUtil.newInstance(srcList).defaultJListKeyPressed(evt);
            }
        });
        swingUtil.addAction("outPutList.mouseClicked", new Action() {
            public void action(EventObject evt) throws Exception {
                if (!JListUtil.newInstance(outPutList).isCorrectMouseClick(evt)) {
                    return;
                }
            }
        });
        swingUtil.addAction("outPutList.keyPressed", new Action() {
            public void action(EventObject evt) throws Exception {
                JListUtil.newInstance(outPutList).defaultJListKeyPressed(evt);
            }
        });
        swingUtil.addAction("outPutDir.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                File dir = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                        .getApproveSelectedFile();
                if (dir == null) {
                    outputDir = DEFAULT_OUTPUT_DIR;
                } else {
                    outputDir = dir;
                }
                reflushOutputList();
            }
        });
        swingUtil.addAction("srcBaseDir.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                File dir = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                        .getApproveSelectedFile();
                Validate.notNull(dir, "src base directory is not correct!");
                manualBaseDir = dir;
            }
        });
        swingUtil.addAction("execute.actionPerformed", new Action() {
            public void action(EventObject evt) throws Exception {
                DefaultListModel model = (DefaultListModel) outPutList.getModel();
                for (int ii = 0; ii < model.size(); ii++) {
                    OutputFile file = (OutputFile) model.getElementAt(ii);
                    if (!file.destFile.getParentFile().exists()) {
                        file.destFile.getParentFile().mkdirs();
                    }
                    FileUtil.copyFile(file.srcFile, file.destFile);
                }
                JOptionPaneUtil.newInstance().iconInformationMessage()
                        .showMessageDialog("copy success!!\nsize = " + model.getSize(), getTitle());
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.apatar.ui.JPublishToApatarDialog.java

private void createDialog() {

    GridBagLayout gridbag = new GridBagLayout();
    GridBagConstraints c = new GridBagConstraints();

    this.setLayout(gridbag);

    c.gridwidth = GridBagConstraints.REMAINDER;
    c.weightx = 1.0;//from  w w w .j a v  a 2 s  .c o  m
    c.weighty = 0.0;
    c.fill = GridBagConstraints.HORIZONTAL;
    //c.insets = new Insets(5, 5, 5, 5);

    JPanel panelLogin = new JPanel();
    panelLogin.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelLogin.setLayout(new BoxLayout(panelLogin, BoxLayout.X_AXIS));
    panelLogin.add(new JLabel("User Name"));
    panelLogin.add(Box.createHorizontalStrut(5));
    panelLogin.add(username);
    username.setComponentPopupMenu(new JDefaultContextMenu(username));
    panelLogin.add(Box.createHorizontalStrut(5));
    panelLogin.add(new JLabel("Password"));
    panelLogin.add(Box.createHorizontalStrut(5));
    panelLogin.add(password);

    JPanel panelForgotPassLink = new JPanel();
    panelForgotPassLink.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelForgotPassLink.setLayout(new BoxLayout(panelForgotPassLink, BoxLayout.X_AXIS));
    panelForgotPassLink.add(new JLabel("Lost your password? "));
    panelForgotPassLink.add(Box.createHorizontalStrut(5));
    panelForgotPassLink.add(forgotPassLinkLabel);

    forgotPassLinkLabel.setFont(UiUtils.NORMAL_SIZE_12_FONT);
    forgotPassLinkLabel.addMouseListener(new MouseHyperLinkEvent());
    forgotPassLinkLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    forgotPassLinkLabel.setText(
            "<html><a href='http://www.apatarforge.org/profile/lostpassword.html'>Click here to retrieve it</a></html>");

    JPanel panelFile = new JPanel();
    panelFile.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelFile.setLayout(new BoxLayout(panelFile, BoxLayout.X_AXIS));
    panelFile.add(selectFromFile);
    panelFile.add(Box.createHorizontalStrut(5));
    panelFile.add(new JLabel("New File "));
    panelFile.add(Box.createHorizontalStrut(5));
    panelFile.add(nameFile);
    panelFile.add(Box.createHorizontalStrut(5));
    panelFile.add(browse);
    nameFile.setEnabled(false);
    nameFile.setComponentPopupMenu(new JDefaultContextMenu(nameFile));
    browse.setEnabled(false);

    JPanel panelLocation = new JPanel();
    panelLocation.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelLocation.setLayout(new BoxLayout(panelLocation, BoxLayout.X_AXIS));
    panelLocation.add(new JLabel("Suggest Location:"));
    panelLocation.add(Box.createHorizontalStrut(5));
    panelLocation.add(location);

    JPanel panelDMName = new JPanel();
    panelDMName.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelDMName.setLayout(new BoxLayout(panelDMName, BoxLayout.X_AXIS));
    JLabel datamapNameLabel = new JLabel("DataMap Name:");
    datamapNameLabel.setBorder(new EmptyBorder(0, 0, 0, 10));
    panelDMName.add(datamapNameLabel);
    panelDMName.add(Box.createHorizontalStrut(5));
    panelDMName.add(dataMapName);
    dataMapName.setComponentPopupMenu(new JDefaultContextMenu(dataMapName));

    JPanel panelDMDescription = new JPanel();
    panelDMDescription.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelDMDescription.setLayout(new BoxLayout(panelDMDescription, BoxLayout.X_AXIS));
    panelDMDescription.add(new JLabel("DataMap Description (16000 Chars)"));
    panelDMDescription.add(Box.createHorizontalStrut(5));
    //JScrollPane scroll = new JScrollPane(dataMapDescription);
    //scroll.setSize(300, 50);
    dataMapDescription.setLineWrap(true);
    dataMapDescription.setWrapStyleWord(true);
    panelDMDescription.add(new JScrollPane(dataMapDescription));

    JPanel panelDMShortDescription = new JPanel();
    panelDMShortDescription.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelDMShortDescription.setLayout(new BoxLayout(panelDMShortDescription, BoxLayout.X_AXIS));
    JLabel labelShort = new JLabel("Short Description:");
    labelShort.setBorder(new EmptyBorder(0, 0, 0, 85));
    panelDMShortDescription.add(labelShort);
    panelDMShortDescription.add(Box.createHorizontalStrut(5));
    shortDescription.setLineWrap(true);
    shortDescription.setWrapStyleWord(true);
    panelDMShortDescription.add(new JScrollPane(shortDescription));
    setEnableShortDescription(false);

    // -------------

    JPanel panelTitleForTags = new JPanel();
    panelTitleForTags.setBorder(new EmptyBorder(10, 10, 0, 10));
    panelTitleForTags.setLayout(new BoxLayout(panelTitleForTags, BoxLayout.X_AXIS));
    panelTitleForTags.add(new JLabel("Add tags associated with your DataMap:"));

    // -------------

    JPanel panelListAddedTags = new JPanel();
    panelListAddedTags.setBorder(new EmptyBorder(0, 10, 10, 10));
    panelListAddedTags.setLayout(new BoxLayout(panelListAddedTags, BoxLayout.X_AXIS));

    // --
    JPanel panelFrom = new JPanel();
    panelFrom.setLayout(new BoxLayout(panelFrom, BoxLayout.Y_AXIS));
    JPanel panelMiddle = new JPanel();
    panelMiddle.setLayout(new BoxLayout(panelMiddle, BoxLayout.X_AXIS));
    JPanel panelTo = new JPanel();
    panelTo.setLayout(new BoxLayout(panelTo, BoxLayout.Y_AXIS));

    // --
    JPanel panelAddNewTag = new JPanel();
    panelAddNewTag.setLayout(new BoxLayout(panelAddNewTag, BoxLayout.X_AXIS));
    panelAddNewTag.add(new JLabel("Add new tag:"));
    panelAddNewTag.add(Box.createHorizontalStrut(5));
    textfieldAddNewTag = new JTextField();
    textfieldAddNewTag.setComponentPopupMenu(new JDefaultContextMenu(textfieldAddNewTag));
    panelAddNewTag.add(textfieldAddNewTag);
    panelAddNewTag.add(Box.createHorizontalStrut(5));
    JButton buttonAddTag = new JButton("Add");
    buttonAddTag.addActionListener(addNewTagMouseListener);
    panelAddNewTag.add(buttonAddTag);

    // --
    JPanel panelDeleteTags = new JPanel();
    panelDeleteTags.setLayout(new BoxLayout(panelDeleteTags, BoxLayout.X_AXIS));

    panelDeleteTags.add(new JLabel("Delete selected tag(s):"));
    panelDeleteTags.add(Box.createHorizontalStrut(5));
    JButton buttonDeleteTag = new JButton("Delete");
    buttonDeleteTag.addActionListener(deleteTagMouseListener);
    panelDeleteTags.add(buttonDeleteTag);
    panelDeleteTags.add(new JPanel());

    // --

    JButton moveTag = new JButton(UiUtils.ARROW_ICON);
    moveTag.addActionListener(addTagsMouseListener);
    panelMiddle.add(moveTag);

    tblModelFrom = new DefaultTableModel();
    tblModelTo = new DefaultTableModel();
    tblModelFrom.addColumn("Tag Name");
    tblModelTo.addColumn("Tag Name");

    tagsTableFrom = new JTable(tblModelFrom);
    tagsTableTo = new JTable(tblModelTo);

    tagsTableFrom.setOpaque(false);
    tagsTableFrom.setBackground(null);
    tagsTableFrom.setBorder(null);
    tagsTableFrom.setShowGrid(false);

    tagsTableTo.setOpaque(false);
    tagsTableTo.setBackground(null);
    tagsTableTo.setBorder(null);
    tagsTableTo.setShowGrid(false);

    tagsTableFrom.getColumn("Tag Name").setCellEditor(new CellEditor(new JTextField()));
    tagsTableTo.getColumn("Tag Name").setCellEditor(new CellEditor(new JTextField()));

    fillTableTags();

    tagsTableFrom.setComponentPopupMenu(new JDefaultContextMenu(tagsTableFrom));
    tagsTableTo.setComponentPopupMenu(new JDefaultContextMenu(tagsTableTo));

    JScrollPane srollPane = new JScrollPane(tagsTableFrom);
    srollPane.setBorder(null);

    JScrollPane srollPane2 = new JScrollPane(tagsTableTo);
    srollPane.setBorder(null);

    panelFrom.add(srollPane);
    panelFrom.add(Box.createVerticalStrut(5));
    panelFrom.add(panelAddNewTag);

    panelTo.add(srollPane2);
    panelTo.add(Box.createVerticalStrut(5));
    panelTo.add(panelDeleteTags);

    panelListAddedTags.add(panelFrom);
    panelListAddedTags.add(Box.createHorizontalStrut(5));
    panelListAddedTags.add(panelMiddle);
    panelListAddedTags.add(Box.createHorizontalStrut(5));
    panelListAddedTags.add(panelTo);

    // -------

    JPanel panelButton = new JPanel();
    panelButton.setLayout(new BoxLayout(panelButton, BoxLayout.X_AXIS));
    panelButton.add(Box.createHorizontalGlue());
    panelButton.add(bOk);
    panelButton.add(Box.createHorizontalStrut(5));
    panelButton.add(bCancel);
    panelButton.add(Box.createHorizontalStrut(5));

    ComponentBuilder.makeComponent(new JCommentPanel(), gridbag, c, getContentPane());

    ComponentBuilder.makeComponent(panelLogin, gridbag, c, getContentPane());
    ComponentBuilder.makeComponent(panelForgotPassLink, gridbag, c, getContentPane());
    ComponentBuilder.makeComponent(panelFile, gridbag, c, getContentPane());
    ComponentBuilder.makeComponent(panelLocation, gridbag, c, getContentPane());
    ComponentBuilder.makeComponent(panelDMName, gridbag, c, getContentPane());

    c.fill = GridBagConstraints.BOTH;

    c.weighty = 2.0;
    ComponentBuilder.makeComponent(panelDMDescription, gridbag, c, getContentPane());

    c.weighty = 0.0;
    ComponentBuilder.makeComponent(autoGenerateShortDescription, gridbag, c, getContentPane());

    c.weighty = 1.0;
    ComponentBuilder.makeComponent(panelDMShortDescription, gridbag, c, getContentPane());

    c.weighty = 1.0;
    ComponentBuilder.makeComponent(panelTitleForTags, gridbag, c, getContentPane());

    c.weighty = 3.0;
    ComponentBuilder.makeComponent(panelListAddedTags, gridbag, c, getContentPane());

    c.weighty = 0.0;
    ComponentBuilder.makeComponent(new JSeparator(), gridbag, c, getContentPane());

    c.weighty = 1.0;
    ComponentBuilder.makeComponent(panelButton, gridbag, c, getContentPane());
}

From source file:com.digitalgeneralists.assurance.ui.components.ResultsPanel.java

public void notify(IAssuranceEvent event) {
    StringBuffer loggingMessage = new StringBuffer(256);
    logger.info(loggingMessage.append("ResultsPanel received event: ").append(event));
    loggingMessage.setLength(0);/*from   w  w  w. j  ava 2  s. c  o  m*/
    loggingMessage = null;

    if (event instanceof SelectedScanChangedEvent) {
        this.resetPanel();
        StringBuilder labelText = new StringBuilder(512);
        this.resultsLabel
                .setText(labelText.append("Results for ").append(event.getSource().toString()).toString());
        labelText.setLength(0);
        labelText = null;
    }

    if (event instanceof ScanStartedEvent) {
        this.resetPanel();
        StringBuilder labelText = new StringBuilder(512);
        this.resultsLabel.setText(
                labelText.append("Loading results for ").append(event.getSource().toString()).toString());
        labelText.setLength(0);
        labelText = null;
        this.add(this.progressIndicator, this.progressIndicatorConstraints);
        this.validate();
        this.progressIndicator.repaint();
    }

    if (event instanceof ScanCompletedEvent) {
        this.applicationDelegate.loadScanResults((Scan) event.getSource());
        this.remove(this.progressIndicator);
        this.validate();
    }

    if (event instanceof ScanProgressEvent) {
        this.resultsLabel.setText(event.getSource().toString());
        this.validate();
    }

    if (event instanceof ScanResultsLoadedEvent) {
        int selectedResultIndex = this.resultsTable.getSelectedRow();

        Scan scan = (Scan) event.getSource();
        // NOTE:  Leaking model initialization like this into the UI is less than ideal.
        scan = (Scan) ModelUtils.initializeEntity(scan, Scan.RESULTS_PROPERTY);
        Collection<ComparisonResult> list = scan.getUnmodifiableResults();

        // NOTE:  Swapping the list model out to suppress change
        // notifications during a data reload feels less than ideal.
        this.resultsTable.setModel(new DefaultTableModel());

        this.resultsTableModel.removeAllElements();

        for (ComparisonResult result : list) {
            this.resultsTableModel.addRow(result);
            result = null;
        }

        this.resultsTable.setModel(this.resultsTableModel);

        this.conditionallyShowMessagePanel(list.size() == 0, "The source and target locations are identical.");
        list = null;

        StringBuilder labelText = new StringBuilder(512);
        this.resultsLabel.setText(labelText.append("Results for ").append(scan.toString()).toString());
        labelText.setLength(0);
        labelText = null;

        if ((selectedResultIndex >= 0) && (this.resultsTableModel.getRowCount() > selectedResultIndex)) {
            this.resultsTable.setRowSelectionInterval(selectedResultIndex, selectedResultIndex);
        }

        scan = null;
    }

    if ((event instanceof ResultMergeCompletedEvent) || (event instanceof DeletedItemRestoreCompletedEvent)) {
        for (int index = 0; index < this.resultsTableModel.getRowCount(); index++) {
            List<List<ComparisonResult>> resultList = new ArrayList<List<ComparisonResult>>(
                    this.resultsTableModel.data);
            if (((ComparisonResult) event.getSource()).getId() == resultList.get(index).get(0).getId()) {
                this.resultsTableModel.updateRow(index, (ComparisonResult) event.getSource());
            }
            resultList = null;
        }
    }

    if (event instanceof ScanMergeStartedEvent) {
        this.resetPanel();
        StringBuilder labelText = new StringBuilder(512);
        this.resultsLabel.setText(labelText.append("Merging ").append(event.getSource().toString()).toString());
        labelText.setLength(0);
        labelText = null;
        this.add(this.progressIndicator, this.progressIndicatorConstraints);
        this.validate();
        this.progressIndicator.repaint();
        StringBuilder message = new StringBuilder(512);
        this.conditionallyShowMessagePanel(true,
                message.append("Merging ").append(event.getSource().toString()).toString());
        message.setLength(0);
        message = null;
    }

    if (event instanceof ScanMergeProgressEvent) {
        this.resultsLabel.setText(event.getSource().toString());
        this.validate();
    }

    if (event instanceof ScanMergeCompletedEvent) {
        this.applicationDelegate.loadScanResults((Scan) event.getSource());
        this.remove(this.progressIndicator);
        this.validate();
    }
}

From source file:view.ResultsPanel.java

public void showHistogram(List<ElementaryMode> modes) {

    //for the JTable
    DefaultTableModel tableModel = new DefaultTableModel();
    JTable tableResult = new JTable();
    tableResult.setModel(tableModel);/*from w w  w  . ja  va  2 s . co m*/

    tableModel.addColumn("Reaction");
    tableModel.addColumn("Presence in the modes");

    tableResult.setAutoCreateRowSorter(true);

    Map<Reaction, Double> stats = new HashMap<Reaction, Double>();

    DecimalFormat df = new DecimalFormat("0.00");

    for (ElementaryMode em : modes) {
        for (Reaction r : em.getContent().keySet()) {
            if (em.getContent().containsKey(r)) {
                if (!stats.containsKey(r)) {
                    stats.put(r, 1.0);
                } else {
                    Reaction key = r;
                    Double value = stats.get(r) + 1;
                    stats.remove(key);
                    stats.put(key, value);
                }
            }
        }
    }

    for (Reaction r : stats.keySet()) {
        tableModel
                .addRow(new Object[] { r, String.valueOf(df.format(stats.get(r) * 100 / modes.size())) + "%" });
    }

    JFrame statisticFrame = new JFrame();
    statisticFrame.add(new JScrollPane(tableResult), BorderLayout.CENTER);
    statisticFrame.setVisible(true);
    statisticFrame.setSize(400, 350);
    statisticFrame.setTitle("Representativeness of each reaction");
    statisticFrame.setLocation(500, 600);

    //histogram
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    Map<Integer, Integer> data = new TreeMap<Integer, Integer>();
    int maxSize = 0;
    for (ElementaryMode em : modes) {
        int modeLength = em.getContent().size();
        if (modeLength > maxSize) {
            maxSize = modeLength;
        }
        if (data.containsKey(modeLength)) {
            int value = data.get(modeLength) + 1;
            data.put(modeLength, value);
        } else {
            data.put(modeLength, 1);
        }
    }

    for (int i = 1; i < maxSize; i++) {
        if (!data.containsKey(i)) {
            data.put(i, 0);
        }
    }
    for (int key : data.keySet()) {
        dataset.addValue(Integer.valueOf((data.get(key))), "test", Integer.valueOf(key));
    }

    String plotTitle = "Number of reactions per elementary mode";
    String xaxis = "Reaction number";
    String yaxis = "Elementary mode number";
    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = false;
    boolean toolTips = false;
    boolean urls = false;
    JFreeChart chart = ChartFactory.createBarChart3D(plotTitle, xaxis, yaxis, dataset, orientation, show,
            toolTips, urls);

    CategoryPlot plot = chart.getCategoryPlot();
    CategoryAxis axis = plot.getDomainAxis();

    plot.getDomainAxis(0).setLabelFont(plot.getDomainAxis().getLabelFont().deriveFont(new Float(11)));

    ChartFrame frame = new ChartFrame("Elementary modes", chart);
    frame.setVisible(true);
    frame.setSize(400, 350);
    frame.setLocation(500, 100);

}

From source file:org.pgptool.gui.ui.mainframe.MainFrameView.java

@Override
protected void internalUnbindFromPm() {
    super.internalUnbindFromPm();

    updateWindowTitle();/*from   w w  w. ja v  a2  s  .  c  om*/

    table.setModel(new DefaultTableModel());
    ctxMenu.removeAll();
    hintView.setPm(null);
}