List of usage examples for javax.swing ButtonGroup ButtonGroup
public ButtonGroup()
ButtonGroup
. From source file:net.sf.jabref.gui.preftabs.TableColumnsTab.java
/** * Customization of external program paths. * * @param prefs a <code>JabRefPreferences</code> value *///w ww. j ava 2s .c om public TableColumnsTab(JabRefPreferences prefs, JabRefFrame frame) { this.prefs = prefs; this.frame = frame; setLayout(new BorderLayout()); TableModel tm = new AbstractTableModel() { @Override public int getRowCount() { return rowCount; } @Override public int getColumnCount() { return 2; } @Override public Object getValueAt(int row, int column) { int internalRow = row; if (internalRow == 0) { return column == 0 ? InternalBibtexFields.NUMBER_COL : String.valueOf(ncWidth); } internalRow--; if (internalRow >= tableRows.size()) { return ""; } Object rowContent = tableRows.get(internalRow); if (rowContent == null) { return ""; } TableRow tr = (TableRow) rowContent; // Only two columns if (column == 0) { return tr.getName(); } else { return tr.getLength() > 0 ? Integer.toString(tr.getLength()) : ""; } } @Override public String getColumnName(int col) { return col == 0 ? Localization.lang("Field name") : Localization.lang("Column width"); } @Override public Class<?> getColumnClass(int column) { if (column == 0) { return String.class; } return Integer.class; } @Override public boolean isCellEditable(int row, int col) { return !((row == 0) && (col == 0)); } @Override public void setValueAt(Object value, int row, int col) { tableChanged = true; // Make sure the vector is long enough. while (row >= tableRows.size()) { tableRows.add(new TableRow("", -1)); } if ((row == 0) && (col == 1)) { ncWidth = Integer.parseInt(value.toString()); return; } TableRow rowContent = tableRows.get(row - 1); if (col == 0) { rowContent.setName(value.toString()); if ("".equals(getValueAt(row, 1))) { setValueAt(String.valueOf(BibtexSingleField.DEFAULT_FIELD_LENGTH), row, 1); } } else { if (value == null) { rowContent.setLength(-1); } else { rowContent.setLength(Integer.parseInt(value.toString())); } } } }; colSetup = new JTable(tm); TableColumnModel cm = colSetup.getColumnModel(); cm.getColumn(0).setPreferredWidth(140); cm.getColumn(1).setPreferredWidth(80); FormLayout layout = new FormLayout("1dlu, 8dlu, left:pref, 4dlu, fill:pref", ""); DefaultFormBuilder builder = new DefaultFormBuilder(layout); JPanel pan = new JPanel(); JPanel tabPanel = new JPanel(); tabPanel.setLayout(new BorderLayout()); JScrollPane sp = new JScrollPane(colSetup, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); colSetup.setPreferredScrollableViewportSize(new Dimension(250, 200)); sp.setMinimumSize(new Dimension(250, 300)); tabPanel.add(sp, BorderLayout.CENTER); JToolBar toolBar = new OSXCompatibleToolbar(SwingConstants.VERTICAL); toolBar.setFloatable(false); AddRowAction addRow = new AddRowAction(); DeleteRowAction deleteRow = new DeleteRowAction(); MoveRowUpAction moveUp = new MoveRowUpAction(); MoveRowDownAction moveDown = new MoveRowDownAction(); toolBar.setBorder(null); toolBar.add(addRow); toolBar.add(deleteRow); toolBar.addSeparator(); toolBar.add(moveUp); toolBar.add(moveDown); tabPanel.add(toolBar, BorderLayout.EAST); fileColumn = new JCheckBox(Localization.lang("Show file column")); urlColumn = new JCheckBox(Localization.lang("Show URL/DOI column")); preferUrl = new JRadioButton(Localization.lang("Show URL first")); preferDoi = new JRadioButton(Localization.lang("Show DOI first")); ButtonGroup preferUrlDoiGroup = new ButtonGroup(); preferUrlDoiGroup.add(preferUrl); preferUrlDoiGroup.add(preferDoi); urlColumn.addChangeListener(arg0 -> { preferUrl.setEnabled(urlColumn.isSelected()); preferDoi.setEnabled(urlColumn.isSelected()); }); arxivColumn = new JCheckBox(Localization.lang("Show ArXiv column")); Collection<ExternalFileType> fileTypes = ExternalFileTypes.getInstance().getExternalFileTypeSelection(); String[] fileTypeNames = new String[fileTypes.size()]; int i = 0; for (ExternalFileType fileType : fileTypes) { fileTypeNames[i++] = fileType.getName(); } listOfFileColumns = new JList<>(fileTypeNames); JScrollPane listOfFileColumnsScrollPane = new JScrollPane(listOfFileColumns); listOfFileColumns.setVisibleRowCount(3); extraFileColumns = new JCheckBox(Localization.lang("Show extra columns")); extraFileColumns.addChangeListener(arg0 -> listOfFileColumns.setEnabled(extraFileColumns.isSelected())); /*** begin: special table columns and special fields ***/ JButton helpButton = new HelpAction(Localization.lang("Help on special fields"), HelpFile.SPECIAL_FIELDS) .getHelpButton(); rankingColumn = new JCheckBox(Localization.lang("Show rank")); qualityColumn = new JCheckBox(Localization.lang("Show quality")); priorityColumn = new JCheckBox(Localization.lang("Show priority")); relevanceColumn = new JCheckBox(Localization.lang("Show relevance")); printedColumn = new JCheckBox(Localization.lang("Show printed status")); readStatusColumn = new JCheckBox(Localization.lang("Show read status")); // "sync keywords" and "write special" fields may be configured mutually exclusive only // The implementation supports all combinations (TRUE+TRUE and FALSE+FALSE, even if the latter does not make sense) // To avoid confusion, we opted to make the setting mutually exclusive syncKeywords = new JRadioButton(Localization.lang("Synchronize with keywords")); writeSpecialFields = new JRadioButton( Localization.lang("Write values of special fields as separate fields to BibTeX")); ButtonGroup group = new ButtonGroup(); group.add(syncKeywords); group.add(writeSpecialFields); specialFieldsEnabled = new JCheckBox(Localization.lang("Enable special fields")); specialFieldsEnabled.addChangeListener(event -> { boolean isEnabled = specialFieldsEnabled.isSelected(); rankingColumn.setEnabled(isEnabled); qualityColumn.setEnabled(isEnabled); priorityColumn.setEnabled(isEnabled); relevanceColumn.setEnabled(isEnabled); printedColumn.setEnabled(isEnabled); readStatusColumn.setEnabled(isEnabled); syncKeywords.setEnabled(isEnabled); writeSpecialFields.setEnabled(isEnabled); }); builder.appendSeparator(Localization.lang("Special table columns")); builder.nextLine(); builder.append(pan); DefaultFormBuilder specialTableColumnsBuilder = new DefaultFormBuilder( new FormLayout("8dlu, 8dlu, 8cm, 8dlu, 8dlu, left:pref:grow", "pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref, pref")); CellConstraints cc = new CellConstraints(); specialTableColumnsBuilder.add(specialFieldsEnabled, cc.xyw(1, 1, 3)); specialTableColumnsBuilder.add(rankingColumn, cc.xyw(2, 2, 2)); specialTableColumnsBuilder.add(relevanceColumn, cc.xyw(2, 3, 2)); specialTableColumnsBuilder.add(qualityColumn, cc.xyw(2, 4, 2)); specialTableColumnsBuilder.add(priorityColumn, cc.xyw(2, 5, 2)); specialTableColumnsBuilder.add(printedColumn, cc.xyw(2, 6, 2)); specialTableColumnsBuilder.add(readStatusColumn, cc.xyw(2, 7, 2)); specialTableColumnsBuilder.add(syncKeywords, cc.xyw(2, 10, 2)); specialTableColumnsBuilder.add(writeSpecialFields, cc.xyw(2, 11, 2)); specialTableColumnsBuilder.add(helpButton, cc.xyw(1, 12, 2)); specialTableColumnsBuilder.add(fileColumn, cc.xyw(5, 1, 2)); specialTableColumnsBuilder.add(urlColumn, cc.xyw(5, 2, 2)); specialTableColumnsBuilder.add(preferUrl, cc.xy(6, 3)); specialTableColumnsBuilder.add(preferDoi, cc.xy(6, 4)); specialTableColumnsBuilder.add(arxivColumn, cc.xyw(5, 5, 2)); specialTableColumnsBuilder.add(extraFileColumns, cc.xyw(5, 6, 2)); specialTableColumnsBuilder.add(listOfFileColumnsScrollPane, cc.xywh(5, 7, 2, 6)); builder.append(specialTableColumnsBuilder.getPanel()); builder.nextLine(); /*** end: special table columns and special fields ***/ builder.appendSeparator(Localization.lang("Entry table columns")); builder.nextLine(); builder.append(pan); builder.append(tabPanel); builder.nextLine(); builder.append(pan); JButton buttonWidth = new JButton(new UpdateWidthsAction()); JButton buttonOrder = new JButton(new UpdateOrderAction()); builder.append(buttonWidth); builder.nextLine(); builder.append(pan); builder.append(buttonOrder); builder.nextLine(); builder.append(pan); builder.nextLine(); pan = builder.getPanel(); pan.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(pan, BorderLayout.CENTER); }
From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.ApproximationSetViewer.java
/** * Initializes this window. This method is invoked in the constructor, and * should not be invoked again./*from w w w . j a v a 2s. co m*/ */ protected void initialize() { //initialize the NFE slider int minimumNFE = Integer.MAX_VALUE; int maximumNFE = Integer.MIN_VALUE; for (Accumulator accumulator : accumulators) { minimumNFE = Math.min(minimumNFE, (Integer) accumulator.get("NFE", 0)); maximumNFE = Math.max(maximumNFE, (Integer) accumulator.get("NFE", accumulator.size("NFE") - 1)); } slider = new JSlider(minimumNFE, maximumNFE, minimumNFE); slider.setPaintTicks(true); slider.setMinorTickSpacing(100); slider.setMajorTickSpacing(1000); slider.addChangeListener(this); //initializes the options available for axis plotting Solution solution = (Solution) ((List<?>) accumulators.get(0).get("Approximation Set", 0)).get(0); Vector<String> objectives = new Vector<String>(); for (int i = 0; i < solution.getNumberOfObjectives(); i++) { objectives.add(localization.getString("text.objective", i + 1)); } for (int i = 0; i < solution.getNumberOfConstraints(); i++) { objectives.add(localization.getString("text.constraint", i + 1)); } for (int i = 0; i < solution.getNumberOfVariables(); i++) { objectives.add(localization.getString("text.variable", i + 1)); } xAxisSelection = new JComboBox(objectives); yAxisSelection = new JComboBox(objectives); xAxisSelection.setSelectedIndex(0); yAxisSelection.setSelectedIndex(1); xAxisSelection.addActionListener(this); yAxisSelection.addActionListener(this); //initialize the reference set bounds initializeReferenceSetBounds(); //initialize plotting controls useInitialBounds = new JRadioButton(localization.getString("action.useInitialBounds.name")); useReferenceSetBounds = new JRadioButton(localization.getString("action.useReferenceSetBounds.name")); useDynamicBounds = new JRadioButton(localization.getString("action.useDynamicBounds.name")); useZoomBounds = new JRadioButton(localization.getString("action.useZoom.name")); useInitialBounds.setToolTipText(localization.getString("action.useInitialBounds.description")); useReferenceSetBounds.setToolTipText(localization.getString("action.useReferenceSetBounds.description")); useDynamicBounds.setToolTipText(localization.getString("action.useDynamicBounds.description")); useZoomBounds.setToolTipText(localization.getString("action.useZoom.description")); ButtonGroup rangeButtonGroup = new ButtonGroup(); rangeButtonGroup.add(useInitialBounds); rangeButtonGroup.add(useReferenceSetBounds); rangeButtonGroup.add(useDynamicBounds); rangeButtonGroup.add(useZoomBounds); if (referenceSet == null) { useReferenceSetBounds.setEnabled(false); } useInitialBounds.setSelected(true); useInitialBounds.addActionListener(this); useReferenceSetBounds.addActionListener(this); useDynamicBounds.addActionListener(this); useZoomBounds.addActionListener(this); //initialize the seed list String[] seeds = new String[accumulators.size()]; for (int i = 0; i < accumulators.size(); i++) { seeds[i] = localization.getString("text.seed", i + 1); } seedList = new JList(seeds); seedList.addListSelectionListener(this); selectAll = new JButton(new AbstractAction() { private static final long serialVersionUID = -3709557130361259485L; { putValue(Action.NAME, localization.getString("action.selectAll.name")); } @Override public void actionPerformed(ActionEvent e) { seedList.getSelectionModel().setSelectionInterval(0, seedList.getModel().getSize() - 1); } }); //initialize miscellaneous components paintHelper = new PaintHelper(); paintHelper.set(localization.getString("text.referenceSet"), Color.BLACK); chartContainer = new JPanel(new BorderLayout()); }
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 av a2 s.c o 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:forms.frDados.java
/** * Carrega os temas disponveis e adiciona ao menu de temas. *///from w ww . ja v a2 s .co m private void inicializarTemas() { String winLnF = UIManager.getSystemLookAndFeelClassName(); ButtonGroup group = new ButtonGroup(); for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { JRadioButtonMenuItem mnuItem = new JRadioButtonMenuItem(info.getName()); mnuItem.addActionListener(this); if (winLnF.equals(info.getClassName())) mnuItem.setSelected(true); group.add(mnuItem); mnuTemas.add(mnuItem); } }
From source file:cool.pandora.modeller.ui.jpanel.base.SaveBagFrame.java
private JPanel createComponents() { final Border border = new EmptyBorder(5, 5, 5, 5); final TitlePane titlePane = new TitlePane(); initStandardCommands();//from ww w . j av a2s. c om final JPanel pageControl = new JPanel(new BorderLayout()); final JPanel titlePaneContainer = new JPanel(new BorderLayout()); titlePane.setTitle(bagView.getPropertyMessage("SaveBagFrame.title")); titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Define the Bag " + "settings"))); titlePaneContainer.add(titlePane.getControl()); titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH); pageControl.add(titlePaneContainer, BorderLayout.NORTH); final JPanel contentPane = new JPanel(); // TODO: Add bag name field // TODO: Add save name file selection button final JLabel location = new JLabel("Save in:"); final JButton browseButton = new JButton(getMessage("bag.button.browse")); browseButton.addActionListener(new SaveBagAsHandler()); browseButton.setEnabled(true); browseButton.setToolTipText(getMessage("bag.button.browse.help")); final DefaultBag bag = bagView.getBag(); if (bag != null) { bagNameField = new JTextField(bag.getName()); bagNameField.setCaretPosition(bag.getName().length()); bagNameField.setEditable(false); bagNameField.setEnabled(false); } // Holey bag control final JLabel holeyLabel = new JLabel(bagView.getPropertyMessage("bag.label.isholey")); holeyLabel.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); final JCheckBox holeyCheckbox = new JCheckBox(bagView.getPropertyMessage("bag.checkbox" + ".isholey")); holeyCheckbox.setBorder(border); holeyCheckbox.addActionListener(new HoleyBagHandler()); holeyCheckbox.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label")); urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description")); urlField = new JTextField(""); try { assert bag != null; urlField.setText(bag.getFetch().getBaseURL()); } catch (Exception e) { log.error("Failed to set url label", e); } urlField.setEnabled(false); // TODO: Add format label final JLabel serializeLabel; serializeLabel = new JLabel(getMessage("bag.label.ispackage")); serializeLabel.setToolTipText(getMessage("bag.serializetype.help")); // TODO: Add format selection panel noneButton = new JRadioButton(getMessage("bag.serializetype.none")); noneButton.setEnabled(true); final AbstractAction serializeListener = new SerializeBagHandler(); noneButton.addActionListener(serializeListener); noneButton.setToolTipText(getMessage("bag.serializetype.none.help")); zipButton = new JRadioButton(getMessage("bag.serializetype.zip")); zipButton.setEnabled(true); zipButton.addActionListener(serializeListener); zipButton.setToolTipText(getMessage("bag.serializetype.zip.help")); /* * tarButton = new JRadioButton(getMessage("bag.serializetype.tar")); * tarButton.setEnabled(true); * tarButton.addActionListener(serializeListener); * tarButton.setToolTipText(getMessage("bag.serializetype.tar.help")); * * tarGzButton = new JRadioButton(getMessage("bag.serializetype.targz")); * tarGzButton.setEnabled(true); * tarGzButton.addActionListener(serializeListener); * tarGzButton.setToolTipText(getMessage("bag.serializetype.targz.help")); * * tarBz2Button = new JRadioButton(getMessage("bag.serializetype.tarbz2")); * tarBz2Button.setEnabled(true); * tarBz2Button.addActionListener(serializeListener); * tarBz2Button.setToolTipText(getMessage("bag.serializetype.tarbz2.help")); */ short mode = 2; if (bag != null) { mode = bag.getSerialMode(); } if (mode == DefaultBag.NO_MODE) { this.noneButton.setEnabled(true); } else if (mode == DefaultBag.ZIP_MODE) { this.zipButton.setEnabled(true); } else { this.noneButton.setEnabled(true); } final ButtonGroup serializeGroup = new ButtonGroup(); serializeGroup.add(noneButton); serializeGroup.add(zipButton); // serializeGroup.add(tarButton); // serializeGroup.add(tarGzButton); // serializeGroup.add(tarBz2Button); final JPanel serializeGroupPanel = new JPanel(new FlowLayout()); serializeGroupPanel.add(serializeLabel); serializeGroupPanel.add(noneButton); serializeGroupPanel.add(zipButton); // serializeGroupPanel.add(tarButton); // serializeGroupPanel.add(tarGzButton); // serializeGroupPanel.add(tarBz2Button); serializeGroupPanel.setBorder(border); serializeGroupPanel.setEnabled(true); serializeGroupPanel.setToolTipText(bagView.getPropertyMessage("bag.serializetype.help")); final JLabel tagLabel = new JLabel(getMessage("bag.label.istag")); tagLabel.setToolTipText(getMessage("bag.label.istag.help")); final JCheckBox isTagCheckbox = new JCheckBox(); isTagCheckbox.setBorder(border); isTagCheckbox.addActionListener(new TagManifestHandler()); isTagCheckbox.setToolTipText(getMessage("bag.checkbox.istag.help")); final JLabel tagAlgorithmLabel = new JLabel(getMessage("bag.label.tagalgorithm")); tagAlgorithmLabel.setToolTipText(getMessage("bag.label.tagalgorithm.help")); final ArrayList<String> listModel = new ArrayList<>(); for (final Algorithm algorithm : Algorithm.values()) { listModel.add(algorithm.bagItAlgorithm); } final JComboBox<String> tagAlgorithmList = new JComboBox<>(listModel.toArray(new String[listModel.size()])); tagAlgorithmList.setName(getMessage("bag.tagalgorithmlist")); tagAlgorithmList.addActionListener(new TagAlgorithmListHandler()); tagAlgorithmList.setToolTipText(getMessage("bag.tagalgorithmlist.help")); final JLabel payloadLabel = new JLabel(getMessage("bag.label.ispayload")); payloadLabel.setToolTipText(getMessage("bag.ispayload.help")); final JCheckBox isPayloadCheckbox = new JCheckBox(); isPayloadCheckbox.setBorder(border); isPayloadCheckbox.addActionListener(new PayloadManifestHandler()); isPayloadCheckbox.setToolTipText(getMessage("bag.ispayload.help")); final JLabel payAlgorithmLabel = new JLabel(bagView.getPropertyMessage("bag.label" + ".payalgorithm")); payAlgorithmLabel.setToolTipText(getMessage("bag.payalgorithm.help")); final JComboBox<String> payAlgorithmList = new JComboBox<String>( listModel.toArray(new String[listModel.size()])); payAlgorithmList.setName(getMessage("bag.payalgorithmlist")); payAlgorithmList.addActionListener(new PayAlgorithmListHandler()); payAlgorithmList.setToolTipText(getMessage("bag.payalgorithmlist.help")); //only if bag is not null if (bag != null) { final String fileName = bag.getName(); bagNameField = new JTextField(fileName); bagNameField.setCaretPosition(fileName.length()); holeyCheckbox.setSelected(bag.isHoley()); urlLabel.setEnabled(bag.isHoley()); isTagCheckbox.setSelected(bag.isBuildTagManifest()); tagAlgorithmList.setSelectedItem(bag.getTagManifestAlgorithm()); isPayloadCheckbox.setSelected(bag.isBuildPayloadManifest()); payAlgorithmList.setSelectedItem(bag.getPayloadManifestAlgorithm()); } final GridBagLayout layout = new GridBagLayout(); final GridBagConstraints glbc = new GridBagConstraints(); final JPanel panel = new JPanel(layout); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); int row = 0; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(location, glbc); panel.add(location); buildConstraints(glbc, 2, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.EAST); glbc.ipadx = 5; layout.setConstraints(browseButton, glbc); glbc.ipadx = 0; panel.add(browseButton); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); glbc.ipadx = 5; layout.setConstraints(bagNameField, glbc); glbc.ipadx = 0; panel.add(bagNameField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(holeyLabel, glbc); panel.add(holeyLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.WEST, GridBagConstraints.WEST); layout.setConstraints(holeyCheckbox, glbc); panel.add(holeyCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(urlLabel, glbc); panel.add(urlLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(urlField, glbc); panel.add(urlField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(serializeLabel, glbc); panel.add(serializeLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); layout.setConstraints(serializeGroupPanel, glbc); panel.add(serializeGroupPanel); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagLabel, glbc); panel.add(tagLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isTagCheckbox, glbc); panel.add(isTagCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagAlgorithmLabel, glbc); panel.add(tagAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(tagAlgorithmList, glbc); panel.add(tagAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payloadLabel, glbc); panel.add(payloadLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isPayloadCheckbox, glbc); panel.add(isPayloadCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payAlgorithmLabel, glbc); panel.add(payAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(payAlgorithmList, glbc); panel.add(payAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); GuiStandardUtils.attachDialogBorder(contentPane); pageControl.add(panel); final JComponent buttonBar = createButtonBar(); pageControl.add(buttonBar, BorderLayout.SOUTH); this.pack(); return pageControl; }
From source file:io.datalayer.jung.LensVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.//from ww w.j ava 2 s .c o 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:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.area.AreaDoseResponseController.java
/** * Initialize main view//from www .ja v a2 s .c o m */ @Override protected void initMainView() { dRPanel = new DRPanel(); //create a ButtonGroup for the radioButtons used for analysis ButtonGroup mainDRRadioButtonGroup = new ButtonGroup(); //adding buttons to a ButtonGroup automatically deselect one when another one gets selected mainDRRadioButtonGroup.add(dRPanel.getInputDRButton()); mainDRRadioButtonGroup.add(dRPanel.getInitialPlotDRButton()); mainDRRadioButtonGroup.add(dRPanel.getNormalizedPlotDRButton()); mainDRRadioButtonGroup.add(dRPanel.getResultsDRButton()); //select as default first button dRPanel.getInputDRButton().setSelected(true); //init dataTable dataTable = new JTable(); JScrollPane scrollPane = new JScrollPane(dataTable); //the table will take all the viewport height available dataTable.setFillsViewportHeight(true); scrollPane.getViewport().setBackground(Color.white); dataTable.getTableHeader().setReorderingAllowed(false); //row and column selection must be false //dataTable.setColumnSelectionAllowed(false); //dataTable.setRowSelectionAllowed(false); dRPanel.getDatatableDRPanel().add(scrollPane, BorderLayout.CENTER); /** * When button is selected, switch view to corresponding subview */ dRPanel.getInputDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //switch shared table view updateModelInTable(dRInputController.getTableModel()); updateTableInfoMessage("This table contains all conditions and their respective slopes"); /** * for (int columnIndex = 0; columnIndex < * dataTable.getColumnCount(); columnIndex++) { * GuiUtils.packColumn(dataTable, columnIndex); } */ dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); //remove other panels dRInitialController.getInitialChartPanel().setChart(null); dRNormalizedController.getNormalizedChartPanel().setChart(null); dRResultsController.getDupeInitialChartPanel().setChart(null); dRResultsController.getDupeNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); //add panel to view dRPanel.getGraphicsDRParentPanel().add(dRInputController.getdRInputPanel(), gridBagConstraints); } }); dRPanel.getInitialPlotDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dRAnalysisGroup != null) { if (isFirstFitting()) { initFirstFitting(); setFirstFitting(false); } //switch shared table view updateModelInTable(dRInitialController.getTableModel()); updateTableInfoMessage( "Concentrations of conditions selected previously have been log-transformed, slopes have not been changed"); /** * for (int columnIndex = 0; columnIndex < * dataTable.getColumnCount(); columnIndex++) { * GuiUtils.packColumn(dataTable, columnIndex); } */ dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); //remove other panels dRNormalizedController.getNormalizedChartPanel().setChart(null); dRResultsController.getDupeInitialChartPanel().setChart(null); dRResultsController.getDupeNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); dRPanel.getGraphicsDRParentPanel().add(dRInitialController.getDRInitialPlotPanel(), gridBagConstraints); //Plot fitted data in dose-response curve, along with R annotation plotDoseResponse(dRInitialController.getInitialChartPanel(), dRInitialController.getDRInitialPlotPanel().getDoseResponseChartParentPanel(), getDataToFit(false), getdRAnalysisGroup(), false); } } }); dRPanel.getNormalizedPlotDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dRAnalysisGroup != null) { //in case user skips "initial" subview and goes straight to normalization if (isFirstFitting()) { initFirstFitting(); setFirstFitting(false); } //switch shared table view updateModelInTable(dRNormalizedController.getTableModel()); updateTableInfoMessage( "Log-transformed concentrations with their normalized responses per replicate"); /** * for (int columnIndex = 0; columnIndex < * dataTable.getColumnCount(); columnIndex++) { * GuiUtils.packColumn(dataTable, columnIndex); } */ dataTable.getTableHeader().setDefaultRenderer(new TableHeaderRenderer(SwingConstants.LEFT)); //remove other panels dRInitialController.getInitialChartPanel().setChart(null); dRResultsController.getDupeInitialChartPanel().setChart(null); dRResultsController.getDupeNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); dRPanel.getGraphicsDRParentPanel().add(dRNormalizedController.getDRNormalizedPlotPanel(), gridBagConstraints); //Plot fitted data in dose-response curve, along with R annotation plotDoseResponse(dRNormalizedController.getNormalizedChartPanel(), dRNormalizedController.getDRNormalizedPlotPanel().getDoseResponseChartParentPanel(), getDataToFit(true), getdRAnalysisGroup(), true); } } }); dRPanel.getResultsDRButton().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (dRAnalysisGroup != null) { //switch shared table view: create and set new table model with most recent statistical values // (these values get recalculated after each new fitting) dRResultsController.setTableModel(dRResultsController.reCreateTableModel(dRAnalysisGroup)); updateModelInTable(dRResultsController.getTableModel()); updateTableInfoMessage( "Statistical values from the curve fit of the initial and normalized data."); //remove other panels dRInitialController.getInitialChartPanel().setChart(null); dRNormalizedController.getNormalizedChartPanel().setChart(null); dRPanel.getGraphicsDRParentPanel().removeAll(); dRPanel.getGraphicsDRParentPanel().revalidate(); dRPanel.getGraphicsDRParentPanel().repaint(); dRPanel.getGraphicsDRParentPanel().add(dRResultsController.getdRResultsPanel(), gridBagConstraints); //plot curves dRResultsController.plotCharts(); } } }); //add view to parent panel areaMainController.getAreaAnalysisPanel().getDoseResponseParentPanel().add(dRPanel, gridBagConstraints); }
From source file:edu.uci.ics.jung.samples.LensVertexImageShaperDemo.java
/** * create an instance of a simple graph with controls to * demo the zoom features.// w ww .j a va 2 s.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:SoundBug.java
JPanel soundPanel() { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(4, 1)); // create the buttons soundNoneButton = new JRadioButton(soundNoneString); soundBackgroundButton = new JRadioButton(soundBackgroundString); soundPointButton = new JRadioButton(soundPointString); //soundConeButton = new JRadioButton(soundConeString); // set up the action commands soundNoneButton.setActionCommand(soundNoneString); soundBackgroundButton.setActionCommand(soundBackgroundActionString); soundPointButton.setActionCommand(soundPointActionString); //soundConeButton.setActionCommand(soundConeString); // add the buttons to a group so that only one can be selected ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(soundNoneButton);//ww w . ja v a 2 s . c o m buttonGroup.add(soundBackgroundButton); buttonGroup.add(soundPointButton); //buttonGroup.add(soundConeButton); // register the applet as the listener for the buttons soundNoneButton.addActionListener(this); soundBackgroundButton.addActionListener(this); soundPointButton.addActionListener(this); // soundConeButton.addActionListener(this); // add the buttons to the panel panel.add(soundNoneButton); panel.add(soundBackgroundButton); panel.add(soundPointButton); //panel.add(soundConeButton); // set the default soundNoneButton.setSelected(true); return panel; }
From source file:com.hexidec.ekit.component.UnicodeDialog.java
public void init(int startIndex) { String customFont = Translatrix.getTranslationString("UnicodeDialogButtonFont"); if (customFont != null && customFont.length() > 0) { buttonFont = new Font(Translatrix.getTranslationString("UnicodeDialogButtonFont"), Font.PLAIN, 12); } else {/*w w w . j a v a 2 s .c o m*/ buttonFont = new Font("Monospaced", Font.PLAIN, 12); } Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); JPanel centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(0, 17, 0, 0)); buttonGroup = new ButtonGroup(); int prefButtonWidth = 32; int prefButtonHeight = 32; centerPanel.add(new JLabel("")); for (int labelLoop = 0; labelLoop < 16; labelLoop++) { JLabel jlblMarker = new JLabel( "x" + (labelLoop > 9 ? "" + (char) (65 + (labelLoop - 10)) : "" + labelLoop)); jlblMarker.setHorizontalAlignment(SwingConstants.CENTER); jlblMarker.setVerticalAlignment(SwingConstants.CENTER); jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f)); centerPanel.add(jlblMarker); } int labelcount = 0; for (int counter = 0; counter < UNICODEBLOCKSIZE; counter++) { if ((counter % 16) == 0) { JLabel jlblMarker = new JLabel( (labelcount > 9 ? "" + (char) (65 + (labelcount - 10)) : "" + labelcount) + "x"); jlblMarker.setHorizontalAlignment(SwingConstants.CENTER); jlblMarker.setVerticalAlignment(SwingConstants.CENTER); jlblMarker.setForeground(new Color(0.5f, 0.5f, 0.75f)); centerPanel.add(jlblMarker); labelcount++; } buttonArray[counter] = new JToggleButton(" "); buttonArray[counter].getModel().setActionCommand(""); buttonArray[counter].setFont(buttonFont); buttonArray[counter].setBorder( javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED)); buttonArray[counter].addActionListener(this); if (counter == 0) { FontRenderContext frcLocal = ((java.awt.Graphics2D) (parentEkit.getGraphics())) .getFontRenderContext(); Rectangle2D fontBounds = buttonFont.getMaxCharBounds(frcLocal); int maxCharWidth = (int) (Math.abs(fontBounds.getX())) + (int) (Math.abs(fontBounds.getWidth())); int maxCharHeight = (int) (Math.abs(fontBounds.getY())) + (int) (Math.abs(fontBounds.getHeight())); Insets buttonInsets = buttonArray[counter].getBorder().getBorderInsets(buttonArray[counter]); prefButtonWidth = maxCharWidth + buttonInsets.left + buttonInsets.right; prefButtonHeight = maxCharHeight + buttonInsets.top + buttonInsets.bottom; } buttonArray[counter].setPreferredSize(new Dimension(prefButtonWidth, prefButtonHeight)); centerPanel.add(buttonArray[counter]); buttonGroup.add(buttonArray[counter]); } JPanel selectorPanel = new JPanel(); jcmbBlockSelector = new JComboBox(unicodeBlocks); jcmbBlockSelector.setSelectedIndex(startIndex); jcmbBlockSelector.setActionCommand(CMDCHANGEBLOCK); jcmbBlockSelector.addActionListener(this); String[] sPages = { "1" }; jcmbPageSelector = new JComboBox(sPages); jcmbPageSelector.setSelectedIndex(0); jcmbPageSelector.setActionCommand(CMDCHANGEBLOCK); jcmbPageSelector.addActionListener(this); selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodeBlock"))); selectorPanel.add(jcmbBlockSelector); selectorPanel.add(new JLabel(Translatrix.getTranslationString("SelectorToolUnicodePage"))); selectorPanel.add(jcmbPageSelector); JPanel buttonPanel = new JPanel(); JButton closeButton = new JButton(Translatrix.getTranslationString("DialogClose")); closeButton.setActionCommand("close"); closeButton.addActionListener(this); buttonPanel.add(closeButton); contentPane.add(centerPanel, BorderLayout.CENTER); contentPane.add(selectorPanel, BorderLayout.NORTH); contentPane.add(buttonPanel, BorderLayout.SOUTH); this.pack(); populateButtons(startIndex, 0); this.setVisible(true); }