List of usage examples for java.awt.event MouseEvent isPopupTrigger
public boolean isPopupTrigger()
From source file:corelyzer.ui.CorelyzerApp.java
public void mousePressed(final MouseEvent e) { // From JDK Doc // Note: Popup menus are triggered differently on different systems. // Therefore, isPopupTrigger should be checked in both mousePressed and // mouseReleased for proper cross-platform functionality. Point p = e.getPoint();/*from w ww. j a va 2s. c om*/ Object actionSource = e.getSource(); if (actionSource instanceof JList) { // find the index of the clicked item in the JList int index = ((JList) e.getSource()).locationToIndex(e.getPoint()); if (index < 0) { return; } // show our popup menu if it was a right/ctrl-click if (e.isPopupTrigger()) { if (actionSource.equals(sessionList)) { Session s = (Session) sessionList.getSelectedValue(); JMenuItem t; // Show label switching if (s == null) { return; } String l = s.isShow() ? "Hide" : "Show"; t = (JMenuItem) sessionPopupMenu.getComponent(0); t.setText(l); sessionPopupMenu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(trackList)) { ((JList) e.getSource()).setSelectedIndex(index); // Update context-aware show/hide TrackSceneNode t = (TrackSceneNode) trackList.getSelectedValue(); if ((t != null) && (t.getId() >= 0)) { boolean isShown = SceneGraph.getTrackShow(t.getId()); String label = isShown ? "Hide" : "Show"; ((JMenuItem) trackPopupMenu.getComponent(0)).setText(label); } trackPopupMenu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(sectionList)) { int[] rows = getSectionList().getSelectedIndices(); JPopupMenu menu = sectionListPopupMenu(rows); menu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(dataFileList)) { ((JList) e.getSource()).setSelectedIndex(index); dataPopupMenu.show(e.getComponent(), p.x, p.y); } } } }
From source file:corelyzer.ui.CorelyzerApp.java
public void mouseReleased(final MouseEvent e) { // From JDK Doc // Note: Popup menus are triggered differently on different systems. // Therefore, isPopupTrigger should be checked in both mousePressed and // mouseReleased for proper cross-platform functionality. Point p = e.getPoint();// w w w. ja v a2 s. c o m Object actionSource = e.getSource(); if (actionSource instanceof JList) { // find the index of the clicked item in the JList int index = ((JList) e.getSource()).locationToIndex(e.getPoint()); if (index < 0) { return; } // show our popup menu if it was a right/ctrl-click if (e.isPopupTrigger()) { if (actionSource.equals(sessionList)) { Session s = (Session) sessionList.getSelectedValue(); JMenuItem t; // Show label switching if (s == null) { return; } String l = s.isShow() ? "Hide" : "Show"; t = (JMenuItem) sessionPopupMenu.getComponent(0); t.setText(l); sessionPopupMenu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(trackList)) { ((JList) e.getSource()).setSelectedIndex(index); // Update context-aware show/hide TrackSceneNode t = (TrackSceneNode) trackList.getSelectedValue(); if ((t != null) && (t.getId() >= 0)) { boolean isShown = SceneGraph.getTrackShow(t.getId()); String label = isShown ? "Hide" : "Show"; ((JMenuItem) trackPopupMenu.getComponent(0)).setText(label); } trackPopupMenu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(sectionList)) { int[] rows = getSectionList().getSelectedIndices(); JPopupMenu menu = sectionListPopupMenu(rows); menu.show(e.getComponent(), p.x, p.y); } else if (actionSource.equals(dataFileList)) { ((JList) e.getSource()).setSelectedIndex(index); dataPopupMenu.show(e.getComponent(), p.x, p.y); } } } }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
protected void initComponent() { layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]"); panel = new JPanel(layout); topPanel = new JPanel(new BorderLayout()); topPanel.setVisible(false);//from w w w . j av a 2s.c om panel.add(topPanel, "growx"); scrollPane = new JScrollPane(impl); impl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); impl.setFillsViewportHeight(true); panel.add(scrollPane, "grow"); impl.setShowGrid(true); impl.setGridColor(Color.lightGray); impl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { handleClickAction(); } } @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } protected void showPopup(MouseEvent e) { if (e.isPopupTrigger() && contextMenuEnabled) { // select row Point p = e.getPoint(); int viewRowIndex = impl.rowAtPoint(p); int rowNumber; if (viewRowIndex >= 0) { rowNumber = impl.convertRowIndexToModel(viewRowIndex); } else { rowNumber = -1; } ListSelectionModel model = impl.getSelectionModel(); if (!model.isSelectedIndex(rowNumber)) { model.setSelectionInterval(rowNumber, rowNumber); } // show popup menu JPopupMenu popupMenu = createPopupMenu(); if (popupMenu.getComponentCount() > 0) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } }); ColumnControlButton columnControlButton = new ColumnControlButton(impl) { @Override protected ColumnVisibilityAction createColumnVisibilityAction(TableColumn column) { ColumnVisibilityAction columnVisibilityAction = super.createColumnVisibilityAction(column); columnVisibilityAction.addPropertyChangeListener(evt -> { if ("SwingSelectedKey".equals(evt.getPropertyName()) && evt.getNewValue() instanceof Boolean) { ColumnVisibilityAction action = (ColumnVisibilityAction) evt.getSource(); String columnName = action.getActionCommand(); boolean collapsed = !((boolean) evt.getNewValue()); Column col = getColumn(columnName); if (col != null) { col.setCollapsed(collapsed); } } }); return columnVisibilityAction; } }; impl.setColumnControl(columnControlButton); impl.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); impl.getActionMap().put("enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (enterPressAction != null) { enterPressAction.actionPerform(DesktopAbstractTable.this); } else { handleClickAction(); } } }); Messages messages = AppBeans.get(Messages.NAME); // localize default column control actions for (Object actionKey : impl.getActionMap().allKeys()) { if ("column.packAll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packAll")); } else if ("column.packSelected".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packSelected")); } else if ("column.horizontalScroll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.horizontalScroll")); } } // Ability to configure fonts in table // Add action to column control String configureFontsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.configureFontsLabel"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "fonts", new AbstractAction(configureFontsLabel) { @Override public void actionPerformed(ActionEvent e) { Component rootComponent = SwingUtilities.getRoot(impl); final FontDialog fontDialog = FontDialog.show(rootComponent, impl.getFont()); fontDialog.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { Font result = fontDialog.getResult(); if (result != null) { impl.setFont(result); packRows(); } } }); fontDialog.open(); } }); // Ability to reset settings String resetSettingsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.resetSettings"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "resetSettings", new AbstractAction(resetSettingsLabel) { @Override public void actionPerformed(ActionEvent e) { resetPresentation(); } }); scrollPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (!columnsInitialized) { adjustColumnHeaders(); } columnsInitialized = true; } }); // init default row height SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (!fontInitialized) { applyFont(impl, impl.getFont()); } } }); }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java
/** * Shows the popup menu when the trigger button (right-click) has been pushed. Deselects the * rows if no row was selected./* w w w . ja va2 s .co m*/ */ private void checkMessageSelectionAndPopupMenu(java.awt.event.MouseEvent evt) { int row = messageTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row == -1) { deselectRows(); } if (evt.isPopupTrigger()) { if (row != -1) { messageTreeTable.setRowSelectionInterval(row, row); } parent.messagePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } }
From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowser.java
/** * Shows the popup menu when the trigger button (right-click) has been pushed. Deselects the * rows if no row was selected./*from w w w .jav a 2 s . c om*/ */ private void checkAttachmentSelectionAndPopupMenu(java.awt.event.MouseEvent evt) { int row = attachmentTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row == -1) { deselectAttachmentRows(); } if (evt.isPopupTrigger()) { if (row != -1) { attachmentTable.setRowSelectionInterval(row, row); } attachmentPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } }
From source file:com.actelion.research.table.view.JVisualization.java
private boolean handlePopupTrigger(MouseEvent e) { if (e.isPopupTrigger()) showPopupMenu();//from w w w. jav a 2s . c o m return false; }
From source file:com.mirth.connect.client.ui.ChannelSetup.java
/** * Shows the trigger-button popup menu.//w w w . j ava 2s. c o m */ private void showChannelEditPopupMenu(java.awt.event.MouseEvent evt) { if (evt.isPopupTrigger()) { parent.channelEditPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } }
From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplatePanel.java
private void initComponents() { splitPane = new JSplitPane(); splitPane.setBackground(getBackground()); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setBorder(BorderFactory.createEmptyBorder()); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(//from w ww . j av a 2 s.c o m Preferences.userNodeForPackage(Mirth.class).getInt("height", UIConstants.MIRTH_HEIGHT) / 3); splitPane.setResizeWeight(0.5); topPanel = new JPanel(); topPanel.setBackground(UIConstants.COMBO_BOX_BACKGROUND); final CodeTemplateTreeTableCellEditor templateCellEditor = new CodeTemplateTreeTableCellEditor(this); templateTreeTable = new MirthTreeTable("CodeTemplate", new HashSet<String>( Arrays.asList(new String[] { "Name", "Description", "Revision", "Last Modified" }))) { private TreeTableNode selectedNode; @Override public boolean isCellEditable(int row, int column) { return column == TEMPLATE_NAME_COLUMN; } @Override public TableCellEditor getCellEditor(int row, int column) { if (isHierarchical(column)) { return templateCellEditor; } else { return super.getCellEditor(row, column); } } @Override protected void beforeSort() { updateCurrentNode(); updateCurrentNode.set(false); int selectedRow = templateTreeTable.getSelectedRow(); selectedNode = selectedRow >= 0 ? (TreeTableNode) templateTreeTable.getPathForRow(selectedRow).getLastPathComponent() : null; } @Override protected void afterSort() { final TreePath selectedPath = selectPathFromNodeId(selectedNode, (CodeTemplateRootTreeTableNode) templateTreeTable.getTreeTableModel().getRoot()); if (selectedPath != null) { selectTemplatePath(selectedPath); } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (selectedPath != null) { selectTemplatePath(selectedPath); } updateCurrentNode.set(true); } }); } }; DefaultTreeTableModel model = new CodeTemplateTreeTableModel(); model.setColumnIdentifiers( Arrays.asList(new String[] { "Name", "Id", "Type", "Description", "Revision", "Last Modified" })); CodeTemplateRootTreeTableNode rootNode = new CodeTemplateRootTreeTableNode(); model.setRoot(rootNode); fullModel = new CodeTemplateTreeTableModel(); fullModel.setColumnIdentifiers( Arrays.asList(new String[] { "Name", "Id", "Type", "Description", "Revision", "Last Modified" })); CodeTemplateRootTreeTableNode fullRootNode = new CodeTemplateRootTreeTableNode(); fullModel.setRoot(fullRootNode); templateTreeTable.setColumnFactory(new CodeTemplateTableColumnFactory()); templateTreeTable.setTreeTableModel(model); templateTreeTable.setOpenIcon(null); templateTreeTable.setClosedIcon(null); templateTreeTable.setLeafIcon(null); templateTreeTable.setRootVisible(false); templateTreeTable.setDoubleBuffered(true); templateTreeTable.setDragEnabled(false); templateTreeTable.setRowSelectionAllowed(true); templateTreeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); templateTreeTable.setRowHeight(UIConstants.ROW_HEIGHT); templateTreeTable.setFocusable(true); templateTreeTable.setOpaque(true); templateTreeTable.getTableHeader().setReorderingAllowed(true); templateTreeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); templateTreeTable.setEditable(true); templateTreeTable.setSortable(true); templateTreeTable.setAutoCreateColumnsFromModel(false); templateTreeTable.setShowGrid(true, true); templateTreeTable.restoreColumnPreferences(); templateTreeTable.setMirthColumnControlEnabled(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { templateTreeTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } templateTreeTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { checkSelection(evt); } @Override public void mouseReleased(MouseEvent evt) { checkSelection(evt); } private void checkSelection(MouseEvent evt) { int row = templateTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row < 0) { templateTreeTable.clearSelection(); } if (evt.isPopupTrigger()) { if (row != -1) { if (!templateTreeTable.isRowSelected(row)) { templateTreeTable.setRowSelectionInterval(row, row); } } codeTemplatePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); templateTreeTable.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { TreePath selectedPath = templateTreeTable.getTreeSelectionModel().getSelectionPath(); if (selectedPath != null) { MutableTreeTableNode selectedNode = (MutableTreeTableNode) selectedPath .getLastPathComponent(); if (selectedNode instanceof CodeTemplateLibraryTreeTableNode && codeTemplateTasks .getContentPane().getComponent(TASK_CODE_TEMPLATE_LIBRARY_DELETE).isVisible()) { doDeleteLibrary(); } else if (selectedNode instanceof CodeTemplateTreeTableNode && codeTemplateTasks .getContentPane().getComponent(TASK_CODE_TEMPLATE_DELETE).isVisible()) { doDeleteCodeTemplate(); } } } } }); templateTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting() && !templateTreeTable.getSelectionModel().getValueIsAdjusting()) { int selectedRow = templateTreeTable.getSelectedRow(); boolean saveEnabled = isSaveEnabled(); boolean adjusting = saveAdjusting.getAndSet(true); printTreeTable(); updateCurrentNode(); currentSelectedRow = selectedRow; if (selectedRow < 0) { if (!adjusting) { switchSplitPaneComponent(blankPanel); } } else { TreePath path = templateTreeTable.getPathForRow(selectedRow); if (path != null) { TreeTableNode node = (TreeTableNode) path.getLastPathComponent(); if (node instanceof CodeTemplateLibraryTreeTableNode) { setLibraryProperties((CodeTemplateLibraryTreeTableNode) node); switchSplitPaneComponent(libraryPanel); } else if (node instanceof CodeTemplateTreeTableNode) { setCodeTemplateProperties((CodeTemplateTreeTableNode) node); switchSplitPaneComponent(templatePanel); } } } updateTasks(); setSaveEnabled(saveEnabled); if (!adjusting) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { saveAdjusting.set(false); } }); } } } }); templateTreeTable.addTreeWillExpandListener(new TreeWillExpandListener() { @Override public void treeWillExpand(TreeExpansionEvent event) throws ExpandVetoException { treeExpansionChanged(); } @Override public void treeWillCollapse(TreeExpansionEvent event) throws ExpandVetoException { treeExpansionChanged(); } private void treeExpansionChanged() { updateCurrentNode(); updateCurrentNode.set(false); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { updateCurrentNode.set(true); } }); } }); templateTreeTableScrollPane = new JScrollPane(templateTreeTable); templateTreeTableScrollPane.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, new Color(0x6E6E6E))); templateFilterNotificationLabel = new JLabel(); templateFilterLabel = new JLabel("Filter:"); templateFilterField = new JTextField(); templateFilterField.setToolTipText( "Filters (by name) the code templates and libraries that show up in the table above."); templateFilterField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent evt) { filterChanged(evt); } @Override public void insertUpdate(DocumentEvent evt) { filterChanged(evt); } @Override public void changedUpdate(DocumentEvent evt) { filterChanged(evt); } private void filterChanged(DocumentEvent evt) { try { updateTemplateFilter(evt.getDocument().getText(0, evt.getLength())); } catch (BadLocationException e) { } } }); templateFilterField.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent evt) { updateTemplateFilter(templateFilterField.getText()); } }); blankPanel = new JPanel(); libraryPanel = new JPanel(); libraryPanel.setBackground(splitPane.getBackground()); libraryLeftPanel = new JPanel(); libraryLeftPanel.setBackground(libraryPanel.getBackground()); librarySummaryLabel = new JLabel("Summary:"); librarySummaryValue = new JLabel(); libraryDescriptionLabel = new JLabel("Description:"); libraryDescriptionScrollPane = new MirthRTextScrollPane(null, false, SyntaxConstants.SYNTAX_STYLE_NONE, false); DocumentListener codeChangeListener = new DocumentListener() { @Override public void removeUpdate(DocumentEvent evt) { codeChanged(); } @Override public void insertUpdate(DocumentEvent evt) { codeChanged(); } @Override public void changedUpdate(DocumentEvent evt) { codeChanged(); } private void codeChanged() { if (codeChangeWorker != null) { codeChangeWorker.cancel(true); } int selectedRow = templateTreeTable.getSelectedRow(); if (selectedRow >= 0) { TreePath selectedPath = templateTreeTable.getPathForRow(selectedRow); if (selectedPath != null) { codeChangeWorker = new CodeChangeWorker( (String) ((TreeTableNode) selectedPath.getLastPathComponent()) .getValueAt(TEMPLATE_ID_COLUMN)); codeChangeWorker.execute(); } } } }; libraryDescriptionScrollPane.getDocument().addDocumentListener(codeChangeListener); libraryRightPanel = new JPanel(); libraryRightPanel.setBackground(libraryPanel.getBackground()); libraryChannelsSelectPanel = new JPanel(); libraryChannelsSelectPanel.setBackground(libraryRightPanel.getBackground()); libraryChannelsLabel = new JLabel("<html><b>Channels</b></html>"); libraryChannelsLabel.setForeground(new Color(64, 64, 64)); libraryChannelsSelectAllLabel = new JLabel("<html><u>Select All</u></html>"); libraryChannelsSelectAllLabel.setForeground(Color.BLUE); libraryChannelsSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); libraryChannelsSelectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { if (evt.getComponent().isEnabled()) { for (int row = 0; row < libraryChannelsTable.getRowCount(); row++) { ChannelInfo channelInfo = (ChannelInfo) libraryChannelsTable.getValueAt(row, LIBRARY_CHANNELS_NAME_COLUMN); channelInfo.setEnabled(true); libraryChannelsTable.setValueAt(channelInfo, row, LIBRARY_CHANNELS_NAME_COLUMN); } setSaveEnabled(true); } } }); libraryChannelsDeselectAllLabel = new JLabel("<html><u>Deselect All</u></html>"); libraryChannelsDeselectAllLabel.setForeground(Color.BLUE); libraryChannelsDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); libraryChannelsDeselectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { if (evt.getComponent().isEnabled()) { for (int row = 0; row < libraryChannelsTable.getRowCount(); row++) { ChannelInfo channelInfo = (ChannelInfo) libraryChannelsTable.getValueAt(row, LIBRARY_CHANNELS_NAME_COLUMN); channelInfo.setEnabled(false); libraryChannelsTable.setValueAt(channelInfo, row, LIBRARY_CHANNELS_NAME_COLUMN); } setSaveEnabled(true); } } }); libraryChannelsFilterLabel = new JLabel("Filter:"); libraryChannelsFilterField = new JTextField(); libraryChannelsFilterField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent evt) { libraryChannelsTable.getRowSorter().allRowsChanged(); } @Override public void insertUpdate(DocumentEvent evt) { libraryChannelsTable.getRowSorter().allRowsChanged(); } @Override public void changedUpdate(DocumentEvent evt) { libraryChannelsTable.getRowSorter().allRowsChanged(); } }); libraryChannelsTable = new MirthTable(); libraryChannelsTable.setModel(new RefreshTableModel(new Object[] { "Name", "Id" }, 0)); libraryChannelsTable.setDragEnabled(false); libraryChannelsTable.setRowSelectionAllowed(false); libraryChannelsTable.setRowHeight(UIConstants.ROW_HEIGHT); libraryChannelsTable.setFocusable(false); libraryChannelsTable.setOpaque(true); libraryChannelsTable.getTableHeader().setReorderingAllowed(false); libraryChannelsTable.setEditable(true); OffsetRowSorter libraryChannelsRowSorter = new OffsetRowSorter(libraryChannelsTable.getModel(), 1); libraryChannelsRowSorter.setRowFilter(new RowFilter<TableModel, Integer>() { @Override public boolean include(Entry<? extends TableModel, ? extends Integer> entry) { String name = entry.getStringValue(LIBRARY_CHANNELS_NAME_COLUMN); return name.equals(NEW_CHANNELS) || StringUtils.containsIgnoreCase(name, StringUtils.trim(libraryChannelsFilterField.getText())); } }); libraryChannelsTable.setRowSorter(libraryChannelsRowSorter); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { libraryChannelsTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_NAME_COLUMN) .setCellRenderer(new ChannelsTableCellRenderer()); libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_NAME_COLUMN) .setCellEditor(new ChannelsTableCellEditor()); // Hide ID column libraryChannelsTable.getColumnExt(LIBRARY_CHANNELS_ID_COLUMN).setVisible(false); libraryChannelsScrollPane = new JScrollPane(libraryChannelsTable); templatePanel = new JPanel(); templatePanel.setBackground(splitPane.getBackground()); templateLeftPanel = new JPanel(); templateLeftPanel.setBackground(templatePanel.getBackground()); templateLibraryLabel = new JLabel("Library:"); templateLibraryComboBox = new JComboBox<String>(); templateLibraryComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { libraryComboBoxActionPerformed(); } }); templateTypeLabel = new JLabel("Type:"); templateTypeComboBox = new JComboBox<CodeTemplateType>(CodeTemplateType.values()); templateTypeComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { setSaveEnabled(true); } }); templateCodeLabel = new JLabel("Code:"); templateCodeTextArea = new MirthRTextScrollPane(ContextType.GLOBAL_DEPLOY); templateCodeTextArea.getDocument().addDocumentListener(codeChangeListener); templateAutoGenerateDocumentationButton = new JButton("Update JSDoc"); templateAutoGenerateDocumentationButton.setToolTipText( "<html>Generates/updates a JSDoc at the beginning of your<br/>code, with parameter/return annotations as needed.</html>"); templateAutoGenerateDocumentationButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String currentText = templateCodeTextArea.getText(); String newText = CodeTemplateUtil.updateCode(templateCodeTextArea.getText()); templateCodeTextArea.setText(newText, false); if (!currentText.equals(newText)) { setSaveEnabled(true); } } }); templateRightPanel = new JPanel(); templateRightPanel.setBackground(templatePanel.getBackground()); templateContextSelectPanel = new JPanel(); templateContextSelectPanel.setBackground(templateRightPanel.getBackground()); templateContextLabel = new JLabel("<html><b>Context</b></html>"); templateContextLabel.setForeground(new Color(64, 64, 64)); templateContextSelectAllLabel = new JLabel("<html><u>Select All</u></html>"); templateContextSelectAllLabel.setForeground(Color.BLUE); templateContextSelectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); templateContextSelectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { TreeTableNode root = (TreeTableNode) templateContextTreeTable.getTreeTableModel().getRoot(); for (Enumeration<? extends TreeTableNode> groups = root.children(); groups.hasMoreElements();) { TreeTableNode group = groups.nextElement(); ((MutablePair<Integer, String>) group.getUserObject()).setLeft(MirthTriStateCheckBox.CHECKED); for (Enumeration<? extends TreeTableNode> children = group.children(); children .hasMoreElements();) { ((MutablePair<Integer, String>) children.nextElement().getUserObject()) .setLeft(MirthTriStateCheckBox.CHECKED); } } templateContextTreeTable.updateUI(); setSaveEnabled(true); } }); templateContextDeselectAllLabel = new JLabel("<html><u>Deselect All</u></html>"); templateContextDeselectAllLabel.setForeground(Color.BLUE); templateContextDeselectAllLabel.setCursor(new Cursor(Cursor.HAND_CURSOR)); templateContextDeselectAllLabel.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent evt) { TreeTableNode root = (TreeTableNode) templateContextTreeTable.getTreeTableModel().getRoot(); for (Enumeration<? extends TreeTableNode> groups = root.children(); groups.hasMoreElements();) { TreeTableNode group = groups.nextElement(); ((MutablePair<Integer, String>) group.getUserObject()).setLeft(MirthTriStateCheckBox.UNCHECKED); for (Enumeration<? extends TreeTableNode> children = group.children(); children .hasMoreElements();) { ((MutablePair<Integer, String>) children.nextElement().getUserObject()) .setLeft(MirthTriStateCheckBox.UNCHECKED); } } templateContextTreeTable.updateUI(); setSaveEnabled(true); } }); final TableCellEditor contextCellEditor = new ContextTreeTableCellEditor(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { setSaveEnabled(true); } }); templateContextTreeTable = new MirthTreeTable() { @Override public TableCellEditor getCellEditor(int row, int column) { if (isHierarchical(column)) { return contextCellEditor; } else { return super.getCellEditor(row, column); } } }; DefaultMutableTreeTableNode rootContextNode = new DefaultMutableTreeTableNode(); DefaultMutableTreeTableNode globalScriptsNode = new DefaultMutableTreeTableNode( new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Global Scripts")); globalScriptsNode.add(new DefaultMutableTreeTableNode( new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_DEPLOY))); globalScriptsNode.add(new DefaultMutableTreeTableNode( new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_UNDEPLOY))); globalScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_PREPROCESSOR))); globalScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.GLOBAL_POSTPROCESSOR))); rootContextNode.add(globalScriptsNode); DefaultMutableTreeTableNode channelScriptsNode = new DefaultMutableTreeTableNode( new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Channel Scripts")); channelScriptsNode.add(new DefaultMutableTreeTableNode( new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_DEPLOY))); channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_UNDEPLOY))); channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_PREPROCESSOR))); channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_POSTPROCESSOR))); channelScriptsNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_ATTACHMENT))); channelScriptsNode.add(new DefaultMutableTreeTableNode( new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.CHANNEL_BATCH))); rootContextNode.add(channelScriptsNode); DefaultMutableTreeTableNode sourceConnectorNode = new DefaultMutableTreeTableNode( new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Source Connector")); sourceConnectorNode.add(new DefaultMutableTreeTableNode( new MutablePair<Integer, ContextType>(MirthTriStateCheckBox.CHECKED, ContextType.SOURCE_RECEIVER))); sourceConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.SOURCE_FILTER_TRANSFORMER))); rootContextNode.add(sourceConnectorNode); DefaultMutableTreeTableNode destinationConnectorNode = new DefaultMutableTreeTableNode( new MutablePair<Integer, String>(MirthTriStateCheckBox.CHECKED, "Destination Connector")); destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_FILTER_TRANSFORMER))); destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_DISPATCHER))); destinationConnectorNode.add(new DefaultMutableTreeTableNode(new MutablePair<Integer, ContextType>( MirthTriStateCheckBox.CHECKED, ContextType.DESTINATION_RESPONSE_TRANSFORMER))); rootContextNode.add(destinationConnectorNode); DefaultTreeTableModel contextModel = new SortableTreeTableModel(rootContextNode); contextModel.setColumnIdentifiers(Arrays.asList(new String[] { "Context" })); templateContextTreeTable.setTreeTableModel(contextModel); templateContextTreeTable.setRootVisible(false); templateContextTreeTable.setDragEnabled(false); templateContextTreeTable.setRowSelectionAllowed(false); templateContextTreeTable.setRowHeight(UIConstants.ROW_HEIGHT); templateContextTreeTable.setFocusable(false); templateContextTreeTable.setOpaque(true); templateContextTreeTable.getTableHeader().setReorderingAllowed(false); templateContextTreeTable.setEditable(true); templateContextTreeTable.setSortable(false); templateContextTreeTable.setShowGrid(true, true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { templateContextTreeTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } templateContextTreeTable.setTreeCellRenderer(new ContextTreeTableCellRenderer()); templateContextTreeTable.setOpenIcon(null); templateContextTreeTable.setClosedIcon(null); templateContextTreeTable.setLeafIcon(null); templateContextTreeTable.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent evt) { checkSelection(evt); } @Override public void mouseReleased(MouseEvent evt) { checkSelection(evt); } private void checkSelection(MouseEvent evt) { if (templateContextTreeTable.rowAtPoint(new Point(evt.getX(), evt.getY())) < 0) { templateContextTreeTable.clearSelection(); } } }); templateContextTreeTable.getTreeTableModel().addTreeModelListener(new TreeModelListener() { @Override public void treeNodesChanged(TreeModelEvent evt) { if (ArrayUtils.isNotEmpty(evt.getChildren())) { TreeTableNode node = (TreeTableNode) evt.getChildren()[0]; if (evt.getTreePath().getPathCount() == 2) { boolean allChildren = true; boolean noChildren = true; for (Enumeration<? extends TreeTableNode> children = node.getParent().children(); children .hasMoreElements();) { TreeTableNode child = children.nextElement(); if (((Pair<Integer, ContextType>) child.getUserObject()) .getLeft() == MirthTriStateCheckBox.UNCHECKED) { allChildren = false; } else { noChildren = false; } } int value; if (allChildren) { value = MirthTriStateCheckBox.CHECKED; } else if (noChildren) { value = MirthTriStateCheckBox.UNCHECKED; } else { value = MirthTriStateCheckBox.PARTIAL; } ((MutablePair<Integer, String>) node.getParent().getUserObject()).setLeft(value); } else if (evt.getTreePath().getPathCount() == 1) { int value = ((Pair<Integer, String>) node.getUserObject()).getLeft(); for (Enumeration<? extends TreeTableNode> children = node.children(); children .hasMoreElements();) { ((MutablePair<Integer, ContextType>) children.nextElement().getUserObject()) .setLeft(value); } } } } @Override public void treeNodesInserted(TreeModelEvent evt) { } @Override public void treeNodesRemoved(TreeModelEvent evt) { } @Override public void treeStructureChanged(TreeModelEvent evt) { } }); templateContextTreeTableScrollPane = new JScrollPane(templateContextTreeTable); }
From source file:com.mirth.connect.client.ui.ChannelSetup.java
/** * Shows the popup menu when the trigger button (right-click) has been pushed. *//*www . ja va2s . c o m*/ private void checkSelectionAndPopupMenu(java.awt.event.MouseEvent evt) { int row = destinationTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (evt.isPopupTrigger()) { if (row != -1) { destinationTable.setRowSelectionInterval(row, row); } showChannelEditPopupMenu(evt); } }
From source file:com.mirth.connect.client.ui.ChannelPanel.java
/** * Shows the popup menu when the trigger button (right-click) has been pushed. Deselects the * rows if no row was selected.//from w w w. j ava2s. c om */ private void checkSelectionAndPopupMenu(MouseEvent evt) { int row = channelTable.rowAtPoint(new Point(evt.getX(), evt.getY())); if (row == -1) { deselectRows(); } if (evt.isPopupTrigger()) { if (row != -1) { if (!channelTable.isRowSelected(row)) { channelTable.setRowSelectionInterval(row, row); } if (((AbstractChannelTableNode) channelTable.getPathForRow(row).getLastPathComponent()) .isGroupNode()) { groupPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } else { channelPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } } else { channelPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }