private void initMasterTable() { EntityTableModel etm = new EntityTableModel(); etm.addColumn("Nombre", "nombre"); etm.addColumn("Descripcion", "descripcion"); etm.addColumn("Costo", "costo"); masterTable.setModel(etm); }
private JComponent createDetailsPanel() { final TableFormat<Pago> tf = CXCTableFormats.getPagoConVentaTF(); final EventList<Pago> pagos = model.getPagos(); final SortedList<Pago> spagos = new SortedList<Pago>(pagos, null); final EventTableModel<Pago> tm = new EventTableModel<Pago>(spagos, tf); selectionModel = new EventSelectionModel<Pago>(spagos); grid = ComponentUtils.getStandardTable(); grid.setModel(tm); grid.setSelectionModel(selectionModel); new TableComparatorChooser<Pago>(grid, spagos, true); ComponentUtils.decorateActions(grid); ComponentUtils.addInsertAction(grid, getInsertAction()); ComponentUtils.addDeleteAction(grid, getDeleteAction()); grid.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) view(); } }); grid.getColumn("Desc (%)").setCellRenderer(Renderers.getPorcentageRenderer()); grid.getColumn("Cgo").setCellRenderer(Renderers.getPorcentageRenderer()); grid.getColumn("Desc Aplic").setCellRenderer(Renderers.getCantidadNormalTableCellRenderer()); final JScrollPane sp = new JScrollPane(grid); return sp; }
/** * Metodo para construir el grid. Subclaseses recomendable que ejecuten super.buildGrid antes de * iniciar una personalizacion de este metodo * * @return */ protected JXTable buildGrid() { final EventTableModel<T> tm = new EventTableModel<T>(sortedSource, getTableFormat()); selectionModel = new EventSelectionModel(sortedSource); selectionModel.setSelectionMode(getSelectionMode()); final JXTable grid = ComponentUtils.getStandardTable(); grid.setModel(tm); grid.setSelectionModel(selectionModel); final Action select = new AbstractAction() { public void actionPerformed(ActionEvent e) { doSelect(); } }; ComponentUtils.addEnterAction(grid, select); grid.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) doSelect(); } }); // new TableComparatorChooser(grid,sortedSource,true); TableComparatorChooser.install( grid, sortedSource, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE); grid.packAll(); return grid; }
public void refresh() { Iterable<Property> properties = Collections.emptyList(); if (beanHelper != null) { Image icon = beanHelper.getIcon(BeanInfo.ICON_COLOR_32x32); if (icon == null) { remove(top); } else { JXImageView logo = new JXImageView(); logo.setImage(icon); add(logo, BorderLayout.NORTH); } properties = filter( beanHelper.getProperties(), new Predicate<Property>() { @Override public boolean apply(Property input) { return !input.isHidden(); } }); } table.setModel(new MyTableModel(properties)); // should we expose minimum row/column sizes as a user property? table.setRowHeight(18); // essentially the minimum row height table.getColumnModel().getColumn(0).setMinWidth(1); table.getColumnModel().getColumn(0).setMaxWidth(1); table.getColumnModel().getColumn(1).setMinWidth(1); table.packAll(); revalidate(); }
// Initialize JTable private void initTable() { DialogTableModel tblModel = new DialogTableModel(students); studentsTbl.setModel(tblModel); studentsTbl.setAutoCreateRowSorter(true); studentsTbl.setRowSelectionAllowed(true); studentsTbl.getRowSorter().toggleSortOrder(1); studentsTbl.setGridColor(Color.gray); studentsTbl.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); studentsTbl.setRowHeight(22); TableColumn tc = studentsTbl.getColumnModel().getColumn(0); tc.setCellEditor(studentsTbl.getDefaultEditor(Boolean.class)); tc.setCellRenderer(studentsTbl.getDefaultRenderer(Boolean.class)); tc.setHeaderRenderer( new CheckBoxTableHeader( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { Object source = e.getSource(); if (source instanceof AbstractButton == false) { return; } boolean checked = e.getStateChange() == ItemEvent.SELECTED; for (int x = 0, y = studentsTbl.getRowCount(); x < y; x++) { studentsTbl.setValueAt(new Boolean(checked), x, 0); } } })); }
private JComponent buildGridPanel() { final String[] props = { "clave", "factura.numero", "factura.fecha", "factura.tipo", "factura.total", "factura.pagos", "factura.devolucionesCred", "factura.saldo", "factura.descuentoPactado", "factura.cargo", "importe" }; final String[] cols = { "Cliente", "Factura", "Fecha", "T", "Total", "Pagos", "Devoluciones", "Saldo", "Desc", "Cargo", "Importe" }; final TableFormat<NotasDeCreditoDet> tf = GlazedLists.tableFormat(NotasDeCreditoDet.class, props, cols); final SortedList<NotasDeCreditoDet> sortedList = new SortedList<NotasDeCreditoDet>(model.getPartidas(), null); final EventTableModel<NotasDeCreditoDet> tm = new EventTableModel<NotasDeCreditoDet>(sortedList, tf); final EventSelectionModel<NotasDeCreditoDet> selectionModel = new EventSelectionModel<NotasDeCreditoDet>(sortedList); selectionModel.setSelectionMode(ListSelection.SINGLE_SELECTION); final Action deleteAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (!selectionModel.getSelected().isEmpty()) { selectionModel.getSelected().remove(0); if (sortedList.isEmpty()) getOKAction().setEnabled(false); } } }; grid = ComponentUtils.getStandardTable(); grid.setModel(tm); grid.packAll(); grid.setSelectionModel(selectionModel); ComponentUtils.addDeleteAction(grid, deleteAction); JScrollPane sp = new JScrollPane(grid); return sp; }
/** * Creates new form FortfuehrungsanlaesseDialog. * * @param parent DOCUMENT ME! * @param modal DOCUMENT ME! */ private FortfuehrungsanlaesseDialog(final Frame parent, final boolean modal) { super(parent, modal); initComponents(); final Highlighter istAbgearbeitetHighlighter = new IstAbgearbeitetHighlighter(); jXTable1.setHighlighters(istAbgearbeitetHighlighter); jXTable1.setModel(new FortfuehrungenTableModel()); jXTable1 .getColumnModel() .getColumn(0) .setCellRenderer(jXTable1.getDefaultRenderer(String.class)); jXTable1 .getColumnModel() .getColumn(1) .setCellRenderer(jXTable1.getDefaultRenderer(String.class)); jXTable1 .getColumnModel() .getColumn(2) .setCellRenderer(jXTable1.getDefaultRenderer(String.class)); jXTable1.getColumnModel().getColumn(0).setPreferredWidth(100); jXTable1.getColumnModel().getColumn(1).setPreferredWidth(150); jXTable1.getColumnModel().getColumn(2).setPreferredWidth(200); jXTable1.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jXTable1.setDragEnabled(false); jXTable1.getTableHeader().setResizingAllowed(true); jXTable1.getTableHeader().setReorderingAllowed(false); // jXTable1.setSortOrder(1, SortOrder.ASCENDING); jXTable1 .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { // If cell selection is enabled, both row and column change events are fired if ((e.getSource() == jXTable1.getSelectionModel()) && jXTable1.getRowSelectionAllowed()) { fortfuehrungsTableListSelectionChanged(e); } } }); jProgressBar1.setVisible(false); }
/** * Lager tabell for avregningimport * * @return tabell */ public JXTable getTableImport() { table = new JXTable(); table.setModel(new DeductImportTableModel(deductImportSelectionList)); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setSelectionModel( new SingleListSelectionAdapter(deductImportSelectionList.getSelectionIndexHolder())); table.setColumnControlVisible(true); deductImportSelectionList.clearSelection(); table.packAll(); table.setSortable(true); return table; }
/** * Lager tabell for rapport * * @return tabell */ public JXTable getTableReport() { table = new JXTable(); tableModel = new ReconcilTableModel(reportSelectionList); table.setModel(tableModel); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setColumnControlVisible(true); table.setSearchable(null); table.setDragEnabled(false); table.setShowGrid(true); table.packAll(); return table; }
public JXTable createConfigureDecadeDetailsTable(LinkTableModel model) { JXTable table = new JXTable(); table.setCellSelectionEnabled(true); table.setFont(monthView.getFont()); table.setShowGrid(false, false); table.setTableHeader(null); table.setDefaultRenderer( Date.class, createDateRenderer(model.selectAction, monthPaddingBorder, JLabel.CENTER)); table.setHighlighters(createCurrentDateHighlighters()); table.setModel(model); Component comp = table.prepareRenderer(table.getCellRenderer(1, 1), 1, 1); table.setRowHeight(comp.getPreferredSize().height); return table; }
public JXTable createConfigureMonthDetailsTable(LinkTableModel dateTableModel) { JXTable table = new JXTable(); table.setCellSelectionEnabled(true); table.setVisibleRowCount(6); table.setFont(monthView.getFont()); table.setShowGrid(false, false); configureDayOfWeeksHeader(table); table.setDefaultRenderer( Date.class, createDateRenderer(dateTableModel.selectAction, paddingBoxBorder, JLabel.TRAILING)); table.setHighlighters(createCurrentDateHighlighters()); table.setModel(dateTableModel); table.packAll(); Component comp = table.prepareRenderer(table.getCellRenderer(1, 1), 1, 1); table.setRowHeight(comp.getPreferredSize().height); return table; }
private void init_tbl_branch_locations() { tbl_branch_locations_ALM = new ArrayListModel(); tbl_branch_locations_M = new Tblbranch_locationsModel(tbl_branch_locations_ALM); tbl_branch_locations.getTableHeader().setPreferredSize(new Dimension(100, 40)); tbl_branch_locations.setModel(tbl_branch_locations_M); tbl_branch_locations.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); tbl_branch_locations.setRowHeight(25); int[] tbl_widths_branch_locations = {200, 200, 70, 0, 0, 0}; for (int i = 0, n = tbl_widths_branch_locations.length; i < n; i++) { if (i == 0) { continue; } TableWidthUtilities.setColumnWidth(tbl_branch_locations, i, tbl_widths_branch_locations[i]); } Dimension d = tbl_branch_locations.getTableHeader().getPreferredSize(); d.height = 25; tbl_branch_locations.getTableHeader().setPreferredSize(d); tbl_branch_locations.getTableHeader().setFont(new java.awt.Font("Arial", 0, 11)); tbl_branch_locations.setRowHeight(25); tbl_branch_locations.setFont(new java.awt.Font("Arial", 0, 11)); }
protected JComponent buildGridPanel() { grid = ComponentUtils.getStandardTable(); grid.setColumnControlVisible(false); source = new BasicEventList(); final EventList<MatcherEditor> editors = new BasicEventList<MatcherEditor>(); editors.add( new TextComponentMatcherEditor( inputField, GlazedLists.textFilterator( new String[] {"documento", "sucursal.nombre", "clave", "nombre"}))); final MatcherEditor editor = new CompositeMatcherEditor(editors); final FilterList filterList = new FilterList(source, new ThreadedMatcherEditor(editor)); SortedList sorted = new SortedList(filterList, null); final EventTableModel tm = new EventTableModel(sorted, getTableFormat()); selectionModel = new EventSelectionModel(sorted); grid.setModel(tm); TableComparatorChooser.install(grid, sorted, TableComparatorChooser.MULTIPLE_COLUMN_MOUSE); grid.setSelectionModel(selectionModel); final Action select = new AbstractAction() { public void actionPerformed(ActionEvent e) { doSelect(); } }; ComponentUtils.addEnterAction(grid, select); grid.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) doSelect(); } }); grid.packAll(); JComponent c = ComponentUtils.createTablePanel(grid); c.setPreferredSize(new Dimension(750, 400)); return c; }
public void setModel(FilterModel model) { super.setModel(model); this.model = model; getColumn(1).setCellRenderer(new RemoveButtonRenderer(this)); getColumn(1).setCellEditor(new RemoveButtonRenderer(this)); }
/** Initialize the GUI */ private void init() { setLayout(new BorderLayout(0, 0)); JPanel panelMain = new JPanel(); add(panelMain, BorderLayout.CENTER); panelMain.setLayout(new MigLayout("", "[grow]", "[grow]")); JScrollPane scrollPane = new JScrollPane(); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); panelMain.add(scrollPane, "cell 0 0,grow"); table = new JXTable() { private static final long serialVersionUID = 1L; public void changeSelection( final int row, final int column, boolean toggle, boolean extend) { super.changeSelection(row, column, toggle, extend); if (table.isCellEditable(row, column)) { editCellAt(row, column); } } }; table.setHorizontalScrollEnabled(true); table.setColumnControlVisible(true); model = new SeriesIdentityTableModel(containerFrame); SeriesIdentityTableCellRenderer renderer = new SeriesIdentityTableCellRenderer(); table.setModel(model); table.getColumn(3).setCellRenderer(renderer); table.getColumn(4).setCellRenderer(renderer); table.getColumn(5).setCellRenderer(renderer); table.getColumn(6).setCellRenderer(renderer); table.getColumn(7).setCellRenderer(renderer); table.getColumn(8).setCellRenderer(renderer); table.getColumnExt(4).setIdentifier("SubObjectColumn"); table.getColumnExt("SubObjectColumn").setVisible(false); table .getColumnModel() .addColumnModelListener( new TableColumnModelListener() { @Override public void columnAdded(TableColumnModelEvent arg0) { chkIncludeSubobjects.setSelected(table.getColumnExt("SubObjectColumn").isVisible()); } @Override public void columnMarginChanged(ChangeEvent arg0) { // TODO Auto-generated method stub } @Override public void columnMoved(TableColumnModelEvent arg0) { // TODO Auto-generated method stub } @Override public void columnRemoved(TableColumnModelEvent arg0) { chkIncludeSubobjects.setSelected(table.getColumnExt("SubObjectColumn").isVisible()); } @Override public void columnSelectionChanged(ListSelectionEvent arg0) { // TODO Auto-generated method stub } }); scrollPane.setViewportView(table); JPanel panelButton = new JPanel(); add(panelButton, BorderLayout.SOUTH); panelButton.setLayout(new MigLayout("", "[grow][][]", "[grow][grow][][][]")); model.addTableModelListener(this); JPanel panel = new JPanel(); panelButton.add(panel, "cell 0 1 1 2,grow"); panel.setLayout(new MigLayout("", "[31px][162px]", "[16px][][]")); JLabel lblKey = new JLabel("Key:"); panel.add(lblKey, "cell 0 0,alignx left,aligny top"); JLabel lblPresentIn = new JLabel("= Present in database"); lblPresentIn.setFont(new Font("Dialog", Font.PLAIN, 12)); lblPresentIn.setIcon(Builder.getIcon("found.png", 16)); panel.add(lblPresentIn, "flowy,cell 1 0,alignx left,aligny top"); JLabel lblAbsentFrom = new JLabel("= Absent from database"); lblAbsentFrom.setFont(new Font("Dialog", Font.PLAIN, 12)); lblAbsentFrom.setIcon(Builder.getIcon("missing.png", 16)); panel.add(lblAbsentFrom, "cell 1 1,alignx left,aligny top"); JLabel lblNotYet = new JLabel("= Not yet searched"); lblNotYet.setFont(new Font("Dialog", Font.PLAIN, 12)); lblNotYet.setIcon(Builder.getIcon("wait.png", 16)); panel.add(lblNotYet, "cell 1 2,alignx left,aligny top"); JPanel panel_1 = new JPanel(); panelButton.add(panel_1, "cell 1 1 2 2,alignx right,growy"); panel_1.setLayout(new MigLayout("", "[116px,fill]", "[22px][][][]")); JButton btnSearchDB = new JButton("Search Database"); btnSearchDB.setFont(new Font("Dialog", Font.BOLD, 9)); panel_1.add(btnSearchDB, "cell 0 0,alignx left,aligny top"); btnSearchDB.setActionCommand("SearchDB"); JButton btnDefineByPattern = new JButton("Define names by pattern"); btnDefineByPattern.setFont(new Font("Dialog", Font.BOLD, 9)); panel_1.add(btnDefineByPattern, "cell 0 1,alignx left,aligny top"); btnDefineByPattern.setActionCommand("DefineByPattern"); JButton btnGenerateMissing = new JButton("Generate missing entities"); btnGenerateMissing.setActionCommand("GenerateMissing"); btnGenerateMissing.addActionListener(this); JButton btnSetDefaults = new JButton("Set default parameters"); btnSetDefaults.setActionCommand("SetDefaults"); btnSetDefaults.addActionListener(this); btnSetDefaults.setFont(new Font("Dialog", Font.BOLD, 9)); panel_1.add(btnSetDefaults, "cell 0 2"); btnGenerateMissing.setFont(new Font("Dialog", Font.BOLD, 9)); panel_1.add(btnGenerateMissing, "flowy,cell 0 3"); btnDefineByPattern.addActionListener(this); btnSearchDB.addActionListener(this); chkIncludeSubobjects = new JCheckBox("Include sub-objects in import"); chkIncludeSubobjects.addActionListener(this); chkIncludeSubobjects.setActionCommand("IncludeExcludeSubObjects"); panelButton.add(chkIncludeSubobjects, "cell 0 3"); chckbxOpenSeriesIn = new JCheckBox("Open series in editor when finished"); chckbxOpenSeriesIn.setSelected(true); panelButton.add(chckbxOpenSeriesIn, "cell 0 4"); }
@SuppressWarnings("unchecked") private void initComponents() { org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance( insalmo_instream_gui.InsalmoInstreamApp.class) .getContext() .getResourceMap(ShowErrorsWarnings.class); // CLOSE closeButton.setName("closeButton"); closeButton.setText(resourceMap.getString("closeButton.text")); closeButton.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { closeButtonActionPerfomed(evt); } }); showErrorWarningsPanel = new javax.swing.JPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setName("showErrorsWarnings"); // ERROR/WARNING TABLE errorTable = this.createXTable(); errorTable.setName("errorTable"); errorTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); DefaultTableModel dataModel = new DefaultTableModel() { Class[] types = new Class[] { java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, Parameter.class }; boolean[] canEdit = new boolean[] {false, false, false, false, false, false}; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }; dataModel.setColumnIdentifiers( new String[] {"", "Parameter", "Value", "Location", "Message", "Parameter Object"}); for (Parameter p : this.openProject.getErrors()) { String filename; if (p.getSource().getClass().equals(SetupParameters.class)) { filename = ((SetupParameters) p.getSource()).getFileName(); } else { filename = "Experiment.Setup"; } dataModel.addRow( new Object[] { "Error", p.getParameterName(), p.getParameterValue(), filename, p.getValidationMessage(), p }); } for (Parameter p : this.openProject.getWarnings()) { String filename; if (p.getSource().getClass().equals(SetupParameters.class)) { filename = ((SetupParameters) p.getSource()).getFileName(); } else { filename = "Experiment.Setup"; } dataModel.addRow( new Object[] { "Warning", p.getParameterName(), p.getParameterValue(), filename, p.getValidationMessage(), p }); } errorTable.setModel(dataModel); errorTable.getColumnExt("Parameter Object").setVisible(false); errorTable.addMouseListener( new MouseListener() { public void mouseClicked(MouseEvent e) { forwardEventToButton(e); } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); tableScrollPane.setViewportView(errorTable); // LABEL errorLabel.setText(resourceMap.getString("errorLabel.text")); javax.swing.GroupLayout showErrorWarningsTypeLayout = new javax.swing.GroupLayout(showErrorWarningsPanel); showErrorWarningsPanel.setLayout(showErrorWarningsTypeLayout); showErrorWarningsTypeLayout.setHorizontalGroup( showErrorWarningsTypeLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( showErrorWarningsTypeLayout .createSequentialGroup() .addContainerGap() .addGroup( showErrorWarningsTypeLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(errorLabel) .addComponent(tableScrollPane) .addComponent(closeButton)) .addContainerGap())); showErrorWarningsTypeLayout.setVerticalGroup( showErrorWarningsTypeLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( showErrorWarningsTypeLayout .createSequentialGroup() .addContainerGap() .addComponent(errorLabel) .addComponent(tableScrollPane) .addComponent(closeButton) .addContainerGap())); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addComponent( showErrorWarningsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap())); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( layout .createSequentialGroup() .addContainerGap() .addComponent( showErrorWarningsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); pack(); }
public AttachmentsView(@Service ApplicationContext context, @Uses AttachmentsModel model) { setLayout(new BorderLayout()); final ActionMap am = context.getActionMap(this); this.attachmentsModel = model; TableFormat tableFormat = new AttachmentsTableFormatter(); tableModel = new EventJXTableModel<AttachmentDTO>(attachmentsModel.getEventList(), tableFormat); attachments = new JXTable(tableModel); attachments.setFocusTraversalKeys( KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, KeyboardFocusManager.getCurrentKeyboardFocusManager() .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS)); attachments.setFocusTraversalKeys( KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, KeyboardFocusManager.getCurrentKeyboardFocusManager() .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS)); attachments.getColumn(0).setPreferredWidth(20); attachments.getColumn(0).setMaxWidth(20); attachments.getColumn(0).setResizable(false); attachments.getColumn(2).setPreferredWidth(100); attachments.getColumn(2).setMaxWidth(100); attachments.getColumn(3).setPreferredWidth(100); attachments.getColumn(3).setMaxWidth(100); attachments.setAutoCreateColumnsFromModel(false); attachments.addHighlighter(HighlighterFactory.createAlternateStriping()); attachments.setModel(tableModel); attachments.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPanel toolbar = new JPanel(); StreamflowButton addButton = new StreamflowButton(am.get("add")); toolbar.add(addButton); StreamflowButton removeButton = new StreamflowButton(am.get("remove")); toolbar.add(removeButton); final StreamflowButton openButton = new StreamflowButton(am.get("open")); toolbar.add(openButton); attachments .getSelectionModel() .addListSelectionListener(new SelectionActionEnabler(am.get("open"))); attachments .getSelectionModel() .addListSelectionListener( new SelectionActionEnabler(am.get("remove")) { @Override public boolean isSelectedValueValid(javax.swing.Action action) { return !attachments .getValueAt(attachments.convertRowIndexToModel(attachments.getSelectedRow()), 0) .equals(Icons.formSubmitted); } }); attachmentsModel.addObserver( new RefreshComponents().visibleOn("createattachment", addButton, removeButton)); attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "open"); attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "remove"); attachments.setActionMap(am); attachments.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent me) { int obj = attachments.getSelectedRow(); if (obj == -1) return; if (me.getClickCount() == 2) { am.get("open") .actionPerformed( new ActionEvent(openButton, ActionEvent.ACTION_PERFORMED, "open")); me.consume(); } } }); attachments .getColumn(0) .setCellRenderer( new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { JLabel iconLabel = new JLabel(" "); switch ((Icons) value) { case attachments: iconLabel = new JLabel(i18n.icon((Icons) value, 11)); break; case conversations: iconLabel = new JLabel(i18n.icon((Icons) value, 11)); break; case formSubmitted: iconLabel = new JLabel(i18n.icon((Icons) value, 11)); break; } iconLabel.setOpaque(true); if (isSelected) iconLabel.setBackground(attachments.getSelectionBackground()); return iconLabel; } }); JScrollPane attachmentsScrollPane = new JScrollPane(attachments); add(attachmentsScrollPane, BorderLayout.CENTER); add(toolbar, BorderLayout.SOUTH); new RefreshWhenShowing(this, attachmentsModel); }
public DownloadsMDIWindow(final UISubsystem ui) throws Exception { super(ui.getMainWindow().getMDIManager(), "downloads", ui); table = new JXTable(); table.setModel(model = new DownloadsTableModel()); table.setAutoCreateColumnsFromModel(false); table.getColumnModel().getColumn(1).setCellRenderer(new ProgressBarCellRenderer()); table.getColumnModel().getColumn(0).setPreferredWidth(300); table.getColumnModel().getColumn(1).setPreferredWidth(80); status = (JLabel) xui.getComponent("status"); downloadingFromText = (JLabel) xui.getComponent("downloadingfromtext"); uploadingToText = (JLabel) xui.getComponent("uploadingtotext"); setFixedColumnSize(table.getColumnModel().getColumn(2), 60); setFixedColumnSize(table.getColumnModel().getColumn(3), 60); setFixedColumnSize(table.getColumnModel().getColumn(4), 60); setFixedColumnSize(table.getColumnModel().getColumn(5), 10); table.setColumnControlVisible(true); downloadGrid = (JDownloadGrid) xui.getComponent("downloadgrid"); table .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getFirstIndex() < 0 || e.getFirstIndex() >= rows.size()) { downloadGrid.setDownload(null); updateDownloadingFromAndUploadingToText(); return; } selectDownloadToShowOnDownloadGrid(); updateDownloadingFromAndUploadingToText(); } }); table.addMouseListener( new MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { maybeShowPopup(e); } @Override public void mousePressed(MouseEvent e) { maybeShowPopup(e); } @Override public void mouseClicked(MouseEvent e) {} private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { int row = table.rowAtPoint(e.getPoint()); boolean b = false; for (int r : table.getSelectedRows()) { if (r == row) { b = true; break; } } if (!b) { table.getSelectionModel().setSelectionInterval(row, row); } popup.show(e.getComponent(), e.getX(), e.getY()); } } }); // table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); ((JScrollPane) xui.getComponent("scroll")).setViewportView(table); popup = (JPopupMenu) xui.getComponent("popup"); update(); setTitle("Downloads"); listenExternalLinks(); postInit(); }