Search in sources :

Example 21 with JComponent

use of javax.swing.JComponent in project binnavi by google.

the class CModuleNodeMenuBuilder method addPluginMenus.

/**
   * Adds the plugin-generated menus to the context menu.
   *
   * @param menu The context menu where the menu items are added.
   */
private void addPluginMenus(final JComponent menu) {
    final List<IModuleMenuPlugin> plugins = new ArrayList<>();
    for (final IPlugin<IPluginInterface> plugin : PluginInterface.instance().getPluginRegistry()) {
        if (plugin instanceof IModuleMenuPlugin) {
            plugins.add((IModuleMenuPlugin) plugin);
        }
    }
    boolean addedSeparator = false;
    for (final IModuleMenuPlugin plugin : plugins) {
        try {
            final List<JComponent> menuItems = plugin.extendModuleMenu(getPluginModules());
            if (menuItems != null) {
                for (final JComponent menuItem : menuItems) {
                    if (!addedSeparator) {
                        menu.add(new JSeparator());
                        addedSeparator = true;
                    }
                    menu.add(menuItem);
                }
            }
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
            final String innerMessage = "E00093: " + "Plugin caused an unexpected exception";
            final String innerDescription = CUtilityFunctions.createDescription(String.format("The plugin %s caused an unexpected exception.", plugin.getName()), new String[] { "The plugin contains a bug." }, new String[] { "The plugin probably behaves erroneously from this point on but it remains active" });
            NaviErrorDialog.show(getParent(), innerMessage, innerDescription, exception);
        }
    }
}
Also used : IPluginInterface(com.google.security.zynamics.binnavi.api2.IPluginInterface) IModuleMenuPlugin(com.google.security.zynamics.binnavi.API.plugins.IModuleMenuPlugin) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) JSeparator(javax.swing.JSeparator)

Example 22 with JComponent

use of javax.swing.JComponent in project binnavi by google.

the class CProjectContainerNodeMenuBuilder method createMenu.

@Override
protected void createMenu(final JComponent menu) {
    menu.add(new JMenuItem(CActionProxy.proxy(new CCreateProjectAction(getParent(), database, new CNodeSelectionUpdater(getProjectTree(), findNode())))));
    final List<IProjectFolderMenuPlugin> plugins = new ArrayList<IProjectFolderMenuPlugin>();
    for (final IPlugin<IPluginInterface> plugin : PluginInterface.instance().getPluginRegistry()) {
        if (plugin instanceof IProjectFolderMenuPlugin) {
            plugins.add((IProjectFolderMenuPlugin) plugin);
        }
    }
    if (!plugins.isEmpty()) {
        menu.add(new JSeparator());
        for (final IProjectFolderMenuPlugin plugin : plugins) {
            try {
                final List<JComponent> menuItems = plugin.extendProjectFolderMenu(getPluginDatabase());
                if (menuItems != null) {
                    for (final JComponent menuItem : menuItems) {
                        menu.add(menuItem);
                    }
                }
            } catch (final Exception exception) {
                CUtilityFunctions.logException(exception);
                final String innerMessage = "E00089: " + "Plugin caused an unexpected exception";
                final String innerDescription = CUtilityFunctions.createDescription(String.format("The plugin %s caused an unexpected exception.", plugin.getName()), new String[] { "The plugin contains a bug." }, new String[] { "The plugin probably behaves erroneously from this point on but it remains active" });
                NaviErrorDialog.show(getParent(), innerMessage, innerDescription, exception);
            }
        }
    }
}
Also used : IPluginInterface(com.google.security.zynamics.binnavi.api2.IPluginInterface) ArrayList(java.util.ArrayList) JComponent(javax.swing.JComponent) CCreateProjectAction(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Actions.CCreateProjectAction) JSeparator(javax.swing.JSeparator) IProjectFolderMenuPlugin(com.google.security.zynamics.binnavi.API.plugins.IProjectFolderMenuPlugin) CNodeSelectionUpdater(com.google.security.zynamics.binnavi.Gui.MainWindow.ProjectTree.Updaters.CNodeSelectionUpdater) JMenuItem(javax.swing.JMenuItem)

Example 23 with JComponent

use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.

the class bug7170310 method check.

private static void check() {
    try {
        JViewport vp = null;
        for (Component c : tabbedPane.getComponents()) {
            if (c instanceof JViewport) {
                vp = (JViewport) c;
                break;
            }
        }
        JComponent v = (JComponent) vp.getView();
        Rectangle vr = vp.getViewRect();
        Dimension vs = v.getSize();
        // The tab view must be scrolled to the end so that the last tab is visible
        if (vs.width != (vr.x + vr.width)) {
            throw new RuntimeException("tabScroller.tabPanel view is positioned incorrectly: " + vs.width + " vs " + (vr.x + vr.width));
        }
    } catch (Exception e) {
        exception = e;
    }
}
Also used : JViewport(javax.swing.JViewport) JComponent(javax.swing.JComponent) Rectangle(java.awt.Rectangle) Dimension(java.awt.Dimension) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 24 with JComponent

use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.

the class TSFrame method createGui.

public static Frame createGui(final boolean useSwing, final boolean useShape, final boolean useTransl, final boolean useNonOpaque, final float factor) {
    Frame frame;
    done = false;
    if (useNonOpaque) {
        if (useSwing) {
            frame = new NonOpaqueJFrame();
        //                frame = new NonOpaqueJAppletFrame(gc);
        } else {
            frame = new NonOpaqueFrame();
        }
        animateComponent(frame);
    } else if (useSwing) {
        frame = new JFrame("Swing Frame");
        JComponent p = new JButton("Swing!");
        p.setPreferredSize(new Dimension(200, 100));
        frame.add("North", p);
        p = new MyJPanel();
        animateComponent(p);
        frame.add("Center", p);
    } else {
        frame = new Frame("AWT Frame") {

            public void paint(Graphics g) {
                g.setColor(Color.red);
                g.fillRect(0, 0, 100, 100);
            }
        };
        frame.setLayout(new BorderLayout());
        Canvas c = new MyCanvas();
        frame.add("North", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("Center", c);
        animateComponent(c);
        c = new MyCanvas();
        frame.add("South", c);
        animateComponent(c);
    }
    final Frame finalFrame = frame;
    frame.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            finalFrame.dispose();
            done = true;
        }
    });
    frame.setPreferredSize(new Dimension(800, 600));
    if (useShape) {
        frame.setUndecorated(true);
    }
    frame.setLocation(450, 10);
    frame.pack();
    GraphicsDevice gd = frame.getGraphicsConfiguration().getDevice();
    if (useShape) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSPARENT)) {
            System.out.println("applying PERPIXEL_TRANSPARENT");
            frame.setShape(new Ellipse2D.Double(0, 0, frame.getWidth(), frame.getHeight() / 3));
            frame.setTitle("PERPIXEL_TRANSPARENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSPARENT unsupported");
        }
    }
    if (useTransl) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
            System.out.println("applying TRANSLUCENT");
            frame.setOpacity(factor);
            frame.setTitle("TRANSLUCENT");
        } else {
            System.out.println("Passed: TRANSLUCENT unsupported");
        }
    }
    if (useNonOpaque) {
        if (gd.isWindowTranslucencySupported(WindowTranslucency.PERPIXEL_TRANSLUCENT)) {
            System.out.println("applying PERPIXEL_TRANSLUCENT");
            frame.setBackground(new Color(0, 0, 0, 0));
            frame.setTitle("PERPIXEL_TRANSLUCENT");
        } else {
            System.out.println("Passed: PERPIXEL_TRANSLUCENT unsupported");
        }
    }
    frame.setVisible(true);
    return frame;
}
Also used : JFrame(javax.swing.JFrame) Frame(java.awt.Frame) MouseEvent(java.awt.event.MouseEvent) Canvas(java.awt.Canvas) Color(java.awt.Color) JButton(javax.swing.JButton) JComponent(javax.swing.JComponent) MouseAdapter(java.awt.event.MouseAdapter) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) Ellipse2D(java.awt.geom.Ellipse2D) Graphics(java.awt.Graphics) GraphicsDevice(java.awt.GraphicsDevice) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent)

Example 25 with JComponent

use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.

the class BMPCompressionTest method showDiff.

private static void showDiff(final BufferedImage in, final BufferedImage out) {
    final int width = in.getWidth();
    final int height = in.getHeight();
    JFrame f = new JFrame("");
    f.getContentPane().add(new JComponent() {

        public Dimension getPreferredSize() {
            return new Dimension(2 * width + 2, height);
        }

        public void paintComponent(Graphics g) {
            g.setColor(Color.black);
            g.drawImage(in, 0, 0, null);
            g.drawImage(out, width + 2, 0, null);
        }
    });
    f.pack();
    f.setVisible(true);
}
Also used : Graphics(java.awt.Graphics) JFrame(javax.swing.JFrame) JComponent(javax.swing.JComponent) Dimension(java.awt.Dimension)

Aggregations

JComponent (javax.swing.JComponent)159 Component (java.awt.Component)30 JButton (javax.swing.JButton)22 JPanel (javax.swing.JPanel)22 BorderLayout (java.awt.BorderLayout)18 Dimension (java.awt.Dimension)17 Insets (java.awt.Insets)15 JLabel (javax.swing.JLabel)15 ActionEvent (java.awt.event.ActionEvent)11 JFrame (javax.swing.JFrame)11 Color (java.awt.Color)10 ActionListener (java.awt.event.ActionListener)10 ArrayList (java.util.ArrayList)10 Point (java.awt.Point)9 Container (java.awt.Container)8 GridBagConstraints (java.awt.GridBagConstraints)8 JTextField (javax.swing.JTextField)8 Graphics (java.awt.Graphics)7 GridBagLayout (java.awt.GridBagLayout)7 File (java.io.File)7