Package com.jgoodies.forms.builder

Examples of com.jgoodies.forms.builder.DefaultFormBuilder


    FormLayout lmButtons = new FormLayout(
        "right:pref, 10dlu, left:pref:grow(1), 4dlu,"
            + "left:pref:grow(1), 4dlu, left:pref:grow(1), "
            + "4dlu, left:pref:grow(1)", "");
    lmButtons.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
    DefaultFormBuilder builderButtons = new DefaultFormBuilder(lmButtons,
        new ScrollablePanel());
    builderButtons.setDefaultDialogBorder();

    builderButtons.append("");
    JLabel bLabel = new JLabel("Buttons");
    bLabel.setIcon(Check.getIcon("JButtonColor16"));
    JLabel tbLabel = new JLabel("Toggle buttons");
    tbLabel.setIcon(Check.getIcon("JToggleButtonColor16"));
    JLabel cbLabel = new JLabel("Check boxes");
    cbLabel.setIcon(Check.getIcon("JCheckBoxColor16"));
    JLabel rbLabel = new JLabel("Radio buttons");
    rbLabel.setIcon(Check.getIcon("JRadioButtonColor16"));

    builderButtons.append(bLabel, tbLabel);
    builderButtons.append(cbLabel, rbLabel);

    builderButtons.appendSeparator("Regular settings");

    this.addButtonRow(builderButtons, "Enabled", null, null);
    this.addButtonRow(builderButtons, "Flat", null,
        new ClientPropertyCommand(SubstanceLookAndFeel.FLAT_PROPERTY,
            Boolean.TRUE));
    this.addButtonRow(builderButtons, "Disabled", null,
        new DisableCommand());
    this
        .addButtonRow(builderButtons, "Selected", null,
            new SelectCommand());
    this.addButtonRow(builderButtons, "Disabled selected", null,
        new ChainCommand<Component>(new DisableCommand(),
            new SelectCommand()));

    builderButtons.appendSeparator("Background settings");
    this.addButtonRow(builderButtons, "Yellow", null,
        new BackgroundColorCommand(Color.yellow));
    this.addButtonRow(builderButtons, "Yellow flat", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.yellow), new ClientPropertyCommand(
            SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE)));
    this.addButtonRow(builderButtons, "Yellow disabled", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.yellow), new DisableCommand()));
    this.addButtonRow(builderButtons, "Yellow selected", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.yellow), new SelectCommand()));
    this.addButtonRow(builderButtons, "Yellow disabled selected", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.yellow), new SelectCommand(),
            new DisableCommand()));
    this.addButtonRow(builderButtons, "Red", null,
        new BackgroundColorCommand(Color.red));
    this.addButtonRow(builderButtons, "Red disabled", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.red), new DisableCommand()));
    this.addButtonRow(builderButtons, "Red selected", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.red), new SelectCommand()));
    this.addButtonRow(builderButtons, "Red disabled selected", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.red), new SelectCommand(), new DisableCommand()));
    this.addButtonRow(builderButtons, "Green", null,
        new BackgroundColorCommand(Color.green));
    this.addButtonRow(builderButtons, "Green disabled", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.green), new DisableCommand()));
    this.addButtonRow(builderButtons, "Green selected", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.green), new SelectCommand()));
    this
        .addButtonRow(builderButtons, "Green disabled selected", null,
            new ChainCommand<Component>(new BackgroundColorCommand(
                Color.green), new SelectCommand(),
                new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark Green", null,
        new BackgroundColorCommand(Color.green.darker()));
    this.addButtonRow(builderButtons, "Dark Green disabled", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.green.darker()), new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark Green selected", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.green.darker()), new SelectCommand()));
    this.addButtonRow(builderButtons, "Dark Green disabled selected", null,
        new ChainCommand<Component>(new BackgroundColorCommand(
            Color.green.darker()), new SelectCommand(),
            new DisableCommand()));

    builderButtons.appendSeparator("Foreground settings");
    this.addButtonRow(builderButtons, "Yellow", null,
        new ForegroundColorCommand(Color.yellow));
    this.addButtonRow(builderButtons, "Yellow disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.yellow), new DisableCommand()));
    this.addButtonRow(builderButtons, "Yellow selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.yellow), new SelectCommand()));
    this.addButtonRow(builderButtons, "Yellow disabled selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.yellow), new SelectCommand(),
            new DisableCommand()));
    this.addButtonRow(builderButtons, "Red", null,
        new ForegroundColorCommand(Color.red));
    this.addButtonRow(builderButtons, "Red disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.red), new DisableCommand()));
    this.addButtonRow(builderButtons, "Red selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.red), new SelectCommand()));
    this.addButtonRow(builderButtons, "Red disabled selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.red), new SelectCommand(), new DisableCommand()));
    this.addButtonRow(builderButtons, "Green", null,
        new ForegroundColorCommand(Color.green));
    this.addButtonRow(builderButtons, "Green disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green), new DisableCommand()));
    this.addButtonRow(builderButtons, "Green selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green), new SelectCommand()));
    this
        .addButtonRow(builderButtons, "Green disabled selected", null,
            new ChainCommand<Component>(new ForegroundColorCommand(
                Color.green), new SelectCommand(),
                new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark Green", null,
        new ForegroundColorCommand(Color.green.darker()));
    this.addButtonRow(builderButtons, "Dark Green disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green.darker()), new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark Green selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green.darker()), new SelectCommand()));
    this.addButtonRow(builderButtons, "Dark Green disabled selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green.darker()), new SelectCommand(),
            new DisableCommand()));

    builderButtons.appendSeparator("Combined settings");
    this.addButtonRow(builderButtons, "Blue/yellow", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.blue), new BackgroundColorCommand(Color.yellow)));
    this.addButtonRow(builderButtons, "Blue/yellow disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.blue), new BackgroundColorCommand(Color.yellow),
            new DisableCommand()));
    this.addButtonRow(builderButtons, "Blue/yellow selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.blue), new BackgroundColorCommand(Color.yellow),
            new SelectCommand()));
    this.addButtonRow(builderButtons, "Blue/yellow disabled selected",
        null, new ChainCommand<Component>(new ForegroundColorCommand(
            Color.blue), new BackgroundColorCommand(Color.yellow),
            new SelectCommand(), new DisableCommand()));
    this.addButtonRow(builderButtons, "Red/light green", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.red), new BackgroundColorCommand(Color.green
            .brighter())));
    this.addButtonRow(builderButtons, "Red/light green disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.red), new BackgroundColorCommand(Color.green
            .brighter()), new DisableCommand()));
    this.addButtonRow(builderButtons, "Red/light green selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.red), new BackgroundColorCommand(Color.green
            .brighter()), new SelectCommand()));
    this
        .addButtonRow(builderButtons,
            "Red/light green disabled selected", null,
            new ChainCommand<Component>(new ForegroundColorCommand(
                Color.red), new BackgroundColorCommand(
                Color.green.brighter()), new SelectCommand(),
                new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark yellow/blue", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.yellow.darker()), new BackgroundColorCommand(
            Color.blue)));
    this.addButtonRow(builderButtons, "Dark yellow/blue disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.yellow.darker()), new BackgroundColorCommand(
            Color.blue), new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark yellow/blue selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.yellow.darker()), new BackgroundColorCommand(
            Color.blue), new SelectCommand()));
    this
        .addButtonRow(builderButtons,
            "Dark yellow/blue disabled selected", null,
            new ChainCommand<Component>(new ForegroundColorCommand(
                Color.yellow.darker()),
                new BackgroundColorCommand(Color.blue),
                new SelectCommand(), new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark green/magenta", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green.darker()), new BackgroundColorCommand(
            Color.magenta)));
    this.addButtonRow(builderButtons, "Dark green/magenta disabled", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green.darker()), new BackgroundColorCommand(
            Color.magenta), new DisableCommand()));
    this.addButtonRow(builderButtons, "Dark green/magenta selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green.darker()), new BackgroundColorCommand(
            Color.magenta), new SelectCommand()));
    this.addButtonRow(builderButtons,
        "Dark green/magenta disabled selected", null,
        new ChainCommand<Component>(new ForegroundColorCommand(
            Color.green.darker()), new BackgroundColorCommand(
            Color.magenta), new SelectCommand(),
            new DisableCommand()));

    JPanel panelButtons = builderButtons.getPanel();
    JScrollPane jspButtons = new JScrollPane(panelButtons);
    panelButtons.setOpaque(false);
    jspButtons.setOpaque(false);
    jspButtons.getViewport().setOpaque(false);

    FormLayout lmOther = new FormLayout(
        "right:pref, 10dlu, left:pref:grow(1), 4dlu,"
            + "left:pref:grow(1), 4dlu, left:pref:grow(1), "
            + "4dlu, left:pref:grow(1)", "");
    lmOther.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
    DefaultFormBuilder builderOther = new DefaultFormBuilder(lmOther,
        new ScrollablePanel());
    builderOther.setDefaultDialogBorder();

    builderOther.append("");
    builderOther.append(new JLabel("Yellow"), new JLabel(
        "Blue + red foreground"));
    builderOther.append(new JLabel("Green"), new JLabel("Dark green"));

    builderOther.appendSeparator("Labels");
    addControlRow(builderOther, "Regular",
        new CreationCommand<Component>() {
          public Component create() {
            return new JLabel("label");
          }
        }, null);
    addControlRow(builderOther, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            return new JLabel("label");
          }
        }, new DisableCommand());
    addControlRow(builderOther, "HTML", new CreationCommand<Component>() {
      public Component create() {
        return new JLabel(
            "<html>text <b>text</b> <font color='red'>text</font>");
      }
    }, null);

    builderOther.appendSeparator("Sliders");
    addControlRow(builderOther, "Regular",
        new CreationCommand<Component>() {
          public Component create() {
            return new JSlider(0, 100, 50);
          }
        }, null);
    addControlRow(builderOther, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            return new JSlider(0, 100, 50);
          }
        }, new DisableCommand());

    builderOther.appendSeparator("Progress bars");
    addControlRow(builderOther, "Regular",
        new CreationCommand<Component>() {
          public Component create() {
            JProgressBar jpb = new JProgressBar(0, 100);
            jpb.setIndeterminate(false);
            jpb.setValue(50);
            jpb.setStringPainted(true);
            return jpb;
          }
        }, null);
    addControlRow(builderOther, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JProgressBar jpb = new JProgressBar(0, 100);
            jpb.setIndeterminate(false);
            jpb.setValue(50);
            jpb.setStringPainted(true);
            return jpb;
          }
        }, new DisableCommand());
    addControlRow(builderOther, "Custom foreground",
        new CreationCommand<Component>() {
          public Component create() {
            JProgressBar jpb = new JProgressBar(0, 100);
            jpb.setIndeterminate(false);
            jpb.setValue(50);
            jpb.setStringPainted(true);
            return jpb;
          }
        }, new ForegroundColorCommand(Color.red));
    addControlRow(builderOther, "Disabled with foreground",
        new CreationCommand<Component>() {
          public Component create() {
            JProgressBar jpb = new JProgressBar(0, 100);
            jpb.setIndeterminate(false);
            jpb.setValue(50);
            jpb.setStringPainted(true);
            return jpb;
          }
        }, new ChainCommand<Component>(new DisableCommand(),
            new ForegroundColorCommand(Color.red)));
    addControlRow(builderOther, "Indeterminate",
        new CreationCommand<Component>() {
          public Component create() {
            JProgressBar jpb = new JProgressBar(0, 100);
            jpb.setIndeterminate(true);
            return jpb;
          }
        }, null);
    addControlRow(builderOther, "Indeterminate disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JProgressBar jpb = new JProgressBar(0, 100);
            jpb.setIndeterminate(true);
            return jpb;
          }
        }, new DisableCommand());

    builderOther.appendSeparator("Combo boxes");
    addControlRow(builderOther, "Regular",
        new CreationCommand<Component>() {
          public Component create() {
            JComboBox jcb = new JComboBox(new Object[] { "Ester",
                "Jordi", "Jordina", "Jorge", "Sergi" });
            return jcb;
          }
        }, null);
    addControlRow(builderOther, "Flat", new CreationCommand<Component>() {
      public Component create() {
        JComboBox jcb = new JComboBox(new Object[] { "Ester", "Jordi",
            "Jordina", "Jorge", "Sergi" });
        return jcb;
      }
    }, new ClientPropertyCommand(SubstanceLookAndFeel.FLAT_PROPERTY,
        Boolean.TRUE));
    addControlRow(builderOther, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JComboBox jcb = new JComboBox(new Object[] { "Ester",
                "Jordi", "Jordina", "Jorge", "Sergi" });
            return jcb;
          }
        }, new DisableCommand());
    addControlRow(builderOther, "Editable",
        new CreationCommand<Component>() {
          public Component create() {
            JComboBox jcb = new JComboBox(new Object[] { "Ester",
                "Jordi", "Jordina", "Jorge", "Sergi" });
            jcb.setEditable(true);
            return jcb;
          }
        }, null);
    addControlRow(builderOther, "Disabled editable",
        new CreationCommand<Component>() {
          public Component create() {
            JComboBox jcb = new JComboBox(new Object[] { "Ester",
                "Jordi", "Jordina", "Jorge", "Sergi" });
            jcb.setEditable(true);
            return jcb;
          }
        }, new DisableCommand());

    CreationCommand<Component> spinnerCreationCmd = new CreationCommand<Component>() {
      public Component create() {
        JSpinner s = new JSpinner(new SpinnerListModel(new Object[] {
            "sample0", "sample", "sample2" }));
        s.getModel().setValue("sample");
        return s;
      }
    };
    builderOther.appendSeparator("Spinners");
    addControlRow(builderOther, "Regular", spinnerCreationCmd, null);
    addControlRow(builderOther, "Flat", spinnerCreationCmd,
        new ClientPropertyCommand(SubstanceLookAndFeel.FLAT_PROPERTY,
            Boolean.TRUE));
    addControlRow(builderOther, "Disabled", spinnerCreationCmd,
        new DisableCommand());

    JPanel panelOther = builderOther.getPanel();
    JScrollPane jspOther = new JScrollPane(panelOther);
    panelOther.setOpaque(false);
    jspOther.setOpaque(false);
    jspOther.getViewport().setOpaque(false);

    FormLayout lmText = new FormLayout(
        "right:pref, 10dlu, left:pref:grow(1), 4dlu,"
            + "left:pref:grow(1), 4dlu, left:pref:grow(1), "
            + "4dlu, left:pref:grow(1)", "");
    lmText.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
    DefaultFormBuilder builderText = new DefaultFormBuilder(lmText,
        new ScrollablePanel());
    builderText.setDefaultDialogBorder();

    builderText.append("");
    builderText.append(new JLabel("Yellow"), new JLabel(
        "Blue + red foreground"));
    builderText.append(new JLabel("Green"), new JLabel("Dark green"));

    builderText.appendSeparator("Text fields");
    addControlRow(builderText, "Regular", new CreationCommand<Component>() {
      public Component create() {
        JTextField field = new JTextField("test", 15);
        return field;
      }
    }, null);
    addControlRow(builderText, "Watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JTextField field = new JTextField("test", 15);
            return field;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderText, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JTextField field = new JTextField("test", 15);
            return field;
          }
        }, new DisableCommand());
    addControlRow(builderText, "Not editable",
        new CreationCommand<Component>() {
          public Component create() {
            JTextField field = new JTextField("test", 15);
            field.setEditable(false);
            return field;
          }
        }, null);

    builderText.appendSeparator("Formatted text fields");
    addControlRow(builderText, "Regular", new CreationCommand<Component>() {
      public Component create() {
        JFormattedTextField field = new JFormattedTextField(
            new DecimalFormat("#,##0.0000"));
        field.setText("2,430.0000");
        return field;
      }
    }, null);
    addControlRow(builderText, "Watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JFormattedTextField field = new JFormattedTextField(
                new DecimalFormat("#,##0.0000"));
            field.setText("2,430.0000");
            return field;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderText, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JFormattedTextField field = new JFormattedTextField(
                new DecimalFormat("#,##0.0000"));
            field.setText("2,430.0000");
            return field;
          }
        }, new DisableCommand());
    addControlRow(builderText, "Not editable",
        new CreationCommand<Component>() {
          public Component create() {
            JFormattedTextField field = new JFormattedTextField(
                new DecimalFormat("#,##0.0000"));
            field.setText("2,430.0000");
            field.setEditable(false);
            return field;
          }
        }, null);

    builderText.appendSeparator("Password fields");
    addControlRow(builderText, "Regular", new CreationCommand<Component>() {
      public Component create() {
        JPasswordField field = new JPasswordField("password", 15);
        return field;
      }
    }, null);
    addControlRow(builderText, "Watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JPasswordField field = new JPasswordField("password",
                15);
            return field;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderText, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JPasswordField field = new JPasswordField("password",
                15);
            return field;
          }
        }, new DisableCommand());
    addControlRow(builderText, "Not editable",
        new CreationCommand<Component>() {
          public Component create() {
            JPasswordField field = new JPasswordField("password",
                15);
            field.setEditable(false);
            return field;
          }
        }, null);

    builderText.appendSeparator("Editor panes");
    addControlRow(builderText, "Regular", new CreationCommand<Component>() {
      public Component create() {
        JEditorPane pane = new JEditorPane("text/html;",
            "Sample <b>content</b><br> <u>text</u>");
        return pane;
      }
    }, null);
    addControlRow(builderText, "Watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JEditorPane pane = new JEditorPane("text/html;",
                "Sample <b>content</b><br> <u>text</u>");
            return pane;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderText, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JEditorPane pane = new JEditorPane("text/html;",
                "Sample <b>content</b><br> <u>text</u>");
            return pane;
          }
        }, new DisableCommand());
    addControlRow(builderText, "Not editable",
        new CreationCommand<Component>() {
          public Component create() {
            JEditorPane pane = new JEditorPane("text/html;",
                "Sample <b>content</b><br> <u>text</u>");
            pane.setEditable(false);
            return pane;
          }
        }, null);

    builderText.appendSeparator("Text areas");
    addControlRow(builderText, "Regular", new CreationCommand<Component>() {
      public Component create() {
        JTextArea area = new JTextArea("Sample content text", 3, 15);
        return area;
      }
    }, null);
    addControlRow(builderText, "Watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JTextArea area = new JTextArea("Sample content text",
                3, 15);
            return area;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderText, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JTextArea area = new JTextArea("Sample content text",
                3, 15);
            return area;
          }
        }, new DisableCommand());
    addControlRow(builderText, "Not editable",
        new CreationCommand<Component>() {
          public Component create() {
            JTextArea area = new JTextArea("Sample content text",
                3, 15);
            area.setEditable(false);
            return area;
          }
        }, null);

    builderText.appendSeparator("Text panes");
    addControlRow(builderText, "Regular", new CreationCommand<Component>() {
      public Component create() {
        JTextPane pane = new JTextPane();
        pane.replaceSelection("Sample content text");
        pane.setPreferredSize(new Dimension(120, 40));
        return pane;
      }
    }, null);
    addControlRow(builderText, "Watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JTextPane pane = new JTextPane();
            pane.replaceSelection("Sample content text");
            pane.setPreferredSize(new Dimension(120, 40));
            return pane;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderText, "Disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JTextPane pane = new JTextPane();
            pane.replaceSelection("Sample content text");
            pane.setPreferredSize(new Dimension(120, 40));
            return pane;
          }
        }, new DisableCommand());
    addControlRow(builderText, "Not editable",
        new CreationCommand<Component>() {
          public Component create() {
            JTextPane pane = new JTextPane();
            pane.replaceSelection("Sample content text");
            pane.setPreferredSize(new Dimension(120, 40));
            pane.setEditable(false);
            return pane;
          }
        }, null);

    JPanel panelText = builderText.getPanel();
    JScrollPane jspText = new JScrollPane(panelText);
    panelText.setOpaque(false);
    jspText.setOpaque(false);
    jspText.getViewport().setOpaque(false);

    JScrollPane coloredScrollPane = new JScrollPane(new CheckeredPanel());
    coloredScrollPane.setBackground(Color.yellow);
    coloredScrollPane.getVerticalScrollBar().setBackground(Color.green);

    FormLayout lmCells = new FormLayout(
        "right:pref, 10dlu, fill:pref:grow(1), 4dlu,"
            + "fill:pref:grow(1), 4dlu, fill:pref:grow(1), "
            + "4dlu, fill:pref:grow(1)", "");
    lmCells.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
    DefaultFormBuilder builderCells = new DefaultFormBuilder(lmCells,
        new ScrollablePanel());
    builderCells.setDefaultDialogBorder();

    builderCells.append("");
    builderCells.append(new JLabel("Yellow"), new JLabel(
        "Blue + red foreground"));
    builderCells.append(new JLabel("Green"), new JLabel("Dark green"));

    builderCells.appendSeparator("Lists");
    addControlRow(builderCells, "List", new CreationCommand<Component>() {
      public Component create() {
        JList list = new JList(new Object[] { "entry1", "entry2",
            "entry3" });
        return list;
      }
    }, null);
    addControlRow(builderCells, "List watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JList list = new JList(new Object[] { "entry1",
                "entry2", "entry3" });
            return list;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderCells, "List disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JList list = new JList(new Object[] { "entry1",
                "entry2", "entry3" });
            return list;
          }
        }, new DisableCommand());

    CreationCommand<Component> tableCreationCmd = new CreationCommand<Component>() {
      public Component create() {
        final JTable table = new JTable(new Object[][] {
            { "entry11", "entry12", "entry13" },
            { "entry21", "entry22", "entry23" },
            { "entry31", "entry32", "entry33" } }, new Object[] {
            "Column1", "Column2", "Column3" });
        table.setName("Table ");
        JScrollPane tableScroll = new JScrollPane(table) {
          @Override
          public void setBackground(Color bg) {
            super.setBackground(bg);
            table.setBackground(bg);
            table.getTableHeader().setBackground(bg);
          }

          @Override
          public void setForeground(Color fg) {
            super.setForeground(fg);
            table.setForeground(fg);
            table.getTableHeader().setForeground(fg);
          }
        };
        Dimension prefTable = table.getPreferredSize();
        tableScroll.setPreferredSize(new Dimension(prefTable.width,
            prefTable.height + 25));
        return tableScroll;
      }
    };
    builderCells.appendSeparator("Tables");
    addControlRow(builderCells, "Table", tableCreationCmd, null);
    addControlRow(builderCells, "Table watermark", tableCreationCmd,
        new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderCells, "Table disabled", tableCreationCmd,
        new DisableViewportCommand());

    CreationCommand<Component> treeCreationCmd = new CreationCommand<Component>() {
      public void expandAll(JTree tree, boolean expand) {
        TreeNode root = (TreeNode) tree.getModel().getRoot();

        // Traverse tree from root
        expandAll(tree, new TreePath(root), expand);
      }

      private void expandAll(JTree tree, TreePath parent, boolean expand) {
        // Traverse children
        TreeNode node = (TreeNode) parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
          for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
          }
        }

        // Expansion or collapse must be done bottom-up
        if (expand) {
          tree.expandPath(parent);
        } else {
          tree.collapsePath(parent);
        }
      }

      public Component create() {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
        DefaultMutableTreeNode son1 = new DefaultMutableTreeNode("son1");
        DefaultMutableTreeNode son2 = new DefaultMutableTreeNode("son2");
        DefaultMutableTreeNode son3 = new DefaultMutableTreeNode("son3");
        DefaultMutableTreeNode gson11 = new DefaultMutableTreeNode(
            "gson11");
        DefaultMutableTreeNode gson12 = new DefaultMutableTreeNode(
            "gson12");
        DefaultMutableTreeNode gson21 = new DefaultMutableTreeNode(
            "gson21");
        DefaultMutableTreeNode gson22 = new DefaultMutableTreeNode(
            "gson22");
        DefaultMutableTreeNode gson31 = new DefaultMutableTreeNode(
            "gson31");
        DefaultMutableTreeNode gson32 = new DefaultMutableTreeNode(
            "gson32");
        DefaultMutableTreeNode ggson111 = new DefaultMutableTreeNode(
            "ggson111");
        DefaultMutableTreeNode ggson112 = new DefaultMutableTreeNode(
            "ggson112");
        DefaultMutableTreeNode ggson113 = new DefaultMutableTreeNode(
            "ggson113");

        gson11.add(ggson111);
        gson11.add(ggson112);
        gson11.add(ggson113);
        son1.add(gson11);
        son1.add(gson12);
        son2.add(gson21);
        son2.add(gson22);
        son3.add(gson31);
        son3.add(gson32);
        root.add(son1);
        root.add(son2);
        root.add(son3);

        JTree tree = new JTree(root);
        expandAll(tree, true);
        return tree;
      }
    };
    builderCells.appendSeparator("Trees");
    addControlRow(builderCells, "Tree", treeCreationCmd, null);
    addControlRow(builderCells, "Tree watermark", treeCreationCmd,
        new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderCells, "Tree disabled", treeCreationCmd,
        new DisableCommand());

    JPanel panelCells = builderCells.getPanel();
    JScrollPane jspCells = new JScrollPane(panelCells);
    panelCells.setOpaque(false);
    jspCells.setOpaque(false);
    jspCells.getViewport().setOpaque(false);
View Full Code Here


                  Mapping sel = (Mapping) list
                      .getSelectedValue();
                  FormLayout lm = new FormLayout(
                      "right:pref, 4dlu, left:pref:grow",
                      "");
                  DefaultFormBuilder builder = new DefaultFormBuilder(
                      lm, new ScrollablePanel());
                  builder.setDefaultDialogBorder();
                  for (int fontSize = 11; fontSize < 25; fontSize++) {
                    builder.append(fontSize + " pixels",
                        sel.creator.create(fontSize));
                  }
                  builder.append("72 pixels", sel.creator
                      .create(72));
                  central = new JScrollPane(
                      builder.getPanel(),
                      JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                      JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                  add(central, BorderLayout.CENTER);
                  doLayout();
                  revalidate();
View Full Code Here

        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    this.setLayout(new BorderLayout());
    this.add(this.sp, BorderLayout.CENTER);

    FormLayout lm = new FormLayout("right:pref, 4dlu, fill:pref:grow", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm,
        new ScrollablePanel());

    builder.appendSeparator("General settings");
    final JCheckBox isEnabled = new JCheckBox("is enabled");
    isEnabled.setSelected(true);
    isEnabled.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        boolean toEnable = isEnabled.isSelected();
        sp.setEnabled(toEnable);
        updateEnabledState(sp, toEnable);
        Check.out("Scroll pane is " + toEnable);
      }
    });
    builder.append("Enabled", isEnabled);

    final JCheckBox hasNullBorder = new JCheckBox("Has null border");
    hasNullBorder.setSelected(false);
    hasNullBorder.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (hasNullBorder.isSelected())
          sp.setBorder(null);
        else
          sp.setBorder(new LineBorder(Color.red));
        sp.repaint();
      }
    });
    builder.append("Border", hasNullBorder);

    final JCheckBox hasPreview = new JCheckBox("Has preview");
    hasPreview.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        sp.putClientProperty(LafWidget.COMPONENT_PREVIEW_PAINTER,
            hasPreview.isSelected() ? new DefaultPreviewPainter()
                : null);
      }
    });
    builder.append("Preview", hasPreview);

    final JCheckBox hasAutoScroll = new JCheckBox("Has auto scroll");
    hasAutoScroll.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        sp.putClientProperty(LafWidget.AUTO_SCROLL, hasAutoScroll
            .isSelected() ? Boolean.TRUE : null);
      }
    });
    builder.append("Auto scroll", hasAutoScroll);

    builder.appendSeparator("Scroll buttons settings");
    final JComboBox buttonPolicyCombo = new JComboBox(new Object[] {
        ScrollPaneButtonPolicyKind.NONE,
        ScrollPaneButtonPolicyKind.OPPOSITE,
        ScrollPaneButtonPolicyKind.ADJACENT,
        ScrollPaneButtonPolicyKind.MULTIPLE,
        ScrollPaneButtonPolicyKind.MULTIPLE_BOTH });
    buttonPolicyCombo.setSelectedItem(ScrollPaneButtonPolicyKind.OPPOSITE);
    buttonPolicyCombo.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        ScrollPaneButtonPolicyKind buttonPolicy = (ScrollPaneButtonPolicyKind) buttonPolicyCombo
            .getSelectedItem();
        sp.putClientProperty(
            SubstanceLookAndFeel.SCROLL_PANE_BUTTONS_POLICY,
            buttonPolicy);
        sp.repaint();
      }
    });
    builder.append("Button policy", buttonPolicyCombo);

    final JCheckBox isFlat = new JCheckBox("Is flat");
    isFlat.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        sp.putClientProperty(SubstanceLookAndFeel.FLAT_PROPERTY, isFlat
            .isSelected() ? Boolean.TRUE : null);
        sp.repaint();
      }
    });
    builder.append("Flat", isFlat);

    final JCheckBox isNever = new JCheckBox("Is never painted");
    isNever.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        sp.putClientProperty(
            SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY,
            isNever.isSelected() ? Boolean.TRUE : null);
        sp.repaint();
      }
    });
    builder.append("Never", isNever);

    this.controlPanel = builder.getPanel();
  }
View Full Code Here

    FormLayout lm = new FormLayout(
        "right:pref, 4dlu, fill:default:grow(1), 4dlu,"
            + "fill:default:grow(1), 4dlu, fill:default:grow(1)",
        "");
    // lm.setColumnGroups(new int[][] { { 3, 5, 7 } });
    DefaultFormBuilder builder = new DefaultFormBuilder(lm,
        new ScrollablePanel());
    builder.setDefaultDialogBorder();

    JLabel textLabel = new JLabel("Text fields");
    JLabel formattedTextLabel = new JLabel("Formatted text fields");
    JLabel passwordLabel = new JLabel("Password fields");
    // textLabel.setFont(textLabel.getFont().deriveFont(Font.BOLD));
    // formattedTextLabel.setFont(formattedTextLabel.getFont().deriveFont(
    // Font.BOLD));
    // passwordLabel.setFont(passwordLabel.getFont().deriveFont(Font.BOLD));

    builder.append("", textLabel);
    builder.append(formattedTextLabel, passwordLabel);

    JTextField jtf1 = new JTextField("sample text");
    builder.append("Enabled", jtf1);

    JFormattedTextField jftf1 = new JFormattedTextField(new DecimalFormat(
        "#,##0.0000"));
    jftf1.setText("2,430.0000");
    JPasswordField jpf1 = new JPasswordField("password", 10);
    builder.append(jftf1, jpf1);

    JTextField jtfNotEditable = new JTextField("sample text");
    jtfNotEditable.setEditable(false);
    builder.append("Not editable", jtfNotEditable);

    JFormattedTextField jftfNotEditable = new JFormattedTextField(
        new DecimalFormat("#,##0.0000"));
    jftfNotEditable.setText("2,430.0000");
    jftfNotEditable.setEditable(false);
    JPasswordField jpfNotEditable = new JPasswordField("password", 10);
    jpfNotEditable.setEditable(false);
    builder.append(jftfNotEditable, jpfNotEditable);

    JTextField jtfNotEditableNoLock = new JTextField("sample text");
    jtfNotEditableNoLock.setEditable(false);
    jtfNotEditableNoLock.putClientProperty(LafWidget.NO_LOCK_ICON,
        Boolean.TRUE);
    builder.append("Not editable no lock", jtfNotEditableNoLock);

    JFormattedTextField jftfNotEditableNoLock = new JFormattedTextField(
        new DecimalFormat("#,##0.0000"));
    jftfNotEditableNoLock.setText("2,430.0000");
    jftfNotEditableNoLock.setEditable(false);
    jftfNotEditableNoLock.putClientProperty(LafWidget.NO_LOCK_ICON,
        Boolean.TRUE);
    JPasswordField jpfNotEditableNoLock = new JPasswordField("password", 10);
    jpfNotEditableNoLock.setEditable(false);
    jpfNotEditableNoLock.putClientProperty(LafWidget.NO_LOCK_ICON,
        Boolean.TRUE);
    builder.append(jftfNotEditableNoLock, jpfNotEditableNoLock);

    JTextField jtfDisabled = new JTextField("sample text");
    jtfDisabled.setEnabled(false);
    builder.append("Disabled", jtfDisabled);

    JFormattedTextField jftfDisabled = new JFormattedTextField(
        new DecimalFormat("#,##0.0000"));
    jftfDisabled.setText("2,430.0000");
    jftfDisabled.setEnabled(false);
    JPasswordField jpfDisabled = new JPasswordField("password", 10);
    jpfDisabled.setEnabled(false);
    builder.append(jftfDisabled, jpfDisabled);

    JTextField jtfNonOpaque = new JTextField("sample text");
    jtfNonOpaque.setOpaque(false);
    builder.append("Non opaque", jtfNonOpaque);

    JFormattedTextField jftfNonOpaque = new JFormattedTextField(
        new DecimalFormat("#,##0.0000"));
    jftfNonOpaque.setText("2,430.0000");
    jftfNonOpaque.setOpaque(false);
    JPasswordField jpfNonOpaque = new JPasswordField("password", 10);
    jpfNonOpaque.setOpaque(false);
    builder.append(jftfNonOpaque, jpfNonOpaque);

    JTextField jtfWatermarkBleed = new JTextField("sample text");
    jtfWatermarkBleed.putClientProperty(
        SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE);
    builder.append("Watermark bleed", jtfWatermarkBleed);

    JFormattedTextField jftfWatermarkBleed = new JFormattedTextField(
        new DecimalFormat("#,##0.0000"));
    jftfWatermarkBleed.setText("2,430.0000");
    jftfWatermarkBleed.putClientProperty(
        SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE);
    JPasswordField jpfWatermarkBleed = new JPasswordField("password", 10);
    jpfWatermarkBleed.putClientProperty(
        SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE);
    builder.append(jftfWatermarkBleed, jpfWatermarkBleed);

    JTextField jtf4 = new JTextField("sample text");
    jtf4.putClientProperty(LafWidget.TEXT_SELECT_ON_FOCUS, Boolean.TRUE);
    builder.append("Select all on focus", jtf4);

    JFormattedTextField jftf4 = new JFormattedTextField(new DecimalFormat(
        "#,##0.0000"));
    jftf4.setText("2,430.0000");
    jftf4.putClientProperty(LafWidget.TEXT_SELECT_ON_FOCUS, Boolean.TRUE);
    builder.append(jftf4);
    builder.nextLine();

    JTextField jtf4_1 = new JTextField("sample text");
    jtf4_1.putClientProperty(LafWidget.TEXT_FLIP_SELECT_ON_ESCAPE,
        Boolean.TRUE);
    builder.append("Flip selection on ESC", jtf4_1);

    JFormattedTextField jftf4_1 = new JFormattedTextField(
        new DecimalFormat("#,##0.0000"));
    jftf4_1.setText("2,430.0000");
    jftf4_1.putClientProperty(LafWidget.TEXT_FLIP_SELECT_ON_ESCAPE,
        Boolean.TRUE);
    builder.append(jftf4_1);
    builder.nextLine();

    JTextField jtf5 = new JTextField("sample text");
    jtf5.putClientProperty(LafWidget.TEXT_EDIT_CONTEXT_MENU, Boolean.TRUE);
    builder.append("With context menu", jtf5);

    JFormattedTextField jftf5 = new JFormattedTextField(new DecimalFormat(
        "#,##0.0000"));
    jftf5.setText("2,430.0000");
    jftf5.putClientProperty(LafWidget.TEXT_EDIT_CONTEXT_MENU, Boolean.TRUE);
    builder.append(jftf5);
    builder.nextLine();

    JTextField jtf6 = new JTextField("sample text");
    jtf6.setMargin(new Insets(2, 2, 2, 2));
    builder.append("With margin a2", jtf6);

    JFormattedTextField jftf6 = new JFormattedTextField(new DecimalFormat(
        "#,##0.0000"));
    jftf6.setText("2,430.0000");
    jftf6.setMargin(new Insets(2, 2, 2, 2));
    JPasswordField jpf6 = new JPasswordField("password", 10);
    jpf6.setMargin(new Insets(2, 2, 2, 2));
    builder.append(jftf6, jpf6);

    JTextField jtf60 = new JTextField("sample text");
    jtf60.setMargin(new Insets(0, 10, 0, 0));
    builder.append("With margin l10", jtf60);

    JFormattedTextField jftf60 = new JFormattedTextField(new DecimalFormat(
        "#,##0.0000"));
    jftf60.setText("2,430.0000");
    jftf60.setMargin(new Insets(0, 10, 0, 0));
    JPasswordField jpf60 = new JPasswordField("password", 10);
    jpf60.setMargin(new Insets(0, 10, 0, 0));
    builder.append(jftf60, jpf60);

    JPasswordField jpfEmptyEchoChar = new JPasswordField("password", 10);
    jpfEmptyEchoChar.setEchoChar((char) 0);
    builder.append("Empty echo char", new JLabel());
    builder.append(new JLabel(), jpfEmptyEchoChar);

    JPasswordField jpfStrengthChecker = new JPasswordField("password", 10);
    try {
      jpfStrengthChecker.putClientProperty(
          LafWidget.PASSWORD_STRENGTH_CHECKER,
          new PasswordStrengthChecker() {
            public PasswordStrength getStrength(char[] password) {
              if (password == null)
                return PasswordStrength.WEAK;
              int length = password.length;
              if (length < 3)
                return PasswordStrength.WEAK;
              if (length < 6)
                return PasswordStrength.MEDIUM;
              return PasswordStrength.STRONG;
            }

            public String getDescription(PasswordStrength strength) {
              if (strength == PasswordStrength.WEAK)
                return "<html>This password is <b>way</b> too weak</html>";
              if (strength == PasswordStrength.MEDIUM)
                return "<html>Come on, you can do<br> a little better than that</html>";
              if (strength == PasswordStrength.STRONG)
                return "OK";
              return null;
            }
          });
      builder.append("Strength checker", new JLabel());
      builder.append(new JLabel(), jpfStrengthChecker);
    } catch (Throwable t) {
    }

    JPasswordField jpfTwoEchoChar = new JPasswordField("password", 10);
    jpfTwoEchoChar.putClientProperty(
        SubstanceLookAndFeel.PASSWORD_ECHO_PER_CHAR, new Integer(2));
    builder.append("Two echo chars", new JLabel());
    builder.append(new JLabel(), jpfTwoEchoChar);

    JLabel editorPaneLabel = new JLabel("Editor panes");
    JLabel textAreaLabel = new JLabel("Text areas");
    JLabel textPaneLabel = new JLabel("Text panes");
    // editorPaneLabel
    // .setFont(editorPaneLabel.getFont().deriveFont(Font.BOLD));
    // textAreaLabel.setFont(textAreaLabel.getFont().deriveFont(Font.BOLD));
    // textPaneLabel.setFont(textPaneLabel.getFont().deriveFont(Font.BOLD));

    builder.append("", editorPaneLabel);
    builder.append(textAreaLabel, textPaneLabel);

    JEditorPane jep1 = new JEditorPane("text/html;",
        "Sample <b>content</b><br> <u>text</u>");
    builder.append("Enabled", jep1);

    JTextArea jta1 = new JTextArea("Sample content text", 3, 20);
    JTextPane jtp1 = new JTextPane();
    jtp1.replaceSelection("Sample content text");
    jtp1.setPreferredSize(new Dimension(100, 40));
    builder.append(jta1, jtp1);

    JEditorPane jepNotEditable = new JEditorPane("text/html;",
        "Sample <b>content</b><br> <u>text</u>");
    jepNotEditable.setEditable(false);
    builder.append("Not editable", jepNotEditable);

    JTextArea jtaNotEditable = new JTextArea("Sample content text", 3, 20);
    jtaNotEditable.setEditable(false);
    JTextPane jtpNotEditable = new JTextPane();
    jtpNotEditable.replaceSelection("Sample content text");
    jtpNotEditable.setPreferredSize(new Dimension(100, 40));
    jtpNotEditable.setEditable(false);
    builder.append(jtaNotEditable, jtpNotEditable);

    JEditorPane jepNotEditableNoLock = new JEditorPane("text/html;",
        "Sample <b>content</b><br> <u>text</u>");
    jepNotEditableNoLock.setEditable(false);
    jepNotEditableNoLock.putClientProperty(LafWidget.NO_LOCK_ICON,
        Boolean.TRUE);
    builder.append("Not editable no lock", jepNotEditableNoLock);

    JTextArea jtaNotEditableNoLock = new JTextArea("Sample content text",
        3, 20);
    jtaNotEditableNoLock.setEditable(false);
    jtaNotEditableNoLock.putClientProperty(LafWidget.NO_LOCK_ICON,
        Boolean.TRUE);
    JTextPane jtpNotEditableNoLock = new JTextPane();
    jtpNotEditableNoLock.replaceSelection("Sample content text");
    jtpNotEditableNoLock.setPreferredSize(new Dimension(100, 40));
    jtpNotEditableNoLock.setEditable(false);
    jtpNotEditableNoLock.putClientProperty(LafWidget.NO_LOCK_ICON,
        Boolean.TRUE);
    builder.append(jtaNotEditableNoLock, jtpNotEditableNoLock);

    JEditorPane jep3 = new JEditorPane("text/html;",
        "Sample <b>content</b><br> <u>text</u>");
    jep3.setEnabled(false);
    builder.append("Disabled", jep3);

    JTextArea jta3 = new JTextArea("Sample content text", 3, 20);
    jta3.setEnabled(false);
    JTextPane jtp3 = new JTextPane();
    jtp3.replaceSelection("Sample content text");
    jtp3.setPreferredSize(new Dimension(100, 40));
    jtp3.setEnabled(false);
    builder.append(jta3, jtp3);

    JEditorPane jepNonOpaque = new JEditorPane("text/html;",
        "Sample <b>content</b><br> <u>text</u>");
    jepNonOpaque.setOpaque(false);
    builder.append("Non opaque", jepNonOpaque);

    JTextArea jtaNonOpaque = new JTextArea("Sample content text", 3, 20);
    jtaNonOpaque.setOpaque(false);
    JTextPane jtpNonOpaque = new JTextPane();
    jtpNonOpaque.replaceSelection("Sample content text");
    jtpNonOpaque.setPreferredSize(new Dimension(100, 40));
    jtpNonOpaque.setOpaque(false);
    builder.append(jtaNonOpaque, jtpNonOpaque);

    JEditorPane jepWatermarkBleed = new JEditorPane("text/html;",
        "Sample <b>content</b><br> <u>text</u>");
    jepWatermarkBleed.putClientProperty(
        SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE);
    builder.append("Watermark bleed", jepWatermarkBleed);

    JTextArea jtaWatermarkBleed = new JTextArea("Sample content text", 3,
        20);
    jtaWatermarkBleed.putClientProperty(
        SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE);
    JTextPane jtpWatermarkBleed = new JTextPane();
    jtpWatermarkBleed.replaceSelection("Sample content text");
    jtpWatermarkBleed.setPreferredSize(new Dimension(100, 40));
    jtpWatermarkBleed.putClientProperty(
        SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE);
    builder.append(jtaWatermarkBleed, jtpWatermarkBleed);

    JEditorPane jep4 = new JEditorPane("text/html;",
        "Sample <b>content</b><br> <u>text</u>");
    jep4.setMargin(new Insets(2, 2, 2, 2));
    builder.append("With margin", jep4);

    JTextArea jta4 = new JTextArea("Sample content text", 3, 20);
    jta4.setMargin(new Insets(2, 2, 2, 2));
    JTextPane jtp4 = new JTextPane();
    jtp4.replaceSelection("Sample content text");
    jtp4.setPreferredSize(new Dimension(100, 40));
    jtp4.setMargin(new Insets(2, 2, 2, 2));
    builder.append(jta4, jtp4);

    JTextArea jtaLineWrap = new JTextArea(
        "The contents of this text area wrap, but not necessarily between words",
        3, 15);
    jtaLineWrap.setLineWrap(true);
    builder.append("Line wrap", new JLabel(""));
    builder.append(jtaLineWrap, new JLabel(""));

    JTextArea jtaLineWrapWords = new JTextArea(
        "The contents of this text area wrap, necessarily between words",
        3, 15);
    jtaLineWrapWords.setLineWrap(true);
    jtaLineWrapWords.setWrapStyleWord(true);
    builder.append("Line wrap words", new JLabel(""));
    builder.append(jtaLineWrapWords, new JLabel(""));

    JTextArea textAreaScroll = new JTextArea(5, 15);
    for (int i = 0; i < 20; i++) {
      textAreaScroll.append("Some long long long line with number " + i
          + "\n");
    }
    textAreaScroll.setEditable(false);
    builder.append("Scrollable", new JScrollPane(textAreaScroll));
    builder.nextLine();

    JTextArea textAreaScrollNoLock = new JTextArea(5, 15);
    for (int i = 0; i < 20; i++) {
      textAreaScrollNoLock.append("Some long long long line with number "
          + i + "\n");
    }
    textAreaScrollNoLock.setEditable(false);
    textAreaScrollNoLock.putClientProperty(LafWidget.NO_LOCK_ICON,
        Boolean.TRUE);
    builder.append("Scrollable no lock", new JScrollPane(
        textAreaScrollNoLock));

    return builder.getPanel();
  }
View Full Code Here

        Color.black, Color.blue);
    instructionalTimeline.setDuration(1000);
    instructionalTimeline.playLoop(RepeatBehavior.REVERSE);

    FormLayout lm = new FormLayout("right:pref, 4dlu, fill:pref:grow", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm,
        new ScrollablePanel());

    builder.appendSeparator("Table settings");
    final JCheckBox isEnabled = new JCheckBox("is enabled");
    isEnabled.setSelected(table.isEnabled());
    isEnabled.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        table.setEnabled(isEnabled.isSelected());
        // the table header is not repainted on disabling / enabling :(
        table.getTableHeader().repaint();
      }
    });
    builder.append("Enabled", isEnabled);

    JButton changeFirstColumn = new JButton("change 1st column");
    changeFirstColumn.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        new Thread(new Runnable() {
          public void run() {
            for (int i = 0; i < table.getModel().getRowCount(); i++) {
              table.getModel().setValueAt(
                  Thread.currentThread().getName() + " " + i,
                  i, 0);
              try {
                Thread.sleep(200);
              } catch (InterruptedException e) {
              }
            }
          }
        }).start();
      }
    });
    builder.append("Change values", changeFirstColumn);

    final JSlider rowCountSlider = new JSlider(20, 1000, this.table
        .getModel().getRowCount());
    rowCountSlider.setPaintLabels(false);
    rowCountSlider.setPaintTicks(false);
    rowCountSlider.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        if (rowCountSlider.getValueIsAdjusting())
          return;
        TablePanel.this.table.setModel(new MyTableModel(rowCountSlider
            .getValue()));
      }
    });
    builder.append("Row count", rowCountSlider);

    final JCheckBox areRowsSelectable = new JCheckBox("Rows selectable");
    areRowsSelectable.setSelected(this.table.getRowSelectionAllowed());
    areRowsSelectable.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TablePanel.this.table.setRowSelectionAllowed(areRowsSelectable
            .isSelected());
      }
    });
    builder.append("Selectable", areRowsSelectable);

    final JCheckBox areColsSelectable = new JCheckBox("Cols selectable");
    areColsSelectable.setSelected(this.table.getColumnSelectionAllowed());
    areColsSelectable.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TablePanel.this.table
            .setColumnSelectionAllowed(areColsSelectable
                .isSelected());
      }
    });
    builder.append("", areColsSelectable);

    final JCheckBox isSorted = new JCheckBox("Sorted");
    isSorted.setSelected(table.getAutoCreateRowSorter());
    isSorted.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        table.setAutoCreateRowSorter(isSorted.isSelected());
        table.repaint();
        table.getTableHeader().repaint();
      }
    });
    builder.append("Sorted", isSorted);

    final JCheckBox customBackgroundCb = new JCheckBox(
        "Has pink background");
    customBackgroundCb.addActionListener(new ActionListener() {
      Color oldBackColor;

      public void actionPerformed(ActionEvent e) {
        if (customBackgroundCb.isSelected()) {
          oldBackColor = table.getBackground();
          table.setBackground(new Color(255, 128, 128));
        } else {
          table.setBackground(oldBackColor);
        }
      }
    });
    builder.append("Background", customBackgroundCb);

    final JCheckBox watermarkBleed = new JCheckBox("Watermark bleed");
    watermarkBleed.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TablePanel.this.table.putClientProperty(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean
                .valueOf(watermarkBleed.isSelected()));
        tableScrollpane.putClientProperty(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean
                .valueOf(watermarkBleed.isSelected()));
        tableScrollpane.repaint();
      }
    });
    builder.append("Watermark", watermarkBleed);

    final JCheckBox linesVertical = new JCheckBox("Vertical visible");
    linesVertical.setSelected(this.table.getShowVerticalLines());
    linesVertical.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TablePanel.this.table.setShowVerticalLines(linesVertical
            .isSelected());
      }
    });
    builder.append("Lines", linesVertical);
    final JCheckBox linesHorizontal = new JCheckBox("Horizontal visible");
    linesHorizontal.setSelected(this.table.getShowHorizontalLines());
    linesHorizontal.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TablePanel.this.table.setShowHorizontalLines(linesHorizontal
            .isSelected());
      }
    });
    builder.append("", linesHorizontal);

    final JComboBox resizeModeCombo = new FlexiComboBox<Integer>(
        JTable.AUTO_RESIZE_OFF, JTable.AUTO_RESIZE_NEXT_COLUMN,
        JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS,
        JTable.AUTO_RESIZE_LAST_COLUMN, JTable.AUTO_RESIZE_ALL_COLUMNS) {
      @Override
      public String getCaption(Integer item) {
        int iv = item;
        switch (iv) {
        case JTable.AUTO_RESIZE_OFF:
          return "off";
        case JTable.AUTO_RESIZE_NEXT_COLUMN:
          return "next";
        case JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS:
          return "subsequent";
        case JTable.AUTO_RESIZE_LAST_COLUMN:
          return "last";
        case JTable.AUTO_RESIZE_ALL_COLUMNS:
          return "all";
        }
        return null;
      }
    };
    resizeModeCombo.setSelectedItem(this.table.getAutoResizeMode());

    resizeModeCombo.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        int selected = (Integer) resizeModeCombo.getSelectedItem();
        TablePanel.this.table.setAutoResizeMode(selected);
      }
    });

    builder.append("Resize mode", resizeModeCombo);

    final JCheckBox hasRollovers = new JCheckBox("Has rollover effect");
    hasRollovers.setSelected(FadeConfigurationManager.getInstance()
        .fadeAllowed(FadeKind.ROLLOVER, this.table));
    hasRollovers.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (hasRollovers.isSelected()) {
          FadeConfigurationManager.getInstance().allowFades(
              FadeKind.ROLLOVER, TablePanel.this.table);
        } else {
          FadeConfigurationManager.getInstance().disallowFades(
              FadeKind.ROLLOVER, TablePanel.this.table);
        }
      }
    });
    builder.append("Rollovers", hasRollovers);

    final JCheckBox hasSelectionAnimations = new JCheckBox(
        "Has selection effect");
    hasSelectionAnimations.setSelected(FadeConfigurationManager
        .getInstance().fadeAllowed(FadeKind.SELECTION, this.table));
    hasSelectionAnimations.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        if (hasSelectionAnimations.isSelected()) {
          FadeConfigurationManager.getInstance().allowFades(
              FadeKind.SELECTION, TablePanel.this.table);
        } else {
          FadeConfigurationManager.getInstance().disallowFades(
              FadeKind.SELECTION, TablePanel.this.table);
        }
      }
    });
    builder.append("Selections", hasSelectionAnimations);

    builder.appendSeparator("Font settings");
    JButton tahoma12 = new JButton("Tahoma 12");
    tahoma12.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        table.setFont(new Font("Tahoma", Font.PLAIN, 12));
      }
    });
    builder.append("Set font", tahoma12);

    JButton tahoma13 = new JButton("Tahoma 13");
    tahoma13.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        table.setFont(new Font("Tahoma", Font.PLAIN, 13));
      }
    });
    builder.append("Set font", tahoma13);

    this.controlPanel = builder.getPanel();
    this.isInitialized = true;
  }
View Full Code Here

    FormLayout lm = new FormLayout(
        "right:pref, 10dlu, left:pref:grow(1), 4dlu,"
            + "left:pref:grow(1), 4dlu, left:pref:grow(1), "
            + "4dlu, left:pref:grow(1)", "");
    lm.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
    DefaultFormBuilder builder = new DefaultFormBuilder(lm,
        new ScrollablePanel());
    builder.setDefaultDialogBorder();

    builder.append("");
    JLabel bLabel = new JLabel("Buttons");
    bLabel.setIcon(Check.getIcon("JButtonColor16"));
    JLabel tbLabel = new JLabel("Toggle buttons");
    tbLabel.setIcon(Check.getIcon("JToggleButtonColor16"));
    JLabel cbLabel = new JLabel("Check boxes");
    cbLabel.setIcon(Check.getIcon("JCheckBoxColor16"));
    JLabel rbLabel = new JLabel("Radio buttons");
    rbLabel.setIcon(Check.getIcon("JRadioButtonColor16"));

    // bLabel.setFont(bLabel.getFont().deriveFont(Font.BOLD));
    // tbLabel.setFont(rbLabel.getFont().deriveFont(Font.BOLD));
    // cbLabel.setFont(cbLabel.getFont().deriveFont(Font.BOLD));
    // rbLabel.setFont(rbLabel.getFont().deriveFont(Font.BOLD));

    builder.append(bLabel, tbLabel);
    builder.append(cbLabel, rbLabel);

    builder.appendSeparator("Regular settings");
    this.addRow(builder, "Enabled", null, null);
    this.addRow(builder, "Disabled", null, new DisableCommand());
    this.addRow(builder, "Selected", null, new SelectCommand());
    this.addRow(builder, "Disabled selected", null,
        new ChainCommand<Component>(new DisableCommand(),
            new SelectCommand()));
    this.addRow(builder, "HTML text", null, new TextCommand(
        "<html>text <b>text</b> <font color='red'>text</font>"));
    this.addRow(builder, "Long text", null, new TextCommand(
        "Some long long text"));
    this.addRow(builder, "With tooltip", null, new TooltipTextCommand(
        "Sample tooltip"));
    this
        .addRow(builder, "Disabled with tooltip", null,
            new ChainCommand(new TooltipTextCommand(
                "Sample tooltip"), new DisableCommand()));
    this.addRow(builder, "Popup menu", null, new PopupMenuCommand());
    this.addRow(builder, "With icon", Check.getIcon("flag_sweden"),
        new IconCommand(Check.getIcon("flag_sweden")));

    builder.appendSeparator("Focus indications");
    this.addRow(builder, "No focus painted", null, new NoFocusCommand());
    this
        .addRow(builder, "None", null, new FocusKindCommand(
            FocusKind.NONE));
    this
        .addRow(builder, "Text", null, new FocusKindCommand(
            FocusKind.TEXT));
    this.addRow(builder, "All", null, new FocusKindCommand(FocusKind.ALL));
    this.addRow(builder, "All inner", null, new FocusKindCommand(
        FocusKind.ALL_INNER));
    this.addRow(builder, "All strong inner", null, new FocusKindCommand(
        FocusKind.ALL_STRONG_INNER));
    this.addRow(builder, "Underline", null, new FocusKindCommand(
        FocusKind.UNDERLINE));
    this.addRow(builder, "Strong underline", null, new FocusKindCommand(
        FocusKind.STRONG_UNDERLINE));

    builder.appendSeparator("Animation speed settings");
    this.addRow(builder, "None", null, new AnimationKindCommand(
        AnimationKind.NONE));
    this.addRow(builder, "Fast", null, new AnimationKindCommand(
        AnimationKind.FAST));
    this.addRow(builder, "Regular", null, new AnimationKindCommand(
        AnimationKind.REGULAR));
    this.addRow(builder, "Slow", null, new AnimationKindCommand(
        AnimationKind.SLOW));
    this.addRow(builder, "Debug", null, new AnimationKindCommand(
        AnimationKind.DEBUG));

    builder.appendSeparator("Size settings");
    this.addRow(builder, "No min size", null, new NoMinSizeCommand());
    this.addRow(builder, "Custom margin", null, new MarginCommand());

    builder.appendSeparator("Side settings");
    this.addRow(builder, "Straight top", null, new StraightSideCommand(
        Side.TOP));
    this.addRow(builder, "Straight bottom", null, new StraightSideCommand(
        Side.BOTTOM));
    this.addRow(builder, "Straight left", null, new StraightSideCommand(
        EnumSet.of(Side.LEFT)));
    this.addRow(builder, "Straight right", null, new StraightSideCommand(
        EnumSet.of(Side.RIGHT)));

    this.addRow(builder, "Open top", null,
        new ChainCommand<AbstractButton>(new StraightSideCommand(
            Side.TOP), new OpenSideCommand(Side.TOP)));
    this.addRow(builder, "Open bottom", null,
        new ChainCommand<AbstractButton>(new StraightSideCommand(
            Side.BOTTOM), new OpenSideCommand(Side.BOTTOM)));
    this.addRow(builder, "Open left", null,
        new ChainCommand<AbstractButton>(new StraightSideCommand(
            EnumSet.of(Side.LEFT)), new OpenSideCommand(EnumSet
            .of(Side.LEFT))));
    this.addRow(builder, "Open right", null,
        new ChainCommand<AbstractButton>(new StraightSideCommand(
            EnumSet.of(Side.RIGHT)), new OpenSideCommand(EnumSet
            .of(Side.RIGHT))));

    builder.appendSeparator("Unicode texts");
    this.addRow(builder, "Hebrew", null, new ChainCommand<AbstractButton>(
        new TextCommand("\u05D0\u05D1\u05D2"), new IconCommand(Check
            .getIcon("flag_israel"))));
    this.addRow(builder, "Chinese", null, new ChainCommand<AbstractButton>(
        new FontCommand(new Font("Arial Unicode MS", Font.PLAIN, 11)),
        new TextCommand("\u4E01\u4E02\u4E03"), new IconCommand(Check
            .getIcon("flag_china"))));
    this.addRow(builder, "Cyrillic", null,
        new ChainCommand<AbstractButton>(new TextCommand(
            "\u0430\u0431\u0432"), new IconCommand(Check
            .getIcon("flag_russia"))));
    this.addRow(builder, "Greek", null, new ChainCommand<AbstractButton>(
        new TextCommand("\u03B1\u03B2\u03B3"), new IconCommand(Check
            .getIcon("flag_greece"))));
    this.addRow(builder, "Latin", null, new ChainCommand<AbstractButton>(
        new TextCommand("\u00E6\u00F0\u0127\u2248"), new IconCommand(
            Check.getIcon("flag_italy"))));

    builder.appendSeparator("Misc settings");
    this.addRow(builder, "No content area", null,
        new NoContentAreaFilledCommand());
    this.addRow(builder, "No border", null, new NoBorderPaintedCommand());
    this.addRow(builder, "No background", null,
        new ChainCommand<AbstractButton>(
            new NoContentAreaFilledCommand(),
            new NoBorderPaintedCommand()));
    this.addRow(builder, "Flat", null, new ClientPropertyCommand(
        SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE));
    this
        .addRow(builder, "Never", null, new ClientPropertyCommand(
            SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY,
            Boolean.TRUE));

    this.addRow(builder, "Fixed font", null, new FontCommand(new Font(
        "Arial", Font.PLAIN, 12)));
    this.addRow(builder, "Null text", null, new TextCommand(null));
    this.addRow(builder, "Empty text", null, new TextCommand(""));

    JPanel panel = builder.getPanel();
    JScrollPane jsp = new JScrollPane(panel);
    panel.setOpaque(false);
    jsp.putClientProperty(LafWidget.AUTO_SCROLL, Boolean.TRUE);
    jsp.setOpaque(false);
    jsp.getViewport().setOpaque(false);
View Full Code Here

    tabbed.addTab("Regular", new JPanel());

    JPanel samplePanel = new JPanel(new BorderLayout());
    FormLayout lm = new FormLayout("fill:default:grow(1), 4dlu,"
        + "fill:default:grow(1)", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm,
        new ScrollablePanel());
    builder.setLineGapSize(Sizes.pixel(1));
    builder.setBorder(new EmptyBorder(2, 2, 2, 2));
    // lm.setColumnGroups(new int[][] { { 3, 5, 7 } });

    // TwoColumnPanel stuff = new TwoColumnPanel();
    // stuff.setVerticalSpacing(4);
    // stuff.setHorizontalSpacing(0);

    JCheckBox cb1 = new JCheckBox("Enabled selected");
    cb1.setSelected(true);
    JCheckBox cb2 = new JCheckBox("Disabled selected");
    cb2.setSelected(true);
    cb2.setEnabled(false);
    JCheckBox cb3 = new JCheckBox("Enabled unselected");
    // cb3.setEnabled(false);
    JRadioButton rb1 = new JRadioButton("Enabled selected");
    rb1.setSelected(true);
    JRadioButton rb2 = new JRadioButton("Disabled selected");
    rb2.setSelected(true);
    rb2.setEnabled(false);
    JRadioButton rb3 = new JRadioButton("Enabled unselected");
    // rb3.setEnabled(false);

    builder.append(cb1, rb1);
    builder.append(cb2, rb2);
    builder.append(cb3, rb3);
    JComboBox combo = new JComboBox(new Object[] { "item1", "item2",
        "item3", "item4" });
    combo.setSelectedIndex(0);
    combo.setEditable(true);
    JTextField text = new JTextField("Text field");
    text.setEditable(false);
    builder.append(combo, text);
    JPanel contentPanel = builder.getPanel();
    contentPanel.setPreferredSize(new Dimension(contentPanel
        .getPreferredSize().width,
        contentPanel.getPreferredSize().height + 100));
    // contentPanel.setOpaque(false);
    contentPanel.setBorder(null);
View Full Code Here

  public static JPanel getPanel() {
    FormLayout lm = new FormLayout(
        "fill:pref, 2dlu, fill:pref, 0dlu, fill:min:grow, 0dlu, fill:pref, 2dlu, fill:pref",
        "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm);
    builder.setBorder(new EmptyBorder(0, 0, 0, 0));

    final JLabel fontSizeLabel = new JLabel();
    fontSizeLabel.setText(SubstanceLookAndFeel.getFontPolicy().getFontSet(
        "Substance", null).getControlFont().getSize()
        + " pt.");
    builder.append(fontSizeLabel);
    // fontSizeLabel.add(Box.createHorizontalStrut(5));

    Icon zoomOutIcon = new ImageIcon(Thread.currentThread()
        .getContextClassLoader().getResource(
            "test/check/icons/16/zoom_out.png"));
    JLabel zoomOutLabel = new JLabel(zoomOutIcon);
    zoomOutLabel.putClientProperty(
        SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS, Boolean.TRUE);
    builder.append(zoomOutLabel);

    final JSlider fontSizeSlider = new JSlider(0, 10, 0);
    fontSizeSlider.setFocusable(false);
    // fontSizeSlider.setOpaque(false);
    fontSizeSlider
        .setToolTipText("Controls the global font set size. Resets Substance as the current LAF.");
    fontSizeSlider.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        // if the value is adjusting - ignore. This is done
        // to make CPU usage better.
        if (!fontSizeSlider.getModel().getValueIsAdjusting()) {
          final int newValue = fontSizeSlider.getValue();
          SwingUtilities.invokeLater(new Runnable() {
            public void run() {
              SubstanceLookAndFeel.setFontPolicy(null);
              final FontSet substanceCoreFontSet = SubstanceLookAndFeel
                  .getFontPolicy().getFontSet("Substance",
                      null);
              FontPolicy newFontPolicy = new FontPolicy() {
                public FontSet getFontSet(String lafName,
                    UIDefaults table) {
                  return new WrapperFontSet(
                      substanceCoreFontSet, newValue);
                }
              };

              SubstanceLookAndFeel.setFontPolicy(newFontPolicy);

              fontSizeLabel.setText(SubstanceLookAndFeel
                  .getFontPolicy().getFontSet("Substance",
                      null).getControlFont().getSize()
                  + " pt.");
            }
          });
        }
      }
    });
    builder.append(fontSizeSlider);

    Icon zoomInIcon = new ImageIcon(Thread.currentThread()
        .getContextClassLoader().getResource(
            "test/check/icons/16/zoom_in.png"));
    JLabel zoomInLabel = new JLabel(zoomInIcon);
    zoomInLabel.putClientProperty(
        SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS, Boolean.TRUE);
    builder.append(zoomInLabel);

    JButton tahoma = new JButton("Tahoma 11");
    tahoma.putClientProperty(
        SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY, Boolean.TRUE);
    tahoma.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            SubstanceLookAndFeel.setFontPolicy(null);
            FontPolicy newFontPolicy = new FontPolicy() {
              public FontSet getFontSet(String lafName,
                  UIDefaults table) {
                return new Tahoma11FontSet();
              }
            };

            SubstanceLookAndFeel.setFontPolicy(newFontPolicy);

            fontSizeLabel.setText(SubstanceLookAndFeel
                .getFontPolicy().getFontSet("Substance", null)
                .getControlFont().getSize()
                + " pt.");
          }
        });
      }
    });
    builder.append(tahoma);

    JPanel result = builder.getPanel();
    // result.setOpaque(false);
    return result;
  }
View Full Code Here

    FormLayout lmCells = new FormLayout(
        "right:pref, 10dlu, fill:pref:grow(1), 4dlu,"
            + "fill:pref:grow(1), 4dlu, fill:pref:grow(1), "
            + "4dlu, fill:pref:grow(1)", "");
    lmCells.setColumnGroups(new int[][] { { 3, 5, 7, 9 } });
    DefaultFormBuilder builderCells = new DefaultFormBuilder(lmCells,
        new ScrollablePanel());
    builderCells.setDefaultDialogBorder();

    builderCells.append("");
    builderCells.append(new JLabel("NONE"), new JLabel("GENERAL"));
    builderCells.append(new JLabel("HEADER"), new JLabel("FOOTER"));

    builderCells.appendSeparator("Lists");
    addControlRow(builderCells, "List", new CreationCommand<Component>() {
      public Component create() {
        JList list = new JList(new Object[] { "entry1", "entry2",
            "entry3" });
        return list;
      }
    }, null);
    addControlRow(builderCells, "List watermark",
        new CreationCommand<Component>() {
          public Component create() {
            JList list = new JList(new Object[] { "entry1",
                "entry2", "entry3" });
            return list;
          }
        }, new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderCells, "List disabled",
        new CreationCommand<Component>() {
          public Component create() {
            JList list = new JList(new Object[] { "entry1",
                "entry2", "entry3" });
            return list;
          }
        }, new DisableCommand());

    CreationCommand<Component> tableCreationCmd = new CreationCommand<Component>() {
      public Component create() {
        final JTable table = new JTable(new Object[][] {
            { "entry11", "entry12", "entry13" },
            { "entry21", "entry22", "entry23" },
            { "entry31", "entry32", "entry33" } }, new Object[] {
            "Column1", "Column2", "Column3" });
        table.setName("Table ");
        JScrollPane tableScroll = new JScrollPane(table) {
          @Override
          public void setBackground(Color bg) {
            super.setBackground(bg);
            table.setBackground(bg);
            table.getTableHeader().setBackground(bg);
          }

          @Override
          public void setForeground(Color fg) {
            super.setForeground(fg);
            table.setForeground(fg);
            table.getTableHeader().setForeground(fg);
          }
        };
        Dimension prefTable = table.getPreferredSize();
        tableScroll.setPreferredSize(new Dimension(prefTable.width,
            prefTable.height + 25));
        return tableScroll;
      }
    };
    builderCells.appendSeparator("Tables");
    addControlRow(builderCells, "Table", tableCreationCmd, null);
    addControlRow(builderCells, "Table watermark", tableCreationCmd,
        new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderCells, "Table disabled", tableCreationCmd,
        new DisableViewportCommand());

    CreationCommand<Component> treeCreationCmd = new CreationCommand<Component>() {
      public void expandAll(JTree tree, boolean expand) {
        TreeNode root = (TreeNode) tree.getModel().getRoot();

        // Traverse tree from root
        expandAll(tree, new TreePath(root), expand);
      }

      private void expandAll(JTree tree, TreePath parent, boolean expand) {
        // Traverse children
        TreeNode node = (TreeNode) parent.getLastPathComponent();
        if (node.getChildCount() >= 0) {
          for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            expandAll(tree, path, expand);
          }
        }

        // Expansion or collapse must be done bottom-up
        if (expand) {
          tree.expandPath(parent);
        } else {
          tree.collapsePath(parent);
        }
      }

      public Component create() {
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
        DefaultMutableTreeNode son1 = new DefaultMutableTreeNode("son1");
        DefaultMutableTreeNode son2 = new DefaultMutableTreeNode("son2");
        DefaultMutableTreeNode son3 = new DefaultMutableTreeNode("son3");
        DefaultMutableTreeNode gson11 = new DefaultMutableTreeNode(
            "gson11");
        DefaultMutableTreeNode gson12 = new DefaultMutableTreeNode(
            "gson12");
        DefaultMutableTreeNode gson21 = new DefaultMutableTreeNode(
            "gson21");
        DefaultMutableTreeNode gson22 = new DefaultMutableTreeNode(
            "gson22");
        DefaultMutableTreeNode gson31 = new DefaultMutableTreeNode(
            "gson31");
        DefaultMutableTreeNode gson32 = new DefaultMutableTreeNode(
            "gson32");
        DefaultMutableTreeNode ggson111 = new DefaultMutableTreeNode(
            "ggson111");
        DefaultMutableTreeNode ggson112 = new DefaultMutableTreeNode(
            "ggson112");
        DefaultMutableTreeNode ggson113 = new DefaultMutableTreeNode(
            "ggson113");

        gson11.add(ggson111);
        gson11.add(ggson112);
        gson11.add(ggson113);
        son1.add(gson11);
        son1.add(gson12);
        son2.add(gson21);
        son2.add(gson22);
        son3.add(gson31);
        son3.add(gson32);
        root.add(son1);
        root.add(son2);
        root.add(son3);

        JTree tree = new JTree(root);
        expandAll(tree, true);
        return tree;
      }
    };
    builderCells.appendSeparator("Trees");
    addControlRow(builderCells, "Tree", treeCreationCmd, null);
    addControlRow(builderCells, "Tree watermark", treeCreationCmd,
        new ClientPropertyCommand(
            SubstanceLookAndFeel.WATERMARK_VISIBLE, Boolean.TRUE));
    addControlRow(builderCells, "Tree disabled", treeCreationCmd,
        new DisableCommand());

    JPanel panelCells = builderCells.getPanel();
    JScrollPane jspCells = new JScrollPane(panelCells);
    panelCells.setOpaque(false);
    jspCells.setOpaque(false);
    jspCells.getViewport().setOpaque(false);
View Full Code Here

    this.setLayout(new BorderLayout());
    jdp = new JDesktopPane();
    this.add(jdp, BorderLayout.CENTER);

    FormLayout lm = new FormLayout("right:pref, 4dlu, fill:pref:grow", "");
    DefaultFormBuilder builder = new DefaultFormBuilder(lm,
        new ScrollablePanel());
    builder.appendSeparator("New sample frame");

    JButton sample = new JButton("Add");
    sample.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            JInternalFrame jif = new SampleInternalFrame() {
              // @Override
              // public void paint(Graphics g) {
              // long start = System.nanoTime();
              // super.paint(g);
              // long end = System.nanoTime();
              // System.err.println("paint done in " + (end -
              // start));
              // }
            };
            jif.setBounds(0, 0, 300, 200);
            jdp.add(jif);
            jif.setVisible(true);
            jif.setComponentOrientation(jdp
                .getComponentOrientation());
          }
        });
      }
    });
    builder.append("Add sample", sample);

    builder.appendSeparator("New custom frame");
    final JCheckBox makeZero = new JCheckBox("Has zero bounds");
    builder.append("Custom settings", makeZero);

    final JCheckBox isClosable = new JCheckBox("Is closable");
    isClosable.setSelected(true);
    builder.append("", isClosable);

    final JCheckBox isMaximizable = new JCheckBox("Is maximizable");
    isMaximizable.setSelected(true);
    builder.append("", isMaximizable);

    final JCheckBox isIconifiable = new JCheckBox("Is iconifiable");
    isIconifiable.setSelected(true);
    builder.append("", isIconifiable);

    final JCheckBox isResizable = new JCheckBox("Is resizable");
    isResizable.setSelected(true);
    builder.append("", isResizable);

    JButton bt = new JButton("Add");
    bt.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        String title = "[" + count + "]Internal title ";
        int c = (int) (20 * Math.random());
        for (int i = 0; i < c; i++) {
          title += "0";
        }
        final JInternalFrame jif = new JInternalFrame(title);
        jif.setFrameIcon(SubstanceLogo.getLogoIcon(SubstanceLookAndFeel
            .getCurrentSkin(jif.getRootPane()).getColorScheme(
                DecorationAreaType.SECONDARY_TITLE_PANE,
                ColorSchemeAssociationKind.FILL,
                ComponentState.DEFAULT)));
        SubstanceLookAndFeel
            .registerSkinChangeListener(new SkinChangeListener() {
              public void skinChanged() {
                jif
                    .setFrameIcon(SubstanceLogo
                        .getLogoIcon(SubstanceLookAndFeel
                            .getCurrentSkin(
                                jif
                                    .getRootPane())
                            .getColorScheme(
                                DecorationAreaType.SECONDARY_TITLE_PANE,
                                ColorSchemeAssociationKind.FILL,
                                ComponentState.DEFAULT)));
              }
            });
        jif.setLayout(new BorderLayout());
        JPanel controls = new JPanel(new FlowLayout());
        int comps = 5 + (int) (10 * Math.random());
        for (int i = 0; i < comps; i++) {
          double r = Math.random();
          if (r < 0.1) {
            controls.add(new JButton("button" + i));
          } else {
            if (r < 0.2) {
              controls.add(new JLabel("label" + i));
            } else {
              if (r < 0.3) {
                controls.add(new JRadioButton("radio" + i));
              } else {
                if (r < 0.4) {
                  controls.add(new JCheckBox("check" + i));
                } else {
                  if (r < 0.5) {
                    controls.add(new JToggleButton("toggle"
                        + i));
                  } else {
                    if (r < 0.6) {
                      controls
                          .add(new JComboBox(
                              new Object[] { "combo"
                                  + i }));
                    } else {
                      if (r < 0.7) {
                        controls.add(new JTextField(
                            "text field" + i));
                      } else {
                        if (r < 0.8) {
                          controls
                              .add(new JPasswordField(
                                  "password"
                                      + i));
                        } else {
                          if (r < 0.9) {
                            controls
                                .add(new JSpinner());
                          } else {
                            controls
                                .add(new JList(
                                    new Object[] { "list"
                                        + i }));
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }

        jif.add(controls, BorderLayout.CENTER);
        jif.setClosable(isClosable.isSelected());
        jif.setMaximizable(isMaximizable.isSelected());
        jif.setIconifiable(isIconifiable.isSelected());
        jif.setResizable(isResizable.isSelected());

        JPanel buttons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        final JCheckBox isModified = new JCheckBox("modified");
        isModified.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jif.putClientProperty(
                SubstanceLookAndFeel.WINDOW_MODIFIED, Boolean
                    .valueOf(isModified.isSelected()));
          }
        });
        buttons.add(isModified);

        JButton changeTitleButton = new JButton("Change title");
        changeTitleButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            String random = "abcdefghijklmnopqrstuvwxyz     ";
            int length = (int) (50 * Math.random());
            String title = "";
            while (length > 0) {
              title += random
                  .charAt((int) (random.length() * Math
                      .random()));
              length--;
            }
            jif.setTitle(title);
          }
        });
        buttons.add(changeTitleButton);

        JButton setNullTitlePane = new JButton("Remove title pane");
        setNullTitlePane.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                ((BasicInternalFrameUI) jif.getUI())
                    .setNorthPane(null);
                jif.revalidate();
              }
            });
          }
        });
        buttons.add(setNullTitlePane);

        jif.add(buttons, BorderLayout.SOUTH);

        count++;
        int width = 50 + (int) (400 * Math.random());
        int height = 50 + (int) (200 * Math.random());
        jif.setBounds(20 * (count % 10), 20 * (count % 10), width,
            height);
        if (makeZero.isSelected())
          jif.setBounds(0, 0, 0, 0);
        jif.setBackground(new Color(128 + (int) (128 * Math.random()),
            128 + (int) (128 * Math.random()),
            128 + (int) (128 * Math.random())));
        // jif.setClosable(true);
        // jif.setMaximizable(true);
        // jif.setResizable(true);
        // jif.setIconifiable(true);
        jif.setComponentOrientation(jdp.getComponentOrientation());
        jdp.add(jif, 1);

        JMenuBar jmb = new JMenuBar();
        jmb.add(SampleMenuFactory.getSkinMenu());

        JMenu jm1 = new JMenu("Menu1");
        jm1.setMnemonic('1');
        int mcount = 0;
        for (LinkedList<JMenuItem> miList : SampleMenuFactory
            .getTestMenuItems()) {
          if (mcount > 0) {
            if (mcount % 2 == 0)
              jm1.addSeparator();
            else
              jm1.add(new JSeparator());
          }
          for (JMenuItem menuItem : miList) {
            jm1.add(menuItem);
          }
          mcount++;
        }
        jmb.add(jm1);
        jif.setJMenuBar(jmb);

        jif.show();
      }
    });

    builder.append("Add custom", bt);

    builder.appendSeparator("Operations");

    JButton minAll = new JButton("Execute");
    minAll.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        for (JInternalFrame jif : jdp.getAllFrames()) {
          try {
            jif.setIcon(true);
          } catch (PropertyVetoException pve) {
          }
        }
      }
    });
    builder.append("Minimize all", minAll);

    JButton closeAll = new JButton("Execute");
    closeAll.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        for (JInternalFrame jif : jdp.getAllFrames()) {
          try {
            jif.setClosed(true);
          } catch (PropertyVetoException pve) {
          }
        }
      }
    });
    builder.append("Close all", closeAll);

    JButton disposeAll = new JButton("Execute");
    disposeAll.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        for (JInternalFrame jif : jdp.getAllFrames()) {
          disposed.add(jif);
          jif.dispose();
        }
      }
    });
    builder.append("Dispose all", disposeAll);

    JButton reshowAll = new JButton("Execute");
    reshowAll.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        for (JInternalFrame jif : disposed) {
          jif.setVisible(true);
        }
      }
    });
    builder.append("Reshow all", reshowAll);

    this.controlPanel = builder.getPanel();

    this.setPreferredSize(new Dimension(400, 400));
    this.setSize(this.getPreferredSize());
    this.setMinimumSize(this.getPreferredSize());
  }
View Full Code Here

TOP

Related Classes of com.jgoodies.forms.builder.DefaultFormBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.