Swing development tip: Migrate event listeners when setting models

Change this -

public void setTableModel(TableModel tableModel) {
    this.tableModel = tableModel;
}

to this -

public void setTableModel(TableModel tableModel) {
    //migrate listeners
    if(this.tableModel != null) {
        if(this.tableModel.getTableModelListeners() != null) {
            for (TableModelListener p : this.tableModel.getTableModelListeners()) {
                tableModel.addTableModelListener(p);
            }
        }
    }
    this.tableModel = tableModel;
}

Enable/Disable Unity/Compiz Window Animations and Visual Effects in Ubuntu 12.04 (Precise Pangolin) and Ubuntu 12.10 (Quantal Quetzal)

For Ubuntu 12.04 (Precise Pangolin)

To turn on/off Unity/Compiz window animations and visual effects in Ubuntu -
  • Go to System Settings from the Ubuntu dash
  • Under 'Personal', click on the 'MyUnity' icon
  • In the 'MyUnity' window, go to 'desktop' tab and set the 'Windows animations' property accordingly.

 

 

 For Ubuntu 12.10 (Quantal Quetzal)

  • Install the CompizConfig Settings Manager application
    • This is available via Ubuntu Software Centre
    • For installing via apt - sudo apt-get install compizconfig-settings-manager
  • Start the application and go to Category > Effects from the left panel
  • Enable or disable effects as desired.
Note: MyUnity does not work with Ubuntu 12.10. This is a known bug. Also, the MyUnity package was removed from the Ubuntu 12.10 repository.

Reference: 11 Tips To Speed Up Computers Running Ubuntu 12.04/Linux Mint 13 (Maya)

Auto-mounting drives on Ubuntu at startup

Find out the device name of the partition you want to mount. Check under /dev or open the partition in nautilus (Ubuntu's file browser/explorer) and run the "mount" command in terminal to identify the device name e.g. /dev/sda3

Go to Ubuntu dash (top right) -> Startup Applications


Add a new startup application as shown in the image below and you're all set! Command : /usr/bin/udisks --mount /dev/sda3


The drive will be mounted automatically when you login to Ubuntu. This solution works on Ubuntu 11.10 (Oneiric), Ubuntu 12.04 (Precise Pangolin) and Ubuntu 12.10 (Quantal Quetzal).

For further details, more advanced settings and system-wide mounting, check - https://help.ubuntu.com/community/AutomaticallyMountPartitions

Changing the default editor in Ubuntu

  • Open terminal (ctrl + alt + t) and type "sudo update-alternatives -–config editor"
  • This will show all available editors 
  • Enter the number of the editor that you want to set as default and press the Enter key (and you're done!)

Another way to do this via the GUI is described here - http://www.addictivetips.com/ubuntu-linux-tips/2-ways-to-change-default-text-editor-in-ubuntu/

Changing the sudo timeout in Ubuntu

By default, Ubuntu remembers the sudo login for 15 minutes - this means you won't be prompted for your password for performing sudo operations for 15 minutes following a successful sudo login. This could be risky and can be changed so that the sudo password will be prompted for on every sudo login irrespective of the duration/timeout -
  • Open terminal and type "sudo visudo"
  • Locate the "Defaults ...." line as shown in the image below
  • Add this to the end of the line - ",timestamp_timeout=0"
    • Setting the timeout to 0 will prompt for the sudo password on every login. Alternatively this timeout can also be set to a number - e.g. setting it to 5 will remember the sudo password for 5 minutes.
  • Save the file and exit


Further reference

Preventing/Disabling Automatic Shutdown/Hibernate on Critical Battery Level in Ubuntu

In Ubuntu 11.10, the critical battery level behaviour can be controlled view the Settings -> Power. But it has 2 options only - shutdown & hibernate. Either of these options will immediately shutdown/hibernate Ubuntu on critical battery level.


To gain more control over this  -
  1. Install dconf editor. This is available on Ubuntu software centre as well
  2. Open the dconf editor (terminal > type dconf-editor)
  3. Navigate to org > gnome > settings-daemon > plugins > power
  4. Set the critical-battery-action option as required.
Settings the critical-battery-action to interactive will display a popup asking you what to do as shown below with a automatic-shutdown-timer of 60 seconds -


Edit: This option works for Ubuntu 12.04 (Precise Pangolin) and Ubuntu 12.10 (Quantal Quetzal) as well.