List of usage examples for java.awt.event MouseEvent getComponent
public Component getComponent()
From source file:io.gameover.utilities.pixeleditor.Pixelizer.java
public JProgressBar getToleranceBar() { if (toleranceBar == null) { toleranceBar = new JProgressBar(); toleranceBar.setPreferredSize(new Dimension(200, 25)); toleranceBar.setValue(10);//from w ww. j a v a2 s. co m toleranceBar.setMaximum(100); toleranceBar.setStringPainted(true); toleranceBar.addMouseListener(new MouseAdapter() { public boolean mouseEntered = false; @Override public void mouseReleased(MouseEvent e) { if (mouseEntered) { JProgressBar pb = (JProgressBar) e.getComponent(); pb.setValue((int) ((((double) e.getX()) / pb.getSize().getWidth()) * 100d)); pb.updateUI(); } } @Override public void mouseEntered(MouseEvent e) { this.mouseEntered = true; } @Override public void mouseExited(MouseEvent e) { this.mouseEntered = false; } }); } return toleranceBar; }
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * creates CAP for Click in Component/*from www . ja va2s . c om*/ * @param id IComponentIdentifier * @param me MouseEvent * @param source Component */ protected void clickInComponent(IComponentIdentifier id, MouseEvent me, Component source) { int clickcount = me.getClickCount(); if (clickcount < 1) { clickcount = 1; } String clCount = (new Integer(clickcount).toString()); String mbutton = (new Integer(me.getButton()).toString()); Action a = m_recordHelper.compSysToAction(id, "CompSystem.ClickDirect"); //$NON-NLS-1$ Rectangle bounds = me.getComponent().getBounds(); int percentX = (int) (me.getX() / bounds.getWidth() * 100); String percentXString = new Integer(percentX).toString(); int percentY = (int) (me.getY() / bounds.getHeight() * 100); String percentYString = new Integer(percentY).toString(); String units = Constants.REC_UNITS; List parValues = new LinkedList(); parValues.add(clCount); parValues.add(mbutton); parValues.add(percentXString); parValues.add(units); parValues.add(percentYString); parValues.add(units); String logName = createLogicalName(source, id); createCAP(a, id, parValues, logName); }
From source file:org.ut.biolab.medsavant.client.view.genetics.charts.SummaryChart.java
private synchronized Chart drawChart(ChartFrequencyMap[] chartMaps) { ChartFrequencyMap filteredChartMap = chartMaps[0]; ChartFrequencyMap unfilteredChartMap = null; DefaultChartModel filteredChartModel = new DefaultChartModel(); DefaultChartModel unfilteredChartModel = null; if (this.showComparedToOriginal) { unfilteredChartMap = ChartFrequencyMap.subtract(chartMaps[1], filteredChartMap, isLogScaleY()); unfilteredChartModel = new DefaultChartModel(); }//from ww w.j a v a 2s . c om final Chart chart = new Chart(); JPanel panel = new JPanel(); Legend legend = new Legend(chart, 0); panel.add(legend); legend.addChart(chart); boolean multiColor = !mapGenerator.isNumeric() || isPie; chart.setRolloverEnabled(true); chart.setSelectionEnabled(true); chart.setSelectionShowsOutline(true); chart.setSelectionShowsExplodedSegments(true); chart.setAntiAliasing(true); chart.setBarGap(5); chart.setBorder(ViewUtil.getBigBorder()); chart.setLabellingTraces(true); chart.setAnimateOnShow(false); chart.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { JPopupMenu popup = createPopup(chart); popup.show(e.getComponent(), e.getX(), e.getY()); } } }); AbstractPieSegmentRenderer rpie = new DefaultPieSegmentRenderer(); chart.setPieSegmentRenderer(rpie); //Makes a box with fill color 255,255,255,0 and put a label with a black //font in that box. The box is positioned directly over the corresponding pie slice. /* SimplePieLabelRenderer plr = new SimplePieLabelRenderer(); plr.setLabelColor(Color.BLACK); plr.setBackground(new Color(0,0,0,0)); rpie.setPieLabelRenderer(plr); */ //....alternatively, the below draws a line from the pie wedge to the label. //see http://www.jidesoft.com/javadoc/com/jidesoft/chart/render/LinePieLabelRenderer.html LinePieLabelRenderer plr = new LinePieLabelRenderer(); plr.setLabelColor(Color.black); plr.setLineColor(Color.black); //see also plr.setLineStroke rpie.setPieLabelRenderer(plr); DefaultBarRenderer rbar = new DefaultBarRenderer(); chart.setBarRenderer(rbar); rpie.setSelectionColor(Color.gray); rbar.setSelectionColor(Color.gray); if (isSortedKaryotypically()) { filteredChartMap.sortKaryotypically(); if (this.showComparedToOriginal) { unfilteredChartMap.sortKaryotypically(); } } if (isSorted() && !mapGenerator.isNumeric() && !isSortedKaryotypically()) { filteredChartMap.sortNumerically(); if (this.showComparedToOriginal) { chartMaps[1].sortNumerically(); } } else { filteredChartMap.undoSortNumerically(); if (this.showComparedToOriginal) { chartMaps[1].undoSortNumerically(); } } long max = filteredChartMap.getMax(); List<ChartCategory> chartCategories; if (this.showComparedToOriginal) { chartCategories = chartMaps[1].getCategories(); max = chartMaps[1].getMax(); } else { chartCategories = filteredChartMap.getCategories(); } CategoryRange<String> range = new CategoryRange<String>(); List<Highlight> highlights = new ArrayList<Highlight>(); Color color = new Color(72, 181, 249); Highlight h; int catNum = 0; int totalCats = filteredChartMap.getEntries().size(); for (ChartCategory category : chartCategories) { range.add(category); if (multiColor) { color = ViewUtil.getColor(catNum++, totalCats); } h = new Highlight(category.getName()); highlights.add(h); chart.setHighlightStyle(h, barStyle(color)); } final CategoryAxis xaxis = new CategoryAxis(range, "Category"); chart.setXAxis(xaxis); if (this.isLogScaleY()) { chart.setYAxis(new Axis(new NumericRange(0, Math.log10(max) * 1.1), "log(Frequency)")); } else { chart.setYAxis(new Axis(new NumericRange(0, max * 1.1), "Frequency")); } addEntriesToChart(filteredChartModel, filteredChartMap, chartCategories, highlights); if (this.showComparedToOriginal) { addEntriesToChart(unfilteredChartModel, unfilteredChartMap, chartCategories, null); } chart.getXAxis().getLabel().setFont(ViewUtil.getMediumTitleFont()); chart.getYAxis().getLabel().setFont(ViewUtil.getMediumTitleFont()); // rotate 90 degrees (using radians) chart.getXAxis().setTickLabelRotation(1.57079633); if (isPie) { System.out.println("Setting chart type to pie"); chart.setChartType(ChartType.PIE); chart.getXAxis().getLabel().setColor(Color.BLUE); } // This adds zooming cababilities to bar charts, not great though /*else { RubberBandZoomer rubberBand = new RubberBandZoomer(chart); chart.addDrawable(rubberBand); chart.addMouseListener(rubberBand); chart.addMouseMotionListener(rubberBand); rubberBand.addZoomListener(new ZoomListener() { public void zoomChanged(ChartSelectionEvent event) { if (event instanceof RectangleSelectionEvent) { Range<?> currentXRange = chart.getXAxis().getOutputRange(); Range<?> currentYRange = chart.getYAxis().getOutputRange(); ZoomFrame frame = new ZoomFrame(currentXRange, currentYRange); zoomStack.push(frame); Rectangle selection = (Rectangle) event.getLocation(); Point topLeft = selection.getLocation(); topLeft.x = (int) Math.floor(frame.getXRange().minimum()); Point bottomRight = new Point(topLeft.x + selection.width, topLeft.y + selection.height); bottomRight.x = (int) Math.ceil(frame.getXRange().maximum()); assert bottomRight.x >= topLeft.x; Point2D rp1 = chart.calculateUserPoint(topLeft); Point2D rp2 = chart.calculateUserPoint(bottomRight); if (rp1 != null && rp2 != null) { assert rp2.getX() >= rp1.getX(); Range<?> xRange = new NumericRange(rp1.getX(), rp2.getX()); assert rp1.getY() >= rp2.getY(); Range<?> yRange = new NumericRange(rp2.getY(), rp1.getY()); //chart.getXAxis().setRange(xRange); chart.getYAxis().setRange(yRange); } } else if (event instanceof PointSelectionEvent) { if (zoomStack.size() > 0) { ZoomFrame frame = zoomStack.pop(); Range<?> xRange = frame.getXRange(); Range<?> yRange = frame.getYRange(); //chart.getXAxis().setRange(xRange); chart.getYAxis().setRange(yRange); } } } }); } * */ for (int i = 1; i < this.getComponentCount(); i++) { this.remove(i); } chart.addModel(filteredChartModel, new ChartStyle().withBars()); if (this.showComparedToOriginal) { chart.addModel(unfilteredChartModel, new ChartStyle(new Color(10, 10, 10, 100)).withBars()); } return chart; }
From source file:nz.ac.massey.cs.gql4jung.browser.ResultBrowser.java
private void initPopupMenu() { popup = new JPopupMenu(); popup.add(this.actRunQuery); popup.add(this.actCancelQuery); popup.addSeparator();//from w w w. ja v a 2s .c o m popup.add(this.actLoadData); popup.add(this.actLoadQuery); popup.addSeparator(); popup.add(this.actNextMajorInstance); popup.add(this.actPreviousMajorInstance); popup.addSeparator(); popup.add(this.actNextMinorInstance); popup.add(this.actPreviousMinorInstance); popupListener = new MouseAdapter() { public void mousePressed(MouseEvent e) { showPopup(e); } public void mouseReleased(MouseEvent e) { showPopup(e); } private void showPopup(MouseEvent e) { if (e.isPopupTrigger()) { popup.show(e.getComponent(), e.getX(), e.getY()); } } }; this.mainPanel.addMouseListener(popupListener); }
From source file:org.fhaes.jsea.JSEAFrame.java
/** * Show popup menu//from ww w. j a v a2 s . c o m * * @param component * @param popup */ private static void addPopup(Component component, final JPopupMenu popup) { component.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { showMenu(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { showMenu(e); } } private void showMenu(MouseEvent e) { popup.show(e.getComponent(), e.getX(), e.getY()); } }); }
From source file:it.iit.genomics.cru.igb.bundles.mi.view.MITable.java
public MITable(MITableModel model, IgbService service, final MIQuery query) { super(model); this.query = query; igbLogger = IGBLogger.getInstance(query.getLabel()); this.igbService = service; this.SymSelectionListener = new MouseListener() { @SuppressWarnings("unchecked") @Override//from w ww .j a va 2 s. c o m public void mouseClicked(MouseEvent e) { if (e.getComponent().isEnabled() && e.getButton() == MouseEvent.BUTTON1) { if (getSelectedRow() >= 0) { int modelRow = convertRowIndexToModel(getSelectedRow()); MIResult interaction = ((MITableModel) getModel()).getResult(modelRow); structuresPanel.setCurrentInteraction(interaction); } MITable table = (MITable) e.getComponent(); int modelRow = convertRowIndexToModel(table.getSelectedRow()); int column = table.getSelectedColumn(); if (e.getClickCount() == 1) { if (column == MITableModel.TRACK_COLUMN) { Object value = table.getValueAt(table.getSelectedRow(), column); if (value instanceof JButton) { MIResult result = ((MITableModel) table.getModel()).getResult(modelRow); TypeContainerAnnot interactorTrack = result.createTrack(); igbService.addTrack(interactorTrack, interactorTrack.getID()); igbService.getSeqMapView().updatePanel(); for (TierGlyph t : igbService.getAllTierGlyphs()) { if (TierGlyph.TierType.ANNOTATION.equals(t.getTierType()) && (t.getAnnotStyle().getTrackName().equals(interactorTrack.getID()))) { SimpleTrackStyle style = new SimpleTrackStyle(interactorTrack.getID(), false) { @Override public boolean drawCollapseControl() { return false; } }; t.getAnnotStyle().copyPropertiesFrom(style); t.getAnnotStyle().setColorProvider(new RGB()); interactorTrack.setProperty(TrackLineParser.ITEM_RGB, "on"); } } igbService.getSeqMapView().updatePanel(); ((JButton) value).setText(interactorTrack.getID()); ((JButton) value).setEnabled(false); updateUI(); } } } else { // symmetry: zoom-in if (column == MITableModel.SYMS1_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor1(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries1(); zoomToSym(syms); } } else if (column == MITableModel.SYMS2_COLUMN) { MoleculeEntry entry = ((MITableModel) table.getModel()).getResult(modelRow) .getInteractor2(); if (query.getTaxid().equals(entry.getTaxid())) { Collection<SeqSymmetry> syms = ((MITableModel) table.getModel()).getResult(modelRow) .getSymmetries2(); zoomToSym(syms); } } // Protein: link to uniprot if (column == MITableModel.INTERACTOR1_COLUMN || column == MITableModel.INTERACTOR2_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String id; String taxid; MoleculeEntry interactor; if (column == MITableModel.INTERACTOR1_COLUMN) { interactor = miResult.getInteractor1(); } else { interactor = miResult.getInteractor2(); } taxid = interactor.getTaxid(); String query; String anchor = ""; switch (taxid) { case MoleculeEntry.TAXID_DNA: case MoleculeEntry.TAXID_RNA: if (miResult.getInteractionStructures().isEmpty()) { return; } query = "http://www.pdb.org/pdb/explore/explore.do?structureId=" + miResult.getInteractionStructures().iterator().next().getStructureID(); break; case MoleculeEntry.TAXID_LIGAND: if (miResult.getInteractionStructures().isEmpty()) { return; } query = DrugBankMapper.getInstance().isDrug(interactor.getGeneName()) ? DrugBankMapper.getInstance().getDrugBankLink(interactor.getGeneName()) : "http://www.ebi.ac.uk/pdbe-srv/pdbechem/chemicalCompound/show/" + interactor.getGeneName(); break; case MoleculeEntry.TAXID_MODIFICATION: query = "http://www.uniprot.org/uniprot/" + miResult.getInteractor1().getUniprotAc(); anchor = "#ptm_processing"; break; default: id = interactor.getUniprotAc(); query = "http://www.uniprot.org/uniprot/" + id; break; } try { URI uri = new URI(URIUtil.encodeQuery(query) + anchor); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website."); return; } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach Uniprot website: " + query); } } // interaction type: link to psicquic if (column == MITableModel.INTERACTION_TYPE_COLUMN) { MIResult miResult = ((MITableModel) table.getModel()).getResult(modelRow); String queryURL; String idA = miResult.getInteractor1().getUniprotAc(); String idB = miResult.getInteractor2().getUniprotAc(); if (null == miResult.getPsicquicUrl()) { // from the structure database if (query.searchDSysMap()) { queryURL = "http://http://dsysmap.irbbarcelona.org/results.php?type=proteins&neigh=2&value=" + idA + "," + idB; } else if (query.searchInteractome3D()) { try { queryURL = "http://interactome3d.irbbarcelona.org/interaction.php?ids=" + idA + ";" + idB + "&dataset=" + it.iit.genomics.cru.bridges.interactome3d.ws.Utils .getDataset(query.getTaxid()); } catch (Interactome3DException e3d) { // it will never happend: if the taxid was not known by // I3D, we wouldn't have an interaction return; } } else { return; } } else { if (false == idA.equals(idB)) { queryURL = miResult.getPsicquicUrl() + "query/id:" + miResult.getInteractor1().getUniprotAc() + "* AND id:" + miResult.getInteractor2().getUniprotAc() + "*"; } else { queryURL = miResult.getPsicquicUrl() + "query/idA:" + miResult.getInteractor1().getUniprotAc() + "* AND idB:" + miResult.getInteractor2().getUniprotAc() + "*"; } } try { URI uri = new URI(URIUtil.encodeQuery(queryURL)); Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null; if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) { desktop.browse(uri); } } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server."); } catch (URISyntaxException ue) { JOptionPane.showMessageDialog(null, "Cannot reach psicquic server: " + queryURL); } } } } } @Override public void mousePressed(MouseEvent me) { } @Override public void mouseReleased(MouseEvent me) { } @Override public void mouseEntered(MouseEvent me) { } @Override public void mouseExited(MouseEvent me) { } }; TableRowSorter<MITableModel> sorter = new MITableRowSorter(model); setRowSorter(sorter); sorter.setRowFilter(evidenceRowFilter()); model.fireTableDataChanged(); this.getTableHeader().setReorderingAllowed(false); TableCellRenderer rend = getTableHeader().getDefaultRenderer(); TableColumnModel tcm = getColumnModel(); for (int j = 0; j < tcm.getColumnCount(); j += 1) { TableColumn tc = tcm.getColumn(j); TableCellRenderer rendCol = tc.getHeaderRenderer(); // likely null if (rendCol == null) { rendCol = rend; } Component c = rendCol.getTableCellRendererComponent(this, tc.getHeaderValue(), false, false, 0, j); tc.setPreferredWidth(c.getPreferredSize().width); } TableCellRenderer buttonRenderer = new JTableButtonRenderer(); getColumn(model.getColumnName(MITableModel.TRACK_COLUMN)).setCellRenderer(buttonRenderer); getColumn(model.getColumnName(MITableModel.SYMS1_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.SYMS2_COLUMN)).setCellRenderer(new GeneRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR1_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTOR2_COLUMN)).setCellRenderer(new MoleculeRenderer()); getColumn(model.getColumnName(MITableModel.INTERACTION_TYPE_COLUMN)) .setCellRenderer(new EvidenceRenderer()); getColumn(model.getColumnName(MITableModel.STRUCTURES_COLUMN)).setCellRenderer(new StructuresRenderer()); setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); int smallWidth = 75; int mediumWidth = 120; int largeWidth = 200; getColumnModel().getColumn(MITableModel.TRACK_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMinWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setMaxWidth(smallWidth); getColumnModel().getColumn(MITableModel.STRUCTURES_COLUMN).setPreferredWidth(smallWidth); addMouseListener(SymSelectionListener); getSelectionModel().addListSelectionListener(new RowSelectionListener()); }
From source file:org.wandora.application.gui.topicpanels.RTopicPanel.java
public void showMenu(String[] struct, MouseEvent evt) { menu = UIBox.makePopupMenu(struct, this); menu.setLocation(evt.getXOnScreen() - 2, evt.getYOnScreen() - 2); menu.show(evt.getComponent(), evt.getX() - 2, evt.getY() - 2); }
From source file:org.zaproxy.zap.extension.multiFuzz.impl.http.HttpFuzzResultDialog.java
@Override public JXTreeTable getTable() { if (table == null) { if (model == null) { model = new HttpFuzzTableModel(); }/*from w w w . ja va 2s . c o m*/ table = new JXTreeTable(model); table.setDoubleBuffered(true); table.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); table.setName("HttpFuzzResultTable"); table.setFont(new java.awt.Font("Default", java.awt.Font.PLAIN, 12)); table.setDefaultRenderer(Pair.class, new IconTableCellRenderer()); int[] widths = { 10, 25, 550, 30, 85, 55, 40, 70 }; for (int i = 0, count = widths.length; i < count; i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setPreferredWidth(widths[i]); } table.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mousePressed(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } @Override public void mouseReleased(java.awt.event.MouseEvent e) { showPopupMenuIfTriggered(e); } private void showPopupMenuIfTriggered(java.awt.event.MouseEvent e) { if (e.isPopupTrigger()) { if (e.isPopupTrigger()) { // Select list item on right click JTable table = (JTable) e.getSource(); int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.changeSelection(row, 0, false, false); } View.getSingleton().getPopupMenu().show(e.getComponent(), e.getX(), e.getY()); } } } }); table.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() { @Override public void valueChanged(javax.swing.event.ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (table.getSelectedRowCount() == 0) { return; } final int row = table.getSelectedRow(); if (getEntry(row) instanceof HttpFuzzRequestRecord) { final HistoryReference historyReference = ((HttpFuzzRequestRecord) getEntry(row)) .getHistory(); try { getMessageInspection().setMessage(historyReference.getHttpMessage()); } catch (HttpMalformedHeaderException | SQLException ex) { logger.error(ex.getMessage(), ex); } } updateValues(); redrawDiagrams(); } } }); } table.getTableHeader().addMouseListener(new MouseListener() { int sortedOn = -1; @Override public void mouseReleased(MouseEvent arg0) { } @Override public void mousePressed(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseClicked(MouseEvent e) { int index = table.columnAtPoint(e.getPoint()); List<HttpFuzzRecord> list = model.getEntries(); if (list.size() == 0) { return; } HttpFuzzRecordComparator comp = new HttpFuzzRecordComparator(); comp.setFeature(index); if (index == sortedOn) { Collections.sort(list, comp); Collections.reverse(list); sortedOn = -1; } else { Collections.sort(list, comp); sortedOn = index; } table.updateUI(); } }); table.setRootVisible(false); table.setVisible(true); return table; }
From source file:krasa.cpu.CpuUsagePanel.java
public CpuUsagePanel(Project project) { refreshColors();// w w w .jav a 2 s . com this.myProject = project; this.projectName = project.getName(); setOpaque(false); setFocusable(false); setToolTipText("IDE CPU usage / System CPU usage"); setBorder(StatusBarWidget.WidgetBorder.INSTANCE); updateUI(); new UiNotifyConnector(this, new Activatable() { @Override public void showNotify() { CpuUsageManager.register(CpuUsagePanel.this); } @Override public void hideNotify() { CpuUsageManager.unregister(CpuUsagePanel.this); } }); MouseAdapter mouseAdapter = new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { CpuUsageManager.update(); final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ActionManager.getInstance().getAction("TakeThreadDump").actionPerformed(new AnActionEvent(e, context, ActionPlaces.UNKNOWN, new Presentation(""), ActionManager.getInstance(), 0)); } else if (SwingUtilities.isRightMouseButton(e)) { final DataContext context = DataManager.getInstance().getDataContext(CpuUsagePanel.this); ListPopup popup = JBPopupFactory.getInstance().createActionGroupPopup(null, getActionGroup(), context, JBPopupFactory.ActionSelectionAid.MNEMONICS, false); Dimension dimension = popup.getContent().getPreferredSize(); Point at = new Point(0, -dimension.height); popup.show(new RelativePoint(e.getComponent(), at)); } } }; addMouseListener(mouseAdapter); }
From source file:org.openconcerto.task.TodoListPanel.java
private void initTable(int mode) { this.t.setBlockRepaint(true); this.t.setBlockEventOnColumn(true); this.model.setMode(mode); this.t.getColumnModel().getColumn(0).setCellRenderer(this.a); this.t.getColumnModel().getColumn(0).setCellEditor(this.a); this.t.setBlockEventOnColumn(true); setIconForColumn(0, this.iconTache); setIconForColumn(1, this.iconPriorite); this.t.setBlockEventOnColumn(true); this.t.getColumnModel().getColumn(1).setCellEditor(this.iconEditor); final JTextField textField = new JTextField() { @Override/*from w w w . j a v a 2 s . c o m*/ public void paint(Graphics g) { super.paint(g); g.setColor(TodoListPanel.this.t.getGridColor()); g.fillRect(getWidth() - 19, 0, 1, getHeight()); g.setColor(new Color(250, 250, 250)); g.fillRect(getWidth() - 18, 0, 18, getHeight()); g.setColor(Color.BLACK); for (int i = 0; i < 3; i++) { int x = getWidth() - 14 + i * 4; int y = getHeight() - 5; g.fillRect(x, y, 1, 2); } } }; textField.setBorder(BorderFactory.createEmptyBorder()); final DefaultCellEditor defaultCellEditor = new DefaultCellEditor(textField); textField.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { if (e.getX() > textField.getWidth() - 19) { TodoListElement l = getTaskAt( SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), TodoListPanel.this.t)); TodoListPanel.this.t.editingCanceled(new ChangeEvent(this)); JFrame f = new JFrame(TM.tr("details")); f.setContentPane(new TodoListElementEditorPanel(l)); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setSize(500, 200); f.setLocation(50, e.getYOnScreen() + TodoListPanel.this.t.getRowHeight()); f.setVisible(true); } } }); this.t.getColumnModel().getColumn(2).setCellEditor(defaultCellEditor); this.t.getColumnModel().getColumn(3).setMaxWidth(300); this.t.getColumnModel().getColumn(3).setMinWidth(100); this.timestampTableCellEditorCreated.stopCellEditing(); this.timestampTableCellEditorDone.stopCellEditing(); this.timestampTableCellEditorDeadLine.stopCellEditing(); if (this.model.getMode() == TodoListModel.EXTENDED_MODE) { this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererCreated); this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorCreated); this.t.getColumnModel().getColumn(4).setCellRenderer(this.timestampTableCellRendererDone); this.t.getColumnModel().getColumn(4).setCellEditor(this.timestampTableCellEditorDone); this.t.getColumnModel().getColumn(5).setCellRenderer(this.timestampTableCellRendererDeadLine); this.t.getColumnModel().getColumn(5).setCellEditor(this.timestampTableCellEditorDeadLine); } else { this.t.getColumnModel().getColumn(3).setCellRenderer(this.timestampTableCellRendererDeadLine); this.t.getColumnModel().getColumn(3).setCellEditor(this.timestampTableCellEditorDeadLine); } final TableColumn userColumn = this.t.getColumnModel() .getColumn(this.t.getColumnModel().getColumnCount() - 1); userColumn.setCellRenderer(this.userTableCellRenderer); userColumn.setMaxWidth(150); userColumn.setMinWidth(100); t.setEnabled(false); initUserCellEditor(userColumn); this.t.setBlockEventOnColumn(false); this.t.setBlockRepaint(false); this.t.getColumnModel().getColumn(1).setCellRenderer(this.iconRenderer); // Better look this.t.setShowHorizontalLines(false); this.t.setGridColor(new Color(230, 230, 230)); this.t.setRowHeight(new JTextField(" ").getPreferredSize().height + 4); AlternateTableCellRenderer.UTILS.setAllColumns(this.t); this.t.repaint(); }