/** Create and display the context menu */ private void displayContextMenu() { ContextMenu menu = ScilabContextMenu.createContextMenu(); ModifyAction modify = new ModifyAction(SwingScilabVariableBrowser.this); menu.add(modify.createMenuItem()); DeleteAction delete = new DeleteAction(SwingScilabVariableBrowser.this); menu.add(delete.createMenuItem()); ExportToCsvAction csvExport = new ExportToCsvAction( (SwingScilabTab) SwingScilabVariableBrowser.this, UiDataMessages.EXPORTCSV); menu.add(csvExport.createMenuItem(SwingScilabVariableBrowser.this, UiDataMessages.EXPORTCSV)); Menu menuPlot = ScilabMenu.createMenu(); menuPlot.setText(UiDataMessages.PLOTALL); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "plot2d", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "Matplot", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "grayplot", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "Sgrayplot", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "champ", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "histplot", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "mesh", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "surf", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "hist3d", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "contour2d", false)); menuPlot.add( PlotAction.createMenuItem( (SwingScilabTab) SwingScilabVariableBrowser.this, "pie", false)); menu.add(menuPlot); menu.setVisible(true); ((SwingScilabContextMenu) menu.getAsSimpleContextMenu()) .setLocation( MouseInfo.getPointerInfo().getLocation().x, MouseInfo.getPointerInfo().getLocation().y); }
/** * Create a JTable with data Model. * * @param columnsName : Titles of JTable columns. */ public SwingScilabVariableBrowser(String[] columnsName, int[] aligment) { super(UiDataMessages.VARIABLE_BROWSER, VARBROWSERUUID); setAssociatedXMLIDForHelp("browsevar"); buildMenuBar(); addMenuBar(menuBar); ToolBar toolBar = ScilabToolBar.createToolBar(); toolBar.add(RefreshAction.createButton(UiDataMessages.REFRESH)); toolBar.addSeparator(); toolBar.add(ModifyAction.createButton(this, UiDataMessages.MODIFY)); toolBar.add(DeleteAction.createButton(this, UiDataMessages.DELETE)); toolBar.addSeparator(); toolBar.add(HelpAction.createButton(UiDataMessages.HELP)); filteringButton = ScilabVarFilteringButtonAction.createButton("Show/hide Scilab variable"); // toolBar.add(filteringButton); addToolBar(toolBar); dataModel = new SwingTableModel<Object>(columnsName); table = new JTable(dataModel) { // Implement table cell tool tips. public String getToolTipText(MouseEvent e) { String tip = null; TableModel model = ((JTable) e.getSource()).getModel(); java.awt.Point p = e.getPoint(); int rowIndex = rowAtPoint(p); if (rowIndex >= 0) { rowIndex = convertRowIndexToModel(rowIndex); int colIndex = columnAtPoint(p); if (colIndex == BrowseVar.TYPE_DESC_COLUMN_INDEX) { /* Scilab type */ try { tip = Messages.gettext("Scilab type:") + " " + model.getValueAt(rowIndex, BrowseVar.TYPE_COLUMN_INDEX).toString(); } catch (IllegalArgumentException exception) { /* If the type is not known/managed, don't crash */ } } else { if (colIndex == BrowseVar.SIZE_COLUMN_INDEX) { /* Use the getModel() method because the * column 5 has been removed from display * but still exist in the model */ tip = Messages.gettext("Bytes:") + " " + model.getValueAt(rowIndex, BrowseVar.BYTES_COLUMN_INDEX).toString(); } } } return tip; } }; table.setFillsViewportHeight(true); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); table.setAutoCreateRowSorter(true); /* Size of the icon column */ table.getColumnModel().getColumn(0).setPreferredWidth(30); /* Hide the columns. But keep it in memory for the tooltip */ TableColumn column = table.getColumnModel().getColumn(BrowseVar.NB_COLS_INDEX); table.removeColumn(column); /* The order to removing does matter since it changes the positions */ column = table.getColumnModel().getColumn(BrowseVar.NB_ROWS_INDEX); table.removeColumn(column); column = table.getColumnModel().getColumn(BrowseVar.TYPE_COLUMN_INDEX); table.removeColumn(column); column = table.getColumnModel().getColumn(BrowseVar.FROM_SCILAB_COLUMN_INDEX); table.removeColumn(column); column = table.getColumnModel().getColumn(BrowseVar.BYTES_COLUMN_INDEX); table.removeColumn(column); table.addMouseListener(new BrowseVarMouseListener()); // Mouse selection mode table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(true); table.setBackground(Color.WHITE); if (table.getGridColor().equals(Color.WHITE)) { table.setGridColor(new Color(128, 128, 128)); } table.setShowHorizontalLines(true); table.setShowVerticalLines(true); for (int i = 0; i < aligment.length; i++) { align(table, columnsName[i], aligment[i]); } // Plug the shortcuts ExportToCsvAction.registerAction(this, table); JScrollPane scrollPane = new JScrollPane(table); setContentPane(scrollPane); WindowsConfigurationManager.restorationFinished(this); }