public PrintableDialog() {
        setTitle("Print Preview");
        printMode.setStyle(CharProps.getIntProperty("last.printmode.style", PrintMode.STYLE_CRAM));
        printMode.setText(CharProps.getIntProperty("last.printmode.text", PrintMode.TEXT_CHARS));

        Container thiss = this.getContentPane();
        thiss.setLayout(new BorderLayout());
        gridPanel = new GridPanel(printMode);

        Paper paper = new Paper();
        double margin = CharProps.getDoubleProperty("paper.margins", gridPanel.getMargins()) * 72;
        String paperSize = CharProps.getProperty("paper.size");
        // A bit of a hack.
        if ("A4".equalsIgnoreCase(paperSize)) {
            paper.setImageableArea(margin, margin, 558.1417322834645, 805.8897637795276);
            paper.setSize(595.275590551181, 841.8897637795276);
        }
        paper.setImageableArea(margin, margin, paper.getWidth() - 2 * margin, paper.getHeight() - 2 * margin);
        format = new PageFormat();
        format.setPaper(paper);

        thiss.add(gridPanel, BorderLayout.CENTER);

        JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
        printButton = new JButton("Print");
        setupButton = new JButton("Page Setup");
        closeButton = new JButton("Close");
        printButton.setBackground(CharApp.COLOR_BUTTON);
        setupButton.setBackground(CharApp.COLOR_BUTTON);
        closeButton.setBackground(CharApp.COLOR_BUTTON);
        printButton.addActionListener(this);
        setupButton.addActionListener(this);
        closeButton.addActionListener(this);

        buttonPanel.add(printButton);
        buttonPanel.add(setupButton);
        buttonPanel.add(closeButton);

        buttonPanel.setBackground(CharApp.COLOR_BG);

        JPanel controlPanel = new JPanel(new GridLayout(3, 1));
        controlPanel.setBackground(CharApp.COLOR_BG);
        style = new JComboBox(styles);
        text = new JComboBox(texts);
        style.setBackground(CharApp.COLOR_BUTTON);
        text.setBackground(CharApp.COLOR_BUTTON);

        guides = new JCheckBox("Guides");
        guides.setBackground(CharApp.COLOR_BG);
        grid = new JCheckBox("Grid Style");
        grid.setBackground(CharApp.COLOR_BG);
        randomize = new JCheckBox("Random");
        randomize.setBackground(CharApp.COLOR_BG);
        fillPage = new JCheckBox("Fill page");
        fillPage.setBackground(CharApp.COLOR_BG);
        lines = new JCheckBox("Lines");
        lines.setBackground(CharApp.COLOR_BG);
        header = new JCheckBox("Header");
        header.setBackground(CharApp.COLOR_BG);
        guides.setSelected("true".equals(CharProps.getProperty("draw.guides")));
        grid.setSelected("true".equals(CharProps.getProperty("draw.gridstyle")));
        grid.setEnabled(guides.isSelected());
        randomize.setSelected(gridPanel.isRandomOrder());
        fillPage.setSelected(gridPanel.isFillThePage());
        lines.setSelected(true);
        header.setSelected(true);

        guides.addActionListener(this);
        grid.addActionListener(this);
        randomize.addActionListener(this);
        fillPage.addActionListener(this);
        lines.addActionListener(this);
        header.addActionListener(this);

        next = new JButton(">");
        prev = new JButton("<");
        next.setBackground(CharApp.COLOR_BUTTON);
        prev.setBackground(CharApp.COLOR_BUTTON);
        fontButton = new JButton("Fonts");
        fontButton.setBackground(CharApp.COLOR_BUTTON);
        sizesButton = new JButton("Boxes");
        sizesButton.setBackground(CharApp.COLOR_BUTTON);
        next.addActionListener(this);
        prev.addActionListener(this);
        fontButton.addActionListener(this);
        sizesButton.addActionListener(this);

        JPanel temp = new JPanel();
        temp.setBackground(CharApp.COLOR_BG);
        temp.add(new JLabel("Style:"));
        temp.add(style);
        temp.add(guides);
        temp.add(grid);
        temp.add(randomize);
        temp.add(fillPage);
        controlPanel.add(temp);
        temp = new JPanel();
        temp.setBackground(CharApp.COLOR_BG);
        temp.add(new JLabel("Text:"));
        temp.add(text);
        temp.add(fontButton);
        temp.add(sizesButton);
        temp.add(lines);
        temp.add(header);
        controlPanel.add(temp);
        controlPanel.add(buttonPanel);

        switch (printMode.getText()) {
            case PrintMode.TEXT_CHARS:
                text.setSelectedIndex(1);
                break;
            case PrintMode.TEXT_PINYIN:
                text.setSelectedIndex(2);
                break;
            case PrintMode.TEXT_ENGLISH:
                text.setSelectedIndex(3);
                break;
            case PrintMode.TEXT_ENGLISH_PINYIN:
                text.setSelectedIndex(4);
                break;
            default:
                text.setSelectedIndex(0);
        }

        switch (printMode.getStyle()) {
            case PrintMode.STYLE_CRAM:
                style.setSelectedIndex(1);
                break;
            case PrintMode.STYLE_ALTERNATING_LINES:
                style.setSelectedIndex(2);
                break;
            case PrintMode.STYLE_READING:
                style.setSelectedIndex(3);
                break;
            default:
                style.setSelectedIndex(0);
        }
        style.addActionListener(this);
        text.addActionListener(this);

        buttonPanel.setBorder(BorderFactory.createLineBorder(Color.blue));
        controlPanel.setBorder(BorderFactory.createLineBorder(Color.blue));

        buttonPanel.add(new JLabel("Page:"));
        buttonPanel.add(prev);
        buttonPanel.add(next);

        JScrollPane scroller = new JScrollPane(controlPanel);
//    thiss.add(controlPanel, BorderLayout.SOUTH);
        thiss.add(scroller, BorderLayout.SOUTH);
        this.setResizable(true);

        this.addComponentListener(new ComponentAdapter() {
            public void componentResized(ComponentEvent e) {
                if (ratio < 0) {
                    ratio = (double) getHeight() / (double) getWidth();
                }
                setSize((int) ((double) getHeight() / ratio), getHeight());
            }
        });
    }