List of usage examples for javax.swing JToolBar JToolBar
public JToolBar(String name, int orientation)
name
and orientation
. From source file:Main.java
public static void main(String[] argv) throws Exception { JToolBar toolbar = new JToolBar(null, JToolBar.VERTICAL); // Get current orientation int orient = toolbar.getOrientation(); }
From source file:ffx.ui.MainMenu.java
/** * <p>// ww w . j a va 2 s . c o m * Constructor for MainMenu.</p> * * @param f a {@link ffx.ui.MainPanel} object. */ public MainMenu(MainPanel f) { // Create the Tool Bar toolBar = new JToolBar("Toolbar", JToolBar.HORIZONTAL); toolBar.setBorderPainted(true); toolBar.setRollover(true); JButton temp = new JButton(); insets = temp.getInsets(); insets.set(2, 2, 2, 2); mainPanel = f; graphics = mainPanel.getGraphics3D(); locale = mainPanel.getFFXLocale(); loader = getClass().getClassLoader(); blankIcon = new ImageIcon(loader.getResource(icons + "blank.gif")); String value = System.getProperty("structures", "false").trim(); try { includeStructureMenu = Boolean.parseBoolean(value); } catch (Exception e) { includeStructureMenu = false; } /** * Main Menubar */ JMenu fileMenu = addMenu("File", 'F'); JMenu selectionMenu = addMenu("Selection", 'E'); JMenu structureMenu = null; if (includeStructureMenu) { structureMenu = addMenu("Structure", 'S'); } JMenu displayMenu = addMenu("Display", 'D'); JMenu colorMenu = addMenu("Color", 'C'); JMenu optionsMenu = addMenu("Options", 'O'); JMenu pickingMenu = addMenu("Picking", 'P'); JMenu trajectoryMenu = addMenu("Trajectory", 'T'); JMenu exportMenu = addMenu("Export", 'X'); JMenu windowMenu = addMenu("Window", 'W'); JMenu helpMenu = addMenu("Help", 'H'); /** * File Menu - Events Handled by the MainPanel Class. */ addMenuItem(fileMenu, icons + "folder_page", "Open", 'O', KeyEvent.VK_O, mainPanel); addMenuItem(fileMenu, icons + "disk", "SaveAs", 'S', KeyEvent.VK_S, mainPanel); addMenuItem(fileMenu, icons + "cancel", "Close", 'C', -1, mainPanel); addMenuItem(fileMenu, "BLANK", "CloseAll", 'A', -1, mainPanel); fileMenu.addSeparator(); addMenuItem(fileMenu, icons + "drive_web", "DownloadFromPDB", 'D', KeyEvent.VK_D, mainPanel); fileMenu.addSeparator(); addMenuItem(fileMenu, "BLANK", "ChooseKeyFile", 'R', -1, mainPanel); addMenuItem(fileMenu, "BLANK", "ChooseLogFile", 'I', -1, mainPanel); addMenuItem(fileMenu, "BLANK", "LoadRestartData", 'R', -1, mainPanel); if (!SystemUtils.IS_OS_MAC_OSX) { fileMenu.addSeparator(); addMenuItem(fileMenu, "BLANK", "Exit", 'E', KeyEvent.VK_Q, mainPanel); } toolBar.addSeparator(); /** * Selection Menu - Events Handled by the MainPanel and GraphicsCanvas. */ addMenuItem(selectionMenu, icons + "add", "SelectAll", 'A', KeyEvent.VK_A, mainPanel); addMenuItem(selectionMenu, "BLANK", "RestrictToSelections", 'R', -1, graphics); addMenuItem(selectionMenu, icons + "arrow_merge", "MergeSelections", 'M', -1, mainPanel); selectionMenu.addSeparator(); highlightCBMI = addCBMenuItem(selectionMenu, icons + "asterisk_yellow", "HighlightSelections", 'H', KeyEvent.VK_H, mainPanel); addMenuItem(selectionMenu, "BLANK", "SetSelectionColor", 'S', -1, graphics); selectionMenu.addSeparator(); labelAtomsMI = addCBMenuItem(selectionMenu, "BLANK", "LabelSelectedAtoms", 'O', -1, graphics); labelResiduesMI = addCBMenuItem(selectionMenu, "BLANK", "LabelSelectedResidues", 'R', -1, graphics); addMenuItem(selectionMenu, "BLANK", "SetLabelFontSize", 'Z', -1, graphics); addMenuItem(selectionMenu, "BLANK", "SetLabelFontColor", 'C', -1, graphics); highlightCBMI.setSelected(false); labelAtomsMI.setSelected(false); labelResiduesMI.setSelected(false); toolBar.addSeparator(); /** * Structure Menu - Events Handled by the MainPanel. */ if (includeStructureMenu) { // Locate a jar file that has PDB Structures. String file = "ffx/xray/structures/1N7S.pdb"; addMenuItem(structureMenu, "BLANK", file, '.', -1, mainPanel); } /** * Display Menu - Events handled by the GraphicsCanvas. */ addMenuItem(displayMenu, "BLANK", "Wireframe", 'W', -1, graphics); addMenuItem(displayMenu, "BLANK", "Tube", 'T', -1, graphics); addMenuItem(displayMenu, "BLANK", "Spacefill", 'S', -1, graphics); addMenuItem(displayMenu, "BLANK", "BallAndStick", 'B', -1, graphics); addMenuItem(displayMenu, "BLANK", "Invisible", 'I', -1, graphics); addMenuItem(displayMenu, "BLANK", "RMIN", 'R', -1, graphics); displayMenu.addSeparator(); addMenuItem(displayMenu, "BLANK", "ShowHydrogens", 'H', -1, graphics); addMenuItem(displayMenu, "BLANK", "HideHydrogens", 'Y', -1, graphics); displayMenu.addSeparator(); addMenuItem(displayMenu, "BLANK", "Fill", 'F', -1, graphics); addMenuItem(displayMenu, "BLANK", "Points", 'P', -1, graphics); addMenuItem(displayMenu, "BLANK", "Lines", 'I', -1, graphics); displayMenu.addSeparator(); addMenuItem(displayMenu, "BLANK", "Preferences", 'P', -1, graphics); /** * Color Menu - Events handled by the GraphicsCanvas. */ addMenuItem(colorMenu, "BLANK", "Monochrome", 'M', -1, graphics); addMenuItem(colorMenu, "BLANK", "CPK", 'C', -1, graphics); addMenuItem(colorMenu, "BLANK", "Residue", 'R', -1, graphics); addMenuItem(colorMenu, "BLANK", "Structure", 'S', -1, graphics); addMenuItem(colorMenu, "BLANK", "Polymer", 'M', -1, graphics); addMenuItem(colorMenu, "BLANK", "PartialCharge", 'P', -1, graphics); addMenuItem(colorMenu, "BLANK", "UserColor", 'U', -1, graphics); colorMenu.addSeparator(); addMenuItem(colorMenu, "BLANK", "ApplyUserColor", 'A', -1, graphics); addMenuItem(colorMenu, "BLANK", "SetUserColor", 'C', -1, graphics); /** * Options Menu - Events handled by the GraphicsCanvas. */ dragModeButtonGroup = new ButtonGroup(); activeRBMI = addBGMI(dragModeButtonGroup, optionsMenu, "BLANK", "ActiveSystem", 'A', KeyEvent.VK_A, graphics); mouseRBMI = addBGMI(dragModeButtonGroup, optionsMenu, "BLANK", "SystemBelowMouse", 'S', KeyEvent.VK_M, graphics); activeRBMI.setSelected(true); optionsMenu.addSeparator(); JMenu leftMouseMenu = addSubMenu(optionsMenu, "LeftMouseButton", 'M'); leftMouseButtonGroup = new ButtonGroup(); rotateRBMI = addBGMI(leftMouseButtonGroup, leftMouseMenu, "BLANK", "Rotate", 'R', KeyEvent.VK_R, graphics); addBGMI(leftMouseButtonGroup, leftMouseMenu, "BLANK", "Translate", 'T', KeyEvent.VK_T, graphics); addBGMI(leftMouseButtonGroup, leftMouseMenu, "BLANK", "Zoom", 'Z', KeyEvent.VK_Z, graphics); rotateRBMI.setSelected(true); optionsMenu.addSeparator(); addMenuItem(optionsMenu, "BLANK", "RotateAboutCenter", 'C', KeyEvent.VK_C, graphics); addMenuItem(optionsMenu, "BLANK", "RotateAboutPick", 'P', KeyEvent.VK_P, graphics); addMenuItem(optionsMenu, "BLANK", "ResetRotation", 'R', -1, graphics); addMenuItem(optionsMenu, "BLANK", "ResetTranslation", 'T', -1, graphics); addMenuItem(optionsMenu, icons + "arrow_refresh", "ResetRotationAndTranslation", 'E', -1, graphics); optionsMenu.addSeparator(); addMenuItem(optionsMenu, icons + "magnifier_zoom_in", "ZoomIn", 'I', -1, graphics); addMenuItem(optionsMenu, icons + "magnifier_zoom_out", "ZoomOut", 'O', -1, graphics); addMenuItem(optionsMenu, "BLANK", "ResetGlobalZoom", 'Z', -1, graphics); addMenuItem(optionsMenu, "BLANK", "ResetGlobalRotation", 'N', -1, graphics); addMenuItem(optionsMenu, "BLANK", "ResetGlobalTranslation", 'O', -1, graphics); addMenuItem(optionsMenu, icons + "house", "ResetGlobalView", 'V', -1, graphics); optionsMenu.addSeparator(); addMenuItem(optionsMenu, "BLANK", "SetBackgroundColor", 'B', -1, graphics); toolBar.addSeparator(); /** * Picking Menu - Events handled by the GraphicsCanvas. */ levelBG = new ButtonGroup(); pickingCBMI = addCBMenuItem(pickingMenu, icons + "wand", "GraphicsPicking", 'G', KeyEvent.VK_0, graphics); pickingCBMI.setSelected(false); pickingMenu.addSeparator(); atomRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickAtom", 'A', KeyEvent.VK_1, graphics); bondRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickBond", 'B', KeyEvent.VK_2, graphics); angleRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickAngle", 'N', KeyEvent.VK_3, graphics); dihedralRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickDihedral", 'D', KeyEvent.VK_4, graphics); residueRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickResidue", 'R', KeyEvent.VK_5, graphics); polymerRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickPolymer", 'P', KeyEvent.VK_6, graphics); moleculeRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickMolecule", 'M', KeyEvent.VK_7, graphics); systemRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "PickSystem", 'S', KeyEvent.VK_8, graphics); pickingMenu.addSeparator(); measureDistanceRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "MeasureDistance", 'I', -1, graphics); measureAngleRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "MeasureAngle", 'L', -1, graphics); measureDihedralRBMI = addBGMI(levelBG, pickingMenu, "BLANK", "MeasureDihedral", 'H', -1, graphics); atomRBMI.setSelected(true); pickingMenu.addSeparator(); addMenuItem(pickingMenu, "BLANK", "SetGraphicsPickingColor", 'S', -1, graphics); toolBar.addSeparator(); /** * Trajectory Menu - Events handled by the MainPanel. */ oscillateCBMI = addCBMenuItem(trajectoryMenu, icons + "control_repeat_blue", "Oscillate", 'O', -1, mainPanel); oscillateCBMI.setSelected(false); addMenuItem(trajectoryMenu, "BLANK", "Frame", 'A', -1, mainPanel); addMenuItem(trajectoryMenu, "BLANK", "Speed", 'E', -1, mainPanel); addMenuItem(trajectoryMenu, "BLANK", "Skip", 'K', -1, mainPanel); trajectoryMenu.addSeparator(); addMenuItem(trajectoryMenu, icons + "control_play_blue", "Play", 'P', -1, mainPanel); addMenuItem(trajectoryMenu, icons + "control_stop_blue", "Stop", 'S', -1, mainPanel); addMenuItem(trajectoryMenu, icons + "control_fastforward_blue", "StepForward", 'F', -1, mainPanel); addMenuItem(trajectoryMenu, icons + "control_rewind_blue", "StepBack", 'B', -1, mainPanel); addMenuItem(trajectoryMenu, icons + "control_start_blue", "Reset", 'R', -1, mainPanel); toolBar.addSeparator(); /** * Export Menu - Events handled by the GraphicsCanvas. */ addMenuItem(exportMenu, icons + "camera", "CaptureGraphics", 'C', KeyEvent.VK_G, graphics); exportMenu.addSeparator(); captureFormatButtonGroup = new ButtonGroup(); addBGMI(captureFormatButtonGroup, exportMenu, "BLANK", "PNG", 'P', -1, graphics).setSelected(true); addBGMI(captureFormatButtonGroup, exportMenu, "BLANK", "JPEG", 'J', -1, graphics); addBGMI(captureFormatButtonGroup, exportMenu, "BLANK", "BMP", 'B', -1, graphics); addBGMI(captureFormatButtonGroup, exportMenu, "BLANK", "WBMP", 'W', -1, graphics); addBGMI(captureFormatButtonGroup, exportMenu, "BLANK", "GIF", 'G', -1, graphics); toolBar.addSeparator(); /** * Window Menu - Events handled by the GraphicsCanvas. */ addMenuItem(windowMenu, icons + "application_home", "ResetPanes", 'R', -1, mainPanel); addMenuItem(windowMenu, icons + "application_osx_terminal", "ResetConsole", 'L', -1, mainPanel); windowMenu.addSeparator(); addMenuItem(windowMenu, icons + "application_side_contract", "ExpandGraphicsWindow", 'E', -1, mainPanel); addMenuItem(windowMenu, icons + "application_side_expand", "ShrinkGraphicsWindow", 'L', -1, mainPanel); windowMenu.addSeparator(); systemsCBMI = addCBMenuItem(windowMenu, "BLANK", "ShowTree", 'T', -1, mainPanel); toolBarCBMI = addCBMenuItem(windowMenu, "BLANK", "ShowToolBar", 'B', -1, mainPanel); globalAxisCBMI = addCBMenuItem(windowMenu, "BLANK", "ShowGlobalAxes", 'C', -1, mainPanel); globalAxisCBMI.setSelected(true); toolBar.addSeparator(); /** * Help Menu - Events handled by the MainPanel. */ Action a = addMenuItem(helpMenu, icons + "help", "HelpContents", 'H', KeyEvent.VK_HELP, mainPanel); /** * Fix the ACCELERATOR_KEY for the Help menu item; no modifiers will be * used. */ a.putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0)); addMenuItem(helpMenu, "BLANK", "About", 'A', -1, mainPanel); }
From source file:io.heming.accountbook.ui.MainFrame.java
private void initToolBar() { toolbar = new JToolBar("ToolBar", JToolBar.HORIZONTAL); // Add Button addButton = new JButton(); addButton.setActionCommand(""); addButton.setToolTipText(""); addButton.setIcon(new ImageIcon(getClass().getResource("edit-add-3.png"))); // Search date range radio buttons ButtonGroup group = new ButtonGroup(); yearToggleButton = new JToggleButton(); yearToggleButton.setToolTipText(""); yearToggleButton.setIcon(new ImageIcon(getClass().getResource("year-s.png"))); group.add(yearToggleButton);/* w ww .j a va 2 s . c o m*/ monthToggleButton = new JToggleButton(); monthToggleButton.setToolTipText(""); monthToggleButton.setIcon(new ImageIcon(getClass().getResource("month-s.png"))); group.add(monthToggleButton); dayToggleButton = new JToggleButton(); dayToggleButton.setToolTipText(""); dayToggleButton.setIcon(new ImageIcon(getClass().getResource("day-s.png"))); group.add(dayToggleButton); customToggleButton = new JToggleButton(); customToggleButton.setToolTipText(""); customToggleButton.setIcon(new ImageIcon(getClass().getResource("all-s.png"))); group.add(customToggleButton); // ??Checkbox monthToggleButton.setSelected(true); Calendar earliestCalendar = Calendar.getInstance(); earliestCalendar.add(Calendar.YEAR, -100); java.util.Date earliestDate = earliestCalendar.getTime(); Calendar latestCalendar = Calendar.getInstance(); latestCalendar.add(Calendar.YEAR, 100); java.util.Date latestDate = latestCalendar.getTime(); // 3? Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.MONTH, -1); calendar.add(Calendar.DAY_OF_MONTH, 1); java.util.Date initDate = calendar.getTime(); SpinnerDateModel startDateModel = new SpinnerDateModel(DateUtil.getStartOfWeek(), earliestDate, latestDate, Calendar.MONTH); startDateSpinner = new JSpinner(startDateModel); JSpinner.DateEditor startDateEditor = new JSpinner.DateEditor(startDateSpinner, "yyyy-MM-dd"); startDateSpinner.setEditor(startDateEditor); calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.DAY_OF_MONTH, -1); initDate = calendar.getTime(); SpinnerDateModel endDateModel = new SpinnerDateModel(initDate, earliestDate, latestDate, Calendar.MONTH); endDateSpinner = new JSpinner(endDateModel); JSpinner.DateEditor endDateEditor = new JSpinner.DateEditor(endDateSpinner, "yyyy-MM-dd"); endDateSpinner.setEditor(endDateEditor); // Keyword text field keywordTextField = new JTextField(); keywordTextField.setPreferredSize(new Dimension(250, 20)); keywordTextField.setMaximumSize(keywordTextField.getPreferredSize()); // Search Button searchButton = new JButton(); searchButton.setActionCommand("?"); searchButton.setToolTipText("?"); searchButton.setIcon(new ImageIcon(getClass().getResource("edit-find-5.png"))); // Layout cards = new JPanel(); cards.setLayout(new CardLayout()); Box box = Box.createHorizontalBox(); box.add(Box.createHorizontalGlue()); startDateSpinner.setPreferredSize(new Dimension(90, 20)); startDateSpinner.setMaximumSize(startDateSpinner.getPreferredSize()); box.add(startDateSpinner); box.add(Box.createHorizontalStrut(6)); endDateSpinner.setPreferredSize(new Dimension(90, 20)); endDateSpinner.setMaximumSize(endDateSpinner.getPreferredSize()); box.add(endDateSpinner); cards.add(new JPanel(), HIDE_DATE_CHOOSER); cards.add(box, SHOW_DATE_CHOOSER); Box dateRangeBox = Box.createHorizontalBox(); dateRangeBox.add(Box.createHorizontalGlue()); dateRangeBox.add(cards); toolbar.add(addButton); toolbar.add(dateRangeBox); toolbar.add(customToggleButton); toolbar.add(yearToggleButton); toolbar.add(monthToggleButton); toolbar.add(dayToggleButton); toolbar.add(keywordTextField); toolbar.add(searchButton); add(toolbar, BorderLayout.NORTH); // Event listener addButton.addActionListener(e -> showAddRecordDialog()); ActionListener listener = e -> searchRecords(); yearToggleButton.addActionListener(listener); monthToggleButton.addActionListener(listener); dayToggleButton.addActionListener(listener); customToggleButton.addActionListener(listener); keywordTextField.addActionListener(listener); searchButton.addActionListener(listener); customToggleButton.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { chooseDateRange(); } } }); }
From source file:ffx.ui.ModelingPanel.java
private void initialize() { // Command Description descriptTextArea = new JTextArea(); descriptTextArea.setEditable(false); descriptTextArea.setLineWrap(true);//from w w w . j av a 2 s. co m descriptTextArea.setWrapStyleWord(true); descriptTextArea.setDoubleBuffered(true); Insets insets = descriptTextArea.getInsets(); insets.set(5, 5, 5, 5); descriptTextArea.setMargin(insets); descriptScrollPane = new JScrollPane(descriptTextArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); descriptScrollPane.setBorder(etchedBorder); // Command Input commandTextArea = new JTextArea(); commandTextArea.setEditable(false); commandTextArea.setLineWrap(true); commandTextArea.setWrapStyleWord(true); commandTextArea.setDoubleBuffered(true); commandTextArea.setMargin(insets); // Command Options optionsTabbedPane = new JTabbedPane(); statusLabel = new JLabel(); statusLabel.setBorder(etchedBorder); statusLabel.setToolTipText(" Modeling command that will be executed"); commandPanel = new JPanel(flowLayout); commandPanel.add(optionsTabbedPane); splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, commandPanel, descriptScrollPane); splitPane.setContinuousLayout(true); splitPane.setResizeWeight(1.0d); splitPane.setOneTouchExpandable(true); setLayout(new BorderLayout()); add(splitPane, BorderLayout.CENTER); add(statusLabel, BorderLayout.SOUTH); // Initialize the Amino/Nucleic Acid ComboBox. acidComboBox.setEditable(false); acidComboBox.setMaximumSize(sizer.getPreferredSize()); acidComboBox.setPreferredSize(sizer.getPreferredSize()); acidComboBox.setMinimumSize(sizer.getPreferredSize()); acidComboBox.setFont(Font.decode("Monospaced")); acidTextField.setMaximumSize(sizer.getPreferredSize()); acidTextField.setMinimumSize(sizer.getPreferredSize()); acidTextField.setPreferredSize(sizer.getPreferredSize()); acidTextArea.setEditable(false); acidTextArea.setWrapStyleWord(true); acidTextArea.setLineWrap(true); acidTextArea.setFont(Font.decode("Monospaced")); acidScrollPane = new JScrollPane(acidTextArea); Dimension d = new Dimension(300, 400); acidScrollPane.setPreferredSize(d); acidScrollPane.setMaximumSize(d); acidScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); // Load the FFX commands.xml file that defines FFX commands. try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); db.setEntityResolver(new DTDResolver()); URL comURL = getClass().getClassLoader().getResource("ffx/ui/commands/commands.xml"); Document doc = db.parse(comURL.openStream()); NodeList nodelist = doc.getChildNodes(); Node commandroot = null; for (int i = 0; i < nodelist.getLength(); i++) { commandroot = nodelist.item(i); if (commandroot.getNodeName().equals("FFXCommands") && commandroot instanceof Element) { break; } } if (commandroot == null || !(commandroot instanceof Element)) { commandList = null; } commandList = ((Element) commandroot).getElementsByTagName("Command"); } catch (ParserConfigurationException | SAXException | IOException e) { System.err.println(e); } finally { if (commandList == null) { System.out.println("Force Field X commands.xml could not be parsed."); logger.severe("Force Field X will exit."); System.exit(-1); } } // Create a ComboBox with commands specific to each type of coordinate // file. xyzCommands = new JComboBox<>(); intCommands = new JComboBox<>(); arcCommands = new JComboBox<>(); pdbCommands = new JComboBox<>(); anyCommands = new JComboBox<>(); Element command; String name; int numcommands = commandList.getLength(); for (int i = 0; i < numcommands; i++) { command = (Element) commandList.item(i); name = command.getAttribute("name"); String temp = command.getAttribute("fileType"); if (temp.contains("ANY")) { temp = "XYZ INT ARC PDB"; anyCommands.addItem(name); } String[] types = temp.split(" +"); for (String type : types) { if (type.contains("XYZ")) { xyzCommands.addItem(name); } if (type.contains("INT")) { intCommands.addItem(name); } if (type.contains("ARC")) { arcCommands.addItem(name); } if (type.contains("PDB")) { pdbCommands.addItem(name); } } } initCommandComboBox(xyzCommands); initCommandComboBox(intCommands); initCommandComboBox(arcCommands); initCommandComboBox(pdbCommands); initCommandComboBox(anyCommands); currentCommandBox = anyCommands; activeCommand = (String) anyCommands.getSelectedItem(); // Load the default Command. loadCommand(); // Load the default Log File Settings. logSettings.setActionCommand("LogSettings"); loadLogSettings(); // Create the Toolbar. toolBar = new JToolBar("Modeling Commands", JToolBar.HORIZONTAL); toolBar.setLayout(new FlowLayout(FlowLayout.LEFT)); jbLaunch = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/cog_go.png"))); jbLaunch.setActionCommand("Launch"); jbLaunch.setToolTipText("Launch the Force Field X Command"); jbLaunch.addActionListener(this); insets.set(2, 2, 2, 2); jbLaunch.setMargin(insets); toolBar.add(jbLaunch); jbStop = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/stop.png"))); jbStop.setActionCommand("End"); jbStop.setToolTipText("Terminate the Current Force Field X Command"); jbStop.addActionListener(this); jbStop.setMargin(insets); jbStop.setEnabled(false); toolBar.add(jbStop); toolBar.addSeparator(); toolBar.add(anyCommands); currentCommandBox = anyCommands; toolBar.addSeparator(); /* toolBar.add(logSettings); JButton jbdelete = new JButton(new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/page_delete.png"))); jbdelete.setActionCommand("Delete"); jbdelete.setToolTipText("Delete Log Files"); jbdelete.addActionListener(this); jbdelete.setMargin(insets); toolBar.add(jbdelete); toolBar.addSeparator(); */ ImageIcon icinfo = new ImageIcon(getClass().getClassLoader().getResource("ffx/ui/icons/information.png")); descriptCheckBox = new JCheckBoxMenuItem(icinfo); descriptCheckBox.addActionListener(this); descriptCheckBox.setActionCommand("Description"); descriptCheckBox.setToolTipText("Show/Hide Modeling Command Descriptions"); descriptCheckBox.setMargin(insets); toolBar.add(descriptCheckBox); toolBar.add(new JLabel("")); toolBar.setBorderPainted(false); toolBar.setFloatable(false); toolBar.setRollover(true); add(toolBar, BorderLayout.NORTH); // Load ModelingPanel preferences. Preferences prefs = Preferences.userNodeForPackage(ffx.ui.ModelingPanel.class); descriptCheckBox.setSelected(!prefs.getBoolean("JobPanel_description", true)); descriptCheckBox.doClick(); }
From source file:org.languagetool.gui.Main.java
private void createGUI() { loadRecentFiles();// w w w .j a v a 2 s . c o m frame = new JFrame("LanguageTool " + JLanguageTool.VERSION); setLookAndFeel(); openAction = new OpenAction(); saveAction = new SaveAction(); saveAsAction = new SaveAsAction(); checkAction = new CheckAction(); autoCheckAction = new AutoCheckAction(true); showResultAction = new ShowResultAction(true); frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new CloseListener()); URL iconUrl = JLanguageTool.getDataBroker().getFromResourceDirAsUrl(TRAY_ICON); frame.setIconImage(new ImageIcon(iconUrl).getImage()); textArea = new JTextArea(); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.addKeyListener(new ControlReturnTextCheckingListener()); textLineNumber = new TextLineNumber(textArea, 2); numberedTextAreaPane = new JScrollPane(textArea); numberedTextAreaPane.setRowHeaderView(textLineNumber); resultArea = new JTextPane(); undoRedo = new UndoRedoSupport(this.textArea, messages); frame.setJMenuBar(createMenuBar()); GridBagConstraints buttonCons = new GridBagConstraints(); JPanel insidePanel = new JPanel(); insidePanel.setOpaque(false); insidePanel.setLayout(new GridBagLayout()); buttonCons.gridx = 0; buttonCons.gridy = 0; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(new JLabel(messages.getString("textLanguage") + " "), buttonCons); //create a ComboBox with flags, do not include hidden languages languageBox = LanguageComboBox.create(messages, EXTERNAL_LANGUAGE_SUFFIX, true, false); buttonCons.gridx = 1; buttonCons.gridy = 0; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(languageBox, buttonCons); JCheckBox autoDetectBox = new JCheckBox(messages.getString("atd")); buttonCons.gridx = 2; buttonCons.gridy = 0; buttonCons.gridwidth = GridBagConstraints.REMAINDER; buttonCons.anchor = GridBagConstraints.LINE_START; insidePanel.add(autoDetectBox, buttonCons); buttonCons.gridx = 0; buttonCons.gridy = 1; buttonCons.gridwidth = GridBagConstraints.REMAINDER; buttonCons.fill = GridBagConstraints.HORIZONTAL; buttonCons.anchor = GridBagConstraints.LINE_END; buttonCons.weightx = 1.0; insidePanel.add(statusLabel, buttonCons); Container contentPane = frame.getContentPane(); GridBagLayout gridLayout = new GridBagLayout(); contentPane.setLayout(gridLayout); GridBagConstraints cons = new GridBagConstraints(); cons.gridx = 0; cons.gridy = 1; cons.fill = GridBagConstraints.HORIZONTAL; cons.anchor = GridBagConstraints.FIRST_LINE_START; JToolBar toolbar = new JToolBar("Toolbar", JToolBar.HORIZONTAL); toolbar.setFloatable(false); contentPane.add(toolbar, cons); JButton openButton = new JButton(openAction); openButton.setHideActionText(true); openButton.setFocusable(false); toolbar.add(openButton); JButton saveButton = new JButton(saveAction); saveButton.setHideActionText(true); saveButton.setFocusable(false); toolbar.add(saveButton); JButton saveAsButton = new JButton(saveAsAction); saveAsButton.setHideActionText(true); saveAsButton.setFocusable(false); toolbar.add(saveAsButton); JButton spellButton = new JButton(this.checkAction); spellButton.setHideActionText(true); spellButton.setFocusable(false); toolbar.add(spellButton); JToggleButton autoSpellButton = new JToggleButton(autoCheckAction); autoSpellButton.setHideActionText(true); autoSpellButton.setFocusable(false); toolbar.add(autoSpellButton); JButton clearTextButton = new JButton(new ClearTextAction()); clearTextButton.setHideActionText(true); clearTextButton.setFocusable(false); toolbar.add(clearTextButton); cons.insets = new Insets(5, 5, 5, 5); cons.fill = GridBagConstraints.BOTH; cons.weightx = 10.0f; cons.weighty = 10.0f; cons.gridx = 0; cons.gridy = 2; cons.weighty = 5.0f; splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, numberedTextAreaPane, new JScrollPane(resultArea)); mainPanel.setLayout(new GridLayout(0, 1)); contentPane.add(mainPanel, cons); mainPanel.add(splitPane); cons.fill = GridBagConstraints.HORIZONTAL; cons.gridx = 0; cons.gridy = 3; cons.weightx = 1.0f; cons.weighty = 0.0f; cons.insets = new Insets(4, 12, 4, 12); contentPane.add(insidePanel, cons); ltSupport = new LanguageToolSupport(this.frame, this.textArea, this.undoRedo); ResultAreaHelper.install(messages, ltSupport, resultArea); languageBox.selectLanguage(ltSupport.getLanguage()); languageBox.setEnabled(!ltSupport.getConfig().getAutoDetect()); autoDetectBox.setSelected(ltSupport.getConfig().getAutoDetect()); taggerShowsDisambigLog = ltSupport.getConfig().getTaggerShowsDisambigLog(); languageBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { // we cannot re-use the existing LT object anymore frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); Language lang = languageBox.getSelectedLanguage(); ComponentOrientation componentOrientation = ComponentOrientation .getOrientation(lang.getLocale()); textArea.applyComponentOrientation(componentOrientation); resultArea.applyComponentOrientation(componentOrientation); ltSupport.setLanguage(lang); } } }); autoDetectBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { boolean selected = e.getStateChange() == ItemEvent.SELECTED; languageBox.setEnabled(!selected); ltSupport.getConfig().setAutoDetect(selected); if (selected) { Language detected = ltSupport.autoDetectLanguage(textArea.getText()); languageBox.selectLanguage(detected); } } }); ltSupport.addLanguageToolListener(new LanguageToolListener() { @Override public void languageToolEventOccurred(LanguageToolEvent event) { if (event.getType() == LanguageToolEvent.Type.CHECKING_STARTED) { String msg = org.languagetool.tools.Tools.i18n(messages, "checkStart"); statusLabel.setText(msg); if (event.getCaller() == getFrame()) { setWaitCursor(); checkAction.setEnabled(false); } } else if (event.getType() == LanguageToolEvent.Type.CHECKING_FINISHED) { if (event.getCaller() == getFrame()) { checkAction.setEnabled(true); unsetWaitCursor(); } String msg = org.languagetool.tools.Tools.i18n(messages, "checkDone", event.getSource().getMatches().size(), event.getElapsedTime()); statusLabel.setText(msg); } else if (event.getType() == LanguageToolEvent.Type.LANGUAGE_CHANGED) { languageBox.selectLanguage(ltSupport.getLanguage()); } else if (event.getType() == LanguageToolEvent.Type.RULE_ENABLED) { //this will trigger a check and the result will be updated by //the CHECKING_FINISHED event } else if (event.getType() == LanguageToolEvent.Type.RULE_DISABLED) { String msg = org.languagetool.tools.Tools.i18n(messages, "checkDoneNoTime", event.getSource().getMatches().size()); statusLabel.setText(msg); } } }); frame.applyComponentOrientation(ComponentOrientation.getOrientation(Locale.getDefault())); Language lang = ltSupport.getLanguage(); ComponentOrientation componentOrientation = ComponentOrientation.getOrientation(lang.getLocale()); textArea.applyComponentOrientation(componentOrientation); resultArea.applyComponentOrientation(componentOrientation); ResourceBundle textLanguageMessageBundle = JLanguageTool.getMessageBundle(ltSupport.getLanguage()); textArea.setText(textLanguageMessageBundle.getString("guiDemoText")); Configuration config = ltSupport.getConfig(); if (config.getFontName() != null || config.getFontStyle() != Configuration.FONT_STYLE_INVALID || config.getFontSize() != Configuration.FONT_SIZE_INVALID) { String fontName = config.getFontName(); if (fontName == null) { fontName = textArea.getFont().getFamily(); } int fontSize = config.getFontSize(); if (fontSize == Configuration.FONT_SIZE_INVALID) { fontSize = textArea.getFont().getSize(); } Font font = new Font(fontName, config.getFontStyle(), fontSize); textArea.setFont(font); } frame.pack(); frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); frame.setLocationByPlatform(true); splitPane.setDividerLocation(200); MainWindowStateBean state = localStorage.loadProperty("gui.state", MainWindowStateBean.class); if (state != null) { if (state.getBounds() != null) { frame.setBounds(state.getBounds()); ResizeComponentListener.setBoundsProperty(frame, state.getBounds()); } if (state.getDividerLocation() != null) { splitPane.setDividerLocation(state.getDividerLocation()); } if (state.getState() != null) { frame.setExtendedState(state.getState()); } } ResizeComponentListener.attachToWindow(frame); maybeStartServer(); }