List of usage examples for javax.swing JRadioButton setSelected
public void setSelected(boolean b)
From source file:emailplugin.MailCreator.java
/** * Gives the User the opportunity to specify which Desktop he uses (KDE or * Gnome)//from w w w . j a v a 2 s .c o m * * @param parent * Parent Dialog * @return true if KDE or Gnome has been selected, false if the User wanted to * specify the App */ private boolean showKdeGnomeDialog(Frame parent) { final JDialog dialog = new JDialog(parent, true); dialog.setTitle(mLocalizer.msg("chooseTitle", "Choose")); JPanel panel = (JPanel) dialog.getContentPane(); panel.setLayout(new FormLayout("10dlu, fill:pref:grow", "default, 3dlu, default, 3dlu, default, 3dlu, default, 3dlu:grow, default")); panel.setBorder(Borders.DIALOG_BORDER); CellConstraints cc = new CellConstraints(); panel.add(UiUtilities.createHelpTextArea(mLocalizer.msg("cantConfigure", "Can't configure on your system")), cc.xyw(1, 1, 2)); JRadioButton kdeButton = new JRadioButton(mLocalizer.msg("kde", "I am using KDE")); panel.add(kdeButton, cc.xy(2, 3)); JRadioButton gnomeButton = new JRadioButton(mLocalizer.msg("gnome", "I am using Gnome")); panel.add(gnomeButton, cc.xy(2, 5)); JRadioButton selfButton = new JRadioButton(mLocalizer.msg("self", "I want to configure by myself")); panel.add(selfButton, cc.xy(2, 7)); ButtonGroup group = new ButtonGroup(); group.add(kdeButton); group.add(gnomeButton); group.add(selfButton); selfButton.setSelected(true); JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dialog.setVisible(false); } }); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonPanel.add(ok); panel.add(buttonPanel, cc.xy(2, 9)); UiUtilities.registerForClosing(new WindowClosingIf() { public void close() { dialog.setVisible(false); } public JRootPane getRootPane() { return dialog.getRootPane(); } }); dialog.getRootPane().setDefaultButton(ok); dialog.pack(); UiUtilities.centerAndShow(dialog); if (kdeButton.isSelected()) { mSettings.setApplication("kfmclient"); mSettings.setParameter("exec {content}"); } else if (gnomeButton.isSelected()) { mSettings.setApplication("gnome-open"); mSettings.setParameter("{content}"); } else { Plugin.getPluginManager().showSettings(mPlugin); return false; } return true; }
From source file:eu.apenet.dpt.standalone.gui.APETabbedPane.java
private JComponent makeCheckboxes() { xsltPanel.setLayout(new BoxLayout(xsltPanel, BoxLayout.PAGE_AXIS)); xsltPanel.add(stylesheetLabel);/*from w w w .j a v a 2 s . c om*/ JRadioButton radioButton; for (File xsltFile : Utilities.getXsltFiles()) { radioButton = new JRadioButton(xsltFile.getName()); if (xsltFile.getName().equals(retrieveFromDb.retrieveDefaultXsl())) radioButton.setSelected(true); radioButton.addActionListener(new XsltSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXslt().add(radioButton); xsltPanel.add(radioButton); xsltPanel.add(Box.createRigidArea(new Dimension(0, 10))); } return xsltPanel; }
From source file:eu.apenet.dpt.standalone.gui.APETabbedPane.java
private JComponent makeCheckboxesXsd() { xsdPanel.setLayout(new BoxLayout(xsdPanel, BoxLayout.PAGE_AXIS)); xsdPanel.add(schemaLabel);/*from w w w . ja v a 2 s . c om*/ JRadioButton radioButton; for (Xsd_enum xsdEnum : Xsd_enum.values()) { radioButton = new JRadioButton(xsdEnum.getReadableName()); if (xsdEnum.getReadableName().equals(retrieveFromDb.retrieveDefaultXsd())) radioButton.setSelected(true); radioButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXsd().add(radioButton); xsdPanel.add(radioButton); xsdPanel.add(Box.createRigidArea(new Dimension(0, 10))); } for (XsdObject additionalXsd : retrieveFromDb.retrieveAdditionalXsds()) { radioButton = new JRadioButton(additionalXsd.getName()); radioButton.addActionListener(new XsdSelectorListener(dataPreparationToolGUI)); dataPreparationToolGUI.getGroupXsd().add(radioButton); xsdPanel.add(radioButton); xsdPanel.add(Box.createRigidArea(new Dimension(0, 10))); } return xsdPanel; }
From source file:JXButtonPanel.java
private JXButtonPanel createRadioJXButtonPanel() { JXButtonPanel panel = new JXButtonPanel(); panel.setLayout(new GridLayout(0, 1)); JRadioButton one = new JRadioButton("One"); panel.add(one);/* w w w .ja v a 2 s.c o m*/ radioGroup.add(one); JRadioButton two = new JRadioButton("Two"); panel.add(two); radioGroup.add(two); JRadioButton three = new JRadioButton("Three"); panel.add(three); radioGroup.add(three); JRadioButton four = new JRadioButton("Four"); panel.add(four); radioGroup.add(four); one.setSelected(true); panel.setBorder(BorderFactory.createTitledBorder("JXButtonPanel")); return panel; }
From source file:net.pandoragames.far.ui.swing.dialog.SettingsDialog.java
private void init() { this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS)); this.setResizable(false); JPanel basePanel = new JPanel(); basePanel.setLayout(new BoxLayout(basePanel, BoxLayout.Y_AXIS)); basePanel.setBorder(// w ww .j a v a 2 s. c om BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); registerCloseWindowKeyListener(basePanel); // sink for error messages MessageLabel errorField = new MessageLabel(); errorField.setMinimumSize(new Dimension(100, swingConfig.getStandardComponentHight())); errorField.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); TwoComponentsPanel lineError = new TwoComponentsPanel(errorField, Box.createRigidArea(new Dimension(1, swingConfig.getStandardComponentHight()))); lineError.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineError); // character set JLabel labelCharset = new JLabel(swingConfig.getLocalizer().localize("label.default-characterset")); labelCharset.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(labelCharset); JComboBox listCharset = new JComboBox(swingConfig.getCharsetList().toArray()); listCharset.setAlignmentX(Component.LEFT_ALIGNMENT); listCharset.setSelectedItem(swingConfig.getDefaultCharset()); listCharset.setEditable(true); listCharset.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); listCharset.addActionListener(new CharacterSetListener(errorField)); listCharset.setEditor(new CharacterSetEditor(errorField)); basePanel.add(listCharset); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // select the group selector JPanel selectorPanel = new JPanel(); selectorPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); selectorPanel.setAlignmentX(Component.LEFT_ALIGNMENT); // linePattern.setAlignmentX( Component.LEFT_ALIGNMENT ); JLabel labelSelector = new JLabel(swingConfig.getLocalizer().localize("label.group-ref-indicator")); selectorPanel.add(labelSelector); JComboBox selectorBox = new JComboBox(FARConfig.GROUPREFINDICATORLIST); selectorBox.setSelectedItem(Character.toString(groupReference)); selectorBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JComboBox cbox = (JComboBox) event.getSource(); String indicator = (String) cbox.getSelectedItem(); groupReference = indicator.charAt(0); } }); selectorPanel.add(selectorBox); basePanel.add(selectorPanel); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); // checkbox DO BACKUP JCheckBox doBackupFlag = new JCheckBox(swingConfig.getLocalizer().localize("label.create-backup")); doBackupFlag.setAlignmentX(Component.LEFT_ALIGNMENT); doBackupFlag.setHorizontalTextPosition(SwingConstants.LEADING); doBackupFlag.setSelected(replaceForm.isDoBackup()); doBackupFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { doBackup = ItemEvent.SELECTED == event.getStateChange(); backupFlagEvent = event; } }); basePanel.add(doBackupFlag); JTextField backupDirPathTextField = new JTextField(); backupDirPathTextField.setPreferredSize( new Dimension(SwingConfig.COMPONENT_WIDTH, swingConfig.getStandardComponentHight())); backupDirPathTextField.setMaximumSize( new Dimension(SwingConfig.COMPONENT_WIDTH_MAX, swingConfig.getStandardComponentHight())); backupDirPathTextField.setText(backupDirectory.getPath()); backupDirPathTextField.setToolTipText(backupDirectory.getPath()); backupDirPathTextField.setEditable(false); JButton openBaseDirFileChooserButton = new JButton(swingConfig.getLocalizer().localize("button.browse")); BrowseButtonListener backupDirButtonListener = new BrowseButtonListener(backupDirPathTextField, new BackUpDirectoryRepository(swingConfig, findForm, replaceForm, errorField), swingConfig.getLocalizer().localize("label.choose-backup-directory")); openBaseDirFileChooserButton.addActionListener(backupDirButtonListener); TwoComponentsPanel lineBaseDir = new TwoComponentsPanel(backupDirPathTextField, openBaseDirFileChooserButton); lineBaseDir.setAlignmentX(Component.LEFT_ALIGNMENT); basePanel.add(lineBaseDir); basePanel.add(Box.createRigidArea(new Dimension(1, SwingConfig.PADDING))); JPanel fileInfoPanel = new JPanel(); fileInfoPanel .setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), swingConfig.getLocalizer().localize("label.default-file-info"))); fileInfoPanel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.setLayout(new BoxLayout(fileInfoPanel, BoxLayout.Y_AXIS)); JLabel fileInfoLabel = new JLabel(swingConfig.getLocalizer().localize("message.displayed-in-info-column")); fileInfoLabel.setAlignmentX(Component.LEFT_ALIGNMENT); fileInfoPanel.add(fileInfoLabel); fileInfoPanel.add(Box.createHorizontalGlue()); JRadioButton nothingRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.nothing")); nothingRadio.setAlignmentX(Component.LEFT_ALIGNMENT); nothingRadio.setActionCommand(SwingConfig.DefaultFileInfo.NOTHING.name()); nothingRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.NOTHING); fileInfoOptions.add(nothingRadio); fileInfoPanel.add(nothingRadio); JRadioButton readOnlyRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.read-only-warning")); readOnlyRadio.setAlignmentX(Component.LEFT_ALIGNMENT); readOnlyRadio.setActionCommand(SwingConfig.DefaultFileInfo.READONLY.name()); readOnlyRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.READONLY); fileInfoOptions.add(readOnlyRadio); fileInfoPanel.add(readOnlyRadio); JRadioButton sizeRadio = new JRadioButton(swingConfig.getLocalizer().localize("label.filesize")); sizeRadio.setAlignmentX(Component.LEFT_ALIGNMENT); sizeRadio.setActionCommand(SwingConfig.DefaultFileInfo.SIZE.name()); sizeRadio.setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.SIZE); fileInfoOptions.add(sizeRadio); fileInfoPanel.add(sizeRadio); JCheckBox showPlainBytesFlag = new JCheckBox( " " + swingConfig.getLocalizer().localize("label.show-plain-bytes")); showPlainBytesFlag.setAlignmentX(Component.LEFT_ALIGNMENT); showPlainBytesFlag.setHorizontalTextPosition(SwingConstants.LEADING); showPlainBytesFlag.setSelected(swingConfig.isShowPlainBytes()); showPlainBytesFlag.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent event) { showBytes = ItemEvent.SELECTED == event.getStateChange(); } }); fileInfoPanel.add(showPlainBytesFlag); JRadioButton lastModifiedRadio = new JRadioButton( swingConfig.getLocalizer().localize("label.last-modified")); lastModifiedRadio.setAlignmentX(Component.LEFT_ALIGNMENT); lastModifiedRadio.setActionCommand(SwingConfig.DefaultFileInfo.LAST_MODIFIED.name()); lastModifiedRadio .setSelected(swingConfig.getDefaultFileInfo() == SwingConfig.DefaultFileInfo.LAST_MODIFIED); fileInfoOptions.add(lastModifiedRadio); fileInfoPanel.add(lastModifiedRadio); basePanel.add(fileInfoPanel); // buttons JPanel buttonPannel = new JPanel(); buttonPannel.setAlignmentX(Component.LEFT_ALIGNMENT); buttonPannel.setLayout(new FlowLayout(FlowLayout.TRAILING)); // cancel JButton cancelButton = new JButton(swingConfig.getLocalizer().localize("button.cancel")); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { SettingsDialog.this.dispose(); } }); buttonPannel.add(cancelButton); // save JButton saveButton = new JButton(swingConfig.getLocalizer().localize("button.save")); saveButton.addActionListener(new SaveButtonListener()); buttonPannel.add(saveButton); this.getRootPane().setDefaultButton(saveButton); this.add(basePanel); this.add(buttonPannel); placeOnScreen(swingConfig.getScreenCenter()); }
From source file:edu.uci.ics.jung.samples.HyperbolicVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.//from w w w . j a v a 2s.co m * */ public HyperbolicVertexImageShaperDemo() { // create a simple graph for the demo graph = new DirectedSparseMultigraph<Number, Number>(); Number[] vertices = createVertices(11); // a Map for the labels Map<Number, String> map = new HashMap<Number, String>(); for (int i = 0; i < vertices.length; i++) { map.put(vertices[i], iconNames[i % iconNames.length]); } // a Map for the Icons Map<Number, Icon> iconMap = new HashMap<Number, Icon>(); for (int i = 0; i < vertices.length; i++) { String name = "/images/topic" + iconNames[i] + ".gif"; try { Icon icon = new LayeredIcon( new ImageIcon(HyperbolicVertexImageShaperDemo.class.getResource(name)).getImage()); iconMap.put(vertices[i], icon); } catch (Exception ex) { System.err.println("You need slashdoticons.jar in your classpath to see the image " + name); } } createEdges(vertices); FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(400, 400)); Transformer<Number, Paint> vpf = new PickableVertexPaintTransformer<Number>(vv.getPickedVertexState(), Color.white, Color.yellow); vv.getRenderContext().setVertexFillPaintTransformer(vpf); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.setBackground(Color.white); final Transformer<Number, String> vertexStringerImpl = new VertexStringerImpl<Number>(map); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); // features on and off. For a real application, use VertexIconAndShapeFunction instead. final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>(); vertexImageShapeFunction.setIconMap(iconMap); vertexIconFunction.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction); vv.getRenderContext().setVertexIconTransformer(vertexIconFunction); // Get the pickedState and add a listener that will decorate the // Vertex images with a checkmark icon when they are picked PickedState<Number> ps = vv.getPickedVertexState(); ps.addItemListener(new PickWithIconListener(vertexIconFunction)); vv.addPostRenderPaintable(new VisualizationServer.Paintable() { int x; int y; Font font; FontMetrics metrics; int swidth; int sheight; String str = "Thank You, slashdot.org, for the images!"; public void paint(Graphics g) { Dimension d = vv.getSize(); if (font == null) { font = new Font(g.getFont().getName(), Font.BOLD, 20); metrics = g.getFontMetrics(font); swidth = metrics.stringWidth(str); sheight = metrics.getMaxAscent() + metrics.getMaxDescent(); x = (d.width - swidth) / 2; y = (int) (d.height - sheight * 1.5); } g.setFont(font); Color oldColor = g.getColor(); g.setColor(Color.lightGray); g.drawString(str, x, y); g.setColor(oldColor); } public boolean useTransform() { return false; } }); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Number>()); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse<Number, Number> graphMouse = new DefaultModalGraphMouse<Number, Number>(); vv.setGraphMouse(graphMouse); 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()); } }); JComboBox modeBox = graphMouse.getModeComboBox(); JPanel modePanel = new JPanel(); modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); this.viewSupport = new HyperbolicImageLensSupport<Number, Number>(vv); this.modelSupport = new LayoutLensSupport<Number, Number>(vv); graphMouse.addItemListener(modelSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(viewSupport.getGraphMouse().getModeListener()); ButtonGroup radio = new ButtonGroup(); JRadioButton none = new JRadioButton("None"); none.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (viewSupport != null) { viewSupport.deactivate(); } if (modelSupport != null) { modelSupport.deactivate(); } } }); none.setSelected(true); JRadioButton hyperView = new JRadioButton("View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); JRadioButton hyperModel = new JRadioButton("Layout"); hyperModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { modelSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); radio.add(none); radio.add(hyperView); radio.add(hyperModel); JMenuBar menubar = new JMenuBar(); JMenu modeMenu = graphMouse.getModeMenu(); menubar.add(modeMenu); JPanel lensPanel = new JPanel(new GridLayout(2, 0)); lensPanel.setBorder(BorderFactory.createTitledBorder("Lens")); lensPanel.add(none); lensPanel.add(hyperView); lensPanel.add(hyperModel); controls.add(lensPanel); }
From source file:io.datalayer.jung.LensVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.//w ww.j av a 2 s. co m * */ public LensVertexImageShaperDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<Number, Number>(); Number[] vertices = createVertices(11); // a Map for the labels Map<Number, String> map = new HashMap<Number, String>(); for (int i = 0; i < vertices.length; i++) { map.put(vertices[i], iconNames[i % iconNames.length]); } // a Map for the Icons Map<Number, Icon> iconMap = new HashMap<Number, Icon>(); for (int i = 0; i < vertices.length; i++) { String name = "/images/topic" + iconNames[i] + ".gif"; try { Icon icon = new LayeredIcon( new ImageIcon(LensVertexImageShaperDemo.class.getResource(name)).getImage()); iconMap.put(vertices[i], icon); } catch (Exception ex) { System.err.println("You need slashdoticons.jar in your classpath to see the image " + name); } } createEdges(vertices); FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(600, 600)); Transformer<Number, Paint> vpf = new PickableVertexPaintTransformer<Number>(vv.getPickedVertexState(), Color.white, Color.yellow); vv.getRenderContext().setVertexFillPaintTransformer(vpf); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.setBackground(Color.white); final Transformer<Number, String> vertexStringerImpl = new VertexStringerImpl<Number>(map); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); // features on and off. For a real application, use VertexIconAndShapeFunction instead. final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>(); vertexImageShapeFunction.setIconMap(iconMap); vertexIconFunction.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction); vv.getRenderContext().setVertexIconTransformer(vertexIconFunction); // Get the pickedState and add a listener that will decorate the // Vertex images with a checkmark icon when they are picked PickedState<Number> ps = vv.getPickedVertexState(); ps.addItemListener(new PickWithIconListener(vertexIconFunction)); vv.addPostRenderPaintable(new VisualizationViewer.Paintable() { int x; int y; Font font; FontMetrics metrics; int swidth; int sheight; String str = "Thank You, slashdot.org, for the images!"; public void paint(Graphics g) { Dimension d = vv.getSize(); if (font == null) { font = new Font(g.getFont().getName(), Font.BOLD, 20); metrics = g.getFontMetrics(font); swidth = metrics.stringWidth(str); sheight = metrics.getMaxAscent() + metrics.getMaxDescent(); x = (d.width - swidth) / 2; y = (int) (d.height - sheight * 1.5); } g.setFont(font); Color oldColor = g.getColor(); g.setColor(Color.lightGray); g.drawString(str, x, y); g.setColor(oldColor); } public boolean useTransform() { return false; } }); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Number>()); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); 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()); } }); JComboBox modeBox = graphMouse.getModeComboBox(); JPanel modePanel = new JPanel(); modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); this.viewSupport = new MagnifyImageLensSupport<Number, Number>(vv); // new ViewLensSupport<Number,Number>(vv, new HyperbolicShapeTransformer(vv, // vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), // new ModalLensGraphMouse()); this.modelSupport = new LayoutLensSupport<Number, Number>(vv); graphMouse.addItemListener(modelSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(viewSupport.getGraphMouse().getModeListener()); ButtonGroup radio = new ButtonGroup(); JRadioButton none = new JRadioButton("None"); none.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (viewSupport != null) { viewSupport.deactivate(); } if (modelSupport != null) { modelSupport.deactivate(); } } }); none.setSelected(true); JRadioButton hyperView = new JRadioButton("View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); JRadioButton hyperModel = new JRadioButton("Layout"); hyperModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { modelSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); radio.add(none); radio.add(hyperView); radio.add(hyperModel); JMenuBar menubar = new JMenuBar(); JMenu modeMenu = graphMouse.getModeMenu(); menubar.add(modeMenu); JPanel lensPanel = new JPanel(new GridLayout(2, 0)); lensPanel.setBorder(BorderFactory.createTitledBorder("Lens")); lensPanel.add(none); lensPanel.add(hyperView); lensPanel.add(hyperModel); controls.add(lensPanel); }
From source file:edu.uci.ics.jung.samples.LensVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.//from ww w. j a v a 2s . c om * */ @SuppressWarnings("rawtypes") public LensVertexImageShaperDemo() { // create a simple graph for the demo graph = new DirectedSparseGraph<Number, Number>(); Number[] vertices = createVertices(11); // a Map for the labels Map<Number, String> map = new HashMap<Number, String>(); for (int i = 0; i < vertices.length; i++) { map.put(vertices[i], iconNames[i % iconNames.length]); } // a Map for the Icons Map<Number, Icon> iconMap = new HashMap<Number, Icon>(); for (int i = 0; i < vertices.length; i++) { String name = "/images/topic" + iconNames[i] + ".gif"; try { Icon icon = new LayeredIcon( new ImageIcon(LensVertexImageShaperDemo.class.getResource(name)).getImage()); iconMap.put(vertices[i], icon); } catch (Exception ex) { System.err.println("You need slashdoticons.jar in your classpath to see the image " + name); } } createEdges(vertices); FRLayout<Number, Number> layout = new FRLayout<Number, Number>(graph); layout.setMaxIterations(100); vv = new VisualizationViewer<Number, Number>(layout, new Dimension(600, 600)); Transformer<Number, Paint> vpf = new PickableVertexPaintTransformer<Number>(vv.getPickedVertexState(), Color.white, Color.yellow); vv.getRenderContext().setVertexFillPaintTransformer(vpf); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.cyan)); vv.setBackground(Color.white); final Transformer<Number, String> vertexStringerImpl = new VertexStringerImpl<Number>(map); vv.getRenderContext().setVertexLabelTransformer(vertexStringerImpl); vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan)); vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan)); // features on and off. For a real application, use VertexIconAndShapeFunction instead. final VertexIconShapeTransformer<Number> vertexImageShapeFunction = new VertexIconShapeTransformer<Number>( new EllipseVertexShapeTransformer<Number>()); final DefaultVertexIconTransformer<Number> vertexIconFunction = new DefaultVertexIconTransformer<Number>(); vertexImageShapeFunction.setIconMap(iconMap); vertexIconFunction.setIconMap(iconMap); vv.getRenderContext().setVertexShapeTransformer(vertexImageShapeFunction); vv.getRenderContext().setVertexIconTransformer(vertexIconFunction); // Get the pickedState and add a listener that will decorate the // Vertex images with a checkmark icon when they are picked PickedState<Number> ps = vv.getPickedVertexState(); ps.addItemListener(new PickWithIconListener(vertexIconFunction)); vv.addPostRenderPaintable(new VisualizationViewer.Paintable() { int x; int y; Font font; FontMetrics metrics; int swidth; int sheight; String str = "Thank You, slashdot.org, for the images!"; public void paint(Graphics g) { Dimension d = vv.getSize(); if (font == null) { font = new Font(g.getFont().getName(), Font.BOLD, 20); metrics = g.getFontMetrics(font); swidth = metrics.stringWidth(str); sheight = metrics.getMaxAscent() + metrics.getMaxDescent(); x = (d.width - swidth) / 2; y = (int) (d.height - sheight * 1.5); } g.setFont(font); Color oldColor = g.getColor(); g.setColor(Color.lightGray); g.drawString(str, x, y); g.setColor(oldColor); } public boolean useTransform() { return false; } }); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller<Number>()); Container content = getContentPane(); final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv); content.add(panel); final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); 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()); } }); JComboBox modeBox = graphMouse.getModeComboBox(); JPanel modePanel = new JPanel(); modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode")); modePanel.add(modeBox); JPanel scaleGrid = new JPanel(new GridLayout(1, 0)); scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel controls = new JPanel(); scaleGrid.add(plus); scaleGrid.add(minus); controls.add(scaleGrid); controls.add(modePanel); content.add(controls, BorderLayout.SOUTH); this.viewSupport = new MagnifyImageLensSupport<Number, Number>(vv); // new ViewLensSupport<Number,Number>(vv, new HyperbolicShapeTransformer(vv, // vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), // new ModalLensGraphMouse()); this.modelSupport = new LayoutLensSupport<Number, Number>(vv); graphMouse.addItemListener(modelSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(viewSupport.getGraphMouse().getModeListener()); ButtonGroup radio = new ButtonGroup(); JRadioButton none = new JRadioButton("None"); none.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (viewSupport != null) { viewSupport.deactivate(); } if (modelSupport != null) { modelSupport.deactivate(); } } }); none.setSelected(true); JRadioButton hyperView = new JRadioButton("View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { viewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); JRadioButton hyperModel = new JRadioButton("Layout"); hyperModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { modelSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); radio.add(none); radio.add(hyperView); radio.add(hyperModel); JMenuBar menubar = new JMenuBar(); JMenu modeMenu = graphMouse.getModeMenu(); menubar.add(modeMenu); JPanel lensPanel = new JPanel(new GridLayout(2, 0)); lensPanel.setBorder(BorderFactory.createTitledBorder("Lens")); lensPanel.add(none); lensPanel.add(hyperView); lensPanel.add(hyperModel); controls.add(lensPanel); }
From source file:it.iit.genomics.cru.igb.bundles.mi.view.StructuresPanel.java
public StructuresPanel(IgbService service, String label) { super("MI Structures", "MI Structures", "Display structure", true); igbLogger = IGBLogger.getInstance(label); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); // Create hidden JmolFrame jmolFrame = new JFrame(); jmolPanel = new JmolPanel(); jmolPanel.setPreferredSize(new Dimension(500, 500)); Box jmolBox = new Box(BoxLayout.Y_AXIS); Box jmolButtonBox = new Box(BoxLayout.X_AXIS); jmolFrame.add(jmolBox);/*from w ww .j ava 2s . c o m*/ jmolBox.add(jmolPanel); jmolBox.add(jmolButtonBox); jmolButtonBox.add(new JLabel("Display type:")); ButtonGroup displayGroup = new ButtonGroup(); JRadioButton cartoonButton = new JRadioButton(JMOL_DISPLAY_CARTOON); JRadioButton ballAndSticksButton = new JRadioButton(JMOL_DISPLAY_BALL_AND_STICK); JmolDisplayListener listener = new JmolDisplayListener(); cartoonButton.addActionListener(listener); ballAndSticksButton.addActionListener(listener); displayGroup.add(cartoonButton); displayGroup.add(ballAndSticksButton); jmolButtonBox.add(cartoonButton); jmolButtonBox.add(ballAndSticksButton); ballAndSticksButton.setSelected(true); jmolFrame.pack(); jmolFrame.setVisible(false); jmolButton.addActionListener(new JmolActionListener()); jmolButton.setIcon(new ImageIcon(getClass().getResource("/jmol.jpg"))); linkButton.addActionListener(new ExternalLinkActionListener()); linkButton.setIcon(CommonUtils.getInstance().getIcon("16x16/actions/searchweb.png")); StructureTableModel model = new StructureTableModel(new ArrayList<StructureItem>(0)); structureList = new StructureTable(model, service); structureList.setTableHeader(null); structureList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane structureListPane = new JScrollPane(structureList); add(structureListPane); }
From source file:IsEDTExample.java
public IsEDTExample() { JTable table = new JTable(tableModel); table.setRowHeight(100);//from www.j a v a2 s .co m table.setDefaultRenderer(Object.class, new ColorRenderer()); add(table); add(new JLabel("Thread Color Shade:")); ButtonGroup group = new ButtonGroup(); JRadioButton redOption = new JRadioButton("Red"); group.add(redOption); redOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = RED; } }); JRadioButton blueOption = new JRadioButton("Blue"); group.add(blueOption); blueOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = BLUE; } }); JRadioButton greenOption = new JRadioButton("Green"); group.add(greenOption); greenOption.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { threadShade = GREEN; } }); redOption.setSelected(true); this.threadShade = RED; add(redOption); add(greenOption); add(blueOption); add(new JButton(new RandomColorAction())); this.keepRunning = true; this.colorShadeThread = new Thread(new RandomColorShadeRunnable()); this.colorShadeThread.start(); }