List of usage examples for javax.swing JComboBox setSelectedIndex
@BeanProperty(bound = false, preferred = true, description = "The item at index is selected.") public void setSelectedIndex(int anIndex)
anIndex
. From source file:org.spiderplan.tools.visulization.GraphFrame.java
/** * @param graph/*from w ww . j av a 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.ut.biolab.medsavant.client.filter.TagFilterView.java
public TagFilterView(int queryID) { super(FILTER_NAME, queryID); setLayout(new BorderLayout()); setBorder(ViewUtil.getBigBorder());//from ww w .j a v a 2s . com 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 w w. j av a 2 s . c om*/ 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:se.cambio.cds.gdl.editor.view.panels.DescriptionPanel.java
public JPanel getAuthorshipLifeCycle() { if (authorshipLifecyclePanel == null) { authorshipLifecyclePanel = new JPanel(new SpringLayout()); authorshipLifecyclePanel//from w w w . j av a 2s. c om .add(new JLabel(GDLEditorLanguageManager.getMessage("AuthorshipLyfecycle") + ":")); JComboBox lyfeCB = new JComboBox(); //TODO Translations? lyfeCB.addItem("Not set"); lyfeCB.addItem("Initial"); lyfeCB.addItem("Author draft"); lyfeCB.addItem("Committee draft"); lyfeCB.addItem("Organisation draft"); lyfeCB.addItem("Submitted"); lyfeCB.addItem("Candidate"); lyfeCB.addItem("Approved candidate"); lyfeCB.addItem("Published"); lyfeCB.addItem("Rejected"); lyfeCB.addItem("Obsolete"); lyfeCB.setSelectedIndex(2); connect(_descriptionContext, "/lifecycleState", lyfeCB); authorshipLifecyclePanel.add(lyfeCB); authorshipLifecyclePanel.add(new JLabel(GDLEditorLanguageManager.getMessage("Copyright") + ":")); JTextField copyrightTF = new JTextField(); String lang = _controller.getCurrentGuideLanguageCode(); connect(_descriptionContext, "/details/" + lang + "/copyright", copyrightTF); authorshipLifecyclePanel.add(copyrightTF); SpringUtilities.makeCompactGrid(authorshipLifecyclePanel, 2, 2, //rows, cols 6, 6, //initX, initY 6, 6); } return authorshipLifecyclePanel; }
From source file:skoa.helpers.ConfiguracionGraficas.java
private void vistaIntermedia4() { vacia = true; //Una vez llegado aqu, ya se empieza a llenar la carpeta destino. for (int i = 0; i < datos.getComponentCount(); i++) datos.remove(i); //Borra datos.removeAll();/*w w w. j a v a 2s .co m*/ JPanel p = new JPanel(); p.setLayout(new GridLayout(3, 1)); //JLabel l=new JLabel(" Grfica "+ng+": "+"Direcciones: "+seleccionadas); //l.setFont(new Font("Tahoma",Font.BOLD,12)); p2 = new JPanel(); p2.setLayout(new GridLayout(1, 3)); l = new JLabel(" Grfica " + ng + ": " + "Direcciones: "); l.setFont(new Font("Tahoma", Font.BOLD, 12)); p2.add(l); Vector<String> AuxSeleccionadas = new Vector<String>(); AuxSeleccionadas.addAll(seleccionadas); JComboBox laux = new JComboBox(AuxSeleccionadas); laux.setEditable(false); laux.setSelectedIndex(0); laux.setFont(new Font("Tahoma", Font.ITALIC, 12)); //p2.add(lo); p2.add(laux);//para que se mantengan las anteriores al aadir nuevas. p2.add(new JPanel()); ng++; //p.add(l); p.add(p2); String l2 = " "; if (c == 1) { if (ejeDual.contentEquals("dual")) l2 = l2 + "Consulta: Evolucin temporal dual, "; else l2 = l2 + "Consulta: Evolucin temporal, "; } else if (c == 2) { if (ejeDual.contentEquals("dual")) l2 = l2 + "Consulta: Acumulacin por intervalos temporales dual, "; else l2 = l2 + "Consulta: Acumulacin por intervalos temporales, "; } else if (c == 3) l2 = l2 + "Consulta: Mx-Mn-Med por intervalos temporales, "; else if (c == 5) l2 = l2 + "Consulta: Evolucin de diferencias en %, "; else if (c == 6) l2 = l2 + "Consulta: Evolucin de diferencias, "; if (f == 1) l2 = l2 + "de un intervalo."; else if (f == 2) l2 = l2 + "completa."; l = new JLabel(l2); l.setFont(new Font("Tahoma", Font.PLAIN, 12)); p.add(l); l2 = " "; if (f == 1) { l2 = l2 + "Desde " + fini + " hasta " + ffin; if (c == 2 || c == 3) l2 = l2 + " con rango de " + rango + " horas."; if (c > 4) l2 = l2 + " con rango de " + rango + " minutos."; } if (f == 2) { if (c == 2 || c == 3) l2 = l2 + "Con rango de " + rango + " horas."; if (c > 4) l2 = l2 + "Con rango de " + rango + " minutos."; } l = new JLabel(l2); l.setFont(new Font("Tahoma", Font.PLAIN, 12)); p.add(l); mantenerVista(p); //EN ESTE PUNTO DEL CDIGO, ANTES DE RESTABLECERVALORES, INVOCAR A LAS CONSULTAS (al constructor) //PARA GENERAR LA CONSULTA CORRESPONDIENTE ANTES DE OBTENER LOS PARMETROS DE LA SIGUIENTE CONSULTA. //nh indica el hilo que se tiene que coger para la consulta actual. try { if (nh == 1) { //Los hilos en su constructor llaman start. h1 = new Consultas(H, c, f, fini, ffin, rango, direcciones, NombreCarpetaActual, dataSource); h1.start(); } else if (nh == 2) { h2 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource); h2.start(); } else if (nh == 3) { h3 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource); h3.start(); } else if (nh == 4) { h4 = new Consultas(H, c, f, fini, ffin, rango, direcciones, dataSource); h4.start(); } nh++; } catch (IOException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } consultasDuales.add(ejeDual); JPanel gen = new JPanel(); gen.setLayout(new GridLayout(2, 1)); gen.add(new JPanel()); gen.add(generar); obtenidos.add(gen); reestablecerPaneles(); cargarVista(); }
From source file:storybook.model.EntityUtil.java
@SuppressWarnings("unchecked") public static void fillEntityCombo(MainFrame mainFrame, JComboBox combo, AbstractEntityHandler entityHandler, AbstractEntity entity, boolean isNew, boolean addEmptyItem) { combo.removeAllItems();//from w ww . ja v a 2 s .co m ListCellRenderer renderer = entityHandler.getListCellRenderer(); if (renderer != null) { combo.setRenderer(renderer); } int i = 0; if (addEmptyItem) { ++i; combo.addItem(""); } BookModel model = mainFrame.getBookModel(); Session session = model.beginTransaction(); SbGenericDAOImpl<?, ?> dao = entityHandler.createDAO(); dao.setSession(session); @SuppressWarnings("unchecked") List<AbstractEntity> entities = (List<AbstractEntity>) dao.findAll(); for (AbstractEntity entity2 : entities) { session.refresh(entity2); combo.addItem(entity2); if (entity != null) { if (entity.getId().equals(entity2.getId())) // don't use combo.setSelectedItem(entity) here // leads to a "no session" exception for tag links { combo.setSelectedIndex(i); } } ++i; } combo.revalidate(); model.commit(); }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Checks whether an input (query or connect string) is already in its * associated combo box. If not, the new information is added to the combo * list/* w w w . ja va 2 s.co m*/ * * @param combo * JComboBox which has a list of the query statements or connect * strings. */ private void checkForNewString(JComboBox combo) { // String newString, foundString; Object newValue; int checkDups, matchAt; boolean match; // boolean newCommented, foundCommented; // newCommented = foundCommented = false; matchAt = -1; if (combo == querySelection) { newValue = new Query(queryText.getText(), whichModeValue()); // newString = queryText.getText(); // newString = newString.replace('\n', ' '); } else { // newString = (String)combo.getEditor().getItem(); newValue = combo.getEditor().getItem(); } // if (newString.startsWith(COMMENT_PREFIX)) { // newCommented = true; // newString = newString.substring(2); // } // if (newString.trim().length() > 0) { if (newValue.toString().length() > 0) { match = false; for (checkDups = 0; checkDups < combo.getItemCount() && !match; ++checkDups) { // if (combo == querySelection) { // foundString = ((Query)combo.getItemAt(checkDups)).getSQL(); // } else { // foundString = ((String)combo.getItemAt(checkDups)); // } // if (foundString.startsWith(COMMENT_PREFIX)) { // foundString = foundString.substring(2); // foundCommented = true; // } else { // foundCommented = false; // } // if (newString.equals(foundString)) { if (newValue.equals(combo.getItemAt(checkDups))) { match = true; if (combo == querySelection) { ((Query) combo.getItemAt(checkDups)).setMode(whichModeValue()); } combo.setSelectedIndex(checkDups); matchAt = checkDups; } } // if (newCommented) { // newString = COMMENT_PREFIX + newString; // } if (!match) { addToCombo(combo, newValue); if (combo == querySelection) { // addToCombo(combo, new Query(newString, whichModeValue())); combo.setSelectedIndex(combo.getModel().getSize() - 1); matchAt = combo.getSelectedIndex(); } } // if (foundCommented != newCommented) { // if (combo == querySelection) { // replaceInCombo(combo, matchAt, // new Query(newString, whichModeValue())); // } else { // replaceInCombo(combo, matchAt, newString); // } // } if (combo == querySelection) { if (((Query) newValue).isCommented() != ((Query) combo.getSelectedItem()).isCommented()) { replaceInCombo(combo, matchAt, newValue); } } } }
From source file:us.daveread.basicquery.BasicQuery.java
/** * Replaces an existing object with a new one * // w ww . j a v a 2 s. c om * @param combo * The JComboBox * @param position * The int value of the positon where the * repalcement occurs * @param newData * The new Object that is to be inserted in the combobox */ private void replaceInCombo(JComboBox combo, int position, Object newData) { ((DefaultComboBoxModel) combo.getModel()).removeElementAt(position); ((DefaultComboBoxModel) combo.getModel()).insertElementAt(newData, position); combo.setSelectedIndex(position); }
From source file:wigraph.ShortestPathRelation.java
private Component getSelectionBox(final boolean from) { Set<String> s = new TreeSet<String>(); for (String v : mGraph.getVertices()) { s.add(v);//from w w w . ja v a 2 s. co m } final JComboBox choices = new JComboBox(s.toArray()); choices.setSelectedIndex(-1); choices.setBackground(Color.WHITE); choices.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String v = (String) choices.getSelectedItem(); if (from) { mFrom = v; } else { mTo = v; } drawShortest(); repaint(); } }); return choices; }