use of javax.swing.SpringLayout in project ACS by ACS-Community.
the class SpringUtilities method makeCompactGrid.
/**
* Aligns the first <code>rows</code> * <code>cols</code>
* components of <code>parent</code> in
* a grid. Each component in a column is as wide as the maximum
* preferred width of the components in that column;
* height is similarly determined for each row.
* The parent is made just big enough to fit them all.
*
* @param rows number of rows - 0 means 'as needed'
* @param cols number of columns - 0 means 'as needed'
* @param initialX x location to start the grid at
* @param initialY y location to start the grid at
* @param xPad x padding between cells
* @param yPad y padding between cells
*/
public static void makeCompactGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
// msc: added ----------
if (rows == 0 && cols == 0)
throw new IllegalArgumentException("rows and cols cannot both be 0");
if (rows == 0) {
rows = (int) Math.ceil(parent.getComponentCount() / cols);
}
if (cols == 0) {
cols = (int) Math.ceil(parent.getComponentCount() / rows);
}
// ---------------------
SpringLayout layout;
try {
layout = (SpringLayout) parent.getLayout();
} catch (ClassCastException exc) {
System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
return;
}
//Align all cells in each column and make them the same width.
Spring x = Spring.constant(initialX);
for (int c = 0; c < cols; c++) {
Spring width = Spring.constant(0);
for (int r = 0; r < rows; r++) {
width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
}
for (int r = 0; r < rows; r++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setX(x);
constraints.setWidth(width);
}
x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
}
//Align all cells in each row and make them the same height.
Spring y = Spring.constant(initialY);
for (int r = 0; r < rows; r++) {
Spring height = Spring.constant(0);
for (int c = 0; c < cols; c++) {
height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
}
for (int c = 0; c < cols; c++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setY(y);
constraints.setHeight(height);
}
y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
}
//Set the parent's size.
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, y);
pCons.setConstraint(SpringLayout.EAST, x);
}
use of javax.swing.SpringLayout in project ACS by ACS-Community.
the class SpringUtilities method getConstraintsForCell.
/* Used by makeCompactGrid. */
private static SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
SpringLayout layout = (SpringLayout) parent.getLayout();
Component c = parent.getComponent(row * cols + col);
return layout.getConstraints(c);
}
use of javax.swing.SpringLayout in project ACS by ACS-Community.
the class CommandCenterGui method prepare.
public void prepare() {
boolean setLookAndFeel = false;
if (setLookAndFeel) {
String lafName = UIManager.getSystemLookAndFeelClassName();
try {
UIManager.setLookAndFeel(lafName);
} catch (Exception exc) {
log.fine("Couldn't set look and feel " + lafName + " due to " + exc);
}
}
// title added later in doFrameTitle()
frame = new JFrame("");
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent evt) {
controller.stop();
}
});
dlgContainerSettings = new EditContainerSettingsDialog(this);
frontPanel = new TabPanel(this);
writeModelToFrontPanel();
// Splitter between tree and the rest
splitLeftRight = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitLeftRight.setOneTouchExpandable(true);
JPanel p2 = new JPanel(new BorderLayout());
p2.setBorder(new EmptyBorder(10, 10, 10, 10));
p2.add(frontPanel, BorderLayout.NORTH);
splitLeftRight.setLeftComponent(p2);
// Deployment Tree
deploymentInfoPanel = new JPanel(new BorderLayout());
deploymentInfoPanel.setBorder(new CompoundBorder(new EmptyBorder(5, 7, 5, 7), new TitledBorder(LineBorder.createBlackLineBorder(), " Deployment Info ")));
deployTree = new DeploymentTree(controller.deploymentTreeControllerImpl);
JPanel addToDeployTree = new AddToDeployTree(this, deployTree);
deploymentInfoPanel.add(addToDeployTree, BorderLayout.NORTH);
deploymentInfoPanel.add(new JScrollPane(deployTree), BorderLayout.CENTER);
splitLeftRight.setRightComponent(deploymentInfoPanel);
// Feedback Area
feedbackTabs = new FeedbackTabs(this, FeedbackTabs.BOTTOM);
// Logo Panel
JPanel logoPanel = new LogoPanel(COLOR_LogoBackground_A, COLOR_LogoBackground_B);
logoPanel.setLayout(new BorderLayout());
JLabel alma = new JLabel(new ImageIcon(controller.findResource("alma.jpg")));
logoPanel.add(alma, BorderLayout.WEST);
JLabel text = new JLabel("Acs Command Center");
text.setForeground(COLOR_LogoForeground);
text.setHorizontalTextPosition(SwingConstants.CENTER);
text.setFont(text.getFont().deriveFont((float) (text.getFont().getSize() * 2.5)));
text.setBorder(new EmptyBorder(5, 30, 5, 30));
logoPanel.add(text, BorderLayout.CENTER);
// JLabel version = new JLabel(controller.version());
// version.setForeground(COLOR_LogoForeground);
// version.setBorder(new EmptyBorder(0, 0, 0, 4));
// JPanel pnl2 = new JPanel(new BorderLayout());
// pnl2.setOpaque(false);
// pnl2.add(version, BorderLayout.SOUTH);
// logoPanel.add(pnl2, BorderLayout.EAST);
menuBar = new JMenuBar();
JMenu fileMenu = new JMenu("Project");
fileMenu.setMnemonic(KeyEvent.VK_P);
{
JMenu newMenu = new JMenu("New");
newMenu.add(new ActionNewProject("Project"));
fileMenu.add(newMenu);
}
fileMenu.add(new ActionOpenProject("Open..."));
fileMenu.add(new ActionSaveProject("Save"));
fileMenu.add(new ActionSaveAsProject("Save As..."));
fileMenu.addSeparator();
fileMenu.add(new ActionExit("Exit"));
menuBar.add(fileMenu);
toolsMenu = new JMenu("Tools");
toolsMenu.setMnemonic(KeyEvent.VK_T);
toolsMenu.add(new ActionConfigureTools("Configure Tools..."));
toolsMenu.addSeparator();
menuBar.add(toolsMenu);
// ---
JMenu extrasMenu = new JMenu("Expert");
extrasMenu.setMnemonic(KeyEvent.VK_E);
{
// JMenu sshMode = new JMenu("SSH Library");
// sshMode.add(new ActionSetSshMode("Platform-independent", false, false));
// sshMode.add(new ActionSetSshMode("Natively installed ssh", true, true));
// extrasMenu.add(sshMode);
// extrasMenu.add(new JSeparator());
JMenu extraTools = new JMenu("Tools Menu");
extraTools.add(new ActionShowExtraTools("View..."));
extraTools.add(new ActionInstallExtraTools("Replace..."));
extrasMenu.add(extraTools);
JMenu builtinTools = new JMenu("Acs Scripts");
builtinTools.add(new ActionShowBuiltinTools("View..."));
builtinTools.add(new ActionLoadBuiltinTools("Replace..."));
extrasMenu.add(builtinTools);
}
extrasMenu.add(new JSeparator());
extrasMenu.add(new ActionShowVariables("Variables..."));
menuBar.add(extrasMenu);
// ---
JMenuItem item;
JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic(KeyEvent.VK_H);
item = helpMenu.add(new ActionShowHelp("Online Help"));
item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
item = helpMenu.add(new ActionShowAbout("About"));
menuBar.add(Box.createHorizontalGlue());
menuBar.add(helpMenu);
// ---
JPanel h = new JPanel(new SpringLayout());
h.add(logoPanel);
h.add(menuBar);
SpringUtilities.makeCompactGrid(h, 0, 1);
frame.getContentPane().add(h, BorderLayout.NORTH);
// ---
pnlManagerLocationForTools = new ManagerLocationPanel.ForTools();
managerLocationDialog1 = new BasicDialog(this, "Specify Manager and Services for Tools", "Set", pnlManagerLocationForTools);
// ---
pnlManagerLocationForContainers = new ManagerLocationPanel.ForContainers();
managerLocationDialog2 = new BasicDialog(this, "Specify Manager and Services for Containers", "Set", pnlManagerLocationForContainers);
// ---
splitTopBottom = new JSplitPane(JSplitPane.VERTICAL_SPLIT, splitLeftRight, feedbackTabs);
splitTopBottom.setOneTouchExpandable(true);
// ---
// 2009-04: Introducing a desktop layout so i can make the
// progress dialog a lightweight window on top the front panel
AccInternalFrame bigInternalFrame = new AccInternalFrame();
bigInternalFrame.add(splitTopBottom);
desktop = new JDesktopPane();
bigInternalFrame.setVisible(true);
desktop.add(bigInternalFrame);
frame.getContentPane().add(desktop, BorderLayout.CENTER);
try {
bigInternalFrame.setSelected(true);
bigInternalFrame.setMaximum(true);
} catch (PropertyVetoException exc) {
}
// for mysterious swing reasons, the desktop has a preferred size
// of (1,1) instead of picking up the preferred size of its child
// component, so i'm doing this manually here.
desktop.setPreferredSize(bigInternalFrame.getPreferredSize());
doFrameTitle();
}
use of javax.swing.SpringLayout in project BIMserver by opensourceBIM.
the class SpringUtilities method getConstraintsForCell.
/* Used by makeCompactGrid. */
private static SpringLayout.Constraints getConstraintsForCell(int row, int col, Container parent, int cols) {
SpringLayout layout = (SpringLayout) parent.getLayout();
Component c = parent.getComponent(row * cols + col);
return layout.getConstraints(c);
}
use of javax.swing.SpringLayout in project BIMserver by opensourceBIM.
the class SpringUtilities method makeCompactGrid.
/**
* Aligns the first <code>rows</code> * <code>cols</code>
* components of <code>parent</code> in
* a grid. Each component in a column is as wide as the maximum
* preferred width of the components in that column;
* height is similarly determined for each row.
* The parent is made just big enough to fit them all.
*
* @param rows number of rows
* @param cols number of columns
* @param initialX x location to start the grid at
* @param initialY y location to start the grid at
* @param xPad x padding between cells
* @param yPad y padding between cells
*/
public static void makeCompactGrid(Container parent, int rows, int cols, int initialX, int initialY, int xPad, int yPad) {
SpringLayout layout;
try {
layout = (SpringLayout) parent.getLayout();
} catch (ClassCastException exc) {
System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
return;
}
// Align all cells in each column and make them the same width.
Spring x = Spring.constant(initialX);
for (int c = 0; c < cols; c++) {
Spring width = Spring.constant(0);
for (int r = 0; r < rows; r++) {
width = Spring.max(width, getConstraintsForCell(r, c, parent, cols).getWidth());
}
for (int r = 0; r < rows; r++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setX(x);
constraints.setWidth(width);
}
x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
}
// Align all cells in each row and make them the same height.
Spring y = Spring.constant(initialY);
for (int r = 0; r < rows; r++) {
Spring height = Spring.constant(0);
for (int c = 0; c < cols; c++) {
height = Spring.max(height, getConstraintsForCell(r, c, parent, cols).getHeight());
}
for (int c = 0; c < cols; c++) {
SpringLayout.Constraints constraints = getConstraintsForCell(r, c, parent, cols);
constraints.setY(y);
constraints.setHeight(height);
}
y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
}
// Set the parent's size.
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, y);
pCons.setConstraint(SpringLayout.EAST, x);
}
Aggregations