List of usage examples for com.jgoodies.binding.beans BeanAdapter getValueModel
public SimplePropertyAdapter getValueModel(String propertyName)
From source file:ambit2.db.results.test.AmbitRowsEventTest.java
License:Open Source License
public static void main(String[] args) { // http://www.java2s.com/Code/Java/Swing-Components/JGoodiesBindingSelectionInListModelExample.htm try {// ww w .j a va 2s. c o m final AmbitRows<Dictionary> dictionary = new AmbitRows<Dictionary>() { /** * */ private static final long serialVersionUID = 6274513733204291475L; @Override protected synchronized IQueryRetrieval createNewQuery(Dictionary target) throws AmbitException { TemplateQuery q = new TemplateQuery(); q.setValue(target.getTemplate()); return q; } }; final AmbitRows<Property> properties = new AmbitRows<Property>() { @Override protected synchronized IQueryRetrieval createNewQuery(Property target) throws AmbitException { QueryField q = new QueryField(); q.setFieldname(target); return q; } }; dictionary.addPropertyChangeListener(dictionary.getPropertyname(), properties); dictionary.addPropertyChangeListener("status", properties); AmbitRowsEventTest test = new AmbitRowsEventTest(); test.setUpDatabase(test.getTestDatabase()); IDatabaseConnection c = test.getConnection("localhost", "ambit2", "3306", "guest", "guest"); dictionary.setConnection(c.getConnection()); properties.setConnection(c.getConnection()); DictionaryObjectQuery q = new DictionaryObjectQuery(); q.setValue("Dataset"); PropertyChangeSupport ps = new PropertyChangeSupport(test); ps.addPropertyChangeListener("topquery", dictionary); ps.firePropertyChange(new QueryChangeEvent(test, "topquery", null, q)); final QueryField qf = new QueryField(); properties.addPropertyChangeListener(properties.getPropertyname(), new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { try { IQueryRetrieval r = properties.process((Property) evt.getNewValue()); qf.setFieldname(((QueryField) r).getFieldname()); } catch (AmbitException x) { x.printStackTrace(); } } }); ListModel listModel = new RowsModel<Dictionary>(dictionary); ValueModel selectedItemHolder1 = new ValueHolder(); SelectionInList<Dictionary> selectionInList = new SelectionInList<Dictionary>(listModel, selectedItemHolder1); final JList jlist = new JList(); Bindings.bind(jlist, selectionInList); BeanAdapter beanAdapter = new BeanAdapter(selectionInList); ValueModel nameModel = beanAdapter.getValueModel("template"); ValueModel parentModel = beanAdapter.getValueModel("parentTemplate"); ListModel listModel2 = new RowsModel<Property>(properties); ValueModel selectedItemHolder2 = new ValueHolder(); SelectionInList<Property> selectionInList2 = new SelectionInList<Property>(listModel2, selectedItemHolder2); BeanAdapter beanAdapter2 = new BeanAdapter(qf); ValueModel fieldnameModel = beanAdapter2.getValueModel("fieldname"); // ValueModel conditionModel = // beanAdapter2.getValueModel("condition"); ValueModel valueModel = beanAdapter2.getValueModel("value"); selectionInList.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { try { dictionary.process((Dictionary) evt.getNewValue()); } catch (Exception x) { x.printStackTrace(); } } }); selectionInList2.addPropertyChangeListener("value", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { try { } catch (Exception x) { x.printStackTrace(); } } }); JPanel p = new JPanel(); p.add(BasicComponentFactory.createTextField(nameModel)); p.add(BasicComponentFactory.createTextField(parentModel)); p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS)); p.add(new JLabel("Dictionary")); p.add(new JScrollPane(jlist)); // p.add(new JComboBox(new // ComboBoxAdapter<Dictionary>(selectionInList))); p.add(new JLabel("Properties")); final JComboBox combo = new JComboBox(new ComboBoxAdapter<Property>(selectionInList2)); p.add(combo); p.add(BasicComponentFactory.createTextField(fieldnameModel)); // p.add(BasicComponentFactory.createTextField(conditionModel)); p.add(BasicComponentFactory.createIntegerField(valueModel)); properties.addPropertyChangeListener("status", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { combo.setEnabled((Boolean) evt.getNewValue()); } }); JOptionPane.showMessageDialog(null, p); c.close(); } catch (Exception x) { x.printStackTrace(); } }
From source file:ambit2.ui.editors.SelectFieldsPanel.java
License:Open Source License
protected void buildPanel(String help) { FormLayout layout = new FormLayout( "3dlu,fill:40dlu:grow,fill:120dlu:grow,3dlu,32dlu, 3dlu, fill:40dlu:grow,fill:120dlu:grow,3dlu", //columns "3dlu,12dlu,3dlu,top:[pref,36dlu], 24dlu,3dlu,24dlu,3dlu,24dlu,3dlu,24dlu,bottom:[pref,72dlu]:grow,1dlu,pref,pref,pref,pref,pref"); //rows setLayout(layout);// w ww .ja v a2 s.c om CellConstraints cc = new CellConstraints(); add(createSeparator("Available"), cc.xywh(2, 2, 2, 1)); add(createSeparator("Selected"), cc.xywh(7, 2, 2, 1)); tables = new JList[fieldsModel.length]; for (int i = 0; i < fieldsModel.length; i++) { tables[i] = new JList(fieldsModel[i]); SelectionInList<Property> selectionInList = new SelectionInList<Property>(fieldsModel[i]); Bindings.bind(tables[i], selectionInList); JScrollPane p = new JScrollPane(tables[i]); p.setBorder(BorderFactory.createEtchedBorder()); p.setPreferredSize(new Dimension(160, 280)); int offset = 2 + i * 5; add(p, cc.xywh(offset, 4, 2, 9)); BeanAdapter beanAdapter = new BeanAdapter(selectionInList); String[][] config = { { "name", "Name" }, { "label", "Alias" }, { "units", "Units" }, { "title", "url" }, { "url", "WWW" } }; for (int j = 0; j < config.length; j++) { String[] c = config[j]; ValueModel model = beanAdapter.getValueModel(c[0]); add(BasicComponentFactory.createLabel(new ValueHolder(c[1])), cc.xywh(offset, j + 14, 1, 1)); JTextField t = BasicComponentFactory.createTextField(model); t.addMouseListener(new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { super.mouseEntered(e); ((JTextField) e.getSource()).setToolTipText(((JTextField) e.getSource()).getText()); } }); add(t, cc.xywh(offset + 1, j + 14, 1, 1)); } /* ValueModel nameModel = beanAdapter.getValueModel("name"); ValueModel commentsModel = beanAdapter.getValueModel("label"); ValueModel titleModel = beanAdapter.getValueModel("title"); ValueModel urlModel = beanAdapter.getValueModel("url"); //p.add(BasicComponentFactory.createTextField(parentModel)); add(BasicComponentFactory.createLabel(new ValueHolder("Name")),cc.xywh(offset,14,1,1)); add(BasicComponentFactory.createTextField(nameModel),cc.xywh(offset+1,14,1,1)); add(BasicComponentFactory.createLabel(new ValueHolder("Alias")),cc.xywh(offset,15,1,1)); add(BasicComponentFactory.createTextField(commentsModel),cc.xywh(offset+1,15,1,1)); add(BasicComponentFactory.createLabel(new ValueHolder("Reference")),cc.xywh(offset,16,1,1)); add(BasicComponentFactory.createTextField(titleModel),cc.xywh(offset+1,16,1,1)); add(BasicComponentFactory.createLabel(new ValueHolder("WWW")),cc.xywh(offset,17,1,1)); add(BasicComponentFactory.createTextField(urlModel),cc.xywh(offset+1,17,1,1)); */ } buttons = new ArrayList<JButton>(); int i = 0; for (MOVE op : MOVE.values()) { JButton button = new JButton(op.display()); button.setPreferredSize(new Dimension(24, 24)); button.setMaximumSize(new Dimension(24, 24)); add(button, cc.xywh(5, 5 + (i * 2), 1, 1)); button.addActionListener(this); button.setActionCommand(op.toString()); i++; } /* JToolBar toolBar[] = new JToolBar[2]; toolBar[0] = new JToolBar(); toolBar[0].add(new JButton("Find")); toolBar[0].add(new JToolBar.Separator()); toolBar[0].add(new JButton("Select all")); toolBar[0].add(new JButton("Unselect all")); toolBar[0].setFloatable(false); add(toolBar[0],cc.xywh(2,14,1,1)); toolBar[1] = new JToolBar(); toolBar[1].add(new JButton("Move Up")); toolBar[1].add(new JButton("Move Down")); toolBar[1].add(new JToolBar.Separator()); toolBar[1].add(new JButton("Select all")); toolBar[1].add(new JButton("Unselect all")); toolBar[1].setFloatable(false); add(toolBar[1],cc.xywh(6,14,1,1)); */ /* helpArea = new JTextPane(); helpArea.setText(help); helpArea.setEditable(false); helpArea.setBackground(new Color(255,255,225)); helpArea.setPreferredSize(new Dimension(288,48)); add(new JScrollPane(helpArea),cc.xywh(2,16,5,1)); */ }
From source file:com.cedarsoft.configuration.xml.ConfigBindingGuiceTest.java
License:Open Source License
@Before public void setUp() throws Exception { injector = Guice.createInjector(new AbstractModule() { @Override/* w ww.j a v a2 s . com*/ protected void configure() { bind(Configuration.class).toInstance(new BaseConfiguration()); bind(MyBean.class).toProvider(new Provider<MyBean>() { @Inject Configuration configuration; @Override @Nonnull public MyBean get() { MyBean myBean = new MyBean(); BeanAdapter<MyBean> beanAdapter = new BeanAdapter<MyBean>(myBean, true); ConfigurationAccess<String> configurationAccess = new ConfigurationAccess<String>( configuration, String.class, MyBean.PROPERTY_VALUE, "theDefaultValue"); ConfigurationBinding.bind(configurationAccess, beanAdapter.getValueModel(MyBean.PROPERTY_VALUE)); return myBean; } }).in(Scopes.SINGLETON); } }); }
From source file:com.cedarsoft.configuration.xml.ConfigurationBindingTest.java
License:Open Source License
@Test public void testMapping() { MyBean bean = new MyBean(); BeanAdapter<MyBean> beanAdapter = new BeanAdapter<MyBean>(bean, true); ValueModel valueModel = beanAdapter.getValueModel("value"); ConfigurationAccess<String> configurationAccess = new ConfigurationAccess<String>(configuration, String.class, "valueKey", "theDefaultValue"); //manually/* w w w. j av a 2 s .c o m*/ ConfigurationConnector<String> connector = new ConfigurationConnector<String>(valueModel, configurationAccess); assertEquals("", bean.getValue()); connector.readFromConfiguration(); assertEquals("theDefaultValue", bean.getValue()); assertEquals("theDefaultValue", configuration.getString("valueKey")); bean.setValue("newValue"); assertEquals("newValue", bean.getValue()); assertEquals("newValue", configuration.getString("valueKey")); }
From source file:com.cedarsoft.configuration.xml.ConfigurationBindingTest.java
License:Open Source License
@Test public void testMapping2() { MyBean bean = new MyBean(); BeanAdapter<MyBean> beanAdapter = new BeanAdapter<MyBean>(bean, true); ConfigurationAccess<String> configurationAccess = new ConfigurationAccess<String>(configuration, String.class, "valueKey", "theDefaultValue"); //manually/*from w w w . j a v a 2s . c o m*/ ConfigurationBinding.bind(configurationAccess, beanAdapter.getValueModel("value")); assertEquals("theDefaultValue", bean.getValue()); assertEquals("theDefaultValue", configuration.getString("valueKey")); bean.setValue("newValue"); assertEquals("newValue", bean.getValue()); assertEquals("newValue", configuration.getString("valueKey")); }
From source file:com.cedarsoft.configuration.xml.ConfigurationBindingTest.java
License:Open Source License
@Test public void testMappingList() { MyBean bean = new MyBean(); assertEquals(0, bean.getValues().size()); BeanAdapter<MyBean> beanAdapter = new BeanAdapter<MyBean>(bean, true); ConfigurationAccess<List> configurationAccess = new ConfigurationAccess<List>(configuration, List.class, "values", Arrays.asList("a", "b")); ConfigurationBinding.bind(configurationAccess, beanAdapter.getValueModel("values")); assertEquals(2, bean.getValues().size()); assertEquals("a", bean.getValues().get(0)); assertEquals("b", bean.getValues().get(1)); assertEquals(2, configuration.getList("values").size()); assertEquals("a", configuration.getList("values").get(0)); assertEquals("b", configuration.getList("values").get(1)); bean.addValue("c"); assertEquals(3, bean.getValues().size()); assertEquals("a", bean.getValues().get(0)); assertEquals("b", bean.getValues().get(1)); assertEquals("c", bean.getValues().get(2)); assertEquals(3, configuration.getList("values").size()); assertEquals("a", configuration.getList("values").get(0)); assertEquals("b", configuration.getList("values").get(1)); assertEquals("c", configuration.getList("values").get(2)); bean.removeValue("b"); assertEquals(2, bean.getValues().size()); assertEquals("a", bean.getValues().get(0)); assertEquals("c", bean.getValues().get(1)); assertEquals(2, configuration.getList("values").size()); assertEquals("a", configuration.getList("values").get(0)); assertEquals("c", configuration.getList("values").get(1)); }
From source file:com.salas.bb.core.actions.ActionsTable.java
License:Open Source License
/** * Registers articles related actions./*from ww w . ja v a 2 s . c om*/ */ private static void registerArticleActions() { FeedRenderingSettings feedRenderingSettings = GlobalModel.SINGLETON.getGlobalRenderingSettings(); // Factory for valueModels corresponding to bean properties of GlobalRenderingSettings BeanAdapter globChannelRenderingAdapter = new BeanAdapter(feedRenderingSettings, true); ValueModel articleFilterModelHolder = globChannelRenderingAdapter.getValueModel("articleFilter"); ValueModel articleViewModeHolder = GlobalModel.SINGLETON.getViewModeValueModel(); ActionManager.register(CMD_ARTICLE_WHATIS, new ShowTipAction(TipOfTheDay.TIP_WHAT_IS_ARTICLE)); ActionManager.register(CMD_ARTICLE_BROWSE, BrowseArticleAction.getInstance()); ActionManager.register(CMD_ARTICLE_BROWSE_TB, new ActionAlias(BrowseArticleAction.getInstance())); ActionManager.register(CMD_ARTICLE_COPY_TEXT, SelectedTextCopyAction.getInstance()); ActionManager.register(CMD_ARTICLE_COPY_TEXT_STYLED, StyledTextCopyAction.getInstance()); ActionManager.register(CMD_ARTICLE_COPY_LINK, ArticleLinkCopyAction.getInstance()); ActionManager.register(CMD_ARTICLE_SEND_LINK, ArticleLinkSendAction.getInstance()); ActionManager.register(CMD_ARTICLE_SAVE_IMAGE, SaveImageAction.getInstance()); ActionManager.register(CMD_ARTICLE_GOTO_NEXT_UNREAD, GotoNextUnreadAction.getInstance()); ActionManager.register(CMD_ARTICLE_GOTO_NEXT_UNREAD_TB, new ActionAlias(GotoNextUnreadAction.getInstance())); ActionManager.register(CMD_ARTICLE_GOTO_NEXT_UNREAD_FEED, GotoNextUnreadInNextFeedAction.getInstance()); ActionManager.register(CMD_ARTICLE_GOTO_PREV_UNREAD, GotoPreviousUnreadAction.getInstance()); ActionManager.register(CMD_ARTICLE_PROPERTIES, ShowArticlePropertiesAction.getInstance()); ActionManager.register(CMD_ARTICLE_MARK_UNREAD, MarkArticleUnreadAction.getInstance()); ActionManager.register(CMD_ARTICLE_MARK_READ, MarkArticleReadAction.getInstance()); ActionManager.register(CMD_ARTICLE_FONT_BIGGER, new FontSizeBiasChangeAction(1)); ActionManager.register(CMD_ARTICLE_FONT_SMALLER, new FontSizeBiasChangeAction(-1)); ActionManager.register(CMD_ARTICLE_SHOW_ALL_TB, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_ALL))); ActionManager.register(CMD_ARTICLE_SHOW_UNREAD_TB, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_UNREAD))); ActionManager.register(CMD_ARTICLE_SHOW_PINNED_TB, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_PINNED))); ActionManager.register(CMD_ARTICLE_SHOW_POSITIVE_TB, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_POSITIVE))); ActionManager.register(CMD_ARTICLE_SHOW_NEGATIVE_TB, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_NEGATIVE))); ActionManager.register(CMD_ARTICLE_SHOW_NON_NEGATIVE_TB, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_NON_NEGATIVE))); ActionManager.register(CMD_ARTICLE_SHOW_ALL, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_ALL))); ActionManager.register(CMD_ARTICLE_SHOW_UNREAD, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_UNREAD))); ActionManager.register(CMD_ARTICLE_SHOW_PINNED, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_PINNED))); ActionManager.register(CMD_ARTICLE_SHOW_POSITIVE, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_POSITIVE))); ActionManager.register(CMD_ARTICLE_SHOW_NEGATIVE, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_NEGATIVE))); ActionManager.register(CMD_ARTICLE_SHOW_NON_NEGATIVE, ToggleAction.createRadio(articleFilterModelHolder, new Integer(IFeedDisplayConstants.FILTER_NON_NEGATIVE))); ActionManager.register(CMD_ARTICLE_VIDEMODE_MINI, ToggleAction.createRadio(articleViewModeHolder, FeedRenderingSettings.VIEW_MODE_MINIMAL)); ActionManager.register(CMD_ARTICLE_VIEWMODE_BRIEF, ToggleAction.createRadio(articleViewModeHolder, FeedRenderingSettings.VIEW_MODE_BRIEF)); ActionManager.register(CMD_ARTICLE_VIEWMODE_FULL, ToggleAction.createRadio(articleViewModeHolder, FeedRenderingSettings.VIEW_MODE_FULL)); ActionManager.register(CMD_ARTICLE_VIEWMODE_MINI_TB, ToggleAction.createRadio(articleViewModeHolder, FeedRenderingSettings.VIEW_MODE_MINIMAL)); ActionManager.register(CMD_ARTICLE_VIEWMODE_BRIEF_TB, ToggleAction.createRadio(articleViewModeHolder, FeedRenderingSettings.VIEW_MODE_BRIEF)); ActionManager.register(CMD_ARTICLE_VIEWMODE_FULL_TB, ToggleAction.createRadio(articleViewModeHolder, FeedRenderingSettings.VIEW_MODE_FULL)); ActionManager.register(CMD_ARTICLE_TAGS, ShowArticleTagsAction.getInstance()); ActionManager.register(CMD_ARTICLE_PIN_UNPIN, PinUnpinArticleAction.getInstance()); ActionManager.register(CMD_ARTICLE_HYPERLINK_OPEN, HyperLinkOpenAction.getInstance()); ActionManager.register(CMD_ARTICLE_HYPERLINK_COPY, HyperLinkCopyAction.getInstance()); ActionManager.register(CMD_ARTICLE_HYPERLINK_SAVE_AS, HyperLinkSaveAsAction.getInstance()); ActionManager.register(CMD_ARTICLE_HYPERLINK_SEND, HyperLinkEmailAction.getInstance()); ActionManager.register(CMD_ARTICLE_POST_TO_BLOG, PostToBlogAction.getInstanceForArticle()); ActionManager.register(CMD_ARTICLE_TWEET_THIS, TweetThisAction.getInstance()); ActionManager.register(CMD_ARTICLE_BLOCK_IMAGE, BlockImageAction.getInstance()); ActionManager.register(CMD_ARTICLE_DISCOVER, DiscoverInArticlesAction.getInstance()); }
From source file:com.stefanbrenner.droplet.ui.ActionPanel.java
License:Open Source License
/** * Create the panel.// w ww. j a v a 2 s. co m */ public ActionPanel(final IActionDevice device, final T action) { setDevice(device); setAction(action); setLayout(new GridBagLayout()); setBackground(DropletColors.getBackgroundColor(getDevice())); GridBagConstraints gbc = UiUtils.createGridBagConstraints(); gbc.fill = GridBagConstraints.BOTH; gbc.insets = new Insets(2, 2, 2, 2); BeanAdapter<IAction> adapter = new BeanAdapter<IAction>(action, true); // enabled checkbox cbEnable = BasicComponentFactory.createCheckBox(adapter.getValueModel(IAction.PROPERTY_ENABLED), StringUtils.EMPTY); cbEnable.setToolTipText(Messages.getString("ActionPanel.enableAction.tooltip")); //$NON-NLS-1$ cbEnable.setFocusable(false); UiUtils.editGridBagConstraints(gbc, 0, 0, 0, 0); add(cbEnable, gbc); // offset spinner spOffset = new MouseWheelSpinner(true); spOffset.setToolTipText(Messages.getString("ActionPanel.Offset.Tooltip")); //$NON-NLS-1$ spOffset.setModel(SpinnerAdapterFactory.createNumberAdapter(adapter.getValueModel(IAction.PROPERTY_OFFSET), 0, 0, ActionPanel.MAX_TIME_INPUT, 1)); ((JSpinner.DefaultEditor) spOffset.getEditor()).getTextField().setColumns(4); UiUtils.editGridBagConstraints(gbc, 1, 0, 0, 0); add(spOffset, gbc); // duration spinner spDuration = new MouseWheelSpinner(true); spDuration.setToolTipText(Messages.getString("ActionPanel.Duration.Tooltip")); //$NON-NLS-1$ if (action instanceof IDurationAction) { spDuration.setModel(SpinnerAdapterFactory.createNumberAdapter( adapter.getValueModel(IDurationAction.PROPERTY_DURATION), 0, 0, ActionPanel.MAX_TIME_INPUT, 1)); ((JSpinner.DefaultEditor) spDuration.getEditor()).getTextField().setColumns(4); UiUtils.editGridBagConstraints(gbc, 2, 0, 0, 0); add(spDuration, gbc); } // remove button btnRemove = new JButton(Messages.getString("ActionPanel.removeAction")); //$NON-NLS-1$ btnRemove.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { remove(); } }); btnRemove.setToolTipText(Messages.getString("ActionPanel.removeAction.tooltip")); //$NON-NLS-1$ btnRemove.setFocusable(false); UiUtils.editGridBagConstraints(gbc, 3, 0, 0, 0); add(btnRemove, gbc); }
From source file:com.stefanbrenner.droplet.ui.DevicePanel.java
License:Open Source License
/** * Create the panel./* w ww . j a v a 2s . c o m*/ */ public DevicePanel(final JComponent parent, final IDroplet droplet, final T device) { this.parent = parent; setDevice(device); setLayout(new BorderLayout(0, 5)); setBorder(BorderFactory.createLineBorder(Color.BLACK)); setBackground(DropletColors.getBackgroundColor(device)); BeanAdapter<T> adapter = new BeanAdapter<T>(device, true); // device name textfield txtName = BasicComponentFactory.createTextField(adapter.getValueModel(IDevice.PROPERTY_NAME)); txtName.setHorizontalAlignment(SwingConstants.CENTER); txtName.setColumns(1); txtName.setToolTipText(device.getName()); adapter.addBeanPropertyChangeListener(IDevice.PROPERTY_NAME, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent event) { txtName.setToolTipText(device.getName()); } }); add(txtName, BorderLayout.NORTH); // actions panel with scroll pane actionsPanel = new JPanel(); actionsPanel.setLayout(new BoxLayout(actionsPanel, BoxLayout.Y_AXIS)); actionsPanel.setBackground(getBackground()); JScrollPane scrollPane = new JScrollPane(actionsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); // resize vertical scrollbar scrollPane.getVerticalScrollBar().putClientProperty("JComponent.sizeVariant", "mini"); //$NON-NLS-1$ //$NON-NLS-2$ SwingUtilities.updateComponentTreeUI(scrollPane); // we need no border scrollPane.setBorder(BorderFactory.createEmptyBorder()); add(scrollPane, BorderLayout.CENTER); { JPanel panel = new JPanel(); panel.setLayout(new GridLayout(0, 1)); createAddButton(panel); // remove button JButton btnRemove = new JButton(Messages.getString("ActionDevicePanel.removeDevice")); //$NON-NLS-1$ btnRemove.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent action) { int retVal = JOptionPane.showConfirmDialog(DevicePanel.this, Messages.getString("ActionDevicePanel.removeDevice") + " '" + device.getName() + "'?", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ StringUtils.EMPTY, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); if (retVal == JOptionPane.YES_OPTION) { droplet.removeDevice(device); } } }); btnRemove.setFocusable(false); panel.add(btnRemove); add(panel, BorderLayout.SOUTH); } }
From source file:com.stefanbrenner.droplet.ui.DropletToolbar.java
License:Open Source License
/** * Create the panel./*from w w w . j a v a2s. c o m*/ */ public DropletToolbar(final JFrame frame, final IDropletContext dropletContext) { this.dropletContext = dropletContext; setLayout(new FlowLayout(FlowLayout.RIGHT)); // show button JButton btnDirect = new JButton(new ControlDevcieAction(frame, dropletContext)); add(btnDirect); // show button JButton btnShow = new JButton(new ShowAction(frame, dropletContext)); add(btnShow); // send button JButton btnSend = new JButton(new SendAction(frame, dropletContext)); add(btnSend); BeanAdapter<IDropletContext> adapter = new BeanAdapter<IDropletContext>(dropletContext, true); // rounds spinner add(new JLabel(Messages.getString("DropletToolbar.rounds"))); //$NON-NLS-1$ spRounds = new MouseWheelSpinner(true); spRounds.setModel(SpinnerAdapterFactory .createNumberAdapter(adapter.getValueModel(IDropletContext.PROPERTY_ROUNDS), 1, 1, 9999, 1)); ((JSpinner.DefaultEditor) spRounds.getEditor()).getTextField().setColumns(4); add(spRounds); // round delay spinner add(new JLabel(Messages.getString("DropletToolbar.delay"))); //$NON-NLS-1$ spRoundDelay = new MouseWheelSpinner(true); spRoundDelay.setModel(SpinnerAdapterFactory.createNumberAdapter( adapter.getValueModel(IDropletContext.PROPERTY_ROUND_DELAY), 1000, 0, 99999999, 1)); ((JSpinner.DefaultEditor) spRoundDelay.getEditor()).getTextField().setColumns(8); updateTooltip(); adapter.addBeanPropertyChangeListener(IDropletContext.PROPERTY_ROUND_DELAY, new PropertyChangeListener() { @Override public void propertyChange(final PropertyChangeEvent event) { updateTooltip(); } }); add(spRoundDelay); // start button JButton btnStart = new JButton(new StartAction(frame, dropletContext)); add(btnStart); // cancel button JButton btnCancel = new JButton(new CancelAction(frame, dropletContext)); add(btnCancel); }