Summary: This page describes the dialog to show the order of pages. |
Relevant major classes of Java SE: java.awt.*, java.awt.geom.*, java.awt.event.*, javax.swing.*, javax.swing.*,
java.util.
|
Classes on this page: DialogOfPageLayout, PagePanel |
1. Overview
戻る=>page top
Figure 1. Page layout dialog (initial dialog)
Figure 2. Page layout dialog (resized dialog)
2. Class DialogOfPageLayout
return=>page top
public class DialogOfPageLayout extends JDialog
Method
|
Description
|
Constructor
|
public DialogOfPageLayout()
Sets the following.
super(ObjectTable.getDrawMain(), "page layout");
this.setName("DialogOfPageLayout");
this.listener=new PageLayoutListener(this);
this.addComponentListener(this.listener);
this.addWindowListener(this.listener);
ObjectTable.getPageManager().saveCurrentPage();
: The above last statement saves the latest state of the page to the file.
|
showDialog
|
public void showDialog()
∙ If this dialog is already opened, this method does nothing.
Whether the dialog is opened or not canbe checked by the by the getMenuComponent of the menuUtil.
∙ Calls the createLayoutPanelmethod.
∙ Shows the dialog by calling this.setVisible(true).
∙ Registers this object to MenuComponentList the setMenuComponent of the menuUtil.
|
setScrollViewPosition |
protected void setScrollViewPosition()
Sets the view position to the scrollPane.
:Calls this method in the componentShownmethod.
|
createLayoutPanel
|
private JPanel createLayoutPanel()
Creates the panel(Figure 1).
∙ Creates anew JPanel object and anew JScrollPane object
and adds the newJScrollPane to the JPanel.
Creates a new PagePanel object and sets it to the viewport of the scrollPane.
∙ Returns the JPanel.
|
getScrollPane |
protected JScrollPane getScrollPane()
Returns the scrollPane. |
getPagePanel |
protected JPanel getPagePanel()
Returns the pagePanel. |
3. Class PagePanel
return=>page top
class PagePanel extends JPanel implements MouseListener, MouseMotionListener
This class provides the following functions.
∙ Draws all the pages in the dialog with the scroll pane.
∙ Selects the page by the mouse and moves theselectedpage to
the destination by the mouse drag.
Field
|
Description
|
dialog |
DialogOfPageLayout dialog
The DialogOfPageLayout object.
|
xNumOfFrames |
int xNumOfFrames
The number of the page frames in horizontal direction.
|
yNumOfFrames
|
int yNumOfFrames
The number of the page frames in vertical direction.
|
pageFrameRects
|
private Rectangle2D[] pageFrameRects
The pageFrameRects[i-1] represents the rectangle in which thecontentsofthe
page[i] are displayed. In other words, the pageFrameRects[i-1] corresponds
the rectangle above thestringof "page-i " in Figure 1 and so on.
|
selectedPage
|
int selectedPage
The index of the selected page.
Selecting page is executed in the mousePressed method and the selected page is displayed with the black frame (Figure 4).
|
gapIndex
|
int gapIndex
The index of the gap between two pageFrameRects.
The gapIndex represents the destination towhich the selected page
is moved.
: Index of the gap=>Figure 3, Destination=> Figure 4
|
gap |
final Dimension gap=new Dimension(20, 20);
This object prepresents the horizontalandverticalgapsbetweenthetwopageFrameRects. |
Method
|
Description
|
Constructor
|
public PagePanel()
setPageLayoutを呼んで、DrawPagePanelに表示する全ページのレイアウトを決める。
|
paint
|
public void paint(Graphics g)
In the loop forthe array of the pageFrameRects, the following operations are done.
∙ Calls the setPageLayout method.
∙ If this.selectedPage>=1, then drawstheboldblackframearountheselectedpage.
∙ If this.gapIndex>=0, then drawstheboldvertical lineat the destination
place where the selected page should be moved.
:The displayoftheselectedpageandthedestination
=> Figure 4
∙ Draws the contents of the page-i(i>=1) in the pageFrameRects[i-1] by the drawPage method.
|
setPageLayout
|
private void setPageLayout()
∙ Calculatesthe xNumOfFrames and yNumOfFrames.
These values can be calculated by using the preferred size of the scroll pane, the returned value of the getPageFrameSize method, the gap and number of pages given by the pageManager.getPageList().size().
∙ Sets the returned value of the getPagePanelSize method to this object as the preferred size.
∙ Calls the getPageFrameRects method and sets the returned value to the pageFrameRects field.
∙Calls the revalidate method of this object.
|
getPageFrameSize |
private Dimension getPageFrameSize()
This method is called by the setPageLayout method.
Returns:
The Dimension object representing the page size with which the contents
of each page are displayed. This page size corresponds to the size of rectangles
above the strings of "page-1", "page-2",... inthe
Figure 1 and Figure 2.
Currently the page size is determined as one-eighth of A4 landscape size.
|
getPagePanelSize |
private Dimension getPagePanelSize()
This method is called by the setPageLayout method.
Returns:
The Dimension object representing the size of this object.
|
getPageFrameRects
|
private Rectangle2D[] getPageFrameRects()
This method is called by the setPageLayout method.
Returns:
The Rectangle2D objects in which the contents of each page are displayed.
The n-thRectangle2Dobject corresponds to the rectangle above
the string of "page-n", in the Figure 1 and Figure 2. The width and the height are equals to those of the returned values of
the getPageFrameSize method.
|
drawPage
|
private void drawPage(Graphics g, int pageIndex, Rectangle2D rect)
Paremeters:
pageIndex - The index of the page to be displayed (pageIndex>=1)
rect - The rectangle in which the page contents are displayed.
Processing:
∙ Sets the ContainerList ofthe pageIndex to the new ContainerManager object and gets the ViewData specified of the pageIndex as follows.
PageManager pageManager=ObjectTable.getPageManager();
ArrayList list=pageManager.getContainerList(pageIndex);
ViewData viewData=pageManager.getViewData(pageIndex);
ContainerManager containerManager=new ContainerManager();
containerManager.setContainerList(list);
∙ Calls the getScale method to map the drawings of the page to the rect.
∙ If the sheet orientation is portrait, then sets the 90 degree rotation
to the Graphics2D(g2).
∙ Draws all the shapes objects in the ContainerList by the drawShape method of the ShapeContainer.
∙ Draws the string of "page-n" under the rect.
|
getScale |
private double getScale(ViewData viewData, Rectangle2D rect)
Parameters:
vieData - The ViewData object.
rect - The rectangle in which all the shapes objects in the ContainerList are displayed.
Returns:
The scale factor for drawing all the shapes objects in the rect.
|
mousePressed
|
public void mousePressed(MouseEvent e)
Gets the index of the page where the mouseposition(startPoint)
is located by the ptInside method.
If the index>0, then sets the index to the selectedPage, otherwise sets 0 to the selectedPage.
|
mouseDragged
|
public void mouseDragged(MouseEvent e)
Gets the index of the gap for the current mouse position (currentPoint).
this.gapIndex=this.getNearestGap(currentPoint);
:The gapIndex represents the destination of the selected page and
they are displayed as Figure 4 in the paint method.
|
mouseReleased
|
public void mouseReleased(MouseEvent e)
When the mouse button is released, the destination of the selected pagetobemoved
is determined. If the this.selectedPage>=1 and this.gapIndex>=0, then calls the following method.
pageManager.movePage(this.selectedPage, this.gapIndex+1);
:The movePage method moves this.selectedPage tothepositionspecifiedby this.gapIndex+1 and displays this.selectedPage.
|
mouseClicked
|
public void mouseClicked(MouseEvent e)
Nothing is done.
|
mouseEntered
|
public void mouseEntered(MouseEvent e)
Nothing is done.
|
mouseExited
|
public void mouseExited(MouseEvent e)
Nothing is done.
|
mouseMoved
|
public void mouseMoved(MouseEvent e)
Nothing is done.
|
ptInside
|
public int ptInside(Point2D point)
Parameter:
point - The mouse position
Returns:
The index of the page where the mouse is located. Returns -1, if
the point isn't contained in any page area.
: The page index (or the index of the page)>=1 => Figure 3
Processing:
The page areas in the dialog are represented by the pageFrameRects.
This method returns (index+1), if the mouse position is contained in the
pageFrameRect[index].
|
getNearestGap
|
public int getNearestGap(Point2D point)
Parameter:
point - The mouse position
Returns:
The index of the gap to which the point is nearest.
: The gap index (ot the index of the gap)>=0 => Figure 3
|
Figure 3 The page index and gap index
Figure 4 The selected page(black frame)
and the desitination (bold vertical line between page-1 and page-2)
4. Class PageLayoutListener
return=>page top
class PageLayoutListener extends WindowAdapter implements ComponentListener
Field
|
Description
|
dialog |
DialogOfPageLayout dialog
The DialogOfPageLayout object.
|
|