List of usage examples for javax.swing JToolBar setBorderPainted
@BeanProperty(expert = true, description = "Does the tool bar paint its borders?") public void setBorderPainted(boolean b)
borderPainted
property, which is true
if the border should be painted. From source file:io.github.tavernaextras.biocatalogue.ui.filtertree.FilterTreePane.java
/** * @return A toolbar that replicates all actions available in the contextual menu of * the filtering tree - mainly: saving current filter, reloading filter tree, * expanding/collapsing and selecting/deselecting everything in the tree. *///from www. j ava 2 s .co m private JToolBar createTreeActionToolbar() { // the actual toolbar - no actions are added to it yet: done in a separate method JToolBar tbTreeActions = new JToolBar(JToolBar.HORIZONTAL); tbTreeActions.setAlignmentX(RIGHT_ALIGNMENT); tbTreeActions.setBorderPainted(true); tbTreeActions.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); tbTreeActions.setFloatable(false); return (tbTreeActions); }
From source file:dk.dma.epd.common.prototype.gui.voct.VOCTAdditionalInfoPanel.java
/** * Constructor/*from ww w .ja va 2s . c o m*/ * * @param compactLayout * if false, there will be message type selectors in the panel */ public VOCTAdditionalInfoPanel(boolean compactLayout) { super(new BorderLayout()); EPD.getInstance().getVoctHandler().addVoctSarInfoListener(this); // Prepare the title header titleHeader.setBackground(getBackground().darker()); titleHeader.setOpaque(true); titleHeader.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); titleHeader.setHorizontalAlignment(SwingConstants.CENTER); add(titleHeader, BorderLayout.NORTH); // Add messages panel scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); messagesPanel.setBackground(UIManager.getColor("List.background")); messagesPanel.setOpaque(false); messagesPanel.setLayout(new GridBagLayout()); messagesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(scrollPane, BorderLayout.CENTER); JPanel sendPanel = new JPanel(new GridBagLayout()); add(sendPanel, BorderLayout.SOUTH); Insets insets = new Insets(2, 2, 2, 2); // Add text area // if (false) { // messageText = new JTextField(); // ((JTextField) messageText).addActionListener(this); // sendPanel.add(messageText, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); // // } else { messageText = new JTextArea(); JScrollPane scrollPane2 = new JScrollPane(messageText); scrollPane2.setPreferredSize(new Dimension(100, 50)); scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); sendPanel.add(scrollPane2, new GridBagConstraints(0, 0, 1, 2, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); // } // Add buttons // ButtonGroup group = new ButtonGroup(); if (!compactLayout) { JToolBar msgTypePanel = new JToolBar(); msgTypePanel.setBorderPainted(false); msgTypePanel.setOpaque(true); msgTypePanel.setFloatable(false); sendPanel.add(msgTypePanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); } if (compactLayout) { addBtn = new JButton("Add to Log"); sendPanel.add(addBtn, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); } // addBtn.setEnabled(false); // messageText.setEditable(false); addBtn.addActionListener(this); }
From source file:dk.dma.epd.common.prototype.gui.notification.ChatServicePanel.java
/** * Constructor//from w ww . j ava2 s. com * * @param compactLayout * if false, there will be message type selectors in the panel */ public ChatServicePanel(boolean compactLayout) { super(new BorderLayout()); // Prepare the title header titleHeader.setBackground(getBackground().darker()); titleHeader.setOpaque(true); titleHeader.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2)); titleHeader.setHorizontalAlignment(SwingConstants.CENTER); add(titleHeader, BorderLayout.NORTH); // Add messages panel scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); messagesPanel.setBackground(UIManager.getColor("List.background")); messagesPanel.setOpaque(false); messagesPanel.setLayout(new GridBagLayout()); messagesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); add(scrollPane, BorderLayout.CENTER); JPanel sendPanel = new JPanel(new GridBagLayout()); add(sendPanel, BorderLayout.SOUTH); Insets insets = new Insets(2, 2, 2, 2); // Add text area if (compactLayout) { messageText = new JTextField(); ((JTextField) messageText).addActionListener(this); sendPanel.add(messageText, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); } else { messageText = new JTextArea(); JScrollPane scrollPane2 = new JScrollPane(messageText); scrollPane2.setPreferredSize(new Dimension(100, 50)); scrollPane2.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane2.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); sendPanel.add(scrollPane2, new GridBagConstraints(0, 0, 1, 2, 1.0, 1.0, NORTH, BOTH, insets, 0, 0)); } // Add buttons ButtonGroup group = new ButtonGroup(); messageTypeBtn = createMessageTypeButton("Send messages", ICON_MESSAGE, true, group); warningTypeBtn = createMessageTypeButton("Send warnings", ICON_WARNING, false, group); alertTypeBtn = createMessageTypeButton("Send alerts", ICON_ALERT, false, group); if (!compactLayout) { JToolBar msgTypePanel = new JToolBar(); msgTypePanel.setBorderPainted(false); msgTypePanel.setOpaque(true); msgTypePanel.setFloatable(false); sendPanel.add(msgTypePanel, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); msgTypePanel.add(messageTypeBtn); msgTypePanel.add(warningTypeBtn); msgTypePanel.add(alertTypeBtn); } if (compactLayout) { sendBtn = new JButton("Send"); sendPanel.add(sendBtn, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); } else { sendBtn = new JButton("Send", ICON_MESSAGE); sendBtn.setPreferredSize(new Dimension(100, sendBtn.getPreferredSize().height)); sendPanel.add(sendBtn, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, NORTH, NONE, insets, 0, 0)); } sendBtn.setEnabled(false); messageText.setEditable(false); sendBtn.addActionListener(this); }
From source file:net.sf.nmedit.nomad.core.Nomad.java
private JToolBar createQuickActionToolbar() { JToolBar toolbar = new JToolBar(); toolbar.setBorderPainted(false); toolbar.setFloatable(false);// www . j a va2 s . c o m toolbar.add(Factory.createToolBarButton(menuLayout.getEntry(MENU_FILE_OPEN))); toolbar.addSeparator(); toolbar.add(Factory.createToolBarButton(menuLayout.getEntry(MENU_FILE_SAVE))); toolbar.addSeparator(); JPopupMenu pop = new JPopupMenu(); Iterator<FileService> iter = ServiceRegistry.getServices(FileService.class); JRadioButtonMenuItem rfirst = null; SelectedAction sa = new SelectedAction(); sa.putValue(AbstractAction.SMALL_ICON, getImage("/icons/tango/16x16/actions/document-new.png")); while (iter.hasNext()) { FileService fs = iter.next(); if (fs.isNewFileOperationSupported()) { JRadioButtonMenuItem rb = new JRadioButtonMenuItem( new AHAction(fs.getName(), fs.getIcon(), fs, "newFile")); sa.add(rb); pop.add(rb); if (rfirst == null) rfirst = rb; } } JButton btn = Factory.createToolBarButton(sa); toolbar.add(btn); new JDropDownButtonControl(btn, pop); return toolbar; }
From source file:com.net2plan.gui.utils.topologyPane.TopologyPanel.java
/** * Default constructor./* w ww .java 2 s .c o m*/ * * @param callback Topology callback listening plugin events * @param defaultDesignDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/networkTopologies}) * @param defaultDemandDirectory Default location for design {@code .n2p} files (it may be null, then default is equal to {@code net2planFolder/workspace/data/trafficMatrices}) * @param canvasType Canvas type (i.e. JUNG) * @param plugins List of plugins to be included (it may be null) */ public TopologyPanel(final IVisualizationCallback callback, File defaultDesignDirectory, File defaultDemandDirectory, Class<? extends ITopologyCanvas> canvasType, List<ITopologyCanvasPlugin> plugins) { File currentDir = SystemUtils.getCurrentDir(); this.callback = callback; this.defaultDesignDirectory = defaultDesignDirectory == null ? new File( currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator() + "data" + SystemUtils.getDirectorySeparator() + "networkTopologies") : defaultDesignDirectory; this.defaultDemandDirectory = defaultDemandDirectory == null ? new File( currentDir + SystemUtils.getDirectorySeparator() + "workspace" + SystemUtils.getDirectorySeparator() + "data" + SystemUtils.getDirectorySeparator() + "trafficMatrices") : defaultDemandDirectory; this.multilayerControlPanel = new MultiLayerControlPanel(callback); try { canvas = canvasType.getDeclaredConstructor(IVisualizationCallback.class, TopologyPanel.class) .newInstance(callback, this); } catch (Exception e) { throw new RuntimeException(e); } if (plugins != null) for (ITopologyCanvasPlugin plugin : plugins) addPlugin(plugin); setLayout(new BorderLayout()); JToolBar toolbar = new JToolBar(); toolbar.setRollover(true); toolbar.setFloatable(false); toolbar.setOpaque(false); toolbar.setBorderPainted(false); JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(toolbar, BorderLayout.NORTH); add(topPanel, BorderLayout.NORTH); JComponent canvasComponent = canvas.getCanvasComponent(); canvasPanel = new JPanel(new BorderLayout()); canvasComponent.setBorder(LineBorder.createBlackLineBorder()); JToolBar multiLayerToolbar = new JToolBar(JToolBar.VERTICAL); multiLayerToolbar.setRollover(true); multiLayerToolbar.setFloatable(false); multiLayerToolbar.setOpaque(false); canvasPanel.add(canvasComponent, BorderLayout.CENTER); canvasPanel.add(multiLayerToolbar, BorderLayout.WEST); add(canvasPanel, BorderLayout.CENTER); btn_load = new JButton(); btn_load.setToolTipText("Load a network design"); btn_loadDemand = new JButton(); btn_loadDemand.setToolTipText("Load a traffic demand set"); btn_save = new JButton(); btn_save.setToolTipText("Save current state to a file"); btn_zoomIn = new JButton(); btn_zoomIn.setToolTipText("Zoom in"); btn_zoomOut = new JButton(); btn_zoomOut.setToolTipText("Zoom out"); btn_zoomAll = new JButton(); btn_zoomAll.setToolTipText("Zoom all"); btn_takeSnapshot = new JButton(); btn_takeSnapshot.setToolTipText("Take a snapshot of the canvas"); btn_showNodeNames = new JToggleButton(); btn_showNodeNames.setToolTipText("Show/hide node names"); btn_showLinkIds = new JToggleButton(); btn_showLinkIds.setToolTipText( "Show/hide link utilization, measured as the ratio between the total traffic in the link (including that in protection segments) and total link capacity (including that reserved by protection segments)"); btn_showNonConnectedNodes = new JToggleButton(); btn_showNonConnectedNodes.setToolTipText("Show/hide non-connected nodes"); btn_increaseNodeSize = new JButton(); btn_increaseNodeSize.setToolTipText("Increase node size"); btn_decreaseNodeSize = new JButton(); btn_decreaseNodeSize.setToolTipText("Decrease node size"); btn_increaseFontSize = new JButton(); btn_increaseFontSize.setToolTipText("Increase font size"); btn_decreaseFontSize = new JButton(); btn_decreaseFontSize.setToolTipText("Decrease font size"); /* Multilayer buttons */ btn_increaseInterLayerDistance = new JButton(); btn_increaseInterLayerDistance .setToolTipText("Increase the distance between layers (when more than one layer is visible)"); btn_decreaseInterLayerDistance = new JButton(); btn_decreaseInterLayerDistance .setToolTipText("Decrease the distance between layers (when more than one layer is visible)"); btn_showLowerLayerInfo = new JToggleButton(); btn_showLowerLayerInfo .setToolTipText("Shows the links in lower layers that carry traffic of the picked element"); btn_showLowerLayerInfo.setSelected(getVisualizationState().isShowInCanvasLowerLayerPropagation()); btn_showUpperLayerInfo = new JToggleButton(); btn_showUpperLayerInfo.setToolTipText( "Shows the links in upper layers that carry traffic that appears in the picked element"); btn_showUpperLayerInfo.setSelected(getVisualizationState().isShowInCanvasUpperLayerPropagation()); btn_showThisLayerInfo = new JToggleButton(); btn_showThisLayerInfo.setToolTipText( "Shows the links in the same layer as the picked element, that carry traffic that appears in the picked element"); btn_showThisLayerInfo.setSelected(getVisualizationState().isShowInCanvasThisLayerPropagation()); btn_npChangeUndo = new JButton(); btn_npChangeUndo.setToolTipText( "Navigate back to the previous state of the network (last time the network design was changed)"); btn_npChangeRedo = new JButton(); btn_npChangeRedo.setToolTipText( "Navigate forward to the next state of the network (when network design was changed"); btn_osmMap = new JToggleButton(); btn_osmMap.setToolTipText( "Toggle between on/off the OSM support. An internet connection is required in order for this to work."); btn_tableControlWindow = new JButton(); btn_tableControlWindow.setToolTipText("Show the network topology control window."); // MultiLayer control window JPopupMenu multiLayerPopUp = new JPopupMenu(); multiLayerPopUp.add(multilayerControlPanel); JPopUpButton btn_multilayer = new JPopUpButton("", multiLayerPopUp); btn_reset = new JButton("Reset"); btn_reset.setToolTipText("Reset the user interface"); btn_reset.setMnemonic(KeyEvent.VK_R); btn_load.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDesign.png"))); btn_loadDemand.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/loadDemand.png"))); btn_save.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/saveDesign.png"))); btn_showNodeNames .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNodeName.png"))); btn_showLinkIds .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLinkUtilization.png"))); btn_showNonConnectedNodes.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png"))); //btn_whatIfActivated.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showNonConnectedNodes.png"))); btn_zoomIn.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomIn.png"))); btn_zoomOut.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomOut.png"))); btn_zoomAll.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/zoomAll.png"))); btn_takeSnapshot.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/takeSnapshot.png"))); btn_increaseNodeSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseNode.png"))); btn_decreaseNodeSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseNode.png"))); btn_increaseFontSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseFont.png"))); btn_decreaseFontSize .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseFont.png"))); btn_increaseInterLayerDistance.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/increaseLayerDistance.png"))); btn_decreaseInterLayerDistance.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/decreaseLayerDistance.png"))); btn_multilayer .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerControl.png"))); btn_showThisLayerInfo .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerPropagation.png"))); btn_showUpperLayerInfo.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerUpperPropagation.png"))); btn_showLowerLayerInfo.setIcon( new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showLayerLowerPropagation.png"))); btn_tableControlWindow .setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showControl.png"))); btn_osmMap.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/showOSM.png"))); btn_npChangeUndo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/undoButton.png"))); btn_npChangeRedo.setIcon(new ImageIcon(TopologyPanel.class.getResource("/resources/gui/redoButton.png"))); btn_load.addActionListener(this); btn_loadDemand.addActionListener(this); btn_save.addActionListener(this); btn_showNodeNames.addActionListener(this); btn_showLinkIds.addActionListener(this); btn_showNonConnectedNodes.addActionListener(this); btn_zoomIn.addActionListener(this); btn_zoomOut.addActionListener(this); btn_zoomAll.addActionListener(this); btn_takeSnapshot.addActionListener(this); btn_reset.addActionListener(this); btn_increaseInterLayerDistance.addActionListener(this); btn_decreaseInterLayerDistance.addActionListener(this); btn_showLowerLayerInfo.addActionListener(this); btn_showUpperLayerInfo.addActionListener(this); btn_showThisLayerInfo.addActionListener(this); btn_increaseNodeSize.addActionListener(this); btn_decreaseNodeSize.addActionListener(this); btn_increaseFontSize.addActionListener(this); btn_decreaseFontSize.addActionListener(this); btn_npChangeUndo.addActionListener(this); btn_npChangeRedo.addActionListener(this); btn_osmMap.addActionListener(this); btn_tableControlWindow.addActionListener(this); toolbar.add(btn_load); toolbar.add(btn_loadDemand); toolbar.add(btn_save); toolbar.add(new JToolBar.Separator()); toolbar.add(btn_zoomIn); toolbar.add(btn_zoomOut); toolbar.add(btn_zoomAll); toolbar.add(btn_takeSnapshot); toolbar.add(new JToolBar.Separator()); toolbar.add(btn_showNodeNames); toolbar.add(btn_showLinkIds); toolbar.add(btn_showNonConnectedNodes); toolbar.add(new JToolBar.Separator()); toolbar.add(btn_increaseNodeSize); toolbar.add(btn_decreaseNodeSize); toolbar.add(btn_increaseFontSize); toolbar.add(btn_decreaseFontSize); toolbar.add(new JToolBar.Separator()); toolbar.add(Box.createHorizontalGlue()); toolbar.add(btn_osmMap); toolbar.add(btn_tableControlWindow); toolbar.add(btn_reset); multiLayerToolbar.add(new JToolBar.Separator()); multiLayerToolbar.add(btn_multilayer); multiLayerToolbar.add(btn_increaseInterLayerDistance); multiLayerToolbar.add(btn_decreaseInterLayerDistance); multiLayerToolbar.add(btn_showLowerLayerInfo); multiLayerToolbar.add(btn_showUpperLayerInfo); multiLayerToolbar.add(btn_showThisLayerInfo); multiLayerToolbar.add(Box.createVerticalGlue()); multiLayerToolbar.add(btn_npChangeUndo); multiLayerToolbar.add(btn_npChangeRedo); this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (e.getComponent().getSize().getHeight() != 0 && e.getComponent().getSize().getWidth() != 0) { canvas.zoomAll(); } } }); List<Component> children = SwingUtils.getAllComponents(this); for (Component component : children) if (component instanceof AbstractButton) component.setFocusable(false); if (ErrorHandling.isDebugEnabled()) { canvas.getCanvasComponent().addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent e) { Point point = e.getPoint(); position.setText("view = " + point + ", NetPlan coord = " + canvas.getCanvasPointFromNetPlanPoint(point)); } }); position = new JLabel(); add(position, BorderLayout.SOUTH); } else { position = null; } new FileDrop(canvasComponent, new LineBorder(Color.BLACK), new FileDrop.Listener() { @Override public void filesDropped(File[] files) { for (File file : files) { try { if (!file.getName().toLowerCase(Locale.getDefault()).endsWith(".n2p")) return; loadDesignFromFile(file); break; } catch (Throwable e) { break; } } } }); btn_showNodeNames.setSelected(getVisualizationState().isCanvasShowNodeNames()); btn_showLinkIds.setSelected(getVisualizationState().isCanvasShowLinkLabels()); btn_showNonConnectedNodes.setSelected(getVisualizationState().isCanvasShowNonConnectedNodes()); final ITopologyCanvasPlugin popupPlugin = new PopupMenuPlugin(callback, this.canvas); addPlugin(new PanGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK)); if (callback.getVisualizationState().isNetPlanEditable() && getCanvas() instanceof JUNGCanvas) addPlugin(new AddLinkGraphPlugin(callback, canvas, MouseEvent.BUTTON1_MASK, MouseEvent.BUTTON1_MASK | MouseEvent.SHIFT_MASK)); addPlugin(popupPlugin); if (callback.getVisualizationState().isNetPlanEditable()) addPlugin(new MoveNodePlugin(callback, canvas, MouseEvent.BUTTON1_MASK | MouseEvent.CTRL_MASK)); setBorder(BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "Network topology")); // setAllowLoadTrafficDemand(callback.allowLoadTrafficDemands()); }
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//from www.ja v a2s . c o 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:pl.otros.vfs.browser.VfsBrowser.java
License:asdf
private void initGui(final String initialPath) { this.setLayout(new BorderLayout()); JLabel pathLabel = new JLabel(Messages.getMessage("browser.location")); pathLabel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); pathField = new JTextField(80); pathField.setFont(pathLabel.getFont().deriveFont(pathLabel.getFont().getSize() * 1.2f)); pathField.setToolTipText(Messages.getMessage("nav.pathTooltip")); GuiUtils.addBlinkOnFocusGain(pathField); pathLabel.setLabelFor(pathField);// w w w.ja va2s . c o m pathLabel.setDisplayedMnemonic(Messages.getMessage("browser.location.mnemonic").charAt(0)); InputMap inputMapPath = pathField.getInputMap(JComponent.WHEN_FOCUSED); inputMapPath.put(KeyStroke.getKeyStroke("ENTER"), "OPEN_PATH"); inputMapPath.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE); pathField.getActionMap().put("OPEN_PATH", new BaseNavigateAction(this) { @Override protected void performLongOperation(CheckBeforeActionResult actionResult) { try { FileObject resolveFile = VFSUtils.resolveFileObject(pathField.getText().trim()); if (resolveFile != null && resolveFile.getType() == FileType.FILE) { loadAndSelSingleFile(resolveFile); pathField.setText(resolveFile.getURL().toString()); actionApproveDelegate.actionPerformed( // TODO: Does actionResult provide an ID for 2nd param here, // or should use a Random number? new ActionEvent(actionResult, (int) new java.util.Date().getTime(), "SELECTED_FILE")); return; } } catch (FileSystemException fse) { // Intentionally empty } goToUrl(pathField.getText().trim()); } @Override protected boolean canGoUrl() { return true; } @Override protected boolean canExecuteDefaultAction() { return false; } }); actionFocusOnTable = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { tableFiles.requestFocusInWindow(); if (tableFiles.getSelectedRow() < 0 && tableFiles.getRowCount() == 0) { tableFiles.getSelectionModel().setSelectionInterval(0, 0); } } }; pathField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable); BaseNavigateActionGoUp goUpAction = new BaseNavigateActionGoUp(this); goUpButton = new JButton(goUpAction); BaseNavigateActionRefresh refreshAction = new BaseNavigateActionRefresh(this); JButton refreshButton = new JButton(refreshAction); JToolBar upperPanel = new JToolBar(Messages.getMessage("nav.ToolBarName")); upperPanel.setRollover(true); upperPanel.add(pathLabel); upperPanel.add(pathField, "growx"); upperPanel.add(goUpButton); upperPanel.add(refreshButton); AddCurrentLocationToFavoriteAction addCurrentLocationToFavoriteAction = new AddCurrentLocationToFavoriteAction( this); JButton addCurrentLocationToFavoriteButton = new JButton(addCurrentLocationToFavoriteAction); addCurrentLocationToFavoriteButton.setText(""); upperPanel.add(addCurrentLocationToFavoriteButton); previewComponent = new PreviewComponent(); vfsTableModel = new VfsTableModel(); tableFiles = new JTable(vfsTableModel); tableFiles.setFillsViewportHeight(true); tableFiles.getColumnModel().getColumn(0).setMinWidth(140); tableFiles.getColumnModel().getColumn(1).setMaxWidth(80); tableFiles.getColumnModel().getColumn(2).setMaxWidth(80); tableFiles.getColumnModel().getColumn(3).setMaxWidth(180); tableFiles.getColumnModel().getColumn(3).setMinWidth(120); sorter = new TableRowSorter<VfsTableModel>(vfsTableModel); final FileNameWithTypeComparator fileNameWithTypeComparator = new FileNameWithTypeComparator(); sorter.addRowSorterListener(new RowSorterListener() { @Override public void sorterChanged(RowSorterEvent e) { RowSorterEvent.Type type = e.getType(); if (type.equals(RowSorterEvent.Type.SORT_ORDER_CHANGED)) { List<? extends RowSorter.SortKey> sortKeys = e.getSource().getSortKeys(); for (RowSorter.SortKey sortKey : sortKeys) { if (sortKey.getColumn() == VfsTableModel.COLUMN_NAME) { fileNameWithTypeComparator.setSortOrder(sortKey.getSortOrder()); } } } } }); sorter.setComparator(VfsTableModel.COLUMN_NAME, fileNameWithTypeComparator); tableFiles.setRowSorter(sorter); tableFiles.setShowGrid(false); tableFiles.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { try { selectionChanged(); } catch (FileSystemException e1) { LOGGER.error("Error during update state", e); } } }); tableFiles.setColumnSelectionAllowed(false); vfsTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { updateStatusText(); } }); tableFiles.setDefaultRenderer(FileSize.class, new FileSizeTableCellRenderer()); tableFiles.setDefaultRenderer(FileNameWithType.class, new FileNameWithTypeTableCellRenderer()); tableFiles.setDefaultRenderer(Date.class, new MixedDateTableCellRenderer()); tableFiles.setDefaultRenderer(FileType.class, new FileTypeTableCellRenderer()); tableFiles.getSelectionModel().addListSelectionListener(new PreviewListener(this, previewComponent)); JPanel favoritesPanel = new JPanel(new MigLayout("wrap, fillx", "[grow]")); favoritesUserListModel = new MutableListModel<Favorite>(); List<Favorite> favSystemLocations = FavoritesUtils.getSystemLocations(); List<Favorite> favUser = FavoritesUtils.loadFromProperties(configuration); List<Favorite> favJVfsFileChooser = FavoritesUtils.getJvfsFileChooserBookmarks(); for (Favorite favorite : favUser) { favoritesUserListModel.add(favorite); } favoritesUserListModel.addListDataListener(new ListDataListener() { @Override public void intervalAdded(ListDataEvent e) { saveFavorites(); } @Override public void intervalRemoved(ListDataEvent e) { saveFavorites(); } @Override public void contentsChanged(ListDataEvent e) { saveFavorites(); } protected void saveFavorites() { FavoritesUtils.storeFavorites(configuration, favoritesUserListModel.getList()); } }); favoritesUserList = new JList(favoritesUserListModel); favoritesUserList.setTransferHandler(new MutableListDropHandler(favoritesUserList)); new MutableListDragListener(favoritesUserList); favoritesUserList.setCellRenderer(new FavoriteListCellRenderer()); favoritesUserList.addFocusListener(new SelectFirstElementFocusAdapter()); addOpenActionToList(favoritesUserList); addEditActionToList(favoritesUserList, favoritesUserListModel); favoritesUserList.getActionMap().put(ACTION_DELETE, new AbstractAction( Messages.getMessage("favorites.deleteButtonText"), Icons.getInstance().getMinusButton()) { @Override public void actionPerformed(ActionEvent e) { Favorite favorite = favoritesUserListModel.getElementAt(favoritesUserList.getSelectedIndex()); if (!Favorite.Type.USER.equals(favorite.getType())) { return; } int response = JOptionPane.showConfirmDialog(VfsBrowser.this, Messages.getMessage("favorites.areYouSureToDeleteConnections"), Messages.getMessage("favorites.confirm"), JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { favoritesUserListModel.remove(favoritesUserList.getSelectedIndex()); } } }); InputMap favoritesListInputMap = favoritesUserList.getInputMap(JComponent.WHEN_FOCUSED); favoritesListInputMap.put(KeyStroke.getKeyStroke("DELETE"), ACTION_DELETE); ActionMap actionMap = tableFiles.getActionMap(); actionMap.put(ACTION_OPEN, new BaseNavigateActionOpen(this)); actionMap.put(ACTION_GO_UP, goUpAction); actionMap.put(ACTION_APPROVE, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (actionApproveButton.isEnabled()) { actionApproveDelegate.actionPerformed(e); } } }); InputMap inputMap = tableFiles.getInputMap(JComponent.WHEN_FOCUSED); inputMap.put(KeyStroke.getKeyStroke("ENTER"), ACTION_OPEN); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.CTRL_MASK), ACTION_APPROVE); inputMap.put(KeyStroke.getKeyStroke("BACK_SPACE"), ACTION_GO_UP); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), ACTION_GO_UP); addPopupMenu(favoritesUserList, ACTION_OPEN, ACTION_EDIT, ACTION_DELETE); JList favoriteSystemList = new JList(new Vector<Object>(favSystemLocations)); favoriteSystemList.setCellRenderer(new FavoriteListCellRenderer()); addOpenActionToList(favoriteSystemList); addPopupMenu(favoriteSystemList, ACTION_OPEN); favoriteSystemList.addFocusListener(new SelectFirstElementFocusAdapter()); JList favoriteJVfsList = new JList(new Vector<Object>(favJVfsFileChooser)); addOpenActionToList(favoriteJVfsList); favoriteJVfsList.setCellRenderer(new FavoriteListCellRenderer()); addPopupMenu(favoriteJVfsList, ACTION_OPEN); favoriteJVfsList.addFocusListener(new SelectFirstElementFocusAdapter()); JLabel favoritesSystemLocationsLabel = getTitleListLabel(Messages.getMessage("favorites.systemLocations"), COMPUTER_ICON); favoritesSystemLocationsLabel.setLabelFor(favoriteSystemList); favoritesSystemLocationsLabel .setDisplayedMnemonic(Messages.getMessage("favorites.systemLocations.mnemonic").charAt(0)); favoritesPanel.add(favoritesSystemLocationsLabel, "gapleft 16"); favoritesPanel.add(favoriteSystemList, "growx"); JLabel favoritesFavoritesLabel = getTitleListLabel(Messages.getMessage("favorites.favorites"), Icons.getInstance().getStar()); favoritesFavoritesLabel.setLabelFor(favoritesUserList); favoritesFavoritesLabel.setDisplayedMnemonic(Messages.getMessage("favorites.favorites.mnemonic").charAt(0)); favoritesPanel.add(favoritesFavoritesLabel, "gapleft 16"); favoritesPanel.add(favoritesUserList, "growx"); if (favoriteJVfsList.getModel().getSize() > 0) { JLabel favoritesJVfsFileChooser = getTitleListLabel( Messages.getMessage("favorites.JVfsFileChooserBookmarks"), null); favoritesJVfsFileChooser.setDisplayedMnemonic( Messages.getMessage("favorites.JVfsFileChooserBookmarks.mnemonic").charAt(0)); favoritesJVfsFileChooser.setLabelFor(favoriteJVfsList); favoritesPanel.add(favoritesJVfsFileChooser, "gapleft 16"); favoritesPanel.add(favoriteJVfsList, "growx"); } tableFiles.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) { tableFiles.getActionMap().get(ACTION_OPEN).actionPerformed(null); } } }); tableFiles.addKeyListener(new QuickSearchKeyAdapter()); cardLayout = new CardLayout(); tablePanel = new JPanel(cardLayout); loadingProgressBar = new JProgressBar(); loadingProgressBar.setStringPainted(true); loadingProgressBar.setString(Messages.getMessage("browser.loading")); loadingProgressBar.setIndeterminate(true); loadingIconLabel = new JLabel(Icons.getInstance().getNetworkStatusOnline()); skipCheckingLinksButton = new JToggleButton(Messages.getMessage("browser.skipCheckingLinks")); skipCheckingLinksButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (taskContext != null) { taskContext.setStop(skipCheckingLinksButton.isSelected()); } } }); showHidCheckBox = new JCheckBox(Messages.getMessage("browser.showHidden.label"), showHidden); showHidCheckBox.setToolTipText(Messages.getMessage("browser.showHidden.tooltip")); showHidCheckBox.setMnemonic(Messages.getMessage("browser.showHidden.mnemonic").charAt(0)); Font tmpFont = showHidCheckBox.getFont(); showHidCheckBox.setFont(tmpFont.deriveFont(tmpFont.getSize() * 0.9f)); showHidCheckBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { updateUiFilters(); } }); final String defaultFilterText = Messages.getMessage("browser.nameFilter.defaultText"); filterField = new JTextField("", 16); filterField.setForeground(filterField.getDisabledTextColor()); filterField.setToolTipText(Messages.getMessage("browser.nameFilter.tooltip")); PromptSupport.setPrompt(defaultFilterText, filterField); filterField.getDocument().addDocumentListener(new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) { documentChanged(); } void documentChanged() { if (filterField.getText().length() == 0) { updateUiFilters(); } } @Override public void removeUpdate(DocumentEvent e) { documentChanged(); } @Override public void changedUpdate(DocumentEvent e) { documentChanged(); } }); filterField.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { updateUiFilters(); } }); AbstractAction actionClearRegexFilter = new AbstractAction(Messages.getMessage("browser.nameFilter.clearFilterText")) { @Override public void actionPerformed(ActionEvent e) { filterField.setText(""); } }; filterField.getActionMap().put(ACTION_FOCUS_ON_TABLE, actionFocusOnTable); filterField.getActionMap().put(ACTION_CLEAR_REGEX_FILTER, actionClearRegexFilter); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke("ENTER"), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ACTION_FOCUS_ON_TABLE); filterField.getInputMap(WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), ACTION_CLEAR_REGEX_FILTER); JLabel nameFilterLabel = new JLabel(Messages.getMessage("browser.nameFilter")); nameFilterLabel.setLabelFor(filterField); nameFilterLabel.setDisplayedMnemonic(Messages.getMessage("browser.nameFilter.mnemonic").charAt(0)); sorter.setRowFilter(createFilter()); statusLabel = new JLabel(); actionApproveButton = new JButton(); actionApproveButton.setFont(actionApproveButton.getFont().deriveFont(Font.BOLD)); actionCancelButton = new JButton(); ActionMap browserActionMap = this.getActionMap(); browserActionMap.put(ACTION_FOCUS_ON_REGEX_FILTER, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { filterField.requestFocus(); filterField.selectAll(); GuiUtils.blinkComponent(filterField); } }); browserActionMap.put(ACTION_FOCUS_ON_PATH, new SetFocusOnAction(pathField)); browserActionMap.put(ACTION_SWITCH_SHOW_HIDDEN, new ClickOnJComponentAction(showHidCheckBox)); browserActionMap.put(ACTION_REFRESH, refreshAction); browserActionMap.put(ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES, addCurrentLocationToFavoriteAction); browserActionMap.put(ACTION_GO_UP, goUpAction); browserActionMap.put(ACTION_FOCUS_ON_TABLE, new SetFocusOnAction(tableFiles)); InputMap browserInputMap = this.getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); browserInputMap.put(KeyStroke.getKeyStroke("control F"), ACTION_FOCUS_ON_REGEX_FILTER); browserInputMap.put(KeyStroke.getKeyStroke("control L"), ACTION_FOCUS_ON_PATH); browserInputMap.put(KeyStroke.getKeyStroke("F4"), ACTION_FOCUS_ON_PATH); browserInputMap.put(KeyStroke.getKeyStroke("control H"), ACTION_SWITCH_SHOW_HIDDEN); browserInputMap.put(KeyStroke.getKeyStroke("control R"), ACTION_REFRESH); browserInputMap.put(KeyStroke.getKeyStroke("F5"), ACTION_REFRESH); browserInputMap.put(KeyStroke.getKeyStroke("control D"), ACTION_ADD_CURRENT_LOCATION_TO_FAVORITES); browserInputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK), ACTION_GO_UP); browserInputMap.put(KeyStroke.getKeyStroke("control T"), ACTION_FOCUS_ON_TABLE); //DO layout // create the layer for the panel using our custom layerUI tableScrollPane = new JScrollPane(tableFiles); JPanel tableScrollPaneWithFilter = new JPanel(new BorderLayout()); tableScrollPaneWithFilter.add(tableScrollPane); JToolBar filtersToolbar = new JToolBar("Filters"); filtersToolbar.setFloatable(false); filtersToolbar.setBorderPainted(true); tableScrollPaneWithFilter.add(filtersToolbar, BorderLayout.SOUTH); filtersToolbar.add(nameFilterLabel); filtersToolbar.add(filterField); filtersToolbar.add(showHidCheckBox); JSplitPane tableWithPreviewPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, tableScrollPaneWithFilter, previewComponent); tableWithPreviewPane.setOneTouchExpandable(true); JPanel loadingPanel = new JPanel(new MigLayout()); loadingPanel.add(loadingIconLabel, "right"); loadingPanel.add(loadingProgressBar, "left, w 420:420:500,wrap"); loadingPanel.add(skipCheckingLinksButton, "span, right"); tablePanel.add(loadingPanel, LOADING); tablePanel.add(tableWithPreviewPane, TABLE); JSplitPane jSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(favoritesPanel), tablePanel); jSplitPane.setOneTouchExpandable(true); jSplitPane.setDividerLocation(180); JPanel southPanel = new JPanel(new MigLayout("", "[]push[][]", "")); southPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); southPanel.add(statusLabel); southPanel.add(actionApproveButton); southPanel.add(actionCancelButton); this.add(upperPanel, BorderLayout.NORTH); this.add(jSplitPane, BorderLayout.CENTER); this.add(southPanel, BorderLayout.SOUTH); try { selectionChanged(); } catch (FileSystemException e) { LOGGER.error("Can't initialize default selection mode", e); } // Why this not done in EDT? // Is it assume that constructor is invoked from an EDT? try { if (initialPath == null) { goToUrl(VFSUtils.getUserHome()); } else { try { FileObject resolveFile = VFSUtils.resolveFileObject(initialPath); if (resolveFile != null && resolveFile.getType() == FileType.FILE) { loadAndSelSingleFile(resolveFile); pathField.setText(resolveFile.getURL().toString()); targetFileSelected = true; return; } } catch (FileSystemException fse) { // Intentionally empty } goToUrl(initialPath); } } catch (FileSystemException e1) { LOGGER.error("Can't initialize default location", e1); } showTable(); }
From source file:ro.nextreports.designer.querybuilder.QueryBuilderPanel.java
private void initUI() { JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.setDividerLocation(250);/*from w w w . jav a 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();// w w w .j a v a 2s. co 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); }