/** Listener to handle button actions */ public void actionPerformed(ActionEvent e) { // Check if the user changed the service filter option if (e.getSource() == service_box) { service_list.setEnabled(service_box.isSelected()); service_list.clearSelection(); remove_service_button.setEnabled(false); add_service_field.setEnabled(service_box.isSelected()); add_service_field.setText(""); add_service_button.setEnabled(false); } // Check if the user pressed the add service button if ((e.getSource() == add_service_button) || (e.getSource() == add_service_field)) { String text = add_service_field.getText(); if ((text != null) && (text.length() > 0)) { service_data.addElement(text); service_list.setListData(service_data); } add_service_field.setText(""); add_service_field.requestFocus(); } // Check if the user pressed the remove service button if (e.getSource() == remove_service_button) { Object[] sels = service_list.getSelectedValues(); for (int i = 0; i < sels.length; i++) { service_data.removeElement(sels[i]); } service_list.setListData(service_data); service_list.clearSelection(); } }
/** Constructor */ public ServiceFilterPanel(String text, Vector list) { empty_border = new EmptyBorder(5, 5, 0, 5); indent_border = new EmptyBorder(5, 25, 5, 5); service_box = new JCheckBox(text); service_box.addActionListener(this); service_data = new Vector(); if (list != null) { service_box.setSelected(true); service_data = (Vector) list.clone(); } service_list = new JList(service_data); service_list.setBorder(new EtchedBorder()); service_list.setVisibleRowCount(5); service_list.addListSelectionListener(this); service_list.setEnabled(service_box.isSelected()); service_scroll = new JScrollPane(service_list); service_scroll.setBorder(new EtchedBorder()); remove_service_button = new JButton("Remove"); remove_service_button.addActionListener(this); remove_service_button.setEnabled(false); remove_service_panel = new JPanel(); remove_service_panel.setLayout(new FlowLayout()); remove_service_panel.add(remove_service_button); service_area = new JPanel(); service_area.setLayout(new BorderLayout()); service_area.add(service_scroll, BorderLayout.CENTER); service_area.add(remove_service_panel, BorderLayout.EAST); service_area.setBorder(indent_border); add_service_field = new JTextField(); add_service_field.addActionListener(this); add_service_field.getDocument().addDocumentListener(this); add_service_field.setEnabled(service_box.isSelected()); add_service_button = new JButton("Add"); add_service_button.addActionListener(this); add_service_button.setEnabled(false); add_service_panel = new JPanel(); add_service_panel.setLayout(new BorderLayout()); JPanel dummy = new JPanel(); dummy.setBorder(empty_border); add_service_panel.add(dummy, BorderLayout.WEST); add_service_panel.add(add_service_button, BorderLayout.EAST); add_service_area = new JPanel(); add_service_area.setLayout(new BorderLayout()); add_service_area.add(add_service_field, BorderLayout.CENTER); add_service_area.add(add_service_panel, BorderLayout.EAST); add_service_area.setBorder(indent_border); setLayout(new BorderLayout()); add(service_box, BorderLayout.NORTH); add(service_area, BorderLayout.CENTER); add(add_service_area, BorderLayout.SOUTH); setBorder(empty_border); }
/** Listener to handle service list selection changes */ public void valueChanged(ListSelectionEvent e) { if (service_list.getSelectedIndex() == -1) { remove_service_button.setEnabled(false); } else { remove_service_button.setEnabled(true); } }
public void updateClientList() { Iterator i = clients.iterator(); DefaultListModel model = new DefaultListModel(); EditorClient placebo = new EditorClient(self, 0, " ", 0, 0, ""); model.addElement(placebo); while (i.hasNext()) { EditorClient c = (EditorClient) i.next(); model.addElement(c); } lstClients.setModel(model); lstClients.setSelectedValue(currClient, true); }
public ClientsPanel() { super(new BorderLayout()); lstClients = new JList(); lstClients.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); lstClients.setCellRenderer( new DefaultListCellRenderer() { public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { EditorClient c = (EditorClient) value; JLabel label = new JLabel(c.getName()); if (c.isPresent()) label.setForeground(MyColors.getMainColor(c.getColorCode())); else label.setForeground(Color.GRAY); if (isSelected) label.setBackground(lstClients.getSelectionBackground()); return label; } }); lstClients.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (EditorServer_Debug) System.out.println(" mouseClicked "); int ndx = lstClients.locationToIndex(new Point(e.getX(), e.getY())); if (ndx > -1 && ndx < lstClients.getModel().getSize()) lstClients.setSelectedIndex(ndx); else { if (EditorServer_Debug) System.out.println(" invalid mouse click on the JList"); } } }); lstClients.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { EditorClient c = (EditorClient) lstClients.getSelectedValue(); currClient = c; updateActionTableFor(currClient); } }); tblActions = new JTable(getClearTableModel()); add(new JScrollPane(lstClients), BorderLayout.WEST); add(new JScrollPane(tblActions), BorderLayout.CENTER); }
public void actionPerformed(ActionEvent e) { List<Resource> loadedDocuments; try { // get all the documents loaded in the system loadedDocuments = Gate.getCreoleRegister().getAllInstances("gate.Document"); } catch (GateException ge) { // gate.Document is not registered in creole.xml....what is!? throw new GateRuntimeException( "gate.Document is not registered in the creole register!\n" + "Something must be terribly wrong...take a vacation!"); } Vector<String> docNames = new Vector<String>(); for (Resource loadedDocument : new ArrayList<Resource>(loadedDocuments)) { if (corpus.contains(loadedDocument)) { loadedDocuments.remove(loadedDocument); } else { docNames.add(loadedDocument.getName()); } } JList docList = new JList(docNames); docList.getSelectionModel().setSelectionInterval(0, docNames.size() - 1); docList.setCellRenderer(renderer); final JOptionPane optionPane = new JOptionPane( new JScrollPane(docList), JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION); final JDialog dialog = optionPane.createDialog(CorpusEditor.this, "Add document(s) to this corpus"); docList.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { optionPane.setValue(JOptionPane.OK_OPTION); dialog.dispose(); } } }); dialog.setVisible(true); if (optionPane.getValue().equals(JOptionPane.OK_OPTION)) { int[] selectedIndices = docList.getSelectedIndices(); for (int selectedIndice : selectedIndices) { corpus.add((Document) loadedDocuments.get(selectedIndice)); } } changeMessage(); }
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 } }
protected void detachFrom(Component jc) { listenedTo.remove(jc); if (extListener != null && extListener.accept(jc)) { extListener.stopListeningTo(jc); } if (isProbablyAContainer(jc)) { detachFromHierarchyOf((Container) jc); } else if (jc instanceof JList) { ((JList) jc).removeListSelectionListener(this); } else if (jc instanceof JComboBox) { ((JComboBox) jc).removeActionListener(this); } else if (jc instanceof JTree) { ((JTree) jc).getSelectionModel().removeTreeSelectionListener(this); } else if (jc instanceof JToggleButton) { ((AbstractButton) jc).removeActionListener(this); } else if (jc instanceof JTextComponent) { } else if (jc instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent jc.removePropertyChangeListener("value", this); ((JTextComponent) jc).getDocument().removeDocumentListener(this); } else if (jc instanceof JColorChooser) { ((JColorChooser) jc).getSelectionModel().removeChangeListener(this); } else if (jc instanceof JSpinner) { ((JSpinner) jc).removeChangeListener(this); } else if (jc instanceof JSlider) { ((JSlider) jc).removeChangeListener(this); } else if (jc instanceof JTable) { ((JTable) jc).getSelectionModel().removeListSelectionListener(this); } if (accept(jc) && !(jc instanceof JPanel)) { jc.removePropertyChangeListener("name", this); Object key = wizardPage.getMapKeyFor(jc); if (key != null) { if (logger.isLoggable(Level.FINE)) { logger.fine( "Named component removed from hierarchy: " + // NOI18N key + ". Removing any corresponding " + // NOI18N "value from the wizard settings map."); // NOI18N } wizardPage.removeFromMap(key); } } if (logger.isLoggable(Level.FINE) && accept(jc)) { logger.fine("Stop listening to " + jc); // NOI18N } }
private void backBind() { status.setText(viewModel.getStatus()); compute.setEnabled(viewModel.isButtonEnabled()); monthlyPayment.setText(viewModel.getMonthlyPayment()); overpaymentWithFees.setText(viewModel.getOverpaymentWithFees()); overpayment.setText(viewModel.getOverpayment()); DefaultTableModel model = viewModel.getGraphicOfPayments(); graphicOfPayments.setModel(model); graphicOfPayments.setPreferredSize( new Dimension( graphicOfPayments.getWidth(), graphicOfPayments.getRowHeight() * model.getRowCount())); List<String> log = viewModel.getLog(); String[] items = log.toArray(new String[log.size()]); logList.setListData(items); }
private static <E> JList<E> newList(DefaultListModel<E> listModel) { JList<E> list = new JList<>(listModel); list.setFont(f13); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); return list; }
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 void unhiliteInactiveParticipant(String cname) { int i = plistModel.indexOf(cname); plist.removeSelectionInterval(i, i); }
public void hiliteActiveParticipant(String cname) { int i = plistModel.indexOf(cname); plist.addSelectionInterval(i, i); }
public DocumentPanel() { super(new BorderLayout()); JLabel lblDocument = new JLabel("Document: " + document.getTitle()); lblDocument.setBorder(new EtchedBorder()); textPane = new JTextPane(document); textPane.setEditable(false); textPane.setMargin(new Insets(5, 20, 5, 5)); textPane.setMaximumSize(new Dimension(364, 1000000000)); textPane.setPreferredSize(new Dimension(364, 400)); textPane.setMinimumSize(new Dimension(364, 10)); textPane.addCaretListener( new CaretListener() { public void caretUpdate(CaretEvent e) { int length = document.getLength(); int offset = e.getDot(); if (e.getDot() == e.getMark()) textPane.getCaret().moveDot(offset + 1); Paragraph p = lockManager.getParFromOffset(offset); int pOffset = p.getOffset(); lblCursor.setText( "Document Length=" + String.valueOf(length) + ", CaretOffset=" + String.valueOf(offset) + ", Paragraph=" + p.toString() + ", Offset in Paragraph=" + String.valueOf(offset - p.getOffset())); } }); Box box = new Box(BoxLayout.X_AXIS); box.add(textPane); box.add(Box.createGlue()); box.setBackground(Color.WHITE); box.setOpaque(true); box.setPreferredSize(new Dimension(600, 10000)); lblCursor = new JLabel("Cursor"); lblCursor.setBorder(new EtchedBorder()); JPanel boxText = new JPanel(new BorderLayout()); boxText.setBorder(new EmptyBorder(5, 5, 5, 5)); boxText.add(lblDocument, BorderLayout.NORTH); boxText.add(new JScrollPane(box), BorderLayout.CENTER); boxText.add(lblCursor, BorderLayout.SOUTH); JLabel lblPars = new JLabel("Paragraphs: "); lblPars.setBorder(new EtchedBorder()); parList = new JList(); parList.setPreferredSize(new Dimension(100, 300)); parList.setEnabled(false); JPanel boxPars = new JPanel(new BorderLayout()); boxPars.setBorder(new EmptyBorder(5, 5, 5, 5)); boxPars.add(lblPars, BorderLayout.NORTH); boxPars.add(new JScrollPane(parList), BorderLayout.CENTER); add(boxText, BorderLayout.CENTER); add(boxPars, BorderLayout.EAST); }
public JunctionLinkDataFrame(final JunctionLink jl) { super( jl.getCurrName() + " properties", false, // resizable false, // closable false, // maximizable true); // iconifiable // PSRender.onHold(); super.setBackground(back_color); super.addInternalFrameListener( new InternalFrameAdapter() { public void internalFrameActivated(InternalFrameEvent e) { reload(); SelectedObject.setSelectedObject(jl); } }); PSRender.moveToTop(jl.getBound(), 0.5); ml = jl; setLocation(50, 50); dataModelMain = new HeadTable(jl); tableMain = new JTable(dataModelMain); tableMain.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); tableMain.setPreferredScrollableViewportSize(new Dimension(500, 20)); // tableMain.setBackground(back_color); // code TableColumn column_code = tableMain.getColumn("Code"); DefaultTableCellRenderer rendererCode = new DefaultTableCellRenderer(); rendererCode.setToolTipText("Enter new code for this path"); column_code.setCellRenderer(rendererCode); column_code.setCellEditor(new TextFieldEditor()); // name TableColumn column_name = tableMain.getColumn("Name"); LanguageButtonRender render_name = new LanguageButtonRender(); render_name.setToolTipText("Path name. Press for change name"); column_name.setCellRenderer(render_name); LanguageButtonEditor editor_name = new LanguageButtonEditor(new JCheckBox()); column_name.setCellEditor(editor_name); // junction 1 TableColumn column_junc_1 = tableMain.getColumn("Junction 1"); MLButtonRenderer rendererJunc_1 = new MLButtonRenderer(); rendererJunc_1.setToolTipText("Code of first Junction, click for open properties"); column_junc_1.setCellRenderer(rendererJunc_1); MLButtonEditor editorJunc = new MLButtonEditor(new JCheckBox()); column_junc_1.setCellEditor(editorJunc); // junction 2 TableColumn column_junc_2 = tableMain.getColumn("Junction 2"); MLButtonRenderer rendererJunc_2 = new MLButtonRenderer(); rendererJunc_2.setToolTipText("Code of second Junction, click for open properties"); column_junc_2.setCellRenderer(rendererJunc_2); column_junc_2.setCellEditor(editorJunc); // type JComboBox comboBoxType = new JComboBox(); String roadNames[] = jl.getTypeNames(); for (int i = 0, len = roadNames.length; i < len; i++) { comboBoxType.addItem(roadNames[i]); } TableColumn column_type = tableMain.getColumn("Type"); DefaultTableCellRenderer rendererType = new DefaultTableCellRenderer(); rendererType.setToolTipText("To change road type click for combo box"); column_type.setCellRenderer(rendererType); column_type.setCellEditor(new DefaultCellEditor(comboBoxType)); // legth TableColumn column_length = tableMain.getColumn("Length"); DefaultTableCellRenderer rendererLen = new DefaultTableCellRenderer(); rendererLen.setToolTipText("The path length in meters"); column_length.setCellRenderer(rendererLen); scrollpaneMain = new JScrollPane(tableMain); scrollpaneMain.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollpaneMain.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); scrollpaneMain.setPreferredSize(new Dimension(500, 50)); Container contentPane = super.getContentPane(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); contentPane.setLayout(gridbag); c.ipady = 0; // make this component tall c.weightx = 0.5; c.gridwidth = 4; c.gridx = 0; c.gridy = 0; gridbag.setConstraints(scrollpaneMain, c); // scrollpaneMain.setBackground(back_color); // scrollpaneMain.setForeground(back_color); contentPane.add(scrollpaneMain); TableModel dataModelPoints = new PointTableModel(jl); tablePoints = new JTable(dataModelPoints); tablePoints.setPreferredScrollableViewportSize( new Dimension(200, dataModelPoints.getRowCount() * tablePoints.getRowHeight())); ListModel lm = new AbstractListModel() { public int getSize() { return 1000; } public Object getElementAt(int index) { return "" + index; } }; JList rowHeader = new JList(lm); rowHeader.setFixedCellWidth(20); rowHeader.setFixedCellHeight(tablePoints.getRowHeight()); // + tablePoints.getRowMargin()); rowHeader.setCellRenderer(new RowHeaderRenderer(tablePoints)); scrollPanePoints = new JScrollPane(tablePoints); scrollPanePoints.setWheelScrollingEnabled(true); scrollPanePoints.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPanePoints.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); int mh; if (dataModelPoints.getRowCount() * tablePoints.getRowHeight() > 100) { mh = 100; } else { mh = dataModelPoints.getRowCount() * tablePoints.getRowHeight(); } scrollPanePoints.setPreferredSize(new Dimension(200, mh)); scrollPanePoints.setRowHeaderView(rowHeader); c.ipadx = 200; c.weightx = 0.5; c.gridwidth = 3; c.gridx = 1; c.gridy = 1; gridbag.setConstraints(scrollPanePoints, c); // scrollPanePoints.setBackground(back_color); contentPane.add(scrollPanePoints); button_ok = new JButton("Ok"); button_ok.addActionListener(this); JPanel buttonPane = new JPanel(null); buttonPane.setPreferredSize(new Dimension(500, 100)); button_ok.setBounds(205, 40, 90, 40); buttonPane.add(button_ok); c.ipady = 10; // make this component tall c.ipadx = 10; c.weightx = 0.5; c.gridwidth = 4; c.gridx = 2; c.gridy = 2; gridbag.setConstraints(buttonPane, c); buttonPane.setBackground(back_color); contentPane.add(buttonPane); super.pack(); super.setVisible(true); // MapApplication.getDesktop().setSelectedFrame(this); }