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:ca.sqlpower.wabit.swingui.enterprise.UserPanel.java
public UserPanel(User baseUser) { final MessageDigest digester; try {// w ww. j a v a2 s .com digester = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e1) { throw new RuntimeException(e1); } this.user = baseUser; this.workspace = (WabitWorkspace) this.user.getParent(); this.loginTextField = new JTextField(); this.loginTextField.setText(user.getName()); this.loginLabel = new JLabel("User name"); this.loginTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setName(loginTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.passwordTextField = new JPasswordField(); this.passwordLabel = new JLabel("Password"); this.passwordTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { try { String pass = new String(passwordTextField.getPassword()); String encoded = new String(Hex.encodeHex(digester.digest(pass.getBytes("UTF-8")))); user.setPassword(encoded); } catch (UnsupportedEncodingException e1) { throw new RuntimeException(e1); } } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.fullNameTextField = new JTextField(); this.fullNameTextField.setText(user.getFullName()); this.fullNameLabel = new JLabel("Full name"); this.fullNameTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setFullName(fullNameTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.emailTextField = new JTextField(); this.emailTextField.setText(user.getEmail()); this.emailLabel = new JLabel("Email"); this.emailTextField.getDocument().addDocumentListener(new DocumentListener() { public void textChanged(DocumentEvent e) { user.setEmail(emailTextField.getText()); } public void changedUpdate(DocumentEvent e) { textChanged(e); } public void insertUpdate(DocumentEvent e) { textChanged(e); } public void removeUpdate(DocumentEvent e) { textChanged(e); } }); this.availableGroupsLabel = new JLabel("Available Groups"); this.availableGroupsListModel = new GroupsListModel(user, workspace, false); this.availableGroupsList = new JList(this.availableGroupsListModel); this.availableGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.availableGroupsList.setCellRenderer(new DefaultListCellRenderer() { final JTree dummyTree = new JTree(); final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer(); @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0, cellHasFocus); } }); this.availableGroupsScrollPane = new JScrollPane(this.availableGroupsList); this.currentGroupsLabel = new JLabel("Current Memberships"); this.currentGroupsListModel = new GroupsListModel(user, workspace, true); this.currentGroupsList = new JList(this.currentGroupsListModel); this.currentGroupsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); this.currentGroupsList.setCellRenderer(new DefaultListCellRenderer() { final JTree dummyTree = new JTree(); final WorkspaceTreeCellRenderer delegate = new WorkspaceTreeCellRenderer(); @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { return delegate.getTreeCellRendererComponent(dummyTree, value, isSelected, false, true, 0, cellHasFocus); } }); this.groupsLabel = new JLabel("Edit user memberships"); this.currentGroupsScrollPane = new JScrollPane(this.currentGroupsList); this.addButton = new JButton(">"); this.addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] selection = availableGroupsList.getSelectedValues(); if (selection.length == 0) { return; } try { workspace.begin("Add user to groups"); for (Object object : selection) { ((Group) object).addMember(new GroupMember(user)); } } finally { workspace.commit(); } } }); this.removeButton = new JButton("<"); this.removeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Object[] selection = currentGroupsList.getSelectedValues(); if (selection.length == 0) { return; } try { workspace.begin("Remove user from groups"); Map<Group, GroupMember> toRemove = new ArrayMap<Group, GroupMember>(); for (Object object : selection) { for (GroupMember membership : ((Group) object).getChildren(GroupMember.class)) { if (membership.getUser().getUUID().equals(user.getUUID())) { toRemove.put((Group) object, membership); } } } for (Entry<Group, GroupMember> entry : toRemove.entrySet()) { entry.getKey().removeMember(entry.getValue()); } } finally { workspace.commit(); } } }); Action deleteAction = new DeleteFromTreeAction(this.workspace, this.user, this.panel, this.workspace.getSession().getContext()); this.toolbarBuilder.add(deleteAction, "Delete this user", WabitIcons.DELETE_ICON_32); // Panel building time JPanel namePassPanel = new JPanel(new MigLayout()); namePassPanel.add(this.loginLabel, "align right, gaptop 20"); namePassPanel.add(this.loginTextField, "span, wrap, wmin 600"); namePassPanel.add(this.passwordLabel, "align right"); namePassPanel.add(this.passwordTextField, "span, wrap, wmin 600"); namePassPanel.add(this.fullNameLabel, "align right, gaptop 20"); namePassPanel.add(this.fullNameTextField, "span, wrap, wmin 600"); namePassPanel.add(this.emailLabel, "align right"); namePassPanel.add(this.emailTextField, "span, wrap, wmin 600"); this.panel.add(namePassPanel, "north"); this.panel.add(this.groupsLabel, "span, wrap, gaptop 20, align center"); JPanel buttonsPanel = new JPanel(new MigLayout()); buttonsPanel.add(this.addButton, "wrap"); buttonsPanel.add(this.removeButton); JPanel availablePanel = new JPanel(new MigLayout()); availablePanel.add(this.availableGroupsLabel, "wrap, align center"); availablePanel.add(this.availableGroupsScrollPane, "wmin 300"); JPanel currentPanel = new JPanel(new MigLayout()); currentPanel.add(this.currentGroupsLabel, "wrap, align center"); currentPanel.add(this.currentGroupsScrollPane, "wmin 300"); this.panel.add(availablePanel); this.panel.add(buttonsPanel, "shrink, span 1 2"); this.panel.add(currentPanel); }
From source file:com.funambol.foundation.admin.SIFSyncSourceConfigPanel.java
/** * Create the panel// w w w . j a va2 s .c o m * * @throws Exception if error occures during creation of the panel */ private void init() { this.setLayout(null); // // Set properties of label, position and border referred to the title //of the panel // titledBorder1 = new TitledBorder(""); panelName.setFont(titlePanelFont); panelName.setText("Edit SIF SyncSource"); panelName.setBounds(new Rectangle(14, 5, 316, 28)); panelName.setAlignmentX(SwingConstants.CENTER); panelName.setBorder(titledBorder1); int y = 60; int dy = 30; int x1 = 14; int x2 = 170; int w1 = 150; int w2 = 350; int h = 18; sourceUriLabel.setText("Source URI: "); sourceUriLabel.setFont(defaultFont); sourceUriLabel.setBounds(x1, y, w1, h); sourceUriValue.setFont(defaultFont); sourceUriValue.setBounds(x2, y, w2, h); y += dy; nameLabel.setText("Name: "); nameLabel.setFont(defaultFont); nameLabel.setBounds(x1, y, w1, h); nameValue.setFont(defaultFont); nameValue.setBounds(x2, y, w2, h); y += dy; typeLabel.setText("Type: "); typeLabel.setFont(defaultFont); typeLabel.setBounds(x1, y, w1, h); typeCombo.setFont(defaultFont); typeCombo.setBounds(x2, y, 100, h); typeCombo.addItem(TYPE_SIF_C); typeCombo.addItem(TYPE_SIF_E); typeCombo.addItem(TYPE_SIF_N); typeCombo.addItem(TYPE_SIF_T); typeCombo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { handleTypeSelected(); } }); handleTypeSelected(); y += dy; directoryLabel.setText("Source Directory: "); directoryLabel.setFont(defaultFont); directoryLabel.setBounds(x1, y, w1, h); directoryValue.setFont(defaultFont); directoryValue.setBounds(x2, y, w2, h); y += dy; twinPropertiesLabel.setText("Twin properties: "); twinPropertiesLabel.setFont(defaultFont); twinPropertiesLabel.setBounds(x1, y, w1, h); descrTwinPropLabel.setText("(Used to identify twins)"); descrTwinPropLabel.setFont(defaultFont); descrTwinPropLabel.setBounds(x1, (y + 15), w1, h); twinPropertiesValue.setFont(defaultFont); twinPropertiesValue.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); twinPropertiesValue.setAutoscrolls(true); scrollTable = new JScrollPane(twinPropertiesValue); scrollTable.setWheelScrollingEnabled(true); scrollTable.setBounds(x2, y, 200, 66); scrollTable.setColumnHeader(null); scrollTable.setMinimumSize(new Dimension(200, 66)); scrollTable.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); y += 45; y += dy; multiUserLabel.setText("MultiUser: "); multiUserLabel.setFont(defaultFont); multiUserLabel.setBounds(x1, y, w1, h); multiUserValue.setSelected(false); multiUserValue.setBounds(x2, y, h, h); y += 5; y += dy; confirmButton.setFont(defaultFont); confirmButton.setText("Add"); confirmButton.setBounds(x2, y, 70, 25); confirmButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { validateValues(); getValues(); if (getState() == STATE_INSERT) { SIFSyncSourceConfigPanel.this.actionPerformed(new ActionEvent(SIFSyncSourceConfigPanel.this, ACTION_EVENT_INSERT, event.getActionCommand())); } else { SIFSyncSourceConfigPanel.this.actionPerformed(new ActionEvent(SIFSyncSourceConfigPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand())); } } catch (Exception e) { notifyError(new AdminException(e.getMessage())); } } }); // // Add all components to the panel // this.add(panelName, null); this.add(sourceUriLabel, null); this.add(sourceUriValue, null); this.add(nameLabel, null); this.add(nameValue, null); this.add(typeLabel, null); this.add(typeCombo, null); this.add(directoryLabel, null); this.add(directoryValue, null); this.add(twinPropertiesLabel, null); this.add(scrollTable, null); this.add(descrTwinPropLabel, null); this.add(multiUserLabel, null); this.add(multiUserValue, null); this.add(confirmButton, null); }
From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java
/** * Constructor of a results "table" which is really a panel * @param esrPane the parent//w w w .j a v a 2 s. co m * @param erTableInfo the info describing the results * @param installServices indicates whether services should be installed * @param isExpandedAtStartUp enough said * @param inclCloseBtn whether to include the close button on the bar */ public ESResultsTablePanel(final ExpressSearchResultsPaneIFace esrPane, final QueryForIdResultsIFace results, final boolean installServices, final boolean isExpandedAtStartUp, final boolean inclCloseBtn) { super(new BorderLayout()); this.esrPane = esrPane; this.results = results; this.bannerColor = results.getBannerColor(); this.isEditable = results.isEditingEnabled(); table = new JTable(); table.setShowVerticalLines(false); table.setRowSelectionAllowed(true); table.setSelectionMode(results.isMultipleSelection() ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION); setBackground(table.getBackground()); if (isEditable) { addContextMenu(); } topTitleBar = new GradiantLabel(results.getTitle(), SwingConstants.LEFT); topTitleBar.setBGBaseColor(bannerColor); topTitleBar.setTextColor(Color.WHITE); topTitleBar.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { expandBtn.doClick(); } } }); String description = results.getDescription(); if (StringUtils.isNotEmpty(description)) { topTitleBar.setToolTipText(description); } expandBtn = new TriangleButton(); expandBtn.setToolTipText(getResourceString("CollapseTBL")); expandBtn.setForeground(bannerColor); expandBtn.setTextColor(Color.WHITE); showTopNumEntriesBtn = new GradiantButton( String.format(getResourceString("ShowTopEntries"), new Object[] { topNumEntries })); showTopNumEntriesBtn.setForeground(bannerColor); showTopNumEntriesBtn.setTextColor(Color.WHITE); showTopNumEntriesBtn.setVisible(false); showTopNumEntriesBtn.setCursor(handCursor); List<ServiceInfo> services = installServices ? getServices() : null; //System.out.println("["+tableInfo.getTableId()+"]["+services.size()+"]"); StringBuffer colDef = new StringBuffer("p,0px,p:g,0px,p,0px,"); int numCols = (installServices ? services.size() : 0) + (inclCloseBtn ? 1 : 0); colDef.append(UIHelper.createDuplicateJGoodiesDef("p", "0px", numCols)); // add additional col defs for services PanelBuilder builder = new PanelBuilder(new FormLayout(colDef.toString(), "f:p:g")); CellConstraints cc = new CellConstraints(); int col = 1; builder.add(expandBtn, cc.xy(col, 1)); col += 2; builder.add(topTitleBar, cc.xy(col, 1)); col += 2; builder.add(showTopNumEntriesBtn, cc.xy(col, 1)); col += 2; if (installServices && services.size() > 0) { serviceBtns = new Hashtable<ServiceInfo, JButton>(); //IconManager.IconSize size = IconManager. int iconSize = AppPreferences.getLocalPrefs().getInt("banner.icon.size", 20); // Install the buttons on the banner with available services for (ServiceInfo serviceInfo : services) { GradiantButton btn = new GradiantButton(serviceInfo.getIcon(iconSize)); // XXX PREF btn.setToolTipText(serviceInfo.getTooltip()); btn.setForeground(bannerColor); builder.add(btn, cc.xy(col, 1)); ESTableAction esta = new ESTableAction(serviceInfo.getCommandAction(), table, serviceInfo.getTooltip()); esta.setProperty("gridtitle", results.getTitle()); btn.addActionListener(esta); serviceBtns.put(serviceInfo, btn); col += 2; } } GradiantButton closeBtn = null; if (inclCloseBtn) { closeBtn = new GradiantButton(IconManager.getIcon("Close")); closeBtn.setToolTipText(getResourceString("ESCloseTable")); closeBtn.setForeground(bannerColor); closeBtn.setRolloverEnabled(true); closeBtn.setRolloverIcon(IconManager.getIcon("CloseHover")); closeBtn.setPressedIcon(IconManager.getIcon("CloseHover")); builder.add(closeBtn, cc.xy(col, 1)); col += 2; } add(builder.getPanel(), BorderLayout.NORTH); tablePane = new JPanel(new BorderLayout()); setupTablePane(); if (isEditable) { //delRSItems = UIHelper.createI18NButton("RESTBL_DEL_ITEMS"); delRSItems = UIHelper.createIconBtn("DelRec", "ESDelRowsTT", null); delRSItems.addActionListener(createRemoveItemAL()); delRSItems.setEnabled(false); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { delRSItems.setEnabled(table.getSelectedRowCount() > 0); } } }); } add(tablePane, BorderLayout.CENTER); moveToRSCmd = new DragSelectedRowsBtn(IconManager.getIcon("Record_Set", IconManager.IconSize.Std16)); if (installServices) { PanelBuilder bottomBar = new PanelBuilder( new FormLayout("4px,p,4px,p,4px,p," + (delRSItems != null ? "4px,p," : "") + "f:p:g", "p")); bottomBar.add(moveToRSCmd, cc.xy(2, 1)); bottomBar.add(selectAllBtn, cc.xy(4, 1)); bottomBar.add(deselectAllBtn, cc.xy(6, 1)); if (delRSItems != null) { bottomBar.add(delRSItems, cc.xy(8, 1)); } botBtnPanel = bottomBar.getPanel(); deselectAllBtn.setEnabled(false); selectAllBtn.setEnabled(true); moveToRSCmd.setEnabled(true); deselectAllBtn.setToolTipText(getResourceString("SELALLTOOLTIP")); selectAllBtn.setToolTipText(getResourceString("DESELALLTOOLTIP")); moveToRSCmd.setToolTipText(getResourceString("MOVEROWSTOOLTIP")); selectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { table.selectAll(); } }); deselectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { table.clearSelection(); } }); moveToRSCmd.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { RecordSetIFace src = (RecordSetIFace) moveToRSCmd.getData(); CommandDispatcher .dispatch(new CommandAction(RecordSetTask.RECORD_SET, "AskForNewRS", src, null, null)); } }); add(botBtnPanel, BorderLayout.SOUTH); } else { botBtnPanel = null; } expandBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { expandTable(false); } }); if (!isExpandedAtStartUp) { expandTable(true); } showTopNumEntriesBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { morePanel.setVisible(true); showTopNumEntriesBtn.setVisible(false); showingAllRows = false; setDisplayRows(rowCount, topNumEntries); // If it is collapsed then expand it if (!expandBtn.isDown()) { tablePane.setVisible(true); expandBtn.setDown(true); } // Make sure the layout is updated invalidate(); doLayout(); esrPane.revalidateScroll(); } }); if (closeBtn != null) { closeBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { removeMe(); } }); } }); } ResultSetTableModel rsm = createModel(); rsm.setPropertyListener(this); resultSetTableModel = rsm; table.setRowSorter(new TableRowSorter<ResultSetTableModel>(resultSetTableModel)); table.setRowSelectionAllowed(true); table.setModel(rsm); configColumns(); rowCount = rsm.getRowCount(); if (rowCount > topNumEntries + 2) { buildMorePanel(); setDisplayRows(rowCount, topNumEntries); } else { setDisplayRows(rowCount, Integer.MAX_VALUE); } invalidate(); doLayout(); UIRegistry.forceTopFrameRepaint(); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { if (botBtnPanel != null) { deselectAllBtn.setEnabled(table.getSelectedRowCount() > 0); selectAllBtn.setEnabled(table.getSelectedRowCount() != table.getRowCount()); moveToRSCmd.setEnabled(table.getSelectedRowCount() > 0); } } if (propChangeListener != null) { if (!e.getValueIsAdjusting()) { propChangeListener.propertyChange( new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0)); } else { propChangeListener.propertyChange( new PropertyChangeEvent(this, "selection", table.getSelectedRowCount(), 0)); } } } }); table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { //synchronized (((JTable)e.getSource()).getTreeLock()) //{ doDoubleClickOnRow(e); //} } }); // Horizontal Alignment is set later TableColumnModel tableColModel = table.getColumnModel(); for (int i = 0; i < tableColModel.getColumnCount(); i++) { tableColModel.getColumn(i).setCellRenderer(new BiColorTableCellRenderer()); } }
From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java
/** * /*from w w w .java 2 s. c om*/ */ protected void buildSpreadsheet() { this.setShowGrid(true); int numRows = model.getRowCount(); scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); setAutoResizeMode(JTable.AUTO_RESIZE_OFF); final SpreadSheet ss = this; JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll", new ActionListener() { public void actionPerformed(ActionEvent ae) { ss.selectAll(); } }); cornerBtn.setEnabled(true); scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn); // Allows row and collumn selections to exit at the same time setCellSelectionEnabled(true); setRowSelectionAllowed(true); setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent) */ @SuppressWarnings("synthetic-access") @Override public void mouseReleased(MouseEvent e) { // XXX For Java 5 Bug prevRowSelInx = getSelectedRow(); prevColSelInx = getSelectedColumn(); if (e.getClickCount() == 2) { int rowIndexStart = getSelectedRow(); int colIndexStart = getSelectedColumn(); ss.editCellAt(rowIndexStart, colIndexStart); if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) { ss.getEditorComponent().requestFocus(); final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent(); String txt = txtComp.getText(); FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont()); int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1; int prevWidth = 0; for (int i = 0; i < txt.length(); i++) { int width = fm.stringWidth(txt.substring(0, i)); int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5); //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf); //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i); if (x < width) { // Clearing the selection is needed for Window for some reason final int inx = i + (x <= basePlusHalf ? -1 : 0); SwingUtilities.invokeLater(new Runnable() { @SuppressWarnings("synthetic-access") public void run() { txtComp.setSelectionStart(0); txtComp.setSelectionEnd(0); txtComp.setCaretPosition(inx > 0 ? inx : 0); } }); break; } prevWidth = width; } } } } }); // Create a row-header to display row numbers. // This row-header is made of labels whose Borders, // Foregrounds, Backgrounds, and Fonts must be // the one used for the table column headers. // Also ensure that the row-header labels and the table // rows have the same height. //i have no idea WHY this has to be called. i rearranged //the table and find replace panel, // i started getting an array index out of //bounds on the column header ON MAC ONLY. //tried firing this off, first and it fixed the problem.//meg this.getModel().fireTableStructureChanged(); /* * Create the Row Header Panel */ rowHeaderPanel = new JPanel((LayoutManager) null); if (getColumnModel().getColumnCount() > 0) { TableColumn column = getColumnModel().getColumn(0); TableCellRenderer renderer = getTableHeader().getDefaultRenderer(); if (renderer == null) { renderer = column.getHeaderRenderer(); } Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, -1, 0); cellFont = cellRenderComp.getFont(); } else { cellFont = (new JLabel()).getFont(); } // Calculate Row Height cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder"); Insets insets = cellBorder.getBorderInsets(tableHeader); FontMetrics metrics = getFontMetrics(cellFont); rowHeight = insets.bottom + metrics.getHeight() + insets.top; rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left; Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows); rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used. rhCellMouseAdapter = new RHCellMouseAdapter(this); // Adding the row header labels for (int ii = 0; ii < numRows; ii++) { addRow(ii, ii + 1, false); } JViewport viewPort = new JViewport(); dim.height = rowHeight * numRows; viewPort.setViewSize(dim); viewPort.setView(rowHeaderPanel); scrollPane.setRowHeader(viewPort); // Experimental from the web, but I think it does the trick. addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown() && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB && e.getKeyCode() != KeyEvent.VK_ENTER) { log.error("Grabbed the event as input"); int rowIndexStart = getSelectedRow(); int colIndexStart = getSelectedColumn(); if (rowIndexStart == -1 || colIndexStart == -1) return; ss.editCellAt(rowIndexStart, colIndexStart); Component c = ss.getEditorComponent(); if (c instanceof JTextComponent) ((JTextComponent) c).setText(""); } } }); resizeAndRepaint(); // Taken from a JavaWorld Example (But it works) KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false); KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false); KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false); Action ssAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { SpreadSheet.this.actionPerformed(e); } }; getInputMap().put(cut, "Cut"); getActionMap().put("Cut", ssAction); getInputMap().put(copy, "Copy"); getActionMap().put("Copy", ssAction); getInputMap().put(paste, "Paste"); getActionMap().put("Paste", ssAction); ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this); ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this); ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this); setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED); }
From source file:it.cnr.icar.eric.client.ui.swing.RegistryObjectsTable.java
/** * Class Constructor.// w ww.j av a 2 s . com * * @param model * * @see */ public RegistryObjectsTable(TableModel model) { // Gives a TableColumnModel so that AutoCreateColumnsFromModel will be false. super(model, new DefaultTableColumnModel()); this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); if (model instanceof RegistryObjectsTableModel) { tableModel = (RegistryObjectsTableModel) model; } else if (model instanceof TableSorter) { tableModel = (RegistryObjectsTableModel) (((TableSorter) model).getModel()); } else { Object[] unexpectedTableModelArgs = { model }; MessageFormat form = new MessageFormat(resourceBundle.getString("error.unexpectedTableModel")); throw new IllegalArgumentException(form.format(unexpectedTableModelArgs)); } setToolTipText(resourceBundle.getString("tip.registryObjectsTable")); setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); ListSelectionModel rowSM = getSelectionModel(); stdRowHeight = getRowHeight(); setRowHeight(stdRowHeight * 3); rowSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (!lsm.isSelectionEmpty()) { setSelectedRow(lsm.getMinSelectionIndex()); } else { setSelectedRow(-1); } } }); createPopup(); addRenderers(); // Add listener to self so that I can bring up popup menus on right mouse click popupListener = new PopupListener(); addMouseListener(popupListener); //add listener for 'authenticated' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_AUTHENTICATED, this); //add listener for 'locale' bound property RegistryBrowser.getInstance().addPropertyChangeListener(RegistryBrowser.PROPERTY_LOCALE, this); }
From source file:com.vgi.mafscaling.ClosedLoop.java
private void createLogDataTable(JScrollPane dataScrollPane) { JPanel dataRunPanel = new JPanel(); dataScrollPane.setViewportView(dataRunPanel); GridBagLayout gbl_dataRunPanel = new GridBagLayout(); gbl_dataRunPanel.columnWidths = new int[] { 0 }; gbl_dataRunPanel.rowHeights = new int[] { 0 }; gbl_dataRunPanel.columnWeights = new double[] { 0.0 }; gbl_dataRunPanel.rowWeights = new double[] { 0.0 }; dataRunPanel.setLayout(gbl_dataRunPanel); logDataTable = new JTable(); logDataTable.getTableHeader().setReorderingAllowed(false); logDataTable.setModel(new DefaultTableModel(LogDataRowCount, ColumnCount)); logDataTable.setColumnSelectionAllowed(true); logDataTable.setCellSelectionEnabled(true); logDataTable.setBorder(new LineBorder(new Color(0, 0, 0))); logDataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); logDataTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); logDataTable.getColumnModel().getColumn(0).setHeaderValue("Time"); logDataTable.getColumnModel().getColumn(1).setHeaderValue("Load"); logDataTable.getColumnModel().getColumn(2).setHeaderValue("RPM"); logDataTable.getColumnModel().getColumn(3).setHeaderValue("MafV"); logDataTable.getColumnModel().getColumn(4).setHeaderValue("AFR"); logDataTable.getColumnModel().getColumn(5).setHeaderValue("STFT"); logDataTable.getColumnModel().getColumn(6).setHeaderValue("LTFT"); logDataTable.getColumnModel().getColumn(7).setHeaderValue("dV/dt"); logDataTable.getColumnModel().getColumn(8).setHeaderValue("IAT"); Utils.initializeTable(logDataTable, ColumnWidth); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(0, 0, 0, 0); gbc.anchor = GridBagConstraints.PAGE_START; gbc.gridx = 0;//from w w w . ja v a 2s . c o m gbc.gridy = 0; dataRunPanel.add(logDataTable.getTableHeader(), gbc); gbc.gridy = 1; dataRunPanel.add(logDataTable, gbc); excelAdapter.addTable(logDataTable, true, false); }
From source file:edu.ku.brc.specify.tasks.subpane.VisualQueryPanel.java
/** * Creates the UI./* w w w. j a va 2 s.c o m*/ */ protected void createUI() { CellConstraints cc = new CellConstraints(); lineLayer = new RenderableLayer(); upBtn = UIHelper.createIconBtn("Green Arrow Up", "", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { moveItems(recSetList, botIdHash, dbObjList, topIdHash); } }); dwnBtn = UIHelper.createIconBtn("Green Arrow Down", "", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { moveItems(dbObjList, topIdHash, recSetList, botIdHash); boolean hasItems = recSetList.getModel().getSize() > 0; rsBtn.setEnabled(hasItems); fmBtn.setEnabled(hasItems); } }); selectAllBtn = UIHelper.createI18NButton("SELECTALL"); selectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dbObjList.clearSelection(); dbObjList.getSelectionModel().setSelectionInterval(0, dbObjList.getModel().getSize()); } }); deselectAllBtn = UIHelper.createI18NButton("DESELECTALL"); deselectAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dbObjList.clearSelection(); } }); PanelBuilder upDwnPB = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g,p,10px,p,f:p:g,p,f:p:g", "p")); //upDwnPB.add(selectAllBtn, cc.xy(2,1)); upDwnPB.add(dwnBtn, cc.xy(4, 1)); upDwnPB.add(upBtn, cc.xy(6, 1)); //upDwnPB.add(deselectAllBtn, cc.xy(7,1)); dbObjList = new JList(new DefaultListModel()); dbObjList.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //wpList.setCellRenderer(new WPListCellRenderer()); dbObjList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { upBtn.setEnabled(false); dwnBtn.setEnabled(dbObjList.getSelectedIndex() != -1); } }); recSetList = new JList(new DefaultListModel()); recSetList.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //trkList.setCellRenderer(new TrkListCellRenderer()); recSetList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { boolean isSel = recSetList.getSelectedIndex() != -1; dwnBtn.setEnabled(false); upBtn.setEnabled(isSel); } }); rsBtn = UIHelper.createIconBtn("Record_Set", IconManager.IconSize.Std24, "", null); fmBtn = UIHelper.createIconBtn("FormEdit", IconManager.IconSize.Std24, "", null); PanelBuilder toolsBtnPB = new PanelBuilder(new FormLayout("f:p:g,2px,p,2px,p", "p")); toolsBtnPB.add(fmBtn, cc.xy(3, 1)); toolsBtnPB.add(rsBtn, cc.xy(5, 1)); PanelBuilder leftPB = new PanelBuilder( new FormLayout("min(p;250px),10px,f:p:g", "p,2px,f:p:g, 4px,p,4px, p,2px,f:p:g, 2px,p")); int y = 1; leftPB.add(topLbl = UIHelper.createLabel("Available Points"), cc.xy(1, y)); y += 2; // I18N leftPB.add(UIHelper.createScrollPane(dbObjList, true), cc.xy(1, y)); y += 2; leftPB.add(upDwnPB.getPanel(), cc.xy(1, y)); y += 2; leftPB.add(UIHelper.createLabel("Selected Objects"), cc.xy(1, y)); y += 2; leftPB.add(UIHelper.createScrollPane(recSetList, true), cc.xy(1, y)); y += 2; leftPB.add(toolsBtnPB.getPanel(), cc.xy(1, y)); y += 2; wwPanel = new WorldWindPanel(); wwPanel.setPreferredSize(new Dimension(MAP_WIDTH, MAP_HEIGHT)); wwPanel.getWorld().addSelectListener(new ClickAndGoSelectListener(wwPanel.getWorld(), MarkerLayer.class)); //wwPanel.getWorld().addSelectListener(getWWSelectListener()); //wwPanel.getWorld().getInputHandler().addMouseListener(getWWMouseAdapter()); PanelBuilder rightPB = new PanelBuilder(new FormLayout("f:p:g", "f:p:g")); // ZZZ lineBuilder = new LineBuilder(wwPanel.getWorld(), lineLayer, polyline); rightPB.add(wwPanel, cc.xy(1, 1)); y += 2; polyline.setAntiAliasHint(Polyline.ANTIALIAS_NICEST); polyline.setLineWidth(1.5); polyline.setFollowTerrain(true); startBtn = UIHelper.createI18NButton("Start"); endBtn = UIHelper.createI18NButton("End"); searchBtn = UIHelper.createI18NButton("SEARCH"); clearAllBtn = UIHelper.createI18NButton("Clear All"); clearSearchBtn = UIHelper.createI18NButton("Clear Search"); typeCBX = UIHelper.createComboBox(TABLE_INFO); PanelBuilder btnPB = new PanelBuilder( new FormLayout("f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g", "p")); btnPB.add(typeCBX, cc.xy(2, 1)); btnPB.add(startBtn, cc.xy(4, 1)); btnPB.add(endBtn, cc.xy(6, 1)); btnPB.add(searchBtn, cc.xy(8, 1)); btnPB.add(clearSearchBtn, cc.xy(10, 1)); btnPB.add(clearAllBtn, cc.xy(12, 1)); PanelBuilder pb = new PanelBuilder(new FormLayout("p,10px,f:p:g", "f:p:g, 4px, p"), this); pb.add(leftPB.getPanel(), cc.xy(1, 1)); pb.add(rightPB.getPanel(), cc.xy(3, 1)); pb.add(btnPB.getPanel(), cc.xyw(1, 3, 3)); pb.setDefaultDialogBorder(); startBtn.setEnabled(true); endBtn.setEnabled(false); searchBtn.setEnabled(false); clearAllBtn.setEnabled(false); clearSearchBtn.setEnabled(false); rsBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { RecordSetIFace rs = createRecordSet(); if (rs != null) { CommandDispatcher.dispatch(new CommandAction(RecordSetTask.RECORD_SET, "Save", null, null, rs)); } } }); fmBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { RecordSetIFace rs = createRecordSet(); if (rs != null) { CommandDispatcher .dispatch(new CommandAction(DataEntryTask.DATA_ENTRY, DataEntryTask.EDIT_DATA, rs)); } } }); searchBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { doSearch(); } catch (IOException e1) { e1.printStackTrace(); } } }); startBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (true) { //doSearch(); //return; } /* double lat = 37.24517; double lon = -100.99083; double[] p = new double[] {-100.90805562872109,37.24714676134192, -101.1442623355922,37.15441022126542, -100.78757107464702,37.1712467680786, -100.90570697458969,37.24401619379327, -100.90805562872109,37.24714676134192}; ArrayList<Position> list = new ArrayList<Position>(); for (int i=0;i<p.length;i++) { Position pos = Position.fromDegrees(p[i+1], p[i], 0); list.add(pos); i++; } polygon = new Polyline(list); polygon.setClosed(true); Position pos = Position.fromDegrees(lat, lon, 0.0); System.out.println("isLocationInside: "+GeometryMath.isLocationInside(pos, polygon.getPositions())); */ //polygonWWPoints.clear(); isCreatingPolygon = true; searchBtn.setEnabled(false); endBtn.setEnabled(true); startBtn.setEnabled(false); // ZZZ lineBuilder.setArmed(true); } }); endBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { polyline.setClosed(true); isCreatingPolygon = false; searchBtn.setEnabled(true); endBtn.setEnabled(false); startBtn.setEnabled(false); searchBtn.setEnabled(true); clearAllBtn.setEnabled(true); clearSearchBtn.setEnabled(true); //polygonWWPoints.add(polygonWWPoints.get(0)); //createPolyline(); // ZZZ lineBuilder.setArmed(false); } }); clearAllBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doClearAll(true); } }); clearSearchBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doClearAll(false); } }); typeCBX.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doPickedNewObjType(); } }); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { typeCBX.setSelectedIndex(0); } }); }
From source file:com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.java
public AbstractPieChartPlotter(final PlotterConfigurationModel settings) { super(settings); setBackground(Color.white);//from w w w .j a v a2s . c o m useDistinct = new ListeningJCheckBox("_" + PARAMETERS_USE_DISTINCT, "Use Only Distinct", false); useDistinct.setToolTipText("Indicates if only distinct values should be used for aggregation functions."); useDistinct.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { settings.setParameterAsBoolean(PARAMETERS_USE_DISTINCT, useDistinct.isSelected()); } }); String[] allFunctions = new String[AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES.length + 1]; allFunctions[0] = "none"; System.arraycopy(AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES, 0, allFunctions, 1, AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES.length); aggregationFunction = new ListeningJComboBox(settings, "_" + PARAMETERS_AGGREGATION, allFunctions); aggregationFunction.setToolTipText( "Select the type of the aggregation function which should be used for grouped values."); aggregationFunction.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { settings.setParameterAsString(PARAMETERS_AGGREGATION, aggregationFunction.getSelectedItem().toString()); } }); for (int i = 0; i < allFunctions.length; i++) { if (allFunctions[i].equals("count")) { aggregationFunction.setSelectedIndex(i); } } explodingGroupList = new ExtendedJList(new ExtendedListModel(), 200); explodingGroupListSelectionModel = new ListeningListSelectionModel("_" + PARAMETERS_EXPLOSION_GROUPS, explodingGroupList); explodingGroupList.setSelectionModel(explodingGroupListSelectionModel); explodingGroupList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object[] values = explodingGroupList.getSelectedValues(); List<String> list = new LinkedList<String>(); for (Object object : values) { list.add((String) object); } String result = ParameterTypeEnumeration.transformEnumeration2String(list); settings.setParameterAsString(PARAMETERS_EXPLOSION_GROUPS, result); } } }); explodingGroupList.setForeground(Color.BLACK); explodingGroupList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); explodingGroupList.setBorder(BorderFactory.createLoweredBevelBorder()); explodingGroupList.setCellRenderer(new PlotterPanel.LineStyleCellRenderer(this)); updateGroups(); explodingSlider = new ListeningJSlider("_" + PARAMETERS_EXPLOSION_AMOUNT, 0, 100, 0); explodingSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { settings.setParameterAsInt(PARAMETERS_EXPLOSION_AMOUNT, explodingSlider.getValue()); } }); }
From source file:com.eviware.soapui.impl.wsdl.monitor.SoapMonitor.java
private JComponent buildLog() { tableModel = new MonitorLogTableModel(); logTable = new JXTable(1, 2); logTable.setColumnControlVisible(true); logTable.setModel(tableModel); logTable.setHorizontalScrollEnabled(true); logTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); operationFilter = new PatternFilter(".*", 0, 4); operationFilter.setAcceptNull(true); interfaceFilter = new PatternFilter(".*", 0, 3); interfaceFilter.setAcceptNull(true); targetHostFilter = new PatternFilter(".*", 0, 2); targetHostFilter.setAcceptNull(true); requestHostFilter = new PatternFilter(".*", 0, 1); requestHostFilter.setAcceptNull(true); Filter[] filters = new Filter[] { requestHostFilter, targetHostFilter, interfaceFilter, operationFilter }; FilterPipeline pipeline = new FilterPipeline(filters); logTable.setFilters(pipeline);/*from ww w. j av a 2 s. c o m*/ ListSelectionModel sel = logTable.getSelectionModel(); sel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent event) { int row = logTable.getSelectedRow(); if (row == -1) { // requestXmlDocument.setXml( null ); // responseXmlDocument.setXml( null ); requestModelItem.setMessageExchange(null); } else { WsdlMonitorMessageExchange exchange = tableModel.getMessageExchangeAt(row); requestModelItem.setMessageExchange(exchange); // responseModelItem.setMessageExchange( exchange ); // requestXmlDocument.setXml( exchange.getRequestContent() ); // responseXmlDocument.setXml( exchange.getResponseContent() ); } addToMockServiceButton.setEnabled(row != -1); addToTestCaseButton.setEnabled(row != -1); // addToRestTestCaseButton.setEnabled( row != -1 ); createRequestButton.setEnabled(row != -1); } }); JPanel tablePane = new JPanel(); tablePane.setLayout(new BorderLayout()); toolbar.addGlue(); tablePane.add(buildFilterBar(), BorderLayout.NORTH); tablePane.add(new JScrollPane(logTable), BorderLayout.CENTER); return tablePane; }
From source file:de.codesourcery.eve.skills.ui.components.impl.ItemChooserComponent.java
private JPanel createListViewPanel() { final JPanel result = new JPanel(); result.setLayout(new GridBagLayout()); // create button panel final JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridBagLayout()); final JButton addButton = new JButton("====>"); final JButton removeButton = new JButton("<===="); final ActionListener buttonListener = new ActionListener() { @Override// w w w . j a va 2 s. c o m public void actionPerformed(ActionEvent e) { if (e.getSource() == addButton) { addButtonClicked(); } else if (e.getSource() == removeButton) { removeButtonClicked(); } else { throw new RuntimeException("Unhandled event source " + e.getSource()); } } }; addButton.addActionListener(buttonListener); removeButton.addActionListener(buttonListener); buttonPanel.add(addButton, constraints(0, 0).noResizing().end()); buttonPanel.add(removeButton, constraints(0, 1).noResizing().end()); // create list panel itemTable.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); itemTable.setModel(selectedItemsModel); itemTable.setRowSorter(selectedItemsModel.getRowSorter()); result.add(buttonPanel, constraints(0, 0).useRelativeWidth().resizeBoth().end()); result.add(new JScrollPane(itemTable), constraints(1, 0).useRemainingWidth().resizeBoth().end()); return result; }