Back to index

moin  1.9.0~rc2
Public Member Functions | Static Public Attributes | Protected Member Functions | Static Package Attributes | Private Member Functions | Private Attributes | Static Private Attributes
CH.ifa.draw.applet.DrawApplet Class Reference

DrawApplication defines a standard presentation for a drawing editor that is run as an applet. More...

Inheritance diagram for CH.ifa.draw.applet.DrawApplet:
Inheritance graph
[legend]
Collaboration diagram for CH.ifa.draw.applet.DrawApplet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void init ()
 Initializes the applet and creates its contents.
void paletteUserSelected (PaletteButton button)
 Handles a user selection in the palette.
void paletteUserOver (PaletteButton button, boolean inside)
 Handles when the mouse enters or leaves a palette button.
Drawing drawing ()
 Gets the current drawing.
Tool tool ()
 Gets the current tool.
DrawingView view ()
 Gets the current drawing view.
void toolDone ()
 Sets the default tool of the editor.
void selectionChanged (DrawingView view)
 Handles a change of the current selection.

Static Public Attributes

static final String IMAGES = "images/"

Protected Member Functions

Panel createAttributesPanel ()
 Creates the attributes panel.
void createAttributeChoices (Panel panel)
 Creates the attribute choices.
Choice createColorChoice (String attribute)
 Creates the color choice for the given attribute.
Choice createFontChoice ()
 Creates the font choice.
Panel createButtonPanel ()
 Creates the buttons panel.
void createButtons (Panel panel)
 Creates the buttons shown in the buttons panel.
Panel createToolPalette ()
 Creates the tools palette.
void createTools (Panel palette)
 Creates the tools.
Tool createSelectionTool ()
 Creates the selection tool used in this editor.
ToolButton createToolButton (String iconName, String toolName, Tool tool)
 Creates a tool button with the given image, tool, and text.
Drawing createDrawing ()
 Creates the drawing used in this application.
StandardDrawingView createDrawingView ()
 Creates the drawing view used in this application.
void loadDrawing (String param)
void setSimpleDisplayUpdate ()
void setBufferedDisplayUpdate ()
void showHelp ()
 Shows a help page for the applet.

Static Package Attributes

static String fgUntitled = "untitled"

Private Member Functions

void initDrawing ()
void setTool (Tool t, String name)
void setSelected (ToolButton button)
void readDrawing (String filename)
void readFromStorableInput (String filename)
void readFromObjectInput (String filename)
String guessType (String file)
void setupAttributes ()
void startSleeper ()
 *** netscape browser work around ***
void stopSleeper ()

Private Attributes

transient Drawing fDrawing
transient Tool fTool
transient StandardDrawingView fView
transient ToolButton fDefaultToolButton
transient ToolButton fSelectedToolButton
transient boolean fSimpleUpdate
transient Button fUpdateButton
transient Choice fFrameColor
transient Choice fFillColor
transient Choice fArrowChoice
transient Choice fFontChoice
transient Thread fSleeper
Iconkit fIconkit

Static Private Attributes

static final String fgDrawPath = "/CH/ifa/draw/"

Detailed Description

DrawApplication defines a standard presentation for a drawing editor that is run as an applet.

The presentation is customized in subclasses.

Supported applet parameters:
DRAWINGS: a blank separated list of drawing names that is shown in the drawings choice.

Definition at line 29 of file DrawApplet.java.


Member Function Documentation

void CH.ifa.draw.applet.DrawApplet.createAttributeChoices ( Panel  panel) [inline, protected]

Creates the attribute choices.

Override to add additional choices.

Definition at line 113 of file DrawApplet.java.

                                                       {
        panel.add(new Label("Fill"));
        fFillColor = createColorChoice("FillColor");
        panel.add(fFillColor);

        //panel.add(new Label("Text"));
        //fTextColor = createColorChoice("TextColor");
        //panel.add(fTextColor);

        panel.add(new Label("Pen"));
        fFrameColor = createColorChoice("FrameColor");
        panel.add(fFrameColor);

        panel.add(new Label("Arrow"));
        CommandChoice choice = new CommandChoice();
        fArrowChoice = choice;
        choice.addItem(new ChangeAttributeCommand("none",     "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_NONE),  fView));
        choice.addItem(new ChangeAttributeCommand("at Start", "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_START), fView));
        choice.addItem(new ChangeAttributeCommand("at End",   "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_END),   fView));
        choice.addItem(new ChangeAttributeCommand("at Both",  "ArrowMode", new Integer(PolyLineFigure.ARROW_TIP_BOTH),  fView));
        panel.add(fArrowChoice);

        panel.add(new Label("Font"));
        fFontChoice = createFontChoice();
        panel.add(fFontChoice);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Creates the attributes panel.

Definition at line 103 of file DrawApplet.java.

                                            {
        Panel panel = new Panel();
        panel.setLayout(new PaletteLayout(2, new Point(2,2), false));
        return panel;
    }

Here is the caller graph for this function:

Panel CH.ifa.draw.applet.DrawApplet.createButtonPanel ( ) [inline, protected]

Creates the buttons panel.

Definition at line 172 of file DrawApplet.java.

                                        {
        Panel panel = new Panel();
        panel.setLayout(new PaletteLayout(2, new Point(2,2), false));
        return panel;
    }

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.createButtons ( Panel  panel) [inline, protected]

Creates the buttons shown in the buttons panel.

Override to add additional buttons.

Parameters:
panelthe buttons panel.

Definition at line 183 of file DrawApplet.java.

                                              {
        panel.add(new Filler(24,20));

        Choice drawingChoice = new Choice();
        drawingChoice.addItem(fgUntitled);

           String param = getParameter("DRAWINGS");
           if (param == null)
               param = "";
              StringTokenizer st = new StringTokenizer(param);
        while (st.hasMoreTokens())
            drawingChoice.addItem(st.nextToken());
        // offer choice only if more than one
        if (drawingChoice.getItemCount() > 1)
            panel.add(drawingChoice);
        else
            panel.add(new Label(fgUntitled));

              drawingChoice.addItemListener(
                  new ItemListener() {
                      public void itemStateChanged(ItemEvent e) {
                          if (e.getStateChange() == ItemEvent.SELECTED) {
                              loadDrawing((String)e.getItem());
                          }
                      }
                  }
              );

        panel.add(new Filler(6,20));

        Button button;
        button = new CommandButton(new DeleteCommand("Delete", fView));
        panel.add(button);

        button = new CommandButton(new DuplicateCommand("Duplicate", fView));
        panel.add(button);

        button = new CommandButton(new GroupCommand("Group", fView));
        panel.add(button);

        button = new CommandButton(new UngroupCommand("Ungroup", fView));
        panel.add(button);

        button = new Button("Help");
              button.addActionListener(
                  new ActionListener() {
                      public void actionPerformed(ActionEvent event) {
                          showHelp();
                      }
                  }
              );
        panel.add(button);

        fUpdateButton = new Button("Simple Update");
              fUpdateButton.addActionListener(
                  new ActionListener() {
                      public void actionPerformed(ActionEvent event) {
                    if (fSimpleUpdate)
                        setBufferedDisplayUpdate();
                    else
                        setSimpleDisplayUpdate();
                      }
                  }
              );

        // panel.add(fUpdateButton); // not shown currently
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Choice CH.ifa.draw.applet.DrawApplet.createColorChoice ( String  attribute) [inline, protected]

Creates the color choice for the given attribute.

Definition at line 143 of file DrawApplet.java.

                                                         {
        CommandChoice choice = new CommandChoice();
       ColorMap map = ColorMap.getColorMap();
        for (int i=0; i < map.size(); i++)
            choice.addItem(
                new ChangeAttributeCommand(
                    map.name(i), attribute,
                    map.color(i),
                    fView
                )
            );
        return choice;
    }

Here is the caller graph for this function:

Drawing CH.ifa.draw.applet.DrawApplet.createDrawing ( ) [inline, protected]

Creates the drawing used in this application.

You need to override this method to use a Drawing subclass in your application. By default a standard Drawing is returned.

Definition at line 294 of file DrawApplet.java.

                                      {
        return new StandardDrawing();
    }

Here is the caller graph for this function:

StandardDrawingView CH.ifa.draw.applet.DrawApplet.createDrawingView ( ) [inline, protected]

Creates the drawing view used in this application.

You need to override this method to use a DrawingView subclass in your application. By default a standard DrawingView is returned.

Definition at line 304 of file DrawApplet.java.

                                                      {
        return new StandardDrawingView(this, 410, 370);
    }

Here is the caller graph for this function:

Choice CH.ifa.draw.applet.DrawApplet.createFontChoice ( ) [inline, protected]

Creates the font choice.

The choice is filled with all the fonts supported by the toolkit.

Definition at line 161 of file DrawApplet.java.

                                        {
        CommandChoice choice = new CommandChoice();
        String fonts[] = Toolkit.getDefaultToolkit().getFontList();
        for (int i = 0; i < fonts.length; i++)
            choice.addItem(new ChangeAttributeCommand(fonts[i], "FontName", fonts[i],  fView));
        return choice;
    }

Here is the caller graph for this function:

Creates the selection tool used in this editor.

Override to use a custom selection tool.

Definition at line 277 of file DrawApplet.java.

                                         {
        return new SelectionTool(view());
    }

Here is the call graph for this function:

Here is the caller graph for this function:

ToolButton CH.ifa.draw.applet.DrawApplet.createToolButton ( String  iconName,
String  toolName,
Tool  tool 
) [inline, protected]

Creates a tool button with the given image, tool, and text.

Definition at line 284 of file DrawApplet.java.

                                                                                       {
        return new ToolButton(this, iconName, toolName, tool);
    }

Here is the caller graph for this function:

Panel CH.ifa.draw.applet.DrawApplet.createToolPalette ( ) [inline, protected]

Creates the tools palette.

Definition at line 254 of file DrawApplet.java.

                                        {
        Panel palette = new Panel();
        palette.setLayout(new PaletteLayout(2,new Point(2,2)));
        return palette;
    }

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.createTools ( Panel  palette) [inline, protected]

Creates the tools.

By default only the selection tool is added. Override this method to add additional tools. Call the inherited method to include the selection tool.

Parameters:
palettethe palette where the tools are added.

Definition at line 266 of file DrawApplet.java.

                                              {
        Tool tool = createSelectionTool();

        fDefaultToolButton = createToolButton(IMAGES+"SEL", "Selection Tool", tool);
        palette.add(fDefaultToolButton);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Gets the current drawing.

See also:
DrawingEditor

Definition at line 333 of file DrawApplet.java.

                             {
        return fDrawing;
    }
String CH.ifa.draw.applet.DrawApplet.guessType ( String  file) [inline, private]

Definition at line 450 of file DrawApplet.java.

                                          {
        if (file.endsWith(".draw"))
            return "storable";
        if (file.endsWith(".ser"))
            return "serialized";
        return "unknown";
    }

Here is the caller graph for this function:

Initializes the applet and creates its contents.

Definition at line 60 of file DrawApplet.java.

                       {
        fIconkit = new Iconkit(this);

              setLayout(new BorderLayout());

        fView = createDrawingView();

        Panel attributes = createAttributesPanel();
        createAttributeChoices(attributes);
        add("North", attributes);

        Panel toolPanel = createToolPalette();
        createTools(toolPanel);
        add("West", toolPanel);

        add("Center", fView);
        Panel buttonPalette = createButtonPanel();
        createButtons(buttonPalette);
        add("South", buttonPalette);

        initDrawing();
        setBufferedDisplayUpdate();
        setupAttributes();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.initDrawing ( ) [inline, private]

Definition at line 371 of file DrawApplet.java.

                               {
        fDrawing = createDrawing();
        fView.setDrawing(fDrawing);
        toolDone();
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.loadDrawing ( String  param) [inline, protected]

Definition at line 395 of file DrawApplet.java.

                                             {
        if (param == fgUntitled) {
            fDrawing.release();
            initDrawing();
            return;
        }

        String filename = getParameter(param);
        if (filename != null)
            readDrawing(filename);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.paletteUserOver ( PaletteButton  button,
boolean  inside 
) [inline]

Handles when the mouse enters or leaves a palette button.

See also:
PaletteListener

Definition at line 322 of file DrawApplet.java.

                                                                      {
        if (inside)
            showStatus(((ToolButton) button).name());
        else
            showStatus(fSelectedToolButton.name());
    }
void CH.ifa.draw.applet.DrawApplet.paletteUserSelected ( PaletteButton  button) [inline]

Handles a user selection in the palette.

See also:
PaletteListener

Definition at line 312 of file DrawApplet.java.

                                                          {
        ToolButton toolButton = (ToolButton) button;
        setTool(toolButton.tool(), toolButton.name());
        setSelected(toolButton);
    }

Here is the call graph for this function:

void CH.ifa.draw.applet.DrawApplet.readDrawing ( String  filename) [inline, private]

Definition at line 407 of file DrawApplet.java.

                                              {
        toolDone();
        String type = guessType(filename);
        if (type.equals("storable"))
            readFromStorableInput(filename);
        else if (type.equals("serialized"))
            readFromObjectInput(filename);
        else
            showStatus("Unknown file type");
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.readFromObjectInput ( String  filename) [inline, private]

Definition at line 433 of file DrawApplet.java.

                                                      {
        try {
            URL url = new URL(getCodeBase(), filename);
            InputStream stream = url.openStream();
            ObjectInput input = new ObjectInputStream(stream);
            fDrawing.release();
            fDrawing = (Drawing)input.readObject();
            fView.setDrawing(fDrawing);
        } catch (IOException e) {
            initDrawing();
            showStatus("Error: " + e);
        } catch (ClassNotFoundException e) {
            initDrawing();
            showStatus("Class not found: " + e);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.readFromStorableInput ( String  filename) [inline, private]

Definition at line 418 of file DrawApplet.java.

                                                        {
        try {
            URL url = new URL(getCodeBase(), filename);
            InputStream stream = url.openStream();
            StorableInput input = new StorableInput(stream);
            fDrawing.release();

            fDrawing = (Drawing)input.readStorable();
            fView.setDrawing(fDrawing);
        } catch (IOException e) {
            initDrawing();
            showStatus("Error:"+e);
        }
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.selectionChanged ( DrawingView  view) [inline]

Handles a change of the current selection.

Updates all menu items that are selection sensitive.

See also:
DrawingEditor

Definition at line 367 of file DrawApplet.java.

Here is the call graph for this function:

Definition at line 495 of file DrawApplet.java.

                                              {
        fView.setDisplayUpdate(new BufferedUpdateStrategy());
        fUpdateButton.setLabel("Buffered Update");
        fSimpleUpdate = false;
    }

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.setSelected ( ToolButton  button) [inline, private]

Definition at line 387 of file DrawApplet.java.

                                                {
        if (fSelectedToolButton != null)
            fSelectedToolButton.reset();
        fSelectedToolButton = button;
        if (fSelectedToolButton != null)
            fSelectedToolButton.select();
    }

Here is the caller graph for this function:

Definition at line 489 of file DrawApplet.java.

                                            {
        fView.setDisplayUpdate(new SimpleUpdateStrategy());
        fUpdateButton.setLabel("Simple Update");
        fSimpleUpdate = true;
    }

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.setTool ( Tool  t,
String  name 
) [inline, private]

Definition at line 377 of file DrawApplet.java.

                                              {
        if (fTool != null)
            fTool.deactivate();
        fTool = t;
        if (fTool != null) {
            showStatus(name);
            fTool.activate();
        }
    }

Here is the caller graph for this function:

Definition at line 458 of file DrawApplet.java.

                                   {
        Color frameColor =
           (Color)AttributeFigure.getDefaultAttribute("FrameColor");
        Color fillColor =
           (Color)AttributeFigure.getDefaultAttribute("FillColor");
        Color textColor =
           (Color)AttributeFigure.getDefaultAttribute("TextColor");
        Integer arrowMode =
           (Integer)AttributeFigure.getDefaultAttribute("ArrowMode");
        String fontName =
           (String)AttributeFigure.getDefaultAttribute("FontName");

        FigureEnumeration k = fView.selectionElements();
        while (k.hasMoreElements()) {
            Figure f = k.nextFigure();
            frameColor = (Color) f.getAttribute("FrameColor");
            fillColor  = (Color) f.getAttribute("FillColor");
            textColor  = (Color) f.getAttribute("TextColor");
            arrowMode  = (Integer) f.getAttribute("ArrowMode");
            fontName   = (String) f.getAttribute("FontName");
        }

        fFrameColor.select(ColorMap.getColorMap().colorIndex(frameColor));
        fFillColor.select(ColorMap.getColorMap().colorIndex(fillColor));
        //fTextColor.select(ColorMap.colorIndex(textColor));
        if (arrowMode != null)
            fArrowChoice.select(arrowMode.intValue());
        if (fontName != null)
            fFontChoice.select(fontName);
    }

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.showHelp ( ) [inline, protected]

Shows a help page for the applet.

The URL of the help page is derived as follows: codeBase+appletClassname+Help.html"

Definition at line 505 of file DrawApplet.java.

                              {
        try {
            String appletPath = getClass().getName().replace('.', '/');
            URL url = new URL(getCodeBase(), appletPath+"Help.html");
            getAppletContext().showDocument(url, "Help");
        } catch (IOException e) {
            showStatus("Help file not found");
        }

    }

Here is the call graph for this function:

Here is the caller graph for this function:

void CH.ifa.draw.applet.DrawApplet.startSleeper ( ) [inline, private]

*** netscape browser work around ***

Definition at line 519 of file DrawApplet.java.

                                {
        if (fSleeper == null)
            fSleeper = new SleeperThread(this);
        fSleeper.start();
    }
void CH.ifa.draw.applet.DrawApplet.stopSleeper ( ) [inline, private]

Definition at line 525 of file DrawApplet.java.

                               {
        if (fSleeper != null)
            fSleeper.stop();
    }

Gets the current tool.

See also:
DrawingEditor

Definition at line 341 of file DrawApplet.java.

                       {
        return fTool;
    }

Here is the caller graph for this function:

Sets the default tool of the editor.

See also:
DrawingEditor

Definition at line 357 of file DrawApplet.java.

Here is the call graph for this function:

Here is the caller graph for this function:

DrawingView CH.ifa.draw.applet.DrawApplet.view ( ) [inline]

Gets the current drawing view.

See also:
DrawingEditor

Definition at line 349 of file DrawApplet.java.

                              {
        return fView;
    }

Here is the caller graph for this function:


Member Data Documentation

transient Choice CH.ifa.draw.applet.DrawApplet.fArrowChoice [private]

Definition at line 46 of file DrawApplet.java.

transient ToolButton CH.ifa.draw.applet.DrawApplet.fDefaultToolButton [private]

Definition at line 37 of file DrawApplet.java.

transient Drawing CH.ifa.draw.applet.DrawApplet.fDrawing [private]

Definition at line 33 of file DrawApplet.java.

transient Choice CH.ifa.draw.applet.DrawApplet.fFillColor [private]

Definition at line 44 of file DrawApplet.java.

transient Choice CH.ifa.draw.applet.DrawApplet.fFontChoice [private]

Definition at line 47 of file DrawApplet.java.

transient Choice CH.ifa.draw.applet.DrawApplet.fFrameColor [private]

Definition at line 43 of file DrawApplet.java.

final String CH.ifa.draw.applet.DrawApplet.fgDrawPath = "/CH/ifa/draw/" [static, private]

Definition at line 54 of file DrawApplet.java.

String CH.ifa.draw.applet.DrawApplet.fgUntitled = "untitled" [static, package]

Definition at line 52 of file DrawApplet.java.

Definition at line 50 of file DrawApplet.java.

transient ToolButton CH.ifa.draw.applet.DrawApplet.fSelectedToolButton [private]

Definition at line 38 of file DrawApplet.java.

transient boolean CH.ifa.draw.applet.DrawApplet.fSimpleUpdate [private]

Definition at line 40 of file DrawApplet.java.

transient Thread CH.ifa.draw.applet.DrawApplet.fSleeper [private]

Definition at line 49 of file DrawApplet.java.

transient Tool CH.ifa.draw.applet.DrawApplet.fTool [private]

Definition at line 34 of file DrawApplet.java.

transient Button CH.ifa.draw.applet.DrawApplet.fUpdateButton [private]

Definition at line 41 of file DrawApplet.java.

transient StandardDrawingView CH.ifa.draw.applet.DrawApplet.fView [private]

Definition at line 36 of file DrawApplet.java.

final String CH.ifa.draw.applet.DrawApplet.IMAGES = "images/" [static]

Definition at line 55 of file DrawApplet.java.


The documentation for this class was generated from the following file: