001: /**
002: * Caption: Zaval Java Resource Editor
003: * $Revision: 0.37 $
004: * $Date: 2002/03/28 9:24:42 $
005: *
006: * @author: Victor Krapivin
007: * @version: 1.3
008: *
009: * Zaval JRC Editor is a visual editor which allows you to manipulate
010: * localization strings for all Java based software with appropriate
011: * support embedded.
012: *
013: * For more info on this product read Zaval Java Resource Editor User's Guide
014: * (It comes within this package).
015: * The latest product version is always available from the product's homepage:
016: * http://www.zaval.org/products/jrc-editor/
017: * and from the SourceForge:
018: * http://sourceforge.net/projects/zaval0002/
019: *
020: * Contacts:
021: * Support : support@zaval.org
022: * Change Requests : change-request@zaval.org
023: * Feedback : feedback@zaval.org
024: * Other : info@zaval.org
025: *
026: * Copyright (C) 2001-2002 Zaval Creative Engineering Group (http://www.zaval.org)
027: *
028: * This program is free software; you can redistribute it and/or
029: * modify it under the terms of the GNU General Public License
030: * (version 2) as published by the Free Software Foundation.
031: *
032: * This program is distributed in the hope that it will be useful,
033: * but WITHOUT ANY WARRANTY; without even the implied warranty of
034: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
035: * GNU General Public License for more details.
036: *
037: * You should have received a copy of the GNU General Public License
038: * along with this program; if not, write to the Free Software
039: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
040: *
041: */package org.zaval.awt;
042:
043: import java.awt.*;
044: import java.util.*;
045:
046: public class ScrollPanel extends Panel implements ScrollArea,
047: LayoutManager {
048: private Scrollbar hBar = new Scrollbar(Scrollbar.HORIZONTAL);
049: private Scrollbar vBar = new Scrollbar(Scrollbar.VERTICAL);
050: private Panel mainPanel = new Panel();
051: private ScrollLayout layout = new ScrollLayout();
052: private ScrollController metrics;
053:
054: public ScrollPanel(ScrollObject obj) {
055: init(new ScrollController(this , obj));
056: }
057:
058: public ScrollPanel(ScrollController m) {
059: init(m);
060: }
061:
062: protected void init(ScrollController m) {
063: metrics = m;
064: if (metrics == null)
065: metrics = new ScrollController(this , null);
066: if (metrics.getScrollArea() == null)
067: metrics.setScrollArea(this );
068:
069: setLayout(layout);
070: add("Center", mainPanel);
071: add("East", vBar);
072: add("South", hBar);
073: add("Stubb", new StubbComponent());
074:
075: ScrollObject obj = metrics.getScrollObject();
076: init(mainPanel, obj.getScrollComponent());
077: }
078:
079: protected void init(Container p, Component c) {
080: p.setLayout(this );
081: p.add(c);
082: }
083:
084: public boolean handleEvent(Event e) {
085: if (metrics.handle(e, 1))
086: return true;
087: return super .handleEvent(e);
088: }
089:
090: public void invalidate() {
091: super .invalidate();
092: if (metrics != null)
093: metrics.invalidate();
094: }
095:
096: public void reshape(int x, int y, int w, int h) {
097: super .reshape(x, y, w, h);
098: if (metrics != null)
099: metrics.invalidate();
100: invalidate();
101: recalc();
102: }
103:
104: public void layout() {
105: recalc();
106: super .layout();
107: }
108:
109: public void recalc() {
110: if (!metrics.isValid())
111: metrics.validate();
112:
113: ScrollObject sobj = metrics.getScrollObject();
114: int maxV = metrics.getMaxVerScroll();
115: int maxH = metrics.getMaxHorScroll();
116:
117: if (maxV < 0)
118: vBar.hide();
119: else {
120: vBar.setValues(0, 0, 0, maxV);
121: sobj.setSOLocation(0, 0);
122: vBar.show();
123: }
124:
125: if (maxH < 0)
126: hBar.hide();
127: else {
128: hBar.setValues(0, 0, 0, maxH);
129: sobj.setSOLocation(0, 0);
130: hBar.show();
131: }
132:
133: sobj.setSOLocation(0, 0);
134: }
135:
136: public Scrollbar getVBar() {
137: return vBar;
138: }
139:
140: public Scrollbar getHBar() {
141: return hBar;
142: }
143:
144: public Dimension getSASize() {
145: return size();
146: }
147:
148: protected ScrollController getMetrics() {
149: return metrics;
150: }
151:
152: public void addLayoutComponent(String s, Component c) {
153: }
154:
155: public void removeLayoutComponent(Component c) {
156: }
157:
158: public Dimension minimumLayoutSize(Container target) {
159: return preferredLayoutSize(target);
160: }
161:
162: public Dimension preferredLayoutSize(Container target) {
163: Component[] c = target.getComponents();
164: if (c.length > 0)
165: return c[0].preferredSize();
166: return new Dimension(0, 0);
167: }
168:
169: public void layoutContainer(Container target) {
170: Component[] c = target.getComponents();
171: ScrollArea a = metrics.getScrollArea();
172: Dimension td = target.size();
173: for (int i = 0; i < c.length; i++) {
174: Dimension d = c[i].preferredSize();
175: if (!a.getVBar().isVisible())
176: d.height = td.height;
177: if (!a.getHBar().isVisible())
178: d.width = td.width;
179:
180: c[i].resize(d.width, d.height);
181: }
182: }
183: }
|