🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
6 messages
6 total messages Started by Alan Shiers Sat, 25 Oct 2003 20:45
displaying child nodes on demand
#1524
Author: Alan Shiers
Date: Sat, 25 Oct 2003 20:45
19 lines
1587 bytes
Hi there,

I'm working on a client/server project where the client side app has a
JTree.  I am trying to set up a TreeModel so that it retrieves from the
server app the names of the child nodes of a given node when the
treeWillExpand(TreeExpansionEvent tee) method gets triggered.  So far I've
accomplished this.  In my TreeModel class I have a method called:

ReceiveChildrenFromServer(DefaultTreeNode parent, String ParentsWholePath,
DataInputStream input)

This method does what it is supposed to, however, once it has populated the
parent node, I expected the JTree to display the nodes.  This is not
happening.  Can someone please explain how I get the JTree to then display
the child nodes.

Thanks,

Alan
Re: displaying child nodes on demand
#1526
Author: Tor Iver Wilhelmsen (TeamB)
Date: Sun, 26 Oct 2003 07:51
13 lines
1441 bytes
"Alan Shiers" <ashiers@hfx.eastlink.ca> writes:

> This method does what it is supposed to, however, once it has
> populated the parent node, I expected the JTree to display the
> nodes.  This is not happening.  Can someone please explain how I get
> the JTree to then display the child nodes.

You need to tell the view. In the model, call
fireTreeStructureChanged() for the TreePath down to where they were
inserted.

(To get the fire* methods generated for you, use the BeansExpress
events tab and click TreeModel in the list of events to fire.)
Re: displaying child nodes on demand
#1527
Author: Alan Shiers
Date: Sun, 26 Oct 2003 22:06
33 lines
2387 bytes
Hi there,

Please help me along here.  JTree itself doesn't have a
fireTreeStructureChanged() method nor does my class which implements
TreeModel.  The only thing I could find in the JavaDocs at
http://java.sun.com/j2se/1.4.2/docs/api/

was an interface called TreeModelListener.  It has a declared method called
treeStructureChanged(TreeModelEvent e).  If I am to use this interface
somehow do I implement it in MyTreeModel class or do I subclass JTree and
implement it there?  I'm not quite sure how to set this up right.

Incidentally, I don't have JBuilder any more.  I'm currently just using Sun
One Studio 4.  Hope to purchase JBuilder again someday soon, but money is a
little tight right now. Just using this newsgroup for techical help.

Alan

"Tor Iver Wilhelmsen (TeamB)" <tor.wilhelmsen@ergo.no> wrote in message
news:u3cdgqvx4.fsf@ergo.no...
> "Alan Shiers" <ashiers@hfx.eastlink.ca> writes:
>
> > This method does what it is supposed to, however, once it has
> > populated the parent node, I expected the JTree to display the
> > nodes.  This is not happening.  Can someone please explain how I get
> > the JTree to then display the child nodes.
>
> You need to tell the view. In the model, call
> fireTreeStructureChanged() for the TreePath down to where they were
> inserted.
>
> (To get the fire* methods generated for you, use the BeansExpress
> events tab and click TreeModel in the list of events to fire.)
Re: displaying child nodes on demand
#1528
Author: Alan Shiers
Date: Mon, 27 Oct 2003 00:14
287 lines
10629 bytes
Hi there,

Ok, I've done a little more digging.  I finally realized that subclassing
DefaultTreeModel is what would give me access to the
fireTreeStructureChanged() method.  So I did exactly that.  Below you'll
find my entire class.  The ReceiveChildrenFromServer( ) method is the one
I'm having a challenge with.

In the class that contains the JTree I listen for tree expansion events, so
in the treeWillExpand( ) method I set a boolean flag in MyTreeModel and the
path to the node that was expanded, like so:

public void treeWillExpand(javax.swing.event.TreeExpansionEvent tee) throws
javax.swing.tree.ExpandVetoException
  {
      System.out.println("Node Expanding.");
      model.setNodeExpanding(true);
      model.setParentNodesPath(tee.getPath());
      expandingNode = (DefaultTreeNode)tee.getPath().getLastPathComponent();
  }

Everytime the getChildCount() method in MyTreeModel is called it sends a
request to the server for the childCount, also if the flag NodeExpanding is
set to true (which it would be from the treeWillExpand( ) method), then we
call RequestChildrenFromServer( ) method which in turn calls
ReceiveChildrenFromServer( ) method.

The ReceiveChildrenFromServer( ) method is definitely collecting the names
of each node as it is being transmitted by the server, however, where I've
inserted the line:

this.fireTreeStructureChanged(parent, path, childIndecies, children);

this compiles fine but I'm still not displaying the child nodes in the
JTree. Any ideas as to why?

Please advise,

Alan

import java.io.*;
import javax.swing.tree.*;
import javax.swing.event.*;
import java.awt.Cursor;
import java.util.*;

public class MyTreeModel extends DefaultTreeModel
{
    DataOutputStream output;
    Response ref;
    int RequestedChildCount;
    private boolean ReceivedChildCount;
    private boolean NodeExpanding;
    RefreshTimer timer = null;
    TreePath ParentNodesPath;


    public MyTreeModel(TreeNode node)
    {
      super(node);
    }

    public MyTreeModel(TreeNode node, boolean asksAllowsChildren)
    {
      super(node, asksAllowsChildren);
    }

    public Object getRoot(){return root;}

    public void setResponseReference(Response reference)
    {
         ref = reference;
    }

    public void setOutputStream(DataOutputStream out)
    {
      output = out;
    }

    public void insertNodeInto(DefaultTreeNode child, DefaultTreeNode
parent, int param)
    {
        parent.insert(child, param);
    }

    public int getChildCount(Object node)
    {

        System.out.println("Entering GetChildCount(Object)");
        int count = -1;
        if(node instanceof DefaultTreeNode)
        {
            count =
this.getChildCount(((DefaultTreeNode)node).getWholeServerPath());
        }
        return count;
    }

    public int getChildCount(String ParentsWholePath)
    {

      System.out.println("Entering GetChildCount(String)");
      int childCount = 0;
      try
      {
        ref.ref.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        DefaultTreeNode node = null;
        String name = "";
        output.writeInt(ref.ref.PATH);
        output.flush();
        output.writeUTF(ParentsWholePath);
        output.flush();
        output.writeInt(ref.ref.REQUEST_CHILD_COUNT);
        output.flush();
        System.out.println("waiting for response...");
        timer = new MyTimer(this);
        timer.start();
        timer.join();
        System.out.println("ReceivedChildCount: " + ReceivedChildCount +
"\nRequestedChildCount: " + RequestedChildCount);
        ReceivedChildCount = false; //reset
        if(RequestedChildCount > 0 & NodeExpanding)
        {
            RequestChildrenFromServer(ParentsWholePath);
            NodeExpanding = false; //reset
        }

ref.ref.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
      catch(InterruptedException ie){}
      catch(IOException ioe){ioe.printStackTrace();}
      catch(NullPointerException npe){npe.printStackTrace();}
      System.out.println("childCount: " + RequestedChildCount);
      return RequestedChildCount;
    }

    protected void setNodeExpanding(boolean value)
    {
       NodeExpanding = value;
    }

    protected void setReceivedChildCount(boolean value)
    {
        ReceivedChildCount = value;
    }

    protected boolean getReceivedChildCount()
    {
        return ReceivedChildCount;
    }

    protected void setRequestedChildCount(int value)
    {
        RequestedChildCount = value;
    }

    protected void setParentNodesPath(TreePath path)
    {
        ParentNodesPath = path;
    }

    protected void RequestChildrenFromServer(String ParentsWholePath)
    {
      System.out.println("Entering RequestChildrenFromServer()");
      System.out.println("ParentsWholePath: " + ParentsWholePath);
      //Request Children from server
      try
      {
        ref.ref.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        output.writeInt(ref.ref.PATH);
        output.flush();
        output.writeUTF(ParentsWholePath);
        output.flush();
        //Sending REQUEST_CHILDREN should cause a response
        //from the server: SENDING_TREE_DATA
        output.writeInt(ref.ref.REQUEST_CHILDREN);
        output.flush();

ref.ref.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));

      }
      catch(IOException ioe){ioe.printStackTrace();}
    }

    protected void ReceiveChildrenFromServer(DefaultTreeNode parent, String
ParentsWholePath, DataInputStream input)
    {
        //If we already have the child nodes for this parent node then just
return out of here.
        if(parent.getHasChildren())return;
        System.out.println("Entering ReceiveChildrenFromServer()");
        DefaultTreeNode child = null;
        int[] childIndecies = null;
        Object[] children = null;
        String name = "";
        try
        {

ref.ref.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
           //read in the number of children from the server
           int childCount = input.readInt();
           //System.out.println("Childcount: " + childCount);
           int nodeType = 0;//default
           //iterate through each of the children as they come in
          //from the server.
          childIndecies = new int[childCount];
          children = new DefaultTreeNode[childCount];
          for(int i = 0; i < childCount; i++)
          {
              name = input.readUTF(); //get the name
              System.out.println("child node: " + name);
              child = new DefaultTreeNode(name); //create a new child node

              //determine if this node is a directory
              //or a file. Empty directories are denoted
             //as having (nodeType == -1)
             nodeType = input.readInt();
             System.out.println("node type: " + nodeType);
             if(nodeType == 0)
             {
                  //Since a file is a leaf node
                  //we won't be needing to continue
                  //reading in nodes for it.
                  child.setAllowsChildren(false);
                  child.setHasChildren(false);
                  child.setLeadingPath(ParentsWholePath);
                  if(ref.ref.serverOS.equals("Windows"))
                      child.setSeparator("\\");
                  else
                      child.setSeparator("/");
              }
              else if(nodeType == -1)
              {
                  child.setAllowsChildren(true); //It's an empty directory
                  child.setHasChildren(false);
                  child.setLeadingPath(ParentsWholePath);
                  if(ref.ref.serverOS.equals("Windows"))
                      child.setSeparator("\\");
                  else
                      child.setSeparator("/");

              }
              else
              {
                  child.setAllowsChildren(true); //It's a directory
                  child.setHasChildren(true);
                  child.setLeadingPath(ParentsWholePath);
                  if(ref.ref.serverOS.equals("Windows"))
                      child.setSeparator("\\");
                  else
                      child.setSeparator("/");

              }

              insertNodeInto(child, parent, i);
              childIndecies[i] = i;
              children[i] = child;
          }
          Object[] path = new TreePath[1];
          path[0] = ParentNodesPath;
          this.fireTreeStructureChanged(parent, path, childIndecies,
children); //<<< Here is the method you recommeded I call

ref.ref.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }
      catch(IOException ioe){ioe.printStackTrace();}
      catch(NullPointerException npe){npe.printStackTrace();}

    }
}


"Tor Iver Wilhelmsen (TeamB)" <tor.wilhelmsen@ergo.no> wrote in message
news:u3cdgqvx4.fsf@ergo.no...
> "Alan Shiers" <ashiers@hfx.eastlink.ca> writes:
>
> > This method does what it is supposed to, however, once it has
> > populated the parent node, I expected the JTree to display the
> > nodes.  This is not happening.  Can someone please explain how I get
> > the JTree to then display the child nodes.
>
> You need to tell the view. In the model, call
> fireTreeStructureChanged() for the TreePath down to where they were
> inserted.
>
> (To get the fire* methods generated for you, use the BeansExpress
> events tab and click TreeModel in the list of events to fire.)
Re: displaying child nodes on demand
#1538
Author: Tad Frysinger [TeamB]
Date: Tue, 28 Oct 2003 15:07
13 lines
1546 bytes
Alan Shiers wrote:
> Hi there,
> 
Actually, the technique I have always used is nodeChanged() method of 
DefaultTreeModel. I think it will do everything you need, all you have 
to do is pass it the PARENT node where you added all the other nodes. If 
you then want to show everything expanded, you can use the normal 
methods on JTree for that.

That way you don't have to subclass anything.

-- 
Tad Frysinger [TeamB]
Re: displaying child nodes on demand
#1554
Author: Alan Shiers
Date: Fri, 31 Oct 2003 17:37
749 lines
31353 bytes
Hi there,

I tried this nodeChanged() method but the root node doesn't display the
child nodes when I expand it.  However, I discovered that if I call
nodeStructureChanged(TreeNode) which is a method in DefaultMutableTreeModel,
it in turn calls fireTreeStructureChanged(...) method.

What I have so far only works when initially getting the child nodes for the
root node when I log onto the server.  The problem comes when I try to
expand one of the root node's children.  I always wind up with the following
error message:

java.lang.ArrayIndexOutOfBoundsException: node has no children
        at
javax.swing.tree.DefaultMutableTreeNode.getChildAt(DefaultMutableTreeNode.ja
va:228)
        at
javax.swing.tree.DefaultTreeModel.getChild(DefaultTreeModel.java:156)
        at
javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeig
htLayoutCache.java:1475)
        at
javax.swing.tree.VariableHeightLayoutCache$TreeStateNode.expand(VariableHeig
htLayoutCache.java:1270)

        ....
        .... etc.


I don't understand how I can give the expanding node its children before the
model tries to access this getChildAt(...) method :(

I thought I was handling it with the if statement in my getChildCount()
method that checks whether or not a particular node in indeed expanding.  If
NodeExpanding is set to true by treeWillExpand( ) method, then the following
if structure should execute, requesting the children's names from the
server.  The server in turn sends an OK message back and starts sending the
names which I collect using my ReceiveChildrenFromServer(...) method.

if(ReceivedChildCount && NodeExpanding)
{
      NodeExpanding = false; //reset
      RequestChildrenFromServer(ParentsWholePath);
      //Set up TreeDataTimer so that we know we have a
      //response from the server.
      timer2 = new TreeDataTimer(this);
      timer2.start();
      timer2.join();

 }

The other, most annoying problem I have, is that whenever I do expand on a
node getChildCount(...) winds up getting called three times.  The only thing
I can think of is it is being called this many times because of the three
stages of mouse movements:  mouseDown, mouseClick, and mouseUp. I'm thinking
that perhaps each of these are firing an event causing the
getChildCount(...) method to also fire three times.  I need somehow to stop
it from doing that and only call the getChildCount(...) method only once.

Please look over by code below and recommend what I need to do to make it
work properly.  I'm tacking on both my Response.java and MyTreeModel.java
classes so that you can see both.  I'll edit out methods not pertinent to
the problem.  Any recommendations you have I will try.

Thanks,

Alan

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

public class Response extends Thread implements TreeWillExpandListener,
TreeModelListener
{

  clientInterface ref;
  JTree jTree1 = null;
  DataInputStream input;
  DefaultTreeNode rootNode;
  String FileSelected = "";
  String clientOS = "";
  boolean gotSendTreeDataMessage;
  long FileSize = 0;
  MyTreeModel model = null;
  DefaultTreeNode expandingNode = null;

  public Response(clientInterface reference)
  {
      ref = reference;
      clientOS = getPlatform();
      ConnectDataInputStream();

  }

  protected void ConnectDataInputStream()
  { //System.out.println("Entering ConnectDataInputStream method.");
    try
    {
      input = new DataInputStream(ref.connection1.getInputStream());
    }
    catch(IOException ioe)
    {

    }
  }

  private int contains(String st, String stringToSearchFor)
  {
    return st.indexOf(stringToSearchFor);
  }

  private String getPlatform()
  {
    String platform = System.getProperty("os.name");
    //System.out.println("Platform = " + platform);

    if(contains(platform, "Unix") > -1)
    {
      return String.valueOf(clientInterface.UNIX);
    }
    else if(contains(platform, "Linux") > -1)
    {
      return String.valueOf(clientInterface.LINUX);
    }
    return String.valueOf(clientInterface.WINDOWS);
  }


  /**
   * As this class extends class Thread, it is required we overwrite
   * the run() method.
   */
  public void run()
  {
      int connected = 0;
      //First let's try to connect to the server.
      try
      {

         //We need to send our username and password
         //before the server will return our home directory.
         String out = ref.username + ":" + ref.password + ":" + clientOS;
         //System.out.println("UserName&Password = " + out);
         ref.RequestOut.output.writeUTF(out);
         ref.RequestOut.output.flush();

         while(true) //Wait for a proper answer from the server.
         {
            connected = input.readInt();
            //System.out.println(connected);
            if(connected == ref.ACCEPTED || connected == ref.FAILED ||
connected == ref.PASSWORD_INVALID)
              break;
         }
         if (connected == ref.ACCEPTED)
         {
            //Get the users' home directory rootPath from the server
            ref.rootPath = input.readUTF();
            //System.out.println(ref.rootPath);
            int OS = input.readInt();
            if(OS == ref.WINDOWS)
              ref.serverOS = "Windows";
            else if(OS == ref.UNIX)
              ref.serverOS = "Unix";
            else
              ref.serverOS = "Linux";
            ref.setTitle(ref.getTitle() + " - Connection successful.");
            ref.jLabel1.setText("Status: ");
            ref.connected = true;
            //extract the name of the last directory name
     //from ref.rootPath. and populate JTree with one root Node
     String root = getNodeName(ref.rootPath);
            populateTree(root);
            //reset icon and text for connection labels
            ref.imageLabel.setIcon(ref.blank);
            ref.textLabel.setText("");
            //Enable menus
            ref.jMenuItem23.setEnabled(true); //Directories/MkDir
            ref.jMenuItem24.setEnabled(true); //Directories/RmDir
            ref.jMenuItem25.setEnabled(true); //Upload/Graphic Files
            ref.jMenuItem26.setEnabled(true); //Upload/Flash Files
            ref.jMenuItem27.setEnabled(true); //Upload/Applet Files
            ref.jMenuItem28.setEnabled(true); //Upload/HTML Files
            ref.jMenuItem29.setEnabled(true); //Upload/Database Files
            ref.jMenuItem30.setEnabled(true); //Upload/Sound Files
            ref.jMenuItem31.setEnabled(true); //Upload/Compressed Files
            /*This try block will attempt to receive string info from the
server
            //in order that it can be used to reconstruct the directory
tree.
            try
            {
                //This could take a while depending on the users connection
speed,
                //so let him know he may have to wait a bit.
                ref.jLabel1.setText("Status: Please wait while the server
provides a directory tree.");
                //run the timer to check after 15 seconds if
gotSendTreeDataMessage
                //got set to true or not.
                timer.setThreadSuspended(false);
                connected = input.readInt();
                if(connected == ref.SENDING_TREE_DATA)
                {
                  gotSendTreeDataMessage = true;
    //extract the name of the last directory name
    //from ref.rootPath.
    String root = getNodeName(ref.rootPath);
                  populateTree(root);
                  //reset icon and text for connection labels
                  ref.imageLabel.setIcon(ref.blank);
                  ref.textLabel.setText("");
                  //Enable menus
                  ref.jMenuItem23.setEnabled(true); //Directories/MkDir
                  ref.jMenuItem24.setEnabled(true); //Directories/RmDir
                  ref.jMenuItem25.setEnabled(true); //Upload/Graphic Files
                  ref.jMenuItem26.setEnabled(true); //Upload/Flash Files
                  ref.jMenuItem27.setEnabled(true); //Upload/Applet Files
                  ref.jMenuItem28.setEnabled(true); //Upload/HTML Files
                  ref.jMenuItem29.setEnabled(true); //Upload/Database Files
                  ref.jMenuItem30.setEnabled(true); //Upload/Sound Files
                  ref.jMenuItem31.setEnabled(true); //Upload/Compressed
Files
                }

            }
            catch(NullPointerException npe)
            {
              //If we come in here it's only because there simply is no
connection
              //to the server application.
              ref.jLabel1.setText("Status: NullPointerException in
Response.run() method.");
              //reset icon and text for connection labels
              ref.imageLabel.setIcon(ref.blank);
              ref.textLabel.setText("");
              disableMenus(true);
              //System.out.println("NullPointerException during
input.readUTF() procedure.");
               npe.printStackTrace();
            }
             */
         }
         else if(connected == ref.FAILED)
         {
            ref.disconnect("Status: Unable to connect to server. Please
ensure your username is correct.");
            //reset icon and text for connection labels
            ref.imageLabel.setIcon(ref.blank);
            ref.textLabel.setText("");
            ref.connected = false;
            return;
         }
         else if(connected == ref.PASSWORD_INVALID)
         {
           ref.disconnect("Status: Unable to connect to server. Please
ensure your password is correct.");
           //reset icon and text for connection labels
           ref.imageLabel.setIcon(ref.blank);
           ref.textLabel.setText("");
           ref.connected = false;
           return;
         }
      }
      catch(NullPointerException npe)
      {
         //If we come in here it's only because there simply is no
connection
         //to the server application.
         ref.jLabel1.setText("Status: NullPointerException in Response.run()
method.");
         //reset icon and text for connection labels
         ref.connected = false;
         ref.imageLabel.setIcon(ref.blank);
         ref.textLabel.setText("");
         //System.out.println("outer NullPointerException while attempting
to connect.");
         input = null; //reset
         disableMenus(true);
         npe.printStackTrace();
         return;
      }
      catch(IOException e)
      {
         ref.jLabel1.setText("Status: IOException in Response.run()
method.");
         JOptionPane.showMessageDialog(ref, "IOException in Response.run()
method.\n" +
                                       "This is caused either by a loss of
connection\n" +
                                       "to the server, or there is
interference\n" +
                                       "facilitated by other Parental
Internet\n" +
                                       "Filtering software running on your
workstation.\n" +
                                       "If this is the case, disable the
filtering\n" +
                                       "software, then attempt to reconnect
to the server.");
         //reset icon and text for connection labels
         ref.connected = false;
         ref.imageLabel.setIcon(ref.blank);
         ref.textLabel.setText("");
         disableMenus(true);
         //e.printStackTrace();
         //There may still be a connection to the server,
         //However, there is sometimes interference due
         //to Internet Filtering Software. So we'll send
         //a quit message back to the server and allow the user
         //to attempt a reconnect.
         try{
         ref.RequestOut.output.writeInt(ref.QUIT);
         ref.RequestOut.output.flush();
         }catch(IOException ioe){}
         return;
      }
      catch(Exception ex)
      {
         ref.jLabel1.setText("Status: Exception in Response.run() method.");
         //reset icon and text for connection labels
         ref.connected = false;
         ref.imageLabel.setIcon(ref.blank);
         ref.textLabel.setText("");
         ex.printStackTrace();
         disableMenus(true);
         return;
      }
      //Now handle Responses from the server
      ref.jLabel1.setText("Status:");
      ListenForResponses();


  }

  private void ListenForResponses()
  {
      int connected = 0;
      while(true)
      {
         try
         {
            //System.out.println("Reading next response...");
            connected = input.readInt();
            //System.out.println("connected: " + connected);
            if(connected == ref.DOWNLOAD_FILE)
            {
               FileSize = input.readLong();
               receiveFile();
            }
            else if(connected == ref.ERROR_SAVING)
            {
               ref.jLabel1.setText("Status: Error Saving " + ref.FileOpen);
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
               ref.isDirty = true;
            }
            else if(connected == ref.ALLOTTED_WEBSPACE_USED_UP)
            {
              ref.imageLabel.setIcon(ref.blank);
              ref.textLabel.setText("");
              ref.RequestOut.WebSpaceFull = true;
              JOptionPane.showMessageDialog(ref, "If you are attempting to
save/upload a new file, or upload multiple files,\n" +
                                                 "you do not have enough
allotted web space to accomodate the file(s).\n" +
                                                 "If you require more space,
contact your System Administrator.", "Message", JOptionPane.PLAIN_MESSAGE);
              ref.jLabel1.setText("Status:");
            }
            else if(connected == ref.WEBSPACE_NOT_USED_UP)
            { //System.out.println("Got the go ahead.");
              ref.RequestOut.proceed = true;
            }
            else if(connected == ref.SAVE_SUCCESSFUL)
            {
               //we only get this if the user has used the File/SaveAs menu.
               refreshTree();
               ref.jLabel1.setText("Status: Save Successful");
               ref.isDirty = false;
            }
            else if(connected == ref.SAVE_UNSUCCESSFUL)
            {
               ref.jLabel1.setText("Status: Save Not Successful");
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.UPLOAD_SUCCESSFUL)
            {  //System.out.println("Got Upload Successful");
               refreshTree();
               ref.jLabel1.setText("Status: Data Transfer Successful");
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.UPLOAD_UNSUCCESSFUL)
            {
               ref.jLabel1.setText("Status: Data Transfer Not Successful");
               JOptionPane.showMessageDialog(ref, "The file(s) uploaded
were\n" +
                                                  "unsuccessful in their
completion.",
                                                  "Upload Status:",

JOptionPane.INFORMATION_MESSAGE);
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.UPLOAD_UNSUCCESSFUL_SECURITY_EXCEPTION)
            {
               ref.jLabel1.setText("Status: Data Transfer Not Successful,
Security Exception");
               JOptionPane.showMessageDialog(ref, "The file(s) uploaded
were\n" +
                                                  "unsuccessful in their
completion.\n" +
                                                  "There was a problem
regarding security\n" +
"access. See your System Administrator for help.",
                                                  "Upload Status:",

JOptionPane.INFORMATION_MESSAGE);
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.DIRECTORY_CREATION_SUCCESSFUL)
            {
               refreshTree();
               ref.jLabel1.setText("Status: Directory creation successful");
            }
            else if(connected == ref.DIRECTORY_CREATION_UNSUCCESSFUL)
            {
             ref.jLabel1.setText("Status: Directory creation not
successful");
             ref.imageLabel.setIcon(ref.blank);
             ref.textLabel.setText("");
            }
            else if(connected == ref.DIRECTORY_DELETION_SUCCESSFUL)
            {
               refreshTree();
               ref.jLabel1.setText("Status: Directory Deletion Successful");
            }
            else if(connected == ref.DIRECTORY_DELETION_UNSUCCESSFUL)
            {
              ref.jLabel1.setText("Status: Directory Deletion Not
Successful");
              ref.imageLabel.setIcon(ref.blank);
              ref.textLabel.setText("");
            }
            else if(connected == ref.FILE_NOT_FOUND_EXCEPTION)
            {
               ref.jLabel1.setText("Status: FileNotFoundException. Perhaps
the node is really an empty directory?");
               ref.isDirty = false;
               ref.setTitle("JText Editor - Connection successful.");
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.SERVER_RESET)
            {
               ref.jLabel1.setText("Status: The main server is being
manually reset. You have been disconnected.");
               ref.setTitle("JText Editor");
               disableMenus(true);
            }
            else if(connected == ref.SERVER_SHUTTING_DOWN)
            {
               ref.jLabel1.setText("Status: The main server is being turned
off. You have been disconnected.");
               ref.setTitle("JText Editor");
               disableMenus(true);
            }
            else if(connected == ref.SENDING_TREE_DATA)
            {
               System.out.println("Received message: SendingTreeData");
               model.setGotTreeData(true);
               model.ReceiveChildrenFromServer(expandingNode,
expandingNode.getWholeServerPath(), input);
               //expandingNode = null;//reset
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.SENDING_CHILDCOUNT)
            {
               System.out.println("Received message: SendingChildCount");
               model.setRequestedChildCount(input.readInt());
               model.setReceivedChildCount(true);
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.PASSWORD_CHANGE_SUCCESSFUL)
            {
              ref.jLabel1.setText("Status: Password changed successfully.");
              ref.imageLabel.setIcon(ref.blank);
              ref.textLabel.setText("");
            }
            else if(connected == ref.PASSWORD_CHANGE_NOT_SUCCESSFUL)
            {
              ref.jLabel1.setText("Status: Password change not successful.
See your administrator for help.");
              ref.imageLabel.setIcon(ref.blank);
              ref.textLabel.setText("");
            }
            else if(connected == ref.FILE_DELETION_SUCCESSFUL)
            {
               ref.jLabel1.setText("Status: File Deleted Successfully.");
               //Now, refresh the tree.
               refreshTree();
            }
            else if(connected == ref.FILE_DELETION_UNSUCCESSFUL)
            {
               ref.jLabel1.setText("Status: File Deletion Not Successful.");
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.FILE_RENAME_SUCCESSFUL)
            {
               ref.jLabel1.setText("Status: File Rename Successful.");
               //Now, refresh the tree.
               refreshTree();
            }
            else if(connected == ref.FILE_RENAME_UNSUCCESSFUL)
            {
               ref.jLabel1.setText("Status: File Rename Not Successful.");
               ref.imageLabel.setIcon(ref.blank);
               ref.textLabel.setText("");
            }
            else if(connected == ref.FILE_CONTENTS)
            {
               //System.out.println("Received queue from server for file
contents.");
               FileSize = input.readLong();
               displayTextFile();
               ref.isDirty = false;

               //System.out.println("Finished receiving file");
            }

       }
       catch(EOFException eof){break;}
       catch(NullPointerException npex)
       {
          //If we come in here it's only because there simply is no
connection
          //to the server application.
          ref.jLabel1.setText("NullPointerException in run() method of
communicationPort.");
          npex.printStackTrace();
          ref.imageLabel.setIcon(ref.blank);
          //System.out.println("NullPointerException during input.readUTF()
procedure of communicationPort.");
          disableMenus(true);
          break;
       }
       catch(IOException e)
       {
          ref.jLabel1.setText("Status: Client disconnected.");
          ref.imageLabel.setIcon(ref.blank);
          disableMenus(true);
          //e.printStackTrace();
          break;
       }
       catch(Exception exc)
       {
          ref.jLabel1.setText("Status: Client disconnected.");
          ref.imageLabel.setIcon(ref.blank);
          disableMenus(true);
          //exc.printStackTrace();
          break;
       }
     }
  }


  /**
   * This function creates an instance of a JTree object and populates
   * it with the data sent by Directory Administrator.
   */
  protected void populateTree(String NodeName)
  {
    //System.out.println("Entering populatTree() method");
    //This could take a while, so change the cursor icon
    //ref.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
    try
    {
        String separator = "";
        if(ref.serverOS.equals("Windows"))
            separator = "\\";
        else
            separator = "/";
        rootNode = new DefaultTreeNode(NodeName, true, separator);
        String rootPath = getLeadingPath(ref.rootPath);
        rootNode.setLeadingPath(rootPath);
        //insert child nodes
        model = new MyTreeModel(rootNode);
        model.setOutputStream(ref.RequestOut.output);
        model.setResponseReference(this);
        model.addTreeModelListener(this);
        //model.setInputStream(input);
        //model.ReceiveChildrenFromServer(rootNode,
rootNode.getWholeServerPath());
        jTree1 = new JTree(model);
        jTree1.setRootVisible(true);
        jTree1.setShowsRootHandles(true);
        jTree1.collapseRow(0);
        MouseListener popupListener = new PopupListener(ref);
        jTree1.addMouseListener(popupListener);

        //Listen to our own expand/collapse events to keep the labels in
sync
        jTree1.addTreeWillExpandListener(this);

    }
    catch(Exception e){System.out.println("Exception in populateTree()
method"); e.printStackTrace();return;}


    jTree1.addTreeSelectionListener(new TreeSelectionListener()
    {
      public void valueChanged(TreeSelectionEvent tse)
      {
        System.out.println("valueChanged");
        DefaultTreeNode temp;
        if(ref.connected)
        {
          try
          {
              TreePath tp = tse.getNewLeadSelectionPath();
              /**
              * SelectedFilePath IS VERY IMPORTANT!
              * It will contain the complete path to the file
              * clicked on by the user's mouse.
              * We can then use it to actually open the file on the server
side.
              */
              ref.SelectedFilePath = ref.getWholePath(tp.toString());
              //SelectedTreePath = tp.toString();
              //System.out.println(ref.FileOpenPath);
              temp = (DefaultTreeNode)tp.getLastPathComponent();
              String st = tp.getLastPathComponent().toString();
              ref.SelectedFile = st;
              FileSelected = st;
              ref.jLabel1.setText("Selected: " + st);

              //We need to toggle the File/Open, Save, and SaveAs menus from
enabled to disabled
              //depending on what the user is selecting.  We don't want
              //the user trying to open a directory.  They should only
              //be allowed to open and save leaf objects (files).
              if(temp.isLeaf())
              {
                //System.out.println("This node is a leaf.");
                //Enable menus
                ref.jMenuItem1.setEnabled(true); //File/New
                ref.jMenuItem2.setEnabled(true); //File/New with HTML Tags
                ref.jMenuItem3.setEnabled(true); //File/Open
                ref.popopenFile.setEnabled(true); //File/Open
                if(ref.FileOpen.equals("")) //nothing has been opened
                {
                  ref.jMenuItem4.setEnabled(false); //File/Save
                  ref.Save.setEnabled(false); //File/Save button
                  ref.jMenuItem5.setEnabled(false); //File/SaveAs
                  ref.popsaveFile.setEnabled(false);
                  ref.popsaveFileAs.setEnabled(false);
                }
                else if(ref.FileOpen.equals(ref.SelectedFile)) //the
selected file and the open file are the same
                {
                  ref.jMenuItem4.setEnabled(true); //File/Save
                  ref.Save.setEnabled(true); //File/Save Button
                  ref.jMenuItem5.setEnabled(true); //File/SaveAs
                  ref.popsaveFile.setEnabled(true);
                  ref.popsaveFileAs.setEnabled(true);
                }
                else //the selected file and the open file are not the same
                {
                  ref.jMenuItem4.setEnabled(false); //File/Save
                  ref.Save.setEnabled(false); //File/Save Button
                  ref.jMenuItem5.setEnabled(false); //File/SaveAs
                  ref.popsaveFile.setEnabled(false);
                  ref.popsaveFileAs.setEnabled(false);
                }
                ref.jMenuItem6.setEnabled(true); //File/Delete
                ref.jMenuItem7.setEnabled(true); //File/Rename
                ref.jMenuItem8.setEnabled(true); //File/Download
                ref.jMenuItem9.setEnabled(true); //File/Print
                //enable popup menus
                ref.popdeleteFile.setEnabled(true); //File/Delete
                ref.poprenameFile.setEnabled(true); //File/Rename
                ref.popdownloadFile.setEnabled(true); //File/Download

                //Enable buttons
                ref.New.setEnabled(true);
                ref.Open.setEnabled(true);
                ref.Print.setEnabled(true);
                ref.Tags.setEnabled(true);
              }
              else
              {
                //System.out.println("This node is a not a leaf.");
                //Disable menus
                ref.jMenuItem1.setEnabled(false); //File/New
                ref.jMenuItem2.setEnabled(false); //File/New with HTML
                ref.jMenuItem3.setEnabled(false); //File/Open
                ref.jMenuItem4.setEnabled(false); //File/Save
                ref.jMenuItem5.setEnabled(false); //File/SaveAs
                ref.jMenuItem6.setEnabled(false); //File/Delete
                ref.jMenuItem7.setEnabled(false); //File/Rename
                ref.jMenuItem8.setEnabled(false); //File/Download
                ref.jMenuItem9.setEnabled(false); //File/Print
                //Disable popup menus
                ref.popopenFile.setEnabled(false); //File/Open
                ref.popsaveFile.setEnabled(false); //File/Save
                ref.popsaveFileAs.setEnabled(false); //File/SaveAs
                ref.popdeleteFile.setEnabled(false); //File/Delete
                ref.poprenameFile.setEnabled(false); //File/Rename
                ref.popdownloadFile.setEnabled(false); //File/Download
                //From -7100215599787870266
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,76fdbd0f345b0d02
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2003-10-22 10:15:38 PST
Date: Wed, 22 Oct 2003 11:08:12 -0600
From: "Tad Frysinger [TeamB]" <tfrysinger@earthlink.net>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624
X-Accept-Language: en-us, en
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: Antialiasing
References: <pan.2003.10.09.00.13.58.656411@mt.net.mk>
In-Reply-To: <pan.2003.10.09.00.13.58.656411@mt.net.mk>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 206.61.185.113
Message-ID: <3f96b98c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1066842508 206.61.185.113 (22 Oct 2003 10:08:28 -0700)
Lines: 12
Path: archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
Xref: archiver1.google.com borland.public.jbuilder.java.swing:57

Aleksandar Pecanov wrote:

> Is it possible to set the default value of RenderingHints.KEY_ANTIALIASING
> to on?
Doing a quick search yields no apparant way to do this. It doesn't 
appear that there is any setting of defaults within the Graphics sources 
either. I think you are stuck with subclassing or overriding each 
component affected where you need this behavior.

-- 
Tad Frysinger [TeamB]
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads