Randomly Intermittent Thoughts

    Thoughts I have pondered, but may not be wholely original…

    Browsing Posts in Technology

    Yesterday I was digging around the interwebs looking to find out how I can hibernate a computer from the command line. My first thought was “Oh, the shutdown command might work”, but nope. It doesn’t have a hibernate option. The I went to Google and did a search for it. A forum thread lead me to Wizmo. This is a freeware utility that can hibernate a computer plus a lot more. I think this is getting added to my toolbox of tools!

    Thanks Steve!

    I was watching a TV show the other day. A girl was about to have her 13th birthday. This seems reasonable for a TV show to have.

    The thing that caught my attention was the girl asked for a progression of things:

    Girl: Can I get a cell phone?
    Parents: No.

    Girl: Can I get a pager (why anyone would want this in todays age is anyone’s guess)?
    Parents: No.

    Girl: Can I at least get a computer in my bed room?
    Parents: No.

    Girl: Well, then could I get my own email address?
    Parents: Well, we’ll think about it.

    … time in show progresses …

    Parents: Ok, you’ll get your own email account, but we’ll have the password and can check on any emails sent/received/deleted.
    Girl (all giddy and overflowing with delight): Yay, this is the best birthday ever.

    My question is: When did getting an email change into a Rite of Passage for young girls and/or boys. I can understand the parents wanting full access, but why is the girl giddy?

    What happened to cars (or just even driving) being the main Rite of Passage?

    Ever wanted to change the color of a JCheckBox in a JTable to the table's foreground color? Now you can!

    Example Screenshot:
    Lower Table has a white check instead of a black check!

    This is a renderer for Booleans in a JTable.

    JAVA:
    1. import java.awt.Color;
    2. import java.awt.Component;
    3. import java.awt.Graphics;
    4.  
    5. import javax.swing.JCheckBox;
    6. import javax.swing.JTable;
    7. import javax.swing.table.TableCellRenderer;
    8.  
    9. /**
    10. * This class implements a boolean renderer for a JTable.  It overrides the icon for the CheckBox to draw in the
    11. * foreground color.
    12. */
    13. public class BooleanRenderer extends JCheckBox implements TableCellRenderer {
    14.    public BooleanRenderer() {
    15.        super();
    16.        setHorizontalAlignment(JCheckBox.CENTER);
    17.        setIcon(new ColorableMetalCheckBoxIcon());
    18.    }
    19.  
    20.    public Component getTableCellRendererComponent(JTable table, Object value,
    21.                                                   boolean isSelected, boolean hasFocus, int row, int column) {
    22.        if (isSelected) {
    23.            setForeground(table.getSelectionForeground());
    24.            super.setBackground(table.getSelectionBackground());
    25.        } else {
    26.            setForeground(table.getForeground());
    27.            setBackground(table.getBackground());
    28.        }
    29.        setSelected((value != null && ((Boolean) value).booleanValue()));
    30.        return this;
    31.    }
    32.  
    33.    /**
    34.     * Changes the check box check mark to be the foreground color.<br/>
    35.     * <b>NOTE:</b>This was found here http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4449413 .
    36.     */
    37.    static class ColorableMetalCheckBoxIcon extends javax.swing.plaf.metal.MetalCheckBoxIcon {
    38.        protected void drawCheck(Component c, Graphics g, int x, int y) {
    39.            final Color old = g.getColor();
    40.            g.setColor(c.getForeground());
    41.            super.drawCheck(c, g, x, y);
    42.            g.setColor(old);
    43.        }
    44.    }
    45. }

    This is the corresponding Editor.

    JAVA:
    1. import java.awt.Component;
    2.  
    3. import javax.swing.DefaultCellEditor;
    4. import javax.swing.JCheckBox;
    5. import javax.swing.JTable;
    6.  
    7. /**
    8. * This class implements a boolean editor for a JTable.  It overrides the icon for the CheckBox to draw in the
    9. * foreground color.
    10. */
    11. public class BooleanEditor extends DefaultCellEditor {
    12.  
    13.    public BooleanEditor() {
    14.        super(new JCheckBox());
    15.        JCheckBox c = (JCheckBox) getComponent();
    16.        c.setHorizontalAlignment(JCheckBox.CENTER);
    17.        c.setIcon(new BooleanRenderer.ColorableMetalCheckBoxIcon());
    18.    }
    19.  
    20.    public Component getTableCellEditorComponent(JTable table,
    21.                                                 Object value,
    22.                                                 boolean isSelected,
    23.                                                 int row,
    24.                                                 int column) {
    25.        JCheckBox c = (JCheckBox) getComponent();
    26.        if (isSelected) {
    27.            c.setForeground(table.getSelectionForeground());
    28.            c.setBackground(table.getSelectionBackground());
    29.        } else {
    30.            c.setForeground(table.getForeground());
    31.            c.setBackground(table.getBackground());
    32.        }
    33.        c.setSelected((value != null && ((Boolean) value).booleanValue()));
    34.        return c;
    35.    }
    36. }

    Quick and Dirty Tester Program!

    JAVA:
    1. import java.awt.Color;
    2. import java.awt.Dimension;
    3. import java.awt.FlowLayout;
    4.  
    5. import javax.swing.*;
    6. import javax.swing.table.AbstractTableModel;
    7. import javax.swing.table.DefaultTableModel;
    8.  
    9. /**
    10. * shows how to use the BooleanEditor and the BooleanRenderer.
    11. */
    12. public class JTableBooleanTester extends JFrame{
    13.     public JTableBooleanTester(){
    14.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    15.        
    16.         Dimension dim = new Dimension(200,75);
    17.        
    18.        
    19.         TestTableModel ttm = new TestTableModel();
    20.        
    21.         JTable table1 = new JTable(ttm);
    22.         table1.setForeground(Color.WHITE);
    23.         table1.setBackground(Color.DARK_GRAY);
    24.         JScrollPane sp1 = new JScrollPane(table1);
    25.         sp1.setPreferredSize(dim);
    26.        
    27.         JTable table2 = new JTable(ttm);
    28.         table2.setForeground(Color.WHITE);
    29.         table2.setBackground(Color.DARK_GRAY);
    30.         table2.setDefaultEditor(Boolean.class, new BooleanEditor());
    31.         table2.setDefaultRenderer(Boolean.class, new BooleanRenderer());
    32.         JScrollPane sp2 = new JScrollPane(table2);
    33.         sp2.setPreferredSize(dim);
    34.        
    35.         getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
    36.         getContentPane().add(sp1);
    37.         getContentPane().add(sp2);
    38.        
    39.         pack();
    40.     }
    41.  
    42.     public static void main(String[] args) throws Exception {
    43.         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    44.         SwingUtilities.invokeLater(new Runnable(){
    45.             public void run() {
    46.                 JFrame frame = new JTableBooleanTester();
    47.                 frame.setVisible(true);
    48.             }
    49.            
    50.         });
    51.     }
    52.    
    53.     static class TestTableModel extends AbstractTableModel{
    54.         Object[][] data = {{Boolean.TRUE, "Testing 1!"},{Boolean.FALSE,"Testing 2!"}};
    55.         Object[] names = {"Bool", "Something!"};
    56.        
    57.         public int getRowCount() {
    58.             return data.length;
    59.         }
    60.  
    61.         public int getColumnCount() {
    62.            
    63.             return names.length;
    64.         }
    65.  
    66.         public Object getValueAt(int rowIndex, int columnIndex) {
    67.             return data[rowIndex][columnIndex];
    68.         }
    69.        
    70.         public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    71.             switch(columnIndex){
    72.             case 0:
    73.                 data[rowIndex][columnIndex] = aValue;
    74.             }
    75.             fireTableDataChanged();
    76.         }
    77.        
    78.         public boolean isCellEditable(int rowIndex, int columnIndex) {
    79.             return 0 == columnIndex;
    80.         }
    81.  
    82.         public Class getColumnClass(int columnIndex){
    83.             return data[0][columnIndex].getClass();
    84.         }
    85.     }
    86. }

    First off, No, this is not a post on heaven or hell.

    I was in the grocery store this morning and on the radio (or intercom or whatever it is you call a speaker system in the grocery store) was playing "Big Yellow Taxi" by the Counting Crows featuring Vanessa Carlton.

    This music got me thinking. Paradise, as defined by me and others I have heard, is located in Hawaii or somewhere in the Caribbean. It has sandy beaches and warm water. The sun shines everyday and warm rains fall for short periods.

    Now my thought: Do I want to live there everyday, all day, all my life? Yes, it is a nice place to visit, relax and enjoy. Sounds like a great vacation spot. But to live there continuously?

    Would I have to give up my access to technology?  Such as mp3 players, computers, and even cars?  Is it our technology that does all the bad stuff in the world?

    I don't know.  I just think "Paradise" is a nice place to visit.  But I like my tech.

    [Nerd Alert]I hope for a day where we can live like Star Trek--all cool fancy tech, but with little or no consequence to the environment.[/Nerd Alert]