List of usage examples for java.awt.event MouseEvent getPoint
public Point getPoint()
From source file:org.omegat.gui.scripting.ScriptingWindow.java
private void initWindowLayout() { // set default size and position frame.setBounds(50, 80, 1150, 650);/*from w w w . j av a 2 s . c o m*/ StaticUIUtils.persistGeometry(frame, Preferences.SCRIPTWINDOW_GEOMETRY_PREFIX); frame.getContentPane().setLayout(new BorderLayout(0, 0)); m_scriptList = new JList<>(); JScrollPane scrollPaneList = new JScrollPane(m_scriptList); m_scriptList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (!evt.getValueIsAdjusting()) { onListSelectionChanged(); } } }); m_scriptList.addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { ListModel<ScriptItem> lm = m_scriptList.getModel(); int index = m_scriptList.locationToIndex(e.getPoint()); if (index > -1) { m_scriptList.setToolTipText(lm.getElementAt(index).getFile().getName()); } } }); m_txtResult = new JEditorPane(); JScrollPane scrollPaneResults = new JScrollPane(m_txtResult); //m_txtScriptEditor = new StandardScriptEditor(); m_txtScriptEditor = getScriptEditor(); m_txtScriptEditor.initLayout(this); JSplitPane splitPane1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, m_txtScriptEditor.getPanel(), scrollPaneResults); splitPane1.setOneTouchExpandable(true); splitPane1.setDividerLocation(430); Dimension minimumSize1 = new Dimension(100, 50); //scrollPaneEditor.setMinimumSize(minimumSize1); scrollPaneResults.setMinimumSize(minimumSize1); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scrollPaneList, splitPane1); splitPane.setOneTouchExpandable(true); splitPane.setDividerLocation(250); Dimension minimumSize = new Dimension(100, 50); scrollPaneList.setMinimumSize(minimumSize); scrollPaneResults.setMinimumSize(minimumSize); frame.getContentPane().add(splitPane, BorderLayout.CENTER); JPanel panelSouth = new JPanel(); FlowLayout fl_panelSouth = (FlowLayout) panelSouth.getLayout(); fl_panelSouth.setAlignment(FlowLayout.LEFT); frame.getContentPane().add(panelSouth, BorderLayout.SOUTH); setupRunButtons(panelSouth); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); frame.setJMenuBar(createMenuBar()); }
From source file:org.openmicroscopy.shoola.agents.util.ui.ScriptingDialog.java
/** Initializes the components. */ private void initComponents() { sorter = new ViewerSorter(); cancelButton = new JButton("Cancel"); cancelButton.setToolTipText("Close the dialog."); cancelButton.setActionCommand("" + CANCEL); cancelButton.addActionListener(this); applyButton = new JButton("Run Script"); applyButton.setToolTipText("Run the selected script."); applyButton.setActionCommand("" + APPLY); applyButton.addActionListener(this); IconManager icons = IconManager.getInstance(); menuButton = new JButton(icons.getIcon(IconManager.FILTER_MENU)); menuButton.setText("Script"); menuButton.setHorizontalTextPosition(JButton.LEFT); menuButton.addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { Object src = e.getSource(); if (src instanceof Component) { Point p = e.getPoint(); createOptionMenu().show((Component) src, p.x, p.y); }/*ww w . j ava 2s. c o m*/ } }); components = new LinkedHashMap<String, ScriptComponent>(); componentsAll = new LinkedHashMap<String, ScriptComponent>(); Map<String, ParamData> types = script.getInputs(); if (types == null) return; List<ScriptComponent> results = new ArrayList<ScriptComponent>(); Entry<String, ParamData> entry; ParamData param; JComponent comp; ScriptComponent c; String name; Class<?> type; Object defValue; Iterator<Entry<String, ParamData>> i = types.entrySet().iterator(); List<Object> values; Number n; String details = ""; String text = ""; String grouping; String parent; Map<String, List<ScriptComponent>> childrenMap = new HashMap<String, List<ScriptComponent>>(); List<ScriptComponent> l; int length; boolean columnsSet; while (i.hasNext()) { text = ""; columnsSet = false; comp = null; entry = i.next(); param = entry.getValue(); name = entry.getKey(); type = param.getPrototype(); values = param.getValues(); defValue = param.getDefaultValue(); if (CollectionUtils.isNotEmpty(values)) { comp = createValuesBox(values, defValue); } if (Long.class.equals(type) || Integer.class.equals(type) || Float.class.equals(type) || Double.class.equals(type)) { if (comp == null) { if (script.isIdentifier(name)) { comp = new NumericalTextField(); ((NumericalTextField) comp).setNumberType(type); ((NumericalTextField) comp).setNegativeAccepted(false); if (CollectionUtils.isNotEmpty(refObjects)) { //support of image type DataObject object = refObjects.get(0); if (script.isSupportedType(object, name)) { defValue = object.getId(); } } } else { comp = new NumericalTextField(); ((NumericalTextField) comp).setNumberType(type); n = param.getMinValue(); if (n != null) { if (Long.class.equals(type)) { text += "Min: " + n.longValue() + " "; ((NumericalTextField) comp).setMinimum(n.longValue()); } else if (Integer.class.equals(type)) { text += "Min: " + n.intValue() + " "; ((NumericalTextField) comp).setMinimum(n.intValue()); } else if (Double.class.equals(type)) { text += "Min: " + n.doubleValue() + " "; ((NumericalTextField) comp).setMinimum(n.doubleValue()); } else if (Float.class.equals(type)) { text += "Min: " + n.floatValue() + " "; ((NumericalTextField) comp).setMinimum(n.floatValue()); } } else { ((NumericalTextField) comp).setNegativeAccepted(true); } n = param.getMaxValue(); if (n != null) { if (Long.class.equals(type)) { text += "Max: " + n.longValue() + " "; ((NumericalTextField) comp).setMaximum(n.longValue()); } else if (Integer.class.equals(type)) { text += "Max: " + n.intValue() + " "; ((NumericalTextField) comp).setMaximum(n.intValue()); } else if (Double.class.equals(type)) { text += "Max: " + n.doubleValue() + " "; ((NumericalTextField) comp).setMaximum(n.doubleValue()); } else if (Float.class.equals(type)) { text += "Max: " + n.floatValue() + " "; ((NumericalTextField) comp).setMaximum(n.floatValue()); } } } if (defValue != null) ((NumericalTextField) comp).setText("" + defValue); } } else if (String.class.equals(type)) { if (comp == null) { comp = new JTextField(); if (defValue != null) { length = defValue.toString().length(); String s = defValue.toString().trim(); ((JTextField) comp).setColumns(length); ((JTextField) comp).setText(s); columnsSet = s.length() > 0; } } } else if (Boolean.class.equals(type)) { if (comp == null) { comp = new JCheckBox(); if (defValue != null) ((JCheckBox) comp).setSelected((Boolean) defValue); } } else if (Map.class.equals(type)) { if (comp == null) comp = new ComplexParamPane(param.getKeyType(), param.getValueType()); else comp = new ComplexParamPane(param.getKeyType(), (JComboBox) comp); } else if (List.class.equals(type)) { if (script.isIdentifier(name)) { identifier = new IdentifierParamPane(Long.class); identifier.setValues(refObjects); identifier.addDocumentListener(this); comp = identifier; } else { if (comp == null) comp = new ComplexParamPane(param.getKeyType()); else comp = new ComplexParamPane((JComboBox) comp); } } if (comp != null) { if (comp instanceof JTextField) { if (!columnsSet) ((JTextField) comp).setColumns(ScriptComponent.COLUMNS); ((JTextField) comp).getDocument().addDocumentListener(this); } if (comp instanceof ComplexParamPane) comp.addPropertyChangeListener(this); comp.setToolTipText(param.getDescription()); c = new ScriptComponent(comp, name); if (text.trim().length() > 0) c.setUnit(text); if (!(comp instanceof JComboBox || comp instanceof JCheckBox)) c.setRequired(!param.isOptional()); if (details != null && details.trim().length() > 0) c.setInfo(details); if (comp instanceof JComboBox && script.isDataType(name)) { dataTypes = (JComboBox) comp; dataTypes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleDataTypeChanges(); } }); } grouping = param.getGrouping(); parent = param.getParent(); c.setParentIndex(parent); if (parent.length() > 0) { l = childrenMap.get(parent); if (l == null) { l = new ArrayList<ScriptComponent>(); childrenMap.put(parent, l); } l.add(c); } if (grouping.length() > 0) { c.setGrouping(grouping); c.setNameLabel(grouping); } else { c.setNameLabel(name); } if (c.hasChildren() || parent.length() == 0) { results.add(c); } componentsAll.put(c.getParameterName(), c); } } ScriptComponent key; Iterator<ScriptComponent> k = results.iterator(); while (k.hasNext()) { key = k.next(); grouping = key.getGrouping(); l = childrenMap.get(grouping); childrenMap.remove(grouping); if (l != null) key.setChildren(sorter.sort(l)); } if (childrenMap != null && childrenMap.size() > 0) { Iterator<String> j = childrenMap.keySet().iterator(); ScriptComponent sc; while (j.hasNext()) { parent = j.next(); sc = new ScriptComponent(); sc.setGrouping(parent); sc.setNameLabel(parent); sc.setChildren(sorter.sort(childrenMap.get(parent))); results.add(sc); } } List<ScriptComponent> sortedKeys = sorter.sort(results); k = sortedKeys.iterator(); while (k.hasNext()) { key = k.next(); components.put(key.getParameterName(), key); } setSelectedDataType(); if (identifier != null) identifier.addPropertyChangeListener(this); canRunScript(); }
From source file:org.processmining.analysis.performance.advanceddottedchartanalysis.ui.DottedChartPanel.java
/** * Required for mouselistener/*from www. ja v a2s . c o m*/ * * @param e * MouseEvent */ public void mouseDragged(MouseEvent e) { Point p = e.getPoint(); if (dcop.getMouseMode().equals(ST_DRAG)) { p4.x -= (p.x - p3.x); p4.y -= (p.y - p3.y); dca.setScrollBarPosition(new Point(p4.x, p4.y)); dca.reDrawBoxOnOverview(); } else if (dcop.getMouseMode().equals(ST_SELECT)) { p2 = e.getPoint(); repaint(); } else if (dcop.getMouseMode().equals(ST_ZOOMIN)) { p2 = e.getPoint(); repaint(); } }
From source file:org.languagetool.gui.LanguageToolSupport.java
private void showPopup(MouseEvent event) { if (documentSpans.isEmpty() && languageTool.getDisabledRules().isEmpty()) { //No errors and no disabled Rules return;/*from w w w. j a va2s . c o m*/ } int offset = this.textComponent.viewToModel(event.getPoint()); Span span = getSpan(offset); JPopupMenu popup = new JPopupMenu("Grammar Menu"); if (span != null) { JLabel msgItem = new JLabel("<html>" + span.msg.replace("<suggestion>", "<b>").replace("</suggestion>", "</b>") + "</html>"); msgItem.setToolTipText(span.desc.replace("<suggestion>", "").replace("</suggestion>", "")); msgItem.setBorder(new JMenuItem().getBorder()); popup.add(msgItem); popup.add(new JSeparator()); for (String r : span.replacement) { ReplaceMenuItem item = new ReplaceMenuItem(r, span); popup.add(item); item.addActionListener(actionListener); } popup.add(new JSeparator()); JMenuItem moreItem = new JMenuItem(messages.getString("guiMore")); moreItem.addActionListener(e -> showDialog(textComponent, span.msg, span.desc, span.rule, span.url)); popup.add(moreItem); JMenuItem ignoreItem = new JMenuItem(messages.getString("guiTurnOffRule")); ignoreItem.addActionListener(e -> disableRule(span.rule.getId())); popup.add(ignoreItem); popup.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); } List<Rule> disabledRules = getDisabledRules(); if (!disabledRules.isEmpty()) { JMenu activateRuleMenu = new JMenu(messages.getString("guiActivateRule")); addDisabledRulesToMenu(disabledRules, activateRuleMenu); popup.add(activateRuleMenu); } if (span != null) { textComponent.setCaretPosition(span.start); textComponent.moveCaretPosition(span.end); } popup.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { } @Override public void popupMenuCanceled(PopupMenuEvent e) { if (span != null) { textComponent.setCaretPosition(span.start); } } }); popup.show(textComponent, event.getPoint().x, event.getPoint().y); }
From source file:org.orbisgis.view.geocatalog.Catalog.java
/** * The user click on the source list control * * @param e The mouse event fired by the LI *///from w w w.j ava 2 s .c om public void onMouseActionOnSourceList(MouseEvent e) { //Manage selection of items before popping up the menu if (e.isPopupTrigger()) { //Right mouse button under linux and windows int itemUnderMouse = -1; //Item under the position of the mouse event //Find the Item under the position of the mouse cursor for (int i = 0; i < sourceListContent.getSize(); i++) { //If the coordinate of the cursor cover the cell bouding box if (sourceList.getCellBounds(i, i).contains(e.getPoint())) { itemUnderMouse = i; break; } } //Retrieve all selected items index int[] selectedItems = sourceList.getSelectedIndices(); //If there are a list item under the mouse if ((selectedItems != null) && (itemUnderMouse != -1)) { //If the item under the mouse was not previously selected if (!CollectionUtils.contains(selectedItems, itemUnderMouse)) { //Control must be pushed to add the list item to the selection if (e.isControlDown()) { sourceList.addSelectionInterval(itemUnderMouse, itemUnderMouse); } else { //Unselect the other items and select only the item under the mouse sourceList.setSelectionInterval(itemUnderMouse, itemUnderMouse); } } } else if (itemUnderMouse == -1) { //Unselect all items sourceList.clearSelection(); } //Selection are ready, now create the popup menu JPopupMenu popup = new JPopupMenu(); popupActions.copyEnabledActions(popup); if (popup.getComponentCount() > 0) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }
From source file:org.openconcerto.erp.core.humanresources.payroll.element.VariablePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private ValidState validVarName; private JRadioButton radioVal = new JRadioButton("Valeur"); private JRadioButton radioFormule = new JRadioButton("Formule"); private final JTextField textValeur = new JTextField(); // private final ITextArea textFormule = new ITextArea(); private final VariableTree treeVariable = new VariableTree(); private final JTextField textNom = new JTextField(); private final JLabel labelWarningBadVar = new JLabelWarning(); private ElementComboBox comboSelSal; private EditFrame edit = null; private final SQLJavaEditor textFormule = new SQLJavaEditor(getMapTree()); public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.validVarName = null; this.textFormule.setEditable(false); // Arbre des variables JScrollPane sc = new JScrollPane(this.treeVariable); sc.setPreferredSize(new Dimension(150, sc.getPreferredSize().height)); this.treeVariable.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent mE) { if (mE.getButton() == MouseEvent.BUTTON3) { JPopupMenu menuDroit = new JPopupMenu(); TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if ((obj == null) || !(obj instanceof VariableRowTreeNode)) { return; }//from w ww . jav a 2s. c om menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit == null) { edit = new EditFrame(getElement(), EditFrame.MODIFICATION); } System.err.println("Action performed"); if (obj != null) { System.err.println("Object not null --> " + obj.toString()); if (obj instanceof VariableRowTreeNode) { System.err.println("Object VariableRowTreeNode"); VariableRowTreeNode varNode = (VariableRowTreeNode) obj; edit.selectionId(varNode.getID(), 1); edit.setVisible(true); } } } }); menuDroit.show((Component) mE.getSource(), mE.getPoint().x, mE.getPoint().y); } else { if (mE.getClickCount() == 2) { TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); Object obj = path.getLastPathComponent(); if (obj != null) { if (obj instanceof FormuleTreeNode) { final FormuleTreeNode n = (FormuleTreeNode) obj; int start = textFormule.getSelectionStart(); String tmp = textFormule.getText(); textFormule.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length())); } } } } } }); JPanel panelDroite = new JPanel(); panelDroite.setLayout(new GridBagLayout()); // Categorie JTextField textCategorie = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy = 0; JLabel labelCategorie = new JLabel("Catgorie"); panelDroite.add(labelCategorie, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(textCategorie, c); c.gridwidth = 1; // Nom c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy++; JLabel labelNom = new JLabel("Nom"); panelDroite.add(labelNom, c); c.gridx++; c.weightx = 1; panelDroite.add(this.textNom, c); this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { updateValidVarName(); } }); c.gridx++; c.weightx = 0; panelDroite.add(this.labelWarningBadVar, c); // Description JLabel labelInfos = new JLabel(getLabelFor("INFOS")); ITextArea textInfos = new ITextArea(); c.gridy++; c.gridx = 1; c.gridwidth = 1; c.weightx = 0; panelDroite.add(labelInfos, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 0; panelDroite.add(textInfos, c); // Valeur c.gridx = 1; c.gridy++; c.gridwidth = 1; c.weightx = 0; panelDroite.add(this.radioVal, c); c.gridx++; c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textValeur, c); c.gridwidth = 1; c.gridx = 1; c.gridy++; panelDroite.add(this.radioFormule, c); c.gridx++; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textFormule, c); c.gridwidth = 1; ButtonGroup group = new ButtonGroup(); group.add(this.radioVal); group.add(this.radioFormule); this.radioVal.setSelected(true); setFormuleEnabled(false); this.radioVal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(false); } }); this.radioFormule.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(true); } }); c.gridy++; c.gridx = 1; c.weighty = 0; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.comboSelSal = new ElementComboBox(false); this.comboSelSal.init(getDirectory().getElement(SalarieSQLElement.class)); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; panelDroite.add(this.comboSelSal, c); c.gridwidth = 1; JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sc, panelDroite); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; this.add(split, c); this.addRequiredSQLObject(this.textNom, "NOM"); this.addSQLObject(this.textValeur, "VALEUR"); this.addSQLObject(this.textFormule, "FORMULE"); this.addSQLObject(textCategorie, "CATEGORIE"); this.addSQLObject(textInfos, "INFOS"); this.comboSelSal.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // TODO Auto-generated method stub textFormule.setSalarieID(comboSelSal.getSelectedId()); } }); } @Override public synchronized ValidState getValidState() { return super.getValidState().and(this.validVarName); } private void setFormuleEnabled(boolean b) { if (b) { this.textValeur.setText(""); } else { this.textFormule.setText(""); } this.textValeur.setEditable(!b); this.textValeur.setEnabled(!b); this.textFormule.setEditable(b); this.textFormule.setEnabled(b); this.treeVariable.setEnabled(b); this.treeVariable.setEditable(b); } private void setValidVarName(ValidState s) { if (!s.equals(this.validVarName)) { this.validVarName = s; final boolean warningVisible = !s.isValid(); if (warningVisible) this.labelWarningBadVar.setText(s.getValidationText()); this.labelWarningBadVar.setVisible(warningVisible); this.fireValidChange(); } } private void updateValidVarName() { this.setValidVarName(this.computeValidVarName()); } private ValidState computeValidVarName() { // on vrifie si la syntaxe de la variable est correct (chiffre lettre et _) final String varName = this.textNom.getText().trim(); System.err.println("Verification de la validit du nom de la variable."); if (varName.length() == 0) { return VAR_NO_NAME; } // ne contient que des chiffre lettre et _ et ne commence pas par un chiffre if (!isJavaVar(varName)) { return VAR_NAME_NOT_CORRECT; } // on vrifie que la variable n'existe pas dja SQLSelect selAllVarName = new SQLSelect(getTable().getBase()); selAllVarName.addSelect(VariablePayeSQLElement.this.getTable().getField("ID")); Where w = new Where(VariablePayeSQLElement.this.getTable().getField("NOM"), "=", varName); w = w.and(new Where(VariablePayeSQLElement.this.getTable().getKey(), "!=", getSelectedID())); selAllVarName.setWhere(w); String reqAllVarName = selAllVarName.asString();// + " AND '" + varName.trim() + "' // REGEXP VARIABLE_PAYE.NOM"; Object[] objKeysRowName = ((List) getTable().getBase().getDataSource().execute(reqAllVarName, new ArrayListHandler())).toArray(); if (objKeysRowName.length > 0) { return VAR_ALREADY_EXIST; } else { // Impossible de crer une variable du meme nom qu'un champ du salarie if (isForbidden(varName)) return VAR_ALREADY_EXIST; this.textFormule.setVarAssign(varName); return ValidState.getTrueInstance(); } } private boolean isJavaVar(String s) { if ((s.charAt(0) >= '0') && ((s.charAt(0) <= '9'))) { System.err.println("Erreur la variable commence par un chiffre!!"); return false; } else { for (int i = 0; i < s.length(); i++) { if (!(((s.charAt(i) >= '0') && (s.charAt(i) <= '9')) || (s.charAt(i) >= 'a') && (s.charAt(i) <= 'z') || (s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z') || (s.charAt(i) == '_'))) { System.err.println("Erreur la variable contient un caractere incorrect!!"); return false; } } return (!CTokenMarker.getKeywords().isExisting(s)); } } @Override public void select(SQLRowAccessor r) { super.select(r); // System.err.println("Select RowAccess -------> " + r.getID() + " For Object " + // this.hashCode()); if (r != null) { if (r.getString("FORMULE").trim().length() == 0) { this.radioVal.setSelected(true); setFormuleEnabled(false); } else { this.radioFormule.setSelected(true); setFormuleEnabled(true); } this.textFormule.setVarAssign(r.getString("NOM")); } this.updateValidVarName(); } }; }
From source file:com.projity.pm.graphic.spreadsheet.common.CommonSpreadSheet.java
public boolean editCellAt(int row, int column, EventObject e) { boolean b = super.editCellAt(row, column, e); if (b && editorComp != null) { // System.out.println("editing cell at " + row + " " + column); Component comp;// ww w .j av a2 s .com boolean nameCell = false; if (editorComp instanceof NameCellComponent) { nameCell = true; NameCellComponent nameCellComp = (NameCellComponent) editorComp; comp = nameCellComp.getTextComponent(); } else comp = editorComp; if (comp instanceof KeyboardFocusable) ((KeyboardFocusable) comp).selectAll(e == null); else if (comp instanceof ChangeAwareTextField) { ChangeAwareTextField text = ((ChangeAwareTextField) comp); if (e == null) { text.selectAll(); } else if (e instanceof MouseEvent) { if (nameCell) { MouseEvent me = (MouseEvent) e; Rectangle bounds = text.getBounds(null); Rectangle cell = getCellRect(row, column, false); bounds.setFrame(cell.getX() + bounds.getX(), cell.getY() + bounds.getY(), bounds.getWidth(), bounds.getHeight()); if (bounds.contains(me.getPoint())) { text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked } else { //because if it's outside there's no caret update text.requestFocus(); text.selectAll(); } } else text.selectAllOnNextCaretUpdate(); //to avoid diselection when the cell is clicked } text.resetChange(); } } return b; }
From source file:io.heming.accountbook.ui.MainFrame.java
public MainFrame() throws Exception { categoryFacade = new CategoryFacade(); recordFacade = new RecordFacade(); builder = new Pages.Builder(); builder.order("id", false); pages = builder.make();//w ww. j a v a2s . c o m date_chooser_visible = false; disable = false; // Create widgets model = new TableModel(); table = new JTable(model) { /** * tip. * * @param evt * @return */ @Override public String getToolTipText(MouseEvent evt) { String tip = null; java.awt.Point point = evt.getPoint(); int row = rowAtPoint(point); int col = columnAtPoint(point); Rectangle bounds = getCellRect(row, col, false); Component comp = prepareRenderer(getCellRenderer(row, col), row, col); try { if (comp.getPreferredSize().width > bounds.width) { tip = getValueAt(row, col).toString(); } } catch (RuntimeException e) { //catch null pointer exception if mouse is over an empty line } return tip; } }; if (pages.hasNext()) { model.setRecords(pages.next()); } // ? table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(0).setPreferredWidth(80); columnModel.getColumn(1).setPreferredWidth(160); columnModel.getColumn(2).setPreferredWidth(80); columnModel.getColumn(3).setPreferredWidth(100); columnModel.getColumn(4).setPreferredWidth(100); columnModel.getColumn(5).setPreferredWidth(360); // Layout JScrollPane pane = new JScrollPane(table); add(pane, BorderLayout.CENTER); table.getTableHeader().setReorderingAllowed(false); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // table header table.getTableHeader().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { int col = table.columnAtPoint(e.getPoint()); String name = table.getColumnName(col); // TODO } }); // ? addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { quit(); } }); categories = categoryFacade.listBySale(); initMenuBar(); initToolBar(); initStatusBar(); initTablePopupMenu(); searchRecords(); setIconImage(new ImageIcon(getClass().getResource("64.png")).getImage()); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setTitle(""); setSize(860, 620); }
From source file:org.orbisgis.core.ui.plugins.views.geocatalog.Catalog.java
public Catalog() { menuTree = new org.orbisgis.core.ui.pluginSystem.menu.MenuTree(); lstSources = new OGList(); lstSources.addMouseListener(new MouseAdapter() { @Override/* w w w . j a va 2 s .c o m*/ public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { int path = -1; for (int i = 0; i < listModel.getSize(); i++) { if (lstSources.getCellBounds(i, i).contains(e.getPoint())) { path = i; break; } } int[] selectionPaths = lstSources.getSelectedIndices(); if ((selectionPaths != null) && (path != -1)) { if (!CollectionUtils.contains(selectionPaths, path)) { if (e.isControlDown()) { lstSources.addSelectionInterval(path, path); } else { lstSources.setSelectionInterval(path, path); } } } else if (path == -1) { lstSources.clearSelection(); } else { } } if (e.isPopupTrigger()) { JPopupMenu popup = getPopup(); if (popup != null) { popup.show(e.getComponent(), e.getX(), e.getY()); } } } }); listModel = new SourceListModel(); lstSources.setModel(listModel); this.setLayout(new BorderLayout()); this.add(new JScrollPane(lstSources), BorderLayout.CENTER); this.add(getNorthPanel(), BorderLayout.NORTH); SourceListRenderer cellRenderer = new SourceListRenderer(this); cellRenderer.setRenderers(new SourceRenderer[0]); lstSources.setCellRenderer(cellRenderer); dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(lstSources, DnDConstants.ACTION_COPY_OR_MOVE, this); editingSources = new HashMap<String, EditableSource>(); //Init the file drop system FileDrop fileDrop = new FileDrop(this, new FileDrop.Listener() { @Override public void filesDropped(java.io.File[] files) { DataManager dm = (DataManager) Services.getService(DataManager.class); SourceManager sourceManager = dm.getSourceManager(); for (File file : files) { // For each file, we ensure that we have a driver // that can be used to read it. If we don't, we don't // open the file. if (OrbisConfiguration.isFileEligible(file)) { try { String name = sourceManager .getUniqueName(FilenameUtils.removeExtension(file.getName())); sourceManager.register(name, file); } catch (SourceAlreadyExistsException e) { ErrorMessages.error(ErrorMessages.SourceAlreadyRegistered + ": ", e); } } } } }); }
From source file:com.peterbochs.sourceleveldebugger.SourceLevelDebugger3.java
private JTable getSymbolTable() { if (symbolTable == null) { symbolTable = new JTable() { public String getToolTipText(MouseEvent event) { Point p = event.getPoint(); int row = rowAtPoint(p); int col = columnAtPoint(p); if (row == -1 || col == -1) { return null; }/*from ww w . j a v a 2s.c om*/ Elf32_Sym symbol = (Elf32_Sym) getValueAt(row, col); String str = "<html><table>"; str += "<tr><td>name</td><td>:</td><td>" + symbol.name + "</td></tr>"; str += "<tr><td>st_name</td><td>:</td><td>" + symbol.st_name + "</td></tr>"; str += "<tr><td>st_value</td><td>:</td><td>0x" + Long.toHexString(symbol.st_value) + "</td></tr>"; str += "<tr><td>st_size</td><td>:</td><td>" + symbol.st_size + "</td></tr>"; str += "<tr><td>st_info</td><td>:</td><td>" + symbol.st_info + "</td></tr>"; str += "<tr><td>st_other</td><td>:</td><td>" + symbol.st_other + "</td></tr>"; str += "<tr><td>st_shndx</td><td>:</td><td>" + symbol.st_shndx + "</td></tr>"; str += "</table></html>"; return str; } }; symbolTable.setModel(symbolTableModel); symbolTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { symbolTableMouseClicked(evt); } }); } return symbolTable; }