List of usage examples for javax.swing JCheckBox setSelected
public void setSelected(boolean b)
From source file:org.forester.archaeopteryx.ControlPanel.java
/** * Set this checkbox state. Not all checkboxes have been instantiated * depending on the config./*from w w w.jav a2 s .c om*/ */ void setCheckbox(final JCheckBox cb, final boolean state) { if (cb != null) { cb.setSelected(state); } }
From source file:com.marginallyclever.makelangelo.MainGUI.java
protected boolean ChooseImageConversionOptions(boolean isDXF) { final JDialog driver = new JDialog(mainframe, translator.get("ConversionOptions"), true); driver.setLayout(new GridBagLayout()); final String[] choices = machineConfiguration.getKnownMachineNames(); final JComboBox<String> machine_choice = new JComboBox<String>(choices); machine_choice.setSelectedIndex(machineConfiguration.getCurrentMachineIndex()); final JSlider input_paper_margin = new JSlider(JSlider.HORIZONTAL, 0, 50, 100 - (int) (machineConfiguration.paper_margin * 100)); input_paper_margin.setMajorTickSpacing(10); input_paper_margin.setMinorTickSpacing(5); input_paper_margin.setPaintTicks(false); input_paper_margin.setPaintLabels(true); //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total")); //allow_metrics.setSelected(allowMetrics); final JCheckBox reverse_h = new JCheckBox(translator.get("FlipForGlass")); reverse_h.setSelected(machineConfiguration.reverseForGlass); final JButton cancel = new JButton(translator.get("Cancel")); final JButton save = new JButton(translator.get("Start")); String[] filter_names = new String[image_converters.size()]; Iterator<Filter> fit = image_converters.iterator(); int i = 0;// w w w .j a v a 2 s . c o m while (fit.hasNext()) { Filter f = fit.next(); filter_names[i++] = f.GetName(); } final JComboBox<String> input_draw_style = new JComboBox<String>(filter_names); input_draw_style.setSelectedIndex(GetDrawStyle()); GridBagConstraints c = new GridBagConstraints(); //c.gridwidth=4; c.gridx=0; c.gridy=0; driver.add(allow_metrics,c); int y = 0; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.gridx = 0; c.gridy = y; driver.add(new JLabel(translator.get("MenuLoadMachineConfig")), c); c.anchor = GridBagConstraints.WEST; c.gridwidth = 2; c.gridx = 1; c.gridy = y++; driver.add(machine_choice, c); if (!isDXF) { c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.gridx = 0; c.gridy = y; driver.add(new JLabel(translator.get("ConversionStyle")), c); c.anchor = GridBagConstraints.WEST; c.gridwidth = 3; c.gridx = 1; c.gridy = y++; driver.add(input_draw_style, c); } c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.gridx = 0; c.gridy = y; driver.add(new JLabel(translator.get("PaperMargin")), c); c.anchor = GridBagConstraints.WEST; c.gridwidth = 3; c.gridx = 1; c.gridy = y++; driver.add(input_paper_margin, c); c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y++; driver.add(reverse_h, c); c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.gridx = 2; c.gridy = y; driver.add(save, c); c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 3; c.gridy = y++; driver.add(cancel, c); startConvertingNow = false; ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == save) { long new_uid = Long.parseLong(choices[machine_choice.getSelectedIndex()]); machineConfiguration.LoadConfig(new_uid); SetDrawStyle(input_draw_style.getSelectedIndex()); machineConfiguration.paper_margin = (100 - input_paper_margin.getValue()) * 0.01; machineConfiguration.reverseForGlass = reverse_h.isSelected(); machineConfiguration.SaveConfig(); // if we aren't connected, don't show the new if (connectionToRobot != null && !connectionToRobot.isRobotConfirmed()) { // Force update of graphics layout. previewPane.updateMachineConfig(); // update window title mainframe.setTitle( translator.get("TitlePrefix") + Long.toString(machineConfiguration.robot_uid) + translator.get("TitleNotConnected")); } startConvertingNow = true; driver.dispose(); } if (subject == cancel) { driver.dispose(); } } }; save.addActionListener(driveButtons); cancel.addActionListener(driveButtons); driver.getRootPane().setDefaultButton(save); driver.pack(); driver.setVisible(true); return startConvertingNow; }
From source file:ffx.ui.ModelingPanel.java
private void loadCommand() { synchronized (this) { // Force Field X Command Element command;//from w w w. j a va2 s .c o m // Command Options NodeList options; Element option; // Option Values NodeList values; Element value; // Options may be Conditional based on previous Option values (not // always supplied) NodeList conditionalList; Element conditional; // JobPanel GUI Components that change based on command JPanel optionPanel; // Clear the previous components commandPanel.removeAll(); optionsTabbedPane.removeAll(); conditionals.clear(); String currentCommand = (String) currentCommandBox.getSelectedItem(); if (currentCommand == null) { commandPanel.validate(); commandPanel.repaint(); return; } command = null; for (int i = 0; i < commandList.getLength(); i++) { command = (Element) commandList.item(i); String name = command.getAttribute("name"); if (name.equalsIgnoreCase(currentCommand)) { break; } } int div = splitPane.getDividerLocation(); descriptTextArea.setText(currentCommand.toUpperCase() + ": " + command.getAttribute("description")); splitPane.setBottomComponent(descriptScrollPane); splitPane.setDividerLocation(div); // The "action" tells Force Field X what to do when the // command finishes commandActions = command.getAttribute("action").trim(); // The "fileType" specifies what file types this command can execute // on String string = command.getAttribute("fileType").trim(); String[] types = string.split(" +"); commandFileTypes.clear(); for (String type : types) { if (type.contains("XYZ")) { commandFileTypes.add(FileType.XYZ); } if (type.contains("INT")) { commandFileTypes.add(FileType.INT); } if (type.contains("ARC")) { commandFileTypes.add(FileType.ARC); } if (type.contains("PDB")) { commandFileTypes.add(FileType.PDB); } if (type.contains("ANY")) { commandFileTypes.add(FileType.ANY); } } // Determine what options are available for this command options = command.getElementsByTagName("Option"); int length = options.getLength(); for (int i = 0; i < length; i++) { // This Option will be enabled (isEnabled = true) unless a // Conditional disables it boolean isEnabled = true; option = (Element) options.item(i); conditionalList = option.getElementsByTagName("Conditional"); /* * Currently, there can only be 0 or 1 Conditionals per Option * There are three types of Conditionals implemented. 1.) * Conditional on a previous Option, this option may be * available 2.) Conditional on input for this option, a * sub-option may be available 3.) Conditional on the presence * of keywords, this option may be available */ if (conditionalList != null) { conditional = (Element) conditionalList.item(0); } else { conditional = null; } // Get the command line flag String flag = option.getAttribute("flag").trim(); // Get the description String optionDescript = option.getAttribute("description"); JTextArea optionTextArea = new JTextArea(" " + optionDescript.trim()); optionTextArea.setEditable(false); optionTextArea.setLineWrap(true); optionTextArea.setWrapStyleWord(true); optionTextArea.setBorder(etchedBorder); // Get the default for this Option (if one exists) String defaultOption = option.getAttribute("default"); // Option Panel optionPanel = new JPanel(new BorderLayout()); optionPanel.add(optionTextArea, BorderLayout.NORTH); String swing = option.getAttribute("gui"); JPanel optionValuesPanel = new JPanel(new FlowLayout()); optionValuesPanel.setBorder(etchedBorder); ButtonGroup bg = null; if (swing.equalsIgnoreCase("CHECKBOXES")) { // CHECKBOXES allows selection of 1 or more values from a // predefined set (Analyze, for example) values = option.getElementsByTagName("Value"); for (int j = 0; j < values.getLength(); j++) { value = (Element) values.item(j); JCheckBox jcb = new JCheckBox(value.getAttribute("name")); jcb.addMouseListener(this); jcb.setName(flag); if (defaultOption != null && jcb.getActionCommand().equalsIgnoreCase(defaultOption)) { jcb.setSelected(true); } optionValuesPanel.add(jcb); } } else if (swing.equalsIgnoreCase("TEXTFIELD")) { // TEXTFIELD takes an arbitrary String as input JTextField jtf = new JTextField(20); jtf.addMouseListener(this); jtf.setName(flag); if (defaultOption != null && defaultOption.equals("ATOMS")) { FFXSystem sys = mainPanel.getHierarchy().getActive(); if (sys != null) { jtf.setText("" + sys.getAtomList().size()); } } else if (defaultOption != null) { jtf.setText(defaultOption); } optionValuesPanel.add(jtf); } else if (swing.equalsIgnoreCase("RADIOBUTTONS")) { // RADIOBUTTONS allows one choice from a set of predifined // values bg = new ButtonGroup(); values = option.getElementsByTagName("Value"); for (int j = 0; j < values.getLength(); j++) { value = (Element) values.item(j); JRadioButton jrb = new JRadioButton(value.getAttribute("name")); jrb.addMouseListener(this); jrb.setName(flag); bg.add(jrb); if (defaultOption != null && jrb.getActionCommand().equalsIgnoreCase(defaultOption)) { jrb.setSelected(true); } optionValuesPanel.add(jrb); } } else if (swing.equalsIgnoreCase("PROTEIN")) { // Protein allows selection of amino acids for the protein // builder optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS)); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(getAminoAcidPanel()); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidComboBox.removeAllItems(); JButton add = new JButton("Edit"); add.setActionCommand("PROTEIN"); add.addActionListener(this); add.setAlignmentX(Button.CENTER_ALIGNMENT); JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidTextField); comboPanel.add(add); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton remove = new JButton("Remove"); add.setMinimumSize(remove.getPreferredSize()); add.setPreferredSize(remove.getPreferredSize()); remove.setActionCommand("PROTEIN"); remove.addActionListener(this); remove.setAlignmentX(Button.CENTER_ALIGNMENT); comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidComboBox); comboPanel.add(remove); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(acidScrollPane); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton reset = new JButton("Reset"); reset.setActionCommand("PROTEIN"); reset.addActionListener(this); reset.setAlignmentX(Button.CENTER_ALIGNMENT); optionValuesPanel.add(reset); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidTextArea.setText(""); acidTextField.setText(""); } else if (swing.equalsIgnoreCase("NUCLEIC")) { // Nucleic allows selection of nucleic acids for the nucleic // acid builder optionValuesPanel.setLayout(new BoxLayout(optionValuesPanel, BoxLayout.Y_AXIS)); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(getNucleicAcidPanel()); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidComboBox.removeAllItems(); JButton add = new JButton("Edit"); add.setActionCommand("NUCLEIC"); add.addActionListener(this); add.setAlignmentX(Button.CENTER_ALIGNMENT); JPanel comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidTextField); comboPanel.add(add); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton remove = new JButton("Remove"); add.setMinimumSize(remove.getPreferredSize()); add.setPreferredSize(remove.getPreferredSize()); remove.setActionCommand("NUCLEIC"); remove.addActionListener(this); remove.setAlignmentX(Button.CENTER_ALIGNMENT); comboPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); comboPanel.add(acidComboBox); comboPanel.add(remove); optionValuesPanel.add(comboPanel); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); optionValuesPanel.add(acidScrollPane); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); JButton button = new JButton("Reset"); button.setActionCommand("NUCLEIC"); button.addActionListener(this); button.setAlignmentX(Button.CENTER_ALIGNMENT); optionValuesPanel.add(button); optionValuesPanel.add(Box.createRigidArea(new Dimension(0, 5))); acidTextArea.setText(""); acidTextField.setText(""); } else if (swing.equalsIgnoreCase("SYSTEMS")) { // SYSTEMS allows selection of an open system JComboBox<FFXSystem> jcb = new JComboBox<>(mainPanel.getHierarchy().getNonActiveSystems()); jcb.setSize(jcb.getMaximumSize()); jcb.addActionListener(this); optionValuesPanel.add(jcb); } // Set up a Conditional for this Option if (conditional != null) { isEnabled = false; String conditionalName = conditional.getAttribute("name"); String conditionalValues = conditional.getAttribute("value"); String cDescription = conditional.getAttribute("description"); String cpostProcess = conditional.getAttribute("postProcess"); if (conditionalName.toUpperCase().startsWith("KEYWORD")) { optionPanel.setName(conditionalName); String keywords[] = conditionalValues.split(" +"); if (activeSystem != null) { Hashtable<String, Keyword> systemKeywords = activeSystem.getKeywords(); for (String key : keywords) { if (systemKeywords.containsKey(key.toUpperCase())) { isEnabled = true; } } } } else if (conditionalName.toUpperCase().startsWith("VALUE")) { isEnabled = true; // Add listeners to the values of this option so // the conditional options can be disabled/enabled. for (int j = 0; j < optionValuesPanel.getComponentCount(); j++) { JToggleButton jtb = (JToggleButton) optionValuesPanel.getComponent(j); jtb.addActionListener(this); jtb.setActionCommand("Conditional"); } JPanel condpanel = new JPanel(); condpanel.setBorder(etchedBorder); JLabel condlabel = new JLabel(cDescription); condlabel.setEnabled(false); condlabel.setName(conditionalValues); JTextField condtext = new JTextField(10); condlabel.setLabelFor(condtext); if (cpostProcess != null) { condtext.setName(cpostProcess); } condtext.setEnabled(false); condpanel.add(condlabel); condpanel.add(condtext); conditionals.add(condlabel); optionPanel.add(condpanel, BorderLayout.SOUTH); } else if (conditionalName.toUpperCase().startsWith("REFLECTION")) { String[] condModifiers; if (conditionalValues.equalsIgnoreCase("AltLoc")) { condModifiers = activeSystem.getAltLocations(); if (condModifiers != null && condModifiers.length > 1) { isEnabled = true; bg = new ButtonGroup(); for (int j = 0; j < condModifiers.length; j++) { JRadioButton jrbmi = new JRadioButton(condModifiers[j]); jrbmi.addMouseListener(this); bg.add(jrbmi); optionValuesPanel.add(jrbmi); if (j == 0) { jrbmi.setSelected(true); } } } } else if (conditionalValues.equalsIgnoreCase("Chains")) { condModifiers = activeSystem.getChainNames(); if (condModifiers != null && condModifiers.length > 0) { isEnabled = true; for (int j = 0; j < condModifiers.length; j++) { JRadioButton jrbmi = new JRadioButton(condModifiers[j]); jrbmi.addMouseListener(this); bg.add(jrbmi); optionValuesPanel.add(jrbmi, j); } } } } } optionPanel.add(optionValuesPanel, BorderLayout.CENTER); optionPanel.setPreferredSize(optionPanel.getPreferredSize()); optionsTabbedPane.addTab(option.getAttribute("name"), optionPanel); optionsTabbedPane.setEnabledAt(optionsTabbedPane.getTabCount() - 1, isEnabled); } } optionsTabbedPane.setPreferredSize(optionsTabbedPane.getPreferredSize()); commandPanel.setLayout(borderLayout); commandPanel.add(optionsTabbedPane, BorderLayout.CENTER); commandPanel.validate(); commandPanel.repaint(); loadLogSettings(); statusLabel.setText(" " + createCommandInput()); }
From source file:com._17od.upm.gui.AccountDialog.java
public AccountDialog(AccountInformation account, JFrame parentWindow, boolean readOnly, ArrayList existingAccounts) { super(parentWindow, true); boolean addingAccount = false; //Request focus on Account JDialog when mouse clicked this.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { requestFocus();/*from ww w .j av a 2 s. c o m*/ } } }); // Set the title based on weather we've been opened in readonly mode and // weather the // Account passed in is empty or not String title = null; if (readOnly) { title = Translator.translate("viewAccount"); } else if (!readOnly && account.getAccountName().trim().equals("")) { title = Translator.translate("addAccount"); addingAccount = true; } else { title = Translator.translate("editAccount"); } setTitle(title); this.pAccount = account; this.existingAccounts = existingAccounts; this.parentWindow = parentWindow; getContentPane().setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); Container container = getContentPane(); // The AccountName Row JLabel accountLabel = new JLabel(Translator.translate("account")); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(accountLabel, c); // This panel will hold the Account field and the copy and paste // buttons. JPanel accountPanel = new JPanel(new GridBagLayout()); accountName = new JTextField(new String(pAccount.getAccountName()), 20); if (readOnly) { accountName.setEditable(false); } c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; accountPanel.add(accountName, c); accountName.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { accountName.selectAll(); } }); JButton acctCopyButton = new JButton(); acctCopyButton.setIcon(Util.loadImage("copy-icon.png")); acctCopyButton.setToolTipText("Copy"); acctCopyButton.setEnabled(true); acctCopyButton.setMargin(new Insets(0, 0, 0, 0)); acctCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(accountName); } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; accountPanel.add(acctCopyButton, c); JButton acctPasteButton = new JButton(); acctPasteButton.setIcon(Util.loadImage("paste-icon.png")); acctPasteButton.setToolTipText("Paste"); acctPasteButton.setEnabled(!readOnly); acctPasteButton.setMargin(new Insets(0, 0, 0, 0)); acctPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(accountName); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; accountPanel.add(acctPasteButton, c); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(accountPanel, c); // Userid Row JLabel useridLabel = new JLabel(Translator.translate("userid")); c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(useridLabel, c); // This panel will hold the User ID field and the copy and paste // buttons. JPanel idPanel = new JPanel(new GridBagLayout()); userId = new JTextField(new String(pAccount.getUserId()), 20); if (readOnly) { userId.setEditable(false); } c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; idPanel.add(userId, c); userId.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { userId.selectAll(); } }); JButton idCopyButton = new JButton(); idCopyButton.setIcon(Util.loadImage("copy-icon.png")); idCopyButton.setToolTipText("Copy"); idCopyButton.setEnabled(true); idCopyButton.setMargin(new Insets(0, 0, 0, 0)); idCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(userId); } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; idPanel.add(idCopyButton, c); JButton idPasteButton = new JButton(); idPasteButton.setIcon(Util.loadImage("paste-icon.png")); idPasteButton.setToolTipText("Paste"); idPasteButton.setEnabled(!readOnly); idPasteButton.setMargin(new Insets(0, 0, 0, 0)); idPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(userId); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; idPanel.add(idPasteButton, c); c.gridx = 1; c.gridy = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(idPanel, c); // Password Row JLabel passwordLabel = new JLabel(Translator.translate("password")); c.gridx = 0; c.gridy = 2; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(15, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(passwordLabel, c); // This panel will hold the password, generate password button, copy and // paste buttons, and hide password checkbox JPanel passwordPanel = new JPanel(new GridBagLayout()); password = new JPasswordField(new String(pAccount.getPassword()), 20); // allow CTRL-C on the password field password.putClientProperty("JPasswordField.cutCopyAllowed", Boolean.TRUE); password.setEditable(!readOnly); password.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { password.selectAll(); } }); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(password, c); JButton generateRandomPasswordButton = new JButton(Translator.translate("generate")); if (readOnly) { generateRandomPasswordButton.setEnabled(false); } generateRandomPasswordButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionevent) { // Get the user's preference about including or not Escape // Characters to generated passwords Boolean includeEscapeChars = new Boolean( Preferences.get(Preferences.ApplicationOptions.INCLUDE_ESCAPE_CHARACTERS, "true")); int pwLength = Preferences.getInt(Preferences.ApplicationOptions.ACCOUNT_PASSWORD_LENGTH, 8); String Password; if ((includeEscapeChars.booleanValue()) && (pwLength > 3)) { // Verify that the generated password satisfies the criteria // for strong passwords(including Escape Characters) do { Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue()); } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue()))); } else if (!(includeEscapeChars.booleanValue()) && (pwLength > 2)) { // Verify that the generated password satisfies the criteria // for strong passwords(excluding Escape Characters) do { Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue()); } while (!(CheckPassStrong(Password, includeEscapeChars.booleanValue()))); } else { // Else a weak password of 3 or less chars will be produced Password = GeneratePassword(pwLength, includeEscapeChars.booleanValue()); } password.setText(Password); } }); if (addingAccount) { generateRandomPasswordButton.doClick(); } c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(generateRandomPasswordButton, c); JButton pwCopyButton = new JButton(); pwCopyButton.setIcon(Util.loadImage("copy-icon.png")); pwCopyButton.setToolTipText("Copy"); pwCopyButton.setEnabled(true); pwCopyButton.setMargin(new Insets(0, 0, 0, 0)); pwCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(password); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(pwCopyButton, c); JButton pwPasteButton = new JButton(); pwPasteButton.setIcon(Util.loadImage("paste-icon.png")); pwPasteButton.setToolTipText("Paste"); pwPasteButton.setEnabled(!readOnly); pwPasteButton.setMargin(new Insets(0, 0, 0, 0)); pwPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(password); } }); c.gridx = 3; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(pwPasteButton, c); JCheckBox hidePasswordCheckbox = new JCheckBox(Translator.translate("hide"), true); defaultEchoChar = password.getEchoChar(); hidePasswordCheckbox.setMargin(new Insets(5, 0, 5, 0)); hidePasswordCheckbox.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { password.setEchoChar(defaultEchoChar); } else { password.setEchoChar((char) 0); } } }); Boolean hideAccountPassword = new Boolean( Preferences.get(Preferences.ApplicationOptions.ACCOUNT_HIDE_PASSWORD, "true")); hidePasswordCheckbox.setSelected(hideAccountPassword.booleanValue()); c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 0); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; passwordPanel.add(hidePasswordCheckbox, c); c.gridx = 1; c.gridy = 2; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(passwordPanel, c); // URL Row JLabel urlLabel = new JLabel(Translator.translate("url")); c.gridx = 0; c.gridy = 3; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(urlLabel, c); // This panel will hold the URL field and the copy and paste buttons. JPanel urlPanel = new JPanel(new GridBagLayout()); url = new JTextField(new String(pAccount.getUrl()), 20); if (readOnly) { url.setEditable(false); } c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; urlPanel.add(url, c); url.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { url.selectAll(); } }); final JButton urlLaunchButton = new JButton(); urlLaunchButton.setIcon(Util.loadImage("launch-url-sm.png")); urlLaunchButton.setToolTipText("Launch URL"); urlLaunchButton.setEnabled(true); urlLaunchButton.setMargin(new Insets(0, 0, 0, 0)); urlLaunchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { String urlText = url.getText(); // Check if the selected url is null or emty and inform the user // via JoptioPane message if ((urlText == null) || (urlText.length() == 0)) { JOptionPane.showMessageDialog(urlLaunchButton.getParent(), Translator.translate("EmptyUrlJoptionpaneMsg"), Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE); // Check if the selected url is a valid formated url(via // urlIsValid() method) and inform the user via JoptioPane // message } else if (!(urlIsValid(urlText))) { JOptionPane.showMessageDialog(urlLaunchButton.getParent(), Translator.translate("InvalidUrlJoptionpaneMsg"), Translator.translate("UrlErrorJoptionpaneTitle"), JOptionPane.WARNING_MESSAGE); // Call the method LaunchSelectedURL() using the selected // url as input } else { LaunchSelectedURL(urlText); } } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; urlPanel.add(urlLaunchButton, c); JButton urlCopyButton = new JButton(); urlCopyButton.setIcon(Util.loadImage("copy-icon.png")); urlCopyButton.setToolTipText("Copy"); urlCopyButton.setEnabled(true); urlCopyButton.setMargin(new Insets(0, 0, 0, 0)); urlCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextField(url); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; urlPanel.add(urlCopyButton, c); JButton urlPasteButton = new JButton(); urlPasteButton.setIcon(Util.loadImage("paste-icon.png")); urlPasteButton.setToolTipText("Paste"); urlPasteButton.setEnabled(!readOnly); urlPasteButton.setMargin(new Insets(0, 0, 0, 0)); urlPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextField(url); } }); c.gridx = 3; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; urlPanel.add(urlPasteButton, c); c.gridx = 1; c.gridy = 3; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(urlPanel, c); // Notes Row JLabel notesLabel = new JLabel(Translator.translate("notes")); c.gridx = 0; c.gridy = 4; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; container.add(notesLabel, c); // This panel will hold the Notes text area and the copy and paste // buttons. JPanel notesPanel = new JPanel(new GridBagLayout()); notes = new JTextArea(new String(pAccount.getNotes()), 10, 20); if (readOnly) { notes.setEditable(false); } notes.setLineWrap(true); // Enable line wrapping. notes.setWrapStyleWord(true); // Line wrap at whitespace. JScrollPane notesScrollPane = new JScrollPane(notes); c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.BOTH; notesPanel.add(notesScrollPane, c); JButton notesCopyButton = new JButton(); notesCopyButton.setIcon(Util.loadImage("copy-icon.png")); notesCopyButton.setToolTipText("Copy"); notesCopyButton.setEnabled(true); notesCopyButton.setMargin(new Insets(0, 0, 0, 0)); notesCopyButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { copyTextArea(notes); } }); c.gridx = 1; c.gridy = 0; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; notesPanel.add(notesCopyButton, c); JButton notesPasteButton = new JButton(); notesPasteButton.setIcon(Util.loadImage("paste-icon.png")); notesPasteButton.setToolTipText("Paste"); notesPasteButton.setEnabled(!readOnly); notesPasteButton.setMargin(new Insets(0, 0, 0, 0)); notesPasteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { pasteToTextArea(notes); } }); c.gridx = 2; c.gridy = 0; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(0, 0, 0, 5); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; notesPanel.add(notesPasteButton, c); c.gridx = 1; c.gridy = 4; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(10, 10, 10, 10); c.weightx = 1; c.weighty = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; container.add(notesPanel, c); // Seperator Row JSeparator sep = new JSeparator(); c.gridx = 0; c.gridy = 5; c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(0, 0, 0, 0); c.weightx = 0; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; container.add(sep, c); // Button Row JPanel buttonPanel = new JPanel(); JButton okButton = new JButton(Translator.translate("ok")); // Link Enter key to okButton getRootPane().setDefaultButton(okButton); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { okButtonAction(); } }); buttonPanel.add(okButton); if (!readOnly) { JButton cancelButton = new JButton(Translator.translate("cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeButtonAction(); } }); buttonPanel.add(cancelButton); } c.gridx = 0; c.gridy = 6; c.anchor = GridBagConstraints.PAGE_END; c.insets = new Insets(5, 0, 5, 0); c.weightx = 0; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.NONE; container.add(buttonPanel, c); }
From source file:com.marginallyclever.makelangelo.MainGUI.java
protected void AdjustGraphics() { final Preferences graphics_prefs = Preferences.userRoot().node("DrawBot").node("Graphics"); final JDialog driver = new JDialog(mainframe, translator.get("MenuGraphicsTitle"), true); driver.setLayout(new GridBagLayout()); //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total")); //allow_metrics.setSelected(allowMetrics); final JCheckBox show_pen_up = new JCheckBox(translator.get("MenuGraphicsPenUp")); final JCheckBox antialias_on = new JCheckBox(translator.get("MenuGraphicsAntialias")); final JCheckBox speed_over_quality = new JCheckBox(translator.get("MenuGraphicsSpeedVSQuality")); final JCheckBox draw_all_while_running = new JCheckBox(translator.get("MenuGraphicsDrawWhileRunning")); show_pen_up.setSelected(graphics_prefs.getBoolean("show pen up", false)); antialias_on.setSelected(graphics_prefs.getBoolean("antialias", true)); speed_over_quality.setSelected(graphics_prefs.getBoolean("speed over quality", true)); draw_all_while_running.setSelected(graphics_prefs.getBoolean("Draw all while running", true)); final JButton cancel = new JButton(translator.get("Cancel")); final JButton save = new JButton(translator.get("Save")); GridBagConstraints c = new GridBagConstraints(); //c.gridwidth=4; c.gridx=0; c.gridy=0; driver.add(allow_metrics,c); int y = 0;//from w ww . j a v a 2 s. com c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(show_pen_up, c); y++; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(draw_all_while_running, c); y++; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(antialias_on, c); y++; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(speed_over_quality, c); y++; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.gridx = 2; c.gridy = y; driver.add(save, c); c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 3; c.gridy = y; driver.add(cancel, c); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == save) { //allowMetrics = allow_metrics.isSelected(); graphics_prefs.putBoolean("show pen up", show_pen_up.isSelected()); graphics_prefs.putBoolean("antialias", antialias_on.isSelected()); graphics_prefs.putBoolean("speed over quality", speed_over_quality.isSelected()); graphics_prefs.putBoolean("Draw all while running", draw_all_while_running.isSelected()); previewPane.setShowPenUp(show_pen_up.isSelected()); driver.dispose(); } if (subject == cancel) { driver.dispose(); } } }; save.addActionListener(driveButtons); cancel.addActionListener(driveButtons); driver.getRootPane().setDefaultButton(save); driver.pack(); driver.setVisible(true); }
From source file:neembuu.uploader.NeembuuUploader.java
void checkBox_selectFromPreviousState() { try {/* ww w. j a v a 2 s . c om*/ List<String> lines = Files.readAllLines(Application.getNeembuuHome().resolve("selectedhostslist"), Charset.forName("UTF-8")); OUTER_LOOP: for (String host : lines) { INNER_LOOP: for (Map.Entry<JCheckBox, SmallModuleEntry> entry : unsyncEntries_map()) { JCheckBox jCheckBox = entry.getKey(); SmallModuleEntry smallModuleEntry = entry.getValue(); if (smallModuleEntry.getName().equalsIgnoreCase(host)) { jCheckBox.setSelected(true); checkBoxActionListener.actionPerformed(null); continue OUTER_LOOP; } } } } catch (IOException ex) { Logger.getLogger(NeembuuUploader.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.declarativa.interprolog.gui.Ini2.java
private void graphComponents() throws IOException { Forest<String, Integer> forest = new DelegateForest<>(); ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest)); Layout layout = new BalloonLayout(forest); //Layout layout = new TreeLayout(forest, 70, 70); final BaseJungScene scene = new SceneImpl(g, layout); jLayeredPane1.setLayout(new BorderLayout()); //jf.setLayout(new BorderLayout()); jLayeredPane1.add(new JScrollPane(scene.createView()), BorderLayout.CENTER); //jf.add(new JScrollPane(scene.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 ww w. ja va 2 s . c om 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 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); 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 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()); jLayeredPane3.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(); } }); }
From source file:com.declarativa.interprolog.gui.Ini3.java
private void graphComponents() throws IOException { Forest<String, Integer> forest = new DelegateForest<>(); ObservableGraph g = new ObservableGraph(new BalloonLayoutDemo().createTree(forest)); Layout layout = new BalloonLayout(forest); //Layout layout = new TreeLayout(forest, 70, 70); final BaseJungScene scene = new SceneImpl(g, layout); jLayeredPane1.setLayout(new BorderLayout()); //jf.setLayout(new BorderLayout()); jLayeredPane1.add(new JScrollPane(scene.createView()), BorderLayout.CENTER); //jf.add(new JScrollPane(scene.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);/* w w w . j a va 2s. com*/ 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 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); 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 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()); jLayeredPane3.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(); } }); }
From source file:it.imtech.metadata.MetaUtility.java
/** * Metodo adibito alla creazione dinamica ricorsiva dell'interfaccia dei * metadati/*from w ww. j av a 2s .c o m*/ * * @param submetadatas Map contente i metadati e i sottolivelli di metadati * @param vocabularies Map contenente i dati contenuti nel file xml * vocabulary.xml * @param parent Jpanel nel quale devono venir inseriti i metadati * @param level Livello corrente */ public void create_metadata_view(Map<Object, Metadata> submetadatas, JPanel parent, int level, final String panelname) throws Exception { ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader); int lenght = submetadatas.size(); int labelwidth = 220; int i = 0; JButton addcontribute = null; for (Map.Entry<Object, Metadata> kv : submetadatas.entrySet()) { ArrayList<Component> tabobjects = new ArrayList<Component>(); if (kv.getValue().MID == 17 || kv.getValue().MID == 23 || kv.getValue().MID == 18 || kv.getValue().MID == 137) { continue; } //Crea un jpanel nuovo e fa appen su parent JPanel innerPanel = new JPanel(new MigLayout("fillx, insets 1 1 1 1")); innerPanel.setName("pannello" + level + i); i++; String datatype = kv.getValue().datatype.toString(); if (kv.getValue().MID == 45) { JPanel choice = new JPanel(new MigLayout()); JComboBox combo = addClassificationChoice(choice, kv.getValue().sequence, panelname); JLabel labelc = new JLabel(); labelc.setText(Utility.getBundleString("selectclassif", bundle)); labelc.setPreferredSize(new Dimension(100, 20)); choice.add(labelc); findLastClassification(panelname); if (last_classification != 0 && classificationRemoveButton == null) { logger.info("Removing last clasification"); classificationRemoveButton = new JButton("-"); classificationRemoveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); removeClassificationToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); findLastClassification(panelname); //update last_classification BookImporter.getInstance().setCursor(null); } }); if (Integer.parseInt(kv.getValue().sequence) == last_classification) { choice.add(classificationRemoveButton, "wrap, width :50:"); } } if (classificationAddButton == null) { logger.info("Adding a new classification"); choice.add(combo, "width 100:600:600"); classificationAddButton = new JButton("+"); classificationAddButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); addClassificationToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); BookImporter.getInstance().setCursor(null); } }); choice.add(classificationAddButton, "width :50:"); } else { //choice.add(combo, "wrap,width 100:700:700"); choice.add(combo, "width 100:700:700"); if (Integer.parseInt(kv.getValue().sequence) == last_classification) { choice.add(classificationRemoveButton, "wrap, width :50"); } } parent.add(choice, "wrap,width 100:700:700"); classificationMID = kv.getValue().MID; innerPanel.setName(panelname + "---ImPannelloClassif---" + kv.getValue().sequence); try { addClassification(innerPanel, classificationMID, kv.getValue().sequence, panelname); } catch (Exception ex) { logger.error("Errore nell'aggiunta delle classificazioni"); } parent.add(innerPanel, "wrap, growx"); BookImporter.policy.addIndexedComponent(combo); continue; } if (datatype.equals("Node")) { JLabel label = new JLabel(); label.setText(kv.getValue().description); label.setPreferredSize(new Dimension(100, 20)); int size = 16 - (level * 2); Font myFont = new Font("MS Sans Serif", Font.PLAIN, size); label.setFont(myFont); if (Integer.toString(kv.getValue().MID).equals("11")) { JPanel temppanel = new JPanel(new MigLayout()); //update last_contribute findLastContribute(panelname); if (last_contribute != 0 && removeContribute == null) { logger.info("Removing last contribute"); removeContribute = new JButton("-"); removeContribute.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance() .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); removeContributorToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); BookImporter.getInstance().setCursor(null); } }); if (!kv.getValue().sequence.equals("")) { if (Integer.parseInt(kv.getValue().sequence) == last_contribute) { innerPanel.add(removeContribute, "width :50:"); } } } if (addcontribute == null) { logger.info("Adding a new contribute"); addcontribute = new JButton("+"); addcontribute.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { BookImporter.getInstance() .setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); addContributorToMetadata(panelname); BookImporter.getInstance().refreshMetadataTab(false, panelname); BookImporter.getInstance().setCursor(null); } }); temppanel.add(label, " width :200:"); temppanel.add(addcontribute, "width :50:"); innerPanel.add(temppanel, "wrap, growx"); } else { temppanel.add(label, " width :200:"); findLastContribute(panelname); if (!kv.getValue().sequence.equals("")) { if (Integer.parseInt(kv.getValue().sequence) == last_contribute) { temppanel.add(removeContribute, "width :50:"); } } innerPanel.add(temppanel, "wrap, growx"); } } else if (Integer.toString(kv.getValue().MID).equals("115")) { logger.info("Devo gestire una provenience!"); } } else { String title = ""; if (kv.getValue().mandatory.equals("Y") || kv.getValue().MID == 14 || kv.getValue().MID == 15) { title = kv.getValue().description + " *"; } else { title = kv.getValue().description; } innerPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), title, TitledBorder.LEFT, TitledBorder.TOP)); if (datatype.equals("Vocabulary")) { TreeMap<String, String> entryCombo = new TreeMap<String, String>(); int index = 0; String selected = null; if (!Integer.toString(kv.getValue().MID).equals("8")) entryCombo.put(Utility.getBundleString("comboselect", bundle), Utility.getBundleString("comboselect", bundle)); for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) { String tempmid = Integer.toString(kv.getValue().MID); if (Integer.toString(kv.getValue().MID_parent).equals("11") || Integer.toString(kv.getValue().MID_parent).equals("13")) { String[] testmid = tempmid.split("---"); tempmid = testmid[0]; } if (vc.getKey().equals(tempmid)) { TreeMap<String, VocEntry> iEntry = vc.getValue(); for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) { entryCombo.put(ivc.getValue().description, ivc.getValue().ID); if (kv.getValue().value != null) { if (kv.getValue().value.equals(ivc.getValue().ID)) { selected = ivc.getValue().ID; } } index++; } } } final ComboMapImpl model = new ComboMapImpl(); model.setVocabularyCombo(true); model.putAll(entryCombo); final JComboBox voc = new javax.swing.JComboBox(model); model.specialRenderCombo(voc); if (Integer.toString(kv.getValue().MID_parent).equals("11") || Integer.toString(kv.getValue().MID_parent).equals("13")) { voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence); } else { voc.setName("MID_" + Integer.toString(kv.getValue().MID)); } if (Integer.toString(kv.getValue().MID).equals("8") && selected == null) selected = "44"; selected = (selected == null) ? Utility.getBundleString("comboselect", bundle) : selected; for (int k = 0; k < voc.getItemCount(); k++) { Map.Entry<String, String> el = (Map.Entry<String, String>) voc.getItemAt(k); if (el.getValue().equals(selected)) voc.setSelectedIndex(k); } voc.setPreferredSize(new Dimension(150, 30)); innerPanel.add(voc, "wrap, width :400:"); tabobjects.add(voc); } else if (datatype.equals("CharacterString") || datatype.equals("GPS")) { final JTextArea textField = new javax.swing.JTextArea(); if (Integer.toString(kv.getValue().MID_parent).equals("11") || Integer.toString(kv.getValue().MID_parent).equals("13")) { textField.setName( "MID_" + Integer.toString(kv.getValue().MID) + "---" + kv.getValue().sequence); } else { textField.setName("MID_" + Integer.toString(kv.getValue().MID)); } textField.setPreferredSize(new Dimension(230, 0)); textField.setText(kv.getValue().value); textField.setLineWrap(true); textField.setWrapStyleWord(true); innerPanel.add(textField, "wrap, width :300:"); textField.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { if (e.getModifiers() > 0) { textField.transferFocusBackward(); } else { textField.transferFocus(); } e.consume(); } } }); tabobjects.add(textField); } else if (datatype.equals("LangString")) { JScrollPane inner_scroll = new javax.swing.JScrollPane(); inner_scroll.setHorizontalScrollBarPolicy( javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); inner_scroll.setVerticalScrollBarPolicy( javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); inner_scroll.setPreferredSize(new Dimension(240, 80)); inner_scroll.setName("langStringScroll"); final JTextArea jTextArea1 = new javax.swing.JTextArea(); jTextArea1.setName("MID_" + Integer.toString(kv.getValue().MID)); jTextArea1.setText(kv.getValue().value); jTextArea1.setSize(new Dimension(350, 70)); jTextArea1.setLineWrap(true); jTextArea1.setWrapStyleWord(true); inner_scroll.setViewportView(jTextArea1); innerPanel.add(inner_scroll, "width :300:"); //Add combo language box JComboBox voc = getComboLangBox(kv.getValue().language); voc.setName("MID_" + Integer.toString(kv.getValue().MID) + "_lang"); voc.setPreferredSize(new Dimension(200, 20)); innerPanel.add(voc, "wrap, width :300:"); jTextArea1.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_TAB) { if (e.getModifiers() > 0) { jTextArea1.transferFocusBackward(); } else { jTextArea1.transferFocus(); } e.consume(); } } }); tabobjects.add(jTextArea1); tabobjects.add(voc); } else if (datatype.equals("Language")) { final JComboBox voc = getComboLangBox(kv.getValue().value); voc.setName("MID_" + Integer.toString(kv.getValue().MID)); voc.setPreferredSize(new Dimension(150, 20)); voc.setBounds(5, 5, 150, 20); innerPanel.add(voc, "wrap, width :500:"); //BookImporter.policy.addIndexedComponent(voc); tabobjects.add(voc); } else if (datatype.equals("Boolean")) { int selected = 0; TreeMap bin = new TreeMap<String, String>(); bin.put("yes", Utility.getBundleString("voc1", bundle)); bin.put("no", Utility.getBundleString("voc2", bundle)); if (kv.getValue().value == null) { switch (kv.getValue().MID) { case 35: selected = 0; break; case 36: selected = 1; break; } } else if (kv.getValue().value.equals("yes")) { selected = 1; } else { selected = 0; } final ComboMapImpl model = new ComboMapImpl(); model.putAll(bin); final JComboBox voc = new javax.swing.JComboBox(model); model.specialRenderCombo(voc); voc.setName("MID_" + Integer.toString(kv.getValue().MID)); voc.setSelectedIndex(selected); voc.setPreferredSize(new Dimension(150, 20)); voc.setBounds(5, 5, 150, 20); innerPanel.add(voc, "wrap, width :300:"); //BookImporter.policy.addIndexedComponent(voc); tabobjects.add(voc); } else if (datatype.equals("License")) { String selectedIndex = null; int vindex = 0; int defaultIndex = 0; TreeMap<String, String> entryCombo = new TreeMap<String, String>(); for (Map.Entry<String, TreeMap<String, VocEntry>> vc : vocabularies.entrySet()) { if (vc.getKey().equals(Integer.toString(kv.getValue().MID))) { TreeMap<String, VocEntry> iEntry = vc.getValue(); for (Map.Entry<String, VocEntry> ivc : iEntry.entrySet()) { entryCombo.put(ivc.getValue().description, ivc.getValue().ID); if (ivc.getValue().ID.equals("1")) defaultIndex = vindex; if (kv.getValue().value != null) { if (ivc.getValue().ID.equals(kv.getValue().value)) { selectedIndex = Integer.toString(vindex); } } vindex++; } } } if (selectedIndex == null) selectedIndex = Integer.toString(defaultIndex); ComboMapImpl model = new ComboMapImpl(); model.putAll(entryCombo); model.setVocabularyCombo(true); JComboBox voc = new javax.swing.JComboBox(model); model.specialRenderCombo(voc); voc.setName("MID_" + Integer.toString(kv.getValue().MID)); voc.setSelectedIndex(Integer.parseInt(selectedIndex)); voc.setPreferredSize(new Dimension(150, 20)); voc.setBounds(5, 5, 150, 20); innerPanel.add(voc, "wrap, width :500:"); //BookImporter.policy.addIndexedComponent(voc); tabobjects.add(voc); } else if (datatype.equals("DateTime")) { //final JXDatePicker datePicker = new JXDatePicker(); JDateChooser datePicker = new JDateChooser(); datePicker.setName("MID_" + Integer.toString(kv.getValue().MID)); JPanel test = new JPanel(new MigLayout()); JLabel lbefore = new JLabel(Utility.getBundleString("beforechristlabel", bundle)); JCheckBox beforechrist = new JCheckBox(); beforechrist.setName("MID_" + Integer.toString(kv.getValue().MID) + "_check"); if (kv.getValue().value != null) { try { if (kv.getValue().value.charAt(0) == '-') { beforechrist.setSelected(true); } Date date1 = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); if (kv.getValue().value.charAt(0) == '-') { date1 = sdf.parse(adjustDate(kv.getValue().value)); } else { date1 = sdf.parse(kv.getValue().value); } datePicker.setDate(date1); } catch (Exception e) { //Console.WriteLine("ERROR import date:" + ex.Message); } } test.add(datePicker, "width :200:"); test.add(lbefore, "gapleft 30"); test.add(beforechrist, "wrap"); innerPanel.add(test, "wrap"); } } //Recursive call create_metadata_view(kv.getValue().submetadatas, innerPanel, level + 1, panelname); if (kv.getValue().editable.equals("Y") || (datatype.equals("Node") && kv.getValue().hidden.equals("0"))) { parent.add(innerPanel, "wrap, growx"); for (Component tabobject : tabobjects) { BookImporter.policy.addIndexedComponent(tabobject); } } } }
From source file:edu.snu.leader.discrete.simulator.SimulatorLauncherGUI.java
/** * Create the frame./*from w ww .j a va2 s. c o m*/ */ public SimulatorLauncherGUI() { NumberFormat countFormat = NumberFormat.getNumberInstance(); countFormat.setParseIntegerOnly(true); NumberFormat doubleFormat = NumberFormat.getNumberInstance(); doubleFormat.setMinimumIntegerDigits(1); doubleFormat.setMaximumFractionDigits(10); setTitle("Simulator"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 515, 340); setResizable(false); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); tabbedPane = new JTabbedPane(JTabbedPane.TOP); contentPane.add(tabbedPane, BorderLayout.CENTER); JPanel panelTab1 = new JPanel(); tabbedPane.addTab("Simulator", null, panelTab1, null); JPanel panelAgentCount = new JPanel(); panelTab1.add(panelAgentCount); JLabel lblNewLabel = new JLabel("Agent Count"); panelAgentCount.add(lblNewLabel); sliderAgent = new JSlider(); panelAgentCount.add(sliderAgent); sliderAgent.setValue(10); sliderAgent.setSnapToTicks(true); sliderAgent.setPaintTicks(true); sliderAgent.setPaintLabels(true); sliderAgent.setMinorTickSpacing(10); sliderAgent.setMajorTickSpacing(10); sliderAgent.setMinimum(10); sliderAgent.setMaximum(70); sliderAgent.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent arg0) { Integer spinnerValue = (Integer) spinnerMaxEaten.getValue(); if (spinnerValue > sliderAgent.getValue()) { spinnerValue = sliderAgent.getValue(); } spinnerMaxEaten.setModel(new SpinnerNumberModel(spinnerValue, new Integer(0), new Integer(sliderAgent.getValue()), new Integer(1))); JFormattedTextField tfMaxEaten = ((JSpinner.DefaultEditor) spinnerMaxEaten.getEditor()) .getTextField(); tfMaxEaten.setEditable(false); } }); JPanel panelCommType = new JPanel(); panelTab1.add(panelCommType); JLabel lblNewLabel_1 = new JLabel("Communication Type"); panelCommType.add(lblNewLabel_1); comboBoxCommType = new JComboBox<String>(); panelCommType.add(comboBoxCommType); comboBoxCommType .setModel(new DefaultComboBoxModel<String>(new String[] { "Global", "Topological", "Metric" })); comboBoxCommType.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxCommType.getSelectedItem(); if (item.equals("Topological")) { panelNearestNeighborCount.setVisible(true); panelMaxLocationRadius.setVisible(false); } else if (item.equals("Metric")) { panelNearestNeighborCount.setVisible(false); panelMaxLocationRadius.setVisible(true); } else if (item.equals("Global")) { panelNearestNeighborCount.setVisible(false); panelMaxLocationRadius.setVisible(false); } } }); JPanel panelDestinationRadius = new JPanel(); panelTab1.add(panelDestinationRadius); JLabel lblDestinationRadius = new JLabel("Destination Radius"); panelDestinationRadius.add(lblDestinationRadius); frmtdtxtfldDestinationRadius = new JFormattedTextField(doubleFormat); frmtdtxtfldDestinationRadius.setColumns(4); frmtdtxtfldDestinationRadius.setValue((Number) 10); panelDestinationRadius.add(frmtdtxtfldDestinationRadius); JPanel panelResultsOutput = new JPanel(); panelTab1.add(panelResultsOutput); JLabel lblResultsOutput = new JLabel("Results Output"); panelResultsOutput.add(lblResultsOutput); final JCheckBox chckbxEskridge = new JCheckBox("Eskridge"); panelResultsOutput.add(chckbxEskridge); final JCheckBox chckbxConflict = new JCheckBox("Conflict"); panelResultsOutput.add(chckbxConflict); final JCheckBox chckbxPosition = new JCheckBox("Position"); panelResultsOutput.add(chckbxPosition); final JCheckBox chckbxPredationResults = new JCheckBox("Predation"); panelResultsOutput.add(chckbxPredationResults); JPanel panelMisc = new JPanel(); panelTab1.add(panelMisc); JLabel lblNewLabel_3 = new JLabel("Misc"); panelMisc.add(lblNewLabel_3); chckbxGraphical = new JCheckBox("Graphical?"); chckbxGraphical.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxGraphical.isSelected()) { frmtdtxtfldRunCount.setValue((Number) 1); frmtdtxtfldRunCount.setEnabled(false); chckbxEskridge.setSelected(false); chckbxEskridge.setEnabled(false); String agentBuilder = (String) comboBoxAgentBuilder.getSelectedItem(); if (agentBuilder.equals("Default")) { comboBoxAgentBuilder.setSelectedIndex(1); } } else { chckbxEskridge.setEnabled(true); frmtdtxtfldRunCount.setEnabled(true); } } }); panelMisc.add(chckbxGraphical); chckbxRandomSeed = new JCheckBox("Random Seed?"); panelMisc.add(chckbxRandomSeed); chckbxPredationEnable = new JCheckBox("Predation?"); chckbxPredationEnable.setSelected(true); chckbxPredationEnable.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxPredationEnable.isSelected()) { panelPredationStuff.setVisible(true); panelPredationBoxes.setVisible(true); panelPredationConstant.setVisible(true); panelNonMoversSurvive.setVisible(true); } else { panelPredationStuff.setVisible(false); panelPredationBoxes.setVisible(false); panelPredationConstant.setVisible(false); panelNonMoversSurvive.setVisible(false); } } }); panelMisc.add(chckbxPredationEnable); JPanel panelCounts = new JPanel(); panelTab1.add(panelCounts); JLabel lblNewLabel_4 = new JLabel("Run Count"); panelCounts.add(lblNewLabel_4); frmtdtxtfldRunCount = new JFormattedTextField(countFormat); frmtdtxtfldRunCount.setToolTipText("The number of runs. Each run has a different random seed."); panelCounts.add(frmtdtxtfldRunCount); frmtdtxtfldRunCount.setColumns(4); frmtdtxtfldRunCount.setValue((Number) 1); JLabel lblNewLabel_5 = new JLabel("Sim Count"); panelCounts.add(lblNewLabel_5); frmtdtxtfldSimCount = new JFormattedTextField(countFormat); frmtdtxtfldSimCount .setToolTipText("The number of simulations per run. Each simulation uses the same random seed."); frmtdtxtfldSimCount.setColumns(4); frmtdtxtfldSimCount.setValue((Number) 1); panelCounts.add(frmtdtxtfldSimCount); JLabel lblNewLabel_6 = new JLabel("Max Time Steps"); panelCounts.add(lblNewLabel_6); frmtdtxtfldMaxTimeSteps = new JFormattedTextField(countFormat); frmtdtxtfldMaxTimeSteps.setToolTipText("The max number of time steps per simulation."); frmtdtxtfldMaxTimeSteps.setColumns(6); frmtdtxtfldMaxTimeSteps.setValue((Number) 20000); panelCounts.add(frmtdtxtfldMaxTimeSteps); ////////Panel tab 2 JPanel panelTab2 = new JPanel(); tabbedPane.addTab("Parameters", null, panelTab2, null); JPanel panelDecisionCalculator = new JPanel(); panelTab2.add(panelDecisionCalculator); JLabel lblDecisionCalculator = new JLabel("Decision Calculator"); panelDecisionCalculator.add(lblDecisionCalculator); final JComboBox<String> comboBoxDecisionCalculator = new JComboBox<String>(); panelDecisionCalculator.add(comboBoxDecisionCalculator); comboBoxDecisionCalculator.setModel( new DefaultComboBoxModel<String>(new String[] { "Default", "Conflict", "Conflict Uninformed" })); JPanel panelAgentBuilder = new JPanel(); panelTab2.add(panelAgentBuilder); JLabel lblAgentBuilder = new JLabel("Agent Builder"); panelAgentBuilder.add(lblAgentBuilder); comboBoxAgentBuilder = new JComboBox<String>(); panelAgentBuilder.add(comboBoxAgentBuilder); comboBoxAgentBuilder.setModel(new DefaultComboBoxModel<String>(new String[] { "Default", "Simple Angular", "Personality Simple Angular", "Simple Angular Uninformed" })); comboBoxAgentBuilder.setSelectedIndex(1); comboBoxAgentBuilder.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { if (chckbxGraphical.isSelected()) { String agentBuilder = (String) comboBoxAgentBuilder.getSelectedItem(); if (agentBuilder.equals("Default")) { comboBoxAgentBuilder.setSelectedIndex(1); } } } }); JPanel panelModel = new JPanel(); panelTab2.add(panelModel); JLabel lblModel = new JLabel("Model"); panelModel.add(lblModel); comboBoxModel = new JComboBox<String>(); panelModel.add(comboBoxModel); comboBoxModel.setModel(new DefaultComboBoxModel<String>(new String[] { "Sueur", "Gautrais" })); comboBoxModel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxModel.getSelectedItem(); if (item.equals("Sueur")) { panelSueurValues.setVisible(true); panelGautraisValues.setVisible(false); } else if (item.equals("Gautrais")) { panelSueurValues.setVisible(false); panelGautraisValues.setVisible(true); } } }); JPanel panelEnvironment = new JPanel(); panelTab2.add(panelEnvironment); JLabel lblEnvironment = new JLabel("Environment"); panelEnvironment.add(lblEnvironment); comboBoxEnvironment = new JComboBox<String>(); comboBoxEnvironment.setModel( new DefaultComboBoxModel<String>(new String[] { "Minimum", "Medium", "Maximum", "Uninformed" })); comboBoxEnvironment.setSelectedIndex(1); comboBoxEnvironment.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { String item = (String) comboBoxEnvironment.getSelectedItem(); if (!item.equals("Uninformed")) { comboBoxDecisionCalculator.setEnabled(true); comboBoxAgentBuilder.setEnabled(true); } if (item.equals("Medium")) { panelAngle.setVisible(true); panelDistance.setVisible(true); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Minimum")) { panelAngle.setVisible(false); panelDistance.setVisible(false); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Maximum")) { panelAngle.setVisible(false); panelDistance.setVisible(false); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(false); } else if (item.equals("Uninformed")) { panelAngle.setVisible(true); panelDistance.setVisible(true); panelPercentage.setVisible(true); panelNumberOfDestinations.setVisible(false); panelInformedCount.setVisible(true); comboBoxDecisionCalculator.setSelectedIndex(2); comboBoxDecisionCalculator.setEnabled(false); comboBoxAgentBuilder.setSelectedIndex(3); comboBoxAgentBuilder.setEnabled(false); } } }); panelEnvironment.add(comboBoxEnvironment); JPanel panelDefaultConflict = new JPanel(); panelTab2.add(panelDefaultConflict); JLabel lblDefaultConflict = new JLabel("Default Conflict"); panelDefaultConflict.add(lblDefaultConflict); final JSpinner spinnerDefaultConflict = new JSpinner(); panelDefaultConflict.add(spinnerDefaultConflict); spinnerDefaultConflict.setModel( new SpinnerNumberModel(new Float(0.9f), new Float(0.1f), new Float(0.91f), new Float(0.05))); JFormattedTextField tfSpinnerConflict = ((JSpinner.DefaultEditor) spinnerDefaultConflict.getEditor()) .getTextField(); tfSpinnerConflict.setEditable(false); JPanel panelCancelationThreshold = new JPanel(); panelTab2.add(panelCancelationThreshold); JLabel lblCancelationThreshold = new JLabel("Cancelation Threshold"); panelCancelationThreshold.add(lblCancelationThreshold); final JSpinner spinnerCancelationThreshold = new JSpinner(); panelCancelationThreshold.add(spinnerCancelationThreshold); spinnerCancelationThreshold.setModel( new SpinnerNumberModel(new Float(1.0f), new Float(0.0f), new Float(1.01f), new Float(0.05))); JFormattedTextField tfCancelationThreshold = ((JSpinner.DefaultEditor) spinnerCancelationThreshold .getEditor()).getTextField(); tfCancelationThreshold.setEditable(false); JPanel panelStopAnywhere = new JPanel(); panelTab2.add(panelStopAnywhere); final JCheckBox chckbxStopAnywhere = new JCheckBox("Stop Anywhere?"); panelStopAnywhere.add(chckbxStopAnywhere); panelNearestNeighborCount = new JPanel(); panelNearestNeighborCount.setVisible(false); panelTab2.add(panelNearestNeighborCount); JLabel lblNearestNeighborCount = new JLabel("Nearest Neighbor Count"); panelNearestNeighborCount.add(lblNearestNeighborCount); frmtdtxtfldNearestNeighborCount = new JFormattedTextField(countFormat); panelNearestNeighborCount.add(frmtdtxtfldNearestNeighborCount); frmtdtxtfldNearestNeighborCount.setColumns(3); frmtdtxtfldNearestNeighborCount.setValue((Number) 10); panelMaxLocationRadius = new JPanel(); panelMaxLocationRadius.setVisible(false); panelTab2.add(panelMaxLocationRadius); JLabel lblMaxLocationRadius = new JLabel("Max Location Radius"); panelMaxLocationRadius.add(lblMaxLocationRadius); frmtdtxtfldMaxLocationRadius = new JFormattedTextField(doubleFormat); panelMaxLocationRadius.add(frmtdtxtfldMaxLocationRadius); frmtdtxtfldMaxLocationRadius.setColumns(5); frmtdtxtfldMaxLocationRadius.setValue((Number) 10.0); panelPredationBoxes = new JPanel(); panelTab2.add(panelPredationBoxes); final JCheckBox chckbxUsePredationThreshold = new JCheckBox("Use Predation Threshold"); panelPredationBoxes.add(chckbxUsePredationThreshold); final JCheckBox chckbxPopulationIndependent = new JCheckBox("Population Independent"); chckbxPopulationIndependent.setSelected(true); panelPredationBoxes.add(chckbxPopulationIndependent); chckbxPopulationIndependent.setToolTipText( "Select this to allow predation to be independent of population size. Max predation for 10 agents will be the same as for 50 agents. "); panelPredationStuff = new JPanel(); panelTab2.add(panelPredationStuff); JLabel lblPredationMinimum = new JLabel("Predation Minimum"); panelPredationStuff.add(lblPredationMinimum); frmtdtxtfldPredationMinimum = new JFormattedTextField(doubleFormat); frmtdtxtfldPredationMinimum.setColumns(4); frmtdtxtfldPredationMinimum.setValue((Number) 0.0); panelPredationStuff.add(frmtdtxtfldPredationMinimum); JLabel lblPredationThreshold = new JLabel("Predation Threshold"); panelPredationStuff.add(lblPredationThreshold); final JSpinner spinnerPredationThreshold = new JSpinner(); panelPredationStuff.add(spinnerPredationThreshold); spinnerPredationThreshold.setModel( new SpinnerNumberModel(new Float(1.0f), new Float(0.0f), new Float(1.01f), new Float(0.05))); JFormattedTextField tfPredationThreshold = ((JSpinner.DefaultEditor) spinnerPredationThreshold.getEditor()) .getTextField(); tfPredationThreshold.setEditable(false); JLabel lblMaxEaten = new JLabel("Max Eaten"); panelPredationStuff.add(lblMaxEaten); spinnerMaxEaten = new JSpinner(); spinnerMaxEaten.setToolTipText("The max number eaten per time step."); panelPredationStuff.add(spinnerMaxEaten); spinnerMaxEaten.setModel(new SpinnerNumberModel(new Integer(10), new Integer(0), new Integer(sliderAgent.getValue()), new Integer(1))); JFormattedTextField tfMaxEaten = ((JSpinner.DefaultEditor) spinnerMaxEaten.getEditor()).getTextField(); tfMaxEaten.setEditable(false); panelPredationConstant = new JPanel(); panelTab2.add(panelPredationConstant); JLabel lblPredationConstant = new JLabel("Predation Constant"); panelPredationConstant.add(lblPredationConstant); frmtdtxtfldPredationConstant = new JFormattedTextField(doubleFormat); panelPredationConstant.add(frmtdtxtfldPredationConstant); frmtdtxtfldPredationConstant.setToolTipText("Value should be positive. Recommended values are near 0.001"); frmtdtxtfldPredationConstant.setColumns(4); frmtdtxtfldPredationConstant.setValue((Number) 0.001); panelNonMoversSurvive = new JPanel(); panelTab2.add(panelNonMoversSurvive); final JCheckBox chckbxNonMoversSurvive = new JCheckBox("Non-movers Survive?"); chckbxNonMoversSurvive.setSelected(false); panelNonMoversSurvive.add(chckbxNonMoversSurvive); ////////Tab 3 JPanel panelTab3 = new JPanel(); tabbedPane.addTab("Environment", null, panelTab3, null); panelTab3.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5)); panelSueurValues = new JPanel(); panelTab3.add(panelSueurValues); panelSueurValues.setLayout(new BoxLayout(panelSueurValues, BoxLayout.Y_AXIS)); JLabel lblSueurValues = new JLabel("Sueur Values"); lblSueurValues.setHorizontalAlignment(SwingConstants.TRAILING); lblSueurValues.setAlignmentX(Component.CENTER_ALIGNMENT); panelSueurValues.add(lblSueurValues); JPanel panelAlpha = new JPanel(); FlowLayout flowLayout = (FlowLayout) panelAlpha.getLayout(); flowLayout.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelAlpha); JLabel lblAlpha = new JLabel("alpha"); lblAlpha.setHorizontalAlignment(SwingConstants.CENTER); panelAlpha.add(lblAlpha); final JFormattedTextField frmtdtxtfldAlpha = new JFormattedTextField(doubleFormat); frmtdtxtfldAlpha.setHorizontalAlignment(SwingConstants.TRAILING); lblAlpha.setLabelFor(frmtdtxtfldAlpha); panelAlpha.add(frmtdtxtfldAlpha); frmtdtxtfldAlpha.setColumns(6); frmtdtxtfldAlpha.setValue((Number) 0.006161429); JPanel panelAlphaC = new JPanel(); FlowLayout flowLayout_2 = (FlowLayout) panelAlphaC.getLayout(); flowLayout_2.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelAlphaC); JLabel lblAlphaC = new JLabel("alpha c"); panelAlphaC.add(lblAlphaC); final JFormattedTextField frmtdtxtfldAlphaC = new JFormattedTextField(doubleFormat); frmtdtxtfldAlphaC.setHorizontalAlignment(SwingConstants.TRAILING); lblAlphaC.setLabelFor(frmtdtxtfldAlphaC); panelAlphaC.add(frmtdtxtfldAlphaC); frmtdtxtfldAlphaC.setColumns(6); frmtdtxtfldAlphaC.setValue((Number) 0.009); JPanel panelBeta = new JPanel(); FlowLayout flowLayout_1 = (FlowLayout) panelBeta.getLayout(); flowLayout_1.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelBeta); JLabel lblBeta = new JLabel("beta"); panelBeta.add(lblBeta); final JFormattedTextField frmtdtxtfldBeta = new JFormattedTextField(doubleFormat); frmtdtxtfldBeta.setHorizontalAlignment(SwingConstants.TRAILING); panelBeta.add(frmtdtxtfldBeta); frmtdtxtfldBeta.setColumns(6); frmtdtxtfldBeta.setValue((Number) 0.013422819); JPanel panelBetaC = new JPanel(); FlowLayout flowLayout_14 = (FlowLayout) panelBetaC.getLayout(); flowLayout_14.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelBetaC); JLabel lblBetaC = new JLabel("beta c"); panelBetaC.add(lblBetaC); final JFormattedTextField frmtdtxtfldBetaC = new JFormattedTextField(doubleFormat); frmtdtxtfldBetaC.setHorizontalAlignment(SwingConstants.TRAILING); panelBetaC.add(frmtdtxtfldBetaC); frmtdtxtfldBetaC.setColumns(6); frmtdtxtfldBetaC.setValue((Number) (-0.009)); JPanel panelS = new JPanel(); FlowLayout flowLayout_3 = (FlowLayout) panelS.getLayout(); flowLayout_3.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelS); JLabel lblS = new JLabel("S"); panelS.add(lblS); final JFormattedTextField frmtdtxtfldS = new JFormattedTextField(countFormat); frmtdtxtfldS.setHorizontalAlignment(SwingConstants.TRAILING); panelS.add(frmtdtxtfldS); frmtdtxtfldS.setColumns(6); frmtdtxtfldS.setValue((Number) 2); JPanel panelQ = new JPanel(); FlowLayout flowLayout_4 = (FlowLayout) panelQ.getLayout(); flowLayout_4.setAlignment(FlowLayout.RIGHT); panelSueurValues.add(panelQ); JLabel lblQ = new JLabel("q"); panelQ.add(lblQ); final JFormattedTextField frmtdtxtfldQ = new JFormattedTextField(doubleFormat); frmtdtxtfldQ.setHorizontalAlignment(SwingConstants.TRAILING); panelQ.add(frmtdtxtfldQ); frmtdtxtfldQ.setColumns(6); frmtdtxtfldQ.setValue((Number) 2.3); panelGautraisValues = new JPanel(); panelGautraisValues.setVisible(false); panelTab3.add(panelGautraisValues); panelGautraisValues.setLayout(new BoxLayout(panelGautraisValues, BoxLayout.Y_AXIS)); JLabel label = new JLabel("Gautrais Values"); label.setAlignmentX(Component.CENTER_ALIGNMENT); panelGautraisValues.add(label); JPanel panelTauO = new JPanel(); FlowLayout flowLayout_5 = (FlowLayout) panelTauO.getLayout(); flowLayout_5.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelTauO); JLabel lblTauO = new JLabel("tau o"); panelTauO.add(lblTauO); final JFormattedTextField frmtdtxtfldTaoO = new JFormattedTextField(doubleFormat); frmtdtxtfldTaoO.setHorizontalAlignment(SwingConstants.TRAILING); panelTauO.add(frmtdtxtfldTaoO); frmtdtxtfldTaoO.setColumns(4); frmtdtxtfldTaoO.setValue((Number) 1290); JPanel panelGammaC = new JPanel(); FlowLayout flowLayout_6 = (FlowLayout) panelGammaC.getLayout(); flowLayout_6.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelGammaC); JLabel lblGammaC = new JLabel("gamma c"); panelGammaC.add(lblGammaC); final JFormattedTextField frmtdtxtfldGammaC = new JFormattedTextField(doubleFormat); frmtdtxtfldGammaC.setHorizontalAlignment(SwingConstants.TRAILING); panelGammaC.add(frmtdtxtfldGammaC); frmtdtxtfldGammaC.setColumns(4); frmtdtxtfldGammaC.setValue((Number) 2.0); JPanel panelEpsilonC = new JPanel(); FlowLayout flowLayout_7 = (FlowLayout) panelEpsilonC.getLayout(); flowLayout_7.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelEpsilonC); JLabel lblEpsilonC = new JLabel("epsilon c"); panelEpsilonC.add(lblEpsilonC); final JFormattedTextField frmtdtxtfldEpsilonC = new JFormattedTextField(doubleFormat); frmtdtxtfldEpsilonC.setHorizontalAlignment(SwingConstants.TRAILING); panelEpsilonC.add(frmtdtxtfldEpsilonC); frmtdtxtfldEpsilonC.setColumns(4); frmtdtxtfldEpsilonC.setValue((Number) 2.3); JPanel panelAlphaF = new JPanel(); FlowLayout flowLayout_8 = (FlowLayout) panelAlphaF.getLayout(); flowLayout_8.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelAlphaF); JLabel lblAlphaF = new JLabel("alpha f"); panelAlphaF.add(lblAlphaF); final JFormattedTextField frmtdtxtfldAlphaF = new JFormattedTextField(doubleFormat); frmtdtxtfldAlphaF.setHorizontalAlignment(SwingConstants.TRAILING); panelAlphaF.add(frmtdtxtfldAlphaF); frmtdtxtfldAlphaF.setColumns(4); frmtdtxtfldAlphaF.setValue((Number) 162.3); JPanel panelBetaF = new JPanel(); FlowLayout flowLayout_9 = (FlowLayout) panelBetaF.getLayout(); flowLayout_9.setAlignment(FlowLayout.RIGHT); panelGautraisValues.add(panelBetaF); JLabel lblBetaF = new JLabel("beta f"); panelBetaF.add(lblBetaF); final JFormattedTextField frmtdtxtfldBetaF = new JFormattedTextField(doubleFormat); frmtdtxtfldBetaF.setHorizontalAlignment(SwingConstants.TRAILING); panelBetaF.add(frmtdtxtfldBetaF); frmtdtxtfldBetaF.setColumns(4); frmtdtxtfldBetaF.setValue((Number) 75.4); JPanel panelEnvironmentVariables = new JPanel(); panelTab3.add(panelEnvironmentVariables); panelEnvironmentVariables.setLayout(new BoxLayout(panelEnvironmentVariables, BoxLayout.Y_AXIS)); JLabel lblEnvironmentVariables = new JLabel("Environment Variables"); lblEnvironmentVariables.setAlignmentX(Component.CENTER_ALIGNMENT); panelEnvironmentVariables.add(lblEnvironmentVariables); panelAngle = new JPanel(); FlowLayout flowLayout_10 = (FlowLayout) panelAngle.getLayout(); flowLayout_10.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelAngle); JLabel lblAngle = new JLabel("Angle"); panelAngle.add(lblAngle); final JFormattedTextField frmtdtxtfldAngle = new JFormattedTextField(doubleFormat); frmtdtxtfldAngle.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldAngle.setToolTipText("Angle between destinations"); panelAngle.add(frmtdtxtfldAngle); frmtdtxtfldAngle.setColumns(3); frmtdtxtfldAngle.setValue((Number) 72.00); panelNumberOfDestinations = new JPanel(); FlowLayout flowLayout_13 = (FlowLayout) panelNumberOfDestinations.getLayout(); flowLayout_13.setAlignment(FlowLayout.RIGHT); panelNumberOfDestinations.setVisible(false); panelEnvironmentVariables.add(panelNumberOfDestinations); JLabel lblNumberOfDestinations = new JLabel("Number of Destinations"); panelNumberOfDestinations.add(lblNumberOfDestinations); JFormattedTextField frmtdtxtfldNumberOfDestinations = new JFormattedTextField(countFormat); frmtdtxtfldNumberOfDestinations.setHorizontalAlignment(SwingConstants.TRAILING); panelNumberOfDestinations.add(frmtdtxtfldNumberOfDestinations); frmtdtxtfldNumberOfDestinations.setColumns(3); frmtdtxtfldNumberOfDestinations.setValue((Number) 2); panelDistance = new JPanel(); FlowLayout flowLayout_11 = (FlowLayout) panelDistance.getLayout(); flowLayout_11.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelDistance); JLabel lblDistance = new JLabel("Distance"); panelDistance.add(lblDistance); frmtdtxtfldDistance = new JFormattedTextField(doubleFormat); frmtdtxtfldDistance.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldDistance.setToolTipText("Distance the destination is from origin (0,0)"); panelDistance.add(frmtdtxtfldDistance); frmtdtxtfldDistance.setColumns(3); frmtdtxtfldDistance.setValue((Number) 150.0); panelPercentage = new JPanel(); FlowLayout flowLayout_12 = (FlowLayout) panelPercentage.getLayout(); flowLayout_12.setAlignment(FlowLayout.RIGHT); panelEnvironmentVariables.add(panelPercentage); JLabel lblPercentage = new JLabel("Percentage"); panelPercentage.add(lblPercentage); frmtdtxtfldPercentage = new JFormattedTextField(doubleFormat); frmtdtxtfldPercentage.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldPercentage.setToolTipText( "The percentage moving to one of the two destinations ( The other gets 1 - percentage)."); panelPercentage.add(frmtdtxtfldPercentage); frmtdtxtfldPercentage.setColumns(3); frmtdtxtfldPercentage.setValue((Number) 0.500); panelInformedCount = new JPanel(); panelEnvironmentVariables.add(panelInformedCount); JLabel lblInformedCount = new JLabel("Informed Count"); panelInformedCount.add(lblInformedCount); final JFormattedTextField frmtdtxtfldInformedCount = new JFormattedTextField(countFormat); frmtdtxtfldInformedCount.setHorizontalAlignment(SwingConstants.TRAILING); frmtdtxtfldInformedCount.setColumns(3); frmtdtxtfldInformedCount.setToolTipText( "The number of agents moving toward a preferred destination. This number is duplicated on the southern pole as well."); frmtdtxtfldInformedCount.setValue((Number) 4); panelInformedCount.setVisible(false); panelInformedCount.add(frmtdtxtfldInformedCount); JPanel panelStartButtons = new JPanel(); JButton btnStartSimulation = new JButton("Create Simulator Instance"); btnStartSimulation.setToolTipText("Creates a new simulator instance from the settings provided."); btnStartSimulation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { boolean isReady = true; ErrorPacketContainer errorPacketContainer = new ErrorPacketContainer(); if (jframeErrorMessages != null && jframeErrorMessages.isVisible()) { jframeErrorMessages.dispose(); } frmtdtxtfldRunCount.setBackground(Color.WHITE); frmtdtxtfldSimCount.setBackground(Color.WHITE); frmtdtxtfldMaxTimeSteps.setBackground(Color.WHITE); frmtdtxtfldPredationMinimum.setBackground(Color.WHITE); frmtdtxtfldPredationConstant.setBackground(Color.WHITE); frmtdtxtfldNearestNeighborCount.setBackground(Color.WHITE); frmtdtxtfldMaxLocationRadius.setBackground(Color.WHITE); frmtdtxtfldPercentage.setBackground(Color.WHITE); frmtdtxtfldDistance.setBackground(Color.WHITE); frmtdtxtfldDestinationRadius.setBackground(Color.WHITE); frmtdtxtfldAngle.setBackground(Color.WHITE); frmtdtxtfldInformedCount.setBackground(Color.WHITE); StringBuilder errorMessages = new StringBuilder(); if (((Number) frmtdtxtfldRunCount.getValue()).intValue() <= 0) { errorMessages.append("Run Count must be positive\n"); frmtdtxtfldRunCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Run Count must be positive", frmtdtxtfldRunCount, 0); isReady = false; } if (((Number) frmtdtxtfldSimCount.getValue()).intValue() <= 0) { errorMessages.append("Sim Count must be positive\n"); frmtdtxtfldSimCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Sim Count must be positive", frmtdtxtfldSimCount, 0); isReady = false; } if (((Number) frmtdtxtfldMaxTimeSteps.getValue()).intValue() <= 0) { errorMessages.append("Max Time Steps must be positive\n"); frmtdtxtfldMaxTimeSteps.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Max Time Steps must be positive", frmtdtxtfldMaxTimeSteps, 0); isReady = false; } if (((Number) frmtdtxtfldPredationMinimum.getValue()).doubleValue() < 0 && chckbxPredationEnable.isSelected()) { errorMessages.append("Predation Minimum must be positive\n"); frmtdtxtfldPredationMinimum.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Predation Minimum must be positive", frmtdtxtfldPredationMinimum, 1); isReady = false; } if (((Number) frmtdtxtfldPredationConstant.getValue()).doubleValue() <= 0 && chckbxPredationEnable.isSelected()) { errorMessages.append("Predation Constant must be positive\n"); frmtdtxtfldPredationConstant.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Predation Constant must be positive", frmtdtxtfldPredationConstant, 1); isReady = false; } if (((Number) frmtdtxtfldNearestNeighborCount.getValue()).intValue() < 0 && panelNearestNeighborCount.isVisible()) { errorMessages.append("Nearest Neighbor Count must be positive\n"); frmtdtxtfldNearestNeighborCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Nearest Neighbor Count must be positive", frmtdtxtfldNearestNeighborCount, 1); isReady = false; } if (((Number) frmtdtxtfldMaxLocationRadius.getValue()).doubleValue() < 0 && panelMaxLocationRadius.isVisible()) { errorMessages.append("Max Location Radius must be positive\n"); frmtdtxtfldMaxLocationRadius.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Max Location Radius must be positive", frmtdtxtfldMaxLocationRadius, 1); isReady = false; } if ((((Number) frmtdtxtfldPercentage.getValue()).doubleValue() < 0.0 || ((Number) frmtdtxtfldPercentage.getValue()).doubleValue() > 1.0) && panelPercentage.isVisible()) { errorMessages.append( "Percentage needs to be greater than or equal to 0 and less than or equal to 1\n"); frmtdtxtfldPercentage.setBackground(Color.YELLOW); errorPacketContainer.addPacket( "Percentage needs to be greater than or equal to 0 and less than or equal to 1", frmtdtxtfldPercentage, 2); isReady = false; } if (((Number) frmtdtxtfldDistance.getValue()).doubleValue() <= 0 && frmtdtxtfldDistance.isVisible()) { errorMessages.append("Distance must be positive\n"); frmtdtxtfldDistance.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Distance must be positive", frmtdtxtfldDistance, 2); isReady = false; } if (((Number) frmtdtxtfldDestinationRadius.getValue()).doubleValue() <= 0) { errorMessages.append("Destination Radius must be positive\n"); frmtdtxtfldDestinationRadius.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Destination Radius must be positive", frmtdtxtfldDestinationRadius, 0); isReady = false; } if (((Number) frmtdtxtfldAngle.getValue()).doubleValue() < 0) { errorMessages.append("Angle must be positive or zero\n"); frmtdtxtfldAngle.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Angle must be positive", frmtdtxtfldAngle, 2); isReady = false; } if (((Number) frmtdtxtfldInformedCount.getValue()).intValue() <= 0) { errorMessages.append("Informed Count must be positive\n"); frmtdtxtfldInformedCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket("Informed Count must be positive", frmtdtxtfldInformedCount, 2); isReady = false; } else if (((Number) frmtdtxtfldInformedCount.getValue()).intValue() * 2 > sliderAgent.getValue()) { errorMessages.append("Informed Count should at most be half the count of total agents\n"); frmtdtxtfldInformedCount.setBackground(Color.YELLOW); errorPacketContainer.addPacket( "Informed Count should at most be half the count of total agents", frmtdtxtfldInformedCount, 2); isReady = false; } if (!isReady) { jframeErrorMessages = createJFrameErrorMessages(errorPacketContainer, tabbedPane); jframeErrorMessages.setVisible(true); } else { _simulatorProperties = new Properties(); _simulatorProperties.put("run-count", String.valueOf(frmtdtxtfldRunCount.getValue())); _simulatorProperties.put("simulation-count", String.valueOf(frmtdtxtfldSimCount.getValue())); _simulatorProperties.put("max-simulation-time-steps", String.valueOf(frmtdtxtfldMaxTimeSteps.getValue())); _simulatorProperties.put("random-seed", String.valueOf(1)); // Doesn't change _simulatorProperties.put("individual-count", String.valueOf(sliderAgent.getValue())); _simulatorProperties.put("run-graphical", String.valueOf(chckbxGraphical.isSelected())); _simulatorProperties.put("pre-calculate-probabilities", String.valueOf(false)); // Doesn't change _simulatorProperties.put("use-random-random-seed", String.valueOf(chckbxRandomSeed.isSelected())); _simulatorProperties.put("can-multiple-initiate", String.valueOf(true)); // Doesn't change _simulatorProperties.put("eskridge-results", String.valueOf(chckbxEskridge.isSelected())); _simulatorProperties.put("conflict-results", String.valueOf(chckbxConflict.isSelected())); _simulatorProperties.put("position-results", String.valueOf(chckbxPosition.isSelected())); _simulatorProperties.put("predation-results", String.valueOf(chckbxPredationResults.isSelected())); _simulatorProperties.put("communication-type", String.valueOf(comboBoxCommType.getSelectedItem()).toLowerCase()); _simulatorProperties.put("nearest-neighbor-count", String.valueOf(frmtdtxtfldNearestNeighborCount.getValue())); _simulatorProperties.put("max-location-radius", String.valueOf(frmtdtxtfldMaxLocationRadius.getValue())); _simulatorProperties.put("destination-size-radius", String.valueOf(frmtdtxtfldDestinationRadius.getValue())); _simulatorProperties.put("max-agents-eaten-per-step", String.valueOf(spinnerMaxEaten.getValue())); _simulatorProperties.put("enable-predator", String.valueOf(chckbxPredationEnable.isSelected())); _simulatorProperties.put("predation-probability-minimum", String.valueOf(frmtdtxtfldPredationMinimum.getValue())); _simulatorProperties.put("predation-multiplier", String.valueOf(frmtdtxtfldPredationConstant.getValue())); _simulatorProperties.put("use-predation-threshold", String.valueOf(chckbxUsePredationThreshold.isSelected())); _simulatorProperties.put("predation-threshold", String.valueOf(spinnerPredationThreshold.getValue())); _simulatorProperties.put("predation-by-population", String.valueOf(chckbxPopulationIndependent.isSelected())); _simulatorProperties.put("count-non-movers-as-survivors", String.valueOf(chckbxNonMoversSurvive.isSelected())); _simulatorProperties.put("stop-at-any-destination", String.valueOf(chckbxStopAnywhere.isSelected())); _simulatorProperties.put("adhesion-time-limit", String.valueOf(frmtdtxtfldMaxTimeSteps.getValue())); _simulatorProperties.put("alpha", String.valueOf(frmtdtxtfldAlpha.getValue())); _simulatorProperties.put("alpha-c", String.valueOf(frmtdtxtfldAlphaC.getValue())); _simulatorProperties.put("beta", String.valueOf(frmtdtxtfldBeta.getValue())); _simulatorProperties.put("beta-c", String.valueOf(frmtdtxtfldBetaC.getValue())); _simulatorProperties.put("S", String.valueOf(frmtdtxtfldS.getValue())); _simulatorProperties.put("q", String.valueOf(frmtdtxtfldQ.getValue())); _simulatorProperties.put("lambda", String.valueOf(0.2)); _simulatorProperties.put("tau-o", String.valueOf(frmtdtxtfldTaoO.getValue())); _simulatorProperties.put("gamma-c", String.valueOf(frmtdtxtfldGammaC.getValue())); _simulatorProperties.put("epsilon-c", String.valueOf(frmtdtxtfldEpsilonC.getValue())); _simulatorProperties.put("alpha-f", String.valueOf(frmtdtxtfldAlphaF.getValue())); _simulatorProperties.put("beta-f", String.valueOf(frmtdtxtfldBetaF.getValue())); _simulatorProperties.put("default-conflict-value", String.valueOf(spinnerDefaultConflict.getValue())); _simulatorProperties.put("cancellation-threshold", String.valueOf(spinnerCancelationThreshold.getValue())); StringBuilder sbAgentBuilder = new StringBuilder(); sbAgentBuilder.append("edu.snu.leader.discrete.simulator.Sueur"); sbAgentBuilder.append(comboBoxAgentBuilder.getSelectedItem().toString().replace(" ", "")); sbAgentBuilder.append("AgentBuilder"); _simulatorProperties.put("agent-builder", String.valueOf(sbAgentBuilder.toString())); StringBuilder sbDecisionCalculator = new StringBuilder(); sbDecisionCalculator.append("edu.snu.leader.discrete.simulator."); sbDecisionCalculator.append(comboBoxModel.getSelectedItem()); // sbDecisionCalculator.append(comboBoxDecisionCalculator.getSelectedItem()); sbDecisionCalculator .append(comboBoxDecisionCalculator.getSelectedItem().toString().replace(" ", "")); sbDecisionCalculator.append("DecisionCalculator"); _simulatorProperties.put("decision-calculator", String.valueOf(sbDecisionCalculator.toString())); StringBuilder sbLocationsFile = new StringBuilder(); sbLocationsFile.append("cfg/sim/locations/metric/valid-metric-loc-"); sbLocationsFile.append(String.format("%03d", sliderAgent.getValue())); sbLocationsFile.append("-seed-00001.dat"); _simulatorProperties.put("locations-file", String.valueOf(sbLocationsFile.toString())); //create destination file DestinationBuilder db = new DestinationBuilder(sliderAgent.getValue(), 1L); StringBuilder sbDestinationsFile = new StringBuilder(); sbDestinationsFile.append("cfg/sim/destinations/destinations-"); switch (comboBoxEnvironment.getSelectedItem().toString()) { case ("Minimum"): sbDestinationsFile.append("diffdis-" + sliderAgent.getValue()); sbDestinationsFile.append("-per-" + frmtdtxtfldPercentage.getValue()); sbDestinationsFile.append("-seed-1.dat"); db.generateDifferentDistance(((Number) frmtdtxtfldPercentage.getValue()).doubleValue(), 200, 100, 75); break; case ("Medium"): sbDestinationsFile.append("split-" + sliderAgent.getValue()); sbDestinationsFile.append("-dis-" + frmtdtxtfldDistance.getValue()); sbDestinationsFile.append("-ang-" + String.format("%.2f", ((Number) frmtdtxtfldAngle.getValue()).doubleValue())); sbDestinationsFile.append("-per-" + String.format("%.3f", ((Number) frmtdtxtfldPercentage.getValue()).doubleValue())); sbDestinationsFile.append("-seed-1.dat"); db.generateSplitNorth(((Number) frmtdtxtfldDistance.getValue()).doubleValue(), ((Number) frmtdtxtfldAngle.getValue()).doubleValue(), ((Number) frmtdtxtfldPercentage.getValue()).doubleValue()); break; case ("Maximum"): sbDestinationsFile.append("poles-" + sliderAgent.getValue()); sbDestinationsFile.append("-per-" + frmtdtxtfldPercentage.getValue()); sbDestinationsFile.append("-seed-1.dat"); db.generatePoles(50, 100, ((Number) frmtdtxtfldPercentage.getValue()).doubleValue()); break; case ("Uninformed"): sbDestinationsFile.append("split-poles-" + frmtdtxtfldInformedCount.getValue()); sbDestinationsFile.append("-dis-" + String.format("%.1f", ((Number) frmtdtxtfldDistance.getValue()).doubleValue())); sbDestinationsFile.append("-ang-" + String.format("%.2f", ((Number) frmtdtxtfldAngle.getValue()).doubleValue())); sbDestinationsFile.append("-per-" + String.format("%.3f", ((Number) frmtdtxtfldPercentage.getValue()).doubleValue())); sbDestinationsFile.append("-seed-1.dat"); db.generateSplitPoles(((Number) frmtdtxtfldDistance.getValue()).doubleValue(), ((Number) frmtdtxtfldAngle.getValue()).doubleValue(), ((Number) frmtdtxtfldPercentage.getValue()).doubleValue(), ((Number) frmtdtxtfldInformedCount.getValue()).intValue()); break; default: //Should never happen break; } _simulatorProperties.put("destinations-file", String.valueOf(sbDestinationsFile.toString())); _simulatorProperties.put("live-delay", String.valueOf(15)); //Doesn't change _simulatorProperties.put("results-dir", "results"); //Doesn't change new Thread(new Runnable() { public void run() { try { runSimulation(); } catch (Exception e) { e.printStackTrace(); } } }).start(); } } }); panelStartButtons.add(btnStartSimulation); JButton btnStartSimulationFrom = new JButton("Run Simulation from Properties File"); btnStartSimulationFrom .setToolTipText("Runs the simulator with the values provided in the properties file."); btnStartSimulationFrom.setEnabled(false); panelStartButtons.add(btnStartSimulationFrom); panelTab3.add(panelStartButtons); }