📄 permislayout.java
字号:
/*
* Copyright (c) 2000-2005, University of Salford
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* Neither the name of the University of Salford nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/*
* PermisCreateGridBagLayout.java
*
* Created on 21 June 2004, 14:51
*/
package issrg.editor.gui;
/**
*
* @author issrg
*/
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import javax.swing.JPanel;
import java.awt.Component;
import java.awt.Container;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.JComponent;
import java.awt.Dimension;
import javax.swing.BoxLayout;
import javax.swing.Box;
import java.awt.Insets;
public class PermisLayout {
private GridBagConstraints cst;
private GridBagLayout grid;
public static int fixSize = 10;
private PermisPolicyEditorMain parent;
/** Creates a new instance of PermisCreateGridBagLayout */
public PermisLayout(PermisPolicyEditorMain parent) {
this.parent = parent;
this.grid = new GridBagLayout();
this.cst = new GridBagConstraints();
}
public GridBagConstraints getGridConstaints( int x, //column
int y, //row
int w, // width
int h, //height
double wx, // grow x-direction 0 no growth
double wy,
int ipy,
int ipx) //grow y-direction
{
this.cst.gridx = x;
this.cst.gridy = y;
this.cst.gridwidth = w;
this.cst.gridheight = h;
this.cst.weightx = wx;
this.cst.weighty = wy;
this.cst.ipadx =ipx;
this.cst.ipady =ipy;
this.cst.fill = GridBagConstraints.HORIZONTAL;
this.cst.insets = new Insets(2, 2, 2,2);
return cst;
}
public static void add(Container ct, JComponent c, GridBagLayout grid,
GridBagConstraints gbc, int x, int y, int w, int h) {
gbc.gridx = x;
gbc.gridy = y;
gbc.gridwidth = w;
gbc.gridheight = h;
grid.setConstraints(c, gbc);
ct.add(c);
}
public static void add(Container ct, JComponent c, GridBagLayout grid,
GridBagConstraints gbc) {
grid.setConstraints(c, gbc);
ct.add(c);
}
public void setLayout(Container ct){
ct.setLayout(this.grid);
}
public static void setLocation(Component cm)
{
Point p = cm.getLocation();
p.x += fixSize;
p.y += fixSize;
cm.setLocation(p);
}
public static void center(Component cm)
{
center(cm, cm.getSize());
}
public static void center(Component cm, Dimension me)
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
cm.setLocation(screenSize.width/2 - me.width/2,
screenSize.height/2 -me.height/2);
}
public static void fixSize(Component cm)
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Point wPos = cm.getLocation();
Dimension wSize = cm.getSize();
if( wSize.width > screenSize.width){
wSize.width = (int)screenSize.width/2;
}
if( wSize.height < 80){
wSize.height = 80;
}
if( wSize.height >screenSize.height){
wSize.height = (int)screenSize.height/2;
}
cm.setSize(wSize);
}
public Dimension getSize()
{
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
//Point wPos = cm.getLocation();
Dimension wSize = null;
// Dimension wframe = parent.getframeSize();
// wSize.width = wframe.width-fixSize;
// wSize.height = wframe.height-fixSize;
return wSize ;
}
/**************************************************************************\
* createHorizontalLayout *
\**************************************************************************/
public Box createHorizontalLayout()
{
Box b = Box.createHorizontalBox();
return b;
}
/**************************************************************************\
* createVerticalLayout *
\**************************************************************************/
public Box createVerticalLayout()
{
Box b = Box.createVerticalBox();
return b;
}
/**************************************************************************\
* Constructor *
\**************************************************************************/
public void createGlue()
{
Box.createGlue();
}
/**************************************************************************\
* Constructor *
\**************************************************************************/
public void addHorizontalStrut(int i)
{
Box.createHorizontalStrut(i);
}
/**************************************************************************\
* Constructor *
\**************************************************************************/
public void addVerticalStrut(int i)
{
Box.createVerticalStrut(i);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -