List of usage examples for javax.swing JPopupMenu getPreferredSize
@Transient
public Dimension getPreferredSize()
preferredSize
has been set to a non-null
value just returns it. From source file:Main.java
public static void showPopupMenu(final JPopupMenu popup, final Component component, int x, int y) { final Point p = new Point(x, y); SwingUtilities.convertPointToScreen(p, component); final Dimension size = popup.getPreferredSize(); final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); boolean horiz = false; boolean vert = false; final int origX = x; if ((p.x + size.width > screen.width) && (size.width < screen.width)) { x += (screen.width - p.x - size.width); horiz = true;/*from w w w . j a v a 2 s.c o m*/ } if ((p.y + size.height > screen.height) && (size.height < screen.height)) { y += (screen.height - p.y - size.height); vert = true; } if (horiz && vert) { x = origX - size.width - 2; } popup.show(component, x, y); }
From source file:com.mirth.connect.client.ui.components.MirthTable.java
public MirthTable(String prefix, Set<String> defaultVisibleColumns) { super();/*w w w. j a v a 2s.co m*/ this.prefix = prefix; this.defaultVisibleColumns = defaultVisibleColumns; userPreferences = Preferences.userNodeForPackage(Mirth.class); columnOrderMap = new HashMap<String, Integer>(); if (StringUtils.isNotEmpty(prefix)) { try { userPreferences = Preferences.userNodeForPackage(Mirth.class); String columns = userPreferences.get(prefix + "ColumnOrderMap", ""); if (StringUtils.isNotEmpty(columns)) { columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns, Map.class); } } catch (Exception e) { } sortKeys = new ArrayList<SortKey>(); try { String sortOrder = userPreferences.get(prefix + "SortOrder", ""); if (StringUtils.isNotEmpty(sortOrder)) { sortKeys = ObjectXMLSerializer.getInstance().deserialize(sortOrder, List.class); } } catch (Exception e) { } } setDragEnabled(true); addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { boolean isAccelerated = (((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0) || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0)); if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) { PlatformUI.MIRTH_FRAME.doContextSensitiveSave(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); /* * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can * override it. */ putClientProperty("terminateEditOnFocusLost", Boolean.FALSE); getTableHeader().addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { saveColumnOrder(); } }); final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon()); columnControlButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPopupMenu columnMenu = getColumnMenu(); Dimension buttonSize = columnControlButton.getSize(); int xPos = columnControlButton.getComponentOrientation().isLeftToRight() ? buttonSize.width - columnMenu.getPreferredSize().width : 0; columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight()); } }); setColumnControl(columnControlButton); }
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
public MirthTreeTable(String prefix, Set<String> defaultVisibleColumns) { customHiddenColumnMap = new HashMap<String, Set<String>>(); this.prefix = prefix; this.defaultVisibleColumns = defaultVisibleColumns; columnOrderMap = new HashMap<String, Integer>(); sortOrderColumn = -1;//from w ww . j a va2s . c om sortOrder = null; if (StringUtils.isNotEmpty(prefix)) { try { userPreferences = Preferences.userNodeForPackage(Mirth.class); String columns = userPreferences.get(prefix + "ColumnOrderMap", ""); if (StringUtils.isNotEmpty(columns)) { columnOrderMap = (Map<String, Integer>) ObjectXMLSerializer.getInstance().deserialize(columns, Map.class); } } catch (Exception e) { } try { String order = userPreferences.get(prefix + "SortOrder", ""); if (StringUtils.isNotEmpty(order)) { sortOrder = ObjectXMLSerializer.getInstance().deserialize(order, SortOrder.class); sortOrderColumn = userPreferences.getInt(prefix + "SortOrderColumn", -1); } } catch (Exception e) { } } addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { boolean isAccelerated = (((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) > 0) || ((e.getModifiers() & InputEvent.CTRL_MASK) > 0)); if ((e.getKeyCode() == KeyEvent.VK_S) && isAccelerated) { PlatformUI.MIRTH_FRAME.doContextSensitiveSave(); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } }); /* * Swingx 1.0 has this set to true by default, which doesn't allow dragging and dropping * into tables. Swingx 0.8 had this set to false. Tables that want it set to true can * override it. */ putClientProperty("terminateEditOnFocusLost", Boolean.FALSE); JTableHeader header = getTableHeader(); header.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { saveColumnOrder(); } }); header.setDefaultRenderer(new SortableHeaderCellRenderer(header.getDefaultRenderer())); final JButton columnControlButton = new JButton(new ColumnControlButton(this).getIcon()); columnControlButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPopupMenu columnMenu = getColumnMenu(); Dimension buttonSize = columnControlButton.getSize(); int xPos = columnControlButton.getComponentOrientation().isLeftToRight() ? buttonSize.width - columnMenu.getPreferredSize().width : 0; columnMenu.show(columnControlButton, xPos, columnControlButton.getHeight()); } }); setColumnControl(columnControlButton); }
From source file:org.datacleaner.windows.AnalysisJobBuilderWindowImpl.java
private JComponent getWindowPanelContent() { if (_datastore != null) { setDatastore(_datastore);// w ww . j a v a 2s .co m } final SaveAnalysisJobActionListener saveAnalysisJobActionListener = _saveAnalysisJobActionListenerProvider .get(); _saveButton.addActionListener(saveAnalysisJobActionListener); _saveAsButton.addActionListener(saveAnalysisJobActionListener); _saveAsButton.setActionCommand(SaveAnalysisJobActionListener.ACTION_COMMAND_SAVE_AS); // Run analysis _executeButton.addActionListener(execute(_analysisJobBuilder)); _executionAlternativesButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JMenuItem executeNormallyMenutItem = WidgetFactory.createMenuItem("Run normally", IconUtils.ACTION_EXECUTE); executeNormallyMenutItem.addActionListener(execute(_analysisJobBuilder)); final JMenuItem executePreviewMenuItem = WidgetFactory.createMenuItem("Run first N records", IconUtils.ACTION_PREVIEW); executePreviewMenuItem.addActionListener(executePreview()); final JMenuItem executeSingleThreadedMenuItem = WidgetFactory.createMenuItem("Run single-threaded", IconUtils.MODEL_ROW); executeSingleThreadedMenuItem.addActionListener(executeSingleThreaded()); final JPopupMenu menu = new JPopupMenu(); menu.add(executeNormallyMenutItem); menu.addSeparator(); menu.add(executePreviewMenuItem); menu.add(executeSingleThreadedMenuItem); final int horizontalPosition = -1 * menu.getPreferredSize().width + _executionAlternativesButton.getWidth(); menu.show(_executionAlternativesButton, horizontalPosition, _executionAlternativesButton.getHeight()); } }); final JButton newJobButton = createToolbarButton("New", IconUtils.MENU_NEW); newJobButton.addActionListener(_newAnalysisJobActionListenerProvider.get()); final JButton openJobButton = createToolbarButton("Open", IconUtils.MENU_OPEN); openJobButton.addActionListener(_openAnalysisJobActionListenerProvider.get()); final JToggleButton moreButton = createMoreMenuButton(); final JButton logoButton = new JButton(imageManager.getImageIcon("images/menu/dc-logo-30.png")); logoButton.setToolTipText("About DataCleaner"); logoButton.setBorder(new EmptyBorder(0, 4, 0, 10)); logoButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { new AboutDialog(getWindowContext()).open(); } }); final JToolBar toolBar = WidgetFactory.createToolBar(); toolBar.add(logoButton); toolBar.add(newJobButton); toolBar.add(openJobButton); toolBar.add(_saveButton); toolBar.add(_saveAsButton); toolBar.add(DCLabel.bright(" | ")); toolBar.add(moreButton); toolBar.add(WidgetFactory.createToolBarSeparator()); toolBar.add(_executeButton); toolBar.add(DCLabel.bright("|")); toolBar.add(_executionAlternativesButton); final JXStatusBar statusBar = WidgetFactory.createStatusBar(_statusLabel); statusBar.add(_classicViewButton); statusBar.add(_graphViewButton); statusBar.add(Box.createHorizontalStrut(10)); final LicenceAndEditionStatusLabel statusLabel = new LicenceAndEditionStatusLabel(_glassPane); statusBar.add(statusLabel); final DCPanel toolBarPanel = new DCPanel(WidgetUtils.BG_COLOR_DARK); toolBarPanel.setLayout(new BorderLayout()); toolBarPanel.add(toolBar, BorderLayout.CENTER); final DCPanel panel = new DCPersistentSizedPanel(_windowSizePreference); panel.setLayout(new BorderLayout()); panel.add(toolBarPanel, BorderLayout.NORTH); panel.add(_leftPanel, BorderLayout.WEST); // newPanel.add(_tabbedPane, BorderLayout.NORTH); panel.add(_contentContainerPanel, BorderLayout.CENTER); panel.add(statusBar, BorderLayout.SOUTH); // invoke to trigger enablement/disablement of buttons. onSourceColumnsChanged(); updateStatusLabel(); WidgetUtils.centerOnScreen(this); return panel; }