List of usage examples for java.awt GridBagConstraints CENTER
int CENTER
To view the source code for java.awt GridBagConstraints CENTER.
Click Source Link
From source file:VASSAL.launch.ModuleManagerWindow.java
public ModuleManagerWindow() { setTitle("VASSAL"); setLayout(new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); ApplicationIcons.setFor(this); final AbstractAction shutDownAction = new AbstractAction() { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { if (!AbstractLaunchAction.shutDown()) return; final Prefs gl = Prefs.getGlobalPrefs(); try { gl.write();//from w w w. j a v a 2s. c om gl.close(); } catch (IOException ex) { WriteErrorDialog.error(ex, gl.getFile()); } finally { IOUtils.closeQuietly(gl); } logger.info("Exiting"); System.exit(0); } }; shutDownAction.putValue(Action.NAME, Resources.getString(Resources.QUIT)); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { shutDownAction.actionPerformed(null); } }); // setup menubar and actions final MenuManager mm = MenuManager.getInstance(); final MenuBarProxy mb = mm.getMenuBarProxyFor(this); // file menu final MenuProxy fileMenu = new MenuProxy(Resources.getString("General.file")); fileMenu.setMnemonic(Resources.getString("General.file.shortcut").charAt(0)); fileMenu.add(mm.addKey("Main.play_module")); fileMenu.add(mm.addKey("Main.edit_module")); fileMenu.add(mm.addKey("Main.new_module")); fileMenu.add(mm.addKey("Main.import_module")); fileMenu.addSeparator(); if (!SystemUtils.IS_OS_MAC_OSX) { fileMenu.add(mm.addKey("Prefs.edit_preferences")); fileMenu.addSeparator(); fileMenu.add(mm.addKey("General.quit")); } // tools menu final MenuProxy toolsMenu = new MenuProxy(Resources.getString("General.tools")); // Initialize Global Preferences Prefs.getGlobalPrefs().getEditor().initDialog(this); Prefs.initSharedGlobalPrefs(); final BooleanConfigurer serverStatusConfig = new BooleanConfigurer(SHOW_STATUS_KEY, null, Boolean.FALSE); Prefs.getGlobalPrefs().addOption(null, serverStatusConfig); dividerLocationConfig = new IntConfigurer(DIVIDER_LOCATION_KEY, null, -10); Prefs.getGlobalPrefs().addOption(null, dividerLocationConfig); toolsMenu.add(new CheckBoxMenuItemProxy(new AbstractAction(Resources.getString("Chat.server_status")) { private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent e) { serverStatusView.toggleVisibility(); serverStatusConfig.setValue(serverStatusConfig.booleanValue() ? Boolean.FALSE : Boolean.TRUE); if (serverStatusView.isVisible()) { setDividerLocation(getPreferredDividerLocation()); } } }, serverStatusConfig.booleanValue())); // help menu final MenuProxy helpMenu = new MenuProxy(Resources.getString("General.help")); helpMenu.setMnemonic(Resources.getString("General.help.shortcut").charAt(0)); helpMenu.add(mm.addKey("General.help")); helpMenu.add(mm.addKey("Main.tour")); helpMenu.addSeparator(); helpMenu.add(mm.addKey("UpdateCheckAction.update_check")); helpMenu.add(mm.addKey("Help.error_log")); if (!SystemUtils.IS_OS_MAC_OSX) { helpMenu.addSeparator(); helpMenu.add(mm.addKey("AboutScreen.about_vassal")); } mb.add(fileMenu); mb.add(toolsMenu); mb.add(helpMenu); // add actions mm.addAction("Main.play_module", new Player.PromptLaunchAction(this)); mm.addAction("Main.edit_module", new Editor.PromptLaunchAction(this)); mm.addAction("Main.new_module", new Editor.NewModuleLaunchAction(this)); mm.addAction("Main.import_module", new Editor.PromptImportLaunchAction(this)); mm.addAction("Prefs.edit_preferences", Prefs.getGlobalPrefs().getEditor().getEditAction()); mm.addAction("General.quit", shutDownAction); URL url = null; try { url = new File(Documentation.getDocumentationBaseDir(), "README.html").toURI().toURL(); } catch (MalformedURLException e) { ErrorDialog.bug(e); } mm.addAction("General.help", new ShowHelpAction(url, null)); mm.addAction("Main.tour", new LaunchTourAction(this)); mm.addAction("AboutScreen.about_vassal", new AboutVASSALAction(this)); mm.addAction("UpdateCheckAction.update_check", new UpdateCheckAction(this)); mm.addAction("Help.error_log", new ShowErrorLogAction(this)); setJMenuBar(mm.getMenuBarFor(this)); // Load Icons moduleIcon = new ImageIcon(getClass().getResource("/images/mm-module.png")); activeExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-active.png")); inactiveExtensionIcon = new ImageIcon(getClass().getResource("/images/mm-extension-inactive.png")); openGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-open.png")); closedGameFolderIcon = new ImageIcon(getClass().getResource("/images/mm-gamefolder-closed.png")); fileIcon = new ImageIcon(getClass().getResource("/images/mm-file.png")); // build module controls final JPanel moduleControls = new JPanel(new BorderLayout()); modulePanelLayout = new CardLayout(); moduleView = new JPanel(modulePanelLayout); buildTree(); final JScrollPane scroll = new JScrollPane(tree); moduleView.add(scroll, "modules"); final JEditorPane l = new JEditorPane("text/html", Resources.getString("ModuleManager.quickstart")); l.setEditable(false); // Try to get background color and font from LookAndFeel; // otherwise, use dummy JLabel to get color and font. Color bg = UIManager.getColor("control"); Font font = UIManager.getFont("Label.font"); if (bg == null || font == null) { final JLabel dummy = new JLabel(); if (bg == null) bg = dummy.getBackground(); if (font == null) font = dummy.getFont(); } l.setBackground(bg); ((HTMLEditorKit) l.getEditorKit()).getStyleSheet() .addRule("body { font: " + font.getFamily() + " " + font.getSize() + "pt }"); l.addHyperlinkListener(BrowserSupport.getListener()); // FIXME: use MigLayout for this! // this is necessary to get proper vertical alignment final JPanel p = new JPanel(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.CENTER; p.add(l, c); moduleView.add(p, "quickStart"); modulePanelLayout.show(moduleView, getModuleCount() == 0 ? "quickStart" : "modules"); moduleControls.add(moduleView, BorderLayout.CENTER); moduleControls.setBorder(new TitledBorder(Resources.getString("ModuleManager.recent_modules"))); add(moduleControls); // build server status controls final ServerStatusView serverStatusControls = new ServerStatusView(new CgiServerStatus()); serverStatusControls.setBorder(new TitledBorder(Resources.getString("Chat.server_status"))); serverStatusView = new ComponentSplitter().splitRight(moduleControls, serverStatusControls, false); serverStatusView.revalidate(); // show the server status controls according to the prefs if (serverStatusConfig.booleanValue()) { serverStatusView.showComponent(); } setDividerLocation(getPreferredDividerLocation()); serverStatusView.addPropertyChangeListener("dividerLocation", new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent e) { setPreferredDividerLocation((Integer) e.getNewValue()); } }); final Rectangle r = Info.getScreenBounds(this); serverStatusControls.setPreferredSize(new Dimension((int) (r.width / 3.5), 0)); setSize(3 * r.width / 4, 3 * r.height / 4); // Save/load the window position and size in prefs final PositionOption option = new PositionOption(PositionOption.key + "ModuleManager", this); Prefs.getGlobalPrefs().addOption(option); }
From source file:erigo.filepump.FilePump.java
private void createAndShowGUI(String default_outputFolderI, double default_filesPerSecI, int default_totNumFilesI, FileMode default_modeI, String default_ftpHostI, String default_ftpUserI, String default_ftpPasswordI) { // Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); // Create the GUI components GridBagLayout framegbl = new GridBagLayout(); filePumpGuiFrame = new JFrame("FilePump"); GridBagLayout gbl = new GridBagLayout(); JPanel guiPanel = new JPanel(gbl); outputFolderLabel = new JLabel(" "); Dimension preferredSize = new Dimension(200, 20); outputFolderLabel.setPreferredSize(preferredSize); filesPerSecLabel = new JLabel("1"); totNumFilesLabel = new JLabel("unlimited"); modeLabel = new JLabel("file system folder"); fileCountLabel = new JLabel("0"); endButton = new JButton("Finish test"); endButton.addActionListener(this); actionButton = new JButton("Start pump"); actionButton.setBackground(Color.GREEN); actionButton.addActionListener(this); filePumpGuiFrame.setFont(new Font("Dialog", Font.PLAIN, 12)); guiPanel.setFont(new Font("Dialog", Font.PLAIN, 12)); int row = 0;/*from w ww .j a va 2s. c o m*/ GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.WEST; gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; gbc.weighty = 0; // ROW 1 JLabel label = new JLabel("Output directory"); gbc.insets = new Insets(15, 15, 0, 5); Utility.add(guiPanel, label, gbl, gbc, 0, row, 1, 1); gbc.insets = new Insets(15, 0, 0, 15); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 100; gbc.weighty = 100; Utility.add(guiPanel, outputFolderLabel, gbl, gbc, 1, row, 1, 1); gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; gbc.weighty = 0; ++row; // ROW 2 label = new JLabel("Files/sec"); gbc.insets = new Insets(15, 15, 0, 5); Utility.add(guiPanel, label, gbl, gbc, 0, row, 1, 1); gbc.insets = new Insets(15, 0, 0, 15); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 100; gbc.weighty = 100; Utility.add(guiPanel, filesPerSecLabel, gbl, gbc, 1, row, 1, 1); gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; gbc.weighty = 0; ++row; // ROW 3 label = new JLabel("Tot num files"); gbc.insets = new Insets(15, 15, 0, 5); Utility.add(guiPanel, label, gbl, gbc, 0, row, 1, 1); gbc.insets = new Insets(15, 0, 0, 15); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 100; gbc.weighty = 100; Utility.add(guiPanel, totNumFilesLabel, gbl, gbc, 1, row, 1, 1); gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; gbc.weighty = 0; ++row; // ROW 4 label = new JLabel("Mode"); gbc.insets = new Insets(15, 15, 0, 5); Utility.add(guiPanel, label, gbl, gbc, 0, row, 1, 1); gbc.insets = new Insets(15, 0, 0, 15); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 100; gbc.weighty = 100; Utility.add(guiPanel, modeLabel, gbl, gbc, 1, row, 1, 1); gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; gbc.weighty = 0; ++row; // ROW 5 label = new JLabel("File count"); gbc.insets = new Insets(15, 15, 0, 5); Utility.add(guiPanel, label, gbl, gbc, 0, row, 1, 1); gbc.insets = new Insets(15, 0, 0, 15); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 100; gbc.weighty = 100; Utility.add(guiPanel, fileCountLabel, gbl, gbc, 1, row, 1, 1); gbc.fill = GridBagConstraints.NONE; gbc.weightx = 0; gbc.weighty = 0; ++row; // ROW 6: command buttons JPanel buttonPanel = new JPanel(); buttonPanel.add(actionButton); buttonPanel.add(endButton); gbc.insets = new Insets(15, 15, 15, 15); gbc.anchor = GridBagConstraints.CENTER; Utility.add(guiPanel, buttonPanel, gbl, gbc, 0, row, 2, 1); gbc.anchor = GridBagConstraints.WEST; ++row; // Now add guiPanel to filePumpGuiFrame gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.BOTH; gbc.weightx = 100; gbc.weighty = 100; gbc.insets = new Insets(0, 0, 0, 0); Utility.add(filePumpGuiFrame, guiPanel, framegbl, gbc, 0, 0, 1, 1); // Add menu JMenuBar menuBar = createMenu(); filePumpGuiFrame.setJMenuBar(menuBar); // Display the window. filePumpGuiFrame.pack(); filePumpGuiFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); filePumpGuiFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { exit(); } }); // Create a settings dialog box pumpSettings = new FilePumpSettings(filePumpGuiFrame, default_outputFolderI, default_filesPerSecI, default_totNumFilesI, default_modeI, default_ftpHostI, default_ftpUserI, default_ftpPasswordI); // Initialize information displayed on the GUI front panel updateMainFrame(); filePumpGuiFrame.setVisible(true); }
From source file:cool.pandora.modeller.ui.jpanel.base.SaveBagFrame.java
private JPanel createComponents() { final Border border = new EmptyBorder(5, 5, 5, 5); final TitlePane titlePane = new TitlePane(); initStandardCommands();/* www .jav a 2 s . c o m*/ final JPanel pageControl = new JPanel(new BorderLayout()); final JPanel titlePaneContainer = new JPanel(new BorderLayout()); titlePane.setTitle(bagView.getPropertyMessage("SaveBagFrame.title")); titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("Define the Bag " + "settings"))); titlePaneContainer.add(titlePane.getControl()); titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH); pageControl.add(titlePaneContainer, BorderLayout.NORTH); final JPanel contentPane = new JPanel(); // TODO: Add bag name field // TODO: Add save name file selection button final JLabel location = new JLabel("Save in:"); final JButton browseButton = new JButton(getMessage("bag.button.browse")); browseButton.addActionListener(new SaveBagAsHandler()); browseButton.setEnabled(true); browseButton.setToolTipText(getMessage("bag.button.browse.help")); final DefaultBag bag = bagView.getBag(); if (bag != null) { bagNameField = new JTextField(bag.getName()); bagNameField.setCaretPosition(bag.getName().length()); bagNameField.setEditable(false); bagNameField.setEnabled(false); } // Holey bag control final JLabel holeyLabel = new JLabel(bagView.getPropertyMessage("bag.label.isholey")); holeyLabel.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); final JCheckBox holeyCheckbox = new JCheckBox(bagView.getPropertyMessage("bag.checkbox" + ".isholey")); holeyCheckbox.setBorder(border); holeyCheckbox.addActionListener(new HoleyBagHandler()); holeyCheckbox.setToolTipText(bagView.getPropertyMessage("bag.isholey.help")); urlLabel = new JLabel(bagView.getPropertyMessage("baseURL.label")); urlLabel.setToolTipText(bagView.getPropertyMessage("baseURL.description")); urlField = new JTextField(""); try { assert bag != null; urlField.setText(bag.getFetch().getBaseURL()); } catch (Exception e) { log.error("Failed to set url label", e); } urlField.setEnabled(false); // TODO: Add format label final JLabel serializeLabel; serializeLabel = new JLabel(getMessage("bag.label.ispackage")); serializeLabel.setToolTipText(getMessage("bag.serializetype.help")); // TODO: Add format selection panel noneButton = new JRadioButton(getMessage("bag.serializetype.none")); noneButton.setEnabled(true); final AbstractAction serializeListener = new SerializeBagHandler(); noneButton.addActionListener(serializeListener); noneButton.setToolTipText(getMessage("bag.serializetype.none.help")); zipButton = new JRadioButton(getMessage("bag.serializetype.zip")); zipButton.setEnabled(true); zipButton.addActionListener(serializeListener); zipButton.setToolTipText(getMessage("bag.serializetype.zip.help")); /* * tarButton = new JRadioButton(getMessage("bag.serializetype.tar")); * tarButton.setEnabled(true); * tarButton.addActionListener(serializeListener); * tarButton.setToolTipText(getMessage("bag.serializetype.tar.help")); * * tarGzButton = new JRadioButton(getMessage("bag.serializetype.targz")); * tarGzButton.setEnabled(true); * tarGzButton.addActionListener(serializeListener); * tarGzButton.setToolTipText(getMessage("bag.serializetype.targz.help")); * * tarBz2Button = new JRadioButton(getMessage("bag.serializetype.tarbz2")); * tarBz2Button.setEnabled(true); * tarBz2Button.addActionListener(serializeListener); * tarBz2Button.setToolTipText(getMessage("bag.serializetype.tarbz2.help")); */ short mode = 2; if (bag != null) { mode = bag.getSerialMode(); } if (mode == DefaultBag.NO_MODE) { this.noneButton.setEnabled(true); } else if (mode == DefaultBag.ZIP_MODE) { this.zipButton.setEnabled(true); } else { this.noneButton.setEnabled(true); } final ButtonGroup serializeGroup = new ButtonGroup(); serializeGroup.add(noneButton); serializeGroup.add(zipButton); // serializeGroup.add(tarButton); // serializeGroup.add(tarGzButton); // serializeGroup.add(tarBz2Button); final JPanel serializeGroupPanel = new JPanel(new FlowLayout()); serializeGroupPanel.add(serializeLabel); serializeGroupPanel.add(noneButton); serializeGroupPanel.add(zipButton); // serializeGroupPanel.add(tarButton); // serializeGroupPanel.add(tarGzButton); // serializeGroupPanel.add(tarBz2Button); serializeGroupPanel.setBorder(border); serializeGroupPanel.setEnabled(true); serializeGroupPanel.setToolTipText(bagView.getPropertyMessage("bag.serializetype.help")); final JLabel tagLabel = new JLabel(getMessage("bag.label.istag")); tagLabel.setToolTipText(getMessage("bag.label.istag.help")); final JCheckBox isTagCheckbox = new JCheckBox(); isTagCheckbox.setBorder(border); isTagCheckbox.addActionListener(new TagManifestHandler()); isTagCheckbox.setToolTipText(getMessage("bag.checkbox.istag.help")); final JLabel tagAlgorithmLabel = new JLabel(getMessage("bag.label.tagalgorithm")); tagAlgorithmLabel.setToolTipText(getMessage("bag.label.tagalgorithm.help")); final ArrayList<String> listModel = new ArrayList<>(); for (final Algorithm algorithm : Algorithm.values()) { listModel.add(algorithm.bagItAlgorithm); } final JComboBox<String> tagAlgorithmList = new JComboBox<>(listModel.toArray(new String[listModel.size()])); tagAlgorithmList.setName(getMessage("bag.tagalgorithmlist")); tagAlgorithmList.addActionListener(new TagAlgorithmListHandler()); tagAlgorithmList.setToolTipText(getMessage("bag.tagalgorithmlist.help")); final JLabel payloadLabel = new JLabel(getMessage("bag.label.ispayload")); payloadLabel.setToolTipText(getMessage("bag.ispayload.help")); final JCheckBox isPayloadCheckbox = new JCheckBox(); isPayloadCheckbox.setBorder(border); isPayloadCheckbox.addActionListener(new PayloadManifestHandler()); isPayloadCheckbox.setToolTipText(getMessage("bag.ispayload.help")); final JLabel payAlgorithmLabel = new JLabel(bagView.getPropertyMessage("bag.label" + ".payalgorithm")); payAlgorithmLabel.setToolTipText(getMessage("bag.payalgorithm.help")); final JComboBox<String> payAlgorithmList = new JComboBox<String>( listModel.toArray(new String[listModel.size()])); payAlgorithmList.setName(getMessage("bag.payalgorithmlist")); payAlgorithmList.addActionListener(new PayAlgorithmListHandler()); payAlgorithmList.setToolTipText(getMessage("bag.payalgorithmlist.help")); //only if bag is not null if (bag != null) { final String fileName = bag.getName(); bagNameField = new JTextField(fileName); bagNameField.setCaretPosition(fileName.length()); holeyCheckbox.setSelected(bag.isHoley()); urlLabel.setEnabled(bag.isHoley()); isTagCheckbox.setSelected(bag.isBuildTagManifest()); tagAlgorithmList.setSelectedItem(bag.getTagManifestAlgorithm()); isPayloadCheckbox.setSelected(bag.isBuildPayloadManifest()); payAlgorithmList.setSelectedItem(bag.getPayloadManifestAlgorithm()); } final GridBagLayout layout = new GridBagLayout(); final GridBagConstraints glbc = new GridBagConstraints(); final JPanel panel = new JPanel(layout); panel.setBorder(new EmptyBorder(10, 10, 10, 10)); int row = 0; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(location, glbc); panel.add(location); buildConstraints(glbc, 2, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.EAST); glbc.ipadx = 5; layout.setConstraints(browseButton, glbc); glbc.ipadx = 0; panel.add(browseButton); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); glbc.ipadx = 5; layout.setConstraints(bagNameField, glbc); glbc.ipadx = 0; panel.add(bagNameField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(holeyLabel, glbc); panel.add(holeyLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.WEST, GridBagConstraints.WEST); layout.setConstraints(holeyCheckbox, glbc); panel.add(holeyCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(urlLabel, glbc); panel.add(urlLabel); buildConstraints(glbc, 1, row, 1, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(urlField, glbc); panel.add(urlField); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(serializeLabel, glbc); panel.add(serializeLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST); layout.setConstraints(serializeGroupPanel, glbc); panel.add(serializeGroupPanel); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagLabel, glbc); panel.add(tagLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isTagCheckbox, glbc); panel.add(isTagCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(tagAlgorithmLabel, glbc); panel.add(tagAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(tagAlgorithmList, glbc); panel.add(tagAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payloadLabel, glbc); panel.add(payloadLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(isPayloadCheckbox, glbc); panel.add(isPayloadCheckbox); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); layout.setConstraints(payAlgorithmLabel, glbc); panel.add(payAlgorithmLabel); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); layout.setConstraints(payAlgorithmList, glbc); panel.add(payAlgorithmList); row++; buildConstraints(glbc, 0, row, 1, 1, 1, 50, GridBagConstraints.NONE, GridBagConstraints.WEST); buildConstraints(glbc, 1, row, 2, 1, 80, 50, GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER); GuiStandardUtils.attachDialogBorder(contentPane); pageControl.add(panel); final JComponent buttonBar = createButtonBar(); pageControl.add(buttonBar, BorderLayout.SOUTH); this.pack(); return pageControl; }
From source file:org.executequery.gui.browser.TableDataTab.java
private void addErrorPanel(StringBuilder sb) { removeAll();/* ww w . j a va 2 s . com*/ JPanel panel = new JPanel(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.CENTER; gbc.insets = new Insets(0, 20, 10, 20); panel.add(new JLabel(sb.toString()), gbc); panel.setBorder(UIUtils.getDefaultLineBorder()); add(panel, errorLabelConstraints); }
From source file:zet.gui.assignmentEditor.JAssignmentPanel.java
/** * Returns the panel on the right side of the {@code JAssignmentPanel} that * contains distributions for all properties and a plot of the distribution * with the current parameters./*from www .j a va 2 s. com*/ * @return the panel on the right side of the {@code JAssignmentPanel} */ private JPanel getRightPanel() { final JPanel rightPanel = new JPanel(new GridBagLayout()); final JPanel tableContainer = new JPanel(new BorderLayout()); tableContainer.add(distributionTable.getTableHeader(), BorderLayout.PAGE_START); tableContainer.add(distributionTable, BorderLayout.CENTER); rightPanel.add(tableContainer, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, new Insets(16, 0, 0, 16), 0, 0)); XYSeriesCollection c = new XYSeriesCollection(); chart = ChartFactory.createXYLineChart(loc.getStringWithoutPrefix("gui.AssignmentEditor.plot.Title"), loc.getStringWithoutPrefix("gui.AssignmentEditor.plot.Values"), // x axis label loc.getStringWithoutPrefix("gui.AssignmentEditor.plot.Probability"), // y axis label c, // Dataset PlotOrientation.VERTICAL, false, true, false // Show legend, tooltips, url ); chartPanel = new ChartPanel(chart); rightPanel.add(chartPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(16, 0, 0, 16), 0, 0)); rightPanel.add(chartPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(16, 0, 0, 16), 0, 0)); return rightPanel; }
From source file:net.technicpack.launcher.ui.InstallerFrame.java
private void setupStandardInstall(JPanel panel) { panel.setLayout(new GridBagLayout()); JLabel standardSpiel = new JLabel("<html><body align=\"left\" style='margin-right:10px;'>" + resources.getString("launcher.installer.standardspiel") + "</body></html>"); standardSpiel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16)); standardSpiel.setForeground(LauncherFrame.COLOR_WHITE_TEXT); standardSpiel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.add(standardSpiel, new GridBagConstraints(0, 0, 3, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(9, 0, 0, 3), 0, 0)); panel.add(Box.createGlue(), new GridBagConstraints(0, 1, 3, 1, 1.0, 0.7, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); standardDefaultDirectory = new JCheckBox(resources.getString("launcher.installer.default")); standardDefaultDirectory.setOpaque(false); standardDefaultDirectory.setHorizontalAlignment(SwingConstants.RIGHT); standardDefaultDirectory.setBorder(BorderFactory.createEmptyBorder()); standardDefaultDirectory.setIconTextGap(0); standardDefaultDirectory.setSelectedIcon(resources.getIcon("checkbox_closed.png")); standardDefaultDirectory.setIcon(resources.getIcon("checkbox_open.png")); standardDefaultDirectory.setFocusPainted(false); standardDefaultDirectory.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 16)); standardDefaultDirectory.setForeground(LauncherFrame.COLOR_WHITE_TEXT); standardDefaultDirectory.setIconTextGap(6); standardDefaultDirectory.setSelected(settings.isPortable() || settings.getTechnicRoot().getAbsolutePath() .equals(SettingsFactory.getTechnicHomeDir().getAbsolutePath())); standardDefaultDirectory.addActionListener(new ActionListener() { @Override/* w ww. j a v a2 s . c o m*/ public void actionPerformed(ActionEvent e) { useDefaultDirectoryChanged(); } }); panel.add(standardDefaultDirectory, new GridBagConstraints(0, 2, 3, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 24, 12, 0), 0, 0)); JLabel installFolderLabel = new JLabel(resources.getString("launcher.installer.folder")); installFolderLabel.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 18)); installFolderLabel.setForeground(LauncherFrame.COLOR_WHITE_TEXT); panel.add(installFolderLabel, new GridBagConstraints(0, 3, 1, 1, 0, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 24, 0, 8), 0, 0)); String installDir = SettingsFactory.getTechnicHomeDir().getAbsolutePath(); if (!settings.isPortable()) installDir = settings.getTechnicRoot().getAbsolutePath(); standardInstallDir = new JTextField(installDir); standardInstallDir.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 18)); standardInstallDir.setBackground(LauncherFrame.COLOR_FORMELEMENT_INTERNAL); standardInstallDir.setHighlighter(null); standardInstallDir.setEditable(false); standardInstallDir.setCursor(null); panel.add(standardInstallDir, new GridBagConstraints(1, 3, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 5), 0, 0)); standardSelectButton = new RoundedButton(resources.getString("launcher.installer.select")); standardSelectButton.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 18)); standardSelectButton.setContentAreaFilled(false); standardSelectButton.setHoverForeground(LauncherFrame.COLOR_BLUE); standardSelectButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { selectStandard(); } }); panel.add(standardSelectButton, new GridBagConstraints(2, 3, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 5, 0, 16), 0, 0)); useDefaultDirectoryChanged(); panel.add(Box.createGlue(), new GridBagConstraints(0, 4, 3, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); String defaultLocaleText = resources.getString("launcheroptions.language.default"); if (!resources.isDefaultLocaleSupported()) { defaultLocaleText = defaultLocaleText .concat(" (" + resources.getString("launcheroptions.language.unavailable") + ")"); } standardLanguages = new JComboBox(); standardLanguages.addItem(new LanguageItem(ResourceLoader.DEFAULT_LOCALE, defaultLocaleText, resources)); for (int i = 0; i < ResourceLoader.SUPPORTED_LOCALES.length; i++) { standardLanguages .addItem(new LanguageItem(resources.getCodeFromLocale(ResourceLoader.SUPPORTED_LOCALES[i]), ResourceLoader.SUPPORTED_LOCALES[i].getDisplayName(ResourceLoader.SUPPORTED_LOCALES[i]), resources.getVariant(ResourceLoader.SUPPORTED_LOCALES[i]))); } if (!settings.getLanguageCode().equalsIgnoreCase(ResourceLoader.DEFAULT_LOCALE)) { Locale loc = resources.getLocaleFromCode(settings.getLanguageCode()); for (int i = 0; i < ResourceLoader.SUPPORTED_LOCALES.length; i++) { if (loc.equals(ResourceLoader.SUPPORTED_LOCALES[i])) { standardLanguages.setSelectedIndex(i + 1); break; } } } standardLanguages.setBorder(new RoundBorder(LauncherFrame.COLOR_SCROLL_THUMB, 1, 10)); standardLanguages.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 14)); standardLanguages.setUI(new LanguageCellUI(resources)); standardLanguages.setForeground(LauncherFrame.COLOR_WHITE_TEXT); standardLanguages.setBackground(LauncherFrame.COLOR_SELECTOR_BACK); standardLanguages.setRenderer(new LanguageCellRenderer(resources, "globe.png", LauncherFrame.COLOR_SELECTOR_BACK, LauncherFrame.COLOR_WHITE_TEXT)); standardLanguages.setEditable(false); standardLanguages.setFocusable(false); standardLanguages.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { standardLanguageChanged(); } }); panel.add(standardLanguages, new GridBagConstraints(0, 5, 1, 0, 0, 0, GridBagConstraints.SOUTHWEST, GridBagConstraints.NONE, new Insets(0, 8, 8, 0), 0, 0)); RoundedButton install = new RoundedButton(resources.getString("launcher.installer.install")); install.setFont(resources.getFont(ResourceLoader.FONT_OPENSANS, 18)); install.setContentAreaFilled(false); install.setForeground(LauncherFrame.COLOR_BUTTON_BLUE); install.setHoverForeground(LauncherFrame.COLOR_BLUE); install.setBorder(BorderFactory.createEmptyBorder(8, 56, 8, 56)); install.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { standardInstall(); } }); panel.add(install, new GridBagConstraints(1, 5, 2, 1, 0, 0, GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 8, 8), 0, 0)); }
From source file:org.esa.snap.rcp.spectrum.SpectrumTopComponent.java
private void initUI() { final JFreeChart chart = ChartFactory.createXYLineChart(Bundle.CTL_SpectrumTopComponent_Name(), "Wavelength (nm)", "", null, PlotOrientation.VERTICAL, true, true, false); chart.getXYPlot().getRangeAxis().addChangeListener(axisChangeEvent -> { if (!isCodeInducedAxisChange) { rangeAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange(); }// w w w . j av a2 s . c om }); chart.getXYPlot().getDomainAxis().addChangeListener(axisChangeEvent -> { if (!isCodeInducedAxisChange) { domainAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange(); } }); chart.getXYPlot().getRangeAxis().setAutoRange(false); rangeAxisAdjustmentIsFrozen = false; chart.getXYPlot().getDomainAxis().setAutoRange(false); domainAxisAdjustmentIsFrozen = false; chartPanel = new ChartPanel(chart); chartHandler = new ChartHandler(chart); final XYPlotMarker plotMarker = new XYPlotMarker(chartPanel, new XYPlotMarker.Listener() { @Override public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) { //do nothing } @Override public void pointDeselected() { //do nothing } }); filterButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Filter24.gif"), false); filterButton.setName("filterButton"); filterButton.setEnabled(false); filterButton.addActionListener(e -> { selectSpectralBands(); recreateChart(); }); showSpectrumForCursorButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/CursorSpectrum24.gif"), true); showSpectrumForCursorButton.addActionListener(e -> recreateChart()); showSpectrumForCursorButton.setName("showSpectrumForCursorButton"); showSpectrumForCursorButton.setSelected(true); showSpectrumForCursorButton.setToolTipText("Show spectrum at cursor position."); showSpectraForSelectedPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/SelectedPinSpectra24.gif"), true); showSpectraForSelectedPinsButton.addActionListener(e -> { if (isShowingSpectraForAllPins()) { showSpectraForAllPinsButton.setSelected(false); } else if (!isShowingSpectraForSelectedPins()) { plotMarker.setInvisible(); } recreateChart(); }); showSpectraForSelectedPinsButton.setName("showSpectraForSelectedPinsButton"); showSpectraForSelectedPinsButton.setToolTipText("Show spectra for selected pins."); showSpectraForAllPinsButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/PinSpectra24.gif"), true); showSpectraForAllPinsButton.addActionListener(e -> { if (isShowingSpectraForSelectedPins()) { showSpectraForSelectedPinsButton.setSelected(false); } else if (!isShowingSpectraForAllPins()) { plotMarker.setInvisible(); } recreateChart(); }); showSpectraForAllPinsButton.setName("showSpectraForAllPinsButton"); showSpectraForAllPinsButton.setToolTipText("Show spectra for all pins."); showGridButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/SpectrumGrid24.gif"), true); showGridButton.addActionListener(e -> chartHandler.setGridVisible(showGridButton.isSelected())); showGridButton.setName("showGridButton"); showGridButton.setToolTipText("Show diagram grid."); AbstractButton exportSpectraButton = ToolButtonFactory .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false); exportSpectraButton.addActionListener(new SpectraExportAction(this)); exportSpectraButton.setToolTipText("Export spectra to text file."); exportSpectraButton.setName("exportSpectraButton"); AbstractButton helpButton = ToolButtonFactory.createButton(new HelpAction(this), false); helpButton.setName("helpButton"); helpButton.setToolTipText("Help."); final JPanel buttonPane = GridBagUtils.createPanel(); final GridBagConstraints gbc = new GridBagConstraints(); gbc.anchor = GridBagConstraints.CENTER; gbc.fill = GridBagConstraints.NONE; gbc.insets.top = 2; gbc.gridy = 0; buttonPane.add(filterButton, gbc); gbc.gridy++; buttonPane.add(showSpectrumForCursorButton, gbc); gbc.gridy++; buttonPane.add(showSpectraForSelectedPinsButton, gbc); gbc.gridy++; buttonPane.add(showSpectraForAllPinsButton, gbc); gbc.gridy++; buttonPane.add(showGridButton, gbc); gbc.gridy++; buttonPane.add(exportSpectraButton, gbc); gbc.gridy++; gbc.insets.bottom = 0; gbc.fill = GridBagConstraints.VERTICAL; gbc.weighty = 1.0; gbc.gridwidth = 2; buttonPane.add(new JLabel(" "), gbc); // filler gbc.fill = GridBagConstraints.NONE; gbc.weighty = 0.0; gbc.gridy = 10; gbc.anchor = GridBagConstraints.EAST; buttonPane.add(helpButton, gbc); chartPanel.setPreferredSize(new Dimension(300, 200)); chartPanel.setBackground(Color.white); chartPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createBevelBorder(BevelBorder.LOWERED), BorderFactory.createEmptyBorder(2, 2, 2, 2))); chartPanel.addChartMouseListener(plotMarker); JPanel mainPane = new JPanel(new BorderLayout(4, 4)); mainPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); mainPane.add(BorderLayout.CENTER, chartPanel); mainPane.add(BorderLayout.EAST, buttonPane); mainPane.setPreferredSize(new Dimension(320, 200)); SnapApp.getDefault().getProductManager().addListener(new ProductManager.Listener() { @Override public void productAdded(ProductManager.Event event) { // ignored } @Override public void productRemoved(ProductManager.Event event) { final Product product = event.getProduct(); if (getCurrentProduct() == product) { chartPanel.getChart().getXYPlot().setDataset(null); setCurrentView(null); setCurrentProduct(null); } if (currentView != null) { final RasterDataNode currentRaster = currentView.getRaster(); if (rasterToSpectraMap.containsKey(currentRaster)) { rasterToSpectraMap.remove(currentRaster); } if (rasterToSpectralBandsMap.containsKey(currentRaster)) { rasterToSpectralBandsMap.remove(currentRaster); } } PlacemarkGroup pinGroup = product.getPinGroup(); for (int i = 0; i < pinGroup.getNodeCount(); i++) { chartHandler.removePinInformation(pinGroup.get(i)); } } }); final ProductSceneView view = getSelectedProductSceneView(); if (view != null) { productSceneViewSelected(view); } setDisplayName(Bundle.CTL_SpectrumTopComponent_Name()); setLayout(new BorderLayout()); add(mainPane, BorderLayout.CENTER); updateUIState(); }
From source file:com.sec.ose.osi.ui.frm.main.manage.JPanManageMain.java
/** * This method initializes jPanelProjectList * /*from w ww . java 2s . co m*/ * @return javax.swing.JPanel */ private JPanel getJPanelProjectList() { if (jPanelProjectList == null) { GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); gridBagConstraints8.anchor = GridBagConstraints.EAST; gridBagConstraints8.weightx = 0.1; gridBagConstraints8.insets = new Insets(0, 0, 0, 10); GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); gridBagConstraints2.anchor = GridBagConstraints.CENTER; gridBagConstraints2.insets = new Insets(0, 0, 0, 10); GridBagConstraints gridBagConstraints = new GridBagConstraints(); gridBagConstraints.fill = GridBagConstraints.BOTH; gridBagConstraints.gridy = 1; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.gridwidth = 3; gridBagConstraints.insets = new Insets(10, 10, 10, 10); gridBagConstraints.gridx = 0; jPanelProjectList = new JPanel(); jPanelProjectList.setLayout(new GridBagLayout()); jPanelProjectList.setBorder(BorderFactory.createTitledBorder(null, "Project", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51))); jPanelProjectList.add(getJButtonAdd(), gridBagConstraints8); jPanelProjectList.add(getJButtonCreate(), gridBagConstraints2); jPanelProjectList.add(getJScrollPanePjtList(), gridBagConstraints); } return jPanelProjectList; }
From source file:shuffle.fwk.service.roster.EditRosterService.java
private Component makeBottomPanel() { JPanel ret = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.NONE; c.insets = new Insets(0, 10, 0, 10); c.weightx = 1.0;/* www . ja va2 s. com*/ c.weighty = 0.0; c.gridx = 1; c.gridy = 1; c.gridwidth = 1; c.gridheight = 1; c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.0; c.gridx++; selectedDisplayLabel = new JLabel(getString(KEY_NONE_SELECTED)); selectedDisplayLabel.setToolTipText(getString(KEY_SELECTED_TOOLTIP)); ; ret.add(selectedDisplayLabel, c); c.insets = new Insets(0, 0, 0, 0); c.anchor = GridBagConstraints.LINE_END; c.weightx = 1.0; c.gridx++; teamFilter = new JCheckBox(getString(KEY_TEAM)); JPanel teamFilterPanel = new JPanel(new BorderLayout()); teamFilterPanel.add(teamFilter, BorderLayout.WEST); teamFilter.setToolTipText(getString(KEY_TEAM_TOOLTIP)); ret.add(teamFilterPanel, c); c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.0; c.gridx++; activeEffect = new EffectChooser(false, EffectChooser.DefaultEntry.SPECIES); JPanel activeEffectPanel = new JPanel(new BorderLayout()); activeEffectPanel.add(activeEffect, BorderLayout.WEST); activeEffect.setToolTipText(getString(KEY_ACTIVE_EFFECT)); ret.add(activeEffectPanel, c); c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.0; c.gridx++; JPanel skillPanel = new JPanel(new BorderLayout()); ImageIcon skillBoosterIcon = getUser().getImageManager().getImageFor(KEY_SKILL_BOOSTER); JLabel skillBoosterLabel = new JLabel(skillBoosterIcon); skillPanel.add(skillBoosterLabel, BorderLayout.EAST); skillLevels = new JComboBox<Integer>(); skillLevels.setEnabled(false); skillLevels.addItem(1); skillPanel.add(skillLevels, BorderLayout.WEST); skillPanel.setToolTipText(getString(KEY_SKILL_BOOSTER_TOOLTIP)); skillLevels.setToolTipText(getString(KEY_SKILL_BOOSTER_TOOLTIP)); ret.add(skillPanel, c); c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.0; c.gridx++; JPanel speedupPanel = new JPanel(new BorderLayout()); ImageIcon candyIcon = getUser().getImageManager().getImageFor(KEY_CANDY_ICON); JLabel candyLabel = new JLabel(candyIcon); speedupPanel.add(candyLabel, BorderLayout.EAST); speedups = new JComboBox<Integer>(); speedups.setEnabled(false); speedups.addItem(0); speedupPanel.add(speedups, BorderLayout.WEST); speedupPanel.setToolTipText(getString(KEY_CANDY_TOOLTIP)); speedups.setToolTipText(getString(KEY_CANDY_TOOLTIP)); ret.add(speedupPanel, c); c.anchor = GridBagConstraints.LINE_END; c.weightx = 0.0; c.gridx++; JButton okButton = new JButton(getString(KEY_OK)); okButton.setToolTipText(getString(KEY_OK_TOOLTIP)); ret.add(okButton, c); setDefaultButton(okButton); c.anchor = GridBagConstraints.CENTER; c.weightx = 0.0; c.gridx++; JButton applyButton = new JButton(getString(KEY_APPLY)); applyButton.setToolTipText(getString(KEY_APPLY_TOOLTIP)); ret.add(applyButton, c); c.anchor = GridBagConstraints.LINE_START; c.weightx = 0.0; c.gridx++; JButton cancelButton = new JButton(new DisposeAction(getString(KEY_CANCEL), this)); cancelButton.setToolTipText(getString(KEY_CANCEL_TOOLTIP)); ret.add(cancelButton, c); okButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onOK(); } }); applyButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onApply(); } }); addSpeedupsListener(); return ret; }
From source file:com._17od.upm.gui.MainWindow.java
private void addComponentsToPane() { // Ensure the layout manager is a BorderLayout if (!(getContentPane().getLayout() instanceof GridBagLayout)) { getContentPane().setLayout(new GridBagLayout()); }/*from w w w .ja v a 2s.c om*/ // Create the menubar setJMenuBar(createMenuBar()); GridBagConstraints c = new GridBagConstraints(); // The toolbar Row c.gridx = 0; c.gridy = 0; c.anchor = GridBagConstraints.FIRST_LINE_START; c.insets = new Insets(0, 0, 0, 0); c.weightx = 0; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; Component toolbar = createToolBar(); getContentPane().add(toolbar, c); // Keep the frame background color consistent getContentPane().setBackground(toolbar.getBackground()); // The seperator Row c.gridx = 0; c.gridy = 1; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(0, 0, 0, 0); c.weightx = 1; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; getContentPane().add(new JSeparator(), c); // The search field row searchIcon = new JLabel(Util.loadImage("search.gif")); searchIcon.setDisabledIcon(Util.loadImage("search_d.gif")); searchIcon.setEnabled(false); c.gridx = 0; c.gridy = 2; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(5, 1, 5, 1); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; getContentPane().add(searchIcon, c); searchField = new JTextField(15); searchField.setEnabled(false); searchField.setMinimumSize(searchField.getPreferredSize()); searchField.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { // This method never seems to be called } public void insertUpdate(DocumentEvent e) { dbActions.filter(); } public void removeUpdate(DocumentEvent e) { dbActions.filter(); } }); searchField.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { dbActions.resetSearch(); } else if (e.getKeyCode() == KeyEvent.VK_ENTER) { // If the user hits the enter key in the search field and // there's only one item // in the listview then open that item (this code assumes // that the one item in // the listview has already been selected. this is done // automatically in the // DatabaseActions.filter() method) if (accountsListview.getModel().getSize() == 1) { viewAccountMenuItem.doClick(); } } } }); c.gridx = 1; c.gridy = 2; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(5, 1, 5, 1); c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; getContentPane().add(searchField, c); resetSearchButton = new JButton(Util.loadImage("stop.gif")); resetSearchButton.setDisabledIcon(Util.loadImage("stop_d.gif")); resetSearchButton.setEnabled(false); resetSearchButton.setToolTipText(Translator.translate(RESET_SEARCH_TXT)); resetSearchButton.setActionCommand(RESET_SEARCH_TXT); resetSearchButton.addActionListener(this); resetSearchButton.setBorder(BorderFactory.createEmptyBorder()); resetSearchButton.setFocusable(false); c.gridx = 2; c.gridy = 2; c.anchor = GridBagConstraints.LINE_START; c.insets = new Insets(5, 1, 5, 1); c.weightx = 1; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; getContentPane().add(resetSearchButton, c); // The accounts listview row accountsListview = new JList(); accountsListview.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); accountsListview.setSelectedIndex(0); accountsListview.setVisibleRowCount(10); accountsListview.setModel(new SortedListModel()); JScrollPane accountsScrollList = new JScrollPane(accountsListview, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); accountsListview.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent e) { // If the listview gets focus, there is one ore more items in // the listview and there is nothing // already selected, then select the first item in the list if (accountsListview.getModel().getSize() > 0 && accountsListview.getSelectedIndex() == -1) { accountsListview.setSelectionInterval(0, 0); } } }); accountsListview.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { dbActions.setButtonState(); } }); accountsListview.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { viewAccountMenuItem.doClick(); } } }); accountsListview.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { viewAccountMenuItem.doClick(); } } }); // Create a shortcut to delete account functionality with DEL(delete) // key accountsListview.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_DELETE) { try { dbActions.reloadDatabaseBefore(new DeleteAccountAction()); } catch (InvalidPasswordException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (ProblemReadingDatabaseFile e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }); c.gridx = 0; c.gridy = 3; c.anchor = GridBagConstraints.CENTER; c.insets = new Insets(0, 1, 1, 1); c.weightx = 1; c.weighty = 1; c.gridwidth = 3; c.fill = GridBagConstraints.BOTH; getContentPane().add(accountsScrollList, c); // The "File Changed" panel c.gridx = 0; c.gridy = 4; c.anchor = GridBagConstraints.CENTER; c.insets = new Insets(0, 1, 0, 1); c.ipadx = 3; c.ipady = 3; c.weightx = 0; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.BOTH; databaseFileChangedPanel = new JPanel(); databaseFileChangedPanel.setLayout(new BoxLayout(databaseFileChangedPanel, BoxLayout.X_AXIS)); databaseFileChangedPanel.setBackground(new Color(249, 172, 60)); databaseFileChangedPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); JLabel fileChangedLabel = new JLabel("Database file changed"); fileChangedLabel.setAlignmentX(LEFT_ALIGNMENT); databaseFileChangedPanel.add(fileChangedLabel); databaseFileChangedPanel.add(Box.createHorizontalGlue()); JButton reloadButton = new JButton("Reload"); reloadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { dbActions.reloadDatabaseFromDisk(); } catch (Exception ex) { dbActions.errorHandler(ex); } } }); databaseFileChangedPanel.add(reloadButton); databaseFileChangedPanel.setVisible(false); getContentPane().add(databaseFileChangedPanel, c); // Add the statusbar c.gridx = 0; c.gridy = 5; c.anchor = GridBagConstraints.CENTER; c.insets = new Insets(0, 1, 1, 1); c.weightx = 1; c.weighty = 0; c.gridwidth = 3; c.fill = GridBagConstraints.HORIZONTAL; getContentPane().add(statusBar, c); }