List of usage examples for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION
int MULTIPLE_INTERVAL_SELECTION
To view the source code for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.
Click Source Link
From source file:com.vgi.mafscaling.OpenLoop.java
private void createRunTables(JPanel dataRunPanel) { GridBagConstraints gbc_run = new GridBagConstraints(); gbc_run.anchor = GridBagConstraints.PAGE_START; gbc_run.insets = new Insets(0, 2, 0, 2); for (int i = 0; i < RunCount; ++i) { runTables[i] = new JTable(); JTable table = runTables[i]; table.getTableHeader().setReorderingAllowed(false); table.setModel(new DefaultTableModel(RunRowsCount, 3)); table.setColumnSelectionAllowed(true); table.setCellSelectionEnabled(true); table.setBorder(new LineBorder(new Color(0, 0, 0))); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getColumnModel().getColumn(0) .setHeaderValue("<html><center>Engine<br>Speed<br>(RPM)<br></center></html>"); table.getColumnModel().getColumn(1) .setHeaderValue("<html><center>MAF<br>Sensor<br>Voltage<br></center></html>"); table.getColumnModel().getColumn(2) .setHeaderValue("<html><center>AFR<br>Error<br>%<br></center></html>"); Utils.initializeTable(table, ColumnWidth); excelAdapter.addTable(table, true, false); gbc_run.gridx = i;//from w ww . j a v a2 s. c o m gbc_run.gridy = 0; dataRunPanel.add(table.getTableHeader(), gbc_run); gbc_run.gridy = 1; dataRunPanel.add(table, gbc_run); } }
From source file:com.diversityarrays.kdxplore.curate.CurationCellEditorImpl.java
public CurationCellEditorImpl(CurationTableModel curationTableModel, FieldLayoutView fieldViewLayoutPanel, CurationData curationData, Closure<Void> refresh, KdxploreDatabase kdxdb, IntFunction<Trait> traitProvider, SampleType[] sampleTypes) throws IOException { super();/*from ww w . j a v a 2 s . c o m*/ this.fieldViewLayoutPanel = fieldViewLayoutPanel; this.refreshFieldLayoutView = refresh; this.curationData = curationData; this.curationTableModel = curationTableModel; sampleEntryPanel = new SampleEntryPanel(curationData, traitProvider, typedSampleTableModel, typedSampleTable, tsmCellRenderer, showPpiOption, refreshFieldLayoutView, changedValueConsumer, sampleTypes); typedSampleTableModel.setCurationData(curationData); for (DeviceIdentifier did : kdxdb.getDeviceIdentifiers()) { devIdentifierById.put(did.getDeviceIdentifierId(), did); } typedSampleTableModel.setShowSampleType(sampleTypes.length > 0); typedSampleTable.setRowHeight(typedSampleTable.getRowHeight() * 2); typedSampleTable.setAutoCreateRowSorter(true); typedSampleTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); typedSampleTable.getSelectionModel().addListSelectionListener(typedSampleListSelectionListener); typedSampleTable.setDefaultRenderer(String.class, new CurationCellRenderer(typedSampleTableModel)); typedSampleTable.setDefaultRenderer(java.util.Date.class, dateCellRenderer); typedSampleTable.setDefaultRenderer(TypedSampleMeasurement.class, tsmCellRenderer); GuiUtil.setVisibleRowCount(typedSampleTable, 5); // typedSampleTable.setDefaultRenderer(Integer.class, new NumberCellRenderer(null, SwingConstants.CENTER)); // typedSampleTable.setDefaultRenderer(String.class, new CurationCellRenderer()); // typedSampleTable.setDefaultRenderer(Double.class, new CurationCellRenderer()); // typedSampleTable.setDefaultRenderer(Object.class, new CurationCellRenderer()); // typedSampleTable.setDefaultRenderer(String.class, new CurationCellRenderer()); // typedSampleTable.setDefaultRenderer(Integer.class, new CurationCellRenderer()); showPpiOption.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { typedSampleTableModel.setShowPositions(showPpiOption.isSelected()); } }); GBH gbh = new GBH(this); int y = 0; gbh.add(0, y, 1, 1, GBH.HORZ, 1, 1, GBH.CENTER, GuiUtil.createLabelSeparator(Vocab.TITLE_SAMPLE_VALUES(), showPpiOption)); ++y; gbh.add(0, y, 1, 1, GBH.BOTH, 2, 3, GBH.CENTER, new PromptScrollPane(typedSampleTable, "No Samples")); ++y; gbh.add(0, y, 1, 1, GBH.BOTH, 1, 1, GBH.CENTER, sampleEntryPanel); ++y; }
From source file:jgnash.ui.commodity.SecuritiesHistoryDialog.java
private void initComponents() { dateField = new DatePanel(); closeField = new JFloatField(); lowField = new JFloatField(); highField = new JFloatField(); securityCombo = new SecurityComboBox(); volumeField = new JIntegerField(); updateButton = new JButton(rb.getString("Button.UpdateOnline"), IconUtils.getIcon("/jgnash/resource/applications-internet.png")); deleteButton = new JButton(rb.getString("Button.Delete")); clearButton = new JButton(rb.getString("Button.Clear")); applyButton = new JButton(rb.getString("Button.Add")); closeButton = new JButton(rb.getString("Button.Close")); model = new HistoryModel(); table = new HistoryTable(); table.setModel(model);//from w w w . j a v a 2 s .c o m table.setPreferredScrollableViewportSize(new Dimension(150, 120)); table.setCellSelectionEnabled(false); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setRowSorter(new TableRowSorter<>(model)); table.setFillsViewportHeight(true); // create an empty chart for panel construction chartPanel = new ChartPanel(new JFreeChart(new XYPlot())); chartPanel.setPreferredSize(new Dimension(150, 90)); applyButton.addActionListener(this); clearButton.addActionListener(this); deleteButton.addActionListener(this); updateButton.addActionListener(this); securityCombo.addActionListener(this); closeButton.addActionListener(this); }
From source file:com.hp.alm.ali.idea.ui.MultipleItemsDialog.java
public MultipleItemsDialog(Project project, String title, final MultipleItemsDialogModel<K, E> model) { super(project, title, true); this.model = model; mySelectionModel = new MySelectionModel(); myListSelectionListener = new MyListSelectionListener(); tooMany = new JLabel("Too many results, narrow your search"); tooMany.setBorder(BorderFactory.createEtchedBorder()); tooMany.setVisible(false);/*w w w. ja va2s. c o m*/ selected = new JLabel("Showing currently selected items"); selected.setVisible(false); toggleSelected = new JToggleButton(); toggleSelected.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { model.setShowingSelected(toggleSelected.isSelected()); if (!model.isShowingSelected() && !model.getSelectedFields().isEmpty()) { updateSelectionFromModel(); } else if (model.isShowingSelected()) { header.getFilterEditor(1).setContent(""); } } }); updateSelected(); table = new JBTable() { @Override public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) { int column = convertColumnIndexToModel(columnIndex); mySelectionModel.setFirstColumnEvent(column == 0); super.changeSelection(rowIndex, columnIndex, toggle, extend); } }; table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(false); table.setAutoCreateColumnsFromModel(false); table.setModel(model); final MyTableRowSorter sorter = new MyTableRowSorter(model); table.setRowSorter(sorter); table.setDefaultRenderer(Boolean.class, new MyRenderer()); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); table.setSelectionModel(mySelectionModel); sorter.setIgnoreAddRowSorterListener(true); // prevent auto-selection (functionality not accessible via proper API) header = new TableFilterHeader(table); sorter.setIgnoreAddRowSorterListener(false); sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(1, SortOrder.ASCENDING))); JPanel panel = new JPanel(new BorderLayout()); JPanel toolbar = new JPanel(new BorderLayout()); toolbar.setBorder(BorderFactory.createEtchedBorder()); panel.add(toolbar, BorderLayout.NORTH); toolbar.add(toggleSelected, BorderLayout.EAST); if (model.isMultiple()) { table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getColumnModel().addColumn(createColumn(0, model, 45, 45)); header.getFilterEditor(0).setEditable(false); header.getFilterEditor(0).setUserInteractionEnabled(false); final LinkListener selectUnselect = new LinkListener() { public void linkSelected(LinkLabel aSource, Object aLinkData) { if (model.isShowingSelected()) { if (!Boolean.TRUE.equals(aLinkData)) { List<Integer> ixs = new ArrayList<Integer>(); for (int i = 0; i < sorter.getViewRowCount(); i++) { ixs.add(sorter.convertRowIndexToModel(i)); } // make sure indexes are not affected by removal by starting from the last Collections.sort(ixs); Collections.reverse(ixs); for (int ix : ixs) { model.setValueAt(aLinkData, ix, 0); } } } else { if (Boolean.TRUE.equals(aLinkData)) { mySelectionModel.doAddSelectionInterval(0, table.getRowCount() - 1); } else { mySelectionModel.removeSelectionInterval(0, table.getRowCount() - 1); } } } }; JPanel left = new JPanel(new FlowLayout(FlowLayout.LEFT)); left.add(new LinkLabel("Select All", IconLoader.getIcon("/actions/selectall.png"), selectUnselect, true)); left.add(new LinkLabel("Unselect All", IconLoader.getIcon("/actions/unselectall.png"), selectUnselect, false)); toolbar.add(left, BorderLayout.WEST); } else { table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } table.getColumnModel().addColumn(createColumn(1, model, 450, null)); table.getSelectionModel().addListSelectionListener(myListSelectionListener); model.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { selected.setVisible(model.isShowingSelected()); tooMany.setVisible(model.hasMore() && !model.isShowingSelected()); updateSelected(); } }); JPanel contentPanel = new JPanel(new BorderLayout()); contentPanel.add(selected, BorderLayout.NORTH); contentPanel.add(new JBScrollPane(table), BorderLayout.CENTER); contentPanel.add(tooMany, BorderLayout.SOUTH); panel.add(contentPanel, BorderLayout.CENTER); JPanel buttons = new JPanel(); okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { ok = true; close(true); } }); buttons.add(okButton); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { close(false); } }); buttons.add(cancel); panel.add(buttons, BorderLayout.SOUTH); getContentPane().add(panel, BorderLayout.CENTER); pack(); setResizable(false); centerOnOwner(); requestPropertyFilterFocus(header); load(true, null); }
From source file:com.atlassian.theplugin.idea.jira.IssueCreateDialog.java
public IssueCreateDialog(@NotNull IssueListToolWindowPanel issueListToolWindowPanel, @NotNull Project project, JIRAServerModel model, final JiraServerData jiraServerData, @NotNull final JiraWorkspaceConfiguration jiraProjectCfg, @Nullable JiraIssueAdapter parent) { super(false); this.issueListToolWindowPanel = issueListToolWindowPanel; this.project = project; this.model = model; this.jiraConfiguration = jiraProjectCfg; parentIssue = parent;/*from w ww . j av a2 s . c o m*/ $$$setupUI$$$(); originalEstimate.getDocument() .addDocumentListener(new JiraTimeWdhmTextFieldListener(originalEstimate, true)); assigneeField = new FieldUser(model, jiraServerData, "", null); mainPanel.add(assigneeField, new GridConstraints(10, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, new Dimension(50, -1), new Dimension(150, -1), null, 0, false)); componentsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); init(); pack(); this.jiraServerData = jiraServerData; setTitle(parentIssue == null ? "Create JIRA Issue" : "Create sub-task for issue " + parentIssue.getKey()); projectComboBox.setRenderer(new ColoredListCellRenderer() { @Override protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) { if (value != null) { append(((JIRAProject) value).getName(), SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES); } } }); typeComboBox.setRenderer(new JiraConstantCellRenderer()); typeComboBox.setEnabled(false); priorityComboBox.setRenderer(new JiraConstantCellRenderer()); projectComboBox.addPopupMenuListener(new PopupMenuListener() { private Object item = null; public void popupMenuWillBecomeVisible(PopupMenuEvent popupMenuEvent) { item = projectComboBox.getSelectedItem(); } public void popupMenuWillBecomeInvisible(PopupMenuEvent popupMenuEvent) { if (item != null && item != projectComboBox.getSelectedItem()) { updateProjectRelatedItems(); } } public void popupMenuCanceled(PopupMenuEvent popupMenuEvent) { item = null; } }); createAction.setEnabled(false); createAndOpenAction.setEnabled(false); }
From source file:com.emr.schemas.SchemerMapper.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor./* w ww .jav a 2 s.c om*/ */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); sourceTablesList = new javax.swing.JList<String>(); sourceTablesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); sourceTablesList.setVisibleRowCount(4); jScrollPane2 = new javax.swing.JScrollPane(); txtSelectedTables = new javax.swing.JTextArea(); jLabel2 = new javax.swing.JLabel(); btnClearSel = new javax.swing.JButton(); btnNextScreen = new javax.swing.JButton(); jSeparator2 = new javax.swing.JSeparator(); setClosable(true); setIconifiable(true); setMaximizable(true); setResizable(true); setTitle("Map Schemas"); jLabel1.setText( "<html><b color='blue'>Select Table(s) to copy data from (<i color='green'>Ctrl-Click to select multiple tables</i>)</b></html>"); sourceTablesList.setModel(listModel); jScrollPane1.setViewportView(sourceTablesList); txtSelectedTables.setColumns(20); txtSelectedTables.setRows(5); jScrollPane2.setViewportView(txtSelectedTables); jLabel2.setText("<html><b color='blue'>Selected Tables</b></html>"); btnClearSel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/clear.png"), "")); btnClearSel.setText("Clear Selection"); btnClearSel.setFocusable(false); btnClearSel.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); btnClearSel.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); btnClearSel.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnClearSelActionPerformed(evt); } }); btnNextScreen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/next.png"), "")); btnNextScreen.setText("Next"); btnNextScreen.setFocusable(false); btnNextScreen.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT); btnNextScreen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); btnNextScreen.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnNextScreenActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 29, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jScrollPane1) .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(layout.createSequentialGroup().addGroup(layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup().addContainerGap() .addComponent(btnNextScreen) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(btnClearSel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 1, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnNextScreen, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(btnClearSel, javax.swing.GroupLayout.Alignment.TRAILING)))); pack(); }
From source file:display.containers.FileManager.java
public Container getPane() { //if (gui==null) { fileSystemView = FileSystemView.getFileSystemView(); desktop = Desktop.getDesktop(); JPanel detailView = new JPanel(new BorderLayout(3, 3)); //fileTableModel = new FileTableModel(); table = new JTable(); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setAutoCreateRowSorter(true);/*w w w. jav a 2s . c om*/ table.setShowVerticalLines(false); table.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getClickCount() >= 2) { Point p = e.getPoint(); int row = table.convertRowIndexToModel(table.rowAtPoint(p)); int column = table.convertColumnIndexToModel(table.columnAtPoint(p)); if (row >= 0 && column >= 0) { mouseDblClicked(row, column); } } } }); table.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent arg0) { } @Override public void keyReleased(KeyEvent arg0) { if (KeyEvent.VK_DELETE == arg0.getKeyCode()) { if (mode != 2) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread t = new Thread(new Runnable() { @Override public void run() { try { deleteSelectedFiles(); } catch (IOException e) { JOptionPane.showMessageDialog(parentFrame, "Error during the deletion.", "Deletion error", JOptionPane.ERROR_MESSAGE); WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } finally { parentFrame.setLock(false); refresh(); parentFrame.getProgressBarPanel().setVisible(false); } } }); t.start(); } else { if (UserProfile.CURRENT_USER.getLevel() == 3) { parentFrame.setLock(true); parentFrame.getProgressBarPanel().setVisible(true); Thread delThread = new Thread(new Runnable() { @Override public void run() { int[] rows = table.getSelectedRows(); int[] columns = table.getSelectedColumns(); for (int i = 0; i < rows.length; i++) { if (!continueAction) { continueAction = true; return; } int row = table.convertRowIndexToModel(rows[i]); try { deleteServerFile(row); } catch (Exception e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during the deletion.", e); } } refresh(); parentFrame.setLock(false); parentFrame.getProgressBarPanel().setVisible(false); } }); delThread.start(); } } } } @Override public void keyPressed(KeyEvent arg0) { // TODO Auto-generated method stub } }); table.getSelectionModel().addListSelectionListener(listSelectionListener); JScrollPane tableScroll = new JScrollPane(table); Dimension d = tableScroll.getPreferredSize(); tableScroll.setPreferredSize(new Dimension((int) d.getWidth(), (int) d.getHeight() / 2)); detailView.add(tableScroll, BorderLayout.CENTER); // the File tree DefaultMutableTreeNode root = new DefaultMutableTreeNode(); treeModel = new DefaultTreeModel(root); table.getRowSorter().addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { ((FileTableModel) table.getModel()).fireTableDataChanged(); } }); // show the file system roots. File[] roots = fileSystemView.getRoots(); for (File fileSystemRoot : roots) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(fileSystemRoot); root.add(node); //showChildren(node); // File[] files = fileSystemView.getFiles(fileSystemRoot, true); for (File file : files) { if (file.isDirectory()) { node.add(new DefaultMutableTreeNode(file)); } } // } JScrollPane treeScroll = new JScrollPane(); Dimension preferredSize = treeScroll.getPreferredSize(); Dimension widePreferred = new Dimension(200, (int) preferredSize.getHeight()); treeScroll.setPreferredSize(widePreferred); JPanel fileView = new JPanel(new BorderLayout(3, 3)); detailView.add(fileView, BorderLayout.SOUTH); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, detailView); JPanel simpleOutput = new JPanel(new BorderLayout(3, 3)); progressBar = new JProgressBar(); simpleOutput.add(progressBar, BorderLayout.EAST); progressBar.setVisible(false); showChildren(getCurrentDir().toPath()); //table.setDragEnabled(true); table.setColumnSelectionAllowed(false); // Menu popup Pmenu = new JPopupMenu(); changeProjectitem = new JMenuItem("Reassign"); renameProjectitem = new JMenuItem("Rename"); twitem = new JMenuItem("To workspace"); tlitem = new JMenuItem("To local"); processitem = new JMenuItem("Select for process"); switch (mode) { case 0: Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnlocalTowork().doClick(); } }); break; case 1: Pmenu.add(tlitem); Pmenu.add(processitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtnWorkTolocal().doClick(); } }); processitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { SwingUtilities.invokeLater(new Runnable() { public void run() { // Recupere les lignes selectionnees int[] indices = table.getSelectedRows(); // On recupere les fichiers correspondants ArrayList<File> files = new ArrayList<File>(); for (int i = 0; i < indices.length; i++) { int row = table.convertRowIndexToModel(indices[i]); File fi = ((FileTableModel) table.getModel()).getFile(row); if (fi.isDirectory()) files.add(fi); } ImageProcessingFrame imf = new ImageProcessingFrame(files); } }); } }); break; case 2: if (UserProfile.CURRENT_USER.getLevel() == 3) { Pmenu.add(changeProjectitem); Pmenu.add(renameProjectitem); } Pmenu.add(twitem); twitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToWorkspace().doClick(); } }); Pmenu.add(tlitem); tlitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { parentFrame.getBtndistToLocal().doClick(); } }); break; } changeProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); ReassignProjectPanel reas = new ReassignProjectPanel(from.toPath()); // mode creation de liens Popup popup = PopupFactory.getSharedInstance().getPopup(WindowManager.MAINWINDOW, reas, (int) WindowManager.MAINWINDOW.getX() + 200, (int) WindowManager.MAINWINDOW.getY() + 150); reas.setPopupWindow(popup); popup.show(); table.setEnabled(true); } }); renameProjectitem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { table.setEnabled(false); final File from = ((FileTableModel) table.getModel()) .getFile(table.convertRowIndexToModel(table.getSelectedRows()[0])); JDialog.setDefaultLookAndFeelDecorated(true); String s = (String) JOptionPane.showInputDialog(WindowManager.MAINWINDOW, "New project name ?", "Rename project", JOptionPane.PLAIN_MESSAGE, null, null, from.getName()); //If a string was returned, say so. if ((s != null) && (s.length() > 0)) { ProjectDAO pdao = new MySQLProjectDAO(); if (new File(from.getParent() + File.separator + s).exists()) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (A file with this filename already exists)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + "). [Duplication error]"); } else { try { boolean succeed = pdao.renameProject(from.getName(), s); if (!succeed) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (no project with this name)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); } else { from.renameTo(new File(from.getParent() + File.separator + s)); // on renomme le repertoire nifti ou dicom correspondant si il existe switch (from.getParentFile().getName()) { case ServerInfo.NRI_ANALYSE_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)), Paths.get(from.getParent().replaceAll( ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME) + File.separator + s)); } catch (IOException e) { e.printStackTrace(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_ANALYSE_NAME, ServerInfo.NRI_DICOM_NAME)+File.separator+s)); break; case ServerInfo.NRI_DICOM_NAME: if (new File(from.getAbsolutePath().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)).exists()) try { Files.move(Paths.get(from.getAbsolutePath().replaceAll( ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)), Paths.get(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME) + File.separator + s)); } catch (IOException e) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Couldn't rename " + from.getName() + " (error with file system)", "Renaming error", JOptionPane.ERROR_MESSAGE); } }); e.printStackTrace(); WindowManager.mwLogger.log(Level.SEVERE, "Error during file project renaming (" + from.getName() + ")", e); } //from.renameTo(new File(from.getParent().replaceAll(ServerInfo.NRI_DICOM_NAME, ServerInfo.NRI_ANALYSE_NAME)+File.separator+s)); break; } refresh(); } } catch (final SQLException e) { WindowManager.mwLogger.log(Level.SEVERE, "Error during SQL project renaming", e); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JDialog.setDefaultLookAndFeelDecorated(true); JOptionPane.showMessageDialog(WindowManager.MAINWINDOW, "Exception : " + e.toString(), "Openning error", JOptionPane.ERROR_MESSAGE); } }); } } } table.setEnabled(true); } }); table.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent me) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseReleased(MouseEvent me) { if (me.getButton() == 3 && table.getSelectedRowCount() > 0) { int row = table.convertRowIndexToModel(table.rowAtPoint(me.getPoint())); changeProjectitem.setVisible(isPatient(((FileTableModel) table.getModel()).getFile(row))); renameProjectitem.setVisible(isProject(((FileTableModel) table.getModel()).getFile(row))); Pmenu.show(me.getComponent(), me.getX(), me.getY()); } } }); // //} return tableScroll; }
From source file:de.codesourcery.eve.skills.ui.components.impl.planning.CalendarComponent.java
@Override protected JPanel createPanel() { addEntryButton.setEnabled(false);//from w ww .j a v a 2 s . c o m addEntryButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { addNewCalendarEntry(); } }); calendarWidget.addSelectionListener(new ISelectionListener<Date>() { @Override public void selectionChanged(Date selected) { addEntryButton.setEnabled(selected != null); tableModel.refresh(); } }); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() != 2 || e.isPopupTrigger()) { return; } final int viewRow = table.rowAtPoint(e.getPoint()); if (viewRow != -1) { editCalendarEntry(tableModel.getRow(table.convertRowIndexToModel(viewRow))); } } }); table.setFillsViewportHeight(true); table.setRowSorter(tableModel.getRowSorter()); table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); final PopupMenuBuilder menuBuilder = new PopupMenuBuilder(); menuBuilder.addItem("Remove", new AbstractAction() { @Override public boolean isEnabled() { return !ArrayUtils.isEmpty(table.getSelectedRows()); } @Override public void actionPerformed(ActionEvent e) { final int[] viewRows = table.getSelectedRows(); if (ArrayUtils.isEmpty(viewRows)) { return; } final int[] modelRows = new int[viewRows.length]; int i = 0; for (int viewRow : viewRows) { modelRows[i++] = table.convertRowIndexToModel(viewRow); } final List<ICalendarEntry> removedEntries = new ArrayList<ICalendarEntry>(); for (int modelRow : modelRows) { removedEntries.add(tableModel.getRow(modelRow)); } for (ICalendarEntry toBeRemoved : removedEntries) { calendarManager.getCalendar().deleteEntry(toBeRemoved); } } }); menuBuilder.addItem("Edit...", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { final int modelRow = table.convertRowIndexToModel(table.getSelectedRows()[0]); editCalendarEntry(tableModel.getRow(modelRow)); } @Override public boolean isEnabled() { return !ArrayUtils.isEmpty(table.getSelectedRows()); } }); menuBuilder.attach(table); // controls panel final JPanel controlsPanel = new JPanel(); controlsPanel.setLayout(new GridBagLayout()); controlsPanel.add(addEntryButton, constraints(0, 0).noResizing().end()); // combine panels final JPanel subPanel = new JPanel(); subPanel.setLayout(new GridBagLayout()); subPanel.add(controlsPanel, constraints(0, 0).useRelativeWidth().weightY(0).end()); subPanel.add(new JScrollPane(table), constraints(0, 1).useRelativeWidth().useRemainingHeight().end()); final ImprovedSplitPane splitPane = new ImprovedSplitPane(JSplitPane.HORIZONTAL_SPLIT, calendarWidget, subPanel); splitPane.setDividerLocation(0.7); final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); result.add(splitPane, constraints(0, 0).resizeBoth().end()); return result; }
From source file:zet.gui.assignmentEditor.JAssignmentPanel.java
/** * Adds all components to the panel./* w w w .j a va 2s . com*/ */ private void addComponents() { setLayout(new BorderLayout()); initDistributions(); // Create the main table tablemodel = new AssignmentTableModel(); tablemodel.addTableModelListener(e -> { drawCharts(); }); distributionTable = new JTable(tablemodel); distributionTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); distributionTable.getSelectionModel().addListSelectionListener((ListSelectionEvent e) -> { drawCharts(); }); distributions = new JComboBox<>(); distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.NormalDistribution")); distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.UniformDistribution")); distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.ExponentialDistribution")); distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.ErlangDistribution")); distributions.addItem(loc.getString("gui.AssignmentEditor.Distribution.HyperExponentialDistribution")); distributionTable.getColumnModel().getColumn(COL_DISTRIBUTION) .setCellEditor(new DefaultCellEditor(distributions)); distributionTable.getColumnModel().getColumn(COL_PARAM1).setCellEditor(new SelectingCellEditor()); distributionTable.getColumnModel().getColumn(COL_PARAM2).setCellEditor(new SelectingCellEditor()); distributionTable.getColumnModel().getColumn(COL_PARAM3).setCellEditor(new SelectingCellEditor()); distributionTable.getColumnModel().getColumn(COL_PARAM4).setCellEditor(new SelectingCellEditor()); distributionTable.getColumnModel().getColumn(COL_PARAM3).setCellRenderer(new InactiveRenderer()); distributionTable.getColumnModel().getColumn(COL_PARAM4).setCellRenderer(new InactiveRenderer()); add(getRightPanel(), BorderLayout.CENTER); final JPanel leftPanel = getLeftPanel(); leftPanel.setMaximumSize(new Dimension(200, 0)); add(leftPanel, BorderLayout.WEST); assignmentSelector.displayAssignments(myProject.getProject()); }
From source file:com.emr.schemas.TableRelationsForm.java
/** * Constructor//from w w w. j a v a 2 s . c o m * @param tables {@link List} List of source tables */ public TableRelationsForm(List tables, SchemerMapper parent) { fileManager = null; dbManager = null; emrConn = null; this.parent = parent; this.tables = tables; //source tables //Create KenyaEMR DB connection fileManager = new FileManager(); String[] settings = fileManager.getConnectionSettings("emr_database.properties", "emr"); if (settings == null) { //Connection settings not found JOptionPane.showMessageDialog(null, "Database Settings not found. Please set the connection settings for the database first.", "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE); //Open KenyaEMRConnectionForm form } else { if (settings.length < 1) { JOptionPane.showMessageDialog(null, "Database Settings not found. Please set the connection settings for the database first.", "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE); //Open KenyaEMRConnectionForm form } else { //Connection settings are ok //We establish a connection dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]); emrConn = dbManager.getConnection(); if (emrConn == null) { JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test", JOptionPane.ERROR_MESSAGE); } } } //get all columns and add them to the columns list for (Object table : tables) { String tablename = (String) table; populateTableColumnsToList(tablename); } model = new DefaultTableModel( new Object[] { "Primary Table", "Column", "Reference Table", "Foreign Column" }, 10); initComponents(); this.setClosable(true); foreignTables = tables; combo1 = new JComboBox();//Combobox for the primary tables combo2 = new JComboBox(); combo3 = new JComboBox(); combo4 = new JComboBox(); combo1.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { String selectedTable = (String) event.getItem(); //populate primary table columns primaryColumns = getTableColumns(selectedTable); DefaultComboBoxModel combo2_model = new DefaultComboBoxModel( primaryColumns.toArray(new String[primaryColumns.size()])); JComboBox comboBox = new JComboBox(); comboBox.setModel(combo2_model); relationsTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox)); } } }); combo3.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent event) { if (event.getStateChange() == ItemEvent.SELECTED) { String selectedTable = (String) event.getItem(); //populate foreign table columns foreignColumns = getTableColumns(selectedTable); DefaultComboBoxModel combo3_model = new DefaultComboBoxModel( foreignColumns.toArray(new String[foreignColumns.size()])); JComboBox comboBox = new JComboBox(); comboBox.setModel(combo3_model); relationsTable.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox)); } } }); ComboBoxTableCellEditor primaryTableEditor = new ComboBoxTableCellEditor(tables, combo1); ComboBoxTableCellEditor primaryTableColumns = new ComboBoxTableCellEditor(primaryColumns, combo2); ComboBoxTableCellEditor foreignTableEditor = new ComboBoxTableCellEditor(foreignTables, combo3);//TODO: remove selected primary table from list ComboBoxTableCellEditor foreignTableColumns = new ComboBoxTableCellEditor(foreignColumns, combo4); relationsTable.getColumnModel().getColumn(0).setCellEditor(primaryTableEditor); relationsTable.getColumnModel().getColumn(1).setCellEditor(primaryTableColumns); relationsTable.getColumnModel().getColumn(2).setCellEditor(foreignTableEditor); relationsTable.getColumnModel().getColumn(3).setCellEditor(foreignTableColumns); columnsList.setCellRenderer(new CheckboxListCellRenderer()); SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), selected_columns); columnsList.addListSelectionListener(listSelectionListener); columnsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); columnsList.setSelectionModel(new DefaultListSelectionModel() { @Override public void setSelectionInterval(int index0, int index1) { if (isSelectedIndex(index0)) super.removeSelectionInterval(index0, index1); else super.addSelectionInterval(index0, index1); } }); }