Java Code Examples for javax.swing.JComponent#addMouseListener()

The following examples show how to use javax.swing.JComponent#addMouseListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: littleluck   File: LuckComboBoxUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <pre>
 * 初始化边框焦点监听器
 *
 * Initializes the border focus listener
 * <pre>
 *
 * @param c
 */
protected void installFocusListener(JComponent c)
{
    handle = new LuckComboboxFocusHandle();

    isFocusBorder = UIManager.getBoolean(LuckComboBoxUIBundle.ISFOCUSBORDER);

    if (isFocusBorder)
    {
        contentShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

        borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

        c.addMouseListener(handle);

        c.addFocusListener(handle);
    }
}
 
Example 2
/**
 * Actually register the rubber as the mouse listener for the provided component.
 *
 * @param component the related component
 */
public final void connectComponent (JComponent component)
{
    // Clean up if needed
    disconnectComponent(this.component);

    // Remember the related component (to get visible rect, etc ...)
    this.component = component;

    if (component != null) {
        // To be notified of mouse clicks
        component.removeMouseListener(this); // No multiple notifications
        component.addMouseListener(this);

        // To be notified of mouse mouvements
        component.removeMouseMotionListener(this); // No multiple notifs
        component.addMouseMotionListener(this);

        // To be notified of mouse  wheel mouvements
        component.removeMouseWheelListener(this); // No multiple notifs
        component.addMouseWheelListener(this);
    }
}
 
Example 3
Source Project: pumpernickel   File: NavigationPanelUI.java    License: MIT License 6 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);

	spinner.addChangeListener(valueListener);
	label = createLabel();
	maybeAdd(label, "Label");
	UpdateLabelListener changeListener = new UpdateLabelListener(
			(JSpinner) c, label);
	changeListener.refreshLabel();
	c.putClientProperty(PROPERTY_LABEL_CHANGE_LISTENER, changeListener);
	((JSpinner) c).addChangeListener(changeListener);
	((JSpinner) c).addPropertyChangeListener(changeListener);
	c.addMouseListener(dragListener);
	c.addMouseMotionListener(dragListener);
	c.setBorder(null);
}
 
Example 4
Source Project: pumpernickel   File: PaletteUI.java    License: MIT License 6 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	c.addPropertyChangeListener(JPalette.PROPERTY_COLORS,
			propertyLayoutListener);
	c.addPropertyChangeListener(PaletteUI.PROPERTY_HIGHLIGHT,
			propertyRepaintListener);
	c.setLayout(new PaletteLayoutManager());
	c.setRequestFocusEnabled(true);
	c.addMouseListener(mouseListener);
	c.addFocusListener(focusListener);
	c.addKeyListener(keyListener);
	c.setFocusable(true);
	Fields fields = getFields((JPalette) c, true);
	fields.install();
	c.setBorder(new CompoundBorder(new LineBorder(new Color(0xB0B0B0)),
			new FocusedBorder(getDefaultBorder())));
	relayoutCells((JPalette) c);
}
 
Example 5
/**
 * <pre>
 * 初始化边框焦点监听器
 *
 * Initializes the border focus listener
 * <pre>
 *
 * @param c
 */
protected void installFocusListener(JComponent c)
{
    handle = createFocusHandle();

    borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

    c.addMouseListener(handle);

    c.addFocusListener(handle);
}
 
Example 6
Source Project: ghidra   File: CodeBrowserPlugin.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void addMarginProvider(MarginProvider marginProvider) {
	JComponent component = marginProvider.getComponent();

	// just in case we get repeated calls
	component.removeMouseListener(focusingMouseListener);
	component.addMouseListener(focusingMouseListener);
	connectedProvider.getListingPanel().addMarginProvider(marginProvider);
}
 
Example 7
Source Project: marathonv5   File: CheckListItemPanel.java    License: Apache License 2.0 5 votes vote down vote up
protected void setMouseListener(JComponent c) {
    c.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (selectedItem != null)
                selectedItem.deselect();
            selectedItem = CheckListItemPanel.this;
            CheckListItemPanel.this.select();
        }
    });
}
 
Example 8
Source Project: pumpernickel   File: BreadCrumbUI.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);

	c.addMouseListener(mouseListener);
	c.addPropertyChangeListener(JBreadCrumb.PATH_KEY, refreshUIListener);
	c.addPropertyChangeListener(JBreadCrumb.FORMATTER_KEY,
			refreshUIListener);
	c.addPropertyChangeListener(PROPERTY_SEPARATOR_ICON, refreshUIListener);
	refreshUI((JBreadCrumb<?>) c);
}
 
Example 9
/**
 * @param pf Portfolio which is dynamically evaluated at mouse-even-time for
 * any contained private companies
 */
public static void addMouseListener(JComponent c,ORUIManager orUIManager,PortfolioModel pf) {
    if (isEnabled(false)) {
        HexHighlightMouseListener l = new HexHighlightMouseListener(orUIManager);
        l.portfolio = pf;
        c.addMouseListener(l);
    }
}
 
Example 10
/**
 * @param tileId ID of the tile the occurrences of which should be highlighted on
 * the map
 * @param enableIrrespectiveOfHighlightConfig If true, the mouse listener is
 * enabled irrespective of the base configuration. Needed since some highlighting
 * should not be disabled by configuration.
 */
public static void addMouseListener(JComponent c,ORUIManager orUIManager, Tile tile,boolean enableIrrespectiveOfHighlightConfig) {
    if (isEnabled(enableIrrespectiveOfHighlightConfig)) {
        HexHighlightMouseListener l = new HexHighlightMouseListener(orUIManager);
        l.tile = tile;
        c.addMouseListener(l);
    }
}
 
Example 11
/**
 * @param p Public company the hexes associated to it (home, destination, ...) are
 * to be highlighted (in case of events)
 * @param enableIrrespectiveOfHighlightConfig If true, the mouse listener is
 * enabled irrespective of the base configuration. Needed since some highlighting
 * should not be disabled by configuration.
 */
public static void addMouseListener(JComponent c,ORUIManager orUIManager,PublicCompany p,boolean enableIrrespectiveOfHighlightConfig) {
    if (isEnabled(enableIrrespectiveOfHighlightConfig)) {
        HexHighlightMouseListener l = new HexHighlightMouseListener(orUIManager);
        l.addToHexListDistinct(p.getHomeHexes());
        l.addToHexListDistinct(p.getDestinationHex());
        c.addMouseListener(l);
    }
}
 
Example 12
public ComponentTitledBorder(Component comp, JComponent container,
        Border border) {
    this.comp = comp;
    this.container = container;
    this.border = border;
    container.addMouseListener(this);
}
 
Example 13
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY, thumbShapeListener);
	calculateGeometry();
}
 
Example 14
/**
   Construct a PanZoomListener that listens for events on a JComponent.
   @param component The component to listen for mouse events on.
*/
public PanZoomListener(JComponent component) {
    this.component = component;
    component.addMouseListener(this);
    component.addMouseMotionListener(this);
    component.addMouseWheelListener(this);
    panTriggerModifiers = InputEvent.BUTTON1_DOWN_MASK;
    zoomTriggerModifiers = InputEvent.BUTTON2_DOWN_MASK;
    zoomThreshold = DEFAULT_MOUSE_ZOOM_THRESHOLD;
    enabled = true;
}
 
Example 15
Source Project: littleluck   File: LuckPasswordFieldUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 初始化边框焦点监听器
 *
 * Initializes the border focus listener
 * <pre>
 *
 * @param c
 */
protected void installFocusListener(JComponent c)
{
    handle = createFocusHandle();

    borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

    c.addMouseListener(handle);

    c.addFocusListener(handle);
}
 
Example 16
Source Project: pumpernickel   File: WritingTextArea.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	c.addKeyListener(keyListener);
	c.addMouseListener(mouseListener);
	layout.addPropertyChangeListener(layoutListener);
}
 
Example 17
Source Project: pumpernickel   File: MultiThumbSliderUI.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY,
			thumbShapeListener);
	calculateGeometry();
}
 
Example 18
Source Project: Rails   File: HexMap.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void addMouseListener(MouseListener ml) {
    for (JComponent l : layers) {
        l.addMouseListener(ml);
    }
}
 
Example 19
Source Project: freecol   File: Canvas.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Adds a component on this Canvas inside a frame.
 *
 * @param comp The component to add to the canvas.
 * @param toolBox Should be set to true if the resulting frame is
 *     used as a toolbox (that is: it should not be counted as a
 *     frame).
 * @param popupPosition A preferred {@code PopupPosition}.
 * @param resizable Whether this component can be resized.
 * @return The {@code JInternalFrame} that was created and added.
 */
private JInternalFrame addAsFrame(JComponent comp, boolean toolBox,
                                  PopupPosition popupPosition,
                                  boolean resizable) {
    final int FRAME_EMPTY_SPACE = 60;

    final JInternalFrame f = (toolBox) ? new ToolBoxFrame()
        : new JInternalFrame();
    Container con = f.getContentPane();
    if (con instanceof JComponent) {
        JComponent c = (JComponent)con;
        c.setOpaque(false);
        c.setBorder(null);
    }

    if (comp.getBorder() != null) {
        if (comp.getBorder() instanceof EmptyBorder) {
            f.setBorder(Utility.blankBorder(10, 10, 10, 10));
        } else {
            f.setBorder(comp.getBorder());
            comp.setBorder(Utility.blankBorder(5, 5, 5, 5));
        }
    } else {
        f.setBorder(null);
    }

    final FrameMotionListener fml = new FrameMotionListener(f);
    comp.addMouseMotionListener(fml);
    comp.addMouseListener(fml);
    if (f.getUI() instanceof BasicInternalFrameUI) {
        BasicInternalFrameUI biu = (BasicInternalFrameUI) f.getUI();
        biu.setNorthPane(null);
        biu.setSouthPane(null);
        biu.setWestPane(null);
        biu.setEastPane(null);
    }

    f.getContentPane().add(comp);
    f.setOpaque(false);
    f.pack();
    int width = f.getWidth();
    int height = f.getHeight();
    if (width > getWidth() - FRAME_EMPTY_SPACE) {
        width = Math.min(width, getWidth());
    }
    if (height > getHeight() - FRAME_EMPTY_SPACE) {
        height = Math.min(height, getHeight());
    }
    f.setSize(width, height);
    Point p = chooseLocation(comp, width, height, popupPosition);
    f.setLocation(p);
    this.addToCanvas(f, MODAL_LAYER);
    f.setName(comp.getClass().getSimpleName());

    f.setFrameIcon(null);
    f.setVisible(true);
    f.setResizable(resizable);
    try {
        f.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}

    return f;
}
 
Example 20
/**
 * Registers a component for tooltip management.
 * <p>
 * This will register key bindings to show and hide the tooltip text only if
 * <code>component</code> has focus bindings. This is done so that components that are not
 * normally focus traversable, such as <code>JLabel</code>, are not made focus traversable as a
 * result of invoking this method.
 * 
 * @param component a <code>JComponent</code> object to add
 * @see JComponent#isFocusTraversable
 */
public void registerComponent(JComponent component) {

  if (!(component instanceof ComponentToolTipProvider))
    return;

  component.addMouseListener(this);
  component.addMouseMotionListener(moveBeforeEnterListener);

  ToolTipManager.sharedInstance().unregisterComponent(component);

}