List of usage examples for javax.swing JComboBox addItemListener
public void addItemListener(ItemListener aListener)
ItemListener
. From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTreeGUI() { treeLayout = new TreeLayout<String, Integer>(graph); radialLayout = new BalloonLayout<String, Integer>(graph); radialLayout.setSize(new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.E); rings = new Rings(radialLayout); Container content = tree2Panel; final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel);// ww w . j a v a2 s.c o m final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }
From source file:org.ut.biolab.medsavant.client.filter.TagFilterView.java
public TagFilterView(int queryID) { super(FILTER_NAME, queryID); setLayout(new BorderLayout()); setBorder(ViewUtil.getBigBorder());//from w w w.j ava 2s .co m setMaximumSize(new Dimension(200, 80)); JPanel cp = new JPanel(); GridBagLayout gbl = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0; c.gridy = 0; cp.setLayout(gbl); variantTags = new ArrayList<VariantTag>(); appliedTags = new ArrayList<VariantTag>(); clear = new JButton("Clear"); applyButton = new JButton("Apply"); try { final JComboBox tagNameCB = new JComboBox(); //tagNameCB.setMaximumSize(new Dimension(1000,30)); final JComboBox tagValueCB = new JComboBox(); //tagValueCB.setMaximumSize(new Dimension(1000,30)); JPanel bottomContainer = new JPanel(); ViewUtil.applyHorizontalBoxLayout(bottomContainer); List<String> tagNames = MedSavantClient.VariantManager .getDistinctTagNames(LoginController.getSessionID()); for (String tag : tagNames) { tagNameCB.addItem(tag); } ta = new JTextArea(); ta.setRows(10); ta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); ta.setEditable(false); applyButton.setEnabled(false); JLabel addButton = ViewUtil .createIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.ADD)); addButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (tagNameCB.getSelectedItem() == null || tagValueCB.getSelectedItem() == null) { return; } VariantTag tag = new VariantTag((String) tagNameCB.getSelectedItem(), (String) tagValueCB.getSelectedItem()); if (variantTags.isEmpty()) { ta.append(tag.toString() + "\n"); } else { ta.append("AND " + tag.toString() + "\n"); } variantTags.add(tag); applyButton.setEnabled(true); } }); clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { variantTags.clear(); ta.setText(""); applyButton.setEnabled(true); } }); int width = 150; ta.setPreferredSize(new Dimension(width, width)); ta.setMaximumSize(new Dimension(width, width)); tagNameCB.setPreferredSize(new Dimension(width, 25)); tagValueCB.setPreferredSize(new Dimension(width, 25)); tagNameCB.setMaximumSize(new Dimension(width, 25)); tagValueCB.setMaximumSize(new Dimension(width, 25)); cp.add(new JLabel("Name"), c); c.gridx++; cp.add(tagNameCB, c); c.gridx++; c.gridx = 0; c.gridy++; cp.add(new JLabel("Value"), c); c.gridx++; cp.add(tagValueCB, c); c.gridx++; cp.add(addButton, c); tagNameCB.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent ie) { updateTagValues((String) tagNameCB.getSelectedItem(), tagValueCB); } }); if (tagNameCB.getItemCount() > 0) { tagNameCB.setSelectedIndex(0); updateTagValues((String) tagNameCB.getSelectedItem(), tagValueCB); } al = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applyButton.setEnabled(false); appliedTags = new ArrayList<VariantTag>(variantTags); Filter f = new Filter() { @Override public Condition[] getConditions() { try { List<Integer> uploadIDs = MedSavantClient.VariantManager .getUploadIDsMatchingVariantTags(LoginController.getSessionID(), TagFilterView.tagsToStringArray(variantTags)); Condition[] uploadIDConditions = new Condition[uploadIDs.size()]; TableSchema table = MedSavantClient.CustomTablesManager.getCustomTableSchema( LoginController.getSessionID(), MedSavantClient.ProjectManager.getVariantTableName( LoginController.getSessionID(), ProjectController.getInstance().getCurrentProjectID(), ReferenceController.getInstance().getCurrentReferenceID(), true)); for (int i = 0; i < uploadIDs.size(); i++) { uploadIDConditions[i] = BinaryCondition.equalTo( table.getDBColumn(BasicVariantColumns.UPLOAD_ID), uploadIDs.get(i)); } return new Condition[] { ComboCondition.or(uploadIDConditions) }; } catch (Exception ex) { ClientMiscUtils.reportError("Error getting upload IDs: %s", ex); } return new Condition[0]; } @Override public String getName() { return FILTER_NAME; } @Override public String getID() { return FILTER_ID; } }; FilterController.getInstance().addFilter(f, TagFilterView.this.queryID); } }; applyButton.addActionListener(al); bottomContainer.add(Box.createHorizontalGlue()); bottomContainer.add(clear); bottomContainer.add(applyButton); add(ViewUtil.getClearBorderedScrollPane(ta), BorderLayout.CENTER); add(bottomContainer, BorderLayout.SOUTH); } catch (Exception ex) { ClientMiscUtils.checkSQLException(ex); } add(cp, BorderLayout.NORTH); this.showViewCard(); }
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);//w ww. j av a 2 s .c o m 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:prototype.TreeLayoutDemo.java
public TreeLayoutDemo() { // create a simple graph for the demo graph = new DelegateForest<String, Integer>(); createTree();/* w ww . j av a2s .c o m*/ treeLayout = new TreeLayout<String, Integer>(graph); radialLayout = new RadialTreeLayout<String, Integer>(graph); vv = new VisualizationViewer<String, Integer>(treeLayout, new Dimension(5000, 5000)); vv.setBackground(Color.white); //vv.setPreferredSize(new Dimension(2000, 2000)); vv.setPreferredSize(new Dimension(5000, 5000)); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); vv.getRenderContext().setVertexLabelTransformer(labler); vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.lightGray)); rings = new Rings(); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JToggleButton radial = new JToggleButton("Radial"); JButton screenshot = new JButton("Screenshot"); screenshot.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Taking Screenshot"); //ExportDialog export = new ExportDialog(); //export.showExportDialog(vv, "Export view as ...", vv, "export"); Properties p = new Properties(); //setSize(5000,5000); p.setProperty("PageSize", "A1"); VectorGraphics g; try { Date dt = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd_HH_mm"); String filename = "C://Users//frisch//Desktop//mapexport//" + "Output" + df.format(dt) + ".svg"; System.out.println(panel.getHeight() + " / " + panel.getWidth()); g = new SVGGraphics2D(new File(filename), new Dimension(5000, 5000));//5000,5000 g.setBackground(Color.WHITE); g.setProperties(p); g.startExport(); vv.printAll(g); g.endExport(); } catch (IOException ex) { Logger.getLogger(GeschaeftsfallViewer.class.getName()).log(Level.SEVERE, null, ex); System.out.println("Exception : " + ex.getMessage()); } } }); radial.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, treeLayout, radialLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.addPreRenderPaintable(rings); } else { LayoutTransition<String, Integer> lt = new LayoutTransition<String, Integer>(vv, radialLayout, treeLayout); Animator animator = new Animator(lt); animator.start(); vv.getRenderContext().getMultiLayerTransformer().setToIdentity(); vv.removePreRenderPaintable(rings); } vv.repaint(); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(radial); controls.add(scaleGrid); controls.add(modeBox); controls.add(screenshot); content.add(controls, BorderLayout.NORTH); }
From source file:ro.nextreports.designer.querybuilder.RuntimeParametersPanel.java
private void initUI() { setLayout(new GridBagLayout()); JPanel panel = new JPanel(); panel.setLayout(new GridBagLayout()); components = new ArrayList<JComponent>(); checks = new ArrayList<JCheckBox>(); int size = paramList.size(); boolean shouldExpand = false; boolean needScroll = false; for (int i = 0; i < size; i++) { final int pos = i; final QueryParameter param = paramList.get(i); if (param.isHidden()) { components.add(null);/* ww w .ja va2 s .c o m*/ checks.add(null); initHiddenParameterValues(param); continue; } String source = param.getSource(); String defaultSource = param.getDefaultSource(); if ((defaultSource != null) && !defaultSource.trim().equals("")) { try { param.setDefaultSourceValues(Globals.getDBViewer().getDefaultSourceValues(con, param)); } catch (NextSqlException e) { Show.error(e); } } final JComponent component; int anchor = GridBagConstraints.WEST; double y = 0.0; int expand = GridBagConstraints.HORIZONTAL; if ((source != null) && !source.equals("")) { List<IdName> values = new ArrayList<IdName>(); try { if (param.isManualSource()) { if (!param.isDependent()) { values = Globals.getDBViewer().getValues(con, source, true, param.getOrderBy()); } } else { int index = source.indexOf("."); int index2 = source.lastIndexOf("."); String tableName = source.substring(0, index); String columnName; String shownColumnName = null; if (index == index2) { columnName = source.substring(index + 1); } else { columnName = source.substring(index + 1, index2); shownColumnName = source.substring(index2 + 1); } values = Globals.getDBViewer().getColumnValues(con, param.getSchema(), tableName, columnName, shownColumnName, param.getOrderBy()); } } catch (NextSqlException e) { error = true; Show.error(e); } catch (InvalidSqlException e) { String m = I18NSupport.getString("source.dialog.valid"); Show.info(m + " : \"select <exp1> , <exp2> from ...\""); } if (param.getSelection().equals(ParameterEditPanel.SINGLE_SELECTION)) { component = new JComboBox(); final JComboBox combo = (JComboBox) component; combo.setRenderer(new IdNameRenderer()); combo.addItem("-- " + I18NSupport.getString("parameter.value.select") + " --"); for (int j = 0, len = values.size(); j < len; j++) { combo.addItem(values.get(j)); } combo.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { IdName in = null; if (combo.getSelectedIndex() > 0) { in = (IdName) combo.getSelectedItem(); } parameterSelection(pos, in); } } }); AutoCompleteDecorator.decorate(combo); needScroll = false; } else { anchor = GridBagConstraints.NORTHWEST; y = 1.0; expand = GridBagConstraints.BOTH; DefaultListModel model = new DefaultListModel(); for (int j = 0, len = values.size(); j < len; j++) { model.addElement(values.get(j)); } List srcList = Arrays.asList(model.toArray()); component = new ListSelectionPanel(srcList, new ArrayList(), "", "", true, false) { protected void onAdd() { selection(); } protected void onRemove() { selection(); } // needed for saved parameters on rerun protected void onSetRight() { selection(); } private void selection() { if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) { Object[] values = getDestinationElements().toArray(); if (values.length == 0) { values = new Object[] { ParameterUtil.NULL }; } parameterSelection(pos, values); } } }; ((ListSelectionPanel) component).setListSize(scrListDim); ((ListSelectionPanel) component).setRenderer(new IdNameRenderer(), new IdNameComparator(param.getOrderBy())); shouldExpand = true; } } else { if (param.getSelection().equals(QueryParameter.MULTIPLE_SELECTION)) { anchor = GridBagConstraints.NORTHWEST; y = 1.0; expand = GridBagConstraints.BOTH; ; component = new ListAddPanel(param) { protected void onAdd() { selection(); } protected void onRemove() { selection(); } private void selection() { if (ParameterManager.getInstance().getChildDependentParameters(param).size() > 0) { Object[] values = getElements().toArray(); parameterSelection(pos, values); } } }; } else { needScroll = false; if (param.getValueClassName().equals("java.util.Date")) { component = new JXDatePicker(); ((JXDatePicker) component).addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { if ("date".equals(e.getPropertyName())) { parameterSelection(pos, ((JXDatePicker) component).getDate()); } } }); // hack to fix bug with big popup button JButton popupButton = (JButton) component.getComponent(1); //popupButton.setMargin(new Insets(2, 2, 2, 2)); popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight())); popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight())); popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY)); } else if (param.getValueClassName().equals("java.sql.Timestamp") || param.getValueClassName().equals("java.sql.Time")) { component = new JDateTimePicker() { protected void onChange() { parameterSelection(pos, getDate()); } }; // hack to fix bug with big popup button JButton popupButton = (JButton) (((JDateTimePicker) component).getDatePicker()) .getComponent(1); //popupButton.setMargin(new Insets(2, 2, 2, 2)); popupButton.setMinimumSize(new Dimension(20, (int) getPreferredSize().getHeight())); popupButton.setPreferredSize(new Dimension(20, (int) getPreferredSize().getHeight())); popupButton.setBorder(BorderFactory.createLineBorder(Color.GRAY)); } else if (param.getValueClassName().equals("java.lang.Boolean")) { component = new JCheckBox(); ((JCheckBox) component).addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { AbstractButton abstractButton = (AbstractButton) actionEvent.getSource(); boolean selected = abstractButton.getModel().isSelected(); parameterSelection(pos, selected); } }); } else { component = new JTextField(25); ((JTextField) component).getDocument().addDocumentListener(new DocumentListener() { @Override public void changedUpdate(DocumentEvent e) { updateFromTextField(e); } @Override public void insertUpdate(DocumentEvent e) { updateFromTextField(e); } @Override public void removeUpdate(DocumentEvent e) { updateFromTextField(e); } private void updateFromTextField(DocumentEvent e) { java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { Object value = null; try { if ("".equals(((JTextField) component).getText().trim())) { value = null; } else { value = ParameterUtil.getParameterValueFromString( param.getValueClassName(), ((JTextField) component).getText()); } parameterSelection(pos, value); } catch (Exception e) { e.printStackTrace(); LOG.error(e.getMessage(), e); } } }); } }); } } } components.add(component); final JCheckBox cb = new JCheckBox(I18NSupport.getString("run.parameter.ignore")); checks.add(cb); final JLabel label = new JLabel(getRuntimeParameterName(param)); panel.add(label, new GridBagConstraints(0, i, 1, 1, 0.0, 0.0, anchor, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); final JComponent addComponent; if (needScroll) { JScrollPane scr = new JScrollPane(component, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scr.setPreferredSize(listDim); addComponent = scr; } else { addComponent = component; } panel.add(addComponent, new GridBagConstraints(1, i, 1, 1, 1.0, y, GridBagConstraints.WEST, expand, new Insets(5, 0, 5, 5), 0, 0)); int checkAnchor = GridBagConstraints.WEST; if ((addComponent instanceof JScrollPane) || (addComponent instanceof ListSelectionPanel)) { checkAnchor = GridBagConstraints.NORTHWEST; } if (Globals.getParametersIgnore()) { panel.add(cb, new GridBagConstraints(2, i, 1, 1, 0.0, 0.0, checkAnchor, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0)); } cb.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (cb.isSelected()) { if (addComponent instanceof JScrollPane) { component.setEnabled(false); } label.setEnabled(false); addComponent.setEnabled(false); param.setIgnore(true); } else { if (addComponent instanceof JScrollPane) { component.setEnabled(true); } label.setEnabled(true); addComponent.setEnabled(true); param.setIgnore(false); } } }); } // populate hidden dependent parameters (this will be done if a parameter depends only on a single hidden parameter) // if a parameter depends on a hidden parameter and other parameters, it cannot be populated here for (int i = 0; i < size; i++) { final QueryParameter param = paramList.get(i); if (param.isHidden()) { populateDependentParameters(param, false); } } if (!shouldExpand) { panel.add(new JLabel(), new GridBagConstraints(0, size, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } JScrollPane scrPanel = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrPanel.setPreferredSize(scrDim); scrPanel.setMinimumSize(scrDim); add(scrPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); setParameterValues(parametersValues); setParameterIgnore(parametersIgnore); }
From source file:samples.graph.DagDemo.java
public DagDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<String, Integer>(); /* Choose one of these examples */ // graph1();//from w ww .j ava2s . co m // graph2(); graph3(); // graph4(); dagLayout = new DAGLayout<String, Integer>(graph, new Dimension(600, 600)); vv = new VisualizationViewer<String, Integer>(dagLayout, new Dimension(600, 600)); vv.setBackground(Color.white); vv.getRenderContext().setEdgeShapeTransformer(new DAGLayout.BentLine<String, Integer>(dagLayout)); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<String>()); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); vv.getRenderContext().setArrowFillPaintTransformer(new Transformer<Integer, Paint>() { public Paint transform(Integer arg) { return Color.lightGray; } }); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.TRANSFORMING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modeBox); content.add(controls, BorderLayout.SOUTH); }
From source file:se.streamsource.streamflow.client.ui.workspace.cases.general.forms.geo.GeoLocationFieldPanel.java
private JComboBox<MapType> createMapTypeSelector() { final JComboBox<MapType> mapTypeSelector = new JComboBox<MapType>(MapType.values()); mapTypeSelector.addItemListener(new ItemListener() { @Override/*from www .ja v a 2 s . c o m*/ public void itemStateChanged(ItemEvent e) { setMapType((MapType) mapTypeSelector.getSelectedItem()); } }); return mapTypeSelector; }
From source file:shuffle.fwk.service.roster.EditRosterService.java
private JPanel createRosterComponent(Species s) { JPanel ret = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; c.gridx = 1;//from w w w. j a v a 2 s. c o m c.gridy = 1; c.anchor = GridBagConstraints.CENTER; MouseAdapter ma = new PressOrClickMouseAdapter() { @Override protected void onRight(MouseEvent e) { onLeft(e); } @Override protected void onLeft(MouseEvent e) { setSelected(s, ret); selectedDisplayLabel.repaint(); } @Override protected void onEnter() { // Do nothing } }; SpeciesPaint sp = new SpeciesPaint(s, false, getMegaFilter()); ImageIcon icon = getUser().getImageManager().getImageFor(sp); JLabel iconLabel = new JLabel(icon); iconLabel.addMouseListener(ma); ret.add(iconLabel, c); c.gridy += 1; JLabel jLabel = new JLabel(s.getLocalizedName(getMegaFilter())); jLabel.setHorizontalTextPosition(SwingConstants.CENTER); jLabel.setHorizontalAlignment(SwingConstants.CENTER); jLabel.addMouseListener(ma); ret.add(jLabel, c); JComboBox<Integer> level = new JComboBox<Integer>(); for (int i = 0; i <= Species.MAX_LEVEL; i++) { level.addItem(i); } Integer thisLevel = getLevelFor(s); level.setSelectedItem(thisLevel); level.setToolTipText(getString(KEY_POKEMON_LEVEL_TOOLTIP)); c.gridy += 1; // put the level selector below the icon. ret.add(level, c); level.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { int index = level.getSelectedIndex(); myData.setLevelForSpecies(s, index); rebuildSelectedLabel(); } }); return ret; }
From source file:shuffle.fwk.service.teams.EditTeamService.java
private Component createTeamComponent(Species s) { Team curTeam = getCurrentTeam();//from w w w. j av a2s . co m JPanel ret = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 1; c.gridy = 1; c.gridwidth = 2; Indicator<SpeciesPaint> ind = new Indicator<SpeciesPaint>(this); boolean isMega = megaProgress >= megaThreshold && s.getName().equals(curTeam.getMegaSlotName()); SpeciesPaint paint = new SpeciesPaint(s, s.equals(Species.FREEZE), isMega); ind.setVisualized(paint); ret.add(ind, c); c.gridy += 1; c.gridwidth = 1; JButton removeButton = new JButton(getString(KEY_REMOVE)); removeButton.setToolTipText(getString(KEY_REMOVE_TOOLTIP)); removeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { removeSpeciesFromTeam(s.getName()); updateTeamPanel(); } }); removeButton.setEnabled( s.getEffect(getUser().getRosterManager()).isPickable() && !s.getType().equals(PkmType.NONE)); ret.add(removeButton, c); c.gridx += 1; JComboBox<Character> keybindsComboBox = new JComboBox<Character>(); Character curBinding = curTeam.getBinding(s); LinkedHashSet<Character> allBindingsFor = new LinkedHashSet<Character>(Arrays.asList(curBinding)); LinkedHashSet<Character> availableBindings = myData.getAllAvailableBindingsFor(s.getName(), curTeam); allBindingsFor.addAll(availableBindings); for (Character ch : allBindingsFor) { keybindsComboBox.addItem(ch); } keybindsComboBox.setSelectedItem(curBinding); final ItemListener bindingListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { JComboBox<?> source = (JComboBox<?>) e.getSource(); int selectedIndex = source.getSelectedIndex(); Character selected = (Character) source.getItemAt(selectedIndex); setBinding(s, selected); updateKeybindComboBoxes(); } }; nameToKeybindComboboxMap.put(s.getName(), keybindsComboBox); nameToItemListenerMap.put(s.getName(), bindingListener); keybindsComboBox.addItemListener(bindingListener); keybindsComboBox.setToolTipText(getString(KEY_KEYBINDS_TOOLTIP)); ret.add(keybindsComboBox, c); MouseAdapter ma = new PressToggleMouseAdapter() { @Override protected void onRight(MouseEvent e) { doToggle(); } @Override protected void onLeft(MouseEvent e) { doToggle(); } private void doToggle() { toggleSupport(s); updateTeamPanel(); } }; ret.addMouseListener(ma); setBorderFor(ret, false, false); if (!Species.FIXED_SPECIES.contains(s)) { boolean isSupport = !curTeam.isNonSupport(s); Color indColor = isSupport ? Color.GREEN : Color.RED; ret.setBackground(indColor); ret.setOpaque(true); } return ret; }
From source file:shuffle.fwk.service.teams.EditTeamService.java
private void updateKeybindComboBoxes() { Team curTeam = getCurrentTeam();/*w w w.j av a2 s. c o m*/ for (String name : curTeam.getNames()) { ItemListener itemListener = nameToItemListenerMap.get(name); JComboBox<Character> box = nameToKeybindComboboxMap.get(name); box.removeItemListener(itemListener); Character prevSelected = box.getItemAt(box.getSelectedIndex()); box.removeAllItems(); Character curBinding = curTeam.getBinding(name); LinkedHashSet<Character> availableBindings = new LinkedHashSet<Character>(Arrays.asList(curBinding)); availableBindings.addAll(myData.getAllAvailableBindingsFor(name, curTeam)); for (Character ch : availableBindings) { if (ch != null) { box.addItem(ch); } } box.setSelectedItem(prevSelected); if (box.getSelectedIndex() < 0) { LOG.warning(getString(KEY_NO_BINDINGS)); } box.addItemListener(itemListener); } }