/** * A chat room was selected. Opens the chat room in the chat window. * * @param e the <tt>MouseEvent</tt> instance containing details of the event that has just * occurred. */ public void mousePressed(MouseEvent e) { // Select the object under the right button click. if ((e.getModifiers() & InputEvent.BUTTON2_MASK) != 0 || (e.getModifiers() & InputEvent.BUTTON3_MASK) != 0 || (e.isControlDown() && !e.isMetaDown())) { int ix = this.chatRoomList.rowAtPoint(e.getPoint()); if (ix != -1) { this.chatRoomList.setRowSelectionInterval(ix, ix); } } Object o = this.chatRoomsTableModel.getValueAt(this.chatRoomList.getSelectedRow()); Point selectedCellPoint = e.getPoint(); SwingUtilities.convertPointToScreen(selectedCellPoint, chatRoomList); if ((e.getModifiers() & InputEvent.BUTTON3_MASK) != 0) { JPopupMenu rightButtonMenu; if (o instanceof ChatRoomWrapper) rightButtonMenu = new ChatRoomRightButtonMenu((ChatRoomWrapper) o); else return; rightButtonMenu.setInvoker(this); rightButtonMenu.setLocation(selectedCellPoint); rightButtonMenu.setVisible(true); } }
@Override public void mouseClicked(MouseEvent e) { indexOfLabelPressed = -1; for (int i = 0; i < orderLabel.length; i++) { if (e.getSource() == orderLabel[i]) { indexOfLabelPressed = i; PointerInfo a = MouseInfo.getPointerInfo(); Point b = a.getLocation(); int x = (int) b.getX(); int y = (int) b.getY(); popup.setLocation(x, y); popup.setInvoker(popup); popup.setVisible(true); revalidate(); repaint(); } } if (e.getSource() == topPanelLabel) { indexOfLabelPressed = -2; } if (indexOfLabelPressed == -1) { okDiscountButton.setText("Deduct"); discountPopup.setLocation(700, 220); discountPopup.setInvoker(discountPopup); discountPopup.setVisible(true); itemDiscountPopupLabel.setText( "$" + finalModifier + " off with " + menuPanel.df.format((1 - finalPercentModifier) * 100) + "%" + " discount"); } else if (indexOfLabelPressed == -2) { // TODO resetAll(); } }
/** * Initializes a new <tt>MuteButton</tt> instance which is to mute the audio stream to a specific * <tt>Call</tt>. * * @param call the <tt>Call</tt> to be associated with the new instance and whose audio stream is * to be muted upon performing its action * @param iconImageID the icon image * @param pressedIconImageID the <tt>ImageID</tt> of the image to be used as the icon in the * pressed button state of the new instance * @param selected <tt>true</tt> if the new toggle button is to be initially selected; otherwise, * <tt>false</tt> * @param inSettingsPanel <tt>true</tt> when the button is used in a menu, to use different * background. */ public InputVolumeControlButton( Call call, ImageID iconImageID, ImageID pressedIconImageID, boolean inSettingsPanel, boolean selected) { super( call, inSettingsPanel, selected, iconImageID, pressedIconImageID, "service.gui.MUTE_BUTTON_TOOL_TIP"); this.mute = selected; volumeControl = getVolumeControl(); // Creates the menu that would contain the volume control component. sliderMenu = new VolumeControlSlider(volumeControl, JSlider.VERTICAL).getPopupMenu(); sliderMenu.setInvoker(this); addMouseListener( new MouseAdapter() { TimerTask timerTask; @Override public void mousePressed(MouseEvent mouseevent) { Timer timer = new Timer(); timerTask = new TimerTask() { @Override public void run() { showSliderMenu(); } }; timer.schedule(timerTask, 1000); } @Override public void mouseReleased(MouseEvent mouseevent) { if (!sliderMenuIsVisible) { if (timerTask != null) { timerTask.cancel(); } } else { setSelected(!isSelected()); } } }); }
/** * Shows the appropriate user interface that would allow the user to add the given * <tt>SourceUIContact</tt> to their contact list. * * @param contact the contact to add */ private void addContact(SourceUIContact contact) { SourceContact sourceContact = (SourceContact) contact.getDescriptor(); List<ContactDetail> details = sourceContact.getContactDetails(OperationSetPersistentPresence.class); int detailsCount = details.size(); if (detailsCount > 1) { JMenuItem addContactMenu = TreeContactList.createAddContactMenu((SourceContact) contact.getDescriptor()); JPopupMenu popupMenu = ((JMenu) addContactMenu).getPopupMenu(); // Add a title label. JLabel infoLabel = new JLabel(); infoLabel.setText( "<html><b>" + GuiActivator.getResources().getI18NString("service.gui.ADD_CONTACT") + "</b></html>"); popupMenu.insert(infoLabel, 0); popupMenu.insert(new Separator(), 1); popupMenu.setFocusable(true); popupMenu.setInvoker(treeContactList); Point location = new Point( addContactButton.getX(), addContactButton.getY() + addContactButton.getHeight()); SwingUtilities.convertPointToScreen(location, treeContactList); location.y = location.y + treeContactList.getPathBounds(treeContactList.getSelectionPath()).y; popupMenu.setLocation(location.x + 8, location.y - 8); popupMenu.setVisible(true); } else if (details.size() == 1) { TreeContactList.showAddContactDialog(details.get(0), sourceContact.getDisplayName()); } }
@Override public void actionPerformed(ActionEvent e) { String source = e.getActionCommand(); Object obj = e.getSource(); // popup buttons if (obj == removeButton) { midPanel.remove(orderLabel[indexOfLabelPressed]); popup.setVisible(false); itemCountOfLabel[indexOfLabelPressed] = 0; revalidate(); repaint(); setCost(); } else if (obj == cancelButton) { popup.setVisible(false); } else if (obj == discountButton) { discountPopup.setLocation(700, 220); discountPopup.setInvoker(discountPopup); discountPopup.setVisible(true); itemDiscountPopupLabel.setText( "Price: " + itemPriceOfLabel[indexOfLabelPressed] + " Discount: " + menuPanel.df.format(((1 - itemPriceModifier[indexOfLabelPressed]) * 100)) + "%"); } else if (obj == countButton) { countPopup.setLocation(700, 220); countPopup.setInvoker(countPopup); countPopup.setVisible(true); } // discount buttons if (indexOfLabelPressed != -1) { // if it is label okDiscountButton.setText("Set Price"); if (obj == discountButton0 || obj == discountButton1 || obj == discountButton2 || obj == discountButton3 || obj == discountButton4 || obj == discountButton5 || obj == discountButton6 || obj == discountButton7 || obj == discountButton8 || obj == discountButton9) { itemDiscountPopupString = itemDiscountPopupString + source; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } else if (obj == clearDiscountButton) { itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemCountPopupString); discountPopup.setVisible(false); } else if (obj == okDiscountButton) { if (itemDiscountPopupString == "") { itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); discountPopup.setVisible(false); } else { itemPriceOfLabel[indexOfLabelPressed] = Double.parseDouble(itemDiscountPopupString) / 100; discountPopup.setVisible(false); setLabelText(); setCost(); itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } } else if (obj == percentDiscountButton) { if (itemDiscountPopupString == "") { itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); discountPopup.setVisible(false); } else { itemPriceModifier[indexOfLabelPressed] = (100 - Double.parseDouble(itemDiscountPopupString)) / 100; discountPopup.setVisible(false); setLabelText(); setCost(); itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } } else if (obj == resetDiscountButton) { itemPriceModifier[indexOfLabelPressed] = 1; itemPriceOfLabel[indexOfLabelPressed] = itemOriginalPrice[indexOfLabelPressed]; setLabelText(); setCost(); discountPopup.setVisible(false); itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } } else if (indexOfLabelPressed == -1) { okDiscountButton.setText("Deduct"); if (obj == discountButton0 || obj == discountButton1 || obj == discountButton2 || obj == discountButton3 || obj == discountButton4 || obj == discountButton5 || obj == discountButton6 || obj == discountButton7 || obj == discountButton8 || obj == discountButton9) { itemDiscountPopupString = itemDiscountPopupString + source; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } else if (obj == clearDiscountButton) { itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemCountPopupString); discountPopup.setVisible(false); } else if (obj == okDiscountButton) { if (itemDiscountPopupString == "") { itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); discountPopup.setVisible(false); } else { finalModifier = Double.parseDouble(itemDiscountPopupString) / 100; discountPopup.setVisible(false); setCost(); itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } } else if (obj == percentDiscountButton) { if (itemDiscountPopupString == "") { itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); discountPopup.setVisible(false); } else { finalPercentModifier = (100 - Double.parseDouble(itemDiscountPopupString)) / 100; discountPopup.setVisible(false); setCost(); itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } } else if (obj == resetDiscountButton) { finalPercentModifier = 1; finalModifier = 0; setCost(); discountPopup.setVisible(false); itemDiscountPopupString = ""; itemDiscountPopupLabel.setText("Discount: " + itemDiscountPopupString); } } // count buttons if (obj == countButton0 || obj == countButton1 || obj == countButton2 || obj == countButton3 || obj == countButton4 || obj == countButton5 || obj == countButton6 || obj == countButton7 || obj == countButton8 || obj == countButton9) { itemCountPopupString = itemCountPopupString + source; itemCountPopupLabel.setText("Item count: " + itemCountPopupString); } else if (obj == clearCountButton) { itemCountPopupString = ""; itemCountPopupLabel.setText("Item count: " + itemCountPopupString); countPopup.setVisible(false); } else if (obj == okCountButton) { if (itemCountPopupString == "") { itemCountPopupString = ""; itemCountPopupLabel.setText("Item count: " + itemCountPopupString); countPopup.setVisible(false); } else { itemCountOfLabel[indexOfLabelPressed] = Integer.parseInt(itemCountPopupString); countPopup.setVisible(false); setLabelText(); setCost(); itemCountPopupString = ""; itemCountPopupLabel.setText("Item count: " + itemCountPopupString); } } }
// Handle some of the common steps between creating the content // and object tables. public AbstractViperTable(TablePanel tp) { super(); this.outerTablePanel = tp; setLayout(new BorderLayout()); EnhancedTable table = new EnhancedTable() { public void changeSelection( int rowIndex, int columnIndex, boolean toggle, boolean extend) { ViperTableModel currModel = AbstractViperTable.this.getCurrentModel(); columnIndex = convertColumnIndexToModel(columnIndex); AttrConfig ac = currModel.getAttributeForColumn(columnIndex); Descriptor d = currModel.getDescriptorAtRow(rowIndex); Node n = null; if (ac != null) { Attribute a = d.getAttribute(ac); n = a; } else if (currModel.getInternalColumn(columnIndex) == ViperTableModel.BY_ID) { n = d; } if (n != null) { if (extend) { mediator.getSelection().addNode(n); } else { mediator.getSelection().setTo(n); } } } public boolean isCellSelected(int row, int column) { ViperTableModel currModel = AbstractViperTable.this.getCurrentModel(); column = convertColumnIndexToModel(column); AttrConfig ac = currModel.getAttributeForColumn(column); Descriptor d = currModel.getDescriptorAtRow(row); if (ac != null) { Attribute a = d.getAttribute(ac); return mediator.getSelection().isSelected(a); } else if (currModel.getInternalColumn(column) == ViperTableModel.BY_ID) { return mediator.getSelection().isSelected(d); } return false; } }; table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.resizeAllColumnsToNaturalWidth(); table.setCellSelectionBackground( table.getSelectionBackground().brighter().brighter().brighter()); table.setCellSelectionForeground(table.getForeground().darker()); initAttributeTable(table); JScrollPane scrollPane = new JScrollPane(table); this.add(scrollPane); popup = new DescPropPopup(); popup.setInvoker(getTable()); getTable() .addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { maybeShowPopup(e); } public void mouseReleased(MouseEvent e) { maybeShowPopup(e); } }); }