alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 * 
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 * 
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
 * Microsystems, Inc. All Rights Reserved.
 */


package org.netbeans.modules.tasklist.usertasks;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.openide.awt.StatusDisplayer;
import org.openide.options.SystemOption;
import org.openide.util.MapFormat;
import org.openide.util.NbBundle;

/** Settings for the user tasklist module.

  • append vs prepend
  • tasklist save name
  • whether or not to accumulate tasks scanned from the editor
  • whether or not we sould save backups
  • number of errors/scanned tasks to add to the display
  • whether those guys should be added to the current display or have separate view
*/ public class Settings extends SystemOption { /** serial uid */ // XXX check this one static final long serialVersionUID = 2L; // Option labels public static final String PROP_APPEND = "append", // NOI18N PROP_FILENAME = "filename", // NOI18N PROP_MAKE_BACKUPS = "backups", // NOI18N PROP_HOURS_PER_DAY = "hoursPerDay"; // NOI18N /** Return the signleton cppSettings */ public static Settings getDefault() { return (Settings) findObject(Settings.class, true); } /** * Get the display name. * * @return value of OPTION_TASK_SETTINGS_NAME */ public String displayName () { return NbBundle.getMessage(Settings.class, "OPTION_TASK_SETTINGS_NAME"); //NOI18N } /* public HelpCtx getHelpCtx () { return new HelpCtx ("Welcome_opt_editing_sources"); //NOI18N } */ /** * @return true iff the user wants backup files to be * created when the tasklist is saved. */ public boolean getBackups() { // By default, true Boolean b = (Boolean)getProperty(PROP_MAKE_BACKUPS); return (b != Boolean.FALSE); } /** Sets the makeBackups property * @param makeBackups True iff you want to make backups */ public void setBackups(boolean makeBackups) { Boolean b = makeBackups ? Boolean.TRUE : Boolean.FALSE; putProperty(PROP_MAKE_BACKUPS, b, true); //firePropertyChange(PROP_MAKE_BACKUPS, null, b); } /** * @return true iff the user wants to append items to the * tasklist instead of prepending. */ public boolean getAppend() { // By default, false Boolean b = (Boolean)getProperty(PROP_APPEND); return (b == Boolean.TRUE); } /** Indicate if the user wants to append items to the * tasklist instead of prepending. * @param append True iff you want to append instead of prepend */ public void setAppend(boolean append) { Boolean b = append ? Boolean.TRUE : Boolean.FALSE; putProperty(PROP_APPEND, b, true); //firePropertyChange(PROP_APPEND, null, b); } /** Sets the name of the file to read/write the tasklist in */ public void setFilename(String fname) { String t = getFilename(); if (t.equals(fname)) return; if (fname.trim().length() == 0) { // Use default fname = NbBundle.getMessage(Settings.class, "DefaultFilename"); //NOI18N } // Check that the file is valid? Should at least make sure // the parent dir exists // Try compiling the regular expression to make sure it's valid File f = new File(expand(fname)); File p = f.getParentFile(); if (!p.exists()) { // Print message in the message window? StatusDisplayer.getDefault().setStatusText( NbBundle.getMessage(Settings.class, "NoFolder", //NOI18N p.getPath())); throw new IllegalArgumentException(); } putProperty(PROP_FILENAME, fname, true); } /** Gets the name of the file to read/write the tasklist in */ public String getFilename() { String fname = (String)getProperty(PROP_FILENAME); if (fname == null) { fname = NbBundle.getMessage(Settings.class, "DefaultFilename"); //NOI18N } return fname; } /** Gets the name of the file to read/write the tasklist in, expanded such that {userdir} etc. is expanded to the real filename. */ public String getExpandedFilename() { String fname = getFilename(); return expand(fname); } /** * Hours per day property * * @return value of the property */ public int getHoursPerDay() { Integer b = (Integer) getProperty(PROP_HOURS_PER_DAY); if (b == null) return 8; else return b.intValue(); } /** * Sets the hours per day property * * @param h value of the property */ public void setHoursPerDay(int h) { if (h > 0 && h <= 24) putProperty(PROP_HOURS_PER_DAY, new Integer(h), true); } /** Expand a given filename using our map format */ private static String expand(String fname) { Map m = new HashMap(2); m.put("userdir", System.getProperty("netbeans.user")); // NOI18N m.put("/", File.separator); // NOI18N MapFormat f = new MapFormat(m); String result = f.format(fname); return result; } }
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.