List of usage examples for javax.swing SwingUtilities isRightMouseButton
public static boolean isRightMouseButton(MouseEvent anEvent)
From source file:jatoo.app.App.java
public App(final String title) { this.title = title; ///* w w w.j a va 2 s . c om*/ // load properties properties = new AppProperties(new File(getWorkingDirectory(), "app.properties")); properties.loadSilently(); // // resources texts = new ResourcesTexts(getClass(), new ResourcesTexts(App.class)); images = new ResourcesImages(getClass(), new ResourcesImages(App.class)); // // create & initialize the window if (isDialog()) { window = new JDialog((Frame) null, getTitle()); if (isUndecorated()) { ((JDialog) window).setUndecorated(true); ((JDialog) window).setBackground(new Color(0, 0, 0, 0)); } ((JDialog) window).setResizable(isResizable()); } else { window = new JFrame(getTitle()); if (isUndecorated()) { ((JFrame) window).setUndecorated(true); ((JFrame) window).setBackground(new Color(0, 0, 0, 0)); } ((JFrame) window).setResizable(isResizable()); } window.addWindowListener(new WindowAdapter() { @Override public void windowClosing(final WindowEvent e) { System.exit(0); } @Override public void windowIconified(final WindowEvent e) { if (isHideWhenMinimized()) { hide(); } } }); // // set icon images // is either all icons from initializer package // or all icons from app package List<Image> windowIconImages = new ArrayList<>(); String[] windowIconImagesNames = new String[] { "016", "020", "022", "024", "032", "048", "064", "128", "256", "512" }; for (String size : windowIconImagesNames) { try { windowIconImages.add(new ImageIcon(getClass().getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } if (windowIconImages.size() == 0) { for (String size : windowIconImagesNames) { try { windowIconImages .add(new ImageIcon(App.class.getResource("app-icon-" + size + ".png")).getImage()); } catch (Exception e) { } } } window.setIconImages(windowIconImages); // // this is the place for to call init method // after all local components are created // from now (after init) is only configuration init(); // // set content pane ( and ansure transparency ) JComponent contentPane = getContentPane(); contentPane.setOpaque(false); ((RootPaneContainer) window).setContentPane(contentPane); // // pack the window right after the set of the content pane window.pack(); // // center window (as default in case restore fails) // and try to restore the last location window.setLocationRelativeTo(null); window.setLocation(properties.getLocation(window.getLocation())); if (!isUndecorated()) { if (properties.getLastUndecorated(isUndecorated()) == isUndecorated()) { if (isResizable() && isSizePersistent()) { final String currentLookAndFeel = String.valueOf(UIManager.getLookAndFeel()); if (properties.getLastLookAndFeel(currentLookAndFeel).equals(currentLookAndFeel)) { window.setSize(properties.getSize(window.getSize())); } } } } // // fix location if out of screen Rectangle intersection = window.getGraphicsConfiguration().getBounds().intersection(window.getBounds()); if ((intersection.width < window.getWidth() * 1 / 2) || (intersection.height < window.getHeight() * 1 / 2)) { UIUtils.setWindowLocationRelativeToScreen(window); } // // restore some properties setAlwaysOnTop(properties.isAlwaysOnTop()); setHideWhenMinimized(properties.isHideWhenMinimized()); setTransparency(properties.getTransparency(transparency)); // // null is also a good value for margins glue gaps (is [0,0,0,0]) Insets marginsGlueGaps = getMarginsGlueGaps(); if (marginsGlueGaps == null) { marginsGlueGaps = new Insets(0, 0, 0, 0); } // // glue to margins on Ctrl + ARROWS if (isGlueToMarginsOnCtrlArrows()) { UIUtils.setActionForCtrlDownKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginBottom(window, marginsGlueGaps.bottom)); UIUtils.setActionForCtrlLeftKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginLeft(window, marginsGlueGaps.left)); UIUtils.setActionForCtrlRightKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginRight(window, marginsGlueGaps.right)); UIUtils.setActionForCtrlUpKeyStroke(((RootPaneContainer) window).getRootPane(), new ActionGlueMarginTop(window, marginsGlueGaps.top)); } // // drag to move ( when provided component is not null ) JComponent dragToMoveComponent = getDragToMoveComponent(); if (dragToMoveComponent != null) { // // move the window by dragging the UI component int marginsGlueRange = Math.min(window.getGraphicsConfiguration().getBounds().width, window.getGraphicsConfiguration().getBounds().height); marginsGlueRange /= 60; marginsGlueRange = Math.max(marginsGlueRange, 15); UIUtils.forwardDragAsMove(dragToMoveComponent, window, marginsGlueRange, marginsGlueGaps); // // window popup dragToMoveComponent.addMouseListener(new MouseAdapter() { public void mouseReleased(final MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { windowPopup = getWindowPopup(e.getLocationOnScreen()); windowPopup.setVisible(true); } } }); // // always dispose the popup when window lose the focus window.addFocusListener(new FocusAdapter() { public void focusLost(final FocusEvent e) { if (windowPopup != null) { windowPopup.setVisible(false); windowPopup = null; } } }); } // // tray icon if (hasTrayIcon()) { if (SystemTray.isSupported()) { Image trayIconImage = windowIconImages.get(0); Dimension trayIconSize = SystemTray.getSystemTray().getTrayIconSize(); for (Image windowIconImage : windowIconImages) { if (Math.abs(trayIconSize.width - windowIconImage.getWidth(null)) < Math .abs(trayIconImage.getWidth(null) - windowIconImage.getWidth(null))) { trayIconImage = windowIconImage; } } final TrayIcon trayIcon = new TrayIcon(trayIconImage); trayIcon.setPopupMenu(getTrayIconPopup()); trayIcon.addMouseListener(new MouseAdapter() { public void mouseClicked(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() >= 2) { if (window.isVisible()) { hide(); } else { show(); } } } } }); try { SystemTray.getSystemTray().add(trayIcon); } catch (AWTException e) { logger.error( "unexpected exception trying to add the tray icon ( the desktop system tray is missing? )", e); } } else { logger.error("the system tray is not supported on the current platform"); } } // // hidden or not if (properties.isVisible()) { window.setVisible(true); } // // close the splash screen // if there is one try { SplashScreen splash = SplashScreen.getSplashScreen(); if (splash != null) { splash.close(); } } catch (UnsupportedOperationException e) { getLogger().info("splash screen not supported", e); } // // add shutdown hook for #destroy() Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { App.this.destroy(); } }); // // after init afterInit(); }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * Handle mouse clicked events.//from www .ja v a2 s . c o m * <P> * Overrides the parent method because we have two seperate areas. */ @Override public void mouseClicked(MouseEvent evt) { Point2D point = evt.getPoint(); boolean rightButton = SwingUtilities.isRightMouseButton(evt) || evt.isControlDown(); if (this.fLeftTreeArea.contains(point)) { /** In tree area. */ Element elem = this.fTreePainter.java2DToClade(point, this.fLeftTreeArea, this.getMouseClickDistance()); if (elem == null) { /** Unselect every thing. */ if (rightButton && this.fSelectedCladeList != null) { this.fSelectedCladeList = null; this.notifyTree2DPanelChangeListeners( new Tree2DPanelChangeEvent(this, Tree2DPanelChangeEvent.ITEM_SELECTED)); } return; } if (rightButton) { this.fSelectedCladeList = new LinkedList<Element>(); this.fSelectedCladeList.add(elem); this.notifyTree2DPanelChangeListeners( new Tree2DPanelChangeEvent(this, Tree2DPanelChangeEvent.ITEM_SELECTED)); } else { /** Unselect every thing and add only this one. */ this.fSelectedCladeList.clear(); this.fSelectedCladeList.add(elem); /** Now show a CladeEditorDialog */ CladeEditorDialog.showDialog(this, elem); } } else { /** In time axis area */ } }
From source file:com.projity.pm.graphic.graph.GraphInteractor.java
public void mousePressed(MouseEvent e) { if (isReadOnly()) return;/*from w w w .j ava 2 s. co m*/ if (SwingUtilities.isRightMouseButton(e)) { if (popup != null) popup.show(getGraph(), e.getX(), e.getY()); } else { if (selected == null) return; if (isMove()) { selection = false; x0 = e.getX(); y0 = e.getY(); drawBarShadow(x0, y0, true); } else if (isDirectAction()) { executeAction(e.getX(), e.getY()); state = NOTHING_SELECTED; //select(e.getX(),e.getY()); //TODO commented to avoid second action when spliting } } }
From source file:com.net2plan.gui.tools.GUINetworkDesign.java
@Override public void configure(JPanel contentPane) { this.currentNetPlan = new NetPlan(); BidiMap<NetworkLayer, Integer> mapLayer2VisualizationOrder = new DualHashBidiMap<>(); Map<NetworkLayer, Boolean> layerVisibilityMap = new HashMap<>(); for (NetworkLayer layer : currentNetPlan.getNetworkLayers()) { mapLayer2VisualizationOrder.put(layer, mapLayer2VisualizationOrder.size()); layerVisibilityMap.put(layer, true); }/* w w w. j av a 2 s .co m*/ this.vs = new VisualizationState(currentNetPlan, mapLayer2VisualizationOrder, layerVisibilityMap, MAXSIZEUNDOLISTPICK); topologyPanel = new TopologyPanel(this, JUNGCanvas.class); JPanel leftPane = new JPanel(new BorderLayout()); JPanel logSection = configureLeftBottomPanel(); if (logSection == null) { leftPane.add(topologyPanel, BorderLayout.CENTER); } else { JSplitPane splitPaneTopology = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPaneTopology.setTopComponent(topologyPanel); splitPaneTopology.setBottomComponent(logSection); splitPaneTopology.addPropertyChangeListener(new ProportionalResizeJSplitPaneListener()); splitPaneTopology.setBorder(new LineBorder(contentPane.getBackground())); splitPaneTopology.setOneTouchExpandable(true); splitPaneTopology.setDividerSize(7); leftPane.add(splitPaneTopology, BorderLayout.CENTER); } contentPane.add(leftPane, "grow"); viewEditTopTables = new ViewEditTopologyTablesPane(GUINetworkDesign.this, new BorderLayout()); reportPane = new ViewReportPane(GUINetworkDesign.this, JSplitPane.VERTICAL_SPLIT); setCurrentNetPlanDoNotUpdateVisualization(currentNetPlan); Pair<BidiMap<NetworkLayer, Integer>, Map<NetworkLayer, Boolean>> res = VisualizationState .generateCanvasDefaultVisualizationLayerInfo(getDesign()); vs.setCanvasLayerVisibilityAndOrder(getDesign(), res.getFirst(), res.getSecond()); /* Initialize the undo/redo manager, and set its initial design */ this.undoRedoManager = new UndoRedoManager(this, MAXSIZEUNDOLISTCHANGES); this.undoRedoManager.addNetPlanChange(); onlineSimulationPane = new OnlineSimulationPane(this); executionPane = new OfflineExecutionPanel(this); whatIfAnalysisPane = new WhatIfAnalysisPane(this); // Closing windows WindowUtils.clearFloatingWindows(); final JTabbedPane tabPane = new JTabbedPane(); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.network), viewEditTopTables); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.offline), executionPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.online), onlineSimulationPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.whatif), whatIfAnalysisPane); tabPane.add(WindowController.WindowToTab.getTabName(WindowController.WindowToTab.report), reportPane); // Installing customized mouse listener MouseListener[] ml = tabPane.getListeners(MouseListener.class); for (int i = 0; i < ml.length; i++) { tabPane.removeMouseListener(ml[i]); } // Left click works as usual, right click brings up a pop-up menu. tabPane.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { JTabbedPane tabPane = (JTabbedPane) e.getSource(); int tabIndex = tabPane.getUI().tabForCoordinate(tabPane, e.getX(), e.getY()); if (tabIndex >= 0 && tabPane.isEnabledAt(tabIndex)) { if (tabIndex == tabPane.getSelectedIndex()) { if (tabPane.isRequestFocusEnabled()) { tabPane.requestFocus(); tabPane.repaint(tabPane.getUI().getTabBounds(tabPane, tabIndex)); } } else { tabPane.setSelectedIndex(tabIndex); } if (!tabPane.isEnabled() || SwingUtilities.isRightMouseButton(e)) { final JPopupMenu popupMenu = new JPopupMenu(); final JMenuItem popWindow = new JMenuItem("Pop window out"); popWindow.addActionListener(e1 -> { final int selectedIndex = tabPane.getSelectedIndex(); final String tabName = tabPane.getTitleAt(selectedIndex); final JComponent selectedComponent = (JComponent) tabPane.getSelectedComponent(); // Pops up the selected tab. final WindowController.WindowToTab windowToTab = WindowController.WindowToTab .parseString(tabName); if (windowToTab != null) { switch (windowToTab) { case offline: WindowController.buildOfflineWindow(selectedComponent); WindowController.showOfflineWindow(true); break; case online: WindowController.buildOnlineWindow(selectedComponent); WindowController.showOnlineWindow(true); break; case whatif: WindowController.buildWhatifWindow(selectedComponent); WindowController.showWhatifWindow(true); break; case report: WindowController.buildReportWindow(selectedComponent); WindowController.showReportWindow(true); break; default: return; } } tabPane.setSelectedIndex(0); }); // Disabling the pop up button for the network state tab. if (WindowController.WindowToTab.parseString(tabPane .getTitleAt(tabPane.getSelectedIndex())) == WindowController.WindowToTab.network) { popWindow.setEnabled(false); } popupMenu.add(popWindow); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } }); // Building windows WindowController.buildTableControlWindow(tabPane); WindowController.showTablesWindow(false); addAllKeyCombinationActions(); updateVisualizationAfterNewTopology(); }
From source file:org.adempiere.apps.graph.PerformanceIndicator.java
/************************************************************************** * Mouse Clicked/* ww w . j a v a2 s . com*/ * @param e mouse event */ public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) fireActionPerformed(e); if (SwingUtilities.isRightMouseButton(e)) popupMenu.show((Component) e.getSource(), e.getX(), e.getY()); }
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
public void fileTableClicked(FileObjectTableModel fileObjectTableModel, JTableX<FileObject> table, MouseEvent e) {/*w w w. j av a 2s. com*/ int row = table.convertRowIndexToModel(table.rowAtPoint(e.getPoint())); //int column = table.convertColumnIndexToModel(table.columnAtPoint(e.getPoint())); final Collection<FileObject> selectedFileObjects = table.getSelectedObjects(); final FileObject f = fileObjectTableModel.getRowObjects().get(row); if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu m = new JPopupMenu(); { JMenuItem menuitem = new JMenuItem("ffnen"); menuitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openFile(f); } }); m.add(menuitem); } { JMenuItem menuitem = new JMenuItem("Ordner ffnen"); menuitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openFolder(f); } }); m.add(menuitem); } { JMenuItem menuitem = new JMenuItem("Herunterladen (ber SOAP)"); menuitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { downloadFiles(selectedFileObjects, DownloadMethod.WEBSERVICE); } }); m.add(menuitem); } { JMenuItem menuitem = new JMenuItem("Herunterladen (ber WEBDAV)"); menuitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!syncService.getIliasSoapService().isWebdavAuthenticationActive()) { syncService.getIliasSoapService().enableWebdavAuthentication( mainFrame.getFieldLogin().getText(), mainFrame.getFieldPassword().getPassword()); } downloadFiles(selectedFileObjects, DownloadMethod.WEBDAV); } }); m.add(menuitem); } { JMenuItem menuitem = new JMenuItem("In Ilias ffnen"); menuitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { openInIlias(f); } }); m.add(menuitem); } { m.add(new JSeparator()); } { JCheckBoxMenuItem menuitem = new JCheckBoxMenuItem("Ignorieren"); menuitem.setSelected(iliasProperties.getBlockedFiles().contains(f.getRefId())); menuitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { switchIgnoreState(selectedFileObjects); } }); m.add(menuitem); } { m.add(new JSeparator()); } { JMenuItem menuitem = new JMenuItem("Fehler anzeigen"); menuitem.setEnabled(f.getException() != null); menuitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showError("Fehler bei " + f.getTargetFile().getAbsolutePath(), f.getException()); } }); m.add(menuitem); } m.show(table, e.getX(), e.getY()); } if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() > 1) { openFile(f); } }
From source file:ucar.unidata.idv.control.chart.PlotWrapper.java
/** * Hook to intercept these calls on the chart * * @param event The event/*w ww . j av a 2 s . co m*/ * * @return Was this event handled by the ChartWrapper */ public boolean chartPanelMouseDragged(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { return EVENT_DONTPASSON; } return EVENT_PASSON; }
From source file:com.projity.pm.graphic.spreadsheet.SpreadSheet.java
public void setModel(SpreadSheetModel spreadSheetModel, SpreadSheetColumnModel spreadSheetColumnModel) { makeCustomTableHeader(spreadSheetColumnModel); TableModel oldModel = getModel(); setModel(spreadSheetModel);/*from w w w .ja v a 2 s . c o m*/ if (spreadSheetColumnModel != null) { //System.out.println("creating new ColModel"); setColumnModel(spreadSheetColumnModel); selection = new SpreadSheetSelectionModel(this); selection.setRowSelection(new SpreadSheetListSelectionModel(selection, true)); selection.setColumnSelection(new SpreadSheetListSelectionModel(selection, false)); setSelectionModel(selection.getRowSelection()); createDefaultColumnsFromModel(spreadSheetModel.getFieldArray()); //Consume memory getColumnModel().setSelectionModel(selection.getColumnSelection()); } registerEditors(); //Consume memory initRowHeader(spreadSheetModel); initModel(); initListeners(); GraphicConfiguration config = GraphicConfiguration.getInstance(); //fix for substance setTableHeader(createDefaultTableHeader()); JTableHeader header = getTableHeader(); header.setPreferredSize( new Dimension((int) header.getPreferredSize().getWidth(), config.getColumnHeaderHeight())); header.addMouseListener(new HeaderMouseListener(this)); addMouseListener(new MouseAdapter() { // Cursor oldCursor = null; // public void mouseEntered(MouseEvent e) { // Point p = e.getPoint(); // int col = columnAtPoint(p); // Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); // System.out.println("mouse entered field " + field); // if (field != null && field.isHyperlink()) { // oldCursor = getCursor(); // setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // System.out.println("setting new cursor to " + Cursor.getPredefinedCursor(Cursor.HAND_CURSOR) + " old is " + oldCursor); // } else // super.mouseEntered(e); // // } // // public void mouseExited(MouseEvent e) { // Point p = e.getPoint(); // int col = columnAtPoint(p); // Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); // System.out.println("mouse exited field " + field); // if (field != null && field.isHyperlink()) { // setCursor(oldCursor); // System.out.println("setting old cursor to " + oldCursor); // e.consume(); // } else // super.mouseEntered(e); // } public void mousePressed(MouseEvent e) { // changed to mousePressed instead of mouseClicked() for snappier handling 17/5/04 hk Point p = e.getPoint(); int row = rowAtPoint(p); int col = columnAtPoint(p); SpreadSheetPopupMenu popup = getPopup(); if (SwingUtilities.isLeftMouseButton(e)) { SpreadSheetColumnModel columnModel = (SpreadSheetColumnModel) getColumnModel(); Field field = ((SpreadSheetModel) getModel()).getFieldInNonTranslatedColumn(col + 1); SpreadSheetModel model = (SpreadSheetModel) getModel(); if (field.isNameField()) { // if (col == columnModel.getNameIndex()) { GraphicNode node = model.getNode(row); if (isOnIcon(e)) { if (model.getCellProperties(node).isCompositeIcon()) { finishCurrentOperations(); selection.getRowSelection().clearSelection(); boolean change = true; if (!node.isFetched()) // for subprojects change = node.fetch(); if (change) model.changeCollapsedState(row); e.consume(); // prevent dbl click treatment below // because editor may have already been // installed we // have to update its collapsed state // updateNameCellEditor(node); // editCellAt(row,model.findGraphicNodeRow(node)); } } } else if (field != null && field.isHyperlink()) { Hyperlink link = (Hyperlink) model.getValueAt(row, col + 1); if (link != null) { BrowserControl.displayURL(link.getAddress()); e.consume(); // prevent dbl click treatment below } } if (!e.isConsumed()) { if (e.getClickCount() == 2) // if above code didn't treat and is dbl click doDoubleClick(row, col); else doClick(row, col); } } else if (popup != null && SwingUtilities.isRightMouseButton(e)) { // e.isPopupTrigger() can be used too // selection.getRowSelection().clearSelection(); // selection.getRowSelection().addSelectionInterval(row, row); popup.setRow(row); popup.setCol(col); popup.show(SpreadSheet.this, e.getX(), e.getY()); } } }); if (oldModel != spreadSheetModel && oldModel instanceof CommonSpreadSheetModel) ((CommonSpreadSheetModel) getModel()).getCache().removeNodeModelListener(this); spreadSheetModel.getCache().addNodeModelListener(this); // getColumnModel().addColumnModelListener(new TableColumnModelListener(){ // public void columnAdded(TableColumnModelEvent e) { // // TODO Auto-generated method stub // // } // public void columnMarginChanged(ChangeEvent e) { // // TODO Auto-generated method stub // // } // public void columnMoved(TableColumnModelEvent e) { // // TODO Auto-generated method stub // // } // public void columnRemoved(TableColumnModelEvent e) { // // TODO Auto-generated method stub // // } // public void columnSelectionChanged(ListSelectionEvent e) { // System.out.println(((e.getValueIsAdjusting())?"lse=":"LSE=")+e.getFirstIndex()+", "+e.getLastIndex()); // SpreadSheet.this.revalidate(); // //SpreadSheet.this.paintImmediately(0, 0, getWidth(), GraphicConfiguration.getInstance().getColumnHeaderHeight()); // } // }); }
From source file:com.peter.mavenrunner.MavenRunnerTopComponent.java
private void projectTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_projectTreeMouseClicked if (SwingUtilities.isRightMouseButton(evt)) { // int row = projectTree.getClosestRowForLocation(evt.getX(), evt.getY()); // projectTree.setSelectionRow(row); MyTreeNode node = (MyTreeNode) projectTree.getSelectionPath().getLastPathComponent(); if (!isDebug) { if (node.type.equals("project")) { addGoalMenuItem.setEnabled(true); editGoalMenuItem.setEnabled(false); deleteGoalMenuItem.setEnabled(false); runMenuItem.setEnabled(false); } else if (node.type.equals("goal")) { addGoalMenuItem.setEnabled(false); editGoalMenuItem.setEnabled(true); deleteGoalMenuItem.setEnabled(true); runMenuItem.setEnabled(true); } else if (node.type.equals("default goal")) { addGoalMenuItem.setEnabled(false); editGoalMenuItem.setEnabled(false); deleteGoalMenuItem.setEnabled(false); runMenuItem.setEnabled(true); }//w w w . ja va 2s.c o m } treePopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } else if (evt.getClickCount() == 2) { runGoal(); } }
From source file:net.minelord.gui.panes.IRCPane.java
public void connected() { SwingUtilities.invokeLater(new Runnable() { @Override//from w ww. j a v a2 s.com public void run() { scroller.setBounds(scrollerWithoutTopicWithUserlist); scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); status = "Connected"; client.connectAlertListener(); TitledBorder title = BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Connected"); title.setTitleJustification(TitledBorder.RIGHT); userList = new JList(client.getUserList().toArray()); userScroller = new JScrollPane(userList); userScroller.setBounds(userScrollerWithoutTopic); userList.setBounds(0, 0, 210, 250); userList.setBackground(Color.gray); userList.setForeground(Color.gray.darker().darker().darker()); userScroller.setBorder(title); userScroller.getVerticalScrollBar().setUnitIncrement(5); scroller.setBorder(BorderFactory .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "")); if (client.getTopic().trim().length() > 0) { topic = new JLabel(client.getTopic()); scroller.setBounds(scrollerWithTopicWithUserlist); userScroller.setBounds(userScrollWithTopic); userList.setBounds(0, 0, 210, 225); title = BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Topic set by " + client.getTopicSetter()); title.setTitleJustification(TitledBorder.LEFT); topic.setBorder(title); topic.setBounds(topicBounds); add(topic); } else topic = new JLabel(""); input.setEnabled(true); input.requestFocus(); final JPopupMenu userPopup = new JPopupMenu(); JLabel breakLine = new JLabel("____"); JLabel help = new JLabel("Politely ask for help"); JLabel message = new JLabel("Message"); JLabel sortNormal = new JLabel("Normal"); JLabel sortAlphabetical = new JLabel("Alphabetical"); JLabel sortRoles = new JLabel("Roles"); help.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { userPopup.setVisible(false); sendMessage("/me kicks " + userList.getModel().getElementAt(userList.getSelectedIndex()) + " in the shins"); sendMessage("I need help you pleb"); } public void mouseReleased(MouseEvent e) { } }); message.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); input.setText("/msg " + userList.getModel().getElementAt(userList.getSelectedIndex()) + (input.getText().length() > 0 && input.getText().charAt(0) == ' ' ? input.getText() : " " + input.getText())); input.select(0, ("/msg " + userList.getModel().getElementAt(userList.getSelectedIndex()) + (input.getText().length() > 0 && input.getText().charAt(0) == ' ' ? "" : " ")) .length()); input.requestFocus(); } }); sortNormal.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); updateUserList(0); } }); sortAlphabetical.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); updateUserList(1); } }); sortRoles.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { userPopup.setVisible(false); updateUserList(2); } }); userPopup.add(help); userPopup.add(message); userPopup.add(breakLine); userPopup.add(sortNormal); userPopup.add(sortAlphabetical); userPopup.add(sortRoles); userList.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { check(e); } public void mouseReleased(MouseEvent e) { check(e); } public void check(MouseEvent e) { userList.setSelectedIndex(userList.locationToIndex(e.getPoint())); userPopup.show(userList, e.getX(), e.getY()); } }); add(userScroller); final JPopupMenu textPopup = new JPopupMenu(); JLabel copy = new JLabel("Copy"); copy.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent paramMouseEvent) { textPopup.setVisible(false); if (text.getSelectedText() != null && text.getSelectedText().length() != 0) { StringSelection selection = new StringSelection(text.getSelectedText()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(selection, selection); } } }); textPopup.add(copy); text.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) textPopup.show(text, e.getX(), e.getY()); } }); add(userScroller); repaint(); } }); }