Example usage for javax.swing JOptionPane OK_OPTION

List of usage examples for javax.swing JOptionPane OK_OPTION

Introduction

In this page you can find the example usage for javax.swing JOptionPane OK_OPTION.

Prototype

int OK_OPTION

To view the source code for javax.swing JOptionPane OK_OPTION.

Click Source Link

Document

Return value form class method if OK is chosen.

Usage

From source file:org.nuclos.client.ui.collect.CollectController.java

/**
 * command: delete current collectable in details<br>
 * Deletes the current collectable in Details mode.
 *
 * @deprecated Move to DetailsController and make private again.
 *///from   w  w  w  .j  ava2s .  c om
public void cmdDeleteCurrentCollectableInDetails() {
    assert this.getCollectStateModel().getCollectState()
            .equals(new CollectState(CollectState.OUTERSTATE_DETAILS, CollectState.DETAILSMODE_VIEW));

    if (this.stopEditingInDetails()) {
        final String sMessage = getSpringLocaleDelegate().getMessage("GenericObjectCollectController.74",
                "Soll der angezeigte Datensatz ({0}) wirklich gel\u00f6scht werden?",
                getSelectedCollectable().getIdentifierLabel());
        final int iBtn = JOptionPane.showConfirmDialog(
                this.getTab(), sMessage, getSpringLocaleDelegate()
                        .getMessage("GenericObjectCollectController.26", "Datensatz l\u00f6schen"),
                JOptionPane.YES_NO_OPTION);

        if (iBtn == JOptionPane.OK_OPTION) {
            UIUtils.runCommand(this.getTab(), new Runnable() {
                @Override
                public void run() {
                    cmdDeleteCurrentCollectableInDetailsImpl();
                }
            });
        }
    }
}

From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java

/**
 * @param result//from   w  w  w.  ja v  a  2  s  .c o m
 * @param clctcomp
 */
private static void addRightOperandToPopupMenu(JPopupMenu result, final AbstractCollectableComponent clctcomp) {
    result.addSeparator();
    final ButtonGroup btngrpCompareWith = new ButtonGroup();
    final SpringLocaleDelegate localeDelegate = SpringLocaleDelegate.getInstance();

    final JRadioButtonMenuItem miValue = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.17", "Wertvergleich"));
    miValue.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.10",
            "Dieses Feld mit einem festen Wert vergleichen"));
    result.add(miValue);
    btngrpCompareWith.add(miValue);
    miValue.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            clctcomp.resetWithComparison();
            clctcomp.runLocked(new Runnable() {
                @Override
                public void run() {
                    clctcomp.updateSearchConditionInModel();
                }
            });
        }
    });

    final JRadioButtonMenuItem miOtherField = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.12", "Feldvergleich..."));
    miOtherField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.9",
            "Dieses Feld mit dem Inhalt eines anderen Felds vergleichen"));
    result.add(miOtherField);
    btngrpCompareWith.add(miOtherField);
    miOtherField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ev) {
            assert clctcomp.clcte != null;

            // select entity field with the same data type:
            final List<CollectableEntityField> lstclctefFiltered = CollectionUtils.select(
                    CollectableUtils.getCollectableEntityFields(clctcomp.clcte),
                    new Predicate<CollectableEntityField>() {
                        @Override
                        public boolean evaluate(CollectableEntityField clctef) {
                            return clctef.getJavaClass() == clctcomp.clctef.getJavaClass();
                        }
                    });
            // and sort by label:
            final List<CollectableEntityField> lstclctefSorted = CollectionUtils.sorted(lstclctefFiltered,
                    new CollectableEntityField.LabelComparator());

            final JComboBox cmbbx = new JComboBox(lstclctefSorted.toArray());
            cmbbx.setSelectedItem(clctcomp.getComparisonOtherField());

            final int iBtn = JOptionPane
                    .showConfirmDialog(clctcomp.getJComponent(),
                            new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.6",
                                    "Anderes Feld: "), cmbbx },
                            localeDelegate.getMessage("AbstractCollectableComponent.15",
                                    "Vergleich mit anderem Feld"),
                            JOptionPane.OK_CANCEL_OPTION);

            if (iBtn == JOptionPane.OK_OPTION) {
                clctcomp.setWithComparison((CollectableEntityField) cmbbx.getSelectedItem());
                if (clctcomp.getComparisonOtherField() != null) {
                    // clear the view:
                    clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField()));

                    if (clctcomp.compop.getOperandCount() < 2) {
                        // If the user selects "other field" and forgot to set the operator, we assume "EQUAL":
                        clctcomp.compop = ComparisonOperator.EQUAL;
                    }
                }
                clctcomp.runLocked(new Runnable() {
                    @Override
                    public void run() {
                        clctcomp.updateSearchConditionInModel();
                    }
                });
            }
        }
    });

    final List<ComparisonParameter> compatibleParameters = ComparisonParameter
            .getCompatibleParameters(clctcomp.getEntityField());
    final JRadioButtonMenuItem miParameterField = new JRadioButtonMenuItem(
            localeDelegate.getMessage("AbstractCollectableComponent.18", null));
    miParameterField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.19", null));
    btngrpCompareWith.add(miParameterField);
    if (compatibleParameters.size() > 0) {
        result.add(miParameterField);
        miParameterField.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ev) {
                ResourceIdMapper<ComparisonParameter> mapper = new ResourceIdMapper<ComparisonParameter>(
                        compatibleParameters);
                JComboBox cmbbx = new JComboBox(CollectionUtils.sorted(compatibleParameters, mapper).toArray());
                cmbbx.setRenderer(new DefaultListRenderer(mapper));
                cmbbx.setSelectedItem(clctcomp.getComparisonParameter());

                final int opt = JOptionPane.showConfirmDialog(clctcomp.getJComponent(),
                        new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.20", null),
                                cmbbx },
                        localeDelegate.getMessage("AbstractCollectableComponent.19", null),
                        JOptionPane.OK_CANCEL_OPTION);

                if (opt == JOptionPane.OK_OPTION) {
                    clctcomp.setWithComparison((ComparisonParameter) cmbbx.getSelectedItem());
                    if (clctcomp.getComparisonParameter() != null) {
                        clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField()));
                        if (clctcomp.compop.getOperandCount() < 2) {
                            clctcomp.compop = ComparisonOperator.EQUAL;
                        }
                    }
                    clctcomp.runLocked(new Runnable() {
                        @Override
                        public void run() {
                            clctcomp.updateSearchConditionInModel();
                        }
                    });
                }
            }
        });
    }

    result.addPopupMenuListener(new PopupMenuListener() {
        @Override
        public void popupMenuWillBecomeVisible(PopupMenuEvent ev) {
            if (clctcomp.getComparisonParameter() != null) {
                miParameterField.setSelected(true);
            } else if (clctcomp.getComparisonOtherField() == null
                    || clctcomp.getComparisonOperator().getOperandCount() < 2) {
                miValue.setSelected(true);
            } else {
                miOtherField.setSelected(true);
            }
        }

        @Override
        public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) {
        }

        @Override
        public void popupMenuCanceled(PopupMenuEvent ev) {
        }
    });
}

From source file:org.nuclos.client.ui.collect.searcheditor.AtomicNodeController.java

/**
 * lets the user add a new node as a new child of the given parent.
 * @param nodeParent/*from w ww.j a  v  a2s  . com*/
 */
public void runAdd(SearchConditionTreeNode nodeParent) {
    final AtomicNodePanel pnl = new AtomicNodePanel();
    final int iBtn = this.newOptionPane(getSpringLocaleDelegate().getMessage("AtomicNodeController.1",
            "Einfache Bedingung hinzuf\u00fcgen"), pnl).showDialog();

    if (iBtn == JOptionPane.OK_OPTION) {
        try {
            final AtomicCollectableSearchCondition cond = pnl.getSearchCondition();
            if (cond != null) {
                nodeParent.add(new AtomicSearchConditionTreeNode(cond));
                nodeParent.refresh(tree);
            }
        } catch (CommonBusinessException ex) {
            Errors.getInstance().showExceptionDialog(getParent(), ex);
        }
    }
}

From source file:org.nuclos.client.ui.collect.searcheditor.AtomicNodeController.java

/**
 * lets the user edit the given node.//from   w  w  w  .j  av a 2  s. c  o m
 * @param node
 */
public void runEdit(AtomicSearchConditionTreeNode node) {
    final AtomicNodePanel pnl = new AtomicNodePanel();
    pnl.setSearchCondition(node.getSearchCondition());
    final int iBtn = this.newOptionPane(
            getSpringLocaleDelegate().getMessage("AtomicNodeController.2", "Einfache Bedingung bearbeiten"),
            pnl).showDialog();

    if (iBtn == JOptionPane.OK_OPTION) {
        try {
            final AtomicCollectableSearchCondition cond = pnl.getSearchCondition();
            final SearchConditionTreeNode nodeParent = (SearchConditionTreeNode) node.getParent();
            final int iChildIndex = nodeParent.getIndex(node);
            nodeParent.remove(iChildIndex);
            if (cond != null) {
                nodeParent.insert(new AtomicSearchConditionTreeNode(cond), iChildIndex);
            }
            nodeParent.refresh(tree);
        } catch (CommonBusinessException ex) {
            Errors.getInstance().showExceptionDialog(getParent(), ex);
        }
    }
}

From source file:org.nuclos.client.wizard.steps.NuclosEntityNameStep.java

@Override
protected void initComponents() {

    colMasterdata = MetaDataClientProvider.getInstance().getAllEntities();

    double size[][] = { { TableLayout.PREFERRED, 200, TableLayout.FILL },
            { 20, 20, 20, 20, 20, TableLayout.FILL } };

    TableLayout layout = new TableLayout(size);
    layout.setVGap(3);//w ww . j  a va2s.c  om
    layout.setHGap(5);
    this.setLayout(layout);
    lbName = new JLabel(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.1",
            "Bitte geben Sie den Namen der neuen Entit\u00e4t ein") + ": ");
    tfName = new JTextField();
    tfName.setToolTipText(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.tooltip.1",
            "Namen der neuen Entit\u00e4t"));
    tfName.addFocusListener(NuclosWizardUtils.createWizardFocusAdapter());
    lbChoice = new JLabel(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.2",
            "oder w\u00e4hlen Sie eine Entit\u00e4t die Sie ver\u00e4ndern m\u00f6chten") + ": ");
    cmbEntity = new JComboBox();
    cmbEntity.setToolTipText(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.tooltip.2",
            "Namen der Entit\u00e4t die Sie ver\u00e4ndern m\u00f6chten"));
    this.fillEntityCombobox();
    cmbEntity.setEditable(true);
    AutoCompleteDecorator.decorate(cmbEntity);

    lbInfo = new JLabel();
    lbInfo.setVisible(false);
    lbInfo.setForeground(Color.RED);

    btnRemove = new JButton(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.8",
            "Entit\u00e4t entfernen"));
    btnRemove.setVisible(false);

    this.add(lbName, "0,0");
    this.add(tfName, "1,0");
    this.add(lbChoice, "0,1");
    this.add(cmbEntity, "1,1");
    this.add(lbInfo, "0,2,1,2");
    this.add(btnRemove, "0,3");

    tfName.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void removeUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            doSomeWork(e);
        }

        protected void doSomeWork(DocumentEvent e) {
            int size = e.getDocument().getLength();
            try {
                for (EntityMetaDataVO metaVO : colMasterdata) {
                    if (e.getDocument().getLength() == 0) {
                        lbInfo.setVisible(false);
                        break;
                    }
                    if (e.getDocument().getLength() > 250) {
                        lbInfo.setText(SpringLocaleDelegate.getInstance().getMessage(
                                "wizard.step.entityname.12", "Der Name ist zu lang. Bitte k\u00fcrzen!"));
                        lbInfo.setVisible(true);
                        NuclosEntityNameStep.this.setComplete(false);
                        return;
                    }

                    if (e.getDocument().getText(0, size).equals(metaVO.getEntity())
                            || e.getDocument().getText(0, size).equals(SpringLocaleDelegate.getInstance()
                                    .getResource(metaVO.getLocaleResourceIdForLabel(), ""))) {
                        NuclosEntityNameStep.this.setComplete(false);
                        lbInfo.setText(SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.4",
                                "Entit\u00e4t ist schon vorhanden"));
                        lbInfo.setVisible(true);
                        return;
                    } else {
                        lbInfo.setVisible(false);
                    }
                    if (e.getDocument().getLength() > 25) {
                        lbInfo.setText(
                                SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.13",
                                        "Der Tabellenname wird fr interne Zwecke gekrzt!"));
                        lbInfo.setVisible(true);
                    } else {
                        lbInfo.setVisible(false);
                    }
                }
                if (size > 0) {
                    if (cmbEntity.getSelectedIndex() > 0) {
                        NuclosEntityNameStep.this.model.resetModel();
                    }
                    NuclosEntityNameStep.this.setComplete(true);
                    cmbEntity.setSelectedIndex(0);
                    cmbEntity.setEnabled(false);
                } else {
                    //NuclosEntityNameStep.this.model.resetModel();
                    NuclosEntityNameStep.this.setComplete(false);
                    model.setTableOrViewName(null);
                    cmbEntity.setEnabled(true);
                }

                NuclosEntityNameStep.this.model
                        .setEntityName(e.getDocument().getText(0, e.getDocument().getLength()));
                if (!NuclosEntityNameStep.this.model.isEditMode()) {
                    NuclosEntityNameStep.this.model
                            .setLabelSingular(e.getDocument().getText(0, e.getDocument().getLength()));
                }
            } catch (BadLocationException ex) {
                Errors.getInstance().showExceptionDialog(NuclosEntityNameStep.this, ex);
            }
        }
    });

    cmbEntity.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(final ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                final Object obj = e.getItem();
                if (obj instanceof EntityWrapper) {
                    EntityMetaDataVO vo = ((EntityWrapper) obj).getWrappedEntity();
                    NuclosEntityNameStep.this.model.setEditMode(true);
                    NuclosEntityNameStep.this.model.resetModel();
                    NuclosEntityNameStep.this.setComplete(true);
                    btnRemove.setVisible(true);
                } else if (obj instanceof String) {
                    NuclosEntityNameStep.this.model.setEditMode(false);
                    NuclosEntityNameStep.this.model.resetModel();
                    tfName.setEnabled(true);
                    btnRemove.setVisible(false);
                    NuclosEntityNameStep.this.setComplete(false);
                }
            }
        }
    });
    ListenerUtil.registerActionListener(btnRemove, this, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                StringBuffer sbMessage = new StringBuffer();
                if (!dropEntityAllowed(((EntityWrapper) cmbEntity.getSelectedItem()).getWrappedEntity(),
                        sbMessage)) {
                    JOptionPane.showMessageDialog(
                            NuclosEntityNameStep.this, sbMessage, SpringLocaleDelegate.getInstance()
                                    .getMessage("wizard.step.inputattribute.12", "Entfernen nicht mglich!"),
                            JOptionPane.OK_OPTION);
                    return;
                }

                boolean blnImportStructure = MetaDataDelegate.getInstance().hasEntityImportStructure(
                        ((EntityWrapper) cmbEntity.getSelectedItem()).getWrappedEntity().getId());
                if (blnImportStructure) {
                    String sMessage = SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.14",
                            "Diese Entitt besitzt Strukturdefinitionen fr Objektimporte. Diese wird gelscht! Sie knnen den Vorgang abbrechen!");
                    int abort = JOptionPane
                            .showConfirmDialog(
                                    NuclosEntityNameStep.this, sMessage, SpringLocaleDelegate.getInstance()
                                            .getMessage("wizard.step.entityname.16", "Achtung!"),
                                    JOptionPane.OK_CANCEL_OPTION);
                    if (abort != JOptionPane.OK_OPTION)
                        return;
                }

                boolean blnWorkflow = MetaDataDelegate.getInstance().hasEntityWorkflow(
                        ((EntityWrapper) cmbEntity.getSelectedItem()).getWrappedEntity().getId());
                if (blnWorkflow) {
                    String sMessage = SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.15",
                            "Diese Entitt ist in einem Arbeitsschritt integriert! Dieser wird gelscht!");
                    int abort = JOptionPane
                            .showConfirmDialog(
                                    NuclosEntityNameStep.this, sMessage, SpringLocaleDelegate.getInstance()
                                            .getMessage("wizard.step.entityname.16", "Achtung!"),
                                    JOptionPane.OK_CANCEL_OPTION);
                    if (abort != JOptionPane.OK_OPTION)
                        return;
                }

                final String sMessage = SpringLocaleDelegate.getInstance().getMessage(
                        "wizard.step.entityname.9",
                        "Sind Sie sicher, dass Sie die Entit\u00e4t l\u00f6schen m\u00f6chten?");
                final String sTitle = SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.10",
                        "L\u00f6schen");

                int dropEntity = JOptionPane.showConfirmDialog(NuclosEntityNameStep.this, sMessage, sTitle,
                        JOptionPane.YES_NO_OPTION);
                switch (dropEntity) {
                case JOptionPane.YES_OPTION:
                    boolean bDropLayout = false;
                    if (MetaDataDelegate.getInstance().hasEntityLayout(
                            ((EntityWrapper) cmbEntity.getSelectedItem()).getWrappedEntity().getId())) {
                        int dropLayout = JOptionPane.showConfirmDialog(NuclosEntityNameStep.this,
                                SpringLocaleDelegate.getInstance().getMessage("wizard.step.entityname.11",
                                        "Soll das Layout der Entitt gelscht werden?"),
                                sTitle, JOptionPane.YES_NO_OPTION);
                        bDropLayout = (dropLayout == JOptionPane.YES_OPTION);
                    }

                    final boolean bDropLayoutfinal = bDropLayout;
                    UIUtils.runCommandLater(getParent(), new Runnable() {

                        @Override
                        public void run() {
                            try {
                                MetaDataDelegate.getInstance().removeEntity(
                                        ((EntityWrapper) cmbEntity.getSelectedItem()).getWrappedEntity(),
                                        bDropLayoutfinal);
                                NuclosWizardUtils.flushCaches();
                                NuclosConsole.getInstance().invalidateAllCaches();
                                NuclosEntityNameStep.this.model.cancelWizard();
                            } catch (Exception ex) {
                                Errors.getInstance().showExceptionDialog(NuclosEntityNameStep.this, ex);
                                return;
                            } finally {
                                MasterDataDelegate.getInstance().invalidateLayoutCache();
                            }
                        }
                    });
                    break;
                case JOptionPane.NO_OPTION:
                default:
                    return;
                }
            } catch (Exception ex) {
                Errors.getInstance().showExceptionDialog(NuclosEntityNameStep.this, ex);
                return;
            }
        }
    });

}

From source file:org.omegat.convert.ConvertProject26to37team.java

public static void checkTeam(File projectRootFolder) throws Exception {
    if (isSVNDirectory(projectRootFolder) || isGITDirectory(projectRootFolder)) {
        // project is 2.6-style team project
        if (isConsoleMode()) {
            Core.getMainWindow().displayWarningRB("TEAM_26_TO_37_CONSOLE");
            return;
        }//from w w w  . j a va 2s .  c o m

        // ask for convert
        int res = JOptionPane.showConfirmDialog(Core.getMainWindow().getApplicationFrame(),
                OStrings.getString("TEAM_26_to_37_CONFIRM_MESSAGE"),
                OStrings.getString("TEAM_26_to_37_CONFIRM_TITLE"), JOptionPane.OK_CANCEL_OPTION);
        if (res != JOptionPane.OK_OPTION) {
            return;
        }

        // convert
        convert(projectRootFolder);
        JOptionPane.showMessageDialog(Core.getMainWindow().getApplicationFrame(),
                OStrings.getString("TEAM_26_to_37_CONVERTED_MESSAGE"),
                OStrings.getString("TEAM_26_to_37_CONFIRM_TITLE"), JOptionPane.INFORMATION_MESSAGE);
    }
}

From source file:org.omegat.gui.align.AlignPanelController.java

/**
 * Display the align tool. The tool is not modal, so this call will return immediately.
 * //w ww . java2 s .c  om
 * @param parent
 *            Parent window of the align tool
 */
public void show(Component parent) {
    frame = new AlignMenuFrame();
    frame.setTitle(OStrings.getString("ALIGNER_PANEL"));
    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            closeFrame(frame);
        }
    });

    panel = new AlignPanel();

    ActionListener comparisonListener = e -> {
        ComparisonMode newValue = (ComparisonMode) ((JComboBox<?>) e.getSource()).getSelectedItem();
        if (newValue != aligner.comparisonMode && confirmReset(frame)) {
            aligner.comparisonMode = newValue;
            reloadBeads();
        } else {
            panel.comparisonComboBox.setSelectedItem(aligner.comparisonMode);
        }
    };
    panel.comparisonComboBox.addActionListener(comparisonListener);
    panel.comparisonComboBox.setRenderer(new EnumRenderer<ComparisonMode>("ALIGNER_ENUM_COMPARISON_MODE_"));

    ActionListener algorithmListener = e -> {
        AlgorithmClass newValue = (AlgorithmClass) ((JComboBox<?>) e.getSource()).getSelectedItem();
        if (newValue != aligner.algorithmClass && confirmReset(frame)) {
            aligner.algorithmClass = newValue;
            reloadBeads();
        } else {
            panel.algorithmComboBox.setSelectedItem(aligner.algorithmClass);
        }
    };
    panel.algorithmComboBox.addActionListener(algorithmListener);
    panel.algorithmComboBox.setRenderer(new EnumRenderer<AlgorithmClass>("ALIGNER_ENUM_ALGORITHM_CLASS_"));

    ActionListener calculatorListener = e -> {
        CalculatorType newValue = (CalculatorType) ((JComboBox<?>) e.getSource()).getSelectedItem();
        if (newValue != aligner.calculatorType && confirmReset(frame)) {
            aligner.calculatorType = newValue;
            reloadBeads();
        } else {
            panel.calculatorComboBox.setSelectedItem(aligner.calculatorType);
        }
    };
    panel.calculatorComboBox.addActionListener(calculatorListener);
    panel.calculatorComboBox.setRenderer(new EnumRenderer<CalculatorType>("ALIGNER_ENUM_CALCULATOR_TYPE_"));

    ActionListener counterListener = e -> {
        CounterType newValue = (CounterType) ((JComboBox<?>) e.getSource()).getSelectedItem();
        if (newValue != aligner.counterType && confirmReset(frame)) {
            aligner.counterType = newValue;
            reloadBeads();
        } else {
            panel.counterComboBox.setSelectedItem(aligner.counterType);
        }
    };
    panel.counterComboBox.addActionListener(counterListener);
    panel.counterComboBox.setRenderer(new EnumRenderer<CounterType>("ALIGNER_ENUM_COUNTER_TYPE_"));

    ActionListener segmentingListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean newValue = ((AbstractButton) e.getSource()).isSelected();
            if (newValue != aligner.segment && confirmReset(frame)) {
                aligner.segment = newValue;
                reloadBeads();
            } else {
                panel.segmentingCheckBox.setSelected(aligner.segment);
                frame.segmentingItem.setSelected(aligner.segment);
            }
        }
    };
    panel.segmentingCheckBox.addActionListener(segmentingListener);
    frame.segmentingItem.addActionListener(segmentingListener);

    ActionListener segmentingRulesListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (confirmReset(frame)) {
                SegmentationCustomizer customizer = new SegmentationCustomizer(false, SRX.getDefault(),
                        Core.getSegmenter().getSRX(), null);
                if (customizer.show(frame)) {
                    customizedSRX = customizer.getResult();
                    Core.setSegmenter(new Segmenter(customizedSRX));
                    reloadBeads();
                }
            }
        }
    };
    panel.segmentingRulesButton.addActionListener(segmentingRulesListener);
    frame.segmentingRulesItem.addActionListener(segmentingRulesListener);

    ActionListener filterSettingsListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (confirmReset(frame)) {
                FiltersCustomizer customizer = new FiltersCustomizer(false,
                        FilterMaster.createDefaultFiltersConfig(), Core.getFilterMaster().getConfig(), null);
                if (customizer.show(frame)) {
                    customizedFilters = customizer.getResult();
                    Core.setFilterMaster(new FilterMaster(customizedFilters));
                    aligner.clearLoaded();
                    reloadBeads();
                }
            }
        }
    };
    panel.fileFilterSettingsButton.addActionListener(filterSettingsListener);
    frame.fileFilterSettingsItem.addActionListener(filterSettingsListener);

    TableCellRenderer renderer = new MultilineCellRenderer();
    panel.table.setDefaultRenderer(Object.class, renderer);
    panel.table.setDefaultRenderer(Boolean.class, renderer);
    panel.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            resizeRows(panel.table);
        }
    });

    ActionListener oneAdjustListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = panel.table.getSelectedRows();
            int col = panel.table.getSelectedColumn();
            boolean up = e.getSource().equals(panel.moveUpButton) || e.getSource().equals(frame.moveUpItem);
            BeadTableModel model = (BeadTableModel) panel.table.getModel();
            if ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
                int trgRow = up ? model.prevBeadFromRow(rows[0]) : model.nextBeadFromRow(rows[rows.length - 1]);
                moveRows(rows, col, trgRow);
            } else {
                int offset = up ? -1 : 1;
                slideRows(rows, col, offset);
            }
        }
    };
    panel.moveUpButton.addActionListener(oneAdjustListener);
    frame.moveUpItem.addActionListener(oneAdjustListener);
    panel.moveDownButton.addActionListener(oneAdjustListener);
    frame.moveDownItem.addActionListener(oneAdjustListener);

    ActionListener mergeListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = panel.table.getSelectedRows();
            int col = panel.table.getSelectedColumn();
            BeadTableModel model = (BeadTableModel) panel.table.getModel();
            if (rows.length == 1) {
                rows = new int[] { rows[0], model.nextNonEmptyCell(rows[0], col) };
            }
            int beads = model.beadsInRowSpan(rows);
            if (beads < 1) {
                // Do nothing
            } else if (beads == 1) {
                mergeRows(rows, col);
            } else {
                moveRows(rows, col, rows[0]);
            }
        }
    };
    panel.mergeButton.addActionListener(mergeListener);
    frame.mergeItem.addActionListener(mergeListener);

    ActionListener splitListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = panel.table.getSelectedRows();
            int col = panel.table.getSelectedColumn();
            BeadTableModel model = (BeadTableModel) panel.table.getModel();
            int beads = model.beadsInRowSpan(rows);
            if (beads != 1) {
                // Do nothing
            } else if (rows.length == 1) {
                splitRow(rows[0], col);
            } else {
                splitBead(rows, col);
            }
        }
    };
    panel.splitButton.addActionListener(splitListener);
    frame.splitItem.addActionListener(splitListener);

    ActionListener editListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            int row = panel.table.getSelectedRow();
            int col = panel.table.getSelectedColumn();
            editRow(row, col);
        }
    };
    panel.editButton.addActionListener(editListener);
    frame.editItem.addActionListener(editListener);

    ListSelectionListener selectionListener = new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            updateCommandAvailability(panel, frame);
        }
    };
    panel.table.getColumnModel().getSelectionModel().addListSelectionListener(selectionListener);
    panel.table.getSelectionModel().addListSelectionListener(selectionListener);

    ActionListener saveListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (!confirmSaveTMX(panel)) {
                return;
            }
            while (true) {
                JFileChooser chooser = new JFileChooser();
                chooser.setSelectedFile(new File(defaultSaveDir, getOutFileName()));
                chooser.setDialogTitle(OStrings.getString("ALIGNER_PANEL_DIALOG_SAVE"));
                if (JFileChooser.APPROVE_OPTION == chooser.showSaveDialog(frame)) {
                    File file = chooser.getSelectedFile();
                    if (file.isFile()) {
                        if (JOptionPane.OK_OPTION != JOptionPane.showConfirmDialog(frame,
                                StringUtil.format(OStrings.getString("ALIGNER_PANEL_DIALOG_OVERWRITE"),
                                        file.getName()),
                                OStrings.getString("ALIGNER_DIALOG_WARNING_TITLE"),
                                JOptionPane.WARNING_MESSAGE)) {
                            continue;
                        }
                    }
                    List<MutableBead> beads = ((BeadTableModel) panel.table.getModel()).getData();
                    try {
                        aligner.writePairsToTMX(file,
                                MutableBead.beadsToEntries(aligner.srcLang, aligner.trgLang, beads));
                        modified = false;
                    } catch (Exception ex) {
                        Log.log(ex);
                        JOptionPane.showMessageDialog(frame, OStrings.getString("ALIGNER_PANEL_SAVE_ERROR"),
                                OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE);
                    }
                }
                break;
            }
        }
    };
    panel.saveButton.addActionListener(saveListener);
    frame.saveItem.addActionListener(saveListener);

    ActionListener resetListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (confirmReset(frame)) {
                if (phase == Phase.ALIGN) {
                    aligner.restoreDefaults();
                }
                reloadBeads();
            }
        }
    };
    panel.resetButton.addActionListener(resetListener);
    frame.resetItem.addActionListener(resetListener);

    ActionListener reloadListener = e -> {
        if (confirmReset(frame)) {
            aligner.clearLoaded();
            reloadBeads();
        }
    };
    frame.reloadItem.addActionListener(reloadListener);

    ActionListener removeTagsListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            boolean newValue = ((AbstractButton) e.getSource()).isSelected();
            if (newValue != aligner.removeTags && confirmReset(frame)) {
                aligner.removeTags = newValue;
                aligner.clearLoaded();
                reloadBeads();
            } else {
                panel.removeTagsCheckBox.setSelected(aligner.removeTags);
                frame.removeTagsItem.setSelected(aligner.removeTags);
            }
        }
    };
    panel.removeTagsCheckBox.addActionListener(removeTagsListener);
    frame.removeTagsItem.addActionListener(removeTagsListener);

    panel.continueButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            phase = Phase.EDIT;
            updatePanel();
        }
    });

    ActionListener highlightListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            doHighlight = ((AbstractButton) e.getSource()).isSelected();
            updateHighlight();
        }
    };
    panel.highlightCheckBox.addActionListener(highlightListener);
    frame.highlightItem.addActionListener(highlightListener);

    ActionListener highlightPatternListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            PatternPanelController patternEditor = new PatternPanelController(highlightPattern);
            highlightPattern = patternEditor.show(frame);
            Preferences.setPreference(Preferences.ALIGNER_HIGHLIGHT_PATTERN, highlightPattern.pattern());
            updateHighlight();
        }
    };
    panel.highlightPatternButton.addActionListener(highlightPatternListener);
    frame.highlightPatternItem.addActionListener(highlightPatternListener);

    frame.markAcceptedItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setStatus(MutableBead.Status.ACCEPTED, panel.table.getSelectedRows());
        }
    });

    frame.markNeedsReviewItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setStatus(MutableBead.Status.NEEDS_REVIEW, panel.table.getSelectedRows());
        }
    });

    frame.clearMarkItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setStatus(MutableBead.Status.DEFAULT, panel.table.getSelectedRows());
        }
    });

    frame.toggleSelectedItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            toggleEnabled(panel.table.getSelectedRows());
        }
    });

    frame.closeItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            closeFrame(frame);
        }
    });

    frame.keepAllItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            toggleAllEnabled(true);
        }
    });

    frame.keepNoneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            toggleAllEnabled(false);
        }
    });

    frame.realignPendingItem.addActionListener(e -> {
        realignPending();
    });

    frame.pinpointAlignStartItem.addActionListener(e -> {
        phase = Phase.PINPOINT;
        ppRow = panel.table.getSelectedRow();
        ppCol = panel.table.getSelectedColumn();
        panel.table.clearSelection();
        updatePanel();
    });

    frame.pinpointAlignEndItem.addActionListener(e -> {
        pinpointAlign(panel.table.getSelectedRow(), panel.table.getSelectedColumn());
    });

    frame.pinpointAlignCancelItem.addActionListener(e -> {
        phase = Phase.EDIT;
        ppRow = -1;
        ppCol = -1;
        panel.table.repaint();
        updatePanel();
    });

    panel.table.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (phase == Phase.PINPOINT) {
                JTable table = (JTable) e.getSource();
                int row = table.rowAtPoint(e.getPoint());
                int col = table.columnAtPoint(e.getPoint());
                pinpointAlign(row, col);
            }
        }
    });

    frame.resetItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | KeyEvent.SHIFT_DOWN_MASK));
    frame.realignPendingItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_R, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    frame.saveItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    frame.closeItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_W, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    // emacs-like keys for table navigation
    // See javax.swing.plaf.BasicTableUI.Actions for supported action names.
    setKeyboardShortcut(panel.table, "selectNextRow", 'n');
    setKeyboardShortcut(panel.table, "selectNextRowExtendSelection", 'N');
    setKeyboardShortcut(panel.table, "selectPreviousRow", 'p');
    setKeyboardShortcut(panel.table, "selectPreviousRowExtendSelection", 'P');
    setKeyboardShortcut(panel.table, "selectNextColumn", 'f');
    setKeyboardShortcut(panel.table, "selectNextColumnExtendSelection", 'F');
    setKeyboardShortcut(panel.table, "selectPreviousColumn", 'b');
    setKeyboardShortcut(panel.table, "selectPreviousColumnExtendSelection", 'B');

    panel.table.setTransferHandler(new AlignTransferHandler());
    panel.table.addPropertyChangeListener("dropLocation", new DropLocationListener());
    if (Preferences.isPreference(Preferences.PROJECT_FILES_USE_FONT)) {
        try {
            String fontName = Preferences.getPreference(Preferences.TF_SRC_FONT_NAME);
            int fontSize = Integer.parseInt(Preferences.getPreference(Preferences.TF_SRC_FONT_SIZE));
            panel.table.setFont(new Font(fontName, Font.PLAIN, fontSize));
        } catch (Exception e) {
            Log.log(e);
        }
    }

    // Set initial state
    updateHighlight();
    updatePanel();
    reloadBeads();

    frame.add(panel);
    frame.pack();
    frame.setMinimumSize(frame.getSize());
    frame.setLocationRelativeTo(parent);
    frame.setVisible(true);
}

From source file:org.omegat.gui.align.AlignPanelController.java

private boolean confirmReset(Component comp) {
    if (!modified) {
        return true;
    }//from   www  .j ava2  s .c  o  m
    return JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(comp,
            OStrings.getString("ALIGNER_PANEL_RESET_WARNING_MESSAGE"),
            OStrings.getString("ALIGNER_DIALOG_WARNING_TITLE"), JOptionPane.OK_CANCEL_OPTION);
}

From source file:org.omegat.gui.align.AlignPanelController.java

/**
 * If the user has modified the SRX rules, offer to save them permanently. Otherwise they are simply
 * discarded. Does nothing when OmegaT's main window is not available (changes are always discarded under
 * standalone use)./*from  w  w  w .j  a  v  a 2  s.co  m*/
 * 
 * @param comp
 *            Parent component for dialog boxes
 */
private void confirmSaveSRX(Component comp) {
    if (Core.getMainWindow() == null || customizedSRX == null) {
        return;
    }
    if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(comp,
            OStrings.getString("ALIGNER_DIALOG_SEGMENTATION_CONFIRM_MESSAGE"),
            OStrings.getString("ALIGNER_DIALOG_CONFIRM_TITLE"), JOptionPane.OK_CANCEL_OPTION)) {
        if (Core.getProject().isProjectLoaded()
                && Core.getProject().getProjectProperties().getProjectSRX() != null) {
            Core.getProject().getProjectProperties().setProjectSRX(customizedSRX);
            try {
                Core.getProject().saveProjectProperties();
            } catch (Exception ex) {
                Log.log(ex);
                JOptionPane.showMessageDialog(comp, OStrings.getString("CT_ERROR_SAVING_PROJ"),
                        OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE);
            }
            ProjectUICommands.promptReload();
        } else {
            Preferences.setSRX(customizedSRX);
        }
    }
}

From source file:org.omegat.gui.align.AlignPanelController.java

/**
 * If the user has modified the file filter settings, offer to save them permanently. Otherwise they are
 * simply discarded. Does nothing when OmegaT's main window is not available (changes are always discarded
 * under standalone use).//  www  . j ava2s.  co m
 * 
 * @param comp
 *            Parent component for dialog boxes
 */
private void confirmSaveFilters(Component comp) {
    if (Core.getMainWindow() == null || customizedFilters == null) {
        return;
    }
    if (JOptionPane.OK_OPTION == JOptionPane.showConfirmDialog(comp,
            OStrings.getString("ALIGNER_DIALOG_FILTERS_CONFIRM_MESSAGE"),
            OStrings.getString("ALIGNER_DIALOG_CONFIRM_TITLE"), JOptionPane.OK_CANCEL_OPTION)) {
        if (Core.getProject().isProjectLoaded()
                && Core.getProject().getProjectProperties().getProjectFilters() != null) {
            Core.getProject().getProjectProperties().setProjectFilters(customizedFilters);
            try {
                Core.getProject().saveProjectProperties();
            } catch (Exception ex) {
                Log.log(ex);
                JOptionPane.showMessageDialog(comp, OStrings.getString("CT_ERROR_SAVING_PROJ"),
                        OStrings.getString("ERROR_TITLE"), JOptionPane.ERROR_MESSAGE);
            }
            ProjectUICommands.promptReload();
        } else {
            Preferences.setFilters(customizedFilters);
        }
    }
}