List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingKnowledgeDBExplorerFrame.java
/** * Constructor./*from www . ja va2s.co m*/ */ GapFillingKnowledgeDBExplorerFrame(final Instances ds, final int dateIdx, final StationsDataProvider gcp) throws Exception { LogoHelper.setLogo(this); this.setTitle("KnowledgeDB: explorer"); this.gcp = gcp; this.tablePanel = new JXPanel(); this.tablePanel.setBorder(new TitledBorder("Cases")); final JXPanel highPanel = new JXPanel(); highPanel.setLayout(new BoxLayout(highPanel, BoxLayout.X_AXIS)); highPanel.add(this.tablePanel); this.geomapPanel = new JXPanel(); this.geomapPanel.add(buildGeoMapChart(new ArrayList<String>(), new ArrayList<String>())); highPanel.add(this.geomapPanel); this.caseChartPanel = new JXPanel(); this.caseChartPanel.setBorder(new TitledBorder("Inspected fake gap")); this.mostSimilarChartPanel = new JXPanel(); this.mostSimilarChartPanel.setBorder(new TitledBorder("Most similar")); this.nearestChartPanel = new JXPanel(); this.nearestChartPanel.setBorder(new TitledBorder("Nearest")); this.downstreamChartPanel = new JXPanel(); this.downstreamChartPanel.setBorder(new TitledBorder("Downstream")); this.upstreamChartPanel = new JXPanel(); this.upstreamChartPanel.setBorder(new TitledBorder("Upstream")); getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.PAGE_AXIS)); //getContentPane().add(new JCheckBox("Use incomplete series")); getContentPane().add(highPanel); //getContentPane().add(new JXButton("Export")); getContentPane().add(caseChartPanel); getContentPane().add(mostSimilarChartPanel); getContentPane().add(nearestChartPanel); getContentPane().add(downstreamChartPanel); getContentPane().add(upstreamChartPanel); //final Instances kdbDS=GapFillingKnowledgeDB.getKnowledgeDBWithBestCasesOnly(); final Instances kdbDS = GapFillingKnowledgeDB.getKnowledgeDB(); final JXTable gapsTable = buidJXTable(kdbDS); final JScrollPane tableScrollPane = new JScrollPane(gapsTable); tableScrollPane.setPreferredSize( new Dimension(COMPONENT_WIDTH - 100, 40 + (int) (tableScrollPane.getPreferredSize().getHeight()))); this.tablePanel.add(tableScrollPane); gapsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); gapsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { final int modelRow = gapsTable.getSelectedRow(); final String attrname = gapsTable.getModel().getValueAt(modelRow, 1).toString(); final int gapsize = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 4).toString()).doubleValue(); final int position = (int) Double .valueOf(gapsTable.getModel().getValueAt(modelRow, 5).toString()).doubleValue(); final String mostSimilarFlag = gapsTable.getModel().getValueAt(modelRow, 14).toString(); final String nearestFlag = gapsTable.getModel().getValueAt(modelRow, 15).toString(); final String downstreamFlag = gapsTable.getModel().getValueAt(modelRow, 16).toString(); final String upstreamFlag = gapsTable.getModel().getValueAt(modelRow, 17).toString(); final String algoname = gapsTable.getModel().getValueAt(modelRow, 12).toString(); final boolean useDiscretizedTime = Boolean .valueOf(gapsTable.getModel().getValueAt(modelRow, 13).toString()); try { geomapPanel.removeAll(); caseChartPanel.removeAll(); mostSimilarChartPanel.removeAll(); nearestChartPanel.removeAll(); downstreamChartPanel.removeAll(); upstreamChartPanel.removeAll(); final Set<String> selected = new HashSet<String>(); final Instances tmpds = WekaDataProcessingUtil.buildFilteredDataSet(ds, 0, ds.numAttributes() - 1, Math.max(0, position - GapsUtil.getCountOfValuesBeforeAndAfter(gapsize)), Math.min(position + gapsize + GapsUtil.getCountOfValuesBeforeAndAfter(gapsize), ds.numInstances() - 1)); final List<String> attributeNames = WekaTimeSeriesUtil .getNamesOfAttributesWithoutGap(tmpds); //final List<String> attributeNames=WekaDataStatsUtil.getAttributeNames(ds); attributeNames.remove(attrname); attributeNames.remove("timestamp"); if (Boolean.valueOf(mostSimilarFlag)) { final String mostSimilarStationName = WekaTimeSeriesSimilarityUtil .findMostSimilarTimeSerie(tmpds, tmpds.attribute(attrname), attributeNames, false); selected.add(mostSimilarStationName); final Attribute mostSimilarStationAttr = tmpds.attribute(mostSimilarStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, mostSimilarStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); mostSimilarChartPanel.add(cp0); } if (Boolean.valueOf(nearestFlag)) { final String nearestStationName = gcp.findNearestStation(attrname, attributeNames); selected.add(nearestStationName); final Attribute nearestStationAttr = ds.attribute(nearestStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, nearestStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); nearestChartPanel.add(cp0); } if (Boolean.valueOf(downstreamFlag)) { final String downstreamStationName = gcp.findDownstreamStation(attrname, attributeNames); selected.add(downstreamStationName); final Attribute downstreamStationAttr = ds.attribute(downstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, downstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); downstreamChartPanel.add(cp0); } if (Boolean.valueOf(upstreamFlag)) { final String upstreamStationName = gcp.findUpstreamStation(attrname, attributeNames); selected.add(upstreamStationName); final Attribute upstreamStationAttr = ds.attribute(upstreamStationName); final ChartPanel cp0 = GapsUIUtil.buildGapChartPanel(ds, dateIdx, upstreamStationAttr, gapsize, position); cp0.getChart().removeLegend(); cp0.setPreferredSize(CHART_DIMENSION); upstreamChartPanel.add(cp0); } final GapFiller gapFiller = GapFillerFactory.getGapFiller(algoname, useDiscretizedTime); final ChartPanel cp = GapsUIUtil.buildGapChartPanelWithCorrection(ds, dateIdx, ds.attribute(attrname), gapsize, position, gapFiller, selected); cp.getChart().removeLegend(); cp.setPreferredSize(new Dimension((int) CHART_DIMENSION.getWidth(), (int) (CHART_DIMENSION.getHeight() * 1.5))); caseChartPanel.add(cp); geomapPanel.add(buildGeoMapChart(Arrays.asList(attrname), selected)); getContentPane().repaint(); pack(); } catch (Exception e1) { e1.printStackTrace(); } } } }); gapsTable.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(final MouseEvent e) { if (!e.isPopupTrigger()) { // nothing? } else { final JPopupMenu jPopupMenu = new JPopupMenu("feur"); final JMenuItem mExport = new JMenuItem("Export this table as CSV"); mExport.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final JFileChooser fc = new JFileChooser(); fc.setAcceptAllFileFilterUsed(false); final int returnVal = fc.showSaveDialog(gapsTable); if (returnVal == JFileChooser.APPROVE_OPTION) { try { final File file = fc.getSelectedFile(); WekaDataAccessUtil.saveInstancesIntoCSVFile(kdbDS, file); } catch (Exception ee) { ee.printStackTrace(); } } } }); jPopupMenu.add(mExport); jPopupMenu.show(gapsTable, e.getX(), e.getY()); } } }); setPreferredSize(new Dimension(FRAME_WIDTH, 1000)); pack(); setVisible(true); /* select the first row */ gapsTable.setRowSelectionInterval(0, 0); }
From source file:com.opendoorlogistics.studio.components.geocoder.SearchResultsPanel.java
SearchResultsPanel(final NominatimConfig config, final GeocodeModel model) { this.model = model; this.config = config; // server selector at top serverBox = Controls.createServerBox(config.getServer()); serverBox.addValueChangedListener(new ValueChangedListener<String>() { @Override/*from ww w .ja va 2s .co m*/ public void comboValueChanged(String newValue) { updateAppearance(); } }); countryCode = Controls.createCountryBox(config.getCountryCode()); countryCode.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { updateAppearance(); } }); // refresh button by server selector refresh = new JButton(Icons.loadFromStandardPath("view-refresh-6.png")); refresh.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { refreshResults(); } }); refresh.setToolTipText("Re-run the query"); // add the controls addLine(Controls.createServerLabel(), serverBox); addWhitespace(6); addLine(Controls.createCountryFilterLabel(), countryCode, Box.createRigidArea(new Dimension(10, 1)), refresh); addWhitespace(); // results table in the middle table = new JTable(); table.setColumnSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { readSelectedIntoModel(); } }); table.setFillsViewportHeight(true); JScrollPane scrollPane = new JScrollPane(table); add(scrollPane); setTableModel(); model.addListener(this); updateAppearance(); }
From source file:de.tor.tribes.ui.views.DSWorkbenchRankFrame.java
/** Creates new form DSWorkbenchRankFrame */ DSWorkbenchRankFrame() {/* ww w. ja v a2 s. co m*/ initComponents(); centerPanel = new GenericTestPanel(); jRankPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jXRankPanel); buildMenu(); capabilityInfoPanel1.addActionListener(this); jRankTabPane.getModel().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { RankTableTab activeTab = getActiveTab(); if (activeTab != null) { activeTab.updateTab(); } } }); jXColumnList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateFilter(); } }); setGlassPane(jxSearchPane); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.ranking_view", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> // updateRankTable(); }
From source file:com.sec.ose.osi.ui.frm.main.report.project.JPanProjectExplorer.java
/** * This method initializes jListSelectedProjects * //from w w w. j av a 2 s. c o m * @return javax.swing.JList */ public JListProjectWithPopup getJListManagedProjects() { if (jListManagedProjects == null) { jListManagedProjects = new JListProjectWithPopup(); jListManagedProjects.addListSelectionListener(new ListSelectionListener() { @SuppressWarnings("deprecation") @Override public void valueChanged(ListSelectionEvent e) { getjPanBOM().setProjectListTextInfo(jListManagedProjects.getSelectedValues()); getjPanBOM().setReportUIEnabled(jListManagedProjects.getSelectedValues()); } }); } return jListManagedProjects; }
From source file:com.digitalgeneralists.assurance.ui.components.ResultsPanel.java
private void initializeComponent() { if (!this.initialized) { GridBagLayout gridbag = new GridBagLayout(); this.setLayout(gridbag); ((DefaultTableCellRenderer) resultsTable.getTableHeader().getDefaultRenderer()) .setHorizontalAlignment(JLabel.CENTER); this.resultsTable.setRowHeight(150); ListSelectionModel selectionModel = this.resultsTable.getSelectionModel(); selectionModel.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { applicationDelegate.fireEvent(new SetScanResultsMenuStateEvent(false)); resultsTable.editCellAt(resultsTable.getSelectedRow(), 0); }// www .ja v a 2s.c om }); GridBagConstraints resultsLabelConstraints = new GridBagConstraints(); resultsLabelConstraints.anchor = GridBagConstraints.WEST; resultsLabelConstraints.fill = GridBagConstraints.BOTH; resultsLabelConstraints.gridx = 0; resultsLabelConstraints.gridy = 0; resultsLabelConstraints.weightx = 1.0; resultsLabelConstraints.weighty = 0.1; resultsLabelConstraints.gridheight = 1; resultsLabelConstraints.gridwidth = 1; resultsLabelConstraints.insets = new Insets(5, 5, 5, 5); this.progressIndicatorConstraints.anchor = GridBagConstraints.WEST; this.progressIndicatorConstraints.fill = GridBagConstraints.BOTH; this.progressIndicatorConstraints.gridx = 0; this.progressIndicatorConstraints.gridy = 1; this.progressIndicatorConstraints.weightx = 1.0; this.progressIndicatorConstraints.weighty = 0.1; this.progressIndicatorConstraints.gridheight = 1; this.progressIndicatorConstraints.gridwidth = 1; this.progressIndicatorConstraints.insets = new Insets(5, 5, 5, 5); this.progressIndicator.setIndeterminate(true); this.resultsListConstraints.anchor = GridBagConstraints.WEST; this.resultsListConstraints.fill = GridBagConstraints.BOTH; this.resultsListConstraints.gridx = 0; this.resultsListConstraints.gridy = 2; this.resultsListConstraints.weightx = 1.0; this.resultsListConstraints.weighty = 0.9; this.resultsListConstraints.gridheight = 1; this.resultsListConstraints.gridwidth = 1; this.resultsListConstraints.insets = new Insets(5, 5, 5, 5); this.add(this.resultsLabel, resultsLabelConstraints); this.add(this.resultsScrollPane, this.resultsListConstraints); this.addAncestorListener(new AncestorListener() { public void ancestorAdded(AncestorEvent event) { resultsTable.setDefaultRenderer(ComparisonResult.class, comparisonResultListRenderer); resultsTable.setDefaultEditor(ComparisonResult.class, comparisonResultListRenderer); applicationDelegate.addEventObserver(ScanStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ComparisonResultAddedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanResultsLoadedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(SelectedScanChangedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ResultMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanMergeStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanMergeProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(ScanMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.addEventObserver(DeletedItemRestoreCompletedEvent.class, (IEventObserver) event.getSource()); } public void ancestorRemoved(AncestorEvent event) { applicationDelegate.removeEventObserver(ScanStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ComparisonResultAddedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanResultsLoadedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(SelectedScanChangedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ResultMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanMergeStartedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanMergeProgressEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(ScanMergeCompletedEvent.class, (IEventObserver) event.getSource()); applicationDelegate.removeEventObserver(DeletedItemRestoreCompletedEvent.class, (IEventObserver) event.getSource()); } public void ancestorMoved(AncestorEvent event) { } }); this.initialized = true; } }
From source file:table.TablePanel.java
public TablePanel(JPanel parent, GridBagConstraints c) { this.parent = parent; this.c = c;// w w w . j a v a2 s.c om dataHandler = null; data = new ArrayList<>(); selectedRows = new ArrayList<>(); tableModel = new MyTableModel(data); table = new JTable(tableModel); table.getColumnModel().getColumn(0).setResizable(false); table.getColumnModel().getColumn(0).setMaxWidth(60); table.getColumnModel().getColumn(1).setResizable(false); table.getColumnModel().getColumn(1).setMaxWidth(50); table.getColumnModel().getColumn(2).setMaxWidth(90); table.getColumnModel().getColumn(49).setMaxWidth(60); for (int i = 0; i < tableModel.getColumnCount(); i++) { if (i > 14 && i < 31) { table.getColumnModel().getColumn(i).setMaxWidth(70); } else if (tableModel.columnNamesTemp[i].contains("LEVEL")) { if (tableModel.columnNamesTemp[i].equals("QEC LEVEL")) { table.getColumnModel().getColumn(i).setMinWidth(90); table.getColumnModel().getColumn(i).setMaxWidth(200); } else { table.getColumnModel().getColumn(i).setMaxWidth(90); } if (tableModel.columnNamesTemp[i - 1].equals("Work Pace")) { table.getColumnModel().getColumn(i - 1).setMinWidth(90); table.getColumnModel().getColumn(i - 1).setMaxWidth(150); } else { table.getColumnModel().getColumn(i - 1).setMaxWidth(90); } } else { // table.getColumnModel().getColumn(i).setMinWidth(120); // table.getColumnModel().getColumn(i).setMaxWidth(250); } } table.getColumnModel().getColumn(table.getColumnCount() - 1).setMaxWidth(60); table.getColumnModel().getColumn(table.getColumnCount() - 1).setResizable(false); table.setRowSelectionAllowed(true); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (!dataHandler.getDeleting() && (table.getSelectedRow() != -1) && e.getColumn() != table.getColumnCount() - 1 && e.getColumn() != 1) { int row = table.getSelectedRow(); int col = e.getColumn(); if (col == 0 && (boolean) table.getValueAt(row, col) == true) { if (!selectedRows.contains((Integer) row)) selectedRows.add(row); } else if (col == 0 && (boolean) table.getValueAt(row, col) == false) { selectedRows.remove((Object) row); } else if (col != 0 && (boolean) table.getValueAt(row, table.getColumnCount() - 1)) { dataHandler.dataEdited(); } } } }); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { private int count = 0; @Override public void valueChanged(ListSelectionEvent arg0) { if (count > 1 && !arg0.getValueIsAdjusting()) { int[] draggedRows = table.getSelectedRows(); for (int i = 0; i < draggedRows.length; i++) if (selectedRows.contains((Integer) draggedRows[i])) { selectedRows.remove((Integer) draggedRows[i]); table.setValueAt(false, draggedRows[i], 0); } else { selectedRows.add((Integer) draggedRows[i]); table.setValueAt(true, draggedRows[i], 0); } // Finalize count = 0; } else if (arg0.getValueIsAdjusting()) count++; else count = 0; } }); // { // // @Override // public Component prepareRenderer(TableCellRenderer renderer, // int row, int column) { // JLabel label = (JLabel) super.prepareRenderer(renderer, row, column); // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) == // false) { // if ((int) row % 2 == 0) { // label.setBackground(new Color(244, 226,215)); // } else { // label.setBackground(new Color(241, 220,205)); // } // } else { // if ((int) row% 2 == 0) { // label.setBackground(new Color(255, 255, 255)); // } else { // label.setBackground(new Color(252, 252, 252)); // } // // } // if(table.getSelectedRow()==row) // label.setBackground(Color.LIGHT_GRAY); // return label; // } // }; // table.prepareRenderer(null, WIDTH, WIDTH); // table.setRowSelectionAllowed(true); // table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDefaultRenderer(Object.class, new MyTableCellRenderer()); // { // // @Override // public Component getTableCellRendererComponent(JTable table, Object // value, boolean isSelected, boolean hasFocus, int row, int column) { // JLabel label = (JLabel) table.prepareRenderer(null, row, column); // if ((boolean) table.getValueAt(row, table.getColumnCount() - 1) == // false) { // if ((int) row % 2 == 0) { // label.setBackground(new Color(244, 226,215)); // } else { // label.setBackground(new Color(241, 220,205)); // } // } else { // if ((int) row% 2 == 0) { // label.setBackground(new Color(255, 255, 255)); // } else { // label.setBackground(new Color(252, 252, 252)); // } // // } // if(table.getSelectedRow()==row) // label.setBackground(Color.LIGHT_GRAY); // return label; // } // }); // { // // @Override // public Component getTableCellRendererComponent(JTable table, Object // value, boolean isSelected, boolean hasFocus, int row, int column) { // Component cell= table.getCellRenderer(row, // column).getTableCellRendererComponent(table, value, isSelected, // hasFocus, row, column); // // // for(int i=1;i<table.getRowCount();i++) { // if((boolean)table.getValueAt(i, table.getColumnCount()-1) ==false) // { // setForeground(Color.black); // setBackground(Color.red); // } // else // { // setBackground(Color.white); // setForeground(Color.black); // } // } // return cell; // } // }); // DefaultTableCellRenderer rightRenderer = new // DefaultTableCellRenderer(); // rightRenderer.setHorizontalAlignment(DefaultTableCellRenderer.RIGHT); for (int i = 0; i < tableModel.getColumnCount(); i++) { table.getTableHeader().getColumnModel().getColumn(i) .setHeaderRenderer(new HeaderRenderer(table, alignments[1])); // table.getColumnModel().getColumn(i).setCellRenderer(new // MyTableCellRenderer()); } table.getTableHeader().setReorderingAllowed(false); table.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); table.setRowHeight(25); // table.setPreferredScrollableViewportSize(new Dimension(10000, 200)); // Create the scroll pane and add the table to it. JScrollPane scrollPane = new JScrollPane(table); // JViewport tableView = new JViewport(); // tableView.add(table); // scrollPane.setViewport(tableView); parent.setSize(table.getWidth(), table.getHeight()); // parent.setPreferredSize(new Dimension(70000,10000)); // scrollPane.setVerticalScrollBar(new JScrollBar(JScrollBar.VERTICAL)); // scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL)); // Add the scroll pane to this panel. // parent.add(table.getTableHeader()); // parent.add(table, c); // Add header in NORTH slot parent.add(table.getTableHeader(), BorderLayout.NORTH); // Add table itself to CENTER slot parent.add(table, BorderLayout.CENTER); }
From source file:logdruid.ui.DateEditor.java
/** * Create the panel./*from w ww . j a va 2 s.co m*/ */ public DateEditor(Repository rep) { repository = rep; model = new MyTableModel2(data, header); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 15, 550, 15 }; gridBagLayout.rowHeights = new int[] { 152, 300 }; gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0 }; gridBagLayout.rowWeights = new double[] { 0.0, 1.0 }; setLayout(gridBagLayout); JPanel panel_1 = new JPanel(); GridBagConstraints gbc_panel_1 = new GridBagConstraints(); gbc_panel_1.fill = GridBagConstraints.BOTH; gbc_panel_1.insets = new Insets(5, 0, 5, 5); gbc_panel_1.gridx = 1; gbc_panel_1.gridy = 0; add(panel_1, gbc_panel_1); panel_1.setLayout(new BorderLayout(0, 0)); table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setBorder(UIManager.getBorder("TextPane.border")); table.setPreferredScrollableViewportSize(new Dimension(0, 0)); table.setFillsViewportHeight(true); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // ((table.getSelectedRow()!=-1)?table.convertRowIndexToModel(table.getSelectedRow()):-1) // persist repository // display selected row if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1) >= 0) { /* * recEditor = new RecordingEditor(repository * .getRecordings().get(((table.getSelectedRow()!=-1)?table. * convertRowIndexToModel(table.getSelectedRow()):-1)), * repository); jPanelDetail.removeAll(); */ // jPanelDetail.add(recEditor, gbc_jPanelDetail); DateFormat df = repository.getDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); if (df != null) { textFieldName.setText((String) df.getName()); textFieldPattern.setText((String) df.getPattern()); textField.setText((String) df.getDateFormat()); } // jPanelDetail.revalidate(); // jPanelDetail.repaint(); // jPanelDetail.setVisible(true); // reloadTable(); those 2 ******** // jPanelDetail.revalidate(); } } }); JScrollPane scrollPane = new JScrollPane(table); panel_1.add(scrollPane, BorderLayout.CENTER); // Set up column sizes. initColumnSizes(table); JPanel panel = new JPanel(); FlowLayout flowLayout = (FlowLayout) panel.getLayout(); flowLayout.setAlignment(FlowLayout.LEFT); flowLayout.setVgap(2); flowLayout.setHgap(2); panel_1.add(panel, BorderLayout.SOUTH); JButton btnNew = new JButton("New"); panel.add(btnNew); btnNew.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { DateFormat df = new DateFormat("name", "\\w{3}\\s[0-9]{1}/[0-9]{2}/[0-9]{2}\\s\\d\\d:\\d\\d:\\d\\d", "EEE. MM/dd/yy HH:mm:ss"); repository.addDateFormat(df); data.add(new Object[] { df.getName(), df.getPattern(), df.getDateFormat() }); table.repaint(); } }); JButton btnDuplicate = new JButton("Duplicate"); btnDuplicate.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1) >= 0) { DateFormat df = repository.getDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); repository.addDateFormat(df); reloadTable(); // data.add(new Object[] { table.getRowCount()+1, // df.getName(),df.getDateFormat()}); table.repaint(); } } }); panel.add(btnDuplicate); JButton btnDelete = new JButton("Delete"); btnDelete.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int selectedRow = ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1); if (selectedRow >= 0) { repository.deleteDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); data.remove( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); reloadTable(); table.setRowSelectionInterval(selectedRow, selectedRow); table.repaint(); } } }); panel.add(btnDelete); jPanelDetail = new JPanel(); gbc_jPanelDetail = new GridBagConstraints(); gbc_jPanelDetail.anchor = GridBagConstraints.NORTH; gbc_jPanelDetail.fill = GridBagConstraints.HORIZONTAL; gbc_jPanelDetail.gridx = 1; gbc_jPanelDetail.gridy = 1; add(jPanelDetail, gbc_jPanelDetail); GridBagLayout gbl_jPanelDetail = new GridBagLayout(); gbl_jPanelDetail.columnWidths = new int[] { 169 }; gbl_jPanelDetail.rowHeights = new int[] { 0, 0, 0, 0, 150, 0 }; gbl_jPanelDetail.columnWeights = new double[] { 1.0, 0.0 }; gbl_jPanelDetail.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 }; jPanelDetail.setLayout(gbl_jPanelDetail); JPanel panel_2 = new JPanel(); panel_2.setBorder(null); GridBagConstraints gbc_panel_2 = new GridBagConstraints(); gbc_panel_2.gridwidth = 2; gbc_panel_2.anchor = GridBagConstraints.NORTHWEST; gbc_panel_2.insets = new Insets(0, 0, 5, 0); gbc_panel_2.gridx = 0; gbc_panel_2.gridy = 0; jPanelDetail.add(panel_2, gbc_panel_2); panel_2.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5)); JLabel label = new JLabel("Name"); panel_2.add(label); textFieldName = new JTextField(); textFieldName.setColumns(20); panel_2.add(textFieldName); JPanel panel_3 = new JPanel(); FlowLayout flowLayout_1 = (FlowLayout) panel_3.getLayout(); flowLayout_1.setAlignment(FlowLayout.LEFT); panel_3.setBorder(null); GridBagConstraints gbc_panel_3 = new GridBagConstraints(); gbc_panel_3.insets = new Insets(0, 0, 5, 0); gbc_panel_3.gridwidth = 2; gbc_panel_3.anchor = GridBagConstraints.NORTHWEST; gbc_panel_3.gridx = 0; gbc_panel_3.gridy = 1; jPanelDetail.add(panel_3, gbc_panel_3); labelPattern = new JLabel("Pattern"); panel_3.add(labelPattern); textFieldPattern = new JTextField(); textFieldPattern.setColumns(40); panel_3.add(textFieldPattern); JButton btnSave = new JButton("Save"); btnSave.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { DateFormat df1 = repository.getDateFormat( ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow()) : -1)); df1.update(textFieldName.getText(), textFieldPattern.getText(), textField.getText()); reloadTable(); } }); JPanel panel_4 = new JPanel(); FlowLayout flowLayout_2 = (FlowLayout) panel_4.getLayout(); flowLayout_2.setAlignment(FlowLayout.LEFT); GridBagConstraints gbc_panel_4 = new GridBagConstraints(); gbc_panel_4.anchor = GridBagConstraints.WEST; gbc_panel_4.insets = new Insets(0, 0, 5, 5); gbc_panel_4.gridx = 0; gbc_panel_4.gridy = 2; jPanelDetail.add(panel_4, gbc_panel_4); JLabel lblFastDateFormat = new JLabel("FastDateFormat"); panel_4.add(lblFastDateFormat); textField = new JTextField(); panel_4.add(textField); textField.setColumns(30); JPanel panel_5 = new JPanel(); FlowLayout flowLayout_3 = (FlowLayout) panel_5.getLayout(); flowLayout_3.setAlignment(FlowLayout.LEFT); GridBagConstraints gbc_panel_5 = new GridBagConstraints(); gbc_panel_5.insets = new Insets(0, 0, 5, 5); gbc_panel_5.fill = GridBagConstraints.BOTH; gbc_panel_5.gridx = 0; gbc_panel_5.gridy = 3; jPanelDetail.add(panel_5, gbc_panel_5); JLabel lblSampleLabel = new JLabel("Sample"); panel_5.add(lblSampleLabel); JPanel panel_6 = new JPanel(); panel_6.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null)); GridBagConstraints gbc_panel_6 = new GridBagConstraints(); gbc_panel_6.ipady = 1; gbc_panel_6.ipadx = 1; gbc_panel_6.insets = new Insets(0, 0, 5, 5); gbc_panel_6.fill = GridBagConstraints.BOTH; gbc_panel_6.gridx = 0; gbc_panel_6.gridy = 4; jPanelDetail.add(panel_6, gbc_panel_6); panel_6.setLayout(new BorderLayout(0, 0)); JTextPane textPane = new JTextPane(); textPane.setBackground(UIManager.getColor("windowBorder")); panel_6.add(textPane); GridBagConstraints gbc_btnSave = new GridBagConstraints(); gbc_btnSave.anchor = GridBagConstraints.WEST; gbc_btnSave.insets = new Insets(0, 0, 0, 5); gbc_btnSave.gridx = 0; gbc_btnSave.gridy = 5; jPanelDetail.add(btnSave, gbc_btnSave); reloadTable(); }
From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java
private void initInboundReplacementTable() { inboundReplacementTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); DefaultTableModel model = new DefaultTableModel(new Object[][] {}, new String[] { "Replace All", "Replace With" }) { public boolean isCellEditable(int rowIndex, int columnIndex) { return true; }/*from ww w . j av a2 s . c o m*/ @Override public void setValueAt(Object value, int row, int column) { if (!value.equals(getValueAt(row, column))) { parent.setSaveEnabled(true); } super.setValueAt(value, row, column); } }; inboundReplacementTable.setSortable(false); inboundReplacementTable.getTableHeader().setReorderingAllowed(false); inboundReplacementTable.setModel(model); inboundReplacementTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { inboundDeleteButton.setEnabled(inboundReplacementTable.getSelectedRow() != -1); } }); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { inboundReplacementTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } inboundDeleteButton.setEnabled(false); }
From source file:net.sourceforge.atunes.kernel.modules.state.RepositoryPanel.java
/** * Initializes panel//from www. j a va2 s.c o m */ public void initialize() { this.refreshTime = new JComboBox(new Integer[] { 0, 5, 10, 15, 30, 60 }); this.commandBeforeAccessRepository = this.controlsBuilder.createTextField(); this.commandBeforeAccessRepository.setColumns(20); this.commandAfterAccessRepository = this.controlsBuilder.createTextField(); this.commandAfterAccessRepository.setColumns(20); this.repositoryFoldersList = this.lookAndFeelManager.getCurrentLookAndFeel().getList(); this.repositoryFoldersList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); this.addFolderButton = new JButton(I18nUtils.getString("ADD")); this.removeFolderButton = new JButton(I18nUtils.getString("REMOVE")); this.repositoryFoldersList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent event) { RepositoryPanel.this.removeFolderButton .setEnabled(RepositoryPanel.this.repositoryFoldersList.getSelectedIndex() != -1); } }); this.addFolderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent arg0) { IFolderSelectorDialog dialog = RepositoryPanel.this.dialogFactory .newDialog(IFolderSelectorDialog.class); dialog.setTitle(I18nUtils.getString("ADD_FOLDER_TO_REPOSITORY")); File folder = dialog.selectFolder(RepositoryPanel.this.osManager.getUserHome()); if (folder != null) { RepositoryPanel.this.repositoryFolders.add(folder); RepositoryPanel.this.repositoryFoldersList .setListData(RepositoryPanel.this.repositoryFolders.toArray()); } } }); this.removeFolderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent event) { RepositoryPanel.this.repositoryFolders .remove(RepositoryPanel.this.repositoryFoldersList.getSelectedIndex()); RepositoryPanel.this.repositoryFoldersList .setListData(RepositoryPanel.this.repositoryFolders.toArray()); } }); this.useRatingsStoredInTag = new JCheckBox(I18nUtils.getString("USE_RATINGS_STORED_IN_TAG")); setupPanel(); }
From source file:au.org.ala.delta.editor.ui.ActionSetsDialog.java
private void addEventHandlers() { runButton.setAction(_actions.get("runDirectiveFile")); addButton.setAction(_actions.get("addDirectiveFile")); editButton.setAction(_actions.get("editDirectiveFile")); deleteButton.setAction(_actions.get("deleteDirectiveFile")); doneButton.setAction(_actions.get("doneWithActionSets")); JTable[] tables = { conforTable, intkeyTable, distTable, keyTable }; for (final JTable table : tables) { table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override//w w w. j a v a 2s .co m public void valueChanged(ListSelectionEvent e) { updateAction(); } }); table.getTableHeader().setReorderingAllowed(false); } tabbedPane.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateAction(); } }); }