List of usage examples for javax.swing JMenuItem addActionListener
public void addActionListener(ActionListener l)
ActionListener
to the button. From source file:org.tsho.dmc2.core.chart.jfree.DmcChartPanel.java
/** * Creates a popup menu for the panel.// w w w. j a v a 2 s . com * * @param properties include a menu item for the chart property editor. * @param save include a menu item for saving the chart. * @param print include a menu item for printing the chart. * @param zoom include menu items for zooming. * * @return The popup menu. */ protected JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom) { JPopupMenu result = new JPopupMenu("Chart:"); boolean separator = false; if (properties) { JMenuItem propertiesItem = new JMenuItem(localizationResources.getString("Properties...")); propertiesItem.setActionCommand(PROPERTIES_ACTION_COMMAND); propertiesItem.addActionListener(this); result.add(propertiesItem); separator = true; } if (save) { if (separator) { result.addSeparator(); separator = false; } JMenuItem saveItem = new JMenuItem(localizationResources.getString("Save_as...")); saveItem.setActionCommand(SAVE_ACTION_COMMAND); saveItem.addActionListener(this); result.add(saveItem); separator = true; } if (print) { if (separator) { result.addSeparator(); separator = false; } JMenuItem printItem = new JMenuItem(localizationResources.getString("Print...")); printItem.setActionCommand(PRINT_ACTION_COMMAND); printItem.addActionListener(this); result.add(printItem); separator = true; } if (zoom) { if (separator) { result.addSeparator(); separator = false; } JMenu zoomInMenu = new JMenu(localizationResources.getString("Zoom_In")); zoomInBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); zoomInBothMenuItem.setActionCommand(ZOOM_IN_BOTH_ACTION_COMMAND); zoomInBothMenuItem.addActionListener(this); zoomInMenu.add(zoomInBothMenuItem); zoomInMenu.addSeparator(); zoomInHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis")); zoomInHorizontalMenuItem.setActionCommand(ZOOM_IN_HORIZONTAL_ACTION_COMMAND); zoomInHorizontalMenuItem.addActionListener(this); zoomInMenu.add(zoomInHorizontalMenuItem); zoomInVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis")); zoomInVerticalMenuItem.setActionCommand(ZOOM_IN_VERTICAL_ACTION_COMMAND); zoomInVerticalMenuItem.addActionListener(this); zoomInMenu.add(zoomInVerticalMenuItem); result.add(zoomInMenu); JMenu zoomOutMenu = new JMenu(localizationResources.getString("Zoom_Out")); zoomOutBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); zoomOutBothMenuItem.setActionCommand(ZOOM_OUT_BOTH_ACTION_COMMAND); zoomOutBothMenuItem.addActionListener(this); zoomOutMenu.add(zoomOutBothMenuItem); zoomOutMenu.addSeparator(); zoomOutHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis")); zoomOutHorizontalMenuItem.setActionCommand(ZOOM_OUT_HORIZONTAL_ACTION_COMMAND); zoomOutHorizontalMenuItem.addActionListener(this); zoomOutMenu.add(zoomOutHorizontalMenuItem); zoomOutVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis")); zoomOutVerticalMenuItem.setActionCommand(ZOOM_OUT_VERTICAL_ACTION_COMMAND); zoomOutVerticalMenuItem.addActionListener(this); zoomOutMenu.add(zoomOutVerticalMenuItem); result.add(zoomOutMenu); JMenu autoRangeMenu = new JMenu(localizationResources.getString("Auto_Range")); autoRangeBothMenuItem = new JMenuItem(localizationResources.getString("All_Axes")); autoRangeBothMenuItem.setActionCommand(AUTO_RANGE_BOTH_ACTION_COMMAND); autoRangeBothMenuItem.addActionListener(this); autoRangeMenu.add(autoRangeBothMenuItem); autoRangeMenu.addSeparator(); autoRangeHorizontalMenuItem = new JMenuItem(localizationResources.getString("Horizontal_Axis")); autoRangeHorizontalMenuItem.setActionCommand(AUTO_RANGE_HORIZONTAL_ACTION_COMMAND); autoRangeHorizontalMenuItem.addActionListener(this); autoRangeMenu.add(autoRangeHorizontalMenuItem); autoRangeVerticalMenuItem = new JMenuItem(localizationResources.getString("Vertical_Axis")); autoRangeVerticalMenuItem.setActionCommand(AUTO_RANGE_VERTICAL_ACTION_COMMAND); autoRangeVerticalMenuItem.addActionListener(this); autoRangeMenu.add(autoRangeVerticalMenuItem); result.addSeparator(); result.add(autoRangeMenu); } return result; }
From source file:ca.uhn.hl7v2.testpanel.ui.TestPanelWindow.java
/** * Initialize the contents of the frame. *//*from w ww . j av a 2 s .c om*/ private void initialize() { myframe = new JFrame(); myframe.setVisible(false); List<Image> l = new ArrayList<Image>(); l.add(Toolkit.getDefaultToolkit() .getImage(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/hapi_16.png"))); l.add(Toolkit.getDefaultToolkit() .getImage(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/hapi_64.png"))); myframe.setIconImages(l); myframe.setTitle("HAPI TestPanel"); myframe.setBounds(100, 100, 796, 603); myframe.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); myframe.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent theE) { myController.close(); } }); JMenuBar menuBar = new JMenuBar(); myframe.setJMenuBar(menuBar); JMenu mnFile = new JMenu("File"); mnFile.setMnemonic('f'); menuBar.add(mnFile); JMenuItem mntmExit = new JMenuItem("Exit"); mntmExit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { myController.close(); } }); JMenuItem mntmNewMessage = new JMenuItem("New Message..."); mntmNewMessage.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addMessage(); } }); mntmNewMessage.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/message_hl7.png"))); mnFile.add(mntmNewMessage); mySaveMenuItem = new JMenuItem("Save"); mySaveMenuItem.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mySaveMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doSaveMessages(); } }); mnFile.add(mySaveMenuItem); mySaveAsMenuItem = new JMenuItem("Save As..."); mySaveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doSaveMessagesAs(); } }); mnFile.add(mySaveAsMenuItem); mymenuItem_3 = new JMenuItem("Open"); mymenuItem_3.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); mymenuItem_3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.openMessages(); } }); myRevertToSavedMenuItem = new JMenuItem("Revert to Saved"); myRevertToSavedMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.revertMessage((Hl7V2MessageCollection) myController.getLeftSelectedItem()); } }); mnFile.add(myRevertToSavedMenuItem); mnFile.add(mymenuItem_3); myRecentFilesMenu = new JMenu("Open Recent"); mnFile.add(myRecentFilesMenu); JSeparator separator = new JSeparator(); mnFile.add(separator); mnFile.add(mntmExit); JMenu mnNewMenu = new JMenu("View"); mnNewMenu.setMnemonic('v'); menuBar.add(mnNewMenu); myShowLogConsoleMenuItem = new JMenuItem("Show Log Console"); myShowLogConsoleMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Prefs.getInstance().setShowLogConsole(!Prefs.getInstance().getShowLogConsole()); updateLogScrollPaneVisibility(); myframe.validate(); } }); mnNewMenu.add(myShowLogConsoleMenuItem); mymenu_1 = new JMenu("Test"); menuBar.add(mymenu_1); mymenuItem_1 = new JMenuItem("Populate TestPanel with Sample Message and Connections..."); mymenuItem_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.populateWithSampleMessageAndConnections(); } }); mymenu_1.add(mymenuItem_1); mymenu_3 = new JMenu("Tools"); menuBar.add(mymenu_3); mnHl7V2FileDiff = new JMenuItem("HL7 v2 File Diff..."); mnHl7V2FileDiff.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myHl7V2FileDiff == null) { myHl7V2FileDiff = new Hl7V2FileDiffController(myController); } myHl7V2FileDiff.show(); } }); mymenu_3.add(mnHl7V2FileDiff); mymenuItem_5 = new JMenuItem("HL7 v2 File Sort..."); mymenuItem_5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myHl7V2FileSort == null) { myHl7V2FileSort = new Hl7V2FileSortController(myController); } myHl7V2FileSort.show(); } }); mymenu_3.add(mymenuItem_5); mymenu_2 = new JMenu("Conformance"); menuBar.add(mymenu_2); mymenuItem_2 = new JMenuItem("Profiles and Tables..."); mymenuItem_2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.showProfilesAndTablesEditor(); } }); mymenu_2.add(mymenuItem_2); mymenu = new JMenu("Help"); mymenu.setMnemonic('H'); menuBar.add(mymenu); mymenuItem = new JMenuItem("About HAPI TestPanel..."); mymenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showAboutDialog(); } }); mymenuItem.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/hapi_16.png"))); mymenu.add(mymenuItem); mymenuItem_4 = new JMenuItem("Licenses..."); mymenuItem_4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new LicensesDialog().setVisible(true); } }); mymenu.add(mymenuItem_4); myframe.getContentPane().setLayout(new BorderLayout(0, 0)); JSplitPane outerSplitPane = new JSplitPane(); outerSplitPane.setBorder(null); myframe.getContentPane().add(outerSplitPane); JSplitPane leftSplitPane = new JSplitPane(); leftSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); outerSplitPane.setLeftComponent(leftSplitPane); JPanel messagesPanel = new JPanel(); leftSplitPane.setLeftComponent(messagesPanel); GridBagLayout gbl_messagesPanel = new GridBagLayout(); gbl_messagesPanel.columnWidths = new int[] { 110, 0 }; gbl_messagesPanel.rowHeights = new int[] { 20, 30, 118, 0, 0 }; gbl_messagesPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_messagesPanel.rowWeights = new double[] { 0.0, 0.0, 100.0, 1.0, Double.MIN_VALUE }; messagesPanel.setLayout(gbl_messagesPanel); JLabel lblMessages = new JLabel("Messages"); GridBagConstraints gbc_lblMessages = new GridBagConstraints(); gbc_lblMessages.insets = new Insets(0, 0, 5, 0); gbc_lblMessages.gridx = 0; gbc_lblMessages.gridy = 0; messagesPanel.add(lblMessages, gbc_lblMessages); JToolBar messagesToolBar = new JToolBar(); messagesToolBar.setFloatable(false); messagesToolBar.setRollover(true); messagesToolBar.setAlignmentX(Component.LEFT_ALIGNMENT); GridBagConstraints gbc_messagesToolBar = new GridBagConstraints(); gbc_messagesToolBar.insets = new Insets(0, 0, 5, 0); gbc_messagesToolBar.weightx = 1.0; gbc_messagesToolBar.anchor = GridBagConstraints.NORTHWEST; gbc_messagesToolBar.gridx = 0; gbc_messagesToolBar.gridy = 1; messagesPanel.add(messagesToolBar, gbc_messagesToolBar); JButton msgOpenButton = new JButton(""); msgOpenButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.openMessages(); } }); myAddMessageButton = new JButton(""); myAddMessageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addMessage(); } }); myAddMessageButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/add.png"))); myAddMessageButton.setToolTipText("New Message"); myAddMessageButton.setBorderPainted(false); myAddMessageButton.addMouseListener(new HoverButtonMouseAdapter(myAddMessageButton)); messagesToolBar.add(myAddMessageButton); myDeleteMessageButton = new JButton(""); myDeleteMessageButton.setToolTipText("Close Selected Message"); myDeleteMessageButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.closeMessage((Hl7V2MessageCollection) myController.getLeftSelectedItem()); } }); myDeleteMessageButton.setBorderPainted(false); myDeleteMessageButton.addMouseListener(new HoverButtonMouseAdapter(myDeleteMessageButton)); myDeleteMessageButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/close.png"))); messagesToolBar.add(myDeleteMessageButton); msgOpenButton.setBorderPainted(false); msgOpenButton.setToolTipText("Open Messages from File"); msgOpenButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/open.png"))); msgOpenButton.addMouseListener(new HoverButtonMouseAdapter(msgOpenButton)); messagesToolBar.add(msgOpenButton); myMsgSaveButton = new JButton(""); myMsgSaveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { doSaveMessages(); } }); myMsgSaveButton.setBorderPainted(false); myMsgSaveButton.setToolTipText("Save Selected Messages to File"); myMsgSaveButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/save.png"))); myMsgSaveButton.addMouseListener(new HoverButtonMouseAdapter(myMsgSaveButton)); messagesToolBar.add(myMsgSaveButton); myMessagesList = new JList(); myMessagesList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (myMessagesList.getSelectedIndex() >= 0) { ourLog.debug("New messages selection " + myMessagesList.getSelectedIndex()); myController.setLeftSelectedItem(myMessagesList.getSelectedValue()); myOutboundConnectionsList.clearSelection(); myOutboundConnectionsList.repaint(); myInboundConnectionsList.clearSelection(); myInboundConnectionsList.repaint(); } updateLeftToolbarButtons(); } }); GridBagConstraints gbc_MessagesList = new GridBagConstraints(); gbc_MessagesList.gridheight = 2; gbc_MessagesList.weightx = 1.0; gbc_MessagesList.weighty = 1.0; gbc_MessagesList.fill = GridBagConstraints.BOTH; gbc_MessagesList.gridx = 0; gbc_MessagesList.gridy = 2; messagesPanel.add(myMessagesList, gbc_MessagesList); JPanel connectionsPanel = new JPanel(); leftSplitPane.setRightComponent(connectionsPanel); GridBagLayout gbl_connectionsPanel = new GridBagLayout(); gbl_connectionsPanel.columnWidths = new int[] { 194, 0 }; gbl_connectionsPanel.rowHeights = new int[] { 0, 30, 0, 0, 0, 0, 0 }; gbl_connectionsPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; gbl_connectionsPanel.rowWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; connectionsPanel.setLayout(gbl_connectionsPanel); JLabel lblConnections = new JLabel("Sending Connections"); lblConnections.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_lblConnections = new GridBagConstraints(); gbc_lblConnections.insets = new Insets(0, 0, 5, 0); gbc_lblConnections.anchor = GridBagConstraints.NORTH; gbc_lblConnections.fill = GridBagConstraints.HORIZONTAL; gbc_lblConnections.gridx = 0; gbc_lblConnections.gridy = 0; connectionsPanel.add(lblConnections, gbc_lblConnections); JToolBar toolBar = new JToolBar(); toolBar.setFloatable(false); GridBagConstraints gbc_toolBar = new GridBagConstraints(); gbc_toolBar.insets = new Insets(0, 0, 5, 0); gbc_toolBar.anchor = GridBagConstraints.NORTH; gbc_toolBar.fill = GridBagConstraints.HORIZONTAL; gbc_toolBar.gridx = 0; gbc_toolBar.gridy = 1; connectionsPanel.add(toolBar, gbc_toolBar); myAddConnectionButton = new JButton(""); myAddConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addOutboundConnection(); } }); myAddConnectionButton.setBorderPainted(false); myAddConnectionButton.addMouseListener(new HoverButtonMouseAdapter(myAddConnectionButton)); myAddConnectionButton.setBorder(null); myAddConnectionButton.setToolTipText("New Connection"); myAddConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/add.png"))); toolBar.add(myAddConnectionButton); myDeleteOutboundConnectionButton = new JButton(""); myDeleteOutboundConnectionButton.setToolTipText("Delete Selected Connection"); myDeleteOutboundConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof OutboundConnection) { myController.removeOutboundConnection((OutboundConnection) myController.getLeftSelectedItem()); } } }); myDeleteOutboundConnectionButton.setBorderPainted(false); myDeleteOutboundConnectionButton .addMouseListener(new HoverButtonMouseAdapter(myDeleteOutboundConnectionButton)); myDeleteOutboundConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/delete.png"))); toolBar.add(myDeleteOutboundConnectionButton); myStartOneOutboundButton = new JButton(""); myStartOneOutboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof OutboundConnection) { myController.startOutboundConnection((OutboundConnection) myController.getLeftSelectedItem()); } } }); myStartOneOutboundButton.setBorderPainted(false); myStartOneOutboundButton.setToolTipText("Start selected connection"); myStartOneOutboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_one.png"))); myStartOneOutboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartOneOutboundButton)); toolBar.add(myStartOneOutboundButton); myStartAllOutboundButton = new JButton(""); myStartAllOutboundButton.setBorderPainted(false); myStartAllOutboundButton.setToolTipText("Start all sending connections"); myStartAllOutboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_all.png"))); myStartAllOutboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartAllOutboundButton)); myStartAllOutboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { myController.startAllOutboundConnections(); } }); toolBar.add(myStartAllOutboundButton); myStopAllOutboundButton = new JButton(""); myStopAllOutboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.stopAllOutboundConnections(); } }); myStopAllOutboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/stop_all.png"))); myStopAllOutboundButton.setToolTipText("Stop all sending connections"); myStopAllOutboundButton.setBorderPainted(false); myStopAllOutboundButton.addMouseListener(new HoverButtonMouseAdapter(myStopAllOutboundButton)); toolBar.add(myStopAllOutboundButton); JScrollPane scrollPane = new JScrollPane(); scrollPane.setBorder(null); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.fill = GridBagConstraints.BOTH; gbc_scrollPane.insets = new Insets(0, 0, 5, 0); gbc_scrollPane.gridx = 0; gbc_scrollPane.gridy = 2; connectionsPanel.add(scrollPane, gbc_scrollPane); myOutboundConnectionsList = new JList(); myOutboundConnectionsList.setBorder(null); myOutboundConnectionsList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (myOutboundConnectionsList.getSelectedIndex() >= 0) { ourLog.debug( "New outbound connection selection " + myOutboundConnectionsList.getSelectedIndex()); myController.setLeftSelectedItem(myOutboundConnectionsList.getSelectedValue()); myMessagesList.clearSelection(); myMessagesList.repaint(); myInboundConnectionsList.clearSelection(); myInboundConnectionsList.repaint(); } updateLeftToolbarButtons(); } }); scrollPane.setViewportView(myOutboundConnectionsList); JLabel lblReceivingConnections = new JLabel("Receiving Connections"); lblReceivingConnections.setHorizontalAlignment(SwingConstants.CENTER); GridBagConstraints gbc_lblReceivingConnections = new GridBagConstraints(); gbc_lblReceivingConnections.insets = new Insets(0, 0, 5, 0); gbc_lblReceivingConnections.gridx = 0; gbc_lblReceivingConnections.gridy = 3; connectionsPanel.add(lblReceivingConnections, gbc_lblReceivingConnections); JToolBar toolBar_1 = new JToolBar(); toolBar_1.setFloatable(false); GridBagConstraints gbc_toolBar_1 = new GridBagConstraints(); gbc_toolBar_1.anchor = GridBagConstraints.WEST; gbc_toolBar_1.insets = new Insets(0, 0, 5, 0); gbc_toolBar_1.gridx = 0; gbc_toolBar_1.gridy = 4; connectionsPanel.add(toolBar_1, gbc_toolBar_1); myAddInboundConnectionButton = new JButton(""); myAddInboundConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.addInboundConnection(); } }); myAddInboundConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/add.png"))); myAddInboundConnectionButton.setToolTipText("New Connection"); myAddInboundConnectionButton.setBorderPainted(false); myAddInboundConnectionButton.addMouseListener(new HoverButtonMouseAdapter(myAddInboundConnectionButton)); toolBar_1.add(myAddInboundConnectionButton); myDeleteInboundConnectionButton = new JButton(""); myDeleteInboundConnectionButton.setToolTipText("Delete Selected Connection"); myDeleteInboundConnectionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof InboundConnection) { myController.removeInboundConnection((InboundConnection) myController.getLeftSelectedItem()); } } }); myDeleteInboundConnectionButton.setBorderPainted(false); myDeleteInboundConnectionButton .addMouseListener(new HoverButtonMouseAdapter(myDeleteInboundConnectionButton)); myDeleteInboundConnectionButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/delete.png"))); toolBar_1.add(myDeleteInboundConnectionButton); myStartOneInboundButton = new JButton(""); myStartOneInboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (myController.getLeftSelectedItem() instanceof InboundConnection) { myController.startInboundConnection((InboundConnection) myController.getLeftSelectedItem()); } } }); myStartOneInboundButton.setBorderPainted(false); myStartOneInboundButton.setToolTipText("Start selected connection"); myStartOneInboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_one.png"))); myStartOneInboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartOneInboundButton)); toolBar_1.add(myStartOneInboundButton); myStartAllInboundButton = new JButton(""); myStartAllInboundButton.setBorderPainted(false); myStartAllInboundButton.setToolTipText("Start all receiving connections"); myStartAllInboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/start_all.png"))); myStartAllInboundButton.addMouseListener(new HoverButtonMouseAdapter(myStartAllInboundButton)); myStartAllInboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent theE) { myController.startAllInboundConnections(); } }); toolBar_1.add(myStartAllInboundButton); myStopAllInboundButton = new JButton(""); myStopAllInboundButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { myController.stopAllInboundConnections(); } }); myStopAllInboundButton.setIcon( new ImageIcon(TestPanelWindow.class.getResource("/ca/uhn/hl7v2/testpanel/images/stop_all.png"))); myStopAllInboundButton.setToolTipText("Stop all receiving connections"); myStopAllInboundButton.setBorderPainted(false); myStopAllInboundButton.addMouseListener(new HoverButtonMouseAdapter(myStopAllInboundButton)); toolBar_1.add(myStopAllInboundButton); JScrollPane scrollPane_1 = new JScrollPane(); scrollPane_1.setBorder(null); GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints(); gbc_scrollPane_1.fill = GridBagConstraints.BOTH; gbc_scrollPane_1.gridx = 0; gbc_scrollPane_1.gridy = 5; connectionsPanel.add(scrollPane_1, gbc_scrollPane_1); myInboundConnectionsList = new JList(); myInboundConnectionsList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (myInboundConnectionsList.getSelectedIndex() >= 0) { ourLog.debug("New inbound connection selection " + myInboundConnectionsList.getSelectedIndex()); myController.setLeftSelectedItem(myInboundConnectionsList.getSelectedValue()); myMessagesList.clearSelection(); myMessagesList.repaint(); myOutboundConnectionsList.clearSelection(); myOutboundConnectionsList.repaint(); myInboundConnectionsList.repaint(); } updateLeftToolbarButtons(); } }); scrollPane_1.setViewportView(myInboundConnectionsList); leftSplitPane.setDividerLocation(200); myWorkspacePanel = new JPanel(); myWorkspacePanel.setBorder(null); outerSplitPane.setRightComponent(myWorkspacePanel); myWorkspacePanel.setLayout(new BorderLayout(0, 0)); outerSplitPane.setDividerLocation(200); myLogScrollPane = new LogTable(); myLogScrollPane.setPreferredSize(new Dimension(454, 120)); myLogScrollPane.setMaximumSize(new Dimension(32767, 120)); myframe.getContentPane().add(myLogScrollPane, BorderLayout.SOUTH); updateLogScrollPaneVisibility(); updateLeftToolbarButtons(); }
From source file:org.gumtree.vis.plot1d.Plot1DPanel.java
@Override protected void displayPopupMenu(int x, int y) { LegendTitle legend = getChart().getLegend(); if (legend != null) { boolean isVisable = legend.isVisible(); RectangleEdge location = legend.getPosition(); if (isVisable) { if (location.equals(RectangleEdge.BOTTOM)) { legendBottom.setSelected(true); legendNone.setSelected(false); legendInternal.setSelected(false); legendRight.setSelected(false); } else if (isVisable && location.equals(RectangleEdge.RIGHT)) { legendRight.setSelected(true); legendNone.setSelected(false); legendInternal.setSelected(false); legendBottom.setSelected(false); }/*from w w w. j av a 2 s . com*/ } else { if (isInternalLegendEnabled) { legendNone.setSelected(false); legendInternal.setSelected(true); legendRight.setSelected(false); legendBottom.setSelected(false); } else { legendNone.setSelected(true); legendInternal.setSelected(false); legendRight.setSelected(false); legendBottom.setSelected(false); } } } XYDataset dataset = getChart().getXYPlot().getDataset(); curveManagementMenu.removeAll(); if (dataset.getSeriesCount() > 0) { curveManagementMenu.setEnabled(true); JMenuItem focusNoneCurveItem = new JRadioButtonMenuItem(); focusNoneCurveItem.setText("None"); focusNoneCurveItem.setActionCommand(UNFOCUS_CURVE_COMMAND); focusNoneCurveItem.addActionListener(this); curveManagementMenu.add(focusNoneCurveItem); boolean isCurveFocused = false; for (int i = 0; i < dataset.getSeriesCount(); i++) { String seriesKey = (String) dataset.getSeriesKey(i); JMenuItem focusOnCurveItem = new JRadioButtonMenuItem(); focusOnCurveItem.setText(seriesKey); focusOnCurveItem.setActionCommand(FOCUS_ON_COMMAND + "-" + seriesKey); focusOnCurveItem.addActionListener(this); curveManagementMenu.add(focusOnCurveItem); if (i == selectedSeriesIndex) { focusOnCurveItem.setSelected(true); isCurveFocused = true; } } if (!isCurveFocused) { focusNoneCurveItem.setSelected(true); } } else { curveManagementMenu.setEnabled(false); } // addMaskMenu(x, y); super.displayPopupMenu(x, y); }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_link.java
private List<JComponent> getExtraOptions(final int row, final Object itemId) { List<JComponent> options = new LinkedList<JComponent>(); final List<Link> rowVisibleLinks = getVisibleElementsInTable(); final NetPlan netPlan = callback.getDesign(); if (itemId != null) { final long linkId = (long) itemId; JMenuItem lengthToEuclidean_thisLink = new JMenuItem("Set link length to node-pair Euclidean distance"); lengthToEuclidean_thisLink.addActionListener(new ActionListener() { @Override//from ww w . j av a 2 s . c o m public void actionPerformed(ActionEvent e) { Link link = netPlan.getLinkFromId(linkId); Node originNode = link.getOriginNode(); Node destinationNode = link.getDestinationNode(); double euclideanDistance = netPlan.getNodePairEuclideanDistance(originNode, destinationNode); link.setLengthInKm(euclideanDistance); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(lengthToEuclidean_thisLink); JMenuItem lengthToHaversine_allNodes = new JMenuItem( "Set link length to node-pair Haversine distance (longitude-latitude) in km"); lengthToHaversine_allNodes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Link link = netPlan.getLinkFromId(linkId); Node originNode = link.getOriginNode(); Node destinationNode = link.getDestinationNode(); double haversineDistanceInKm = netPlan.getNodePairHaversineDistanceInKm(originNode, destinationNode); link.setLengthInKm(haversineDistanceInKm); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(lengthToHaversine_allNodes); JMenuItem scaleLinkLength_thisLink = new JMenuItem("Scale link length"); scaleLinkLength_thisLink.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double scaleFactor; while (true) { String str = JOptionPane.showInputDialog(null, "(Multiplicative) Scale factor", "Scale link length", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { scaleFactor = Double.parseDouble(str); if (scaleFactor < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid scale value. Please, introduce a non-negative number", "Error setting scale factor"); } } netPlan.getLinkFromId(linkId) .setLengthInKm(netPlan.getLinkFromId(linkId).getLengthInKm() * scaleFactor); callback.updateVisualizationAfterChanges(Collections.singleton(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(scaleLinkLength_thisLink); if (netPlan.isMultilayer()) { Link link = netPlan.getLinkFromId(linkId); if (link.getCoupledDemand() != null) { JMenuItem decoupleLinkItem = new JMenuItem("Decouple link (if coupled to unicast demand)"); decoupleLinkItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { netPlan.getLinkFromId(linkId).getCoupledDemand().decouple(); model.setValueAt("", row, 20); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(decoupleLinkItem); } else { JMenuItem createLowerLayerDemandFromLinkItem = new JMenuItem( "Create lower layer demand from link"); createLowerLayerDemandFromLinkItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<Long> layerIds = netPlan.getNetworkLayerIds(); final JComboBox layerSelector = new WiderJComboBox(); for (long layerId : layerIds) { if (layerId == netPlan.getNetworkLayerDefault().getId()) continue; final String layerName = netPlan.getNetworkLayerFromId(layerId).getName(); String layerLabel = "Layer " + layerId; if (!layerName.isEmpty()) layerLabel += " (" + layerName + ")"; layerSelector.addItem(StringLabeller.of(layerId, layerLabel)); } layerSelector.setSelectedIndex(0); JPanel pane = new JPanel(); pane.add(new JLabel("Select layer: ")); pane.add(layerSelector); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the lower layer to create the demand", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); Link link = netPlan.getLinkFromId(linkId); netPlan.addDemand(link.getOriginNode(), link.getDestinationNode(), link.getCapacity(), link.getAttributes(), netPlan.getNetworkLayerFromId(layerId)); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error creating lower layer demand from link"); } } } }); options.add(createLowerLayerDemandFromLinkItem); JMenuItem coupleLinkToDemand = new JMenuItem("Couple link to lower layer demand"); coupleLinkToDemand.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<Long> layerIds = netPlan.getNetworkLayerIds(); final JComboBox layerSelector = new WiderJComboBox(); final JComboBox demandSelector = new WiderJComboBox(); for (long layerId : layerIds) { if (layerId == netPlan.getNetworkLayerDefault().getId()) continue; final String layerName = netPlan.getNetworkLayerFromId(layerId).getName(); String layerLabel = "Layer " + layerId; if (!layerName.isEmpty()) layerLabel += " (" + layerName + ")"; layerSelector.addItem(StringLabeller.of(layerId, layerLabel)); } layerSelector.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (layerSelector.getSelectedIndex() >= 0) { long selectedLayerId = (Long) ((StringLabeller) layerSelector .getSelectedItem()).getObject(); demandSelector.removeAllItems(); for (Demand demand : netPlan .getDemands(netPlan.getNetworkLayerFromId(selectedLayerId))) { if (demand.isCoupled()) continue; long ingressNodeId = demand.getIngressNode().getId(); long egressNodeId = demand.getEgressNode().getId(); String ingressNodeName = demand.getIngressNode().getName(); String egressNodeName = demand.getEgressNode().getName(); demandSelector.addItem(StringLabeller.unmodifiableOf(demand.getId(), "d" + demand.getId() + " [n" + ingressNodeId + " (" + ingressNodeName + ") -> n" + egressNodeId + " (" + egressNodeName + ")]")); } } if (demandSelector.getItemCount() == 0) { demandSelector.setEnabled(false); } else { demandSelector.setSelectedIndex(0); demandSelector.setEnabled(true); } } }); layerSelector.setSelectedIndex(-1); layerSelector.setSelectedIndex(0); JPanel pane = new JPanel(new MigLayout("", "[][grow]", "[][]")); pane.add(new JLabel("Select layer: ")); pane.add(layerSelector, "growx, wrap"); pane.add(new JLabel("Select demand: ")); pane.add(demandSelector, "growx, wrap"); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the lower layer demand", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long demandId; try { demandId = (long) ((StringLabeller) demandSelector.getSelectedItem()) .getObject(); } catch (Throwable ex) { throw new RuntimeException("No demand was selected"); } netPlan.getDemandFromId(demandId) .coupleToUpperLayerLink(netPlan.getLinkFromId(linkId)); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error coupling lower layer demand to link"); } } } }); options.add(coupleLinkToDemand); } } } if (rowVisibleLinks.size() > 1) { if (!options.isEmpty()) options.add(new JPopupMenu.Separator()); JMenuItem caFixValue = new JMenuItem("Set capacity to all"); caFixValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double u_e; while (true) { String str = JOptionPane.showInputDialog(null, "Capacity value", "Set capacity to all table links", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { u_e = Double.parseDouble(str); if (u_e < 0) throw new NumberFormatException(); break; } catch (NumberFormatException ex) { ErrorHandling.showErrorDialog( "Non-valid capacity value. Please, introduce a non-negative number", "Error setting capacity value"); } } try { for (Link link : rowVisibleLinks) link.setCapacity(u_e); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set capacity to all links"); } } }); options.add(caFixValue); JMenuItem caFixValueUtilization = new JMenuItem("Set capacity to match a given utilization"); caFixValueUtilization.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double utilization; while (true) { String str = JOptionPane.showInputDialog(null, "Link utilization value", "Set capacity to all table links to match a given utilization", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { utilization = Double.parseDouble(str); if (utilization <= 0) throw new NumberFormatException(); break; } catch (NumberFormatException ex) { ErrorHandling.showErrorDialog( "Non-valid link utilization value. Please, introduce a strictly positive number", "Error setting link utilization value"); } } try { for (Link link : rowVisibleLinks) link.setCapacity(link.getOccupiedCapacity() / utilization); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set capacity to all links according to a given link utilization"); } } }); options.add(caFixValueUtilization); JMenuItem lengthToAll = new JMenuItem("Set link length to all"); lengthToAll.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double l_e; while (true) { String str = JOptionPane.showInputDialog(null, "Link length value (in km)", "Set link length to all table links", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { l_e = Double.parseDouble(str); if (l_e < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid link length value. Please, introduce a non-negative number", "Error setting link length"); } } NetPlan netPlan = callback.getDesign(); try { for (Link link : rowVisibleLinks) link.setLengthInKm(l_e); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set link length to all links"); } } }); options.add(lengthToAll); JMenuItem lengthToEuclidean_allLinks = new JMenuItem( "Set all table link lengths to node-pair Euclidean distance"); lengthToEuclidean_allLinks.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { for (Link link : rowVisibleLinks) link.setLengthInKm(netPlan.getNodePairEuclideanDistance(link.getOriginNode(), link.getDestinationNode())); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set link length value to all links"); } } }); options.add(lengthToEuclidean_allLinks); JMenuItem lengthToHaversine_allLinks = new JMenuItem( "Set all table link lengths to node-pair Haversine distance (longitude-latitude) in km"); lengthToHaversine_allLinks.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); try { for (Link link : rowVisibleLinks) { link.setLengthInKm(netPlan.getNodePairHaversineDistanceInKm(link.getOriginNode(), link.getDestinationNode())); } callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to set link length value to all links"); } } }); options.add(lengthToHaversine_allLinks); JMenuItem scaleLinkLength_allLinks = new JMenuItem("Scale all table link lengths"); scaleLinkLength_allLinks.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double scaleFactor; while (true) { String str = JOptionPane.showInputDialog(null, "(Multiplicative) Scale factor", "Scale (all) link length", JOptionPane.QUESTION_MESSAGE); if (str == null) return; try { scaleFactor = Double.parseDouble(str); if (scaleFactor < 0) throw new RuntimeException(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog( "Non-valid scale value. Please, introduce a non-negative number", "Error setting scale factor"); } } NetPlan netPlan = callback.getDesign(); try { for (Link link : rowVisibleLinks) link.setLengthInKm(link.getLengthInKm() * scaleFactor); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to scale link length"); } } }); options.add(scaleLinkLength_allLinks); if (netPlan.isMultilayer()) { final Set<Link> coupledLinks = rowVisibleLinks.stream().filter(e -> e.isCoupled()) .collect(Collectors.toSet()); if (!coupledLinks.isEmpty()) { JMenuItem decoupleAllLinksItem = new JMenuItem("Decouple all table links"); decoupleAllLinksItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (Link link : coupledLinks) if (link.getCoupledDemand() == null) link.getCoupledMulticastDemand().decouple(); else link.getCoupledDemand().decouple(); int numRows = model.getRowCount(); for (int i = 0; i < numRows; i++) model.setValueAt("", i, 20); callback.getVisualizationState().resetPickedState(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } }); options.add(decoupleAllLinksItem); } if (coupledLinks.size() < rowVisibleLinks.size()) { JMenuItem createLowerLayerDemandsFromLinksItem = new JMenuItem( "Create lower layer unicast demands from uncoupled links"); createLowerLayerDemandsFromLinksItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final JComboBox layerSelector = new WiderJComboBox(); for (NetworkLayer layer : netPlan.getNetworkLayers()) { if (layer.getId() == netPlan.getNetworkLayerDefault().getId()) continue; final String layerName = layer.getName(); String layerLabel = "Layer " + layer.getId(); if (!layerName.isEmpty()) layerLabel += " (" + layerName + ")"; layerSelector.addItem(StringLabeller.of(layer.getId(), layerLabel)); } layerSelector.setSelectedIndex(0); JPanel pane = new JPanel(); pane.add(new JLabel("Select layer: ")); pane.add(layerSelector); while (true) { int result = JOptionPane.showConfirmDialog(null, pane, "Please select the lower layer to create demands", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (result != JOptionPane.OK_OPTION) return; try { long layerId = (long) ((StringLabeller) layerSelector.getSelectedItem()) .getObject(); NetworkLayer layer = netPlan.getNetworkLayerFromId(layerId); for (Link link : rowVisibleLinks) if (!link.isCoupled()) link.coupleToNewDemandCreated(layer); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges( Sets.newHashSet(NetworkElementType.LINK, NetworkElementType.DEMAND)); callback.getUndoRedoNavigationManager().addNetPlanChange(); break; } catch (Throwable ex) { ErrorHandling.showErrorDialog(ex.getMessage(), "Error creating lower layer demands"); } } } }); options.add(createLowerLayerDemandsFromLinksItem); } } } return options; }
From source file:com.net2plan.gui.utils.viewEditTopolTables.specificTables.AdvancedJTable_link.java
@Override public void doPopup(final MouseEvent e, final int row, final Object itemId) { JPopupMenu popup = new JPopupMenu(); final ITableRowFilter rf = callback.getVisualizationState().getTableRowFilter(); final List<Link> linkRowsInTheTable = getVisibleElementsInTable(); /* Add the popup menu option of the filters */ final List<Link> selectedLinks = (List<Link>) (List<?>) getSelectedElements().getFirst(); if (!selectedLinks.isEmpty()) { final JMenu submenuFilters = new JMenu("Filters"); final JMenuItem filterKeepElementsAffectedThisLayer = new JMenuItem( "This layer: Keep elements associated to this link traffic"); final JMenuItem filterKeepElementsAffectedAllLayers = new JMenuItem( "All layers: Keep elements associated to this link traffic"); submenuFilters.add(filterKeepElementsAffectedThisLayer); if (callback.getDesign().getNumberOfLayers() > 1) submenuFilters.add(filterKeepElementsAffectedAllLayers); filterKeepElementsAffectedThisLayer.addActionListener(new ActionListener() { @Override//w w w . java2 s .c o m public void actionPerformed(ActionEvent e) { if (selectedLinks.size() > 1) throw new RuntimeException(); TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedLinks.get(0), true); callback.getVisualizationState().updateTableRowFilter(filter); callback.updateVisualizationJustTables(); } }); filterKeepElementsAffectedAllLayers.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (selectedLinks.size() > 1) throw new RuntimeException(); TBFToFromCarriedTraffic filter = new TBFToFromCarriedTraffic(selectedLinks.get(0), false); callback.getVisualizationState().updateTableRowFilter(filter); callback.updateVisualizationJustTables(); } }); popup.add(submenuFilters); popup.addSeparator(); } if (callback.getVisualizationState().isNetPlanEditable()) { popup.add(getAddOption()); for (JComponent item : getExtraAddOptions()) popup.add(item); } if (!linkRowsInTheTable.isEmpty()) { if (callback.getVisualizationState().isNetPlanEditable()) { if (row != -1) { if (popup.getSubElements().length > 0) popup.addSeparator(); JMenuItem removeItem = new JMenuItem("Remove " + networkElementType); removeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); try { Link link = netPlan.getLinkFromId((long) itemId); link.remove(); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ErrorHandling.addErrorOrException(ex, getClass()); ErrorHandling.showErrorDialog("Unable to remove " + networkElementType); } } }); popup.add(removeItem); } addPopupMenuAttributeOptions(e, row, itemId, popup); JMenuItem removeItems = new JMenuItem("Remove all " + networkElementType + "s in table"); removeItems.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NetPlan netPlan = callback.getDesign(); try { if (rf == null) netPlan.removeAllLinks(); else for (Link ee : linkRowsInTheTable) ee.remove(); callback.getVisualizationState() .recomputeCanvasTopologyBecauseOfLinkOrNodeAdditionsOrRemovals(); callback.updateVisualizationAfterChanges(Sets.newHashSet(NetworkElementType.LINK)); callback.getUndoRedoNavigationManager().addNetPlanChange(); } catch (Throwable ex) { ex.printStackTrace(); ErrorHandling.showErrorDialog(ex.getMessage(), "Unable to remove all " + networkElementType + "s"); } } }); popup.add(removeItems); List<JComponent> extraOptions = getExtraOptions(row, itemId); if (!extraOptions.isEmpty()) { if (popup.getSubElements().length > 0) popup.addSeparator(); for (JComponent item : extraOptions) popup.add(item); } } List<JComponent> forcedOptions = getForcedOptions(); if (!forcedOptions.isEmpty()) { if (popup.getSubElements().length > 0) popup.addSeparator(); for (JComponent item : forcedOptions) popup.add(item); } } popup.show(e.getComponent(), e.getX(), e.getY()); }
From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.script.PainelScript.java
private JMenuBar criaMenuBar() { menuBar = new JMenuBar(); menuBar.setBackground(parentFrame.corDefault); JMenu menuArquivo = new JMenu(GERAL.ARQUIVO); menuArquivo.setMnemonic('A'); menuArquivo.setMnemonic(KeyEvent.VK_A); menuArquivo.setBackground(parentFrame.corDefault); JMenu avaliadores = new JMenu(); MenuSilvinha menuSilvinha = new MenuSilvinha(parentFrame, null); menuSilvinha.criaMenuAvaliadores(avaliadores); // menuArquivo.add(avaliadores); // menuArquivo.add(new JSeparator()); JMenuItem btnAbrir = new JMenuItem(GERAL.BTN_ABRIR); btnAbrir.addActionListener(this); btnAbrir.setActionCommand("Abrir"); btnAbrir.setMnemonic('A'); btnAbrir.setAccelerator(//w w w. jav a 2s . c o m javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, ActionEvent.CTRL_MASK)); btnAbrir.setMnemonic(KeyEvent.VK_A); btnAbrir.setToolTipText(GERAL.DICA_ABRIR); btnAbrir.getAccessibleContext().setAccessibleDescription(GERAL.DICA_ABRIR); menuArquivo.add(btnAbrir); JMenuItem btnAbrirUrl = new JMenuItem(br.org.acessobrasil.silvinha2.mli.XHTML_Panel.BTN_ABRIR_URL); btnAbrirUrl.addActionListener(this); btnAbrirUrl.setActionCommand("AbrirURL"); btnAbrirUrl.setMnemonic('U'); btnAbrirUrl.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, ActionEvent.CTRL_MASK)); btnAbrirUrl.setMnemonic(KeyEvent.VK_U); btnAbrirUrl.setToolTipText(br.org.acessobrasil.silvinha2.mli.XHTML_Panel.DICA_ABRIR); btnAbrirUrl.getAccessibleContext() .setAccessibleDescription(br.org.acessobrasil.silvinha2.mli.XHTML_Panel.DICA_ABRIR); menuArquivo.add(btnAbrirUrl); btnSalvar = new JMenuItem(GERAL.BTN_SALVAR); btnSalvar.addActionListener(this); btnSalvar.setActionCommand("Salvar"); btnSalvar.setMnemonic('S'); btnSalvar.setAccelerator( javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, ActionEvent.CTRL_MASK)); btnSalvar.setMnemonic(KeyEvent.VK_S); btnSalvar.getAccessibleContext().setAccessibleDescription(GERAL.DICA_SALVA_REAVALIA); menuArquivo.add(btnSalvar); JMenuItem btnSalvarAs = new JMenuItem(GERAL.BTN_SALVAR_COMO); btnSalvarAs.addActionListener(this); btnSalvarAs.setActionCommand("SaveAs"); btnSalvarAs.setMnemonic('c'); btnSalvarAs.setMnemonic(KeyEvent.VK_C); // btnSalvarAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, // ActionEvent.CTRL_MASK)); btnSalvarAs.setToolTipText(GERAL.DICA_SALVAR_COMO); btnSalvarAs.getAccessibleContext().setAccessibleDescription(GERAL.DICA_SALVAR_COMO); menuArquivo.add(btnSalvarAs); menuArquivo.add(new JSeparator()); JMenuItem btnFechar = new JMenuItem(GERAL.SAIR); btnFechar.addActionListener(this); btnFechar.setActionCommand("Sair"); btnFechar.setMnemonic('a'); btnFechar.setMnemonic(KeyEvent.VK_A); btnFechar.setToolTipText(GERAL.DICA_SAIR); btnFechar.getAccessibleContext().setAccessibleDescription(GERAL.DICA_SAIR); menuArquivo.add(btnFechar); menuBar.add(menuArquivo); menuBar.add(this.criaMenuEditar()); menuBar.add(avaliadores); JMenu menuSimuladores = new JMenu(); menuSilvinha.criaMenuSimuladores(menuSimuladores); menuBar.add(menuSimuladores); JMenu mnFerramenta = new JMenu(); menuSilvinha.criaMenuFerramentas(mnFerramenta); menuBar.add(mnFerramenta); JMenu menuAjuda = new JMenu(GERAL.AJUDA); menuSilvinha.criaMenuAjuda(menuAjuda); menuBar.add(menuAjuda); return menuBar; }
From source file:gdt.jgui.entity.index.JIndexPanel.java
private void initPopup() { try {//from ww w . ja v a 2s.co m //System.out.println("IndexPanel:initPopup:selection="+selection$); Properties locator = Locator.toProperties(selection$); String nodeType$ = locator.getProperty(NODE_TYPE); //System.out.println("IndexPanel:initPopup:node type="+nodeType$); if (NODE_TYPE_ROOT.equals(nodeType$)) { popup = null; return; } if (NODE_TYPE_GROUP.equals(nodeType$)) { popup = new JPopupMenu(); JMenuItem newGroupItem = new JMenuItem("New group"); newGroupItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // System.out.println("JIndexPanel:popup:new parent group: selection="+selection$); Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String title$ = "New group" + Identity.key().substring(0, 4); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, title$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT_TITLE, "Create group"); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_CREATE_GROUP); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(newGroupItem); popup.addSeparator(); JMenuItem renameItem = new JMenuItem("Rename"); renameItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String title$ = locator.getProperty(Locator.LOCATOR_TITLE); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, title$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_RENAME_GROUP); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(renameItem); JMenuItem setIconItem = new JMenuItem("Set icon"); setIconItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); JIconSelector is = new JIconSelector(); String isLocator$ = is.getLocator(); isLocator$ = Locator.append(isLocator$, Entigrator.ENTIHOME, entihome$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_SET_ICON_GROUP); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); isLocator$ = Locator.append(isLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, isLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(setIconItem); JMenuItem orderItem = new JMenuItem("Order"); orderItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Properties locator = Locator.toProperties(selection$); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); String nodeKey$ = locator.getProperty(NODE_KEY); index = orderGroupDefault(index, nodeKey$); index.putElementItem("index.selection", new Core(null, "selection", nodeKey$)); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(orderItem); popup.addSeparator(); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cut = false; console.clipboard.clear(); if (selection$ != null) console.clipboard.putString(selection$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(copyItem); JMenuItem cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cut = true; console.clipboard.clear(); if (selection$ != null) console.clipboard.putString(selection$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(cutItem); final String[] sa = console.clipboard.getContent(); if (sa != null && sa.length > 0) { JMenuItem pasteItem = new JMenuItem("Paste"); pasteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { // System.out.println("JIndexPanel:popup:new parent group: selection="+selection$); Properties selectionLocator = Locator.toProperties(selection$); String indexLocator$ = getLocator(); String groupKey$ = selectionLocator.getProperty(NODE_KEY); Properties indexLocator = Locator.toProperties(indexLocator$); String entihome$ = indexLocator.getProperty(Entigrator.ENTIHOME); String entityKey$ = indexLocator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); for (String aSa : sa) { index = pasteItemToGroup(index, groupKey$, aSa); } entigrator.save(index); cut = false; JConsoleHandler.execute(console, getLocator()); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(pasteItem); } popup.addSeparator(); JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { try { Properties locator = Locator.toProperties(selection$); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); String nodeKey$ = locator.getProperty(NODE_KEY); String groupKey$ = locator.getProperty(NODE_GROUP_KEY); index = removeNode(index, nodeKey$); index.putElementItem("index.selection", new Core(null, "selection", groupKey$)); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } } }); popup.add(deleteItem); return; } if (NODE_TYPE_REFERENCE.equals(nodeType$)) { popup = new JPopupMenu(); final String locatorType$ = locator.getProperty(Locator.LOCATOR_TYPE); JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Properties locator = Locator.toProperties(selection$); // String locatorType$=locator.getProperty(Locator.LOCATOR_TYPE); // System.out.println("IndexPanel:open:node type="+locatorType$); if (JFolderPanel.LOCATOR_TYPE_FILE.equals(locatorType$)) { String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File itemFile = new File(filePath$); try { Desktop.getDesktop().open(itemFile); } catch (Exception ee) { LOGGER.info(ee.toString()); } return; } if (JWeblinksPanel.LOCATOR_TYPE_WEB_LINK.equals(locatorType$)) { try { String url$ = locator.getProperty(JWeblinksPanel.WEB_LINK_URL); Desktop.getDesktop().browse(new URI(url$)); } catch (Exception ee) { LOGGER.info(ee.toString()); } return; } String responseLocator$ = getLocator(); // System.out.println("IndexPanel:open:response locator="+Locator.remove(responseLocator$,Locator.LOCATOR_ICON)); selection$ = Locator.append(selection$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(responseLocator$)); // System.out.println("IndexPanel:open:selection="+Locator.remove(Locator.remove(selection$, Locator.LOCATOR_ICON),JRequester.REQUESTER_RESPONSE_LOCATOR)); selection$ = Locator.append(selection$, Entigrator.ENTIHOME, entihome$); JConsoleHandler.execute(console, selection$); } }); popup.add(openItem); if (JFolderPanel.LOCATOR_TYPE_FILE.equals(locator.getProperty(Locator.LOCATOR_TYPE))) { JMenuItem openFolderItem = new JMenuItem("Open folder"); openFolderItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Properties locator = Locator.toProperties(selection$); String filePath$ = locator.getProperty(JFolderPanel.FILE_PATH); File itemFile = new File(filePath$); try { Desktop.getDesktop().open(itemFile.getParentFile()); } catch (Exception ee) { LOGGER.info(ee.toString()); } return; } }); popup.add(openFolderItem); } JMenuItem deleteItem = new JMenuItem("Delete"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int response = JOptionPane.showConfirmDialog(console.getContentPanel(), "Delete ?", "Confirm", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (response == JOptionPane.YES_OPTION) { Properties selectionLocator = Locator.toProperties(selection$); String indexLocator$ = getLocator(); Properties indexLocator = Locator.toProperties(indexLocator$); String entihome$ = indexLocator.getProperty(Entigrator.ENTIHOME); String entityKey$ = indexLocator.getProperty(EntityHandler.ENTITY_KEY); Entigrator entigrator = console.getEntigrator(entihome$); Sack index = entigrator.getEntityAtKey(entityKey$); String nodeKey$ = selectionLocator.getProperty(NODE_KEY); String groupKey$ = selectionLocator.getProperty(NODE_GROUP_KEY); index.removeElementItem("index.jlocator", nodeKey$); index.putElementItem("index.selection", new Core(null, "selection", groupKey$)); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } } }); popup.add(deleteItem); popup.addSeparator(); JMenuItem renameItem = new JMenuItem("Rename"); renameItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JConsoleHandler.execute(console, selection$); try { Properties locator = Locator.toProperties(selection$); String entihome$ = locator.getProperty(Entigrator.ENTIHOME); String nodeKey$ = locator.getProperty(NODE_KEY); String title$; Core title = index.getElementItem("index.title", nodeKey$); if (title != null && title.value != null) title$ = title.value; else title$ = locator.getProperty(Locator.LOCATOR_TITLE); JTextEditor te = new JTextEditor(); String teLocator$ = te.getLocator(); teLocator$ = Locator.append(teLocator$, Entigrator.ENTIHOME, entihome$); teLocator$ = Locator.append(teLocator$, JTextEditor.TEXT, title$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_RENAME_REFERENCE); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); teLocator$ = Locator.append(teLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, teLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(renameItem); JMenuItem setIconItem = new JMenuItem("Set icon"); setIconItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JConsoleHandler.execute(console, selection$); try { Properties locator = Locator.toProperties(selection$); JIconSelector is = new JIconSelector(); String isLocator$ = is.getLocator(); isLocator$ = Locator.append(isLocator$, Entigrator.ENTIHOME, entihome$); String ipLocator$ = getLocator(); ipLocator$ = Locator.append(ipLocator$, JRequester.REQUESTER_ACTION, ACTION_SET_ICON_REFERENCE); ipLocator$ = Locator.append(ipLocator$, SELECTION, Locator.compressText(selection$)); ipLocator$ = Locator.append(ipLocator$, BaseHandler.HANDLER_METHOD, "response"); isLocator$ = Locator.append(isLocator$, JRequester.REQUESTER_RESPONSE_LOCATOR, Locator.compressText(ipLocator$)); JConsoleHandler.execute(console, isLocator$); } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(setIconItem); JMenuItem resetItem = new JMenuItem("Reset"); resetItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JConsoleHandler.execute(console, selection$); try { Properties locator = Locator.toProperties(selection$); String nodeKey$ = locator.getProperty(NODE_KEY); Core title = index.getElementItem("index.title", nodeKey$); if (title != null) { index.removeElementItem("index.title", nodeKey$); Entigrator entigrator = console.getEntigrator(entihome$); entigrator.save(index); JConsoleHandler.execute(console, getLocator()); } } catch (Exception ee) { Logger.getLogger(JIndexPanel.class.getName()).info(ee.toString()); } } }); popup.add(resetItem); popup.addSeparator(); JMenuItem copyItem = new JMenuItem("Copy"); copyItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cut = false; console.clipboard.clear(); console.clipboard.putString(selection$); } }); popup.add(copyItem); JMenuItem cutItem = new JMenuItem("Cut"); cutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cut = true; console.clipboard.clear(); console.clipboard.putString(selection$); } }); popup.add(cutItem); } } catch (Exception e) { Logger.getLogger(getClass().getName()).severe(e.toString()); } }
From source file:net.sf.firemox.clickable.target.card.MCard.java
@Override public void mouseClicked(MouseEvent e) { if (!(getParent() instanceof MZone) && !(getParent() instanceof MCard)) { return;//from w w w . j av a 2s . c o m } StackManager.noReplayToken.take(); MZone container = getContainer(); try { TargetFactory.triggerTargetable = this; if (ConnectionManager.isConnected() && e.getButton() == MouseEvent.BUTTON1) { // only if left button is pressed if (!StackManager.actionManager.clickOn(this)) { // this card is activated and you control it if (!(StackManager.actionManager.currentAction instanceof WaitingAbility)) { // we are not waiting ability if (container instanceof ExpandableZone) { ((ExpandableZone) container).toggle(); } return; } final List<Ability> abilities = ((WaitingAbility) StackManager.actionManager.currentAction) .abilitiesOf(this); final List<Ability> advAbilities = ((WaitingAbility) StackManager.actionManager.currentAction) .advancedAbilitiesOf(this); // is there any playable ability with this card ? if ((abilities == null || abilities.isEmpty()) && (advAbilities == null || advAbilities.isEmpty())) { // no playable ability, and this card is not wait for -> toggle if (container instanceof ExpandableZone) { ((ExpandableZone) container).toggle(); } return; } // a choice has to be made if (advAbilities != null && !advAbilities.isEmpty() || abilities != null && abilities.size() > 1) { /* * several abilities for this card, we fill the popup ability menu */ TargetFactory.abilitiesMenu.removeAll(); if (abilities != null) { for (Ability ability : abilities) { final JMenuItem item = new JMenuItem( "<html>" + ability.toHtmlString(null) + "</html>"); item.addActionListener(this); TargetFactory.abilitiesMenu.add(item); } } if (advAbilities != null && !advAbilities.isEmpty()) { TargetFactory.abilitiesMenu.add(new JSeparator()); for (Ability ability : advAbilities) { final JMenuItem item = new JMenuItem( "<html>" + ability.toHtmlString(null) + "</html>", WARNING_PICTURE); item.addActionListener(this); TargetFactory.abilitiesMenu.add(item); } } // show the option popup menu TargetFactory.abilitiesMenu.show(e.getComponent(), e.getX(), e.getY()); return; } else if (abilities != null && abilities.size() == 1 && (advAbilities == null || advAbilities.isEmpty())) { // only one playable ability, we select it automatically ((UserAbility) abilities.get(0)).mouseClicked(0); } } else if (StackManager.idHandedPlayer != 0) { if (container instanceof ExpandableZone) { ((ExpandableZone) container).toggle(); } } else { // Since this click has been handled, the opponent will be informed on sendClickToOpponent(); StackManager.actionManager.succeedClickOn(this); } } else if (ConnectionManager.isConnected()) { // only if not left button is pressed CardFactory.contextMenu.removeAll(); TargetFactory.triggerTargetable = this; // add counter item CardFactory.countItem.setText(LanguageManager.getString("countcard", container.toString(), String.valueOf(container.getCardCount()))); CardFactory.contextMenu.add(CardFactory.countItem); // add refresh picture item CardFactory.contextMenu.add(CardFactory.reloadPictureItem); // add expand/gather item if (container instanceof ExpandableZone) { if (container == ZoneManager.expandedZone) { CardFactory.contextMenu.add(CardFactory.gatherItem); } else { CardFactory.contextMenu.add(CardFactory.expandItem); } } CardFactory.contextMenu.add(new JSeparator()); // add the "database" item --> activate the tabbed panel CardFactory.contextMenu.add(CardFactory.databaseCardInfoItem); // TODO add "java properties" item --> show an inspect popup. // CardFactory.contextMenu.add(CardFactory.javaDebugItem); // TODO add "show id" option // show the option popup menu CardFactory.contextMenu.show(e.getComponent(), e.getX(), e.getY()); } } catch (Throwable t) { t.printStackTrace(); } finally { StackManager.noReplayToken.release(); } }
From source file:biz.wolschon.finance.jgnucash.JGnucash.java
/** * This method initializes import-menu/*from w w w . j ava2 s .c o m*/ * with plugins. * * @return javax.swing.JMenu */ @SuppressWarnings("unchecked") protected JMenu getToolMenu() { if (toolMenu == null) { toolMenu = new JMenu(); toolMenu.setText("Tools"); toolMenu.setMnemonic('t'); //importMenu.setEnabled(false);// first we need to load a file PluginManager manager = getPluginManager(); // if we are configured for the plugin-api if (manager != null) { ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(), "Tool"); for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) { Extension ext = it.next(); String pluginName = "unknown"; try { pluginName = ext.getParameter("name").valueAsString(); JMenuItem newMenuItem = new JMenuItem(); newMenuItem.putClientProperty("extension", ext); Parameter descrParam = ext.getParameter("description"); Parameter iconParam = ext.getParameter("icon"); URL iconUrl = null; if (iconParam != null) { try { iconUrl = getPluginManager() .getPluginClassLoader(ext.getDeclaringPluginDescriptor()) .getResource(iconParam.valueAsString()); if (iconUrl != null) { newMenuItem.setIcon(new ImageIcon(iconUrl)); } } catch (Exception e) { LOGGER.error("cannot load icon for Tool-Plugin '" + pluginName + "'", e); } } newMenuItem.setText(pluginName); if (descrParam != null) { newMenuItem.setToolTipText(descrParam.valueAsString()); } newMenuItem.addActionListener(new ToolPluginMenuAction(this, ext, pluginName)); toolMenu.add(newMenuItem); } catch (Exception e) { LOGGER.error("cannot load Tool-Plugin '" + pluginName + "'", e); JOptionPane.showMessageDialog(this, "Error", "Cannot load Tool-Plugin '" + pluginName + "'", JOptionPane.ERROR_MESSAGE); } } } } return toolMenu; }
From source file:biz.wolschon.finance.jgnucash.JGnucash.java
/** * This method initializes import-menu with * plugins./*from w w w . j ava 2 s.c om*/ * * @return javax.swing.JMenu */ @SuppressWarnings("unchecked") protected JMenu getImportMenu() { if (importMenu == null) { importMenu = new JMenu(); importMenu.setText("Import"); importMenu.setMnemonic('i'); //importMenu.setEnabled(false);// first we need to load a file PluginManager manager = getPluginManager(); // if we are configured for the plugin-api if (manager != null) { ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(), "Importer"); for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) { Extension ext = it.next(); String pluginName = "unknown"; try { pluginName = ext.getParameter("name").valueAsString(); JMenuItem newMenuItem = new JMenuItem(); newMenuItem.putClientProperty("extension", ext); Parameter descrParam = ext.getParameter("description"); Parameter iconParam = ext.getParameter("icon"); URL iconUrl = null; if (iconParam != null) { try { iconUrl = getPluginManager() .getPluginClassLoader(ext.getDeclaringPluginDescriptor()) .getResource(iconParam.valueAsString()); if (iconUrl != null) { newMenuItem.setIcon(new ImageIcon(iconUrl)); } } catch (Exception e) { LOGGER.error("cannot load icon for Importer-Plugin '" + pluginName + "'", e); } } newMenuItem.setText(pluginName); if (descrParam != null) { newMenuItem.setToolTipText(descrParam.valueAsString()); } newMenuItem.addActionListener(new ImportPluginMenuAction(this, ext, pluginName)); importMenu.add(newMenuItem); } catch (Exception e) { LOGGER.error("cannot load Importer-Plugin '" + pluginName + "'", e); JOptionPane.showMessageDialog(this, "Error", "Cannot load Importer-Plugin '" + pluginName + "'", JOptionPane.ERROR_MESSAGE); } } } } return importMenu; }