Example usage for javax.swing JDialog pack

List of usage examples for javax.swing JDialog pack

Introduction

In this page you can find the example usage for javax.swing JDialog pack.

Prototype

@SuppressWarnings("deprecation")
public void pack() 

Source Link

Document

Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.

Usage

From source file:com.nikonhacker.gui.EmulatorUI.java

private void showAboutDialog() {
    // for copying style
    JLabel label = new JLabel();
    Font font = label.getFont();//ww w . j ava 2  s  .  c om

    // create some css from the label's font
    String style = "font-family:" + font.getFamily() + ";" + "font-weight:"
            + (font.isBold() ? "bold" : "normal") + ";" + "font-size:" + font.getSize() + "pt;";

    // html content
    JEditorPane editorPane = new JEditorPane("text/html", "<html><body style=\"" + style + "\">"
            + "<font size=\"+1\">" + ApplicationInfo.getNameVersion() + "</font><br/>"
            + "<i>A dual (Fujitsu FR + Toshiba TX) microcontroller emulator in Java, aimed at mimicking the behaviour of Nikon DSLRs</i><br/>"
            + "<font size=\"-2\">Built on " + ApplicationInfo.getBuildTime() + "</font><br/><br/>"
            + "This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.<br/>"
            + "This software is provided under the GNU General Public License, version 3 - "
            + makeLink("http://www.gnu.org/licenses/gpl-3.0.txt") + "<br/>"
            + "This software is based on, or makes use of, the following works:<ul>\n"
            + "<li>Simeon Pilgrim's deciphering of firmware encoding and lots of information shared on his blog - "
            + makeLink("http://simeonpilgrim.com/blog/") + "</li>"
            + "<li>Dfr Fujitsu FR diassembler Copyright (c) Kevin Schoedel - "
            + makeLink("http://scratchpad.wikia.com/wiki/Disassemblers/DFR")
            + "<br/>and its port to C# by Simeon Pilgrim</li>"
            + "<li>\"How To Write a Computer Emulator\" article by Marat Fayzullin - "
            + makeLink("http://fms.komkon.org/EMUL8/HOWTO.html") + "</li>"
            + "<li>The PearColator x86 emulator project - "
            + makeLink("http://apt.cs.man.ac.uk/projects/jamaica/tools/PearColator/") + "</li>"
            + "<li>The Jacksum checksum library Copyright (c) Dipl.-Inf. (FH) Johann Nepomuk Lfflmann  - "
            + makeLink("http://www.jonelo.de/java/jacksum/") + "</li>"
            + "<li>HexEditor & RSyntaxTextArea swing components, Copyright (c) Robert Futrell - "
            + makeLink("http://fifesoft.com/hexeditor/") + "</li>"
            + "<li>JGraphX graph drawing library, Copyright (c) JGraph Ltd - "
            + makeLink("http://www.jgraph.com/jgraph.html") + "</li>"
            + "<li>Apache commons libraries, Copyright (c) The Apache Software Foundation - "
            + makeLink("http://commons.apache.org/") + "</li>"
            + "<li>VerticalLayout, Copyright (c) Cellspark - " + makeLink("http://www.cellspark.com/vl.html")
            + "</li>" + "<li>MigLayout, Copyright (c) MigInfoCom - " + makeLink("http://www.miginfocom.com/")
            + "</li>" + "<li>Glazed Lists, Copyright (c) 2003-2006, publicobject.com, O'Dell Engineering Ltd - "
            + makeLink("http://www.glazedlists.com/") + "</li>"
            + "<li>Samples from the Java Tutorial (c) Sun Microsystems / Oracle - "
            + makeLink("http://docs.oracle.com/javase/tutorial") + "</li>"
            + "<li>MARS, MIPS Assembler and Runtime Simulator (c) 2003-2011, Pete Sanderson and Kenneth Vollmar - "
            + makeLink("http://courses.missouristate.edu/KenVollmar/MARS") + "</li>"
            + "<li>SteelSeries (and SteelCheckBox) Swing components (c) 2010, Gerrit Grunwald - "
            + makeLink("http://harmoniccode.blogspot.be/search/label/steelseries") + "</li>" + "</ul>"
            + "License terms for all included code are available in the 'licenses' folder of the distribution."
            + "<p>For more information, help or ideas, please join us at " + makeLink("http://nikonhacker.com")
            + "</p></body></html>");

    // handle link events
    editorPane.addHyperlinkListener(new HyperlinkListener() {
        public void hyperlinkUpdate(HyperlinkEvent e) {
            if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                try {
                    Desktop.getDesktop().browse(e.getURL().toURI());
                } catch (Exception e1) {
                    // noop
                }
            }
        }
    });
    editorPane.setEditable(false);
    Color greyLayer = new Color(label.getBackground().getRed(), label.getBackground().getGreen(),
            label.getBackground().getBlue(), 192);
    editorPane.setBackground(greyLayer);
    //editorPane.setOpaque(false);

    // show
    //        JOptionPane.showMessageDialog(this, editorPane, "About", JOptionPane.PLAIN_MESSAGE);

    final JDialog dialog = new JDialog(this, "About", true);

    JPanel contentPane = new BackgroundImagePanel(new BorderLayout(),
            Toolkit.getDefaultToolkit().getImage(EmulatorUI.class.getResource("images/nh_full.jpg")));
    contentPane.add(editorPane, BorderLayout.CENTER);

    JButton okButton = new JButton("OK");
    okButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });
    JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    bottomPanel.add(okButton);
    bottomPanel.setBackground(greyLayer);
    // bottomPanel.setOpaque(false);

    contentPane.add(bottomPanel, BorderLayout.SOUTH);

    dialog.setContentPane(contentPane);
    dialog.pack();
    dialog.setLocationRelativeTo(this);
    dialog.setResizable(false);
    dialog.setVisible(true);
}

From source file:edu.umich.robot.GuiApplication.java

public void createSuperdroidRobotDialog() {
    final Pose pose = new Pose();

    FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu",
            "pref, 2dlu, pref, 2dlu, pref");

    layout.setRowGroups(new int[][] { { 1, 3 } });

    final JDialog dialog = new JDialog(frame, "Create Superdroid Robot", true);
    dialog.setLayout(layout);/*  w w w .j ava  2  s .co  m*/
    final JTextField name = new JTextField();
    final JTextField x = new JTextField(Double.toString((pose.getX())));
    final JTextField y = new JTextField(Double.toString((pose.getY())));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(name, cc.xyw(3, 1, 5));
    dialog.add(new JLabel("x"), cc.xy(1, 3));
    dialog.add(x, cc.xy(3, 3));
    dialog.add(new JLabel("y"), cc.xy(5, 3));
    dialog.add(y, cc.xy(7, 3));
    dialog.add(cancel, cc.xyw(1, 5, 3));
    dialog.add(ok, cc.xyw(5, 5, 3));

    x.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setX(Double.parseDouble(x.getText()));
            } catch (NumberFormatException ex) {
                x.setText(Double.toString(pose.getX()));
            }
        }
    });

    y.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setY(Double.parseDouble(y.getText()));
            } catch (NumberFormatException ex) {
                y.setText(Double.toString(pose.getX()));
            }
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = name.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Create Superdroid: robot name empty");
                return;
            }
            for (char c : robotName.toCharArray())
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create Superdroid: illegal robot name");
                    return;
                }

            controller.createSuperdroidRobot(robotName, pose, true);
            controller.createSimSuperdroid(robotName);
            dialog.dispose();
        }
    };
    name.addActionListener(okListener);
    x.addActionListener(okListener);
    y.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

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

From source file:edu.umich.robot.GuiApplication.java

/**
 * <p>//from w  ww  .  j ava 2s.com
 * Pops up a window to create a new splinter robot to add to the simulation.
 */
public void createSplinterRobotDialog() {
    final Pose pose = new Pose();

    FormLayout layout = new FormLayout("right:pref, 4dlu, 30dlu, 4dlu, right:pref, 4dlu, 30dlu",
            "pref, 2dlu, pref, 2dlu, pref");

    layout.setRowGroups(new int[][] { { 1, 3 } });

    final JDialog dialog = new JDialog(frame, "Create Splinter Robot", true);
    dialog.setLayout(layout);
    final JTextField name = new JTextField();
    final JTextField x = new JTextField(Double.toString((pose.getX())));
    final JTextField y = new JTextField(Double.toString((pose.getY())));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(name, cc.xyw(3, 1, 5));
    dialog.add(new JLabel("x"), cc.xy(1, 3));
    dialog.add(x, cc.xy(3, 3));
    dialog.add(new JLabel("y"), cc.xy(5, 3));
    dialog.add(y, cc.xy(7, 3));
    dialog.add(cancel, cc.xyw(1, 5, 3));
    dialog.add(ok, cc.xyw(5, 5, 3));

    x.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setX(Double.parseDouble(x.getText()));
            } catch (NumberFormatException ex) {
                x.setText(Double.toString(pose.getX()));
            }
        }
    });

    y.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            try {
                pose.setY(Double.parseDouble(y.getText()));
            } catch (NumberFormatException ex) {
                y.setText(Double.toString(pose.getX()));
            }
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = name.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Create splinter: robot name empty");
                return;
            }
            for (char c : robotName.toCharArray())
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create splinter: illegal robot name");
                    return;
                }

            controller.createSplinterRobot(robotName, pose, true);
            controller.createSimSplinter(robotName);
            controller.createSimLaser(robotName);
            dialog.dispose();
        }
    };
    name.addActionListener(okListener);
    x.addActionListener(okListener);
    y.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);
    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

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

From source file:edu.umich.robot.GuiApplication.java

public void connectSuperdroidRobotDialog() {
    final int defaultPort = 3192;

    FormLayout layout = new FormLayout("right:pref, 4dlu, 35dlu, 4dlu, 35dlu",
            "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref");

    final JDialog dialog = new JDialog(frame, "Connect to Superdroid", true);
    dialog.setLayout(layout);/*from   w ww  .  ja va  2s  .c  o m*/
    final JTextField namefield = new JTextField("charlie");
    final JTextField hostfield = new JTextField("192.168.1.165");
    final JTextField portfield = new JTextField(Integer.toString(defaultPort));
    final JButton cancel = new JButton("Cancel");
    final JButton ok = new JButton("OK");

    CellConstraints cc = new CellConstraints();
    dialog.add(new JLabel("Name"), cc.xy(1, 1));
    dialog.add(namefield, cc.xyw(3, 1, 3));
    dialog.add(new JLabel("Host"), cc.xy(1, 3));
    dialog.add(hostfield, cc.xyw(3, 3, 3));
    dialog.add(new JLabel("Port"), cc.xy(1, 5));
    dialog.add(portfield, cc.xyw(3, 5, 3));
    dialog.add(cancel, cc.xy(3, 7));
    dialog.add(ok, cc.xy(5, 7));

    portfield.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            int p = defaultPort;
            try {
                p = Integer.parseInt(portfield.getText());
                if (p < 1)
                    p = 1;
                if (p > 65535)
                    p = 65535;
            } catch (NumberFormatException ex) {
            }
            portfield.setText(Integer.toString(p));
        }
    });

    final ActionListener okListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String robotName = namefield.getText().trim();
            if (robotName.isEmpty()) {
                logger.error("Connect Superdroid: robot name empty");
                return;
            }

            for (char c : robotName.toCharArray()) {
                if (!Character.isDigit(c) && !Character.isLetter(c)) {
                    logger.error("Create Superdroid: illegal robot name");
                    return;
                }
            }

            try {
                controller.createRealSuperdroid(robotName, hostfield.getText(),
                        Integer.valueOf(portfield.getText()));
            } catch (UnknownHostException ex) {
                ex.printStackTrace();
                logger.error("Connect Superdroid: " + ex);
            } catch (SocketException ex) {
                ex.printStackTrace();
                logger.error("Connect Superdroid: " + ex);
            }
            dialog.dispose();
        }
    };

    namefield.addActionListener(okListener);
    hostfield.addActionListener(okListener);
    portfield.addActionListener(okListener);
    ok.addActionListener(okListener);

    ActionListener cancelAction = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);

    dialog.getRootPane().registerKeyboardAction(cancelAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);

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

From source file:com.marginallyclever.makelangelo.MainGUI.java

protected void JogMotors() {
    JDialog driver = new JDialog(mainframe, translator.get("JogMotors"), true);
    driver.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();

    final JButton buttonAneg = new JButton(translator.get("JogIn"));
    final JButton buttonApos = new JButton(translator.get("JogOut"));
    final JCheckBox m1i = new JCheckBox(translator.get("Invert"), machineConfiguration.m1invert);

    final JButton buttonBneg = new JButton(translator.get("JogIn"));
    final JButton buttonBpos = new JButton(translator.get("JogOut"));
    final JCheckBox m2i = new JCheckBox(translator.get("Invert"), machineConfiguration.m2invert);

    c.gridx = 0;//from  www. j a v  a  2 s.c om
    c.gridy = 0;
    driver.add(new JLabel(translator.get("Left")), c);
    c.gridx = 0;
    c.gridy = 1;
    driver.add(new JLabel(translator.get("Right")), c);

    c.gridx = 1;
    c.gridy = 0;
    driver.add(buttonAneg, c);
    c.gridx = 1;
    c.gridy = 1;
    driver.add(buttonBneg, c);

    c.gridx = 2;
    c.gridy = 0;
    driver.add(buttonApos, c);
    c.gridx = 2;
    c.gridy = 1;
    driver.add(buttonBpos, c);

    c.gridx = 3;
    c.gridy = 0;
    driver.add(m1i, c);
    c.gridx = 3;
    c.gridy = 1;
    driver.add(m2i, c);

    ActionListener driveButtons = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == buttonApos)
                sendLineToRobot("D00 L100");
            if (subject == buttonAneg)
                sendLineToRobot("D00 L-100");
            if (subject == buttonBpos)
                sendLineToRobot("D00 R100");
            if (subject == buttonBneg)
                sendLineToRobot("D00 R-100");
            sendLineToRobot("M114");
        }
    };

    ActionListener invertButtons = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            machineConfiguration.m1invert = m1i.isSelected();
            machineConfiguration.m2invert = m2i.isSelected();
            machineConfiguration.SaveConfig();
            SendConfig();
        }
    };

    buttonApos.addActionListener(driveButtons);
    buttonAneg.addActionListener(driveButtons);

    buttonBpos.addActionListener(driveButtons);
    buttonBneg.addActionListener(driveButtons);

    m1i.addActionListener(invertButtons);
    m2i.addActionListener(invertButtons);

    sendLineToRobot("M114");
    driver.pack();
    driver.setVisible(true);
}

From source file:com.marginallyclever.makelangelo.MainGUI.java

protected void AdjustGraphics() {
    final Preferences graphics_prefs = Preferences.userRoot().node("DrawBot").node("Graphics");

    final JDialog driver = new JDialog(mainframe, translator.get("MenuGraphicsTitle"), true);
    driver.setLayout(new GridBagLayout());

    //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total"));
    //allow_metrics.setSelected(allowMetrics);

    final JCheckBox show_pen_up = new JCheckBox(translator.get("MenuGraphicsPenUp"));
    final JCheckBox antialias_on = new JCheckBox(translator.get("MenuGraphicsAntialias"));
    final JCheckBox speed_over_quality = new JCheckBox(translator.get("MenuGraphicsSpeedVSQuality"));
    final JCheckBox draw_all_while_running = new JCheckBox(translator.get("MenuGraphicsDrawWhileRunning"));

    show_pen_up.setSelected(graphics_prefs.getBoolean("show pen up", false));
    antialias_on.setSelected(graphics_prefs.getBoolean("antialias", true));
    speed_over_quality.setSelected(graphics_prefs.getBoolean("speed over quality", true));
    draw_all_while_running.setSelected(graphics_prefs.getBoolean("Draw all while running", true));

    final JButton cancel = new JButton(translator.get("Cancel"));
    final JButton save = new JButton(translator.get("Save"));

    GridBagConstraints c = new GridBagConstraints();
    //c.gridwidth=4;    c.gridx=0;  c.gridy=0;  driver.add(allow_metrics,c);

    int y = 0;//from w w w .  j a  v  a2 s  .  c  o m

    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(show_pen_up, c);
    y++;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(draw_all_while_running, c);
    y++;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(antialias_on, c);
    y++;
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 1;
    c.gridy = y;
    driver.add(speed_over_quality, c);
    y++;

    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 2;
    c.gridy = y;
    driver.add(save, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = y;
    driver.add(cancel, c);

    ActionListener driveButtons = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == save) {
                //allowMetrics = allow_metrics.isSelected();
                graphics_prefs.putBoolean("show pen up", show_pen_up.isSelected());
                graphics_prefs.putBoolean("antialias", antialias_on.isSelected());
                graphics_prefs.putBoolean("speed over quality", speed_over_quality.isSelected());
                graphics_prefs.putBoolean("Draw all while running", draw_all_while_running.isSelected());

                previewPane.setShowPenUp(show_pen_up.isSelected());
                driver.dispose();
            }
            if (subject == cancel) {
                driver.dispose();
            }
        }
    };

    save.addActionListener(driveButtons);
    cancel.addActionListener(driveButtons);
    driver.getRootPane().setDefaultButton(save);
    driver.pack();
    driver.setVisible(true);
}

From source file:org.nuclos.client.ui.collect.Chart.java

private void actionCommandShow() {
    final JOptionPane optpn = new JOptionPane(subform, JOptionPane.PLAIN_MESSAGE, JOptionPane.CLOSED_OPTION);

    // perform the dialog:
    final JDialog dlg = optpn.createDialog(panel, "Chart-Daten anzeigen");
    dlg.setModal(true);//from  w  w  w  .  j a v a2 s  .  c  o m
    dlg.setResizable(true);
    dlg.pack();
    dlg.setLocationRelativeTo(panel);
    dlg.setVisible(true);
}

From source file:fxts.stations.util.preferences.EditAction.java

public void actionPerformed(ActionEvent aEvent) {
    JButton okButton = UIManager.getInst().createButton();
    JButton cancelButton = UIManager.getInst().createButton();
    final JDialog dialog = new JDialog(mEditorPanel.getParentDialog());
    dialog.setTitle(mEditorPanel.getTitle());
    JPanel editPanel = new JPanel();
    JPanel buttonPanel = new JPanel();
    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(UIFrontEnd.getInstance().getSideLayout());
    //mainPanel.setLayout(new SideLayout());

    //sets button panel
    buttonPanel.setLayout(UIFrontEnd.getInstance().getSideLayout());
    okButton.setText(mResMan.getString("IDS_OK_BUTTON"));
    //okButton.setPreferredSize(new Dimension(80, 27));
    GridBagConstraints sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.insets = new Insets(10, 10, 10, 10);
    sideConstraints.gridx = 0;/*from   www  .j  a  va2 s .  c  o m*/
    sideConstraints.gridy = 0;
    ResizeParameterWrapper resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.5, 0.0, 0.5, 0.0);
    resizeParameter.setToConstraints(sideConstraints);
    buttonPanel.add(okButton, sideConstraints);
    cancelButton.setText(mResMan.getString("IDS_CANCEL_BUTTON"));
    //cancelButton.setPreferredSize(new Dimension(80, 27));
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.insets = new Insets(10, 10, 10, 10);
    sideConstraints.gridx = 1;
    sideConstraints.gridy = 0;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.5, 0.0, 0.5, 0.0);
    resizeParameter.setToConstraints(sideConstraints);
    buttonPanel.add(cancelButton, sideConstraints);

    //adds button panel
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.insets = new Insets(10, 10, 10, 10);
    sideConstraints.gridx = 0;
    sideConstraints.gridy = 1;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 1.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    mainPanel.add(buttonPanel, sideConstraints);

    //sets edit panel
    final IEditor editor = mType.getEditor();
    editor.setValue(mValue);
    editPanel.setLayout(UIFrontEnd.getInstance().getSideLayout());
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 0.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    Component editComp = editor.getComponent();

    //Mar 25 2004 - kav: added for right tab order at Font Chooser at java 1.4.
    if (editComp instanceof FontChooser) {
        FontChooser fc = (FontChooser) editComp;
        fc.setNextFocusedComp(okButton);
    }
    editPanel.add(editComp, sideConstraints);

    //adds editor panel
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.gridx = 0;
    sideConstraints.gridy = 0;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 0.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    mainPanel.add(editPanel, sideConstraints);

    //adds main panel
    dialog.getContentPane().setLayout(UIFrontEnd.getInstance().getSideLayout());
    //dialog.getContentPane().setLayout(new SideLayout());
    sideConstraints = UIFrontEnd.getInstance().getSideConstraints();
    sideConstraints.fill = GridBagConstraints.BOTH;
    resizeParameter = UIFrontEnd.getInstance().getResizeParameter();
    resizeParameter.init(0.0, 0.0, 1.0, 1.0);
    resizeParameter.setToConstraints(sideConstraints);
    dialog.getContentPane().add(mainPanel, sideConstraints);

    //adds listeners to buttons
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            if (editor.getValue().equals(mValue)) {
                //
            } else {
                mValue = editor.getValue();
                mEditorPanel.setValue(mValue);
                mEditorPanel.refreshControls();
                mEditorPanel.setValueChanged(true);
            }
            dialog.setVisible(false);
            dialog.dispose();
        }
    });
    okButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "ExitAction");
    okButton.getActionMap().put("ExitAction", new AbstractAction() {
        /**
         * Invoked when an action occurs.
         */
        public void actionPerformed(ActionEvent aEvent) {
            editor.setValue(mValue);
            dialog.setVisible(false);
            dialog.dispose();
        }
    });
    okButton.requestFocus();
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent aEvent) {
            editor.setValue(mValue);
            dialog.setVisible(false);
            dialog.dispose();
        }
    });
    //dialog.setResizable(false);
    dialog.setModal(true);
    dialog.pack();

    //sets minimal sizes for components
    Dimension dim = mainPanel.getSize();
    mainPanel.setMinimumSize(dim);
    mainPanel.setPreferredSize(dim);

    //sets size of buttons
    Dimension dimOkButton = okButton.getSize();
    Dimension dimCancelButton = cancelButton.getSize();
    int nMaxWidth = dimOkButton.getWidth() > dimCancelButton.getWidth() ? (int) dimOkButton.getWidth()
            : (int) dimCancelButton.getWidth();
    okButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight()));
    okButton.setSize(new Dimension(nMaxWidth, (int) dimOkButton.getHeight()));
    cancelButton.setPreferredSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight()));
    cancelButton.setSize(new Dimension(nMaxWidth, (int) dimCancelButton.getHeight()));
    dialog.setLocationRelativeTo(dialog.getOwner());
    dialog.setVisible(true);
}

From source file:GUI.GUI_reporting.java

private void btnLancerStatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLancerStatActionPerformed
    // TODO add your handling code here:

    // faire la requete sql et ranger les variables aux bon endroits
    JDialog reponse = new JDialog();
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    final DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String text = "";
    String Infox = "";
    String Infoy = "";
    switch (action) {//////////////////:Pie charts//////////////////////////////////////
    case 1://w w w. jav  a  2  s .  c  o m
        //set values
        pieDataset.setValue("de 700  1100", getEmployeParSalaire(1));
        pieDataset.setValue("de 1100  1300", getEmployeParSalaire(2));
        pieDataset.setValue("de 1300  1700", getEmployeParSalaire(3));
        pieDataset.setValue("Plus de 1700", getEmployeParSalaire(4));
        text = "Nombre d'employs par tranche de salaire";
        break;

    case 2:
        //set values
        pieDataset.setValue("REA", getEmployeParService(1));
        pieDataset.setValue("CHG", getEmployeParService(2));
        pieDataset.setValue("CAR", getEmployeParService(3));
        text = "Nombre d'employs par service";
        break;
    case 3:
        //set values
        pieDataset.setValue("Anesthesiste", getEmployeParSpecialite(1));
        pieDataset.setValue("Cardiologue", getEmployeParSpecialite(2));
        pieDataset.setValue("Generaliste", getEmployeParSpecialite(3));
        pieDataset.setValue("Orthopediste", getEmployeParSpecialite(4));
        pieDataset.setValue("Pneumologue", getEmployeParSpecialite(5));
        pieDataset.setValue("Radiologue", getEmployeParSpecialite(6));
        pieDataset.setValue("Traumatologue", getEmployeParSpecialite(7));
        text = "Nombre d'employs par spcialit";
        break;
    case 4:
        //set values
        pieDataset.setValue("Jour", getEmployeRotation(1));
        pieDataset.setValue("Nuit", getEmployeRotation(2));
        text = "Nombre d'employs par rotation";
        break;
    /// diagrammes en barre/////////////////////////////
    case 5:
        //dataset.addValue(WIDTH, WIDTH, action);
        final String REA = "Moyenne pour REA";
        final String CHG = "Moyenne pour CHG";
        final String CAR = "Moyenne pour CAR";
        final String salaire = "salaire";
        dataset.addValue(getSalaireParService(1), salaire, REA);
        dataset.addValue(getSalaireParService(2), salaire, CHG);
        dataset.addValue(getSalaireParService(3), salaire, CAR);
        Infox = "service";
        Infoy = "salaire";
        text = "Salaire moyen par service";
        break;

    case 6:
        //set values
        final String malade = "Malade";
        final String rea = "REA";
        final String chg = "CHG";
        final String car = "CAR";
        dataset.addValue(getMaladeParService(1), malade, rea);
        dataset.addValue(getMaladeParService(2), malade, chg);
        dataset.addValue(getMaladeParService(3), malade, car);
        Infox = "Service";
        Infoy = "Nombre de malades";
        text = "Nombre de malade par service";
        break;
    case 7:
        //set values
        final String MAAF = "MAAF";
        final String MNAM = "MNAM";
        final String LMDE = "LMDE";
        final String MNH = "MNH";
        final String MGEN = "MGEN";
        final String MMA = "MMA";
        final String CNAMTS = "CNAMTS";
        final String CCVRP = "CCVRP";
        final String MAS = "MAS";
        final String AG2R = "AG2R";
        final String MNFTC = "MNFTC";
        final String MGSP = "MGSP";
        final String salaire0 = "Mutuelle";
        Infox = "Mutuelle";
        Infoy = "Malades";
        text = "Nombre de malades par mutuelle";

        //                      / init
        dataset.addValue(getMaladeParMutuelle(1), salaire0, MAAF);
        dataset.addValue(getMaladeParMutuelle(2), salaire0, MNAM);
        dataset.addValue(getMaladeParMutuelle(3), salaire0, LMDE);
        dataset.addValue(getMaladeParMutuelle(4), salaire0, MNH);
        dataset.addValue(getMaladeParMutuelle(5), salaire0, MGEN);
        dataset.addValue(getMaladeParMutuelle(6), salaire0, MMA);
        dataset.addValue(getMaladeParMutuelle(7), salaire0, CNAMTS);
        dataset.addValue(getMaladeParMutuelle(8), salaire0, CCVRP);
        dataset.addValue(getMaladeParMutuelle(9), salaire0, MAS);
        dataset.addValue(getMaladeParMutuelle(10), salaire0, AG2R);
        dataset.addValue(getMaladeParMutuelle(11), salaire0, MNFTC);
        dataset.addValue(getMaladeParMutuelle(12), salaire0, MGSP);
        break;

    case 8:
        //set values
        final String malades = "Chambre";
        final String reas = "REA";
        final String chgs = "CHG";
        final String cars = "CAR";
        dataset.addValue(getChambreParService(1), malades, reas);
        dataset.addValue(getChambreParService(2), malades, chgs);
        dataset.addValue(getChambreParService(3), malades, cars);
        Infox = "Service";
        Infoy = "Nombre de chambre";
        text = "Nombre de chambre par service";
        break;

    default:
        break;

    }
    // Piechart
    if (action > 0 && action < 5) {
        final JFreeChart pieChart = ChartFactory.createPieChart(text, pieDataset, true, false, false);
        final ChartPanel cPanel = new ChartPanel(pieChart);
        reponse.add(cPanel);
        reponse.pack();
        //panelHistogramme.pack();
        reponse.setVisible(true);
    }
    //Histogramme
    if (action > 4 && action < 11) {

        final JFreeChart barChart = ChartFactory.createBarChart(text, Infox, Infoy, dataset,
                PlotOrientation.VERTICAL, true, true, false);
        final ChartPanel cPanel = new ChartPanel(barChart);
        reponse.add(cPanel);
        reponse.pack();
        //panelHistogramme.pack();
        reponse.setVisible(true);
    }

    /*
     DefaultPieDataset pieDataset = new DefaultPieDataset(); 
     pieDataset.setValue("Valeur1", new Integer(27)); 
     pieDataset.setValue("Valeur2", new Integer(10)); 
     pieDataset.setValue("Valeur3", new Integer(50)); 
     pieDataset.setValue("Valeur4", new Integer(5)); 
     JFreeChart pieChart = ChartFactory.createPieChart("Test camembert",pieDataset, true, true, true); 
     ChartPanel cPanel = new ChartPanel(pieChart); 
     panelHistogramme.add(cPanel); 
     */

}

From source file:com.marginallyclever.makelangelo.MainGUI.java

protected void AdjustSounds() {
    final JDialog driver = new JDialog(mainframe, translator.get("MenuSoundsTitle"), true);
    driver.setLayout(new GridBagLayout());

    final JTextField sound_connect = new JTextField(prefs.get("sound_connect", ""), 32);
    final JTextField sound_disconnect = new JTextField(prefs.get("sound_disconnect", ""), 32);
    final JTextField sound_conversion_finished = new JTextField(prefs.get("sound_conversion_finished", ""), 32);
    final JTextField sound_drawing_finished = new JTextField(prefs.get("sound_drawing_finished", ""), 32);

    final JButton change_sound_connect = new JButton(translator.get("MenuSoundsConnect"));
    final JButton change_sound_disconnect = new JButton(translator.get("MenuSoundsDisconnect"));
    final JButton change_sound_conversion_finished = new JButton(translator.get("MenuSoundsFinishConvert"));
    final JButton change_sound_drawing_finished = new JButton(translator.get("MenuSoundsFinishDraw"));

    //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total"));
    //allow_metrics.setSelected(allowMetrics);

    final JButton cancel = new JButton(translator.get("Cancel"));
    final JButton save = new JButton(translator.get("Save"));

    GridBagConstraints c = new GridBagConstraints();
    //c.gridwidth=4;    c.gridx=0;  c.gridy=0;  driver.add(allow_metrics,c);

    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;//from w  ww  . ja  v a 2  s .  c o  m
    c.gridx = 0;
    c.gridy = 3;
    driver.add(change_sound_connect, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 3;
    driver.add(sound_connect, c);
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 4;
    driver.add(change_sound_disconnect, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 4;
    driver.add(sound_disconnect, c);
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 5;
    driver.add(change_sound_conversion_finished, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 5;
    driver.add(sound_conversion_finished, c);
    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 0;
    c.gridy = 6;
    driver.add(change_sound_drawing_finished, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 3;
    c.gridx = 1;
    c.gridy = 6;
    driver.add(sound_drawing_finished, c);

    c.anchor = GridBagConstraints.EAST;
    c.gridwidth = 1;
    c.gridx = 2;
    c.gridy = 12;
    driver.add(save, c);
    c.anchor = GridBagConstraints.WEST;
    c.gridwidth = 1;
    c.gridx = 3;
    c.gridy = 12;
    driver.add(cancel, c);

    ActionListener driveButtons = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Object subject = e.getSource();
            if (subject == change_sound_connect)
                sound_connect.setText(SelectFile());
            if (subject == change_sound_disconnect)
                sound_disconnect.setText(SelectFile());
            if (subject == change_sound_conversion_finished)
                sound_conversion_finished.setText(SelectFile());
            if (subject == change_sound_drawing_finished)
                sound_drawing_finished.setText(SelectFile());

            if (subject == save) {
                //allowMetrics = allow_metrics.isSelected();
                prefs.put("sound_connect", sound_connect.getText());
                prefs.put("sound_disconnect", sound_disconnect.getText());
                prefs.put("sound_conversion_finished", sound_conversion_finished.getText());
                prefs.put("sound_drawing_finished", sound_drawing_finished.getText());
                machineConfiguration.SaveConfig();
                driver.dispose();
            }
            if (subject == cancel) {
                driver.dispose();
            }
        }
    };

    change_sound_connect.addActionListener(driveButtons);
    change_sound_disconnect.addActionListener(driveButtons);
    change_sound_conversion_finished.addActionListener(driveButtons);
    change_sound_drawing_finished.addActionListener(driveButtons);

    save.addActionListener(driveButtons);
    cancel.addActionListener(driveButtons);
    driver.getRootPane().setDefaultButton(save);
    driver.pack();
    driver.setVisible(true);
}