List of usage examples for javax.swing JToolBar putClientProperty
public final void putClientProperty(Object key, Object value)
From source file:SwingToolBarSample.java
public static void main(String args[]) { ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { System.out.println(actionEvent.getActionCommand()); }//from w w w .j a va 2 s .co m }; JFrame frame = new JFrame("JToolBar Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JToolBar toolbar = new JToolBar(); toolbar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); for (int i = 0, n = buttonColors.length; i < n; i++) { Object color[] = buttonColors[i]; if (color == null) { toolbar.addSeparator(); } else { Icon icon = new DiamondIcon((Color) color[COLOR_POSITION], true, 20, 20); JButton button = new JButton(icon); button.setActionCommand((String) color[STRING_POSITION]); button.addActionListener(actionListener); toolbar.add(button); } } Action action = new ActionMenuSample.ShowAction(frame); toolbar.add(action); Container contentPane = frame.getContentPane(); contentPane.add(toolbar, BorderLayout.NORTH); JTextArea textArea = new JTextArea(); JScrollPane pane = new JScrollPane(textArea); contentPane.add(pane, BorderLayout.CENTER); frame.setSize(350, 150); frame.setVisible(true); }
From source file:com.archivas.clienttools.arcmover.gui.panels.ProfilePanel.java
private void initGuiComponents() { fileListModel = new FileListTableModel(); fileList = new FileListTable(fileListModel); fileList.addKeyListener(new KeyAdapter() { @Override// ww w. ja v a 2 s .co m public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { openSelectedFile(); e.consume(); } } }); fileList.setAutoCreateColumnsFromModel(true); fileList.setDropMode(DropMode.ON_OR_INSERT_ROWS); fileList.setFillsViewportHeight(true); fileList.setGridColor(new Color(-1)); fileListScrollPane = new JScrollPane(fileList); fileListScrollPane.setAutoscrolls(false); fileListScrollPane.setBackground(UIManager.getColor("TableHeader.background")); fileListScrollPane.setPreferredSize(new Dimension(100, 128)); fileListScrollPane.setEnabled(false); // // toolbar // final JToolBar toolBar1 = new JToolBar(); toolBar1.setBorderPainted(false); toolBar1.setFloatable(false); toolBar1.setRollover(true); toolBar1.putClientProperty("JToolBar.isRollover", Boolean.TRUE); homeDirectoryButton = new JButton(); homeDirectoryButton.setHorizontalAlignment(2); homeDirectoryButton.setIcon(GUIHelper.HOME_ICON); homeDirectoryButton.setMargin(new Insets(3, 3, 3, 3)); homeDirectoryButton.setText(""); homeDirectoryButton.setToolTipText("Go to home directory"); homeDirectoryButton.setEnabled(false); toolBar1.add(homeDirectoryButton); refreshButton = new JButton(); refreshButton.setHorizontalAlignment(2); refreshButton.setIcon(new ImageIcon(getClass().getResource("/images/refresh.gif"))); refreshButton.setMargin(new Insets(3, 3, 3, 3)); refreshButton.setText(""); refreshButton.setToolTipText("Refresh current directory listing"); refreshButton.setEnabled(false); toolBar1.add(refreshButton); upDirectoryButton = new JButton(); upDirectoryButton.setHideActionText(false); upDirectoryButton.setHorizontalAlignment(2); upDirectoryButton.setIcon(GUIHelper.UP_DIR_ICON); upDirectoryButton.setMargin(new Insets(3, 3, 3, 3)); upDirectoryButton.setToolTipText("Up"); upDirectoryButton.setEnabled(false); toolBar1.add(upDirectoryButton); browseDirectoryButton = new JButton(); browseDirectoryButton.setHideActionText(false); browseDirectoryButton.setHorizontalAlignment(2); browseDirectoryButton.setIcon(GUIHelper.DIRECTORY_ICON); browseDirectoryButton.setMargin(new Insets(3, 3, 3, 3)); browseDirectoryButton.setToolTipText(BROWSE_LFS_TEXT); browseDirectoryButton.setEnabled(false); toolBar1.add(browseDirectoryButton); profileModel = new ProfileComboBoxModel(); profileSelectionCombo = new JComboBox(profileModel); profileSelectionCombo.setEnabled(false); profileSelectionCombo.setToolTipText("Select a namespace profile"); profileSelectionCombo.setPrototypeDisplayValue("#"); pathCombo = new JComboBox(); pathCombo.setEditable(false); pathCombo.setEnabled(false); pathCombo.setToolTipText("Current directory path"); pathCombo.setPrototypeDisplayValue("#"); sslButton = new JButton(); sslButton.setAlignmentY(0.0f); sslButton.setBorderPainted(false); sslButton.setHorizontalAlignment(2); sslButton.setHorizontalTextPosition(11); sslButton.setIcon(new ImageIcon(getClass().getResource("/images/lockedstate.gif"))); sslButton.setMargin(new Insets(0, 0, 0, 0)); sslButton.setMaximumSize(new Dimension(20, 20)); sslButton.setMinimumSize(new Dimension(20, 20)); sslButton.setPreferredSize(new Dimension(20, 20)); sslButton.setText(""); sslButton.setToolTipText("View certificate"); sslButton.setEnabled(false); // // profile and toolbar buttons // JPanel profileAndToolbarPanel = new FixedHeightPanel(); profileAndToolbarPanel.setLayout(new BoxLayout(profileAndToolbarPanel, BoxLayout.X_AXIS)); profileAndToolbarPanel.add(profileSelectionCombo); profileAndToolbarPanel.add(Box.createHorizontalStrut(25)); profileAndToolbarPanel.add(toolBar1); // // Path & SSLCert button // JPanel pathPanel = new FixedHeightPanel(); pathPanel.setLayout(new BoxLayout(pathPanel, BoxLayout.X_AXIS)); pathCombo.setAlignmentY(CENTER_ALIGNMENT); pathPanel.add(pathCombo); pathPanel.add(Box.createHorizontalStrut(5)); sslButton.setAlignmentY(CENTER_ALIGNMENT); pathPanel.add(sslButton); // // Put it all together // setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(profileAndToolbarPanel); add(Box.createVerticalStrut(5)); add(pathPanel); add(Box.createVerticalStrut(5)); add(fileListScrollPane); setBorder(new EmptyBorder(12, 12, 12, 12)); }
From source file:org.openmicroscopy.shoola.env.ui.TaskBarView.java
/** * Helper method to create an empty, floatable toolbar with rollover * effect for the icon buttons and an etched border. * * @return See above.//w w w.j av a 2s . co m */ private JToolBar createToolBar() { JToolBar bar = new JToolBar(); bar.setBorder(BorderFactory.createEtchedBorder()); bar.setFloatable(false); bar.putClientProperty("JToolBar.isRollover", Boolean.valueOf(true)); return bar; }
From source file:ro.nextreports.designer.querybuilder.QueryBuilderPanel.java
private void initUI() { JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.setDividerLocation(250);// w w w . j a va 2 s . c om split.setOneTouchExpandable(true); JToolBar toolBar = new JToolBar(); toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); toolBar.setBorderPainted(false); // add refresh action toolBar.add(new AbstractAction() { public Object getValue(String key) { if (AbstractAction.SMALL_ICON.equals(key)) { return ImageUtil.getImageIcon("refresh"); } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) { return I18NSupport.getString("querybuilder.refresh"); } return super.getValue(key); } public void actionPerformed(ActionEvent e) { try { if (Globals.getConnection() == null) { return; } // refresh tables, views, procedures TreeUtil.refreshDatabase(); // add new queries to tree TreeUtil.refreshQueries(); // add new reports to tree TreeUtil.refreshReports(); // add new charts to tree TreeUtil.refreshCharts(); } catch (Exception ex) { Show.error(ex); } } }); // add expand action toolBar.add(new AbstractAction() { public Object getValue(String key) { if (AbstractAction.SMALL_ICON.equals(key)) { return ImageUtil.getImageIcon("expandall"); } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) { return I18NSupport.getString("querybuilder.expand.all"); } return super.getValue(key); } public void actionPerformed(ActionEvent e) { TreeUtil.expandAll(dbBrowserTree); } }); // add collapse action toolBar.add(new AbstractAction() { public Object getValue(String key) { if (AbstractAction.SMALL_ICON.equals(key)) { return ImageUtil.getImageIcon("collapseall"); } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) { return I18NSupport.getString("querybuilder.collapse.all"); } return super.getValue(key); } public void actionPerformed(ActionEvent e) { TreeUtil.collapseAll(dbBrowserTree); } }); // add properties button /* JButton propButton = new MagicButton(new AbstractAction() { public Object getValue(String key) { if (AbstractAction.SMALL_ICON.equals(key)) { return ImageUtil.getImageIcon("properties"); } return super.getValue(key); } public void actionPerformed(ActionEvent e) { DBBrowserPropertiesPanel joinPanel = new DBBrowserPropertiesPanel(); JDialog dlg = new DBBrowserPropertiesDialog(joinPanel); dlg.pack(); dlg.setResizable(false); Show.centrateComponent(Globals.getMainFrame(), dlg); dlg.setVisible(true); } }); propButton.setToolTipText(I18NSupport.getString("querybuilder.properties")); */ //browserButtonsPanel.add(propButton); // ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(browserButtonsPanel); browserPanel = new JXPanel(new BorderLayout()); browserPanel.add(toolBar, BorderLayout.NORTH); // browser tree JScrollPane scroll = new JScrollPane(dbBrowserTree); browserPanel.add(scroll, BorderLayout.CENTER); split.setLeftComponent(browserPanel); tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM); // tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE); // look like eclipse JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split2.setResizeWeight(0.66); split2.setOneTouchExpandable(true); // desktop pane desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); desktop.setDropTarget( new DropTarget(desktop, DnDConstants.ACTION_MOVE, new DesktopPaneDropTargetListener(), true)); // create the toolbar JToolBar toolBar2 = new JToolBar(); toolBar2.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders toolBar2.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); toolBar2.setBorderPainted(false); Action distinctAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (distinctButton.isSelected()) { selectQuery.setDistinct(true); } else { selectQuery.setDistinct(false); } } }; distinctAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.distinct")); distinctAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.distinct")); toolBar2.add(distinctButton = new JToggleButton(distinctAction)); Action groupByAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { groupBy = groupByButton.isSelected(); Globals.getEventBus().publish(new GroupByEvent(QueryBuilderPanel.this.desktop, groupBy)); } }; groupByAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.group_by")); groupByAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.group.by")); toolBar2.add(groupByButton = new JToggleButton(groupByAction)); Action clearAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { clear(false); } }; clearAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("clear")); clearAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.clear")); toolBar2.add(clearAction); // add separator SwingUtil.addCustomSeparator(toolBar2); // add run button Action runQueryAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { selectSQLViewTab(); sqlView.doRun(); } }; runQueryAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run")); KeyStroke ks = KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4")); runQueryAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " (" + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")"); runQueryAction.putValue(Action.ACCELERATOR_KEY, ks); toolBar2.add(runQueryAction); // register run query shortcut GlobalHotkeyManager hotkeyManager = GlobalHotkeyManager.getInstance(); InputMap inputMap = hotkeyManager.getInputMap(); ActionMap actionMap = hotkeyManager.getActionMap(); inputMap.put((KeyStroke) runQueryAction.getValue(Action.ACCELERATOR_KEY), "runQueryAction"); actionMap.put("runQueryAction", runQueryAction); JScrollPane scroll2 = new JScrollPane(desktop, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll2.setPreferredSize(DBTablesDesktopPane.PREFFERED_SIZE); DecoratedScrollPane.decorate(scroll2); JPanel topPanel = new JPanel(); topPanel.setLayout(new GridBagLayout()); topPanel.add(toolBar2, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); topPanel.add(scroll2, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); split2.setTopComponent(topPanel); designPanel = new DesignerTablePanel(selectQuery); split2.setBottomComponent(designPanel); split2.setDividerLocation(400); tabbedPane.addTab(I18NSupport.getString("querybuilder.query.designer"), ImageUtil.getImageIcon("designer"), split2); tabbedPane.setMnemonicAt(0, 'D'); sqlView = new SQLViewPanel(); sqlView.getEditorPane().setDropTarget(new DropTarget(sqlView.getEditorPane(), DnDConstants.ACTION_MOVE, new SQLViewDropTargetListener(), true)); tabbedPane.addTab(I18NSupport.getString("querybuilder.query.editor"), ImageUtil.getImageIcon("sql"), sqlView); tabbedPane.setMnemonicAt(1, 'E'); split.setRightComponent(tabbedPane); // register a change listener tabbedPane.addChangeListener(new ChangeListener() { // this method is called whenever the selected tab changes public void stateChanged(ChangeEvent ev) { if (ev.getSource() == QueryBuilderPanel.this.tabbedPane) { // get current tab int sel = QueryBuilderPanel.this.tabbedPane.getSelectedIndex(); if (sel == 1) { // sql view String query; if (!synchronizedPanels) { query = sqlView.getQueryString(); synchronizedPanels = true; } else { if (Globals.getConnection() != null) { query = getSelectQuery().toString(); } else { query = ""; } // if (query.equals("")) { // query = sqlView.getQueryString(); // } } if (resetTable) { sqlView.clear(); resetTable = false; } //System.out.println("query="+query); sqlView.setQueryString(query); } else if (sel == 0) { // design view if (queryWasModified(false)) { Object[] options = { I18NSupport.getString("optionpanel.yes"), I18NSupport.getString("optionpanel.no") }; String m1 = I18NSupport.getString("querybuilder.lost"); String m2 = I18NSupport.getString("querybuilder.continue"); int option = JOptionPane.showOptionDialog(Globals.getMainFrame(), "<HTML>" + m1 + "<BR>" + m2 + "</HTML>", I18NSupport.getString("querybuilder.confirm"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[1]); if (option != JOptionPane.YES_OPTION) { synchronizedPanels = false; tabbedPane.setSelectedIndex(1); } else { resetTable = true; } } } else if (sel == 2) { // report view } } } }); // this.add(split, BorderLayout.CENTER); parametersPanel = new ParametersPanel(); }
From source file:ro.nextreports.designer.querybuilder.SQLViewPanel.java
private void initUI() { sqlEditor = new Editor() { public void afterCaretMove() { removeHighlightErrorLine();/*from www . j ava 2s. c o m*/ } }; this.queryArea = sqlEditor.getEditorPanel().getEditorPane(); queryArea.setText(DEFAULT_QUERY); errorPainter = new javax.swing.text.Highlighter.HighlightPainter() { @Override public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) { try { Rectangle r = c.modelToView(c.getCaretPosition()); g.setColor(Color.RED.brighter().brighter()); g.fillRect(0, r.y, c.getWidth(), r.height); } catch (BadLocationException e) { // ignore } } }; ActionMap actionMap = sqlEditor.getEditorPanel().getEditorPane().getActionMap(); // create the toolbar JToolBar toolBar = new JToolBar(); toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH); toolBar.setBorderPainted(false); // add cut action Action cutAction = actionMap.get(BaseEditorKit.cutAction); cutAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("cut")); cutAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.cut")); toolBar.add(cutAction); // add copy action Action copyAction = actionMap.get(BaseEditorKit.copyAction); copyAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("copy")); copyAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.copy")); toolBar.add(copyAction); // add paste action Action pasteAction = actionMap.get(BaseEditorKit.pasteAction); pasteAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("paste")); pasteAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.paste")); toolBar.add(pasteAction); // add separator SwingUtil.addCustomSeparator(toolBar); // add undo action Action undoAction = actionMap.get(BaseEditorKit.undoAction); undoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("undo")); undoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("undo")); toolBar.add(undoAction); // add redo action Action redoAction = actionMap.get(BaseEditorKit.redoAction); redoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("redo")); redoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("redo")); toolBar.add(redoAction); // add separator SwingUtil.addCustomSeparator(toolBar); // add find action Action findReplaceAction = actionMap.get(BaseEditorKit.findReplaceAction); findReplaceAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("find")); findReplaceAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqleditor.findReplaceActionName")); toolBar.add(findReplaceAction); // add separator SwingUtil.addCustomSeparator(toolBar); // add run action runAction = new SQLRunAction(); runAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run")); runAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4"))); runAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " (" + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")"); // runAction is globally registered in QueryBuilderPanel ! toolBar.add(runAction); // ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(buttonsPanel); // create the table resultTable = new JXTable(); resultTable.setDefaultRenderer(Integer.class, new ToStringRenderer()); // to remove thousand separators resultTable.setDefaultRenderer(Long.class, new ToStringRenderer()); resultTable.setDefaultRenderer(Date.class, new DateRenderer()); resultTable.setDefaultRenderer(Double.class, new DoubleRenderer()); resultTable.addMouseListener(new CopyTableMouseAdapter(resultTable)); TableUtil.setRowHeader(resultTable); resultTable.setColumnControlVisible(true); // resultTable.getTableHeader().setReorderingAllowed(false); resultTable.setHorizontalScrollEnabled(true); // highlight table Highlighter alternateHighlighter = HighlighterFactory.createAlternateStriping(Color.WHITE, ColorUtil.PANEL_BACKROUND_COLOR); Highlighter nullHighlighter = new TextHighlighter(ResultSetTableModel.NULL_VALUE, Color.YELLOW.brighter()); Highlighter blobHighlighter = new TextHighlighter(ResultSetTableModel.BLOB_VALUE, Color.GRAY.brighter()); Highlighter clobHighlighter = new TextHighlighter(ResultSetTableModel.CLOB_VALUE, Color.GRAY.brighter()); resultTable.setHighlighters(alternateHighlighter, nullHighlighter, blobHighlighter, clobHighlighter); resultTable.setBackground(ColorUtil.PANEL_BACKROUND_COLOR); resultTable.setGridColor(Color.LIGHT_GRAY); resultTable.setRolloverEnabled(true); resultTable.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED)); JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT); split.setResizeWeight(0.66); split.setOneTouchExpandable(true); JPanel topPanel = new JPanel(); topPanel.setLayout(new GridBagLayout()); topPanel.add(toolBar, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0)); topPanel.add(sqlEditor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); JPanel bottomPanel = new JPanel(); bottomPanel.setLayout(new GridBagLayout()); JScrollPane scrPanel = new JScrollPane(resultTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); statusPanel = new SQLStatusPanel(); bottomPanel.add(scrPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); bottomPanel.add(statusPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); split.setTopComponent(topPanel); split.setBottomComponent(bottomPanel); split.setDividerLocation(400); setLayout(new BorderLayout()); this.add(split, BorderLayout.CENTER); }