List of usage examples for javax.swing JComboBox addActionListener
public void addActionListener(ActionListener l)
ActionListener
. From source file:org.kepler.gui.ViewManager.java
/** * Instantiate all of the ViewPanes that are specified in configuration.xml * //from w ww . j a va 2 s. co m * @param parent */ public void initializeViews(TableauFrame parent) { try { ViewPaneFactory VPfactory = (ViewPaneFactory) parent.getConfiguration().getAttribute("ViewPaneFactory"); if (VPfactory == null) { VPfactory = new ViewPaneFactory(parent.getConfiguration(), "ViewPaneFactory"); } if (VPfactory != null) { boolean success = VPfactory.createViewPanes(parent); if (!success) { System.out.println("error: ViewPane is null. " + "This " + "problem can be fixed by adding a viewPaneFactory " + "property in the configuration.xml file."); } } else { System.out.println( "error: ViewPane is " + "null. This " + "problem can be fixed by adding a viewPaneFactory " + "property in the configuration.xml file."); } } catch (ptolemy.kernel.util.NameDuplicationException nde) { } catch (Exception e) { System.out.println("Could not create the ViewPaneFactory: " + e.getMessage()); e.printStackTrace(); return; } // Create the view area and add all the viewpanes to it JPanel viewArea = new JPanel(new CardLayout()); Vector<ViewPane> frameViews = getFrameViews(parent); String[] viewsList = new String[frameViews.size()]; for (int i = 0; i < frameViews.size(); i++) { ViewPane vp = frameViews.elementAt(i); viewArea.add((Component) vp, vp.getViewName()); viewsList[i] = vp.getViewName(); if (isDebugging) log.debug("add one element to viewsList:" + viewsList[i]); } try { addConfiguredTabPanes(parent); } catch (Exception e) { e.printStackTrace(); } // while( e. hasMoreElements() ){ // TableauFrame tableFrame = (TableauFrame)(e.nextElement()); // System.out.println("getContainer in _viewAreas:"+ // tableFrame.getTableau().getContainer()); // System.out.println("isMaster in _viewAreas:"+ // tableFrame.getTableau().isMaster()); // if (tableFrame.getTableau().getContainer()==null && // tableFrame.getTableau().isMaster()) // { // _viewAreas.remove(tableFrame); // System.out.println("one element is in _viewAreas removed"); // _viewComboBoxes.remove(tableFrame); // System.out.println("one element is in _viewComboBoxes removed"); // } // // } _viewAreas.put(parent, viewArea); if (isDebugging) { log.debug("_viewAreas:" + _viewAreas.size()); log.debug("_viewAreas key set:" + _viewAreas.keySet()); } JComboBox viewComboBox = new JComboBox(viewsList); if (viewComboBox != null && viewComboBox.getItemCount() > 0) { viewComboBox.setSelectedIndex(0); viewComboBox.addActionListener(new ViewComboBoxListener()); _viewComboBoxes.put(parent, viewComboBox); if (isDebugging) log.debug("_viewComboBoxes:" + _viewComboBoxes.size()); } }
From source file:org.kineticsystem.commons.data.demo.panels.ContactFilterPane.java
/** * Default constructor.//from w w w .ja va2 s .co m * @param contacts The list of contacts to sort and filter. */ public ContactFilterPane(ActiveList<RandomContact> source) { // source = new SortedList<RandomContact>(source); // ((SortedList<RandomContact>) source).setComparator(new BeanComparator("name")); // Light table format. TableStructure lightTableFormat = new BeanTableStructure(new String[] { null, null, null, null }, new String[] { "Name", "Surname", "Age", "Email" }); TableCellRenderer[] lightTableRenderers = new TableCellRenderer[] { new ColorTableCellRenderer("name", null), new ColorTableCellRenderer("surname", null), new ColorTableCellRenderer("age", null), new ColorTableCellRenderer("email", null) }; Comparator[] lightTableComparators = new Comparator[] { new BeanComparator("name"), new BeanComparator("surname"), new BeanComparator("age"), new BeanComparator("email") }; String lightTableMessage = "Show name, surname, age and email"; // Full table format. TableStructure fullTableFormat = new BeanTableStructure(new String[] { null, null, null, null, null, null }, new String[] { "Name", "Surname", "Address", "Country", "Continent", "Email" }); TableCellRenderer[] fullTableRenderers = new TableCellRenderer[] { new ColorTableCellRenderer("name", null), new ColorTableCellRenderer("surname", null), new ColorTableCellRenderer("address", null), new ColorTableCellRenderer("country", null), new ColorTableCellRenderer("continent", null), new ColorTableCellRenderer("email", null) }; Comparator[] fullTableComparators = new Comparator[] { new BeanComparator("name"), new BeanComparator("surname"), new BeanComparator("address"), new BeanComparator("country"), new BeanComparator("continent"), new BeanComparator("email") }; String fullTableMessage = "Show name, surname, address, country, " + "continent and email"; // Table model and table view. tableModel = new TableModelAdapter(source, lightTableFormat); table = new JTable(tableModel); sorter = new TableRowSorter<TableModel>(tableModel); for (int i = 0; i < lightTableComparators.length; i++) { sorter.setComparator(i, lightTableComparators[i]); table.getColumnModel().getColumn(i).setCellRenderer(lightTableRenderers[i]); } table.setRowSorter(sorter); JScrollPane tableScrollPane = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); // Table structure selector. DefaultComboBoxModel tableFormatComboModel = new DefaultComboBoxModel(new TableModeItem[] { new TableModeItem(lightTableMessage, lightTableFormat, lightTableRenderers, lightTableComparators), new TableModeItem(fullTableMessage, fullTableFormat, fullTableRenderers, fullTableComparators) }); JComboBox formatCombo = new JComboBox(tableFormatComboModel); formatCombo.setToolTipText("Select a format."); formatCombo.addActionListener(new FormatComboActionListener()); // Table filter selector. DefaultComboBoxModel filterComboModel = new DefaultComboBoxModel( new FilterComboItem[] { new FilterComboItem("Address", "address"), new FilterComboItem("Country", "country"), new FilterComboItem("Email", "email"), new FilterComboItem("Name", "name"), new FilterComboItem("Surname", "surname") }); filterCombo = new JComboBox(filterComboModel); filterCombo.setToolTipText("Select a filter."); filterCombo.setSelectedIndex(3); filterText = new JTextField(""); filterText.setToolTipText("Type a regular expression."); filterText.getDocument().addDocumentListener(new FilterDocumentListener()); filterButton = new JButton("Filter"); filterButton.setToolTipText("Press to filter."); filterButton.addActionListener(new FilterButtonActionListener()); // Layout. Cell cell = new Cell(); TetrisLayout filterLayout = new TetrisLayout(1, 3); filterLayout.setColWeight(0, 100); filterLayout.setColWeight(1, 0); filterLayout.setColWeight(2, 0); JPanel filterPane = new JPanel(filterLayout); filterPane.add(filterText, cell); filterPane.add(filterCombo, cell); filterPane.add(filterButton, cell); TetrisLayout tableLayout = new TetrisLayout(3, 1); tableLayout.setRowWeight(0, 0); tableLayout.setRowWeight(1, 0); tableLayout.setRowWeight(2, 100); setLayout(tableLayout); add(filterPane, cell); add(formatCombo, cell); add(tableScrollPane, cell); }
From source file:org.openmicroscopy.shoola.agents.imviewer.util.player.MoviePlayerControl.java
/** Adds listeners to the UI components. */ private void initListeners() { JTextField editor = view.editor; editor.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) editorActionHandler();/*from ww w . j a va 2s .com*/ } }); //JButton attachButtonListener(view.play, PLAY_CMD); attachButtonListener(view.pause, PAUSE_CMD); attachButtonListener(view.stop, STOP_CMD); //JComboBox JComboBox box = view.movieTypes; box.setActionCommand("" + MOVIE_TYPE_CMD); box.addActionListener(this); //JSpinner view.fps.addChangeListener(this); //MoviePane attachFieldListeners(view.startT); attachFieldListeners(view.endT); attachFieldListeners(view.startZ); attachFieldListeners(view.endZ); attachButtonListener(view.acrossZ, ACROSS_Z_CMD); attachButtonListener(view.acrossT, ACROSS_T_CMD); //attachButtonListener(view.acrossZT, ACROSS_ZT_CMD); view.tSlider.addPropertyChangeListener(this); view.zSlider.addPropertyChangeListener(this); }
From source file:org.openmicroscopy.shoola.agents.util.SelectionWizard.java
/** * Creates the filtering controls.//from w ww. ja v a2 s . com * * @return See above. */ private JPanel createFilteringControl() { JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(new JLabel("Filter by")); String txt = null; if (TagAnnotationData.class.equals(type)) { txt = "tag"; } else if (TagAnnotationData.class.equals(type)) { txt = "attachment"; } String[] values = new String[2]; StringBuilder builder = new StringBuilder(); builder.append("start of "); if (txt != null) { builder.append(txt); builder.append(" "); } builder.append("name"); values[0] = builder.toString(); builder = new StringBuilder(); builder.append("anywhere in "); if (txt != null) { builder.append(txt); builder.append(" "); } builder.append("name"); values[1] = builder.toString(); JComboBox box = new JComboBox(values); int selected = 0; if (uiDelegate.isFilterAnywhere()) selected = 1; box.setSelectedIndex(selected); box.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JComboBox src = (JComboBox) e.getSource(); uiDelegate.setFilterAnywhere(src.getSelectedIndex() == 1); } }); JPanel rows = new JPanel(); rows.setLayout(new BoxLayout(rows, BoxLayout.Y_AXIS)); p.add(box); rows.add(p); if (!ExperimenterData.class.equals(type)) { //Filter by owner p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(new JLabel("Filter by owner")); values = new String[3]; values[SelectionWizardUI.ALL] = "All"; values[SelectionWizardUI.CURRENT] = "Owned by me"; values[SelectionWizardUI.OTHERS] = "Owned by others"; box = new JComboBox(values); box.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JComboBox src = (JComboBox) e.getSource(); uiDelegate.setOwnerIndex(src.getSelectedIndex()); } }); p.add(box); rows.add(p); } return UIUtilities.buildComponentPanel(rows); }
From source file:org.pentaho.reporting.engine.classic.core.modules.gui.base.PreviewPane.java
protected JComboBox createZoomSelector(final PreviewPane pane) { final JComboBox zoomSelect = new JComboBox(pane.getZoomModel()); zoomSelect.addActionListener(new ZoomSelectAction(pane.getZoomModel(), pane)); zoomSelect.setAlignmentX(Component.RIGHT_ALIGNMENT); return zoomSelect; }
From source file:org.pentaho.ui.xul.swing.tags.SwingTree.java
private TableCellEditor getCellEditor(final SwingTreeCol col) { return new DefaultCellEditor(new JComboBox()) { JComponent control;/*w w w . j a va 2 s.c o m*/ @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, final int row, final int column) { Component comp; ColumnType colType = col.getColumnType(); if (colType == ColumnType.DYNAMIC) { colType = ColumnType.valueOf(extractDynamicColType(elements.toArray()[row], column)); } final XulTreeCell cell = getRootChildren().getItem(row).getRow().getCell(column); switch (colType) { case CHECKBOX: final JCheckBox checkbox = new JCheckBox(); final JTable tbl = table; checkbox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SwingTree.this.table.setValueAt(checkbox.isSelected(), row, column); tbl.getCellEditor().stopCellEditing(); } }); control = checkbox; if (value instanceof String) { checkbox.setSelected(((String) value).equalsIgnoreCase("true")); //$NON-NLS-1$ } else if (value instanceof Boolean) { checkbox.setSelected((Boolean) value); } else if (value == null) { checkbox.setSelected(false); } if (isSelected) { checkbox.setBackground(Color.LIGHT_GRAY); } comp = checkbox; checkbox.setEnabled(!cell.isDisabled()); break; case EDITABLECOMBOBOX: case COMBOBOX: Vector val = (value != null && value instanceof Vector) ? (Vector) value : new Vector(); final JComboBox comboBox = new JComboBox(val); if (isSelected) { comboBox.setBackground(Color.LIGHT_GRAY); } if (colType == ColumnType.EDITABLECOMBOBOX) { comboBox.setEditable(true); final JTextComponent textComp = (JTextComponent) comboBox.getEditor().getEditorComponent(); textComp.addKeyListener(new KeyListener() { private String oldValue = ""; //$NON-NLS-1$ public void keyPressed(KeyEvent e) { oldValue = textComp.getText(); } public void keyReleased(KeyEvent e) { if (oldValue != null && !oldValue.equals(textComp.getText())) { SwingTree.this.table.setValueAt(textComp.getText(), row, column); oldValue = textComp.getText(); } else if (oldValue == null) { // AWT error where sometimes the keyReleased is fired before keyPressed. oldValue = textComp.getText(); } else { logger.debug("Special key pressed, ignoring"); //$NON-NLS-1$ } } public void keyTyped(KeyEvent e) { } }); comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // if(textComp.hasFocus() == false && comboBox.hasFocus()){ SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$ + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$ SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column); // } } }); } else { comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SwingTree.logger.debug("Setting ComboBox value from editor: " //$NON-NLS-1$ + comboBox.getSelectedItem() + ", " + row + ", " + column); //$NON-NLS-1$ //$NON-NLS-2$ SwingTree.this.table.setValueAt(comboBox.getSelectedIndex(), row, column); } }); } control = comboBox; comboBox.setEnabled(!cell.isDisabled()); comp = comboBox; break; case LABEL: JLabel lbl = new JLabel(cell.getLabel()); comp = lbl; control = lbl; break; case CUSTOM: return new CustomCellEditorWrapper(cell, customEditors.get(col.getType())); default: final JTextField label = new JTextField((String) value); label.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } public void insertUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } public void removeUpdate(DocumentEvent arg0) { SwingTree.this.table.setValueAt(label.getText(), row, column); } }); if (isSelected) { label.setOpaque(true); // label.setBackground(Color.LIGHT_GRAY); } control = label; comp = label; label.setEnabled(!cell.isDisabled()); label.setDisabledTextColor(Color.DARK_GRAY); break; } return comp; } @Override public Object getCellEditorValue() { if (control instanceof JCheckBox) { return ((JCheckBox) control).isSelected(); } else if (control instanceof JComboBox) { JComboBox box = (JComboBox) control; if (box.isEditable()) { return ((JTextComponent) box.getEditor().getEditorComponent()).getText(); } else { return box.getSelectedIndex(); } } else if (control instanceof JTextField) { return ((JTextField) control).getText(); } else { return ((JLabel) control).getText(); } } }; }
From source file:org.spiderplan.tools.visulization.GraphFrame.java
/** * @param graph/*from w w w . j ava 2 s. c o m*/ * @param history optional history of the graph * @param title * @param lC the layout * @param edgeLabels map from edges to string labels * @param w width of the window * @param h height of the window */ @SuppressWarnings({ "rawtypes", "unchecked" }) public GraphFrame(AbstractTypedGraph<V, E> graph, Vector<AbstractTypedGraph<V, E>> history, String title, LayoutClass lC, Map<E, String> edgeLabels, int w, int h) { super(title); this.edgeLabels = edgeLabels; this.g = new ObservableGraph<V, E>(graph); this.g.addGraphEventListener(this); this.defaultEdgeType = this.g.getDefaultEdgeType(); this.layoutClass = lC; this.history = history; this.setLayout(lC); layout.setSize(new Dimension(w, h)); try { Relaxer relaxer = new VisRunner((IterativeContext) layout); relaxer.stop(); relaxer.prerelax(); } catch (java.lang.ClassCastException e) { } // Layout<V,E> staticLayout = new StaticLayout<V,E>(g, layout); // Layout<V,E> staticLayout = new SpringLayout<V, E>(g); vv = new VisualizationViewer<V, E>(layout, new Dimension(w, h)); JRootPane rp = this.getRootPane(); rp.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); getContentPane().setLayout(new BorderLayout()); getContentPane().setBackground(java.awt.Color.lightGray); getContentPane().setFont(new Font("Serif", Font.PLAIN, 10)); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.S); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<V>()); vv.setForeground(Color.black); graphMouse = new EditingModalGraphMouse<V, E>(vv.getRenderContext(), null, null); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); // vv.getRenderContext().setEd vv.getRenderContext().setEdgeLabelTransformer(this); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<E>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.addComponentListener(new ComponentAdapter() { /** * @see java.awt.event.ComponentAdapter#componentResized(java.awt.event.ComponentEvent) */ @Override public void componentResized(ComponentEvent arg0) { super.componentResized(arg0); layout.setSize(arg0.getComponent().getSize()); } }); getContentPane().add(vv); /** * Create simple container for stuff on SOUTH border of this JFrame */ Container c = new Container(); c.setLayout(new FlowLayout()); c.setBackground(java.awt.Color.lightGray); c.setFont(new Font("Serif", Font.PLAIN, 10)); /** * Button to dump jpeg */ dumpJPEG = new JButton("Dump"); dumpJPEG.addActionListener(this); dumpJPEG.setName("Dump"); c.add(dumpJPEG); /** * Button that creates offspring frame for selected vertices */ subGraphButton = new JButton("Subgraph"); subGraphButton.addActionListener(this); subGraphButton.setName("Subgraph"); c.add(subGraphButton); subGraphDepthLabel = new JLabel("Depth"); c.add(subGraphDepthLabel); subGraphDepth = new JTextField("0", 2); subGraphDepth.setHorizontalAlignment(SwingConstants.CENTER); subGraphDepth.setToolTipText("Depth of sub-graph created from selected nodes."); c.add(subGraphDepth); /** * Button that switches mouse mode */ switchMode = new JButton("Transformation"); switchMode.addActionListener(this); switchMode.setName("SwitchMode"); c.add(switchMode); /** * ComboBox for Layout selection: */ JComboBox layoutList; if (graph instanceof Forest) { String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "Baloon", "ISOM", "KK", "PolarPoint", "RadialTree", "Tree" }; layoutList = new JComboBox(layoutStrings); } else { String[] layoutStrings = { "Static", "Circle", "DAG", "Spring", "Spring2", "FR", "FR2", "ISOM", "KK", "PolarPoint" }; layoutList = new JComboBox(layoutStrings); } layoutList.setSelectedIndex(5); layoutList.addActionListener(this); layoutList.setName("SelectLayout"); c.add(layoutList); /** * Add container to layout */ c.setVisible(true); getContentPane().add(c, BorderLayout.SOUTH); /** * Setup history scroll bar */ if (history != null) { historySlider = new JSlider(0, history.size() - 1, history.size() - 1); historySlider.addChangeListener(this); historySlider.setMajorTickSpacing(10); historySlider.setMinorTickSpacing(1); historySlider.setPaintTicks(true); historySlider.setPaintLabels(true); historySlider.setBorder(BorderFactory.createEmptyBorder(0, 0, 10, 0)); Font font = new Font("Serif", Font.ITALIC, 15); historySlider.setFont(font); getContentPane().add(historySlider, BorderLayout.NORTH); } this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.pack(); this.setVisible(true); }
From source file:org.tinymediamanager.ui.panels.MediaScraperConfigurationPanel.java
private JPanel createConfigPanel() { JPanel panel = new JPanel(); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[] { 0 }; gridBagLayout.rowHeights = new int[] { 0 }; gridBagLayout.columnWeights = new double[] { Double.MIN_VALUE }; gridBagLayout.rowWeights = new double[] { Double.MIN_VALUE }; panel.setLayout(gridBagLayout);/* w ww .java2 s .co m*/ GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = 0; // build up the panel for being displayed in the popup MediaProviderConfig config = mediaProvider.getProviderInfo().getConfig(); for (Entry<String, MediaProviderConfigObject> entry : config.getConfigObjects().entrySet()) { if (!entry.getValue().isVisible()) { continue; } constraints.anchor = GridBagConstraints.LINE_START; constraints.ipadx = 20; // label JLabel label = new JLabel(entry.getValue().getKeyDescription()); constraints.gridx = 0; panel.add(label, constraints); JComponent comp; switch (entry.getValue().getType()) { case BOOL: // display as checkbox JCheckBox checkbox = new JCheckBox(); checkbox.setSelected(entry.getValue().getValueAsBool()); checkbox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dirty = true; } }); comp = checkbox; break; case SELECT: case SELECT_INDEX: // display as combobox JComboBox<String> combobox = new JComboBox<>( entry.getValue().getPossibleValues().toArray(new String[0])); combobox.setSelectedItem(entry.getValue().getValueAsString()); combobox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dirty = true; } }); comp = combobox; break; default: // display as text JTextField tf; if (entry.getValue().isEncrypt()) { tf = new JPasswordField(config.getValue(entry.getKey())); } else { tf = new JTextField(config.getValue(entry.getKey())); } tf.setPreferredSize(new Dimension(100, 24)); tf.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { dirty = true; } @Override public void insertUpdate(DocumentEvent e) { dirty = true; } @Override public void changedUpdate(DocumentEvent e) { dirty = true; } }); comp = tf; break; } comp.putClientProperty(entry.getKey(), entry.getKey()); constraints.ipadx = 0; constraints.gridx = 1; panel.add(comp, constraints); // add a hint if a long text has been found try { String desc = BUNDLE.getString( "scraper." + mediaProvider.getProviderInfo().getId() + "." + entry.getKey() + ".desc"); //$NON-NLS-1$ if (StringUtils.isNotBlank(desc)) { JLabel lblHint = new JLabel(IconManager.HINT); lblHint.setToolTipText(desc); constraints.gridx = 2; panel.add(lblHint, constraints); } } catch (Exception ignored) { } constraints.gridy++; } return panel; }
From source file:pl.otros.logview.gui.LogViewMainFrame.java
private void initToolbar() { toolBar = new JToolBar(); final JComboBox searchMode = new JComboBox( new String[] { "String contains search: ", "Regex search: ", "Query search: " }); final SearchAction searchActionForward = new SearchAction(otrosApplication, SearchDirection.FORWARD); final SearchAction searchActionBackward = new SearchAction(otrosApplication, SearchDirection.REVERSE); searchFieldCbxModel = new DefaultComboBoxModel(); searchField = new JXComboBox(searchFieldCbxModel); searchField.setEditable(true);/*from ww w. jav a 2s . com*/ AutoCompleteDecorator.decorate(searchField); searchField.setMinimumSize(new Dimension(150, 10)); searchField.setPreferredSize(new Dimension(250, 10)); searchField.setToolTipText( "<HTML>Enter text to search.<BR/>" + "Enter - search next,<BR/>Alt+Enter search previous,<BR/>" + "Ctrl+Enter - mark all found</HTML>"); final DelayedSwingInvoke delayedSearchResultUpdate = new DelayedSwingInvoke() { @Override protected void performActionHook() { JTextComponent editorComponent = (JTextComponent) searchField.getEditor().getEditorComponent(); int stringEnd = editorComponent.getSelectionStart(); if (stringEnd < 0) { stringEnd = editorComponent.getText().length(); } try { String selectedText = editorComponent.getText(0, stringEnd); if (StringUtils.isBlank(selectedText)) { return; } OtrosJTextWithRulerScrollPane<JTextPane> logDetailWithRulerScrollPane = otrosApplication .getSelectedLogViewPanel().getLogDetailWithRulerScrollPane(); MessageUpdateUtils.highlightSearchResult(logDetailWithRulerScrollPane, otrosApplication.getAllPluginables().getMessageColorizers()); RulerBarHelper.scrollToFirstMarker(logDetailWithRulerScrollPane); } catch (BadLocationException e) { LOGGER.log(Level.SEVERE, "Can't update search highlight", e); } } }; JTextComponent searchFieldTextComponent = (JTextComponent) searchField.getEditor().getEditorComponent(); searchFieldTextComponent.getDocument().addDocumentListener(new DocumentInsertUpdateHandler() { @Override protected void documentChanged(DocumentEvent e) { delayedSearchResultUpdate.performAction(); } }); final MarkAllFoundAction markAllFoundAction = new MarkAllFoundAction(otrosApplication); final SearchModeValidatorDocumentListener searchValidatorDocumentListener = new SearchModeValidatorDocumentListener( (JTextField) searchField.getEditor().getEditorComponent(), observer, SearchMode.STRING_CONTAINS); SearchMode searchModeFromConfig = configuration.get(SearchMode.class, "gui.searchMode", SearchMode.STRING_CONTAINS); final String lastSearchString; int selectedSearchMode = 0; if (searchModeFromConfig.equals(SearchMode.STRING_CONTAINS)) { selectedSearchMode = 0; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_STRING, ""); } else if (searchModeFromConfig.equals(SearchMode.REGEX)) { selectedSearchMode = 1; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_REGEX, ""); } else if (searchModeFromConfig.equals(SearchMode.QUERY)) { selectedSearchMode = 2; lastSearchString = configuration.getString(ConfKeys.SEARCH_LAST_QUERY, ""); } else { LOGGER.warning("Unknown search mode " + searchModeFromConfig); lastSearchString = ""; } Component editorComponent = searchField.getEditor().getEditorComponent(); if (editorComponent instanceof JTextField) { final JTextField sfTf = (JTextField) editorComponent; sfTf.getDocument().addDocumentListener(searchValidatorDocumentListener); sfTf.getDocument().addDocumentListener(new DocumentInsertUpdateHandler() { @Override protected void documentChanged(DocumentEvent e) { try { int length = e.getDocument().getLength(); if (length > 0) { searchResultColorizer.setSearchString(e.getDocument().getText(0, length)); } } catch (BadLocationException e1) { LOGGER.log(Level.SEVERE, "Error: ", e1); } } }); sfTf.addKeyListener(new SearchFieldKeyListener(searchActionForward, sfTf)); sfTf.setText(lastSearchString); } searchMode.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SearchMode mode = null; boolean validationEnabled = false; String confKey = null; String lastSearch = ((JTextField) searchField.getEditor().getEditorComponent()).getText(); if (searchMode.getSelectedIndex() == 0) { mode = SearchMode.STRING_CONTAINS; searchValidatorDocumentListener.setSearchMode(mode); validationEnabled = false; searchMode.setToolTipText("Checking if log message contains string (case is ignored)"); confKey = ConfKeys.SEARCH_LAST_STRING; } else if (searchMode.getSelectedIndex() == 1) { mode = SearchMode.REGEX; validationEnabled = true; searchMode .setToolTipText("Checking if log message matches regular expression (case is ignored)"); confKey = ConfKeys.SEARCH_LAST_REGEX; } else if (searchMode.getSelectedIndex() == 2) { mode = SearchMode.QUERY; validationEnabled = true; String querySearchTooltip = "<HTML>" + // "Advance search using SQL-like quries (i.e. level>=warning && msg~=failed && thread==t1)<BR/>" + // "Valid operator for query search is ==, ~=, !=, LIKE, EXISTS, <, <=, >, >=, &&, ||, ! <BR/>" + // "See wiki for more info<BR/>" + // "</HTML>"; searchMode.setToolTipText(querySearchTooltip); confKey = ConfKeys.SEARCH_LAST_QUERY; } searchValidatorDocumentListener.setSearchMode(mode); searchValidatorDocumentListener.setEnable(validationEnabled); searchActionForward.setSearchMode(mode); searchActionBackward.setSearchMode(mode); markAllFoundAction.setSearchMode(mode); configuration.setProperty("gui.searchMode", mode); searchResultColorizer.setSearchMode(mode); List<Object> list = configuration.getList(confKey); searchFieldCbxModel.removeAllElements(); for (Object o : list) { searchFieldCbxModel.addElement(o); } searchField.setSelectedItem(lastSearch); } }); searchMode.setSelectedIndex(selectedSearchMode); final JCheckBox markFound = new JCheckBox("Mark search result"); markFound.setMnemonic(KeyEvent.VK_M); searchField.addKeyListener(markAllFoundAction); configuration.addConfigurationListener(markAllFoundAction); JButton markAllFoundButton = new JButton(markAllFoundAction); final JComboBox markColor = new JComboBox(MarkerColors.values()); markFound.setSelected(configuration.getBoolean("gui.markFound", true)); markFound.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { boolean selected = markFound.isSelected(); searchActionForward.setMarkFound(selected); searchActionBackward.setMarkFound(selected); configuration.setProperty("gui.markFound", markFound.isSelected()); } }); markColor.setRenderer(new MarkerColorsComboBoxRenderer()); // markColor.addActionListener(new ActionListener() { // // @Override // public void actionPerformed(ActionEvent e) { // MarkerColors markerColors = (MarkerColors) markColor.getSelectedItem(); // searchActionForward.setMarkerColors(markerColors); // searchActionBackward.setMarkerColors(markerColors); // markAllFoundAction.setMarkerColors(markerColors); // configuration.setProperty("gui.markColor", markColor.getSelectedItem()); // otrosApplication.setSelectedMarkColors(markerColors); // } // }); markColor.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { MarkerColors markerColors = (MarkerColors) markColor.getSelectedItem(); searchActionForward.setMarkerColors(markerColors); searchActionBackward.setMarkerColors(markerColors); markAllFoundAction.setMarkerColors(markerColors); configuration.setProperty("gui.markColor", markColor.getSelectedItem()); otrosApplication.setSelectedMarkColors(markerColors); } }); markColor.getModel() .setSelectedItem(configuration.get(MarkerColors.class, "gui.markColor", MarkerColors.Aqua)); buttonSearch = new JButton(searchActionForward); buttonSearch.setMnemonic(KeyEvent.VK_N); JButton buttonSearchPrev = new JButton(searchActionBackward); buttonSearchPrev.setMnemonic(KeyEvent.VK_P); enableDisableComponetsForTabs.addComponet(buttonSearch); enableDisableComponetsForTabs.addComponet(buttonSearchPrev); enableDisableComponetsForTabs.addComponet(searchField); enableDisableComponetsForTabs.addComponet(markFound); enableDisableComponetsForTabs.addComponet(markAllFoundButton); enableDisableComponetsForTabs.addComponet(searchMode); enableDisableComponetsForTabs.addComponet(markColor); toolBar.add(searchMode); toolBar.add(searchField); toolBar.add(buttonSearch); toolBar.add(buttonSearchPrev); toolBar.add(markFound); toolBar.add(markAllFoundButton); toolBar.add(markColor); JButton nextMarked = new JButton(new JumpToMarkedAction(otrosApplication, Direction.FORWARD)); nextMarked.setToolTipText(nextMarked.getText()); nextMarked.setText(""); nextMarked.setMnemonic(KeyEvent.VK_E); enableDisableComponetsForTabs.addComponet(nextMarked); toolBar.add(nextMarked); JButton prevMarked = new JButton(new JumpToMarkedAction(otrosApplication, Direction.BACKWARD)); prevMarked.setToolTipText(prevMarked.getText()); prevMarked.setText(""); prevMarked.setMnemonic(KeyEvent.VK_R); enableDisableComponetsForTabs.addComponet(prevMarked); toolBar.add(prevMarked); enableDisableComponetsForTabs.addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.INFO))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.WARNING))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, 1, Level.SEVERE))); enableDisableComponetsForTabs.addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.INFO))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.WARNING))); enableDisableComponetsForTabs .addComponet(toolBar.add(new SearchByLevel(otrosApplication, -1, Level.SEVERE))); }
From source file:renderer.DependencyGrapher.java
/** * create an instance of a simple graph in two views with controls to * demo the features./* w ww . ja va 2 s. c o m*/ * */ public DependencyGrapher() { // create a simple graph for the demo final DependencyDirectedSparceMultiGraph<String, Number> graph = createGraph(); //TestGraphs.getOneComponentGraph(); // the preferred sizes for the two views // create one layout for the graph final FRLayout2<String, Number> layout = new FRLayout2<String, Number>(graph); layout.setMaxIterations(500); VisualizationModel<String, Number> vm = new DefaultVisualizationModel<String, Number>(layout, preferredSize1); Transformer<Number, String> stringer = new Transformer<Number, String>() { public String transform(Number e) { if (graph.getEdgeAttributes(e) != null) { return graph.getEdgeAttributes(e).toString(); } return null; } }; // create 2 views that share the same model final VisualizationViewer<String, Number> vv = new VisualizationViewer<String, Number>(vm, preferredSize1); vv.setBackground(Color.white); vv.getRenderContext().setEdgeLabelTransformer(stringer); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<String, Number>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(vv.getPickedVertexState(), Color.red, Color.yellow)); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO); // add default listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); // ToolTipManager.sharedInstance().setDismissDelay(10000); Container content = getContentPane(); Container panel = new JPanel(new BorderLayout()); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); panel.add(gzsp); helpDialog = new JDialog(); helpDialog.getContentPane().add(new JLabel(instructions)); RenderContext<String, Number> rc = vv.getRenderContext(); AnnotatingGraphMousePlugin annotatingPlugin = new AnnotatingGraphMousePlugin(rc); // create a GraphMouse for the main view // final AnnotatingModalGraphMouse graphMouse = new AnnotatingModalGraphMouse(rc, annotatingPlugin); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); final ScalingControl scaler = new CrossoverScalingControl(); JButton filterReset = new JButton("Reset"); filterReset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getModel().setGraphLayout(layout); } }); JButton filterFilter = new JButton("Filter"); filterReset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getModel().setGraphLayout(layout); } }); JRadioButton filterDirectionInOut = new JRadioButton("In/Out"); filterDirectionInOut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Dependency Direction: " + EdgeType.IN_OUT); _filterEdgeDirection = EdgeType.IN_OUT; filterLayout = getNewLayout(graph, layout); vv.getModel().setGraphLayout(filterLayout); } }); JRadioButton filterDirectionIn = new JRadioButton("In"); filterDirectionIn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Dependency Direction: " + EdgeType.IN); _filterEdgeDirection = EdgeType.IN; filterLayout = getNewLayout(graph, layout); vv.getModel().setGraphLayout(filterLayout); } }); JRadioButton filterDirectionOut = new JRadioButton("Out"); filterDirectionOut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Dependency Direction: " + EdgeType.OUT); _filterEdgeDirection = EdgeType.OUT; filterLayout = getNewLayout(graph, layout); vv.getModel().setGraphLayout(filterLayout); } }); ButtonGroup filterRadios = new ButtonGroup(); filterRadios.add(filterDirectionInOut); filterRadios.add(filterDirectionIn); filterRadios.add(filterDirectionOut); filterRadios.setSelected(filterDirectionInOut.getModel(), true); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.setSelectedItem(ModalGraphMouse.Mode.PICKING); final JComboBox filterBox = new JComboBox(graph.getVertices().toArray()); filterBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { _filterChoice = filterBox.getSelectedItem().toString(); System.out.println(_filterChoice); filterLayout = getNewLayout(graph, layout); vv.getModel().setGraphLayout(filterLayout); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { helpDialog.pack(); helpDialog.setVisible(true); } }); JPanel controls = new JPanel(); JPanel modeControls = new JPanel(); modeControls.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modeControls.add(graphMouse.getModeComboBox()); controls.add(modeControls); JPanel annotationControlPanel = new JPanel(); annotationControlPanel.setBorder(BorderFactory.createTitledBorder("Annotation Controls")); AnnotationControls annotationControls = new AnnotationControls(annotatingPlugin); annotationControlPanel.add(annotationControls.getAnnotationsToolBar()); controls.add(annotationControlPanel); JPanel helpControls = new JPanel(); helpControls.setBorder(BorderFactory.createTitledBorder("Help")); helpControls.add(help); controls.add(helpControls); JPanel filterControls = new JPanel(); filterControls.setBorder(BorderFactory.createTitledBorder("Filter")); filterControls.add(filterBox); filterControls.add(filterDirectionInOut); filterControls.add(filterDirectionIn); filterControls.add(filterDirectionOut); filterControls.add(filterReset); controls.add(filterControls); content.add(panel); content.add(controls, BorderLayout.SOUTH); }