Anyone can comment, so leave your views

Tuesday, November 25, 2008

Select Files & Folders: C# dotnet project excerpts

I recently had to do a MS Visual Studio DotNet C# project to mimic the back up tab of the Backup utility (attached image)
 
Two sites that helped : http://www.tangiblesoftwaresolutions.com/ and http://www.infragistics.com/ (tree view, over riding how a control is to be drawn, native support for 3 states of check boxes)
 
 
Interesting part is how it has to select parent nodes and gray them when you select a node whose parent/ grand parents are not selected.
 
Here is my altervative to using a image list and instead caching a few images
 
using System;
using System.Threading;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
 
using System.Data;
 
using System.Text;
using Infragistics.Win;
 
//using Infragistics.Win.UltraWinTree;
using Icons2;
 
using Infragistics.Win.UltraWinListView;
using Infragistics.Win.UltraWinTree;
using Infragistics.Shared.Serialization;
using FldrSel.draw;
using System.Runtime.InteropServices;
 
namespace Icons2
{
    /**
    * a holder for an icon and its ID
    * not required in all cases
    */
    public class IconInf
    {
        public Icon theIcon;
        public int id;
    }
    [StructLayout(LayoutKind.Sequential)]
    public struct SHFILEINFO
    {
        public IntPtr hIcon;
        public IntPtr iIcon;
        public uint dwAttributes;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szDisplayName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
        public string szTypeName;
    };
 
    class Win32
    {
        public const uint SHGFI_ICON = 0x100;
        public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
        public const uint SHGFI_SMALLICON = 0x1; // 'Small icon
 
        [DllImport("shell32.dll")]
        public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbSizeFileInfo, uint uFlags);
    }
   
    public class Othr
    {
        private struct SHFILEINFO
        {
            public IntPtr hIcon; // : icon
            public int iIcon; // : icondex
            public int dwAttributes; // : SFGAO_ flags
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
            public string szDisplayName;
            [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
            public string szTypeName;
        }
 
        [System.Runtime.InteropServices.DllImport("shell32.dll", EntryPoint = "SHGetFileInfo", ExactSpelling = false, CharSet = System.Runtime.InteropServices.CharSet.Auto, SetLastError = true)]
        private static extern IntPtr SHGetFileInfo(string pszPath, int dwFileAttributes, ref SHFILEINFO psfi, int cbFileInfo, int uFlags);
 
        private const int SHGFI_ICON = 0X100;
        private const int SHGFI_SMALLICON = 0X1;
        private const int SHGFI_LARGEICON = 0X0; // Large icon
  
        public const string FOLDER_STR = "[folder]";
        public const string DRIVE_STR = "[folder]";
        Dictionary<string, IconInf> icons = new Dictionary<string, IconInf>();
 
        public Othr()
        {
        }
        public void init(){
            string sExtn = "txt";
            if (!icons.ContainsKey(sExtn))
            {
 
                DefaultIcon di = new DefaultIcon();
                IconInf oIconInf = new IconInf();
                oIconInf.theIcon = di.GetIcon(sExtn);
                oIconInf.id = icons.Count;
                icons.Add(sExtn, oIconInf);
            }
        }
 

        public IconInf getIcon(string sFileName)
        {
            return getIcon2(sFileName);
        }
        private IconInf getIcon2(string FileName)
        {
            lock (icons)
            {
                if (icons.Count > 1100)
                {
                    System.Collections.ArrayList keys = new System.Collections.ArrayList(icons.Keys);
                    for (int i = 700; i < 800; i++)//remove from the middle, hopefully they are less used
                    {                      
                        icons.Remove(keys[i].ToString());
                       
                    }
                    init();//reinit
 
                }
            }
           
            System.Drawing.Icon myIcon = null;
 

            IntPtr hImgSmall = default(IntPtr); //The handle to the system image list.
            IntPtr hImgLarge = default(IntPtr);
            string sExtn = null;
            sExtn = "txt";
 
 
 
            try
            {
               
                //FileName = "d:\Dev"
                if (!System.IO.Directory.Exists(FileName))
                {
                    sExtn = FileName.Substring((FileName.LastIndexOf(".") + 1));
                }
                else
                {
                    sExtn = FileName;
                }
                if (icons.ContainsKey(FileName))
                {
                    sExtn = FileName;
                }
                else if (icons.ContainsKey(sExtn))
                {
                    //do nothing
                }
                else
                {
                    DefaultIcon di = new DefaultIcon();
                    IconInf oIconInf =  new IconInf();
                    oIconInf.theIcon = di.GetIcon(sExtn);
                    oIconInf.id = icons.Count;
                    icons.Add(sExtn, oIconInf);
 
                }
 
            }
            catch (Exception ex)
            {
 
                try
                {
                    SHFILEINFO shinfo = new SHFILEINFO();
                    shinfo = new SHFILEINFO();
                    hImgSmall = SHGetFileInfo(FileName, 0, ref shinfo, Marshal.SizeOf(shinfo), SHGFI_ICON | SHGFI_SMALLICON);
                    myIcon = System.Drawing.Icon.FromHandle(shinfo.hIcon);
                    //icons[sExtn] = myIcon;
                   
                    IconInf oIconInf = new IconInf();
                    oIconInf.theIcon = myIcon;
                    oIconInf.id = icons.Count;
                    icons.Add(sExtn, oIconInf);
                }
                catch (Exception ex2)
                {
                    //default
                    sExtn = "txt";
                }
            }
 
            IconInf oIconInf2 = icons[sExtn];           
            return oIconInf2;
 
        }
       
    }
}

Friday, September 19, 2008

StringTableModel1Col JAVA jtable table model for one column of data all of type string

/**
*

StringTableModel1Col JAVA jtable table model for one column of data all of type string

@author tushar.kapila at gmail .com

*/
package xmltagger.common;
 
import javax.swing.table.*;
import java.util.*; import javax.swing.*;
 

public class StringTableModel1Col extends AbstractTableModel{
 ArrayList<String> data = new ArrayList<String>();// need array of arrays for multi col
 
 public void setValueAt(Object aValue,
                       int rowIndex,
                       int columnIndex){
 
  if(rowIndex >= data.size()){
   int toAdd = rowIndex - data.size();
   for(int i = 0; i < toAdd; i++){
    data.add("");
   }
  }
  data.set(rowIndex,(String)aValue);
 }
 
  public int getRowCount(){
   return data.size();
  }
  public int getColumnCount(){
   return 1;
  }
  public Object getValueAt(int row, int column){
   return data.get(row);
  }
 
}

Wednesday, September 17, 2008

mocha host - bad www.MochaHost.com

I used mocha host for jsp / java servlets hosting - but they are bad - could not get jsps to work and they did not refund even though I asked for a cancel when I could not get it to work :

 Posted On: 05 Sep 2008 12:49 AM
i requested the restart 2 days back but i got no email informing me of restart ! nor does it seem to have worked the site is not working - jsp not appearing.
 
eatj gives better free service please cancel this account and refund as i asked for java but never got it
 

Sunday, September 7, 2008

IE DEFAULT PRINT

HEADER
 
&w&bPage &p of &P
 
FOOTER
&u&b&d
 

Saturday, August 30, 2008

html javascript A demo showing html UI reacting in real time

A demo showing html UI reacting in real time.

Number 1
Number 2
Operation
Result
.
The html:
<html>
<title>A demo showing html UI reacting in real time.</title>
<body>
<form name=f1 action=aa type=get>
<table >
<tr><td>
Number 1</td> <td><input id=t1 onChange=t1c()></td>
 
</tr>
 

<tr><td>
Number 2</td> <td><input id=t2 onChange=t1c()></td>
 
</tr>
 

<tr id=oprw><td>
Operation</td> <td><select id=op onChange=t1c()>
<option value=a>+<option>
<option value=s>-<option>
<option value=m>*<option>
<option value=d>/<option>
</select></td>
 
</tr>
 
<tr><td>
Result</td> <td><input id=r disabled=true></td>
 
</tr>
<tr>
 
<td><input id=d1 onChange=d1c()></td>
</table>
</form>.
<script>
 
function t1c(){
 //alert("t1c");
 var op = document.getElementById("op");
 var t1 = document.getElementById("t1");
 var t2 = document.getElementById("t2");
 var oprw = document.getElementById("oprw");
 if(isNaN(t2.value))return;
 var r =  document.getElementById("r");
 alert("t1c " + t1.value + " t2 " + t2.value + " op " + op.value
 + " Number( t1.value) "+ Number( t1.value)
 + " Number( t2.value) "+ Number( t2.value));
 r.disabled = false;
 switch (op.value){
  case 'a':
  alert ("add" + (Number( t1.value) + Number( t2.value)))
   //r.value = Math.parseDouble(t1.value) + Math.parseDouble(t2.value);
   r.value = String (Number( t1.value) + Number( t2.value));
   break;
  case 's':
   //r.value = Math.parseDouble(t1.value) + Math.parseDouble(t2.value);
   r.value = (1 * t1.value) - (1 * t2.value);
   break;
  case 'm':
   //r.value = Math.parseDouble(t1.value) + Math.parseDouble(t2.value);
   r.value = (1 * t1.value) * (1 * t2.value);
   break;
 
  case 'd':
   //r.value = Math.parseDouble(t1.value) + Math.parseDouble(t2.value);
   r.value = (1 * t1.value) / (1 * t2.value);
   break;
 
 }
 r.disabled = true ;
}
</script>
 
 
</body>
</html>
 
Same but not escaped:
Number 1
Number 2
Operation
Result
. ;

Regards
Tushar Kapila
http://sel2in.com
Java, PHP, VB6 Apps. Fight Back pain: Exercise timer application
http://ksoft7.tripod.com/g3.html search page that allows you to search within any website uses google works best in Internet explorer and opera
http://minutes-alarm.sourceforge.net freeware minute alarm, easy reminder for back ache - stand up or meeting ...


Volunteer computer Cancer cures www.worldcommunitygrid.org
Click: www.thehungersite.com , and www.bhookh.com feed hungry , its free. www.ecologyfund.com
Physics-particle research & you helping http://stephenbrooks.org/muon1
Please add these to your start-up how to: http://tusharkapila.blogspot.com/2008/05/s.html

Saturday, August 16, 2008

Java Drop Shadow text effect download source

http://java.sun.com/developer/Books/2dgraphics/index.html good 3 d graphics attached new code for java 6 get the code from http://sel2in.com/pages/prog/java/awt/dropShadowText/download_java_2d_api_shadow_drop_text.html attachments not allowed here :(

Friday, June 13, 2008

Testing Web Applications With a Real URL on local system on Windows

moved to http://how2that.blogspot.com/2009/12/testing-web-applications-with-real-url.html

Sunday, May 11, 2008

html javascript: change page title

To change the title of a document can use
 
<script type="text/javascript">
document.title = document.title  + " :Run Mailer"; </script>
 
Useful when the title comes from a template but you want to customize
 
Ofcouse you dont have to append old title can just be
 
<script type="text/javascript">
document.title = "Run Mailer";
</script>

Regards
Tushar Kapila
http://sel2in.com
Java, PHP, VB6 Apps. Fight Back pain: Exercise timer application
http://ksoft7.tripod.com/g3.html search page that allows you to search within any website uses google works best in Internet explorer and opera
http://minutes-alarm.sourceforge.net freeware minute alarm, easy reminder for back ache - stand up or meeting ...

Volunteer computer Cancer cures www.worldcommunitygrid.org
Click: www.thehungersite.com , and www.bhookh.com feed hungry , its free. www.ecologyfund.com
Please add these to your start-up how to: http://tusharkapila.blogspot.com/2008/05/s.html
 

Regards
Tushar Kapila
http://sel2in.com
Java, PHP, VB6 Apps. Fight Back pain: Exercise timer application
http://ksoft7.tripod.com/g3.html search page that allows you to search within any website uses google works best in Internet explorer and opera
http://minutes-alarm.sourceforge.net freeware minute alarm, easy reminder for back ache - stand up or meeting ...

Volunteer computer Cancer cures www.worldcommunitygrid.org
Click: www.thehungersite.com , and www.bhookh.com feed hungry , its free. www.ecologyfund.com
Please add these to your start-up how to: http://tusharkapila.blogspot.com/2008/05/s.html


Thursday, February 28, 2008

trivia: generaelL Hyd ( KACHEGUDA) station (KCG)

Train No. & Name: 2785/BANGALORE EXP
Class: SL 
From: KACHEGUDA(KCG) To : BANGALORE CY JN(SBC)
Coach No:  S11 Distance: 0673 KM

Friday, February 22, 2008

nice flash

simply marry promo http://www.fireandice.co.in/
 

Thursday, February 21, 2008

mobile parser for device type, prog entry

prog entry ignore http://sourceforge.net/projects/wurfl help to detect mobile client

G
 
Forum
Ads by google:











Source code, testing article - one stop shop Software applications written in Java for cell phones, PHP, Java Dot net, PHP & Perl for the web and Vb6, Java, VB6, Perl and Excel VBA for the desktop .

- Tushar G Kapila
Bangalore India 2007 © Remaining page can be removed if you save on your pc or server.

Contributors