Java Code Examples for java.awt.event.MouseAdapter

The following are top voted examples for showing how to use java.awt.event.MouseAdapter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: routerapp   File: NavigationView.java   View source code 7 votes vote down vote up
/**
 * 
 */
private void buildTree() {
    DefaultMutableTreeNode root = new DefaultMutableTreeNode("user");
    tree = new JTree(root);
    tree.putClientProperty("JTree.lineStyle", "Angled");
    tree.setCellRenderer(new NavigationTreeCellRenderer());
    tree.setShowsRootHandles(true);
    
    DefaultTreeSelectionModel model = new DefaultTreeSelectionModel();
    model.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    
    graphsCategory = new DefaultMutableTreeNode("graphs");
    
    mouseAdapter = new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            itemSelected(e);
        }
    };
    tree.addMouseListener(mouseAdapter);
    
    root.add(graphsCategory);        
    loadGraphs();
}
 
Example 2
Project: owa-notifier   File: WindowNotification.java   View source code 7 votes vote down vote up
public WindowNotification() {
	m_window = new JWindow();
	m_window.setAlwaysOnTop(true);

	m_listener = new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			fireListeners(CLICKED);
			if (m_closeOnClick)
				removeFromManager();
		}
	};

	setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
	setPanel(new JPanel());
}
 
Example 3
Project: enigma-vk   File: ClassSelector.java   View source code 6 votes vote down vote up
public ClassSelector(Comparator<ClassEntry> comparator) {
	m_comparator = comparator;
	
	// configure the tree control
	setRootVisible(false);
	setShowsRootHandles(false);
	setModel(null);
	
	// hook events
	addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent event) {
			if (m_listener != null && event.getClickCount() == 2) {
				// get the selected node
				TreePath path = getSelectionPath();
				if (path != null && path.getLastPathComponent() instanceof ClassSelectorClassNode) {
					ClassSelectorClassNode node = (ClassSelectorClassNode)path.getLastPathComponent();
					m_listener.onSelectClass(node.getClassEntry());
				}
			}
		}
	});
	
	// init defaults
	m_listener = null;
}
 
Example 4
Project: Neukoelln_SER316   File: TableSorter.java   View source code 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() {
        boolean ascending = false;
        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);
                if (column == sortBy)                    
                    ascending = !ascending;
                else
                    ascending = true; 
                sorter.sortByColumn(column, ascending);   
                tableView.getTableHeader().updateUI();                  
            }
        }
    };
    JTableHeader th = tableView.getTableHeader(); 
    th.addMouseListener(listMouseListener); 
}
 
Example 5
Project: QN-ACTR-Release   File: WhatIfPlot.java   View source code 6 votes vote down vote up
public WhatIfPlot(double[] xAxis) {
	super();
	this.xAxis = xAxis;
	// Adds popup menu
	this.addMouseListener(new MouseAdapter() {
		/**
		 * Invoked when the mouse has been clicked on a component.
		 */
		@Override
		public void mouseClicked(MouseEvent e) {
			if (e.getButton() == MouseEvent.BUTTON3) {
				popup.show(WhatIfPlot.this, e.getX(), e.getY());
			}
		}
	});
}
 
Example 6
Project: Equella   File: AbstractChoiceDialog.java   View source code 6 votes vote down vote up
public void addChoice(final String key, String displayText)
{
	final JRadioButton rb = new JRadioButton(displayText);
	if( doubleClickToSelect )
	{
		rb.addMouseListener(new MouseAdapter()
		{
			@Override
			public void mouseClicked(MouseEvent e)
			{
				if( e.getClickCount() >= 2 )
				{
					addClicked(key);
				}
			}
		});
	}

	choices.addButton(rb, key);

	// Add after the instructions label and any existing choices
	add(rb, choices.size());
}
 
Example 7
Project: Cognizant-Intelligent-Test-Scripter   File: AppMainFrame.java   View source code 6 votes vote down vote up
private Box.Filler simpleFiller() {
    Box.Filler filler = new Box.Filler(
            new java.awt.Dimension(10, 0),
            new java.awt.Dimension(10, 0),
            new java.awt.Dimension(10, 32767));

    filler.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent me) {
            setGlassPane(docker);
            SwingUtilities.invokeLater(() -> {
                getGlassPane().setVisible(true);
            });
        }

    });
    return filler;
}
 
Example 8
Project: litiengine   File: JCheckBoxList.java   View source code 6 votes vote down vote up
public JCheckBoxList() {
  setCellRenderer(new CellRenderer());
  addMouseListener(new MouseAdapter() {
    @Override
    public void mousePressed(MouseEvent e) {
      int index = locationToIndex(e.getPoint());
      if (index != -1) {
        JCheckBox checkbox = getModel().getElementAt(index);

        if (e.getPoint().x < checkbox.getHorizontalTextPosition()) {

          checkbox.setSelected(!checkbox.isSelected());
        }
        repaint();
      }
    }
  });
  setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
 
Example 9
Project: jdk8u-jdk   File: MissingEventsOnModalDialogTest.java   View source code 6 votes vote down vote up
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 10
Project: SpotSpotter   File: CameraShot.java   View source code 6 votes vote down vote up
/**
 * Initialize the contents of the frame.
 */
private void initialize() {
	frame = new JFrame();
	frame.setBounds(100, 100, 800, 450);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.getContentPane().setLayout(null);

	final JButton btnNewButton = new JButton("\u62CD\u7167");
	btnNewButton.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent arg0) {
			flag = 1;// ��̬��������Ϊ1���Ӷ����°�ťʱ��ֹͣ����ͷ�ĵ���
		}
	});
	btnNewButton.setBounds(33, 13, 113, 27);
	frame.getContentPane().add(btnNewButton);

	label = new JLabel("");
	label.setBounds(0, 0, 800, 450);
	frame.getContentPane().add(label);
}
 
Example 11
Project: VISNode   File: ProcessBrowser.java   View source code 6 votes vote down vote up
/**
 * Creates the process list
 *
 * @return JComponent
 */
private JComponent buildList() {
    list = new JList<>();
    list.setCellRenderer(new CellRenderer(list.getCellRenderer()));
    list.setTransferHandler(new ProcessTransferHandler());
    list.setDragEnabled(true);
    list.setDropMode(DropMode.ON_OR_INSERT);
    list.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            if (e.getClickCount() % 2 == 0) {
                ProcessInformationPane.showDialog(list.getSelectedValue());
            }
        }
    });
    return ScrollFactory.pane(list).create();
}
 
Example 12
Project: Equella   File: BusyGlassPane.java   View source code 6 votes vote down vote up
/**
 * GlassPane constructor comment.
 * 
 * @param Container a
 */
protected BusyGlassPane(Component activeComponent, boolean stopClosing)
{
	this.stopClosing = stopClosing;

	// add adapters that do nothing for keyboard and mouse actions
	addMouseListener(new MouseAdapter()
	{
		// We don't care about any events
	});

	addKeyListener(new KeyAdapter()
	{
		// We don't care about any events
	});

	setActiveComponent(activeComponent);
}
 
Example 13
Project: openjdk-jdk10   File: AltGraphModifierTest.java   View source code 6 votes vote down vote up
public static void initTestWindow() {
    mainFrame = new Frame();
    mainFrame.setTitle("TestWindow");
    mainFrame.setBounds(700, 10, 300, 300);
    mainFrame.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            int ex = e.getModifiersEx();
            if ((ex & InputEvent.ALT_GRAPH_DOWN_MASK) == 0) {
                AltGraphModifierTest.fail("Alt-Gr Modifier bit is not set.");
            } else {
                AltGraphModifierTest.pass();
            }
        }
    });
    mainFrame.setVisible(true);
}
 
Example 14
Project: openvisualtraceroute   File: HyperlinkLabel.java   View source code 6 votes vote down vote up
/**
 * Constructor
 */
public HyperlinkLabel() {
	super();
	setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

	setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
	addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(final MouseEvent evt) {
			if (_url != null) {
				Util.browse(_url, getText());
			}
		}
	});
	setForeground(Color.BLUE);
}
 
Example 15
Project: incubator-netbeans   File: CategoryDescriptor.java   View source code 6 votes vote down vote up
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());
            }
        }
    };
}
 
Example 16
Project: incubator-netbeans   File: TaskListTable.java   View source code 6 votes vote down vote up
public MyTableHeader( TableColumnModel model ) {
    super( model );
    addMouseListener( new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if( e.getClickCount() != 1 )
                return;
            int column = columnAtPoint( e.getPoint() );
            if( column > 0 && getModel() instanceof TaskListModel ) {
                ((TaskListModel)getModel()).toggleSort( column );
                repaint();
            }
        }
    });
    this.setReorderingAllowed( false );
}
 
Example 17
Project: WePush   File: TabListener.java   View source code 6 votes vote down vote up
public static void addListeners() {
    // 暂时停止使用,仅留作demo,日后需要时再使用
    MainWindow.mainWindow.getTabbedPane().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            super.mouseClicked(e);
            int index = MainWindow.mainWindow.getTabbedPane().getSelectedIndex();
            switch (index) {
                case 6:
                    break;
                default:
                    break;
            }
        }
    });
}
 
Example 18
Project: incubator-netbeans   File: QueryPanel.java   View source code 6 votes vote down vote up
public ExpandablePanel(JLabel l, JPanel p, final Icon ei, final Icon ci) {
    this.panel = p;
    this.label = l;
    this.ci = ci;
    this.ei = ei;
    this.label.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if(panel.isVisible()) {
                colapse();
            } else {
                expand();
            }
        }
    });
}
 
Example 19
Project: Tarski   File: mxGraphComponent.java   View source code 6 votes vote down vote up
/**
 * Adds handling of edit and stop-edit events after all other handlers have been installed.
 */
protected void installDoubleClickHandler() {
  graphControl.addMouseListener(new MouseAdapter() {
    public void mouseReleased(MouseEvent e) {
      if (isEnabled()) {
        if (!e.isConsumed() && isEditEvent(e)) {
          Object cell = getCellAt(e.getX(), e.getY(), false);

          if (cell != null && getGraph().isCellEditable(cell)) {
            startEditingAtCell(cell, e);
          }
        } else {
          // Other languages use focus traversal here, in Java
          // we explicitely stop editing after a click elsewhere
          stopEditing(!invokesStopCellEditing);
        }
      }
    }

  });
}
 
Example 20
Project: Reinickendorf_SER316   File: TableSorter.java   View source code 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() {
        boolean ascending = false;
        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);
                if (column == sortBy)                    
                    ascending = !ascending;
                else
                    ascending = true; 
                sorter.sortByColumn(column, ascending);   
                tableView.getTableHeader().updateUI();                  
            }
        }
    };
    JTableHeader th = tableView.getTableHeader(); 
    th.addMouseListener(listMouseListener); 
}
 
Example 21
Project: JavaGraph   File: GraphEditorTab.java   View source code 6 votes vote down vote up
/** Post-processes an already constructed toolbar.
 */
private void processToolBar(JToolBar toolBar) {
    for (int i = 0; i < toolBar.getComponentCount(); i++) {
        Component element = toolBar.getComponent(i);
        if (element instanceof JButton) {
            JButton button = (JButton) element;
            Action action = button.getAction();
            if (action != null) {
                getJGraph().addAccelerator(action);
            }
        }
    }
    // ensure the JGraph gets focus as soon as the graph panel
    // is clicked anywhere
    // for reasons not clear to me, mouse listeners do not work on
    // the level of the JGraphPanel
    toolBar.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            getJGraph().requestFocus();
        }
    });
}
 
Example 22
Project: jmt   File: ClassesPanel.java   View source code 6 votes vote down vote up
private void enableDeletes() {
	//deleteOneClass.setEnabled(classes>1);
	//todo zanzottera inserito controllo inizialmente non si possono cancellare le 2 classi
	deleteOneClass.setEnabled(classes > MINCLASSES);
	/*It seems the only way to implement row deletion...*/
	this.addMouseListener(new MouseAdapter() {
		@Override
		public void mouseClicked(MouseEvent e) {
			if (classes > MINCLASSES && (columnAtPoint(e.getPoint()) == getColumnCount() - 1) && getRowCount() > 1) {
				setRowSelectionInterval(rowAtPoint(e.getPoint()), rowAtPoint(e.getPoint()));
				deleteSelectedClasses();
			}
		}
	});
	getColumnModel().getColumn(getColumnCount() - 1).setMinWidth(20);
	getColumnModel().getColumn(getColumnCount() - 1).setMaxWidth(20);
}
 
Example 23
Project: jmt   File: WhatIfPlot.java   View source code 6 votes vote down vote up
public WhatIfPlot(double[] xAxis) {
	super();
	this.xAxis = xAxis;
	// Adds popup menu
	this.addMouseListener(new MouseAdapter() {
		/**
		 * Invoked when the mouse has been clicked on a component.
		 */
		@Override
		public void mouseClicked(MouseEvent e) {
			if (e.getButton() == MouseEvent.BUTTON3) {
				popup.show(WhatIfPlot.this, e.getX(), e.getY());
			}
		}
	});
}
 
Example 24
Project: TransparentDiscord   File: UITitleBar.java   View source code 6 votes vote down vote up
/**
 * Creates a title bar with the given text and ability to close the parent jframe
 * @param titleText the text to display as the title, can be HTML formatted
 * @param parent the jframe to close when the X is clicked
 */
public UITitleBar(String titleText, JFrame parent) {
    setBackground(Color.decode("#7289DA"));
    setLayout(new BorderLayout());

    JLabel title = new JLabel(titleText);
    title.setFont(TransparentDiscord.boldFont.deriveFont(Font.PLAIN, 16));
    title.setBorder(new EmptyBorder(20,20,20,20));
    add(title, BorderLayout.WEST);

    JLabel closeButton = new JLabel("X");
    closeButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            parent.setVisible(false);
        }
    });
    closeButton.setBorder(new EmptyBorder(20,20,20,20));
    closeButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
    add(closeButton, BorderLayout.EAST);
}
 
Example 25
Project: TransparentDiscord   File: UIChannelListItem.java   View source code 6 votes vote down vote up
/**
 * Constructs a list item around a text channel
 * @param channel
 */
public UIChannelListItem(TextChannel channel) {
    this(channel.getId());

    displayName = new JLabel(channel.getName());
    displayName.setFont(TransparentDiscord.defaultFont.deriveFont(Font.PLAIN, 16));
    displayName.setBorder(new EmptyBorder(10,10,10,10));

    add(displayName, BorderLayout.CENTER);

    //When clicked, open the chat
    addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent mouseEvent) {
            TransparentDiscord.openChat(channel);
        }
    });
}
 
Example 26
Project: marathonv5   File: RMenuItemTest.java   View source code 6 votes vote down vote up
public void selectMenuItem() {
    final LoggingRecorder lr = new LoggingRecorder();
    final List<JMenuItem> items = new ArrayList<JMenuItem>();
    siw(new Runnable() {
        @Override public void run() {
            JMenu AMenu = (JMenu) menus.get(0);
            AMenu.doClick();
            items.addAll(getMenuComponents(AMenu));
        }
    });
    items.get(1).addMouseListener(new MouseAdapter() {
        @Override public void mousePressed(MouseEvent e) {
            RMenuItem rMenuItem = new RMenuItem(items.get(1), null, null, lr);
            rMenuItem.mouseButton1Pressed(e);
        }
    });
    IDevice d = Device.getDevice();
    d.click(items.get(1), Buttons.LEFT, 1, 5, 5);
    Call call = lr.getCall();
    AssertJUnit.assertEquals("select_menu", call.getFunction());
    AssertJUnit.assertEquals("A Menu>>Both text and icon", call.getState());
}
 
Example 27
Project: SER316-Ingolstadt   File: TableSorter.java   View source code 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() {
        boolean ascending = false;
        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);
                if (column == sortBy)                    
                    ascending = !ascending;
                else
                    ascending = true; 
                sorter.sortByColumn(column, ascending);   
                tableView.getTableHeader().updateUI();                  
            }
        }
    };
    JTableHeader th = tableView.getTableHeader(); 
    th.addMouseListener(listMouseListener); 
}
 
Example 28
Project: Progetto-C   File: Hiero.java   View source code 6 votes vote down vote up
public void close () {
	final long endTime = System.currentTimeMillis();
	new Thread(new Runnable() {
		public void run () {
			if (endTime - startTime < minMillis) {
				addMouseListener(new MouseAdapter() {
					public void mousePressed (MouseEvent evt) {
						dispose();
					}
				});
				try {
					Thread.sleep(minMillis - (endTime - startTime));
				} catch (InterruptedException ignored) {
				}
			}
			EventQueue.invokeLater(new Runnable() {
				public void run () {
					dispose();
				}
			});
		}
	}, "Splash").start();
}
 
Example 29
Project: onprom   File: CustomTree.java   View source code 6 votes vote down vote up
public void setPopMenu(JPopupMenu _menu) {
  menu = _menu;
  if (menu != null) {
    addMouseListener(new MouseAdapter() {
      @Override
      public void mouseClicked(MouseEvent e) {
        if (SwingUtilities.isRightMouseButton(e)) {
          setSelectionRow(getClosestRowForLocation(e.getX(), e.getY()));
          if (getSelectionCount() > 0 && isRootNotSelected()) {
            menu.show(CustomTree.this, e.getX(), e.getY());
          }
        } else if (e.getClickCount() == 2) {
          try {
            if (action != null)
              action.call();
          } catch (Exception ex) {
            logger.warn(ex.getMessage(), ex);
          }
        }
      }
    });
  }
}
 
Example 30
Project: PTEAssistant   File: UserTableHeaderCellRenderer.java   View source code 6 votes vote down vote up
public UserTableHeaderCellRenderer(JTable table) {
    this.tableModel = (UserTableModel) table.getModel();
    this.tableHeader = table.getTableHeader();
    selectBox = new JCheckBox(tableModel.getColumnName(0));
    selectBox.setSelected(false);
    tableHeader.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 0) {
                int selectColumn = tableHeader.columnAtPoint(e.getPoint());
                if (selectColumn == 0) {
                    boolean value = !selectBox.isSelected();
                    selectBox.setSelected(value);
                    tableModel.selectAll(value);
                    tableHeader.repaint();
                }
            }
        }
    });
}
 
Example 31
Project: SER316-Munich   File: TableSorter.java   View source code 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() {
        boolean ascending = false;
        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);
                if (column == sortBy)                    
                    ascending = !ascending;
                else
                    ascending = true; 
                sorter.sortByColumn(column, ascending);   
                tableView.getTableHeader().updateUI();                  
            }
        }
    };
    JTableHeader th = tableView.getTableHeader(); 
    th.addMouseListener(listMouseListener); 
}
 
Example 32
Project: JavaGraph   File: ResourceDisplay.java   View source code 6 votes vote down vote up
/**
 * Initialises all listening activity on the display, and
 * calls {@link #activateListening()}.
 */
@Override
protected void installListeners() {
    getSimulatorModel().addListener(this, Change.GRAMMAR, Change.toChange(getResourceKind()));
    // adds a mouse listener that offers a popup menu with a detach action
    getTabPane().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getButton() == MouseEvent.BUTTON3) {
                int index = getTabPane().indexAtLocation(e.getX(), e.getY());
                if (index >= 0) {
                    ResourceTab tab = (ResourceTab) getTabPane().getComponentAt(index);
                    if (tab != getMainTab()) {
                        createDetachMenu(tab).show(ResourceDisplay.this, e.getX(), e.getY());
                    }
                }
            }
        }
    });
    activateListening();
}
 
Example 33
Project: chiefproject   File: CreatorPlayerPanelButton.java   View source code 6 votes vote down vote up
public JButton changePlayerGenderRight(){
    JButton changePlayerGender = new JButton(
            readXML.readXML(1,"currency",2));
    changePlayerGender.setForeground(setColor.getColor(setColor.button,1));
    changePlayerGender.setBackground(null);
    changePlayerGender.setBorder(null);
    changePlayerGender.setFont(setFont.getFont(setFont.buttonFontI));
    changePlayerGender.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent mouseEvent) {
            int genderId = Integer.parseInt(cacheHandle.readCache(cacheHandle.player,"gender"));
            switch (genderId){
                case 0:
                    genderId ++;
                    cacheHandle.setCache(cacheHandle.player,"gender",Integer.toString(genderId));
                    loadPanel.loadPanel(loadPanel.creatorPlayerPanelId);
                    break;
                case 1:
                    break;
            }
        }
    });
    return changePlayerGender;
}
 
Example 34
Project: SER316-Dresden   File: TableSorter.java   View source code 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() {
        boolean ascending = false;
        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) {
                //Util.debug("Sorting ...");
                //int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; 
                //boolean ascending = (shiftPressed == 0);
                if (column == sortBy)                    
                    ascending = !ascending;
                else
                    ascending = true; 
                sorter.sortByColumn(column, ascending);   
                tableView.getTableHeader().updateUI();                  
            }
        }
    };
    JTableHeader th = tableView.getTableHeader(); 
    th.addMouseListener(listMouseListener); 
}
 
Example 35
Project: MaxSim   File: CheckRenderer.java   View source code 6 votes vote down vote up
public CheckRenderer(final JList<Object> 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 36
Project: gate-core   File: Splash.java   View source code 6 votes vote down vote up
/**
 * Constructor from owner, GraphicsConfiguration and content.
 */
public Splash(Window owner, GraphicsConfiguration gc, final JComponent content) {
  super(owner, gc);
  getContentPane().setLayout(new BorderLayout());
  content.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
  getContentPane().add(content, BorderLayout.CENTER);
  content.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      // when the content pane is clicked, hide it
      setVisible(false);
    }
  });
  validate();
  pack();
}
 
Example 37
Project: jmonet   File: TextTool.java   View source code 6 votes vote down vote up
private void addTextArea(int x, int y) {
    int left = getCanvas().getBounds().x + x;
    int top = getCanvas().getBounds().y + y;

    textArea.setVisible(true);
    textArea.setBorder(new EmptyBorder(0, 0, 0, 0));
    textArea.setText("");
    textArea.setBounds(left, top, (int)(getCanvas().getBounds().getWidth() * getCanvas().getScale()) - left, (int)(getCanvas().getBounds().getHeight() * getCanvas().getScale()) - top);
    textArea.setFont(getScaledFont());
    textArea.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
            TextTool.this.mousePressed(e, new Point(0, 0));
        }
    });

    getCanvas().addComponent(textArea);
    textArea.requestFocus();
}
 
Example 38
Project: Cognizant-Intelligent-Test-Scripter   File: TestDataComponent.java   View source code 6 votes vote down vote up
private MouseAdapter onAddNewTDTab() {
    return new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent me) {
            JTabbedPane tabbedPane = (JTabbedPane) me.getSource();
            if (tabbedPane.getSelectedIndex() != -1 && getSelectedData() == null) {
                Rectangle rect = tabbedPane.getUI().
                        getTabBounds(tabbedPane, tabbedPane.getSelectedIndex());
                if (rect.contains(me.getPoint())) {
                    tabbedPane.setSelectedIndex(tabbedPane.getSelectedIndex() - 1);
                    addNewTestData(tabbedPane);
                }
            }
        }
    };
}
 
Example 39
Project: Open-DM   File: AboutDialog.java   View source code 6 votes vote down vote up
public AboutDialog(Window owner, String version) {
    super(owner);

    addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            AboutDialog.this.dispose();
        }
    });

    addKeyListener(this);

    setTitle("Open Data Migrator for Hitachi Content Platform");

    ClassLoader cl = this.getClass().getClassLoader();
    SplashPanel panel = new SplashPanel(
            new ImageIcon(cl.getResource("images/HCPDataMigratorSplashBackground.png"))
                    .getImage());

    getContentPane().add(panel);
    setModal(true);
    pack();

    setLocationRelativeTo(owner);
    setResizable(false);
    setVisible(true);
}
 
Example 40
Project: openjdk-jdk10   File: JInternalFrameMoveOverlapping.java   View source code 5 votes vote down vote up
@Override
protected void prepareControls() {


    JDesktopPane desktopPane = new JDesktopPane();

    JInternalFrame bottomFrame = new JInternalFrame("bottom frame", false, false, false, false);
    bottomFrame.setSize(220, 220);
    super.propagateAWTControls(bottomFrame);
    desktopPane.add(bottomFrame);
    bottomFrame.setVisible(true);

    JInternalFrame topFrame = new JInternalFrame("top frame", false, false, false, false);
    topFrame.setSize(200, 200);
    topFrame.add(new JButton("LW Button") {

        {
            addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {
                    lwClicked = true;
                }
            });
        }
    });
    desktopPane.add(topFrame);
    topFrame.setVisible(true);

    JFrame frame = new JFrame("Test Window");
    frame.setSize(300, 300);
    frame.setContentPane(desktopPane);
    frame.setVisible(true);

    locTopFrame = topFrame.getLocationOnScreen();
    locTarget = new Point(locTopFrame.x + bottomFrame.getWidth() / 2, locTopFrame.y + bottomFrame.getHeight()/2);
}