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:table.TablePanel.java
public TablePanel(JPanel parent, GridBagConstraints c) { this.parent = parent; this.c = c;//from w w w. j ava 2 s. com dataHandler = null; data = new ArrayList<>(); selectedRows = new ArrayList<>(); tableModel = new MyTableModel(data); table = new JTable(tableModel); table.getColumnModel().getColumn(0).setResizable(false); table.getColumnModel().getColumn(0).setMaxWidth(60); table.getColumnModel().getColumn(1).setResizable(false); table.getColumnModel().getColumn(1).setMaxWidth(50); table.getColumnModel().getColumn(2).setMaxWidth(90); table.getColumnModel().getColumn(49).setMaxWidth(60); for (int i = 0; i < tableModel.getColumnCount(); i++) { if (i > 14 && i < 31) { table.getColumnModel().getColumn(i).setMaxWidth(70); } else if (tableModel.columnNamesTemp[i].contains("LEVEL")) { if (tableModel.columnNamesTemp[i].equals("QEC LEVEL")) { table.getColumnModel().getColumn(i).setMinWidth(90); table.getColumnModel().getColumn(i).setMaxWidth(200); } else { table.getColumnModel().getColumn(i).setMaxWidth(90); } if (tableModel.columnNamesTemp[i - 1].equals("Work Pace")) { table.getColumnModel().getColumn(i - 1).setMinWidth(90); table.getColumnModel().getColumn(i - 1).setMaxWidth(150); } else { table.getColumnModel().getColumn(i - 1).setMaxWidth(90); } } else { // table.getColumnModel().getColumn(i).setMinWidth(120); // table.getColumnModel().getColumn(i).setMaxWidth(250); } } table.getColumnModel().getColumn(table.getColumnCount() - 1).setMaxWidth(60); table.getColumnModel().getColumn(table.getColumnCount() - 1).setResizable(false); table.setRowSelectionAllowed(true); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (!dataHandler.getDeleting() && (table.getSelectedRow() != -1) && e.getColumn() != table.getColumnCount() - 1 && e.getColumn() != 1) { int row = table.getSelectedRow(); int col = e.getColumn(); if (col == 0 && (boolean) table.getValueAt(row, col) == true) { if (!selectedRows.contains((Integer) row)) selectedRows.add(row); } else if (col == 0 && (boolean) table.getValueAt(row, col) == false) { selectedRows.remove((Object) row); } else if (col != 0 && (boolean) table.getValueAt(row, table.getColumnCount() - 1)) { dataHandler.dataEdited(); } } } }); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { private int count = 0; @Override public void valueChanged(ListSelectionEvent arg0) { if (count > 1 && !arg0.getValueIsAdjusting()) { int[] draggedRows = table.getSelectedRows(); for (int i = 0; i < draggedRows.length; i++) if (selectedRows.contains((Integer) draggedRows[i])) { selectedRows.remove((Integer) draggedRows[i]); table.setValueAt(false, draggedRows[i], 0); } else { selectedRows.add((Integer) draggedRows[i]); table.setValueAt(true, draggedRows[i], 0); } // Finalize count = 0; } else if (arg0.getValueIsAdjusting()) count++; else count = 0; } }); // { // // @Override // public Component prepareRenderer(TableCellRenderer renderer, // int row, int column) { // JLabel label = (JLabel) super.prepareRenderer(renderer, row, column); // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) == // false) { // if ((int) row % 2 == 0) { // label.setBackground(new Color(244, 226,215)); // } else { // label.setBackground(new Color(241, 220,205)); // } // } else { // if ((int) row% 2 == 0) { // label.setBackground(new Color(255, 255, 255)); // } else { // label.setBackground(new Color(252, 252, 252)); // } // // } // if(table.getSelectedRow()==row) // label.setBackground(Color.LIGHT_GRAY); // return label; // } // }; // table.prepareRenderer(null, WIDTH, WIDTH); // table.setRowSelectionAllowed(true); // table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDefaultRenderer(Object.class, new MyTableCellRenderer()); // { // // @Override // public Component getTableCellRendererComponent(JTable table, Object // value, boolean isSelected, boolean hasFocus, int row, int column) { // JLabel label = (JLabel) table.prepareRenderer(null, row, column); // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) == // false) { // if ((int) row % 2 == 0) { // label.setBackground(new Color(244, 226,215)); // } else { // label.setBackground(new Color(241, 220,205)); // } // } else { // if ((int) row% 2 == 0) { // label.setBackground(new Color(255, 255, 255)); // } else { // label.setBackground(new Color(252, 252, 252)); // } // // } // if(table.getSelectedRow()==row) // label.setBackground(Color.LIGHT_GRAY); // return label; // } // }); // { // // @Override // public Component getTableCellRendererComponent(JTable table, Object // value, boolean isSelected, boolean hasFocus, int row, int column) { // Component cell= table.getCellRenderer(row, // column).getTableCellRendererComponent(table, value, isSelected, // hasFocus, row, column); // // // for(int i=1;i<table.getRowCount();i++) { // if((boolean)table.getValueAt(i, table.getColumnCount()-1) ==false) // { // setForeground(Color.black); // setBackground(Color.red); // } // else // { // setBackground(Color.white); // setForeground(Color.black); // } // } // return cell; // } // }); // DefaultTableCellRenderer rightRenderer = new // DefaultTableCellRenderer(); // rightRenderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT); for (int i = 0; i < tableModel.getColumnCount(); i++) { table.getTableHeader().getColumnModel().getColumn(i) .setHeaderRenderer(new HeaderRenderer(table, alignments[1])); // table.getColumnModel().getColumn(i).setCellRenderer(new // MyTableCellRenderer()); } table.getTableHeader().setReorderingAllowed(false); table.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); table.setRowHeight(25); // table.setPreferredScrollableViewportSize(new Dimension(10000, 200)); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // JViewport tableView = new JViewport(); // tableView.add(table); // scrollPane.setViewport(tableView); parent.setSize(table.getWidth(), table.getHeight()); // parent.setPreferredSize(new Dimension(70000,10000)); // scrollPane.setVerticalScrollBar(new JScrollBar(JScrollBar.VERTICAL)); // scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL)); // Add the scroll pane to this panel. // parent.add(table.getTableHeader()); // parent.add(table, c); // Add header in NORTH slot parent.add(table.getTableHeader(), BorderLayout.NORTH); // Add table itself to CENTER slot parent.add(table, BorderLayout.CENTER); }
From source file:TableSelectionDemo.java
public TableSelectionDemo() { super(new BorderLayout()); String[] columnNames = { "French", "Spanish", "Italian" }; String[][] tableData = { { "un", "uno", "uno" }, { "deux", "dos", "due" }, { "trois", "tres", "tre" }, { "quatre", "cuatro", "quattro" }, { "cinq", "cinco", "cinque" }, { "six", "seis", "sei" }, { "sept", "siete", "sette" } }; table = new JTable(tableData, columnNames); listSelectionModel = table.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); // Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);//ww w . j ava2 s . c o m comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); // Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(420, 130)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(250, 50)); topHalf.setPreferredSize(new Dimension(200, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); // XXX: next line needed if bottomHalf is a scroll pane: // bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 110)); splitPane.add(bottomHalf); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDRInputController.java
/** * Initialise data, called on switch from linear regression to dose-response *///from w w w. j a va 2 s . c o m @Override public void initDRInputData() { //get conditions processed in area analysis List<PlateCondition> processedConditions = doseResponseController.getProcessedConditions(); //number of replicates per condition will be added to list as information List<Integer> numberOfReplicates = doseResponseController.getNumberOfReplicates(); //create and set the table model for the top panel table setTableModel(createTableModel(processedConditions)); // put conditions in selectable list ObservableList<PlateCondition> plateConditionBindingList = ObservableCollections .observableList(processedConditions); JListBinding jListBinding = SwingBindings.createJListBinding(AutoBinding.UpdateStrategy.READ_WRITE, plateConditionBindingList, dRInputPanel.getConditionsList()); bindingGroup.addBinding(jListBinding); bindingGroup.bind(); dRInputPanel.getConditionsList() .setCellRenderer(new RectIconListRenderer(processedConditions, numberOfReplicates)); dRInputPanel.getConditionsList().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); doseResponseController.getDRPanel().getGraphicsDRParentPanel().add(dRInputPanel); doseResponseController.getDRPanel().revalidate(); doseResponseController.getDRPanel().repaint(); }
From source file:dnd.BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); //Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); //LEFT COLUMN //Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); //Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); //RIGHT COLUMN //Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); //Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); //Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setVisibleRowCount(-1);/* ww w . j a v a 2 s. com*/ list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) list.getModel(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the current string under the drop. String value = (String) listModel.getElementAt(index); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Display a dialog with the drop information. String dropValue = "\"" + data + "\" dropped "; if (dl.isInsert()) { if (dl.getIndex() == 0) { displayDropLocation(dropValue + "at beginning of list"); } else if (dl.getIndex() >= list.getModel().getSize()) { displayDropLocation(dropValue + "at end of list"); } else { String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1); String value2 = (String) list.getModel().getElementAt(dl.getIndex()); displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\""); } } else { displayDropLocation(dropValue + "on top of " + "\"" + value + "\""); } /** This is commented out for the basicdemo.html tutorial page. ** If you add this code snippet back and delete the ** "return false;" line, the list will accept drops ** of type string. // Perform the actual import. if (insert) { listModel.add(index, data); } else { listModel.set(index, data); } return true; */ return false; } public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); list.setDropMode(DropMode.ON_OR_INSERT); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); //Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon); DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); //Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:components.SharedModelDemo.java
public SharedModelDemo() { super(new BorderLayout()); Vector data = new Vector(7); String[] columnNames = { "French", "Spanish", "Italian" }; String[] oneData = { "un", "uno", "uno" }; String[] twoData = { "deux", "dos", "due" }; String[] threeData = { "trois", "tres", "tre" }; String[] fourData = { "quatre", "cuatro", "quattro" }; String[] fiveData = { "cinq", "cinco", "cinque" }; String[] sixData = { "six", "seis", "sei" }; String[] sevenData = { "sept", "siete", "sette" }; //Build the model. SharedDataModel dataModel = new SharedDataModel(columnNames); dataModel.addElement(oneData);/*w w w . j av a2 s . c o m*/ dataModel.addElement(twoData); dataModel.addElement(threeData); dataModel.addElement(fourData); dataModel.addElement(fiveData); dataModel.addElement(sixData); dataModel.addElement(sevenData); list = new JList(dataModel); list.setCellRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList l, Object value, int i, boolean s, boolean f) { String[] array = (String[]) value; return super.getListCellRendererComponent(l, array[0], i, s, f); } }); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); table = new JTable(dataModel); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); //Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); //Build output area. output = new JTextArea(10, 40); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); //Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.X_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(300, 100)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(400, 50)); topHalf.setPreferredSize(new Dimension(400, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.NORTH); bottomHalf.add(outputPane, BorderLayout.CENTER); //XXX: next line needed if bottomHalf is a scroll pane: //bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }
From source file:com.compomics.colims.client.controller.AnalyticalRunsSearchSettingsController.java
@Override @PostConstruct/* w ww .j ava 2 s . co m*/ public void init() { //register to event bus eventBus.register(this); analyticalRunsSearchSettingsDialog = new AnalyticalRunsSearchSettingsDialog(mainController.getMainFrame(), true); //init sample analytical runs table SortedList<AnalyticalRun> sortedAnalyticalRuns = new SortedList<>(analyticalRuns, new IdComparator()); analyticalRunsTableModel = GlazedListsSwing.eventTableModel(sortedAnalyticalRuns, new AnalyticalRunManagementTableFormat()); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().setModel(analyticalRunsTableModel); analyticalRunsSelectionModel = new DefaultEventSelectionModel<>(sortedAnalyticalRuns); analyticalRunsSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().setSelectionModel(analyticalRunsSelectionModel); //set column widths analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.RUN_ID).setPreferredWidth(35); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.RUN_ID).setMaxWidth(35); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.RUN_ID).setMinWidth(35); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.NAME).setPreferredWidth(200); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.START_DATE).setPreferredWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.START_DATE).setMaxWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.START_DATE).setMinWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.CREATED).setPreferredWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.CREATED).setMaxWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.CREATED).setMinWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.NUMBER_OF_SPECTRA).setPreferredWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.NUMBER_OF_SPECTRA).setMaxWidth(80); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().getColumnModel() .getColumn(AnalyticalRunManagementTableFormat.NUMBER_OF_SPECTRA).setMinWidth(80); analyticalRunsSearchSettingsDialog.getEditAnalyticalRunButton().addActionListener(e -> { EventList<AnalyticalRun> selectedAnalyticalRuns = analyticalRunsSelectionModel.getSelected(); if (selectedAnalyticalRuns.size() == 1) { analyticalRunEditController.updateView(selectedAnalyticalRuns.get(0)); } else { eventBus.post(new MessageEvent("Analytical run selection", "Please select one and only one analytical run to edit.", JOptionPane.INFORMATION_MESSAGE)); } }); analyticalRunsSearchSettingsDialog.getDeleteAnalyticalRunButton().addActionListener(e -> { EventList<AnalyticalRun> selectedAnalyticalRuns = analyticalRunsSelectionModel.getSelected(); if (selectedAnalyticalRuns.size() == 1) { boolean deleteConfirmation = deleteEntity(selectedAnalyticalRuns.get(0), AnalyticalRun.class); if (deleteConfirmation) { AnalyticalRun selectedAnalyticalRun = selectedAnalyticalRuns.get(0); //remove from overview table and clear selection analyticalRuns.remove(selectedAnalyticalRun); analyticalRunsSelectionModel.clearSelection(); eventBus.post(new AnalyticalRunChangeEvent(EntityChangeEvent.Type.DELETED, selectedAnalyticalRun.getId(), sampleToEdit.getId())); //remove analytical run from the selected sample and update the table sampleToEdit.getAnalyticalRuns().remove(selectedAnalyticalRun); analyticalRunsSearchSettingsDialog.getAnalyticalRunsTable().updateUI(); } } else { eventBus.post(new MessageEvent("Analytical run selection", "Please select one and only one analytical run to delete.", JOptionPane.INFORMATION_MESSAGE)); } }); analyticalRunsSelectionModel.addListSelectionListener(lse -> { if (!lse.getValueIsAdjusting()) { AnalyticalRun analyticalRun = getSelectedAnalyticalRun(); setAnalyticalRunDetailsSearchSettings(analyticalRun); } }); analyticalRunsSearchSettingsDialog.getCloseButton() .addActionListener(e -> analyticalRunsSearchSettingsDialog.dispose()); }
From source file:components.TableSelectionDemo.java
public void actionPerformed(ActionEvent event) { String command = event.getActionCommand(); //Cell selection is disabled in Multiple Interval Selection //mode. The enabled state of cellCheck is a convenient flag //for this status. if ("Row Selection" == command) { table.setRowSelectionAllowed(rowCheck.isSelected()); //In MIS mode, column selection allowed must be the //opposite of row selection allowed. if (!cellCheck.isEnabled()) { table.setColumnSelectionAllowed(!rowCheck.isSelected()); }/*from www . j a v a 2s. co m*/ } else if ("Column Selection" == command) { table.setColumnSelectionAllowed(columnCheck.isSelected()); //In MIS mode, row selection allowed must be the //opposite of column selection allowed. if (!cellCheck.isEnabled()) { table.setRowSelectionAllowed(!columnCheck.isSelected()); } } else if ("Cell Selection" == command) { table.setCellSelectionEnabled(cellCheck.isSelected()); } else if ("Multiple Interval Selection" == command) { table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //If cell selection is on, turn it off. if (cellCheck.isSelected()) { cellCheck.setSelected(false); table.setCellSelectionEnabled(false); } //And don't let it be turned back on. cellCheck.setEnabled(false); } else if ("Single Interval Selection" == command) { table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); //Cell selection is ok in this mode. cellCheck.setEnabled(true); } else if ("Single Selection" == command) { table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Cell selection is ok in this mode. cellCheck.setEnabled(true); } //Update checkboxes to reflect selection mode side effects. rowCheck.setSelected(table.getRowSelectionAllowed()); columnCheck.setSelected(table.getColumnSelectionAllowed()); if (cellCheck.isEnabled()) { cellCheck.setSelected(table.getCellSelectionEnabled()); } }
From source file:fr.free.hd.servers.gui.PhonemView.java
@Override protected JComponent createControl() { final JPanel view = new JPanel(new BorderLayout()); Collection<Phonem> phonesList = phonemsDAO.getPhonems(); Map<String, Phonem> mapList = new HashMap<String, Phonem>(); for (Phonem phonem : phonesList) { mapList.put(phonem.getPhonem(), phonem); }//from w w w . j a v a 2 s.c om final StatementListModel model = new StatementListModel(mapList); printCommand.setModel(model); printCommand.setFace(face); copyCommand.setModel(model); copyCommand.setFace(face); list = new JList(model); final JScrollPane sp = new JScrollPane(list); final JTextField field = new JTextField(); field.getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { model.setString(field.getText()); } @Override public void insertUpdate(DocumentEvent e) { model.setString(field.getText()); } @Override public void removeUpdate(DocumentEvent e) { model.setString(field.getText()); } }); final PhonemListModel phonemModel = new PhonemListModel((List<Phonem>) phonesList); final JList phonemList = new JList(phonemModel); final JScrollPane spPhonemList = new JScrollPane(phonemList); phonemList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { // private int oldIndex = -1; @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting() == false) { Phonem innerPhonem = (Phonem) phonemModel.getElementAt(phonemList.getSelectedIndex()); field.setText(field.getText() + innerPhonem.getPhonem()); } } }); phonemList.setCellRenderer(new PhonemListRenderer()); list.setCellRenderer(new StatementPhonemListRenderer(face)); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setLayoutOrientation(JList.HORIZONTAL_WRAP); list.setVisibleRowCount(1); view.add(spPhonemList, BorderLayout.WEST); view.add(sp, BorderLayout.CENTER); view.add(field, BorderLayout.SOUTH); field.requestFocus(); return view; }
From source file:BasicDnD.java
public BasicDnD() { super(new BorderLayout()); JPanel leftPanel = createVerticalBoxPanel(); JPanel rightPanel = createVerticalBoxPanel(); // Create a table model. DefaultTableModel tm = new DefaultTableModel(); tm.addColumn("Column 0"); tm.addColumn("Column 1"); tm.addColumn("Column 2"); tm.addColumn("Column 3"); tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" }); tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" }); tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" }); tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" }); // LEFT COLUMN // Use the table model to create a table. table = new JTable(tm); leftPanel.add(createPanelForComponent(table, "JTable")); // Create a color chooser. colorChooser = new JColorChooser(); leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser")); // RIGHT COLUMN // Create a textfield. textField = new JTextField(30); textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast"); rightPanel.add(createPanelForComponent(textField, "JTextField")); // Create a scrolled text area. textArea = new JTextArea(5, 30); textArea.setText("Favorite shows:\nBuffy, Alias, Angel"); JScrollPane scrollPane = new JScrollPane(textArea); rightPanel.add(createPanelForComponent(scrollPane, "JTextArea")); // Create a list model and a list. DefaultListModel listModel = new DefaultListModel(); listModel.addElement("Martha Washington"); listModel.addElement("Abigail Adams"); listModel.addElement("Martha Randolph"); listModel.addElement("Dolley Madison"); listModel.addElement("Elizabeth Monroe"); listModel.addElement("Louisa Adams"); listModel.addElement("Emily Donelson"); list = new JList(listModel); list.setVisibleRowCount(-1);/*from w w w. j av a2s .co m*/ list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setTransferHandler(new TransferHandler() { public boolean canImport(TransferHandler.TransferSupport info) { // we only import Strings if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); if (dl.getIndex() == -1) { return false; } return true; } public boolean importData(TransferHandler.TransferSupport info) { if (!info.isDrop()) { return false; } // Check for String flavor if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) { displayDropLocation("List doesn't accept a drop of this type."); return false; } JList.DropLocation dl = (JList.DropLocation) info.getDropLocation(); DefaultListModel listModel = (DefaultListModel) list.getModel(); int index = dl.getIndex(); boolean insert = dl.isInsert(); // Get the current string under the drop. String value = (String) listModel.getElementAt(index); // Get the string that is being dropped. Transferable t = info.getTransferable(); String data; try { data = (String) t.getTransferData(DataFlavor.stringFlavor); } catch (Exception e) { return false; } // Display a dialog with the drop information. String dropValue = "\"" + data + "\" dropped "; if (dl.isInsert()) { if (dl.getIndex() == 0) { displayDropLocation(dropValue + "at beginning of list"); } else if (dl.getIndex() >= list.getModel().getSize()) { displayDropLocation(dropValue + "at end of list"); } else { String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1); String value2 = (String) list.getModel().getElementAt(dl.getIndex()); displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\""); } } else { displayDropLocation(dropValue + "on top of " + "\"" + value + "\""); } /** * This is commented out for the basicdemo.html tutorial page. * If you * add this code snippet back and delete the * "return false;" line, the * list will accept drops * of type string. // Perform the actual * import. if (insert) { listModel.add(index, data); } else { * listModel.set(index, data); } return true; */ return false; } public int getSourceActions(JComponent c) { return COPY; } protected Transferable createTransferable(JComponent c) { JList list = (JList) c; Object[] values = list.getSelectedValues(); StringBuffer buff = new StringBuffer(); for (int i = 0; i < values.length; i++) { Object val = values[i]; buff.append(val == null ? "" : val.toString()); if (i != values.length - 1) { buff.append("\n"); } } return new StringSelection(buff.toString()); } }); list.setDropMode(DropMode.ON_OR_INSERT); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(listView, "JList")); // Create a tree. DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia"); DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon"); rootNode.add(sharon); DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya"); sharon.add(maya); DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya"); sharon.add(anya); sharon.add(new DefaultMutableTreeNode("Bongo")); maya.add(new DefaultMutableTreeNode("Muffin")); anya.add(new DefaultMutableTreeNode("Winky")); DefaultTreeModel model = new DefaultTreeModel(rootNode); tree = new JTree(model); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JScrollPane treeView = new JScrollPane(tree); treeView.setPreferredSize(new Dimension(300, 100)); rightPanel.add(createPanelForComponent(treeView, "JTree")); // Create the toggle button. toggleDnD = new JCheckBox("Turn on Drag and Drop"); toggleDnD.setActionCommand("toggleDnD"); toggleDnD.addActionListener(this); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel); splitPane.setOneTouchExpandable(true); add(splitPane, BorderLayout.CENTER); add(toggleDnD, BorderLayout.PAGE_END); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); }
From source file:org.onesun.sdi.swing.app.views.DataServicesView.java
private void createControls() { copyDataButton.addActionListener(new ActionListener() { @Override/*from w ww . j av a 2 s .c o m*/ public void actionPerformed(ActionEvent e) { datasetModel = new DatasetModel(); final Metadata origMetadata = AppCommonsUI.PREVIEW_DATASET_MODEL.getMetadata(); Metadata metadata = new Metadata(); // copy metadata for (String key : origMetadata.keySet()) { metadata.put(key, origMetadata.get(key)); } final List<Map<String, String>> origData = AppCommonsUI.PREVIEW_DATASET_MODEL.getData(); List<Map<String, String>> data = new ArrayList<Map<String, String>>(); // copy data for (Map<String, String> datum : origData) { Map<String, String> record = new TreeMap<String, String>(); for (String key : datum.keySet()) { record.put(key, datum.get(key)); } data.add(record); } datasetModel.setMetadata(metadata); datasetModel.setData(data); dataTable.setModel(datasetModel); rowCountLabel.setText( "Rows: " + datasetModel.getRowCount() + ", Columns: " + datasetModel.getColumnCount()); JTableUtils.packColumns(dataTable, 2); rowCountLabel.invalidate(); dataTable.invalidate(); dataTable.validate(); scrollPane.invalidate(); } }); JPanel panel = new JPanel(new BorderLayout(5, 5)); panel.add(new JLabel("Enrichment Services"), BorderLayout.NORTH); dataServicesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); dataServicesList.setListData(DataServicesFactory.getServiceNames()); dataServicesList.setPreferredSize(new Dimension(400, 300)); JScrollPane listScrollPane = new JScrollPane(dataServicesList); panel.add(listScrollPane, BorderLayout.CENTER); containerPanel.add(panel); panel = new JPanel(new BorderLayout(5, 5)); JPanel labelAndControlPanel = new JPanel(new BorderLayout(5, 5)); labelAndControlPanel.add(new JLabel("Columns to be enriched"), BorderLayout.CENTER); JPanel controlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); JButton selectButton = new JButton(AppIcons.getIcon("select")); controlPanel.add(selectButton); selectButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean columnsAvailable = false; if (datasetModel != null) { Metadata metadata = datasetModel.getMetadata(); if (metadata != null) { columnsAvailable = true; int size = metadata.keySet().size(); String[] values = new String[size]; int index = 0; for (String key : metadata.keySet()) { values[index] = key; index++; } metadataSelectionDialog.setValues(values); } } if (columnsAvailable == true) { metadataSelectionDialog.setVisible(true); } else { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_NO_METADATA); return; } } }); JButton clearButton = new JButton(AppIcons.getIcon("clear")); clearButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectedColumnList.setListData(new String[] {}); selectedColumnList.invalidate(); } }); controlPanel.add(clearButton); labelAndControlPanel.add(controlPanel, BorderLayout.EAST); panel.add(labelAndControlPanel, BorderLayout.NORTH); selectedColumnList.setPreferredSize(new Dimension(400, 300)); listScrollPane = new JScrollPane(selectedColumnList); panel.add(listScrollPane, BorderLayout.CENTER); containerPanel.add(panel); executeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { if (AppCommons.TASKLET.getConnectionProperties() == null) { JOptionPane.showMessageDialog(rootPanel, AppMessages.INFORMATION_CHOOSE_A_CONNECTION); return; } if (AppCommonsUI.PREVIEW_DATASET_MODEL == null || AppCommonsUI.PREVIEW_DATASET_MODEL.getRowCount() <= 0) { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_NO_DATA_TO_ENTRICH); return; } List<String> selectedServiceNames = dataServicesList.getSelectedValuesList(); if ((selectedServiceNames != null && selectedServiceNames.size() == 0) || (selectedColumnNames.length == 0)) { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_MISSING_DATA_SERVICE_AND_COLUMNS); return; } DefaultCusor.startWaitCursor(rootPanel); List<Map<String, String>> data = datasetModel.getData(); Metadata metadata = datasetModel.getMetadata(); for (String name : selectedServiceNames) { DataService service = DataServicesFactory.getDataService(name); if (service instanceof TextAnalysisService) { TextAnalysisService taService = (TextAnalysisService) service; List<Object> objects = new ArrayList<Object>(); for (Map<String, String> datum : data) { objects.add(datum); } taService.setData(objects); taService.setMetadata(metadata); taService.setColumns(selectedColumnNames); taService.execute(); } } rowCountLabel.setText("Rows: " + data.size() + ", Columns: " + metadata.size()); rowCountLabel.invalidate(); datasetModel = new DatasetModel(); datasetModel.setMetadata(metadata); datasetModel.setData(data); datasetModel.fireTableStructureChanged(); datasetModel.fireTableDataChanged(); dataTable.setModel(datasetModel); JTableUtils.packColumns(dataTable, 2); dataTable.invalidate(); dataTable.validate(); scrollPane.invalidate(); DefaultCusor.stopWaitCursor(rootPanel); } }); computeMetricsButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (datasetModel == null || datasetModel.getRowCount() == 0) { JOptionPane.showMessageDialog(rootPanel, AppMessages.ERROR_NO_DATA); return; } List<Map<String, String>> data = datasetModel.getData(); int upsetCount = 0; int happyCount = 0; int negativeCount = 0; int positiveCount = 0; for (Map<String, String> datum : data) { for (String k : datum.keySet()) { if (k.compareTo("uclassify_sentiment") == 0) { String text = datum.get(k); String[] tokens = text.replace("{", "").replace("}", "").split(", "); for (String token : tokens) { String[] nvp = token.split("="); Double score = Double.parseDouble(nvp[1]); if (nvp[0].compareToIgnoreCase("negative") == 0 && score > 50.0) { negativeCount++; } if (nvp[0].compareToIgnoreCase("positive") == 0 && score >= 50.0) { positiveCount++; } } } else if (k.compareTo("uclassify_mood") == 0) { String text = datum.get(k); String[] tokens = text.replace("{", "").replace("}", "").split(", "); for (String token : tokens) { String[] nvp = token.split("="); Double score = Double.parseDouble(nvp[1]); if (nvp[0].compareToIgnoreCase("upset") == 0 && score > 50.0) { upsetCount++; } if (nvp[0].compareToIgnoreCase("happy") == 0 && score >= 50.0) { happyCount++; } } } } } DefaultPieDataset moodDataset = new DefaultPieDataset(); moodDataset.setValue("upset", upsetCount); moodDataset.setValue("happy", happyCount); DefaultPieDataset sentimentDataset = new DefaultPieDataset(); sentimentDataset.setValue("negative", negativeCount); sentimentDataset.setValue("positive", positiveCount); JFreeChart moodChart = ChartFactory.createPieChart("How is mood?", moodDataset, true, true, true); JFreeChart sentimentChart = ChartFactory.createPieChart("How is sentiment?", sentimentDataset, true, true, true); ChartDialog cd = new ChartDialog(AppCommonsUI.MAIN_WINDOW, moodChart, sentimentChart); cd.setSize(new Dimension(900, 500)); cd.setVisible(true); } }); }