List of usage examples for javax.swing JPanel setBorder
@BeanProperty(preferred = true, visualUpdate = true, description = "The component's border.") public void setBorder(Border border)
From source file:com.floreantpos.ui.forms.QuickCustomerForm.java
private void createCustomerForm() { setLayout(new BorderLayout(10, 10)); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); setOpaque(true);// w w w. ja v a2s. c o m JPanel inputPanel = new JPanel(); inputPanel.setLayout(new MigLayout("insets 10 10 10 10", "[][][][]", "[][][][][]")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ inputPanel.setBorder(BorderFactory.createTitledBorder("Enter Customer Information")); JLabel lblAddress = new JLabel(Messages.getString("CustomerForm.18")); //$NON-NLS-1$ tfAddress = new JTextArea(new FixedLengthDocument(220)); JScrollPane scrlDescription = new JScrollPane(tfAddress); scrlDescription.setPreferredSize(PosUIManager.getSize(338, 52)); JLabel lblZip = new JLabel(Messages.getString("CustomerForm.21")); //$NON-NLS-1$ tfZip = new FixedLengthTextField(30); JLabel lblCitytown = new JLabel(Messages.getString("CustomerForm.24")); //$NON-NLS-1$ tfCity = new FixedLengthTextField(); JLabel lblState = new JLabel(Messages.getString("QuickCustomerForm.0")); //$NON-NLS-1$ tfState = new JTextField(30); JLabel lblCellPhone = new JLabel(Messages.getString("CustomerForm.32")); //$NON-NLS-1$ inputPanel.add(lblCellPhone, "cell 0 1,alignx right"); //$NON-NLS-1$ tfCellPhone = new JTextField(30); inputPanel.add(tfCellPhone, "cell 1 1"); //$NON-NLS-1$ //setPreferredSize(PosUIManager.getSize(800, 350)); JLabel lblFirstName = new JLabel(Messages.getString("CustomerForm.3")); //$NON-NLS-1$ //inputPanel.add(lblFirstName, "cell 0 2,alignx right"); //$NON-NLS-1$ tfFirstName = new FixedLengthTextField(); //inputPanel.add(tfFirstName, "cell 1 2"); //$NON-NLS-1$ JLabel lblLastName = new JLabel(Messages.getString("CustomerForm.11")); //$NON-NLS-1$ //inputPanel.add(lblLastName, "cell 0 3,alignx right"); //$NON-NLS-1$ tfLastName = new FixedLengthTextField(); //inputPanel.add(tfLastName, "cell 1 3"); //$NON-NLS-1$ JLabel lblName = new JLabel("Name"); //$NON-NLS-1$ inputPanel.add(lblName, "cell 0 3,alignx right"); //$NON-NLS-1$ tfName = new FixedLengthTextField(); tfName.setLength(120); inputPanel.add(tfName, "cell 1 3"); //$NON-NLS-1$ inputPanel.add(lblZip, "cell 0 4,right"); //$NON-NLS-1$ inputPanel.add(tfZip, "cell 1 4"); //$NON-NLS-1$ inputPanel.add(lblCitytown, "cell 0 5,right"); //$NON-NLS-1$ inputPanel.add(tfCity, "cell 1 5"); //$NON-NLS-1$ inputPanel.add(lblState, "cell 0 6,right"); //$NON-NLS-1$ inputPanel.add(tfState, "cell 1 6"); //$NON-NLS-1$ inputPanel.add(lblAddress, "cell 2 1 1 6,right"); //$NON-NLS-1$ inputPanel.add(scrlDescription, "grow, cell 3 1 1 6"); //$NON-NLS-1$ qwertyKeyPad = new QwertyKeyPad(); add(inputPanel, BorderLayout.CENTER); if (isKeypad) { add(qwertyKeyPad, BorderLayout.SOUTH); //$NON-NLS-1$ } tfZip.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { getStateAndCityByZipCode(); } }); tfZip.addFocusListener(new FocusListener() { @Override public void focusLost(FocusEvent e) { getStateAndCityByZipCode(); } @Override public void focusGained(FocusEvent e) { } }); enableCustomerFields(false); callOrderController(); }
From source file:me.childintime.childintime.ui.window.tool.BmiToolDialog.java
private JPanel buildUiBodyStatePanel() { // Create a grid bag constraints configuration GridBagConstraints c = new GridBagConstraints(); // Body state panel final JPanel bodyStatePanel = new JPanel(new GridBagLayout()); bodyStatePanel.setBorder(new CompoundBorder(BorderFactory.createTitledBorder("BMI tool"), BorderFactory.createEmptyBorder(8, 8, 8, 8))); // Add the student panel to the body state panel c.fill = GridBagConstraints.BOTH; c.gridx = 0;/* w w w.ja v a 2s .c o m*/ c.gridy = 0; c.weightx = 1; c.weighty = 1; c.gridheight = 2; c.insets = new Insets(0, 0, 0, 0); c.anchor = GridBagConstraints.CENTER; bodyStatePanel.add(buildUiStudentPanel(), c); // Add the input panel to the body state panel c.fill = GridBagConstraints.BOTH; c.gridx = 1; c.gridy = 0; c.weightx = 1; c.weighty = 1; c.gridheight = 1; c.insets = new Insets(0, 16, 0, 0); c.anchor = GridBagConstraints.NORTH; bodyStatePanel.add(buildUiChartPanel(), c); // Add the input panel to the body state panel c.fill = GridBagConstraints.BOTH; c.gridx = 1; c.gridy = 1; c.weightx = 0; c.weighty = 0; c.gridheight = 1; c.insets = new Insets(32, 16, 0, 0); c.anchor = GridBagConstraints.CENTER; bodyStatePanel.add(buildUiStudentBodyStatesPanel(), c); // Return the body state panel return bodyStatePanel; }
From source file:com.hp.alm.ali.idea.ui.MultipleItemsDialog.java
public MultipleItemsDialog(Project project, String title, final MultipleItemsDialogModel<K, E> model) { super(project, title, true); this.model = model; mySelectionModel = new MySelectionModel(); myListSelectionListener = new MyListSelectionListener(); tooMany = new JLabel("Too many results, narrow your search"); tooMany.setBorder(BorderFactory.createEtchedBorder()); tooMany.setVisible(false);//from w ww. jav a 2 s . c om selected = new JLabel("Showing currently selected items"); selected.setVisible(false); toggleSelected = new JToggleButton(); toggleSelected.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { model.setShowingSelected(toggleSelected.isSelected()); if (!model.isShowingSelected() && !model.getSelectedFields().isEmpty()) { updateSelectionFromModel(); } else if (model.isShowingSelected()) { header.getFilterEditor(1).setContent(""); } } }); updateSelected(); table = new JBTable() { @Override public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) { int column = convertColumnIndexToModel(columnIndex); mySelectionModel.setFirstColumnEvent(column == 0); super.changeSelection(rowIndex, columnIndex, toggle, extend); } }; table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(false); table.setAutoCreateColumnsFromModel(false); table.setModel(model); final MyTableRowSorter sorter = new MyTableRowSorter(model); table.setRowSorter(sorter); table.setDefaultRenderer(Boolean.class, new MyRenderer()); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); table.setSelectionModel(mySelectionModel); sorter.setIgnoreAddRowSorterListener(true); // prevent auto-selection (functionality not accessible via proper API) header = new TableFilterHeader(table); sorter.setIgnoreAddRowSorterListener(false); sorter.setSortKeys(Arrays.asList(new RowSorter.SortKey(1, SortOrder.ASCENDING))); JPanel panel = new JPanel(new BorderLayout()); JPanel toolbar = new JPanel(new BorderLayout()); toolbar.setBorder(BorderFactory.createEtchedBorder()); panel.add(toolbar, BorderLayout.NORTH); toolbar.add(toggleSelected, BorderLayout.EAST); if (model.isMultiple()) { table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.getColumnModel().addColumn(createColumn(0, model, 45, 45)); header.getFilterEditor(0).setEditable(false); header.getFilterEditor(0).setUserInteractionEnabled(false); final LinkListener selectUnselect = new LinkListener() { public void linkSelected(LinkLabel aSource, Object aLinkData) { if (model.isShowingSelected()) { if (!Boolean.TRUE.equals(aLinkData)) { List<Integer> ixs = new ArrayList<Integer>(); for (int i = 0; i < sorter.getViewRowCount(); i++) { ixs.add(sorter.convertRowIndexToModel(i)); } // make sure indexes are not affected by removal by starting from the last Collections.sort(ixs); Collections.reverse(ixs); for (int ix : ixs) { model.setValueAt(aLinkData, ix, 0); } } } else { if (Boolean.TRUE.equals(aLinkData)) { mySelectionModel.doAddSelectionInterval(0, table.getRowCount() - 1); } else { mySelectionModel.removeSelectionInterval(0, table.getRowCount() - 1); } } } }; JPanel left = new JPanel(new FlowLayout(FlowLayout.LEFT)); left.add(new LinkLabel("Select All", IconLoader.getIcon("/actions/selectall.png"), selectUnselect, true)); left.add(new LinkLabel("Unselect All", IconLoader.getIcon("/actions/unselectall.png"), selectUnselect, false)); toolbar.add(left, BorderLayout.WEST); } else { table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } table.getColumnModel().addColumn(createColumn(1, model, 450, null)); table.getSelectionModel().addListSelectionListener(myListSelectionListener); model.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { selected.setVisible(model.isShowingSelected()); tooMany.setVisible(model.hasMore() && !model.isShowingSelected()); updateSelected(); } }); JPanel contentPanel = new JPanel(new BorderLayout()); contentPanel.add(selected, BorderLayout.NORTH); contentPanel.add(new JBScrollPane(table), BorderLayout.CENTER); contentPanel.add(tooMany, BorderLayout.SOUTH); panel.add(contentPanel, BorderLayout.CENTER); JPanel buttons = new JPanel(); okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { ok = true; close(true); } }); buttons.add(okButton); JButton cancel = new JButton("Cancel"); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { close(false); } }); buttons.add(cancel); panel.add(buttons, BorderLayout.SOUTH); getContentPane().add(panel, BorderLayout.CENTER); pack(); setResizable(false); centerOnOwner(); requestPropertyFilterFocus(header); load(true, null); }
From source file:emailplugin.MailCreator.java
/** * Gives the User the opportunity to specify which Desktop he uses (KDE or * Gnome)//from ww w .jav 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:com.midas.classify.gui.DecisionTreeViewer.java
public DecisionTreeViewer(DelegateTree<TreeNode, TreeEdge> tr, String[] cls) { setLayout(new BorderLayout()); // ---------------------------------------------- // // INICIALIZACION DE COMPONENTES DE VISUALIZACION // // ---------------------------------------------- // tree = tr;//from w ww .j ava 2 s. com classNames = cls; classColors = new TreeMap(); nodeColor = Color.BLUE; for (int i = 0; i < cls.length; ++i) { classColors.put(cls[i], Color.RED); } leafNodes = new TreeSet(); for (TreeNode n : tr.getVertices()) { if (tr.isLeaf(n)) { for (String s : cls) { if (n.toString().startsWith(s)) { leafNodes.add(s); break; } } } } TreeLayout<TreeNode, TreeEdge> layout = new TreeLayout(tr); vv = new VisualizationViewer(layout); vv.setBackground(Color.white); vv.getRenderContext().setEdgeFontTransformer(new EdgeFontTransformer()); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<TreeNode, TreeEdge>()); PickedState<TreeNode> picked_state = vv.getPickedVertexState(); vv.getRenderContext().setVertexFillPaintTransformer(new VertexFillColorTransformer<TreeNode>(picked_state)); vv.getRenderContext().setVertexDrawPaintTransformer(new VertexDrawColorTransformer<TreeNode>(picked_state)); vv.getRenderContext().setVertexFontTransformer(new VertexFontTransformer()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller()); GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(vv); gm = new DefaultModalGraphMouse(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); // ---------------------------------------- // // INICIALIZACION DE COMPONENTES DE CONTROL // // ---------------------------------------- // fontChooser = new JFontChooser(); JPanel pControl = new JPanel(new GridLayout(7, 1, 4, 2)); JPanel pZoom = new JPanel(new GridLayout(1, 2, 2, 2)); pZoom.setBorder(new TitledBorder("Zoom")); bZoomIn = new JButton("+"); bZoomIn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); bZoomOut = new JButton("-"); bZoomOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); pZoom.add(bZoomIn); pZoom.add(bZoomOut); JPanel pFont = new JPanel(new GridLayout(1, 2, 2, 2)); pFont.setBorder(new TitledBorder("Fonts")); bNodeFont = new JButton("Node Font"); bNodeFont.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fontChooser.showDialog(null); if (r == JFontChooser.OK_OPTION) { nodeFont = fontChooser.getSelectedFont(); vv.repaint(); } } }); bEdgeFont = new JButton("Edge Font"); bEdgeFont.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fontChooser.showDialog(null); if (r == JFontChooser.OK_OPTION) { edgeFont = fontChooser.getSelectedFont(); vv.repaint(); } } }); pFont.add(bNodeFont); pFont.add(bEdgeFont); bNodeColor = new JButton("Node Color"); bNodeColor.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { nodeColor = JColorChooser.showDialog(null, "Select color for intern nodes", Color.RED); vv.repaint(); } }); JPanel pMode = new JPanel(); pMode.setBorder(new TitledBorder("Mode")); cbMode = new JComboBox(); cbMode.addItem(ModalGraphMouse.Mode.TRANSFORMING); cbMode.addItem(ModalGraphMouse.Mode.PICKING); cbMode.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { gm.setMode((ModalGraphMouse.Mode) e.getItem()); } }); pMode.add(cbMode); JPanel pColors = new JPanel(new GridLayout(1, 2, 2, 2)); pColors.setBorder(new TitledBorder("Node Colors")); cbClasses = new JComboBox(classNames); cbClasses.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(null, "Select class color for " + cbClasses.getSelectedItem(), Color.RED); classColors.put(cbClasses.getSelectedItem().toString(), c); vv.repaint(); } }); pColors.add(cbClasses); pColors.add(bNodeColor); JPanel pLabelPosition = new JPanel(); pLabelPosition.setBorder(new TitledBorder("Label Position")); cbLabelPosition = new JComboBox(); cbLabelPosition.addItem(Renderer.VertexLabel.Position.N); cbLabelPosition.addItem(Renderer.VertexLabel.Position.NE); cbLabelPosition.addItem(Renderer.VertexLabel.Position.E); cbLabelPosition.addItem(Renderer.VertexLabel.Position.SE); cbLabelPosition.addItem(Renderer.VertexLabel.Position.S); cbLabelPosition.addItem(Renderer.VertexLabel.Position.SW); cbLabelPosition.addItem(Renderer.VertexLabel.Position.W); cbLabelPosition.addItem(Renderer.VertexLabel.Position.NW); cbLabelPosition.addItem(Renderer.VertexLabel.Position.N); cbLabelPosition.addItem(Renderer.VertexLabel.Position.CNTR); cbLabelPosition.addItem(Renderer.VertexLabel.Position.AUTO); cbLabelPosition.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { Renderer.VertexLabel.Position position = (Renderer.VertexLabel.Position) e.getItem(); vv.getRenderer().getVertexLabelRenderer().setPosition(position); vv.repaint(); } }); cbLabelPosition.setSelectedItem(Renderer.VertexLabel.Position.SE); pLabelPosition.add(cbLabelPosition); chkShowEdgeNames = new JCheckBox("Show Edge Name"); chkShowEdgeNames.addActionListener(new ActionListener() { ToStringLabeller strLabeller = new ToStringLabeller(); ConstantTransformer none = new ConstantTransformer(null); @Override public void actionPerformed(ActionEvent e) { AbstractButton src = (AbstractButton) e.getSource(); if (src.isSelected()) { vv.getRenderContext().setEdgeLabelTransformer(strLabeller); } else { vv.getRenderContext().setEdgeLabelTransformer(none); } vv.repaint(); } }); chkShowEdgeNames.setSelected(true); chkShowNodeNames = new JCheckBox("Show Node Name"); chkShowNodeNames.addActionListener(new ActionListener() { ToStringLabeller strLabeller = new ToStringLabeller(); ConstantTransformer none = new ConstantTransformer(null); @Override public void actionPerformed(ActionEvent e) { AbstractButton src = (AbstractButton) e.getSource(); if (src.isSelected()) { vv.getRenderContext().setVertexLabelTransformer(strLabeller); } else { vv.getRenderContext().setVertexLabelTransformer(none); } vv.repaint(); } }); chkShowNodeNames.setSelected(true); pControl.add(pZoom); pControl.add(pFont); pControl.add(pMode); pControl.add(pLabelPosition); pControl.add(pColors); pControl.add(chkShowNodeNames); pControl.add(chkShowEdgeNames); // Agregar componentes al panel add(scrollPane); JPanel p = new JPanel(new FlowLayout()); p.add(pControl); add(p, BorderLayout.EAST); }
From source file:kg.apc.jmeter.vizualizers.SynthesisReportGui.java
/** * Main visualizer setup./*from w w w .j a v a2s . c om*/ */ private void init() { this.setLayout(new BorderLayout()); // MAIN PANEL JPanel mainPanel = new JPanel(); Border margin = new EmptyBorder(10, 10, 5, 10); mainPanel.setBorder(margin); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.add(JMeterPluginsUtils.addHelpLinkToPanel(makeTitlePanel(), WIKIPAGE)); // SortFilterModel mySortedModel = // new SortFilterModel(myStatTableModel); JTable myJTable = new JTable(model); myJTable.getTableHeader().setDefaultRenderer(new JMeterHeaderAsPropertyRenderer(COLUMNS_MSG_PARAMETERS)); myJTable.setPreferredScrollableViewportSize(new Dimension(500, 70)); RendererUtils.applyRenderers(myJTable, RENDERERS); JScrollPane myScrollPane = new JScrollPane(myJTable); this.add(mainPanel, BorderLayout.NORTH); this.add(myScrollPane, BorderLayout.CENTER); saveTable.addActionListener(this); JPanel opts = new JPanel(); opts.add(useGroupName, BorderLayout.WEST); opts.add(saveTable, BorderLayout.CENTER); opts.add(saveHeaders, BorderLayout.EAST); this.add(opts, BorderLayout.SOUTH); }
From source file:Main.java
public Main() { super(new BorderLayout()); listModel = new DefaultListModel(); listModel.addElement("Debbie Scott"); listModel.addElement("Scott Hommel"); listModel.addElement("Sharon Zakhour"); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);//from ww w . j a va 2 s . co m list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:com.google.code.facebook.graph.sna.applet.LensDemo.java
/** * create an instance of a simple graph with controls to * demo the zoomand hyperbolic features. * /*from www . ja va2 s. c om*/ */ public LensDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); graphLayout = new FRLayout<String, Number>(graph); ((FRLayout) graphLayout).setMaxIterations(1000); Dimension preferredSize = new Dimension(600, 600); Map<String, Point2D> map = new HashMap<String, Point2D>(); Transformer<String, Point2D> vlf = TransformerUtils.mapTransformer(map); grid = this.generateVertexGrid(map, preferredSize, 25); gridLayout = new StaticLayout<String, Number>(grid, vlf, preferredSize); final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>( graphLayout, preferredSize); vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize); PickedState<String> ps = vv.getPickedVertexState(); PickedState<Number> pes = vv.getPickedEdgeState(); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(ps, Color.red, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.cyan)); vv.setBackground(Color.white); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); final Transformer<String, Shape> ovals = vv.getRenderContext().getVertexShapeTransformer(); final Transformer<String, Shape> squares = new ConstantTransformer(new Rectangle2D.Float(-10, -10, 20, 20)); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); hyperbolicViewSupport = new ViewLensSupport<String, Number>(vv, new HyperbolicShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse()); hyperbolicLayoutSupport = new LayoutLensSupport<String, Number>(vv, new HyperbolicTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)), new ModalLensGraphMouse()); magnifyViewSupport = new ViewLensSupport<String, Number>(vv, new MagnifyShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f))); magnifyLayoutSupport = new LayoutLensSupport<String, Number>(vv, new MagnifyTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)), new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f))); hyperbolicLayoutSupport.getLensTransformer() .setLensShape(hyperbolicViewSupport.getLensTransformer().getLensShape()); magnifyViewSupport.getLensTransformer() .setLensShape(hyperbolicLayoutSupport.getLensTransformer().getLensShape()); magnifyLayoutSupport.getLensTransformer() .setLensShape(magnifyViewSupport.getLensTransformer().getLensShape()); 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()); } }); ButtonGroup radio = new ButtonGroup(); JRadioButton normal = new JRadioButton("None"); normal.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (hyperbolicViewSupport != null) { hyperbolicViewSupport.deactivate(); } if (hyperbolicLayoutSupport != null) { hyperbolicLayoutSupport.deactivate(); } if (magnifyViewSupport != null) { magnifyViewSupport.deactivate(); } if (magnifyLayoutSupport != null) { magnifyLayoutSupport.deactivate(); } } } }); final JRadioButton hyperView = new JRadioButton("Hyperbolic View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton hyperModel = new JRadioButton("Hyperbolic Layout"); hyperModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton magnifyView = new JRadioButton("Magnified View"); magnifyView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { magnifyViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton magnifyModel = new JRadioButton("Magnified Layout"); magnifyModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { magnifyLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); JLabel modeLabel = new JLabel(" Mode Menu >>"); modeLabel.setUI(new VerticalLabelUI(false)); radio.add(normal); radio.add(hyperModel); radio.add(hyperView); radio.add(magnifyModel); radio.add(magnifyView); normal.setSelected(true); graphMouse.addItemListener(hyperbolicLayoutSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(magnifyLayoutSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(magnifyViewSupport.getGraphMouse().getModeListener()); ButtonGroup graphRadio = new ButtonGroup(); JRadioButton graphButton = new JRadioButton("Graph"); graphButton.setSelected(true); graphButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(graphLayout); vv.getRenderContext().setVertexShapeTransformer(ovals); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.repaint(); } } }); JRadioButton gridButton = new JRadioButton("Grid"); gridButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(gridLayout); vv.getRenderContext().setVertexShapeTransformer(squares); vv.getRenderContext().setVertexLabelTransformer(new ConstantTransformer(null)); vv.repaint(); } } }); graphRadio.add(graphButton); graphRadio.add(gridButton); JPanel modePanel = new JPanel(new GridLayout(3, 1)); modePanel.setBorder(BorderFactory.createTitledBorder("Display")); modePanel.add(graphButton); modePanel.add(gridButton); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); gzsp.setCorner(menubar); Box controls = Box.createHorizontalBox(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel hyperControls = new JPanel(new GridLayout(3, 2)); hyperControls.setBorder(BorderFactory.createTitledBorder("Examiner Lens")); zoomControls.add(plus); zoomControls.add(minus); hyperControls.add(normal); hyperControls.add(new JLabel()); hyperControls.add(hyperModel); hyperControls.add(magnifyModel); hyperControls.add(hyperView); hyperControls.add(magnifyView); controls.add(zoomControls); controls.add(hyperControls); controls.add(modePanel); controls.add(modeLabel); content.add(controls, BorderLayout.SOUTH); }
From source file:ListDemo.java
public ListDemo() { super(new BorderLayout()); listModel = new DefaultListModel(); listModel.addElement("Debbie Scott"); listModel.addElement("Scott Hommel"); listModel.addElement("Sharon Zakhour"); // Create the list and put it in a scroll pane. list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setSelectedIndex(0);/*from w w w . ja v a 2 s . co m*/ list.addListSelectionListener(this); list.setVisibleRowCount(5); JScrollPane listScrollPane = new JScrollPane(list); JButton hireButton = new JButton(hireString); HireListener hireListener = new HireListener(hireButton); hireButton.setActionCommand(hireString); hireButton.addActionListener(hireListener); hireButton.setEnabled(false); fireButton = new JButton(fireString); fireButton.setActionCommand(fireString); fireButton.addActionListener(new FireListener()); employeeName = new JTextField(10); employeeName.addActionListener(hireListener); employeeName.getDocument().addDocumentListener(hireListener); String name = listModel.getElementAt(list.getSelectedIndex()).toString(); // Create a panel that uses BoxLayout. JPanel buttonPane = new JPanel(); buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS)); buttonPane.add(fireButton); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(new JSeparator(SwingConstants.VERTICAL)); buttonPane.add(Box.createHorizontalStrut(5)); buttonPane.add(employeeName); buttonPane.add(hireButton); buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(listScrollPane, BorderLayout.CENTER); add(buttonPane, BorderLayout.PAGE_END); }
From source file:edu.uci.ics.jung.samples.LensDemo.java
/** * create an instance of a simple graph with controls to * demo the zoomand hyperbolic features. * //from w w w .j a v a 2 s . co m */ @SuppressWarnings({ "rawtypes", "unchecked" }) public LensDemo() { // create a simple graph for the demo graph = TestGraphs.getOneComponentGraph(); graphLayout = new FRLayout<String, Number>(graph); ((FRLayout) graphLayout).setMaxIterations(1000); Dimension preferredSize = new Dimension(600, 600); Map<String, Point2D> map = new HashMap<String, Point2D>(); Transformer<String, Point2D> vlf = TransformerUtils.mapTransformer(map); grid = this.generateVertexGrid(map, preferredSize, 25); gridLayout = new StaticLayout<String, Number>(grid, vlf, preferredSize); final VisualizationModel<String, Number> visualizationModel = new DefaultVisualizationModel<String, Number>( graphLayout, preferredSize); vv = new VisualizationViewer<String, Number>(visualizationModel, preferredSize); PickedState<String> ps = vv.getPickedVertexState(); PickedState<Number> pes = vv.getPickedEdgeState(); vv.getRenderContext().setVertexFillPaintTransformer( new PickableVertexPaintTransformer<String>(ps, Color.red, Color.yellow)); vv.getRenderContext().setEdgeDrawPaintTransformer( new PickableEdgePaintTransformer<Number>(pes, Color.black, Color.cyan)); vv.setBackground(Color.white); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); final Transformer<String, Shape> ovals = vv.getRenderContext().getVertexShapeTransformer(); final Transformer<String, Shape> squares = new ConstantTransformer(new Rectangle2D.Float(-10, -10, 20, 20)); // add a listener for ToolTips vv.setVertexToolTipTransformer(new ToStringLabeller()); Container content = getContentPane(); GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv); content.add(gzsp); /** * the regular graph mouse for the normal view */ final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse(); vv.setGraphMouse(graphMouse); vv.addKeyListener(graphMouse.getModeKeyListener()); hyperbolicViewSupport = new ViewLensSupport<String, Number>(vv, new HyperbolicShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse()); hyperbolicLayoutSupport = new LayoutLensSupport<String, Number>(vv, new HyperbolicTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)), new ModalLensGraphMouse()); magnifyViewSupport = new ViewLensSupport<String, Number>(vv, new MagnifyShapeTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.VIEW)), new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f))); magnifyLayoutSupport = new LayoutLensSupport<String, Number>(vv, new MagnifyTransformer(vv, vv.getRenderContext().getMultiLayerTransformer().getTransformer(Layer.LAYOUT)), new ModalLensGraphMouse(new LensMagnificationGraphMousePlugin(1.f, 6.f, .2f))); hyperbolicLayoutSupport.getLensTransformer() .setLensShape(hyperbolicViewSupport.getLensTransformer().getLensShape()); magnifyViewSupport.getLensTransformer() .setLensShape(hyperbolicLayoutSupport.getLensTransformer().getLensShape()); magnifyLayoutSupport.getLensTransformer() .setLensShape(magnifyViewSupport.getLensTransformer().getLensShape()); 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()); } }); ButtonGroup radio = new ButtonGroup(); JRadioButton normal = new JRadioButton("None"); normal.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { if (hyperbolicViewSupport != null) { hyperbolicViewSupport.deactivate(); } if (hyperbolicLayoutSupport != null) { hyperbolicLayoutSupport.deactivate(); } if (magnifyViewSupport != null) { magnifyViewSupport.deactivate(); } if (magnifyLayoutSupport != null) { magnifyLayoutSupport.deactivate(); } } } }); final JRadioButton hyperView = new JRadioButton("Hyperbolic View"); hyperView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton hyperModel = new JRadioButton("Hyperbolic Layout"); hyperModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { hyperbolicLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton magnifyView = new JRadioButton("Magnified View"); magnifyView.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { magnifyViewSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); final JRadioButton magnifyModel = new JRadioButton("Magnified Layout"); magnifyModel.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { magnifyLayoutSupport.activate(e.getStateChange() == ItemEvent.SELECTED); } }); JLabel modeLabel = new JLabel(" Mode Menu >>"); modeLabel.setUI(new VerticalLabelUI(false)); radio.add(normal); radio.add(hyperModel); radio.add(hyperView); radio.add(magnifyModel); radio.add(magnifyView); normal.setSelected(true); graphMouse.addItemListener(hyperbolicLayoutSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(hyperbolicViewSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(magnifyLayoutSupport.getGraphMouse().getModeListener()); graphMouse.addItemListener(magnifyViewSupport.getGraphMouse().getModeListener()); ButtonGroup graphRadio = new ButtonGroup(); JRadioButton graphButton = new JRadioButton("Graph"); graphButton.setSelected(true); graphButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(graphLayout); vv.getRenderContext().setVertexShapeTransformer(ovals); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.repaint(); } } }); JRadioButton gridButton = new JRadioButton("Grid"); gridButton.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { visualizationModel.setGraphLayout(gridLayout); vv.getRenderContext().setVertexShapeTransformer(squares); vv.getRenderContext().setVertexLabelTransformer(new ConstantTransformer(null)); vv.repaint(); } } }); graphRadio.add(graphButton); graphRadio.add(gridButton); JPanel modePanel = new JPanel(new GridLayout(3, 1)); modePanel.setBorder(BorderFactory.createTitledBorder("Display")); modePanel.add(graphButton); modePanel.add(gridButton); JMenuBar menubar = new JMenuBar(); menubar.add(graphMouse.getModeMenu()); gzsp.setCorner(menubar); Box controls = Box.createHorizontalBox(); JPanel zoomControls = new JPanel(new GridLayout(2, 1)); zoomControls.setBorder(BorderFactory.createTitledBorder("Zoom")); JPanel hyperControls = new JPanel(new GridLayout(3, 2)); hyperControls.setBorder(BorderFactory.createTitledBorder("Examiner Lens")); zoomControls.add(plus); zoomControls.add(minus); hyperControls.add(normal); hyperControls.add(new JLabel()); hyperControls.add(hyperModel); hyperControls.add(magnifyModel); hyperControls.add(hyperView); hyperControls.add(magnifyView); controls.add(zoomControls); controls.add(hyperControls); controls.add(modePanel); controls.add(modeLabel); content.add(controls, BorderLayout.SOUTH); }