List of usage examples for java.awt.event MouseAdapter MouseAdapter
MouseAdapter
From source file:com.aw.swing.mvp.binding.component.BndSJTable.java
private MouseAdapter getJTableMouseListener(final JTableMouseProcessor jTableMouseProcessor) { return new MouseAdapter() { public void mouseClicked(MouseEvent e) { jTableMouseProcessor.processMouseEventsOnBody(e); }//w ww . jav a2 s . c om /** * Invoked when a mouse button has been pressed on a component. */ public void mousePressed(MouseEvent e) { gridManager.setFocusIsMouseTriggered(true); } /** * Invoked when a mouse button has been released on a component. */ public void mouseReleased(MouseEvent e) { gridManager.setFocusIsMouseTriggered(false); } }; }
From source file:com.diversityarrays.kdxplore.field.FieldViewDialog.java
public FieldViewDialog(Window owner, String title, SampleGroupChoice sgcSamples, Trial trial, SampleGroupChoice sgcNewMedia, KDSmartDatabase db) throws IOException { super(owner, title, ModalityType.MODELESS); advanceRetreatControls = Box.createHorizontalBox(); advanceRetreatControls.add(new JButton(retreatAction)); advanceRetreatControls.add(new JButton(advanceAction)); autoAdvanceControls = Box.createHorizontalBox(); autoAdvanceControls.add(new JButton(autoAdvanceAction)); autoAdvanceOption.addActionListener(new ActionListener() { @Override//www . j a va 2 s . c o m public void actionPerformed(ActionEvent e) { updateMovementControls(); } }); this.database = db; this.sampleGroupChoiceForSamples = sgcSamples; this.sampleGroupChoiceForNewMedia = sgcNewMedia; NumberSpinner fontSpinner = new NumberSpinner(new SpinnerNumberModel(), "0.00"); this.fieldViewPanel = FieldViewPanel.create(database, trial, SeparatorVisibilityOption.VISIBLE, null, Box.createHorizontalGlue(), new JButton(showInfoAction), Box.createHorizontalGlue(), new JLabel("Font Size:"), fontSpinner, Box.createHorizontalGlue(), advanceRetreatControls, autoAdvanceOption, autoAdvanceControls); initialiseAction(advanceAction, "ic_object_advance_black.png", "Auto-Advance"); this.xyProvider = fieldViewPanel.getXYprovider(); this.traitMap = fieldViewPanel.getTraitMap(); fieldLayoutTable = fieldViewPanel.getFieldLayoutTable(); JScrollPane scrollPane = fieldViewPanel.getFieldTableScrollPane(); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); fieldLayoutTable.setTransferHandler(flth); fieldLayoutTable.setDropMode(DropMode.ON); fieldLayoutTable.addMouseListener(new MouseAdapter() { JPopupMenu popupMenu; @Override public void mouseClicked(MouseEvent e) { if (!SwingUtilities.isRightMouseButton(e) || 1 != e.getClickCount()) { return; } Point pt = e.getPoint(); int row = fieldLayoutTable.rowAtPoint(pt); if (row >= 0) { int col = fieldLayoutTable.columnAtPoint(pt); if (col >= 0) { Plot plot = fieldViewPanel.getPlotAt(col, row); if (plot != null) { if (popupMenu == null) { popupMenu = new JPopupMenu("View Attachments"); } popupMenu.removeAll(); Set<File> set = plot.getMediaFiles(); if (Check.isEmpty(set)) { popupMenu.add(new JMenuItem("No Attachments available")); } else { for (File file : set) { Action a = new AbstractAction(file.getName()) { @Override public void actionPerformed(ActionEvent e) { try { Desktop.getDesktop().browse(file.toURI()); } catch (IOException e1) { MsgBox.warn(FieldViewDialog.this, e1, file.getName()); } } }; popupMenu.add(new JMenuItem(a)); } } popupMenu.show(fieldLayoutTable, pt.x, pt.y); } } } } }); Font font = fieldLayoutTable.getFont(); float fontSize = font.getSize2D(); fontSizeModel = new SpinnerNumberModel(fontSize, fontSize, 50.0, 1.0); fontSpinner.setModel(fontSizeModel); fontSizeModel.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { float fsize = fontSizeModel.getNumber().floatValue(); System.out.println("Using fontSize=" + fsize); Font font = fieldLayoutTable.getFont().deriveFont(fsize); fieldLayoutTable.setFont(font); FontMetrics fm = fieldLayoutTable.getFontMetrics(font); int lineHeight = fm.getMaxAscent() + fm.getMaxDescent(); fieldLayoutTable.setRowHeight(4 * lineHeight); // GuiUtil.initialiseTableColumnWidths(fieldLayoutTable, false); fieldLayoutTable.repaint(); } }); fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); fieldLayoutTable.setResizable(true, true); fieldLayoutTable.getTableColumnResizer().setResizeAllColumns(true); advanceAction.setEnabled(false); fieldLayoutTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { handlePlotSelection(); } } }); TableColumnModel columnModel = fieldLayoutTable.getColumnModel(); columnModel.addColumnModelListener(new TableColumnModelListener() { @Override public void columnSelectionChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { handlePlotSelection(); } } @Override public void columnRemoved(TableColumnModelEvent e) { } @Override public void columnMoved(TableColumnModelEvent e) { } @Override public void columnMarginChanged(ChangeEvent e) { } @Override public void columnAdded(TableColumnModelEvent e) { } }); PropertyChangeListener listener = new PropertyChangeListener() { // Use a timer and redisplay other columns when delay is GT 100 ms Timer timer = new Timer(true); TimerTask timerTask; long lastActive; boolean busy = false; private int eventColumnWidth; private TableColumn eventColumn; @Override public void propertyChange(PropertyChangeEvent evt) { if (busy) { return; } if (evt.getSource() instanceof TableColumn && "width".equals(evt.getPropertyName())) { eventColumn = (TableColumn) evt.getSource(); eventColumnWidth = eventColumn.getWidth(); lastActive = System.currentTimeMillis(); if (timerTask == null) { timerTask = new TimerTask() { @Override public void run() { if (System.currentTimeMillis() - lastActive > 200) { timerTask.cancel(); timerTask = null; busy = true; try { for (Enumeration<TableColumn> en = columnModel.getColumns(); en .hasMoreElements();) { TableColumn tc = en.nextElement(); if (tc != eventColumn) { tc.setWidth(eventColumnWidth); } } } finally { busy = false; } } } }; timer.scheduleAtFixedRate(timerTask, 100, 150); } } } }; for (Enumeration<TableColumn> en = columnModel.getColumns(); en.hasMoreElements();) { TableColumn tc = en.nextElement(); tc.addPropertyChangeListener(listener); } Map<Integer, Plot> plotById = new HashMap<>(); for (Plot plot : fieldViewPanel.getFieldLayout()) { plotById.put(plot.getPlotId(), plot); } TrialItemVisitor<Sample> sampleVisitor = new TrialItemVisitor<Sample>() { @Override public void setExpectedItemCount(int count) { } @Override public boolean consumeItem(Sample sample) throws IOException { Plot plot = plotById.get(sample.getPlotId()); if (plot == null) { throw new IOException("Missing plot for plotId=" + sample.getPlotId() + " sampleIdent=" + Util.createUniqueSampleKey(sample)); } plot.addSample(sample); SampleCounts counts = countsByTraitId.get(sample.getTraitId()); if (counts == null) { counts = new SampleCounts(); countsByTraitId.put(sample.getTraitId(), counts); } if (sample.hasBeenScored()) { ++counts.scored; } else { ++counts.unscored; } return true; } }; database.visitSamplesForTrial(sampleGroupChoiceForSamples, trial.getTrialId(), SampleOrder.ALL_BY_PLOT_ID_THEN_TRAIT_ID_THEN_INSTANCE_NUMBER_ORDER_THEN_SPECIMEN_NUMBER, sampleVisitor); setDefaultCloseOperation(DISPOSE_ON_CLOSE); this.trial = trial; KDClientUtils.initAction(ImageId.SETTINGS_24, showInfoAction, "Trial Summary"); Action clear = new AbstractAction("Clear") { @Override public void actionPerformed(ActionEvent e) { infoTextArea.setText(""); } }; JPanel bottom = new JPanel(new BorderLayout()); bottom.add(GuiUtil.createLabelSeparator("Plot Details", new JButton(clear)), BorderLayout.NORTH); bottom.add(new JScrollPane(infoTextArea), BorderLayout.CENTER); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, fieldViewPanel, new JScrollPane(infoTextArea)); splitPane.setResizeWeight(0.0); splitPane.setOneTouchExpandable(true); setContentPane(splitPane); updateMovementControls(); pack(); }
From source file:de.tor.tribes.ui.views.DSWorkbenchTroopsFrame.java
private void buildMenu() { JXTaskPane editTaskPane = new JXTaskPane(); editTaskPane.setTitle("Bearbeiten"); JXButton createTroopInfo = new JXButton( new ImageIcon(DSWorkbenchTroopsFrame.class.getResource("/res/ui/troop_info_new.png"))); createTroopInfo/*from w w w. ja v a2 s .c o m*/ .setToolTipText("<html>Truppeninformationen fr einzelne Dörfer manuell einfügen.<br/>" + "Die eingefügten Informationen beziehen sich nur auf die aktuell gewählte Ansicht.<br/>" + "Unterstützungen können auf diese Weise <b>nicht</b> eingefügt werden.</html>"); createTroopInfo.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { TroopTableTab tab = (TroopTableTab) getActiveTab(); if (tab.getTroopSet().equals(TroopsManager.SUPPORT_GROUP)) { tab.showError("Diese Funktion ist fr Untersttzungen nicht verfgbar"); return; } addTroopsManuallyEvent(); } }); editTaskPane.getContentPane().add(createTroopInfo); JXTaskPane transferTaskPane = new JXTaskPane(); transferTaskPane.setTitle("bertragen"); JXButton transferVillageList = new JXButton( new ImageIcon(DSWorkbenchTroopsFrame.class.getResource("/res/ui/center_ingame.png"))); transferVillageList.setToolTipText("Zentriert das gewhlte Dorf im Spiel"); transferVillageList.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { TroopTableTab tab = getActiveTab(); if (tab != null) { tab.centerVillageInGame(); } } }); transferTaskPane.getContentPane().add(transferVillageList); JXButton openPlace = new JXButton( new ImageIcon(DSWorkbenchTroopsFrame.class.getResource("/res/ui/place.png"))); openPlace.setToolTipText("ffnet den Versammlungsplatz des gewhlten Dorfes im Spiel"); openPlace.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { TroopTableTab tab = getActiveTab(); if (tab != null) { tab.openPlaceInGame(); } } }); openPlace.setSize(transferVillageList.getSize()); openPlace.setMinimumSize(transferVillageList.getMinimumSize()); openPlace.setMaximumSize(transferVillageList.getMaximumSize()); openPlace.setPreferredSize(transferVillageList.getPreferredSize()); transferTaskPane.getContentPane().add(openPlace); if (!GlobalOptions.isMinimal()) { JXButton centerVillage = new JXButton( new ImageIcon(DSWorkbenchTroopsFrame.class.getResource("/res/center_24x24.png"))); centerVillage.setToolTipText("Zentriert das gewhlte Dorf auf der Hauptkarte"); centerVillage.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { TroopTableTab tab = getActiveTab(); if (tab != null) { tab.centerVillage(); } } }); transferTaskPane.getContentPane().add(centerVillage); } JXTaskPane miscPane = new JXTaskPane(); miscPane.setTitle("Sonstiges"); JXButton selectionDetailsButton = new JXButton( new ImageIcon(DSWorkbenchTroopsFrame.class.getResource("/res/ui/information.png"))); selectionDetailsButton.setToolTipText("Zeigt Details zu den gewhlten Drfern an"); selectionDetailsButton.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { TroopTableTab tab = (TroopTableTab) getActiveTab(); if (tab != null) { tab.showSelectionDetails(); } } }); selectionDetailsButton.setSize(transferVillageList.getSize()); selectionDetailsButton.setMinimumSize(transferVillageList.getMinimumSize()); selectionDetailsButton.setMaximumSize(transferVillageList.getMaximumSize()); selectionDetailsButton.setPreferredSize(transferVillageList.getPreferredSize()); miscPane.getContentPane().add(selectionDetailsButton); centerPanel.setupTaskPane(editTaskPane, transferTaskPane, miscPane); }
From source file:com.itemanalysis.jmetrik.gui.Jmetrik.java
public Jmetrik() { super("jMetrik"); setPreferredSize(new Dimension(1024, 650)); setDefaultCloseOperation(EXIT_ON_CLOSE); //properly close database if user closes window this.addWindowListener(new WindowAdapter() { @Override/*from www .j ava 2 s . co m*/ public void windowClosing(WindowEvent we) { if (workspace != null) { workspace.closeDatabase(); } System.exit(0); } }); //add statusbar statusBar = new StatusBar(1024, 30); statusBar.setBorder(new EmptyBorder(2, 2, 2, 2)); getContentPane().add(statusBar, BorderLayout.SOUTH); //start logging startLog(); //left-right splitpane JSplitPane splitPane1 = new JSplitPane(); splitPane1.setDividerLocation(200); //setup workspace list workspaceList = new JList(); workspaceList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); workspaceList.setModel(new SortedListModel<DataTableName>()); workspaceList.addKeyListener(new DeleteKeyListener()); // workspaceList.getInsets().set(5, 5, 5, 5); //add icon to list cell renderer String urlString = "/images/spreadsheet.png"; URL url = this.getClass().getResource(urlString); final ImageIcon tableIcon = new ImageIcon(url, "Table"); workspaceList.setCellRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); label.setIcon(tableIcon); return label; } }); JScrollPane scrollPane1 = new JScrollPane(workspaceList); scrollPane1.setPreferredSize(new Dimension(200, 698)); splitPane1.setLeftComponent(scrollPane1); //tabbed pane for top pane tabbedPane = new JTabbedPane(); tabbedPane.setTabPlacement(JTabbedPane.BOTTOM); //setup data table dataTable = new DataTable(); dataTable.setRowHeight(18); //change size of table header and center text JTableHeader header = dataTable.getTableHeader(); header.setDefaultRenderer(new TableHeaderCellRenderer()); JScrollPane dataScrollPane = new JScrollPane(dataTable); tabbedPane.addTab("Data", dataScrollPane); //setup variable table variableTable = new DataTable(); variableTable.setRowHeight(18); variableTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); if (e.getClickCount() == 2) { JTable target = (JTable) e.getSource(); int row = target.getSelectedRow(); int col = target.getSelectedColumn(); if (col == 0) { if (target.getModel() instanceof VariableModel) { VariableModel vModel = (VariableModel) target.getModel(); String s = (String) vModel.getValueAt(row, col); DatabaseName db = workspace.getDatabaseName(); DataTableName table = workspace.getCurrentDataTable(); RenameVariableDialog renameVariableDialog = new RenameVariableDialog(Jmetrik.this, db, table, s); renameVariableDialog.setVisible(true); if (renameVariableDialog.canRun()) { RenameVariableCommand command = renameVariableDialog.getCommand(); workspace.runProcess(command); } } //end instanceof } //end if col==0 } //end if click count==2 }//end mouse clicked }); //change size of table header and center text JTableHeader variableHeader = variableTable.getTableHeader(); variableHeader.setDefaultRenderer(new TableHeaderCellRenderer()); variableHeader.setPreferredSize(new Dimension(30, 21)); JScrollPane variableScrollPane = new JScrollPane(variableTable); tabbedPane.addTab("Variables", variableScrollPane); splitPane1.setRightComponent(tabbedPane); getContentPane().add(splitPane1, BorderLayout.CENTER); //add status bar listener - needed to display status message that are generated within this class this.addPropertyChangeListener(statusBar.getStatusListener()); //add listener for displaying error messages - needed to display errors and exceptions this.addPropertyChangeListener(new ErrorOccurredPropertyChangeListener()); //instantiate file utilities fileUtils = new JmetrikFileUtils(); fileUtils.addPropertyChangeListener(statusBar.getStatusListener()); //set import and export path to user's documents folder JFileChooser chooser = new JFileChooser(); FileSystemView fw = chooser.getFileSystemView(); importExportPath = fw.getDefaultDirectory().toString().replaceAll("\\\\", "/"); //create and start a workspace startWorkspace(); //create menu bar and tool bar this.setJMenuBar(createMenuBar()); JToolBar toolBar = createToolBar(); toolBar.setFloatable(false); toolBar.setRollover(true); getContentPane().add(toolBar, BorderLayout.PAGE_START); pack(); }
From source file:com.dnsoft.inmobiliaria.controllers.ConsultaCCPropietariosController.java
void accionesBotones() { view.botonVolver1.addMouseListener(new MouseAdapter() { @Override/* www . j a v a 2s . c o m*/ public void mouseClicked(MouseEvent evt) { ConsultaCCPropietariosController.this.view.dispose(); } }); view.btnCuenta.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { detallesCCPropietario(); } }); view.btnPropietario.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { verPropietarioSeleccionado(); } }); }
From source file:org.pf.midea.MainUI.java
private void menuItemAboutActionPerformed(ActionEvent e) { JFrame about = new JFrame(" "); about.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); JPanel nestedPanel = new JPanel(); nestedPanel.setLayout(new GridLayout(17, 1)); nestedPanel//from ww w .java 2 s. co m .add(new JLabel("? ? ?")); nestedPanel.add(new JLabel("? ?")); nestedPanel.add(new JLabel(" ?")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel(" . . ?, 20072013")); nestedPanel.add(new JLabel(" ? ? ")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel(" ???")); nestedPanel.add(new JLabel( " ? ? 4.2.")); nestedPanel.add(new JLabel( " ? ??")); nestedPanel.add(new JLabel(" COPYING (??? ).")); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel( "? ? ?? ?:")); JLabel labelMail = new JLabel( "<html><a href=\"mailto:oleksandr@natalenko.name\">oleksandr@natalenko.name</a></html>"); labelMail.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop() .mail(new URI("mailto:oleksandr@natalenko.name?subject=" + URLEncoder.encode( "? ? ?", "UTF-8"))); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } } }); nestedPanel.add(labelMail); nestedPanel.add(new JLabel("")); nestedPanel.add(new JLabel("-? :")); JLabel labelURL = new JLabel("<html><a href=\"http://natalenko.name/\">http://natalenko.name/</a></html>"); labelURL.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { try { Desktop.getDesktop().browse(new URI("http://natalenko.name/")); } catch (URISyntaxException | IOException ex) { ex.printStackTrace(); } } }); nestedPanel.add(labelURL); about.add(nestedPanel); about.pack(); about.setLocationRelativeTo(null); about.setVisible(true); }
From source file:au.org.ala.delta.intkey.ui.TaxonSelectionDialog.java
private void init(List<Item> taxa, boolean displayNumbering, boolean singleSelect, boolean includeSpecimenAsOption) { ResourceMap resourceMap = Application.getInstance().getContext().getResourceMap(TaxonSelectionDialog.class); resourceMap.injectFields(this); ActionMap actionMap = Application.getInstance().getContext().getActionMap(TaxonSelectionDialog.class, this); setTitle(MessageFormat.format(title, _directiveName)); _fullTextTaxonFormatter = new ItemFormatter(true, CommentStrippingMode.RETAIN, AngleBracketHandlingMode.REPLACE, true, false, false); _panelButtons.setBorder(new EmptyBorder(0, 20, 10, 20)); _panelButtons.setLayout(new GridLayout(0, 5, 5, 5)); _btnOk = new JButton(); _btnOk.setAction(actionMap.get("taxonSelectionDialog_OK")); _btnSelectAll = new JButton(); _btnSelectAll.setAction(actionMap.get("taxonSelectionDialog_SelectAll")); _btnKeywords = new JButton(); _btnKeywords.setAction(actionMap.get("taxonSelectionDialog_Keywords")); _btnImages = new JButton(); _btnImages.setAction(actionMap.get("taxonSelectionDialog_Images")); _btnImages.setEnabled(false);/* w w w . j a v a2 s .c o m*/ _btnSearch = new JButton(); _btnSearch.setAction(actionMap.get("taxonSelectionDialog_Search")); _btnCancel = new JButton(); _btnCancel.setAction(actionMap.get("taxonSelectionDialog_Cancel")); _btnDeselectAll = new JButton(); _btnDeselectAll.setAction(actionMap.get("taxonSelectionDialog_DeselectAll")); _btnFullText = new JButton(); _btnFullText.setAction(actionMap.get("taxonSelectionDialog_FullText")); _btnFullText.setEnabled(false); _btnHelp = new JButton(); _btnHelp.setAction(actionMap.get("taxonSelectionDialog_Help")); // Some of the buttons should not be displayed if not in advanced mode if (_context.getUI().isAdvancedMode()) { _panelButtons.add(_btnOk); _panelButtons.add(_btnSelectAll); _panelButtons.add(_btnKeywords); _panelButtons.add(_btnImages); _panelButtons.add(_btnSearch); _panelButtons.add(_btnCancel); _panelButtons.add(_btnDeselectAll); _panelButtons.add(_btnFullText); _panelButtons.add(_btnHelp); } else { _panelButtons.setLayout(new GridLayout(0, 4, 5, 0)); _panelButtons.add(_btnOk); _panelButtons.add(_btnCancel); _panelButtons.add(_btnSelectAll); _panelButtons.add(_btnDeselectAll); } _selectedTaxa = null; _includeSpecimenAsOption = includeSpecimenAsOption; if (taxa != null) { _listModel = new DefaultListModel(); if (_includeSpecimenAsOption) { _listModel.addElement(IntkeyContext.SPECIMEN_KEYWORD); } for (Item taxon : taxa) { _listModel.addElement(taxon); } _list.setCellRenderer(new TaxonCellRenderer(displayNumbering, false)); _list.setModel(_listModel); } if (singleSelect) { _list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } _list.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (_list.getSelectedIndices().length == 1 && !_list.getSelectedValue().equals(IntkeyContext.SPECIMEN_KEYWORD)) { Item taxon = (Item) _list.getSelectedValue(); _btnImages.setEnabled(taxon.getImages().size() > 0); _btnFullText.setEnabled(true); } else { _btnImages.setEnabled(false); _btnFullText.setEnabled(false); } } }); _list.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) { // Treat double click on a list item as the ok button being // pressed. taxonSelectionDialog_OK(); } } }); _selectedKeywords = new ArrayList<String>(); }
From source file:net.sf.xmm.moviemanager.gui.DialogIMDbMultiAdd.java
JPanel createFileLocationPanel() { // Panel file location JPanel fileLocationPanel = new JPanel(); fileLocationPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), " Movie parts "), BorderFactory.createEmptyBorder(0, 3, 3, 3))); fileLocationPanel.setLayout(new BorderLayout()); fileLocation = new JTextArea(); fileLocation.setEditable(false);//from w w w.j a v a2s .c o m JScrollPane fileLocaScroll = new JScrollPane(fileLocation); fileLocationPanel.add(fileLocaScroll, BorderLayout.CENTER); fileLocation.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //handleFileLocationPopup(e); } }); return fileLocationPanel; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopAbstractTable.java
protected void initComponent() { layout = new MigLayout("flowy, fill, insets 0", "", "[min!][fill]"); panel = new JPanel(layout); topPanel = new JPanel(new BorderLayout()); topPanel.setVisible(false);// ww w. j ava2s . c o m panel.add(topPanel, "growx"); scrollPane = new JScrollPane(impl); impl.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); impl.setFillsViewportHeight(true); panel.add(scrollPane, "grow"); impl.setShowGrid(true); impl.setGridColor(Color.lightGray); impl.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) { handleClickAction(); } } @Override public void mousePressed(MouseEvent e) { showPopup(e); } @Override public void mouseReleased(MouseEvent e) { showPopup(e); } protected void showPopup(MouseEvent e) { if (e.isPopupTrigger() && contextMenuEnabled) { // select row Point p = e.getPoint(); int viewRowIndex = impl.rowAtPoint(p); int rowNumber; if (viewRowIndex >= 0) { rowNumber = impl.convertRowIndexToModel(viewRowIndex); } else { rowNumber = -1; } ListSelectionModel model = impl.getSelectionModel(); if (!model.isSelectedIndex(rowNumber)) { model.setSelectionInterval(rowNumber, rowNumber); } // show popup menu JPopupMenu popupMenu = createPopupMenu(); if (popupMenu.getComponentCount() > 0) { popupMenu.show(e.getComponent(), e.getX(), e.getY()); } } } }); ColumnControlButton columnControlButton = new ColumnControlButton(impl) { @Override protected ColumnVisibilityAction createColumnVisibilityAction(TableColumn column) { ColumnVisibilityAction columnVisibilityAction = super.createColumnVisibilityAction(column); columnVisibilityAction.addPropertyChangeListener(evt -> { if ("SwingSelectedKey".equals(evt.getPropertyName()) && evt.getNewValue() instanceof Boolean) { ColumnVisibilityAction action = (ColumnVisibilityAction) evt.getSource(); String columnName = action.getActionCommand(); boolean collapsed = !((boolean) evt.getNewValue()); Column col = getColumn(columnName); if (col != null) { col.setCollapsed(collapsed); } } }); return columnVisibilityAction; } }; impl.setColumnControl(columnControlButton); impl.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter"); impl.getActionMap().put("enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (enterPressAction != null) { enterPressAction.actionPerform(DesktopAbstractTable.this); } else { handleClickAction(); } } }); Messages messages = AppBeans.get(Messages.NAME); // localize default column control actions for (Object actionKey : impl.getActionMap().allKeys()) { if ("column.packAll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packAll")); } else if ("column.packSelected".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.packSelected")); } else if ("column.horizontalScroll".equals(actionKey)) { BoundAction action = (BoundAction) impl.getActionMap().get(actionKey); action.setName(messages.getMessage(DesktopTable.class, "DesktopTable.horizontalScroll")); } } // Ability to configure fonts in table // Add action to column control String configureFontsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.configureFontsLabel"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "fonts", new AbstractAction(configureFontsLabel) { @Override public void actionPerformed(ActionEvent e) { Component rootComponent = SwingUtilities.getRoot(impl); final FontDialog fontDialog = FontDialog.show(rootComponent, impl.getFont()); fontDialog.addWindowListener(new WindowAdapter() { @Override public void windowClosed(WindowEvent e) { Font result = fontDialog.getResult(); if (result != null) { impl.setFont(result); packRows(); } } }); fontDialog.open(); } }); // Ability to reset settings String resetSettingsLabel = messages.getMessage(DesktopTable.class, "DesktopTable.resetSettings"); impl.getActionMap().put(ColumnControlButton.COLUMN_CONTROL_MARKER + "resetSettings", new AbstractAction(resetSettingsLabel) { @Override public void actionPerformed(ActionEvent e) { resetPresentation(); } }); scrollPane.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (!columnsInitialized) { adjustColumnHeaders(); } columnsInitialized = true; } }); // init default row height SwingUtilities.invokeLater(new Runnable() { @Override public void run() { if (!fontInitialized) { applyFont(impl, impl.getFont()); } } }); }
From source file:corina.cross.AllScoresView.java
private void makeDoubleClickable() { // double-click-able table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) // double-clicks only graphSelectedCrossdate(); }//w w w . j ava2s . c om }); }