📄 erdbackgroundpanel.java
字号:
/* * ErdBackgroundPanel.java * * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */package org.executequery.gui.erd;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Image;import java.awt.*;import java.awt.print.*;import javax.swing.ImageIcon;import javax.swing.JComponent;import org.executequery.SystemUtilities;/* ---------------------------------------------------------- * CVS NOTE: Changes to the CVS repository prior to the * release of version 3.0.0beta1 has meant a * resetting of CVS revision numbers. * ---------------------------------------------------------- *//** * * @author Takis Diakoumis * @version $Revision: 1.6 $ * @date $Date: 2006/09/10 09:44:30 $ */public class ErdBackgroundPanel extends JComponent { /** Whether to display the grid */ private boolean displayGrid; /** Whether to display the page margins */ private boolean displayMargin; /** The grid image to tile */ private Image gridImage; /** The background colour */ private Color backgroundColour; /** The dashed stroke */ private static BasicStroke dashedStroke; /** the grid colour */ private Color gridColour; /** <p>Constructs a new instance with the specified * <code>ErdViewerPanel</code> as the parent or controller * object. * * @param the parent controller object */ public ErdBackgroundPanel(boolean displayGrid) { setDoubleBuffered(true); setToDisplayGrid(displayGrid); //setToDisplayGrid(false); displayMargin = false; backgroundColour = Color.WHITE; float dash2[] = {10f, 3.0f}; dashedStroke = new BasicStroke(1.0f, 0, 0, 10f, dash2, 0.0f); } /** <p>Overrides this class's <code>paintComponent</code> * method to draw the grid background if this is a * selected option. * * @param the <code>Graphics</code> object */ protected void paintComponent(Graphics _g) { Graphics2D g = (Graphics2D)_g; // draw the background grid if (displayGrid) { int width = getWidth(); int height = getHeight(); int xy = 0; int gridSize = 25; if (gridColour == null) { gridColour = new Color(-3158040); } g.setColor(gridColour); // draw the horizontal grid lines for (int i = 0, k = height / gridSize; i < k; i++) { xy += gridSize; g.drawLine(0, xy, width, xy); } xy = 0; // draw the vertical grid lines for (int i = 0, k = width / gridSize; i < k; i++) { xy += gridSize; g.drawLine(xy, 0, xy, height); } /* int width = getWidth(); int height = getHeight(); int imageWidth = gridImage.getWidth(this); int imageHeight = gridImage.getHeight(this); for (int x = 0; x < width; x += imageWidth) { for (int y = 0; y < height; y += imageHeight) { g.drawImage(gridImage, x, y, this); } } */ } else { g.setColor(backgroundColour); g.fillRect(0, 0, getWidth(), getHeight()); } if (displayMargin) { PageFormat pageFormat = SystemUtilities.getPageFormat(); Paper paper = pageFormat.getPaper(); boolean isPortrait = pageFormat.getOrientation() == PageFormat.PORTRAIT; int imageWidth = 0; int imageHeight = 0; if (isPortrait) { imageWidth = (int)(pageFormat.getImageableWidth() / ErdPrintable.PRINT_SCALE); imageHeight = (int)(pageFormat.getImageableHeight() / ErdPrintable.PRINT_SCALE); } else { imageWidth = (int)(pageFormat.getImageableHeight() / ErdPrintable.PRINT_SCALE); imageHeight = (int)(pageFormat.getImageableWidth() / ErdPrintable.PRINT_SCALE); } g.setColor(Color.GRAY); g.setStroke(dashedStroke); g.drawLine(imageWidth, 0, imageWidth, imageHeight); g.drawLine(0, imageHeight, imageWidth, imageHeight); } } public void setBackground(Color c) { if (c != null) backgroundColour = c; else backgroundColour = Color.WHITE; displayGrid = false; gridImage = null; } public Color getBackground() { return backgroundColour; } public boolean shouldDisplayGrid() { return displayGrid; } public void swapBackground() { setToDisplayGrid(!displayGrid); } private void setToDisplayGrid(boolean displayGrid) { this.displayGrid = displayGrid; if (displayGrid) { ImageIcon icon = new ImageIcon(ErdBackgroundPanel.class.getResource( "/org/executequery/images/ErdGrid.gif")); gridImage = icon.getImage(); } } public void setDisplayMargin(boolean displayMargin) { this.displayMargin = displayMargin; } public boolean shouldDisplayMargin() { return displayMargin; } public void swapPageMargin() { displayMargin = !displayMargin; } public int getHeight() { return getPreferredSize().height; } public int getWidth() { return getPreferredSize().width; } public Rectangle getBounds() { return new Rectangle(0, 0, getWidth(), getHeight()); } public Dimension getMaximumSize() { return getPreferredSize(); } public Dimension getMinimumSize() { return getPreferredSize(); } public Dimension getSize() { return getPreferredSize(); } public void clean() { gridImage = null; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -