/** * @param owner the parent Window (Dialog or Frame) * @param frame the JabRef Frame * @param panel the currently selected BasePanel * @param modal should this dialog be modal? * @param metaData The metadata of the current database * @param fieldName the field this selector is initialized for. May be null. */ public ContentSelectorDialog2( Window owner, JabRefFrame frame, BasePanel panel, boolean modal, MetaData metaData, String fieldName) { super(owner, Localization.lang("Setup selectors")); this.setModal(modal); this.metaData = metaData; this.frame = frame; this.panel = panel; this.currentField = fieldName; initLayout(); setupFieldSelector(); setupWordSelector(); setupActions(); Util.bindCloseDialogKeyToCancelAction(this.rootPane, cancel.getAction()); int fieldInd = fieldListModel.indexOf(currentField); if (fieldInd >= 0) { fieldList.setSelectedIndex(fieldInd); } pack(); }
private void init() { getContentPane().setLayout(new BorderLayout()); getContentPane().add(labelPatternPanel, BorderLayout.CENTER); JButton ok = new JButton(Localization.lang("Ok")); JButton cancel = new JButton(); // label of "cancel" is set later as the label is overwritten by assigning an // action to the button JPanel lower = new JPanel(); lower.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); ButtonBarBuilder bb = new ButtonBarBuilder(lower); bb.addGlue(); bb.addButton(ok); bb.addButton(cancel); bb.addGlue(); getContentPane().add(lower, BorderLayout.SOUTH); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setPreferredSize(new Dimension(500, 600)); pack(); ok.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { metaData.setLabelPattern(labelPatternPanel.getLabelPatternAsDatabaseLabelPattern()); panel.markNonUndoableBaseChanged(); dispose(); } }); final JDialog dialog = this; Action cancelAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING)); } }; cancel.setAction(cancelAction); cancel.setText(Localization.lang("Cancel")); Util.bindCloseDialogKeyToCancelAction(this.getRootPane(), cancelAction); }