そこで、特定の「モデル」に応じて、高さ 50 ピクセル、長さ約 84600 ピクセルの水平の「タイムライン」バーを生成するプログラムを作成しました。各ピクセルは、24 時間にわたって秒単位でイベントをモデリングしているため、1 秒を表します。
問題は、32768 ピクセルを超えるとバーが途切れることです。
ScrolledComposite を使用してキャンバスの一部のみを表示し、スクロールバーがバッファリングを介してドラッグされたときに新しいデータが表示されている間にそのスクロールを行うなどのソリューションを読みましたが、これを行う方法にまったく慣れていません。
私が見た別の解決策は、ScrolledComposite を使用せずに canvas.scroll のみを使用することでした。ソース コードを実行すると (問題を説明するためのテスト プログラム)、スクロールバーがスクロールしてキャンバス全体を表示できないことが明らかになりました。この「ソリューション」のテスト プログラムを以下に示します。助けてください!
package canvas;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Event;
public class Test {
static int shellStyle = SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND | SWT.H_SCROLL;
static int canvasStyle = SWT.NO_REDRAW_RESIZE;// | SWT.H_SCROLL | SWT.V_SCROLL;
public static void main(String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display, shellStyle);
shell.setLayout(new FillLayout());
shell.setBackground(display.getSystemColor((SWT.COLOR_CYAN)));
shell.setText("Canvas Test");
Image image;
final Canvas canvas = new Canvas(shell, canvasStyle);
canvas.setLayout(new FillLayout());
canvas.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
final Point origin = new Point(0,0);
final ScrollBar hBar = shell.getHorizontalBar();
Rectangle size = canvas.getBounds();
hBar.setMaximum(size.width);
hBar.setMinimum(0);
// Create a paint handler for the canvas
canvas.addPaintListener(new PaintListener() {
public void paintControl(PaintEvent e) {
// Do some drawing
e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_YELLOW));
e.gc.fillRectangle(100, 200, 100, 200);
e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_CYAN));
e.gc.fillRectangle(900, 200, 600, 200);
e.gc.setBackground(display.getSystemColor(SWT.COLOR_DARK_MAGENTA));
e.gc.fillRectangle(500, 200, 300, 200);
e.gc.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
e.gc.fillRectangle(1600, 200, 300, 200);
}
});
// The below event handlers allow for horizontal scrolling functionality
hBar.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
int x = 0;
int hSelection = hBar.getSelection();
int destX = -hSelection - origin.x;
Rectangle rect = shell.getBounds();
canvas.scroll(destX, 0, x, 0, rect.width, rect.height, false);
origin.x = -hSelection;
x = destX;
}
});
shell.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event e) {
Rectangle rect = canvas.getClientArea();
Rectangle client = shell.getClientArea();
hBar.setMaximum(rect.width);
hBar.setThumb(Math.min(rect.width, client.width));
int hPage = rect.width - client.width;
int hSelection = hBar.getSelection();
if (hSelection >= hPage) {
if (hPage <= 0)
hSelection = 0;
origin.x = -hSelection;
}
shell.redraw();
}
});
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
}
編集:ちょっとありがとうp12t! ちょっと質問があります...この行: final PointのtimelineSize = new Point(84600, 50);
これは、x 軸のピクセルごとに「ポイント」があり、y 軸のピクセルが 50 個下にあるということですか? など: ++++++++++
. . . . . . . . . .
したがって、各「+ 記号」は水平方向の x 軸ピクセルであり、84600 の「ポイント」は 50 y 軸ピクセル下に示されている「期間」です。これについての私の理解は正しいですか?(ところで、私が上に示した例は10のポイントを示しています)
また、あなたの意見では、私は何が間違っていましたか? または私はそれを間違って実装しました..