List of usage examples for javax.swing JRadioButton setSelected
public void setSelected(boolean b)
From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java
@SuppressWarnings("unchecked") protected void changeLookAndFeel() { final JDialog dialog = new JDialog(mainFrame, "Design ndern"); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); Collection<TwoObjectsX<String, String>> lookAndFeels = FunctionsX.asList( new TwoObjectsX<String, String>("Metal", UIManager.getCrossPlatformLookAndFeelClassName()), new TwoObjectsX<String, String>("Betriebssystem Standard", UIManager.getSystemLookAndFeelClassName()), new TwoObjectsX<String, String>("Nimbus", NimbusLookAndFeel.class.getName())); dialog.setLayout(new GridLayout(0, 1)); ButtonGroup b = new ButtonGroup(); for (final TwoObjectsX<String, String> lookAndFeel : lookAndFeels) { JRadioButton rb = new JRadioButton(lookAndFeel.getObjectA()); if (iliasProperties.getLookAndFeel().equals(lookAndFeel.getObjectB())) { rb.setSelected(true); }/*from w w w .ja v a2 s . c o m*/ rb.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { UIManager.setLookAndFeel(lookAndFeel.getObjectB()); iliasProperties.setLookAndFeel(lookAndFeel.getObjectB()); saveProperties(iliasProperties); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e1) { showError("Fehler beim ndern des Designs", e1); } SwingUtilities.updateComponentTreeUI(mainFrame); SwingUtilities.updateComponentTreeUI(dialog); } }); b.add(rb); dialog.add(rb); } dialog.pack(); dialog.setLocationRelativeTo(mainFrame); dialog.setVisible(true); }
From source file:LightBug.java
JPanel lightPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(0, 1)); panel.add(new JLabel("Light type")); // create the buttons JRadioButton lightNoneButton = new JRadioButton(lightNoneString); JRadioButton lightDirectionalButton = new JRadioButton(lightDirectionalString); JRadioButton lightPointButton = new JRadioButton(lightPointString); JRadioButton lightSpotButton = new JRadioButton(lightSpotString); // set up the action commands lightNoneButton.setActionCommand(lightNoneString); lightDirectionalButton.setActionCommand(lightDirectionalString); lightPointButton.setActionCommand(lightPointString); lightSpotButton.setActionCommand(lightSpotString); // add the buttons to a group so that only one can be selected ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(lightNoneButton);//ww w .j a va 2 s. c o m buttonGroup.add(lightDirectionalButton); buttonGroup.add(lightPointButton); buttonGroup.add(lightSpotButton); // register the applet as the listener for the buttons lightNoneButton.addActionListener(this); lightDirectionalButton.addActionListener(this); lightPointButton.addActionListener(this); lightSpotButton.addActionListener(this); // add the buttons to the panel panel.add(lightNoneButton); panel.add(lightDirectionalButton); panel.add(lightPointButton); panel.add(lightSpotButton); // set the default lightDirectionalButton.setSelected(true); return panel; }
From source file:it.ventuland.ytd.ui.GUIClient.java
private void addComponentsToPane(final Container pane) { this.panel = new JPanel(); this.panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.insets = new Insets(5, 5, 5, 5); gbc.anchor = GridBagConstraints.WEST; ActionManager lActionManager = new ActionManager(); dlm = new DefaultListModel<String>(); this.urllist = new JList<String>(dlm); // TODO maybe we add a button to remove added URLs from list? //this.userlist.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); this.urllist.setFocusable(false); textarea = new JTextArea(2, 2); textarea.setEditable(true);// w w w . j av a 2 s .c om textarea.setFocusable(false); JScrollPane leftscrollpane = new JScrollPane(this.urllist); JScrollPane rightscrollpane = new JScrollPane(textarea); this.middlepane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftscrollpane, rightscrollpane); this.middlepane.setOneTouchExpandable(true); this.middlepane.setDividerLocation(150); Dimension minimumSize = new Dimension(25, 25); leftscrollpane.setMinimumSize(minimumSize); rightscrollpane.setMinimumSize(minimumSize); this.directorybutton = new JButton("", createImageIcon("images/open.png", "")); gbc.gridx = 0; gbc.gridy = 0; this.directorybutton.addActionListener(lActionManager); this.panel.add(this.directorybutton, gbc); this.saveconfigcheckbox = new JCheckBox("Save config"); this.saveconfigcheckbox.setSelected(false); this.panel.add(this.saveconfigcheckbox); this.saveconfigcheckbox.setEnabled(false); // TODO check if initial download directory exists // assume that at least the users homedir exists String shomedir = System.getProperty("user.home").concat(File.separator); gbc.gridx = 0; gbc.gridy = 2; gbc.gridwidth = 2; gbc.fill = GridBagConstraints.HORIZONTAL; this.directorytextfield = new JTextField(shomedir, 20 + (mIsDebug ? 48 : 0)); this.directorytextfield.setEnabled(false); this.directorytextfield.setFocusable(true); this.directorytextfield.addActionListener(lActionManager); this.panel.add(this.directorytextfield, gbc); JLabel dirhint = new JLabel("Download to folder:"); gbc.gridx = 0; gbc.gridy = 1; this.panel.add(dirhint, gbc); this.middlepane.setPreferredSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().width / 3, Toolkit.getDefaultToolkit().getScreenSize().height / 4 + (mIsDebug ? 200 : 0))); gbc.gridx = 0; gbc.gridy = 3; gbc.fill = GridBagConstraints.BOTH; gbc.weighty = 2; gbc.weightx = 2; gbc.gridwidth = 2; this.panel.add(this.middlepane, gbc); // radio buttons for resolution to download mVideoResolutionBtnGrp = new ButtonGroup(); JPanel lRadioPanel = new JPanel(new GridLayout(1, 0)); List<Object> lVidQ = mAppContext.getList("youtube-downloader.video-quality"); JRadioButton lRadioButton = null; for (Object obj : lVidQ) { String lQuality = (String) obj; String lToolTip = mAppContext.getString("youtube-downloader.video-quality." + lQuality + ".tooltip"); boolean lSelected = mAppContext .getBoolean("youtube-downloader.video-quality." + lQuality + ".selected"); boolean lEnabled = mAppContext.getBoolean("youtube-downloader.video-quality." + lQuality + ".enabled"); lRadioButton = new JRadioButton(lQuality); lRadioButton.setName(lQuality); lRadioButton.setActionCommand(lQuality.toLowerCase()); lRadioButton.addActionListener(lActionManager); lRadioButton.setToolTipText(lToolTip); lRadioButton.setSelected(lSelected); lRadioButton.setEnabled(lEnabled); mVideoResolutionBtnGrp.add(lRadioButton); lRadioPanel.add(lRadioButton); } gbc.gridx = 1; gbc.gridy = 0; gbc.gridheight = 0; gbc.gridwidth = 0; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.NORTHEAST; this.panel.add(lRadioPanel, gbc); // radio buttons for video format to download mVideoQualityBtnGrp = new ButtonGroup(); lRadioPanel = new JPanel(new GridLayout(1, 0)); save3dcheckbox = new JCheckBox("3D"); save3dcheckbox.setToolTipText("stereoscopic video"); save3dcheckbox.setSelected(false); save3dcheckbox.setEnabled(true); lRadioPanel.add(save3dcheckbox); List<Object> lVidR = mAppContext.getList("youtube-downloader.video-resolution"); lRadioButton = null; for (Object obj : lVidR) { String lResolution = (String) obj; String lToolTip = mAppContext .getString("youtube-downloader.video-resolution." + lResolution + ".tooltip"); boolean lSelected = mAppContext .getBoolean("youtube-downloader.video-resolution." + lResolution + ".selected"); boolean lEnabled = mAppContext .getBoolean("youtube-downloader.video-resolution." + lResolution + ".enabled"); lRadioButton = new JRadioButton(lResolution); lRadioButton.setName(lResolution); lRadioButton.setActionCommand(lResolution.toLowerCase()); lRadioButton.addActionListener(lActionManager); lRadioButton.setToolTipText(lToolTip); lRadioButton.setSelected(lSelected); lRadioButton.setEnabled(lEnabled); mVideoQualityBtnGrp.add(lRadioButton); lRadioPanel.add(lRadioButton); } gbc.gridx = 1; gbc.gridy = 1; gbc.gridheight = 0; gbc.gridwidth = 0; gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.NORTHEAST; this.panel.add(lRadioPanel, gbc); JLabel hint = new JLabel("Type, paste or drag'n drop a YouTube video address:"); gbc.fill = 0; gbc.gridwidth = 0; gbc.gridheight = 1; gbc.weightx = 0; gbc.weighty = 0; gbc.gridx = 0; gbc.gridy = 4; gbc.anchor = GridBagConstraints.WEST; this.panel.add(hint, gbc); textinputfield = new JTextField(20); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = 5; gbc.gridwidth = 2; textinputfield.setEnabled(true); textinputfield.setFocusable(true); textinputfield.addActionListener(lActionManager); textinputfield.getDocument().addDocumentListener(new UrlInsertListener()); this.panel.add(textinputfield, gbc); this.quitbutton = new JButton("", createImageIcon("images/exit.png", "")); gbc.gridx = 2; gbc.gridy = 5; gbc.gridwidth = 0; this.quitbutton.addActionListener(lActionManager); this.quitbutton.setActionCommand("quit"); this.quitbutton.setToolTipText("Exit."); this.panel.add(this.quitbutton, gbc); pane.add(this.panel); addWindowListener(new GUIWindowAdapter()); this.setDropTarget(new DropTarget(this, new DragDropListener())); textarea.setTransferHandler(null); // otherwise the dropped text would be inserted }
From source file:eu.apenet.dpt.standalone.gui.DataPreparationToolGUI.java
public void refreshButtons(FileInstance fileInstance, int groupId) { Enumeration buttons;// w w w.ja va 2 s . com if (groupId == Utilities.XSD_GROUP) { buttons = groupXsd.getElements(); } else { buttons = groupXslt.getElements(); } while (buttons.hasMoreElements()) { JRadioButton jRadioButton = (JRadioButton) buttons.nextElement(); if (jRadioButton.getText().equals(fileInstance.getConversionScriptName()) || jRadioButton.getText().equals(fileInstance.getValidationSchemaName())) { jRadioButton.setSelected(true); break; } } }
From source file:TexBug.java
JPanel texture2DPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 0)); // horizontal JPanel leftPanel = new JPanel(); leftPanel.setLayout(new GridLayout(0, 1)); // vertical panel.add(leftPanel);// w w w . ja v a 2s. c om JPanel rightPanel = new JPanel(); rightPanel.setLayout(new GridLayout(0, 1)); // vertical panel.add(rightPanel); texEnableCheckBox = new JCheckBox(texEnableString); // set up the action commands texEnableCheckBox.setActionCommand(texEnableString); // register the applet as the listener for the buttons texEnableCheckBox.addActionListener(this); // set the initial value texEnableCheckBox.setSelected(texEnable); // add the checkbox to the panel leftPanel.add(texEnableCheckBox); // texture boundary S leftPanel.add(new JLabel("Boundary S Mode:")); // create the buttons JRadioButton texBoundarySWrapButton = new JRadioButton(wrapString); JRadioButton texBoundarySClampButton = new JRadioButton(clampString); // set up the action commands texBoundarySWrapButton.setActionCommand(texBoundarySWrapString); texBoundarySClampButton.setActionCommand(texBoundarySClampString); // add the buttons to a group so that only one can be selected ButtonGroup boundSButtonGroup = new ButtonGroup(); boundSButtonGroup.add(texBoundarySWrapButton); boundSButtonGroup.add(texBoundarySClampButton); // register the applet as the listener for the buttons texBoundarySWrapButton.addActionListener(this); texBoundarySClampButton.addActionListener(this); // add the buttons to the panel leftPanel.add(texBoundarySWrapButton); leftPanel.add(texBoundarySClampButton); // set the default texBoundarySWrapButton.setSelected(true); // texture boundary T leftPanel.add(new JLabel("Boundary T Mode:")); // create the buttons JRadioButton texBoundaryTWrapButton = new JRadioButton(wrapString); JRadioButton texBoundaryTClampButton = new JRadioButton(clampString); // set up the action commands texBoundaryTWrapButton.setActionCommand(texBoundaryTWrapString); texBoundaryTClampButton.setActionCommand(texBoundaryTClampString); // add the buttons to a group so that only one can be selected ButtonGroup boundTButtonGroup = new ButtonGroup(); boundTButtonGroup.add(texBoundaryTWrapButton); boundTButtonGroup.add(texBoundaryTClampButton); // register the applet as the listener for the buttons texBoundaryTWrapButton.addActionListener(this); texBoundaryTClampButton.addActionListener(this); // add the buttons to the panel leftPanel.add(texBoundaryTWrapButton); leftPanel.add(texBoundaryTClampButton); // set the default texBoundaryTWrapButton.setSelected(true); // texture min filter rightPanel.add(new JLabel("Min Filter:")); // create the buttons JRadioButton texMinFilterBasePointButton = new JRadioButton(texFilterBasePointString); JRadioButton texMinFilterBaseLinearButton = new JRadioButton(texFilterBaseLinearString); JRadioButton texMinFilterMultiPointButton = new JRadioButton(texFilterMultiPointString); JRadioButton texMinFilterMultiLinearButton = new JRadioButton(texFilterMultiLinearString); JRadioButton texMinFilterNicestButton = new JRadioButton(nicestString); JRadioButton texMinFilterFastestButton = new JRadioButton(fastestString); // set up the action commands texMinFilterBasePointButton.setActionCommand(texMinFilterBasePointString); texMinFilterBaseLinearButton.setActionCommand(texMinFilterBaseLinearString); texMinFilterMultiPointButton.setActionCommand(texMinFilterMultiPointString); texMinFilterMultiLinearButton.setActionCommand(texMinFilterMultiLinearString); texMinFilterNicestButton.setActionCommand(texMinFilterNicestString); texMinFilterFastestButton.setActionCommand(texMinFilterFastestString); // add the buttons to a group so that only one can be selected ButtonGroup minFilterButtonGroup = new ButtonGroup(); minFilterButtonGroup.add(texMinFilterBasePointButton); minFilterButtonGroup.add(texMinFilterBaseLinearButton); minFilterButtonGroup.add(texMinFilterMultiPointButton); minFilterButtonGroup.add(texMinFilterMultiLinearButton); minFilterButtonGroup.add(texMinFilterNicestButton); minFilterButtonGroup.add(texMinFilterFastestButton); // register the applet as the listener for the buttons texMinFilterBasePointButton.addActionListener(this); texMinFilterBaseLinearButton.addActionListener(this); texMinFilterMultiPointButton.addActionListener(this); texMinFilterMultiLinearButton.addActionListener(this); texMinFilterNicestButton.addActionListener(this); texMinFilterFastestButton.addActionListener(this); // add the buttons to the panel rightPanel.add(texMinFilterBasePointButton); rightPanel.add(texMinFilterBaseLinearButton); rightPanel.add(texMinFilterMultiPointButton); rightPanel.add(texMinFilterMultiLinearButton); rightPanel.add(texMinFilterNicestButton); rightPanel.add(texMinFilterFastestButton); // set the default texMinFilterBasePointButton.setSelected(true); // texture max filter rightPanel.add(new JLabel("Mag Filter:")); // create the buttons JRadioButton texMagFilterBasePointButton = new JRadioButton(texFilterBasePointString); JRadioButton texMagFilterBaseLinearButton = new JRadioButton(texFilterBaseLinearString); JRadioButton texMagFilterNicestButton = new JRadioButton(nicestString); JRadioButton texMagFilterFastestButton = new JRadioButton(fastestString); // set up the action commands texMagFilterBasePointButton.setActionCommand(texMagFilterBasePointString); texMagFilterBaseLinearButton.setActionCommand(texMagFilterBaseLinearString); texMagFilterNicestButton.setActionCommand(texMagFilterNicestString); texMagFilterFastestButton.setActionCommand(texMagFilterFastestString); // add the buttons to a group so that only one can be selected ButtonGroup magFilterButtonGroup = new ButtonGroup(); magFilterButtonGroup.add(texMagFilterBasePointButton); magFilterButtonGroup.add(texMagFilterBaseLinearButton); magFilterButtonGroup.add(texMagFilterNicestButton); magFilterButtonGroup.add(texMagFilterFastestButton); // register the applet as the listener for the buttons texMagFilterBasePointButton.addActionListener(this); texMagFilterBaseLinearButton.addActionListener(this); texMagFilterNicestButton.addActionListener(this); texMagFilterFastestButton.addActionListener(this); // add the buttons to the panel rightPanel.add(texMagFilterBasePointButton); rightPanel.add(texMagFilterBaseLinearButton); rightPanel.add(texMagFilterNicestButton); rightPanel.add(texMagFilterFastestButton); // set the default texMagFilterBasePointButton.setSelected(true); // MipMap Mode leftPanel.add(new JLabel("MipMap Mode:")); // create the buttons JRadioButton texMipMapBaseButton = new JRadioButton(texMipMapBaseString); JRadioButton texMipMapMultiButton = new JRadioButton(texMipMapMultiString); // set up the action commands texMipMapBaseButton.setActionCommand(texMipMapBaseString); texMipMapMultiButton.setActionCommand(texMipMapMultiString); // add the buttons to a group so that only one can be selected ButtonGroup texMipMapButtonGroup = new ButtonGroup(); texMipMapButtonGroup.add(texMipMapBaseButton); texMipMapButtonGroup.add(texMipMapMultiButton); // register the applet as the listener for the buttons texMipMapBaseButton.addActionListener(this); texMipMapMultiButton.addActionListener(this); // add the buttons to the panel leftPanel.add(texMipMapBaseButton); leftPanel.add(texMipMapMultiButton); // set the default texMipMapBaseButton.setSelected(true); return panel; }
From source file:com.dragoniade.deviantart.ui.PreferencesDialog.java
public PreferencesDialog(final DownloaderGUI owner, Properties config) { super(owner, "Preferences", true); HttpClientParams params = new HttpClientParams(); params.setVersion(HttpVersion.HTTP_1_1); params.setSoTimeout(30000);//from www .j a v a 2 s .c o m client = new HttpClient(params); setProxy(ProxyCfg.parseConfig(config)); sample = new Deviation(); sample.setId(15972367L); sample.setTitle("Fella Promo"); sample.setArtist("devart"); sample.setImageDownloadUrl(DOWNLOAD_URL); sample.setImageFilename(Deviation.extractFilename(DOWNLOAD_URL)); sample.setCollection(new Collection(1L, "MyCollect")); setLayout(new BorderLayout()); panes = new JTabbedPane(JTabbedPane.TOP); JPanel genPanel = new JPanel(); BoxLayout genLayout = new BoxLayout(genPanel, BoxLayout.Y_AXIS); genPanel.setLayout(genLayout); panes.add("General", genPanel); JLabel userLabel = new JLabel("Username"); userLabel.setToolTipText("The username the account you want to download the favorites from."); userField = new JTextField(config.getProperty(Constants.USERNAME)); userLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); userLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); userField.setAlignmentX(JLabel.LEFT_ALIGNMENT); userField.setMaximumSize(new Dimension(Integer.MAX_VALUE, userField.getFont().getSize() * 2)); genPanel.add(userLabel); genPanel.add(userField); JPanel radioPanel = new JPanel(); BoxLayout radioLayout = new BoxLayout(radioPanel, BoxLayout.X_AXIS); radioPanel.setAlignmentX(JLabel.LEFT_ALIGNMENT); radioPanel.setBorder(new EmptyBorder(0, 5, 0, 5)); radioPanel.setLayout(radioLayout); JLabel searchLabel = new JLabel("Search for"); searchLabel .setToolTipText("Select what you want to download from that user: it favorites or it galleries."); searchLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); searchLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); selectedSearch = SEARCH.lookup(config.getProperty(Constants.SEARCH, SEARCH.getDefault().getId())); buttonGroup = new ButtonGroup(); for (final SEARCH search : SEARCH.values()) { JRadioButton radio = new JRadioButton(search.getLabel()); radio.setAlignmentX(JLabel.LEFT_ALIGNMENT); radio.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { selectedSearch = search; } }); buttonGroup.add(radio); radioPanel.add(radio); if (search.equals(selectedSearch)) { radio.setSelected(true); } } genPanel.add(radioPanel); final JTextField sampleField = new JTextField(""); sampleField.setEditable(false); JLabel locationLabel = new JLabel("Download location"); locationLabel.setToolTipText("The folder pattern where you want the file to be downloaded in."); JLabel legendsLabel = new JLabel( "<html><body>Field names: %user%, %artist%, %title%, %id%, %filename%, %collection%, %ext%<br></br>Example:</body></html>"); legendsLabel.setToolTipText("An example of where a file will be downloaded to."); locationString = new StringBuilder(); locationField = new JTextField(config.getProperty(Constants.LOCATION)); locationField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } public void keyReleased(KeyEvent e) { File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample, sample.getImageFilename()); locationString.setLength(0); locationString.append(dest.getAbsolutePath()); sampleField.setText(locationString.toString()); if (useSameForMatureBox.isSelected()) { locationMatureString.setLength(0); locationMatureString.append(sampleField.getText()); locationMatureField.setText(locationField.getText()); } } public void keyTyped(KeyEvent e) { } }); locationField.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseExited(MouseEvent e) { sampleField.setText(locationString.toString()); } public void mouseEntered(MouseEvent e) { sampleField.setText(locationString.toString()); } public void mouseClicked(MouseEvent e) { } }); JLabel locationMatureLabel = new JLabel("Mature download location"); locationMatureLabel.setToolTipText( "The folder pattern where you want the file marked as 'Mature' to be downloaded in."); locationMatureString = new StringBuilder(); locationMatureField = new JTextField(config.getProperty(Constants.MATURE)); locationMatureField.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { // TODO Auto-generated method stub } public void keyReleased(KeyEvent e) { File dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample, sample.getImageFilename()); locationMatureString.setLength(0); locationMatureString.append(dest.getAbsolutePath()); sampleField.setText(locationMatureString.toString()); } public void keyTyped(KeyEvent e) { } }); locationMatureField.addMouseListener(new MouseListener() { public void mouseReleased(MouseEvent e) { } public void mousePressed(MouseEvent e) { } public void mouseExited(MouseEvent e) { sampleField.setText(locationString.toString()); } public void mouseEntered(MouseEvent e) { sampleField.setText(locationMatureString.toString()); } public void mouseClicked(MouseEvent e) { } }); useSameForMatureBox = new JCheckBox("Use same location for mature deviation?"); useSameForMatureBox.setSelected(locationLabel.getText().equals(locationMatureField.getText())); useSameForMatureBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (useSameForMatureBox.isSelected()) { locationMatureField.setEditable(false); locationMatureField.setText(locationField.getText()); locationMatureString.setLength(0); locationMatureString.append(locationString); } else { locationMatureField.setEditable(true); } } }); File dest = LocationHelper.getFile(locationField.getText(), userField.getText(), sample, sample.getImageFilename()); sampleField.setText(dest.getAbsolutePath()); locationString.append(sampleField.getText()); dest = LocationHelper.getFile(locationMatureField.getText(), userField.getText(), sample, sample.getImageFilename()); locationMatureString.append(dest.getAbsolutePath()); locationLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); locationField.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationField.setMaximumSize(new Dimension(Integer.MAX_VALUE, locationField.getFont().getSize() * 2)); locationMatureLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationMatureLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); locationMatureField.setAlignmentX(JLabel.LEFT_ALIGNMENT); locationMatureField .setMaximumSize(new Dimension(Integer.MAX_VALUE, locationMatureField.getFont().getSize() * 2)); useSameForMatureBox.setAlignmentX(JLabel.LEFT_ALIGNMENT); legendsLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); legendsLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); legendsLabel.setMaximumSize(new Dimension(Integer.MAX_VALUE, legendsLabel.getFont().getSize() * 2)); sampleField.setAlignmentX(JLabel.LEFT_ALIGNMENT); sampleField.setMaximumSize(new Dimension(Integer.MAX_VALUE, sampleField.getFont().getSize() * 2)); genPanel.add(locationLabel); genPanel.add(locationField); genPanel.add(locationMatureLabel); genPanel.add(locationMatureField); genPanel.add(useSameForMatureBox); genPanel.add(legendsLabel); genPanel.add(sampleField); genPanel.add(Box.createVerticalBox()); final KeyListener prxChangeListener = new KeyListener() { public void keyTyped(KeyEvent e) { proxyChangeState = true; } public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { } }; JPanel prxPanel = new JPanel(); BoxLayout prxLayout = new BoxLayout(prxPanel, BoxLayout.Y_AXIS); prxPanel.setLayout(prxLayout); panes.add("Proxy", prxPanel); JLabel prxHostLabel = new JLabel("Proxy Host"); prxHostLabel.setToolTipText("The hostname of the proxy server"); prxHostField = new JTextField(config.getProperty(Constants.PROXY_HOST)); prxHostLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxHostLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxHostField.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxHostField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxHostField.getFont().getSize() * 2)); JLabel prxPortLabel = new JLabel("Proxy Port"); prxPortLabel.setToolTipText("The port of the proxy server (Default 80)."); prxPortSpinner = new JSpinner(); prxPortSpinner.setModel(new SpinnerNumberModel( Integer.parseInt(config.getProperty(Constants.PROXY_PORT, "80")), 1, 65535, 1)); prxPortLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPortLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxPortSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPortSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPortSpinner.getFont().getSize() * 2)); JLabel prxUserLabel = new JLabel("Proxy username"); prxUserLabel.setToolTipText("The username used for authentication, if applicable."); prxUserField = new JTextField(config.getProperty(Constants.PROXY_USERNAME)); prxUserLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxUserLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxUserField.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxUserField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxUserField.getFont().getSize() * 2)); JLabel prxPassLabel = new JLabel("Proxy username"); prxPassLabel.setToolTipText("The username used for authentication, if applicable."); prxPassField = new JPasswordField(config.getProperty(Constants.PROXY_PASSWORD)); prxPassLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPassLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); prxPassField.setAlignmentX(JLabel.LEFT_ALIGNMENT); prxPassField.setMaximumSize(new Dimension(Integer.MAX_VALUE, prxPassField.getFont().getSize() * 2)); prxUseBox = new JCheckBox("Use a proxy?"); prxUseBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { prxChangeListener.keyTyped(null); if (prxUseBox.isSelected()) { prxHostField.setEditable(true); prxPortSpinner.setEnabled(true); prxUserField.setEditable(true); prxPassField.setEditable(true); } else { prxHostField.setEditable(false); prxPortSpinner.setEnabled(false); prxUserField.setEditable(false); prxPassField.setEditable(false); } } }); prxUseBox.setSelected(!Boolean.parseBoolean(config.getProperty(Constants.PROXY_USE))); prxUseBox.doClick(); proxyChangeState = false; prxHostField.addKeyListener(prxChangeListener); prxUserField.addKeyListener(prxChangeListener); prxPassField.addKeyListener(prxChangeListener); prxPortSpinner.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { proxyChangeState = true; } }); prxPanel.add(prxUseBox); prxPanel.add(prxHostLabel); prxPanel.add(prxHostField); prxPanel.add(prxPortLabel); prxPanel.add(prxPortSpinner); prxPanel.add(prxUserLabel); prxPanel.add(prxUserField); prxPanel.add(prxPassLabel); prxPanel.add(prxPassField); prxPanel.add(Box.createVerticalBox()); final JPanel advPanel = new JPanel(); BoxLayout advLayout = new BoxLayout(advPanel, BoxLayout.Y_AXIS); advPanel.setLayout(advLayout); panes.add("Advanced", advPanel); panes.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { JTabbedPane pane = (JTabbedPane) e.getSource(); if (proxyChangeState && pane.getSelectedComponent() == advPanel) { Properties properties = new Properties(); properties.setProperty(Constants.PROXY_USERNAME, prxUserField.getText().trim()); properties.setProperty(Constants.PROXY_PASSWORD, new String(prxPassField.getPassword()).trim()); properties.setProperty(Constants.PROXY_HOST, prxHostField.getText().trim()); properties.setProperty(Constants.PROXY_PORT, prxPortSpinner.getValue().toString()); properties.setProperty(Constants.PROXY_USE, Boolean.toString(prxUseBox.isSelected())); ProxyCfg prx = ProxyCfg.parseConfig(properties); setProxy(prx); revalidateSearcher(null); } } }); JLabel domainLabel = new JLabel("Deviant Art domain name"); domainLabel.setToolTipText("The deviantART main domain, should it ever change."); domainField = new JTextField(config.getProperty(Constants.DOMAIN)); domainLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); domainLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); domainField.setAlignmentX(JLabel.LEFT_ALIGNMENT); domainField.setMaximumSize(new Dimension(Integer.MAX_VALUE, domainField.getFont().getSize() * 2)); advPanel.add(domainLabel); advPanel.add(domainField); JLabel throttleLabel = new JLabel("Throttle search delay"); throttleLabel.setToolTipText( "Slow down search query by inserting a pause between them. This help prevent abuse when doing a massive download."); throttleSpinner = new JSpinner(); throttleSpinner.setModel( new SpinnerNumberModel(Integer.parseInt(config.getProperty(Constants.THROTTLE, "0")), 5, 60, 1)); throttleLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); throttleLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); throttleSpinner.setAlignmentX(JLabel.LEFT_ALIGNMENT); throttleSpinner.setMaximumSize(new Dimension(Integer.MAX_VALUE, throttleSpinner.getFont().getSize() * 2)); advPanel.add(throttleLabel); advPanel.add(throttleSpinner); JLabel searcherLabel = new JLabel("Searcher"); searcherLabel.setToolTipText("Select a searcher that will look for your favorites."); searcherBox = new JComboBox(); searcherBox.setRenderer(new TogglingRenderer()); final AtomicInteger index = new AtomicInteger(0); searcherBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox combo = (JComboBox) e.getSource(); Object selectedItem = combo.getSelectedItem(); if (selectedItem instanceof SearchItem) { SearchItem item = (SearchItem) selectedItem; if (item.isValid) { index.set(combo.getSelectedIndex()); } else { combo.setSelectedIndex(index.get()); } } } }); try { for (Class<Search> clazz : SearcherClassCache.getInstance().getClasses()) { Search searcher = clazz.newInstance(); String name = searcher.getName(); SearchItem item = new SearchItem(name, clazz.getName(), true); searcherBox.addItem(item); } String selectedClazz = config.getProperty(Constants.SEARCHER, com.dragoniade.deviantart.deviation.SearchRss.class.getName()); revalidateSearcher(selectedClazz); } catch (Exception e1) { throw new RuntimeException(e1); } searcherLabel.setAlignmentX(JLabel.LEFT_ALIGNMENT); searcherLabel.setBorder(new EmptyBorder(0, 5, 0, 5)); searcherBox.setAlignmentX(JLabel.LEFT_ALIGNMENT); searcherBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, searcherBox.getFont().getSize() * 2)); advPanel.add(searcherLabel); advPanel.add(searcherBox); advPanel.add(Box.createVerticalBox()); add(panes, BorderLayout.CENTER); JButton saveBut = new JButton("Save"); userField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; if (field.getText().trim().length() == 0) { JOptionPane.showMessageDialog(input, "The user musn't be empty.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); locationField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; String content = field.getText().trim(); if (content.length() == 0) { JOptionPane.showMessageDialog(input, "The location musn't be empty.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } if (!content.contains("%filename%") && !content.contains("%id%")) { JOptionPane.showMessageDialog(input, "The location must contains at least a %filename% or an %id% field.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); locationMatureField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; String content = field.getText().trim(); if (content.length() == 0) { JOptionPane.showMessageDialog(input, "The Mature location musn't be empty.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } if (!content.contains("%filename%") && !content.contains("%id%")) { JOptionPane.showMessageDialog(input, "The Mature location must contains at least a %username% or an %id% field.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); domainField.setInputVerifier(new InputVerifier() { @Override public boolean verify(JComponent input) { JTextField field = (JTextField) input; String domain = field.getText().trim(); if (domain.length() == 0) { JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain.", "Warning", JOptionPane.WARNING_MESSAGE); return false; } if (domain.toLowerCase().startsWith("http://")) { JOptionPane.showMessageDialog(input, "You must specify the deviantART main domain, not the full URL (aka www.deviantart.com).", "Warning", JOptionPane.WARNING_MESSAGE); return false; } return true; } }); locationField.setVerifyInputWhenFocusTarget(true); final JDialog parent = this; saveBut.addActionListener(new ActionListener() { String errorMsg = "The location is invalid or cannot be written to."; public void actionPerformed(ActionEvent e) { String username = userField.getText().trim(); String location = locationField.getText().trim(); String locationMature = locationMatureField.getText().trim(); String domain = domainField.getText().trim(); String throttle = throttleSpinner.getValue().toString(); String searcher = searcherBox.getSelectedItem().toString(); String prxUse = Boolean.toString(prxUseBox.isSelected()); String prxHost = prxHostField.getText().trim(); String prxPort = prxPortSpinner.getValue().toString(); String prxUsername = prxUserField.getText().trim(); String prxPassword = new String(prxPassField.getPassword()).trim(); if (!testPath(location, username)) { JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE); } if (!testPath(locationMature, username)) { JOptionPane.showMessageDialog(parent, errorMsg, "Error", JOptionPane.ERROR_MESSAGE); } Properties p = new Properties(); p.setProperty(Constants.USERNAME, username); p.setProperty(Constants.LOCATION, location); p.setProperty(Constants.MATURE, locationMature); p.setProperty(Constants.DOMAIN, domain); p.setProperty(Constants.THROTTLE, throttle); p.setProperty(Constants.SEARCHER, searcher); p.setProperty(Constants.SEARCH, selectedSearch.getId()); p.setProperty(Constants.PROXY_USE, prxUse); p.setProperty(Constants.PROXY_HOST, prxHost); p.setProperty(Constants.PROXY_PORT, prxPort); p.setProperty(Constants.PROXY_USERNAME, prxUsername); p.setProperty(Constants.PROXY_PASSWORD, prxPassword); owner.savePreferences(p); parent.dispose(); } }); JButton cancelBut = new JButton("Cancel"); cancelBut.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { parent.dispose(); } }); JPanel buttonPanel = new JPanel(); BoxLayout butLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS); buttonPanel.setLayout(butLayout); buttonPanel.add(saveBut); buttonPanel.add(cancelBut); add(buttonPanel, BorderLayout.SOUTH); pack(); setResizable(false); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((d.width - getWidth()) / 2, (d.height - getHeight()) / 2); setVisible(true); }
From source file:edu.uci.ics.jung.samples.PerspectiveTransformerDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom and perspective features. * /*from www. ja v a 2 s . c om*/ */ @SuppressWarnings("serial") public PerspectiveTransformerDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); graphLayout = new FRLayout<String, Number>(graph); ((FRLayout<String, Number>) graphLayout).setMaxIterations(1000); Dimension preferredSize = new Dimension(600, 600); Map<String, Point2D> map = new HashMap<String, Point2D>(); Transformer<String, Point2D> vlf = TransformerUtils.mapTransformer(map); grid = this.generateVertexGrid(map, preferredSize, 25); gridLayout = new StaticLayout<String, Number>(grid, vlf, preferredSize); final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>( graphLayout, preferredSize); vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize); PickedState<Number> pes = vv.getPickedEdgeState(); vv.getRenderContext() .setEdgeDrawPaintTransformer(new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.red)); vv.getRenderContext().setVertexShapeTransformer(new Transformer<String, Shape>() { public Shape transform(String v) { return new Rectangle2D.Float(-10, -10, 20, 20); } }); vv.setBackground(Color.white); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<String>()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); viewSupport = new PerspectiveViewTransformSupport<String, Number>(vv); layoutSupport = new PerspectiveLayoutTransformSupport<String, Number>(vv); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 0.9f, vv.getCenter()); } }); final JSlider horizontalSlider = new JSlider(-120, 120, 0) { /* (non-Javadoc) * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { return new Dimension(80, super.getPreferredSize().height); } }; final JSlider verticalSlider = new JSlider(-120, 120, 0) { /* (non-Javadoc) * @see javax.swing.JComponent#getPreferredSize() */ @Override public Dimension getPreferredSize() { return new Dimension(super.getPreferredSize().width, 80); } }; verticalSlider.setOrientation(JSlider.VERTICAL); final ChangeListener changeListener = new ChangeListener() { public void stateChanged(ChangeEvent e) { int vval = -verticalSlider.getValue(); int hval = horizontalSlider.getValue(); Dimension d = vv.getSize(); PerspectiveTransform pt = null; pt = PerspectiveTransform.getQuadToQuad(vval, hval, d.width - vval, -hval, d.width + vval, d.height + hval, -vval, d.height - hval, 0, 0, d.width, 0, d.width, d.height, 0, d.height); viewSupport.getPerspectiveTransformer().setPerspectiveTransform(pt); layoutSupport.getPerspectiveTransformer().setPerspectiveTransform(pt); vv.repaint(); } }; horizontalSlider.addChangeListener(changeListener); verticalSlider.addChangeListener(changeListener); JPanel perspectivePanel = new JPanel(new BorderLayout()); JPanel perspectiveCenterPanel = new JPanel(new BorderLayout()); perspectivePanel.setBorder(BorderFactory.createTitledBorder("Perspective Controls")); final JButton center = new JButton("Center"); center.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { horizontalSlider.setValue(0); verticalSlider.setValue(0); } }); ButtonGroup radio = new ButtonGroup(); JRadioButton normal = new JRadioButton("None"); normal.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange() == ItemEvent.SELECTED; if (selected) { if (viewSupport != null) { viewSupport.deactivate(); } if (layoutSupport != null) { layoutSupport.deactivate(); } } center.setEnabled(!selected); horizontalSlider.setEnabled(!selected); verticalSlider.setEnabled(!selected); } }); final JRadioButton perspectiveView = new JRadioButton("In View"); perspectiveView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton perspectiveModel = new JRadioButton("In Layout"); perspectiveModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { layoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); radio.add(normal); radio.add(perspectiveModel); radio.add(perspectiveView); normal.setSelected(true); ButtonGroup graphRadio = new ButtonGroup(); JRadioButton graphButton = new JRadioButton("Graph"); graphButton.setSelected(true); graphButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(graphLayout); vv.repaint(); } } }); JRadioButton gridButton = new JRadioButton("Grid"); gridButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(gridLayout); vv.repaint(); } } }); graphRadio.add(graphButton); graphRadio.add(gridButton); JPanel modePanel = new JPanel(new GridLayout(2, 1)); modePanel.setBorder(BorderFactory.createTitledBorder("Display")); modePanel.add(graphButton); modePanel.add(gridButton); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); gzsp.setCorner(menubar); Container controls = new JPanel(new BorderLayout()); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel perspectiveControls = new JPanel(new GridLayout(3, 1)); zoomControls.add(plus); zoomControls.add(minus); perspectiveControls.add(normal); perspectiveControls.add(perspectiveModel); perspectiveControls.add(perspectiveView); controls.add(zoomControls, BorderLayout.WEST); controls.add(modePanel); perspectivePanel.add(perspectiveControls, BorderLayout.WEST); perspectiveCenterPanel.add(horizontalSlider, BorderLayout.SOUTH); perspectivePanel.add(verticalSlider, BorderLayout.EAST); perspectiveCenterPanel.add(center); perspectivePanel.add(perspectiveCenterPanel); controls.add(perspectivePanel, BorderLayout.EAST); content.add(controls, BorderLayout.SOUTH); }
From source file:PickTest.java
private void addRadioButton(JPanel panel, ButtonGroup bg, String ownerName, String buttonName, boolean selected) { JRadioButton item; item = new JRadioButton(buttonName); item.setName(ownerName);/*from ww w. j a va 2 s .com*/ item.addActionListener(this); if (selected) { item.setSelected(true); } panel.add(item); bg.add(item); }
From source file:net.rptools.maptool.launcher.MapToolLauncher.java
private JPanel buildTroubleshootingPanel() { final JPanel p = new JPanel(); p.setLayout(new BorderLayout()); ActionListener levelChange = new ActionListener() { @Override/*w w w . j a v a 2 s . co m*/ public void actionPerformed(ActionEvent e) { Level x = Level.parse(e.getActionCommand()); if (Level.OFF.equals(x) || Level.INFO.equals(x) || Level.WARNING.equals(x) || Level.SEVERE.equals(x)) log.setLevel(x); } }; JPanel logPanel = new JPanel(); logPanel.setLayout(new GridLayout(0, 1)); logPanel.setBorder(new TitledBorder(new LineBorder(Color.BLACK), CopiedFromOtherJars.getText("msg.logDetailPanel.border"))); //$NON-NLS-1$ logPanel.setAlignmentX(Component.LEFT_ALIGNMENT); ButtonGroup logGroup = new ButtonGroup(); for (Level type : new Level[] { Level.OFF, Level.INFO, Level.WARNING, Level.SEVERE }) { JRadioButton jrb = new JRadioButton(type.toString()); jrb.setActionCommand(type.toString()); jrb.addActionListener(levelChange); jrb.setBorder( BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.red), jrb.getBorder())); logPanel.add(jrb); logGroup.add(jrb); if (type == Level.WARNING) { jrb.setSelected(true); log.setLevel(type); } } jcbEnableAssertions.setAlignmentX(Component.LEFT_ALIGNMENT); jcbEnableAssertions.setText(CopiedFromOtherJars.getText("msg.info.enableAssertions")); //$NON-NLS-1$ jcbEnableAssertions.setToolTipText(CopiedFromOtherJars.getText("msg.tooltip.enableAssertions")); //$NON-NLS-1$ jcbEnableAssertions.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (!extraArgs.contains(ASSERTIONS_OPTION)) { extraArgs = (ASSERTIONS_OPTION + " " + extraArgs); //$NON-NLS-1$ } } else if (e.getStateChange() == ItemEvent.DESELECTED) { extraArgs = extraArgs.replace(ASSERTIONS_OPTION, ""); //$NON-NLS-1$ } extraArgs = extraArgs.trim(); jtfArgs.setText(extraArgs); updateCommand(); } }); p.add(logPanel, BorderLayout.NORTH); Box other = new Box(BoxLayout.PAGE_AXIS); other.add(jcbEnableAssertions); other.add(Box.createVerticalGlue()); p.add(other, BorderLayout.CENTER); return p; }
From source file:ffx.ui.ModelingPanel.java
private void loadCommand() { synchronized (this) { // Force Field X Command Element command;/* w w w . j av a 2 s . c om*/ // 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()); }