1 | package org.expeditee.gui;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 |
|
---|
5 | import org.expeditee.items.Item;
|
---|
6 | import org.expeditee.items.Text;
|
---|
7 |
|
---|
8 | public class FrameCreator {
|
---|
9 |
|
---|
10 | private String _name;
|
---|
11 |
|
---|
12 | private final static int START_Y = 40;
|
---|
13 |
|
---|
14 | private final static int START_X = 20;
|
---|
15 |
|
---|
16 | private Frame _current = null;
|
---|
17 |
|
---|
18 | private int _lastX = START_X;
|
---|
19 |
|
---|
20 | private int _maxX = 0;
|
---|
21 |
|
---|
22 | private int _lastY = START_Y;
|
---|
23 |
|
---|
24 | private Text _Mnext = new Text(-1, "@Next");
|
---|
25 |
|
---|
26 | private Text _Mprev = new Text(-1, "@Previous");
|
---|
27 |
|
---|
28 | private Item _next;
|
---|
29 |
|
---|
30 | private Item _prev;
|
---|
31 |
|
---|
32 | public FrameCreator(String name, boolean recreate) {
|
---|
33 | int num = -1;
|
---|
34 | if (!recreate)
|
---|
35 | num = FrameIO.getLastNumber(name);
|
---|
36 |
|
---|
37 | Frame toUse = null;
|
---|
38 |
|
---|
39 | if (num == -1)
|
---|
40 | toUse = FrameIO.CreateFrameset(name, FrameIO.HELP_PATH);
|
---|
41 | else
|
---|
42 | toUse = FrameIO.CreateFrame(name, name, null);
|
---|
43 |
|
---|
44 | _name = name;
|
---|
45 | _lastY += toUse.getTitle().getPosition().y;
|
---|
46 | _current = toUse;
|
---|
47 |
|
---|
48 | // set positions of next\prev frame links
|
---|
49 | _Mnext.setPosition(FrameGraphics.getMaxSize().width - 100,
|
---|
50 | FrameGraphics.getMaxSize().height - 15);
|
---|
51 | _Mprev.setPosition(50, FrameGraphics.getMaxSize().height - 15);
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Creates the next frame in the frameset, with a previous button already
|
---|
56 | * added and linked to the last frame. _current then gets updated to point
|
---|
57 | * at the newly created Frame, and _lastY is reset
|
---|
58 | */
|
---|
59 | public void createNextFrame() {
|
---|
60 | Frame newFrame = FrameIO.CreateFrame(_current.getFramesetName(),
|
---|
61 | _name, null);
|
---|
62 |
|
---|
63 | // add link to previous frame
|
---|
64 | _prev = _Mprev.copy();
|
---|
65 | _prev.setID(newFrame.getNextItemID());
|
---|
66 | _prev.setLink(_current.getFrameName());
|
---|
67 | newFrame.addItem(_prev);
|
---|
68 |
|
---|
69 | // add link to new frame
|
---|
70 | _next = _Mnext.copy();
|
---|
71 | _next.setID(_current.getNextItemID());
|
---|
72 | _next.setLink(newFrame.getFrameName());
|
---|
73 | _current.addItem(_next);
|
---|
74 | FrameIO.SaveFrame(_current, false);
|
---|
75 |
|
---|
76 | // update\reset globals
|
---|
77 | _current = newFrame;
|
---|
78 | _lastY = START_Y + _current.getTitle().getPosition().y;;
|
---|
79 | _lastX = START_X;
|
---|
80 | _maxX = 0;
|
---|
81 | }
|
---|
82 |
|
---|
83 | public void addItem(Item toAdd) {
|
---|
84 | // if we have reached the end of the Y axis, try moving over on the X
|
---|
85 | // axis
|
---|
86 | if (_lastY >= _Mprev.getY() - _Mprev.getBoundsHeight()) {
|
---|
87 | _lastX = _maxX + 10;
|
---|
88 | _lastY = START_Y;
|
---|
89 | }
|
---|
90 |
|
---|
91 | // if there is no more room on the X axis, we have to start a new frame
|
---|
92 | if (toAdd.getBoundsWidth() + _lastX > FrameGraphics.getMaxSize().width) {
|
---|
93 | createNextFrame();
|
---|
94 | }
|
---|
95 |
|
---|
96 | toAdd.setPosition(_lastX, _lastY);
|
---|
97 | toAdd.setOffset(0, 0);
|
---|
98 | toAdd.setID(_current.getNextItemID());
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * List<Item> items = new ArrayList<Item>(4);
|
---|
102 | *
|
---|
103 | * items.add(_current.getName()); items.add(_current.getTitle());
|
---|
104 | * items.add(_prev); items.add(_next);
|
---|
105 | *
|
---|
106 | * _current.getItems().removeAll(items);
|
---|
107 | *
|
---|
108 | * //new system.agents.Format().process(_current);
|
---|
109 | *
|
---|
110 | * //FrameUtils.Align(items, toAdd, true);
|
---|
111 | */
|
---|
112 | _current.addItem(toAdd);
|
---|
113 | // _current.addAllItems(items);
|
---|
114 |
|
---|
115 | FrameIO.SaveFrame(_current, false);
|
---|
116 |
|
---|
117 | _lastY = toAdd.getY() + toAdd.getBoundsHeight();
|
---|
118 | _maxX = Math.max(toAdd.getX() + toAdd.getBoundsWidth(), _maxX);
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void addText(String toAdd) {
|
---|
122 | /*
|
---|
123 | * Text text = _current.createNewText(); text.setText(toAdd);
|
---|
124 | *
|
---|
125 | * addItem(text);
|
---|
126 | */
|
---|
127 | addText(toAdd, null);
|
---|
128 | }
|
---|
129 |
|
---|
130 | public void addText(String toAdd, Color c) {
|
---|
131 | Text text = _current.createNewText();
|
---|
132 | text.setText(toAdd);
|
---|
133 | text.setColor(c);
|
---|
134 |
|
---|
135 | addItem(text);
|
---|
136 | }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Returns the Frame name of the current (latest) frame in the message
|
---|
140 | * frameset.
|
---|
141 | *
|
---|
142 | * @return The Frame currently being used in the message frameset
|
---|
143 | */
|
---|
144 | public String getCurrent() {
|
---|
145 | if (_current == null)
|
---|
146 | return null;
|
---|
147 |
|
---|
148 | return _current.getFrameName();
|
---|
149 | }
|
---|
150 | }
|
---|