Java Code Examples for javax.swing.event.MouseInputListener

The following examples show how to use javax.swing.event.MouseInputListener. 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   Source File: LuckRootPaneUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>创建窗体鼠标监听器, 处理窗体的移动和拖拽事件</p>
 * 
 * <p>Create Window mouse listener, handle window move and drag event.</p>
 *
 * @param root <code>JRootPane</code>
 * @return <code>MouseInputListener</code> window move and drag event listener.
 */
protected MouseInputListener installWindowListeners(JRootPane root)
{
    Window window = SwingUtilities.getWindowAncestor(root);

    if (window != null)
    {
        if (mouseInputListener == null)
        {
            mouseInputListener = new WindowMouseHandler(root);
        }

        window.addMouseListener(mouseInputListener);

        window.addMouseMotionListener(mouseInputListener);
    }

    return mouseInputListener;
}
 
Example 2
Source Project: bboxdb   Source File: MapViewerFactory.java    License: Apache License 2.0 6 votes vote down vote up
public static JXMapViewer createMapViewer() {
	final JXMapViewer mapViewer = new JXMapViewer();

	// Create a TileFactoryInfo for OpenStreetMap
	final TileFactoryInfo info = new OSMTileFactoryInfo();
	final DefaultTileFactory tileFactory = new DefaultTileFactory(info);
       tileFactory.setLocalCache(new FileBasedLocalCache(cacheDir.toFile(), false));
	mapViewer.setTileFactory(tileFactory);

	final MouseInputListener mia = new PanMouseInputListener(mapViewer);
	mapViewer.addMouseListener(mia);
	mapViewer.addMouseMotionListener(mia);
	
       mapViewer.addMouseWheelListener(new ZoomMouseWheelListenerCursor(mapViewer));
	
       mapViewer.addKeyListener(new PanKeyListener(mapViewer));
	
	// Use 8 threads in parallel to load the tiles
	tileFactory.setThreadPoolSize(8);
	
	// Show start point
	showHagen(mapViewer);
	
	return mapViewer;
}
 
Example 3
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());

  DefaultListModel<String> model = new DefaultListModel<>();
  model.addElement("11\n1");
  model.addElement("222222222222222\n222222222222222");
  model.addElement("3333333333333333333\n33333333333333333333\n33333333333333333");
  model.addElement("444");

  add(new JScrollPane(new JList<String>(model) {
    private transient MouseInputListener handler;
    @Override public void updateUI() {
      removeMouseListener(handler);
      removeMouseMotionListener(handler);
      super.updateUI();
      setFixedCellHeight(-1);
      handler = new CellButtonsMouseListener<>(this);
      addMouseListener(handler);
      addMouseMotionListener(handler);
      setCellRenderer(new ButtonsRenderer<>(model));
    }
  }));
  setPreferredSize(new Dimension(320, 240));
}
 
Example 4
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
private static <E> JList<E> makeList(ListModel<E> model) {
  return new JList<E>(model) {
    private transient MouseInputListener listener;
    @Override public void updateUI() {
      removeMouseListener(listener);
      removeMouseMotionListener(listener);
      setForeground(null);
      setBackground(null);
      setSelectionForeground(null);
      setSelectionBackground(null);
      super.updateUI();
      listener = new ClearSelectionListener();
      addMouseListener(listener);
      addMouseMotionListener(listener);
    }
  };
  // list.putClientProperty("List.isFileList", Boolean.TRUE);
  // list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  // list.setFixedCellWidth(64);
  // list.setFixedCellHeight(64);
  // list.setVisibleRowCount(0);
  // return list;
}
 
Example 5
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
private static JMenuItem makeStayOpenCheckBoxMenuItem(String title) {
  JMenuItem mi = new JMenuItem(" ");
  mi.setLayout(new BorderLayout());
  mi.add(new JCheckBox(title) {
    private transient MouseInputListener handler;
    @Override public void updateUI() {
      removeMouseListener(handler);
      removeMouseMotionListener(handler);
      super.updateUI();
      handler = new DispatchParentHandler();
      addMouseListener(handler);
      addMouseMotionListener(handler);
      setFocusable(false);
      setOpaque(false);
    }
  });
  return mi;
}
 
Example 6
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 6 votes vote down vote up
private MainPanel() {
  super(new GridLayout(1, 2, 5, 5));

  Box box1 = makeTestBox();
  box1.setBorder(BorderFactory.createTitledBorder("DragScrollListener"));
  MouseInputListener l = new DragScrollListener();
  box1.addMouseListener(l);
  box1.addMouseMotionListener(l);
  add(new JScrollPane(box1));

  Box box2 = makeTestBox();
  box2.setBorder(BorderFactory.createTitledBorder("DragScrollLayerUI"));
  add(new JLayer<>(new JScrollPane(box2), new DragScrollLayerUI()));

  setPreferredSize(new Dimension(320, 240));
}
 
Example 7
Source Project: nextreports-designer   Source File: JGridHeader.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void updateUI() {

    // register(or not) listener for selection
    if  (allowSelection) {
        setUI(new BasicGridHeaderUI());
    } else  {
        setUI(new BasicGridHeaderUI() {
            @Override
            protected MouseInputListener createMouseInputListener() {
                return null;
            }
        });
    }

    // register listener for cell resize
    if (resize) {
        setUI(new BasicGridHeaderUI() {
            protected MouseInputListener createMouseInputListener() {
                return new HeaderResizeMouseInputListener();
            }
        });
    }
    
    repaintManager.resizeAndRepaint();
}
 
Example 8
Source Project: littleluck   Source File: FrameDemo.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 自定义拖拽区域
 */
protected MouseInputListener installWindowListeners(JRootPane root)
{
    MouseInputListener listener = super.installWindowListeners(root);

    if(listener instanceof WindowMouseHandler)
    {
        ((WindowMouseHandler) listener).setDragArea(new LuckRectangle(root));
    }

    return listener;
}
 
Example 9
Source Project: java-swing-tips   Source File: MainPanel.java    License: MIT License 5 votes vote down vote up
private MainPanel() {
  super(new BorderLayout());
  IntStream.range(0, 100)
      .mapToObj(i -> i % 19 == 0 || i % 17 == 0 ? PATTERN : "Java")
      .map(s -> new Object[] {s, ""})
      .forEach(model::addRow);

  scroll.setVerticalScrollBar(scrollbar);
  scrollbar.getModel().addChangeListener(e -> label.repaint());

  label.setIcon(new HighlightIcon());
  Border in = BorderFactory.createLineBorder(Color.BLACK);
  Border out = BorderFactory.createEmptyBorder(5, 5, 5, 5);
  label.setBorder(BorderFactory.createCompoundBorder(out, in));
  MouseInputListener handler = new HighlightBarHandler();
  label.addMouseListener(handler);
  label.addMouseMotionListener(handler);

  JToggleButton button = new JToggleButton("highlight");
  button.addActionListener(e -> {
    emphasisIndices.clear();
    if (((JToggleButton) e.getSource()).isSelected()) {
      updateHighlighter();
    }
    label.getRootPane().repaint();
  });

  Box box = Box.createHorizontalBox();
  box.add(Box.createHorizontalGlue());
  box.add(button);
  add(scroll);
  add(label, BorderLayout.EAST);
  add(box, BorderLayout.SOUTH);
  setPreferredSize(new Dimension(320, 240));
}
 
Example 10
Source Project: darklaf   Source File: MouseInputDelegate.java    License: MIT License 4 votes vote down vote up
public MouseInputDelegate(final MouseInputListener delegate) {
    this(delegate, delegate);
}
 
Example 11
Source Project: jdk1.8-source-analysis   Source File: WindowsMenuUI.java    License: Apache License 2.0 4 votes vote down vote up
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}
 
Example 12
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}
 
Example 13
Source Project: dragonwell8_jdk   Source File: AquaListUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a delegate that implements MouseInputListener.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaListUI.MouseInputHandler();
}
 
Example 14
Source Project: dragonwell8_jdk   Source File: AquaTableUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the mouse listener for the JTable.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaTableUI.MouseInputHandler();
}
 
Example 15
Source Project: TencentKona-8   Source File: WindowsMenuUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}
 
Example 16
Source Project: TencentKona-8   Source File: AquaListUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a delegate that implements MouseInputListener.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaListUI.MouseInputHandler();
}
 
Example 17
Source Project: TencentKona-8   Source File: AquaTableUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the mouse listener for the JTable.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaTableUI.MouseInputHandler();
}
 
Example 18
Source Project: jdk8u60   Source File: WindowsMenuUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}
 
Example 19
Source Project: jdk8u60   Source File: AquaListUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a delegate that implements MouseInputListener.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaListUI.MouseInputHandler();
}
 
Example 20
Source Project: jdk8u60   Source File: AquaTableUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the mouse listener for the JTable.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaTableUI.MouseInputHandler();
}
 
Example 21
Source Project: JDKSourceCode1.8   Source File: WindowsMenuUI.java    License: MIT License 4 votes vote down vote up
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}
 
Example 22
Source Project: lizzie   Source File: BasicLizziePaneUI.java    License: GNU General Public License v3.0 4 votes vote down vote up
protected MouseInputListener createDockingListener() {
  getHandler().lp = lizziePane;
  return getHandler();
}
 
Example 23
Source Project: openjdk-jdk8u   Source File: WindowsMenuUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}
 
Example 24
Source Project: openjdk-jdk8u   Source File: AquaListUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a delegate that implements MouseInputListener.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaListUI.MouseInputHandler();
}
 
Example 25
Source Project: openjdk-jdk8u   Source File: AquaTableUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the mouse listener for the JTable.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaTableUI.MouseInputHandler();
}
 
Example 26
Source Project: netbeans   Source File: CategoryList.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected MouseInputListener createMouseInputListener () {
    return new ListMouseInputHandler ();
}
 
Example 27
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}
 
Example 28
/**
 * Creates a delegate that implements MouseInputListener.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaListUI.MouseInputHandler();
}
 
Example 29
/**
 * Creates the mouse listener for the JTable.
 */
protected MouseInputListener createMouseInputListener() {
    return new AquaTableUI.MouseInputHandler();
}
 
Example 30
Source Project: openjdk-jdk9   Source File: WindowsMenuUI.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected MouseInputListener createMouseInputListener(JComponent c) {
    return new WindowsMouseInputHandler();
}