List of usage examples for java.awt.event MouseEvent getSource
public Object getSource()
From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java
private void fireTransferAttacksToAttackViewEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireTransferAttacksToAttackViewEvent if (evt.getSource() == jInsertButton) { String planName = jNewAttackPlanField.getText(); if (planName.length() == 0) { planName = (String) jExistingAttackPlanBox.getSelectedItem(); } else {/*from w w w. j a va 2s.co m*/ AttackManager.getSingleton().addGroup(planName); } int[] rows = jResultTable.getSelectedRows(); AttackManager.getSingleton().invalidate(); for (int row : rows) { Village source = (Village) jResultTable.getValueAt(row, 0); UnitHolder unit = (UnitHolder) jResultTable.getValueAt(row, 1); Village target = (Village) jResultTable.getValueAt(row, 2); Date sendTime = (Date) jResultTable.getValueAt(row, 3); double dist = DSCalculator.calculateDistance(source, target); long runtime = Math.round(dist * unit.getSpeed() * 60000); AttackManager.getSingleton().addAttack(source, target, unit, new Date(sendTime.getTime() + runtime), false, planName, Attack.NO_TYPE, false); } AttackManager.getSingleton().revalidate(); } jAttackPlanSelectionDialog.setVisible(false); }
From source file:com.jcraft.weirdx.DDXWindowImpSwing.java
public void mouseEntered(MouseEvent e) { if (window != null && window.getFrame() != null) { java.awt.Window frame = window.getFrame(); if ((frame instanceof java.awt.Frame) && frame == e.getSource()) { try { if (window.isRealized()) { XWindow.setInputFocus(window.client, window.id, 1, (int) System.currentTimeMillis(), false); }// w w w . j av a 2 s. com } catch (Exception ee) { LOG.error(ee); } return; } } String str = CopyPaste.getString(); if (!CopyPaste.isOwner() && str != null) { synchronized (window.screen.root) { Property p = window.screen.root.getProperty(); while (p != null) { if (p.propertyName == 9) break; p = p.next; } if (p != null) { p.data = str.getBytes(); p.size = p.data.length; } } Selection sel = Selection.getSelection(1); // PRIMARY if (sel != null && sel.client != null) { int time = (int) System.currentTimeMillis(); Event event = new Event(); event.mkSelectionClear(time, sel.wid, sel.selection); try { sel.client.sendEvent(event, 1, Event.NoEventMask, Event.NoEventMask, null); } catch (Exception ee) { //System.out.println(ee); } ; sel.window = window.screen.root; sel.wid = window.screen.root.id; sel.lastTimeChanged = time; sel.client = null; } CopyPaste.setString(str); } if (window.id == window.screen.rootId) { return; } if (window.isMapped()) { requestFocus(); XWindow.focus.win = window.id; } int x = e.getX() + window.x; int y = e.getY() + window.y; XWindow.sprite.hot.x = x; XWindow.sprite.hot.y = y; int mod = e.getModifiers(); int state = 0; if ((mod & InputEvent.BUTTON1_MASK) != 0) state |= (1 << 8); if ((mod & InputEvent.BUTTON2_MASK) != 0) state |= (1 << 9); if ((mod & InputEvent.BUTTON3_MASK) != 0) state |= (1 << 10); if ((mod & InputEvent.SHIFT_MASK) != 0) state |= 1; if ((mod & InputEvent.CTRL_MASK) != 0) state |= 4; // alt -> state|=8; Client client = window.client; if (client == null || client == serverClient) return; event.mkEnterNotify(0, // Ancestor window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 0, // Normal 0x1 | 0x02 // focus|same-screen ); try { XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1); } catch (Exception ee) { } }
From source file:com.vgi.mafscaling.LogView.java
private void createLogViewPanel() { logViewPanel = new JPanel(); GridBagLayout gbl_logViewPanel = new GridBagLayout(); gbl_logViewPanel.columnWidths = new int[] { 0 }; gbl_logViewPanel.rowHeights = new int[] { 0, 0 }; gbl_logViewPanel.columnWeights = new double[] { 1.0 }; gbl_logViewPanel.rowWeights = new double[] { 1.0, 0.0 }; logViewPanel.setLayout(gbl_logViewPanel); try {/*ww w.j a va2 s . com*/ logDataTable = new DBTable(); logDataTable.copyColumnHeaderNames = true; logDataTable.defaultClickCountToStartEditor = 2; logDataTable.doNotUseDatabaseSort = true; logDataTable.listenKeyPressEventsWholeWindow = true; logDataTable.createControlPanel(DBTable.READ_NAVIGATION); logDataTable.enableExcelCopyPaste(); logDataTable.setSortEnabled(false); logDataTable.setSkin(new TableSkin()); logDataTable.refresh(new String[1][25]); logDataTable.setComparator(new DoubleComparator()); logDataTable.getTable().setCellSelectionEnabled(true); logDataTable.getTable().setColumnSelectionAllowed(true); logDataTable.getTable().setRowSelectionAllowed(true); logDataTable.getTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JTextField rowTextField = ((JTextField) logDataTable.getControlPanel().getComponent(3)); rowTextField.setPreferredSize(null); rowTextField.setColumns(5); GridBagConstraints gbc_logDataTable = new GridBagConstraints(); gbc_logDataTable.insets = insets0; gbc_logDataTable.anchor = GridBagConstraints.PAGE_START; gbc_logDataTable.fill = GridBagConstraints.BOTH; gbc_logDataTable.gridx = 0; gbc_logDataTable.gridy = 0; logViewPanel.add(logDataTable, gbc_logDataTable); listModel = new DefaultListModel<JLabel>(); selectionCombo.removeAllItems(); String name; JTableHeader tableHeader = logDataTable.getTableHeader(); for (int i = 0; i < logDataTable.getColumnCount(); ++i) { Column col = logDataTable.getColumn(i); col.setNullable(true); col.setHeaderRenderer(new CheckboxHeaderRenderer(i + 1, tableHeader)); name = col.getHeaderValue().toString(); selectionCombo.addItem(name); listModel.addElement(new JLabel(name, new CheckBoxIcon(), JLabel.LEFT)); } JList<JLabel> menuList = new JList<JLabel>(listModel); menuList.setOpaque(false); menuList.setCellRenderer(new ImageListCellRenderer()); menuList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); menuList.setLayoutOrientation(JList.VERTICAL); menuList.setFixedCellHeight(25); menuList.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { if (e.getClickCount() == 1 && colors.size() > 0) { JList<?> list = (JList<?>) e.getSource(); int index = list.locationToIndex(e.getPoint()); if (index >= 0) { int colIdx = logDataTable.getCurrentIndexForOriginalColumn(index); Column col = logDataTable.getColumn(colIdx); if (col.getHeaderRenderer() instanceof CheckboxHeaderRenderer) { CheckboxHeaderRenderer renderer = (CheckboxHeaderRenderer) col .getHeaderRenderer(); JLabel label = (JLabel) list.getModel().getElementAt(index); CheckBoxIcon checkIcon = (CheckBoxIcon) label.getIcon(); checkIcon.setChecked(!checkIcon.isChecked()); if (checkIcon.isChecked()) { checkIcon.setColor(colors.pop()); JTable table = logDataTable.getTable(); TableModel model = table.getModel(); addXYSeries(model, index, col.getHeaderValue().toString(), checkIcon.getColor()); } else { colors.push(checkIcon.getColor()); checkIcon.setColor(renderer.getDefaultColor()); removeXYSeries(index); } list.repaint(); } } } } catch (Exception ex) { ex.printStackTrace(); } } }); headerScrollPane = new JScrollPane(menuList); GridBagConstraints gbc_headersTree = new GridBagConstraints(); gbc_headersTree.insets = insets0; gbc_headersTree.anchor = GridBagConstraints.PAGE_START; gbc_headersTree.fill = GridBagConstraints.BOTH; gbc_headersTree.gridx = 0; gbc_headersTree.gridy = 1; logViewPanel.add(headerScrollPane, gbc_headersTree); headerScrollPane.setVisible(false); } catch (Exception e) { e.printStackTrace(); logger.error(e); } }
From source file:edu.ku.brc.af.ui.forms.validation.ValFormattedTextFieldSingle.java
/** * @param formatterArg the formatter (can't be null) * @param isViewOnlyArg is it for view mode * @param isPartialOK can only a part of the format be typed in (used for search forms) * @param suggestedNumCols suggested number of columns that can be bigger than the format *///from w w w .ja v a 2 s. c om protected void init(final UIFieldFormatterIFace formatterArg, final boolean isViewOnlyArg, final boolean isPartialOKArg, final Integer suggNumCols, final boolean addFocusListeners) { setControlSize(this); isPartialOK = isPartialOKArg; this.isViewOnly = isViewOnlyArg; this.suggestedNumCols = suggNumCols; initColors(); inner = getInsets(); setFormatterInternal(formatterArg); //log.debug(formatter.getName()); int numCols; if (suggestedNumCols != null) { numCols = Math.max(suggestedNumCols, formatter.getUILength()); } else { numCols = formatter.getUILength(); } setColumns(numCols); addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent) */ @Override public void mousePressed(MouseEvent e) { //System.err.println(e); super.mousePressed(e); } }); if (addFocusListeners) { addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { log.debug("[" + getText() + "]"); ((JTextField) e.getSource()).selectAll(); //System.err.println(e); repaint(); } @Override public void focusLost(FocusEvent e) { isNew = false; validateState(); repaint(); } }); } setBackground(isRequired ? requiredFieldColor.getColor() : viewBGColor.getColor()); if (!isViewOnlyArg) { if (!formatterArg.isUserInputNeeded() && !isPartialOK && isAutoFmtOn) { ViewFactory.changeTextFieldUIForDisplay(this, false); } else { super.setEnabled(true); } } }
From source file:com.jcraft.weirdx.DDXWindowImp.java
public void mouseEntered(MouseEvent e) { if (window == null) return;//from w w w . j a v a 2s . c o m if (window.getFrame() != null) { java.awt.Window frame = window.getFrame(); if ((frame instanceof java.awt.Frame) && frame == e.getSource()) { try { if (window.isRealized()) { XWindow.setInputFocus(window.client, window.id, 1, (int) System.currentTimeMillis(), false); } } catch (Exception ee) { LOG.error(ee); } return; } } String str = CopyPaste.getString(); if (!CopyPaste.isOwner() && str != null) { synchronized (window.screen.root) { Property p = window.screen.root.getProperty(); while (p != null) { if (p.propertyName == 9) break; p = p.next; } if (p != null) { p.data = str.getBytes(); p.size = p.data.length; } } Selection sel = Selection.getSelection(1); // PRIMARY if (sel != null && sel.client != null) { int time = (int) System.currentTimeMillis(); Event event = new Event(); event.mkSelectionClear(time, sel.wid, sel.selection); try { sel.client.sendEvent(event, 1, Event.NoEventMask, Event.NoEventMask, null); } catch (Exception ee) { //System.out.println(ee); } ; sel.window = window.screen.root; sel.wid = window.screen.root.id; sel.lastTimeChanged = time; sel.client = null; } CopyPaste.setString(str); } if (window.id == window.screen.rootId) { return; } if (window.isMapped()) { requestFocus(); XWindow.focus.win = window.id; } int x = e.getX() + window.x; int y = e.getY() + window.y; XWindow.sprite.hot.x = x; XWindow.sprite.hot.y = y; int mod = e.getModifiers(); int state = 0; if ((mod & InputEvent.BUTTON1_MASK) != 0) state |= (1 << 8); if ((mod & InputEvent.BUTTON2_MASK) != 0) state |= (1 << 9); if ((mod & InputEvent.BUTTON3_MASK) != 0) state |= (1 << 10); if ((mod & InputEvent.SHIFT_MASK) != 0) state |= 1; if ((mod & InputEvent.CTRL_MASK) != 0) state |= 4; // alt -> state|=8; Client client = window.client; if (client == null || client == serverClient) return; event.mkEnterNotify(0, // Ancestor window.screen.rootId, window.id, 0, x, y, e.getX(), e.getY(), state, 0, // Normal 0x1 | 0x02 // focus|same-screen ); try { XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1); } catch (Exception ee) { } }
From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java
private void fireCalculateReTimingsEvent(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_fireCalculateReTimingsEvent jCalculationSettingsDialog.setVisible(false); if (evt.getSource() == jDoCalculateButton) { DefaultTableModel model = (DefaultTableModel) jAttackPlanTable.getModel(); List<String> selectedPlans = new LinkedList<String>(); for (int i = 0; i < jAttackPlanTable.getRowCount(); i++) { int row = jAttackPlanTable.convertRowIndexToModel(i); if ((Boolean) model.getValueAt(row, 1)) { selectedPlans.add((String) model.getValueAt(row, 0)); }//w ww.j a v a 2 s . co m } List<Village> ignore = new LinkedList<Village>(); //process all plans for (String plan : selectedPlans) { logger.debug("Checking plan '" + plan + "'"); List<ManageableType> elements = AttackManager.getSingleton().getAllElements(plan); //process all attacks for (ManageableType element : elements) { Attack a = (Attack) element; if (!ignore.contains(a.getSource())) { ignore.add(a.getSource()); } } } Object[] tags = jTagList.getSelectedValues(); if (tags == null || tags.length == 0) { JOptionPaneHelper.showInformationBox(DSWorkbenchReTimerFrame.this, "Keine Dorfgruppe ausgewhlt", "Information"); return; } List<Village> candidates = new LinkedList<Village>(); for (Object o : tags) { Tag t = (Tag) o; List<Integer> ids = t.getVillageIDs(); for (Integer id : ids) { //add all villages tagged by current tag Village v = DataHolder.getSingleton().getVillagesById().get(id); if (!candidates.contains(v) && !ignore.contains(v)) { candidates.add(v); } } } if (jRelationBox.isSelected()) { //remove all villages that are not tagges by the current tag boolean oneFailed = false; Village[] aCandidates = candidates.toArray(new Village[] {}); for (Village v_tmp : aCandidates) { for (Object o : tags) { Tag t = (Tag) o; if (!t.tagsVillage(v_tmp.getId())) { oneFailed = true; break; } } if (oneFailed) { //at least one tag is not valid for village candidates.remove(v_tmp); oneFailed = false; } } } Village target = parsedAttack.getSource(); UnitHolder unit = (UnitHolder) jUnitBox.getSelectedItem(); Hashtable<Village, Date> timings = new Hashtable<Village, Date>(); for (Village candidate : candidates) { double dist = DSCalculator.calculateDistance(candidate, target); long runtime = Math.round(dist * unit.getSpeed() * 60000.0); VillageTroopsHolder holder = TroopsManager.getSingleton().getTroopsForVillage(candidate, TroopsManager.TROOP_TYPE.OWN); boolean useVillage = true; if (holder != null) { if (holder.getTroopsOfUnitInVillage(unit) == 0) { useVillage = false; } } if (useVillage) { try { double dur = DSCalculator.calculateMoveTimeInSeconds(parsedAttack.getSource(), target, unit.getSpeed()) * 1000.0; double ret = (double) parsedAttack.getArriveTime().getTime() + dur; ret /= 1000; ret = Math.round(ret + .5); ret *= 1000; long sendTime = (long) ret - runtime; if (sendTime > System.currentTimeMillis() + 60000) { timings.put(candidate, new Date(sendTime)); } } catch (Exception e) { } } } buildResults(timings, target, unit); } }
From source file:org.yccheok.jstock.gui.NewBuyTransactionJDialog.java
private MouseListener getJFormattedTextFieldMouseListener() { MouseListener ml = new MouseAdapter() { @Override//from ww w . j a va 2 s .c o m public void mousePressed(final MouseEvent e) { if (e.getClickCount() == 2) { // Ignore double click. return; } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JTextField tf = (JTextField) e.getSource(); int offset = tf.viewToModel(e.getPoint()); tf.setCaretPosition(offset); } }); } }; return ml; }
From source file:com.jcraft.weirdx.DDXWindowImpSwing.java
@SuppressWarnings("unused") public void mouseDragged(MouseEvent e) { if (threeButton) { if (threeBstate != s) { if (threeBstate == sp) { procPressed(threeBPressed); threeBPressed = null;/*from www. j a va 2 s. com*/ threeBstate = s; } else if (threeBstate == spp) { e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK))) | InputEvent.BUTTON2_MASK, e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()); } else if (threeBstate == sppr) { return; } } } int x = e.getX() + window.x; int y = e.getY() + window.y; XWindow.sprite.hot.x = x; XWindow.sprite.hot.y = y; int mod = e.getModifiers(); // button 1 -> 16 // button 2 -> 8 // button 3 -> 4 // shift -> 1 // control -> 2 // alt -> 12 ?? int state = 0; int detail = 0; if ((mod & InputEvent.BUTTON1_MASK) != 0) { state |= (1 << 8); detail = 1; } if ((mod & InputEvent.BUTTON2_MASK) != 0) { state |= (1 << 9); detail = 2; } if ((mod & InputEvent.BUTTON3_MASK) != 0) { state |= (1 << 10); detail = 3; } if ((mod & InputEvent.SHIFT_MASK) != 0) state |= 1; if ((mod & InputEvent.CTRL_MASK) != 0) state |= 4; // alt -> state|=8; XWindow.sprite.hot.state = state; px = x; py = y; event.mkMotionNotify(1, window.screen.rootId, /*window.id,*/ XWindow.sprite.win.id, 0, px, py, e.getX(), e.getY(), state, 1); try { if (!XWindow.checkMotion(event, window)) { return; } event.mkMotionNotify(1, window.screen.rootId, /*window.id,*/ XWindow.sprite.win.id, 0, px, py, px - XWindow.sprite.win.x, py - XWindow.sprite.win.y, //e.getX(), //e.getY(), state, 1); if (XWindow.grab != null) XWindow.sendGrabbedEvent(event, false, 1); else XWindow.sendDeviceEvent(XWindow.sprite.win, event, XWindow.grab, null, 1); } catch (Exception ee) { } }
From source file:com.jcraft.weirdx.DDXWindowImp.java
public void mousePressed(MouseEvent e) { if (threeButton) { if (threeBstate == s) { threeBPressed = e;/*from ww w . j a v a 2 s . co m*/ threeBstate = sp; return; } if (threeBstate == sp // || threeBstate==sppr ) { threeBPressed = null; threeBstate = spp; e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK))) | InputEvent.BUTTON2_MASK, e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()); } } procPressed(e); }
From source file:com.jcraft.weirdx.DDXWindowImp.java
@SuppressWarnings("unused") public void mouseDragged(MouseEvent e) { if (threeButton) { if (threeBstate != s) { if (threeBstate == sp) { procPressed(threeBPressed); threeBPressed = null;/* ww w .j a v a 2 s . co m*/ threeBstate = s; } else if (threeBstate == spp) { e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK))) | InputEvent.BUTTON2_MASK, e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger()); } else if (threeBstate == sppr) { return; } } } if (window == null) return; // calc abs cursor position use old window position for calculation // as mouseDragged (if you use Panel) delivers its coordinates relative to the position after mousepressed // UPDATE: this was a bug of the IBM JDK // int x=e.getX()+oldwindowx; // int y=e.getY()+oldwindowy; int x = e.getX() + window.x; int y = e.getY() + window.y; // set new drag position (absolute) XWindow.sprite.hot.x = x; XWindow.sprite.hot.y = y; int mod = e.getModifiers(); // button 1 -> 16 // button 2 -> 8 // button 3 -> 4 // shift -> 1 // control -> 2 // alt -> 12 ?? int state = 0; int detail = 0; if ((mod & InputEvent.BUTTON1_MASK) != 0) { state |= (1 << 8); detail = 1; } if ((mod & InputEvent.BUTTON2_MASK) != 0) { state |= (1 << 9); detail = 2; } if ((mod & InputEvent.BUTTON3_MASK) != 0) { state |= (1 << 10); detail = 3; } if ((mod & InputEvent.SHIFT_MASK) != 0) state |= 1; if ((mod & InputEvent.CTRL_MASK) != 0) state |= 4; // alt -> state|=8; XWindow.sprite.hot.state = state; px = x; py = y; event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py, e.getX(), e.getY(), state, 1); try { if (!XWindow.checkMotion(event, window)) { return; } event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py, px - XWindow.sprite.win.x, py - XWindow.sprite.win.y, state, 1); if (XWindow.grab != null) { XWindow.sendGrabbedEvent(event, false, 1); } else { XWindow.sendDeviceEvent(XWindow.sprite.win, event, XWindow.grab, null, 1); } } catch (Exception ee) { } }