List of usage examples for javax.swing.table TableRowSorter TableRowSorter
public TableRowSorter(M model)
TableRowSorter
using model
as the underlying TableModel
. From source file:org.drugis.addis.gui.components.EnhancedTable.java
public static EnhancedTable createWithSorter(TableModel model) { EnhancedTable enhancedTable = createBare(model); TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); enhancedTable.setRowSorter(sorter);/*from ww w .j a va2 s . c o m*/ return enhancedTable; }
From source file:org.evors.rs.ui.frames.PopulationViewer.java
private void sortByFitness() { TableRowSorter<TableModel> sorter = new TableRowSorter<>(jTable1.getModel()); jTable1.setRowSorter(sorter);//from www. ja va 2 s . c o m List<RowSorter.SortKey> sortKeys = new ArrayList<>(); int columnIndexToSort = 1; sortKeys.add(new RowSorter.SortKey(columnIndexToSort, SortOrder.ASCENDING)); sorter.setSortKeys(sortKeys); sorter.sort(); }
From source file:org.geworkbench.engine.ccm.ComponentConfigurationManagerWindow.java
/** * Set up the GUI/*from w ww . ja v a 2s .co m*/ * * @param void * @return void */ private void initComponents() { frame = new JFrame("geWorkbench - Component Configuration Manager"); topPanel = new JPanel(); displayLabel = new JLabel(); String[] displayChoices = { DISPLAY_FILTER_ALL, DISPLAY_ONLY_LOADED, DISPLAY_ONLY_UNLOADED }; displayComboBox = new JComboBox(displayChoices); showByTypeLabel = new JLabel(); String[] showByTypeChoices = new String[PluginComponent.categoryList.size() + 2]; showByTypeChoices[0] = SHOW_BY_TYPE_ALL; int index = 1; for (String s : PluginComponent.categoryList) { showByTypeChoices[index] = s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); index++; } ; showByTypeChoices[index] = SHOW_BY_TYPE_OTHERS; Arrays.sort(showByTypeChoices); showByTypeComboBox = new JComboBox(showByTypeChoices); showByTypeComboBox.setMaximumRowCount(showByTypeChoices.length); keywordSearchLabel = new JLabel("Keyword search:"); keywordSearchField = new JTextField("Enter Text"); splitPane = new JSplitPane(); scrollPaneForTextPane = new JScrollPane(); textPane = new JTextPane(); bottompanel = new JPanel(); CellConstraints cc = new CellConstraints(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { ccmWindow = null; } }); viewLicenseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { viewLicense_actionPerformed(e); } }); applyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { applyCcmSelections_actionPerformed(e); } }); resetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetCcmSelections_actionPerformed(e); } }); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeCcmSelections_actionPerformed(e); } }); //======== frame ======== { Container frameContentPane = frame.getContentPane(); frameContentPane.setLayout(new BorderLayout()); //======== outerPanel ======== { frameContentPane.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent e) { if ("border".equals(e.getPropertyName())) throw new RuntimeException(); } }); //======== topPanel ======== { FormLayout topPanelLayout = new FormLayout( " 32dlu, default, 4dlu, default, 32dlu, default, 4dlu, default, 32dlu, default, 4dlu, 64dlu, 32dlu", "center:25dlu"); topPanel.setLayout(topPanelLayout); //---- displayLabel ---- displayLabel.setText("Display:"); topPanel.add(displayLabel, cc.xy(2, 1)); //======== scrollPaneForTopList1 ======== { //---- displayComboBox ---- ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { ItemSelectable is = (ItemSelectable) actionEvent.getSource(); Object[] selections = is.getSelectedObjects(); String selection = (String) selections[0]; ccmTableModel.setLoadedFilterValue(selection); sorter.setRowFilter(combinedFilter); ccmTableModel.fireTableDataChanged(); } }; displayComboBox.addActionListener(actionListener); } topPanel.add(displayComboBox, cc.xy(4, 1)); //---- showByTypeLabel ---- showByTypeLabel.setText("Show by type:"); topPanel.add(showByTypeLabel, cc.xy(6, 1)); //======== scrollPaneForTopList2 ======== { //---- showByTypeComboBox ---- ActionListener actionListener2 = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { ItemSelectable is = (ItemSelectable) actionEvent.getSource(); Object[] selections = is.getSelectedObjects(); String selection = (String) selections[0]; ccmTableModel.setTypeFilterValue(selection); sorter.setRowFilter(combinedFilter); ccmTableModel.fireTableDataChanged(); } }; showByTypeComboBox.addActionListener(actionListener2); } topPanel.add(showByTypeComboBox, cc.xy(8, 1)); //---- topLabel3 ---- topPanel.add(keywordSearchLabel, cc.xy(10, 1)); //======== scrollPaneForTopList3 ======== { // ---- keywordSearchField ---- KeyListener actionListener3 = new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { String text = keywordSearchField.getText(); ccmTableModel.setKeywordFilterValue(text); sorter.setRowFilter(combinedFilter); ccmTableModel.fireTableDataChanged(); } public void keyTyped(KeyEvent e) { } }; keywordSearchField.setText("Enter Text"); keywordSearchField.addKeyListener(actionListener3); } topPanel.add(keywordSearchField, cc.xy(12, 1)); } // Top Panel frameContentPane.add(topPanel, BorderLayout.NORTH); //======== splitPane ======== { splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setResizeWeight(0.5); //======== scrollPaneForTable ======== { //---- table ---- ccmTableModel = new CCMTableModel(manager); setOriginalChoices(); table = new JTable(ccmTableModel); sorter = new TableRowSorter<CCMTableModel>(ccmTableModel); table.setRowSorter(sorter); table.setDefaultRenderer(Object.class, new CellRenderer()); table.setDefaultRenderer(CCMTableModel.ImageLink.class, new ImageLinkRenderer()); table.setDefaultRenderer(CCMTableModel.HyperLink.class, new HyperLinkRenderer()); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ListSelectionModel cellSM = table.getSelectionModel(); cellSM.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); cellSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { boolean adjusting = e.getValueIsAdjusting(); if (adjusting) { return; } int selectedRow = table.getSelectedRow(); ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { textPane.setText(" "); } else { String description = (String) ccmTableModel.getValueAt( table.convertRowIndexToModel(selectedRow), CCMTableModel.DESCRIPTION_INDEX); textPane.setText(description); if (textPane.getCaretPosition() > 1) { textPane.setCaretPosition(1); } } } }); table.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent event) { launchBrowser(); } }); TableColumn column = table.getColumnModel().getColumn(CCMTableModel.SELECTION_INDEX); column.setMaxWidth(50); column = table.getColumnModel().getColumn(CCMTableModel.VERSION_INDEX); column.setMaxWidth(60); column = table.getColumnModel().getColumn(CCMTableModel.TUTORIAL_URL_INDEX); column.setMaxWidth(70); column = table.getColumnModel().getColumn(CCMTableModel.TOOL_URL_INDEX); column.setMaxWidth(70); scrollPaneForTable = new JScrollPane(table); } splitPane.setTopComponent(scrollPaneForTable); //======== scrollPaneForTextPane ======== { //---- textPane ---- textPane.setEditable(false); scrollPaneForTextPane.setViewportView(textPane); } splitPane.setBottomComponent(scrollPaneForTextPane); } //======== splitPane ========. frameContentPane.add(splitPane, BorderLayout.CENTER); //======== bottompanel ======== { bottompanel.setLayout(new FormLayout("20dlu," + "default, 4dlu, " + // view License "default,200dlu, " + // Apply "default, 4dlu, " + // Reset "default, 4dlu, " + // Cancel "default " // Close , "center:25dlu")); viewLicenseButton.setText("View License"); bottompanel.add(viewLicenseButton, cc.xy(2, 1)); //---- applyButton ---- applyButton.setText("Apply"); bottompanel.add(applyButton, cc.xy(6, 1)); //---- resetButton ---- resetButton.setText("Reset"); bottompanel.add(resetButton, cc.xy(8, 1)); //---- closeButton ---- closeButton.setText("Close"); bottompanel.add(closeButton, cc.xy(10, 1)); } //======== bottompanel ========. frameContentPane.add(bottompanel, BorderLayout.SOUTH); } //======== outerPanel ======== frame.pack(); frame.setLocationRelativeTo(frame.getOwner()); } // ============ frame ============ topPanel.setVisible(true); splitPane.setVisible(true); scrollPaneForTable.setVisible(true); table.setVisible(true); scrollPaneForTextPane.setVisible(true); textPane.setVisible(true); bottompanel.setVisible(true); sorter.setRowFilter(combinedFilter); frame.setVisible(true); splitPane.setDividerLocation(.7d); }
From source file:org.geworkbench.engine.ccm.ComponentConfigurationManagerWindow2.java
/** * Set up the GUI/*w ww . ja v a 2s.c o m*/ * * @param void * @return void */ private void initComponents() { frame = new JFrame("geWorkbench - Component Configuration Manager"); topPanel = new JPanel(); displayLabel = new JLabel(); String[] displayChoices = { DISPLAY_FILTER_ALL, DISPLAY_ONLY_LOADED, DISPLAY_ONLY_UNLOADED }; displayComboBox = new JComboBox(displayChoices); showByTypeLabel = new JLabel(); String[] showByTypeChoices = new String[PluginComponent.categoryList.size() + 2]; showByTypeChoices[0] = SHOW_BY_TYPE_ALL; int index = 1; for (String s : PluginComponent.categoryList) { showByTypeChoices[index] = s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); index++; } ; showByTypeChoices[index] = SHOW_BY_TYPE_OTHERS; Arrays.sort(showByTypeChoices); showByTypeComboBox = new JComboBox(showByTypeChoices); showByTypeComboBox.setMaximumRowCount(showByTypeChoices.length); keywordSearchLabel = new JLabel("Keyword search:"); keywordSearchField = new JTextField("Enter Text"); splitPane = new JSplitPane(); scrollPaneForTextPane = new JScrollPane(); textPane = new JTextPane(); bottompanel = new JPanel(); CellConstraints cc = new CellConstraints(); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { ccmWindow = null; } }); viewLicenseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { viewLicense_actionPerformed(e); } }); applyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { applyCcmSelections_actionPerformed(e); } }); resetButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { resetCcmSelections_actionPerformed(e); } }); closeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeCcmSelections_actionPerformed(e); } }); componentUpdateButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { componentRemoteUpdate_actionPerformed(e); } }); //======== frame ======== { Container frameContentPane = frame.getContentPane(); frameContentPane.setLayout(new BorderLayout()); //======== outerPanel ======== { frameContentPane.addPropertyChangeListener(new java.beans.PropertyChangeListener() { public void propertyChange(java.beans.PropertyChangeEvent e) { if ("border".equals(e.getPropertyName())) throw new RuntimeException(); } }); //======== topPanel ======== { FormLayout topPanelLayout = new FormLayout( " 32dlu, default, 4dlu, default, 32dlu, default, 4dlu, default, 32dlu, default, 4dlu, 64dlu, 32dlu", "center:25dlu"); topPanel.setLayout(topPanelLayout); //---- displayLabel ---- displayLabel.setText("Display:"); topPanel.add(displayLabel, cc.xy(2, 1)); //======== scrollPaneForTopList1 ======== { //---- displayComboBox ---- ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { ItemSelectable is = (ItemSelectable) actionEvent.getSource(); Object[] selections = is.getSelectedObjects(); String selection = (String) selections[0]; ccmTableModel.setLoadedFilterValue(selection); sorter.setRowFilter(combinedFilter); ccmTableModel.fireTableDataChanged(); } }; displayComboBox.addActionListener(actionListener); } topPanel.add(displayComboBox, cc.xy(4, 1)); //---- showByTypeLabel ---- showByTypeLabel.setText("Show by type:"); topPanel.add(showByTypeLabel, cc.xy(6, 1)); //======== scrollPaneForTopList2 ======== { //---- showByTypeComboBox ---- ActionListener actionListener2 = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { ItemSelectable is = (ItemSelectable) actionEvent.getSource(); Object[] selections = is.getSelectedObjects(); String selection = (String) selections[0]; ccmTableModel.setTypeFilterValue(selection); sorter.setRowFilter(combinedFilter); ccmTableModel.fireTableDataChanged(); } }; showByTypeComboBox.addActionListener(actionListener2); } topPanel.add(showByTypeComboBox, cc.xy(8, 1)); //---- topLabel3 ---- topPanel.add(keywordSearchLabel, cc.xy(10, 1)); //======== scrollPaneForTopList3 ======== { // ---- keywordSearchField ---- KeyListener actionListener3 = new KeyListener() { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { String text = keywordSearchField.getText(); ccmTableModel.setKeywordFilterValue(text); sorter.setRowFilter(combinedFilter); ccmTableModel.fireTableDataChanged(); } public void keyTyped(KeyEvent e) { } }; keywordSearchField.setText("Enter Text"); keywordSearchField.addKeyListener(actionListener3); } topPanel.add(keywordSearchField, cc.xy(12, 1)); } // Top Panel frameContentPane.add(topPanel, BorderLayout.NORTH); //======== splitPane ======== { splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setResizeWeight(0.5); //======== scrollPaneForTable ======== { //---- table ---- ccmTableModel = new CCMTableModel2(manager.componentConfigurationManager); setOriginalChoices(); table = new JTable(ccmTableModel); sorter = new TableRowSorter<CCMTableModel2>(ccmTableModel); table.setRowSorter(sorter); table.setDefaultRenderer(Object.class, new CellRenderer()); table.setDefaultRenderer(CCMTableModel2.ImageLink.class, new ImageLinkRenderer()); table.setDefaultRenderer(CCMTableModel2.HyperLink.class, new HyperLinkRenderer()); table.setDefaultRenderer(CCMTableModel2.DownloadLink.class, new DownloadLinkRenderer()); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); ListSelectionModel cellSM = table.getSelectionModel(); cellSM.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); cellSM.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { boolean adjusting = e.getValueIsAdjusting(); if (adjusting) { return; } int[] selectedRow = table.getSelectedRows(); ListSelectionModel lsm = (ListSelectionModel) e.getSource(); if (lsm.isSelectionEmpty()) { textPane.setText(" "); } else { String description = (String) ccmTableModel.getValueAt( table.convertRowIndexToModel(selectedRow[0]), CCMTableModel2.DESCRIPTION_INDEX); textPane.setText(description); if (textPane.getCaretPosition() > 1) { textPane.setCaretPosition(1); } } if (table.getSelectedRow() >= 0) { int modelColumn = table.convertColumnIndexToModel(table.getSelectedColumn()); if (modelColumn == CCMTableModel2.AVAILABLE_UPDATE_INDEX) installRemoteComponent(); else launchBrowser(); } } }); TableColumn column = table.getColumnModel().getColumn(CCMTableModel2.SELECTION_INDEX); column.setMaxWidth(50); column = table.getColumnModel().getColumn(CCMTableModel2.VERSION_INDEX); column.setMaxWidth(60); column = table.getColumnModel().getColumn(CCMTableModel2.AVAILABLE_UPDATE_INDEX); column.setMaxWidth(60); column = table.getColumnModel().getColumn(CCMTableModel2.TUTORIAL_URL_INDEX_2); column.setMaxWidth(70); column = table.getColumnModel().getColumn(CCMTableModel2.TOOL_URL_INDEX_2); column.setMaxWidth(70); scrollPaneForTable = new JScrollPane(table); } splitPane.setTopComponent(scrollPaneForTable); //======== scrollPaneForTextPane ======== { //---- textPane ---- textPane.setEditable(false); scrollPaneForTextPane.setViewportView(textPane); } splitPane.setBottomComponent(scrollPaneForTextPane); } //======== splitPane ========. frameContentPane.add(splitPane, BorderLayout.CENTER); //======== bottompanel ======== { bottompanel.setLayout(new FormLayout("20dlu," + "default, 4dlu, " + // view License "default,100dlu, " + // Component Update "default, 4dlu, " + // Apply "default, 4dlu, " + // Reset "default, 4dlu, " + // Cancel "default " // Close , "center:25dlu")); viewLicenseButton.setText("View License"); bottompanel.add(viewLicenseButton, cc.xy(2, 1)); //---- componentUpdateButton ---- bottompanel.add(componentUpdateButton, cc.xy(6, 1)); //---- applyButton ---- applyButton.setText("Apply"); bottompanel.add(applyButton, cc.xy(8, 1)); //---- resetButton ---- resetButton.setText("Reset"); bottompanel.add(resetButton, cc.xy(10, 1)); //---- closeButton ---- closeButton.setText("Close"); bottompanel.add(closeButton, cc.xy(12, 1)); } //======== bottompanel ========. frameContentPane.add(bottompanel, BorderLayout.SOUTH); } //======== outerPanel ======== frame.pack(); frame.setLocationRelativeTo(frame.getOwner()); } // ============ frame ============ topPanel.setVisible(true); splitPane.setVisible(true); scrollPaneForTable.setVisible(true); table.setVisible(true); scrollPaneForTextPane.setVisible(true); textPane.setVisible(true); bottompanel.setVisible(true); sorter.setRowFilter(combinedFilter); frame.setVisible(true); splitPane.setDividerLocation(.7d); }
From source file:org.kineticsystem.commons.data.demo.panels.ContactFilterPane.java
/** * Default constructor.//from ww w .ja v a 2 s . c om * @param contacts The list of contacts to sort and filter. */ public ContactFilterPane(ActiveList<RandomContact> source) { // source = new SortedList<RandomContact>(source); // ((SortedList<RandomContact>) source).setComparator(new BeanComparator("name")); // Light table format. TableStructure lightTableFormat = new BeanTableStructure(new String[] { null, null, null, null }, new String[] { "Name", "Surname", "Age", "Email" }); TableCellRenderer[] lightTableRenderers = new TableCellRenderer[] { new ColorTableCellRenderer("name", null), new ColorTableCellRenderer("surname", null), new ColorTableCellRenderer("age", null), new ColorTableCellRenderer("email", null) }; Comparator[] lightTableComparators = new Comparator[] { new BeanComparator("name"), new BeanComparator("surname"), new BeanComparator("age"), new BeanComparator("email") }; String lightTableMessage = "Show name, surname, age and email"; // Full table format. TableStructure fullTableFormat = new BeanTableStructure(new String[] { null, null, null, null, null, null }, new String[] { "Name", "Surname", "Address", "Country", "Continent", "Email" }); TableCellRenderer[] fullTableRenderers = new TableCellRenderer[] { new ColorTableCellRenderer("name", null), new ColorTableCellRenderer("surname", null), new ColorTableCellRenderer("address", null), new ColorTableCellRenderer("country", null), new ColorTableCellRenderer("continent", null), new ColorTableCellRenderer("email", null) }; Comparator[] fullTableComparators = new Comparator[] { new BeanComparator("name"), new BeanComparator("surname"), new BeanComparator("address"), new BeanComparator("country"), new BeanComparator("continent"), new BeanComparator("email") }; String fullTableMessage = "Show name, surname, address, country, " + "continent and email"; // Table model and table view. tableModel = new TableModelAdapter(source, lightTableFormat); table = new JTable(tableModel); sorter = new TableRowSorter<TableModel>(tableModel); for (int i = 0; i < lightTableComparators.length; i++) { sorter.setComparator(i, lightTableComparators[i]); table.getColumnModel().getColumn(i).setCellRenderer(lightTableRenderers[i]); } table.setRowSorter(sorter); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // Table structure selector. DefaultComboBoxModel tableFormatComboModel = new DefaultComboBoxModel(new TableModeItem[] { new TableModeItem(lightTableMessage, lightTableFormat, lightTableRenderers, lightTableComparators), new TableModeItem(fullTableMessage, fullTableFormat, fullTableRenderers, fullTableComparators) }); JComboBox formatCombo = new JComboBox(tableFormatComboModel); formatCombo.setToolTipText("Select a format."); formatCombo.addActionListener(new FormatComboActionListener()); // Table filter selector. DefaultComboBoxModel filterComboModel = new DefaultComboBoxModel( new FilterComboItem[] { new FilterComboItem("Address", "address"), new FilterComboItem("Country", "country"), new FilterComboItem("Email", "email"), new FilterComboItem("Name", "name"), new FilterComboItem("Surname", "surname") }); filterCombo = new JComboBox(filterComboModel); filterCombo.setToolTipText("Select a filter."); filterCombo.setSelectedIndex(3); filterText = new JTextField(""); filterText.setToolTipText("Type a regular expression."); filterText.getDocument().addDocumentListener(new FilterDocumentListener()); filterButton = new JButton("Filter"); filterButton.setToolTipText("Press to filter."); filterButton.addActionListener(new FilterButtonActionListener()); // Layout. Cell cell = new Cell(); TetrisLayout filterLayout = new TetrisLayout(1, 3); filterLayout.setColWeight(0, 100); filterLayout.setColWeight(1, 0); filterLayout.setColWeight(2, 0); JPanel filterPane = new JPanel(filterLayout); filterPane.add(filterText, cell); filterPane.add(filterCombo, cell); filterPane.add(filterButton, cell); TetrisLayout tableLayout = new TetrisLayout(3, 1); tableLayout.setRowWeight(0, 0); tableLayout.setRowWeight(1, 0); tableLayout.setRowWeight(2, 100); setLayout(tableLayout); add(filterPane, cell); add(formatCombo, cell); add(tableScrollPane, cell); }
From source file:org.ngrinder.recorder.ui.RecordingControlPanel.java
protected JTable createFilterTables(ConnectionFilter connectionFilter) { final FilterTableModel dm = new FilterTableModel(connectionFilter); JTable jTable = new JTable(dm); TableColumnModel columnModel = jTable.getColumnModel(); setColumnWidth(columnModel.getColumn(0), 30, 30, 30); setColumnWidth(columnModel.getColumn(2), 30, 50, 30); jTable.setRowSorter(new TableRowSorter<TableModel>(dm)); createUpdateCheckScheduledTask(dm);//from w w w . ja va 2 s . com return jTable; }
From source file:org.trzcinka.intellitrac.view.toolwindow.tickets.tickets_list.TicketsListForm.java
private void createUIComponents() { constantToolbarForm = new ConstantToolbarForm(); sorter = new TableRowSorter<TicketsListModel>(ticketsModel.getTicketsListTableModel()); ticketsList = new JTable(ticketsModel.getTicketsListTableModel()); ticketsList.setRowSorter(sorter);//from w w w .j a v a 2 s . c o m filterColumnsModel = new FilterColumnsComboModel(); filterColumnsComboBox = new JComboBox(filterColumnsModel); filterColumnsComboBox.setSelectedIndex(0); filterColumnsComboBox.setRenderer(new FilterColumnsComboRenderer()); filterStringTextField = new JTextField(); filterStringTextField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { newFilter(); } public void insertUpdate(DocumentEvent e) { newFilter(); } public void removeUpdate(DocumentEvent e) { newFilter(); } }); }
From source file:org.wandora.application.gui.OccurrenceTableSingleType.java
/** Creates a new instance of OccurrenceTableSingleType */ public OccurrenceTableSingleType(Topic topic, Topic type, Options options, Wandora wandora) throws TopicMapException { this.wandora = wandora; this.topic = topic; TopicMap tm = wandora.getTopicMap(); try {//from w ww . j a v a2 s. c o m Options opts = options; if (opts == null) opts = wandora.getOptions(); if (opts != null) { tableType = opts.get(VIEW_OPTIONS_KEY); if (tableType == null || tableType.length() == 0) tableType = VIEW_SCHEMA; defaultRowHeight = opts.getInt(ROW_HEIGHT_OPTIONS_KEY); } } catch (Exception e) { e.printStackTrace(); } this.type = type; HashSet<Topic> langSet = new LinkedHashSet(); if (VIEW_USED.equalsIgnoreCase(tableType) || VIEW_USED_AND_SCHEMA.equalsIgnoreCase(tableType)) { Hashtable<Topic, String> occs = null; Topic langTopic = null; occs = topic.getData(type); for (Enumeration<Topic> keys = occs.keys(); keys.hasMoreElements();) { langTopic = keys.nextElement(); langSet.add(langTopic); } } if (VIEW_SCHEMA.equalsIgnoreCase(tableType) || VIEW_USED_AND_SCHEMA.equalsIgnoreCase(tableType)) { Collection<Topic> langTopics = tm.getTopicsOfType(LANGUAGE_SI); langSet.addAll(langTopics); } langs = langSet.toArray(new Topic[langSet.size()]); data = new String[langs.length]; originalData = new String[langs.length]; colors = new Color[langs.length]; for (int j = 0; j < langs.length; j++) { if (langs[j] != null) { data[j] = topic.getData(type, langs[j]); if (data[j] == null) data[j] = ""; originalData[j] = data[j]; colors[j] = wandora.topicHilights.getOccurrenceColor(topic, type, langs[j]); } } dataModel = new DataTableModel(); sorter = new TableRowSorter(dataModel); final TableCellRenderer oldRenderer = this.getTableHeader().getDefaultRenderer(); this.getTableHeader().setPreferredSize(new Dimension(100, 23)); this.getTableHeader().setDefaultRenderer(new TableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = oldRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); return c; } }); this.setAutoCreateColumnsFromModel(false); TableColumn column = new TableColumn(0, 40, new TopicCellRenderer(), new TopicCellEditor()); this.addColumn(column); column = new TableColumn(1, 400, new DataCellRenderer(), new DataCellEditor()); this.addColumn(column); this.setTableHeader(this.getTableHeader()); this.setModel(dataModel); this.setRowSorter(sorter); sorter.setSortsOnUpdates(true); updateRowHeights(); popupStruct = WandoraMenuManager.getOccurrenceTableMenu(this, options); JPopupMenu popup = UIBox.makePopupMenu(popupStruct, wandora); this.setComponentPopupMenu(popup); this.addMouseListener(this); this.setColumnSelectionAllowed(false); this.setRowSelectionAllowed(false); this.setDragEnabled(true); this.setTransferHandler(new OccurrencesTableTransferHandler()); this.setDropMode(DropMode.ON); this.createDefaultTableSelectionModel(); }
From source file:pl.otros.logview.gui.LogViewPanel.java
public LogViewPanel(final LogDataTableModel dataTableModel, TableColumns[] visibleColumns, final OtrosApplication otrosApplication) { super();/*from ww w . j ava 2 s. c o m*/ this.dataTableModel = dataTableModel; this.otrosApplication = otrosApplication; this.statusObserver = otrosApplication.getStatusObserver(); configuration = otrosApplication.getConfiguration(); AllPluginables allPluginable = AllPluginables.getInstance(); markersContainer = allPluginable.getMarkersContainser(); markersContainer.addListener(new MarkersMenuReloader()); logFiltersContainer = allPluginable.getLogFiltersContainer(); messageColorizersContainer = allPluginable.getMessageColorizers(); messageFormattersContainer = allPluginable.getMessageFormatters(); selectedMessageColorizersContainer = new PluginableElementsContainer<MessageColorizer>(); selectedMessageFormattersContainer = new PluginableElementsContainer<MessageFormatter>(); for (MessageColorizer messageColorizer : messageColorizersContainer.getElements()) { selectedMessageColorizersContainer.addElement(messageColorizer); } for (MessageFormatter messageFormatter : messageFormattersContainer.getElements()) { selectedMessageFormattersContainer.addElement(messageFormatter); } messageColorizersContainer.addListener( new SynchronizePluginableContainerListener<MessageColorizer>(selectedMessageColorizersContainer)); messageFormattersContainer.addListener( new SynchronizePluginableContainerListener<MessageFormatter>(selectedMessageFormattersContainer)); menuLabelFont = new JLabel().getFont().deriveFont(Font.BOLD); filtersPanel = new JPanel(); logsTablePanel = new JPanel(); logsMarkersPanel = new JPanel(); leftPanel = new JPanel(new MigLayout()); logDetailTextArea = new JTextPane(); logDetailTextArea.setEditable(false); MouseAdapter locationInfo = new LocationClickMouseAdapter(otrosApplication, logDetailTextArea); logDetailTextArea.addMouseMotionListener(locationInfo); logDetailTextArea.addMouseListener(locationInfo); logDetailTextArea.setBorder(BorderFactory.createTitledBorder("Details")); logDetailWithRulerScrollPane = RulerBarHelper.wrapTextComponent(logDetailTextArea); table = new JTableWith2RowHighliting(dataTableModel); // Initialize default column visible before creating context menu table.setColumnControlVisible(true); final ColumnControlButton columnControlButton = new ColumnControlButton(table) { @Override public void togglePopup() { populatePopup(); super.togglePopup(); } @Override protected List<Action> getAdditionalActions() { final List<Action> additionalActions = super.getAdditionalActions(); final AbstractAction saveLayout = new AbstractAction("Save current to new column layout", Icons.DISK) { @Override public void actionPerformed(ActionEvent actionEvent) { String newLayoutName = JOptionPane.showInputDialog(table, "New Layout name"); if (newLayoutName == null) { return; } newLayoutName = newLayoutName.trim(); LOGGER.info(String.format("Saving New column layout '%s'", newLayoutName)); ArrayList<String> visibleColNames = new ArrayList<String>(); for (TableColumn tc : table.getColumns()) { Object o = tc.getIdentifier(); if (!(o instanceof TableColumns)) { LOGGER.severe("TableColumn identifier of unexpected type: " + tc.getIdentifier().getClass().getName()); LOGGER.warning("Throw up a pop-up"); return; } TableColumns tcs = (TableColumns) o; visibleColNames.add(tcs.getName()); } ColumnLayout columnLayout = new ColumnLayout(newLayoutName, visibleColNames); final List<ColumnLayout> columnLayouts = LogTableFormatConfigView .loadColumnLayouts(configuration); columnLayouts.add(columnLayout); LogTableFormatConfigView.saveColumnLayouts(columnLayouts, configuration); populatePopup(); } }; additionalActions.add(saveLayout); final List<ColumnLayout> columnLayoutNames = LogTableFormatConfigView .loadColumnLayouts(configuration); for (final ColumnLayout columnLayout : columnLayoutNames) { final String name = columnLayout.getName(); final AbstractAction applyColumnLayout = new ApplyColumnLayoutAction(name, Icons.EDIT_COLUMNS, columnLayout, table); additionalActions.add(applyColumnLayout); } return additionalActions; } }; table.setColumnControl(columnControlButton); List<TableColumn> columns = table.getColumns(true); for (int i = 0; i < columns.size(); i++) { columns.get(i).setIdentifier(TableColumns.getColumnById(i)); } for (TableColumn tableColumn : columns) { table.getColumnExt(tableColumn.getIdentifier()).setVisible(false); } for (TableColumns tableColumns : visibleColumns) { table.getColumnExt(tableColumns).setVisible(true); } table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); updateColumnsSize(); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); final Renderers renderers = Renderers.getInstance(otrosApplication); table.setDefaultRenderer(String.class, new TableMarkDecoratorRenderer(renderers.getStringRenderer())); table.setDefaultRenderer(Object.class, new TableMarkDecoratorRenderer(table.getDefaultRenderer(Object.class))); table.setDefaultRenderer(Integer.class, new TableMarkDecoratorRenderer(table.getDefaultRenderer(Object.class))); table.setDefaultRenderer(Level.class, new TableMarkDecoratorRenderer(renderers.getLevelRenderer())); table.setDefaultRenderer(Date.class, new TableMarkDecoratorRenderer(renderers.getDateRenderer())); final TimeDeltaRenderer timeDeltaRenderer = new TimeDeltaRenderer(); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent listSelectionEvent) { final int[] selectedRows = table.getSelectedRows(); if (selectedRows.length > 0) { final int selectedRow = selectedRows[selectedRows.length - 1]; final Date selectedDate = dataTableModel.getLogData(table.convertRowIndexToModel(selectedRow)) .getDate(); timeDeltaRenderer.setSelectedTimestamp(selectedDate); table.repaint(); } } }); table.setDefaultRenderer(TimeDelta.class, new TableMarkDecoratorRenderer(timeDeltaRenderer)); ((EventSource) configuration.getConfiguration()).addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent ce) { if (ce.getType() == AbstractConfiguration.EVENT_SET_PROPERTY && !ce.isBeforeUpdate()) { if (ce.getPropertyName().equals(ConfKeys.LOG_TABLE_FORMAT_DATE_FORMAT)) { table.setDefaultRenderer(Date.class, new TableMarkDecoratorRenderer(new DateRenderer( configuration.getString(ConfKeys.LOG_TABLE_FORMAT_DATE_FORMAT, "HH:mm:ss.SSS")))); updateTimeColumnSize(); } else if (ce.getPropertyName().equals(ConfKeys.LOG_TABLE_FORMAT_LEVEL_RENDERER)) { table.setDefaultRenderer(Level.class, new TableMarkDecoratorRenderer(new LevelRenderer(configuration.get( LevelRenderer.Mode.class, ConfKeys.LOG_TABLE_FORMAT_LEVEL_RENDERER, LevelRenderer.Mode.IconsOnly)))); updateLevelColumnSize(); } } } }); table.setDefaultRenderer(Boolean.class, new TableMarkDecoratorRenderer(table.getDefaultRenderer(Boolean.class))); table.setDefaultRenderer(Note.class, new TableMarkDecoratorRenderer(new NoteRenderer())); table.setDefaultRenderer(MarkerColors.class, new TableMarkDecoratorRenderer(new MarkTableRenderer())); table.setDefaultEditor(Note.class, new NoteTableEditor()); table.setDefaultEditor(MarkerColors.class, new MarkTableEditor(otrosApplication)); table.setDefaultRenderer(ClassWrapper.class, new TableMarkDecoratorRenderer(renderers.getClassWrapperRenderer())); sorter = new TableRowSorter<LogDataTableModel>(dataTableModel); for (int i = 0; i < dataTableModel.getColumnCount(); i++) { sorter.setSortable(i, false); } sorter.setSortable(TableColumns.ID.getColumn(), true); sorter.setSortable(TableColumns.TIME.getColumn(), true); table.setRowSorter(sorter); messageDetailListener = new MessageDetailListener(this, dateFormat, selectedMessageFormattersContainer, selectedMessageColorizersContainer); table.getSelectionModel().addListSelectionListener(messageDetailListener); dataTableModel.addNoteObserver(messageDetailListener); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { boolean hasFocus = otrosApplication.getApplicationJFrame().isFocused(); final boolean enabled = otrosApplication.getConfiguration() .getBoolean(ConfKeys.JUMP_TO_CODE_AUTO_JUMP_ENABLED, false); if (hasFocus && enabled && !e.getValueIsAdjusting()) { try { final LogData logData = dataTableModel .getLogData(table.convertRowIndexToModel(e.getFirstIndex())); LocationInfo li = new LocationInfo(logData.getClazz(), logData.getMethod(), logData.getFile(), Integer.valueOf(logData.getLine())); final JumpToCodeService jumpToCodeService = otrosApplication.getServices() .getJumpToCodeService(); final boolean ideAvailable = jumpToCodeService.isIdeAvailable(); if (ideAvailable) { LOGGER.fine("Jumping to " + li); jumpToCodeService.jump(li); } } catch (Exception e1) { LOGGER.warning("Can't perform jump to code " + e1.getMessage()); } } } }); notes = new JTextArea(); notes.setEditable(false); NoteObserver allNotesObserver = new AllNotesTextAreaObserver(notes); dataTableModel.addNoteObserver(allNotesObserver); addFiltersGUIsToPanel(filtersPanel); logsTablePanel.setLayout(new BorderLayout()); logsTablePanel.add(new JScrollPane(table)); JPanel messageDetailsPanel = new JPanel(new BorderLayout()); messageDetailToolbar = new JToolBar("MessageDetail"); messageDetailsPanel.add(messageDetailToolbar, BorderLayout.NORTH); messageDetailsPanel.add(logDetailWithRulerScrollPane); initMessageDetailsToolbar(); jTabbedPane = new JTabbedPane(); jTabbedPane.add("Message detail", messageDetailsPanel); jTabbedPane.add("All notes", new JScrollPane(notes)); leftPanel.add(filtersPanel, "wrap, growx"); leftPanel.add(new JSeparator(SwingConstants.HORIZONTAL), "wrap,growx"); leftPanel.add(logsMarkersPanel, "wrap,growx"); JSplitPane splitPaneLogsTableAndDetails = new JSplitPane(JSplitPane.VERTICAL_SPLIT, logsTablePanel, jTabbedPane); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(leftPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), splitPaneLogsTableAndDetails); splitPane.setOneTouchExpandable(true); this.setLayout(new BorderLayout()); this.add(splitPane); splitPaneLogsTableAndDetails.setDividerLocation(0.5d); splitPaneLogsTableAndDetails.setOneTouchExpandable(true); splitPane.setDividerLocation(leftPanel.getPreferredSize().width + 10); PopupListener popupListener = new PopupListener(new Callable<JPopupMenu>() { @Override public JPopupMenu call() throws Exception { return initTableContextMenu(); } }); table.addMouseListener(popupListener); table.addKeyListener(popupListener); PopupListener popupListenerMessageDetailMenu = new PopupListener(new Callable<JPopupMenu>() { @Override public JPopupMenu call() throws Exception { return initMessageDetailPopupMenu(); } }); logDetailTextArea.addMouseListener(popupListenerMessageDetailMenu); logDetailTextArea.addKeyListener(popupListenerMessageDetailMenu); dataTableModel.notifyAllNoteObservers(new NoteEvent(EventType.CLEAR, dataTableModel, null, 0)); table.addKeyListener(new MarkRowBySpaceKeyListener(otrosApplication)); initAcceptConditions(); }
From source file:pl.otros.vfs.browser.VfsBrowser.java
License:asdf
private void initGui(final String initialPath) { this.setLayout(new BorderLayout()); JLabel pathLabel = new JLabel(Messages.getMessage("browser.location")); pathLabel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); pathField = new JTextField(80); pathField.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getSize() * 1.2f)); pathField.setToolTipText(Messages.getMessage("nav.pathTooltip")); GuiUtils.addBlinkOnFocusGain(pathField); pathLabel.setLabelFor(pathField);/*from w ww. ja va2 s. co m*/ pathLabel.setDisplayedMnemonic(Messages.getMessage("browser.location.mnemonic").charAt(0)); InputMap inputMapPath = pathField.getInputMap(JComponent.WHEN_FOCUSED); inputMapPath.put(KeyStroke.getKeyStroke("ENTER"), "OPEN_PATH"); inputMapPath.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE); pathField.getActionMap().put("OPEN_PATH", new BaseNavigateAction(this) { @Override protected void performLongOperation(CheckBeforeActionResult actionResult) { try { FileObject resolveFile = VFSUtils.resolveFileObject(pathField.getText().trim()); if (resolveFile != null && resolveFile.getType() == FileType.FILE) { loadAndSelSingleFile(resolveFile); pathField.setText(resolveFile.getURL().toString()); actionApproveDelegate.actionPerformed( // TODO: Does actionResult provide an ID for 2nd param here, // or should use a Random number? new ActionEvent(actionResult, (int) new java.util.Date().getTime(), "SELECTED_FILE")); return; } } catch (FileSystemException fse) { // Intentionally empty } goToUrl(pathField.getText().trim()); } @Override protected boolean canGoUrl() { return true; } @Override protected boolean canExecuteDefaultAction() { return false; } }); actionFocusOnTable = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { tableFiles.requestFocusInWindow(); if (tableFiles.getSelectedRow() < 0 && tableFiles.getRowCount() == 0) { tableFiles.getSelectionModel().setSelectionInterval(0, 0); } } }; pathField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable); BaseNavigateActionGoUp goUpAction = new BaseNavigateActionGoUp(this); goUpButton = new JButton(goUpAction); BaseNavigateActionRefresh refreshAction = new BaseNavigateActionRefresh(this); JButton refreshButton = new JButton(refreshAction); JToolBar upperPanel = new JToolBar(Messages.getMessage("nav.ToolBarName")); upperPanel.setRollover(true); upperPanel.add(pathLabel); upperPanel.add(pathField, "growx"); upperPanel.add(goUpButton); upperPanel.add(refreshButton); AddCurrentLocationToFavoriteAction addCurrentLocationToFavoriteAction = new AddCurrentLocationToFavoriteAction( this); JButton addCurrentLocationToFavoriteButton = new JButton(addCurrentLocationToFavoriteAction); addCurrentLocationToFavoriteButton.setText(""); upperPanel.add(addCurrentLocationToFavoriteButton); previewComponent = new PreviewComponent(); vfsTableModel = new VfsTableModel(); tableFiles = new JTable(vfsTableModel); tableFiles.setFillsViewportHeight(true); tableFiles.getColumnModel().getColumn(0).setMinWidth(140); tableFiles.getColumnModel().getColumn(1).setMaxWidth(80); tableFiles.getColumnModel().getColumn(2).setMaxWidth(80); tableFiles.getColumnModel().getColumn(3).setMaxWidth(180); tableFiles.getColumnModel().getColumn(3).setMinWidth(120); sorter = new TableRowSorter<VfsTableModel>(vfsTableModel); final FileNameWithTypeComparator fileNameWithTypeComparator = new FileNameWithTypeComparator(); sorter.addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { RowSorterEvent.Type type = e.getType(); if (type.equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) { List<? extends RowSorter.SortKey> sortKeys = e.getSource().getSortKeys(); for (RowSorter.SortKey sortKey : sortKeys) { if (sortKey.getColumn() == VfsTableModel.COLUMN_NAME) { fileNameWithTypeComparator.setSortOrder(sortKey.getSortOrder()); } } } } }); sorter.setComparator(VfsTableModel.COLUMN_NAME, fileNameWithTypeComparator); tableFiles.setRowSorter(sorter); tableFiles.setShowGrid(false); tableFiles.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { try { selectionChanged(); } catch (FileSystemException e1) { LOGGER.error("Error during update state", e); } } }); tableFiles.setColumnSelectionAllowed(false); vfsTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateStatusText(); } }); tableFiles.setDefaultRenderer(FileSize.class, new FileSizeTableCellRenderer()); tableFiles.setDefaultRenderer(FileNameWithType.class, new FileNameWithTypeTableCellRenderer()); tableFiles.setDefaultRenderer(Date.class, new MixedDateTableCellRenderer()); tableFiles.setDefaultRenderer(FileType.class, new FileTypeTableCellRenderer()); tableFiles.getSelectionModel().addListSelectionListener(new PreviewListener(this, previewComponent)); JPanel favoritesPanel = new JPanel(new MigLayout("wrap, fillx", "[grow]")); favoritesUserListModel = new MutableListModel<Favorite>(); List<Favorite> favSystemLocations = FavoritesUtils.getSystemLocations(); List<Favorite> favUser = FavoritesUtils.loadFromProperties(configuration); List<Favorite> favJVfsFileChooser = FavoritesUtils.getJvfsFileChooserBookmarks(); for (Favorite favorite : favUser) { favoritesUserListModel.add(favorite); } favoritesUserListModel.addListDataListener(new ListDataListener() { @Override public void intervalAdded(ListDataEvent e) { saveFavorites(); } @Override public void intervalRemoved(ListDataEvent e) { saveFavorites(); } @Override public void contentsChanged(ListDataEvent e) { saveFavorites(); } protected void saveFavorites() { FavoritesUtils.storeFavorites(configuration, favoritesUserListModel.getList()); } }); favoritesUserList = new JList(favoritesUserListModel); favoritesUserList.setTransferHandler(new MutableListDropHandler(favoritesUserList)); new MutableListDragListener(favoritesUserList); favoritesUserList.setCellRenderer(new FavoriteListCellRenderer()); favoritesUserList.addFocusListener(new SelectFirstElementFocusAdapter()); addOpenActionToList(favoritesUserList); addEditActionToList(favoritesUserList, favoritesUserListModel); favoritesUserList.getActionMap().put(ACTION_DELETE, new AbstractAction( Messages.getMessage("favorites.deleteButtonText"), Icons.getInstance().getMinusButton()) { @Override public void actionPerformed(ActionEvent e) { Favorite favorite = favoritesUserListModel.getElementAt(favoritesUserList.getSelectedIndex()); if (!Favorite.Type.USER.equals(favorite.getType())) { return; } int response = JOptionPane.showConfirmDialog(VfsBrowser.this, Messages.getMessage("favorites.areYouSureToDeleteConnections"), Messages.getMessage("favorites.confirm"), JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { favoritesUserListModel.remove(favoritesUserList.getSelectedIndex()); } } }); InputMap favoritesListInputMap = favoritesUserList.getInputMap(JComponent.WHEN_FOCUSED); favoritesListInputMap.put(KeyStroke.getKeyStroke("DELETE"), ACTION_DELETE); ActionMap actionMap = tableFiles.getActionMap(); actionMap.put(ACTION_OPEN, new BaseNavigateActionOpen(this)); actionMap.put(ACTION_GO_UP, goUpAction); actionMap.put(ACTION_APPROVE, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (actionApproveButton.isEnabled()) { actionApproveDelegate.actionPerformed(e); } } }); InputMap inputMap = tableFiles.getInputMap(JComponent.WHEN_FOCUSED); inputMap.put(KeyStroke.getKeyStroke("ENTER"), ACTION_OPEN); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK), ACTION_APPROVE); inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), ACTION_GO_UP); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), ACTION_GO_UP); addPopupMenu(favoritesUserList, ACTION_OPEN, ACTION_EDIT, ACTION_DELETE); JList favoriteSystemList = new JList(new Vector<Object>(favSystemLocations)); favoriteSystemList.setCellRenderer(new FavoriteListCellRenderer()); addOpenActionToList(favoriteSystemList); addPopupMenu(favoriteSystemList, ACTION_OPEN); favoriteSystemList.addFocusListener(new SelectFirstElementFocusAdapter()); JList favoriteJVfsList = new JList(new Vector<Object>(favJVfsFileChooser)); addOpenActionToList(favoriteJVfsList); favoriteJVfsList.setCellRenderer(new FavoriteListCellRenderer()); addPopupMenu(favoriteJVfsList, ACTION_OPEN); favoriteJVfsList.addFocusListener(new SelectFirstElementFocusAdapter()); JLabel favoritesSystemLocationsLabel = getTitleListLabel(Messages.getMessage("favorites.systemLocations"), COMPUTER_ICON); favoritesSystemLocationsLabel.setLabelFor(favoriteSystemList); favoritesSystemLocationsLabel .setDisplayedMnemonic(Messages.getMessage("favorites.systemLocations.mnemonic").charAt(0)); favoritesPanel.add(favoritesSystemLocationsLabel, "gapleft 16"); favoritesPanel.add(favoriteSystemList, "growx"); JLabel favoritesFavoritesLabel = getTitleListLabel(Messages.getMessage("favorites.favorites"), Icons.getInstance().getStar()); favoritesFavoritesLabel.setLabelFor(favoritesUserList); favoritesFavoritesLabel.setDisplayedMnemonic(Messages.getMessage("favorites.favorites.mnemonic").charAt(0)); favoritesPanel.add(favoritesFavoritesLabel, "gapleft 16"); favoritesPanel.add(favoritesUserList, "growx"); if (favoriteJVfsList.getModel().getSize() > 0) { JLabel favoritesJVfsFileChooser = getTitleListLabel( Messages.getMessage("favorites.JVfsFileChooserBookmarks"), null); favoritesJVfsFileChooser.setDisplayedMnemonic( Messages.getMessage("favorites.JVfsFileChooserBookmarks.mnemonic").charAt(0)); favoritesJVfsFileChooser.setLabelFor(favoriteJVfsList); favoritesPanel.add(favoritesJVfsFileChooser, "gapleft 16"); favoritesPanel.add(favoriteJVfsList, "growx"); } tableFiles.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { tableFiles.getActionMap().get(ACTION_OPEN).actionPerformed(null); } } }); tableFiles.addKeyListener(new QuickSearchKeyAdapter()); cardLayout = new CardLayout(); tablePanel = new JPanel(cardLayout); loadingProgressBar = new JProgressBar(); loadingProgressBar.setStringPainted(true); loadingProgressBar.setString(Messages.getMessage("browser.loading")); loadingProgressBar.setIndeterminate(true); loadingIconLabel = new JLabel(Icons.getInstance().getNetworkStatusOnline()); skipCheckingLinksButton = new JToggleButton(Messages.getMessage("browser.skipCheckingLinks")); skipCheckingLinksButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (taskContext != null) { taskContext.setStop(skipCheckingLinksButton.isSelected()); } } }); showHidCheckBox = new JCheckBox(Messages.getMessage("browser.showHidden.label"), showHidden); showHidCheckBox.setToolTipText(Messages.getMessage("browser.showHidden.tooltip")); showHidCheckBox.setMnemonic(Messages.getMessage("browser.showHidden.mnemonic").charAt(0)); Font tmpFont = showHidCheckBox.getFont(); showHidCheckBox.setFont(tmpFont.deriveFont(tmpFont.getSize() * 0.9f)); showHidCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateUiFilters(); } }); final String defaultFilterText = Messages.getMessage("browser.nameFilter.defaultText"); filterField = new JTextField("", 16); filterField.setForeground(filterField.getDisabledTextColor()); filterField.setToolTipText(Messages.getMessage("browser.nameFilter.tooltip")); PromptSupport.setPrompt(defaultFilterText, filterField); filterField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { documentChanged(); } void documentChanged() { if (filterField.getText().length() == 0) { updateUiFilters(); } } @Override public void removeUpdate(DocumentEvent e) { documentChanged(); } @Override public void changedUpdate(DocumentEvent e) { documentChanged(); } }); filterField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { updateUiFilters(); } }); AbstractAction actionClearRegexFilter = new AbstractAction(Messages.getMessage("browser.nameFilter.clearFilterText")) { @Override public void actionPerformed(ActionEvent e) { filterField.setText(""); } }; filterField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable); filterField.getActionMap().put(ACTION_CLEAR_REGEX_FILTER, actionClearRegexFilter); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ACTION_CLEAR_REGEX_FILTER); JLabel nameFilterLabel = new JLabel(Messages.getMessage("browser.nameFilter")); nameFilterLabel.setLabelFor(filterField); nameFilterLabel.setDisplayedMnemonic(Messages.getMessage("browser.nameFilter.mnemonic").charAt(0)); sorter.setRowFilter(createFilter()); statusLabel = new JLabel(); actionApproveButton = new JButton(); actionApproveButton.setFont(actionApproveButton.getFont().deriveFont(Font.BOLD)); actionCancelButton = new JButton(); ActionMap browserActionMap = this.getActionMap(); browserActionMap.put(ACTION_FOCUS_ON_REGEX_FILTER, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { filterField.requestFocus(); filterField.selectAll(); GuiUtils.blinkComponent(filterField); } }); browserActionMap.put(ACTION_FOCUS_ON_PATH, new SetFocusOnAction(pathField)); browserActionMap.put(ACTION_SWITCH_SHOW_HIDDEN, new ClickOnJComponentAction(showHidCheckBox)); browserActionMap.put(ACTION_REFRESH, refreshAction); browserActionMap.put(ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES, addCurrentLocationToFavoriteAction); browserActionMap.put(ACTION_GO_UP, goUpAction); browserActionMap.put(ACTION_FOCUS_ON_TABLE, new SetFocusOnAction(tableFiles)); InputMap browserInputMap = this.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); browserInputMap.put(KeyStroke.getKeyStroke("control F"), ACTION_FOCUS_ON_REGEX_FILTER); browserInputMap.put(KeyStroke.getKeyStroke("control L"), ACTION_FOCUS_ON_PATH); browserInputMap.put(KeyStroke.getKeyStroke("F4"), ACTION_FOCUS_ON_PATH); browserInputMap.put(KeyStroke.getKeyStroke("control H"), ACTION_SWITCH_SHOW_HIDDEN); browserInputMap.put(KeyStroke.getKeyStroke("control R"), ACTION_REFRESH); browserInputMap.put(KeyStroke.getKeyStroke("F5"), ACTION_REFRESH); browserInputMap.put(KeyStroke.getKeyStroke("control D"), ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES); browserInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK), ACTION_GO_UP); browserInputMap.put(KeyStroke.getKeyStroke("control T"), ACTION_FOCUS_ON_TABLE); //DO layout // create the layer for the panel using our custom layerUI tableScrollPane = new JScrollPane(tableFiles); JPanel tableScrollPaneWithFilter = new JPanel(new BorderLayout()); tableScrollPaneWithFilter.add(tableScrollPane); JToolBar filtersToolbar = new JToolBar("Filters"); filtersToolbar.setFloatable(false); filtersToolbar.setBorderPainted(true); tableScrollPaneWithFilter.add(filtersToolbar, BorderLayout.SOUTH); filtersToolbar.add(nameFilterLabel); filtersToolbar.add(filterField); filtersToolbar.add(showHidCheckBox); JSplitPane tableWithPreviewPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, tableScrollPaneWithFilter, previewComponent); tableWithPreviewPane.setOneTouchExpandable(true); JPanel loadingPanel = new JPanel(new MigLayout()); loadingPanel.add(loadingIconLabel, "right"); loadingPanel.add(loadingProgressBar, "left, w 420:420:500,wrap"); loadingPanel.add(skipCheckingLinksButton, "span, right"); tablePanel.add(loadingPanel, LOADING); tablePanel.add(tableWithPreviewPane, TABLE); JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(favoritesPanel), tablePanel); jSplitPane.setOneTouchExpandable(true); jSplitPane.setDividerLocation(180); JPanel southPanel = new JPanel(new MigLayout("", "[]push[][]", "")); southPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); southPanel.add(statusLabel); southPanel.add(actionApproveButton); southPanel.add(actionCancelButton); this.add(upperPanel, BorderLayout.NORTH); this.add(jSplitPane, BorderLayout.CENTER); this.add(southPanel, BorderLayout.SOUTH); try { selectionChanged(); } catch (FileSystemException e) { LOGGER.error("Can't initialize default selection mode", e); } // Why this not done in EDT? // Is it assume that constructor is invoked from an EDT? try { if (initialPath == null) { goToUrl(VFSUtils.getUserHome()); } else { try { FileObject resolveFile = VFSUtils.resolveFileObject(initialPath); if (resolveFile != null && resolveFile.getType() == FileType.FILE) { loadAndSelSingleFile(resolveFile); pathField.setText(resolveFile.getURL().toString()); targetFileSelected = true; return; } } catch (FileSystemException fse) { // Intentionally empty } goToUrl(initialPath); } } catch (FileSystemException e1) { LOGGER.error("Can't initialize default location", e1); } showTable(); }