List of usage examples for javax.swing JComboBox setRenderer
@BeanProperty(expert = true, description = "The renderer that paints the item selected in the list.") public void setRenderer(ListCellRenderer<? super E> aRenderer)
From source file:org.nuclos.client.ui.collect.component.AbstractCollectableComponent.java
/** * @param result// w w w. j a v a2 s. co m * @param clctcomp */ private static void addRightOperandToPopupMenu(JPopupMenu result, final AbstractCollectableComponent clctcomp) { result.addSeparator(); final ButtonGroup btngrpCompareWith = new ButtonGroup(); final SpringLocaleDelegate localeDelegate = SpringLocaleDelegate.getInstance(); final JRadioButtonMenuItem miValue = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.17", "Wertvergleich")); miValue.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.10", "Dieses Feld mit einem festen Wert vergleichen")); result.add(miValue); btngrpCompareWith.add(miValue); miValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { clctcomp.resetWithComparison(); clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } }); final JRadioButtonMenuItem miOtherField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.12", "Feldvergleich...")); miOtherField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.9", "Dieses Feld mit dem Inhalt eines anderen Felds vergleichen")); result.add(miOtherField); btngrpCompareWith.add(miOtherField); miOtherField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { assert clctcomp.clcte != null; // select entity field with the same data type: final List<CollectableEntityField> lstclctefFiltered = CollectionUtils.select( CollectableUtils.getCollectableEntityFields(clctcomp.clcte), new Predicate<CollectableEntityField>() { @Override public boolean evaluate(CollectableEntityField clctef) { return clctef.getJavaClass() == clctcomp.clctef.getJavaClass(); } }); // and sort by label: final List<CollectableEntityField> lstclctefSorted = CollectionUtils.sorted(lstclctefFiltered, new CollectableEntityField.LabelComparator()); final JComboBox cmbbx = new JComboBox(lstclctefSorted.toArray()); cmbbx.setSelectedItem(clctcomp.getComparisonOtherField()); final int iBtn = JOptionPane .showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.6", "Anderes Feld: "), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.15", "Vergleich mit anderem Feld"), JOptionPane.OK_CANCEL_OPTION); if (iBtn == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((CollectableEntityField) cmbbx.getSelectedItem()); if (clctcomp.getComparisonOtherField() != null) { // clear the view: clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { // If the user selects "other field" and forgot to set the operator, we assume "EQUAL": clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); final List<ComparisonParameter> compatibleParameters = ComparisonParameter .getCompatibleParameters(clctcomp.getEntityField()); final JRadioButtonMenuItem miParameterField = new JRadioButtonMenuItem( localeDelegate.getMessage("AbstractCollectableComponent.18", null)); miParameterField.setToolTipText(localeDelegate.getMessage("AbstractCollectableComponent.19", null)); btngrpCompareWith.add(miParameterField); if (compatibleParameters.size() > 0) { result.add(miParameterField); miParameterField.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ev) { ResourceIdMapper<ComparisonParameter> mapper = new ResourceIdMapper<ComparisonParameter>( compatibleParameters); JComboBox cmbbx = new JComboBox(CollectionUtils.sorted(compatibleParameters, mapper).toArray()); cmbbx.setRenderer(new DefaultListRenderer(mapper)); cmbbx.setSelectedItem(clctcomp.getComparisonParameter()); final int opt = JOptionPane.showConfirmDialog(clctcomp.getJComponent(), new Object[] { localeDelegate.getMessage("AbstractCollectableComponent.20", null), cmbbx }, localeDelegate.getMessage("AbstractCollectableComponent.19", null), JOptionPane.OK_CANCEL_OPTION); if (opt == JOptionPane.OK_OPTION) { clctcomp.setWithComparison((ComparisonParameter) cmbbx.getSelectedItem()); if (clctcomp.getComparisonParameter() != null) { clctcomp.updateView(CollectableUtils.getNullField(clctcomp.getEntityField())); if (clctcomp.compop.getOperandCount() < 2) { clctcomp.compop = ComparisonOperator.EQUAL; } } clctcomp.runLocked(new Runnable() { @Override public void run() { clctcomp.updateSearchConditionInModel(); } }); } } }); } result.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent ev) { if (clctcomp.getComparisonParameter() != null) { miParameterField.setSelected(true); } else if (clctcomp.getComparisonOtherField() == null || clctcomp.getComparisonOperator().getOperandCount() < 2) { miValue.setSelected(true); } else { miOtherField.setSelected(true); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent ev) { } @Override public void popupMenuCanceled(PopupMenuEvent ev) { } }); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java
/** * Populates the JComboBox with the items provided adding hover tooltips, * selecting the specified item and attaching the listener. * //from ww w. j a va 2 s.c om * @param comboBox The JComboBox to populate * @param listItems The items to populate the box with * @param select The item to select in the JComboBox * @param itemListener An item listener to add for the JComboBox */ private void displayItems(JComboBox comboBox, List<DataNode> listItems, DataNode select, ItemListener itemListener) { if (comboBox == null || listItems == null) return; //Only add the item the user can actually select if (itemListener != null) comboBox.removeItemListener(itemListener); comboBox.removeAllItems(); List<String> tooltips = new ArrayList<String>(listItems.size()); List<String> lines; ExperimenterData exp; SelectableComboBoxModel model = new SelectableComboBoxModel(); Selectable<DataNode> selected = null; GroupData group = getSelectedGroup(); ExperimenterData user = getSelectedUser(); long userID = -1; if (user != null) userID = user.getId(); ExperimenterData loggedIn = ImporterAgent.getUserDetails(); boolean isAdmin = ImporterAgent.isAdministrator(); long loggedInID = loggedIn.getId(); boolean userIsAdmin = isAdmin(userID); for (DataNode node : listItems) { exp = getExperimenter(node.getOwner()); lines = new ArrayList<String>(); if (exp != null) { lines.add("<b>Owner: </b>" + EditorUtil.formatExperimenter(exp)); } lines.addAll(UIUtilities.wrapStyleWord(node.getFullName())); tooltips.add(UIUtilities.formatToolTipText(lines)); boolean selectable = true; if (!node.isDefaultNode()) { selectable = canLink(node.getDataObject(), userID, group, loggedInID, isAdmin, userIsAdmin); } Selectable<DataNode> comboBoxItem = new Selectable<DataNode>(node, selectable); if (select != null && node.getDataObject().getId() == select.getDataObject().getId()) selected = comboBoxItem; model.addElement(comboBoxItem); } ComboBoxToolTipRenderer renderer = createComboboxRenderer(); renderer.setTooltips(tooltips); comboBox.setModel(model); comboBox.setRenderer(renderer); if (selected != null) comboBox.setSelectedItem(selected); if (itemListener != null) comboBox.addItemListener(itemListener); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.chooser.LocationDialog.java
/** * Populates the JComboBox with the user details provided, * selecting the logged in user and attaching the item listener. * //from w w w . jav a 2 s.c om * @param comboBox The JComboBox to populate * @param group The group being displayed * @param itemListener An item listener to add for the JComboBox * @param userID The id of the user. */ private void displayUsers(JComboBox comboBox, GroupData group, ItemListener itemListener, long userID) { if (comboBox == null || group == null) return; if (itemListener != null) comboBox.removeItemListener(itemListener); comboBox.removeAllItems(); DefaultComboBoxModel model = new SelectableComboBoxModel(); Selectable<ExperimenterDisplay> selected = null; List<ExperimenterData> members = sort(group.getExperimenters()); boolean canImportAs; Selectable<ExperimenterDisplay> item; List<String> tooltips = new ArrayList<String>(members.size()); List<String> lines; for (ExperimenterData user : members) { canImportAs = canImportForUserInGroup(user, group); item = new Selectable<ExperimenterDisplay>(new ExperimenterDisplay(user), canImportAs); if (user.getId() == userID) selected = item; lines = new ArrayList<String>(); lines.addAll(UIUtilities.wrapStyleWord(EditorUtil.formatExperimenter(user))); tooltips.add(UIUtilities.formatToolTipText(lines)); model.addElement(item); } ComboBoxToolTipRenderer renderer = createComboboxRenderer(); renderer.setTooltips(tooltips); comboBox.setModel(model); comboBox.setRenderer(renderer); if (selected != null) comboBox.setSelectedItem(selected); if (itemListener != null) comboBox.addItemListener(itemListener); }
From source file:org.openmicroscopy.shoola.agents.imviewer.util.proj.ProjSavingDialog.java
/** * Takes the dataNdoes and populates the combo box with the values as well * as adding a tooltip for each item//www . j a v a 2 s .c o m * * @param dataNodes the nodes used to be displayed in the combo box * @param comboBox the JComboBox that hosts the options */ private void populateAndAddTooltipsToComboBox(List<DataNode> dataNodes, JComboBox comboBox) { List<String> tooltips = new ArrayList<String>(dataNodes.size()); List<String> lines; ExperimenterData exp; for (DataNode n : dataNodes) { exp = getExperimenter(n.getOwner()); comboBox.addItem(n); lines = new ArrayList<String>(); if (exp != null) { lines.add("<b>Owner: </b>" + EditorUtil.formatExperimenter(exp)); } lines.addAll(UIUtilities.wrapStyleWord(n.getFullName())); tooltips.add(UIUtilities.formatToolTipText(lines)); } //To be modified. exp = ImViewerAgent.getUserDetails(); ComboBoxToolTipRenderer renderer = new ComboBoxToolTipRenderer(exp.getId()); comboBox.setRenderer(renderer); renderer.setTooltips(tooltips); }
From source file:org.springframework.richclient.factory.DefaultComponentFactory.java
public void configureForEnum(JComboBox comboBox, Class enumType) { Collection enumValues = getEnumResolver().getLabeledEnumSet(enumType); if (logger.isDebugEnabled()) { logger.debug("Populating combo box model with enums of type '" + enumType.getName() + "'; enums are [" + enumValues + "]"); }/*ww w. j a v a 2 s . co m*/ CompoundComparator comparator = new CompoundComparator(); comparator.addComparator(LabeledEnum.LABEL_ORDER); comparator.addComparator(new ComparableComparator()); comboBox.setModel(new ComboBoxListModel(new ArrayList(enumValues), comparator)); comboBox.setRenderer(new LabeledEnumListRenderer(messageSource)); comboBox.setEditor(new LabeledEnumComboBoxEditor(messageSource, comboBox.getEditor())); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTreeGUI() { //create a graph Graph<String, String> ig = Graphs .<String, String>synchronizedDirectedGraph(new DirectedSparseMultigraph<String, String>()); ObservableGraph<String, String> og = new ObservableGraph<String, String>(ig); og.addGraphEventListener(new GraphEventListener<String, String>() { public void handleGraphEvent(GraphEvent<String, String> evt) { System.err.println("got " + evt); }//from w w w .j av a 2s.c om }); this.g = og; //create a graphdraw layout = new FRLayout<String, String>(g); //layout = new ISOMLayout<String, String>(g); //layout = new KKLayout<String, String>(g); //layout = new CircleLayout<String, String>(g); vv = new VisualizationViewer<String, String>(layout, null); //tree2Panel.putClientProperty("defeatSystemEventQueueCheck", Boolean.TRUE); tree2Panel.setLayout(new BorderLayout()); tree2Panel.setBackground(java.awt.Color.lightGray); tree2Panel.setFont(new Font("Serif", Font.PLAIN, 12)); vv.getModel().getRelaxer().setSleepTime(500); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller()); Transformer<String, Paint> vertexColor = new Transformer<String, Paint>() { public Paint transform(String i) { if (i.equals(ComponentTreeCellRenderer.getFullTitle(sample, false))) { return Color.ORANGE; } else { return Color.PINK; } } }; Transformer<String, Paint> edgeColor = new Transformer<String, Paint>() { public Paint transform(String i) { return Color.WHITE; } }; Transformer<String, Shape> vertexShape = new Transformer<String, Shape>() { public Shape transform(String i) { if (i.equals(ComponentTreeCellRenderer.getFullTitle(sample, false))) { return new Rectangle(-150, -20, 300, 40); } else { return new Rectangle(-150, -10, 300, 20); } } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexColor); vv.getRenderContext().setEdgeDrawPaintTransformer(edgeColor); vv.getRenderContext().setVertexShapeTransformer(vertexShape); ; vv.setForeground(Color.BLACK); tree2Panel.add(vv, BorderLayout.CENTER); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.setRenderer(new JUNGModeRenderer()); 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); tree2Panel.add(controls, BorderLayout.NORTH); }
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 w w w . ja v a 2s .co 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:ro.nextreports.designer.chart.ChartPropertyPanel.java
private Property getYAxisColumnProperty(List<NameType> columns) { DefaultProperty columnProp = new DefaultProperty(); columnProp.setName(Y_COLUMN_COL);//from w ww . j a va 2s . c o m columnProp.setDisplayName(COLUMN_COL_PARAM_NAME); columnProp.setType(String.class); ComboBoxPropertyEditor columnEditor = new ComboBoxPropertyEditor(); JComboBox combo = (JComboBox) columnEditor.getCustomEditor(); combo.setRenderer(new ChartColumnListCellRenderer(columns)); List<String> names = new ArrayList<String>(); for (NameType nt : columns) { names.add(nt.getName()); } columnEditor.setAvailableValues(names.toArray(new String[names.size()])); String column = null; if ((chart.getYColumns() != null) && (chart.getYColumns().size() > 0)) { column = chart.getYColumns().get(0); } columnProp.setValue(column); columnProp.setCategory(I18NSupport.getString("property.category.chart.ycolumn")); editorRegistry.registerEditor(columnProp, columnEditor); for (int i = 2; i <= 10; i++) { columnProp.addSubProperty(getYAxisColumnProperty(getListWithSelect(columns), i)); } return columnProp; }
From source file:ro.nextreports.designer.chart.ChartPropertyPanel.java
private Property getYAxisColumnProperty(List<NameType> columns, int index) { DefaultProperty columnProp = new DefaultProperty(); columnProp.setName(Y_COLUMN_COL + "_" + index); columnProp.setDisplayName(COLUMN_COL_PARAM_NAME + " " + index); columnProp.setType(String.class); ComboBoxPropertyEditor columnEditor = new ComboBoxPropertyEditor(); JComboBox combo = (JComboBox) columnEditor.getCustomEditor(); combo.setRenderer(new ChartColumnListCellRenderer(columns)); List<String> names = new ArrayList<String>(); for (NameType nt : columns) { names.add(nt.getName());/* ww w .j a v a 2 s .co m*/ } columnEditor.setAvailableValues(names.toArray(new String[names.size()])); String column = (chart.getYColumns().size() > index - 1) ? chart.getYColumns().get(index - 1) : null; columnProp.setValue(column); columnProp.setCategory(I18NSupport.getString("property.category.chart.ycolumn")); editorRegistry.registerEditor(columnProp, columnEditor); return columnProp; }
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);/*w ww . ja v a 2 s .c om*/ 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); }