Results 1 to 2 of 2
  1. #1
    Digital Larry is offline Member
    Join Date
    Mar 2013
    Rep Power

    Default Getting stuck developing CAD program

    I am developing a DSP CAD program in Java/AWT/Swing.

    The idea is that small bits of DSP code are represented by a little block with signal input and output pins, and control inputs. Then there are
    also other blocks that don't process signal, but they just do conversions on control signals. All fine so far.

    The application so far is based on a JFrame and some JPanels and JToolbars inside. If there are some variables that more than one JPanel needs to access, then they live in the JFrame. All that's fine too.

    All of my mouse interaction is in a custom class which extends JPanel. Depending on the drawing mode (which is set by JButtons in a JToolbar), the Mouse Events will do certain things.

    For example, if we are in "Add Block" mode, then a mouse click will add a new block to the ArrayList, and draw it on the JPanel (actually it calls repaint(). The paintComponent() method actually iterates through the ArrayList of all blocks which were added and draws them at the location they were added). If we're in "Delete" mode, then a mouse click scans through the list and checks to see if we hit the visible "handle" of a block in the ArrayList and if so, it gets deleted. In "move" mode, we pick up the block and drag it around until we set it down with another click.

    Each DSP functional block has a number of pins for connections, which are added dynamically during the constructor for a specific type of DSP function. The base class for these is called "SpinCADBlock" which is simply a generic block with no pins, but you can still add, delete and move them.

    Now here's where I'm getting stuck. When I want to connect one block to another, I select "Connect" mode. Then, when I click with the mouse, that handler scans through all blocks and for each block scans through each pin. If it finds a pin at the same location as the mouse pointer, then you break out of that loop and variables "currentBlock" and "currentPin" are used - right now all I'm doing is changing the color of the pin (it's just a little circle). What I WANT to do is attach a line to the pin at one end, and to the mouse pointer at the other end, and have that line move and stretch, attached at one fixed end to the block/pin. Now when I am drawing or moving the blocks, that's not a problem, because I have added all of them to an ArrayList, and paintComponent() just goes through and redraws all of them. But the "line" is not really a "thing" in the design yet and I can't figure out where/how to draw it.

    Ultimately the "lines" will represent connections between Pins, and the only important thing as far as the underlying data (DSP code) goes is for an "input" pin to know what "output" it is connected to. As an output could go several places, the output pins don't know and don't care where they are connected. Again, here I am sort of confused as to the best approach. I was thinking of having a separate "Connectors" class but that doesn't seem warranted.

    Each DSP block has a location and an ArrayList of Pins. I can distinguish Input Pins from Output Pins. So in the case of an Input Pin, I guess I should add "sourceBlock" and "sourcePin" variables. There's also the possibility that an Input Pin is not connected to anything, in which case the DSP code needs to use a user-supplied fixed value instead.

    Bottom line, I need some suggestions about:
    1) Drawing the connection line when only one end is attached to a Pin (the other end is still on the mouse) and
    2) Finding a way to connect all the connections visually once they are made. As I am iterating through the ArrayList of blocks, I would like to make sure they are ordered properly so that sourceBlocks and sourcePins have already been iterated by the time an inputPin which needs them is iterated.

    I hope this makes sense.


  2. #2
    Digital Larry is offline Member
    Join Date
    Mar 2013
    Rep Power

    Default Re: Getting stuck developing CAD program

    Well it was not as hard as I thought. I just declared a Line2D in my extended panel class.

    I guess I was confused or ignorant about the Model-View-Controller architecture. I am really working primarily on the "View" right now and having an extra Line2D hanging around waiting for me to use it is no big deal, even if there is no corresponding bit in the data model. I just make it "null" when I don't want it drawn. Drawing the line is part of the "paintComponent" method.

Similar Threads

  1. Stuck on a banking program
    By Ortlep in forum New To Java
    Replies: 2
    Last Post: 12-14-2011, 07:37 PM
  2. Stuck - simple program
    By dirtycash in forum New To Java
    Replies: 4
    Last Post: 11-24-2008, 07:44 PM
  3. Really Stuck on how to Start this program
    By random0munky in forum New To Java
    Replies: 4
    Last Post: 10-29-2008, 08:57 AM
  4. Replies: 8
    Last Post: 08-26-2008, 04:50 AM
  5. FireSimulation Program, got stuck with a bug...
    By riz618 in forum New To Java
    Replies: 5
    Last Post: 01-28-2008, 03:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts