List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:com.anrisoftware.prefdialog.miscswing.components.menu.PopupMenuComponent.java
private void createComponentMouseListener() { componentMouseListener = new MouseAdapter() { @Override//w w w. ja v a 2 s . c om public void mousePressed(MouseEvent e) { if (!mouseFilter.allow(e)) { return; } if (alreadyShowingPopup) { showPopup = false; } } @Override public void mouseReleased(MouseEvent e) { if (!mouseFilter.allow(e)) { return; } if (showPopup) { showPopup(e.getPoint()); } else { showPopup = true; } } }; }
From source file:autoGui.RegisterPagePanel.java
RegisterPagePanel(JFrame parent, MouseAdapter backHandler) { parent.getContentPane().add(RegisterPage, "name_22846752421143"); RegisterPage.setLayout(null);/*from ww w . j a va 2 s . c o m*/ //System.out.println(parent.getContentPane()); RegisterPage.setBounds(100, 100, 1036, 608); email = new JTextField(); email.setBounds(642, 87, 116, 22); RegisterPage.add(email); email.setColumns(10); JLabel lblEmail = new JLabel("Email*"); lblEmail.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblEmail.setBounds(506, 89, 56, 16); RegisterPage.add(lblEmail); JLabel lblNewLabel = new JLabel("Password*"); lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel.setBounds(506, 132, 71, 16); RegisterPage.add(lblNewLabel); JLabel lblFirstName = new JLabel("First Name*"); lblFirstName.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblFirstName.setBounds(141, 87, 88, 16); RegisterPage.add(lblFirstName); firstName = new JTextField(); firstName.setBounds(241, 85, 142, 22); RegisterPage.add(firstName); firstName.setColumns(10); JLabel lblNewLabel_1 = new JLabel("Middle Name"); lblNewLabel_1.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel_1.setBounds(141, 132, 88, 16); RegisterPage.add(lblNewLabel_1); middleName = new JTextField(); middleName.setBounds(241, 129, 142, 22); RegisterPage.add(middleName); middleName.setColumns(10); JLabel lblNewLabel_2 = new JLabel("Last Name*"); lblNewLabel_2.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel_2.setBounds(141, 174, 88, 16); RegisterPage.add(lblNewLabel_2); lastName = new JTextField(); lastName.setBounds(241, 172, 142, 22); RegisterPage.add(lastName); lastName.setColumns(10); JLabel lblPersonalInformation = new JLabel("Personal Information"); lblPersonalInformation.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblPersonalInformation.setBounds(86, 33, 159, 27); RegisterPage.add(lblPersonalInformation); JLabel lblContactInformation = new JLabel("Contact Information"); lblContactInformation.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblContactInformation.setBounds(459, 33, 175, 27); RegisterPage.add(lblContactInformation); JLabel lblPhoneNumber = new JLabel("Phone*"); lblPhoneNumber.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblPhoneNumber.setBounds(506, 217, 71, 16); RegisterPage.add(lblPhoneNumber); phone = new JTextField(); phone.setBounds(642, 215, 116, 22); RegisterPage.add(phone); phone.setColumns(10); password = new JPasswordField(); password.setBounds(642, 130, 116, 22); RegisterPage.add(password); JButton btnBack_5 = new JButton("Back"); btnBack_5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); btnBack_5.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (lastPage == 6) { lastPage = 4; } RegisterPage.setVisible(false); parent.getContentPane().getComponent(lastPage).setVisible(true); backHandler.mouseClicked(e); } }); btnBack_5.setBounds(12, 525, 97, 25); RegisterPage.add(btnBack_5); JButton btnExit_6 = new JButton("Exit"); btnExit_6.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { parent.setVisible(false); parent.dispose(); } }); btnExit_6.setBounds(909, 525, 97, 25); RegisterPage.add(btnExit_6); JLabel lblAddress = new JLabel("Address*"); lblAddress.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblAddress.setBounds(141, 217, 56, 16); RegisterPage.add(lblAddress); address = new JTextField(); address.setBounds(241, 215, 142, 22); RegisterPage.add(address); address.setColumns(10); address2 = new JTextField(); address2.setBounds(241, 260, 142, 22); RegisterPage.add(address2); address2.setColumns(10); JLabel lblCity = new JLabel("City*"); lblCity.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblCity.setBounds(141, 308, 56, 16); RegisterPage.add(lblCity); city = new JTextField(); city.setBounds(241, 306, 142, 22); RegisterPage.add(city); city.setColumns(10); JLabel lblAddress_1 = new JLabel("Address 2"); lblAddress_1.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblAddress_1.setBounds(141, 263, 77, 16); RegisterPage.add(lblAddress_1); JLabel lblZip = new JLabel("Zip*"); lblZip.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblZip.setBounds(141, 402, 56, 16); RegisterPage.add(lblZip); zip = new JTextField(); zip.setBounds(241, 400, 142, 22); RegisterPage.add(zip); zip.setColumns(10); JLabel lblState = new JLabel("State*"); lblState.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblState.setBounds(141, 355, 56, 16); RegisterPage.add(lblState); state = new JTextField(); state.setBounds(241, 353, 142, 22); RegisterPage.add(state); state.setColumns(10); JLabel lblRequired = new JLabel("* = required"); lblRequired.setBounds(301, 39, 88, 16); RegisterPage.add(lblRequired); JLabel lblLicenseInfo = new JLabel("License Information"); lblLicenseInfo.setFont(new Font("Tahoma", Font.PLAIN, 16)); lblLicenseInfo.setBounds(459, 257, 148, 27); RegisterPage.add(lblLicenseInfo); JLabel lblNumber = new JLabel("Number*"); lblNumber.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNumber.setBounds(506, 310, 71, 16); RegisterPage.add(lblNumber); license = new JTextField(); license.setBounds(642, 306, 116, 22); RegisterPage.add(license); license.setColumns(10); JLabel lblDateOfBirth = new JLabel("Date of Birth*"); lblDateOfBirth.setBounds(506, 372, 88, 16); RegisterPage.add(lblDateOfBirth); birthMonth = new JComboBox(); birthMonth.setModel(new DefaultComboBoxModel(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })); birthMonth.setBounds(642, 370, 71, 22); RegisterPage.add(birthMonth); birthDay = new JComboBox(); birthDay.setModel(new DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" })); birthDay.setBounds(708, 370, 62, 22); RegisterPage.add(birthDay); List<Integer> years = new ArrayList<Integer>(); for (int i = 1915; i <= 2015; ++i) { years.add(i); } birthYear = new JComboBox(years.toArray()); birthYear.setBounds(769, 370, 97, 22); RegisterPage.add(birthYear); JButton btnContinue = new JButton("Continue ->"); btnContinue.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { register(parent); } }); btnContinue.setBounds(674, 428, 133, 34); RegisterPage.add(btnContinue); JLabel lblConfirmPassword = new JLabel("Confirm Password*"); lblConfirmPassword.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblConfirmPassword.setBounds(506, 174, 121, 16); RegisterPage.add(lblConfirmPassword); repassword = new JPasswordField(); repassword.setBounds(642, 172, 116, 22); RegisterPage.add(repassword); JLabel lblNewLabel_3 = new JLabel("Credit card #*"); lblNewLabel_3.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblNewLabel_3.setBounds(141, 448, 93, 16); RegisterPage.add(lblNewLabel_3); cardNumber = new JTextField(); cardNumber.setBounds(241, 443, 142, 28); RegisterPage.add(cardNumber); cardNumber.setColumns(10); JLabel lblCardExp = new JLabel("Card exp*"); lblCardExp.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblCardExp.setBounds(141, 496, 82, 16); RegisterPage.add(lblCardExp); cardExpMonth = new JComboBox(); cardExpMonth.setModel(new DefaultComboBoxModel(new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" })); cardExpMonth.setBounds(238, 493, 77, 27); RegisterPage.add(cardExpMonth); cardExpDay = new JComboBox(); cardExpDay.setModel(new DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" })); cardExpDay.setBounds(312, 493, 71, 27); RegisterPage.add(cardExpDay); JLabel lblLicenseState = new JLabel("License state*"); lblLicenseState.setFont(new Font("Tahoma", Font.PLAIN, 14)); lblLicenseState.setBounds(506, 338, 88, 16); RegisterPage.add(lblLicenseState); licenseState = new JTextField(); licenseState.setBounds(642, 333, 116, 28); RegisterPage.add(licenseState); licenseState.setColumns(10); RegisterPage.setVisible(false); }
From source file:Main.java
public Main() { super(new GridLayout(1, 0)); final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; final Object[][] data = { { "Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false) }, { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) }, { "Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false) }, { "Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true) }, { "Philip", "Milne", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/*from w ww . j a va2 s. c o m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (ALLOW_ROW_SELECTION) { // true by default ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No rows are selected."); } else { int selectedRow = lsm.getMinSelectionIndex(); System.out.println("Row " + selectedRow + " is now selected."); } } }); } else { table.setRowSelectionAllowed(false); } if (ALLOW_COLUMN_SELECTION) { // false by default if (ALLOW_ROW_SELECTION) { // We allow both row and column selection, which // implies that we *really* want to allow individual // cell selection. table.setCellSelectionEnabled(true); } table.setColumnSelectionAllowed(true); ListSelectionModel colSM = table.getColumnModel().getSelectionModel(); colSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No columns are selected."); } else { int selectedCol = lsm.getMinSelectionIndex(); System.out.println("Column " + selectedCol + " is now selected."); } } }); } if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // Add the scroll pane to this panel. add(scrollPane); }
From source file:iqq.app.ui.manager.MainManager.java
public void enableTray() { if (SystemTray.isSupported() && tray == null) { menu = new PopupMenu(); MenuItem restore = new MenuItem(" ? "); restore.addActionListener(new ActionListener() { @Override//from w ww. j a v a2 s .c o m public void actionPerformed(ActionEvent e) { show(); } }); MenuItem exit = new MenuItem(" ? "); exit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); menu.add(restore); menu.addSeparator(); menu.add(exit); if (SystemUtils.isMac()) { defaultImage = skinService.getIconByKey("window/titleWIconBlack").getImage(); } else { defaultImage = mainFrame.getIconImage(); } blankImage = new BufferedImage(32, 32, BufferedImage.TYPE_INT_ARGB); tray = SystemTray.getSystemTray(); icon = new TrayIcon(defaultImage, "IQQ"); icon.setImageAutoSize(true); if (!SystemUtils.isMac()) { icon.setPopupMenu(menu); } try { tray.add(icon); icon.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { logger.debug("MouseEvent " + e.getButton() + " " + e.getClickCount()); //?? if (e.getButton() == MouseEvent.BUTTON1) { if (flashOwner != null) { Map<String, Object> data = (Map<String, Object>) flashOwner.getAttachment(); if (data != null && data.containsKey("action") && data.get("action").equals("ADD_BUDDY_REQUEST")) { IMContext.getBean(FrameManager.class).showGetFriendRequest((IMBuddy) flashOwner, data.get("buddy_request_id").toString()); eventService.broadcast(new UIEvent(UIEventType.FLASH_USER_STOP, flashOwner)); return; } else { // ? chatManager.addChat(flashOwner); } } else { show(); } } } }); } catch (AWTException e) { logger.error("SystemTray add icon.", e); } } }
From source file:SimpleTableSelectionDemo.java
public SimpleTableSelectionDemo() { super(new GridLayout(1, 0)); final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; final Object[][] data = { { "Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false) }, { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) }, { "Kathy", "Walrath", "Knitting", new Integer(2), new Boolean(false) }, { "Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true) }, { "Philip", "Milne", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/*from w w w .ja v a 2s .c om*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (ALLOW_ROW_SELECTION) { // true by default ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No rows are selected."); } else { int selectedRow = lsm.getMinSelectionIndex(); System.out.println("Row " + selectedRow + " is now selected."); } } }); } else { table.setRowSelectionAllowed(false); } if (ALLOW_COLUMN_SELECTION) { // false by default if (ALLOW_ROW_SELECTION) { // We allow both row and column selection, which // implies that we *really* want to allow individual // cell selection. table.setCellSelectionEnabled(true); } table.setColumnSelectionAllowed(true); ListSelectionModel colSM = table.getColumnModel().getSelectionModel(); colSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No columns are selected."); } else { int selectedCol = lsm.getMinSelectionIndex(); System.out.println("Column " + selectedCol + " is now selected."); } } }); } if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // Add the scroll pane to this panel. add(scrollPane); }
From source file:components.SimpleTableSelectionDemo.java
public SimpleTableSelectionDemo() { super(new GridLayout(1, 0)); final String[] columnNames = { "First Name", "Last Name", "Sport", "# of Years", "Vegetarian" }; final Object[][] data = { { "Kathy", "Smith", "Snowboarding", new Integer(5), new Boolean(false) }, { "John", "Doe", "Rowing", new Integer(3), new Boolean(true) }, { "Sue", "Black", "Knitting", new Integer(2), new Boolean(false) }, { "Jane", "White", "Speed reading", new Integer(20), new Boolean(true) }, { "Joe", "Brown", "Pool", new Integer(10), new Boolean(false) } }; final JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);/*from www .j a v a 2 s .co m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); if (ALLOW_ROW_SELECTION) { // true by default ListSelectionModel rowSM = table.getSelectionModel(); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No rows are selected."); } else { int selectedRow = lsm.getMinSelectionIndex(); System.out.println("Row " + selectedRow + " is now selected."); } } }); } else { table.setRowSelectionAllowed(false); } if (ALLOW_COLUMN_SELECTION) { // false by default if (ALLOW_ROW_SELECTION) { //We allow both row and column selection, which //implies that we *really* want to allow individual //cell selection. table.setCellSelectionEnabled(true); } table.setColumnSelectionAllowed(true); ListSelectionModel colSM = table.getColumnModel().getSelectionModel(); colSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { //Ignore extra messages. if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { System.out.println("No columns are selected."); } else { int selectedCol = lsm.getMinSelectionIndex(); System.out.println("Column " + selectedCol + " is now selected."); } } }); } if (DEBUG) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { printDebugData(table); } }); } //Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); //Add the scroll pane to this panel. add(scrollPane); }
From source file:uk.co.markfrimston.tasktree.Main.java
public Main(TaskTree taskTree) { super();/*from w w w .ja va2 s . c o m*/ this.taskTree = taskTree; this.setTitle("Task Tree"); this.setSize(new Dimension(300, 500)); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel quickInPanel = new JPanel(new BorderLayout()); this.quickIn = new JTextArea(); this.quickIn.addKeyListener(new KeyAdapter() { public void keyReleased(KeyEvent arg0) { if (arg0.getKeyCode() == KeyEvent.VK_ENTER) { String newText = quickIn.getText().trim(); if (newText != null && newText.length() > 0) { addTask(Main.this.taskTree.getRoot(), 0, newText, true); try { Main.this.taskTree.changesMade(); } catch (Exception e) { error(e.getMessage()); } } quickIn.setText(""); } } }); this.quickIn.setPreferredSize(new Dimension(300, 75)); this.quickIn.setBorder(BorderFactory.createTitledBorder("Quick Input")); quickInPanel.add(this.quickIn, BorderLayout.CENTER); this.syncButton = new JButton("Sync"); this.syncButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new SyncThread(Main.this).start(); } }); quickInPanel.add(this.syncButton, BorderLayout.EAST); this.getContentPane().add(quickInPanel, BorderLayout.NORTH); this.tree = new JTree(taskTree.getTreeModel()); DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object newVal = htmlFilter(String.valueOf(node.getUserObject())); if (node.getChildCount() > 0 && !tree.isExpanded(new TreePath(node.getPath()))) { DefaultMutableTreeNode firstLeaf = (DefaultMutableTreeNode) node.getFirstLeaf(); newVal = htmlFilter(String.valueOf(node.getUserObject())) + " <span style='color:silver;font-style:italic'>" + "(" + String.valueOf(firstLeaf.getUserObject()) + ")</span>"; } newVal = "<html>" + newVal + "</html>"; return super.getTreeCellRendererComponent(tree, newVal, selected, expanded, leaf, row, hasFocus); } }; ImageIcon bulletIcon = new ImageIcon(Main.class.getResource("bullet.gif")); renderer.setLeafIcon(bulletIcon); renderer.setOpenIcon(bulletIcon); renderer.setClosedIcon(bulletIcon); renderer.setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0)); this.tree.setCellRenderer(renderer); this.tree.setRootVisible(false); this.tree.setShowsRootHandles(true); this.tree.addMouseListener(new MouseAdapter() { protected void doSelectRow(MouseEvent arg0) { int row = tree.getRowForLocation(arg0.getX(), arg0.getY()); if (row != -1) { tree.setSelectionRow(row); if (arg0.isPopupTrigger()) { popup.show(tree, arg0.getX(), arg0.getY()); } } } public void mousePressed(MouseEvent arg0) { doSelectRow(arg0); } public void mouseReleased(MouseEvent arg0) { doSelectRow(arg0); } }); JScrollPane treeScroll = new JScrollPane(tree); treeScroll.setBorder(BorderFactory.createTitledBorder("Task List")); this.getContentPane().add(treeScroll, BorderLayout.CENTER); this.popup = new JPopupMenu(); JMenuItem addBefore = new JMenuItem("Add Before"); addBefore.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected); promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addBefore); JMenuItem addAfter = new JMenuItem("Add After"); addAfter.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = parent.getIndex(selected) + 1; promptAndInsert(parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(addAfter); JMenuItem addNested = new JMenuItem("Add Nested"); addNested.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); int pos = selected.getChildCount(); promptAndInsert(selected, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { ex.getMessage(); } } }); this.popup.add(addNested); this.popup.add(new JSeparator()); JMenuItem moveTop = new JMenuItem("Move to Top"); moveTop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, 0); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveTop); JMenuItem moveUp = new JMenuItem("Move Up"); moveUp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.max(parent.getIndex(selected) - 1, 0); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveUp); JMenuItem moveDown = new JMenuItem("Move Down"); moveDown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); int pos = Math.min(parent.getIndex(selected) + 1, parent.getChildCount() - 1); moveTask(selected, parent, pos); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveDown); JMenuItem moveBottom = new JMenuItem("Move to Bottom"); moveBottom.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selected.getParent(); moveTask(selected, parent, parent.getChildCount() - 1); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(moveBottom); this.popup.add(new JSeparator()); JMenuItem rename = new JMenuItem("Edit"); rename.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DefaultMutableTreeNode selected = getSelectedNode(); String newText = prompt((String) selected.getUserObject()); if (newText != null && newText.length() > 0) { selected.setUserObject(newText); Main.this.taskTree.getTreeModel().reload(selected); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } } }); this.popup.add(rename); JMenuItem delete = new JMenuItem("Delete"); delete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { promptAndRemove(getSelectedNode()); try { Main.this.taskTree.changesMade(); } catch (Exception ex) { error(ex.getMessage()); } } }); this.popup.add(delete); this.setVisible(true); loadConfig(); load(); syncButton.setVisible(this.taskTree.hasSyncCapability()); }
From source file:CubaHSQLDBServer.java
private void addCopyPopup(final JTextArea source) { final JPopupMenu popup = new JPopupMenu(); popup.add(new AbstractAction("Copy to clipboard") { @Override/* w ww. j a v a 2 s .c o m*/ public void actionPerformed(ActionEvent e) { StringSelection contents = new StringSelection(source.getText()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, contents); } }); source.add(popup); source.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(source, e.getX(), e.getY()); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(source, e.getX(), e.getY()); } } }); }
From source file:StrokeTest.java
public StrokeComponent() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent event) { Point p = event.getPoint(); for (int i = 0; i < points.length; i++) { double x = points[i].getX() - SIZE / 2; double y = points[i].getY() - SIZE / 2; Rectangle2D r = new Rectangle2D.Double(x, y, SIZE, SIZE); if (r.contains(p)) { current = i;//from ww w .j a v a 2 s. c o m return; } } } public void mouseReleased(MouseEvent event) { current = -1; } }); addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent event) { if (current == -1) return; points[current] = event.getPoint(); repaint(); } }); points = new Point2D[3]; points[0] = new Point2D.Double(200, 100); points[1] = new Point2D.Double(100, 200); points[2] = new Point2D.Double(200, 200); current = -1; width = 8.0F; }
From source file:com.mirth.connect.client.ui.components.MirthTable.java
public void setMirthColumnControlEnabled(boolean enabled) { if (enabled) { if (tableSortAdapter == null) { tableSortAdapter = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { getColumnMenu().show(e.getComponent(), e.getX(), e.getY()); }/* ww w . j a v a2 s . c o m*/ } }; getTableHeader().addMouseListener(tableSortAdapter); } } else { if (tableSortAdapter != null) { getTableHeader().removeMouseListener(tableSortAdapter); tableSortAdapter = null; } } setColumnControlVisible(enabled); }