public void start(MouseListener listener) { frame = new JFrame("Snake for Wear (but now on desktop)"); frame.getContentPane().setPreferredSize(new Dimension(500, 500)); frame.pack(); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); surface = new JPanel() { @Override public void paintComponent(Graphics graphics) { render((Graphics2D) graphics); } }; surface.setFocusable(true); surface.setBackground(Color.black); surface.addMouseListener(listener); frame.add(surface); frame.setVisible(true); }
public void init() { if (script == null) { throw new RuntimeException("Script is null"); } if (script instanceof MouseListener) { addMouseListener((MouseListener) script); } if (script instanceof MouseMotionListener) { addMouseMotionListener((MouseMotionListener) script); } if (script instanceof MessageListener) { addMessageListener((MessageListener) script); } if (script instanceof Paintable) { Context.getInstance().addPaintable((Paintable) script); } if (script instanceof GameActionListener) { addActionListener((GameActionListener) script); } }
public void removeListener() { for (MouseListener ml : com.getMouseListeners()) { com.removeMouseListener(ml); } for (MouseMotionListener mml : com.getMouseMotionListeners()) { com.removeMouseMotionListener(mml); } for (KeyListener kl : com.getKeyListeners()) { com.removeKeyListener(kl); } reset(); com.repaint(); }
private void init() { this.setLayout(new FlowLayout( FlowLayout.LEADING, 0, 0)); setLinkLikeButton(button); leftParenthesis = new JLabel("("); //NOI18N rightParenthesis = new JLabel(")"); //NOI18N add(leftParenthesis); add(button); add(rightParenthesis); MouseListener ml = createLabelMouseListener(); leftParenthesis.addMouseListener(ml); rightParenthesis.addMouseListener(ml); button.setEnabled(false); this.setMaximumSize( this.getPreferredSize()); }
private MouseListener createMouseListener() { return new MouseAdapter() { public void mouseClicked(MouseEvent event) { if (SwingUtilities.isRightMouseButton(event)) { JComponent comp = (JComponent)event.getSource(); Item item = null; if (comp instanceof JList) { JList list = (JList)comp; Point p = event.getPoint(); int index = list.locationToIndex(p); if (index >= 0 && !list.getCellBounds(index, index).contains(p)) { index = -1; } if (index >= 0) { item = (Item)list.getModel().getElementAt(index); } } Action[] actions = null == item ? category.getActions() : item.getActions(); JPopupMenu popup = Utilities.actionsToPopup( actions, getComponent() ); Utils.addCustomizationMenuItems( popup, getPalettePanel().getController(), getPalettePanel().getSettings() ); popup.show(comp, event.getX(), event.getY()); } } }; }
public void init() { if (script == null) { throw new RuntimeException("Script is null"); } if (script instanceof MouseListener) { addMouseListener((MouseListener) script); } if (script instanceof MouseMotionListener) { addMouseMotionListener((MouseMotionListener) script); } // if (script instanceof MessageListener) { // addMessageListener((MessageListener) script); // } if (script instanceof Paintable) { Context.getInstance().addPaintable((Paintable) script); } // if (script instanceof GameActionListener) { // addActionListener((GameActionListener) script); // } }
public CompletionScrollPane(JTextComponent editorComponent, MouseListener mouseListener) { setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_AS_NEEDED); // Use maximumSize property to store the limit of the preferred size setMaximumSize(new Dimension(400, 300)); // At least 2 items; do -1 for title height int maxVisibleRowCount = Math.max(2, getMaximumSize().height / CompletionLayout.COMPLETION_ITEM_HEIGHT - 1); // Add the completion view view = new JPanel(); JCheckBox checkbox = new JCheckBox("Rename comments"); checkbox.setFocusable(false); view.add(checkbox); JCheckBox checkbox1 = new JCheckBox("Rename Test Class"); checkbox1.setFocusable(false); view.add(checkbox1); setViewportView(view); installKeybindings(editorComponent); }
public CloseableTabComponent(Icon icon, String title, boolean closeable, String tooltip, final NBTabbedPane parent, MouseListener controller) { super(new BorderLayout( 2, 0 ) ); lblTitle.setText( title ); if( parent.getType() == TabbedType.EDITOR ) lblTitle.setIcon( icon ); add(lblTitle, BorderLayout.CENTER); lblTitle.setToolTipText( tooltip ); addMouseListener(controller); lblTitle.addMouseListener( controller); if( closeable ) { closeButton = CloseButtonFactory.createBigCloseButton(); add(closeButton, BorderLayout.EAST); closeButton.addMouseListener( controller ); if( parent.getType() == TabbedType.EDITOR ) closeButton.setToolTipText( NbBundle.getMessage(CloseableTabComponent.class, "BtnClose_Tooltip") ); } else { closeButton = null; } this.parent = parent; setOpaque(false); }
public ExtendedJLabel( ControlJFrame objPcontrolJFrame, MouseListener objPmouseListener, String strPlabel, Icon objLicon, Color objPbackgroundColor, int intPtooltip) { super(strPlabel, objLicon, SwingConstants.CENTER); this.objGcontrolJFrame = objPcontrolJFrame; this.intGtooltip = intPtooltip; this.setFont(this.objGcontrolJFrame.getFont()); if (objPbackgroundColor != null) { this.setBackground(objPbackgroundColor); } this.setOpaque(true); if (objPmouseListener != null) { this.objGmouseListener = objPmouseListener; this.addMouseListener(this.objGmouseListener); } else { if (this.objGmouseListener != null) { this.removeMouseListener(this.objGmouseListener); } } }
/** * {@inheritDoc} */ @Override public void removeNotify() { super.removeNotify(); getGUI().dialogRemove(FreeColDialog.this); removeAll(); if (this.pane != null) { this.pane.removePropertyChangeListener(this); this.pane = null; } for (MouseListener listener : getMouseListeners()) { removeMouseListener(listener); } }
/** * Adds a {@link MouseListener} for this component. Makes sure it works on resized components as * well as charts. */ @Override public void addMouseListener(final MouseListener listener) { super.addMouseListener(listener); // needed because we set the size of them/added tooltips so they intercept events now labelAttName.addMouseListener(listener); labelStatsMissing.addMouseListener(listener); labelStatsConstruction.addMouseListener(listener); labelStatsMin.addMouseListener(listener); labelStatsMax.addMouseListener(listener); labelStatsAvg.addMouseListener(listener); labelStatsDeviation.addMouseListener(listener); labelStatsLeast.addMouseListener(listener); labelStatsMost.addMouseListener(listener); labelStatsValues.addMouseListener(listener); labelStatsDuration.addMouseListener(listener); labelStatsFrom.addMouseListener(listener); labelStatsUntil.addMouseListener(listener); }
/** * Removes a {@link MouseListener} from this component. Makes sure it is removed from resized * components as well as from charts. */ @Override public void removeMouseListener(final MouseListener listener) { super.removeMouseListener(listener); // needed because we set the size of them/added tooltips so they intercept events now labelAttName.removeMouseListener(listener); labelStatsMissing.removeMouseListener(listener); labelStatsConstruction.removeMouseListener(listener); labelStatsMin.removeMouseListener(listener); labelStatsMax.removeMouseListener(listener); labelStatsAvg.removeMouseListener(listener); labelStatsDeviation.removeMouseListener(listener); labelStatsLeast.removeMouseListener(listener); labelStatsMost.removeMouseListener(listener); labelStatsValues.removeMouseListener(listener); labelStatsDuration.removeMouseListener(listener); labelStatsFrom.removeMouseListener(listener); labelStatsUntil.removeMouseListener(listener); }
/** * Removes an event listener from the Panel. * * @param eventListener * The event listener. * * @throws IllegalArgumentException * If the event listener isn't supported by this function. */ public void removeListener(final EventListener eventListener) { if (eventListener instanceof KeyListener) { this.removeKeyListener((KeyListener) eventListener); return; } if (eventListener instanceof MouseListener) { this.removeMouseListener((MouseListener) eventListener); return; } if (eventListener instanceof MouseMotionListener) { this.removeMouseMotionListener((MouseMotionListener) eventListener); return; } throw new IllegalArgumentException("The " + eventListener.getClass().getSimpleName() + " is not supported."); }
public void addDropTarget(final Component c, final MouseListener l) { c.addMouseListener(new MouseAdapter() { public void mouseEntered(MouseEvent e) { Component source = (Component) e.getSource(); if (source.isShowing()) { if (lastRelease != null) { e.translatePoint(source.getLocationOnScreen().x, source.getLocationOnScreen().y); if (isCloseEnough(e.getPoint(), lastRelease.getPoint())) { e.translatePoint(-source.getLocationOnScreen().x, -source.getLocationOnScreen().y); l.mouseReleased(e); } } else { dropTarget = source; dropHandler = l; } } } }); }
private MouseListener blokajMouseListener() { final MouseAdapter adapter = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int selectedIndex = blokajTable.getSelectedRow(); if (selectedIndex < 0) { blokajRoomsTable.revalidate(); blokajRoomsTable.repaint(); blokajCustomerTable.revalidate(); blokajCustomerTable.repaint(); } reservIdFromRow = blokajTable.getValueAt(selectedIndex, 0).toString(); blokajRoomsModel.setRowCount(0); populateBlokajRoomsModel(blokajRoomsModel, reservIdFromRow); blokajCustomerModel.setRowCount(0); populateBlokajCustomerModel(blokajCustomerModel, reservIdFromRow); super.mousePressed(e); } }; return adapter; }
private MouseListener rowSelectorListener() { final MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int selectedIndex = reservationTable.getSelectedRow(); if (selectedIndex < 0) { reservationTable.revalidate(); reservationTable.repaint(); } selectedReservationId = Long.parseLong(String.valueOf(reservationTable.getValueAt(selectedIndex, 0))); System.out.println(selectedReservationId); super.mouseClicked(e); } }; return mouseAdapter; }
/** * Adds listeners that listen for changes to the current line, so we can * update our "current line highlight." This is needed only because of an * apparent difference between the JRE 1.4.2 and 1.5.0 (needed on 1.4.2, * not needed on 1.5.0). */ private void addCurrentLineHighlightListeners() { boolean add = true; MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); for (int i=0; i<mouseMotionListeners.length; i++) { if (mouseMotionListeners[i]==mouseListener) { add = false; break; } } if (add) { //System.err.println("Adding mouse motion listener!"); addMouseMotionListener(mouseListener); } MouseListener[] mouseListeners = getMouseListeners(); for (int i=0; i<mouseListeners.length; i++) { if (mouseListeners[i]==mouseListener) { add = false; break; } } if (add) { //System.err.println("Adding mouse listener!"); addMouseListener(mouseListener); } }
/** * Checks if this {@code Canvas} contains any in game components. * * @return {@code true} if there is any in game components. */ public boolean containsInGameComponents() { KeyListener[] keyListeners = getKeyListeners(); if (keyListeners.length > 0) { return true; } MouseListener[] mouseListeners = getMouseListeners(); if (mouseListeners.length > 0) { return true; } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); if (mouseMotionListeners.length > 0) { return true; } return false; }
/** * Removes components that is only used when in game. */ public void removeInGameComponents() { // remove listeners, they will be added when launching the new game... KeyListener[] keyListeners = getKeyListeners(); for (KeyListener keyListener : keyListeners) { removeKeyListener(keyListener); } MouseListener[] mouseListeners = getMouseListeners(); for (MouseListener mouseListener : mouseListeners) { removeMouseListener(mouseListener); } MouseMotionListener[] mouseMotionListeners = getMouseMotionListeners(); for (MouseMotionListener mouseMotionListener : mouseMotionListeners) { removeMouseMotionListener(mouseMotionListener); } for (Component c : getComponents()) { removeFromCanvas(c); } }
public static void registerForMouseEvent(Component comp, MouseListener mouseListener) { if(comp instanceof JScrollPane) { JScrollPane pane = (JScrollPane) comp; comp = pane.getViewport().getView(); } if(comp instanceof Container) { Container container = (Container) comp; Component[] components = container.getComponents(); for(int i = 0; i < components.length; i++) { registerForMouseEvent(components[i], mouseListener); } } //No registration for XOpenTypedata that are themselves clickable. //No registration for JButton that are themselves clickable. if(comp != null && (!(comp instanceof XOpenTypeViewer.XOpenTypeData) && !(comp instanceof JButton)) ) comp.addMouseListener(mouseListener); }
/** * Clean up this colony panel. */ private void cleanup() { unloadButton.removeActionListener(unloadCmd); fillButton.removeActionListener(fillCmd); warehouseButton.removeActionListener(warehouseCmd); buildQueueButton.removeActionListener(buildQueueCmd); colonyUnitsButton.removeActionListener(colonyUnitsCmd); if (setGoodsButton != null) { setGoodsButton.removeActionListener(setGoodsCmd); } if (traceWorkButton != null) { traceWorkButton.removeActionListener(occupationCmd); } removePropertyChangeListeners(); if (getSelectedUnit() != null) { getSelectedUnit().removePropertyChangeListener(this); } removeMouseListeners(); for (MouseListener listener : getMouseListeners()) { removeMouseListener(listener); } setTransferHandlers(false); buildingsPanel.cleanup(); cargoPanel.cleanup(); constructionPanel.cleanup(); inPortPanel.cleanup(); outsideColonyPanel.cleanup(); populationPanel.cleanup(); tilesPanel.cleanup(); warehousePanel.cleanup(); removeAll(); }
@Override public void unregisterMouseListener(final MouseListener listener) { if (!this.mouseListeners.contains(listener)) { return; } this.mouseListeners.remove(listener); }
private void handleMouseOver( Container c, MouseListener ml ) { c.addMouseListener(ml); for( Component child : c.getComponents() ) { child.addMouseListener(ml); if( child instanceof Container ) handleMouseOver((Container)child, ml); } }
/** * Create listener that delegates mouse clicks on parenthesis to the button. */ private MouseListener createLabelMouseListener() { return new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (button.isEnabled()) { for (ActionListener al : button.getActionListeners()) { al.actionPerformed(null); } } } }; }
public ExtendedJLabel( ControlJFrame objPcontrolJFrame, MouseListener objPmouseListener, String strPlabel, Color objPbackgroundColor, int intPtooltip) { this(objPcontrolJFrame, objPmouseListener, strPlabel, null, objPbackgroundColor, intPtooltip); }
/** * Dispatch mouse event directly in org.openide.explorer.propertysheet.PSheet * to make it more reliable. */ @Override public void clickForPopup() { final Component eventsHandleComponent = findSubComponent(new ComponentChooser() { @Override public boolean checkComponent(Component comp) { return comp.getClass().getSimpleName().equals("PSheet"); //NOI18N } @Override public String getDescription() { return "org.openide.explorer.propertysheet.PSheet"; //NOI18N } }); if (eventsHandleComponent != null) { runMapping(new MapVoidAction("mousePressed") { @Override public void map() { ((MouseListener) eventsHandleComponent).mousePressed( new MouseEvent(getSource(), MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 0, getCenterXForClick(), getCenterYForClick(), 1, true)); } }); } else { super.clickForPopup(); } }
@Override protected Component createPreviousButton() { AbstractButton ab = (AbstractButton) super.createPreviousButton(); JButton b = new SpinnerButton("down"); b.addActionListener((ActionListener) getUIResource(ab.getActionListeners())); b.addMouseListener((MouseListener) getUIResource(ab.getMouseListeners())); return b; }
@Override protected Component createNextButton() { AbstractButton ab = (AbstractButton) super.createNextButton(); JButton b = new SpinnerButton("up"); b.setRequestFocusEnabled(false); b.addActionListener((ActionListener) getUIResource(ab.getActionListeners())); b.addMouseListener((MouseListener) getUIResource(ab.getMouseListeners())); return b; }
/** * Shows the given video Component. * * @param vp The video Component. * @param ml A MouseListener for stopping the video. * @param kl A KeyListener for stopping the video. */ public void showVideoComponent(final Component vp, final MouseListener ml, final KeyListener kl) { addMouseListener(ml); addKeyListener(kl); addCentered(vp, JLayeredPane.PALETTE_LAYER); }
public static void addMouseListener(Object obj, Object arg) { try { Method m = obj.getClass().getMethod("addMouseListener", MouseListener.class); m.invoke(obj, arg); } catch (Exception e) { e.printStackTrace(); } }
/** * Clear all mouse listeners. NOTE: this method will also remove the default listener. */ public void clearMouseListeners() { MouseListener[] listeners = frame.getMouseListeners(); for (MouseListener listener : listeners) { removeMouseListener(listener); } }
public synchronized void addMouseListener(MouseListener l) { if (listenersActive) { super.addMouseListener(l); } else { mouseListeners.add(l); } }
private MouseListener openCustomerListener() { final MouseAdapter adapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { final int rowIndex = customerTable.getSelectedRow(); final String name = customerTable.getValueAt(rowIndex, 2).toString(); final String lastname = customerTable.getValueAt(rowIndex, 3).toString(); theCustomer = customerDaoImpl.findCustomerByName(name, lastname); custWindow.setId(theCustomer.getCustomerId() + ""); custWindow.setName(theCustomer.getFirstName()); custWindow.setSurname(theCustomer.getLastName()); custWindow.setDocument(theCustomer.getDocument()); custWindow.setDocNo(theCustomer.getDocumentNo()); custWindow.setCountry(theCustomer.getCountry()); custWindow.setDateOfBirth(theCustomer.getDateOfBirth()); custWindow.setEmail(theCustomer.getEmail()); custWindow.setFatherName(theCustomer.getFatherName()); custWindow.setMotherName(theCustomer.getMotherName()); custWindow.setGender(theCustomer.getGender()); custWindow.setPhone(theCustomer.getPhone()); custWindow.setMariaggeStaus(theCustomer.getMaritalStatus()); custWindow.setReservationId(theCustomer.getReservationId() + ""); custWindow.setInfoMessage(" "); custWindow.setVisible(true); loggingEngine.setMessage("Displaying customer..."); loggingEngine.setMessage("Displayed customer details : " + theCustomer.toString()); } super.mousePressed(e); } }; return adapter; }
private MouseListener customMouseListener() { final MouseAdapter listener = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { final int rowIndex = table.getSelectedRow(); rowId = Long.valueOf(table.getValueAt(rowIndex, 0).toString()); System.out.println("SELECTED ROW : 'rowId :'" + rowId); super.mousePressed(e); } }; return listener; }
private MouseListener openCustomerListener() { final MouseAdapter adapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.getClickCount() == 2) { final int rowIndex = customerTable.getSelectedRow(); final String name = customerTable.getValueAt(rowIndex, 1).toString(); final String lastname = customerTable.getValueAt(rowIndex, 2).toString(); theCustomer = customerDaoImpl.findCustomerByName(name, lastname); custWindow.setId(theCustomer.getCustomerId() + ""); custWindow.setName(theCustomer.getFirstName()); custWindow.setSurname(theCustomer.getLastName()); custWindow.setDocument(theCustomer.getDocument()); custWindow.setDocNo(theCustomer.getDocumentNo()); custWindow.setCountry(theCustomer.getCountry()); custWindow.setDateOfBirth(theCustomer.getDateOfBirth()); custWindow.setEmail(theCustomer.getEmail()); custWindow.setFatherName(theCustomer.getFatherName()); custWindow.setMotherName(theCustomer.getMotherName()); custWindow.setGender(theCustomer.getGender()); custWindow.setPhone(theCustomer.getPhone()); custWindow.setMariaggeStaus(theCustomer.getMaritalStatus()); custWindow.setReservationId(theCustomer.getReservationId() + ""); custWindow.setInfoMessage(" "); custWindow.setVisible(true); loggingEngine.setMessage("Displaying customer..."); loggingEngine.setMessage("Displayed customer details : " + theCustomer.toString()); } super.mousePressed(e); } }; return adapter; }
private MouseListener customMouseEvent() { final MouseAdapter adapter = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { selectedRowIndex = companiesTable.getSelectedRow(); if(selectedRowIndex >= 0) { selectedCompanyName = companiesTable.getValueAt(selectedRowIndex, 0).toString(); } super.mouseClicked(e); } }; return adapter; }
public JMapController(JMapViewer map) { this.map = map; if (this instanceof MouseListener) map.addMouseListener((MouseListener) this); if (this instanceof MouseWheelListener) map.addMouseWheelListener((MouseWheelListener) this); if (this instanceof MouseMotionListener) map.addMouseMotionListener((MouseMotionListener) this); }
/** * Strips off the UI's mouse listeners attached to the associated toolbar * and replaces them with this handler's listeners. */ private void installListeners() { if (!ourVersionIsCompatible) return; ourToolBar.removePropertyChangeListener("UI", ourUIListener); // Uninstall the current ui, collect the remaining listeners // on the toolbar, and reinstall the ui... final ComponentUI ui = ourToolBar.getUI(); ui.uninstallUI(ourToolBar); final java.util.List mList = Arrays.asList(ourToolBar .getListeners(MouseListener.class)); final java.util.List mmList = Arrays.asList(ourToolBar .getListeners(MouseMotionListener.class)); ui.installUI(ourToolBar); // ...then remove the listeners that were added by the ui... final MouseListener[] ml = ourToolBar .getListeners(MouseListener.class); final MouseMotionListener[] mml = ourToolBar .getListeners(MouseMotionListener.class); for (int i = 0; i < ml.length; i++) { if (!mList.contains(ml[i])) ourToolBar.removeMouseListener(ml[i]); } for (int i = 0; i < mml.length; i++) { if (!mmList.contains(mml[i])) ourToolBar.removeMouseMotionListener(mml[i]); } // ...and add our listeners to the toolbar. ourToolBar.addMouseListener(ourDragListener); ourToolBar.addMouseMotionListener(ourDragListener); ourToolBar.addPropertyChangeListener("UI", ourUIListener); }