Example usage for javax.swing.table DefaultTableModel getRowCount

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

Introduction

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

Prototype

public int getRowCount() 

Source Link

Document

Returns the number of rows in this data table.

Usage

From source file:org.agmip.ui.afsirs.frames.SWFrame.java

private void soilNameComboActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_soilNameComboActionPerformed

    // TODO add your handling code here:
    if (isInitializing)
        return;//ww w.  j  ava 2s  .c  o m

    int index = soilNameCombo.getSelectedIndex();
    if (index == -1)
        return;
    //index = index ==-1? 0 : index;
    SoilData soilData = utils.getSoilData();
    String key = (String) soilFileListCombo.getSelectedItem();
    key = key.trim();
    ArrayList<Soil> soilList = soilData.getSoilsFromFile(key);

    if (soilList.size() > 0) {

        if (index == -1) {

            // TODO add your handling code here:
            DefaultTableModel model = (DefaultTableModel) soilTable.getModel();
            int row = model.getRowCount();
            for (int i = 0; i < row; i++) {
                model.removeRow(0);
            }
            index = 0;
            Soil soil = soilList.get(index);
            for (int i = 0; i < soil.getNL(); i++) {
                Object[] vec = new Object[4];
                vec[0] = i + 1;
                vec[1] = soil.getDU()[i];
                vec[2] = soil.getWC()[i];
                vec[3] = soil.getWCU()[i] - soil.getWCL()[i];
                model.addRow(vec);

            }
        } else {

            // This is to take the backup of the data so that I can 

            //Soil soil = soilList.get(selectedSoilIndex);
            DefaultTableModel model = (DefaultTableModel) soilTable.getModel();

            if (prevSoil != null) {
                for (int i = 0; i < model.getRowCount(); i++) {
                    prevSoil.getDU()[i] = (Double) model.getValueAt(i, 1);
                    prevSoil.getWC()[i] = (Double) model.getValueAt(i, 2);
                }
            }

            int row = model.getRowCount();
            for (int i = 0; i < row; i++) {
                model.removeRow(0);
            }

            Soil soil = soilList.get(index);

            DU = soil.getDU();
            WCL = soil.getWCL();
            WCU = soil.getWCU();
            WC = soil.getWC();
            NL = soil.getNL();
            SNAME = soil.getName();
            utils.setDefaultSoil(soil);

            for (int i = 0; i < soil.getNL(); i++) {
                Object[] vec = new Object[4];
                vec[0] = i + 1;
                vec[1] = soil.getDU()[i];
                vec[2] = soil.getWC()[i];
                vec[3] = (WCU[i] - WCL[i]);
                model.addRow(vec);

            }

            prevSoil = soil;
        }

    }
    //selectedSoilIndex = index;
}

From source file:org.jas.gui.MainWindow.java

@EventMethod(Events.APPLY_METADATA)
void onReadyToApplyMetadata(MetadataAlbumValues metadataValues) {
    String artist = metadataValues.getArtist();
    String album = metadataValues.getAlbum();
    String genre = metadataValues.getGenre();
    String year = metadataValues.getYear();
    String tracks = metadataValues.getTracks();
    String cd = metadataValues.getCd();
    String cds = metadataValues.getCds();
    DefaultTableModel model = (DefaultTableModel) descriptionTable.getModel();
    List<Metadata> metadatas = controlEngineConfigurator.getControlEngine().get(Model.METADATA);
    log.info(metadataWithAlbum.size());//from   w ww.  j a  va2s.com
    for (int i = 0; i < model.getRowCount(); i++) {
        Metadata metadata = metadatas.get(i);
        if (!StringUtils.isEmpty(artist)) {
            getDescriptionTable().getModel().setValueAt(artist, i, ApplicationState.ARTIST_COLUMN);
        }
        if (!StringUtils.isEmpty(album)) {
            getDescriptionTable().getModel().setValueAt(album, i, ApplicationState.ALBUM_COLUMN);
        }
        if (!StringUtils.isEmpty(genre)) {
            getDescriptionTable().getModel().setValueAt(genre, i, ApplicationState.GENRE_COLUMN);
        }
        if (!StringUtils.isEmpty(year)) {
            getDescriptionTable().getModel().setValueAt(year, i, ApplicationState.YEAR_COLUMN);
        }
        if (!StringUtils.isEmpty(tracks)) {
            getDescriptionTable().getModel().setValueAt(tracks, i, ApplicationState.TOTAL_TRACKS_NUMBER_COLUMN);
        }
        if (!StringUtils.isEmpty(cd)) {
            getDescriptionTable().getModel().setValueAt(cd, i, ApplicationState.CD_NUMBER_COLUMN);
        }
        if (!StringUtils.isEmpty(cds)) {
            getDescriptionTable().getModel().setValueAt(cds, i, ApplicationState.TOTAL_CDS_NUMBER_COLUMN);
        }
        if (metadataValues.getCoverArt() != null) {
            log.info("coverArt detected for: " + metadata.getTitle());
            CoverArt coverArt = new CoverArt(metadataValues.getCoverArt(), CoverArtType.DRAG_AND_DROP);
            metadata.setNewCoverArt(coverArt);
            metadataWithAlbum.add(metadata);
            getDescriptionTable().getModel().setValueAt(ActionResult.New, i, ApplicationState.STATUS_COLUMN);
            if (i == selectedRow) {
                updateImage(i);
            }
            getApplyButton().setEnabled(!working);
            log.info("setting applyButton to : " + !working);
        }
    }
}

From source file:la2launcher.MainFrame.java

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
    final long initTime = new Date().getTime();
    ReentrantLock lock = new ReentrantLock();
    final String patcherUrl = "http://" + updateHost + "/hf//updater.lst.la2";//new ArrayBlockingQueue<Runnable>(10000)
    final ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 5, 1, TimeUnit.HOURS,
            new ArrayBlockingQueue<Runnable>(10000));
    filesProcessed = 0;/*from  w  w w. ja  v  a2 s .  co m*/
    tpe.execute(new Runnable() {
        @Override
        public void run() {
            jTextArea2.setText("");
            DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
            jProgressBar1.setMinimum(0);
            jProgressBar1.setMaximum(model.getRowCount());
            jProgressBar1.setValue(0);
            jLabel4.setText("0/" + model.getRowCount());
            for (int i = 0; i < model.getRowCount(); i++) {
                boolean checked = (Boolean) model.getValueAt(i, 1);
                String fileName = (String) model.getValueAt(i, 0);
                if (checked) {
                    tpe.execute(new Runnable() {
                        @Override
                        public void run() {

                            final String fileUrl = "http://" + updateHost + "/hf/" + fileName.replace("\\", "/")
                                    + ".la2";
                            try {
                                printMsg("  " + fileUrl);
                                File file = new File(gamePath + fileName + ".rar");
                                File fileExt = new File(gamePath + fileName);

                                file.getParentFile().mkdirs();
                                FileOutputStream fos = new FileOutputStream(file);
                                CloseableHttpClient httpclient = HttpClients.createDefault();
                                HttpGet httpGet = new HttpGet(fileUrl);
                                CloseableHttpResponse response1 = httpclient.execute(httpGet);

                                HttpEntity entity1 = response1.getEntity();
                                copyStream(entity1.getContent(), fos, new CopyListener() {
                                    @Override
                                    public void transfered(int n) {
                                        bytesRecieved += n;
                                        bytesRecievedTotal += n;
                                    }
                                });
                                response1.close();
                                fos.close();

                                printMsg("?? : " + fileName);

                                lock.lock();
                                //fixBzip2File(file);
                                //printMsg(" ?");

                                extractArchive(file.getAbsolutePath());

                                //BZip2CompressorInputStream bz = new BZip2CompressorInputStream(new FileInputStream(file));
                                //OutputStream pout = new FileOutputStream(fileExt);
                                //copyStream(archStream, pout, null);
                                //pout.close();
                                //archStream.close();
                                //jTextArea2.setText(jTextArea2.getText() + "\r\n? : " + fileName);
                                printMsg("? : " + fileName);
                                //file.delete();

                                //                                    File tgt = new File(gamePath + fileName);
                                //                                    if (tgt.exists()) {
                                //                                        tgt.delete();
                                //                                    }
                                //tgt.getParentFile().mkdirs();
                                //Files.move(fileExt.toPath(), new File(gamePath + fileName).toPath());
                                //jTextArea2.setText(jTextArea2.getText() + "\r\n ??: " + fileName);
                                printMsg(" ??: " + fileName);
                                jProgressBar1.setIndeterminate(false);
                                jLabel4.setText((++filesProcessed) + "/" + model.getRowCount());
                                jProgressBar1.setValue((int) filesProcessed);
                                lock.unlock();
                            } catch (IOException ex) {
                                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                            } catch (Exception ex) {
                                Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                            }
                        }
                    });
                }
            }
        }
    });

    jButton5.setEnabled(false);
    jButton6.setEnabled(false);
    jButton7.setEnabled(false);
    jButton8.setEnabled(false);
    jButton9.setEnabled(false);
    jButton10.setEnabled(false);
    jProgressBar1.setIndeterminate(true);
    new Thread() {
        @Override
        public void run() {
            do {
                long millis = new Date().getTime();
                try {
                    sleep(300);
                } catch (InterruptedException ex) {
                    Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex);
                }
                millis = new Date().getTime() - millis;
                BigDecimal totBig = new BigDecimal(bytesRecievedTotal / (1024 * 1024.0));
                totBig = totBig.setScale(2, BigDecimal.ROUND_CEILING);
                jLabel5.setText("?: " + (bytesRecieved / millis) + "KB/s. : "
                        + totBig + " MB");
                bytesRecieved = 0;
            } while (tpe.getActiveCount() > 0);
            tpe.shutdown();
            jButton5.setEnabled(true);
            jButton6.setEnabled(true);
            jButton7.setEnabled(true);
            jButton8.setEnabled(true);
            jButton9.setEnabled(true);
            jButton10.setEnabled(true);
            jProgressBar1.setIndeterminate(false);
            printMsg("  " + (new Date().getTime() - initTime)
                    + " ?.");
        }
    }.start();
}

From source file:de.fionera.javamailer.gui.mainView.controllerMain.java

/**
 * Adds the Actionlisteners to the Mainview
 *
 * @param viewMain The Mainview/*  www .  j  a v  a  2 s .c o m*/
 */
private void addActionListener(viewMain viewMain) {
    /**
     * Changes the Amount in the AmountLabel when the slider is moved
     */
    viewMain.getSetMailSettingsPanel().getSliderAmountMails().addChangeListener(e -> {
        Main.amountMails = ((JSlider) e.getSource()).getValue();
        viewMain.getSetMailSettingsPanel().getLabelNumberAmountMails()
                .setText("" + ((JSlider) e.getSource()).getValue());
    });

    /**
     * Changes the Delay in the DelayLabel when the slider is moved
     */
    viewMain.getSetMailSettingsPanel().getSliderDelayMails().addChangeListener(e -> {
        Main.delayMails = ((JSlider) e.getSource()).getValue();
        viewMain.getSetMailSettingsPanel().getLabelNumberDelayMails()
                .setText("" + ((JSlider) e.getSource()).getValue());
    });

    /**
     * Closes the Program, when close is clicked
     */
    viewMain.getCloseItem().addActionListener(e -> System.exit(0));

    /**
     * Opens the Settings when the settingsbutton is clicked
     */
    viewMain.getSettingsItem().addActionListener(e -> new controllerSettings());

    /**
     * Save current Setup
     */
    viewMain.getSaveSettings().addActionListener(e -> {
        JFileChooser jChooser = new JFileChooser();
        JFrame parentFrame = new JFrame();

        FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub");
        jChooser.setFileFilter(filter);

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jChooser.setDialogTitle("Select Setup");

        int userSelection = jChooser.showSaveDialog(parentFrame);

        if (userSelection == JFileChooser.APPROVE_OPTION) {
            File fileToSave = new File(jChooser.getSelectedFile() + ".jms");

            saveSetup(viewMain, fileToSave, new ObjectMapper());
        }
    });

    /**
     * Load Setup
     */
    viewMain.getLoadSettings().addActionListener(e -> {
        JFileChooser jChooser = new JFileChooser();

        FileNameExtensionFilter filter = new FileNameExtensionFilter("Setup file", "jms", "Blub");
        jChooser.setFileFilter(filter);

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        jChooser.setDialogTitle("Select Setup");
        jChooser.showOpenDialog(null);

        File file = jChooser.getSelectedFile();

        if (file != null) {
            if (file.getName().endsWith("jms")) {
                try {
                    loadSetup(viewMain, file, new ObjectMapper());
                } catch (Exception error) {
                    error.printStackTrace();
                }
            }
        }
    });

    /**
     * Opens the Open File dialog and start the Parsing of it
     */
    viewMain.getSelectRecipientsPanel().getSelectExcelFileButton().addActionListener(e -> {
        DefaultTableModel model;
        JFileChooser jChooser = new JFileChooser();

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel 97 - 2003 (.xls)", "xls"));
        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Excel (.xlsx)", "xlsx"));
        jChooser.setDialogTitle("Select only Excel workbooks");
        jChooser.showOpenDialog(null);
        File file = jChooser.getSelectedFile();
        if (file != null) {
            parseFilesForImport parseFilesForImport = new parseFilesForImport();

            if (file.getName().endsWith("xls")) {
                ArrayList returnedData = parseFilesForImport.parseXLSFile(file);

                model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1));

                int tableWidth = model.getColumnCount() * 150;
                int tableHeight = model.getRowCount() * 25;
                viewMain.getSelectRecipientsPanel().getTable()
                        .setPreferredSize(new Dimension(tableWidth, tableHeight));

            } else if (file.getName().endsWith("xlsx")) {
                ArrayList returnedData = parseFilesForImport.parseXLSXFile(file);

                model = new DefaultTableModel((String[][]) returnedData.get(0), (String[]) returnedData.get(1));

                int tableWidth = model.getColumnCount() * 150;
                int tableHeight = model.getRowCount() * 25;
                viewMain.getSelectRecipientsPanel().getTable()
                        .setPreferredSize(new Dimension(tableWidth, tableHeight));

            } else {
                JOptionPane.showMessageDialog(null, "Please select only Excel file.", "Error",
                        JOptionPane.ERROR_MESSAGE);

                model = new DefaultTableModel();
            }
        } else {
            model = new DefaultTableModel();

        }

        viewMain.getSelectRecipientsPanel().getTable().setModel(model);

        int tableWidth = model.getColumnCount() * 150;
        int tableHeight = model.getRowCount() * 25;
        viewMain.getSelectRecipientsPanel().getTable().setPreferredSize(new Dimension(tableWidth, tableHeight));
        viewMain.getCheckAllSettings().getLabelRecipientsAmount().setText("" + model.getRowCount());
        viewMain.getCheckAllSettings().getLabelTimeAmount()
                .setText(""
                        + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()
                                * viewMain.getSelectRecipientsPanel().getTable().getRowCount()
                                / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()
                        + " Seconds");
    });

    /**
     * Starts the sending of th Mails, when the send button is clicked
     */
    viewMain.getCheckAllSettings().getSendMails().addActionListener(e -> {

        String subject = viewMain.getSetMailSettingsPanel().getFieldSubject().getText();
        Sender sender = (Sender) viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem();
        JTable table = viewMain.getSelectRecipientsPanel().getTable();

        if (table != null && sender != null && !subject.equals("")) {
            new sendMails(viewMain);
        }
    });

    /**
     * Clears the Table on buttonclick
     */
    viewMain.getSelectRecipientsPanel().getClearTableButton().addActionListener(e -> {
        viewMain.getSelectRecipientsPanel().getTable().setModel(new DefaultTableModel());
        viewMain.getSelectRecipientsPanel().getTable().setBackground(null);

    });

    /**
     * Removes a single Row on menu click in the editMailPanel
     */
    viewMain.getSelectRecipientsPanel().getDeleteRow().addActionListener(e -> {
        ((DefaultTableModel) viewMain.getSelectRecipientsPanel().getTable().getModel())
                .removeRow(viewMain.getSelectRecipientsPanel().getTable().getSelectedRowCount());
        viewMain.getSelectRecipientsPanel().getTable().setBackground(null);

    });

    /**
     * The Changes the displayed Value when the Time in the Timespinner is getting changed.
     */
    viewMain.getSetMailSettingsPanel().getTimeSpinner().addChangeListener(e -> {
        parseDate.parseDate(viewMain);
        viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, "
                + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining");
        viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString());
        viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate());

    });
    viewMain.getSetMailSettingsPanel().getDatePicker().addActionListener(e -> {
        parseDate.parseDate(viewMain);
        viewMain.getSetMailSettingsPanel().getLabelSendingIn().setText(parseDate.getDays() + " Days, "
                + parseDate.getHours() + " hours and " + parseDate.getMinutes() + " minutes remaining");
        viewMain.getSetMailSettingsPanel().getLabelSendingAt().setText(parseDate.getDate().toString());
        viewMain.getSetMailSettingsPanel().setDate(parseDate.getDate());
    });

    /**
     * Actionevent for the Edit Sender Button
     */
    viewMain.getSetMailSettingsPanel().getButtonEditSender()
            .addActionListener(e -> new controllerEditSender(controllerMain));

    /**
     * Actionevent for the Import Button in the EditMail View
     */
    viewMain.getEditMailPanel().getImportWord().addActionListener(e -> {
        JFileChooser jChooser = new JFileChooser();

        jChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("Microsoft Word 97 - 2003 (.doc)", "doc"));
        jChooser.addChoosableFileFilter(new FileNameExtensionFilter("HTML File (.html)", "html"));
        jChooser.setDialogTitle("Select only Word Documents");
        jChooser.showOpenDialog(null);
        File file = jChooser.getSelectedFile();
        if (file != null) {
            parseFilesForImport parseFilesForImport = new parseFilesForImport();

            if (file.getName().endsWith("doc")) {
                String returnedData = parseFilesForImport.parseDOCFile(file);
                viewMain.getEditMailPanel().setEditorText(returnedData);

            } else if (file.getName().endsWith("html")) {
                String content = "";
                try {
                    content = Jsoup.parse(file, "UTF-8").toString();
                } catch (IOException e1) {
                    e1.printStackTrace();
                }

                viewMain.getEditMailPanel().setEditorText(content);

            } else {
                JOptionPane.showMessageDialog(null, "Please select a Document file.", "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    /**
     * The Tab Changelistener
     * The first if Statement sets the Labels on the Checkallsettings Panel to the right Values
     */
    viewMain.getTabbedPane().addChangeListener(e -> {
        if (viewMain.getTabbedPane().getSelectedComponent() == viewMain.getCheckAllSettings()) {

            viewMain.getCheckAllSettings().getLabelMailBelow()
                    .setText(viewMain.getEditMailPanel().getEditorText()); //Displays the Mail

            viewMain.getCheckAllSettings().getLabelRecipientsAmount()
                    .setText("" + viewMain.getSelectRecipientsPanel().getTable().getModel().getRowCount()); //Displays the Amount of Recipients

            if (viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem() != null) {
                viewMain.getCheckAllSettings().getLabelFromInserted().setText(
                        viewMain.getSetMailSettingsPanel().getSelectSender().getSelectedItem().toString());
            } else {
                viewMain.getCheckAllSettings().getLabelFromInserted().setText("Select a Sender first");
            }

            viewMain.getCheckAllSettings().getLabelSubjectInserted()
                    .setText(viewMain.getSetMailSettingsPanel().getFieldSubject().getText()); //Displays the Subject

            if (viewMain.getSetMailSettingsPanel().getCheckBoxDelayMails().isSelected()) {
                viewMain.getCheckAllSettings().getLabelDelay().setVisible(true);
                viewMain.getCheckAllSettings().getLabelAmount().setVisible(true);
                viewMain.getCheckAllSettings().getLabelTime().setVisible(true);
                viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(true);
                viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(true);
                viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(true);

                viewMain.getCheckAllSettings().getLabelDelayNumber()
                        .setText("" + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()); //The Delay Number
                viewMain.getCheckAllSettings().getLabelAmountNumber()
                        .setText("" + viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()); //The Amount of Mail in one package
                viewMain.getCheckAllSettings().getLabelTimeAmount()
                        .setText(""
                                + viewMain.getSetMailSettingsPanel().getSliderDelayMails().getValue()
                                        * viewMain.getSelectRecipientsPanel().getTable().getRowCount()
                                        / viewMain.getSetMailSettingsPanel().getSliderAmountMails().getValue()
                                + " Seconds"); //The Time the Sending needs

            } else {
                viewMain.getCheckAllSettings().getLabelDelay().setVisible(false);
                viewMain.getCheckAllSettings().getLabelAmount().setVisible(false);
                viewMain.getCheckAllSettings().getLabelTime().setVisible(false);
                viewMain.getCheckAllSettings().getLabelDelayNumber().setVisible(false);
                viewMain.getCheckAllSettings().getLabelAmountNumber().setVisible(false);
                viewMain.getCheckAllSettings().getLabelTimeAmount().setVisible(false);
            }

            if (viewMain.getSetMailSettingsPanel().getCheckBoxSendLater().isSelected()) {
                viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(true);
                viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(true);
                viewMain.getCheckAllSettings().getLabelSendingAt()
                        .setText(viewMain.getSetMailSettingsPanel().getDate().toString());

            } else {
                viewMain.getCheckAllSettings().getLabelSendingAt().setVisible(false);
                viewMain.getCheckAllSettings().getLabelSendingWhen().setVisible(false);
            }

        }
    });

}

From source file:org.agmip.ui.afsirs.frames.SWFrame.java

private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
    if (soilTable.isEditing()) {
        soilTable.getCellEditor().stopCellEditing();
    }//from w  ww.  java  2s  .c om

    wcErrorLabel.setVisible(false);
    errorLabel.setVisible(false);
    soilNameLabel.setForeground(Color.black);
    soilTextureLabel.setForeground(Color.black);
    dwtLabel.setForeground(Color.black);

    boolean isFailed = false;
    int ISOIL = soilListBox.getSelectedIndex();
    if (jRadioKeyboard.isSelected()) {

        if (soilNameText.getText().length() < 1) {
            //if (soilNameCombo.getItemAt(0).length() < 1) {
            isFailed = true;
            soilNameLabel.setForeground(Color.red);
        }

        if (soilTextureText.getText().length() < 1) {
            isFailed = true;
            soilTextureLabel.setForeground(Color.red);
        }

        DefaultTableModel model = (DefaultTableModel) soilTable.getModel();
        int nl = NLComboBox.getSelectedIndex() + 1;
        if (nl != model.getRowCount()) {
            isFailed = true;
        }
    }

    if (dwtText.isEnabled()) {
        try {
            DWT = Double.parseDouble(dwtText.getText());
        } catch (NumberFormatException e) {
            dwtLabel.setForeground(Color.red);
            isFailed = true;
        }
        if (DWT < 0.01) {
            dwtLabel.setForeground(Color.red);
            isFailed = true;
        }
    }

    //@rohit_note: Data needs to be taken based on the selection from UI Map/File/Keyboard. For eg. If this is file/Keyboard
    // Then Take the data from the controls/ else if it is Map then take the data from the json File. 
    SNAME = soilNameText.getText();
    TXT[0] = soilTextureText.getText();
    DefaultTableModel model = (DefaultTableModel) soilTable.getModel();
    SoilData soilData = utils.getSoilData();

    if (soilData == null) {
        soilData = new SoilData();
        utils.setSoilData(soilData);
    }

    try {

        for (int i = 0; i < NL; i++) {
            DU[i] = (Double) model.getValueAt(i, 1);
            WC[i] = (Double) model.getValueAt(i, 2);

            if (jRadioButtonSavedLocation.isSelected()) {
                ArrayList<Soil> soilList = soilData
                        .getSoilsFromFile((String) soilFileListCombo.getSelectedItem());
                soilData.setKey((String) soilFileListCombo.getSelectedItem());
                if (soilList != null) {
                    Soil soil = soilList.get(soilNameCombo.getSelectedIndex());
                    soil.getDU()[i] = DU[i];
                    soil.getWC()[i] = WC[i];
                    utils.setDefaultSoil(soil);
                }
            } else if (WC[i] < 0.01 || WC[i] > 0.9) {
                isFailed = true;
                wcErrorLabel.setVisible(true);
            }
        }
    } catch (Exception e) {
        isFailed = true;
        errorLabel.setVisible(true);
    }

    if (isFailed) {
        return;
    }

    if (jRadioKeyboard.isSelected() || jRadioFile.isSelected()) {
        // The Soil name will be Empty
        Soil soil = new Soil(ISOIL, SNAME, "", "", SNAME, NL);
        soil.setValues(WC, WCL, WCU, DU, TXT);
        soilData.addSoil(jRadioKeyboard.isSelected() ? Messages.KEYBOARD_KEY : Messages.FILE_KEY, soil);
        utils.setSoilData(soilData);
        utils.setDefaultSoil(soil);

    }

    //Define Lower Soil Layer Dimensions
    utils.setDWT(DWT);

    setVisible(false);
    if (soilDataNext != null) {
        soilDataNext.setVisible(true);
    } else {
        if (utils.getPerennial()) {
            DCOEFPerennialFrame nextFrame = new DCOEFPerennialFrame(this);
            nextFrame.setVisible(true);
            soilDataNext = nextFrame;
        } else {
            DCOEFAnnualFrame nextFrame = new DCOEFAnnualFrame(this);
            nextFrame.setVisible(true);
            soilDataNext = nextFrame;
        }
    }

    //finish.setVisible(true);
}

From source file:grupob.TipoProceso.java

private void btnGuardarInstitucionalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarInstitucionalActionPerformed
    // TODO add your handling code here:
    DefaultTableModel modelo = (DefaultTableModel) tblInstitucional.getModel();
    if (0 < modelo.getRowCount()) {
        modelo.getColumnCount();/*from w  w  w .  ja  v  a  2 s .c om*/
        Institucion institucion = new Institucion();
        for (int i = 0; i < modelo.getRowCount(); i++) {
            institucion.setId(listaInstituciones.get(i).getId());
            institucion.setNombre(tblInstitucional.getValueAt(i, 0).toString());

            String n = tblInstitucional.getValueAt(i, 1).toString();
            int num = -1;
            try {
                num = Integer.parseInt(n);

            } catch (Exception ex) {

                JOptionPane.showMessageDialog(null,
                        "Error: Ingreso un valor distinto de un numero en la fila: " + (i + 1) + " columna: 2");
                return;

            }

            if (num < 0) {
                JOptionPane.showMessageDialog(null,
                        "Error: Ingreso un numero negativo en la fila: " + (i + 1) + " columna: 2");
                return;
            }

            institucion.setCantidadVotantesRegistrados(num);

            institucion.setTipoProceso(5);//Tipo de proceso 5
            for (int j = 0; i < listaLocalesI.size(); j++) {
                if (listaLocalesI.get(j).getNombre().equals(tblInstitucional.getValueAt(i, 2).toString())) {
                    institucion.setIdLocal(listaLocalesI.get(j).getId());
                    break;
                }
            }
            Manager.updateInstitucion(institucion);
            //            System.out.println(listaInstituciones.get(i).getId());
            //            System.out.println(tblInstitucional.getValueAt(i, 0).toString());
            //            System.out.println(tblInstitucional.getValueAt(i, 1).toString());
            //            System.out.println(tblInstitucional.getValueAt(i, 2).toString());        

        }

        //            
    }

    JOptionPane.showMessageDialog(this, "Se guardaron los cambios con exito");

}

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

private JButton getResetQueryBtn() {
    if (resetQueryBtn == null) {
        resetQueryBtn = new JButton();
        resetQueryBtn.setText("???");
        resetQueryBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                DefaultTableModel dirCompareModel = getDefaultTableModel();
                for (Object[] rows : modelOrignList) {
                    dirCompareModel.addRow(rows);
                }//from  w  w w. ja v  a 2  s  .co m
                while (dirCompareTable.getModel().getRowCount() != dirCompareModel.getRowCount()) {
                    dirCompareTable.setModel(dirCompareModel);
                    System.out.println("reset dirCompareTable");
                }
                initComponents();
            }
        });
    }
    return resetQueryBtn;
}

From source file:gdt.jgui.tool.JEntityEditor.java

private void deleteRows() {
    try {//from www  . jav  a  2 s. c o  m
        JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent();
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int rCnt = table.getRowCount();
        ArrayList<Integer> srl = new ArrayList<Integer>();
        for (int i = 0; i < rCnt; i++)
            if (listModel.isSelectedIndex(i)) {
                srl.add(new Integer(i));
            }
        Integer[] sra = srl.toArray(new Integer[0]);
        ArrayList<Core> ol = new ArrayList<Core>();
        Core row;
        boolean skip;
        for (int i = 0; i < rCnt; i++) {
            skip = false;
            for (int aSra : sra) {
                if (i == aSra) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                row = new Core((String) tableModel.getValueAt(i, 0), (String) tableModel.getValueAt(i, 1),
                        (String) tableModel.getValueAt(i, 2));
                ol.add(row);
            }
        }
        Core[] ra = ol.toArray(new Core[0]);
        while (tableModel.getRowCount() > 0)
            tableModel.removeRow(0);
        for (Core aRa : ra) {
            tableModel.addRow(new String[] { aRa.type, aRa.name, aRa.value });
        }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:Clavis.Windows.WShedule.java

public synchronized void refreshTable(int val) {
    DefaultTableModel modelo = (DefaultTableModel) jTable1.getModel();
    if (modelo.getRowCount() > 0) {
        int tam = modelo.getRowCount();
        for (int h = 0; h < tam; h++) {
            modelo.removeRow(0);// w  ww .  j  a  va 2  s.c  o  m
        }
    }

    java.util.List<Keys.Request> requisicoes = new java.util.ArrayList<>();
    if (DataBase.DataBase.testConnection(url)) {
        DataBase.DataBase db = new DataBase.DataBase(url);
        requisicoes = Clavis.RequestList
                .simplifyRequests(db.getRequestsByMaterialByDateInterval(mat, inicio, fim));
        db.close();
    }
    lista = new java.util.ArrayList<>();
    andamento = 0;
    switch (val) {
    case 0:
        estado = lingua.translate("Todos");
        for (Keys.Request req : requisicoes) {
            String[] multipla = req.getActivity().split(":::");
            String saux;
            if (multipla.length > 1) {
                saux = multipla[0];
                Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                pop.create();
                jTable1.addMouseListener(new MouseAdapter() {
                    int x = andamento;
                    int y = 3;

                    @Override
                    public void mousePressed(MouseEvent e) {
                        if (e.getButton() == MouseEvent.BUTTON1) {
                            int row = jTable1.rowAtPoint(e.getPoint());
                            int col = jTable1.columnAtPoint(e.getPoint());
                            if ((row == x) && (col == y)) {
                                pop.show(e.getComponent(), e.getX(), e.getY());
                            }
                        }
                    }

                    @Override
                    public void mouseReleased(MouseEvent e) {
                        if (e.getButton() == MouseEvent.BUTTON1) {
                            if (pop.isShowing()) {
                                pop.setVisible(false);
                            }
                        }
                    }
                });
            } else {
                saux = req.getActivity();
            }
            if (saux.equals("")) {
                saux = lingua.translate("Sem descrio");
            }
            if (mat.getMaterialTypeID() == 1) {
                Object[] ob = { req.getPerson().getName(),
                        req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                        req.getBeginDate().toString(), saux, req.getSubject().getName() };
                modelo.addRow(ob);
            } else {
                Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                        req.getEndDate().toString(), saux };
                modelo.addRow(ob);
            }
            lista.add(req);
            andamento++;
        }
        break;
    case 1:
        estado = lingua.translate("terminado");
        for (Keys.Request req : requisicoes) {
            if (req.isTerminated()) {
                String[] multipla = req.getActivity().split(":::");
                String saux;
                if (multipla.length > 1) {
                    saux = multipla[0];
                    Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                    pop.create();
                    jTable1.addMouseListener(new MouseAdapter() {
                        int x = andamento;
                        int y = 3;

                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                int row = jTable1.rowAtPoint(e.getPoint());
                                int col = jTable1.columnAtPoint(e.getPoint());
                                if ((row == x) && (col == y)) {
                                    pop.show(e.getComponent(), e.getX(), e.getY());
                                }
                            }
                        }

                        @Override
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                if (pop.isShowing()) {
                                    pop.setVisible(false);
                                }
                            }
                        }
                    });
                } else {
                    saux = req.getActivity();
                }
                if (saux.equals("")) {
                    saux = lingua.translate("Sem descrio");
                }
                if (mat.getMaterialTypeID() == 1) {
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), saux, req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), saux };
                    modelo.addRow(ob);
                }
                lista.add(req);
                andamento++;
            }
        }
        break;
    case 2:
        estado = lingua.translate("no realizado");
        for (Keys.Request req : requisicoes) {
            if ((!req.isActive()) && ((req.getEndDate().isBigger(new TimeDate.Date()) > 0)
                    || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0)
                            && (req.getTimeEnd().compareTime(new TimeDate.Time()) > 0)))) {
                String[] multipla = req.getActivity().split(":::");
                String saux;
                if (multipla.length > 1) {
                    saux = multipla[0];
                    Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                    pop.create();
                    jTable1.addMouseListener(new MouseAdapter() {
                        int x = andamento;
                        int y = 3;

                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                int row = jTable1.rowAtPoint(e.getPoint());
                                int col = jTable1.columnAtPoint(e.getPoint());
                                if ((row == x) && (col == y)) {
                                    pop.show(e.getComponent(), e.getX(), e.getY());
                                }
                            }
                        }

                        @Override
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                if (pop.isShowing()) {
                                    pop.setVisible(false);
                                }
                            }
                        }
                    });
                } else {
                    saux = req.getActivity();
                }
                if (saux.equals("")) {
                    saux = lingua.translate("Sem descrio");
                }
                if (mat.getMaterialTypeID() == 1) {
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), saux, req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), saux };
                    modelo.addRow(ob);
                }
                lista.add(req);
                andamento++;
            }
        }
        break;
    case 3:
        estado = lingua.translate("por realizar");
        for (Keys.Request req : requisicoes) {
            if ((!req.isActive()) && (!req.isTerminated())
                    && ((req.getEndDate().isBigger(new TimeDate.Date()) < 0)
                            || ((req.getEndDate().isBigger(new TimeDate.Date()) == 0)
                                    && (req.getTimeEnd().compareTime(new TimeDate.Time()) < 0)))) {
                String[] multipla = req.getActivity().split(":::");
                String saux;
                if (multipla.length > 1) {
                    saux = multipla[0];
                    Components.PopUpMenu pop = new Components.PopUpMenu(multipla, lingua);
                    pop.create();
                    jTable1.addMouseListener(new MouseAdapter() {
                        int x = andamento;
                        int y = 3;

                        @Override
                        public void mousePressed(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                int row = jTable1.rowAtPoint(e.getPoint());
                                int col = jTable1.columnAtPoint(e.getPoint());
                                if ((row == x) && (col == y)) {
                                    pop.show(e.getComponent(), e.getX(), e.getY());
                                }
                            }
                        }

                        @Override
                        public void mouseReleased(MouseEvent e) {
                            if (e.getButton() == MouseEvent.BUTTON1) {
                                if (pop.isShowing()) {
                                    pop.setVisible(false);
                                }
                            }
                        }
                    });
                } else {
                    saux = req.getActivity();
                }
                if (saux.equals("")) {
                    saux = lingua.translate("Sem descrio");
                }
                if (mat.getMaterialTypeID() == 1) {
                    Object[] ob = { req.getPerson().getName(),
                            req.getTimeBegin().toString(0) + " - " + req.getTimeEnd().toString(0),
                            req.getBeginDate().toString(), saux, req.getSubject().getName() };
                    modelo.addRow(ob);
                } else {
                    Object[] ob = { req.getPerson().getName(), req.getBeginDate().toString(),
                            req.getEndDate().toString(), saux };
                    modelo.addRow(ob);
                }
                lista.add(req);
                andamento++;
            }
        }
        break;
    }
    valores = new String[lista.size()][4];
    for (int i = 0; i < lista.size(); i++) {
        String[] multipla = lista.get(i).getActivity().split(":::");
        String saux = multipla[0];
        if (saux.equals("")) {
            saux = lingua.translate("Sem descrio");
        }
        if (mat.getMaterialTypeID() == 1) {
            valores[i][0] = lista.get(i).getPerson().getName();
            valores[i][1] = lista.get(i).getTimeBegin().toString(0) + " - "
                    + lista.get(i).getTimeEnd().toString(0);
            valores[i][2] = lista.get(i).getBeginDate().toString();
            valores[i][3] = saux + " - " + lista.get(i).getSubject().getName();
        } else {
            valores[i][0] = lista.get(i).getPerson().getName();
            valores[i][1] = lista.get(i).getBeginDate().toString();
            valores[i][2] = lista.get(i).getEndDate().toString();
            valores[i][3] = saux;
        }
    }
}

From source file:gdt.jgui.entity.fields.JFieldsEditor.java

private void deleteRows() {
    try {//from  w w  w .j a  v a  2 s .  c  o m
        JTable table = (JTable) scrollPane.getViewport().getView();
        DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
        ListSelectionModel listModel = table.getSelectionModel();
        int rCnt = table.getRowCount();
        ArrayList<Integer> srl = new ArrayList<Integer>();
        for (int i = 0; i < rCnt; i++)
            if (listModel.isSelectedIndex(i)) {
                srl.add(new Integer(i));
            }
        Integer[] sra = srl.toArray(new Integer[0]);
        ArrayList<Core> ol = new ArrayList<Core>();
        Core row;
        boolean skip;
        for (int i = 0; i < rCnt; i++) {
            skip = false;
            for (int aSra : sra) {
                if (i == aSra) {
                    skip = true;
                    break;
                }
            }
            if (!skip) {
                row = new Core(null, (String) tableModel.getValueAt(i, 0),
                        (String) tableModel.getValueAt(i, 1));
                ol.add(row);
            }
        }
        Core[] ra = ol.toArray(new Core[0]);
        while (tableModel.getRowCount() > 0)
            tableModel.removeRow(0);
        for (Core aRa : ra) {
            tableModel.addRow(new String[] { aRa.name, aRa.value });
        }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}