List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTree.java
public DesktopTree() { layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]"); panel = new JPanel(layout); topPanel = new JPanel(new BorderLayout()); topPanel.setVisible(false);//from w w w. j av a2 s . c o m panel.add(topPanel, "growx"); impl = new JTree(); treeView = new JScrollPane(impl); panel.add(treeView, "grow"); impl.setRootVisible(false); impl.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); impl.setExpandsSelectedPaths(true); impl.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { // select row Point p = e.getPoint(); TreePath treePath = impl.getPathForLocation(p.x, p.y); if (treePath != null) { TreeSelectionModel model = impl.getSelectionModel(); model.setSelectionPath(treePath); } // show popup menu createPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } }); impl.addKeyListener(new KeyAdapter() { protected static final int ENTER_CODE = 10; @Override public void keyPressed(KeyEvent e) { if (ENTER_CODE == e.getKeyCode() && e.getComponent() == DesktopTree.this.getComponent()) { if (enterPressAction != null) { enterPressAction.actionPerform(DesktopTree.this); } else { handleClickAction(); } } } }); }
From source file:de.fhg.igd.mapviewer.BasicMapKit.java
/** * Creates a basic map kit//from w w w.j a v a 2 s . c o m * * @param cache the tile cache to use */ public BasicMapKit(TileCache cache) { super(); this.cache = cache; getMiniMap().setPanEnabled(false); getMiniMap().setCursor(Cursor.getDefaultCursor()); getZoomSlider().setCursor(Cursor.getDefaultCursor()); getZoomInButton().setCursor(Cursor.getDefaultCursor()); getZoomOutButton().setCursor(Cursor.getDefaultCursor()); getMiniMap().addMouseListener(new MouseAdapter() { /** * @see MouseAdapter#mouseClicked(MouseEvent) */ @Override public void mouseClicked(MouseEvent me) { getMainMap().setCenterPosition(getMiniMap().convertPointToGeoPosition(me.getPoint())); } }); // create painter for map tools toolPainter = new MapToolPainter(getMainMap()); customPainter = new CompoundPainter<JXMapViewer>(); customPainter.setCacheable(false); mapPainter = new CompoundPainter<JXMapViewer>(); mapPainter.setCacheable(false); painter = new CompoundPainter<JXMapViewer>(); painter.setPainters(customPainter, toolPainter, mapPainter); painter.setCacheable(false); updatePainters(); // register as state provider // GuiState.getInstance().registerStateProvider(this); }
From source file:ru.codemine.pos.ui.windows.products.ProductsListWindow.java
@Override public void setupActionListeners() { setNewActionListener(newProduct);/* w w w . j a va 2 s .co m*/ setEditActionListener(editProduct); setDeleteActionListener(deleteProduct); setRefreshActionListener(refreshProductList); toolButtonPrintStickers.addActionListener(printProductStickers); menuItemPrintStickers.addActionListener(printProductStickers); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Point p = e.getPoint(); int row = table.rowAtPoint(p); if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { menuItemEdit.doClick(); } } }); actionListenersInit = true; }
From source file:ru.codemine.pos.ui.windows.devices.kkm.KkmListWindow.java
@Override public void setupActionListeners() { setNewActionListener(newKkmDevice);//from w w w . j ava2s .c o m setEditActionListener(editKkmDevice); setDeleteActionListener(deleteKkm); setProcessActionListener(setActiveKkm); setRefreshActionListener(refreshKkmDeviceList); toolButtonTestCheque.addActionListener(testKkmDevice); table.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { Point p = e.getPoint(); int row = table.rowAtPoint(p); if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { menuItemEdit.doClick(); } } }); actionListenersInit = true; }
From source file:gtu._work.ui.RegexCatchReplacer.java
private void initGUI() { try {/*from w w w. j a v a 2 s . com*/ { } BorderLayout thisLayout = new BorderLayout(); getContentPane().setLayout(thisLayout); this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("source", null, jPanel1, null); { jScrollPane1 = new JScrollPane(); jPanel1.add(jScrollPane1, BorderLayout.CENTER); { replaceArea = new JTextArea(); jScrollPane1.setViewportView(replaceArea); replaceArea.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { JPopupMenuUtil.newInstance(replaceArea).applyEvent(evt) .addJMenuItem("load from file", true, new ActionListener() { Thread newThread; public void actionPerformed(ActionEvent arg0) { if (newThread != null && newThread.getState() != Thread.State.TERMINATED) { JCommonUtil._jOptionPane_showMessageDialog_error( "file is loading!"); return; } final File file = JCommonUtil._jFileChooser_selectFileOnly(); if (file == null) { JCommonUtil._jOptionPane_showMessageDialog_error( "file is not correct!"); return; } String defaultCharset = Charset.defaultCharset().displayName(); String chst = (String) JCommonUtil._jOptionPane_showInputDialog( "input your charset!", defaultCharset); final Charset charset2 = Charset.forName( StringUtils.defaultIfEmpty(chst, defaultCharset)); newThread = new Thread(Thread.currentThread().getThreadGroup(), new Runnable() { public void run() { try { loadFromFileSb = new StringBuilder(); BufferedReader reader = new BufferedReader( new InputStreamReader( new FileInputStream(file), charset2)); for (String line = null; (line = reader .readLine()) != null;) { loadFromFileSb.append(line + "\n"); } reader.close(); replaceArea .setText(loadFromFileSb.toString()); JCommonUtil ._jOptionPane_showMessageDialog_info( "load completed!"); } catch (Exception e) { JCommonUtil.handleException(e); } } }, "" + System.currentTimeMillis()); newThread.setDaemon(true); newThread.start(); } }).show(); } }); } } } { jPanel2 = new JPanel(); BorderLayout jPanel2Layout = new BorderLayout(); jPanel2.setLayout(jPanel2Layout); jTabbedPane1.addTab("param", null, jPanel2, null); { exeucte = new JButton(); jPanel2.add(exeucte, BorderLayout.SOUTH); exeucte.setText("exeucte"); exeucte.setPreferredSize(new java.awt.Dimension(491, 125)); exeucte.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { exeucteActionPerformed(evt); } }); } { jPanel3 = new JPanel(); GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel2.add(jPanel3, BorderLayout.CENTER); { repFromText = new JTextField(); } { repToText = new JTextField(); } jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup() .addContainerGap(25, 25) .addGroup(jPanel3Layout.createParallelGroup() .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repFromText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel3Layout.createSequentialGroup().addComponent(repToText, GroupLayout.PREFERRED_SIZE, 446, GroupLayout.PREFERRED_SIZE))) .addContainerGap(20, Short.MAX_VALUE)); jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap() .addComponent(repFromText, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(repToText, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); } { addToTemplate = new JButton(); jPanel2.add(addToTemplate, BorderLayout.NORTH); addToTemplate.setText("add to template"); addToTemplate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { prop.put(repFromText.getText(), repToText.getText()); reloadTemplateList(); } }); } } { jPanel4 = new JPanel(); BorderLayout jPanel4Layout = new BorderLayout(); jPanel4.setLayout(jPanel4Layout); jTabbedPane1.addTab("result", null, jPanel4, null); { jScrollPane2 = new JScrollPane(); jPanel4.add(jScrollPane2, BorderLayout.CENTER); jScrollPane2.setPreferredSize(new java.awt.Dimension(491, 283)); { DefaultTableModel resultAreaModel = JTableUtil.createModel(true, "match", "count"); resultArea = new JTable(); jScrollPane2.setViewportView(resultArea); JTableUtil.defaultSetting(resultArea); resultArea.setModel(resultAreaModel); } } } { jPanel5 = new JPanel(); BorderLayout jPanel5Layout = new BorderLayout(); jPanel5.setLayout(jPanel5Layout); jTabbedPane1.addTab("template", null, jPanel5, null); { jScrollPane3 = new JScrollPane(); jPanel5.add(jScrollPane3, BorderLayout.CENTER); { templateList = new JList(); jScrollPane3.setViewportView(templateList); reloadTemplateList(); } templateList.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (templateList.getLeadSelectionIndex() == -1) { return; } Entry<Object, Object> entry = (Entry<Object, Object>) JListUtil .getLeadSelectionObject(templateList); repFromText.setText((String) entry.getKey()); repToText.setText((String) entry.getValue()); } }); templateList.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent evt) { JListUtil.newInstance(templateList).defaultJListKeyPressed(evt); } }); } } { jPanel6 = new JPanel(); FlowLayout jPanel6Layout = new FlowLayout(); jPanel6.setLayout(jPanel6Layout); jTabbedPane1.addTab("result1", null, jPanel6, null); { resultBtn1 = new JButton(); jPanel6.add(resultBtn1); resultBtn1.setText("to String[]"); resultBtn1.setPreferredSize(new java.awt.Dimension(105, 32)); resultBtn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTableUtil tableUtil = JTableUtil.newInstance(resultArea); int[] rowPoss = tableUtil.getSelectedRows(); DefaultTableModel model = tableUtil.getModel(); List<Object> valueList = new ArrayList<Object>(); for (int ii = 0; ii < rowPoss.length; ii++) { valueList.add(model.getValueAt(rowPoss[ii], 0)); } String reult = valueList.toString().replaceAll("[\\s]", "") .replaceAll("[\\,]", "\",\"").replaceAll("[\\[\\]]", "\""); ClipboardUtil.getInstance().setContents(reult); } }); } { resultBtn2 = new JButton(); jPanel6.add(resultBtn2); resultBtn2.setText("TODO"); resultBtn2.setPreferredSize(new java.awt.Dimension(105, 32)); resultBtn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.out.println("resultBtn1.actionPerformed, event=" + evt); //TODO add your code for resultBtn1.actionPerformed JCommonUtil._jOptionPane_showMessageDialog_info("TODO"); } }); } } } this.setSize(512, 350); JCommonUtil.setFont(repToText, repFromText, replaceArea, templateList); JCommonUtil.frameCloseDo(this, new WindowAdapter() { public void windowClosing(WindowEvent paramWindowEvent) { if (StringUtils.isNotBlank(repFromText.getText())) { prop.put(repFromText.getText(), repToText.getText()); } try { prop.store(new FileOutputStream(propFile), "regexText"); } catch (Exception e) { JCommonUtil.handleException("properties store error!", e); } setVisible(false); dispose(); } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.uchc.octane.OctaneWindowControl.java
/** * Constructor// w ww .j a v a 2s . co m * * @param imp the image */ public OctaneWindowControl(ImagePlus imp) { super(); path_ = null; imp_ = imp; FileInfo fi = imp.getOriginalFileInfo(); if (fi != null) { path_ = fi.directory; } imp.getCanvas().addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { findMolecule(); } } }); }
From source file:com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel.java
private void buildUI() { editor = new GroovyEditor(new ScriptStepGroovyEditorModel()); logArea = new JLogList("Groovy Test Log"); logArea.addLogger(groovyStep.getName() + "#" + hashCode(), true); logArea.getLogList().addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() < 2) return; String value = logArea.getLogList().getSelectedValue().toString(); if (value == null) return; editor.selectError(value);/*from w w w . j av a 2s . co m*/ } }); logArea.getLogList().getModel().addListDataListener(new ListDataChangeListener() { @Override public void dataChanged(ListModel model) { logInspector.setTitle("Log Output (" + model.getSize() + ")"); } }); inspectorPanel = JInspectorPanelFactory.build(editor); logInspector = inspectorPanel.addInspector(new JComponentInspector<JComponent>(logArea, "Log Output (0)", "Groovy Log output for this script", true)); inspectorPanel.setDefaultDividerLocation(0.8F); inspectorPanel.activate(logInspector); add(inspectorPanel.getComponent(), BorderLayout.CENTER); add(buildToolbar(), BorderLayout.NORTH); add(buildStatusBar(), BorderLayout.SOUTH); componentEnabler.add(editor); }
From source file:Transfer.java
public Transfer() { // Establish the GUI Container cp = new Box(BoxLayout.X_AXIS); setContentPane(cp);//from w w w .j a v a2 s. co m JPanel firstPanel = new JPanel(); propertyComboBox = new JComboBox(); propertyComboBox.addItem("text"); propertyComboBox.addItem("font"); propertyComboBox.addItem("background"); propertyComboBox.addItem("foreground"); firstPanel.add(propertyComboBox); cp.add(firstPanel); cp.add(Box.createGlue()); tf = new JTextField("Hello"); tf.setForeground(Color.RED); tf.setDragEnabled(true); cp.add(tf); cp.add(Box.createGlue()); l = new JLabel("Hello"); l.setBackground(Color.YELLOW); cp.add(l); cp.add(Box.createGlue()); JSlider stryder = new JSlider(SwingConstants.VERTICAL); stryder.setMinimum(10); stryder.setValue(14); stryder.setMaximum(72); stryder.setMajorTickSpacing(10); stryder.setPaintTicks(true); cp.add(stryder); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 300); // Add Listeners and Converters setMyTransferHandlers((String) propertyComboBox.getSelectedItem()); // Mousing in the Label starts a Drag. MouseListener myDragListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { JComponent c = (JComponent) e.getSource(); TransferHandler handler = c.getTransferHandler(); handler.exportAsDrag(c, e, TransferHandler.COPY); } }; l.addMouseListener(myDragListener); // Selecting in the ComboBox makes that the property that is xfered. propertyComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ce) { JComboBox bx = (JComboBox) ce.getSource(); String prop = (String) bx.getSelectedItem(); setMyTransferHandlers(prop); } }); // Typing a word and pressing enter in the TextField tries // to set that as the font name. tf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JTextField jtf = (JTextField) evt.getSource(); String fontName = jtf.getText(); Font font = new Font(fontName, Font.BOLD, 18); tf.setFont(font); } }); // Setting the Slider sets that font into the textfield. stryder.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { JSlider sl = (JSlider) evt.getSource(); Font oldf = tf.getFont(); Font newf = oldf.deriveFont((float) sl.getValue()); tf.setFont(newf); } }); }
From source file:MemoryMonitor.java
public MemoryMonitor() { setLayout(new BorderLayout()); setBorder(new TitledBorder(new EtchedBorder(), "Memory Monitor")); add(surf = new Surface()); controls = new JPanel(); controls.setPreferredSize(new Dimension(135, 80)); Font font = new Font("serif", Font.PLAIN, 10); JLabel label = new JLabel("Sample Rate"); label.setFont(font);//from w w w . j a va2 s. co m label.setForeground(Color.red); controls.add(label); tf = new JTextField("1000"); tf.setPreferredSize(new Dimension(45, 20)); controls.add(tf); controls.add(label = new JLabel("ms")); label.setFont(font); label.setForeground(Color.red); controls.add(dateStampCB); dateStampCB.setFont(font); addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { removeAll(); if ((doControls = !doControls)) { surf.stop(); add(controls); } else { try { surf.sleepAmount = Long.parseLong(tf.getText().trim()); } catch (Exception ex) { } surf.start(); add(surf); } validate(); repaint(); } }); }
From source file:eu.europa.esig.dss.applet.view.validationpolicy.EditView.java
private void registerMouseListener(final JTree tree) { MouseListener mouseAdapter = new MouseAdapter() { @Override// ww w. ja v a 2 s. co m public void mousePressed(MouseEvent mouseEvent) { if (mouseEvent.getButton() == MouseEvent.BUTTON3) { final int selectedRow = tree.getRowForLocation(mouseEvent.getX(), mouseEvent.getY()); final TreePath selectedPath = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); if (selectedRow != -1) { final XmlDomAdapterNode clickedItem = (XmlDomAdapterNode) selectedPath .getLastPathComponent(); final boolean isLeaf = tree.getModel().isLeaf(selectedPath.getLastPathComponent()); // Do nothing on root element if (selectedPath.getPathCount() > 1) { // find the allowed actions, to know if a popup menu should be displayed and the content of the popup menu + action handlers if (clickedItem.node instanceof Element) { nodeActionAdd(mouseEvent, selectedRow, selectedPath, clickedItem, tree); } else if (isLeaf) { valueLeafActionEdit(mouseEvent, selectedPath, clickedItem, tree); } } } } } }; tree.addMouseListener(mouseAdapter); }