private void setActive(boolean active) { myCloseButton.putClientProperty("paintActive", Boolean.valueOf(active)); if (getWindowDecorationStyle() == JRootPane.FRAME) { myIconifyButton.putClientProperty("paintActive", Boolean.valueOf(active)); myToggleButton.putClientProperty("paintActive", Boolean.valueOf(active)); } getRootPane().repaint(); }
public static void main(String[] args) { JButton button = new JButton(); button.putClientProperty("JButton.buttonType", "metal"); JButton button2 = new JButton(); LayoutStyle style = new AquaLayoutStyle(); int gap = style.getPreferredGap(button, button2, LayoutStyle.RELATED, SwingConstants.EAST, null); System.err.println("gap= " + gap); button.putClientProperty("JButton.buttonType", "square"); button2.putClientProperty("JButton.buttonType", "square"); gap = style.getPreferredGap(button, button2, LayoutStyle.RELATED, SwingConstants.EAST, null); System.err.println("gap= " + gap); }
@Override public JComponent createUI( DescriptionType inputOrOutput, Map<URI, Object> dataMap, Orientation orientation) { // Create the main panel JComponent component = new JPanel(new MigLayout("fill")); boolean isOptional = false; if (inputOrOutput instanceof InputDescriptionType) { isOptional = ((InputDescriptionType) inputOrOutput).getMinOccurs().equals(new BigInteger("0")); } // Display the SourceCA into a JTextField JTextField jtf = new JTextField(); jtf.setToolTipText(inputOrOutput.getAbstract().get(0).getValue()); // "Save" the CA inside the JTextField jtf.getDocument().putProperty(DATA_MAP_PROPERTY, dataMap); URI uri = URI.create(inputOrOutput.getIdentifier().getValue()); jtf.getDocument().putProperty(URI_PROPERTY, uri); // add the listener for the text changes in the JTextField jtf.getDocument() .addDocumentListener( EventHandler.create(DocumentListener.class, this, "saveDocumentText", "document")); if (isOptional) { if (dataMap.containsKey(uri)) { jtf.setText(dataMap.get(uri).toString()); } } GeometryData geometryData = null; if (inputOrOutput instanceof InputDescriptionType) { geometryData = (GeometryData) ((InputDescriptionType) inputOrOutput).getDataDescription().getValue(); } // If the DescriptionType is an output, there is nothing to show, so exit if (geometryData == null) { return null; } component.add(jtf, "growx"); if (orientation.equals(Orientation.VERTICAL)) { JPanel buttonPanel = new JPanel(new MigLayout()); // Create the button Browse JButton pasteButton = new JButton(ToolBoxIcon.getIcon(ToolBoxIcon.PASTE)); // "Save" the sourceCA and the JTextField in the button pasteButton.putClientProperty(TEXT_FIELD_PROPERTY, jtf); pasteButton.setBorderPainted(false); pasteButton.setContentAreaFilled(false); pasteButton.setMargin(new Insets(0, 0, 0, 0)); // Add the listener for the click on the button pasteButton.addActionListener(EventHandler.create(ActionListener.class, this, "onPaste", "")); buttonPanel.add(pasteButton); component.add(buttonPanel, "dock east"); } return component; }
private static JButton createButton(String accessibleName, Icon icon, Action action) { JButton button = new JButton() { boolean mouseOverButton = false; { enableEvents(AWTEvent.MOUSE_EVENT_MASK); addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { mouseOverButton = true; repaint(); } @Override public void mouseExited(MouseEvent e) { mouseOverButton = false; repaint(); } }); } @Override protected void paintComponent(Graphics g) { final Window window = SwingUtilities.windowForComponent(this); float alpha = window.isActive() && mouseOverButton ? 1f : 0.5f; final GraphicsConfig config = GraphicsUtil.paintWithAlpha(g, alpha); getIcon().paintIcon(this, g, 0, 0); config.restore(); } }; button.setFocusPainted(false); button.setFocusable(false); button.setOpaque(false); button.putClientProperty("paintActive", Boolean.TRUE); button.putClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY, accessibleName); button.setBorder(JBUI.Borders.empty()); button.setText(null); button.setAction(action); button.setIcon(icon); return button; }
public JButton createButton(Action a) { JButton b = new JButton() { public Dimension getMaximumSize() { int width = Short.MAX_VALUE; int height = super.getMaximumSize().height; return new Dimension(width, height); } }; // setting the following client property informs the button to show // the action text as it's name. The default is to not show the // action text. b.putClientProperty("displayActionText", Boolean.TRUE); b.setAction(a); // b.setAlignmentX(JButton.CENTER_ALIGNMENT); return b; }
Spacer(ZoneModel model, int index, SpacerHandle knobHandle) { this.model = model; this.index = index; this.knobHandle = knobHandle; knobPainter = new KnobPainter(this); setOpaque(false); setCursor(SliderCursor); initKeyMaps(); Icon icon = getIcon("unstick"); Icon pressedIcon = getIcon("unstickPressed"); Icon highlightIcon = getIcon("unstickHighlight"); unstickButton = new JButton(icon); unstickButton.setSize(icon.getIconWidth(), icon.getIconHeight()); unstickButton.setPressedIcon(pressedIcon); unstickButton.setRolloverEnabled(true); unstickButton.setRolloverIcon(highlightIcon); unstickButton.setBorder(null); unstickButton.putClientProperty(SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY, Boolean.TRUE); unstickButton.setBorderPainted(false); unstickButton.setRolloverEnabled(true); unstickButton.setOpaque(false); unstickButton.setCursor(ClickCursor); unstickButton.setFocusable(false); unstickButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { Spacer.this.model.removePoint(Spacer.this.index); } }); if (model.containsPoint(index)) { add(unstickButton); } model.addZoneModelListener(this); setFocusable(true); addFocusListener(this); addMouseListener(this); }
public static JToolBar getToolbar(String label, int size, boolean hasStrings) { JToolBar toolBar = new JToolBar(); JButton buttonCut = new JButton(hasStrings ? "cut" : null, getIcon(size + "/edit-cut")); buttonCut.putClientProperty(SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE); toolBar.add(buttonCut); JButton buttonCopy = new JButton(hasStrings ? "copy" : null, getIcon(size + "/edit-copy")); buttonCopy.putClientProperty(SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE); buttonCopy.setEnabled(false); toolBar.add(buttonCopy); JButton buttonPaste = new JButton(getIcon(size + "/edit-paste")); toolBar.add(buttonPaste); JButton buttonSelectAll = new JButton(getIcon(size + "/edit-select-all")); toolBar.add(buttonSelectAll); JButton buttonDelete = new JButton(getIcon(size + "/edit-delete")); toolBar.add(buttonDelete); toolBar.addSeparator(); // add an inner toolbar to check the painting of toolbar // gradient and drop shadows under different skins. JToolBar innerToolbar = new JToolBar(JToolBar.HORIZONTAL); innerToolbar.setFloatable(false); JToggleButton buttonFormatCenter = new JToggleButton(getIcon(size + "/format-justify-center")); buttonFormatCenter.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 5.0f); innerToolbar.add(buttonFormatCenter); JToggleButton buttonFormatLeft = new JToggleButton(getIcon(size + "/format-justify-left")); innerToolbar.add(buttonFormatLeft); JToggleButton buttonFormatRight = new JToggleButton(getIcon(size + "/format-justify-right")); innerToolbar.add(buttonFormatRight); JToggleButton buttonFormatFill = new JToggleButton(getIcon(size + "/format-justify-fill")); buttonFormatFill.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 0.0f); innerToolbar.add(buttonFormatFill); toolBar.add(innerToolbar); toolBar.addSeparator(); if (size > 20) { JToolBar innerToolbar2 = new JToolBar(JToolBar.HORIZONTAL); innerToolbar2.setFloatable(false); JPanel innerPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); innerToolbar2.add(innerPanel, BorderLayout.CENTER); final JToggleButton buttonStyleBold = new JToggleButton(getIcon(size + "/format-text-bold")); Set<Side> rightSide = EnumSet.of(Side.RIGHT); buttonStyleBold.putClientProperty(SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, rightSide); buttonStyleBold.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 3.0f); final JToggleButton buttonStyleItalic = new JToggleButton(getIcon(size + "/format-text-italic")); buttonStyleItalic.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 0.0f); buttonStyleItalic.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, rightSide); final JToggleButton buttonStyleUnderline = new JToggleButton(getIcon(size + "/format-text-underline")); buttonStyleUnderline.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 0.0f); buttonStyleUnderline.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, rightSide); final JToggleButton buttonStyleStrikethrough = new JToggleButton(getIcon(size + "/format-text-strikethrough")); buttonStyleStrikethrough.putClientProperty( SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, EnumSet.of(Side.LEFT)); buttonStyleStrikethrough.putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS, 3.0f); buttonStyleBold.setSelected(true); innerPanel.add(buttonStyleBold); innerPanel.add(buttonStyleItalic); innerPanel.add(buttonStyleUnderline); innerPanel.add(buttonStyleStrikethrough); toolBar.add(innerToolbar2); } toolBar.add(Box.createGlue()); JButton buttonExit = new JButton(getIcon(size + "/process-stop")); buttonExit.setToolTipText("Closes the test application"); buttonExit.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); toolBar.add(buttonExit); return toolBar; }
protected JComponent createSouthPanel() { JPanel panel = new JPanel(new BorderLayout()); panel.setBorder(BorderFactory.createEmptyBorder(8, 0, 0, 0)); JPanel buttonPanel = new JPanel(); if (SystemInfo.isMac) { panel.add(buttonPanel, BorderLayout.EAST); buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS)); if (!UIUtil.isUnderDarcula()) { myHelpButton.putClientProperty("JButton.buttonType", "help"); } if (UIUtil.isUnderAquaLookAndFeel()) { myHelpButton.setText(""); } JPanel leftPanel = new JPanel(); if (ApplicationInfo.contextHelpAvailable()) { leftPanel.add(myHelpButton); } leftPanel.add(myCancelButton); panel.add(leftPanel, BorderLayout.WEST); if (mySteps.size() > 1) { buttonPanel.add(Box.createHorizontalStrut(5)); buttonPanel.add(myPreviousButton); } buttonPanel.add(Box.createHorizontalStrut(5)); buttonPanel.add(myNextButton); } else { panel.add(buttonPanel, BorderLayout.CENTER); GroupLayout layout = new GroupLayout(buttonPanel); buttonPanel.setLayout(layout); layout.setAutoCreateGaps(true); final GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup(); final GroupLayout.ParallelGroup vGroup = layout.createParallelGroup(); final Collection<Component> buttons = ContainerUtil.newArrayListWithExpectedSize(5); final boolean helpAvailable = ApplicationInfo.contextHelpAvailable(); if (helpAvailable && UIUtil.isUnderGTKLookAndFeel()) { add(hGroup, vGroup, buttons, myHelpButton); } add(hGroup, vGroup, null, Box.createHorizontalGlue()); if (mySteps.size() > 1) { add(hGroup, vGroup, buttons, myPreviousButton); } add(hGroup, vGroup, buttons, myNextButton, myCancelButton); if (helpAvailable && !UIUtil.isUnderGTKLookAndFeel()) { add(hGroup, vGroup, buttons, myHelpButton); } layout.setHorizontalGroup(hGroup); layout.setVerticalGroup(vGroup); layout.linkSize(buttons.toArray(new Component[buttons.size()])); } myPreviousButton.setEnabled(false); myPreviousButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doPreviousAction(); } }); myNextButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { if (isLastStep()) { // Commit data of current step and perform OK action final Step currentStep = mySteps.get(myCurrentStep); LOG.assertTrue(currentStep != null); try { currentStep._commit(true); doOKAction(); } catch (final CommitStepException exc) { String message = exc.getMessage(); if (message != null) { Messages.showErrorDialog(myContentPanel, message); } } } else { doNextAction(); } } }); myCancelButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { doCancelAction(); } }); myHelpButton.addActionListener( new ActionListener() { public void actionPerformed(final ActionEvent e) { helpAction(); } }); return panel; }