protected void attachTo(Component jc) { if (extListener != null && extListener.accept(jc)) { extListener.startListeningTo(jc, extNotifier); listenedTo.add(jc); if (wizardPage.getMapKeyFor(jc) != null) { wizardPage.maybeUpdateMap(jc); } return; } if (isProbablyAContainer(jc)) { attachToHierarchyOf((Container) jc); } else if (jc instanceof JList) { listenedTo.add(jc); ((JList) jc).addListSelectionListener(this); } else if (jc instanceof JComboBox) { ((JComboBox) jc).addActionListener(this); } else if (jc instanceof JTree) { listenedTo.add(jc); ((JTree) jc).getSelectionModel().addTreeSelectionListener(this); } else if (jc instanceof JToggleButton) { ((AbstractButton) jc).addItemListener(this); } else if (jc instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent jc.addPropertyChangeListener("value", this); } else if (jc instanceof JTextComponent) { listenedTo.add(jc); ((JTextComponent) jc).getDocument().addDocumentListener(this); } else if (jc instanceof JColorChooser) { listenedTo.add(jc); ((JColorChooser) jc).getSelectionModel().addChangeListener(this); } else if (jc instanceof JSpinner) { ((JSpinner) jc).addChangeListener(this); } else if (jc instanceof JSlider) { ((JSlider) jc).addChangeListener(this); } else if (jc instanceof JTable) { listenedTo.add(jc); ((JTable) jc).getSelectionModel().addListSelectionListener(this); } else { if (logger.isLoggable(Level.FINE)) { logger.fine( "Don't know how to listen to a " + // NOI18N jc.getClass().getName()); } } if (accept(jc) && !(jc instanceof JPanel)) { jc.addPropertyChangeListener("name", this); if (wizardPage.getMapKeyFor(jc) != null) { wizardPage.maybeUpdateMap(jc); } } if (logger.isLoggable(Level.FINE) && accept(jc)) { logger.fine("Begin listening to " + jc); // NOI18N } }
private HypothecCalculator() { initialize(); KeyAdapter keyListener = new KeyAdapter() { public void keyReleased(final KeyEvent e) { bind(); viewModel.checkInput(); backBind(); } }; houseCost.addKeyListener(keyListener); interestRate.addKeyListener(keyListener); downPayment.addKeyListener(keyListener); countOfPeriods.addKeyListener(keyListener); flatFee.addKeyListener(keyListener); monthlyFee.addKeyListener(keyListener); month.addKeyListener(keyListener); year.addKeyListener(keyListener); currencyType.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { bind(); backBind(); } }); periodType.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { bind(); backBind(); } }); interestRateType.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { bind(); backBind(); } }); flatFeeType.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { bind(); backBind(); } }); monthlyFeeType.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { bind(); backBind(); } }); creditType.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { bind(); backBind(); } }); compute.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { bind(); viewModel.compute(); backBind(); } }); }
private static void createAudioPreview( final AudioSystem audioSystem, final JComboBox comboBox, final SoundLevelIndicator soundLevelIndicator) { final ActionListener captureComboActionListener = new ActionListener() { private final SimpleAudioLevelListener audioLevelListener = new SimpleAudioLevelListener() { public void audioLevelChanged(int level) { soundLevelIndicator.updateSoundLevel(level); } }; private AudioMediaDeviceSession deviceSession; private final BufferTransferHandler transferHandler = new BufferTransferHandler() { public void transferData(PushBufferStream stream) { try { stream.read(transferHandlerBuffer); } catch (IOException ioe) { } } }; private final Buffer transferHandlerBuffer = new Buffer(); public void actionPerformed(ActionEvent event) { setDeviceSession(null); CaptureDeviceInfo cdi; if (comboBox == null) { cdi = soundLevelIndicator.isShowing() ? audioSystem.getCaptureDevice() : null; } else { Object selectedItem = soundLevelIndicator.isShowing() ? comboBox.getSelectedItem() : null; cdi = (selectedItem instanceof DeviceConfigurationComboBoxModel.CaptureDevice) ? ((DeviceConfigurationComboBoxModel.CaptureDevice) selectedItem).info : null; } if (cdi != null) { for (MediaDevice md : mediaService.getDevices(MediaType.AUDIO, MediaUseCase.ANY)) { if (md instanceof AudioMediaDeviceImpl) { AudioMediaDeviceImpl amd = (AudioMediaDeviceImpl) md; if (cdi.equals(amd.getCaptureDeviceInfo())) { try { MediaDeviceSession deviceSession = amd.createSession(); boolean setDeviceSession = false; try { if (deviceSession instanceof AudioMediaDeviceSession) { setDeviceSession((AudioMediaDeviceSession) deviceSession); setDeviceSession = true; } } finally { if (!setDeviceSession) deviceSession.close(); } } catch (Throwable t) { if (t instanceof ThreadDeath) throw (ThreadDeath) t; } break; } } } } } private void setDeviceSession(AudioMediaDeviceSession deviceSession) { if (this.deviceSession == deviceSession) return; if (this.deviceSession != null) { try { this.deviceSession.close(); } finally { this.deviceSession.setLocalUserAudioLevelListener(null); soundLevelIndicator.resetSoundLevel(); } } this.deviceSession = deviceSession; if (this.deviceSession != null) { this.deviceSession.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW)); this.deviceSession.setLocalUserAudioLevelListener(audioLevelListener); this.deviceSession.start(MediaDirection.SENDONLY); try { DataSource dataSource = this.deviceSession.getOutputDataSource(); dataSource.connect(); PushBufferStream[] streams = ((PushBufferDataSource) dataSource).getStreams(); for (PushBufferStream stream : streams) stream.setTransferHandler(transferHandler); dataSource.start(); } catch (Throwable t) { if (t instanceof ThreadDeath) throw (ThreadDeath) t; else setDeviceSession(null); } } } }; if (comboBox != null) comboBox.addActionListener(captureComboActionListener); soundLevelIndicator.addHierarchyListener( new HierarchyListener() { public void hierarchyChanged(HierarchyEvent event) { if ((event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) { SwingUtilities.invokeLater( new Runnable() { public void run() { captureComboActionListener.actionPerformed(null); } }); } } }); }
/** * Creates the video advanced settings. * * @return video advanced settings panel. */ private static Component createVideoAdvancedSettings() { ResourceManagementService resources = NeomediaActivator.getResources(); final DeviceConfiguration deviceConfig = mediaService.getDeviceConfiguration(); TransparentPanel centerPanel = new TransparentPanel(new GridBagLayout()); centerPanel.setMaximumSize(new Dimension(WIDTH, 150)); JButton resetDefaultsButton = new JButton(resources.getI18NString("impl.media.configform.VIDEO_RESET")); JPanel resetButtonPanel = new TransparentPanel(new FlowLayout(FlowLayout.RIGHT)); resetButtonPanel.add(resetDefaultsButton); final JPanel centerAdvancedPanel = new TransparentPanel(new BorderLayout()); centerAdvancedPanel.add(centerPanel, BorderLayout.NORTH); centerAdvancedPanel.add(resetButtonPanel, BorderLayout.SOUTH); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.anchor = GridBagConstraints.NORTHWEST; constraints.insets = new Insets(5, 5, 0, 0); constraints.gridx = 0; constraints.weightx = 0; constraints.weighty = 0; constraints.gridy = 0; centerPanel.add( new JLabel(resources.getI18NString("impl.media.configform.VIDEO_RESOLUTION")), constraints); constraints.gridy = 1; constraints.insets = new Insets(0, 0, 0, 0); final JCheckBox frameRateCheck = new SIPCommCheckBox(resources.getI18NString("impl.media.configform.VIDEO_FRAME_RATE")); centerPanel.add(frameRateCheck, constraints); constraints.gridy = 2; constraints.insets = new Insets(5, 5, 0, 0); centerPanel.add( new JLabel(resources.getI18NString("impl.media.configform.VIDEO_PACKETS_POLICY")), constraints); constraints.weightx = 1; constraints.gridx = 1; constraints.gridy = 0; constraints.insets = new Insets(5, 0, 0, 5); Object[] resolutionValues = new Object[DeviceConfiguration.SUPPORTED_RESOLUTIONS.length + 1]; System.arraycopy( DeviceConfiguration.SUPPORTED_RESOLUTIONS, 0, resolutionValues, 1, DeviceConfiguration.SUPPORTED_RESOLUTIONS.length); final JComboBox sizeCombo = new JComboBox(resolutionValues); sizeCombo.setRenderer(new ResolutionCellRenderer()); sizeCombo.setEditable(false); centerPanel.add(sizeCombo, constraints); // default value is 20 final JSpinner frameRate = new JSpinner(new SpinnerNumberModel(20, 5, 30, 1)); frameRate.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { deviceConfig.setFrameRate( ((SpinnerNumberModel) frameRate.getModel()).getNumber().intValue()); } }); constraints.gridy = 1; constraints.insets = new Insets(0, 0, 0, 5); centerPanel.add(frameRate, constraints); frameRateCheck.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (frameRateCheck.isSelected()) { deviceConfig.setFrameRate( ((SpinnerNumberModel) frameRate.getModel()).getNumber().intValue()); } else // unlimited framerate deviceConfig.setFrameRate(-1); frameRate.setEnabled(frameRateCheck.isSelected()); } }); final JSpinner videoMaxBandwidth = new JSpinner( new SpinnerNumberModel(deviceConfig.getVideoMaxBandwidth(), 1, Integer.MAX_VALUE, 1)); videoMaxBandwidth.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { deviceConfig.setVideoMaxBandwidth( ((SpinnerNumberModel) videoMaxBandwidth.getModel()).getNumber().intValue()); } }); constraints.gridx = 1; constraints.gridy = 2; constraints.insets = new Insets(0, 0, 5, 5); centerPanel.add(videoMaxBandwidth, constraints); resetDefaultsButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // reset to defaults sizeCombo.setSelectedIndex(0); frameRateCheck.setSelected(false); frameRate.setEnabled(false); frameRate.setValue(20); // unlimited framerate deviceConfig.setFrameRate(-1); videoMaxBandwidth.setValue(DeviceConfiguration.DEFAULT_VIDEO_MAX_BANDWIDTH); } }); // load selected value or auto Dimension videoSize = deviceConfig.getVideoSize(); if ((videoSize.getHeight() != DeviceConfiguration.DEFAULT_VIDEO_HEIGHT) && (videoSize.getWidth() != DeviceConfiguration.DEFAULT_VIDEO_WIDTH)) sizeCombo.setSelectedItem(deviceConfig.getVideoSize()); else sizeCombo.setSelectedIndex(0); sizeCombo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { Dimension selectedVideoSize = (Dimension) sizeCombo.getSelectedItem(); if (selectedVideoSize == null) { // the auto value, default one selectedVideoSize = new Dimension( DeviceConfiguration.DEFAULT_VIDEO_WIDTH, DeviceConfiguration.DEFAULT_VIDEO_HEIGHT); } deviceConfig.setVideoSize(selectedVideoSize); } }); frameRateCheck.setSelected( deviceConfig.getFrameRate() != DeviceConfiguration.DEFAULT_VIDEO_FRAMERATE); frameRate.setEnabled(frameRateCheck.isSelected()); if (frameRate.isEnabled()) frameRate.setValue(deviceConfig.getFrameRate()); return centerAdvancedPanel; }
/** * Creates basic controls for a type (AUDIO or VIDEO). * * @param type the type. * @return the build Component. */ public static Component createBasicControls(final int type) { final JComboBox deviceComboBox = new JComboBox(); deviceComboBox.setEditable(false); deviceComboBox.setModel( new DeviceConfigurationComboBoxModel( deviceComboBox, mediaService.getDeviceConfiguration(), type)); JLabel deviceLabel = new JLabel(getLabelText(type)); deviceLabel.setDisplayedMnemonic(getDisplayedMnemonic(type)); deviceLabel.setLabelFor(deviceComboBox); final Container devicePanel = new TransparentPanel(new FlowLayout(FlowLayout.CENTER)); devicePanel.setMaximumSize(new Dimension(WIDTH, 25)); devicePanel.add(deviceLabel); devicePanel.add(deviceComboBox); final JPanel deviceAndPreviewPanel = new TransparentPanel(new BorderLayout()); int preferredDeviceAndPreviewPanelHeight; switch (type) { case DeviceConfigurationComboBoxModel.AUDIO: preferredDeviceAndPreviewPanelHeight = 225; break; case DeviceConfigurationComboBoxModel.VIDEO: preferredDeviceAndPreviewPanelHeight = 305; break; default: preferredDeviceAndPreviewPanelHeight = 0; break; } if (preferredDeviceAndPreviewPanelHeight > 0) deviceAndPreviewPanel.setPreferredSize( new Dimension(WIDTH, preferredDeviceAndPreviewPanelHeight)); deviceAndPreviewPanel.add(devicePanel, BorderLayout.NORTH); final ActionListener deviceComboBoxActionListener = new ActionListener() { public void actionPerformed(ActionEvent event) { boolean revalidateAndRepaint = false; for (int i = deviceAndPreviewPanel.getComponentCount() - 1; i >= 0; i--) { Component c = deviceAndPreviewPanel.getComponent(i); if (c != devicePanel) { deviceAndPreviewPanel.remove(i); revalidateAndRepaint = true; } } Component preview = null; if ((deviceComboBox.getSelectedItem() != null) && deviceComboBox.isShowing()) { preview = createPreview(type, deviceComboBox, deviceAndPreviewPanel.getPreferredSize()); } if (preview != null) { deviceAndPreviewPanel.add(preview, BorderLayout.CENTER); revalidateAndRepaint = true; } if (revalidateAndRepaint) { deviceAndPreviewPanel.revalidate(); deviceAndPreviewPanel.repaint(); } } }; deviceComboBox.addActionListener(deviceComboBoxActionListener); /* * We have to initialize the controls to reflect the configuration * at the time of creating this instance. Additionally, because the * video preview will stop when it and its associated controls * become unnecessary, we have to restart it when the mentioned * controls become necessary again. We'll address the two goals * described by pretending there's a selection in the video combo * box when the combo box in question becomes displayable. */ deviceComboBox.addHierarchyListener( new HierarchyListener() { public void hierarchyChanged(HierarchyEvent event) { if ((event.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) { SwingUtilities.invokeLater( new Runnable() { public void run() { deviceComboBoxActionListener.actionPerformed(null); } }); } } }); return deviceAndPreviewPanel; }
public TableModelDemo() { try { // Load the JDBC driver Class.forName("com.mysql.jdbc.Driver"); Class.forName("oracle.jdbc.driver.OracleDriver"); System.out.println("Driver loaded"); // Create a row set rowSet = new CachedRowSetImpl(); // Set RowSet properties // rowSet.setUrl("jdbc:mysql://localhost/javabook"); rowSet.setUrl("jdbc:oracle:thin:@liang.armstrong.edu:1521:orcl"); rowSet.setUsername("scott"); rowSet.setPassword("tiger"); rowSet.setCommand("select * from StateCapital"); rowSet.setConcurrency(ResultSet.CONCUR_UPDATABLE); rowSet.execute(); tableModel.setRowSet(rowSet); rowSet.addRowSetListener(tableModel); } catch (Exception ex) { ex.printStackTrace(); } JPanel panel1 = new JPanel(); panel1.setLayout(new GridLayout(2, 2)); panel1.add(jbtAddRow); panel1.add(jbtAddColumn); panel1.add(jbtDeleteRow); panel1.add(jbtDeleteColumn); JPanel panel2 = new JPanel(); panel2.add(jbtSave); panel2.add(jbtClear); panel2.add(jbtRestore); JPanel panel3 = new JPanel(); panel3.setLayout(new BorderLayout(5, 0)); panel3.add(new JLabel("Selection Mode"), BorderLayout.WEST); panel3.add(jcboSelectionMode, BorderLayout.CENTER); JPanel panel4 = new JPanel(); panel4.setLayout(new FlowLayout(FlowLayout.LEFT)); panel4.add(jchkRowSelectionAllowed); panel4.add(jchkColumnSelectionAllowed); JPanel panel5 = new JPanel(); panel5.setLayout(new GridLayout(2, 1)); panel5.add(panel3); panel5.add(panel4); JPanel panel6 = new JPanel(); panel6.setLayout(new BorderLayout()); panel6.add(panel1, BorderLayout.SOUTH); panel6.add(panel2, BorderLayout.CENTER); add(panel5, BorderLayout.NORTH); add(new JScrollPane(jTable1), BorderLayout.CENTER); add(panel6, BorderLayout.SOUTH); // Initialize table selection mode jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); jbtAddRow.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { rowSet.absolute(2); rowSet.moveToInsertRow(); rowSet.updateString("state", "Georia"); rowSet.updateString("capital", "Atlanta"); rowSet.insertRow(); ((CachedRowSetImpl) rowSet).acceptChanges(); rowSet.moveToCurrentRow(); } catch (Exception ex) { ex.printStackTrace(); } // if (jTable1.getSelectedRow() >= 0) // tableModel.insertRow(jTable1.getSelectedRow(), // new java.util.Vector()); // else // tableModel.addRow(new java.util.Vector()); } }); jbtAddColumn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // String name = JOptionPane.showInputDialog("New Column Name"); // tableModel.addColumn(name, new java.util.Vector()); } }); jbtDeleteRow.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jTable1.getSelectedRow() >= 0) { try { rowSet.absolute(jTable1.getSelectedRow() + 1); rowSet.deleteRow(); ((CachedRowSetImpl) rowSet).acceptChanges(); } catch (Exception ex) { ex.printStackTrace(); } } } }); jbtDeleteColumn.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (jTable1.getSelectedColumn() >= 0) { TableColumnModel columnModel = jTable1.getColumnModel(); TableColumn tableColumn = columnModel.getColumn(jTable1.getSelectedColumn()); columnModel.removeColumn(tableColumn); } } }); jbtSave.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("tablemodel.dat")); // out.writeObject(tableModel.getDataVector()); out.writeObject(getColumnNames()); out.close(); } catch (Exception ex) { ex.printStackTrace(); } } }); jbtClear.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // tableModel.setRowCount(0); } }); jbtRestore.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { ObjectInputStream in = new ObjectInputStream(new FileInputStream("tablemodel.dat")); Vector rowData = (Vector) in.readObject(); Vector columnNames = (Vector) in.readObject(); // tableModel.setDataVector(rowData, columnNames); in.close(); } catch (Exception ex) { ex.printStackTrace(); } } }); jchkRowSelectionAllowed.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jTable1.setRowSelectionAllowed(jchkRowSelectionAllowed.isSelected()); } }); jchkColumnSelectionAllowed.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { jTable1.setColumnSelectionAllowed(jchkColumnSelectionAllowed.isSelected()); } }); jcboSelectionMode.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String selectedItem = (String) jcboSelectionMode.getSelectedItem(); if (selectedItem.equals("SINGLE_SELECTION")) jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); else if (selectedItem.equals("SINGLE_INTERVAL_SELECTION")) jTable1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); else if (selectedItem.equals("MULTIPLE_INTERVAL_SELECTION")) jTable1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } }); }
public FrontEnd() { setLocation(0, 0); setSize(1285, 750); setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { System.exit(0); } }); table = new JTable(dtm) { @Override public boolean isCellEditable(int row, int column) { if (column == 0 || column == 1) return false; else return true; } }; final JComboBox comboBoxRun = new JComboBox(); comboBoxRun.setEditable(true); comboBoxRun.addItem("Run all tests"); comboBoxRun.addItem("Run all tests and then rerun Failed tests"); comboBoxRun.addItem("Only run Failed tests"); table.getColumnModel().getColumn(0).setPreferredWidth(422); table.getColumnModel().getColumn(1).setPreferredWidth(460); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowSelectionAllowed(false); table.getTableHeader().setReorderingAllowed(false); table.getTableHeader().setPreferredSize(new Dimension(100, HEADER_HEIGHT)); table.getTableHeader().setFont(new Font(null, Font.BOLD, 12)); table.getTableHeader().setBackground(Color.LIGHT_GRAY); table.getTableHeader().setPreferredSize(new Dimension(10000, 32)); JScrollPane sp = new JScrollPane(table); JPanel subPanel = new JPanel(); JPanel subPanel1 = new JPanel(); openF = new JButton("Choose File"); openFo = new JButton("Choose Folder"); selFo = new JButton("Select Single Folder"); canF = new JButton("Cancel"); canF.setEnabled(false); resLab = new JLabel("Results Path"); Launch = new JButton("Launch"); foSel = new JButton("..."); foSel.setPreferredSize(new Dimension(18, 18)); resBox = new JTextField(placeS); resBox.setPreferredSize(new Dimension(500, 24)); resBox.setEditable(false); duplC = new JCheckBox("Remove Duplicates"); duplC.setSelected(true); subPanel.add(openF); subPanel.add(openFo); subPanel.add(selFo); subPanel.add(canF); subPanel.add(Launch); subPanel.add(duplC); subPanel.add(comboBoxRun); subPanel1.add(resLab); subPanel1.add(resBox); subPanel1.add(foSel); initUI(); getContentPane().add(sp, BorderLayout.CENTER); getContentPane().add(subPanel, BorderLayout.SOUTH); getContentPane().add(subPanel1, BorderLayout.NORTH); sValue = (String) comboBoxRun.getSelectedItem(); comboBoxRun.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { String sValue = (String) comboBoxRun.getSelectedItem(); if (sValue.equals("Run all Tests")) { flagF = 1; } if (sValue.contains("Run all tests and then rerun Failed tests")) { flagF = 2; } if (sValue.contains("Only run Failed tests")) { flagF = 3; } System.out.println(flagF); } }); openF.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { openFile(); } }); openFo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { openFolder(); } }); selFo.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { selFolder(); } }); canF.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { cancelSel(); } }); foSel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { resFol(); resBox.setText(placeS); } }); Launch.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { doLaunch(); } catch (IOException ex) { Logger.getLogger(FrontEnd.class.getName()).log(Level.SEVERE, null, ex); } } }); table.addMouseListener( new java.awt.event.MouseAdapter() { @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { // Bring up pop up on row/col of right click JTable source = (JTable) e.getSource(); int row = source.rowAtPoint(e.getPoint()); int column = source.columnAtPoint(e.getPoint()); if (!source.isRowSelected(row) || !source.isColumnSelected(column)) source.changeSelection(row, column, false, false); doPop(e); } } }); }
/** Generates Configuration tab. */ private void fillConfigurationPanel() { JPanel desc = new JPanel(new GridLayout(2, 0)); desc.setBorder(BorderFactory.createTitledBorder("Description")); desc.add( new JLabel("<html><font color=\"blue\">" + myMonitor.getDescription() + "</font></html>")); desc.add(cbEnabled); cbEnabled.setSelected(enabled); cbEnabled.addChangeListener(this); confPanel.add(desc); JPanel mlpanel = new JPanel(new GridLayout(1, 0)); mlpanel.setBorder(BorderFactory.createTitledBorder("Monitored Network Elements")); montable = new JTable(montablemodel); montable.setPreferredScrollableViewportSize(new Dimension(200, 100)); montable.getColumnModel().getColumn(0).setPreferredWidth(140); montable.getColumnModel().getColumn(1).setPreferredWidth(60); montable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int row = montable.rowAtPoint(new Point(e.getX(), e.getY())); AbstractNetworkElement ne = null; if ((row >= 0) && (row < myMonitor.getPredecessors().size())) ne = myMonitor.getPredecessors().get(row); else return; treePane.actionSelected(ne, true); } return; } }); mlpanel.add(new JScrollPane(montable)); confPanel.add(mlpanel); JPanel cpanel = new JPanel(new GridLayout(1, 0)); cpanel.setBorder(BorderFactory.createTitledBorder("Controlleded Network Elements")); ctrltable = new JTable(ctrltablemodel); ctrltable.setPreferredScrollableViewportSize(new Dimension(200, 100)); ctrltable.getColumnModel().getColumn(0).setPreferredWidth(140); ctrltable.getColumnModel().getColumn(1).setPreferredWidth(60); ctrltable.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { int row = ctrltable.rowAtPoint(new Point(e.getX(), e.getY())); AbstractNetworkElement ne = null; if ((row >= 0) && (row < myMonitor.getSuccessors().size())) ne = myMonitor.getSuccessors().get(row); else return; treePane.actionSelected(ne, true); } return; } }); cpanel.add(new JScrollPane(ctrltable)); confPanel.add(cpanel); JPanel pcl = new JPanel(new FlowLayout()); // controller list buttonProp.setEnabled(false); buttonProp.setActionCommand(cmdCtrlProp); buttonProp.addActionListener(this); pcl.setBorder(BorderFactory.createTitledBorder("Complex Controller")); buttonProp.setEnabled(false); listCControllers = new JComboBox(); listCControllers.addItem("None"); String[] ctrlClasses = myMonitor.getComplexControllerClasses(); for (int i = 0; i < ctrlClasses.length; i++) { if ((myController != null) && (myController.getClass().getName().compareTo(ctrlClasses[i]) == 0)) { listCControllers.addItem(myController); listCControllers.setSelectedIndex(i + 1); buttonProp.setEnabled(true); } else { try { Class cl = Class.forName(ctrlClasses[i]); AbstractControllerComplex cc = (AbstractControllerComplex) cl.newInstance(); cc.setMyMonitor(myMonitor); cc.initialize(); listCControllers.addItem(cc); } catch (Exception e) { } } } listCControllers.setActionCommand(cmdCtrlList); listCControllers.addActionListener(this); pcl.add(listCControllers); pcl.add(buttonProp); confPanel.add(pcl); return; }
/** Creates the view's listeners */ public void createListeners() { // If the table selection changes, set the currentInsuranceCompany accordingly (Listens to // keyboard and mouse) insuranceCompaniesTable .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if ((e.getValueIsAdjusting() == false) && (insuranceCompaniesTable.getSelectedRow() != -1)) { int selectedCompanyId = Integer.valueOf( (String) insuranceCompaniesTable.getValueAt( insuranceCompaniesTable.getSelectedRow(), 0)); controller.selectInsuranceCompany(selectedCompanyId); } } }); // Add a new InsuranceCompany addInsuranceCompanyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { controller.addInsuranceCompany(); } }); // Save an InsuranceCompany saveInsuranceCompanyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Check if a row is selected if (insuranceCompaniesTable.getSelectedRow() != -1) { int selectedCompanyId = Integer.parseInt( (String) insuranceCompaniesTable.getValueAt( insuranceCompaniesTable.getSelectedRow(), 0)); String[] newData = { companyNameTextField.getText(), telephoneTextField.getText(), urlTextField.getText(), insuranceTypesTextField.getText(), percentageTextField.getText(), generalDescriptionTextField.getText() }; // Input validation boolean checkInput = true; for (String input : newData) { if ((input.equals("")) || (input.equals(":"))) { checkInput = false; } } // Use regex pattern to check double values if (!percentageTextField.getText().matches("(-|\\+)?[0-9]+(\\.[0-9]+)?")) { checkInput = false; } if (checkInput) { recordEdited = insuranceCompaniesTable.getSelectedRow(); controller.updateInsuranceCompany(selectedCompanyId, newData); } else { showErrorMsg( "Error Saving Insurance Company", "Please enter proper values:\n(Fields cannot be blank or contain \":\")"); } } else { showErrorMsg("Error Saving Insurance Company", "Please select a valid table row."); } } }); // Delete an InsuranceCompany deleteInsuranceCompanyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Check if a row is selected if (insuranceCompaniesTable.getSelectedRow() != -1) { int i = JOptionPane.showConfirmDialog( null, "<html>Are you sure you want to delete following Insurance Company:<br><br><b>ID: " + (String) insuranceCompaniesTable.getValueAt( insuranceCompaniesTable.getSelectedRow(), 0) + " - " + (String) insuranceCompaniesTable.getValueAt( insuranceCompaniesTable.getSelectedRow(), 1) + "</b></html>", "Delete Insurance Company", JOptionPane.YES_NO_OPTION); if (i == JOptionPane.YES_OPTION) { int selectedCompanyId = Integer.parseInt( (String) insuranceCompaniesTable.getValueAt( insuranceCompaniesTable.getSelectedRow(), 0)); controller.deleteInsuranceCompany(selectedCompanyId); searchTextField.setText(""); } } else { showErrorMsg("Error Deleting Insurance Company", "Please select a valid table row."); } } }); // Enable dynamic searching, by just typing into the searchTextField searchTextField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) {} public void removeUpdate(DocumentEvent e) { searchInsuranceCompany(); } public void insertUpdate(DocumentEvent e) { searchInsuranceCompany(); } }); // Clear the searchTextField clearSearchButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { searchTextField.setText(""); } }); // Enable sorting sortComboBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String sortStrategy = (String) sortComboBox.getSelectedItem(); if (sortStrategy.equals("ID")) { model.setSortingStrategy(null); } else if (sortStrategy.equals("Company Name")) { model.setSortingStrategy(new InsuranceCompanyNameComparator()); } else { model.setSortingStrategy(new InsuranceCompanyPercentageComparator()); } updateTable(); } }); }
public ListSelectionDemo() { super(new BorderLayout()); String[] listData = {"one", "two", "three", "four", "five", "six", "seven"}; String[] columnNames = {"French", "Spanish", "Italian"}; list = new JList(listData); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2); comboBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); // Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane( output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); // topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(100, 50)); topHalf.setPreferredSize(new Dimension(100, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); // XXX: next line needed if bottomHalf is a scroll pane: // bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }
public static void main(String args[]) { // style that is necessary try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException e) { } catch (InstantiationException e) { } catch (IllegalAccessException e) { } catch (UnsupportedLookAndFeelException e) { } // Standard preparation for a frame fmain = new JFrame("Schedule Appointments"); // Create and name frame fmain.setSize(330, 375); // Set size to 400x400 pixels pane = fmain.getContentPane(); pane.setLayout(null); // Apply null layout fmain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Close when X is clicked // controls and portions of Calendar lmonth = new JLabel("January"); lyear = new JLabel("Change year:"); cyear = new JComboBox(); prev = new JButton("<<"); next = new JButton(">>"); canc = new JButton("Cancel"); mcal = new DefaultTableModel() { public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; Cal = new JTable(mcal); scal = new JScrollPane(Cal); pcal = new JPanel(null); canc.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); // action listeners for buttons and the like prev.addActionListener(new btnPrev_Action()); next.addActionListener(new btnNext_Action()); cyear.addActionListener(new cmbYear_Action()); Cal.addMouseListener(new mouseCont()); // Adding the elements to the pane pane.add(pcal); pcal.add(lmonth); pcal.add(cyear); pcal.add(prev); pcal.add(next); pcal.add(canc); pcal.add(scal); // Setting where the elements are on the pane pcal.setBounds(0, 0, 320, 335); lmonth.setBounds(160 - lmonth.getPreferredSize().width / 2, 25, 100, 25); canc.setBounds(10, 305, 80, 20); cyear.setBounds(215, 305, 100, 20); prev.setBounds(10, 25, 50, 25); next.setBounds(260, 25, 50, 25); scal.setBounds(10, 50, 300, 250); // Make frame visible fmain.setResizable(false); fmain.setVisible(true); // Inner workings for the day mechanism GregorianCalendar cal = new GregorianCalendar(); // Create calendar rday = cal.get(GregorianCalendar.DAY_OF_MONTH); // Get day rmonth = cal.get(GregorianCalendar.MONTH); // Get month ryear = cal.get(GregorianCalendar.YEAR); // Get year currentMonth = rmonth; // Match month and year currentYear = ryear; // Add days String[] days = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; // All of the days for (int i = 0; i < 7; i++) { mcal.addColumn(days[i]); } Cal.getParent().setBackground(Cal.getBackground()); // Set background // No resize/reorder Cal.getTableHeader().setResizingAllowed(false); Cal.getTableHeader().setReorderingAllowed(false); // Single cell selection Cal.setColumnSelectionAllowed(true); Cal.setRowSelectionAllowed(true); Cal.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Set row/column count Cal.setRowHeight(38); mcal.setColumnCount(7); mcal.setRowCount(6); // Placing the dates in the cells for (int i = ryear - 100; i <= ryear + 100; i++) { cyear.addItem(String.valueOf(i)); } // Refresh calendar refreshCalendar(rmonth, ryear); // Refresh calendar }