List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:org.kuali.test.ui.components.dialogs.ImportPlatformTestsDlg.java
private void initComponents() { JPanel p = new JPanel(new BorderLayout()); JPanel p2 = new JPanel(new FlowLayout()); p2.add(new JLabel("Available Platforms:", JLabel.RIGHT)); String[] platforms = getAvailablePlatforms(); p2.add(platformCombo = new JComboBox(platforms)); p.add(progressBar = new JProgressBar(), BorderLayout.CENTER); progressBar.setIndeterminate(false); p.add(p2, BorderLayout.NORTH); platformCombo.addActionListener(new ActionListener() { @Override/*from w ww .ja va 2 s.c om*/ public void actionPerformed(ActionEvent e) { loadTestList(platformCombo.getSelectedItem().toString()); } }); getContentPane().add(p, BorderLayout.NORTH); getContentPane().add(new JScrollPane(availableTests = new JList()), BorderLayout.CENTER); availableTests.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION); availableTests.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { getSaveButton().setEnabled(!availableTests.getSelectedValuesList().isEmpty()); } }); if (platforms.length > 0) { loadTestList(platforms[0]); } addStandardButtons(); getSaveButton().setEnabled(false); setDefaultBehavior(); }
From source file:org.monkeys.gui.matcher.MatcherPanel.java
private void wireEvents() { this.modifyPanel.addModifyMatchesListener(new ModifyMatchesListener() { @Override// www. ja v a2s .com public void searchAndReplace(final Pattern search, final String replace) { searchAndReplaceSelected(search, replace); } @Override public void appendSuffix(final String text) { appendSuffixSelected(text); } @Override public void preappendPrefix(final String text) { preappendPrefixSelected(text); } }); this.matchingList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent event) { if (!event.getValueIsAdjusting()) { matchingListSelected(event); } } }); this.matchingList.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { matchingListTableChanged(e); } }); }
From source file:org.n52.ifgicopter.spf.output.GpxOutputPlugin.java
/** * /*from ww w. j a v a2 s. c om*/ * @return */ private JPanel makeGUI() { if (this.panel == null) { this.panel = new JPanel(new BorderLayout()); JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); JButton selectFileButton = new JButton(SELECT_GPX_FILE_TEXT); selectFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectGpxFileAction(); } }); controlPanel.add(selectFileButton); this.outputFileLabel = new JLabel(); controlPanel.add(this.outputFileLabel); JButton saveFileButton = new JButton(SAVE_CURRENT_FILE_TEXT); saveFileButton.setToolTipText("Does also save manual changes undless model changes were made."); saveFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { saveCurrentFile(); } }); controlPanel.add(saveFileButton); // JCheckBox scrollLockCheckBox = new JCheckBox("scroll lock"); // scrollLockCheckBox.setSelected(true); // scrollLockCheckBox.addActionListener(new ActionListener() { // @Override // public void actionPerformed(final ActionEvent e) { // EventQueue.invokeLater(new Runnable() { // // @Override // public void run() { // JCheckBox source = (JCheckBox) e.getSource(); // // GpxOutputPlugin.this.textPane.setAutoscrolls(source.isSelected()); // } // }); // } // }); // controlPanel.add(scrollLockCheckBox); this.panel.add(controlPanel, BorderLayout.NORTH); JPanel valuesPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); DefaultListModel listModel = new DefaultListModel(); listModel.addElement(NO_DATA_LIST_ELEMENT); this.valuesToSaveList = new JList(listModel); this.valuesToSaveList.setVisibleRowCount(2); this.valuesToSaveList .setToolTipText("Select (multiple) values to include in the GPX file [Multiple using <Ctrl>]."); this.valuesToSaveList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { JList list = (JList) e.getSource(); // DefaultListModel listModel = (DefaultListModel) list.getModel(); Object[] selectedValues = list.getSelectedValues(); log.debug("New selection in value list:" + Arrays.toString(selectedValues)); GpxOutputPlugin.this.valuesToSave.clear(); for (Object o : selectedValues) { if (o instanceof String) { String s = (String) o; if (!GpxOutputPlugin.this.valuesToSave.contains(s)) GpxOutputPlugin.this.valuesToSave.add(s); } } } }); } }); this.valuesToSaveList.setSize(200, 22); this.valuesToSaveList.setAlignmentY(Component.CENTER_ALIGNMENT); valuesPanel.add(new JLabel("Saved attributes:")); valuesPanel.add(this.valuesToSaveList); valuesPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); this.panel.add(valuesPanel, BorderLayout.EAST); this.textPane = new XmlTextPane(); this.textPane.setEditable(true); this.textPane.setFont(Font.getFont(Font.MONOSPACED)); JScrollPane scrollPane = new JScrollPane(this.textPane); this.panel.add(scrollPane, BorderLayout.CENTER); JButton refreshTextFieldButton = new JButton("Update"); refreshTextFieldButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { EventQueue.invokeLater(new Runnable() { @Override public void run() { updateGUI(); } }); } }); this.panel.add(refreshTextFieldButton, BorderLayout.SOUTH); updateGUI(); } return this.panel; }
From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java
/** * Setup Job History Tab Pane/*from w w w . java 2s .c o m*/ * * @return JPanel for History tab */ private JPanel setupHistory() { JPanel historyPanel = new JPanel(); historyPanel.setLayout(new BorderLayout(10, 10)); /* -- Job List -- */ JPanel jobListPanel = new JPanel(); historyPanel.add(jobListPanel, BorderLayout.CENTER); jobListPanel.setLayout(new BorderLayout(10, 10)); jobListPanel.setBorder(BorderFactory.createTitledBorder("Grid Jobs")); final JList jobList = new JList(historyList); JScrollPane jobListScroll = new JScrollPane(jobList); jobListPanel.add(jobListScroll, BorderLayout.CENTER); jobListScroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); jobListScroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); addUIElement("history.joblist", jobList); jobList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jobList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { // Ignore intermediate events if (e.getValueIsAdjusting()) return; displayJobInfo(jobList.getSelectedValue()); } }); JPanel jobInfoPanel = new JPanel(); historyPanel.add(jobInfoPanel, BorderLayout.SOUTH); jobInfoPanel.setLayout(new BorderLayout(10, 10)); jobInfoPanel.setBorder(BorderFactory.createTitledBorder("Job Information")); JPanel centerPanel = new JPanel(); jobInfoPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setLayout(new GridLayout(0, 4, 10, 10)); JLabel jobIdLabel = new JLabel("GridJob ID :"); centerPanel.add(jobIdLabel); JLabel jobId = new JLabel("N/A"); centerPanel.add(jobId); addUIElement("history.jobid", jobId); // Add to components map JLabel jobNameLabel = new JLabel("GridJob Name :"); centerPanel.add(jobNameLabel); JLabel jobName = new JLabel("N/A"); centerPanel.add(jobName); addUIElement("history.jobname", jobName); // Add to components map JLabel startTimeLabel = new JLabel("Start Time :"); centerPanel.add(startTimeLabel); JLabel startTime = new JLabel("N/A"); centerPanel.add(startTime); addUIElement("history.starttime", startTime); // Add to components map JLabel durationLabel = new JLabel("Duration :"); centerPanel.add(durationLabel); JLabel duration = new JLabel("N/A"); centerPanel.add(duration); addUIElement("history.duration", duration); // Add to components map JLabel tasksLabel = new JLabel("Tasks Executed :"); centerPanel.add(tasksLabel); JLabel tasks = new JLabel("N/A"); centerPanel.add(tasks); addUIElement("history.tasks", tasks); // Add to components map JLabel failuresLabel = new JLabel("Failures :"); centerPanel.add(failuresLabel); JLabel failures = new JLabel("N/A"); centerPanel.add(failures); addUIElement("history.failures", failures); // Add to components map // Place Holders centerPanel.add(new JLabel()); centerPanel.add(new JLabel()); return historyPanel; }
From source file:org.nekorp.workflow.desktop.view.DatosClienteView.java
@Override public void iniciaVista() { initComponents();/*from ww w.j a va2 s .c o m*/ bindComponents(); searchModel = new ClienteSearchJListModel(); search.setModel(searchModel); //esto resuelve el problema de regresar el foco a la caja de texto. search.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (search.hasFocus()) { nombreCliente.requestFocus(); } } }); this.nombreCliente.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { actualizarNombreCliente(); } @Override public void removeUpdate(DocumentEvent e) { actualizarNombreCliente(); } @Override public void changedUpdate(DocumentEvent e) { actualizarNombreCliente(); } }); this.cancelIcon.add(iconProvider.getIcon(cancelSearchIconRaw)); this.searchIcon.add(iconProvider.getIcon(searchIconRaw)); }
From source file:org.nuclos.client.layout.wysiwyg.editor.ui.panels.WYSIWYGMetaInformationPicker.java
/** * //from www .jav a 2 s .co m * @param values * @param parent */ private WYSIWYGMetaInformationPicker(Window owner, List<String> values, TableLayoutPanel parent) { super(owner); this.setIconImage(NuclosIcons.getInstance().getScaledDialogIcon(48).getImage()); Container contentPane = this.getContentPane(); contentPane.setLayout(new TableLayout(layoutDefinition)); originalValues = values; filter = new JTextField(); /** the keybinding*/ filter.addKeyListener(new KeyListener() { @Override public void keyPressed(KeyEvent e) { } @Override public void keyReleased(KeyEvent e) { /** up and down cursor for selecting the next or previous entry */ if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) { int selectedItem = itemList.getSelectedIndex(); if (e.getKeyCode() == KeyEvent.VK_UP) selectedItem--; else if (e.getKeyCode() == KeyEvent.VK_DOWN) selectedItem++; if (selectedItem < 0) { selectedItem = listModel.getSize() - 1; } else if (selectedItem == listModel.getSize()) { selectedItem = 0; } itemList.setSelectedIndex(selectedItem); itemList.ensureIndexIsVisible(selectedItem); } else if (e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_ESCAPE) { /** enter for saving, esc for cancel */ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) selectedEntity = null; dispose(); } else { /** every other key is used for filtering the entries */ filterItems(WYSIWYGMetaInformationPicker.this.filter.getText()); } } @Override public void keyTyped(KeyEvent e) { } }); /** request focus in the filter window */ filter.requestFocusInWindow(); this.add(filter, new TableLayoutConstraints(1, 1, 3, 1)); itemList = new JList(listModel); itemList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); itemList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (itemList.getSelectedValue() != null) selectedEntity = (String) itemList.getSelectedValue(); } }); freeExpr = new JCheckBox(SpringLocaleDelegate.getInstance() .getMessageFromResource("wysiwg.metainformation.picker.freeexpr")); this.add(freeExpr, new TableLayoutConstraints(1, 2, 3, 2)); freeExpr.setVisible(true); // double click on item to select itemList.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { performSaveAction(); } } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } }); filterItems(null); JScrollPane scrollpane = new JScrollPane(itemList); this.add(scrollpane, new TableLayoutConstraints(1, 4, 3, 4)); JButton apply = new JButton(BUTTON_LABELS.LABEL_APPLY); apply.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { performSaveAction(); } }); this.add(apply, new TableLayoutConstraints(1, 6)); JButton cancel = new JButton(BUTTON_LABELS.LABEL_CANCEL); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { performCancelAction(); } }); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { performCancelAction(); } }); this.add(cancel, new TableLayoutConstraints(3, 6)); this.setBounds(this.getBounds().x, this.getBounds().y, 300, 400); this.setTitle(TABLELAYOUT_PANEL.SELECT_FIELD_FOR_METAINFORMATION); this.setModal(true); }
From source file:org.nuclos.client.main.mainframe.workspace.WorkspaceEditor.java
private void initListener() { btSave.addActionListener(new ActionListener() { @Override/*from w w w.ja v a 2s .c o m*/ public void actionPerformed(ActionEvent e) { final String name = tfName.getText().trim(); final boolean hide = chckHide.isSelected(); final boolean hideName = chckHideName.isSelected(); final boolean hideMenuBar = chckHideMenuBar.isSelected(); final boolean alwaysOpenAtLogin = chckAlwaysOpenAtLogin.isSelected(); final boolean useLastFrameSettings = chckUseLastFrameSettings.isSelected(); final boolean alwaysReset = chckAlwaysReset.isSelected(); final String nuclosResource = nuclosIconChooser.getSelectedResourceIconName(); final Map<String, String> parameters = parameterModel.getParameters(); if (StringUtils.looksEmpty(name)) { JOptionPane.showMessageDialog(contentPanel, SpringLocaleDelegate.getInstance() .getMessage("WorkspaceEditor.7", "Bitte geben Sie einen Namen an")); } else { wovo.setName(name); wovo.getWoDesc().setHide(hide); wovo.getWoDesc().setHideName(hideName); wovo.getWoDesc().setHideMenuBar(hideMenuBar); wovo.getWoDesc().setAlwaysOpenAtLogin(alwaysOpenAtLogin); wovo.getWoDesc().setUseLastFrameSettings(useLastFrameSettings); wovo.getWoDesc().setAlwaysReset(alwaysReset); wovo.getWoDesc().setNuclosResource(nuclosResource); wovo.getWoDesc().removeAllParameters(); wovo.getWoDesc().setAllParameters(parameters); saved = true; dialog.dispose(); } } }); btCancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); jtbParameter.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { btRemoveParameter.setEnabled(jtbParameter.getSelectedRow() != -1); } }); }
From source file:org.nuclos.client.ui.collect.result.ResultController.java
private ListSelectionListener newListSelectionListener(final JTable tblResult) { return new ListSelectionListener() { @Override//from www.jav a 2s. com public void valueChanged(ListSelectionEvent ev) { try { final ListSelectionModel lsm = (ListSelectionModel) ev.getSource(); final CollectStateModel<?> clctstatemodel = clctctl.getCollectStateModel(); if (clctstatemodel.getOuterState() == CollectState.OUTERSTATE_RESULT) { final int iResultMode = CollectStateModel.getResultModeFromSelectionModel(lsm); if (iResultMode != clctctl.getCollectStateModel().getResultMode()) { clctctl.setCollectState(CollectState.OUTERSTATE_RESULT, iResultMode); } } if (!ev.getValueIsAdjusting()) { // Autoscroll selection. It's okay to do that here rather than in the CollectStateListener. if (!lsm.isSelectionEmpty() && tblResult.getAutoscrolls()) { // ensure that the last selected row is visible: final int iRowIndex = lsm.getLeadSelectionIndex(); final int iColIndex = tblResult.getSelectedColumn(); final Rectangle rectCell = tblResult.getCellRect(iRowIndex, iColIndex != -1 ? iColIndex : 0, true); if (rectCell != null) { tblResult.scrollRectToVisible(rectCell); } } } } catch (CommonBusinessException ex) { Errors.getInstance().showExceptionDialog(clctctl.getTab(), ex); } } // valueChanged }; }
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 w w .j a va 2 s . c o m*/ * @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.scripting.ScriptingWindow.java
private void initWindowLayout() { // set default size and position frame.setBounds(50, 80, 1150, 650);/*w w w .j a v a 2s . co m*/ StaticUIUtils.persistGeometry(frame, Preferences.SCRIPTWINDOW_GEOMETRY_PREFIX); frame.getContentPane().setLayout(new BorderLayout(0, 0)); m_scriptList = new JList<>(); JScrollPane scrollPaneList = new JScrollPane(m_scriptList); m_scriptList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { onListSelectionChanged(); } } }); m_scriptList.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { ListModel<ScriptItem> lm = m_scriptList.getModel(); int index = m_scriptList.locationToIndex(e.getPoint()); if (index > -1) { m_scriptList.setToolTipText(lm.getElementAt(index).getFile().getName()); } } }); m_txtResult = new JEditorPane(); JScrollPane scrollPaneResults = new JScrollPane(m_txtResult); //m_txtScriptEditor = new StandardScriptEditor(); m_txtScriptEditor = getScriptEditor(); m_txtScriptEditor.initLayout(this); JSplitPane splitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, m_txtScriptEditor.getPanel(), scrollPaneResults); splitPane1.setOneTouchExpandable(true); splitPane1.setDividerLocation(430); Dimension minimumSize1 = new Dimension(100, 50); //scrollPaneEditor.setMinimumSize(minimumSize1); scrollPaneResults.setMinimumSize(minimumSize1); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPaneList, splitPane1); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(250); Dimension minimumSize = new Dimension(100, 50); scrollPaneList.setMinimumSize(minimumSize); scrollPaneResults.setMinimumSize(minimumSize); frame.getContentPane().add(splitPane, BorderLayout.CENTER); JPanel panelSouth = new JPanel(); FlowLayout fl_panelSouth = (FlowLayout) panelSouth.getLayout(); fl_panelSouth.setAlignment(FlowLayout.LEFT); frame.getContentPane().add(panelSouth, BorderLayout.SOUTH); setupRunButtons(panelSouth); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setJMenuBar(createMenuBar()); }