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:semaforo.Semaforo.java

public synchronized void updateTableWeek(JTable TableWeek, int index, int tamano) {

    Settings settings = Controller.getSettings();

    //  TableWeek.getColumnModel().getColumn(0).setPreferredWidth(120);
    //  TableWeek.getColumnModel().getColumn(9).setPreferredWidth(120);
    // CustomRenderer cr = new CustomRenderer(TableWeek.getDefaultRenderer(Object.class), Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
    //  TableWeek.setDefaultRenderer(Object.class, cr);
    DefaultTableModel model = (DefaultTableModel) TableWeek.getModel();

    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(3);//from w  w w .j av  a2 s.  co  m

    int num = Math.min(settings.getTickers().size(), model.getRowCount());
    if (TableWeek.getModel().getRowCount() > 0) {
        num = Math.min(settings.getTickers().size(), TableWeek.getModel().getRowCount());
    }

    for (int i = 0; i < num; i++) {
        for (int m = 0; m < TableTicker.getModel().getRowCount(); m++) {
            if (TableTicker != null && TableTicker.getModel() != null) {
                if (TableTicker.getModel().getValueAt(m, 0) != null) {
                    if (TableTicker.getModel().getValueAt(m, 0)
                            .equals(settings.getTickers().get(i).getName())) {
                        model.setValueAt(String.format("%.2f", settings.getTickers().get(i).getMinValue(index)),
                                m, 0);
                        model.setValueAt(String.format("%.2f", settings.getTickers().get(i).getMaxValue(index)),
                                m, tamano); //TODO: Parametrizar
                        //                            JOptionPane.showMessageDialog(null,index+"", "", JOptionPane.ERROR_MESSAGE);
                        if (index == 13) {
                            DDBB.updateTicker(TableTicker.getModel().getValueAt(m, 0).toString(),
                                    String.format("%.2f", settings.getTickers().get(i).getMinValue(index)),
                                    String.format("%.2f", settings.getTickers().get(i).getMaxValue(index)));
                        }
                    }
                }
            }
        }
    }
}

From source file:semaforo.Semaforo.java

public synchronized void updateTableTickers() {
    Settings settings = Controller.getSettings();

    //  TableWeek.getColumnModel().getColumn(0).setPreferredWidth(120);
    //  TableWeek.getColumnModel().getColumn(9).setPreferredWidth(120);
    // CustomRenderer cr = new CustomRenderer(TableWeek.getDefaultRenderer(Object.class), Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
    //  TableWeek.setDefaultRenderer(Object.class, cr);
    DefaultTableModel model = (DefaultTableModel) TableTicker.getModel();

    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);//from   ww  w .  ja  v a 2s  .  c  o m

    int num = Math.min(settings.getTickers().size(), model.getRowCount());
    if (TableTicker.getModel().getRowCount() > 0) {
        num = Math.min(settings.getTickers().size(), TableTicker.getModel().getRowCount());
    }

    isload = false;

    for (int i = 0; i < num; i++) {
        if (settings.getTickers().get(i).getCurrentPrice() <= 0) {
            isload = true;
        }
    }

    new Thread() {

        @Override
        public void run() {
            if (loadingDialog == null) {
                JFrame frame = new JFrame();
                loadingDialog = new LoadingDialog(null, "Please Wait", "Loading Data");
                loadingDialog.setEnabled(false);
                loadingDialog.setAlwaysOnTop(false);

            }

            if (loadingDialog.isShowing() && isload == false /*&& isloadHistory == false*/) {
                loadingDialog.setVisible(false);
            } else if (!loadingDialog.isShowing() && isload == true /*&& isloadHistory == true*/) {
                loadingDialog.setVisible(true);
            }

        }
    }.start();

}

From source file:semaforo.Semaforo.java

public void setUp() {

    this.setTitle("Semaforo");
    URL hj = getClass().getResource("resources/semaforo.png");
    setIconImage(Toolkit.getDefaultToolkit().getImage(hj));

    listener = new UpdateTableListener() {

        @Override//from  w  w  w. j  ava2s  .  c  om
        public void addTickers() {

            // Add in Tickers Table
            Settings settings = Controller.getSettings();
            synchronized (updateLock) {
                update = 1;
            }
            CustomRenderer cr = new CustomRenderer(TableTicker.getDefaultRenderer(Object.class),
                    Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);

            TableTicker.setDefaultRenderer(Object.class, cr);
            DefaultTableModel model = (DefaultTableModel) TableTicker.getModel();

            Object[] o = new Object[2];
            for (int i = model.getRowCount(); i < settings.getTickers().size(); i++) {

                o[0] = settings.getTickers().get(i).getName();
                o[1] = 0;
                model.addRow(o);
            }

            // Resize the vector of values
            num_positions = Controller.getSettings().getTickers().size();

            num_positions++;

            // Add in Week Tables
            CustomRenderer cr1 = new CustomRenderer(TableWeek1.getDefaultRenderer(Object.class),
                    Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
            CustomRenderer cr2 = new CustomRenderer(TableWeek2.getDefaultRenderer(Object.class),
                    Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);
            CustomRenderer cr3 = new CustomRenderer(TableWeek3.getDefaultRenderer(Object.class),
                    Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);

            // Table Week 1
            TableWeek1.setDefaultRenderer(Object.class, cr1);
            DefaultTableModel model1 = (DefaultTableModel) TableWeek1.getModel();

            Object[] o1 = new Object[10];

            // Table Week 2
            TableWeek2.setDefaultRenderer(Object.class, cr2);
            DefaultTableModel model2 = (DefaultTableModel) TableWeek2.getModel();

            Object[] o2 = new Object[10];

            // Table Week 3
            TableWeek3.setDefaultRenderer(Object.class, cr3);
            DefaultTableModel model3 = (DefaultTableModel) TableWeek3.getModel();

            Object[] o3 = new Object[10];

            for (int i = model1.getRowCount(); i < settings.getTickers().size(); i++) {

                model1.addRow(o1);

                model2.addRow(o2);

                model3.addRow(o3);
            }

            synchronized (updateLock) {
                update = 0;
            }

        }

        @Override
        public boolean canUpdate() {
            return update == 1;
        }

        @Override
        public void stopThread() {
            synchronized (updateLock) {
                update = 2;
            }
        }

        @Override
        public void updateTickers() {
            synchronized (updateLock) {
                Settings settings = Controller.getSettings();
                update = 2;

                CustomRenderer cr = new CustomRenderer(TableTicker.getDefaultRenderer(Object.class),
                        Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY, Color.LIGHT_GRAY);

                TableTicker.setDefaultRenderer(Object.class, cr);

                for (int i = 0; i < settings.getTickers().size(); i++) {

                    TableTicker.setValueAt(settings.getTickers().get(i).getName(), i, 0);
                }

                update = 0;
            }
        }

        @Override
        public void updateVariables() {
            Settings settings = Controller.getSettings();
            validate();
            repaint();

            timer.setDelay(settings.getVaribable(DDBB.RATIO_REFRESCO));
        }

        @Override
        public void reomveTicker(int index) {
            synchronized (updateLock) {
                // Add in Tickers Table

                update = 2;

                DefaultTableModel model = (DefaultTableModel) TableTicker.getModel();
                model.removeRow(index);

                // Remove row in Week Tables
                // Table Week 1
                DefaultTableModel model1 = (DefaultTableModel) TableWeek1.getModel();

                // Table Week 2
                DefaultTableModel model2 = (DefaultTableModel) TableWeek2.getModel();

                // Table Week 3
                DefaultTableModel model3 = (DefaultTableModel) TableWeek3.getModel();

                // Table Week 1
                model1.removeRow(index);

                // Table Week 2
                model2.removeRow(index);

                // Table Week 3
                model3.removeRow(index);

                num_positions = Controller.getSettings().getTickers().size();

                update = 0;

            }
        }
    };

    Controller.setup(listener);/* = new Controller();*/

    Settings settings = Controller.getSettings();

    num_positions = Controller.getSettings().getTickers().size();

    loadTableTickers();

    loadTableWeek(TableWeek1, WEEK1);

    loadTableWeek(TableWeek2, WEEK2);

    loadTableWeek(TableWeek3, WEEK3);

    String cad = settings.getVaribable(DDBB.RANGO_1) > 1 ? "weeks" : "week";

    cad = settings.getVaribable(DDBB.RANGO_2) > 1 ? "weeks" : "week";

    cad = settings.getVaribable(DDBB.RANGO_3) > 1 ? "weeks" : "week";

    TableTicker.setCellSelectionEnabled(false);
    TableWeek1.setCellSelectionEnabled(false);
    TableWeek2.setCellSelectionEnabled(false);
    TableWeek3.setCellSelectionEnabled(false);
    /*validate();
     repaint();*/
    settingsGUI = new SettingsGUI(listener);
    features = new Features();
    features.setBackground(java.awt.Color.BLACK);

}

From source file:com.mirth.connect.client.ui.ChannelSetup.java

private void saveChannelTags() {
    currentChannel.getProperties().getTags().clear();

    DefaultTableModel model = (DefaultTableModel) tagTable.getModel();
    int rowCount = model.getRowCount();

    for (int i = 0; i < rowCount; i++) {
        currentChannel.getProperties().getTags().add((String) model.getValueAt(i, 0));
    }/* w w  w  . j  av a  2s.  co m*/
}

From source file:com.mirth.connect.client.ui.ChannelSetup.java

private void addMetaDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addMetaDataButtonActionPerformed
    DefaultTableModel model = ((DefaultTableModel) metaDataTable.getModel());
    int row = model.getRowCount();

    model.addRow(new Object[] { "", MetaDataColumnType.STRING, "" });

    metaDataTable.setRowSelectionInterval(row, row);

    revertMetaDataButton.setEnabled(true);

    parent.setSaveEnabled(true);//from   ww  w  . j ava 2  s.  co m
}

From source file:captureplugin.CapturePlugin.java

/**
 * Check the programs after data update.
 *///  w w  w .j  av a 2 s. co  m
public void handleTvDataUpdateFinished() {
    mNeedsUpdate = true;

    if (mAllowedToShowDialog) {
        mNeedsUpdate = false;

        DeviceIf[] devices = mConfig.getDeviceArray();

        final DefaultTableModel model = new DefaultTableModel() {
            public boolean isCellEditable(int row, int column) {
                return false;
            }
        };

        model.setColumnCount(5);
        model.setColumnIdentifiers(new String[] { mLocalizer.msg("device", "Device"),
                Localizer.getLocalization(Localizer.I18N_CHANNEL), mLocalizer.msg("date", "Date"),
                ProgramFieldType.START_TIME_TYPE.getLocalizedName(),
                ProgramFieldType.TITLE_TYPE.getLocalizedName() });

        JTable table = new JTable(model);
        table.getTableHeader().setReorderingAllowed(false);
        table.getTableHeader().setResizingAllowed(false);
        table.getColumnModel().getColumn(0).setCellRenderer(new DefaultTableCellRenderer() {
            public Component getTableCellRendererComponent(JTable renderTable, Object value, boolean isSelected,
                    boolean hasFocus, int row, int column) {
                Component c = super.getTableCellRendererComponent(renderTable, value, isSelected, hasFocus, row,
                        column);

                if (value instanceof DeviceIf) {
                    if (((DeviceIf) value).getDeleteRemovedProgramsAutomatically() && !isSelected) {
                        c.setForeground(Color.red);
                    }
                }

                return c;
            }
        });

        int[] columnWidth = new int[5];

        for (int i = 0; i < columnWidth.length; i++) {
            columnWidth[i] = UiUtilities.getStringWidth(table.getFont(), model.getColumnName(i)) + 10;
        }

        for (DeviceIf device : devices) {
            Program[] deleted = device.checkProgramsAfterDataUpdateAndGetDeleted();

            if (deleted != null && deleted.length > 0) {
                for (Program p : deleted) {
                    if (device.getDeleteRemovedProgramsAutomatically() && !p.isExpired() && !p.isOnAir()) {
                        device.remove(UiUtilities.getLastModalChildOf(getParentFrame()), p);
                    } else {
                        device.removeProgramWithoutExecution(p);
                    }

                    if (!p.isExpired()) {
                        Object[] o = new Object[] { device, p.getChannel().getName(), p.getDateString(),
                                p.getTimeString(), p.getTitle() };

                        for (int i = 0; i < columnWidth.length; i++) {
                            columnWidth[i] = Math.max(columnWidth[i],
                                    UiUtilities.getStringWidth(table.getFont(), o[i].toString()) + 10);
                        }

                        model.addRow(o);
                    }
                }
            }

            device.getProgramList();
        }

        if (model.getRowCount() > 0) {
            int sum = 0;

            for (int i = 0; i < columnWidth.length; i++) {
                table.getColumnModel().getColumn(i).setPreferredWidth(columnWidth[i]);

                if (i < columnWidth.length - 1) {
                    table.getColumnModel().getColumn(i).setMaxWidth(columnWidth[i]);
                }

                sum += columnWidth[i];
            }

            JScrollPane scrollPane = new JScrollPane(table);
            scrollPane.setPreferredSize(new Dimension(450, 250));

            if (sum > 500) {
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                scrollPane.getViewport().setPreferredSize(
                        new Dimension(sum, scrollPane.getViewport().getPreferredSize().height));
            }

            JButton export = new JButton(mLocalizer.msg("exportList", "Export list"));
            export.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JFileChooser chooser = new JFileChooser();
                    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
                    chooser.setFileFilter(new FileFilter() {
                        public boolean accept(File f) {
                            return f.isDirectory() || f.toString().toLowerCase().endsWith(".txt");
                        }

                        public String getDescription() {
                            return "*.txt";
                        }
                    });

                    chooser.setSelectedFile(new File("RemovedPrograms.txt"));
                    if (chooser.showSaveDialog(
                            UiUtilities.getLastModalChildOf(getParentFrame())) == JFileChooser.APPROVE_OPTION) {
                        if (chooser.getSelectedFile() != null) {
                            String file = chooser.getSelectedFile().getAbsolutePath();

                            if (!file.toLowerCase().endsWith(".txt") && file.indexOf('.') == -1) {
                                file = file + ".txt";
                            }

                            if (file.indexOf('.') != -1) {
                                try {
                                    RandomAccessFile write = new RandomAccessFile(file, "rw");
                                    write.setLength(0);

                                    String eolStyle = File.separator.equals("/") ? "\n" : "\r\n";

                                    for (int i = 0; i < model.getRowCount(); i++) {
                                        StringBuilder line = new StringBuilder();

                                        for (int j = 0; j < model.getColumnCount(); j++) {
                                            line.append(model.getValueAt(i, j)).append(' ');
                                        }

                                        line.append(eolStyle);

                                        write.writeBytes(line.toString());
                                    }

                                    write.close();
                                } catch (Exception ee) {
                                }
                            }
                        }
                    }
                }
            });

            Object[] message = {
                    mLocalizer.msg("deletedText",
                            "The data was changed and the following programs were deleted:"),
                    scrollPane, export };

            JOptionPane pane = new JOptionPane();
            pane.setMessage(message);
            pane.setMessageType(JOptionPane.PLAIN_MESSAGE);

            final JDialog d = pane.createDialog(UiUtilities.getLastModalChildOf(getParentFrame()),
                    mLocalizer.msg("CapturePlugin", "CapturePlugin") + " - "
                            + mLocalizer.msg("deletedTitle", "Deleted programs"));
            d.setResizable(true);
            d.setModal(false);

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    d.setVisible(true);
                }
            });
        }
    }
}

From source file:com.mirth.connect.client.ui.ChannelSetup.java

public void saveMetaDataColumns() {
    DefaultTableModel model = (DefaultTableModel) metaDataTable.getModel();

    List<MetaDataColumn> metaDataColumns = currentChannel.getProperties().getMetaDataColumns();
    metaDataColumns.clear();//  w w  w .jav  a 2  s. c om

    for (int i = 0; i < model.getRowCount(); i++) {
        MetaDataColumn column = new MetaDataColumn();
        column.setName((String) model.getValueAt(i, 0));
        column.setType((MetaDataColumnType) model.getValueAt(i, 1));
        column.setMappingName((String) model.getValueAt(i, 2));

        metaDataColumns.add(column);
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void miscSplit() {
    if (jideTabbedPane1.getSelectedIndex() == 0) {
        DefaultTableModel model = (DefaultTableModel) jSourcesTable.getModel();
        int sources = model.getRowCount();
        if (sources == 0) {
            showInfo("Keine Herkunftsdrfer eingetragen");
            return;
        }//www . ja v  a  2  s.  c  o  m
        List<Village> sourceVillages = new LinkedList<Village>();
        Hashtable<Village, UnitHolder> attTable = new Hashtable<Village, UnitHolder>();
        Hashtable<Village, UnitHolder> fakeTable = new Hashtable<Village, UnitHolder>();
        for (int i = 0; i < sources; i++) {
            Village sourceVillage = (Village) model.getValueAt(i, jSourcesTable.convertColumnIndexToModel(0));
            if (!sourceVillages.contains(sourceVillage)) {
                sourceVillages.add(sourceVillage);
                boolean fake = (Boolean) jSourcesTable.getValueAt(i,
                        jSourcesTable.convertColumnIndexToModel(2));
                UnitHolder unit = (UnitHolder) jSourcesTable.getValueAt(i,
                        jSourcesTable.convertColumnIndexToModel(1));
                if (fake) {
                    fakeTable.put(sourceVillage, unit);
                } else {
                    attTable.put(sourceVillage, unit);
                }
            }
        }
        mTroopSplitDialog.setupAndShow(sourceVillages);
        TroopSplit[] splits = mTroopSplitDialog.getSplits();
        if (splits.length == 0) {
            //canceled
            return;
        }
        for (int i = sources - 1; i >= 0; i--) {
            model.removeRow(i);
        }
        int overallSplitCount = 0;
        for (TroopSplit split : splits) {
            overallSplitCount += split.getSplitCount();
            for (int i = 0; i < split.getSplitCount(); i++) {
                boolean isFake = false;
                UnitHolder unit = attTable.get(split.getVillage());
                if (unit == null) {
                    unit = fakeTable.get(split.getVillage());
                    isFake = true;
                }
                model.addRow(new Object[] { split.getVillage(), unit, isFake, 0 });
            }
        }

        String message = ((sourceVillages.size() == 1) ? "Herkunftsdorf "
                : sourceVillages.size() + " Herkunftsdrfer ")
                + ((overallSplitCount == 1) ? "einmal" : overallSplitCount + " mal ") + " geteilt";
        showSuccess(message);
    } else {
        showInfo("Diese Funktion ist nur fr Herkunftsdrfer verfgbar");
    }
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void fireCalculateAttackEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireCalculateAttackEvent
    if (!jCalculateButton.isEnabled()) {
        logger.debug("Button disabled. Calculation is still running...");
        return;/*from  ww  w  .j  a va 2 s. c  om*/
    }
    //algorithm calculation
    //pre check
    DefaultTableModel victimModel = (DefaultTableModel) jVictimTable.getModel();
    DefaultTableModel attackModel = (DefaultTableModel) jSourcesTable.getModel();
    if (attackModel.getRowCount() == 0) {
        logger.warn("Validation of attacker tab failed");
        JOptionPaneHelper.showErrorBox(this, "Keine Herkunftsdrfer ausgewhlt", "Fehler");
        jideTabbedPane1.setSelectedIndex(0);
        return;
    }
    if (victimModel.getRowCount() == 0) {
        logger.warn("Validation of victim tab failed");
        JOptionPaneHelper.showErrorBox(this, "Keine Ziele ausgewhlt", "Fehler");
        jideTabbedPane1.setSelectedIndex(1);
        return;
    }
    if (!mSettingsPanel.validatePanel()) {
        logger.warn("Validation of settings tab failed");
        jideTabbedPane1.setSelectedIndex(2);
        return;
    }
    //reading values
    List<Village> victimVillages = new LinkedList<Village>();
    List<Village> victimVillagesFaked = new LinkedList<Village>();
    Hashtable<Village, Integer> maxAttacksTable = new Hashtable<Village, Integer>();
    for (int i = 0; i < victimModel.getRowCount(); i++) {
        if ((Boolean) victimModel.getValueAt(i, 2) == Boolean.TRUE) {
            victimVillagesFaked.add((Village) victimModel.getValueAt(i, 1));
        } else {
            victimVillages.add((Village) victimModel.getValueAt(i, 1));
        }
        maxAttacksTable.put((Village) victimModel.getValueAt(i, 1), (Integer) victimModel.getValueAt(i, 3));
    }
    //build source-unit map
    int snobSources = 0;
    // <editor-fold defaultstate="collapsed" desc=" Build attacks and fakes">
    Hashtable<UnitHolder, List<Village>> sources = new Hashtable<UnitHolder, List<Village>>();
    Hashtable<UnitHolder, List<Village>> fakes = new Hashtable<UnitHolder, List<Village>>();
    for (int i = 0; i < attackModel.getRowCount(); i++) {
        Village vSource = (Village) attackModel.getValueAt(i, 0);
        UnitHolder uSource = (UnitHolder) attackModel.getValueAt(i, 1);
        boolean fake = (Boolean) attackModel.getValueAt(i, 2);
        if (!fake) {
            List<Village> sourcesForUnit = sources.get(uSource);
            if (uSource.getPlainName().equals("snob")) {
                if (sourcesForUnit == null) {
                    snobSources = 0;
                } else {
                    snobSources = sourcesForUnit.size();
                }
            }
            if (sourcesForUnit == null) {
                sourcesForUnit = new LinkedList<Village>();
                sourcesForUnit.add(vSource);
                sources.put(uSource, sourcesForUnit);
            } else {
                sourcesForUnit.add(vSource);
            }
        } else {
            List<Village> fakesForUnit = fakes.get(uSource);
            if (fakesForUnit == null) {
                fakesForUnit = new LinkedList<Village>();
                fakesForUnit.add(vSource);
                fakes.put(uSource, fakesForUnit);
            } else {
                fakesForUnit.add(vSource);
            }
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc=" Check for units not supported by the algorithm">
    boolean useMiscUnits = false;
    Enumeration<UnitHolder> involvedUnits = sources.keys();
    while (involvedUnits.hasMoreElements()) {
        UnitHolder u = involvedUnits.nextElement();
        //check for misc unit
        if (!u.getPlainName().equals("ram") && !u.getPlainName().equals("catapult")) {
            useMiscUnits = true;
            break;
        }
    }
    if (!useMiscUnits) {
        involvedUnits = fakes.keys();
        while (involvedUnits.hasMoreElements()) {
            UnitHolder u = involvedUnits.nextElement();
            //check for misc unit
            if (!u.getPlainName().equals("ram") && !u.getPlainName().equals("catapult")) {
                useMiscUnits = true;
                break;
            }
        }
    }
    // </editor-fold>
    boolean fakeOffTargets = mSettingsPanel.fakeOffTargets();
    //mSettingsPanel.getAttacksPerVillage();
    TimeFrame timeFrame = mSettingsPanel.getTimeFrame();
    //start processing
    AbstractAttackAlgorithm algo = null;
    boolean supportMiscUnits = false;
    if (mSettingsPanel.useBruteForce()) {
        logger.info("Using 'BruteForce' calculation");
        algo = new BruteForce();
        //algo = new Recurrection();
        supportMiscUnits = true;
        logPanel.setAbortable(false);
    } else {
        logger.info("Using 'systematic' calculation");
        algo = new Iterix();
        supportMiscUnits = false;
        logPanel.setAbortable(true);
    }
    //check misc-units criteria
    if (useMiscUnits && !supportMiscUnits) {
        if (JOptionPaneHelper.showQuestionConfirmBox(this,
                "Der gewhlte Algorithmus untersttzt nur Rammen und Katapulte als angreifende Einheiten.\n"
                        + "Drfer fr die eine andere Einheit gewhlt wurde werden ignoriert.\n"
                        + "Trotzdem fortfahren?",
                "Warnung", "Nein", "Ja") == JOptionPane.NO_OPTION) {
            logger.debug("User aborted calculation due to algorithm");
            return;
        }
    }
    mSettingsPanel.storeProperties();
    logPanel.clear();
    algo.initialize(sources, fakes, victimVillages, victimVillagesFaked, maxAttacksTable, timeFrame,
            fakeOffTargets, logPanel);
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            try {
                jCalculateButton.setEnabled(false);
                mLogFrame.setVisible(true);
                mLogFrame.toFront();
            } catch (Exception e) {
            }
        }
    });
    algo.execute(this);
}

From source file:de.tor.tribes.ui.windows.TribeTribeAttackFrame.java

private void addTargetVillages(List<Village> pVillages) {
    int maxAttacksPerVillage = 1;
    try {//from   ww  w.  j a va 2s  .  c o  m
        maxAttacksPerVillage = (Integer) jMaxAttacksPerVillage.getValue();
    } catch (Exception e) {
        maxAttacksPerVillage = 1;
    }

    DefaultTableModel theModel = (DefaultTableModel) jVictimTable.getModel();
    for (Village v : pVillages) {
        if (v.getTribe() != null) {
            boolean added = false;
            for (int i = 0; i < theModel.getRowCount(); i++) {
                if (jVictimTable.getValueAt(i, 1).equals(v)) {
                    Integer amount = (Integer) jVictimTable.getValueAt(i, 3);
                    jVictimTable.setValueAt(amount + 1, i, 3);
                    added = true;
                    break;
                }
            }
            if (!added) {
                ((DefaultTableModel) jVictimTable.getModel()).addRow(new Object[] { v.getTribe(), v,
                        jMarkTargetAsFake.isSelected(), maxAttacksPerVillage, 0 });
            }
        }
    }
}