Example usage for com.jgoodies.looks.plastic PlasticLookAndFeel setPlasticTheme

List of usage examples for com.jgoodies.looks.plastic PlasticLookAndFeel setPlasticTheme

Introduction

In this page you can find the example usage for com.jgoodies.looks.plastic PlasticLookAndFeel setPlasticTheme.

Prototype

public static void setPlasticTheme(PlasticTheme theme) 

Source Link

Document

Sets the theme for colors and fonts used by the Plastic L&F.

After setting the theme, you need to re-install the Look&Feel, as well as update the UI's of any previously created components - just as if you'd change the Look&Feel.

Usage

From source file:ch.epfl.lis.gnwgui.GnwGui.java

License:Open Source License

/**
 * //  w  w w  .  j  a v a 2s. c  om
 */
public static void setLookAndFeel() {

    boolean defautlLAF = GnwGuiSettings.getInstance().useSwingNativeLookAndFeel();

    try {
        if (defautlLAF) {
            // use the native look and feel
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } else {
            PlasticLookAndFeel.setPlasticTheme(new Silver());
            UIManager.setLookAndFeel("com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
            PlasticXPLookAndFeel lookXP = new PlasticXPLookAndFeel();
            UIManager.setLookAndFeel(lookXP);
        }
    } catch (ClassNotFoundException e) {
        log.warning("Unable to set Java Look and Feel (ClassNotFoundException): " + e.getMessage());
    } catch (InstantiationException e) {
        log.warning("Unable to set Java Look and Feel (InstantiationException): " + e.getMessage());
    } catch (IllegalAccessException e) {
        log.warning("Unable to set Java Look and Feel (IllegalAccessException): " + e.getMessage());
    } catch (UnsupportedLookAndFeelException e) {
        log.warning("Unable to set Java Look and Feel (UnsupportedLookAndFeelException): " + e.getMessage());
    }
}

From source file:ch.hsr.audiotagger.AudioTaggerApplication.java

License:Open Source License

public static void main(String[] args) throws Exception {
    /* Vorbereiten: */
    initSettings();//  ww w  .j a va  2  s  . c o m
    boolean isMac = false;
    if (Settings.getInstance().getBoolean(Settings.KEY_COMMON_ENABLE_MAC_DETECTION)) {
        isMac = isMac();
    }

    /* Look&Feel: */
    if (!isMac) {
        try {
            PlasticLookAndFeel.setPlasticTheme(new SkyBlue());
            UIManager.setLookAndFeel(new PlasticXPLookAndFeel());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }

    } else {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
            e.printStackTrace();
        }
    }
    GUIImageManager.loadImageManager("/ch/hsr/audiotagger/ui/res/");

    /* Platformspezifisches AudioTaggerFrame instanzieren und anzeigen: */
    AudioTaggerFrame frame = null;
    if (isMac)
        frame = new MacAudioTaggerFrame();
    else
        frame = new UniversalAudioTaggerFrame();

    frame.setVisible(true);
}

From source file:com.archivas.clienttools.arcmover.gui.HCPDataMigrator.java

License:Open Source License

public static void main(String[] args) {
    try {/*w w w. ja  v a2 s .  co  m*/
        for (Map.Entry<Object, Object> prop : System.getProperties().entrySet()) {
            LOG.log(Level.INFO, "System Property: " + prop.getKey() + "=" + prop.getValue());
        }

        PlasticXPLookAndFeel.setPlasticTheme(new ExperienceBlue());
        PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());

        UIManager.setLookAndFeel(new PlasticXPLookAndFeel());

        // Change label texts per UI bug #21966
        UIManager.put(FILE_CHOOSER_LOOK_IN_LABEL_TEXT_PROPERTY,
                UIManager.getString(FILE_CHOOSER_LOOK_IN_LABEL_TEXT_PROPERTY).replace(":", ""));
        UIManager.put(FILE_CHOOSER_FILE_NAME_LABEL_TEXT_PROPERTY,
                UIManager.getString(FILE_CHOOSER_FILE_NAME_LABEL_TEXT_PROPERTY).replace(":", ""));
        UIManager.put(FILE_CHOOSER_FILES_OF_TYPE_LABEL_TEXT_PROPERTY,
                UIManager.getString(FILE_CHOOSER_FILES_OF_TYPE_LABEL_TEXT_PROPERTY).replace(":", ""));

    } catch (Exception e) {
        LOG.warning("" + e);
        throw new RuntimeException(e);
    }

    SplashDialog splash = new SplashDialog();
    try {
        validateLaunchOK(splash);
        upgrade(splash);
        new HCPDataMigrator(splash);
    } catch (StorageAdapterException e) {
        LOG.warning("" + e);
        throw new RuntimeException(e);
    }
}

From source file:com.github.mgeiss.xls2ora.Xls2Ora.java

License:Apache License

public static void main(String[] args) {
    try {/*from   w  ww . j  a  v a  2 s  . c om*/
        PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());
        UIManager.setLookAndFeel(new PlasticLookAndFeel());
    } catch (Exception ex) {
    }

    WorkflowController controller = new WorkflowController();
    controller.setStartPanel(new SelectSourcePanel(controller));
}

From source file:com.jnesto.platform.runner.Runner.java

License:Apache License

/**
 * Inicializa a camada de aparncia por padro.
 *
 *///  www . j  a  v a2  s. c  om
protected void initializeLookAndFeel() {
    try {
        PlasticLookAndFeel.setPlasticTheme(new com.jgoodies.looks.plastic.theme.ExperienceBlue());
        UIManager.setLookAndFeel(new com.jgoodies.looks.plastic.Plastic3DLookAndFeel());
    } catch (UnsupportedLookAndFeelException ex) {
    }
}

From source file:com.mirth.connect.client.ui.Mirth.java

License:Open Source License

public static void initUIManager() {
    try {/*from   w  w w  .ja v a  2s  .c o m*/
        PlasticLookAndFeel.setPlasticTheme(new MirthTheme());
        PlasticXPLookAndFeel look = new PlasticXPLookAndFeel();
        UIManager.setLookAndFeel(look);
        UIManager.put("win.xpstyle.name", "metallic");
        LookAndFeelAddons.setAddon(WindowsLookAndFeelAddons.class);

        /*
         * MIRTH-1225 and MIRTH-2019: Create alternate key bindings if CTRL is not the same as
         * the menu shortcut key (i.e. COMMAND on OSX)
         */
        if (InputEvent.CTRL_MASK != Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) {
            createAlternateKeyBindings();
        }

        if (SystemUtils.IS_OS_MAC) {
            OSXAdapter.setAboutHandler(Mirth.class, Mirth.class.getDeclaredMethod("aboutMac", (Class[]) null));
            OSXAdapter.setQuitHandler(Mirth.class, Mirth.class.getDeclaredMethod("quitMac", (Class[]) null));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    // keep the tooltips from disappearing
    ToolTipManager.sharedInstance().setDismissDelay(3600000);

    // TabbedPane defaults
    // UIManager.put("TabbedPane.selected", new Color(0xffffff));
    // UIManager.put("TabbedPane.background",new Color(225,225,225));
    // UIManager.put("TabbedPane.tabAreaBackground",new Color(225,225,225));
    UIManager.put("TabbedPane.highlight", new Color(225, 225, 225));
    UIManager.put("TabbedPane.selectHighlight", new Color(0xc3c3c3));
    UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0, 0, 0, 0));

    // TaskPane defaults
    UIManager.put("TaskPane.titleBackgroundGradientStart", new Color(0xffffff));
    UIManager.put("TaskPane.titleBackgroundGradientEnd", new Color(0xffffff));

    // Set fonts
    UIManager.put("TextPane.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ToggleButton.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Panel.font", UIConstants.DIALOG_FONT);
    UIManager.put("PopupMenu.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("OptionPane.font", UIConstants.DIALOG_FONT);
    UIManager.put("Label.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Tree.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ScrollPane.font", UIConstants.DIALOG_FONT);
    UIManager.put("TextField.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Viewport.font", UIConstants.DIALOG_FONT);
    UIManager.put("MenuBar.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("FormattedTextField.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("DesktopIcon.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TableHeader.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ToolTip.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("PasswordField.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TaskPane.font", UIConstants.TEXTFIELD_BOLD_FONT);
    UIManager.put("Table.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TabbedPane.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ProgressBar.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("CheckBoxMenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ColorChooser.font", UIConstants.DIALOG_FONT);
    UIManager.put("Button.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TextArea.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Spinner.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("RadioButton.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("TitledBorder.font", UIConstants.TEXTFIELD_BOLD_FONT);
    UIManager.put("EditorPane.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("RadioButtonMenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ToolBar.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("MenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("CheckBox.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("JXTitledPanel.title.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("Menu.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("ComboBox.font", UIConstants.TEXTFIELD_PLAIN_FONT);
    UIManager.put("JXLoginPanel.banner.font", UIConstants.BANNER_FONT);
    UIManager.put("List.font", UIConstants.TEXTFIELD_PLAIN_FONT);

    InputMap im = (InputMap) UIManager.get("Button.focusInputMap");
    im.put(KeyStroke.getKeyStroke("pressed ENTER"), "pressed");
    im.put(KeyStroke.getKeyStroke("released ENTER"), "released");

    try {
        UIManager.put("wizard.sidebar.image",
                ImageIO.read(com.mirth.connect.client.ui.Frame.class.getResource("images/wizardsidebar.png")));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.mirth.connect.manager.ManagerDialog.java

License:Open Source License

public ManagerDialog() {
    try {/* w  w  w .ja va  2  s. co  m*/
        PlasticLookAndFeel.setPlasticTheme(new MirthTheme());
        PlasticXPLookAndFeel look = new PlasticXPLookAndFeel();
        UIManager.setLookAndFeel(look);
        UIManager.put("win.xpstyle.name", "metallic");

        LookAndFeelAddons.setAddon(WindowsLookAndFeelAddons.class);

        getContentPane().setBackground(Color.WHITE);
        setTitle("Mirth Connect Server Manager");
        setResizable(false);

        serviceController = ServiceControllerFactory.getServiceController();
        managerController = ManagerController.getInstance();
        heapSize = (String) managerController.getServerProperties()
                .getProperty(ManagerConstants.ADMINISTRATOR_MAX_HEAP_SIZE);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:com.mrfeinberg.babelizer.app.BabelizerMain.java

License:Apache License

public static void main(final String[] args) {
    try {//w  ww.  jav a  2s.  co m
        if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
            UIManager.put("ClassLoader", LookUtils.class.getClassLoader());
            PlasticLookAndFeel.setPlasticTheme(new ExperienceBlue());
            UIManager.setLookAndFeel(new PlasticXPLookAndFeel());
        }
    } catch (final Exception e) {
        System.err.println(e);
    }
    new BabelizerMain();
}

From source file:com.prodp.apsim.APProcessHandler.java

License:Apache License

/**
 * // w  w  w . j  a v a  2s . c  o  m
 * Sets up the whole game.
 * 
 * Sets up things like the GUI, put through {@link APGUI}, the scene
 * objects, and other things in {@link APFinalData}.
 * 
 * @throws AWTException
 * @throws ClassNotFoundException
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws UnsupportedLookAndFeelException
 * @throws CloneNotSupportedException
 */

public void init() throws AWTException, ClassNotFoundException, InstantiationException, IllegalAccessException,
        UnsupportedLookAndFeelException, CloneNotSupportedException {

    // Get the icon
    try {
        APFinalData.apIconImage = new ImageIcon(
                ImageIO.read(new APMain().getClass().getResource("icons/apsim.png"))).getImage();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // For mouse control and screenshots
    center = new Robot();

    // Set Graphics
    graphics.setSceneAntialiasing(GraphicsConfigTemplate.PREFERRED);
    graphics.setDoubleBuffer(GraphicsConfigTemplate.PREFERRED);
    graphicsConfig = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
            .getBestConfiguration(graphics);
    c3d = new APRenderer(graphicsConfig, (JComponent) APFinalData.mainFrame.getContentPane());
    c3d.setVisible(true);

    // setLookAndFeel
    PlasticLookAndFeel.set3DEnabled(true);
    PlasticLookAndFeel.setTabStyle(Plastic3DLookAndFeel.TAB_STYLE_METAL_VALUE);
    PlasticLookAndFeel.setPlasticTheme(new DesertBluer());

    UIManager.setLookAndFeel(new PlasticLookAndFeel());

    Options.setPopupDropShadowEnabled(true);
    Options.setUseNarrowButtons(true);

    // This is the Processor initialization
    final APProcess firstProcess = new APProcess("Untitled" + untitled + ".aps");
    APList.addProcess(firstProcess);

    APProcess process = APList.getCurrentProcess();

    // The default position
    mainRoutineFinalTransform.setTranslation(new Vector3f(0, 0, 0));

    // Set up the grass
    Transform3D grass3d = new Transform3D();
    grass3d.setScale(50);

    TextureAttributes ta = new TextureAttributes();
    ta.setTextureMode(TextureAttributes.MODULATE);
    ta.setPerspectiveCorrectionMode(TextureAttributes.FASTEST);
    ta.setTextureTransform(grass3d);

    Appearance floorapp = new Appearance();
    floorapp.setTexture(
            new TextureLoader(new APRandImage(1024, 1024, BufferedImage.TYPE_3BYTE_BGR, new Color(111, 71, 40),
                    new Color(50, 30, 7), new Color(104, 57, 23), new Color(22, 12, 6)), "RGB", null)
                            .getTexture());
    floorapp.setTextureAttributes(ta);

    // Referencing the position of the floor to floorcoord
    APFinalData.floor.setCoordRefFloat(APFinalData.floorcoord);
    APFinalData.floor.setTexCoordRefFloat(0, APFinalData.floortex);

    // Hide the cursor
    c3d.setCursor(APFinalData.transparentCursor);

    // Main geometry array
    cMain = new QuadArray(APFinalData.LIMIT * 24, QuadArray.COORDINATES | QuadArray.COLOR_4
            | QuadArray.BY_REFERENCE | QuadArray.TEXTURE_COORDINATE_2);

    // Wind geometry array
    windLoc = new LineArray(2 * APFinalData.PRESSURE_COUNT,
            LineArray.COORDINATES | LineArray.COLOR_3 | LineArray.BY_REFERENCE);

    // Dynamic positioning
    cMain.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
    cMain.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);

    windLoc.setCapability(GeometryArray.ALLOW_REF_DATA_READ);
    windLoc.setCapability(GeometryArray.ALLOW_REF_DATA_WRITE);

    // Set the reference of the geometry array to the coordinates and the
    // colors
    cMain.setCoordRefFloat(process.coords);
    cMain.setColorRefByte(process.colors);
    cMain.setTexCoordRefFloat(0, process.texturecoords);

    windLoc.setCoordRefFloat(process.windcoords);
    windLoc.setColorRefByte(process.windcolors);

    // Now add the reactionary components

    APRList.addReaction(new APReaction(new APPair(APMaterial.WOOD.getID(), APMaterial.LAVA.getID()),
            APMaterial.FIRE, 0.2f, APFinalData.CHANGE_BLOCK_FLAG));
    APRList.addReaction(new APReaction(new APPair(APMaterial.WOOD.getID(), APMaterial.FIRE.getID()),
            APMaterial.FIRE, 0.1f, APFinalData.CHANGE_BLOCK_FLAG));
    APRList.addReaction(new APReaction(new APPair(APMaterial.STONE.getID(), APMaterial.LAVA.getID()),
            APMaterial.LAVA, 0.1f, APFinalData.CHANGE_BLOCK_FLAG));
    APRList.addReaction(new APReaction(new APPair(APMaterial.WATER.getID(), APMaterial.LAVA.getID()),
            APMaterial.STEAM, 0.4f, APFinalData.CHANGE_BLOCK_FLAG));
    APRList.addReaction(new APReaction(new APPair(APMaterial.LAVA.getID(), APMaterial.WATER.getID()),
            APMaterial.STONE, 0.9f, APFinalData.CHANGE_BLOCK_FLAG));
    APRList.addReaction(new APReaction(new APPair(APMaterial.FIRE.getID(), APMaterial.WATER.getID()),
            APMaterial.NULL, 0.9f, APFinalData.REMOVE_BLOCK_FLAG));
    APRList.addReaction(new APReaction(new APPair(APMaterial.WATER.getID(), APMaterial.ICE.getID()),
            APMaterial.ICE, 0.01f, APFinalData.CHANGE_BLOCK_FLAG));
    APRList.addReaction(new APReaction(new APPair(APMaterial.ICE.getID(), APMaterial.LAVA.getID()),
            APMaterial.WATER, 1, APFinalData.CHANGE_BLOCK_FLAG));

    APFinalData.mainFrame.init();

    // Set the canvas size
    c3d.setPreferredSize(new Dimension(550, 300));
    c3d.setLocation(0, 0);

    // Don't let the geometry clip off
    final Appearance polyAppearance = new Appearance();
    polyAppearance.setPolygonAttributes(
            new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_NONE, 0));
    polyAppearance.setTextureAttributes(new TextureAttributes());
    polyAppearance.setTexture(APFinalData.textures);

    final Appearance lineAppearance = new Appearance();
    lineAppearance.setLineAttributes(new LineAttributes(1, LineAttributes.PATTERN_SOLID, false));

    TransparencyAttributes trans = new TransparencyAttributes();
    trans.setTransparencyMode(TransparencyAttributes.BLENDED);
    polyAppearance.setTransparencyAttributes(trans);

    // Add the GeometryArray to the Shape3D
    aobjects.addGeometry(cMain);
    aobjects.setAppearance(polyAppearance);

    lobjects.addGeometry(windLoc);
    lobjects.setAppearance(lineAppearance);

    ground.addGeometry(APFinalData.floor);
    ground.setAppearance(floorapp);

    // Initialize the AmbientLight
    APFinalData.whiteLight.setInfluencingBounds(bounds);

    // Sky
    Background back = new Background();
    back.setApplicationBounds(new BoundingSphere(new Point3d(0, 0, 0), 1));

    skyTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    skyTrans.rotX(0);
    skyTG.setTransform(skyTrans);
    skyTG.addChild(sky);

    BranchGroup backgeom = new BranchGroup();
    backgeom.addChild(skyTG);

    back.setGeometry(backgeom);

    // Add the brush
    selection.setCapability(QuadArray.ALLOW_REF_DATA_WRITE);
    selections.addGeometry(selection);
    selections.setAppearance(APFinalData.wireframe);

    APFinalData.brushes.addChild(selections);

    // Scene initialization
    scene = new APSceneGraph(c3d);
    scene.addChild(APFinalData.whiteLight, aobjects, lobjects, ground, back, APFinalData.brushes);

    // Add it to the world
    scene.addBranchGraph();

    // Prepare the world
    scene.prepare(mainRoutineFinalTransform);

    // Make the Canvas draw right
    c3d.setDoubleBufferEnable(true);

    // Stereo Red-blue
    c3d.getView().getPhysicalBody().setLeftEyePosition(new Point3d(-0.01, 0, 0));
    c3d.getView().getPhysicalBody().setRightEyePosition(new Point3d(0.01, 0, 0));
    c3d.getView().setDepthBufferFreezeTransparent(false);

    // Note: c3d has no anaglyphs
    c3d.setStereoMode(StereoMode.OFF);

    // Add Canvas listeners
    c3d.addMouseListener(this);
    c3d.addMouseMotionListener(this);
    c3d.addKeyListener(this);

    // Add menubar listeners
    APFinalData.Exit.addActionListener(this);
    APFinalData.New.addActionListener(this);
    APFinalData.Open.addActionListener(this);
    APFinalData.Save.addActionListener(this);
    APFinalData.Save_As.addActionListener(this);
    APFinalData.Import.addActionListener(this);
    APFinalData.Export.addActionListener(this);
    APFinalData.Element.addActionListener(this);
    APFinalData.Exit.addActionListener(this);
    APFinalData.Join_Server.addActionListener(this);
    APFinalData.Create_Server.addActionListener(this);
    APFinalData.View_Options.addActionListener(this);
    APFinalData.Sound.addActionListener(this);
    APFinalData.Online_Help.addActionListener(this);
    APFinalData.About_Us.addActionListener(this);
    APFinalData.Update.addActionListener(this);
    APFinalData.View_Ok.addActionListener(this);
    APFinalData.View_Cancel.addActionListener(this);
    APFinalData.Element_Ok.addActionListener(this);
    APFinalData.Element_Cancel.addActionListener(this);
    APFinalData.antiaDisable.addActionListener(this);
    APFinalData.antiaEnable.addActionListener(this);
    APFinalData.anaglyphFull.addActionListener(this);
    APFinalData.anaglyphGray.addActionListener(this);
    APFinalData.anaglyphHalf.addActionListener(this);
    APFinalData.anaglyphNone.addActionListener(this);
    APFinalData.anaglyphOptim.addActionListener(this);
    APFinalData.anaglyphRedBlue.addActionListener(this);
    APFinalData.anaglyphRedGreen.addActionListener(this);
    APFinalData.senseSlider.addChangeListener(this);
    APFinalData.elementChooser.addActionListener(this);
    APFinalData.SprayVacuum.addActionListener(this);
    APFinalData.Wind.addActionListener(this);

    APFinalData.processSwitch.setBackground(Color.WHITE);
    APFinalData.processSwitch.addChangeListener(this);
    APFinalData.processSwitch.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);

    // APFinalData.mainFrame.setVisible(true);

    // Make the thread
    if (threedanim == null)
        threedanim = new Thread(new APMain(), "APThread");

    // Make it the best thread
    threedanim.setPriority(APSceneGraph.getJ3DThreadPriority());
    threedanim.setDaemon(false);
    threedanim.start();

    // Make it live
    isRunning = true;

    APFinalData.mainFrame.setVisible(true);
}

From source file:com.sdi.pws.gui.Pws.java

License:Open Source License

private static void startgGui() {
    // Set the look and feel.
    PlasticLookAndFeel.setPlasticTheme(new DesertRed());
    try {/*from   w  w  w.j av  a  2s.  c o m*/
        UIManager.setLookAndFeel(new PlasticLookAndFeel());
    } catch (Exception ignored) {
    }

    // Change the default JOptionPane icons.
    UIManager.put("OptionPane.okIcon", new ImageIcon(Pws.class.getClassLoader().getResource("assets/go.png")));
    UIManager.put("OptionPane.cancelIcon",
            new ImageIcon(Pws.class.getClassLoader().getResource("assets/cancel.png")));

    // Load user preferences.
    final Preferences lPrefs = new PreferencesImpl();
    PrefStorage.loadPreferences(lPrefs);
    final ChangeViewPreferences lGlobalPreferences = new ChangeViewPreferences(lPrefs);

    // Application Frame.
    final JFrame lAppFrame = new JFrame();
    lAppFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    final ImageIcon lAppIcon = new ImageIcon(Pws.class.getClassLoader().getResource("assets/pwt-icon.gif"));
    lAppFrame.setIconImage(lAppIcon.getImage());

    // Application Menu Bar.
    final JMenuBar lAppMenu = new JMenuBar();
    lAppFrame.setJMenuBar(lAppMenu);

    // File menu.
    final JMenu lFileMenu = new JMenu(GuiUtil.getText("menu.file"));
    lFileMenu.setMnemonic('F');
    lAppMenu.add(lFileMenu);

    final JMenu lConvertMenu = new JMenu(GuiUtil.getText("menu.convert"));
    lConvertMenu.setMnemonic('C');
    final ImageIcon lConvertIcon = new ImageIcon(Pws.class.getClassLoader().getResource("assets/convert.png"));
    lConvertMenu.setIcon(lConvertIcon);

    final JMenu lImportMenu = new JMenu(GuiUtil.getText("menu.import"));
    lImportMenu.setMnemonic('I');
    // Install the icon.
    final ImageIcon lImportIcon = new ImageIcon(Pws.class.getClassLoader().getResource("assets/import.png"));
    lImportMenu.setIcon(lImportIcon);

    final JMenu lExportMenu = new JMenu(GuiUtil.getText("menu.export"));
    lExportMenu.setMnemonic('E');
    // Install the icon.
    final ImageIcon lExportIcon = new ImageIcon(Pws.class.getClassLoader().getResource("assets/export.png"));
    lExportMenu.setIcon(lExportIcon);

    // Password menu.
    final JMenu lPasswordMenu = new JMenu(GuiUtil.getText("menu.password"));
    lPasswordMenu.setMnemonic('P');
    lAppMenu.add(lPasswordMenu);

    // View menu.
    final JMenu lViewMenu = new JMenu(GuiUtil.getText("menu.view"));
    lViewMenu.setMnemonic('V');
    lAppMenu.add(lViewMenu);

    // Help menu.
    final JMenu lHelpMenu = new JMenu(GuiUtil.getText("menu.help"));
    lHelpMenu.setMnemonic('H');
    lAppMenu.add(lHelpMenu);
    // Listen for help.
    final JMenuItem lHelpItem = new JMenuItem(GuiUtil.getText("menuitem.help"),
            new ImageIcon(Pws.class.getClassLoader().getResource("assets/help.png")));
    final HelpBroker lBroker = GuiUtil.getHelpBroker();
    lBroker.setCurrentID("intro_html");
    lHelpItem.addActionListener(new CSH.DisplayHelpFromSource(lBroker));
    lHelpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    lHelpMenu.add(lHelpItem);

    // Vertical button panel size.
    final int lButtonPanelWidth = 27;

    // Left button panel.
    final JPanel lLeftButtonPanel = new JPanel();
    lLeftButtonPanel.setLayout(new GridLayout(2, 1));
    lLeftButtonPanel.setMaximumSize(new Dimension(lButtonPanelWidth, 0));
    lLeftButtonPanel.setMinimumSize(new Dimension(lButtonPanelWidth, 0));
    lLeftButtonPanel.setPreferredSize(new Dimension(lButtonPanelWidth, 0));
    lAppFrame.getRootPane().getContentPane().add(lLeftButtonPanel, BorderLayout.WEST);
    // Button panel buttons.
    JButton lLeftCopyUID = new JButton();
    lLeftButtonPanel.add(lLeftCopyUID);
    JButton lLeftCopyPwd = new JButton();
    lLeftButtonPanel.add(lLeftCopyPwd);
    // Set startup visibility.
    try {
        lLeftButtonPanel.setVisible(lGlobalPreferences.getBoolPref(Preferences.PREF_BUTTONS_LEFT));
    } catch (PreferencesException ignored) {
    }
    // Set dynamic visibility.
    lGlobalPreferences.addPropertyChangeListener(Preferences.PREF_BUTTONS_LEFT, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            try {
                lLeftButtonPanel.setVisible(lGlobalPreferences.getBoolPref(Preferences.PREF_BUTTONS_LEFT));
            } catch (PreferencesException ignored) {
            }
        }
    });

    // Right button panel.
    final JPanel lRightButtonPanel = new JPanel();
    lRightButtonPanel.setLayout(new GridLayout(2, 1));
    lRightButtonPanel.setMaximumSize(new Dimension(lButtonPanelWidth, 0));
    lRightButtonPanel.setMinimumSize(new Dimension(lButtonPanelWidth, 0));
    lRightButtonPanel.setPreferredSize(new Dimension(lButtonPanelWidth, 0));
    lAppFrame.getRootPane().getContentPane().add(lRightButtonPanel, BorderLayout.EAST);
    // Button panel buttons.
    JButton lRightCopyUID = new JButton();
    lRightButtonPanel.add(lRightCopyUID);
    JButton lRightCopyPWD = new JButton();
    lRightButtonPanel.add(lRightCopyPWD);
    // Set startup visibility.
    try {
        lRightButtonPanel.setVisible(lGlobalPreferences.getBoolPref(Preferences.PREF_BUTTONS_RIGHT));
    } catch (PreferencesException ignored) {
    }
    // Set dynamic visibility.
    lGlobalPreferences.addPropertyChangeListener(Preferences.PREF_BUTTONS_RIGHT, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            try {
                lRightButtonPanel.setVisible(lGlobalPreferences.getBoolPref(Preferences.PREF_BUTTONS_RIGHT));
            } catch (PreferencesException eIgnore) {
            }
        }
    });

    // View stack.
    final JPanel lViews = new JPanel();
    final CardLayout lViewLayout = new CardLayout();
    lViews.setLayout(lViewLayout);
    lAppFrame.getRootPane().getContentPane().add(lViews, BorderLayout.CENTER);

    // Table view.
    final JTable lTableView = new JTable();
    lTableView.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    final JScrollPane lTableViewScroll = new JScrollPane(lTableView);
    final FilteredCellRenderer lFilteredRenderer = new FilteredCellRenderer();
    lTableView.setDefaultRenderer(ChangeViewField.class, lFilteredRenderer);
    final Box lTableBox = Box.createVerticalBox();
    // Create the filter panel.
    final JPanel lFilterPanel = new JPanel();
    lFilterPanel.setLayout(new BorderLayout());
    final JLabel lFilterLabel = new JLabel(
            new ImageIcon(Start.class.getClassLoader().getResource("assets/loep.png")));
    lFilterLabel.setBorder(new EmptyBorder(1, 1, 1, 5));
    lFilterPanel.setBackground(Color.white);
    lFilterPanel.add(lFilterLabel, BorderLayout.WEST);
    final JTextField lTableFilter = new JTextField();
    lFilterPanel.add(lTableFilter, BorderLayout.CENTER);
    lFilterPanel.setBorder(lTableFilter.getBorder());
    lTableFilter.setBorder(null);
    // Force fixed height filter box. Widht can vary, but height should remain the same.
    lFilterPanel.setMaximumSize(new Dimension(10000, 50));
    lTableBox.add(lFilterPanel);
    lTableBox.add(lTableViewScroll);
    lViews.add(lTableBox, Preferences.VIEW_TABLE);

    // Tree view.
    final JTree lTreeView = new JTree();
    lTreeView.setBorder(new EmptyBorder(3, 3, 3, 3));
    final JScrollPane lTreeViewScroll = new JScrollPane(lTreeView);
    lViews.add(lTreeViewScroll, Preferences.VIEW_TREE);

    // Select current view and initialize view name holder.
    final String lDefaultView = lGlobalPreferences.getPref(Preferences.PREF_DEFAULT_VIEW);
    final StringHolder lViewName = new StringHolderImpl(lDefaultView);
    lViewLayout.show(lViews, lDefaultView);

    // Initialize a default empty database.
    final ChangeViewDatabase lDb = new ChangeViewDatabase(new PwsDatabaseImpl());
    lDb.setCodec(new Codec2());
    lDb.setChanged(false);
    final DatabaseHolder lDbHolder = new DatabaseHolderImpl(lDb);

    // Application title.
    final TitleRenderer lTitlemgr = new TitleRenderer(lAppFrame, lDbHolder);

    // Init the table view. Several wrappers are added for additional table functionality.
    final TableViewDatabase lTableModel = new TableViewDatabase(lDb);
    final SortableTableModel lSortedTableModel = new SortableTableModel(lTableModel);
    final FilteredTableModel lFilteredTableModel = new FilteredTableModel(lSortedTableModel);
    final TreeViewDatabase lTreeModel = new TreeViewDatabase(lDb);
    lTableView.setModel(lFilteredTableModel);
    lTreeView.setModel(lTreeModel);
    // Add a filter feedback.
    lTableFilter.addKeyListener(new KeyListener() {
        public void keyPressed(KeyEvent e) {
            doit();
        }

        public void keyReleased(KeyEvent e) {
            doit();
        }

        public void keyTyped(KeyEvent e) {
        }

        private void doit() {
            // Apply the search pattern to the table model.
            final String lSearchString = lTableFilter.getText();
            lFilteredRenderer.setSearchString(lSearchString);
            lFilteredTableModel.search(lSearchString);
            // If there is one and only one row left in the table, we automatically select it.
            if (lFilteredTableModel.getRowCount() == 1)
                lTableView.getSelectionModel().setSelectionInterval(0, 0);
        }
    });

    // Selector.
    final TableViewSelector lTableSelector = new TableViewSelector(lFilteredTableModel, lTableView);
    final TreeViewSelector lTreeSelector = new TreeViewSelector(lTreeView);
    final DynamicRecordSelector lRecordSelector = new DynamicRecordSelector(
            (("tree".equals(lViewName)) ? lTreeSelector : lTableSelector));

    lDbHolder.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            // Get the new plain database.
            final ChangeViewDatabase lCurrentDb = lDbHolder.getCurrentDatabase();

            // Give it to the models.
            lTableModel.setDatabase(lCurrentDb);
            lTreeModel.setDatabase(lCurrentDb);
        }
    });

    // Actions.
    final ClipboardMonitor lMonitor = new ClipboardMonitor();
    final Action lCopyUidAction = new CopyUid(lRecordSelector, lMonitor);
    lPasswordMenu.add(lCopyUidAction).setAccelerator(
            KeyStroke.getKeyStroke('U', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
    lLeftCopyUID.setAction(new ActionNoName(lCopyUidAction));
    lRightCopyUID.setAction(new ActionNoName(lCopyUidAction));

    final Action lCopyPwdAction = new CopyPwd(lRecordSelector, lMonitor);
    lPasswordMenu.add(lCopyPwdAction).setAccelerator(
            KeyStroke.getKeyStroke('P', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
    lLeftCopyPwd.setAction(new ActionNoName(lCopyPwdAction));
    lRightCopyPWD.setAction(new ActionNoName(lCopyPwdAction));

    final Action lClearClipboardAction = new ClearClipboard(lMonitor);
    lPasswordMenu.add(lClearClipboardAction).setAccelerator(
            KeyStroke.getKeyStroke('D', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

    final Action lOpenFileAction = new FileOpen(lAppFrame.getRootPane(), lDbHolder, lGlobalPreferences);
    lFileMenu.add(lOpenFileAction).setAccelerator(
            KeyStroke.getKeyStroke('O', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

    final Action lSaveFileAction = new FileSave(lAppFrame.getRootPane(), lDbHolder, lGlobalPreferences);
    lFileMenu.add(lSaveFileAction).setAccelerator(
            KeyStroke.getKeyStroke('S', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

    final Action lSaveAsFileAction = new FileSaveAs(lAppFrame.getRootPane(), lDbHolder, lGlobalPreferences);
    lFileMenu.add(lSaveAsFileAction).setAccelerator(
            KeyStroke.getKeyStroke('A', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

    final Action lNewFileAction = new FileNew(lAppFrame.getRootPane(), lDbHolder);
    lFileMenu.add(lNewFileAction).setAccelerator(
            KeyStroke.getKeyStroke('N', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

    final Action lChangePassphraseAction = new PassphraseChange(lAppFrame, lDbHolder, lGlobalPreferences);
    lFileMenu.add(lChangePassphraseAction);

    lFileMenu.addSeparator();
    lFileMenu.add(lConvertMenu);
    lFileMenu.add(lImportMenu);
    lFileMenu.add(lExportMenu);

    final Action lAppPrefsAction = new AppPrefsEdit(lAppFrame.getRootPane(), lGlobalPreferences);
    lFileMenu.add(lAppPrefsAction);

    final Action lAppExitAction = new AppExit(lAppFrame.getRootPane(), lDbHolder, lGlobalPreferences);
    lFileMenu.addSeparator();
    lFileMenu.add(lAppExitAction).setAccelerator(
            KeyStroke.getKeyStroke('Q', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
    lAppFrame.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            lAppExitAction.actionPerformed(new ActionEvent(lAppFrame, 0, null));
        }
    });

    final Action lEditEntryAction = new EntryEdit(lAppFrame.getRootPane(), lRecordSelector, lDbHolder,
            lGlobalPreferences);
    lPasswordMenu.addSeparator();
    lPasswordMenu.add(lEditEntryAction).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
    // Force the Enter key on the table and tree to do an edit.
    // If we don't force this, the enter will have the same effect as walking through the list/tree.
    lTableView.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "EDIT");
    lTableView.getActionMap().put("EDIT", lEditEntryAction);
    lTreeView.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "EDIT");
    lTreeView.getActionMap().put("EDIT", lEditEntryAction);

    final Action lNewEntryAction = new EntryNew(lAppFrame.getRootPane(), lTreeModel, lGlobalPreferences);
    lPasswordMenu.add(lNewEntryAction).setAccelerator(
            KeyStroke.getKeyStroke('E', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));

    // Force the CTRL-A key on the table and tree to do a new.
    // If we don't force this, the CTRL-A will have the same effect as selecting all entries.
    lTableView.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "NEW");
    lTableView.getActionMap().put("NEW", lNewEntryAction);
    lTreeView.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK), "NEW");
    lTreeView.getActionMap().put("NEW", lNewEntryAction);

    final Action lDeleteEntryAction = new EntryDelete(lAppFrame.getRootPane(), lTreeModel, lRecordSelector);
    lPasswordMenu.add(lDeleteEntryAction).setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));

    final int lTextGap = 3;

    final Action lTableViewAction = new ViewTable(lViews, lRecordSelector, lTableSelector, lViewName);
    final JRadioButton lTableButton = new JRadioButton(lTableViewAction);
    lTableButton.setIconTextGap(lTextGap);
    lTableButton.setSelected(!lTableViewAction.isEnabled());
    lTableViewAction.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent aPropertyChangeEvent) {
            lTableButton.setSelected(!lTableViewAction.isEnabled());
        }
    });
    lViewMenu.add(lTableButton);

    final Action lTreeViewAction = new ViewTree(lViews, lRecordSelector, lTreeSelector, lViewName);
    final JRadioButton lTreeButton = new JRadioButton(lTreeViewAction);
    lTreeButton.setIconTextGap(lTextGap);
    lTreeButton.setSelected(!lTreeViewAction.isEnabled());
    lTreeButton.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent aPropertyChangeEvent) {
            lTreeButton.setSelected(!lTreeViewAction.isEnabled());
        }
    });
    lViewMenu.add(lTreeButton);

    // The stay on top option.
    final JCheckBox lStayPut = new JCheckBox(GuiUtil.getText("action.stayontop"));
    try {
        lStayPut.setSelected(lGlobalPreferences.getBoolPref(Preferences.PREF_STAY_ON_TOP));
    } catch (PreferencesException e) {
    }
    lStayPut.setIconTextGap(lTextGap);
    lViewMenu.add(lStayPut);
    lAppFrame.setAlwaysOnTop(lStayPut.isSelected());
    lStayPut.addPropertyChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent aPropertyChangeEvent) {
            lAppFrame.setAlwaysOnTop(lStayPut.isSelected());
        }
    });

    // Add right mouse button popup to the table view.
    lTableView.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            checkPopup(e);
        }

        public void mouseClicked(MouseEvent e) {
            checkPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            checkPopup(e);
        }

        private void checkPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {
                // See if we have a selection.
                final PwsRecord lRecord = lRecordSelector.getSelectedRecord();

                // Create an array of URL actions if there any URL's hidden in the notes field.
                // URL actions are only possible if there is a selected record.
                Action[] lUrlActions = null;
                String lNotes = null;
                if (lRecord != null && lRecord.hasType(PwsField.FIELD_NOTES)) {
                    try {
                        lNotes = lRecord.get(PwsField.FIELD_NOTES).getAsString();
                    } catch (Exception eIgnore) {
                    }
                    java.util.List<String> lUrls = SwinglibUtil.extractUrl(lNotes);
                    if (lUrls.size() > 0) {
                        lUrlActions = new Action[lUrls.size()];
                        for (int i = 0; i < lUrls.size(); i++)
                            lUrlActions[i] = new BrowseUrl(lUrls.get(i));
                    }
                }
                // Create the popup menu dynamically.
                JPopupMenu lPop;

                lPop = SwinglibUtil.popupBuilder(
                        new Action[] { lCopyUidAction, lCopyPwdAction, lClearClipboardAction },
                        new Action[] { lEditEntryAction, lNewEntryAction, lDeleteEntryAction }, lUrlActions);
                // Show the popup to the user.
                lPop.show(lTableView, e.getX(), e.getY());
            }
        }
    });
    // Add right mouse button popup.
    lTreeView.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            checkPopup(e);
        }

        public void mouseClicked(MouseEvent e) {
            checkPopup(e);
        }

        public void mouseReleased(MouseEvent e) {
            checkPopup(e);
        }

        private void checkPopup(MouseEvent e) {
            if (e.isPopupTrigger()) {

                // See if we have a selection.
                final PwsRecord lRecord = lRecordSelector.getSelectedRecord();

                // Create an array of URL actions if there any URL's hidden in the notes field.
                // URL actions are only possible if there is a selected record.
                Action[] lUrlActions = null;
                String lNotes = null;
                if (lRecord != null && lRecord.hasType(PwsField.FIELD_NOTES)) {
                    try {
                        lNotes = lRecord.get(PwsField.FIELD_NOTES).getAsString();
                    } catch (Exception eIgnore) {
                    }
                    java.util.List<String> lUrls = SwinglibUtil.extractUrl(lNotes);
                    if (lUrls.size() > 0) {
                        lUrlActions = new Action[lUrls.size()];
                        for (int i = 0; i < lUrls.size(); i++)
                            lUrlActions[i] = new BrowseUrl(lUrls.get(i));
                    }
                }
                // Create the popup menu dynamically.
                JPopupMenu lPop;
                lPop = SwinglibUtil.popupBuilder(
                        new Action[] { lCopyUidAction, lCopyPwdAction, lClearClipboardAction },
                        new Action[] { lEditEntryAction, lNewEntryAction, lDeleteEntryAction }, lUrlActions);

                // Show the popup to the user.
                lPop.show(lTreeView, e.getX(), e.getY());
            }
        }
    });

    final Action lFileUpgradeAction = new FileVersionUpgrade(lAppFrame.getRootPane(), lDbHolder,
            lGlobalPreferences);
    lConvertMenu.add(lFileUpgradeAction);

    final Action lFiledowngradeAction = new FileVersionDowngrade(lAppFrame.getRootPane(), lDbHolder);
    lConvertMenu.add(lFiledowngradeAction);

    final Action lFileExportCsvAction = new FileCsvExport(lAppFrame.getRootPane(), lDbHolder,
            lGlobalPreferences);
    lExportMenu.add(lFileExportCsvAction);

    final Action lFileImportCsvAction = new FileCsvImport(lAppFrame.getRootPane(), lDbHolder,
            lGlobalPreferences);
    lImportMenu.add(lFileImportCsvAction);

    final Action lFileImportPwsAction = new FilePwsImport(lAppFrame.getRootPane(), lDbHolder,
            lGlobalPreferences);
    lImportMenu.add(lFileImportPwsAction);

    final Action lFileExportXmlAction = new FileXmlExport(lAppFrame.getRootPane(), lDbHolder,
            lGlobalPreferences);
    lExportMenu.add(lFileExportXmlAction);

    final Action lFileImportXmlAction = new FileXmlImport(lAppFrame.getRootPane(), lDbHolder,
            lGlobalPreferences);
    lImportMenu.add(lFileImportXmlAction);

    final Action lAboutAction = new AppAbout(lAppFrame.getRootPane());
    lHelpMenu.add(lAboutAction);

    // Start screen.
    Start.startPws(lAppFrame, lDbHolder, lGlobalPreferences);

    // Start the GUI.
    lAppFrame.pack();
    GuiUtil.centerComponent(lAppFrame);
    lAppFrame.setVisible(true);
}