Saturday, November 15, 2014

Extjs best practises

 

 

 

 

                                                            1.use MVC

2.use xtype

3.define custom xtypes

4.use compressor - give minified files to client

5.use SenchaArchitect or cmd

6.travese dom using up/down etc - dont give ID and dont get by ID to elements

7.use icons instead of "text+icons"

8.inject images using css

9.use theming

10.avoid using deprecated commands and use new commands like using Ext.launch method

instead of Ext.onReady

11.dont declare deep tree... use layouts precisely... try to keep things with in 2 or 3

levels

12.Reuse the components

13. Try to do population and manipulation in afterRenderer than in beforeRenederer

14.Always handle exceptions, especially failure cases of a Ajax call

 

Wednesday, November 12, 2014

While trying samples with Ext.tab.Panel, as usual I though about the next step of using nested panels and load an external html file into a panel.
And I tried a few simple straight forward stuffs and for some reason it kept failing. Eventually I came up with an answer as usual. Guess I dont want to be stuck with this silly issue every again. And hence this post. Following is a part of my practise project which is necessary for the nested tab implementation

I have the following in code in the head section of my "index.html" file

 <!-- STYLES -->
    <link rel="stylesheet" type="text/css" href="\ext-4.2.1.883/resources/css/ext-all.css">
    <!-- LIBS -->
    <script type="text/javascript" src="\ext-4.2.1.883/ext-all-debug.js"></script>
    <!-- APP -->
    <script type="text/javascript" src="./app.js"></script>

The contents of my "external.html" file are as follows
<div id='karthick'>
My Custom text from an external HTMl
</div>

And the following in my "app.js" file

 Ext.require('Ext.tab.*'); Ext.application({ name: "Tab Panel example", launch : function() { var tabs = Ext.create('Ext.tab.Panel', { width : 450, height: 400, renderTo: document.body, activeTab : 0, id:'parentTab', items : [{ title:'Home', itemId : 'tab1', xtype: 'container', loader: { url: 'external.htm', autoLoad: true }, closable : true }, { title:'Away', itemId : 'tab2', closable : true, items:[{ xtype:'tabpanel', items : [{ title: 'Nested Tab 1', itemId : 'nested tab1', closable : true, html:'nested tab1' },{ title: 'Nested Tab 2', itemId : 'nested tab2', closable : true, html:'nested tab2', disabled:true }] }] }] }); } });

So the end result is as follows
The highlights in this example are
1. You are using a nested tabbed table created through Ext-js 4.2
2. It implements some inbuilt properties like
- closable:true
- and disable:true
3. You have included an external html file's content into your page


Note: this example wont work if you are trying this example in a local stand alone machine. Use a server like tomcat or IIS, because, the inclusion of content from an other html file includes AJAX requests in the back end by Ext-JS which would definitely fail in local or conclusively it requires a server to operate

Nested Tab example in Ext-Js

While trying samples with Ext.tab.Panel, as usual I though about the next step of using nested panels.
And I tried a few simple straight forward stuffs and for some reason it kept failing. Eventually I came up with an answer as usual. Guess I dont want to be stuck with this silly issue every again. And hence this post. Following is a part of my practise project which is necessary for the nested tab implementation

You can safely omit external.htm file for now

I have the following in code in the head section of my "index.html" file

 <!-- STYLES -->
    <link rel="stylesheet" type="text/css" href="\ext-4.2.1.883/resources/css/ext-all.css">
 
    <!-- LIBS -->
    <script type="text/javascript" src="\ext-4.2.1.883/ext-all-debug.js"></script>
 
    <!-- APP -->
    <script type="text/javascript" src="./app.js"></script>

And the following in my "app.js" file

Ext.require('Ext.tab.*');

Ext.application({
name: "Tab Panel example",
launch : function() {
var tabs = Ext.create('Ext.tab.Panel', {
width : 450,
height: 400,
renderTo: document.body,
activeTab : 1,
id:'parentTab',
items : [{
title:'Home',
itemId : 'tab1',
html: 'First tab content',
closable : true
}, {
title:'Away',
itemId : 'tab2',
closable : true,
items:[{
xtype:'tabpanel',
items : [{
title: 'Nested Tab 1',
itemId : 'nested tab1',
closable : true,
html:'nested tab1'
},{
title: 'Nested Tab 2',
itemId : 'nested tab2',
closable : true,
html:'nested tab2',
disabled:true
}]
}]
}]
});

}
});

The end result that I obtained is as follows. 


:)

Wednesday, November 5, 2014

File Upload using Servlets


Create a simple Dynamic Web project in the eclipse IDE. I have installed Apache Tomcat 7.0.10 and following is my folder stucture. You can safely skip the HelloWorld.java and LogFilter.java files from this folder structure as they don't have any thing to do with this post.

My motive is to give a simple explanation/illustration on how a file upload control can be implemented in java programs using servlets.

Step 1. create a FileUploadTest.html file in your WebContent folder. I tried putting the same under a sub folder of the WebContent folder. But it never worked. It was not able to communicate with the corresponding servlet.
The code contents of this HTML file are as follows
test




Step 2: Create a servlet class with the following contents in it

package com.practise.karthik.servlet;

// Import required java libraries
import java.io.*;
import java.util.*;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.commons.io.output.*;

public class UploadServlet extends HttpServlet {
 
   private boolean isMultipart;
   private String filePath;
   private int maxFileSize = 50 * 1024;
   private int maxMemSize = 4 * 1024;
   private File file ;

   public void init( ){
      // Get the file location where it would be stored.
      filePath =
             getServletContext().getInitParameter("file-upload");
   }
   public void doPost(HttpServletRequest request,
               HttpServletResponse response)
              throws ServletException, java.io.IOException {
      // Check that we have a file upload request
      isMultipart = ServletFileUpload.isMultipartContent(request);
      response.setContentType("text/html");
      java.io.PrintWriter out = response.getWriter( );
      if( !isMultipart ){
         out.println("<html>");
         out.println("<head>");
         out.println("<title>Servlet upload</title>");
         out.println("</head>");
         out.println("<body>");
         out.println("<p>No file uploaded</p>");
         out.println("</body>");
         out.println("</html>");
         return;
      }
      DiskFileItemFactory factory = new DiskFileItemFactory();
      // maximum size that will be stored in memory
      factory.setSizeThreshold(maxMemSize);
      // Location to save data that is larger than maxMemSize.
      factory.setRepository(new File("c:\\temp"));

      // Create a new file upload handler
      ServletFileUpload upload = new ServletFileUpload(factory);
      // maximum file size to be uploaded.
      upload.setSizeMax( maxFileSize );

      try{
      // Parse the request to get file items.
      List fileItems = upload.parseRequest(request);
      // Process the uploaded file items
      Iterator i = fileItems.iterator();

      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet upload</title>");
      out.println("</head>");
      out.println("<body>");
      while ( i.hasNext () )
      {
         FileItem fi = (FileItem)i.next();
         if ( !fi.isFormField () )
         {
            // Get the uploaded file parameters
            String fieldName = fi.getFieldName();
            String fileName = fi.getName();
            String contentType = fi.getContentType();
            boolean isInMemory = fi.isInMemory();
            long sizeInBytes = fi.getSize();
            // Write the file
            if( fileName.lastIndexOf("\\") >= 0 ){
               file = new File( filePath +
               fileName.substring( fileName.lastIndexOf("\\"))) ;
            }else{
               file = new File( filePath +
               fileName.substring(fileName.lastIndexOf("\\")+1)) ;
            }
            fi.write( file ) ;
            out.println("Uploaded Filename: " + fileName + "<br>");
         }
      }
      out.println("</body>");
      out.println("</html>");
   }catch(Exception ex) {
       System.out.println(ex);
   }
   }
   public void doGet(HttpServletRequest request,
                       HttpServletResponse response)
        throws ServletException, java.io.IOException {
     
        throw new ServletException("GET method used with " +
                getClass( ).getName( )+": POST method required.");
   }
}

Step 3: Add the following to your web.xml
 <servlet>
<servlet-name>UploadServlet</servlet-name>
<servlet-class>com.practise.karthik.servlet.UploadServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>UploadServlet</servlet-name>
<url-pattern>/UploadServlet</url-pattern>
</servlet-mapping>


Set 4 : Now you would need a couple of jar files that would help you with the file upload functionality

commons-fileupload.x.x.jar file - You can download it fromhttp://commons.apache.org/fileupload/.
commons-io-x.x.jar file - You can download it from http://commons.apache.org/io/.

Step 5: Download these files and add them to the lib folder under the WEB-INF folder and add it to the project's build path


Step 6: Now stop your Apache Tomcat Server if its already running. 
 - Right click on the html file mentioned in step 1, 
 - click on "Run as" and 
 - click on "Run on server" option
 - choose your installed Tomcat server ( hope you had already added the server to your Servers view in the eclipse) and
 - finish

This helped me get to the following screen



Choose your file and click on the "Upload File" button. You should receive a confirmation screen with the name of the file that you just uploaded as follows


This helped me upload my file to my server space configured in the web.xml and I am able to find the uploaded file as follows

Friday, October 17, 2014

replacing newline with characters in java

I had a string named “remarks” with the following value in it

 

10/17/2014 07:14 AM test1

test1

test1

test1

10/17/2014 07:14 AM dfgdfg

 

I tried to replace all line feeds in this string with a particular character set in java and so I tried the following

 

String re = remarks1.replaceAll("\n","$#$”);

System.out.println(re);

 

This kept giving me illegal arguments exception.

 

So I tried

String re = remarks1.replaceAll("\\n","$#$");

System.out.println(re);

 

Now I felt weird. This is not normal behavior as most of my searches said this should work. Hence I felt a little irritated and I tried a different string instead of “$#$”. It was a stupid attempt though. But to my astonishment it worked fine

 

Curse compiler. Stupid same and its issue with “$” characters

 

Following worked at last

 

String re = remarks1.replaceAll("\\n","@#@");

System.out.println(re);

 

The output was

10/17/2014 07:14 AM test1@#@test1@#@test1@#@test1@#@10/17/2014 07:14 AM dfgdfg@#@

 

At ease 0.0  grrr

Thursday, August 14, 2014

error c00c0240 - "Could not complete the operation due to error c00c0240." - AJAX request in Struts

I happened to encounter this error when I was attempting to debug an Ajax call to a Struts action. It made me feel miserable for a while as both firebug as well as eclipse debuggers with console showed no trace of the origins of the error. As usual I searched out for the error number and ended up with a lot of stack overflow posts. One of these posts were typically explaining me the same issue that I was facing and had a link to a blog post which contained a solution to the same. And to my relief, my companies network restrictions prevented that page from being loaded. Wait WTF!!! Yes... that’s how grateful I felt roflJ.

 

Enough of my story, the issue in my case was that the AJAX request that I framed and tested was

 

var x= new XMLHttpRequest();x.open("GET","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText

 

This was giving me some un relevant message like the following and my debugging points never worked and neither the eclipse console had any logs printed in them through the log4j framework.

 

"
<html>
<head>
  <script type="text/javascript" src="/****/js/*****.js"></script>
   <script type="text/JavaScript">
           window.document.onkeydown=checkKeyCode;
   </script>
</head>
<body>
<table  width="100%" valign="top" height="100%">
<tr>
<td align="center"><font color="red"><h4>
There was a problem, please try again!</h4></font>
</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
</tr>
</table>
</body>
</html>"

 

And I found the “THE ISSAC NEWTON” in me like most of the times, as something stuck me and I tried “POST” instead of “GET”

 

And now, I see some positive results. My debugging points in the eclipse is working.. Hurray!!!!!

 

var x= new XMLHttpRequest();x.open("POST","http://localhost:7001/****/*************Action.do",false);x.send(null);x.responseText

 

Hurray!!!!! Again. But wait, WTF its just that my debugging points in eclipse are working. So wait my work is not done yet

 

L J

 

Friday, July 25, 2014

Writting run time code in eclipse for debugging as in firebug console

While debugging an application/program in eclipse , go to the display screen in the side menu items with in the eclipse and type run time variables and execute the same like you would prefer to do in firebug, where you type commands and click on run.

 

Alternatively, to bring up the Display screen, you can go to

 

window->show view ->Display or Ctrl+Shift+D

 

I have simply heard about the same and have not tried it yet. So plz don’t blame me if it does not work for you.

 

Hope this works 0.0

 

Thursday, July 24, 2014

Customizing the UNIX User Environment - Part 1 - UNIX shell configuration files - Part 1

Customizing the UNIX User Environment

**********************************************************************************

UNIX shell configuration files

**********************************************************************************

Introducing shell configuration files

---------------------------------------

 

A shell is an interactive interface that you use to communicate with the UNIX kernel. It provides a way of executing commands and getting standard feedback in the UNIX environment.

 

Kernel is a software layer that enables interaction of the HLL with the hardware

 

The most commonly used UNIX shells unclude the

- Bourne shell - is the oriinal UNIX shell, developed by Stephen Bourne. It doesnot support some of the features of the more recent shells, such as command-line editing

- Korn shell - is similar to the Bourne Shell but incorprates features from the C shell - dev by David Korn

- Bash shell - is the GNU (operating system) implementation of the Bourne shell, and stands for Bourne Again Shell. It adds features such as command-line editing to the original Bourne shell.

- C shell - is a UNIX shell developed by Bill Joy. It is similar to the Bourne shell, but its command set has been adapted syntactically to match the C language.

 

Typically a shell runs in interactive mode, meaning that you can type commands into it and get results. It's also possible to run a shell non interactively. For example, while working in the Bash shell you might need to run a shell script that required the C shell. If properly configured, the script could invoke the C shell in a noninteractive mode long enough to complete the script's running.

 

When a shell starts up, it reads several different configuration files to learn how you want it to look and behave. Typically, a shell will begin by reading the /etc/profile file. This file contains global environment variables that the root user wants constant for all users, and only root can edit this file.

 

Once the shell has processed the /etc/profile file, it reads the .profile file located in the home direcotry of the user that started the shell. The initial period indicates that the file is hidden.

 

Because UNIX generally only reads the .profile file during login, specific shells have additional startup and configuration files. Both the Korn and Bash shells have an evironment variable called ENV that points to a script that is run whenever a new shell is started, not just at login.The name of the file that ENV poins to is arbitrary. However, by convention, on Bash it is called .bashrc, and on Korn .kshrc.

Customizing the UNIX User Environment - Part 1 - UNIX shell configuration files - Part 2

Customizing the UNIX User Environment

**********************************************************************************

UNIX shell configuration files

**********************************************************************************

 

Configuring user profiles

----------------------------------------

The file that most directly affects a user's experience of a shell is the .profile file located in a user'a home directory.

This file contains variables and commands that relate to how a user's shells will look and respond

 

Following is an example of a Bash shell .profile file.

 

bash-2.05a# cat .profile

#variables

SHELL=/bin/bash              #specifies path to the executable file for this shell

ENV=$HOME/.bashrc

PS1=$PWD

PATH=/usr/java/j2sdk_1_4_01/bin:$PATH

bash-2.05a#

 

Any line of text in a .profile file that begins with a hash (#) is a comment and the system ignores it.

Note: There are no mandatory .profile variables. Each variable shown here is an example, and is not strictly required to run a functional system.

 

ENV vairable specifies the path to the script that will be run for every subsequent instance of this shell-such as non interactive subshells launched by other scripts. It references the path value stored in the shell variable HOME - set elsewhere - by placing a dollar symbol ($) in front of the variable name.

 

The PS1 variable specifies the text that should be displayed as a prompt. In this case, it references the value stored in the PWS global variable, which is the path to the current working directory

 

The PATH variable specifies paths for the system to search for executables binaries. The PATH variable is normally set in the /etc/profile file. In this case, the value of the PATH variable is appended with additional information specifically for this user.

 

Followin gis a sample .bashrc file. which would normally be referenced by the EBV variable in a user's .profile file.

 

bash-2.05a# cat .bashrc

#Aliases

alias f=finger

alias fun=/usr/games

bash-2.05a#

 

Note : There are no mandatory .bashrc commands. Each command shown here is an example, and is not stricly required to run a functional system.

 

This .bashrc file contains alias commands that allow you to assign a shortcut name to a command or path, to minimize typing.

The first command assigns an alias of "f" to the finger command, which means you could now execute the finger command simply by typing f.

If the target of an alias consists of more than a single word, you should enclose it in single quotes.

 

The next alias command assigns an alias of "fun" to the path /usr/games. This means you could now navigate to that path by typing cd fun.

 

Alias commands can be executed from the shell prompt.

When the target of an alias is longer than a single word, you need to remember to enclose it in single quotes. In this case, the full statement reads as folloes:

alias list = 'ls -l|more'

 

Summary

--------------

A shell provides an interface for users to interact with the kernel. You configure shells using the /etc/profile and .profile files.

The .profile file contains variables and commands that configure a specific user's shell, but the file is usualy only referenced at login. Any commands that should be executed for every script should be placed in a separate file and referenced using the ENV variable.

Customizing the UNIX User Environment - Part 1 - Working with UNIX environment - Part 3

Customizing the UNIX User Environment

**********************************************************************************

Working with UNIX environment

**********************************************************************************

Global and local variables

-----------------------------

 

You use variables to customize how a shell looks, behaves, and responds to user input.

There are two kinds of variables: global or environment variables and local or shell variables

 

The root user sets global variables and stores them in the /etc/profiles file. Global variables affect all users' shells, providing standard parameters for any shell environment.

Programs running in the system have access to global variables, and use them to make behavior decisions.

 

Users can set theor own local variables, storing them in .profile files in their home directories.

Local variables affect a particular user's shell session only.

 

Some common global variables include

-EDITOR  - specifies default editor to use for general text edits. Default value is the vi text editor

-PATH  - specified one or more paths that the system will search for executable files when you enter a command at the shell prompt. The default setting is /usr/bin.

-PRINTER - specifies the default pronter. By default this is not set

-PS1 - specifies the prompt displayed in the shell. Default is $

-SHELL - specifies the path to the default shell program. on most systens this would be /bin/sh.

-TERM - specifies the default terminal used to access the system. The default value is vt100.

 

Some common local variables include

-HOME - specifies the path to the user's home directory

-LOGNAME - specifies the name that the user uses to log in with

-MAIL - specifies the path to the user's mailbox

 

When you set a global variable in a local context, the global variable gets overrided. Local variables are for customizing an individual user's experience of the system, so they override global variable values - for that user only.

 

You can view all of the currently set variables in your shell using the env command. Please type env in the console and hit enter to see the currently set variables

 

You can view the value of an individual variable using the echo command.

bash-2.05a$ echo $PATH

 

You need to prefix the variable name with a $ symbol in order to reference its contents rather than just typing it's name

 

In Bourne shell derivatives, you can set individual variables from the shell prompt by simply declaring them using the form variable=value.

The code shown here sets the value of the PS1 variable - the text that the shell displays as a prompt - to the current working directory, followed by a $.

 

The PS1 variable supports several switches to make it easier to configure, including

-\h - systems hostname

-\s - reference the name of the current shell

-\t - reference the current time in 24 hour format (HH:MM:SS)

-\u - reference your current username

-\w - reference the name of the current working directory

 

Once you've set the value of a variable you can force any subshells you launch to use the same value, using the export command, as shown here.

 

bash-2.05a$ PS1='\w$'

/home/ak$ export PS1

/home/ak$

 

Setting variables in the C shell is similar to Bourne variants, but requires the use of the setenv command.

The code shown here sets the value of the ld_library_path variable to /usr/lib.

 

easynomad2$ setenv ld_library_path variable to /usr/lib

easynomad2$

 

The C shell uses a different set of variables from the Bourne derivative shells. Because some of the variable names are the same, all C shell variables are expressed in lowercase.

 

Customizing the UNIX User Environment - Part 1 - Working with UNIX environment - Part 4

Customizing the UNIX User Environment

**********************************************************************************

Working with UNIX environment

**********************************************************************************

 

User environment commands

------------------------------------------------------------

UNIX comes with many standard command programs, stored in directories such as /bin, /usr/bin, and /sbin.

Shell programs have additional commands built into them. These commands are known as user environment - or built-in - commands.

 

One of the most useful built-in commands is the su command. Executed without arguments, it allows you to become the root user while logged into any other account, as shown here.

This is extremely convenient if you find yourself in need of admin privileges while logged in as another user, as it saves you having to logout and in again as root. If you use su, you will be required to supply the root password.

 

bash-2.05a$ su

Password:

su-2.05a#

 

When you've finished your admin task, you end your su session with the exit command, which returns you to your normal shell.

 

su-2.05a# exit

exit

bash-2.05a$

 

One of the functions of groups in UNIX is to allow members of groups to share files with each other, or to access resources that belong to the group.

If you need to move a fils, directory or other resource to a different group, you can do so using the built-in command chgrp.

 

Syntax: chgrp [-R] new _groupt object

It takes atleast two arguments: the destination group and the name of the object being moved. And you can specify the -R option if you're moving a directory and you want its subdirectories and all their contents to be moved as well.

 

You can get a lost of all users currently logged into the system using who command.

You can find out more about a currently logged in user using the finger command with their username as an argument

 

The finger command produces info abt a currently logged in user, including their fullname, the path to theor home directory, and which shell they're currently using.

 

Customizing the UNIX User Environment - Part 2 - Customizing X - Part 1

Customizing the UNIX User Environment

**********************************************************************************

Customizing X

**********************************************************************************

 

In UNIX systems, the X Window System - also called X - controls the interaction between the GUI display and the programs and applications that use it. The most popular and widespread of the X window System is XFree86

 

X architecture

------------------------

The X Window System uses a client-server architecture. The X server process runs on the computer that is displaying the GUI. This is usually a terminal or workstation.

 

The X client process runs on the computer that runs the application that suppies data to the GUI. This can be the same computer that displays the GUI, but it can also be a remote computer such as a network server.

 

Because X client applications can run on central network servers, you can implement networks where the terminal computers are very simple. X terminals need to have enough RAM and disk space to run the UNIX kernel and the X server procecss, but they dont need disk space for applications. They need a network card to communicate with servers, but they dont necessarily need a modem

 

Simple terminals that run only the kernel and X are called as X terminals. They function only as display terminals, with all application processing taking place on the server.

 

Although X hanfles the interaction between the GUI and the programs that display in it, X doesn't control the way windows look and behave.

The function is taken care of by window managers. These are programs that run on X servers. They rely on X for their interaction with the Kernel

 

The window manager determines the way window look on screen and the kind of controls - such as close and maximize buttons - that they have.

The window manager also controls the way users can move windows and alternate the focus between them.

 

There are many window managers for X, including Sawfish and Blackbox. Each window manager imarts its own look and feel to the GUI

 

The look and feel of a window manager depends on the set of GUI controls - or widgets - that it includes. Widgets are elements like buttons and drop-down lists. Each window manager has a different set of widgets

 

Because the UNIX GUI is made up of the X server process, a window manager, and usually a desktop environment, it requires much more processing and system resources than a command-line shell.

 

X is well suited to end-user computers like home PCs and office workstations. It shouldn't be used on busy servers like database and web servers because it uses system resources and slows down the server's vital operations.

 

A UNIX GUI can be comprised of an X server process, a window manager, and a desktop environment.

 

The X Window System also called X running on a computer are resource intensive, so you shouldn't use them on busy servers.

 

Customizing the UNIX User Environment - Part 2 - Customizing X - Part 2

Customizing the UNIX User Environment

**********************************************************************************

Customizing X

**********************************************************************************

 

Setting up an XFree86 server

-----------------------------------

XFree86 is the most widespread version of the X Window System. The latest version of XFree86 is version 4.x. Before you set up a computer to be an XFree 86 4.x server, you need to gather information about its display hardware. You need to find out about its

 

- monitor refresh rate - the horizontal scan rate and the vertical synchronization rate of the monitor

- display adapter chipset

- display adapter memory - determines the max resoulution and color depth that X can use.

 

To set up a computer as an XFree85 4.x server, you need to generate an initial X configuration file. To do this, you log in as the superuser and type the following at the shell prompt. Which inturn checks the computer's display hardware and generates a matching configuration file called XF86Config.new

 

bash-2.05a$ XFree86 - configure

bash-2.05a$ ls -l | grep 'XF86'

-rw-r--r-- 1 root wheel 2383 Oct 31 17:08 XF86Config.new

bash-2.05a$

 

You need to test whether the configuration file is set up correctly. To do this, you type the command statement shown here.

 

bash-2.05a$ XFree86 -xf86config XF86Config.new

 

XFree86 runs a test to determine whether X works with the configuration file. If it works, you should see a gray grid background with a black X-shaped cursor in the center.

 

To exit the test, you press Ctrl+Alt+Backspace.

 

Once you've generated and tested the XFree86 configuration file, you open the file using a text editor such as vi and tune it for the hardware and display configuration that you want.

The XFree86Config file consists of several sections, each of which deals with a specific area of X configuration.

The following sections specify basic XFree86 configuration settings

-Module - specifies optional modules that X can load when it start up. Eg font modules and double buffer extension (DBE) module

-Files - allows you to specify path to RGB color code db as well as paths to font directories

-Server flags - enable/disable various X server settings including detailed error messages

 

The following section of the XFree86Config file deal with the X server's input and output devices:

-Input devices - protocols & settings for i/p devices & specify props like keyboard layout, keystrike autorepeat speed, three-button mouse emulation etc..

-Monitor - horz scan rate and vert synchronization rate for monitor

-Graphics device - disp adapter and video memory

-Screen - color depth & resolution

-ServerLayout - configuring X for multiple monitors

 

You need to configure the refresh rate, color depth, and screen resolution before you can run X reliably

 

To specify the refresh rate of your monito, you open the XFb6Config file and go to the Monitor section.

You specify the horizontal refresh rate by assigning a value in KHz to the HorizSync parameter and you specify the vertical refresh rate by assigning a value in Hz to the VertRefresh parameter.

 

Note: You can find out your monito's refresh rates from the monitor's user manual or from the plaguw at the rear of the monitor.

 

To specify color depth and screen resolution, you go to the Screen section of the XF86Config file.

The Screen section contains multiple Display subsections, each of which applies to a particular color depth. You can set different screen resoluitons for each color depth.

 

To set the screen resolution for a particular color depth, you add a line to the relevant subsection and specify the resolution using the Modes parameter

 

You set the default color depth using the DefaultColorDepth parameter at the beginning of the Screen section.

When you start X, it displays at the default color depth and uses the screen resolution that you've specified in the Display subsection corresponding to that color depth.

 

Once you've finished editing the XF86Config file, you copy it to the /etc/X11 directory. X will then use this configuration fole each time you start X.

 

bash-2.05a$ cp XF86Config.new /etc/X11/XF86Config

 

Unless a computer has been configured to load X automatically at startup, you need to start X manually from the command prompt. You type the following command to do it

 

bash-2.05a$ startx

 

When X starts up, it also loads the window manager and desktop environment that are currently configured as defaults.

 

To shut down X, you choose Logout from the desktop's main menu or press cntrl+Alt+Backspace to kill X.

Customizing the UNIX User Environment - Part 2 - Customizing X - Part 3

Customizing the UNIX User Environment

**********************************************************************************

Customizing X

**********************************************************************************

 

Installing fonts

----------------------------

X can use a variety of fonts to display text in windows and on widgets. Before you can use these fonts, however, you need to install them and configure X so that it knows where to find the font files.

XFree86 4.x supports three types of fonts:

-Type 1 fonts - use an Adobe postsscript standard. They store the character glyphs and font metrics in two separate files

-TrueType fonts - use an Apple standard. They've also been widely adopted by Microsoft. They are highly scalable and store all their font info in a single file

-antialiased fonts - new feature of XFree86 4.x. They are rendered more smoothly than other types of fonts.

 

UNIX stores Type 1 fonts in several font directories that branch from /usr/ports/x11-fonts/.

These include the urwfonts directory and the free fonts directory.

 

To install donts from a font directory, you navigate to the directory and type

make install clean.

 

bash-2.05a$ cd urwfonts

bash-2.05a$ make install clean

 

when you install a set of fonts, UNIX creates font directories in /usr/X11R6/lib/X11/fonts/

 

To configure X so that it can access these fonts, you need to edit the Files section of the XF86Config file.

 

You add a FontPath row to the Files section, specifying the location of the font directory. In this case, you specify the path to the URW font directory.

 

XFree86 4.x supports TrueType fonts using an extension module called freetype. You need to enable this module so that X can access TrueType fonts.

 

To enable the freetype module, you edit the XF86Config file, adding the following row to the Modules section:

Load "freetype"

 

XFree86 4.02 and later versions support antialiasing for all scalable font types. However, many desktop toolkits don't support antialiasing. The Qr toolkit for the KDE desktop is one of those that do.

 

To enable antialising with Qt, you need to edit the /usr/X11R6/lib/X11/XftConfig file using a text editor such as vi. You add lines defining each of the font directories for which you want to enable antialiasing

 

Because antialiasing smooths out the edges of screen fonts, it makes small fonts more readable and large fonts more attractive. However, it causes eyestrain when applied to medium-size fonts.

 

To disable antialiasing for medium-size fonts, you add a section to the XftConfig file that matches a range of font sizes - in this case 10 to 14 points - and disables antialiasing for it.

 

On a large network, it may be better to set up a font server and configure X to look for fonts on the font server.

 

To configure X to use a font server, you need to edit the XF86Config file and add a FontPath line to the Files section that specifies the port number of the font server. If font server is on port 3 you would see something line

 

FontPath "unix:/3"

 

Note: this procedure sets up a system-wide font server. To add a user-specific font server, you need to edit the .xinitrc file in the user's home directory

 

 

 

Customizing the UNIX User Environment - Part 3 - UNIX X window managers and desktops - Part 1

Customizing the UNIX User Environment

**********************************************************************************

UNIX X window managers and desktops

**********************************************************************************

XDM

-----------

The X Display Manager (XDM) is a program that manages login sessions for the X Window System.

 

XDM prompts users for theor username and password. Then it authorizes them and opens a session on an X server for them.

When a user exits the X interface. XDM closes the session and prompts the next user for their username and password.

 

XDM is particularly useful in large network implementations that have more than one X dispay server. In such cases, XDM allows users to choose which server they want to connect to.

 

To start XDM, you run the XDM binary, which in this case is located in the /usr/X11R6/bin directory. You need to be logged in as root to do this.

 

You can configure a system so that XDM runs automatically when the system starts up. The procedure for doing this varies from one flavor of UNIX to another.

 

If you're using a system with virtual terminals - such as FreeBSD - you can add a line to the /etc/ttys file that automatically runs XDM in one of the virtual terminals. In this example, XDM uses the ninth virtual terminal.

 

Once you've started XDM, it display a graphical login window whenever a user needs to login.

You can customize the appearance of this window. This example shows a common default.

 

You can configure XDM by editiong the following files, all of which are located in /usr/X11R6/lib/X11/xdm:

- xdm-config - file contains flobal default settings that apply to all of the displays to which users can connect

- xdm-errors - file contains a record of error messages generated by the X sessions that XDM runs. It's useful for troubleshooting

- xdm-pid - file allows you to specify the process ID of the XDM process.

- Xaccess - file contains a set of rules for controlling access to XDM. You can use it to determine how remote X client connections are authorized.

- Xresources - file contains default settings for the appearance of the login screen, and specifies the default display server.

- Xservers - file lists all the remote display servers to which users of XDM can connect. They can choose any of these servers when they log in.

- Xsession - file is the default session script that runs when users log in and start a session.

 

Note : The directory in which these files are located may differ depending on the UNIX implementation you're using.

 

In addition to the XDM configuration files, the /usr/X11R6/lib/X11/xdm directory contains a set of display setup scripts.

These scripts are named Xsetup_0, Xsetup_1, and soon. You can use them to specify background processes that run automatically when XDM starts an X session on a particular display.

Customizing the UNIX User Environment - Part 3 - UNIX X window managers and desktops - Part 2

Customizing the UNIX User Environment

**********************************************************************************

UNIX X window managers and desktops

**********************************************************************************

Integrated desktop environments

-----------------------------------------------------------------------------------

Integrated desktop environments provide an attractive and user-friendly interface to UNIX systems. It is a preconfigured session of a window manager.

 

Integrated desktop environemnts commonly contain

- default settings for window appearance and behavior

- a set of defautl widgets

- a set of desktop backgrounds

- default desktop icons such as a recycle bin

- a panel for managing tasks and workspaces

 

There are three common integrated desktop envionments for UNIX

- Common Desktop Environment (CDE)

- Gnome

- Kool Desktop Environment (KDE)

 

All of the above mentioned evnironment have at the minimum, A trash icon, easy access drip-down menus and workspace buttons in common

 

KDE is bundled with its own window manager, while Gnome i most commonly used with Sawfish. Desktop environments and window managers are distinct GUI components - you are not obliged to have a window manager but, when you do, it sits on top of your desktop.

 

Summary

---------

The X Display Manager (XDM) is a program that manages login sessions for the X Window System. XDM prompts users for their username and password. Then it authorizes them and opens a session on an X server for them. When a user exits the X interface, XDM closes the session and prompts the next user for their username and password.

 

Window managers are programs that run on an X server and determine the appearance and behavior of windows in the GUI environment. For example, window managers determine window colors and borders, button size and style, and focus policy.

 

Integrated desktop environemnts are preconfigured sessions of a window manager, providing default widgets, icons, and backgrounds. Most of them include a panel that allows you to manage tasks and workspaces. The three most popular desktop environments are the Common Desktop Environment(CDE), Gnome, and the Kool Desktop Environment (KDE).

Customizing the UNIX User Environment - Part 3 - UNIX X window managers and desktops - Part 3

Customizing the UNIX User Environment

**********************************************************************************

UNIX X window managers and desktops

**********************************************************************************

Integrated desktop environments

-----------------------------------------------------------------------------------

Integrated desktop environments provide an attractive and user-friendly interface to UNIX systems. It is a preconfigured session of a window manager.

 

Integrated desktop environemnts commonly contain

- default settings for window appearance and behavior

- a set of defautl widgets

- a set of desktop backgrounds

- default desktop icons such as a recycle bin

- a panel for managing tasks and workspaces

 

There are three common integrated desktop envionments for UNIX

- Common Desktop Environment (CDE)

- Gnome

- Kool Desktop Environment (KDE)

 

All of the above mentioned evnironment have at the minimum, A trash icon, easy access drip-down menus and workspace buttons in common

 

KDE is bundled with its own window manager, while Gnome i most commonly used with Sawfish. Desktop environments and window managers are distinct GUI components - you are not obliged to have a window manager but, when you do, it sits on top of your desktop.

 

Summary

---------

The X Display Manager (XDM) is a program that manages login sessions for the X Window System. XDM prompts users for their username and password. Then it authorizes them and opens a session on an X server for them. When a user exits the X interface, XDM closes the session and prompts the next user for their username and password.

 

Window managers are programs that run on an X server and determine the appearance and behavior of windows in the GUI environment. For example, window managers determine window colors and borders, button size and style, and focus policy.

 

Integrated desktop environemnts are preconfigured sessions of a window manager, providing default widgets, icons, and backgrounds. Most of them include a panel that allows you to manage tasks and workspaces. The three most popular desktop environments are the Common Desktop Environment(CDE), Gnome, and the Kool Desktop Environment (KDE).

Customizing the UNIX User Environment - Part 4 - UNIX documentation - Part 1

Customizing the UNIX User Environment

**********************************************************************************

UNIX documentation

**********************************************************************************

UNIX system documentation refers to reference material, which is in the form of both online and hard copy tutorial documents and manuals. The system documentation enables a user to access help information on how to install UNIX and use UNIX commands and utilities.

The system documentation may include the online manual, commonly referred to as "the man pages," info pages, and instructions in "readme" files, which are sometimes provided with applications. Although documentation is usually available in an electronic format, hardcopy documentation is sometimes provided with a system.

 

Overview of the online manual

-------------------

The UNIX online manual - known as the man pages - contains explanations of all the UNIX commands.

You can use these explanations as a handy reference to find out what a particular command does

You can also use it to search for a task you want to perform

 

The online manual includes the following sections

commands - The user commands section contains help information on UNIX commands that ordinary users can access

systemcalls - contains help info on functions that only the kernel provides

subroutines - contains help information on library functions

special files - contains help info on devices listed in the dev directory

file formats - contains help info on file format descriptions for example /etc/passwd

macro packages and conventions - contains info on miscellaneous apps

games - contains info on games installed on a computer system

system maintenance - contains help info about system administration tools executable by the root

 

Subroutines (add info) - Third party library APIs are supplied to perform tasks which are not included in the default installations. You can program against these libraries using an appropriate language, such as C++. The suppliers of the livraries include their own man pages that descrine each function and how to use it.

 

System Calls (add info) - By virtue of the kernel UNIX allows many programs to run simultaneously by giving each one the illusion that it exists on its own private virtual-machine. Calls from your applications to the kernel are known as system calls. You can use the trace command to see the system calls that a particular application generates.

 

System Maintenance (add info) - Administration function allows you to maintain a UNIX system. For example, they allow you to gather details on a specific user(finger), determine who is currently logged on (who is), and remove a specific process(kill).