Example usage for javax.swing UIDefaults UIDefaults

List of usage examples for javax.swing UIDefaults UIDefaults

Introduction

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

Prototype

public UIDefaults() 

Source Link

Document

Creates an empty defaults table.

Usage

From source file:ejemplo.grafica.java

private void suciedad() {

    //agregar/*from ww  w  .ja  va2  s.c om*/
    double nivelSuciedad = parseDouble(txtNivel.getText());
    double min, pocosucia, sucia, muysucia, parte, max;
    max = parseDouble(txtMaxNivel.getText());
    parte = max / 3;
    min = 0;
    pocosucia = parte;
    sucia = parte * 2;
    muysucia = parte * 3;

    //niveles para el color
    //niveles normal
    if (nivelSuciedad >= min && nivelSuciedad < pocosucia) {

        UIDefaults defaults = new UIDefaults();
        defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(Color.BLUE));
        defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(Color.BLUE));
        progressBar.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
        progressBar.putClientProperty("Nimbus.Overrides", defaults);

    } else {
        //nivel sucio
        if (nivelSuciedad >= pocosucia && nivelSuciedad < sucia) {
            UIDefaults defaults = new UIDefaults();
            defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(Color.LIGHT_GRAY));
            defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(Color.LIGHT_GRAY));
            progressBar.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
            progressBar.putClientProperty("Nimbus.Overrides", defaults);
        } else {
            //nivel muy sucio
            if (nivelSuciedad >= sucia && nivelSuciedad <= muysucia) {
                UIDefaults defaults = new UIDefaults();
                defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(Color.GRAY));
                defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(Color.GRAY));
                progressBar.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
                progressBar.putClientProperty("Nimbus.Overrides", defaults);
            }

        }
    }

    //fin niveles
}

From source file:GUI.MainWindow.java

/**
 * @param args the command line arguments
 *//*from   w  w  w  . jav  a  2s  .c  o m*/
public static void main(String args[]) {
    /* Set the Nimbus look and feel */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
    /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
     * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
     */
    try {

        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null,
                ex);
    }
    //</editor-fold>

    // Create right click context menu for most Text Components
    final JPopupMenu copypaste = new JPopupMenu();

    JMenuItem cut = new JMenuItem(new DefaultEditorKit.CutAction());
    cut.setText("Cut");
    copypaste.add(cut);

    JMenuItem copy = new JMenuItem(new DefaultEditorKit.CopyAction());
    copy.setText("Copy");
    copypaste.add(copy);

    JMenuItem paste = new JMenuItem(new DefaultEditorKit.PasteAction());
    paste.setText("Paste");
    copypaste.add(paste);

    // Taken from here. It succinctly added a right click context menu to every text component.
    // http://stackoverflow.com/questions/19424574/adding-a-context-menu-to-all-swing-text-components-in-application
    javax.swing.UIManager.addAuxiliaryLookAndFeel(new LookAndFeel() {
        private final UIDefaults defaults = new UIDefaults() {
            public javax.swing.plaf.ComponentUI getUI(JComponent c) {
                if (c instanceof javax.swing.text.JTextComponent) {
                    if (c.getClientProperty(this) == null) {
                        c.setComponentPopupMenu(copypaste);
                        c.putClientProperty(this, Boolean.TRUE);
                    }
                }
                return null;
            }
        };

        @Override
        public UIDefaults getDefaults() {
            return defaults;
        }

        ;

        @Override
        public String getID() {
            return "TextContextMenu";
        }

        @Override
        public String getName() {
            return getID();
        }

        @Override
        public String getDescription() {
            return getID();
        }

        @Override
        public boolean isNativeLookAndFeel() {
            return false;
        }

        @Override
        public boolean isSupportedLookAndFeel() {
            return true;
        }
    });

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new MainWindow().setVisible(true);
        }
    });
}

From source file:uk.sipperfly.ui.Exactly.java

private void unBagActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_unBagActionPerformed
    UIDefaults defaults = new UIDefaults();

    defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    this.unBaggingProgress.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    this.unBaggingProgress.putClientProperty("Nimbus.Overrides", defaults);

    String location = destDirLocation.getText();
    List<String> validDirs = new ArrayList<String>();
    String sourcelocation = this.inputLocationDir.getText();
    if (sourcelocation.isEmpty() || sourcelocation == null) {
        UpdateResult("Must choose a source folder.", 1);
        return;//w  w  w.  j a  v a  2  s.  c  o m
    }
    if (!location.isEmpty() && location != null) {
        validDirs.add(location);
        File f = new File(destDirLocation.getText());
        if (!f.exists()) {
            UpdateResult("Must choose a valid destination folder.", 1);
            return;
        }
        try {
            bgw = new BackgroundWorker(validDirs, this, 4);
            bgw.execute();
        } catch (IOException ex) {
            Logger.getLogger(GACOM).log(Level.SEVERE, null, ex);
        }
    } else {
        UpdateResult("Must choose destination folder.", 1);
        return;
    }
}

From source file:uk.sipperfly.ui.Exactly.java

private void unBaggingProgressPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_unBaggingProgressPropertyChange
    UIDefaults defaults = new UIDefaults();

    defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
}

From source file:uk.sipperfly.ui.Exactly.java

private void jProgressBar2PropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_jProgressBar2PropertyChange
    UIDefaults defaults = new UIDefaults();
    defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
}

From source file:uk.sipperfly.ui.Exactly.java

private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
    this.warning.setVisible(false);
    this.btnTransferFiles.setEnabled(false);
    this.btnCancel.setVisible(true);
    List<String> validDirs = new ArrayList<String>();
    List<String> directories = new ArrayList<String>();
    directories = this.uIManager.getInputDirectories();
    directories.add(editInputDir.getText());
    for (String directory : directories) {
        if (!directory.isEmpty()) {
            validDirs.add(directory);/* w  w  w.  j a  v a2s . c  o m*/
        }
    }

    UIDefaults defaults = new UIDefaults();
    defaults.put("ProgressBar[Enabled].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    defaults.put("ProgressBar[Enabled+Finished].foregroundPainter", new MyPainter(new Color(0, 102, 0)));
    this.jProgressBar2.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    this.jProgressBar2.putClientProperty("Nimbus.Overrides", defaults);

    try {
        bgw = new BackgroundWorker(validDirs, this, 1);
        bgw.execute();
    } catch (IOException ex) {
        this.btnCancel.setVisible(false);
        this.btnTransferFiles.setEnabled(true);
        Logger.getLogger(GACOM).log(Level.SEVERE, null, ex);
    }
}