List of usage examples for javax.swing.table DefaultTableCellRenderer DefaultTableCellRenderer
public DefaultTableCellRenderer()
From source file:com.view.PortfolioManagerWindow.java
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor.//from w w w . ja v a2 s .c o m */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; logOutButton = new javax.swing.JButton(); PMPlatformTabbedPane = new javax.swing.JTabbedPane(); PendingOrders = new javax.swing.JPanel(); PendingOrderRequests = new javax.swing.JScrollPane(); PMPendingOrdersTable = new javax.swing.JTable(); PMPendingOrderFilter = new javax.swing.JButton(); FilterOptionsPMPending = new javax.swing.JComboBox<>(); FilterTextPMPending = new javax.swing.JTextField(); ClearFilterPMPendingOrder = new javax.swing.JButton(); PMEOD = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); PMEODBoughtScrollPane = new javax.swing.JScrollPane(); PMEODBoughtTable = new javax.swing.JTable(); PMEODSoldScrollPane = new javax.swing.JScrollPane(); PMEODSoldTable = new javax.swing.JTable(); jLabel3 = new javax.swing.JLabel(); FilterTextPMEOD = new javax.swing.JTextField(); FilterOptionsPMEOD = new javax.swing.JComboBox<>(); PMEODFilter = new javax.swing.JButton(); ClearFilterPMEOD = new javax.swing.JButton(); CreateOrder = new javax.swing.JPanel(); PMSelectTraderOptions = new javax.swing.JComboBox<>(); jLabel5 = new javax.swing.JLabel(); PMSendOrderScrollPane = new javax.swing.JScrollPane(); PMSendOrderTable = new javax.swing.JTable(); PMSendOrder = new javax.swing.JButton(); PMAddOrderRow = new javax.swing.JButton(); PMOrderHistory = new javax.swing.JPanel(); PMOrderHistoryScrollPane = new javax.swing.JScrollPane(); PMOrderHistoryTable = new javax.swing.JTable(); FilterTextPMOrderHistory = new javax.swing.JTextField(); FilterOptionsPMOrderHistory = new javax.swing.JComboBox<>(); PMOrderHistoryFilter = new javax.swing.JButton(); ClearFilterPMOrderHistory = new javax.swing.JButton(); ChangePassword = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("MoneyTree Trading Platform: Portfolio Manager"); setMinimumSize(new java.awt.Dimension(1024, 768)); getContentPane().setLayout(new java.awt.GridBagLayout()); logOutButton.setText("Logout"); logOutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logOutButtonActionPerformed(evt); } }); getContentPane().add(logOutButton, new java.awt.GridBagConstraints()); PMPlatformTabbedPane.setMinimumSize(new java.awt.Dimension(150, 65)); PMPendingOrdersTable.setBackground(new java.awt.Color(102, 102, 102)); PMPendingOrdersTable .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); String[] CurrencyValues = { "USD", "GBP" }; PMPendingOrdersTable.setForeground(new java.awt.Color(255, 255, 255)); PMPendingOrdersTable.setModel(com.controller.CPMOrderMANIAC.getPRTableModel()); PMPendingOrdersTable.setGridColor(new java.awt.Color(255, 255, 255)); PMPendingOrdersTable.getTableHeader().setReorderingAllowed(false); PendingOrderRequests.setViewportView(PMPendingOrdersTable); PMPendingOrderFilter.setText("Filter"); PMPendingOrderFilter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMPendingOrderFilterActionPerformed(evt); } }); FilterOptionsPMPending.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "Order ID", "Portfolio ID", "Symbol", "Quantity", "Action", "Stop Price", "Limit Price", "Account Type", "Order Type", "Assigned To" })); FilterTextPMPending.setText("Filter Text"); ClearFilterPMPendingOrder.setText("Clear Filter"); ClearFilterPMPendingOrder.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearFilterPMPendingOrderActionPerformed(evt); } }); javax.swing.GroupLayout PendingOrdersLayout = new javax.swing.GroupLayout(PendingOrders); PendingOrders.setLayout(PendingOrdersLayout); PendingOrdersLayout.setHorizontalGroup( PendingOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PendingOrdersLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(PendingOrderRequests, javax.swing.GroupLayout.PREFERRED_SIZE, 801, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) .addGroup(PendingOrdersLayout.createSequentialGroup().addContainerGap() .addComponent(FilterTextPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(FilterOptionsPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMPendingOrderFilter).addGap(18, 18, 18) .addComponent(ClearFilterPMPendingOrder) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PendingOrdersLayout.setVerticalGroup(PendingOrdersLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PendingOrdersLayout.createSequentialGroup().addContainerGap() .addComponent(PendingOrderRequests, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(PendingOrdersLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(FilterTextPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(FilterOptionsPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(PMPendingOrderFilter).addComponent(ClearFilterPMPendingOrder)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("Pending Order Requests", PendingOrders); jLabel2.setText("Bought"); PMEODBoughtTable.setModel(CPMEndOfDay.getBuyTableModel()); PMEODBoughtScrollPane.setViewportView(PMEODBoughtTable); PMEODSoldTable.setModel(CPMEndOfDay.getSellTableModel()); PMEODSoldScrollPane.setViewportView(PMEODSoldTable); jLabel3.setText("Sold"); FilterTextPMEOD.setText("Filter By"); FilterOptionsPMEOD.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "Portfolio ID", "Symbol", "Quantity", "Price" })); PMEODFilter.setText("Filter"); PMEODFilter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMEODFilterActionPerformed(evt); } }); ClearFilterPMEOD.setText("Clear Filter"); ClearFilterPMEOD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearFilterPMEODActionPerformed(evt); } }); javax.swing.GroupLayout PMEODLayout = new javax.swing.GroupLayout(PMEOD); PMEOD.setLayout(PMEODLayout); PMEODLayout.setHorizontalGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PMEODLayout.createSequentialGroup() .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(PMEODLayout.createSequentialGroup().addGap(124, 124, 124) .addComponent(FilterTextPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(FilterOptionsPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMEODFilter)) .addGroup(PMEODLayout.createSequentialGroup().addGroup(PMEODLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMEODLayout.createSequentialGroup().addGap(234, 234, 234) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PMEODLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(PMEODBoughtScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18))) .addGroup(PMEODLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(PMEODSoldScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PMEODLayout.createSequentialGroup().addComponent(jLabel3) .addGap(132, 132, 132))))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ClearFilterPMEOD).addGap(55, 55, 55))); PMEODLayout.setVerticalGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMEODLayout.createSequentialGroup().addContainerGap() .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(jLabel2)) .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMEODLayout.createSequentialGroup().addGap(15, 15, 15).addComponent( PMEODSoldScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(PMEODLayout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(PMEODBoughtScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(21, 21, 21) .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(PMEODFilter) .addComponent(FilterOptionsPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(FilterTextPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ClearFilterPMEOD)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("EOD", PMEOD); PMSelectTraderOptions.setModel(new javax.swing.DefaultComboBoxModel<>(TraderNames)); PMSelectTraderOptions.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMSelectTraderOptionsActionPerformed(evt); } }); jLabel5.setText("Select Trader to Assign To:"); PMSendOrderTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null, null, null, null, null } }, new String[] { "Portfolio ID", "Stock Exchange", "Symbol", "Quantity", "Action", "Order Type", "Stop Price", "Limit Price", "Account Type" }) { Class[] types = new Class[] { java.lang.Long.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.String.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); TableColumn col2 = PMSendOrderTable.getColumnModel().getColumn(1); col2.setCellEditor(new myComboBoxEditor(StockExchange)); col2.setCellRenderer(new MyComboBoxRenderer(StockExchange)); TableColumn col1 = PMSendOrderTable.getColumnModel().getColumn(4); col1.setCellEditor(new myComboBoxEditor(ActionItems)); col1.setCellRenderer(new MyComboBoxRenderer(ActionItems)); TableColumn col5 = PMSendOrderTable.getColumnModel().getColumn(5); col5.setCellEditor(new myComboBoxEditor(OrderType)); col5.setCellRenderer(new MyComboBoxRenderer(OrderType)); TableColumn col3 = PMSendOrderTable.getColumnModel().getColumn(8); col3.setCellEditor(new myComboBoxEditor(AccountType)); col3.setCellRenderer(new MyComboBoxRenderer(AccountType)); /////////////////////////////////////GG TableColumn col4 = PMSendOrderTable.getColumnModel().getColumn(2); CSVReader csv = new CSVReader(); ArrayList<String> symbolList = csv.loadSymbol(); Java2sAutoComboBox comboBox = new Java2sAutoComboBox(symbolList); comboBox.setDataList(symbolList); comboBox.setMaximumRowCount(5); col4.setCellEditor(new DefaultCellEditor(comboBox)); //Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); col4.setCellRenderer(renderer); /////////////////////////////////////gg PMSendOrderScrollPane.setViewportView(PMSendOrderTable); PMSendOrder.setText("Send Order"); PMSendOrder.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMSendOrderActionPerformed(evt); } }); PMAddOrderRow.setText("Add Row"); PMAddOrderRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMAddOrderRowActionPerformed(evt); } }); javax.swing.GroupLayout CreateOrderLayout = new javax.swing.GroupLayout(CreateOrder); CreateOrder.setLayout(CreateOrderLayout); CreateOrderLayout.setHorizontalGroup(CreateOrderLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(PMSendOrderScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CreateOrderLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(CreateOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CreateOrderLayout .createSequentialGroup().addComponent(jLabel5).addGap(18, 18, 18) .addComponent(PMSelectTraderOptions, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(213, 213, 213).addComponent(PMSendOrder).addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CreateOrderLayout.createSequentialGroup().addComponent(PMAddOrderRow) .addGap(109, 109, 109))))); CreateOrderLayout.setVerticalGroup(CreateOrderLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(CreateOrderLayout.createSequentialGroup().addGap(5, 5, 5).addGroup(CreateOrderLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(CreateOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(PMSelectTraderOptions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(PMSendOrder)).addGap(28, 28, 28) .addComponent(PMSendOrderScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMAddOrderRow) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("Create Order", CreateOrder); PMOrderHistoryTable.setBackground(new java.awt.Color(102, 102, 102)); PMOrderHistoryTable .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); PMOrderHistoryTable.setForeground(new java.awt.Color(255, 255, 255)); PMOrderHistoryTable.setModel(com.controller.CPMOrderMANIAC.getOHTableModel()); PMOrderHistoryTable.setGridColor(new java.awt.Color(255, 255, 255)); PMOrderHistoryTable.getTableHeader().setReorderingAllowed(false); PMOrderHistoryScrollPane.setViewportView(PMOrderHistoryTable); FilterTextPMOrderHistory.setText("Filter By"); FilterOptionsPMOrderHistory.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "Order ID", "Portfolio ID", "Symbol", "Quantity", "Action", "Stop Price", "Limit Price", "Account Type", "Order Type", "Assigned To" })); PMOrderHistoryFilter.setText("Filter"); PMOrderHistoryFilter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMOrderHistoryFilterActionPerformed(evt); } }); ClearFilterPMOrderHistory.setText("Clear Filter"); ClearFilterPMOrderHistory.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearFilterPMOrderHistoryActionPerformed(evt); } }); javax.swing.GroupLayout PMOrderHistoryLayout = new javax.swing.GroupLayout(PMOrderHistory); PMOrderHistory.setLayout(PMOrderHistoryLayout); PMOrderHistoryLayout .setHorizontalGroup( PMOrderHistoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMOrderHistoryLayout.createSequentialGroup().addContainerGap() .addGroup(PMOrderHistoryLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(PMOrderHistoryScrollPane) .addGroup(PMOrderHistoryLayout.createSequentialGroup() .addComponent(FilterTextPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(FilterOptionsPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMOrderHistoryFilter) .addGap(18, 18, 18).addComponent(ClearFilterPMOrderHistory) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); PMOrderHistoryLayout.setVerticalGroup(PMOrderHistoryLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMOrderHistoryLayout.createSequentialGroup() .addComponent(PMOrderHistoryScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(PMOrderHistoryLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(FilterTextPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(FilterOptionsPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(PMOrderHistoryFilter).addComponent(ClearFilterPMOrderHistory)) .addGap(0, 0, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("Executed Order History", PMOrderHistory); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 2; gridBagConstraints.ipady = 127; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 85); getContentPane().add(PMPlatformTabbedPane, gridBagConstraints); ChangePassword.setText("Change Password"); ChangePassword.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ChangePasswordActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(11, 610, 0, 85); getContentPane().add(ChangePassword, gridBagConstraints); pack(); }
From source file:com.mirth.connect.connectors.http.HttpListener.java
private void initComponentsManual() { staticResourcesTable.setModel(new RefreshTableModel(StaticResourcesColumn.getNames(), 0) { @Override// ww w . j av a 2 s . c o m public boolean isCellEditable(int rowIndex, int columnIndex) { return true; } }); staticResourcesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); staticResourcesTable.setRowHeight(UIConstants.ROW_HEIGHT); staticResourcesTable.setFocusable(true); staticResourcesTable.setSortable(false); staticResourcesTable.setOpaque(true); staticResourcesTable.setDragEnabled(false); staticResourcesTable.getTableHeader().setReorderingAllowed(false); staticResourcesTable.setShowGrid(true, true); staticResourcesTable.setAutoCreateColumnsFromModel(false); staticResourcesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); staticResourcesTable.setRowSelectionAllowed(true); staticResourcesTable.setCustomEditorControls(true); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { staticResourcesTable.setHighlighters(HighlighterFactory .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR)); } class ContextPathCellEditor extends TextFieldCellEditor { public ContextPathCellEditor() { getTextField().setDocument(new MirthFieldConstraints("^\\S*$")); } @Override protected boolean valueChanged(String value) { if (StringUtils.isEmpty(value) || value.equals("/")) { return false; } if (value.equals(getOriginalValue())) { return false; } for (int i = 0; i < staticResourcesTable.getRowCount(); i++) { if (value.equals(fixContentPath((String) staticResourcesTable.getValueAt(i, StaticResourcesColumn.CONTEXT_PATH.getIndex())))) { return false; } } parent.setSaveEnabled(true); return true; } @Override public Object getCellEditorValue() { String value = fixContentPath((String) super.getCellEditorValue()); String baseContextPath = getBaseContextPath(); if (value.equals(baseContextPath)) { return null; } else { return fixContentPath(StringUtils.removeStartIgnoreCase(value, baseContextPath + "/")); } } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { String resourceContextPath = fixContentPath((String) value); setOriginalValue(resourceContextPath); getTextField().setText(getBaseContextPath() + resourceContextPath); return getTextField(); } } ; staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex()) .setCellEditor(new ContextPathCellEditor()); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTEXT_PATH.getIndex()) .setCellRenderer(new DefaultTableCellRenderer() { @Override protected void setValue(Object value) { super.setValue(getBaseContextPath() + fixContentPath((String) value)); } }); class ResourceTypeCellEditor extends MirthComboBoxTableCellEditor implements ActionListener { private Object originalValue; public ResourceTypeCellEditor(JTable table, Object[] items, int clickCount, boolean focusable) { super(table, items, clickCount, focusable, null); for (ActionListener actionListener : comboBox.getActionListeners()) { comboBox.removeActionListener(actionListener); } comboBox.addActionListener(this); } @Override public boolean stopCellEditing() { if (ObjectUtils.equals(getCellEditorValue(), originalValue)) { cancelCellEditing(); } else { parent.setSaveEnabled(true); } return super.stopCellEditing(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { originalValue = value; return super.getTableCellEditorComponent(table, value, isSelected, row, column); } @Override public void actionPerformed(ActionEvent evt) { ((AbstractTableModel) staticResourcesTable.getModel()).fireTableCellUpdated( staticResourcesTable.getSelectedRow(), StaticResourcesColumn.VALUE.getIndex()); stopCellEditing(); fireEditingStopped(); } } String[] resourceTypes = ResourceType.stringValues(); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMinWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()).setMaxWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .setCellEditor(new ResourceTypeCellEditor(staticResourcesTable, resourceTypes, 1, false)); staticResourcesTable.getColumnExt(StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .setCellRenderer(new MirthComboBoxTableCellRenderer(resourceTypes)); class ValueCellEditor extends AbstractCellEditor implements TableCellEditor { private JPanel panel; private JLabel label; private JTextField textField; private String text; private String originalValue; public ValueCellEditor() { panel = new JPanel(new MigLayout("insets 0 1 0 0, novisualpadding, hidemode 3")); panel.setBackground(UIConstants.BACKGROUND_COLOR); label = new JLabel(); label.addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent evt) { new ValueDialog(); stopCellEditing(); } }); panel.add(label, "grow, pushx, h 19!"); textField = new JTextField(); panel.add(textField, "grow, pushx, h 19!"); } @Override public boolean isCellEditable(EventObject evt) { if (evt == null) { return false; } if (evt instanceof MouseEvent) { return ((MouseEvent) evt).getClickCount() >= 2; } return true; } @Override public Object getCellEditorValue() { if (label.isVisible()) { return text; } else { return textField.getText(); } } @Override public boolean stopCellEditing() { if (ObjectUtils.equals(getCellEditorValue(), originalValue)) { cancelCellEditing(); } else { parent.setSaveEnabled(true); } return super.stopCellEditing(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { boolean custom = table.getValueAt(row, StaticResourcesColumn.RESOURCE_TYPE.getIndex()) .equals(ResourceType.CUSTOM.toString()); label.setVisible(custom); textField.setVisible(!custom); panel.setBackground(table.getSelectionBackground()); label.setBackground(panel.getBackground()); label.setMaximumSize(new Dimension(table.getColumnModel().getColumn(column).getWidth(), 19)); String text = (String) value; this.text = text; originalValue = text; label.setText(text); textField.setText(text); return panel; } class ValueDialog extends MirthDialog { public ValueDialog() { super(parent, true); setTitle("Custom Value"); setPreferredSize(new Dimension(600, 500)); setLayout(new MigLayout("insets 12, novisualpadding, hidemode 3, fill", "", "[grow]7[]")); setBackground(UIConstants.BACKGROUND_COLOR); getContentPane().setBackground(getBackground()); final MirthSyntaxTextArea textArea = new MirthSyntaxTextArea(); textArea.setSaveEnabled(false); textArea.setText(text); textArea.setBorder(BorderFactory.createEtchedBorder()); add(textArea, "grow"); add(new JSeparator(), "newline, grow"); JPanel buttonPanel = new JPanel(new MigLayout("insets 0, novisualpadding, hidemode 3")); buttonPanel.setBackground(getBackground()); JButton openFileButton = new JButton("Open File..."); openFileButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String content = parent.browseForFileString(null); if (content != null) { textArea.setText(content); } } }); buttonPanel.add(openFileButton); JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { text = textArea.getText(); label.setText(text); textField.setText(text); staticResourcesTable.getModel().setValueAt(text, staticResourcesTable.getSelectedRow(), StaticResourcesColumn.VALUE.getIndex()); parent.setSaveEnabled(true); dispose(); } }); buttonPanel.add(okButton); JButton cancelButton = new JButton("Cancel"); cancelButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { dispose(); } }); buttonPanel.add(cancelButton); add(buttonPanel, "newline, right"); pack(); setLocationRelativeTo(parent); setVisible(true); } } } ; staticResourcesTable.getColumnExt(StaticResourcesColumn.VALUE.getIndex()) .setCellEditor(new ValueCellEditor()); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMinWidth(100); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()).setMaxWidth(150); staticResourcesTable.getColumnExt(StaticResourcesColumn.CONTENT_TYPE.getIndex()) .setCellEditor(new TextFieldCellEditor() { @Override protected boolean valueChanged(String value) { if (value.equals(getOriginalValue())) { return false; } parent.setSaveEnabled(true); return true; } }); staticResourcesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent evt) { if (getSelectedRow(staticResourcesTable) != -1) { staticResourcesLastIndex = getSelectedRow(staticResourcesTable); staticResourcesDeleteButton.setEnabled(true); } else { staticResourcesDeleteButton.setEnabled(false); } } }); contextPathField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent evt) { changedUpdate(evt); } @Override public void removeUpdate(DocumentEvent evt) { changedUpdate(evt); } @Override public void changedUpdate(DocumentEvent evt) { ((AbstractTableModel) staticResourcesTable.getModel()).fireTableDataChanged(); } }); staticResourcesDeleteButton.setEnabled(false); }
From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java
private void initCustumComponents() { logoLabel = new javax.swing.JLabel(); icon = new ImageIcon(getCLub()); logoLabel.setIcon(icon); // NOI18N logoLabel.setBounds(this.getWidth() - icon.getIconWidth(), this.getHeight() - icon.getIconHeight(), icon.getIconWidth(), icon.getIconHeight()); LayerdPane.add(logoLabel, JLayeredPane.PALETTE_LAYER); clockLabel = new javax.swing.JLabel(); clockLabel.setFont(new java.awt.Font("Lucida Grande", 0, fontSize)); // NOI18N clockLabel.setText(""); clockLabel.setForeground(Color.YELLOW); LayerdPane.add(clockLabel, JLayeredPane.PALETTE_LAYER); jTable1.setRowSelectionAllowed(false); jTable1.setModel(new javax.swing.table.DefaultTableModel(new Object[][] {}, new String[] { "Plaats", "Atleet", "Tijd" }) { Class[] types = new Class[] { java.lang.Integer.class, java.lang.String.class, java.lang.String.class }; boolean[] canEdit = new boolean[] { false, false, false }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; }//from w w w .j av a2 s . c o m public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jScrollPane1.getViewport().setBackground(Color.black); this.setBackground(Color.black); JTableHeader header = jTable1.getTableHeader(); header.setOpaque(false); jPanel1.setBackground(Color.black); header.setBackground(Color.black); header.setForeground(Color.YELLOW); DefaultTableCellRenderer headerRenderer = new DefaultTableCellRenderer(); headerRenderer.setBackground(Color.BLACK); for (int i = 0; i < jTable1.getModel().getColumnCount(); i++) { if (jTable1.getModel().getColumnCount() > 0) { jTable1.getColumnModel().getColumn(i).setHeaderRenderer(headerRenderer); } } DefaultTableCellRenderer LEFTRenderer = new DefaultTableCellRenderer(); LEFTRenderer.setHorizontalAlignment(JLabel.LEFT); jTable1.getColumnModel().getColumn(0).setCellRenderer(LEFTRenderer); ChangeFont(fontSize); }
From source file:org.jets3t.apps.cockpit.Cockpit.java
/** * Initialises the application's GUI elements. *//*from ww w. ja va2s. c o m*/ private void initGui() { initMenus(); JPanel appContent = new JPanel(new GridBagLayout()); this.getContentPane().add(appContent); // Buckets panel. JPanel bucketsPanel = new JPanel(new GridBagLayout()); JButton bucketActionButton = new JButton(); bucketActionButton.setToolTipText("Bucket actions menu"); guiUtils.applyIcon(bucketActionButton, "/images/nuvola/16x16/actions/misc.png"); bucketActionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton sourceButton = (JButton) e.getSource(); bucketActionMenu.show(sourceButton, 0, sourceButton.getHeight()); } }); bucketsPanel.add(new JHtmlLabel("<html><b>Buckets</b></html>", this), new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); bucketsPanel.add(bucketActionButton, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); bucketTableModel = new BucketTableModel(false); bucketTableModelSorter = new TableSorter(bucketTableModel); bucketsTable = new JTable(bucketTableModelSorter); bucketTableModelSorter.setTableHeader(bucketsTable.getTableHeader()); bucketsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bucketsTable.getSelectionModel().addListSelectionListener(this); bucketsTable.setShowHorizontalLines(true); bucketsTable.setShowVerticalLines(false); bucketsTable.addMouseListener(new ContextMenuListener()); bucketsPanel.add(new JScrollPane(bucketsTable), new GridBagConstraints(0, 1, 2, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0)); bucketsPanel.add(new JLabel(" "), new GridBagConstraints(0, 2, 2, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0)); // Filter panel. filterObjectsPanel = new JPanel(new GridBagLayout()); filterObjectsPrefix = new JTextField(); filterObjectsPrefix.setToolTipText("Only show objects with this prefix"); filterObjectsPrefix.addActionListener(this); filterObjectsPrefix.setActionCommand("RefreshObjects"); filterObjectsDelimiter = new JComboBox(new String[] { "", "/", "?", "\\" }); filterObjectsDelimiter.setEditable(true); filterObjectsDelimiter.setToolTipText("Object name delimiter"); filterObjectsDelimiter.addActionListener(this); filterObjectsDelimiter.setActionCommand("RefreshObjects"); filterObjectsPanel.add(new JHtmlLabel("Prefix:", this), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0)); filterObjectsPanel.add(filterObjectsPrefix, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); filterObjectsPanel.add(new JHtmlLabel("Delimiter:", this), new GridBagConstraints(2, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0)); filterObjectsPanel.add(filterObjectsDelimiter, new GridBagConstraints(3, 0, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0)); filterObjectsPanel.setVisible(false); // Objects panel. JPanel objectsPanel = new JPanel(new GridBagLayout()); int row = 0; filterObjectsCheckBox = new JCheckBox("Filter objects"); filterObjectsCheckBox.addActionListener(this); filterObjectsCheckBox.setToolTipText("Check this option to filter the objects listed"); objectsPanel.add(new JHtmlLabel("<html><b>Objects</b></html>", this), new GridBagConstraints(0, row, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); objectsPanel.add(filterObjectsCheckBox, new GridBagConstraints(1, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); JButton objectActionButton = new JButton(); objectActionButton.setToolTipText("Object actions menu"); guiUtils.applyIcon(objectActionButton, "/images/nuvola/16x16/actions/misc.png"); objectActionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JButton sourceButton = (JButton) e.getSource(); objectActionMenu.show(sourceButton, 0, sourceButton.getHeight()); } }); objectsPanel.add(objectActionButton, new GridBagConstraints(2, row, 1, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); objectsPanel.add(filterObjectsPanel, new GridBagConstraints(0, ++row, 3, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0)); objectsTable = new JTable(); objectTableModel = new ObjectTableModel(); objectTableModelSorter = new TableSorter(objectTableModel); objectTableModelSorter.setTableHeader(objectsTable.getTableHeader()); objectsTable.setModel(objectTableModelSorter); objectsTable.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() { private static final long serialVersionUID = 301092191828910402L; @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { String formattedSize = byteFormatter.formatByteSize(((Long) value).longValue()); return super.getTableCellRendererComponent(table, formattedSize, isSelected, hasFocus, row, column); } }); objectsTable.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() { private static final long serialVersionUID = 7285511556343895652L; @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Date date = (Date) value; return super.getTableCellRendererComponent(table, yearAndTimeSDF.format(date), isSelected, hasFocus, row, column); } }); objectsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); objectsTable.getSelectionModel().addListSelectionListener(this); objectsTable.setShowHorizontalLines(true); objectsTable.setShowVerticalLines(true); objectsTable.addMouseListener(new ContextMenuListener()); objectsTableSP = new JScrollPane(objectsTable); objectsPanel.add(objectsTableSP, new GridBagConstraints(0, ++row, 3, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0)); objectsSummaryLabel = new JHtmlLabel("Please select a bucket", this); objectsSummaryLabel.setHorizontalAlignment(JLabel.CENTER); objectsSummaryLabel.setFocusable(false); objectsPanel.add(objectsSummaryLabel, new GridBagConstraints(0, ++row, 3, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0)); // Combine sections. JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bucketsPanel, objectsPanel); splitPane.setOneTouchExpandable(true); splitPane.setContinuousLayout(true); appContent.add(splitPane, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsDefault, 0, 0)); // Set preferred sizes int preferredWidth = 800; int preferredHeight = 600; this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight))); splitPane.setResizeWeight(0.30); // Initialize drop target. initDropTarget(new JComponent[] { objectsTableSP, objectsTable }); objectsTable.getDropTarget().setActive(false); objectsTableSP.getDropTarget().setActive(false); }
From source file:br.com.jinsync.view.FrmJInSync.java
private void listCopy(List<Copybook> listCopy) { tableCopy = new JTable(); tableCopy.setBackground(Color.WHITE); tableCopy.setRowSelectionAllowed(true); tableCopy.setCellSelectionEnabled(true); tableCopy.setColumnSelectionAllowed(false); tableCopy.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(SwingConstants.RIGHT); // listCopy = listTotCopy; modeloCopybook = new CopybookTableModel(listCopy); tableCopy.setModel(modeloCopybook);/*from www . j a v a 2s .co m*/ tableCopy.setFont(new Font("Courier New", Font.PLAIN, 12)); tableCopy.getColumnModel().getColumn(0).setMinWidth(0); tableCopy.getColumnModel().getColumn(0).setPreferredWidth(0); tableCopy.getColumnModel().getColumn(0).setMaxWidth(0); // Coluna Sequencia tableCopy.getColumnModel().getColumn(1).setPreferredWidth(60); // Coluna Nivel tableCopy.getColumnModel().getColumn(2).setMinWidth(0); tableCopy.getColumnModel().getColumn(2).setPreferredWidth(0); tableCopy.getColumnModel().getColumn(2).setMaxWidth(0); // Coluna Nome tableCopy.getColumnModel().getColumn(3).setPreferredWidth(300); // Coluna Redefines tableCopy.getColumnModel().getColumn(4).setPreferredWidth(300); // Coluna Formato tableCopy.getColumnModel().getColumn(5).setPreferredWidth(120); // Coluna Inteiro tableCopy.getColumnModel().getColumn(6).setPreferredWidth(70); tableCopy.getColumnModel().getColumn(6).setCellRenderer(rightRenderer); // Coluna Decimal tableCopy.getColumnModel().getColumn(7).setPreferredWidth(70); tableCopy.getColumnModel().getColumn(7).setCellRenderer(rightRenderer); // Coluna Inicio tableCopy.getColumnModel().getColumn(8).setPreferredWidth(50); tableCopy.getColumnModel().getColumn(8).setCellRenderer(rightRenderer); tableCopy.getColumnModel().getColumn(9).setPreferredWidth(68); tableCopy.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scrCopy.setViewportView(tableCopy); }
From source file:com.mirth.connect.client.ui.browsers.event.EventBrowser.java
private void makeAttributesTable() { setEventAttributes(null, true);/*from w w w . j a v a 2s. c o m*/ // listen for trigger button and double click to edit channel. eventAttributesTable.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { if (eventAttributesTable.rowAtPoint(new Point(evt.getX(), evt.getY())) == -1) { return; } if (evt.getClickCount() >= 2) { new ViewContentDialog((String) eventAttributesTable.getModel().getValueAt( eventAttributesTable.getSelectedModelIndex(), ATTRIBUTES_VALUE_COLUMN_NUMBER)); } } }); eventAttributesTable.setSelectionMode(0); // Disable HTML in a column. DefaultTableCellRenderer noHTMLRenderer = new DefaultTableCellRenderer(); noHTMLRenderer.putClientProperty("html.disable", Boolean.TRUE); eventAttributesTable.getColumnExt(ATTRIBUTES_VALUE_COLUMN_NAME).setCellRenderer(noHTMLRenderer); eventAttributesPane.setViewportView(eventAttributesTable); }
From source file:edu.ku.brc.af.ui.forms.TableViewObj.java
/** * Build the table now that we have all the information we need for the columns. *///from w w w. j av a2 s. c o m protected void buildTable() { // Now Build the JTable model = new ColTableModel(); table = new JTable(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(false); table.setFocusable(false); //table.setPreferredScrollableViewportSize(new Dimension(200,table.getRowHeight()*6)); configColumns(); //table.setCellSelectionEnabled(false); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { ListSelectionModel lsm = (ListSelectionModel) e.getSource(); updateUI(!lsm.isSelectionEmpty()); } } }); table.addMouseListener(new java.awt.event.MouseAdapter() { @Override public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getClickCount() == 2) { int index = table.getSelectedRow(); editRow(index, false); } } }); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setHorizontalAlignment(SwingConstants.CENTER); /* // This is BROKEN! table.setCellSelectionEnabled(true); for (int i=0;i<model.getColumnCount();i++) { TableColumn column = table.getColumn(model.getColumnName(i)); //log.info(model.getColumnName(i)); //column.setCellRenderer(renderer); ColumnInfo columnInfo = columnList.get(i); Component comp = columnInfo.getComp(); //column.setCellEditor(new DefaultCellEditor(new JTextField())); if (comp instanceof GetSetValueIFace) { column.setCellEditor(new MyTableCellEditor(columnInfo)); } else if (comp instanceof JTextField) { column.setCellEditor(new DefaultCellEditor((JTextField)comp)); } else { log.error("Couldn't figure out DefaultCellEditor for comp ["+comp.getClass().getSimpleName()+"]"); } } */ tableScroller = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); orderablePanel = new JPanel(new BorderLayout()); orderablePanel.add(tableScroller, BorderLayout.CENTER); mainComp.add(orderablePanel, BorderLayout.CENTER); initColumnSizes(table); }
From source file:edu.harvard.mcz.imagecapture.VerbatimClassifyDialog.java
/** * This method initializes jTableNumbers * /*www.j av a2 s . com*/ * @return javax.swing.JTable */ private JTable getJTableNumbers() { if (jTableNumbers == null) { jTableNumbers = new JTable(new NumberTableModel()); JComboBox<String> jComboNumberTypes = new JComboBox<String>(); jComboNumberTypes.setModel(new DefaultComboBoxModel<String>(NumberLifeCycle.getDistinctTypes())); jComboNumberTypes.setEditable(true); TableColumn typeColumn = jTableNumbers.getColumnModel().getColumn(NumberTableModel.COLUMN_TYPE); DefaultCellEditor comboBoxEditor = new DefaultCellEditor(jComboNumberTypes); //TODO: enable autocomplete for numbertypes picklist. //AutoCompleteDecorator.decorate((JComboBox) comboBoxEditor.getComponent()); typeColumn.setCellEditor(comboBoxEditor); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for pick list of number types."); typeColumn.setCellRenderer(renderer); } return jTableNumbers; }
From source file:dataviewer.DataViewer.java
private void renderData(DefaultTableModel model) { tb_data.setVisible(false);// ww w. j a v a 2 s . c o m tb_data.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); c.setBackground(row % 2 == 0 ? Color.WHITE : new Color(240, 240, 240)); if (table.isCellSelected(row, column)) { c.setBackground(new Color(200, 0, 0)); c.setForeground(Color.white); } else if (table.isRowSelected(row)) { c.setBackground(new Color(0, 0, 200)); c.setForeground(Color.white); } else { c.setForeground(Color.black); } return c; } }); tb_data.setGridColor(new Color(220, 220, 220)); tb_data.setShowVerticalLines(true); tb_data.setModel(model); for (int i = 0; i < model.getColumnCount(); ++i) { if (model.getColumnName(i).equals("_N_")) { TableRowSorter trs = new TableRowSorter(model); trs.setComparator(i, new IntComparator()); tb_data.setRowSorter(trs); } } for (int j = 0; j < tb_data.getColumnCount(); j++) { int width = 0; TableColumn col = tb_data.getColumnModel().getColumn(j); TableCellRenderer renderer = tb_data.getTableHeader().getDefaultRenderer(); Component comp = renderer.getTableCellRendererComponent(tb_data, col.getHeaderValue(), false, false, 0, 0); width = Math.max(comp.getPreferredSize().width, width); for (int i = 0; i < tb_data.getRowCount(); i++) { renderer = tb_data.getCellRenderer(i, j); comp = tb_data.prepareRenderer(renderer, i, j); width = Math.max(comp.getPreferredSize().width, width); } tb_data.getColumnModel().getColumn(j).setPreferredWidth(width + 20); } tb_data.setVisible(true); }
From source file:mt.listeners.InteractiveRANSAC.java
public void updateRANSAC() { negcount = 0;/*from w w w.j a va2 s . c om*/ negtimediff = 0; averageshrink = 0; catindex = 0; negsegments = new ArrayList<Pair<LinearFunction, ArrayList<PointFunctionMatch>>>(); ArrayList<Rateobject> allrates = new ArrayList<Rateobject>(); ArrayList<Averagerate> averagerates = new ArrayList<Averagerate>(); ++updateCount; dataset.removeAllSeries(); this.dataset.addSeries(Tracking.drawPoints(mts, calibrations)); @SuppressWarnings("unchecked") ArrayList<Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>>> segments = Tracking .findAllFunctions(points, function, maxError, minInliers, maxDist); if (segments == null || segments.size() == 0) { --updateCount; return; } // sort the segments according to time HORIZONTAL to each other and the // PointFunctionMatches internally sort(segments); final LinearFunction linear = new LinearFunction(); int linearcount = 1; i = 1; segment = 1; int count = 0; int rescount = 0; int catcount = 0; double timediff = 0; double restimediff = 0; double averagegrowth = 0; double growthrate = 0; double shrinkrate = 0; double minstartY = leastStart(segments); double minstartX = Double.MAX_VALUE; double minendX = Double.MAX_VALUE; double catfrequ = 0; double resfrequ = 0; double lifetime = 0; ArrayList<Double> previousendX = new ArrayList<Double>(); ResultsTable rt = new ResultsTable(); ResultsTable rtAll = new ResultsTable(); List<Pair<Float, Float>> starttimerates = new ArrayList<Pair<Float, Float>>(); List<Pair<Float, Float>> catstarttimerates = new ArrayList<Pair<Float, Float>>(); for (final Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>> result : segments) { if (LinearFunction.slopeFits(result.getB(), linear, minSlope, maxSlope)) { final Pair<Double, Double> minMax = Tracking.fromTo(result.getB()); double startX = minMax.getA(); double endX = minMax.getB(); if (startX < minstartX) { minstartX = startX; } if (endX < minendX) { minendX = endX; } Polynomial<?, Point> polynomial = (Polynomial) result.getA(); dataset.addSeries( Tracking.drawFunction(polynomial, minMax.getA(), minMax.getB(), 0.5, "Segment " + segment)); if (functionChoice > 0) { Tracking.setColor(chart, i, new Color(255, 0, 0)); Tracking.setDisplayType(chart, i, true, false); Tracking.setStroke(chart, i, 0.5f); chart.setTitle("Length plot for" + " " + this.inputfiles[row].getName()); } else { Tracking.setColor(chart, i, new Color(0, 128, 0)); Tracking.setDisplayType(chart, i, true, false); Tracking.setStroke(chart, i, 2f); chart.setTitle("Length plot for" + " " + this.inputfiles[row].getName()); } ++i; if (functionChoice > 0) { dataset.addSeries(Tracking.drawFunction(linear, minMax.getA(), minMax.getB(), 0.5, "Linear Segment " + segment)); Tracking.setColor(chart, i, new Color(0, 128, 0)); Tracking.setDisplayType(chart, i, true, false); Tracking.setStroke(chart, i, 2f); ++i; } double startY = polynomial.predict(startX); double linearrate = linear.getCoefficient(1); if (linearrate > 0 && startY - minstartY > restolerance && previousendX.size() > 0) { rescount++; restimediff += -previousendX.get(previousendX.size() - 1) + startX; } if (linearrate > 0) { count++; growthrate = linearrate; // Ignore last growth event for getting fcat if (points.get(points.size() - 1).getW()[0] - endX >= tptolerance) catcount++; timediff += endX - startX; lifetime = endX - startX; averagegrowth += linearrate; lifecount.add(new ValuePair<Integer, Double>(count, lifetime)); Rateobject velocity = new Rateobject(linearrate * calibrations[0] / calibrations[2], (int) (startX * calibrations[2]), (int) (endX * calibrations[2])); allrates.add(velocity); rt.incrementCounter(); rt.addValue("Start time", startX * calibrations[2]); rt.addValue("End time", endX * calibrations[2]); rt.addValue("Growth velocity", linearrate * calibrations[0] / calibrations[2]); Pair<Float, Float> startrate = new ValuePair<Float, Float>((float) startX, (float) linearrate); starttimerates.add(startrate); } if (linearrate < 0) { negcount++; negtimediff += endX - startX; shrinkrate = linearrate; averageshrink += linearrate; rt.incrementCounter(); rt.addValue("Start time", startX * calibrations[2]); rt.addValue("End time", endX * calibrations[2]); rt.addValue("Growth velocity", linearrate * calibrations[0] / calibrations[2]); Pair<Float, Float> startrate = new ValuePair<Float, Float>((float) startX, (float) linearrate); starttimerates.add(startrate); } if (linearrate > 0) { previousendX.add(endX); } dataset.addSeries(Tracking.drawPoints(Tracking.toPairList(result.getB()), calibrations, "Inliers " + segment)); Tracking.setColor(chart, i, new Color(255, 0, 0)); Tracking.setDisplayType(chart, i, false, true); Tracking.setSmallUpTriangleShape(chart, i); ++i; ++segment; } else { System.out.println("Removed segment because slope is wrong."); } } if (this.detectCatastrophe) { if (segments.size() < 2) { System.out.println("Only two points found"); } else { for (int catastrophy = 0; catastrophy < segments.size() - 1; ++catastrophy) { final Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>> start = segments.get(catastrophy); final Pair<AbstractFunction2D, ArrayList<PointFunctionMatch>> end = segments .get(catastrophy + 1); double tStart = start.getB().get(start.getB().size() - 1).getP1().getL()[0]; double tEnd = end.getB().get(0).getP1().getL()[0]; final double lStart = start.getB().get(start.getB().size() - 1).getP1().getL()[1]; final double lEnd = end.getB().get(0).getP1().getL()[1]; final ArrayList<Point> catastropyPoints = new ArrayList<Point>(); for (final Point p : points) if (p.getL()[0] >= tStart && p.getL()[0] <= tEnd) catastropyPoints.add(p); if (catastropyPoints.size() > 2) { if (Math.abs(lStart - lEnd) >= this.minDistanceCatastrophe) { // maximally 1.1 timepoints between points on a line final Pair<LinearFunction, ArrayList<PointFunctionMatch>> fit = Tracking .findFunction(catastropyPoints, new LinearFunction(), 0.75, 3, 1.1); if (fit != null) { if (fit.getA().getM() < 0) { sort(fit); negsegments.add(fit); double minY = Math.min(fit.getB().get(0).getP1().getL()[1], fit.getB().get(fit.getB().size() - 1).getP1().getL()[1]); double maxY = Math.max(fit.getB().get(0).getP1().getL()[1], fit.getB().get(fit.getB().size() - 1).getP1().getL()[1]); final Pair<Double, Double> minMax = Tracking.fromTo(fit.getB()); double startX = minMax.getA(); double endX = minMax.getB(); double linearrate = fit.getA().getCoefficient(1); if (linearrate < 0) { dataset.addSeries(Tracking.drawFunction((Polynomial) fit.getA(), minMax.getA() - 1, minMax.getB() + 1, 0.1, minY - 2.5, maxY + 2.5, "CRansac " + catastrophy)); negcount++; negtimediff += endX - startX; shrinkrate = linearrate; averageshrink += linearrate; rt.incrementCounter(); rt.addValue("Start time", startX * calibrations[2]); rt.addValue("End time", endX * calibrations[2]); rt.addValue("Growth velocity", linearrate * calibrations[0] / calibrations[2]); Pair<Float, Float> startrate = new ValuePair<Float, Float>((float) startX, (float) linearrate); starttimerates.add(startrate); Rateobject velocity = new Rateobject( linearrate * calibrations[0] / calibrations[2], (int) (startX * calibrations[2]), (int) (endX * calibrations[2])); allrates.add(velocity); Tracking.setColor(chart, i, new Color(0, 0, 255)); Tracking.setDisplayType(chart, i, true, false); Tracking.setStroke(chart, i, 2f); ++i; dataset.addSeries(Tracking.drawPoints(Tracking.toPairList(fit.getB()), calibrations, "C(inl) " + catastrophy)); Tracking.setColor(chart, i, new Color(0, 0, 255)); Tracking.setDisplayType(chart, i, false, true); Tracking.setShape(chart, i, ShapeUtils.createDownTriangle(4f)); ++i; } } } } else { System.out.println("Catastrophy height not sufficient " + Math.abs(lStart - lEnd) + " < " + this.minDistanceCatastrophe); } } } } } if (this.detectmanualCatastrophe) { catindex++; catstarttimerates = ManualCat(segments, allrates, shrinkrate, rt); } if (count > 0) averagegrowth /= count; if (catcount > 0) catfrequ = catcount / (timediff * calibrations[2]); if (rescount > 0) resfrequ = rescount / (restimediff * calibrations[2]); if (negcount > 0) averageshrink /= negcount; if (resfrequ < 0) resfrequ = 0; rt.show("Rates(real units) for" + " " + this.inputfile.getName()); averageshrink *= calibrations[0] / calibrations[2]; averagegrowth *= calibrations[0] / calibrations[2]; rtAll.incrementCounter(); rtAll.addValue("Average Growth", averagegrowth); rtAll.addValue("Growth events", count); rtAll.addValue("Average Shrink", averageshrink); rtAll.addValue("Shrink events", negcount); rtAll.addValue("Catastrophe Frequency", catfrequ); rtAll.addValue("Catastrophe events", catcount); rtAll.addValue("Rescue Frequency", resfrequ); rtAll.addValue("Rescue events", rescount); // rtAll.show("Average Rates and Frequencies (real units)"); starttimerates.addAll(catstarttimerates); sortTime(starttimerates); for (int index = 0; index < starttimerates.size() - 1; ++index) { int prevsign = (int) Math.signum(starttimerates.get(index).getB()); int nextsign = (int) Math.signum(starttimerates.get(index + 1).getB()); if (nextsign == prevsign) wrongfile = true; else wrongfile = false; wrongfileindex = new ValuePair<Boolean, Integer>(wrongfile, row); wrongfileindexlist.put(row, wrongfile); } table.getModel().setValueAt(new DecimalFormat("#.###").format(averagegrowth), row, 1); table.getModel().setValueAt(new DecimalFormat("#.###").format(averageshrink), row, 2); table.getModel().setValueAt(new DecimalFormat("#").format(count), row, 3); table.getModel().setValueAt(new DecimalFormat("#").format(negcount), row, 4); table.getModel().setValueAt(new DecimalFormat("#.###").format(catfrequ), row, 5); table.getModel().setValueAt(new DecimalFormat("#.###").format(resfrequ), row, 6); if (wrongfileindexlist.get(row) != null) { table.getModel().setValueAt(wrongfileindexlist.get(row).toString(), row, 7); } int size = 100; table.getColumnModel().getColumn(0).setPreferredWidth(size); table.getColumnModel().getColumn(1).setPreferredWidth(size); table.getColumnModel().getColumn(2).setPreferredWidth(size); table.getColumnModel().getColumn(3).setPreferredWidth(size); table.getColumnModel().getColumn(4).setPreferredWidth(size); table.getColumnModel().getColumn(5).setPreferredWidth(size); table.getColumnModel().getColumn(6).setPreferredWidth(size); table.getColumnModel().getColumn(7).setPreferredWidth(size); table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowA, int col) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, rowA, col); String status = (String) table.getModel().getValueAt(row, 7); if ("true".equals(status)) { setBackground(Color.GRAY); } else { setBackground(Color.GRAY); } return this; } }); table.validate(); scrollPane.validate(); Averagerate avrate = new Averagerate(averagegrowth, averageshrink, catfrequ, resfrequ, count, negcount, catcount, rescount, this.inputfile); averagerates.add(avrate); Compilepositiverates.put(row, allrates); Compileaverage.put(row, avrate); --updateCount; }