List of usage examples for javax.swing JComboBox setSelectedItem
@BeanProperty(bound = false, preferred = true, description = "Sets the selected item in the JComboBox.") public void setSelectedItem(Object anObject)
From source file:com.eviware.soapui.support.components.SimpleForm.java
public void setComponentValue(String label, String value) { JComponent component = getComponent(label); if (component instanceof JScrollPane) { component = (JComponent) ((JScrollPane) component).getViewport().getComponent(0); }// w ww . jav a2 s .c om if (component instanceof JTextComponent) { ((JTextComponent) component).setText(value); } else if (component instanceof JComboBox) { JComboBox comboBox = ((JComboBox) component); comboBox.setSelectedItem(value); } else if (component instanceof JList) { ((JList) component).setSelectedValue(value, true); } else if (component instanceof JCheckBox) { ((JCheckBox) component).setSelected(Boolean.valueOf(value)); } else if (component instanceof JFormComponent) { ((JFormComponent) component).setValue(value); } else if (component instanceof RSyntaxTextArea) { ((RSyntaxTextArea) component).setText(value); } }
From source file:com.haulmont.cuba.desktop.LoginDialog.java
protected void initLocales(JComboBox<String> localeCombo) { String currLocale = loginProperties.loadLastLocale(); if (StringUtils.isBlank(currLocale)) { currLocale = messages.getTools().localeToString(resolvedLocale); }/*from ww w. j av a 2 s . c o m*/ String selected = null; for (Map.Entry<String, Locale> entry : locales.entrySet()) { localeCombo.addItem(entry.getKey()); if (messages.getTools().localeToString(entry.getValue()).equals(currLocale)) selected = entry.getKey(); } if (selected == null) selected = locales.keySet().iterator().next(); localeCombo.setSelectedItem(selected); }
From source file:be.agiv.security.demo.Main.java
private void showPreferences() { JTabbedPane tabbedPane = new JTabbedPane(); GridBagLayout proxyGridBagLayout = new GridBagLayout(); GridBagConstraints proxyGridBagConstraints = new GridBagConstraints(); JPanel proxyPanel = new JPanel(proxyGridBagLayout) { private static final long serialVersionUID = 1L; @Override//from w ww . ja v a2s .c om public Insets getInsets() { return new Insets(10, 10, 10, 10); } }; tabbedPane.addTab("Proxy", proxyPanel); JCheckBox proxyEnableCheckBox = new JCheckBox("Enable proxy", this.proxyEnable); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy = 0; proxyGridBagConstraints.anchor = GridBagConstraints.WEST; proxyGridBagConstraints.ipadx = 5; proxyGridBagConstraints.gridwidth = GridBagConstraints.REMAINDER; proxyGridBagLayout.setConstraints(proxyEnableCheckBox, proxyGridBagConstraints); proxyPanel.add(proxyEnableCheckBox); proxyGridBagConstraints.gridwidth = 1; JLabel proxyHostLabel = new JLabel("Host:"); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy++; proxyGridBagLayout.setConstraints(proxyHostLabel, proxyGridBagConstraints); proxyPanel.add(proxyHostLabel); JTextField proxyHostTextField = new JTextField(this.proxyHost, 20); proxyGridBagConstraints.gridx++; proxyGridBagLayout.setConstraints(proxyHostTextField, proxyGridBagConstraints); proxyPanel.add(proxyHostTextField); JLabel proxyPortLabel = new JLabel("Port:"); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy++; proxyGridBagLayout.setConstraints(proxyPortLabel, proxyGridBagConstraints); proxyPanel.add(proxyPortLabel); JTextField proxyPortTextField = new JTextField(Integer.toString(this.proxyPort), 8); proxyGridBagConstraints.gridx++; proxyGridBagLayout.setConstraints(proxyPortTextField, proxyGridBagConstraints); proxyPanel.add(proxyPortTextField); JLabel proxyTypeLabel = new JLabel("Type:"); proxyGridBagConstraints.gridx = 0; proxyGridBagConstraints.gridy++; proxyGridBagLayout.setConstraints(proxyTypeLabel, proxyGridBagConstraints); proxyPanel.add(proxyTypeLabel); JComboBox proxyTypeComboBox = new JComboBox(new Object[] { Proxy.Type.HTTP, Proxy.Type.SOCKS }); proxyTypeComboBox.setSelectedItem(this.proxyType); proxyGridBagConstraints.gridx++; proxyGridBagLayout.setConstraints(proxyTypeComboBox, proxyGridBagConstraints); proxyPanel.add(proxyTypeComboBox); int dialogResult = JOptionPane.showConfirmDialog(this, tabbedPane, "Preferences", JOptionPane.OK_CANCEL_OPTION); if (dialogResult == JOptionPane.CANCEL_OPTION) { return; } this.statusBar.setStatus("Applying new preferences..."); this.proxyHost = proxyHostTextField.getText(); this.proxyPort = Integer.parseInt(proxyPortTextField.getText()); this.proxyType = (Proxy.Type) proxyTypeComboBox.getSelectedItem(); this.proxyEnable = proxyEnableCheckBox.isSelected(); }
From source file:com.brainflow.application.toplevel.Brainflow.java
private IImageDataSource specialHandling(IImageDataSource dataSource) { if (dataSource.getFileFormat().equals("Analyze7.5")) { JPanel panel = new JPanel(); JLabel messageLabel = new JLabel("Please select correct image orientation from menu: "); java.util.List<Anatomy3D> choices = Anatomy3D.getInstanceList(); JComboBox choiceBox = new JComboBox(choices.toArray()); //todo hackery alert Anatomy anatomy = dataSource.getImageInfo().getAnatomy(); choiceBox.setSelectedItem(anatomy); FormLayout layout = new FormLayout("4dlu, l:p, p:g, 4dlu", "6dlu, p, 10dlu, p, 6dlu"); CellConstraints cc = new CellConstraints(); panel.setLayout(layout);//from ww w . jav a 2s . c o m panel.add(messageLabel, cc.xyw(2, 2, 2)); panel.add(choiceBox, cc.xyw(2, 4, 2)); JOptionPane.showMessageDialog(brainFrame, panel, "Analyze 7.5 image format ...", JOptionPane.WARNING_MESSAGE); Anatomy selectedAnatomy = (Anatomy) choiceBox.getSelectedItem(); if (selectedAnatomy != anatomy) { //todo hackery alert dataSource.getImageInfo().setAnatomy((Anatomy3D) selectedAnatomy); dataSource.releaseData(); } } return dataSource; }
From source file:edu.ku.brc.specify.config.FeedBackDlg.java
@Override protected FeedBackSenderItem getFeedBackSenderItem(final Class<?> cls, final Exception exception) { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,4px,p,4px,p,4px,p,4px,f:p:g")); Vector<String> taskItems = new Vector<String>(); for (Taskable task : TaskMgr.getInstance().getAllTasks()) { taskItems.add(task.getTitle());//from w w w . ja v a2s .c o m } String[] OTHERS = { "WEBSITE", "CSTSUP", "INSTL", "DOC", "WHTPR", "HLP" }; for (String key : OTHERS) { taskItems.add(UIRegistry.getResourceString("FeedBackDlg." + key)); } Collections.sort(taskItems); final JComboBox taskCBX = createComboBox(taskItems); final JTextField subjectTF = createTextField(); final JTextField issueTF = createTextField(); final JTextArea commentsTA = createTextArea(15, 60); int y = 1; pb.add(createI18NLabel("FeedBackDlg.INFO"), cc.xyw(1, y, 4)); y += 2; pb.add(createI18NFormLabel("FeedBackDlg.SUB"), cc.xy(1, y)); pb.add(subjectTF, cc.xyw(3, y, 2)); y += 2; pb.add(createI18NFormLabel("FeedBackDlg.COMP"), cc.xy(1, y)); pb.add(taskCBX, cc.xy(3, y)); y += 2; //pb.add(createFormLabel("Question/Issue"), cc.xy(1, y)); //pb.add(issueTF, cc.xyw(3, y, 2)); y += 2; pb.add(createI18NFormLabel("FeedBackDlg.COMM"), cc.xy(1, y)); y += 2; pb.add(createScrollPane(commentsTA, true), cc.xyw(1, y, 4)); y += 2; Taskable currTask = SubPaneMgr.getInstance().getCurrentSubPane().getTask(); taskCBX.setSelectedItem(currTask != null ? currTask : TaskMgr.getDefaultTaskable()); pb.setDefaultDialogBorder(); CustomDialog dlg = new CustomDialog((Frame) null, UIRegistry.getResourceString("FeedBackDlg.TITLE"), true, pb.getPanel()); centerAndShow(dlg); if (!dlg.isCancelled()) { String taskTitle = (String) taskCBX.getSelectedItem(); if (taskTitle != null) { for (Taskable task : TaskMgr.getInstance().getAllTasks()) { if (task.getTitle().equals(taskTitle)) { taskTitle = task.getName(); } } } else { taskTitle = "No Task Name"; } FeedBackSenderItem item = new FeedBackSenderItem(taskTitle, subjectTF.getText(), issueTF.getText(), commentsTA.getText(), "", cls != null ? cls.getName() : ""); return item; } return null; }
From source file:es.emergya.ui.plugins.admin.aux1.RecursoDialog.java
public RecursoDialog(final Recurso rec, final AdminResources adminResources) { super();// w w w .j a v a 2s . co m setAlwaysOnTop(true); setSize(600, 400); setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { super.windowClosing(e); if (cambios) { int res = JOptionPane.showConfirmDialog(RecursoDialog.this, "Existen cambios sin guardar. Seguro que desea cerrar la ventana?", "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION); if (res != JOptionPane.CANCEL_OPTION) { e.getWindow().dispose(); } } else { e.getWindow().dispose(); } } }); final Recurso r = (rec == null) ? null : RecursoConsultas.get(rec.getId()); if (r != null) { setTitle(i18n.getString("Resources.summary.titleWindow") + " " + r.getIdentificador()); } else { setTitle(i18n.getString("Resources.summary.titleWindow.new")); } setIconImage(getBasicWindow().getFrame().getIconImage()); JPanel base = new JPanel(); base.setBackground(Color.WHITE); base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS)); // Icono del titulo JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING)); title.setOpaque(false); JLabel labelTitulo = null; if (r != null) { labelTitulo = new JLabel(i18n.getString("Resources.summary"), LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT); } else { labelTitulo = new JLabel(i18n.getString("Resources.cabecera.nuevo"), LogicConstants.getIcon("tittleficha_icon_recurso"), JLabel.LEFT); } labelTitulo.setFont(LogicConstants.deriveBoldFont(12f)); title.add(labelTitulo); base.add(title); // Nombre JPanel mid = new JPanel(new SpringLayout()); mid.setOpaque(false); mid.add(new JLabel(i18n.getString("Resources.name"), JLabel.RIGHT)); final JTextField name = new JTextField(25); if (r != null) { name.setText(r.getNombre()); } name.getDocument().addDocumentListener(changeListener); name.setEditable(r == null); mid.add(name); // patrullas final JLabel labelSquads = new JLabel(i18n.getString("Resources.squad"), JLabel.RIGHT); mid.add(labelSquads); List<Patrulla> pl = PatrullaConsultas.getAll(); pl.add(0, null); final JComboBox squads = new JComboBox(pl.toArray()); squads.setPrototypeDisplayValue("XXXXXXXXXXXXXXXXXXXXXXXXX"); squads.addActionListener(changeSelectionListener); squads.setOpaque(false); labelSquads.setLabelFor(squads); if (r != null) { squads.setSelectedItem(r.getPatrullas()); } else { squads.setSelectedItem(null); } squads.setEnabled((r != null && r.getHabilitado() != null) ? r.getHabilitado() : true); mid.add(squads); // // Identificador // mid.setOpaque(false); // mid.add(new JLabel(i18n.getString("Resources.identificador"), // JLabel.RIGHT)); // final JTextField identificador = new JTextField(""); // if (r != null) { // identificador.setText(r.getIdentificador()); // } // identificador.getDocument().addDocumentListener(changeListener); // identificador.setEditable(r == null); // mid.add(identificador); // Espacio en blanco // mid.add(Box.createHorizontalGlue()); // mid.add(Box.createHorizontalGlue()); // Tipo final JLabel labelTipoRecursos = new JLabel(i18n.getString("Resources.type"), JLabel.RIGHT); mid.add(labelTipoRecursos); final JComboBox types = new JComboBox(RecursoConsultas.getTipos()); labelTipoRecursos.setLabelFor(types); types.addActionListener(changeSelectionListener); if (r != null) { types.setSelectedItem(r.getTipo()); } else { types.setSelectedItem(0); } // types.setEditable(true); types.setEnabled(true); mid.add(types); // Estado Eurocop mid.add(new JLabel(i18n.getString("Resources.status"), JLabel.RIGHT)); final JTextField status = new JTextField(); if (r != null && r.getEstadoEurocop() != null) { status.setText(r.getEstadoEurocop().getIdentificador()); } status.setEditable(false); mid.add(status); // Subflota y patrulla mid.add(new JLabel(i18n.getString("Resources.subfleet"), JLabel.RIGHT)); final JComboBox subfleets = new JComboBox(FlotaConsultas.getAllHabilitadas()); subfleets.addActionListener(changeSelectionListener); if (r != null) { subfleets.setSelectedItem(r.getFlotas()); } else { subfleets.setSelectedIndex(0); } subfleets.setEnabled(true); subfleets.setOpaque(false); mid.add(subfleets); // Referencia humana mid.add(new JLabel(i18n.getString("Resources.incidences"), JLabel.RIGHT)); final JTextField rhumana = new JTextField(); // if (r != null && r.getIncidencias() != null) { // rhumana.setText(r.getIncidencias().getReferenciaHumana()); // } rhumana.setEditable(false); mid.add(rhumana); // dispositivo mid.add(new JLabel(i18n.getString("Resources.device"), JLabel.RIGHT)); final PlainDocument plainDocument = new PlainDocument() { private static final long serialVersionUID = 4929271093724956016L; @Override public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { if (this.getLength() + str.length() <= LogicConstants.LONGITUD_ISSI) { super.insertString(offs, str, a); } } }; final JTextField issi = new JTextField(plainDocument, "", LogicConstants.LONGITUD_ISSI); plainDocument.addDocumentListener(changeListener); issi.setEditable(true); mid.add(issi); mid.add(new JLabel(i18n.getString("Resources.enabled"), JLabel.RIGHT)); final JCheckBox enabled = new JCheckBox("", true); enabled.addActionListener(changeSelectionListener); enabled.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (enabled.isSelected()) { squads.setSelectedIndex(0); } squads.setEnabled(enabled.isSelected()); } }); enabled.setEnabled(true); enabled.setOpaque(false); if (r != null) { enabled.setSelected(r.getHabilitado()); } else { enabled.setSelected(true); } if (r != null && r.getDispositivo() != null) { issi.setText( StringUtils.leftPad(String.valueOf(r.getDispositivo()), LogicConstants.LONGITUD_ISSI, '0')); } mid.add(enabled); // Fecha ultimo gps mid.add(new JLabel(i18n.getString("Resources.lastPosition"), JLabel.RIGHT)); JTextField lastGPS = new JTextField(); final Date lastGPSDateForRecurso = HistoricoGPSConsultas.lastGPSDateForRecurso(r); if (lastGPSDateForRecurso != null) { lastGPS.setText(SimpleDateFormat.getDateTimeInstance().format(lastGPSDateForRecurso)); } lastGPS.setEditable(false); mid.add(lastGPS); // Espacio en blanco mid.add(Box.createHorizontalGlue()); mid.add(Box.createHorizontalGlue()); // informacion adicional JPanel infoPanel = new JPanel(new SpringLayout()); final JTextField info = new JTextField(25); info.getDocument().addDocumentListener(changeListener); infoPanel.add(new JLabel(i18n.getString("Resources.info"))); infoPanel.add(info); infoPanel.setOpaque(false); info.setOpaque(false); SpringUtilities.makeCompactGrid(infoPanel, 1, 2, 6, 6, 6, 18); if (r != null) { info.setText(r.getInfoAdicional()); } else { info.setText(""); } info.setEditable(true); // Espacio en blanco mid.add(Box.createHorizontalGlue()); mid.add(Box.createHorizontalGlue()); SpringUtilities.makeCompactGrid(mid, 5, 4, 6, 6, 6, 18); base.add(mid); base.add(infoPanel); JPanel buttons = new JPanel(); buttons.setOpaque(false); JButton accept = null; if (r == null) { accept = new JButton("Crear", LogicConstants.getIcon("button_crear")); } else { accept = new JButton("Guardar", LogicConstants.getIcon("button_save")); } accept.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { if (cambios || r == null || r.getId() == null) { boolean shithappens = true; if ((r == null || r.getId() == null)) { // Estamos // creando // uno nuevo if (RecursoConsultas.alreadyExists(name.getText())) { shithappens = false; JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.error.nombreUnico")); } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) { JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT, "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI)); shithappens = false; } else if (issi.getText() != null && issi.getText().length() > 0 && LogicConstants.isNumeric(issi.getText()) && RecursoConsultas.alreadyExists(new Integer(issi.getText()))) { shithappens = false; JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.error.dispositivoUnico")); } } if (shithappens) { if (name.getText().isEmpty()) { JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.error.nombreNulo")); } else if (issi.getText() != null && issi.getText().length() > 0 && StringUtils .trimToEmpty(issi.getText()).length() != LogicConstants.LONGITUD_ISSI) { JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString(Locale.ROOT, "admin.recursos.popup.error.faltanCifras", LogicConstants.LONGITUD_ISSI)); } else if (issi.getText() != null && issi.getText().length() > 0 && LogicConstants.isNumeric(issi.getText()) && r != null && r.getId() != null && RecursoConsultas.alreadyExists(new Integer(issi.getText()), r.getId())) { JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.error.issiUnico")); } else if (issi.getText() != null && issi.getText().length() > 0 && !LogicConstants.isNumeric(issi.getText())) { JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.error.noNumerico")); // } else if (identificador.getText().isEmpty()) // { // JOptionPane // .showMessageDialog( // RecursoDialog.this, // i18n.getString("admin.recursos.popup.error.identificadorNulo")); } else if (subfleets.getSelectedIndex() == -1) { JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.error.noSubflota")); } else if (types.getSelectedItem() == null || types.getSelectedItem().toString().trim().isEmpty()) { JOptionPane.showMessageDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.error.noTipo")); } else { int i = JOptionPane.showConfirmDialog(RecursoDialog.this, i18n.getString("admin.recursos.popup.dialogo.guardar.titulo"), i18n.getString("admin.recursos.popup.dialogo.guardar.guardar"), JOptionPane.YES_NO_CANCEL_OPTION); if (i == JOptionPane.YES_OPTION) { Recurso recurso = r; if (r == null) { recurso = new Recurso(); } recurso.setInfoAdicional(info.getText()); if (issi.getText() != null && issi.getText().length() > 0) { recurso.setDispositivo(new Integer(issi.getText())); } else { recurso.setDispositivo(null); } recurso.setFlotas(FlotaConsultas.find(subfleets.getSelectedItem().toString())); if (squads.getSelectedItem() != null && enabled.isSelected()) { recurso.setPatrullas( PatrullaConsultas.find(squads.getSelectedItem().toString())); } else { recurso.setPatrullas(null); } recurso.setNombre(name.getText()); recurso.setHabilitado(enabled.isSelected()); // recurso.setIdentificador(identificador // .getText()); recurso.setTipo(types.getSelectedItem().toString()); dispose(); RecursoAdmin.saveOrUpdate(recurso); adminResources.refresh(null); PluginEventHandler.fireChange(adminResources); } else if (i == JOptionPane.NO_OPTION) { dispose(); } } } } else { log.debug("No hay cambios"); dispose(); } } catch (Throwable t) { log.error("Error guardando un recurso", t); } } }); buttons.add(accept); JButton cancelar = new JButton("Cancelar", LogicConstants.getIcon("button_cancel")); cancelar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (cambios) { if (JOptionPane.showConfirmDialog(RecursoDialog.this, "Existen cambios sin guardar. Seguro que desea cerrar la ventana?", "Cambios sin guardar", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.CANCEL_OPTION) { dispose(); } } else { dispose(); } } }); buttons.add(cancelar); base.add(buttons); getContentPane().add(base); setLocationRelativeTo(null); cambios = false; if (r == null) { cambios = true; } pack(); int x; int y; Container myParent = getBasicWindow().getPluginContainer().getDetachedTab(0); Point topLeft = myParent.getLocationOnScreen(); Dimension parentSize = myParent.getSize(); Dimension mySize = getSize(); if (parentSize.width > mySize.width) { x = ((parentSize.width - mySize.width) / 2) + topLeft.x; } else { x = topLeft.x; } if (parentSize.height > mySize.height) { y = ((parentSize.height - mySize.height) / 2) + topLeft.y; } else { y = topLeft.y; } setLocation(x, y); cambios = false; }
From source file:com.google.code.facebook.graph.sna.applet.VertexCollapseDemoWithLayouts.java
public VertexCollapseDemoWithLayouts() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); collapsedGraph = graph;/*from www.jav a 2 s .c om*/ collapser = new GraphCollapser(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); vv = new VisualizationViewer(visualizationModel, preferredSize); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction()); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); } }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* (non-Javadoc) * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction#getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); 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()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); collapsedGraph = g; double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); exclusions.removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { layout.setGraph(graph); exclusions.clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), instructions, "Help", JOptionPane.PLAIN_MESSAGE); } }); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv)); jcb.setSelectedItem(FRLayout.class); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); controls.add(jcb); content.add(controls, BorderLayout.SOUTH); }
From source file:eu.apenet.dpt.standalone.gui.eag2012.EagIdentityPanel.java
/** * Builds and answer the editor's tab for the given layout. * @return the editor's panel//w w w . j a va 2s . c om */ protected JComponent buildEditorPanel(List<String> errors) { if (errors == null) errors = new ArrayList<String>(0); else if (Utilities.isDev && errors.size() > 0) { LOG.info("Errors in form:"); for (String error : errors) { LOG.info(error); } } FormLayout layout = new FormLayout("right:max(50dlu;p), 4dlu, 100dlu, 7dlu, right:p, 4dlu, 100dlu", EDITOR_ROW_SPEC); layout.setColumnGroups(new int[][] { { 1, 3, 5, 7 } }); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); rowNb = 1; builder.addLabel(labels.getString("eag2012.commons.countryCode") + "*", cc.xy(1, rowNb)); builder.addLabel(eag.getArchguide().getIdentity().getRepositorid().getCountrycode(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.commons.idUsedInApe"), cc.xy(5, rowNb)); builder.addLabel(eag.getControl().getRecordId().getValue(), cc.xy(7, rowNb)); setNextRow(); for (OtherRecordId otherRecordId : eag.getControl().getOtherRecordId()) { builder.addLabel(labels.getString("eag2012.control.identifierInstitution"), cc.xy(1, rowNb)); builder.addLabel(otherRecordId.getValue(), cc.xy(3, rowNb)); setNextRow(); } // name of the institution nameInstitutionTfs = new ArrayList<TextFieldWithLanguage>( eag.getArchguide().getIdentity().getAutform().size()); int loop = 0; for (Autform autform : eag.getArchguide().getIdentity().getAutform()) { TextFieldWithLanguage textFieldWithLanguage = new TextFieldWithLanguage(autform.getContent(), autform.getLang()); nameInstitutionTfs.add(textFieldWithLanguage); if (loop++ == 0) { builder.addLabel(labels.getString("eag2012.commons.nameOfInstitution") + "*", cc.xy(1, rowNb)); textFieldWithLanguage.getTextField().setEnabled(false); } else { builder.addLabel(labels.getString("eag2012.commons.nameOfInstitution"), cc.xy(1, rowNb)); } builder.add(textFieldWithLanguage.getTextField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(5, rowNb)); builder.add(textFieldWithLanguage.getLanguageBox(), cc.xy(7, rowNb)); setNextRow(); } JButton addNewNameInstitutionBtn = new ButtonTab(labels.getString("eag2012.identity.addAnotherForm")); addNewNameInstitutionBtn.addActionListener(new AddNameInstitutionAction(eag, tabbedPane, model)); builder.add(addNewNameInstitutionBtn, cc.xy(1, rowNb)); setNextRow(); parallelNameTfs = new ArrayList<TextFieldWithLanguage>( eag.getArchguide().getIdentity().getParform().size()); loop = 0; for (Parform parform : eag.getArchguide().getIdentity().getParform()) { TextFieldWithLanguage textFieldWithLanguage = new TextFieldWithLanguage(parform.getContent(), parform.getLang()); parallelNameTfs.add(textFieldWithLanguage); if (loop++ == 0 && StringUtils.isNotEmpty(textFieldWithLanguage.getTextValue())) textFieldWithLanguage.getTextField().setEnabled(false); builder.addLabel(labels.getString("eag2012.commons.parallelNameOfInstitution"), cc.xy(1, rowNb)); builder.add(textFieldWithLanguage.getTextField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(5, rowNb)); builder.add(textFieldWithLanguage.getLanguageBox(), cc.xy(7, rowNb)); setNextRow(); } JButton addNewParallelNameInstitutionBtn = new ButtonTab( labels.getString("eag2012.identity.addAnotherParallelName")); addNewParallelNameInstitutionBtn .addActionListener(new AddParallelNameInstitutionAction(eag, tabbedPane, model)); builder.add(addNewParallelNameInstitutionBtn, cc.xy(1, rowNb)); setNextRow(); formerlyUsedNameTfs = new ArrayList<FormerlyUsedName>( eag.getArchguide().getIdentity().getNonpreform().size()); for (int formerNameCounter = 0; formerNameCounter < eag.getArchguide().getIdentity().getNonpreform() .size(); formerNameCounter++) { Nonpreform nonpreform = eag.getArchguide().getIdentity().getNonpreform().get(formerNameCounter); String nameStr = ""; for (int i = 0; i < nonpreform.getContent().size(); i++) { Object object = nonpreform.getContent().get(i); if (object instanceof String) { nameStr += (String) object; } if (object instanceof UseDates) { UseDates useDates = (UseDates) object; if (useDates.getDateSet() != null) { datesForFormerlyUsedName = new ArrayList<TextFieldWithDate>( useDates.getDateSet().getDateOrDateRange().size()); for (Object object1 : useDates.getDateSet().getDateOrDateRange()) { if (object1 instanceof eu.apenet.dpt.utils.eag2012.Date) { TextFieldWithDate textFieldWithDate = new TextFieldWithDate("", "", "", "", ((eu.apenet.dpt.utils.eag2012.Date) object1).getContent()); datesForFormerlyUsedName.add(textFieldWithDate); } if (object1 instanceof DateRange) { TextFieldWithDate textFieldWithDate = new TextFieldWithDate("", "", ((DateRange) object1).getFromDate().getContent(), ((DateRange) object1).getToDate().getContent(), ""); textFieldWithDate.setDateRange(true); datesForFormerlyUsedName.add(textFieldWithDate); } } } else { datesForFormerlyUsedName = new ArrayList<TextFieldWithDate>(); if (useDates.getDate() != null) { TextFieldWithDate textFieldWithDate = new TextFieldWithDate("", "", "", "", useDates.getDate().getContent()); datesForFormerlyUsedName.add(textFieldWithDate); } if (useDates.getDateRange() != null) { TextFieldWithDate textFieldWithDate = new TextFieldWithDate("", "", useDates.getDateRange().getFromDate().getContent(), useDates.getDateRange().getToDate().getContent(), ""); textFieldWithDate.setDateRange(true); datesForFormerlyUsedName.add(textFieldWithDate); } } } } if (datesForFormerlyUsedName.isEmpty()) datesForFormerlyUsedName.add(new TextFieldWithDate("", "", "", "", "")); FormerlyUsedName formerlyUsedName = new FormerlyUsedName(nameStr, nonpreform.getLang(), datesForFormerlyUsedName); formerlyUsedName.setOrderInXmlFile(formerNameCounter); formerlyUsedNameTfs.add(formerlyUsedName); builder.addLabel(labels.getString("eag2012.identity.previousNameOfArchive"), cc.xy(1, rowNb)); builder.add(formerlyUsedName.getNameTextField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.commons.language"), cc.xy(5, rowNb)); builder.add(formerlyUsedName.getLanguageBox(), cc.xy(7, rowNb)); setNextRow(); builder.addLabel(labels.getString("eag2012.identity.yearsOfUsedName"), cc.xy(1, rowNb)); setNextRow(); for (TextFieldWithDate textFieldWithDate : datesForFormerlyUsedName) { if (!textFieldWithDate.isDateRange()) { builder.addLabel(labels.getString("eag2012.commons.year"), cc.xy(1, rowNb)); builder.add(textFieldWithDate.getDateField(), cc.xy(3, rowNb)); setNextRow(); } else { builder.addLabel(labels.getString("eag2012.commons.year") + " " + labels.getString("eag2012.commons.from"), cc.xy(1, rowNb)); builder.add(textFieldWithDate.getFromDateField(), cc.xy(3, rowNb)); builder.addLabel(labels.getString("eag2012.commons.to"), cc.xy(5, rowNb)); builder.add(textFieldWithDate.getToDateField(), cc.xy(7, rowNb)); setNextRow(); } } if (!formerlyUsedNameTfs.isEmpty()) { JButton addSingleYearBtn = new ButtonTab(labels.getString("eag2012.commons.addYearButton")); addSingleYearBtn.setName("formerName_addSingleBtn_" + formerNameCounter); addSingleYearBtn.addActionListener(new AddSingleYearAction(eag, tabbedPane, model)); builder.add(addSingleYearBtn, cc.xy(1, rowNb)); JButton addYearRangeBtn = new ButtonTab(labels.getString("eag2012.commons.addYearRangeButton")); addYearRangeBtn.setName("formerName_addYearRangeBtn_" + formerNameCounter); addYearRangeBtn.addActionListener(new AddYearRangeAction(eag, tabbedPane, model)); builder.add(addYearRangeBtn, cc.xy(3, rowNb)); setNextRow(); } } JButton addNewNonpreNameInstitutionBtn = new ButtonTab( labels.getString("eag2012.identity.addAnotherFormerlyUsedName")); addNewNonpreNameInstitutionBtn .addActionListener(new AddNonpreNameInstitutionAction(eag, tabbedPane, model)); builder.add(addNewNonpreNameInstitutionBtn, cc.xy(1, rowNb)); setNextRow(); //print repositoryType combo if (eag.getArchguide().getIdentity().getRepositoryType() != null && !eag.getArchguide().getIdentity().getRepositoryType().isEmpty()) { for (RepositoryType repoType : eag.getArchguide().getIdentity().getRepositoryType()) { builder.addLabel(labels.getString("eag2012.identity.selectType"), cc.xy(1, rowNb)); JComboBox comboBox = new JComboBox(typeInstitution); if (repoType.getValue() != null && !repoType.getValue().isEmpty()) { comboBox.setSelectedItem(repoType.getValue()); } else { comboBox.setSelectedItem("---"); } typeInstitutionComboList.add(comboBox); builder.add(comboBox, cc.xy(3, rowNb)); setNextRow(); } } else { builder.addLabel(labels.getString("eag2012.identity.selectType"), cc.xy(1, rowNb)); JComboBox comboBox = new JComboBox(typeInstitution); comboBox.setSelectedItem("---"); typeInstitutionComboList.add(comboBox); builder.add(comboBox, cc.xy(3, rowNb)); setNextRow(); } //add another repositoryType button JButton addNewTypeOfTheInstitution = new ButtonTab( labels.getString("eag2012.identity.addAnotherRepositoryType")); addNewTypeOfTheInstitution.addActionListener(new AddRepositoryTypeAction(eag, tabbedPane, model)); builder.add(addNewTypeOfTheInstitution, cc.xy(1, rowNb)); setNextRow(); builder.addSeparator("", cc.xyw(1, rowNb, 7)); setNextRow(); JButton exitBtn = new ButtonTab(labels.getString("eag2012.commons.exit")); builder.add(exitBtn, cc.xy(1, rowNb)); exitBtn.addActionListener(new ExitBtnAction(eag, tabbedPane, model)); JButton previousTabBtn = new ButtonTab(labels.getString("eag2012.commons.previousTab")); builder.add(previousTabBtn, cc.xy(3, rowNb)); previousTabBtn.addActionListener(new ChangeTabBtnAction(eag, tabbedPane, model, false)); JButton nextTabBtn = new ButtonTab(labels.getString("eag2012.commons.nextTab")); builder.add(nextTabBtn, cc.xy(5, rowNb)); nextTabBtn.addActionListener(new ChangeTabBtnAction(eag, tabbedPane, model, true)); setNextRow(); JButton saveBtn = new ButtonTab(labels.getString("eag2012.commons.save")); builder.add(saveBtn, cc.xy(5, rowNb)); saveBtn.addActionListener(new SaveBtnAction(eag, tabbedPane, model)); setNextRow(); builder.addSeparator("", cc.xyw(1, rowNb, 7)); setNextRow(); JButton nextInstitutionTabBtn = new ButtonTab(labels.getString("eag2012.controls.nextInstitution")); nextInstitutionTabBtn.addActionListener(new NextInstitutionTabBtnAction(eag, tabbedPane, model)); builder.add(nextInstitutionTabBtn, cc.xy(5, rowNb)); // Define the change tab listener. this.removeChangeListener(); this.tabbedPane.addChangeListener(new ChangeTabListener(this.eag, this.tabbedPane, this.model, 1)); JPanel panel = builder.getPanel(); KeyboardFocusManager.getCurrentKeyboardFocusManager() .addPropertyChangeListener(new FocusManagerListener(panel)); return panel; }
From source file:projects.wdlf47tuc.ProcessAllSwathcal.java
/** * Main entry point./* w w w .ja v a2 s . c om*/ * * @param args * * @throws IOException * */ public ProcessAllSwathcal() { // Path to AllSwathcal.dat file File allSwathcal = new File( "/home/nrowell/Astronomy/Data/47_Tuc/Kalirai_2012/UVIS/www.stsci.edu/~jkalirai/47Tuc/AllSwathcal.dat"); // Read file contents into the List try (BufferedReader in = new BufferedReader(new FileReader(allSwathcal))) { String sourceStr; while ((sourceStr = in.readLine()) != null) { Source source = Source.parseSource(sourceStr); if (source != null) { allSources.add(source); } } } catch (IOException e) { } logger.info("Parsed " + allSources.size() + " Sources from AllSwathcal.dat"); // Initialise chart cmdPanel = new ChartPanel(updateDataAndPlotCmd(allSources)); cmdPanel.addChartMouseListener(new ChartMouseListener() { @Override public void chartMouseClicked(ChartMouseEvent e) { // Capture mouse click location, transform to graph coordinates and add // a point to the polygonal selection box. Point2D p = cmdPanel.translateScreenToJava2D(e.getTrigger().getPoint()); Rectangle2D plotArea = cmdPanel.getScreenDataArea(); XYPlot plot = (XYPlot) cmdPanel.getChart().getPlot(); double chartX = plot.getDomainAxis().java2DToValue(p.getX(), plotArea, plot.getDomainAxisEdge()); double chartY = plot.getRangeAxis().java2DToValue(p.getY(), plotArea, plot.getRangeAxisEdge()); points.add(new double[] { chartX, chartY }); cmdPanel.setChart(plotCmd()); } @Override public void chartMouseMoved(ChartMouseEvent arg0) { } }); // Create colour combo boxes final JComboBox<Filter> magComboBox = new JComboBox<Filter>(filters); final JComboBox<Filter> col1ComboBox = new JComboBox<Filter>(filters); final JComboBox<Filter> col2ComboBox = new JComboBox<Filter>(filters); // Set initial values magComboBox.setSelectedItem(magFilter); col1ComboBox.setSelectedItem(col1Filter); col2ComboBox.setSelectedItem(col2Filter); // Create an action listener for these ActionListener al = new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { if (evt.getSource() == magComboBox) { magFilter = (Filter) magComboBox.getSelectedItem(); } if (evt.getSource() == col1ComboBox) { col1Filter = (Filter) col1ComboBox.getSelectedItem(); } if (evt.getSource() == col2ComboBox) { col2Filter = (Filter) col2ComboBox.getSelectedItem(); } // Changed colour(s), so reset selection box coordinates points.clear(); cmdPanel.setChart(updateDataAndPlotCmd(allSources)); } }; magComboBox.addActionListener(al); col1ComboBox.addActionListener(al); col2ComboBox.addActionListener(al); // Add a bit of padding to space things out magComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); col1ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); col2ComboBox.setBorder(new EmptyBorder(5, 5, 5, 5)); // Set up statistic sliders final JSlider magErrMaxSlider = GuiUtil.buildSlider(magErrorRangeMin, magErrorRangeMax, 3, "%3.3f"); final JSlider chi2MaxSlider = GuiUtil.buildSlider(chi2RangeMin, chi2RangeMax, 3, "%3.3f"); final JSlider sharpMinSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f"); final JSlider sharpMaxSlider = GuiUtil.buildSlider(sharpRangeMin, sharpRangeMax, 3, "%3.3f"); // Set intial values magErrMaxSlider.setValue( (int) Math.rint(100.0 * (magErrMax - magErrorRangeMin) / (magErrorRangeMax - magErrorRangeMin))); chi2MaxSlider.setValue((int) Math.rint(100.0 * (chi2Max - chi2RangeMin) / (chi2RangeMax - chi2RangeMin))); sharpMinSlider .setValue((int) Math.rint(100.0 * (sharpMin - sharpRangeMin) / (sharpRangeMax - sharpRangeMin))); sharpMaxSlider .setValue((int) Math.rint(100.0 * (sharpMax - sharpRangeMin) / (sharpRangeMax - sharpRangeMin))); // Set labels & initial values final JLabel magErrMaxLabel = new JLabel(getMagErrMaxLabel()); final JLabel chi2MaxLabel = new JLabel(getChi2MaxLabel()); final JLabel sharpMinLabel = new JLabel(getSharpMinLabel()); final JLabel sharpMaxLabel = new JLabel(getSharpMaxLabel()); // Create a change listener fot these ChangeListener cl = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider source = (JSlider) e.getSource(); if (source == magErrMaxSlider) { // Compute max mag error from slider position double newMagErrMax = magErrorRangeMin + (magErrorRangeMax - magErrorRangeMin) * (source.getValue() / 100.0); magErrMax = newMagErrMax; magErrMaxLabel.setText(getMagErrMaxLabel()); } if (source == chi2MaxSlider) { // Compute Chi2 max from slider position double newChi2Max = chi2RangeMin + (chi2RangeMax - chi2RangeMin) * (source.getValue() / 100.0); chi2Max = newChi2Max; chi2MaxLabel.setText(getChi2MaxLabel()); } if (source == sharpMinSlider) { // Compute sharp min from slider position double newSharpMin = sharpRangeMin + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0); sharpMin = newSharpMin; sharpMinLabel.setText(getSharpMinLabel()); } if (source == sharpMaxSlider) { // Compute sharp max from slider position double newSharpMax = sharpRangeMin + (sharpRangeMax - sharpRangeMin) * (source.getValue() / 100.0); sharpMax = newSharpMax; sharpMaxLabel.setText(getSharpMaxLabel()); } cmdPanel.setChart(updateDataAndPlotCmd(allSources)); } }; magErrMaxSlider.addChangeListener(cl); chi2MaxSlider.addChangeListener(cl); sharpMinSlider.addChangeListener(cl); sharpMaxSlider.addChangeListener(cl); // Add a bit of padding to space things out magErrMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); chi2MaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); sharpMinSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); sharpMaxSlider.setBorder(new EmptyBorder(5, 5, 5, 5)); // Text field to store distance modulus final JTextField distanceModulusField = new JTextField(Double.toString(mu)); distanceModulusField.setBorder(new EmptyBorder(5, 5, 5, 5)); Border compound = BorderFactory.createCompoundBorder(new LineBorder(this.getBackground(), 5), BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); final JButton lfButton = new JButton("Luminosity function for selection"); lfButton.setBorder(compound); lfButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Read distance modulus field try { double mu_new = Double.parseDouble(distanceModulusField.getText()); mu = mu_new; } catch (NullPointerException | NumberFormatException ex) { JOptionPane.showMessageDialog(lfButton, "Error parsing the distance modulus: " + ex.getMessage(), "Distance Modulus Error", JOptionPane.ERROR_MESSAGE); return; } if (boxedSources.isEmpty()) { JOptionPane.showMessageDialog(lfButton, "No sources are currently selected!", "Selection Error", JOptionPane.ERROR_MESSAGE); } else { computeAndPlotLuminosityFunction(boxedSources); } } }); final JButton clearSelectionButton = new JButton("Clear selection"); clearSelectionButton.setBorder(compound); clearSelectionButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { points.clear(); cmdPanel.setChart(plotCmd()); } }); JPanel controls = new JPanel(new GridLayout(9, 2)); controls.setBorder(new EmptyBorder(10, 10, 10, 10)); controls.add(new JLabel("Magnitude = ")); controls.add(magComboBox); controls.add(new JLabel("Colour 1 = ")); controls.add(col1ComboBox); controls.add(new JLabel("Colour 2 = ")); controls.add(col2ComboBox); controls.add(magErrMaxLabel); controls.add(magErrMaxSlider); controls.add(chi2MaxLabel); controls.add(chi2MaxSlider); controls.add(sharpMinLabel); controls.add(sharpMinSlider); controls.add(sharpMaxLabel); controls.add(sharpMaxSlider); controls.add(new JLabel("Adopted distance modulus = ")); controls.add(distanceModulusField); controls.add(lfButton); controls.add(clearSelectionButton); this.setLayout(new BorderLayout()); this.add(cmdPanel, BorderLayout.CENTER); this.add(controls, BorderLayout.SOUTH); this.validate(); }
From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.graph.CollapsableGraphView.java
public CollapsableGraphView(Graph graph, boolean val) throws HeadlessException { super();//from ww w. ja v a 2 s . c om setGraph(graph); layout = new FRLayout(graph); Dimension preferredSize = new Dimension(400, 400); final VisualizationModel visualizationModel = new DefaultVisualizationModel(layout, preferredSize); VisualizationViewer vv = new VisualizationViewer(visualizationModel, preferredSize); vv.addGraphMouseListener(new CollapsableGraphMouseListener<Number>()); vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeTransformer()); PickedState<Integer> picked_state = vv.getPickedVertexState(); // create decorators vv.getRenderContext().setVertexFillPaintTransformer(IB_TransformerFactory.getDefaultPaintTransformer(vv)); setVisViewer(vv); final PredicatedParallelEdgeIndexFunction eif = PredicatedParallelEdgeIndexFunction.getInstance(); final Set exclusions = new HashSet(); eif.setPredicate(new Predicate() { public boolean evaluate(Object e) { return exclusions.contains(e); } }); vv.getRenderContext().setParallelEdgeIndexFunction(eif); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller() { /* * (non-Javadoc) * * @see edu.uci.ics.jung.visualization.decorators.DefaultToolTipFunction# * getToolTipText(java.lang.Object) */ @Override public String transform(Object v) { if (v instanceof Graph) { return ((Graph) v).getVertices().toString(); } return super.transform(v); } }); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(graphMouse.getModeListener()); graphMouse.setMode(ModalGraphMouse.Mode.PICKING); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JButton collapse = new JButton("Collapse"); collapse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Collapsing the graph"); // Pick all port zeros, and their IMMEDIATE links // PickManager.getInstance().pickAllSwitches(vv); VisualizationViewer vv = getVisViewer(); Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); if (picked.size() > 1) { System.out.println("CGV: The number picked is: " + picked.size()); Graph inGraph = layout.getGraph(); Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); Graph g = collapser.collapse(layout.getGraph(), clusterGraph); collapsedGraph = g; double sumx = 0; double sumy = 0; for (Object v : picked) { Point2D p = (Point2D) layout.transform(v); sumx += p.getX(); sumy += p.getY(); } Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / picked.size()); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); layout.setLocation(clusterGraph, cp); vv.getPickedVertexState().clear(); vv.repaint(); } // Collection picked = new // HashSet(vv.getPickedVertexState().getPicked()); // if (picked.size() > 1) // { // Graph inGraph = layout.getGraph(); // Graph clusterGraph = collapser.getClusterGraph(inGraph, picked); // // Graph g = collapser.collapse(layout.getGraph(), clusterGraph); // collapsedGraph = g; // double sumx = 0; // double sumy = 0; // for (Object v : picked) // { // Point2D p = (Point2D) layout.transform(v); // sumx += p.getX(); // sumy += p.getY(); // } // Point2D cp = new Point2D.Double(sumx / picked.size(), sumy / // picked.size()); // vv.getRenderContext().getParallelEdgeIndexFunction().reset(); // layout.setGraph(g); // layout.setLocation(clusterGraph, cp); // vv.getPickedVertexState().clear(); // vv.repaint(); // } } }); JButton compressEdges = new JButton("Compress Edges"); compressEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); getExclusions().addAll(edges); vv.repaint(); } } }); JButton expandEdges = new JButton("Expand Edges"); expandEdges.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Collection picked = vv.getPickedVertexState().getPicked(); if (picked.size() == 2) { Pair pair = new Pair(picked); Graph graph = layout.getGraph(); Collection edges = new HashSet(graph.getIncidentEdges(pair.getFirst())); edges.retainAll(graph.getIncidentEdges(pair.getSecond())); getExclusions().removeAll(edges); vv.repaint(); } } }); JButton expand = new JButton("Expand"); expand.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Collection picked = new HashSet(vv.getPickedVertexState().getPicked()); for (Object v : picked) { if (v instanceof Graph) { Graph g = collapser.expand(layout.getGraph(), (Graph) v); vv.getRenderContext().getParallelEdgeIndexFunction().reset(); layout.setGraph(g); } vv.getPickedVertexState().clear(); vv.repaint(); } } }); JButton reset = new JButton("Reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { VisualizationViewer vv = getVisViewer(); Graph g = getGraph(); layout.setGraph(g); getExclusions().clear(); vv.repaint(); } }); JButton help = new JButton("Help"); help.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog((JComponent) e.getSource(), getInstructions(), "Help", JOptionPane.PLAIN_MESSAGE); } }); Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String valueString = value.toString(); valueString = valueString.substring(valueString.lastIndexOf('.') + 1); return super.getListCellRendererComponent(list, valueString, index, isSelected, cellHasFocus); } }); jcb.addActionListener(new LayoutChooser(jcb, vv, this)); jcb.setSelectedItem(FRLayout.class); JPanel controls = new JPanel(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); zoomControls.add(plus); zoomControls.add(minus); controls.add(zoomControls); JPanel collapseControls = new JPanel(new GridLayout(3, 1)); collapseControls.setBorder(BorderFactory.createTitledBorder("Picked")); collapseControls.add(collapse); collapseControls.add(expand); collapseControls.add(compressEdges); collapseControls.add(expandEdges); collapseControls.add(reset); controls.add(collapseControls); controls.add(modeBox); controls.add(help); controls.add(jcb); content.add(controls, BorderLayout.SOUTH); }