Example usage for javax.swing JButton setSize

List of usage examples for javax.swing JButton setSize

Introduction

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

Prototype

public void setSize(int width, int height) 

Source Link

Document

Resizes this component so that it has width width and height height .

Usage

From source file:snepsui.Interface.DrawNetwork.java

/**
 * Initializes the components in the DrawNetwork panel
 *///from   ww w . j a v a 2  s. co  m
private void initGUI() {
    nodesList = new LinkedList<Node>();
    molNodes = new Hashtable<String, CaseFrame>();
    builtMolNodes = new Hashtable<String, Node>();

    this.setPreferredSize(new Dimension(815, 600));

    graph = new DirectedOrderedSparseMultigraph<String, String>();

    this.layout = new StaticLayout<String, String>(graph, new Dimension(700, 450));

    shape = new Transformer<String, Integer>() {
        public Integer transform(String vertex) {
            int stringLength = 0;
            if (molNodes.containsKey(vertex)) {
                stringLength = 3;
            } else {
                for (Node node : nodesList) {
                    if (vertex.equals(node.getIdentifier())) {
                        stringLength = node.getIdentifier().length();
                    }
                }
            }
            return stringLength;
        }
    };

    vertexPaint = new Transformer<String, Paint>() {
        public Paint transform(String vertex) {
            if (molNodes.containsKey(vertex)) {
                if (builtMolNodes.containsKey(vertex)) {
                    Node node = builtMolNodes.get(vertex);
                    if (node.getClass().getSimpleName().equals("PatternNode")) {
                        return Color.blue;
                    } else if (node.getClass().getSimpleName().equals("ClosedNode")) {
                        return Color.yellow;
                    }
                } else
                    return Color.white;
            } else {
                for (Node node : nodesList) {
                    if (node.getIdentifier().equals(vertex)) {
                        if (node.getClass().getSimpleName().equals("BaseNode")) {
                            return Color.green;
                        } else if (node.getClass().getSimpleName().equals("VariableNode")) {
                            return Color.gray;
                        } else if (node.getClass().getSimpleName().equals("PatternNode")) {
                            return Color.blue;
                        } else if (node.getClass().getSimpleName().equals("ClosedNode")) {
                            return Color.yellow;
                        } else {
                            return Color.magenta;
                        }
                    }
                }
            }
            return Color.white;
        }
    };

    edgeLabel = new Transformer<String, String>() {
        public String transform(String edge) {
            String result = "";

            if (edge.isEmpty())
                graph.removeEdge("");
            vv.repaint();
            try {
                result = edge.substring(0, edge.indexOf(":"));
            } catch (StringIndexOutOfBoundsException e) {

            }
            return result;
        }
    };

    VertexShapeSizeAspect<String> vssa = new VertexShapeSizeAspect<String>(graph, shape);

    vv = new VisualizationViewer<String, String>(layout, new Dimension(700, 470));
    vv.setBackground(Color.white);

    vv.getRenderContext().setVertexLabelTransformer(MapTransformer.<String, String>getInstance(
            LazyMap.<String, String>decorate(new HashMap<String, String>(), new ToStringLabeller<String>())));
    vv.getRenderContext().setEdgeLabelTransformer(MapTransformer.<String, String>getInstance(
            LazyMap.<String, String>decorate(new HashMap<String, String>(), new ToStringLabeller<String>())));
    vv.setVertexToolTipTransformer(vv.getRenderContext().getVertexLabelTransformer());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    vv.getRenderContext().setVertexShapeTransformer(vssa);
    vv.getRenderContext()
            .setEdgeLabelClosenessTransformer(new ConstantDirectionalEdgeValueTransformer(0.5, 0.5));
    vv.getRenderContext().setEdgeLabelTransformer(edgeLabel);
    vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
    vv.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            point = e.getPoint();
        }

        public void mouseReleased(MouseEvent e) {
            vv.repaint();
        }
    });
    vssa.setScaling(true);

    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    this.add(panel);
    Factory<String> vertexFactory = new VertexFactory();
    Factory<String> edgeFactory = new EdgeFactory();

    final EditingModalGraphMouse<String, String> graphMouse = new EditingModalGraphMouse<String, String>(
            vv.getRenderContext(), vertexFactory, edgeFactory);

    graphMouse.add(new CustomEditingPopupGraphMousePlugin<String>(vertexFactory, edgeFactory));
    graphMouse.remove(graphMouse.getPopupEditingPlugin());

    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    graphMouse.setMode(ModalGraphMouse.Mode.EDITING);

    final ScalingControl scaler = new CrossoverScalingControl();

    vv.scaleToLayout(scaler);

    String path = "src/snepsui/Interface/resources/icons/";

    JButton plus = new JButton();
    plus.setIcon(new ImageIcon(path + "zoom_in.png"));
    plus.setSize(18, 18);
    plus.setFocusPainted(false);
    plus.setBorderPainted(false);
    plus.setContentAreaFilled(false);
    plus.setMargin(new Insets(0, 0, 0, 0));
    plus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });

    JButton minus = new JButton();
    minus.setIcon(new ImageIcon(path + "zoom_out.png"));
    minus.setSize(18, 18);
    minus.setFocusPainted(false);
    minus.setBorderPainted(false);
    minus.setContentAreaFilled(false);
    minus.setMargin(new Insets(0, 0, 0, 0));
    minus.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JPanel scaleGrid = new JPanel(new GridLayout(1, 2));
    scaleGrid.setBorder(BorderFactory.createTitledBorder("Zoom"));

    JButton colors = new JButton(new ImageIcon(path + "colors.png"));
    colors.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(getRootPane(), new NodeColors());
        }
    });

    JButton infoButton = new JButton(new ImageIcon(path + "info.png"));
    infoButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(vv, instructions, "Instructions", JOptionPane.INFORMATION_MESSAGE,
                    new ImageIcon("src/snepsui/Interface/resources/icons/info.png"));
        }
    });

    JButton resetbutton = new JButton(new ImageIcon(path + "refresh.png"));
    resetbutton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ImageIcon icon = new ImageIcon("src/snepsui/Interface/resources/icons/info.png");
            int result = JOptionPane.showConfirmDialog(vv, "Are you sure you want to reset the drawing area?",
                    "Reset", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, icon);
            if (result == JOptionPane.YES_OPTION) {
                builtMolNodes.clear();
                molNodes.clear();
                nodesList.clear();

                LinkedList<String> vertexList = new LinkedList<String>();
                Collection<String> vertices = graph.getVertices();
                for (String vertex : vertices) {
                    vertexList.add(vertex);
                }

                for (String item : vertexList) {
                    graph.removeVertex(item);
                }
                vv.repaint();
            }
        }
    });

    JLabel caseframeLabel = new JLabel("Case Frames");
    DefaultComboBoxModel caseframeComboBoxModel = new DefaultComboBoxModel(
            new String[] { "define-caseframe", "undefine-caseframe" });
    caseframeComboBox = new JComboBox();
    caseframeComboBox.setModel(caseframeComboBoxModel);
    caseframeComboBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            addCaseFrameCommands(e);
        }
    });

    JLabel relationsLabel = new JLabel("Relations");
    DefaultComboBoxModel relationsComboBoxModel = new DefaultComboBoxModel(
            new String[] { "define", "undefine" });
    relationsComboBox = new JComboBox();
    relationsComboBox.setModel(relationsComboBoxModel);
    relationsComboBox.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            addRelationCommands(e);
        }
    });

    JPanel options = new JPanel(new GridLayout(3, 1));
    options.add(infoButton);
    options.add(resetbutton);
    options.add(colors);
    this.add(options, BorderLayout.EAST);

    JPanel controls = new JPanel();
    scaleGrid.add(plus);
    scaleGrid.add(minus);
    controls.add(scaleGrid);
    controls.add(relationsLabel);
    controls.add(relationsComboBox);
    controls.add(caseframeLabel);
    controls.add(caseframeComboBox);
    JComboBox modeBox = graphMouse.getModeComboBox();
    controls.add(modeBox);
    this.add(controls, BorderLayout.SOUTH);
}

From source file:tkwatch.Utilities.java

/**
 * Returns a quit button./*from  w w  w.j a v a2  s  .co m*/
 * 
 * @return A button that cleans up and exits.
 */
public static final JButton getQuitButton() {
    final JButton button = new JButton("Quit");
    button.setToolTipText("Exit the application.");
    button.setSize(Constants.BUTTON_WIDTH, Constants.BUTTON_HEIGHT);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent e) {
            System.out.flush();
            System.exit(0);
        }
    });
    return button;
}