Search in sources :

Example 1 with JButton

use of javax.swing.JButton in project zookeeper by apache.

the class Toolbar method init.

private void init() {
    toolbar.setFloatable(false);
    for (Button button : Button.values()) {
        JButton jbutton = button.createJButton(iconResource);
        buttons.put(button, jbutton);
        toolbar.add(jbutton);
    }
}
Also used : JButton(javax.swing.JButton) JButton(javax.swing.JButton)

Example 2 with JButton

use of javax.swing.JButton in project checkstyle by checkstyle.

the class OperatorHelper method myMethod.

//indent:4 exp:4
private void myMethod() {
    //indent:4 exp:4
    class localFoo {
    }
    class localFoo2 {

        //indent:12 exp:12
        int x;

        //indent:12 exp:12
        int func() {
            return 3;
        }
    }
    //indent:8 exp:8
    //     : this is broken right now: //indent:8 exp:8
    //   1) this is both an expression and an OBJBLOCK //indent:8 exp:8
    //   2) methods aren't yet parsed //indent:8 exp:8
    //   3) only CLASSDEF is handled now, not OBJBLOCK //indent:8 exp:8
    new JButton().addActionListener(new //indent:8 exp:8
    ActionListener() {

        //indent:8 exp:8
        public void actionPerformed(ActionEvent e) {
        //indent:12 exp:12
        }
    });
    //indent:8 exp:8
    new JButton().addActionListener(new //indent:8 exp:8
    ActionListener() {

        public void actionPerformed(ActionEvent e) {
            //indent:12 exp:12
            //indent:16 exp:16
            int i = 2;
        }
    });
    //indent:8 exp:8
    Object o = new //indent:8 exp:8
    ActionListener() {

        //indent:8 exp:8
        public void actionPerformed(ActionEvent e) {
        //indent:12 exp:12
        }
    };
    //indent:8 exp:8
    myfunc2(//indent:8 exp:8
    10, //indent:8 exp:8
    10, //indent:8 exp:8
    10, myfunc3(//indent:12 exp:>=12
    11, //indent:12 exp:>=12
    11, 11, //indent:16 exp:>=16
    11), //indent:12 exp:>=12
    10, //indent:12 exp:>=12
    10, //indent:12 exp:>=12
    10);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton)

Example 3 with JButton

use of javax.swing.JButton in project checkstyle by checkstyle.

the class MainFrame method createButtonsPanel.

/**
     * Create buttons panel.
     * @return buttons panel.
     */
private JPanel createButtonsPanel() {
    final JButton openFileButton = new JButton(new FileSelectionAction());
    openFileButton.setMnemonic(KeyEvent.VK_S);
    openFileButton.setText("Open File");
    reloadAction.setEnabled(false);
    final JButton reloadFileButton = new JButton(reloadAction);
    reloadFileButton.setMnemonic(KeyEvent.VK_R);
    reloadFileButton.setText("Reload File");
    final JComboBox<ParseMode> modesCombobox = new JComboBox<>(ParseMode.values());
    modesCombobox.setSelectedIndex(0);
    modesCombobox.addActionListener(e -> {
        model.setParseMode((ParseMode) modesCombobox.getSelectedItem());
        reloadAction.actionPerformed(null);
    });
    final JLabel modesLabel = new JLabel("Modes:", SwingConstants.RIGHT);
    final int leftIndentation = 10;
    modesLabel.setBorder(BorderFactory.createEmptyBorder(0, leftIndentation, 0, 0));
    final JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new GridLayout(1, 2));
    buttonPanel.add(openFileButton);
    buttonPanel.add(reloadFileButton);
    final JPanel modesPanel = new JPanel();
    modesPanel.add(modesLabel);
    modesPanel.add(modesCombobox);
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(buttonPanel);
    mainPanel.add(modesPanel, BorderLayout.LINE_END);
    return mainPanel;
}
Also used : JPanel(javax.swing.JPanel) GridLayout(java.awt.GridLayout) JComboBox(javax.swing.JComboBox) BorderLayout(java.awt.BorderLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) ParseMode(com.puppycrawl.tools.checkstyle.gui.MainFrameModel.ParseMode)

Example 4 with JButton

use of javax.swing.JButton in project OpenNotebook by jaltekruse.

the class ObjectPropertiesFrame method generatePanel.

/**
	 * Generates a menu for adjusting the properties of a mathobject.
	 * 
	 * @param o - object to base menu panel on
	 */
public void generatePanel(MathObject o) {
    System.out.println("generate panel" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (o == null) {
        return;
    }
    this.getContentPane().removeAll();
    object = o;
    JPanel panel = mainPanel;
    mainPanel.removeAll();
    adjusters.removeAllElements();
    listAdjusters.removeAllElements();
    this.setTitle(o.getType());
    JTabbedPane panelTabs = null;
    JPanel tabOneContents = null, tabTwoContents = null;
    GridBagConstraints con = new GridBagConstraints();
    con.fill = GridBagConstraints.BOTH;
    con.weightx = 1;
    con.weighty = 1;
    con.insets = new Insets(2, 2, 2, 2);
    con.gridx = 0;
    con.gridy = 0;
    System.out.println("end init stuff" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (o instanceof GraphObject || (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())) {
        // there are too many attributes and actions for the graph to put them all in one panel
        // add a tabbed pane to make it more reasonable and avoid scrolling
        panelTabs = new JTabbedPane();
        this.getContentPane().add(panelTabs);
        tabOneContents = new JPanel();
        tabOneContents.setLayout(new GridBagLayout());
        tabTwoContents = new JPanel();
        tabTwoContents.setLayout(new GridBagLayout());
        System.out.println("1 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        JScrollPane tabScrollPane = new JScrollPane(panelTabs);
        tabScrollPane.getVerticalScrollBar().setUnitIncrement(16);
        tabScrollPane.getHorizontalScrollBar().setUnitIncrement(16);
        System.out.println("2 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        tabScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        if (o instanceof GraphObject) {
            panelTabs.add("Nav", tabOneContents);
            panelTabs.add("Grid", tabTwoContents);
            panel = tabOneContents;
        } else if (o instanceof ExpressionObject) {
            panelTabs.add("Expression", tabOneContents);
            panelTabs.add("Solve", tabTwoContents);
            panel = tabOneContents;
        }
        System.out.println("3 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
        this.getContentPane().add(tabScrollPane);
        System.out.println("4 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    } else {
        this.getContentPane().add(scrollPane);
    }
    System.out.println("done with tabs " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    con.weighty = .01;
    JPanel actionPics = new JPanel();
    actionPics.setLayout(new GridLayout(0, 4, 4, 4));
    JPanel otherActions = new JPanel();
    otherActions.setLayout(new GridLayout(0, 1, 4, 4));
    ImageIcon pic;
    JButton button;
    if (!notebookPanel.isInStudentMode()) {
        for (final String s : o.getActions()) {
            pic = getIconForAction(s);
            if (pic != null)
                createButton(s, 0, 0, 0, 0, actionPics);
            else
                createButton(s, 0, 0, 0, 0, otherActions);
        }
    }
    System.out.println("teacher actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    boolean skipAction;
    for (final String s : o.getStudentActions()) {
        skipAction = false;
        if (object instanceof GraphObject) {
            // use more intuitive
            for (String str : graphNavActions) {
                if (s.equals(str)) {
                    skipAction = true;
                    break;
                }
            }
        }
        if (object instanceof ExpressionObject) {
            // in a separate panel to make the list of actions smaller
            for (String str : expressionOpActions) {
                if (s.equals(str)) {
                    skipAction = true;
                    break;
                }
            }
        }
        if (skipAction) {
            continue;
        }
        pic = getIconForAction(s);
        if (pic != null)
            createButton(s, 0, 0, 0, 0, actionPics);
        else
            createButton(s, 0, 0, 0, 0, otherActions);
    }
    System.out.println("student actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (otherActions.getComponentCount() != 0) {
        // only add panel for actions if components have been added to it
        panel.add(otherActions, con);
        con.gridy++;
    }
    if (actionPics.getComponentCount() != 0) {
        // only add panel for action pics if components have been added to it
        panel.add(actionPics, con);
        con.gridy++;
    }
    if (object instanceof GraphObject) {
        panel.add(createGraphNavigator(), con);
        con.gridy++;
    }
    if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode()) {
        // there are too many attributes and actions for the expression to put them all in one panel
        // added a tabbed pane to make it more reasonable and avoid scrolling
        // this line moves to the other tab to place components there
        panel = tabTwoContents;
    }
    if (object instanceof ExpressionObject) {
        panel.add(createExpressionModifier(), con);
        con.gridy++;
    }
    //Switch back to tab one if in teacher mode, to allow attribute adjusters to be on the first tab
    if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())
        panel = tabOneContents;
    con.fill = GridBagConstraints.HORIZONTAL;
    if (o instanceof GraphObject) {
        // there are too many attributes and actions for the graph to put them all in one panel
        // added a tabbed pane to make it more reasonable and avoid scrolling
        // this line moves to the other tab to place components there
        panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        con.anchor = GridBagConstraints.PAGE_START;
        tabTwoContents.add(panel, con);
        con.anchor = GridBagConstraints.CENTER;
    }
    con.fill = GridBagConstraints.BOTH;
    for (MathObjectAttribute mAtt : o.getAttributes()) {
        if (notebookPanel.isInStudentMode() && mAtt.isStudentEditable() || (!notebookPanel.isInStudentMode() && mAtt.isUserEditable())) {
            // only show editing dialog if in teacher mode (not student)
            //or if the attribute has been left student editable
            adjusters.add(getAdjuster(mAtt, notebookPanel, panel));
            if (mAtt instanceof StringAttribute) {
                // make string panels stretch vertically
                con.weighty = 1;
                con.fill = GridBagConstraints.BOTH;
            } else {
                // make all others stretch very little vertically
                con.weighty = 0;
                con.fill = GridBagConstraints.HORIZONTAL;
            }
            panel.add(adjusters.get(adjusters.size() - 1), con);
            con.gridy++;
        }
    }
    System.out.println("end att adjusters:" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    con.weighty = 1;
    if (o instanceof GraphObject) {
        // see above comments about tabs for some objects
        panel = tabOneContents;
    }
    for (ListAttribute list : o.getLists()) {
        if ((notebookPanel.isInStudentMode() && list.isStudentEditable()) || (!notebookPanel.isInStudentMode() && list.isUserEditable())) {
            // only show editing dialog if in teacher mode (not student)
            //or if the attribute has been left student editable
            listAdjusters.add(new ListAdjuster(list, notebookPanel, panel));
            panel.add(listAdjusters.get(listAdjusters.size() - 1), con);
            con.gridy++;
        }
    }
    System.out.println("end lists:" + +(new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
    if (panel.getComponentCount() == 0) {
        panel.add(new JLabel("No actions for this object"), con);
    }
    panel.revalidate();
    this.pack();
    this.update();
    this.setSize(this.getWidth() + 30, this.getHeight());
    System.out.println("done making props frame" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) ImageIcon(javax.swing.ImageIcon) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) StringAttribute(doc.attributes.StringAttribute) JLabel(javax.swing.JLabel) GraphObject(doc.mathobjects.GraphObject) Date(java.util.Date) GridLayout(java.awt.GridLayout) MathObjectAttribute(doc.attributes.MathObjectAttribute) ExpressionObject(doc.mathobjects.ExpressionObject) ListAttribute(doc.attributes.ListAttribute)

Example 5 with JButton

use of javax.swing.JButton in project jna by java-native-access.

the class AlphaMaskDemo2 method run.

public void run() {
    // Must find a graphics configuration with a depth of 32 bits
    GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
    frame = new JFrame("Alpha Mask Demo");
    alphaWindow = new JWindow(frame, gconfig);
    icon = new JLabel();
    icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    alphaWindow.getContentPane().add(icon);
    JButton quit = new JButton("Quit");
    JLabel label = new JLabel("Drag this window by its image");
    label.setHorizontalAlignment(SwingConstants.CENTER);
    alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
    alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
    quit.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    MouseInputAdapter handler = new MouseInputAdapter() {

        private Point offset;

        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isLeftMouseButton(e))
                offset = e.getPoint();
        }

        public void mouseReleased(MouseEvent e) {
            offset = null;
        }

        public void mouseDragged(MouseEvent e) {
            if (offset != null) {
                Window w = (Window) e.getSource();
                Point where = e.getPoint();
                where.translate(-offset.x, -offset.y);
                Point loc = w.getLocationOnScreen();
                loc.translate(where.x, where.y);
                w.setLocation(loc.x, loc.y);
            }
        }
    };
    alphaWindow.addMouseListener(handler);
    alphaWindow.addMouseMotionListener(handler);
    JPanel p = new JPanel(new BorderLayout(8, 8));
    p.setBorder(new EmptyBorder(8, 8, 8, 8));
    p.setTransferHandler(new TransferHandler() {

        private static final long serialVersionUID = 1L;

        public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
            List<DataFlavor> list = Arrays.asList(transferFlavors);
            if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
                return true;
            }
            if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
                return true;
            }
            System.err.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
            return false;
        }

        public boolean importData(JComponent comp, Transferable t) {
            try {
                if (t.isDataFlavorSupported(URL_FLAVOR)) {
                    URL url = (URL) t.getTransferData(URL_FLAVOR);
                    setImage(Toolkit.getDefaultToolkit().getImage(url));
                    return true;
                }
                if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
                    String s = (String) t.getTransferData(URI_LIST_FLAVOR);
                    String[] uris = s.split("[\r\n]");
                    if (uris.length > 0) {
                        URL url = new URL(uris[0]);
                        setImage(Toolkit.getDefaultToolkit().getImage(url));
                        return true;
                    }
                    return false;
                }
                if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
                    Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
                    setImage(image);
                    return true;
                }
                if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
                    List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
                    File f = files.get(0);
                    URL url = new URL("file://" + f.toURI().toURL().getPath());
                    Image image = Toolkit.getDefaultToolkit().getImage(url);
                    setImage(image);
                    return true;
                }
                DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
                if (flavor != null) {
                    Reader reader = flavor.getReaderForText(t);
                    char[] buf = new char[512];
                    StringBuilder b = new StringBuilder();
                    int count;
                    // encoding wrong
                    while ((count = reader.read(buf)) > 0) {
                        for (int i = 0; i < count; i++) {
                            if (buf[i] != 0)
                                b.append(buf, i, 1);
                        }
                    }
                    String html = b.toString();
                    Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
                    Matcher m = p.matcher(html);
                    if (m.find()) {
                        URL url = new URL(m.group(1));
                        System.out.println("Load image from " + url);
                        Image image = Toolkit.getDefaultToolkit().getImage(url);
                        setImage(image);
                        return true;
                    }
                    System.err.println("Can't parse text: " + html);
                    return false;
                }
                System.err.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
            } catch (UnsupportedFlavorException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Throwable e) {
                e.printStackTrace();
            }
            return false;
        }
    });
    p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
    p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    final JSlider slider = new JSlider(0, 255, 255);
    slider.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            int value = slider.getValue();
            WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
        }
    });
    p.add(slider, BorderLayout.SOUTH);
    frame.getContentPane().add(p);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    centerOnScreen(frame);
    frame.setVisible(true);
    WindowUtils.setWindowTransparent(alphaWindow, true);
    alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4, frame.getY());
    try {
        URL url = getClass().getResource("tardis.png");
        if (url != null) {
            setImage(Toolkit.getDefaultToolkit().getImage(url));
        }
    } catch (Exception e) {
    }
}
Also used : JPanel(javax.swing.JPanel) Matcher(java.util.regex.Matcher) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) Reader(java.io.Reader) Image(java.awt.Image) URL(java.net.URL) GraphicsConfiguration(java.awt.GraphicsConfiguration) DataFlavor(java.awt.datatransfer.DataFlavor) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) JSlider(javax.swing.JSlider) List(java.util.List) ChangeListener(javax.swing.event.ChangeListener) EmptyBorder(javax.swing.border.EmptyBorder) Window(java.awt.Window) JWindow(javax.swing.JWindow) Pattern(java.util.regex.Pattern) MouseEvent(java.awt.event.MouseEvent) JWindow(javax.swing.JWindow) JComponent(javax.swing.JComponent) Transferable(java.awt.datatransfer.Transferable) JLabel(javax.swing.JLabel) Point(java.awt.Point) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) TransferHandler(javax.swing.TransferHandler) File(java.io.File) MouseInputAdapter(javax.swing.event.MouseInputAdapter)

Aggregations

JButton (javax.swing.JButton)923 JPanel (javax.swing.JPanel)408 ActionEvent (java.awt.event.ActionEvent)389 ActionListener (java.awt.event.ActionListener)317 JLabel (javax.swing.JLabel)278 JScrollPane (javax.swing.JScrollPane)166 BoxLayout (javax.swing.BoxLayout)158 FlowLayout (java.awt.FlowLayout)142 BorderLayout (java.awt.BorderLayout)138 Dimension (java.awt.Dimension)138 Insets (java.awt.Insets)114 JTextField (javax.swing.JTextField)114 GridBagLayout (java.awt.GridBagLayout)110 JCheckBox (javax.swing.JCheckBox)103 GridBagConstraints (java.awt.GridBagConstraints)95 ImageIcon (javax.swing.ImageIcon)95 JTable (javax.swing.JTable)67 JDialog (javax.swing.JDialog)65 JComboBox (javax.swing.JComboBox)56 JTextArea (javax.swing.JTextArea)56