List of usage examples for javax.swing JPanel setAlignmentX
@BeanProperty(description = "The preferred horizontal alignment of the component.") public void setAlignmentX(float alignmentX)
From source file:FileChooserDemo.java
public FileChooserDemo() { UIManager.LookAndFeelInfo[] installedLafs = UIManager.getInstalledLookAndFeels(); for (UIManager.LookAndFeelInfo lafInfo : installedLafs) { try {//from w w w.j a v a 2 s . c o m Class lnfClass = Class.forName(lafInfo.getClassName()); LookAndFeel laf = (LookAndFeel) (lnfClass.newInstance()); if (laf.isSupportedLookAndFeel()) { String name = lafInfo.getName(); supportedLaFs.add(new SupportedLaF(name, laf)); } } catch (Exception e) { // If ANYTHING weird happens, don't add it continue; } } setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); chooser = new JFileChooser(); previewer = new FilePreviewer(chooser); // Create Custom FileView fileView = new ExampleFileView(); // fileView.putIcon("jpg", new ImageIcon(getClass().getResource("/resources/images/jpgIcon.jpg"))); // fileView.putIcon("gif", new ImageIcon(getClass().getResource("/resources/images/gifIcon.gif"))); // create a radio listener to listen to option changes OptionListener optionListener = new OptionListener(); // Create options openRadioButton = new JRadioButton("Open"); openRadioButton.setSelected(true); openRadioButton.addActionListener(optionListener); saveRadioButton = new JRadioButton("Save"); saveRadioButton.addActionListener(optionListener); customButton = new JRadioButton("Custom"); customButton.addActionListener(optionListener); customField = new JTextField(8) { public Dimension getMaximumSize() { return new Dimension(getPreferredSize().width, getPreferredSize().height); } }; customField.setText("Doit"); customField.setAlignmentY(JComponent.TOP_ALIGNMENT); customField.setEnabled(false); customField.addActionListener(optionListener); ButtonGroup group1 = new ButtonGroup(); group1.add(openRadioButton); group1.add(saveRadioButton); group1.add(customButton); // filter buttons showAllFilesFilterCheckBox = new JCheckBox("Show \"All Files\" Filter"); showAllFilesFilterCheckBox.addActionListener(optionListener); showAllFilesFilterCheckBox.setSelected(true); showImageFilesFilterCheckBox = new JCheckBox("Show JPG and GIF Filters"); showImageFilesFilterCheckBox.addActionListener(optionListener); showImageFilesFilterCheckBox.setSelected(false); accessoryCheckBox = new JCheckBox("Show Preview"); accessoryCheckBox.addActionListener(optionListener); accessoryCheckBox.setSelected(false); // more options setHiddenCheckBox = new JCheckBox("Show Hidden Files"); setHiddenCheckBox.addActionListener(optionListener); showFullDescriptionCheckBox = new JCheckBox("With File Extensions"); showFullDescriptionCheckBox.addActionListener(optionListener); showFullDescriptionCheckBox.setSelected(true); showFullDescriptionCheckBox.setEnabled(false); useFileViewCheckBox = new JCheckBox("Use FileView"); useFileViewCheckBox.addActionListener(optionListener); useFileViewCheckBox.setSelected(false); useEmbedInWizardCheckBox = new JCheckBox("Embed in Wizard"); useEmbedInWizardCheckBox.addActionListener(optionListener); useEmbedInWizardCheckBox.setSelected(false); useControlsCheckBox = new JCheckBox("Show Control Buttons"); useControlsCheckBox.addActionListener(optionListener); useControlsCheckBox.setSelected(true); enableDragCheckBox = new JCheckBox("Enable Dragging"); enableDragCheckBox.addActionListener(optionListener); // File or Directory chooser options ButtonGroup group3 = new ButtonGroup(); justFilesRadioButton = new JRadioButton("Just Select Files"); justFilesRadioButton.setSelected(true); group3.add(justFilesRadioButton); justFilesRadioButton.addActionListener(optionListener); justDirectoriesRadioButton = new JRadioButton("Just Select Directories"); group3.add(justDirectoriesRadioButton); justDirectoriesRadioButton.addActionListener(optionListener); bothFilesAndDirectoriesRadioButton = new JRadioButton("Select Files or Directories"); group3.add(bothFilesAndDirectoriesRadioButton); bothFilesAndDirectoriesRadioButton.addActionListener(optionListener); singleSelectionRadioButton = new JRadioButton("Single Selection", true); singleSelectionRadioButton.addActionListener(optionListener); multiSelectionRadioButton = new JRadioButton("Multi Selection"); multiSelectionRadioButton.addActionListener(optionListener); ButtonGroup group4 = new ButtonGroup(); group4.add(singleSelectionRadioButton); group4.add(multiSelectionRadioButton); // Create show button showButton = new JButton("Show FileChooser"); showButton.addActionListener(this); showButton.setMnemonic('s'); // Create laf combo box lafComboBox = new JComboBox(supportedLaFs); lafComboBox.setEditable(false); lafComboBox.addActionListener(optionListener); // ******************************************************** // ******************** Dialog Type *********************** // ******************************************************** JPanel control1 = new InsetPanel(insets); control1.setBorder(BorderFactory.createTitledBorder("Dialog Type")); control1.setLayout(new BoxLayout(control1, BoxLayout.Y_AXIS)); control1.add(Box.createRigidArea(vpad20)); control1.add(openRadioButton); control1.add(Box.createRigidArea(vpad7)); control1.add(saveRadioButton); control1.add(Box.createRigidArea(vpad7)); control1.add(customButton); control1.add(Box.createRigidArea(vpad4)); JPanel fieldWrapper = new JPanel(); fieldWrapper.setLayout(new BoxLayout(fieldWrapper, BoxLayout.X_AXIS)); fieldWrapper.setAlignmentX(Component.LEFT_ALIGNMENT); fieldWrapper.add(Box.createRigidArea(hpad10)); fieldWrapper.add(Box.createRigidArea(hpad10)); fieldWrapper.add(customField); control1.add(fieldWrapper); control1.add(Box.createRigidArea(vpad20)); control1.add(Box.createGlue()); // ******************************************************** // ***************** Filter Controls ********************** // ******************************************************** JPanel control2 = new InsetPanel(insets); control2.setBorder(BorderFactory.createTitledBorder("Filter Controls")); control2.setLayout(new BoxLayout(control2, BoxLayout.Y_AXIS)); control2.add(Box.createRigidArea(vpad20)); control2.add(showAllFilesFilterCheckBox); control2.add(Box.createRigidArea(vpad7)); control2.add(showImageFilesFilterCheckBox); control2.add(Box.createRigidArea(vpad4)); JPanel checkWrapper = new JPanel(); checkWrapper.setLayout(new BoxLayout(checkWrapper, BoxLayout.X_AXIS)); checkWrapper.setAlignmentX(Component.LEFT_ALIGNMENT); checkWrapper.add(Box.createRigidArea(hpad10)); checkWrapper.add(Box.createRigidArea(hpad10)); checkWrapper.add(showFullDescriptionCheckBox); control2.add(checkWrapper); control2.add(Box.createRigidArea(vpad20)); control2.add(Box.createGlue()); // ******************************************************** // ****************** Display Options ********************* // ******************************************************** JPanel control3 = new InsetPanel(insets); control3.setBorder(BorderFactory.createTitledBorder("Display Options")); control3.setLayout(new BoxLayout(control3, BoxLayout.Y_AXIS)); control3.add(Box.createRigidArea(vpad20)); control3.add(setHiddenCheckBox); control3.add(Box.createRigidArea(vpad7)); control3.add(useFileViewCheckBox); control3.add(Box.createRigidArea(vpad7)); control3.add(accessoryCheckBox); control3.add(Box.createRigidArea(vpad7)); control3.add(useEmbedInWizardCheckBox); control3.add(Box.createRigidArea(vpad7)); control3.add(useControlsCheckBox); control3.add(Box.createRigidArea(vpad7)); control3.add(enableDragCheckBox); control3.add(Box.createRigidArea(vpad20)); control3.add(Box.createGlue()); // ******************************************************** // ************* File & Directory Options ***************** // ******************************************************** JPanel control4 = new InsetPanel(insets); control4.setBorder(BorderFactory.createTitledBorder("File and Directory Options")); control4.setLayout(new BoxLayout(control4, BoxLayout.Y_AXIS)); control4.add(Box.createRigidArea(vpad20)); control4.add(justFilesRadioButton); control4.add(Box.createRigidArea(vpad7)); control4.add(justDirectoriesRadioButton); control4.add(Box.createRigidArea(vpad7)); control4.add(bothFilesAndDirectoriesRadioButton); control4.add(Box.createRigidArea(vpad20)); control4.add(singleSelectionRadioButton); control4.add(Box.createRigidArea(vpad7)); control4.add(multiSelectionRadioButton); control4.add(Box.createRigidArea(vpad20)); control4.add(Box.createGlue()); // ******************************************************** // **************** Look & Feel Switch ******************** // ******************************************************** JPanel panel = new JPanel(); panel.add(new JLabel("Look and Feel: ")); panel.add(lafComboBox); panel.add(showButton); // ******************************************************** // ****************** Wrap 'em all up ********************* // ******************************************************** JPanel wrapper = new JPanel(); wrapper.setLayout(new BoxLayout(wrapper, BoxLayout.X_AXIS)); add(Box.createRigidArea(vpad20)); wrapper.add(Box.createRigidArea(hpad10)); wrapper.add(Box.createRigidArea(hpad10)); wrapper.add(control1); wrapper.add(Box.createRigidArea(hpad10)); wrapper.add(control2); wrapper.add(Box.createRigidArea(hpad10)); wrapper.add(control3); wrapper.add(Box.createRigidArea(hpad10)); wrapper.add(control4); wrapper.add(Box.createRigidArea(hpad10)); wrapper.add(Box.createRigidArea(hpad10)); add(wrapper); add(Box.createRigidArea(vpad20)); add(panel); add(Box.createRigidArea(vpad20)); }
From source file:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java
/** * Build action buttons sub panel//www. j a v a 2 s .c om */ protected JPanel buildActionButtonSubPanel() { // Add the action buttons sub panel. JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); JButton cancelButton = new JButton(resourceBundle.getString("Cancel")); cancelButton.setMnemonic('A'); cancelButton.setToolTipText(resourceBundle.getString("ToolTip.Cancel_measurement")); panel.add(Box.createHorizontalGlue()); panel.add(saveButton); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(cancelButton); // Save button listener. saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sendOutputToServer(); } }); // Cancel button listener. cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { confirmOnExit(); } }); panel.setAlignmentX(Component.LEFT_ALIGNMENT); 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 w w w.j a v a 2 s . c om*/ 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:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java
protected JPanel buildFileSelectionSubPanel() { final JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(Box.createVerticalGlue()); JButton openButton = new JButton(resourceBundle.getString("Select_file")); openButton.setMnemonic('O'); openButton.setToolTipText(resourceBundle.getString("ToolTip.Select_file")); panel.add(openButton);//from w w w. jav a 2 s. c om panel.add(Box.createRigidArea(new Dimension(10, 10))); JLabel fileLabel = new ABIFileLabel(); panel.add(fileLabel); // Open button listener. openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int returnVal = fileChooser.showOpenDialog(appWindow); if (returnVal == JFileChooser.APPROVE_OPTION) { abiFile = fileChooser.getSelectedFile(); panel.repaint(); saveButton.setEnabled(true); } } }); panel.setAlignmentX(Component.LEFT_ALIGNMENT); return panel; }
From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication2.java
private void setSliders() { if (sliderPanel != null) sliderPanel.removeAll();/*from w w w . ja v a2s . c o m*/ else sliderPanel = new JPanel(); JPanel rPanel = new JPanel(); // rPanel.setBackground(Color.blue); JPanel rPanel2 = new JPanel(); // rPanel2.setBackground(Color.green); rPanel.setAlignmentX(LEFT_ALIGNMENT); rPanel2.setAlignmentX(LEFT_ALIGNMENT); rSliders = new FloatTextField[numStocks]; //expected return JPanel matrixPanel = new JPanel(); matrixPanel.setAlignmentX(LEFT_ALIGNMENT); mSliders = new FloatTextField[15]; JPanel tPanel = new JPanel(); tPanel.setAlignmentX(LEFT_ALIGNMENT); // tPanel.setBackground(Color.blue); //tSlider = new ValueSliderFloat2("Tangency:", -0.5, 0.5, false); tSlider = new FloatTextField("Tangency:", t1_y, 0, 1); //tSlider.setPreferredSize(new Dimension(SLIDER_SIZE_X,45)); newMSlider(1, 0, tSlider, tPanel); //expected return rPanel.setLayout(new GridBagLayout()); rPanel.add(new JLabel("Expected Return:")); for (int i = 0; i < numStocks; i++) { rSliders[i] = new FloatTextField("E(R" + (i + 1) + ")", ExpectedReturn[i][0], -0.2, 0.2); rSliders[i].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45)); rSliders[i].setToolTipText("Adjusting the value of expected return for stock " + (i + 1) + "."); newMSlider(1, i, rSliders[i], rPanel); } ER_matrix = new Matrix(numStocks, 1, ExpectedReturn); // Covariance rPanel2.setLayout(new GridBagLayout()); rPanel2.add(new JLabel("Variance:")); for (int i = 0; i < numStocks; i++) { mSliders[i] = new FloatTextField("VAR(R" + (i + 1) + ")", COVR[i][i], 0.0, 0.2); mSliders[i].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45)); mSliders[i].setToolTipText("Adjusting the value of variance " + (i + 1) + "."); newMSlider(1, i, mSliders[i], rPanel2); } matrixPanel.setLayout(new GridBagLayout()); if (covarianceFlag) addRadioButton(0, 0, "Switch Input Matrix:", "Switch Input Matrix", switchArray, 0, matrixPanel, (ActionListener) this); else addRadioButton(0, 0, "Switch Input Matrix:", "Switch Input Matrix", switchArray, 1, matrixPanel, (ActionListener) this); switchedFlag = false; if (covarianceFlag) { // matrixPanel.add(new JLabel("Covariance Matrix:")); int k = numStocks; for (int i = 1; i < numStocks; i++) for (int j = 0; j < i; j++) { mSliders[k] = new FloatTextField("COV" + (i + 1) + (j + 1), COVR[i][j], -0.5, 0.5); mSliders[k].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45)); mSliders[k] .setToolTipText("Adjusting the value of correlation " + (i + 1) + "," + (j + 1) + "."); newMSlider(i, j, mSliders[k], matrixPanel); k++; } } else { // matrixPanel.add(new JLabel("Correlation Matrix:")); int k = numStocks; for (int i = 1; i < numStocks; i++) for (int j = 0; j < i; j++) { mSliders[k] = new FloatTextField("CORR" + (i + 1) + (j + 1), CORR[i][j], -0.5, 0.5); mSliders[k].setPreferredSize(new Dimension(SLIDER_SIZE_X / numStocks, 45)); mSliders[k] .setToolTipText("Adjusting the value of correlation " + (i + 1) + "," + (j + 1) + "."); newMSlider(i, j, mSliders[k], matrixPanel); if (CORR[i][j] > 1) System.out.println("setting slider CORR[" + i + "][" + j + "]=" + CORR[i][j]); k++; } } try { CORR = covr2corr(COVR, ExpectedReturn, numStocks); } catch (Exception e) { System.out.println("corrlation out of range."); } covr_matrix = new Matrix(numStocks, numStocks, COVR); corr_matrix = new Matrix(numStocks, numStocks, CORR); sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.PAGE_AXIS)); /*Box box = Box.createVerticalBox(); box.add(rPanel); box.add(rPanel2); box.add(new JLabel("Correlation Matrix:")); box.add(matrixPanel); sliderPanel.add(box);*/ //sliderPanel.setBackground(Color.red); matrixPanel.validate(); sliderPanel.add(rPanel); sliderPanel.add(rPanel2); sliderPanel.add(Box.createRigidArea(new Dimension(0, 5))); sliderPanel.add(matrixPanel); sliderPanel.add(tPanel); sliderPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); sliderPanel.validate(); //sliderPanel.setBackground(Color.white); }
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/*www .ja v a2 s. c o 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:org.obiba.onyx.jade.instrument.ricelake.RiceLakeWeightInstrumentRunner.java
/** * Build action buttons sub panel/* ww w. j a va2 s . c o m*/ */ protected JPanel buildActionButtonSubPanel() { JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(Box.createHorizontalGlue()); panel.add(saveButton); JButton resetButton = new JButton(resourceBundle.getString("Reset")); resetButton.setMnemonic('R'); resetButton.setToolTipText(resourceBundle.getString("ToolTip.Reset_measurement")); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(resetButton); JButton cancelButton = new JButton(resourceBundle.getString("Cancel")); cancelButton.setMnemonic('A'); cancelButton.setToolTipText(resourceBundle.getString("ToolTip.Cancel_measurement")); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(cancelButton); JButton configureButton = new JButton(resourceBundle.getString("Configure")); configureButton.setMnemonic('C'); configureButton.setToolTipText(resourceBundle.getString("ToolTip.Configure")); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(configureButton); // Configure button listener configureButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { configure(); } }); // Reset button listener resetButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { clearData(); } }); // Save button listener. saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sendOutputToServer(); } }); // Cancel button listener. cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { confirmOnExit(); } }); panel.setAlignmentX(Component.LEFT_ALIGNMENT); return (panel); }
From source file:edu.ucla.stat.SOCR.applications.demo.PortfolioApplication.java
private void initSliders() { sliderPanel = new JPanel(); JPanel rPanel = new JPanel(); JPanel rPanel2 = new JPanel(); rSliders = new FloatSlider[numStocks]; R = new double[numStocks]; double[] r = { 0.0064, 0.0022, 0.02117, 0.01, 0.0134 }; JPanel matrixPanel = new JPanel(); mSliders = new FloatSlider[15]; CORR = new double[numStocks][numStocks]; double[] m = { 0.0101, 0.0045, 0.0122, 0.0041, 0.0026, 0.0119, 0.0012, 0.0011, 0.0015, 0.0141, 0.0043, 0.0022, 0.0058, 0.005, 0.0144 }; rPanel.setLayout(new GridBagLayout()); rPanel.add(new JLabel("Expected Return:")); for (int i = 0; i < numStocks; i++) { R[i] = r[i];/*from w ww.jav a 2 s . com*/ rSliders[i] = new edu.ucla.stat.SOCR.util.FloatSlider("E(R" + (i + 1) + ")", -0.1, 0.1, r[i], false); rSliders[i].setPreferredSize(new Dimension(CHART_SIZE_X / 3, 80)); rSliders[i] .setToolTipText("Slider for adjusting the value of expected return for stock " + (i + 1) + "."); newMSlider(1, i, rSliders[i], r[i], rPanel); } rPanel2.setLayout(new GridBagLayout()); rPanel2.add(new JLabel("Covariance:")); for (int i = 0; i < numStocks; i++) { R[i] = r[i]; mSliders[i] = new edu.ucla.stat.SOCR.util.FloatSlider("VAR(R" + (i + 1) + ")", 0, 0.5); mSliders[i].setPreferredSize(new Dimension(CHART_SIZE_X / 3, 80)); mSliders[i].setToolTipText("Slider for adjusting the value of covariance " + (i + 1) + "."); newMSlider(1, i, mSliders[i], m[i], rPanel2); } matrixPanel.setLayout(new GridBagLayout()); matrixPanel.add(new JLabel("Correlation Matrix:")); int k = 0; for (int i = 0; i < numStocks; i++) for (int j = 0; j <= i; j++) { CORR[i][j] = m[k]; if (i == j) { mSliders[k] = new edu.ucla.stat.SOCR.util.FloatSlider("VAR(R" + (i + 1) + ")", 0, 0.5); // newMSlider(i,j,mSliders[k],m[k],matrixPanel); } else { mSliders[k] = new edu.ucla.stat.SOCR.util.FloatSlider("COV" + (j + 1) + (i + 1), 0, 0.5); mSliders[k].setPreferredSize(new Dimension(CHART_SIZE_X * 5 / 12, 80)); mSliders[k].setToolTipText("Slider for adjusting the value of covariance matrix (" + (j + 1) + "," + (i + 1) + ")."); newMSlider(i, j, mSliders[k], m[k], matrixPanel); } k++; } sliderPanel.setLayout(new BoxLayout(sliderPanel, BoxLayout.PAGE_AXIS)); /*Box box = Box.createVerticalBox(); box.add(rPanel); box.add(rPanel2); box.add(new JLabel("Correlation Matrix:")); box.add(matrixPanel); sliderPanel.add(box);*/ rPanel.setAlignmentX(LEFT_ALIGNMENT); rPanel2.setAlignmentX(LEFT_ALIGNMENT); matrixPanel.setAlignmentX(LEFT_ALIGNMENT); sliderPanel.add(rPanel); sliderPanel.add(rPanel2); sliderPanel.add(Box.createRigidArea(new Dimension(0, 5))); sliderPanel.add(matrixPanel); sliderPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); //sliderPanel.setBackground(Color.white); }
From source file:com.google.code.facebook.graph.sna.applet.PluggableRendererDemo.java
/** * @param jp panel to which controls will be added *///from w w w. j av a2s . c om @SuppressWarnings("serial") protected void addBottomControls(final JPanel jp) { final JPanel control_panel = new JPanel(); jp.add(control_panel, BorderLayout.EAST); control_panel.setLayout(new BorderLayout()); final Box vertex_panel = Box.createVerticalBox(); vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices")); final Box edge_panel = Box.createVerticalBox(); edge_panel.setBorder(BorderFactory.createTitledBorder("Edges")); final Box both_panel = Box.createVerticalBox(); control_panel.add(vertex_panel, BorderLayout.NORTH); control_panel.add(edge_panel, BorderLayout.SOUTH); control_panel.add(both_panel, BorderLayout.CENTER); // set up vertex controls v_color = new JCheckBox("seed highlight"); v_color.addActionListener(this); v_stroke = new JCheckBox("stroke highlight on selection"); v_stroke.addActionListener(this); v_labels = new JCheckBox("show voltage values"); v_labels.addActionListener(this); v_shape = new JCheckBox("shape by degree"); v_shape.addActionListener(this); v_size = new JCheckBox("size by voltage"); v_size.addActionListener(this); v_size.setSelected(true); v_aspect = new JCheckBox("stretch by degree ratio"); v_aspect.addActionListener(this); v_small = new JCheckBox("filter when degree < " + VertexDisplayPredicate.MIN_DEGREE); v_small.addActionListener(this); vertex_panel.add(v_color); vertex_panel.add(v_stroke); vertex_panel.add(v_labels); vertex_panel.add(v_shape); vertex_panel.add(v_size); vertex_panel.add(v_aspect); vertex_panel.add(v_small); // set up edge controls JPanel gradient_panel = new JPanel(new GridLayout(1, 0)); gradient_panel.setBorder(BorderFactory.createTitledBorder("Edge paint")); no_gradient = new JRadioButton("Solid color"); no_gradient.addActionListener(this); no_gradient.setSelected(true); // gradient_absolute = new JRadioButton("Absolute gradient"); // gradient_absolute.addActionListener(this); gradient_relative = new JRadioButton("Gradient"); gradient_relative.addActionListener(this); ButtonGroup bg_grad = new ButtonGroup(); bg_grad.add(no_gradient); bg_grad.add(gradient_relative); //bg_grad.add(gradient_absolute); gradient_panel.add(no_gradient); //gradientGrid.add(gradient_absolute); gradient_panel.add(gradient_relative); JPanel shape_panel = new JPanel(new GridLayout(3, 2)); shape_panel.setBorder(BorderFactory.createTitledBorder("Edge shape")); e_line = new JRadioButton("line"); e_line.addActionListener(this); e_line.setSelected(true); // e_bent = new JRadioButton("bent line"); // e_bent.addActionListener(this); e_wedge = new JRadioButton("wedge"); e_wedge.addActionListener(this); e_quad = new JRadioButton("quad curve"); e_quad.addActionListener(this); e_cubic = new JRadioButton("cubic curve"); e_cubic.addActionListener(this); e_ortho = new JRadioButton("orthogonal"); e_ortho.addActionListener(this); ButtonGroup bg_shape = new ButtonGroup(); bg_shape.add(e_line); // bg.add(e_bent); bg_shape.add(e_wedge); bg_shape.add(e_quad); bg_shape.add(e_ortho); bg_shape.add(e_cubic); shape_panel.add(e_line); // shape_panel.add(e_bent); shape_panel.add(e_wedge); shape_panel.add(e_quad); shape_panel.add(e_cubic); shape_panel.add(e_ortho); fill_edges = new JCheckBox("fill edge shapes"); fill_edges.setSelected(false); fill_edges.addActionListener(this); shape_panel.add(fill_edges); shape_panel.setOpaque(true); e_color = new JCheckBox("highlight edge weights"); e_color.addActionListener(this); e_labels = new JCheckBox("show edge weight values"); e_labels.addActionListener(this); e_uarrow_pred = new JCheckBox("undirected"); e_uarrow_pred.addActionListener(this); e_darrow_pred = new JCheckBox("directed"); e_darrow_pred.addActionListener(this); e_darrow_pred.setSelected(true); e_arrow_centered = new JCheckBox("centered"); e_arrow_centered.addActionListener(this); JPanel arrow_panel = new JPanel(new GridLayout(1, 0)); arrow_panel.setBorder(BorderFactory.createTitledBorder("Show arrows")); arrow_panel.add(e_uarrow_pred); arrow_panel.add(e_darrow_pred); arrow_panel.add(e_arrow_centered); e_show_d = new JCheckBox("directed"); e_show_d.addActionListener(this); e_show_d.setSelected(true); e_show_u = new JCheckBox("undirected"); e_show_u.addActionListener(this); e_show_u.setSelected(true); JPanel show_edge_panel = new JPanel(new GridLayout(1, 0)); show_edge_panel.setBorder(BorderFactory.createTitledBorder("Show edges")); show_edge_panel.add(e_show_u); show_edge_panel.add(e_show_d); shape_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(shape_panel); gradient_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(gradient_panel); show_edge_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(show_edge_panel); arrow_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(arrow_panel); e_color.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_color); e_labels.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_labels); // set up zoom controls zoom_at_mouse = new JCheckBox("<html><center>zoom at mouse<p>(wheel only)</center></html>"); zoom_at_mouse.addActionListener(this); zoom_at_mouse.setSelected(true); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel zoomPanel = new JPanel(); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); plus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(plus); minus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(minus); zoom_at_mouse.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(zoom_at_mouse); JPanel fontPanel = new JPanel(); // add font and zoom controls to center panel font = new JCheckBox("bold text"); font.addActionListener(this); font.setAlignmentX(Component.CENTER_ALIGNMENT); fontPanel.add(font); both_panel.add(zoomPanel); both_panel.add(fontPanel); JComboBox modeBox = gm.getModeComboBox(); modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel modePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); JPanel comboGrid = new JPanel(new GridLayout(0, 1)); comboGrid.add(modePanel); fontPanel.add(comboGrid); JComboBox cb = new JComboBox(); cb.addItem(Renderer.VertexLabel.Position.N); cb.addItem(Renderer.VertexLabel.Position.NE); cb.addItem(Renderer.VertexLabel.Position.E); cb.addItem(Renderer.VertexLabel.Position.SE); cb.addItem(Renderer.VertexLabel.Position.S); cb.addItem(Renderer.VertexLabel.Position.SW); cb.addItem(Renderer.VertexLabel.Position.W); cb.addItem(Renderer.VertexLabel.Position.NW); cb.addItem(Renderer.VertexLabel.Position.N); cb.addItem(Renderer.VertexLabel.Position.CNTR); cb.addItem(Renderer.VertexLabel.Position.AUTO); cb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { Renderer.VertexLabel.Position position = (Renderer.VertexLabel.Position) e.getItem(); vv.getRenderer().getVertexLabelRenderer().setPosition(position); vv.repaint(); } }); cb.setSelectedItem(Renderer.VertexLabel.Position.SE); JPanel positionPanel = new JPanel(); positionPanel.setBorder(BorderFactory.createTitledBorder("Label Position")); positionPanel.add(cb); comboGrid.add(positionPanel); }
From source file:edu.uci.ics.jung.samples.PluggableRendererDemo.java
/** * @param jp panel to which controls will be added *///from w w w . ja v a2 s .c o m @SuppressWarnings({ "rawtypes", "unchecked" }) protected void addBottomControls(final JPanel jp) { final JPanel control_panel = new JPanel(); jp.add(control_panel, BorderLayout.EAST); control_panel.setLayout(new BorderLayout()); final Box vertex_panel = Box.createVerticalBox(); vertex_panel.setBorder(BorderFactory.createTitledBorder("Vertices")); final Box edge_panel = Box.createVerticalBox(); edge_panel.setBorder(BorderFactory.createTitledBorder("Edges")); final Box both_panel = Box.createVerticalBox(); control_panel.add(vertex_panel, BorderLayout.NORTH); control_panel.add(edge_panel, BorderLayout.SOUTH); control_panel.add(both_panel, BorderLayout.CENTER); // set up vertex controls v_color = new JCheckBox("seed highlight"); v_color.addActionListener(this); v_stroke = new JCheckBox("stroke highlight on selection"); v_stroke.addActionListener(this); v_labels = new JCheckBox("show voltage values"); v_labels.addActionListener(this); v_shape = new JCheckBox("shape by degree"); v_shape.addActionListener(this); v_size = new JCheckBox("size by voltage"); v_size.addActionListener(this); v_size.setSelected(true); v_aspect = new JCheckBox("stretch by degree ratio"); v_aspect.addActionListener(this); v_small = new JCheckBox("filter when degree < " + VertexDisplayPredicate.MIN_DEGREE); v_small.addActionListener(this); vertex_panel.add(v_color); vertex_panel.add(v_stroke); vertex_panel.add(v_labels); vertex_panel.add(v_shape); vertex_panel.add(v_size); vertex_panel.add(v_aspect); vertex_panel.add(v_small); // set up edge controls JPanel gradient_panel = new JPanel(new GridLayout(1, 0)); gradient_panel.setBorder(BorderFactory.createTitledBorder("Edge paint")); no_gradient = new JRadioButton("Solid color"); no_gradient.addActionListener(this); no_gradient.setSelected(true); // gradient_absolute = new JRadioButton("Absolute gradient"); // gradient_absolute.addActionListener(this); gradient_relative = new JRadioButton("Gradient"); gradient_relative.addActionListener(this); ButtonGroup bg_grad = new ButtonGroup(); bg_grad.add(no_gradient); bg_grad.add(gradient_relative); //bg_grad.add(gradient_absolute); gradient_panel.add(no_gradient); //gradientGrid.add(gradient_absolute); gradient_panel.add(gradient_relative); JPanel shape_panel = new JPanel(new GridLayout(3, 2)); shape_panel.setBorder(BorderFactory.createTitledBorder("Edge shape")); e_line = new JRadioButton("line"); e_line.addActionListener(this); e_line.setSelected(true); // e_bent = new JRadioButton("bent line"); // e_bent.addActionListener(this); e_wedge = new JRadioButton("wedge"); e_wedge.addActionListener(this); e_quad = new JRadioButton("quad curve"); e_quad.addActionListener(this); e_cubic = new JRadioButton("cubic curve"); e_cubic.addActionListener(this); e_ortho = new JRadioButton("orthogonal"); e_ortho.addActionListener(this); ButtonGroup bg_shape = new ButtonGroup(); bg_shape.add(e_line); // bg.add(e_bent); bg_shape.add(e_wedge); bg_shape.add(e_quad); bg_shape.add(e_ortho); bg_shape.add(e_cubic); shape_panel.add(e_line); // shape_panel.add(e_bent); shape_panel.add(e_wedge); shape_panel.add(e_quad); shape_panel.add(e_cubic); shape_panel.add(e_ortho); fill_edges = new JCheckBox("fill edge shapes"); fill_edges.setSelected(false); fill_edges.addActionListener(this); shape_panel.add(fill_edges); shape_panel.setOpaque(true); e_color = new JCheckBox("highlight edge weights"); e_color.addActionListener(this); e_labels = new JCheckBox("show edge weight values"); e_labels.addActionListener(this); e_uarrow_pred = new JCheckBox("undirected"); e_uarrow_pred.addActionListener(this); e_darrow_pred = new JCheckBox("directed"); e_darrow_pred.addActionListener(this); e_darrow_pred.setSelected(true); e_arrow_centered = new JCheckBox("centered"); e_arrow_centered.addActionListener(this); JPanel arrow_panel = new JPanel(new GridLayout(1, 0)); arrow_panel.setBorder(BorderFactory.createTitledBorder("Show arrows")); arrow_panel.add(e_uarrow_pred); arrow_panel.add(e_darrow_pred); arrow_panel.add(e_arrow_centered); e_show_d = new JCheckBox("directed"); e_show_d.addActionListener(this); e_show_d.setSelected(true); e_show_u = new JCheckBox("undirected"); e_show_u.addActionListener(this); e_show_u.setSelected(true); JPanel show_edge_panel = new JPanel(new GridLayout(1, 0)); show_edge_panel.setBorder(BorderFactory.createTitledBorder("Show edges")); show_edge_panel.add(e_show_u); show_edge_panel.add(e_show_d); shape_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(shape_panel); gradient_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(gradient_panel); show_edge_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(show_edge_panel); arrow_panel.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(arrow_panel); e_color.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_color); e_labels.setAlignmentX(Component.LEFT_ALIGNMENT); edge_panel.add(e_labels); // set up zoom controls zoom_at_mouse = new JCheckBox("<html><center>zoom at mouse<p>(wheel only)</center></html>"); zoom_at_mouse.addActionListener(this); zoom_at_mouse.setSelected(true); final ScalingControl scaler = new CrossoverScalingControl(); JButton plus = new JButton("+"); plus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); JButton minus = new JButton("-"); minus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); JPanel zoomPanel = new JPanel(); zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom")); plus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(plus); minus.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(minus); zoom_at_mouse.setAlignmentX(Component.CENTER_ALIGNMENT); zoomPanel.add(zoom_at_mouse); JPanel fontPanel = new JPanel(); // add font and zoom controls to center panel font = new JCheckBox("bold text"); font.addActionListener(this); font.setAlignmentX(Component.CENTER_ALIGNMENT); fontPanel.add(font); both_panel.add(zoomPanel); both_panel.add(fontPanel); JComboBox modeBox = gm.getModeComboBox(); modeBox.setAlignmentX(Component.CENTER_ALIGNMENT); JPanel modePanel = new JPanel(new BorderLayout()) { public Dimension getMaximumSize() { return getPreferredSize(); } }; modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); JPanel comboGrid = new JPanel(new GridLayout(0, 1)); comboGrid.add(modePanel); fontPanel.add(comboGrid); JComboBox cb = new JComboBox(); cb.addItem(Renderer.VertexLabel.Position.N); cb.addItem(Renderer.VertexLabel.Position.NE); cb.addItem(Renderer.VertexLabel.Position.E); cb.addItem(Renderer.VertexLabel.Position.SE); cb.addItem(Renderer.VertexLabel.Position.S); cb.addItem(Renderer.VertexLabel.Position.SW); cb.addItem(Renderer.VertexLabel.Position.W); cb.addItem(Renderer.VertexLabel.Position.NW); cb.addItem(Renderer.VertexLabel.Position.N); cb.addItem(Renderer.VertexLabel.Position.CNTR); cb.addItem(Renderer.VertexLabel.Position.AUTO); cb.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { Renderer.VertexLabel.Position position = (Renderer.VertexLabel.Position) e.getItem(); vv.getRenderer().getVertexLabelRenderer().setPosition(position); vv.repaint(); } }); cb.setSelectedItem(Renderer.VertexLabel.Position.SE); JPanel positionPanel = new JPanel(); positionPanel.setBorder(BorderFactory.createTitledBorder("Label Position")); positionPanel.add(cb); comboGrid.add(positionPanel); }