List of usage examples for javax.swing SwingUtilities isLeftMouseButton
public static boolean isLeftMouseButton(MouseEvent anEvent)
From source file:ded.ui.DiagramController.java
@Override public void mouseReleased(MouseEvent e) { this.eventReceived(e); // Click+drag should only be initiated with left mouse button, so ignore // release of others. if (!SwingUtilities.isLeftMouseButton(e)) { return;// w w w . j a va 2 s . co m } if (this.mode == Mode.DCM_DRAGGING || this.mode == Mode.DCM_RECT_LASSO) { this.setMode(Mode.DCM_SELECT); } }
From source file:ded.ui.DiagramController.java
@Override public void mouseClicked(MouseEvent e) { this.eventReceived(e); // Double-click on control to edit it. if (SwingUtilities.isLeftMouseButton(e) && (e.getClickCount() == 2)) { Controller c = this.hitTest(e.getPoint(), null); if (c != null) { c.edit();// w w w .j a va2 s .co m } } }
From source file:com.diversityarrays.kdxplore.trialmgr.trait.TraitExplorerPanel.java
public TraitExplorerPanel(MessagePrinter mp, OfflineData od, DALClientProvider clientProvider, // KdxUploadHandler uploadHandler, BackgroundRunner backgroundRunner, ImageIcon addBarcodeIcon, Transformer<Trial, Boolean> checkIfEditorActive) { super(new BorderLayout()); this.backgroundRunner = backgroundRunner; this.clientProvider = clientProvider; // this.uploadHandler = uploadHandler; this.messagePrinter = mp; this.offlineData = od; this.checkIfEditorActive = checkIfEditorActive; offlineData.addOfflineDataChangeListener(offlineDataListener); editingLocked.setIcon(KDClientUtils.getIcon(ImageId.LOCKED)); editingLocked.addActionListener(new ActionListener() { @Override//from w w w. j ava2 s. c om public void actionPerformed(ActionEvent e) { changeEditable(editingLocked.isSelected(), DONT_OVERRIDE); } }); changeManager.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateUndoRedoActions(); } }); KDClientUtils.initAction(ImageId.TRASH_24, deleteTraitsAction, "Remove Trait"); deleteTraitsAction.setEnabled(false); KDClientUtils.initAction(ImageId.REFRESH_24, refreshAction, "Refresh Data"); KDClientUtils.initAction(ImageId.PLUS_BLUE_24, addNewTraitAction, "Add Trait"); KDClientUtils.initAction(ImageId.UPLOAD_24, uploadTraitsAction, "Upload Traits"); KDClientUtils.initAction(ImageId.ADD_TRIALS_24, importTraitsAction, "Import Traits"); KDClientUtils.initAction(ImageId.EXPORT_24, exportTraitsAction, "Export Traits"); try { Class.forName("com.diversityarrays.kdxplore.upload.TraitUploadTask"); } catch (ClassNotFoundException e1) { uploadTraitsAction.setEnabled(false); if (RunMode.getRunMode().isDeveloper()) { new Toast((JComponent) null, "<HTML>Developer Warning<BR>" + "Trait Upload currently unavailable<BR>", 4000) .showAsError(); } } traitPropertiesTable .setTransferHandler(TableTransferHandler.initialiseForCopySelectAll(traitPropertiesTable, true)); traitPropertiesTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (traitPropertiesTableModel.getRowCount() > 0) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GuiUtil.initialiseTableColumnWidths(traitPropertiesTable); } }); traitPropertiesTableModel.removeTableModelListener(this); } } }); traitTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { showCorrectCard(); } }); TrialManagerPreferences preferences = TrialManagerPreferences.getInstance(); preferences.addChangeListener(TrialManagerPreferences.BAD_FOR_CALC, badForCalcColorChangeListener); badForCalc.setForeground(preferences.getBadForCalcColor()); badForCalc.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { KdxPreference<Color> pref = TrialManagerPreferences.BAD_FOR_CALC; String title = pref.getName(); KdxplorePreferenceEditor.startEditorDialog(TraitExplorerPanel.this, title, pref); } } }); traitsTable.setAutoCreateRowSorter(true); int index = traitTableModel.getTraitNameColumnIndex(); if (index >= 0) { traitsTable.getColumnModel().getColumn(index).setCellRenderer(traitNameCellRenderer); } traitsTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e) && 2 == e.getClickCount()) { e.consume(); int vrow = traitsTable.rowAtPoint(e.getPoint()); if (vrow >= 0) { int mrow = traitsTable.convertRowIndexToModel(vrow); if (mrow >= 0) { Trait trait = traitTableModel.getTraitAtRow(mrow); Integer selectViewRow = null; if (!traitTrialsTableModel.isSelectedTrait(trait)) { selectViewRow = vrow; } if (traitsEditable) { startEditingTraitInternal(trait, selectViewRow, null); } else { warnEditingLocked(); } } } } } }); traitsTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); traitsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { List<Trait> selectedTraits = getSelectedTraits(); traitTrialsTableModel.setSelectedTraits(selectedTraits); if (selectedTraits.size() == 1) { Trait trait = null; int vrow = traitsTable.getSelectedRow(); if (vrow >= 0) { int mrow = traitsTable.convertRowIndexToModel(vrow); if (mrow >= 0) { trait = traitTableModel.getEntityAt(mrow); } } showTraitDetails(trait); } deleteTraitsAction.setEnabled(selectedTraits.size() > 0); showCorrectCard(); } } }); TraitTableModel.initValidationExpressionRenderer(traitsTable); if (RunMode.getRunMode().isDeveloper()) { TraitTableModel.initTableForRawExpression(traitsTable); } cardPanel.add(noTraitsComponent, CARD_NO_TRAITS); cardPanel.add(selectTraitComponent, CARD_SELECT_TO_EDIT); cardPanel.add(new JScrollPane(traitPropertiesTable), CARD_TRAIT_EDITOR); JButton undoButton = initAction(undoAction, ImageId.UNDO_24, "Undo", KeyStroke.getKeyStroke('Z', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); JButton redoButton = initAction(redoAction, ImageId.REDO_24, "Redo", KeyStroke.getKeyStroke('Y', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); Box undoRedoButtons = Box.createHorizontalBox(); undoRedoButtons.add(undoButton); undoRedoButtons.add(redoButton); JPanel detailsPanel = new JPanel(new BorderLayout()); detailsPanel.add(GuiUtil.createLabelSeparator("Details", undoRedoButtons), BorderLayout.NORTH); detailsPanel.add(cardPanel, BorderLayout.CENTER); detailsPanel.add(legendPanel, BorderLayout.SOUTH); PromptScrollPane scrollPane = new PromptScrollPane(traitsTable, "Drag/Drop Traits CSV file or use 'Import Traits'"); TableTransferHandler tth = TableTransferHandler.initialiseForCopySelectAll(traitsTable, true); traitsTable.setTransferHandler(new ChainingTransferHandler(flth, tth)); scrollPane.setTransferHandler(flth); if (addBarcodeIcon == null) { barcodesMenuAction.putValue(Action.NAME, "Barcodes..."); } else { barcodesMenuAction.putValue(Action.SMALL_ICON, addBarcodeIcon); } italicsForProtectedCheckbox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { traitNameCellRenderer.setUseItalicsForProtected(italicsForProtectedCheckbox.isSelected()); traitsTable.repaint(); } }); Box leftTopControls = Box.createHorizontalBox(); leftTopControls.add(importTraitsButton); leftTopControls.add(barcodesMenuButton); leftTopControls.add(new JButton(addNewTraitAction)); leftTopControls.add(new JButton(uploadTraitsAction)); leftTopControls.add(new JButton(exportTraitsAction)); leftTopControls.add(Box.createHorizontalGlue()); leftTopControls.add(editingLocked); leftTopControls.add(fixTraitLevelsButton); leftTopControls.add(refreshButton); leftTopControls.add(Box.createHorizontalStrut(8)); leftTopControls.add(new JButton(deleteTraitsAction)); // leftTopControls.add(Box.createHorizontalStrut(4)); Box explanations = Box.createHorizontalBox(); explanations.add(italicsForProtectedCheckbox); explanations.add(badForCalc); explanations.add(Box.createHorizontalGlue()); fixTraitLevelsButton.setToolTipText("Fix Traits with " + TraitLevel.UNDECIDABLE.visible + " 'Level'"); fixTraitLevelsButton.setVisible(false); JPanel leftTop = new JPanel(new BorderLayout()); leftTop.add(leftTopControls, BorderLayout.NORTH); leftTop.add(scrollPane, BorderLayout.CENTER); leftTop.add(explanations, BorderLayout.SOUTH); JPanel leftBot = new JPanel(new BorderLayout()); leftBot.add(GuiUtil.createLabelSeparator("Used by Trials"), BorderLayout.NORTH); leftBot.add(new PromptScrollPane(traitTrialsTable, "Any Trials using selected Traits appear here")); JSplitPane leftSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, leftTop, leftBot); leftSplit.setResizeWeight(0.5); splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftSplit, detailsPanel); splitPane.setOneTouchExpandable(true); splitPane.setResizeWeight(0.5); add(splitPane, BorderLayout.CENTER); }
From source file:com.vgi.mafscaling.LogView.java
private void createGraghPanel() { JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false);/*from ww w . j a v a2 s. com*/ chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); chartPanel.setPopupMenu(null); chart.setBackgroundPaint(new Color(60, 60, 65)); rpmDataset = new XYSeriesCollection(); rpmPlotRenderer = new XYLineAndShapeRenderer(); dataset = new XYSeriesCollection(); plotRenderer = new XYLineAndShapeRenderer(); NumberAxis xAxis = new NumberAxis(); xAxis.setTickLabelsVisible(false); xAxis.setTickLabelPaint(Color.WHITE); xAxis.setAutoRangeIncludesZero(false); NumberAxis yAxis = new NumberAxis(); yAxis.setTickLabelsVisible(false); yAxis.setTickLabelPaint(Color.WHITE); yAxis.setAutoRangeIncludesZero(false); NumberAxis y2Axis = new NumberAxis(); y2Axis.setTickLabelsVisible(false); y2Axis.setTickLabelPaint(Color.WHITE); y2Axis.setAutoRangeIncludesZero(false); plot = chartPanel.getChart().getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.LIGHT_GRAY); plot.setRangeGridlinePaint(Color.LIGHT_GRAY); plot.setBackgroundPaint(new Color(80, 80, 85)); plot.setDataset(0, rpmDataset); plot.setRenderer(0, rpmPlotRenderer); plot.setDomainAxis(0, xAxis); plot.setRangeAxis(0, yAxis); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); plot.setDataset(1, dataset); plot.setRenderer(1, plotRenderer); plot.setRangeAxis(1, y2Axis); plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 1); LegendTitle legend = new LegendTitle(plot); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); legend.setItemPaint(Color.WHITE); chart.addLegend(legend); xyMarker = new XYDomainMutilineAnnotation(); plot.addAnnotation(xyMarker); chartMouseListener = new ChartMouseListener() { @Override public void chartMouseMoved(ChartMouseEvent event) { try { Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint()); double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge()); boolean isLeft = (p.getX() < (dataArea.getMaxX() - dataArea.getMinX()) / 2) ? true : false; if (setMarkers(x, isLeft)) { try { int selectedCol = logDataTable.getTable().getSelectedColumn(); if (selectedCol < 0) selectedCol = 0; if (logPlayWindow == null || startMarker != null || endMarker != null) { logDataTable.getTable().setRowSelectionInterval((int) x, (int) x); logDataTable.getTable().changeSelection((int) x, selectedCol, false, false); } else { logPlayWindow.setProgressBar((int) x); } } catch (Exception e) { e.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } @Override public void chartMouseClicked(ChartMouseEvent event) { if (logPlayWindow == null) return; if (xyMarker.count() == 0) return; Rectangle2D dataArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea(); Point2D p = chartPanel.translateScreenToJava2D(event.getTrigger().getPoint()); double x = plot.getDomainAxis().java2DToValue(p.getX(), dataArea, plot.getDomainAxisEdge()); if (x < 0 || (int) x >= logDataTable.getRowCount()) return; if (SwingUtilities.isLeftMouseButton(event.getTrigger())) { if (startMarker == null) { startMarker = new ValueMarker(x); startMarker.setPaint(Color.GREEN); startMarker.setStroke(new BasicStroke(1.5f)); plot.addDomainMarker(startMarker); } else { plot.removeDomainMarker(startMarker); startMarker = null; } } else if (SwingUtilities.isRightMouseButton(event.getTrigger())) { if (endMarker == null) { endMarker = new ValueMarker(x); endMarker.setPaint(Color.GREEN); endMarker.setStroke(new BasicStroke(1.5f)); plot.addDomainMarker(endMarker); } else { plot.removeDomainMarker(endMarker); endMarker = null; } } chartPanel.repaint(); logPlayWindow.setStartEndArea(startMarker, endMarker); } }; chartPanel.addChartMouseListener(chartMouseListener); }
From source file:com.t3.client.ui.T3Frame.java
private JComponent createTokenTreePanel() { final JTree tree = new JTree(); tokenPanelTreeModel = new TokenPanelTreeModel(tree); tree.setModel(tokenPanelTreeModel);/*w ww . j a v a 2 s .c o m*/ tree.setCellRenderer(new TokenPanelTreeCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); tree.addMouseListener(new MouseAdapter() { // TODO: Make this a handler class, not an aic @Override public void mousePressed(MouseEvent e) { // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY())); TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } Object row = path.getLastPathComponent(); int rowIndex = tree.getRowForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e)) { if (!SwingUtil.isShiftDown(e)) { tree.clearSelection(); } tree.addSelectionInterval(rowIndex, rowIndex); if (row instanceof Token) { if (e.getClickCount() == 2) { Token token = (Token) row; getCurrentZoneRenderer().clearSelectedTokens(); getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY())); // Pick an appropriate tool getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class); getCurrentZoneRenderer().setActiveLayer(token.getLayer()); getCurrentZoneRenderer().selectToken(token.getId()); getCurrentZoneRenderer().requestFocusInWindow(); } } } if (SwingUtilities.isRightMouseButton(e)) { if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) { tree.clearSelection(); tree.addSelectionInterval(rowIndex, rowIndex); } final int x = e.getX(); final int y = e.getY(); EventQueue.invokeLater(new Runnable() { @Override public void run() { Token firstToken = null; Set<GUID> selectedTokenSet = new HashSet<GUID>(); for (TreePath path : tree.getSelectionPaths()) { if (path.getLastPathComponent() instanceof Token) { Token token = (Token) path.getLastPathComponent(); if (firstToken == null) { firstToken = token; } if (AppUtil.playerOwns(token)) { selectedTokenSet.add(token.getId()); } } } if (!selectedTokenSet.isEmpty()) { try { if (firstToken.isStamp()) { new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(), firstToken).showPopup(tree); } else { new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(), firstToken).showPopup(tree); } } catch (IllegalComponentStateException icse) { log.info(tree.toString(), icse); } } } }); } } }); TabletopTool.getEventDispatcher().addListener(new AppEventListener() { @Override public void handleAppEvent(AppEvent event) { tokenPanelTreeModel.setZone((Zone) event.getNewValue()); } }, TabletopTool.ZoneEvent.Activated); return tree; }
From source file:velocitekProStartAnalyzer.MainWindow.java
private void createChartPanel() { XYSeriesCollection dataset = JDBCPointDao.dataSet; JFreeChart chart = createChart(dataset); ChartPanel chartPanel = new ChartPanel(chart, true, false, false, true, false); chartPanel.setMinimumDrawWidth(0);//from w ww .j a v a 2s . c om chartPanel.setMinimumDrawHeight(0); chartPanel.setMaximumDrawWidth(1920); chartPanel.setMaximumDrawHeight(1200); chartPanel.getPopupMenu().addSeparator(); chartPanel.getPopupMenu().add(btnAvgSpeedChart); chartPanel.getPopupMenu().add(btnMedianSpeedChart); chartPanel.getPopupMenu().add(btnResetSpeedChart); chartPanel.getPopupMenu().addSeparator(); btnMenuSaveSubmenuForChart = new JMenu("Save"); chartPanel.getPopupMenu().add(btnMenuSaveSubmenuForChart); if (JDBCPointDao.points.isEmpty()) { btnSaveAsVCC.setEnabled(false); } saveChartAsPng(chartPanel); btnMenuSaveSubmenuForChart.add(btnSaveChartAsPngForChart); btnMenuSaveSubmenuForChart.add(btnSaveTableAsPngForChart); btnMenuSaveSubmenuForChart.add(btnSaveMapAsPngForChart); btnMenuSaveSubmenuForChart.addSeparator(); btnMenuSaveSubmenuForChart.add(btnSaveAsVCC); chartPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); // make the crosshairs disappear if the mouse is out of range if (!xAxis.getRange().contains(x)) { x = Double.NaN; } x = Math.round(x); if (SwingUtilities.isLeftMouseButton(event.getTrigger()) && event.getTrigger().isShiftDown()) { for (PointDto cord : JDBCPointDao.points) { { if (cord.getPointID() == x) { if (pointTable.getSelectionModel() == null) { for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.setRowSelectionInterval(i, i); } } } else { for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.addRowSelectionInterval(pointTable.getSelectedRow(), i); } } } pointTable.scrollRectToVisible( pointTable.getCellRect(pointTable.getSelectedRow(), 0, true)); } } } } else { for (PointDto cord : JDBCPointDao.points) { { if (cord.getPointID() == x) { if (pointTable.getSelectionModel() != null) { pointTable.getSelectionModel().clearSelection(); } for (int i = 0; i < pointTable.getModel().getRowCount(); i++) { if (pointTable.getModel().getValueAt(i, 0).equals(cord.getPointID())) { pointTable.setRowSelectionInterval(i, i); } } pointTable.scrollRectToVisible( pointTable.getCellRect(pointTable.getSelectedRow(), 0, true)); //MainWindow.pointTable.revalidate(); } } } } } @Override public void chartMouseMoved(ChartMouseEvent event) { Rectangle2D dataArea = chartPanel.getScreenDataArea(); JFreeChart chart = event.getChart(); XYPlot plot = (XYPlot) chart.getPlot(); ValueAxis xAxis = plot.getDomainAxis(); double x = xAxis.java2DToValue(event.getTrigger().getX(), dataArea, RectangleEdge.BOTTOM); // make the crosshairs disappear if the mouse is out of range if (!xAxis.getRange().contains(x)) { x = Double.NaN; } double y = DatasetUtilities.findYValue(plot.getDataset(), 0, x); xCrosshair.setValue(x); yCrosshair.setValue(y); x = Math.round(x); for (PointDto cord : JDBCPointDao.points) { if (cord.getPointID() == x) { mapPanel.map().removeMapMarker(mapPanel.getMapPoint()); mapPanel.setMapPoint( new MapMarkerDot(null, null, cord.getPointLatidude(), cord.getPointLongtidude())); mapPanel.setMapPoint(mapPanel.getMapPoint()); mapPanel.getMapPoint().setColor(colorMapMarkerCircle); mapPanel.getMapPoint().setBackColor(colorMapMarkerHover); mapPanel.map().addMapMarker(mapPanel.getMapPoint()); } } } }); XYPlot xyPlot = (XYPlot) chart.getPlot(); ValueAxis rangeAxis = xyPlot.getRangeAxis(); NavigableMap<Double, PointDto> pointDtoSortedSpeedMap = new TreeMap<Double, PointDto>(); if (!JDBCPointDao.points.isEmpty()) { for (PointDto pointDto : JDBCPointDao.points) { pointDtoSortedSpeedMap.put(pointDto.getPointSpeed(), pointDto); } rangeAxis.setRange(pointDtoSortedSpeedMap.firstEntry().getKey() - 0.1, pointDtoSortedSpeedMap.lastEntry().getKey() + 0.1); } CrosshairOverlay crosshairOverlay = new CrosshairOverlay(); xCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); xCrosshair.setLabelVisible(true); yCrosshair = new Crosshair(Double.NaN, Color.GRAY, new BasicStroke(0f)); yCrosshair.setLabelVisible(true); crosshairOverlay.addDomainCrosshair(xCrosshair); crosshairOverlay.addRangeCrosshair(yCrosshair); chartPanel.addOverlay(crosshairOverlay); graphPanel.removeAll(); graphPanel.add(chartPanel, BorderLayout.CENTER); graphPanel.revalidate(); graphPanel.repaint(); graphMapSplitPanel.revalidate(); }
From source file:net.rptools.maptool.client.ui.MapToolFrame.java
private JComponent createDrawTreePanel() { final JTree tree = new JTree(); drawablesPanel = new DrawablesPanel(); drawPanelTreeModel = new DrawPanelTreeModel(tree); tree.setModel(drawPanelTreeModel);/*from w w w .j ava 2 s . c om*/ tree.setCellRenderer(new DrawPanelTreeCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setContinuousLayout(true); splitPane.setTopComponent(new JScrollPane(tree)); splitPane.setBottomComponent(drawablesPanel); splitPane.setDividerLocation(100); // Add mouse Event for right click menu tree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } Object row = path.getLastPathComponent(); int rowIndex = tree.getRowForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e)) { if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) { tree.clearSelection(); } tree.addSelectionInterval(rowIndex, rowIndex); if (row instanceof DrawnElement) { if (e.getClickCount() == 2) { DrawnElement de = (DrawnElement) row; getCurrentZoneRenderer() .centerOn(new ZonePoint((int) de.getDrawable().getBounds().getCenterX(), (int) de.getDrawable().getBounds().getCenterY())); } } int[] treeRows = tree.getSelectionRows(); java.util.Arrays.sort(treeRows); drawablesPanel.clearSelectedIds(); for (int i = 0; i < treeRows.length; i++) { TreePath p = tree.getPathForRow(treeRows[i]); if (p.getLastPathComponent() instanceof DrawnElement) { DrawnElement de = (DrawnElement) p.getLastPathComponent(); drawablesPanel.addSelectedId(de.getDrawable().getId()); } } } if (SwingUtilities.isRightMouseButton(e)) { if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) { tree.clearSelection(); tree.addSelectionInterval(rowIndex, rowIndex); drawablesPanel.clearSelectedIds(); } final int x = e.getX(); final int y = e.getY(); EventQueue.invokeLater(new Runnable() { public void run() { DrawnElement firstElement = null; Set<GUID> selectedDrawSet = new HashSet<GUID>(); for (TreePath path : tree.getSelectionPaths()) { if (path.getLastPathComponent() instanceof DrawnElement) { DrawnElement de = (DrawnElement) path.getLastPathComponent(); if (firstElement == null) { firstElement = de; } selectedDrawSet.add(de.getDrawable().getId()); } } if (!selectedDrawSet.isEmpty()) { try { new DrawPanelPopupMenu(selectedDrawSet, x, y, getCurrentZoneRenderer(), firstElement).showPopup(tree); } catch (IllegalComponentStateException icse) { log.info(tree.toString(), icse); } } } }); } } }); // Add Zone Change event MapTool.getEventDispatcher().addListener(new AppEventListener() { public void handleAppEvent(AppEvent event) { drawPanelTreeModel.setZone((Zone) event.getNewValue()); } }, MapTool.ZoneEvent.Activated); return splitPane; }
From source file:io.heming.accountbook.ui.MainFrame.java
private void initTablePopupMenu() { JPopupMenu popupMenu = new JPopupMenu(); JMenuItem deleteMenuItem = new JMenuItem("(D)", new ImageIcon(getClass().getResource("edit-delete-6.png"))); deleteMenuItem.setMnemonic('D'); popupMenu.add(deleteMenuItem);/* w w w .jav a 2s .c o m*/ deleteMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { deleteRecord(); } }); popupMenu.addSeparator(); JMenuItem editMenuItem = new JMenuItem("(E)", new ImageIcon(getClass().getResource("edit-4.png"))); editMenuItem.setMnemonic('E'); popupMenu.add(editMenuItem); editMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Record record = model.getRecord(table.convertRowIndexToModel(table.getSelectedRow())); showUpdateRecordDialog(record); } }); // ??popup menu table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (disable) return; JTable table = (JTable) e.getSource(); Point point = e.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(e.getPoint()); if (SwingUtilities.isRightMouseButton(e)) { if (row >= 0 && col >= 0) { table.setRowSelectionInterval(row, row); } popupMenu.show(e.getComponent(), e.getX(), e.getY()); } else if (SwingUtilities.isLeftMouseButton(e)) { if (e.getClickCount() == 2) { if (row >= 0 && col >= 0) { // Record record = model.getRecord(table.convertRowIndexToModel(row)); // showUpdateRecordDialog(record); } } } } }); table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter"); table.getActionMap().put("Enter", new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { if (disable) return; //do something on JTable enter pressed int row = table.getSelectedRow(); if (row >= 0) { Record record = model.getRecord(table.convertRowIndexToModel(row)); showUpdateRecordDialog(record); } } }); }
From source file:net.rptools.maptool.client.ui.MapToolFrame.java
private JComponent createTokenTreePanel() { final JTree tree = new JTree(); tokenPanelTreeModel = new TokenPanelTreeModel(tree); tree.setModel(tokenPanelTreeModel);/* w w w.j av a2 s . c o m*/ tree.setCellRenderer(new TokenPanelTreeCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); tree.addMouseListener(new MouseAdapter() { // TODO: Make this a handler class, not an aic @Override public void mousePressed(MouseEvent e) { // tree.setSelectionPath(tree.getPathForLocation(e.getX(), e.getY())); TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } Object row = path.getLastPathComponent(); int rowIndex = tree.getRowForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e)) { if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) { tree.clearSelection(); } tree.addSelectionInterval(rowIndex, rowIndex); if (row instanceof Token) { if (e.getClickCount() == 2) { Token token = (Token) row; getCurrentZoneRenderer().clearSelectedTokens(); getCurrentZoneRenderer().centerOn(new ZonePoint(token.getX(), token.getY())); // Pick an appropriate tool getToolbox().setSelectedTool(token.isToken() ? PointerTool.class : StampTool.class); getCurrentZoneRenderer().setActiveLayer(token.getLayer()); getCurrentZoneRenderer().selectToken(token.getId()); getCurrentZoneRenderer().requestFocusInWindow(); } } } if (SwingUtilities.isRightMouseButton(e)) { if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) { tree.clearSelection(); tree.addSelectionInterval(rowIndex, rowIndex); } final int x = e.getX(); final int y = e.getY(); EventQueue.invokeLater(new Runnable() { public void run() { Token firstToken = null; Set<GUID> selectedTokenSet = new HashSet<GUID>(); for (TreePath path : tree.getSelectionPaths()) { if (path.getLastPathComponent() instanceof Token) { Token token = (Token) path.getLastPathComponent(); if (firstToken == null) { firstToken = token; } if (AppUtil.playerOwns(token)) { selectedTokenSet.add(token.getId()); } } } if (!selectedTokenSet.isEmpty()) { try { if (firstToken.isStamp()) { new StampPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(), firstToken).showPopup(tree); } else { new TokenPopupMenu(selectedTokenSet, x, y, getCurrentZoneRenderer(), firstToken).showPopup(tree); } } catch (IllegalComponentStateException icse) { log.info(tree.toString(), icse); } } } }); } } }); MapTool.getEventDispatcher().addListener(new AppEventListener() { public void handleAppEvent(AppEvent event) { tokenPanelTreeModel.setZone((Zone) event.getNewValue()); } }, MapTool.ZoneEvent.Activated); return tree; }
From source file:Classes.MainForm.java
public void initTray() throws IOException { MainForm.trayIcon = null;/* w ww . ja va 2 s . co m*/ this.systemTray = SystemTray.getSystemTray(); ActionListener actionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { MainForm.trayIcon .displayMessage(PropertiesHandler.getSingleton().getValue(1061), PropertiesHandler.getSingleton().getValue(1098) + " " + PropertiesHandler.getSingleton().getValue(1099), TrayIcon.MessageType.INFO); } catch (Exception e1) { } } }; MouseListener mouseListener = new MouseListener() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { if (!mainFrame.isVisible()) { mainFrame.setVisible(true); } } } public void mouseEntered(MouseEvent e) { //mouseEntered not supported /* try { MainForm.trayIcon.displayMessage(PropertiesHandler.getSingleton().getValue(1061), PropertiesHandler.getSingleton().getValue(1098)+" "+PropertiesHandler.getSingleton().getValue(1099),TrayIcon.MessageType.INFO); } catch (Exception e1) {} */ } public void mouseExited(MouseEvent e) { }//mouseExited not supported public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent e) { } }; MainForm.trayIcon = new TrayIcon(trayIconIcon, PropertiesHandler.getSingleton().getValue(1061), popupMenu);//create tray icon MainForm.trayIcon.setImageAutoSize(true); MainForm.trayIcon.addActionListener(actionListener); MainForm.trayIcon.addMouseListener(mouseListener); try { systemTray.add(MainForm.trayIcon); MainForm.trayIcon.displayMessage(PropertiesHandler.getSingleton().getValue(1061), PropertiesHandler.getSingleton().getValue(1098) + " " + PropertiesHandler.getSingleton().getValue(1099), TrayIcon.MessageType.INFO); } catch (Exception e1) { } }