Java Code Examples for java.awt.event.MouseAdapter

The following examples show how to use java.awt.event.MouseAdapter. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: CQL   Source File: View.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * The default constructor sets all the visual settings for the JGraph, as well
 * as Initializing the view to be empty. It also adds appropriate listeners for
 * all of the actions we are concerned with.
 *
 * @param inFrame    The view frame of the sketch
 * @param inSketch   The sketch this view is on
 * @param inOverview The overview in which this
 */
public View(ViewFrame inFrame, Sketch inSketch, Overview inOverview) {
	super(inFrame, inOverview);

	_ourSketch = inSketch;

	_stateManager = new ModelStateManager<>(this);

	// Set up mouse listener to watch for double clicks
	// - Double clicks edit a query node
	this.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			if ((_ourSketch.getFrame().getMode() == SketchFrame.Mode.EDIT) && (e.getClickCount() == 2)) {
				Object[] currSelection = getSelectionCells();

				if ((currSelection.length == 1) && (currSelection[0] instanceof QueryNode)) {
					DefineQueryNodeAction.updateNode((QueryNode) currSelection[0]);
				}
			}
		}
	});
}
 
Example 2
Source Project: PacketProxy   Source File: GUIOptionCharSetDialog.java    License: Apache License 2.0 6 votes vote down vote up
private JScrollPane tableScrollPane(){
	table_model = new CharSetsTableModel(getTableDataWithAvailableCharsets(), columns);
	JTable table = new JTable(table_model);
	TableColumn col = table.getColumnModel().getColumn(0);
	col.setMinWidth(50);
	col.setMaxWidth(50);
	table.addMouseListener(new MouseAdapter() {
		@Override
		public void mousePressed(MouseEvent e) {
			super.mousePressed(e);
			if(0==table.getSelectedColumn()){
				return;
			}
			table.setValueAt(!(Boolean)table.getValueAt(table.getSelectedRow(), 0), table.getSelectedRow(),0);
		}
	});
	sorter = new TableRowSorter<CharSetsTableModel>(table_model);
	table.setRowSorter(sorter);
	JScrollPane jscrollPane = new JScrollPane(table);

	return jscrollPane;
}
 
Example 3
Source Project: lizzie   Source File: SubBoardPane.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Creates a window */
public SubBoardPane(LizzieMain owner) {
  super(owner);

  subBoardRenderer = new BoardRenderer(false);

  setVisible(false);

  // TODO BufferStrategy does not support transparent background?
  //    createBufferStrategy(2);
  //    bs = getBufferStrategy();

  addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          if (e.getButton() == MouseEvent.BUTTON1) { // left click
            if (Lizzie.config.showSubBoard) {
              Lizzie.config.toggleLargeSubBoard();
              owner.invalidLayout();
            }
          }
        }
      });
}
 
Example 4
public JCheckBoxList() {
    super();

    setModel(new DefaultListModel());
    setCellRenderer(new CheckboxCellRenderer());

    addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            int index = locationToIndex(e.getPoint());

            if (index != -1) {
                Object obj = getModel().getElementAt(index);
                if (obj instanceof JCheckBox) {
                    JCheckBox checkbox = (JCheckBox) obj;
                    if (e.getPoint().getX() < 20){
                        checkbox.setSelected(!checkbox.isSelected());
                    }
                    repaint();
                }
            }
        }
    });

    setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
 
Example 5
Source Project: code   Source File: OuterClassExample.java    License: Apache License 2.0 6 votes vote down vote up
OuterClassExample(){
    super();
     
    setTitle("QQ");
    setBounds(100, 100, 380, 280); 
    getContentPane().setLayout(null); 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    textField = new JTextField("密码");
    textField.setBounds(100, 155, 120, 21);
    getContentPane().add(textField);
    textField.addMouseListener(new MouseAdapter(){
        @Override
        public void mouseClicked(MouseEvent e) {
            getContentPane().remove(textField);
            passwordField = new JPasswordField();
            passwordField.setBounds(100, 155, 120, 21); 
            getContentPane().add(passwordField);
        }
    });
     
}
 
Example 6
Source Project: lizzie   Source File: LizziePane.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Creates a window */
public LizziePane(LizzieMain owner) {
  //    super(owner);
  //    initCompotents();
  //    input = owner.input;
  //    installInputListeners();
  setOpaque(false);

  addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          Lizzie.frame.getFocus();
        }
      });
}
 
Example 7
private static void showModalDialog(Frame targetFrame) {

        Dialog dialog = new Dialog(targetFrame, true);

        dialog.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                passed = true;
                dialog.dispose();
            }
        });

        dialog.setSize(400, 300);
        dialog.setTitle("Modal Dialog!");

        clickOnModalDialog(dialog);
        dialog.setVisible(true);
    }
 
Example 8
Source Project: lizzie   Source File: VariationTreePane.java    License: GNU General Public License v3.0 6 votes vote down vote up
/** Creates a window */
public VariationTreePane(LizzieMain owner) {
  super(owner);
  this.owner = owner;

  variationTree = new VariationTree();

  setVisible(false);

  //    createBufferStrategy(2);
  //    bs = getBufferStrategy();

  addMouseListener(
      new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
          if (e.getButton() == MouseEvent.BUTTON1) { // left click
            onClicked(e.getX(), e.getY());
          }
        }
      });
}
 
Example 9
Source Project: Cafebabe   Source File: SettingList.java    License: GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public SettingList(Setting... settings) {
	this.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
	CheckBoxListModel clm = new CheckBoxListModel();
	for (Setting setting : settings) {
		clm.addCheckBoxElement(new SettingNode(setting), setting.get());
	}
	this.setModel(clm);
	this.repaint();
	for (MouseListener ml : this.getMouseListeners())
		this.removeMouseListener(ml);
	addMouseListener(new MouseAdapter() {
		public void mousePressed(MouseEvent e) {
			int index = locationToIndex(e.getPoint());
			if (index != -1) {
				CheckBoxCellData checkbox = (CheckBoxCellData) getModel().getElementAt(index);
				SettingNode sn = (SettingNode) checkbox.getUserObject();
				checkbox.invertSelection();
				repaint();
				sn.setUserSelected(checkbox.isSelected());
			}
		}
	});
	setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

}
 
Example 10
Source Project: Cafebabe   Source File: OpList.java    License: GNU General Public License v3.0 6 votes vote down vote up
public OpList(OpcodeChooserDialog chooser, int... opcodes) {
	this.chooser = chooser;
	this.opcodes = opcodes;
	this.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12));
	LazyListModel<OpcodeNode> llm = new LazyListModel<OpcodeNode>();
	for (int opcode : opcodes) {
		llm.addElement(new OpcodeNode(opcode));
	}
	this.setModel(llm);
	for (MouseListener ml : this.getMouseListeners())
		this.removeMouseListener(ml);
	this.addMouseListener(new MouseAdapter() {
		public void mouseClicked(MouseEvent evt) {
			if (evt.getClickCount() >= 1) {
				int index = locationToIndex(evt.getPoint());
				OpcodeNode on = llm.getElementAt(index);
				chooser.setOpcode(on.opcode);
				setSelectedIndex(index);
				chooser.refresh();
			}
		}
	});

}
 
Example 11
Source Project: ghidra   Source File: ColorEditor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * The default constructor.
 *
 */
public ColorEditor() {
	previewLabel.setOpaque(true);
	previewLabel.setPreferredSize(new Dimension(100, 20));
	previewLabel.setHorizontalAlignment(SwingConstants.CENTER);
	previewLabel.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent evt) {
			// show the editor to get the user value
			showDialog(evt.getComponent());

			ColorEditor.this.firePropertyChange();

			// now set the new value
			updateColor(color);
		}
	});
}
 
Example 12
Source Project: ghidra   Source File: GTableWidget.java    License: Apache License 2.0 6 votes vote down vote up
private void init(AnyObjectTableModel<T> model) {
	this.myModel = model;
	this.gFilterTable = new GFilterTable<>(model);
	this.table = gFilterTable.getTable();
	table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
	table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
	table.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			if (!e.isShiftDown()) {
				processMouseClicked(e);
			}
		}
	});

	add(gFilterTable);
}
 
Example 13
Source Project: openjdk-jdk8u   Source File: TableSorter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example 14
Source Project: jdk8u60   Source File: MultiGradientTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private GradientPanel() {
    startX = 20;
    startY = 20;
    endX   = 100;
    endY   = 100;
    ctrX   = 100;
    ctrY   = 100;
    focusX = 100;
    focusY = 100;
    radius = 100.0f;

    makeNewPaint();

    MouseAdapter l = new MyMouseAdapter();
    addMouseListener(l);
    addMouseMotionListener(l);
}
 
Example 15
Source Project: amodeus   Source File: SpinnerMenu.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void design(JPopupMenu jPopupMenu) {
    for (Type type : spinnerLabel.list) {
        JMenuItem jMenuItem = new JMenuItem(type.toString());
        if (hover)
            jMenuItem.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseEntered(MouseEvent myMouseEvent) {
                    setValue(type);
                }
            });
        jMenuItem.addActionListener(myActionEvent -> {
            if (!type.equals(spinnerLabel.getValue())) // invoke only when different
                setValue(type);
        });
        map.put(type, jMenuItem);
        jPopupMenu.add(jMenuItem);
    }
}
 
Example 16
Source Project: ghidra   Source File: RegisterValuesPanel.java    License: Apache License 2.0 6 votes vote down vote up
RegisterValuesPanel(PluginTool tool, RegisterManagerProvider provider) {
	this.tool = tool;
	this.provider = provider;
	setLayout(new BorderLayout());
	table = createBasicTable();
	add(new JScrollPane(table), BorderLayout.CENTER);
	table.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			int row = table.rowAtPoint(e.getPoint());
			int col = table.columnAtPoint(e.getPoint());
			col = table.convertColumnIndexToModel(col);
			if (e.getClickCount() == 2 && row >= 0) {
				editRow(row);
			}
		}
	});
	table.setDefaultRenderer(RegisterValueRange.class, new RegisterValueRenderer(table));

}
 
Example 17
Source Project: arcusplatform   Source File: ModelTableView.java    License: Apache License 2.0 6 votes vote down vote up
private Component createToolbar() {
   JLabel toolbar = new JLabel();
   toolbar.setBackground(Color.DARK_GRAY);
   toolbar.setIcon(UIManager.getIcon("Tree.expandedIcon"));
   toolbar.setText("Collapse All");
   toolbar.addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
         // TODO check left key
         allCollapsed = !allCollapsed;
         setCollapsed(allCollapsed);
         if(allCollapsed) {
            toolbar.setIcon(UIManager.getIcon("Tree.collapsedIcon"));
            toolbar.setText("Expand All");
         }
         else {
            toolbar.setIcon(UIManager.getIcon("Tree.expandedIcon"));
            toolbar.setText("Collapse All");
         }
      }
   });
   return toolbar;
}
 
Example 18
Source Project: TencentKona-8   Source File: CheckRenderer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public CheckRenderer(final JList list) {
    this.list = list;
    list.addMouseListener(
            new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    int index = list.locationToIndex(e.getPoint());
                    Point p2 = list.indexToLocation(index);
                    Rectangle r = new Rectangle(p2.x, p2.y, getPreferredSize().height, getPreferredSize().height);
                    if (r.contains(e.getPoint())) {
                        CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index);
                        node.setSelected(!node.isSelected());
                        list.repaint();
                        e.consume();
                    }
                }
            });

    this.setPreferredSize(new Dimension(getPreferredSize().width, getPreferredSize().height - 5));
    startBackground = this.getBackground();
}
 
Example 19
Source Project: TencentKona-8   Source File: TableSorter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example 20
private static void showModalDialog(Frame targetFrame) {

        Dialog dialog = new Dialog(targetFrame, true);

        dialog.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                passed = true;
                dialog.dispose();
            }
        });

        dialog.setSize(400, 300);
        dialog.setTitle("Modal Dialog!");

        clickOnModalDialog(dialog);
        dialog.setVisible(true);
    }
 
Example 21
private GradientPanel() {
    startX = 20;
    startY = 20;
    endX   = 100;
    endY   = 100;
    ctrX   = 100;
    ctrY   = 100;
    focusX = 100;
    focusY = 100;
    radius = 100.0f;

    makeNewPaint();

    MouseAdapter l = new MyMouseAdapter();
    addMouseListener(l);
    addMouseMotionListener(l);
}
 
Example 22
Source Project: knife   Source File: ConfigTable.java    License: MIT License 6 votes vote down vote up
private void addClickSort() {
	TableRowSorter<ConfigTableModel> sorter = new TableRowSorter<ConfigTableModel>(ConfigTableModel);
	ConfigTable.this.setRowSorter(sorter);

	JTableHeader header = this.getTableHeader();
	header.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			try {
				//ConfigTable.this.getRowSorter().getSortKeys().get(0).getColumn();
				sorter.getSortKeys().get(0).getColumn();
				////当Jtable中无数据时,jtable.getRowSorter()是null
			} catch (Exception e1) {
				e1.printStackTrace(new PrintWriter(BurpExtender.callbacks.getStderr(), true));//working?
			}
		}
	});
}
 
Example 23
Source Project: jdk8u60   Source File: CheckRenderer.java    License: GNU General Public License v2.0 6 votes vote down vote up
public CheckRenderer(final JList list) {
    this.list = list;
    list.addMouseListener(
            new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    int index = list.locationToIndex(e.getPoint());
                    Point p2 = list.indexToLocation(index);
                    Rectangle r = new Rectangle(p2.x, p2.y, getPreferredSize().height, getPreferredSize().height);
                    if (r.contains(e.getPoint())) {
                        CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index);
                        node.setSelected(!node.isSelected());
                        list.repaint();
                        e.consume();
                    }
                }
            });

    this.setPreferredSize(new Dimension(getPreferredSize().width, getPreferredSize().height - 5));
    startBackground = this.getBackground();
}
 
Example 24
DatasetTreeView() {
  // the catalog tree
  tree = new JTree() {
    public JToolTip createToolTip() {
      return new MultilineTooltip();
    }
  };
  tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode(null, false)));
  tree.setCellRenderer(new MyTreeCellRenderer());

  tree.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
      int selRow = tree.getRowForLocation(e.getX(), e.getY());
      if (selRow != -1) {
        TreeNode node = (TreeNode) tree.getLastSelectedPathComponent();
        if (node instanceof VariableNode) {
          Variable v = ((VariableNode) node).var;
          firePropertyChangeEvent(new PropertyChangeEvent(this, "Selection", null, v));
        }
      }
    }
  });

  tree.putClientProperty("JTree.lineStyle", "Angled");
  tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  tree.setToggleClickCount(1);
  ToolTipManager.sharedInstance().registerComponent(tree);

  // layout
  setLayout(new BorderLayout());
  add(new JScrollPane(tree), BorderLayout.CENTER);
}
 
Example 25
Source Project: darklaf   Source File: TristateCheckBox.java    License: MIT License 5 votes vote down vote up
public TristateCheckBox(final String text, final Icon icon, final TristateState initial) {
    super(text, icon);
    setModel(new TristateButtonModel(initial));
    // override action behaviour
    super.addMouseListener(new MouseAdapter() {
        public void mousePressed(final MouseEvent e) {
            TristateCheckBox.this.iterateState();
        }
    });
}
 
Example 26
Source Project: darklaf   Source File: TristateCheckBoxMenuItem.java    License: MIT License 5 votes vote down vote up
/**
 * Creates a tristate check box menu item with the specified text, icon, and selection state.
 *
 * @param text  the text of the check box menu item.
 * @param icon  the icon of the check box menu item.
 * @param state the selected state of the check box menu item.
 */
public TristateCheckBoxMenuItem(final String text, final Icon icon, final TristateState state) {
    super(text, icon);
    setModel(new TristateButtonModel(state));
    // override action behaviour
    super.addMouseListener(new MouseAdapter() {
        public void mousePressed(final MouseEvent e) {
            TristateCheckBoxMenuItem.this.iterateState();
        }
    });
    setFocusable(false);
}
 
Example 27
Source Project: jdk8u60   Source File: TreePosTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
JTextField addListener(final JTextField f) {
    f.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            body.setCaretPosition(Integer.valueOf(f.getText()));
            body.getCaret().setVisible(true);
        }
    });
    return f;
}
 
Example 28
private void setListeners()
{
    this.addMouseListener(new MouseAdapter()
    {
        @Override
        public void mouseClicked(MouseEvent e)
        {
            if (e.getButton() == MouseEvent.BUTTON1)
            {
                int position = getCaretPosition();
                int urlIndex = 0;
                for (int[] range : urlRange)
                {
                    if (position >= range[0] && position <= range[1])
                    {
                        String url = urlList.get(urlIndex);
                        openUrlWithDefaultBrowser(url);
                    }

                    urlIndex++;
                }
            }

            super.mouseClicked(e);
        }
    });
}
 
Example 29
Source Project: openAGV   Source File: BlocksTreeViewManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Registers a listener for mouse events that helps to select the element in the tree view that
 * the user has clicked on.
 * This is necessary as long as {@link AbstractTreeViewPanel#selectItem(java.lang.Object)} simply
 * selects the first occurrence of the given object, not expecting the object to occur in the tree
 * more than once.
 */
private void initSpecializedSelector() {
  JTree tree = getTreeView().getTree();
  tree.addMouseListener(new MouseAdapter() {
    @Override
    public void mousePressed(MouseEvent e) {
      tree.setSelectionPath(tree.getClosestPathForLocation(e.getX(), e.getY()));
    }
  });
}
 
Example 30
Source Project: blog-codes   Source File: ClickHandler.java    License: Apache License 2.0 5 votes vote down vote up
public ClickHandler()
{
	super("Hello, World!");
	
	final mxGraph graph = new mxGraph();
	Object parent = graph.getDefaultParent();

	graph.getModel().beginUpdate();
	try
	{
	   Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80,
	         30);
	   Object v2 = graph.insertVertex(parent, null, "World!",
	         240, 150, 80, 30);
	   graph.insertEdge(parent, null, "Edge", v1, v2);
	}
	finally
	{
	   graph.getModel().endUpdate();
	}
	
	final mxGraphComponent graphComponent = new mxGraphComponent(graph);
	getContentPane().add(graphComponent);
	
	graphComponent.getGraphControl().addMouseListener(new MouseAdapter()
	{
	
		public void mouseReleased(MouseEvent e)
		{
			Object cell = graphComponent.getCellAt(e.getX(), e.getY());
			
			if (cell != null)
			{
				System.out.println("cell="+graph.getLabel(cell));
			}
		}
	});
}