List of usage examples for javax.swing JComboBox addActionListener
public void addActionListener(ActionListener l)
ActionListener
. From source file:com.declarativa.interprolog.gui.ListenerWindow.java
private void graphComponents() throws IOException { Forest<String, Integer> forest = new DelegateForest<>(); Forest<String, Integer> forest2 = new DelegateForest<>(); Forest<String, Integer> forest3 = new DelegateForest<>(); //ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest)); ObservableGraph g = new ObservableGraph(new GraphGenerator().createTree(forest)); ObservableGraph g2 = new ObservableGraph(new GraphGenerator().createTree2(forest2)); ObservableGraph g3 = new ObservableGraph(new GraphGenerator().createTree3(forest3)); //Layout layout = new BalloonLayout(forest); Layout layout = new BalloonLayout(forest); Layout layout2 = new BalloonLayout(forest2); Layout layout3 = new TreeLayout(forest3, 70, 70); final BaseJungScene scene = new SceneImpl(g, layout); final BaseJungScene scene2 = new SceneImpl(g2, layout2); final BaseJungScene scene3 = new SceneImpl(g3, layout3); jLayeredPane1.setLayout(new BorderLayout()); //jf.setLayout(new BorderLayout()); jLayeredPane5.setLayout(new BorderLayout()); jLayeredPane8.setLayout(new BorderLayout()); jLayeredPane1.add(new JScrollPane(scene.createView()), BorderLayout.CENTER); //jf.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER); jLayeredPane5.add(new JScrollPane(scene2.createView()), BorderLayout.CENTER); jLayeredPane8.add(new JScrollPane(scene3.createView()), BorderLayout.CENTER); JToolBar bar = new JToolBar(); bar.setMargin(new Insets(5, 5, 5, 5)); bar.setLayout(new FlowLayout(5)); DefaultComboBoxModel<Layout> mdl = new DefaultComboBoxModel<>(); mdl.addElement(new KKLayout(g)); mdl.addElement(layout);//from w ww . j a va2 s . co m mdl.addElement(new BalloonLayout(forest)); mdl.addElement(new RadialTreeLayout(forest)); mdl.addElement(new CircleLayout(g)); mdl.addElement(new FRLayout(g)); mdl.addElement(new FRLayout2(g)); mdl.addElement(new ISOMLayout(g)); mdl.addElement(new edu.uci.ics.jung.algorithms.layout.SpringLayout(g)); mdl.addElement(new SpringLayout2(g)); mdl.addElement(new DAGLayout(g)); mdl.addElement(new XLayout(g)); mdl.setSelectedItem(layout); final JCheckBox checkbox = new JCheckBox("Animate iterative layouts"); scene.setLayoutAnimationFramesPerSecond(48); scene2.setLayoutAnimationFramesPerSecond(48); scene3.setLayoutAnimationFramesPerSecond(48); final JComboBox<Layout> layouts = new JComboBox(mdl); layouts.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln, boolean bln1) { o = o.getClass().getSimpleName(); return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates. } }); bar.add(new JLabel(" Layout Type")); bar.add(layouts); layouts.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Layout layout = (Layout) layouts.getSelectedItem(); // These two layouts implement IterativeContext, but they do // not evolve toward anything, they just randomly rearrange // themselves. So disable animation for these. if (layout instanceof ISOMLayout || layout instanceof DAGLayout) { checkbox.setSelected(false); } scene.setGraphLayout(layout, true); } }); bar.add(new JLabel(" Connection Shape")); DefaultComboBoxModel<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapes = new DefaultComboBoxModel<>(); shapes.addElement(new EdgeShape.QuadCurve<String, Number>()); shapes.addElement(new EdgeShape.BentLine<String, Number>()); shapes.addElement(new EdgeShape.CubicCurve<String, Number>()); shapes.addElement(new EdgeShape.Line<String, Number>()); shapes.addElement(new EdgeShape.Box<String, Number>()); shapes.addElement(new EdgeShape.Orthogonal<String, Number>()); shapes.addElement(new EdgeShape.Wedge<String, Number>(10)); final JComboBox<Transformer<Context<Graph<String, Number>, Number>, Shape>> shapesBox = new JComboBox<>( shapes); shapesBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { Transformer<Context<Graph<String, Number>, Number>, Shape> xform = (Transformer<Context<Graph<String, Number>, Number>, Shape>) shapesBox .getSelectedItem(); scene.setConnectionEdgeShape(xform); } }); shapesBox.setRenderer(new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList<?> jlist, Object o, int i, boolean bln, boolean bln1) { o = o.getClass().getSimpleName(); return super.getListCellRendererComponent(jlist, o, i, bln, bln1); //To change body of generated methods, choose Tools | Templates. } }); shapesBox.setSelectedItem(new EdgeShape.QuadCurve<>()); bar.add(shapesBox); //jf.add(bar, BorderLayout.NORTH); bar.add(new ListenerWindow.MinSizePanel(scene.createSatelliteView())); bar.setFloatable(false); bar.setRollover(true); final JLabel selectionLabel = new JLabel("<html> </html>"); System.out.println("LOOKUP IS " + scene.getLookup()); Lookup.Result<String> selectedNodes = scene.getLookup().lookupResult(String.class); LookupListener listener = new LookupListener() { @Override public void resultChanged(LookupEvent le) { System.out.println("RES CHANGED"); Lookup.Result<String> res = (Lookup.Result<String>) le.getSource(); StringBuilder sb = new StringBuilder("<html>"); List<String> l = new ArrayList<>(res.allInstances()); Collections.sort(l); for (String s : l) { if (sb.length() != 0) { sb.append(", "); } sb.append(s); } sb.append("</html>"); selectionLabel.setText(sb.toString()); System.out.println("LOOKUP EVENT " + sb); } }; selectedNodes.addLookupListener(listener); selectedNodes.allInstances(); bar.add(selectionLabel); checkbox.setSelected(true); checkbox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { scene.setAnimateIterativeLayouts(checkbox.isSelected()); } }); bar.add(checkbox); jLayeredPane3.setLayout(new BorderLayout()); jLayeredPane6.setLayout(new BorderLayout()); jLayeredPane3.add(bar); jLayeredPane6.add(bar); // jf.setSize(jf.getGraphicsConfiguration().getBounds().width - 120, 700); // jf.setSize(new Dimension(1280, 720)); // jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { @Override public void windowOpened(WindowEvent we) { scene.relayout(true); scene.validate(); scene2.relayout(true); scene2.validate(); scene3.relayout(true); scene3.validate(); } }); }
From source file:com.nikonhacker.gui.EmulatorUI.java
private void openChipOptionsDialog(final int chip) { // ------------------------ Disassembly options JPanel disassemblyOptionsPanel = new JPanel(new MigLayout("", "[left,grow][left,grow]")); // Prepare sample code area final RSyntaxTextArea listingArea = new RSyntaxTextArea(20, 90); SourceCodeFrame.prepareAreaFormat(chip, listingArea); final List<JCheckBox> outputOptionsCheckBoxes = new ArrayList<JCheckBox>(); ActionListener areaRefresherListener = new ActionListener() { public void actionPerformed(ActionEvent e) { try { Set<OutputOption> sampleOptions = EnumSet.noneOf(OutputOption.class); dumpOptionCheckboxes(outputOptionsCheckBoxes, sampleOptions); int baseAddress = framework.getPlatform(chip).getCpuState().getResetAddress(); int lastAddress = baseAddress; Memory sampleMemory = new DebuggableMemory(false); sampleMemory.map(baseAddress, 0x100, true, true, true); StringWriter writer = new StringWriter(); Disassembler disassembler; if (chip == Constants.CHIP_FR) { sampleMemory.store16(lastAddress, 0x1781); // PUSH RP lastAddress += 2;//from w ww . ja v a 2 s .c om sampleMemory.store16(lastAddress, 0x8FFE); // PUSH (FP,AC,R12,R11,R10,R9,R8) lastAddress += 2; sampleMemory.store16(lastAddress, 0x83EF); // ANDCCR #0xEF lastAddress += 2; sampleMemory.store16(lastAddress, 0x9F80); // LDI:32 #0x68000000,R0 lastAddress += 2; sampleMemory.store16(lastAddress, 0x6800); lastAddress += 2; sampleMemory.store16(lastAddress, 0x0000); lastAddress += 2; sampleMemory.store16(lastAddress, 0x2031); // LD @(FP,0x00C),R1 lastAddress += 2; sampleMemory.store16(lastAddress, 0xB581); // LSL #24,R1 lastAddress += 2; sampleMemory.store16(lastAddress, 0x1A40); // DMOVB R13,@0x40 lastAddress += 2; sampleMemory.store16(lastAddress, 0x9310); // ORCCR #0x10 lastAddress += 2; sampleMemory.store16(lastAddress, 0x8D7F); // POP (R8,R9,R10,R11,R12,AC,FP) lastAddress += 2; sampleMemory.store16(lastAddress, 0x0781); // POP RP lastAddress += 2; disassembler = new Dfr(); disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore disassembler.setOutputFileName(null); disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8) + "=CODE" }); } else { sampleMemory.store32(lastAddress, 0x340B0001); // li $t3, 0x0001 lastAddress += 4; sampleMemory.store32(lastAddress, 0x17600006); // bnez $k1, 0xBFC00020 lastAddress += 4; sampleMemory.store32(lastAddress, 0x00000000); // nop lastAddress += 4; sampleMemory.store32(lastAddress, 0x54400006); // bnezl $t4, 0xBFC00028 lastAddress += 4; sampleMemory.store32(lastAddress, 0x3C0C0000); // ?lui $t4, 0x0000 lastAddress += 4; int baseAddress16 = lastAddress; int lastAddress16 = baseAddress16; sampleMemory.store32(lastAddress16, 0xF70064F6); // save $ra,$s0,$s1,$s2-$s7,$fp, 0x30 lastAddress16 += 4; sampleMemory.store16(lastAddress16, 0x6500); // nop lastAddress16 += 2; sampleMemory.store32(lastAddress16, 0xF7006476); // restore $ra,$s0,$s1,$s2-$s7,$fp, 0x30 lastAddress16 += 4; sampleMemory.store16(lastAddress16, 0xE8A0); // ret lastAddress16 += 2; disassembler = new Dtx(); disassembler.setDebugPrintWriter(new PrintWriter(new StringWriter())); // Ignore disassembler.setOutputFileName(null); disassembler.processOptions(new String[] { "-m", "0x" + Format.asHex(baseAddress, 8) + "-0x" + Format.asHex(lastAddress, 8) + "=CODE:32", "-m", "0x" + Format.asHex(baseAddress16, 8) + "-0x" + Format.asHex(lastAddress16, 8) + "=CODE:16" }); } disassembler.setOutputOptions(sampleOptions); disassembler.setMemory(sampleMemory); disassembler.initialize(); disassembler.setOutWriter(writer); disassembler.disassembleMemRanges(); disassembler.cleanup(); listingArea.setText(""); listingArea.append(writer.toString()); listingArea.setCaretPosition(0); } catch (Exception ex) { ex.printStackTrace(); } } }; int i = 1; for (OutputOption outputOption : OutputOption.allFormatOptions) { JCheckBox checkBox = makeOutputOptionCheckBox(chip, outputOption, prefs.getOutputOptions(chip), false); if (checkBox != null) { outputOptionsCheckBoxes.add(checkBox); disassemblyOptionsPanel.add(checkBox, (i % 2 == 0) ? "wrap" : ""); checkBox.addActionListener(areaRefresherListener); i++; } } if (i % 2 == 0) { disassemblyOptionsPanel.add(new JLabel(), "wrap"); } // Force a refresh areaRefresherListener.actionPerformed(new ActionEvent(outputOptionsCheckBoxes.get(0), 0, "")); // disassemblyOptionsPanel.add(new JLabel("Sample output:", SwingConstants.LEADING), "gapbottom 1, span, split 2, aligny center"); // disassemblyOptionsPanel.add(new JSeparator(), "span 2,wrap"); disassemblyOptionsPanel.add(new JSeparator(), "span 2, gapleft rel, growx, wrap"); disassemblyOptionsPanel.add(new JLabel("Sample output:"), "span 2,wrap"); disassemblyOptionsPanel.add(new JScrollPane(listingArea), "span 2,wrap"); disassemblyOptionsPanel.add(new JLabel("Tip: hover over the option checkboxes for help"), "span 2, center, wrap"); // ------------------------ Emulation options JPanel emulationOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); emulationOptionsPanel.add(new JLabel()); JLabel warningLabel = new JLabel( "NOTE: these options only take effect after reloading the firmware (or performing a 'Stop and reset')"); warningLabel.setBackground(Color.RED); warningLabel.setOpaque(true); warningLabel.setForeground(Color.WHITE); warningLabel.setHorizontalAlignment(SwingConstants.CENTER); emulationOptionsPanel.add(warningLabel); emulationOptionsPanel.add(new JLabel()); final JCheckBox writeProtectFirmwareCheckBox = new JCheckBox("Write-protect firmware"); writeProtectFirmwareCheckBox.setSelected(prefs.isFirmwareWriteProtected(chip)); emulationOptionsPanel.add(writeProtectFirmwareCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, any attempt to write to the loaded firmware area will result in an Emulator error. This can help trap spurious writes")); final JCheckBox dmaSynchronousCheckBox = new JCheckBox("Make DMA synchronous"); dmaSynchronousCheckBox.setSelected(prefs.isDmaSynchronous(chip)); emulationOptionsPanel.add(dmaSynchronousCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, DMA operations will be performed immediately, pausing the CPU. Otherwise they are performed in a separate thread.")); final JCheckBox autoEnableTimersCheckBox = new JCheckBox("Auto enable timers"); autoEnableTimersCheckBox.setSelected(prefs.isAutoEnableTimers(chip)); emulationOptionsPanel.add(autoEnableTimersCheckBox); emulationOptionsPanel .add(new JLabel("If checked, timers will be automatically enabled upon reset or firmware load.")); // Log memory messages final JCheckBox logMemoryMessagesCheckBox = new JCheckBox("Log memory messages"); logMemoryMessagesCheckBox.setSelected(prefs.isLogMemoryMessages(chip)); emulationOptionsPanel.add(logMemoryMessagesCheckBox); emulationOptionsPanel .add(new JLabel("If checked, messages related to memory will be logged to the console.")); // Log serial messages final JCheckBox logSerialMessagesCheckBox = new JCheckBox("Log serial messages"); logSerialMessagesCheckBox.setSelected(prefs.isLogSerialMessages(chip)); emulationOptionsPanel.add(logSerialMessagesCheckBox); emulationOptionsPanel.add( new JLabel("If checked, messages related to serial interfaces will be logged to the console.")); // Log register messages final JCheckBox logRegisterMessagesCheckBox = new JCheckBox("Log register messages"); logRegisterMessagesCheckBox.setSelected(prefs.isLogRegisterMessages(chip)); emulationOptionsPanel.add(logRegisterMessagesCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, warnings related to unimplemented register addresses will be logged to the console.")); // Log pin messages final JCheckBox logPinMessagesCheckBox = new JCheckBox("Log pin messages"); logPinMessagesCheckBox.setSelected(prefs.isLogPinMessages(chip)); emulationOptionsPanel.add(logPinMessagesCheckBox); emulationOptionsPanel.add(new JLabel( "If checked, warnings related to unimplemented I/O pins will be logged to the console.")); emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL)); // Alt mode upon Debug JPanel altDebugPanel = new JPanel(new FlowLayout()); Object[] altDebugMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray(); final JComboBox altModeForDebugCombo = new JComboBox(new DefaultComboBoxModel(altDebugMode)); for (int j = 0; j < altDebugMode.length; j++) { if (altDebugMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponDebug(chip))) { altModeForDebugCombo.setSelectedIndex(j); } } altDebugPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip] + " runs in sync Debug: ")); altDebugPanel.add(altModeForDebugCombo); emulationOptionsPanel.add(altDebugPanel); emulationOptionsPanel .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip] + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Debug mode")); // Alt mode upon Step JPanel altStepPanel = new JPanel(new FlowLayout()); Object[] altStepMode = EnumSet.allOf(EmulationFramework.ExecutionMode.class).toArray(); final JComboBox altModeForStepCombo = new JComboBox(new DefaultComboBoxModel(altStepMode)); for (int j = 0; j < altStepMode.length; j++) { if (altStepMode[j].equals(prefs.getAltExecutionModeForSyncedCpuUponStep(chip))) { altModeForStepCombo.setSelectedIndex(j); } } altStepPanel.add(new JLabel(Constants.CHIP_LABEL[1 - chip] + " mode when " + Constants.CHIP_LABEL[chip] + " runs in sync Step: ")); altStepPanel.add(altModeForStepCombo); emulationOptionsPanel.add(altStepPanel); emulationOptionsPanel .add(new JLabel("If 'sync mode' is selected, this is the mode the " + Constants.CHIP_LABEL[1 - chip] + " chip will run in when running the " + Constants.CHIP_LABEL[chip] + " in Step mode")); // ------------------------ Prepare tabbed pane JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Disassembly Options", null, disassemblyOptionsPanel); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " Emulation Options", null, emulationOptionsPanel); if (chip == Constants.CHIP_TX) { JPanel chipSpecificOptionsPanel = new JPanel(new VerticalLayout(5, VerticalLayout.LEFT)); chipSpecificOptionsPanel.add(new JLabel("Eeprom status upon startup:")); ActionListener eepromInitializationRadioActionListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.setEepromInitMode(Prefs.EepromInitMode.valueOf(e.getActionCommand())); } }; JRadioButton blank = new JRadioButton("Blank"); blank.setActionCommand(Prefs.EepromInitMode.BLANK.name()); blank.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.BLANK.equals(prefs.getEepromInitMode())) blank.setSelected(true); JRadioButton persistent = new JRadioButton("Persistent across sessions"); persistent.setActionCommand(Prefs.EepromInitMode.PERSISTENT.name()); persistent.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.PERSISTENT.equals(prefs.getEepromInitMode())) persistent.setSelected(true); JRadioButton lastLoaded = new JRadioButton("Last Loaded"); lastLoaded.setActionCommand(Prefs.EepromInitMode.LAST_LOADED.name()); lastLoaded.addActionListener(eepromInitializationRadioActionListener); if (Prefs.EepromInitMode.LAST_LOADED.equals(prefs.getEepromInitMode())) lastLoaded.setSelected(true); ButtonGroup group = new ButtonGroup(); group.add(blank); group.add(persistent); group.add(lastLoaded); chipSpecificOptionsPanel.add(blank); chipSpecificOptionsPanel.add(persistent); chipSpecificOptionsPanel.add(lastLoaded); chipSpecificOptionsPanel.add(new JLabel("Front panel type:")); final JComboBox frontPanelNameCombo = new JComboBox(new String[] { "D5100_small", "D5100_large" }); if (prefs.getFrontPanelName() != null) { frontPanelNameCombo.setSelectedItem(prefs.getFrontPanelName()); } frontPanelNameCombo.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.setFrontPanelName((String) frontPanelNameCombo.getSelectedItem()); } }); chipSpecificOptionsPanel.add(frontPanelNameCombo); emulationOptionsPanel.add(new JSeparator(JSeparator.HORIZONTAL)); tabbedPane.addTab(Constants.CHIP_LABEL[chip] + " specific options", null, chipSpecificOptionsPanel); } // ------------------------ Show it if (JOptionPane.OK_OPTION == JOptionPane.showOptionDialog(this, tabbedPane, Constants.CHIP_LABEL[chip] + " options", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, JOptionPane.DEFAULT_OPTION)) { // save output options dumpOptionCheckboxes(outputOptionsCheckBoxes, prefs.getOutputOptions(chip)); // apply TxCPUState.initRegisterLabels(prefs.getOutputOptions(chip)); // save other prefs prefs.setFirmwareWriteProtected(chip, writeProtectFirmwareCheckBox.isSelected()); prefs.setDmaSynchronous(chip, dmaSynchronousCheckBox.isSelected()); prefs.setAutoEnableTimers(chip, autoEnableTimersCheckBox.isSelected()); prefs.setLogRegisterMessages(chip, logRegisterMessagesCheckBox.isSelected()); prefs.setLogSerialMessages(chip, logSerialMessagesCheckBox.isSelected()); prefs.setLogPinMessages(chip, logPinMessagesCheckBox.isSelected()); prefs.setLogMemoryMessages(chip, logMemoryMessagesCheckBox.isSelected()); prefs.setAltExecutionModeForSyncedCpuUponDebug(chip, (EmulationFramework.ExecutionMode) altModeForDebugCombo.getSelectedItem()); prefs.setAltExecutionModeForSyncedCpuUponStep(chip, (EmulationFramework.ExecutionMode) altModeForStepCombo.getSelectedItem()); } }
From source file:userinterface.properties.GUIGraphHandler.java
public void defineConstantsAndPlot(Expression expr, JPanel graph, String seriesName, Boolean isNewGraph, boolean is2D) { JDialog dialog;//from w w w. ja v a 2 s .c o m JButton ok, cancel; JScrollPane scrollPane; ConstantPickerList constantList; JComboBox<String> xAxis, yAxis; //init everything dialog = new JDialog(GUIPrism.getGUI()); dialog.setTitle("Define constants and select axes"); dialog.setSize(500, 400); dialog.setLocationRelativeTo(GUIPrism.getGUI()); dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS)); dialog.setModal(true); constantList = new ConstantPickerList(); scrollPane = new JScrollPane(constantList); xAxis = new JComboBox<String>(); yAxis = new JComboBox<String>(); ok = new JButton("Ok"); ok.setMnemonic('O'); cancel = new JButton("Cancel"); cancel.setMnemonic('C'); //add all components to their dedicated panels JPanel exprPanel = new JPanel(new FlowLayout()); exprPanel.setBorder(new TitledBorder("Function")); exprPanel.add(new JLabel(expr.toString())); JPanel axisPanel = new JPanel(); axisPanel.setBorder(new TitledBorder("Select axis constants")); axisPanel.setLayout(new BoxLayout(axisPanel, BoxLayout.Y_AXIS)); JPanel xAxisPanel = new JPanel(new FlowLayout()); xAxisPanel.add(new JLabel("X axis:")); xAxisPanel.add(xAxis); JPanel yAxisPanel = new JPanel(new FlowLayout()); yAxisPanel.add(new JLabel("Y axis:")); yAxisPanel.add(yAxis); axisPanel.add(xAxisPanel); axisPanel.add(yAxisPanel); JPanel constantPanel = new JPanel(new BorderLayout()); constantPanel.setBorder(new TitledBorder("Please define the following constants")); constantPanel.add(scrollPane, BorderLayout.CENTER); constantPanel.add(new ConstantHeader(), BorderLayout.NORTH); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); bottomPanel.add(ok); bottomPanel.add(cancel); //fill the axes components for (int i = 0; i < expr.getAllConstants().size(); i++) { xAxis.addItem(expr.getAllConstants().get(i)); if (!is2D) yAxis.addItem(expr.getAllConstants().get(i)); } if (!is2D) { yAxis.setSelectedIndex(1); } //fill the constants table for (int i = 0; i < expr.getAllConstants().size(); i++) { ConstantLine line = new ConstantLine(expr.getAllConstants().get(i), TypeDouble.getInstance()); constantList.addConstant(line); if (!is2D) { if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } //do enables if (is2D) { yAxis.setEnabled(false); } ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok"); ok.getActionMap().put("ok", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { ok.doClick(); } }); cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); cancel.getActionMap().put("cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { cancel.doClick(); } }); //add action listeners xAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (is2D) { return; } String item = xAxis.getSelectedItem().toString(); if (item.equals(yAxis.getSelectedItem().toString())) { int index = yAxis.getSelectedIndex(); if (index != yAxis.getItemCount() - 1) { yAxis.setSelectedIndex(++index); } else { yAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); yAxis.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String item = yAxis.getSelectedItem().toString(); if (item.equals(xAxis.getSelectedItem().toString())) { int index = xAxis.getSelectedIndex(); if (index != xAxis.getItemCount() - 1) { xAxis.setSelectedIndex(++index); } else { xAxis.setSelectedIndex(--index); } } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString()) || line.getName().equals(yAxis.getSelectedItem().toString())) { line.doFuncEnables(false); } else { line.doFuncEnables(true); } } } }); ok.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { constantList.checkValid(); } catch (PrismException e2) { JOptionPane.showMessageDialog(dialog, "<html> One or more of the defined constants are invalid. <br><br> <font color=red>Error: </font>" + e2.getMessage() + "</html>", "Parse Error", JOptionPane.ERROR_MESSAGE); return; } if (is2D) { // it will always be a parametric graph in 2d case ParametricGraph pGraph = (ParametricGraph) graph; ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); if (xAxisConstant == null) { //should never happen JOptionPane.showMessageDialog(dialog, "The selected axis is invalid.", "Error", JOptionPane.ERROR_MESSAGE); return; } double xStartValue = Double.parseDouble(xAxisConstant.getStartValue()); double xEndValue = Double.parseDouble(xAxisConstant.getEndValue()); double xStepValue = Double.parseDouble(xAxisConstant.getStepValue()); int seriesCount = 0; for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getName().equals(xAxis.getSelectedItem().toString())) { seriesCount++; } else { seriesCount += line.getTotalNumOfValues(); } } // if there will be too many series to be plotted, ask the user if they are sure they know what they are doing if (seriesCount > 10) { int res = JOptionPane.showConfirmDialog(dialog, "This configuration will create " + seriesCount + " series. Continue?", "Confirm", JOptionPane.YES_NO_OPTION); if (res == JOptionPane.NO_OPTION) { return; } } Values singleValuesGlobal = new Values(); //add the single values to a global values list for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } // we just have one variable so we can plot directly if (constantList.getNumConstants() == 1 || singleValuesGlobal.getNumValues() == constantList.getNumConstants() - 1) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); pGraph.getXAxisSettings().setHeading(xAxis.getSelectedItem().toString()); pGraph.getYAxisSettings().setHeading("function"); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { e1.printStackTrace(); } } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } if (isNewGraph) { addGraph(pGraph); } dialog.dispose(); return; } for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line == xAxisConstant || singleValuesGlobal.contains(line.getName())) { continue; } double lineStart = Double.parseDouble(line.getStartValue()); double lineEnd = Double.parseDouble(line.getEndValue()); double lineStep = Double.parseDouble(line.getStepValue()); for (double j = lineStart; j < lineEnd; j += lineStep) { SeriesKey key = pGraph.addSeries(seriesName); pGraph.hideShape(key); for (double x = xStartValue; x <= xEndValue; x += xStepValue) { double ans = -1; Values vals = new Values(); vals.addValue(xAxis.getSelectedItem().toString(), x); vals.addValue(line.getName(), j); for (int ii = 0; ii < singleValuesGlobal.getNumValues(); ii++) { try { vals.addValue(singleValuesGlobal.getName(ii), singleValuesGlobal.getDoubleValue(ii)); } catch (PrismLangException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } for (int ii = 0; ii < constantList.getNumConstants(); ii++) { if (constantList.getConstantLine(ii) == xAxisConstant || singleValuesGlobal .contains(constantList.getConstantLine(ii).getName()) || constantList.getConstantLine(ii) == line) { continue; } ConstantLine temp = constantList.getConstantLine(ii); double val = Double.parseDouble(temp.getStartValue()); vals.addValue(temp.getName(), val); } try { ans = expr.evaluateDouble(vals); } catch (PrismLangException e1) { e1.printStackTrace(); } pGraph.addPointToSeries(key, new PrismXYDataItem(x, ans)); } } } if (isNewGraph) { addGraph(graph); } } else { // this will always be a parametric graph for the 3d case ParametricGraph3D pGraph = (ParametricGraph3D) graph; //add the graph to the gui addGraph(pGraph); //Get the constants we want to put on the x and y axis ConstantLine xAxisConstant = constantList.getConstantLine(xAxis.getSelectedItem().toString()); ConstantLine yAxisConstant = constantList.getConstantLine(yAxis.getSelectedItem().toString()); //add the single values to a global values list Values singleValuesGlobal = new Values(); for (int i = 0; i < constantList.getNumConstants(); i++) { ConstantLine line = constantList.getConstantLine(i); if (line.getTotalNumOfValues() == 1) { double singleValue = Double.parseDouble(line.getSingleValue()); singleValuesGlobal.addValue(line.getName(), singleValue); } } pGraph.setGlobalValues(singleValuesGlobal); pGraph.setAxisConstants(xAxis.getSelectedItem().toString(), yAxis.getSelectedItem().toString()); pGraph.setBounds(xAxisConstant.getStartValue(), xAxisConstant.getEndValue(), yAxisConstant.getStartValue(), yAxisConstant.getEndValue()); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { //plot the graph pGraph.plot(expr.toString(), xAxis.getSelectedItem().toString(), "Function", yAxis.getSelectedItem().toString()); //calculate the sampling rates from the step sizes as given by the user int xSamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); int ySamples = (int) ((Double.parseDouble(xAxisConstant.getEndValue()) - Double.parseDouble(xAxisConstant.getStartValue())) / Double.parseDouble(xAxisConstant.getStepValue())); pGraph.setSamplingRates(xSamples, ySamples); } }); } dialog.dispose(); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.dispose(); } }); //add everything to the dialog show the dialog dialog.add(exprPanel); dialog.add(axisPanel); dialog.add(constantPanel); dialog.add(bottomPanel); dialog.setVisible(true); }
From source file:com.game.ui.views.PlayerEditor.java
@Override public void actionPerformed(ActionEvent ae) { validationMess.setText(""); validationMess.setVisible(false);//w ww . ja va 2s.c o m if (ae.getActionCommand().equalsIgnoreCase("dropDown")) { JComboBox comboBox = (JComboBox) ae.getSource(); String type = comboBox.getSelectedItem().toString(); for (GameCharacter user : GameBean.playerDetails) { Player player = (Player) user; if (player.getType().equalsIgnoreCase(type)) { ((JTextField) leftPanel.getComponent(2)).setText(player.getName()); ((JTextField) leftPanel.getComponent(4)).setText(player.getImagePath()); ((JTextField) leftPanel.getComponent(6)).setText(new Integer(player.getHealth()).toString()); ((JTextField) leftPanel.getComponent(8)).setText(new Integer(player.getAttackPts()).toString()); ((JTextField) leftPanel.getComponent(10)).setText(new Integer(player.getArmor()).toString()); ((JTextField) leftPanel.getComponent(12)) .setText(new Integer(player.getAttackRange()).toString()); ((JTextField) leftPanel.getComponent(14)).setText(new Integer(player.getMovement()).toString()); ((JTextField) leftPanel.getComponent(16)).setText(player.getType()); JComboBox cBox = (JComboBox) leftPanel.getComponent(18); cBox.setSelectedItem(player.getInventory().getEquippedWeapon().getName()); lvlPanel.txtFields[0].setText("" + player.getLevel()); lvlPanel.txtFields[1].setText("" + player.getExp()); lvlPanel.txtFields[2].setText("" + player.getStrength()); lvlPanel.txtFields[3].setText("" + player.getVitality()); lvlPanel.txtFields[4].setText("" + player.getDexterity()); lvlPanel.txtFields[5].setText("" + player.getWisdom()); break; // return; } } } else { String name = ((JTextField) leftPanel.getComponent(2)).getText(); String image = ((JTextField) leftPanel.getComponent(4)).getText(); String health = ((JTextField) leftPanel.getComponent(6)).getText(); String attackPts = ((JTextField) leftPanel.getComponent(8)).getText(); String armourPts = ((JTextField) leftPanel.getComponent(10)).getText(); String attackRnge = ((JTextField) leftPanel.getComponent(12)).getText(); String movement = ((JTextField) leftPanel.getComponent(14)).getText(); String type = ((JTextField) leftPanel.getComponent(16)).getText(); String weapon = ((JComboBox) leftPanel.getComponent(18)).getSelectedItem().toString(); int attr[] = new int[6]; attr[0] = Integer.parseInt(lvlPanel.txtFields[0].getText()); attr[1] = Integer.parseInt(lvlPanel.txtFields[1].getText()); attr[2] = Integer.parseInt(lvlPanel.txtFields[2].getText()); attr[3] = Integer.parseInt(lvlPanel.txtFields[3].getText()); attr[4] = Integer.parseInt(lvlPanel.txtFields[4].getText()); attr[5] = Integer.parseInt(lvlPanel.txtFields[5].getText()); // validationMess.setText(""); // validationMess.setVisible(false); if (StringUtils.isNotBlank(image) && StringUtils.isNotBlank(health) && StringUtils.isNotBlank(attackPts) && StringUtils.isNotBlank(armourPts) && StringUtils.isNotBlank(attackRnge) && StringUtils.isNotBlank(movement) && StringUtils.isNotBlank(type) && StringUtils.isNotBlank(weapon)) { validationMess.setVisible(false); Player player = new Player(); //have to remove the following statement later.. player.setName(name); player.setAttackPts(Integer.parseInt(attackPts)); player.setAttackRange(Integer.parseInt(attackRnge)); player.setHealth(Integer.parseInt(health)); player.setImagePath(image); player.setMovement(Integer.parseInt(movement)); player.setArmor(Integer.parseInt(armourPts)); player.setType(type); Inventory inventory = new Inventory(); int position = GameUtils.getPositionOfWeaponItem(weapon); Weapon weaponObj = (Weapon) GameBean.weaponDetails.get(position); inventory.setEquippedWeapon(weaponObj); player.setInventory(inventory); player.setLevel(attr[0]); player.setExp(attr[1]); player.setStrength(attr[2]); player.setVitality(attr[3]); player.setDexterity(attr[4]); player.setWisdom(attr[5]); boolean characterAlrdyPresent = false; for (int i = 0; i < GameBean.playerDetails.size(); i++) { Player charFromList = (Player) GameBean.playerDetails.get(i); if (charFromList.getType().equalsIgnoreCase(type)) { GameBean.playerDetails.remove(i); characterAlrdyPresent = true; } } GameBean.playerDetails.add(player); try { GameUtils.writeCharactersToXML(GameBean.playerDetails, Configuration.PATH_FOR_USER_CHARACTERS); validationMess.setText("Saved Successfully.."); validationMess.setVisible(true); if (!characterAlrdyPresent) { comboBox.addItem(type); comboBox.removeActionListener(this); comboBox.setSelectedItem(type); comboBox.addActionListener(this); } } catch (Exception e) { System.out.println("PlayerEditor : actionPerformed() : Some error occured " + e); validationMess.setText("Some error occured.."); validationMess.setVisible(true); e.printStackTrace(); } } else { validationMess.setText("Pls enter all the fields or pls choose a character from the drop down"); validationMess.setVisible(true); } } this.revalidate(); // JFrame frame = (JFrame)SwingUtilities.getAncestorNamed("Frame", this); // frame.revalidate(); }
From source file:edu.ku.brc.af.ui.forms.FormViewObj.java
/** * Sets the multiview if it is owned or mvParented by it. * @param cbx combobox to add a listener to *///from ww w . ja v a2 s .c o m public void addMultiViewListener(final JComboBox cbx) { class MVActionListener implements ActionListener { protected MultiView mv; public MVActionListener(final MultiView mv) { this.mv = mv; } public void actionPerformed(ActionEvent ae) { doSelectorWasSelected(mv, ae); } } if (cbx != null) { cbx.addActionListener(new MVActionListener(mvParent)); } }
From source file:mt.listeners.InteractiveRANSAC.java
public void CardTable() { this.lambdaSB = new Scrollbar(Scrollbar.HORIZONTAL, this.lambdaInt, 1, MIN_SLIDER, MAX_SLIDER + 1); maxSlopeSB.setValue(utility.Slicer.computeScrollbarPositionFromValue((float) maxSlope, (float) MIN_ABS_SLOPE, (float) MAX_ABS_SLOPE, scrollbarSize)); maxDistSB.setValue(//ww w . ja v a2 s . co m utility.Slicer.computeScrollbarPositionFromValue(maxDist, MIN_Gap, MAX_Gap, scrollbarSize)); minInliersSB.setValue(utility.Slicer.computeScrollbarPositionFromValue(minInliers, MIN_Inlier, MAX_Inlier, scrollbarSize)); maxErrorSB.setValue( utility.Slicer.computeScrollbarPositionFromValue(maxError, MIN_ERROR, MAX_ERROR, scrollbarSize)); minSlopeSB.setValue(utility.Slicer.computeScrollbarPositionFromValue((float) minSlope, (float) MIN_ABS_SLOPE, (float) MAX_ABS_SLOPE, scrollbarSize)); lambdaLabel = new Label("Linearity (fraction) = " + new DecimalFormat("#.##").format(lambda), Label.CENTER); maxErrorLabel = new Label("Maximum Error (px) = " + new DecimalFormat("#.##").format(maxError) + " ", Label.CENTER); minInliersLabel = new Label( "Minimum No. of timepoints (tp) = " + new DecimalFormat("#.##").format(minInliers), Label.CENTER); maxDistLabel = new Label("Maximum Gap (tp) = " + new DecimalFormat("#.##").format(maxDist), Label.CENTER); minSlopeLabel = new Label("Min. Segment Slope (px/tp) = " + new DecimalFormat("#.##").format(minSlope), Label.CENTER); maxSlopeLabel = new Label("Max. Segment Slope (px/tp) = " + new DecimalFormat("#.##").format(maxSlope), Label.CENTER); maxResLabel = new Label( "MT is rescued if the start of event# i + 1 > start of event# i by px = " + this.restolerance, Label.CENTER); CardLayout cl = new CardLayout(); Object[] colnames = new Object[] { "Track File", "Growth velocity", "Shrink velocity", "Growth events", "Shrink events", "fcat", "fres", "Error" }; Object[][] rowvalues = new Object[0][colnames.length]; if (inputfiles != null) { rowvalues = new Object[inputfiles.length][colnames.length]; for (int i = 0; i < inputfiles.length; ++i) { rowvalues[i][0] = inputfiles[i].getName(); } } table = new JTable(rowvalues, colnames); table.setFillsViewportHeight(true); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.isOpaque(); int size = 100; table.getColumnModel().getColumn(0).setPreferredWidth(size); table.getColumnModel().getColumn(1).setPreferredWidth(size); table.getColumnModel().getColumn(2).setPreferredWidth(size); table.getColumnModel().getColumn(3).setPreferredWidth(size); table.getColumnModel().getColumn(4).setPreferredWidth(size); table.getColumnModel().getColumn(5).setPreferredWidth(size); table.getColumnModel().getColumn(6).setPreferredWidth(size); table.getColumnModel().getColumn(7).setPreferredWidth(size); maxErrorField = new TextField(5); maxErrorField.setText(Float.toString(maxError)); minInlierField = new TextField(5); minInlierField.setText(Float.toString(minInliers)); maxGapField = new TextField(5); maxGapField.setText(Float.toString(maxDist)); maxSlopeField = new TextField(5); maxSlopeField.setText(Float.toString(maxSlope)); minSlopeField = new TextField(5); minSlopeField.setText(Float.toString(minSlope)); maxErrorSB.setSize(new Dimension(SizeX, 20)); minSlopeSB.setSize(new Dimension(SizeX, 20)); minInliersSB.setSize(new Dimension(SizeX, 20)); maxDistSB.setSize(new Dimension(SizeX, 20)); maxSlopeSB.setSize(new Dimension(SizeX, 20)); maxErrorField.setSize(new Dimension(SizeX, 20)); minInlierField.setSize(new Dimension(SizeX, 20)); maxGapField.setSize(new Dimension(SizeX, 20)); minSlopeField.setSize(new Dimension(SizeX, 20)); maxSlopeField.setSize(new Dimension(SizeX, 20)); scrollPane = new JScrollPane(table); scrollPane.setMinimumSize(new Dimension(300, 200)); scrollPane.setPreferredSize(new Dimension(300, 200)); scrollPane.getViewport().add(table); scrollPane.setAutoscrolls(true); // Location panelFirst.setLayout(layout); panelSecond.setLayout(layout); PanelSavetoFile.setLayout(layout); PanelParameteroptions.setLayout(layout); Panelfunction.setLayout(layout); Panelslope.setLayout(layout); PanelCompileRes.setLayout(layout); PanelDirectory.setLayout(layout); panelCont.setLayout(cl); panelCont.add(panelFirst, "1"); panelCont.add(panelSecond, "2"); panelFirst.setName("Ransac fits for rates and frequency analysis"); c.insets = new Insets(5, 5, 5, 5); c.anchor = GridBagConstraints.BOTH; c.ipadx = 35; inputLabelT = new Label("Compute length distribution at time: "); inputLabelTcont = new Label("(Press Enter to start computation) "); inputFieldT = new TextField(5); inputFieldT.setText("1"); c.gridwidth = 10; c.gridheight = 10; c.gridy = 1; c.gridx = 0; String[] Method = { "Linear Function only", "Linearized Quadratic function", "Linearized Cubic function" }; JComboBox<String> ChooseMethod = new JComboBox<String>(Method); final Checkbox findCatastrophe = new Checkbox("Detect Catastrophies", this.detectCatastrophe); final Checkbox findmanualCatastrophe = new Checkbox("Detect Catastrophies without fit", this.detectmanualCatastrophe); final Scrollbar minCatDist = new Scrollbar(Scrollbar.HORIZONTAL, this.minDistCatInt, 1, MIN_SLIDER, MAX_SLIDER + 1); final Scrollbar maxRes = new Scrollbar(Scrollbar.HORIZONTAL, this.restoleranceInt, 1, MIN_SLIDER, MAX_SLIDER + 1); final Label minCatDistLabel = new Label("Min. Catastrophy height (tp) = " + this.minDistanceCatastrophe, Label.CENTER); final Button done = new Button("Done"); final Button batch = new Button("Save Parameters for Batch run"); final Button cancel = new Button("Cancel"); final Button Compile = new Button("Compute rates and freq. till current file"); final Button AutoCompile = new Button("Auto Compute Velocity and Frequencies"); final Button Measureserial = new Button("Select directory of MTrack generated files"); final Button WriteLength = new Button("Compute length distribution at framenumber : "); final Button WriteStats = new Button("Compute lifetime and mean length distribution"); final Button WriteAgain = new Button("Save Velocity and Frequencies to File"); PanelDirectory.add(Measureserial, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelDirectory.add(scrollPane, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelDirectory.setBorder(selectdirectory); PanelDirectory.setPreferredSize(new Dimension(SizeX, SizeY)); panelFirst.add(PanelDirectory, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); SliderBoxGUI combomaxerror = new SliderBoxGUI(errorstring, maxErrorSB, maxErrorField, maxErrorLabel, scrollbarSize, maxError, MAX_ERROR); PanelParameteroptions.add(combomaxerror.BuildDisplay(), new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); SliderBoxGUI combomininlier = new SliderBoxGUI(inlierstring, minInliersSB, minInlierField, minInliersLabel, scrollbarSize, minInliers, MAX_Inlier); PanelParameteroptions.add(combomininlier.BuildDisplay(), new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); SliderBoxGUI combomaxdist = new SliderBoxGUI(maxgapstring, maxDistSB, maxGapField, maxDistLabel, scrollbarSize, maxDist, MAX_Gap); PanelParameteroptions.add(combomaxdist.BuildDisplay(), new GridBagConstraints(0, 3, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelParameteroptions.add(ChooseMethod, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelParameteroptions.add(lambdaSB, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelParameteroptions.add(lambdaLabel, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelParameteroptions.setPreferredSize(new Dimension(SizeX, SizeY)); PanelParameteroptions.setBorder(selectparam); panelFirst.add(PanelParameteroptions, new GridBagConstraints(3, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); SliderBoxGUI combominslope = new SliderBoxGUI(minslopestring, minSlopeSB, minSlopeField, minSlopeLabel, scrollbarSize, (float) minSlope, (float) MAX_ABS_SLOPE); Panelslope.add(combominslope.BuildDisplay(), new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); SliderBoxGUI combomaxslope = new SliderBoxGUI(maxslopestring, maxSlopeSB, maxSlopeField, maxSlopeLabel, scrollbarSize, (float) maxSlope, (float) MAX_ABS_SLOPE); Panelslope.add(combomaxslope.BuildDisplay(), new GridBagConstraints(0, 2, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); Panelslope.add(findCatastrophe, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0)); Panelslope.add(findmanualCatastrophe, new GridBagConstraints(4, 4, 3, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0)); Panelslope.add(minCatDist, new GridBagConstraints(0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0)); Panelslope.add(minCatDistLabel, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL, insets, 0, 0)); Panelslope.setBorder(selectslope); Panelslope.setPreferredSize(new Dimension(SizeX, SizeY)); panelFirst.add(Panelslope, new GridBagConstraints(3, 1, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelCompileRes.add(AutoCompile, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelCompileRes.add(WriteLength, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelCompileRes.add(inputFieldT, new GridBagConstraints(3, 1, 3, 1, 0.1, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelCompileRes.add(WriteStats, new GridBagConstraints(0, 4, 3, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); PanelCompileRes.setPreferredSize(new Dimension(SizeX, SizeY)); PanelCompileRes.setBorder(compileres); panelFirst.add(PanelCompileRes, new GridBagConstraints(0, 1, 3, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, insets, 0, 0)); if (inputfiles != null) { table.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() >= 1) { if (!jFreeChartFrame.isVisible()) jFreeChartFrame = Tracking.display(chart, new Dimension(500, 500)); JTable target = (JTable) e.getSource(); row = target.getSelectedRow(); // do some action if appropriate column if (row > 0) displayclicked(row); else displayclicked(0); } } }); } maxErrorSB.addAdjustmentListener(new ErrorListener(this, maxErrorLabel, errorstring, MIN_ERROR, MAX_ERROR, scrollbarSize, maxErrorSB)); minInliersSB.addAdjustmentListener(new MinInlierListener(this, minInliersLabel, inlierstring, MIN_Inlier, MAX_Inlier, scrollbarSize, minInliersSB)); maxDistSB.addAdjustmentListener( new MaxDistListener(this, maxDistLabel, maxgapstring, MIN_Gap, MAX_Gap, scrollbarSize, maxDistSB)); ChooseMethod.addActionListener(new FunctionItemListener(this, ChooseMethod)); lambdaSB.addAdjustmentListener(new LambdaListener(this, lambdaLabel, lambdaSB)); minSlopeSB.addAdjustmentListener(new MinSlopeListener(this, minSlopeLabel, minslopestring, (float) MIN_ABS_SLOPE, (float) MAX_ABS_SLOPE, scrollbarSize, minSlopeSB)); maxSlopeSB.addAdjustmentListener(new MaxSlopeListener(this, maxSlopeLabel, maxslopestring, (float) MIN_ABS_SLOPE, (float) MAX_ABS_SLOPE, scrollbarSize, maxSlopeSB)); findCatastrophe.addItemListener( new CatastrophyCheckBoxListener(this, findCatastrophe, minCatDistLabel, minCatDist)); findmanualCatastrophe.addItemListener( new ManualCatastrophyCheckBoxListener(this, findmanualCatastrophe, minCatDistLabel, minCatDist)); minCatDist.addAdjustmentListener(new MinCatastrophyDistanceListener(this, minCatDistLabel, minCatDist)); Measureserial.addActionListener(new MeasureserialListener(this)); Compile.addActionListener(new CompileResultsListener(this)); AutoCompile.addActionListener(new AutoCompileResultsListener(this)); WriteLength.addActionListener(new WriteLengthListener(this)); WriteStats.addActionListener(new WriteStatsListener(this)); WriteAgain.addActionListener(new WriteRatesListener(this)); done.addActionListener(new FinishButtonListener(this, false)); batch.addActionListener(new RansacBatchmodeListener(this)); cancel.addActionListener(new FinishButtonListener(this, true)); inputFieldT.addTextListener(new LengthdistroListener(this)); maxSlopeField.addTextListener(new MaxSlopeLocListener(this, false)); minSlopeField.addTextListener(new MinSlopeLocListener(this, false)); maxErrorField.addTextListener(new ErrorLocListener(this, false)); minInlierField.addTextListener(new MinInlierLocListener(this, false)); maxGapField.addTextListener(new MaxDistLocListener(this, false)); panelFirst.setVisible(true); functionChoice = 0; cl.show(panelCont, "1"); Cardframe.add(panelCont, BorderLayout.CENTER); setFunction(); Cardframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Cardframe.pack(); Cardframe.setVisible(true); Cardframe.pack(); }
From source file:nl.ru.ai.projects.parrot.biomav.editor.BehaviorEditor.java
private void setNewSelectedParameterControlInterface(ParameterControlInterface pcInterface) { pcInterfacePanelContents.removeAll(); selectedPCInterface = null;// www. j a v a 2s .c o m if (pcInterface != null) { selectedPCInterface = pcInterface; final ParameterControlInterface fpcInterface = pcInterface; String[] parameterNames = pcInterface.getParameterNames(); ParameterControlInterface.ParameterTypes[] parameterTypes = pcInterface.getParameterTypes(); for (int i = 0; i < parameterTypes.length; i++) { JLabel label = new JLabel(parameterNames[i]); pcInterfacePanelContents.add(label); final int index = i; switch (parameterTypes[i]) { case OPTIONS: final JComboBox optionComboBox = new JComboBox(pcInterface.getParameterOptions(i)); optionComboBox.setEditable(false); optionComboBox.setSelectedItem(pcInterface.getParameterValue(i)); optionComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { fpcInterface.setParameterValue(index, optionComboBox.getSelectedItem()); repaint(); } }); pcInterfacePanelContents.add(optionComboBox); break; } } } pcInterfacePanel.validate(); }
From source file:org.encog.workbench.tabs.visualize.bayesian.BayesianStructureTab.java
public BayesianStructureTab(BayesianNetwork method) { super(null);/*from w w w .ja v a 2 s . c o m*/ // Graph<V, E> where V is the type of the vertices // and E is the type of the edges this.graph = buildGraph(method); Layout<DrawnEvent, DrawnEventConnection> layout = new KKLayout(graph); vv = new VisualizationViewer<DrawnEvent, DrawnEventConnection>(layout); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.CNTR); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<DrawnEvent>()); vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner()); vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.N); vv.setVertexToolTipTransformer(new Transformer<DrawnEvent, String>() { public String transform(DrawnEvent edge) { return edge.getToolTip(); } }); Transformer<DrawnEvent, Paint> vertexPaint = new Transformer<DrawnEvent, Paint>() { public Paint transform(DrawnEvent neuron) { return Color.white; } }; final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); this.setLayout(new BorderLayout()); add(panel, BorderLayout.CENTER); final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); final ScalingControl scaler = new CrossoverScalingControl(); 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); 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 reset = new JButton("reset"); reset.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT).setToIdentity(); vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW).setToIdentity(); } }); JComboBox modeBox = graphMouse.getModeComboBox(); modeBox.addItemListener(((DefaultModalGraphMouse<Integer, Number>) vv.getGraphMouse()).getModeListener()); JPanel controls = new JPanel(); controls.setLayout(new FlowLayout(FlowLayout.LEFT)); controls.add(plus); controls.add(minus); controls.add(reset); controls.add(modeBox); controls.add(jcb); Border border = BorderFactory.createEtchedBorder(); controls.setBorder(border); add(controls, BorderLayout.NORTH); }
From source file:org.esa.snap.ui.tooladapter.dialogs.ToolParameterEditorDialog.java
public JPanel createMainPanel() { GridBagLayout layout = new GridBagLayout(); layout.columnWidths = new int[] { 100, 390 }; mainPanel = new JPanel(layout); addTextPropertyEditor(mainPanel, "Name: ", "name", parameter.getName(), 0, true); addTextPropertyEditor(mainPanel, "Alias: ", "alias", parameter.getAlias(), 1, true); //dataType//from ww w . j a v a 2 s . c om mainPanel.add(new JLabel("Type"), getConstraints(2, 0, 1)); JComboBox comboEditor = new JComboBox(typesMap.keySet().toArray()); comboEditor.setSelectedItem(typesMap.getKey(parameter.getDataType())); comboEditor.addActionListener(ev -> { JComboBox cb = (JComboBox) ev.getSource(); String typeName = (String) cb.getSelectedItem(); if (!parameter.getDataType().equals(typesMap.get(typeName))) { parameter.setDataType((Class<?>) typesMap.get(typeName)); //reset value set parameter.setValueSet(null); paramContext.getPropertySet().getProperty(parameter.getName()).getDescriptor().setValueSet(null); try { valuesContext.getPropertySet().getProperty("valueSet").setValue(null); } catch (ValidationException e) { logger.warning(e.getMessage()); } //editor must updated try { if (editorComponent != null) { mainPanel.remove(editorComponent); } editorComponent = uiWrapper.reloadUIComponent((Class<?>) typesMap.get(typeName)); if (!("File".equals(typeName) || "List".equals(typeName))) { editorComponent.setInputVerifier(new TypedValueValidator( "The value entered is not of the specified data type", parameter.getDataType())); } mainPanel.add(editorComponent, getConstraints(3, 1, 1)); mainPanel.revalidate(); } catch (Exception e) { logger.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } } }); mainPanel.add(comboEditor, getConstraints(2, 1, 1)); //defaultValue mainPanel.add(new JLabel("Default value"), getConstraints(3, 0, 1)); try { editorComponent = uiWrapper.getUIComponent(); mainPanel.add(editorComponent, getConstraints(3, 1, 1)); } catch (Exception e) { e.printStackTrace(); } addTextPropertyEditor(mainPanel, "Description: ", "description", parameter.getDescription(), 4, false); addTextPropertyEditor(mainPanel, "Label: ", "label", parameter.getLabel(), 5, false); addTextPropertyEditor(mainPanel, "Unit: ", "unit", parameter.getUnit(), 6, false); addTextPropertyEditor(mainPanel, "Interval: ", "interval", parameter.getInterval(), 7, false); JComponent valueSetEditor = addTextPropertyEditor(mainPanel, "Value set: ", "valueSet", StringUtils.join(parameter.getValueSet(), ArrayConverter.SEPARATOR), 8, false); valueSetEditor.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { } @Override public void focusLost(FocusEvent ev) { //the value set may impact the editor try { String newValueSet = ((JTextField) valueSetEditor).getText(); if (newValueSet.isEmpty()) { parameter.setValueSet(null); valuesContext.getPropertySet().getProperty("valueSet").setValue(null); } else { parameter.setValueSet(newValueSet.split(ArrayConverter.SEPARATOR)); valuesContext.getPropertySet().getProperty("valueSet") .setValue(newValueSet.split(ArrayConverter.SEPARATOR)); } if (editorComponent != null) { mainPanel.remove(editorComponent); } createContextForValueEditor(); if (!(File.class.equals(parameter.getDataType()) || parameter.getDataType().isArray())) { editorComponent.setInputVerifier(new TypedValueValidator( "The value entered is not of the specified data type", parameter.getDataType())); } mainPanel.add(editorComponent, getConstraints(3, 1, 1)); mainPanel.revalidate(); } catch (Exception e) { logger.warning(e.getMessage()); Dialogs.showError(e.getMessage()); } } }); addTextPropertyEditor(mainPanel, "Condition: ", "condition", parameter.getCondition(), 9, false); addTextPropertyEditor(mainPanel, "Pattern: ", "pattern", parameter.getPattern(), 10, false); addTextPropertyEditor(mainPanel, "Format: ", "format", parameter.getFormat(), 11, false); addBoolPropertyEditor(mainPanel, "Not null", "notNull", parameter.isNotNull(), 12); addBoolPropertyEditor(mainPanel, "Not empty", "notEmpty", parameter.isNotEmpty(), 13); addTextPropertyEditor(mainPanel, "ItemAlias: ", "itemAlias", parameter.getItemAlias(), 14, false); addBoolPropertyEditor(mainPanel, "Deprecated", "deprecated", parameter.isDeprecated(), 15); return mainPanel; }
From source file:org.graphwalker.GUI.App.java
@SuppressWarnings("serial") private void addButtons(JToolBar toolBar) { loadButton = makeNavigationButton("open", LOAD, "Load a model (graphml file)", "Load", true); toolBar.add(loadButton);// w w w . j av a 2 s. c o m reloadButton = makeNavigationButton("reload", RELOAD, "Reload/Restart already loaded Model", "Reload", false); toolBar.add(reloadButton); firstButton = makeNavigationButton("first", FIRST, "Start at the beginning", "First", false); toolBar.add(firstButton); backButton = makeNavigationButton("back", BACK, "Backs a step", "Back", false); toolBar.add(backButton); runButton = makeNavigationButton("run", RUN, "Starts the execution/Take a step forward in the log", "Run", false); toolBar.add(runButton); pauseButton = makeNavigationButton("pause", PAUSE, "Pauses the execution", "Pause", false); toolBar.add(pauseButton); nextButton = makeNavigationButton("next", NEXT, "Walk a step in the model/Go to the end of log", "Next", false); toolBar.add(nextButton); soapButton = makeNavigationCheckBoxButton("soap", SOAP, "Run MBT in SOAP(Web Services) mode", "Soap"); soapButton.setSelected(Util.readSoapGuiStartupState()); toolBar.add(soapButton); centerOnVertexButton = makeNavigationCheckBoxButton("centerOnVertex", CENTERONVERTEX, "Center the layout on the current vertex", "Center on current vertex"); toolBar.add(centerOnVertexButton); @SuppressWarnings("rawtypes") Class[] combos = getCombos(); final JComboBox jcb = new JComboBox(combos); // use a renderer to shorten the layout name presentation jcb.setRenderer(new DefaultListCellRenderer() { @Override 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, getVv())); jcb.setSelectedItem(StaticLayout.class); toolBar.add(jcb); }