Example usage for javax.swing JMenu setPreferredSize

List of usage examples for javax.swing JMenu setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JMenu setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:JFlap_2.EditingGraphViewer1.java

/**
 * @param args the command line arguments
 *///ww  w. j  a  v  a 2 s  .  co m
public static void main(String[] args) {
    EditingGraphViewer1 sgv = new EditingGraphViewer1();
    // Layout<V, E>, VisualizationViewer<V,E>
    Layout<Integer, String> layout = new StaticLayout(sgv.g);
    layout.setSize(new Dimension(300, 300));
    VisualizationViewer<Integer, String> vv = new VisualizationViewer<Integer, String>(layout);
    vv.setPreferredSize(new Dimension(350, 350));
    // Show vertex and edge labels
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller());
    EditingModalGraphMouse gm = new EditingModalGraphMouse(vv.getRenderContext(), sgv.vertexFactory,
            sgv.edgeFactory);
    vv.setGraphMouse(gm);

    JFrame frame = new JFrame("Editing Graph Viewer 1");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    JMenuBar menuBar = new JMenuBar();
    JMenu modeMenu = gm.getModeMenu();
    modeMenu.setText("Mouse Mode");
    modeMenu.setIcon(null);
    modeMenu.setPreferredSize(new Dimension(80, 20));

    menuBar.add(modeMenu);
    frame.setJMenuBar(menuBar);
    gm.setMode(ModalGraphMouse.Mode.EDITING);
    frame.pack();
    frame.setVisible(true);

}

From source file:levelBuilder.DialogMaker.java

/**
 * Various routines necessary for displaying graph.
 *//*from   ww w.  jav a  2  s . co  m*/
private static void displayGraph() {
    JFrame frame = new JFrame("Dialog Maker");
    layout = new KKLayout<DialogNode, Double>(g);
    VisualizationViewer<DialogNode, Double> vv = new VisualizationViewer<DialogNode, Double>(layout);
    layout.setSize(new Dimension(windowWidth, windowHeight));
    vv.setPreferredSize(new Dimension(windowWidth, windowHeight));

    //Changes fields in node properties window when a node is selected
    pickedState = vv.getPickedVertexState();
    pickedState.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            Object subject = e.getItem();
            if (subject instanceof DialogNode) {
                selectedNode = (DialogNode) subject;
                textField.setText(selectedNode.getText());
                npcBox.setSelected(selectedNode.getIsNPC());
                String working = "";
                for (int c = 0; c < selectedNode.getChildren().length; c++) {
                    if (c == 0)
                        working += selectedNode.getChildren()[c].getText();
                    else
                        working += "," + selectedNode.getChildren()[c].getText();
                }
                if (working.equals("null"))
                    working = "";
                childrenField.setText(working.replace("]", "").replace("[", ""));
                working = Arrays.toString(selectedNode.getProbSets().get(strategy));
                if (working.equals("null"))
                    working = "";
                probSetField.setText(working.replace("]", "").replace("[", "").replace(" ", ""));
            }
        }
    });

    //Colors vertices according to 'initial', 'end', or 'middle' status.
    vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<DialogNode, Paint>() {
        @Override
        public Paint transform(DialogNode n) {
            if (n.getText().equals("initial"))
                return new Color(100, 255, 100);
            if (n.getChildren().length == 0)
                return new Color(255, 100, 100);
            return new Color(100, 100, 255);
        }
    });

    //Labels vertices with node text.
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<DialogNode, String>() {
        @Override
        public String transform(DialogNode n) {
            return n.getText().split(" ")[0];
        }

    });

    //Draws shape of vertices according to player or non-player status.
    vv.getRenderContext().setVertexShapeTransformer(new Transformer<DialogNode, Shape>() {
        @Override
        public Shape transform(DialogNode n) {
            if (n.getIsNPC())
                return new Rectangle(-15, -15, 30, 30);
            else
                return new Ellipse2D.Double(-15.0, -15.0, 30.0, 30.0);
        }

    });

    //Labels edges with probability of child being selected under the current strategy.
    vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Double, String>() {
        @Override
        public String transform(Double e) {
            DialogNode source = g.getSource(e);
            if (source.getProbSets().size() > 0)
                for (int c = 0; c < source.getChildren().length; c++)
                    if (source.getChildren()[c].equals(g.getDest(e))) {
                        if (source.getProbSets().get(strategy) != null)
                            return Double.toString(source.getProbSets().get(strategy)[c]);
                        else //If node does not have probSet for that strategy, default to strategy 0.
                            return Double.toString(source.getProbSets().get(0)[c]);
                    }
            return null;
        }
    });
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);

    //Routines for editing mode.
    EditingModalGraphMouse<DialogNode, Double> gm = new EditingModalGraphMouse<DialogNode, Double>(
            vv.getRenderContext(),
            //Runs when a new node is created.
            new Factory<DialogNode>() {
                @Override
                public DialogNode create() {
                    DialogNode n = new DialogNode(isNPCBoxChecked, textField.getText(),
                            new ArrayList<double[]>(), new DialogNode[0]);
                    dg.addNode(n);
                    return n;
                }
            },
            //Runs when a new edge is created.
            new Factory<Double>() {
                @Override
                public Double create() {
                    addedEdgeID = Math.random();
                    return addedEdgeID;
                }
            });
    vv.setGraphMouse(gm);

    //Frame and mode menu.
    JMenuBar menuBar = new JMenuBar();
    JMenu modeMenu = gm.getModeMenu();
    modeMenu.setText("Mouse Mode");
    modeMenu.setIcon(null);
    modeMenu.setPreferredSize(new Dimension(100, 20));
    menuBar.add(modeMenu);
    frame.setJMenuBar(menuBar);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(vv);
    frame.pack();
    frame.setVisible(true);

    //      //Sets position of each node.
    //      for (DialogNode n : nodeMap.values()) {
    //         Point2D.Double point = new Point2D.Double(n.getX(), n.getY());
    //         if (point.x != 0.0 && point.y != 0.0)
    //            layout.setLocation(n, point);
    //      }
}

From source file:org.wmediumd.WmediumdGraphView.java

public WmediumdGraphView() {

    JMenuBar menuBar;//  w ww . j a va  2 s. co m
    JMenu menu;
    JMenuItem menuItem;

    setup();
    setupVisualization();
    setupMouse();

    // Let's add a menu for changing mouse modes
    menuBar = new JMenuBar();

    menu = new JMenu();
    menu.setText("File");
    menu.setIcon(null);

    menuItem = new JMenuItem("New file");
    menuItem.setIcon(UIManager.getIcon("FileView.fileIcon"));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            // TODO Use the Factory
            MyNode.nodeCount = 0;
            MyLink.linkCount = 0;
            graph.clear();
            frame.repaint();
        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem("Load file");
    menuItem.setIcon(UIManager.getIcon("FileChooser.upFolderIcon"));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            FileChooserLoad fl = new FileChooserLoad();
            if (fl.getMatrixList().rates() == MyLink.rates) {
                MyNode.nodeCount = 0;
                MyLink.linkCount = 0;
                graph.clear();
                graph.setDataFromMatrixList(fl.getMatrixList());
                frame.repaint();
            }

        }
    });
    menu.add(menuItem);

    menuItem = new JMenuItem("Save as...");
    menuItem.setIcon(UIManager.getIcon("FileView.floppyDriveIcon"));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (MyNode.nodeCount > 1) {
                System.out.println(generateConfigString());
                new FileChooserSave(generateConfigString());
            }
        }
    });
    menu.add(menuItem);

    menu.addSeparator();
    menuItem = new JMenuItem("Exit");
    menuItem.setIcon(UIManager.getIcon("InternalFrame.closeIcon"));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            System.exit(0);
        }
    });
    menu.add(menuItem);
    menuBar.add(menu);

    menu = graphMouse.getModeMenu(); // Obtain mode menu from the mouse
    menu.setText("Edit");
    menu.setIcon(null); // I'm using this in a main menu
    menu.setPreferredSize(new Dimension(40, 15)); // Change the size
    menuBar.add(menu);

    menu = new JMenu("Help");

    menuItem = new JMenuItem("Help");
    menuItem.setIcon(UIManager.getIcon("FileChooser.detailsViewIcon"));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            openURL("http://o11s.org/trac/wiki/MeshTestingWmediumd#a4.1.Usingwconfig");
        }
    });
    menu.add(menuItem);
    menu.addSeparator();

    menuItem = new JMenuItem("About");
    menuItem.setIcon(UIManager.getIcon("FileChooser.homeFolderIcon"));
    menuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {

            JOptionPane.showMessageDialog(
                    frame, "Wireless medium daemon\n" + "configuration tool <v0.2b>\n\n"
                            + "(C) 2011 - Javier Lopez\n" + "<jlopex@gmail.com>\n",
                    "About", JOptionPane.INFORMATION_MESSAGE);

        }
    });
    menu.add(menuItem);

    menuBar.add(menu);

    graphMouse.setMode(ModalGraphMouse.Mode.EDITING); // Start off in editing mode
    vViewer.setGraphMouse(graphMouse);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(vViewer);
    frame.pack();
    frame.setVisible(true);
}

From source file:Samples.Advanced.GraphEditorDemo.java

/**
 * a driver for this demo//from w w w  .j av  a  2  s.c o m
 */
@SuppressWarnings("serial")
public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final GraphEditorDemo demo = new GraphEditorDemo();

    JMenu menu = new JMenu("File");
    menu.add(new AbstractAction("Make Image") {
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            int option = chooser.showSaveDialog(demo);
            if (option == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                demo.writeJPEGImage(file);
            }
        }
    });
    menu.add(new AbstractAction("Print") {
        public void actionPerformed(ActionEvent e) {
            PrinterJob printJob = PrinterJob.getPrinterJob();
            printJob.setPrintable(demo);
            if (printJob.printDialog()) {
                try {
                    printJob.print();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    });
    JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    JMenuBar menuBar = new JMenuBar();
    menuBar.add(menu);
    JMenu matrixMenu = new JMenu();
    matrixMenu.setText("Matrix");
    matrixMenu.setIcon(null);
    matrixMenu.setPreferredSize(new Dimension(80, 20));
    menuBar.add(matrixMenu);
    JMenuItem copyMatrix = new JMenuItem("Copy Matrix to clipboard", KeyEvent.VK_C);
    copyMatrix.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    menuBar.add(copyMatrix);
    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(demo);
    copyMatrix.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            Vem textTransfer = new Vem();

            //Set up Matrix
            List<Integer[]> graphMatrix = new ArrayList<Integer[]>();
            int MatrixSize = graph.getVertexCount();

            Integer[] activeV = new Integer[MatrixSize];
            int count = 0;
            int activeVPos = 0;

            while (activeVPos < MatrixSize) {
                if (graph.containsVertex(count)) {
                    activeV[activeVPos] = count;
                    activeVPos++;
                }
                count++;
            }

            // sgv.g.getVertices().toArray()  ((Integer[])(sgv.g.getVertices().toArray()))
            for (int i = 0; i < MatrixSize; i++) {
                Integer[] tempArray = new Integer[MatrixSize];
                for (int j = 0; j < MatrixSize; j++) {
                    if (graph.findEdge(activeV[i], activeV[j]) != null) {
                        tempArray[j] = 1;
                    } else {
                        tempArray[j] = 0;
                    }
                }
                graphMatrix.add(tempArray);
            }
            //graphMatrix.add(new Integer[]{1, 2, 3});
            //graphMatrix.add(new Integer[]{4, 5 , 6, 7});

            //System.out.println(matrixToString(graphMatrix));
            //System.out.println(matrixToMathematica(graphMatrix));

            textTransfer.setClipboardContents("" + matrixToMathematica(graphMatrix));
            System.out.println("Clipboard contains:" + textTransfer.getClipboardContents());
        }
    });

    frame.pack();
    frame.setVisible(true);
}