Example usage for javax.swing JButton getInsets

List of usage examples for javax.swing JButton getInsets

Introduction

In this page you can find the example usage for javax.swing JButton getInsets.

Prototype

@BeanProperty(expert = true)
public Insets getInsets() 

Source Link

Document

If a border has been set on this component, returns the border's insets; otherwise calls super.getInsets.

Usage

From source file:ffx.ui.MainMenu.java

/**
 * <p>//from w ww  . j a  v a 2 s. co 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:ffx.ui.KeywordPanel.java

/**
 * <p>//from   www  .j a v  a  2 s .  c  o  m
 * initToolBar</p>
 */
public void initToolBar() {
    toolBar = new JToolBar("Keyword Editor");
    toolBar.setLayout(flowLayout);
    ClassLoader loader = getClass().getClassLoader();
    JButton jbopen = new JButton(new ImageIcon(loader.getResource("ffx/ui/icons/folder_page.png")));
    jbopen.setActionCommand("Open...");
    jbopen.setToolTipText("Open a *.KEY File for Editing");
    jbopen.addActionListener(this);
    Insets insets = jbopen.getInsets();
    insets.top = 2;
    insets.bottom = 2;
    insets.left = 2;
    insets.right = 2;
    jbopen.setMargin(insets);
    //toolBar.add(jbopen);
    JButton jbsave = new JButton(new ImageIcon(loader.getResource("ffx/ui/icons/disk.png")));
    jbsave.setActionCommand("Save");
    jbsave.setToolTipText("Save the Active *.KEY File");
    jbsave.addActionListener(this);
    jbsave.setMargin(insets);
    toolBar.add(jbsave);
    JButton jbsaveas = new JButton(new ImageIcon(loader.getResource("ffx/ui/icons/page_save.png")));
    jbsaveas.setActionCommand("Save As...");
    jbsaveas.setToolTipText("Save the Active *.KEY File Under a New Name");
    jbsaveas.addActionListener(this);
    jbsaveas.setMargin(insets);
    toolBar.add(jbsaveas);
    JButton jbclose = new JButton(new ImageIcon(loader.getResource("ffx/ui/icons/cancel.png")));
    jbclose.setActionCommand("Close");
    jbclose.setToolTipText("Close the Active *.KEY File");
    jbclose.addActionListener(this);
    jbclose.setMargin(insets);
    //toolBar.add(jbclose);
    toolBar.addSeparator();
    groupComboBox.setMaximumSize(groupComboBox.getPreferredSize());
    groupComboBox.addActionListener(this);
    groupComboBox.setEditable(false);
    toolBar.add(groupComboBox);
    toolBar.addSeparator();
    ImageIcon icinfo = new ImageIcon(loader.getResource("ffx/ui/icons/information.png"));
    descriptCheckBox = new JCheckBoxMenuItem(icinfo);
    descriptCheckBox.setActionCommand("Description");
    descriptCheckBox.setToolTipText("Show/Hide Keyword Descriptions");
    descriptCheckBox.addActionListener(this);
    descriptCheckBox.setMargin(insets);
    toolBar.add(descriptCheckBox);
    toolBar.add(new JLabel(""));
    toolBar.setBorderPainted(false);
    toolBar.setFloatable(false);
    toolBar.setRollover(true);
    toolBar.setOrientation(JToolBar.HORIZONTAL);
}

From source file:org.openmicroscopy.shoola.util.ui.UIUtilities.java

/** 
 * Create a separator to add to a toolbar. The separator needs to be 
 * set when the layout of the toolbar is reset.
 * //w w w.j a  v a  2  s.  c  o  m
 * @param button   The button to add to the toolBar. The height of the 
 *                separator depends of the insets of the button.
 * @param icon     The icon to add to the button. The height of the 
  *                 separator depends of the height of the icon.
 * @return See below.
 */
public static JSeparator toolBarSeparator(JButton button, Icon icon) {
    JSeparator separator = new JSeparator(SwingConstants.VERTICAL);
    if (button == null)
        return separator;
    Insets i = button.getInsets();
    int h = 0;
    if (icon != null)
        h = icon.getIconHeight();
    Dimension d = new Dimension(SEPARATOR_WIDTH, i.top + h + i.bottom);
    separator.setPreferredSize(d);
    separator.setSize(d);
    return separator;
}