List of usage examples for java.awt.event MouseEvent getClickCount
public int getClickCount()
From source file:org.slage.ui.ConsolePanel.java
/** * Creates a new instance of ConsolePanel * // ww w . j a v a2s . c om * @param owningGame Game that owns this console */ public ConsolePanel(SlageGame owningGame) { this.game = owningGame; updateUI(); textCommand.setBorder(null); // Pressing enter in the command sends it and posts it to the scrollback textCommand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (getGame().isPaused()) return; Command command = null; try { command = getGame().getParser().parseToCommand(textCommand.getText()); } catch (Exception ex) { LOG.debug(ex); } // give focus to frame for keys getGame().getFrame().requestFocusInWindow(); // blank out box textCommand.setText(""); if (command != null) command.fire(); } }); listScrollback.setCellRenderer(new TextRenderer("Cell Renderer", null, null)); // double clicking on the scrollback re-fires the command listScrollback.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (getGame().isPaused()) return; if (evt.getClickCount() == 2 && listScrollback.getSelectedValue() instanceof Command) { Command comm = (Command) listScrollback.getSelectedValue(); comm.fire(); } } }); setLayout(null); // set up scrolling for list scrollback scrollPane = new JScrollPane(listScrollback); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setWheelScrollingEnabled(true); add(scrollPane, BorderLayout.NORTH); add(textCommand, BorderLayout.SOUTH); resize(); }
From source file:io.github.jeremgamer.editor.panels.Actions.java
public Actions(final JFrame frame, final ActionPanel ap) { this.frame = frame; this.setBorder(BorderFactory.createTitledBorder("")); JButton add = null;/*from ww w .j a va 2 s.co m*/ try { add = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("add.png")))); } catch (IOException e) { e.printStackTrace(); } add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") String name = jop.showInputDialog(null, "Nommez l'action :", "Crer une action", JOptionPane.QUESTION_MESSAGE); if (name != null) { for (int i = 0; i < data.getSize(); i++) { if (data.get(i).equals(name)) { name += "1"; } } data.addElement(name); new ActionSave(name); OtherPanel.updateLists(); ButtonPanel.updateLists(); ActionPanel.updateLists(); } } catch (IOException e) { e.printStackTrace(); } } }); JButton remove = null; try { remove = new JButton(new ImageIcon(ImageIO.read(ImageGetter.class.getResource("remove.png")))); } catch (IOException e) { e.printStackTrace(); } remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { if (actionList.getSelectedValue() != null) { File file = new File("projects/" + Editor.getProjectName() + "/actions/" + actionList.getSelectedValue() + ".rbd"); JOptionPane jop = new JOptionPane(); @SuppressWarnings("static-access") int option = jop.showConfirmDialog(null, "tes-vous sr de vouloir supprimer cette action?", "Avertissement", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (option == JOptionPane.OK_OPTION) { if (actionList.getSelectedValue().equals(ap.getFileName())) { ap.setFileName(""); } ap.hide(); file.delete(); data.remove(actionList.getSelectedIndex()); OtherPanel.updateLists(); ButtonPanel.updateLists(); } } } catch (NullPointerException npe) { npe.printStackTrace(); } } }); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.LINE_AXIS)); buttons.add(add); buttons.add(remove); updateList(); actionList.addMouseListener(new MouseAdapter() { @SuppressWarnings("unchecked") public void mouseClicked(MouseEvent evt) { JList<String> list = (JList<String>) evt.getSource(); if (evt.getClickCount() == 2) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } else if (evt.getClickCount() == 3) { int index = list.locationToIndex(evt.getPoint()); if (isOpen == false) { ap.show(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); previousSelection = list.getSelectedValue(); isOpen = true; } else { try { if (previousSelection.equals(list.getModel().getElementAt(index))) { ap.hide(); previousSelection = list.getSelectedValue(); list.clearSelection(); isOpen = false; } else { ap.hideThenShow(); previousSelection = list.getSelectedValue(); ap.load(new File("projects/" + Editor.getProjectName() + "/actions/" + list.getModel().getElementAt(index) + ".rbd")); } } catch (NullPointerException npe) { ap.hide(); list.clearSelection(); } } } } }); JScrollPane listPane = new JScrollPane(actionList); listPane.getVerticalScrollBar().setUnitIncrement(Editor.SCROLL_SPEED); this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS)); this.add(buttons); this.add(listPane); OtherPanel.updateLists(); }
From source file:inflor.core.gates.ui.PolygonGateAdapter.java
@Override public void mouseClicked(MouseEvent e) { Point2D v = ChartUtils.getPlotCoordinates(e, panel); if (SwingUtilities.isLeftMouseButton(e)) { // add the next segment anchorPoint = v;/*from w w w . j av a 2 s . co m*/ vertices.add(v); updateTemporaryAnnotation(); } if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { XYLineAnnotation closingSegment = new XYLineAnnotation(anchorPoint.getX(), anchorPoint.getY(), vertices.get(0).getX(), vertices.get(0).getY()); segments.add(closingSegment); panel.addTemporaryAnnotation(closingSegment); // Finish the polygon and ask for a name int pointCount = vertices.size() * 2; double[] polygon = new double[pointCount]; for (int i = 0; i < pointCount; i++) { polygon[i] = vertices.get(i / 2).getX(); polygon[i + 1] = vertices.get(i / 2).getY(); i++;//Sonar warning but wont fix, I think. } // Pop a gate editor dialog GateNameEditor dialog = new GateNameEditor(); dialog.setVisible(true); // On Close... if (dialog.isOK()) { PolygonGateAnnotation finalPolygon = new PolygonGateAnnotation(dialog.getGateName(), panel.getDomainAxisName(), panel.getRangeAxisName(), polygon, LookAndFeel.DEFAULT_STROKE, LookAndFeel.DEFAULT_GATE_COLOR); panel.createGateAnnotation(finalPolygon); } dialog.dispose(); // remove the anchor point && cleanup segments. vertices.clear(); panel.removeTemporaryAnnotation(anchorSegment); anchorSegment = null; anchorPoint = null; segments.forEach(panel::removeTemporaryAnnotation);//TODO:if this is broken, maybe sonar was wrong? segments = null; panel.activateGateSelectButton(); } }
From source file:br.org.acessobrasil.ases.ferramentas_de_reparo.vista.xhtml.PainelXHTML.java
public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 2) { int row = this.tabelaDeErros.getSelectedRow(); if (row == -1) return; int linhaToGo = Integer.parseInt(tabelaDeErros.getValueAt(row, 0).toString()); if (linhaToGo == 0) return; textAreaSourceCode.goToLine(linhaToGo); textAreaSourceCode.selectLine(linhaToGo); }/*from w w w.j av a2s . c o m*/ }
From source file:net.sourceforge.happybank.main.BankMain.java
private void initComponents() { frame = new javax.swing.JFrame(); menuBar = new javax.swing.JMenuBar(); menuFile = new javax.swing.JMenu(); menuItemExit = new javax.swing.JMenuItem(); menuActions = new javax.swing.JMenu(); menuItemView = new javax.swing.JMenuItem(); separator2 = new javax.swing.JSeparator(); menuHelp = new javax.swing.JMenu(); separator4 = new javax.swing.JSeparator(); menuItemAbout = new javax.swing.JMenuItem(); accountEntries = new javax.swing.JTable(); accountModel = new AccountTableModel(); /*//from www .ja va 2s. co m * File menu */ menuFile.setMnemonic('F'); menuFile.setText("File"); // - Exit option menuItemExit.setMnemonic('X'); menuItemExit.setText("Exit"); menuItemExit.setActionCommand("Exit"); menuItemExit.addActionListener(new ActionHandler()); menuFile.add(menuItemExit); menuBar.add(menuFile); // Actions menu menuActions.setMnemonic('A'); menuActions.setText("Actions"); // - View option menuItemView.setMnemonic('V'); menuItemView .setAccelerator(KeyStroke.getKeyStroke('V', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menuItemView.setText("View"); menuItemView.setActionCommand("View"); menuItemView.addActionListener(new ActionHandler()); menuActions.add(menuItemView); menuActions.add(separator2); // Help menu menuHelp.setMnemonic('H'); menuHelp.setText("Help"); // - About option menuHelp.add(separator4); menuItemAbout.setMnemonic('A'); menuItemAbout.setText("About"); menuItemAbout.setActionCommand("About"); menuItemAbout.addActionListener(new ActionHandler()); menuHelp.add(menuItemAbout); menuBar.add(menuHelp); /* * configure the TabListCellRenderer */ accountEntries.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); accountEntries.setAutoCreateColumnsFromModel(false); accountEntries.setModel(accountModel); accountEntries.getTableHeader().setReorderingAllowed(false); accountEntries.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); accountEntries.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { // capture single click if (evt.getClickCount() == 1 && SwingUtilities.isLeftMouseButton(evt)) { // ignore } // capture double click if (evt.getClickCount() == 2) { // edit the account int row = accountEntries.rowAtPoint(evt.getPoint()); accountEntries.setRowSelectionInterval(row, row); onViewAccount(); } } // mouseClicked }); // MouseAdapter // set the column widths and alignment for (int k = 0; k < AccountTableModel.COLUMNS.length; k++) { TableCellEditor zipper = new DefaultCellEditor(new JTextField()); DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(AccountTableModel.COLUMNS[k].cAlignment); TableColumn column = new TableColumn(k, AccountTableModel.COLUMNS[k].cWidth, textRenderer, zipper); accountEntries.addColumn(column); } // set the table header JTableHeader header = accountEntries.getTableHeader(); header.setUpdateTableInRealTime(false); /* * create the selection area */ accountPanel = new JPanel(); accountPanel.setLayout(new BorderLayout()); scrollPane = new JScrollPane(accountEntries); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); scrollPane.setPreferredSize(new java.awt.Dimension(750, 300)); accountPanel.add(scrollPane); frame.getContentPane().add(accountPanel, java.awt.BorderLayout.CENTER); /* * layout the frame */ frame.setJMenuBar(menuBar); frame.setTitle(APP_NAME); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(screenSize.width / 2 - 300, screenSize.height / 2 - 200); // add a listener for the close event frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { onExit(); } }); loadAccounts(); }
From source file:org.colombbus.tangara.ConfigurationWindow.java
/** * This method initializes the components to put in this JFrame. * *///from www.j a va2 s .c o m private void initialize() { //We load the default properties. loadDefaultProperties(); //We load the table contents. loadProperties(); String[] columnNames = { Messages.getString("ConfigurationWindow.propertyColumn"), Messages.getString("ConfigurationWindow.valueColumn") }; SpecialTableModel model = new SpecialTableModel(modelData, columnNames); propertiesTable = new JTable(model); propertiesTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //We set the double click listener on the table. propertiesTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = propertiesTable.rowAtPoint(p); ConfigurationPropertyWindow confPropertyWindow = new ConfigurationPropertyWindow( ConfigurationWindow.this, row, (String) propertiesTable.getValueAt(row, 0), (String) propertiesTable.getValueAt(row, 1)); confPropertyWindow.setVisible(true); } } }); //We set the content pane of the window. this.setContentPane(getMainPanel()); }
From source file:com.diversityarrays.kdxplore.editing.EntityPropertiesTable.java
@Override public boolean editCellAt(int row, int column, EventObject e) { if (e instanceof MouseEvent) { MouseEvent me = (MouseEvent) e; if (SwingUtilities.isLeftMouseButton(me) && 2 != me.getClickCount()) { return false; }/*from w ww . j a v a2 s. c om*/ me.consume(); } @SuppressWarnings("unchecked") EntityPropertiesTableModel<T> eptm = (EntityPropertiesTableModel<T>) getModel(); if (!eptm.isCellEditable(row, column)) { return false; } if (handleEditCellAt(eptm, row, column)) { return false; } PropertyDescriptor pd = eptm.getPropertyDescriptor(row); if (pd == null) { return super.editCellAt(row, column); } Class<?> propertyClass = pd.getPropertyType(); if (propertyChangeConfirmer != null && !propertyChangeConfirmer.isChangeAllowed(pd)) { return false; } if (java.util.Date.class.isAssignableFrom(propertyClass)) { try { java.util.Date dateValue = (Date) pd.getReadMethod().invoke(eptm.getEntity()); if (propertyChangeConfirmer != null) { propertyChangeConfirmer.setValueBeforeChange(dateValue); } Closure<Date> onComplete = new Closure<Date>() { @Override public void execute(Date result) { if (result != null) { if (propertyChangeConfirmer == null || propertyChangeConfirmer.valueChangeCanCommit(pd, result)) { getModel().setValueAt(result, row, column); } } } }; String title = pd.getDisplayName(); DatePickerDialog datePicker = new DatePickerDialog(GuiUtil.getOwnerWindow(this), title, onComplete); datePicker.setDate(dateValue); datePicker.setVisible(true); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e1) { e1.printStackTrace(); } return false; } // else if (Enum.class.isAssignableFrom(propertyClass)) { // } Log.d(TAG, "editCellAt(" + row + "," + column + ") No Editor override provided for " + propertyClass.getName()); return super.editCellAt(row, column, e); }
From source file:MouseDragActionPanel.java
public MouseDragActionPanel() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); currentSquareIndex = getSquare(x, y); if (currentSquareIndex < 0) // not inside a square add(x, y);/*ww w .j a va 2 s. co m*/ } public void mouseClicked(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); if (evt.getClickCount() >= 2) { remove(currentSquareIndex); } } }); addMouseMotionListener(this); }
From source file:savant.plugin.builtin.SAFEBrowser.java
public final Component getCenterPanel(List<TreeBrowserEntry> roots) { table = new TreeTable(new TreeBrowserModel(roots) { @Override//ww w .ja v a 2 s.com public String[] getColumnNames() { return new String[] { "Name", "Description" }; } }); table.setSortable(false); table.setRespectRenderPreferredHeight(true); // configure the TreeTable table.setExpandAllAllowed(true); table.setShowTreeLines(false); table.setSortingEnabled(false); table.setRowHeight(18); table.setShowGrid(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.expandFirstLevel(); table.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { actOnSelectedItem(true); } } @Override public void mousePressed(MouseEvent e) { } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } }); // do not select row when expanding a row. table.setSelectRowWhenToggling(false); table.getColumnModel().getColumn(0).setPreferredWidth(200); //table.getColumnModel().getColumn(1).setPreferredWidth(400); //table.getColumnModel().getColumn(2).setPreferredWidth(100); //table.getColumnModel().getColumn(3).setPreferredWidth(100); //table.getColumnModel().getColumn(4).setPreferredWidth(50); table.getColumnModel().getColumn(0).setCellRenderer(FILE_RENDERER); // add searchable feature TableSearchable searchable = new TableSearchable(table) { @Override protected String convertElementToString(Object item) { if (item instanceof TreeBrowserEntry) { return ((TreeBrowserEntry) item).getType(); } return super.convertElementToString(item); } }; searchable.setMainIndex(0); // only search for name column JScrollPane scrollPane = new JScrollPane(table); scrollPane.getViewport().setBackground(Color.WHITE); JPanel panel = new JPanel(new BorderLayout(6, 6)); panel.add(scrollPane, BorderLayout.CENTER); panel.setPreferredSize(new Dimension(800, 500)); return panel; }
From source file:br.com.utfpr.pb.view.CaixasView.java
private void jTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableMouseClicked // TODO add your handling code here: tableEvent();//from ww w.j a v a 2 s. c om if (evt.getClickCount() == 2 && !evt.isConsumed()) { evt.consume(); //handle double click event. openModal(); } }