mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GT-2698 refactor UI elements to lock down HTML rendering
This commit is contained in:
parent
a03c96d37b
commit
e0c25b0590
360 changed files with 3895 additions and 4563 deletions
|
@ -23,6 +23,7 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
import ghidra.util.HTMLUtilities;
|
||||
import ghidra.util.SystemUtilities;
|
||||
|
||||
public class FileLocker {
|
||||
|
@ -120,14 +121,15 @@ public class FileLocker {
|
|||
return "no properties in lock file";
|
||||
}
|
||||
|
||||
StringBuffer buf = new StringBuffer("<p><table border=0>");
|
||||
StringBuilder buf = new StringBuilder("<p><table border=0>");
|
||||
for (String name : PROPERTY_KEYS) {
|
||||
buf.append("<tr><td>");
|
||||
buf.append(" ");
|
||||
buf.append(name);
|
||||
buf.append(HTMLUtilities.friendlyEncodeHTML(name));
|
||||
buf.append(": ");
|
||||
buf.append("</td><td>");
|
||||
buf.append(existingLockProperties.get(name));
|
||||
buf.append(
|
||||
HTMLUtilities.friendlyEncodeHTML(existingLockProperties.get(name).toString()));
|
||||
buf.append("</td></tr>");
|
||||
}
|
||||
buf.append("</table>");
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -26,15 +25,16 @@ public class ErrorPropertyEditor extends PropertyEditorSupport {
|
|||
private JLabel errorLabel;
|
||||
private Object editorValue;
|
||||
|
||||
public ErrorPropertyEditor( String errorMessage, Object value ) {
|
||||
public ErrorPropertyEditor(String errorMessage, Object value) {
|
||||
editorValue = value;
|
||||
String message = errorMessage;
|
||||
if ( editorValue != null ) {
|
||||
if (editorValue != null) {
|
||||
message += " - value: " + value.toString();
|
||||
}
|
||||
|
||||
errorLabel = new JLabel( message );
|
||||
errorLabel.setForeground( Color.RED );
|
||||
|
||||
errorLabel = new JLabel(message);
|
||||
errorLabel.setForeground(Color.RED);
|
||||
errorLabel.putClientProperty("html.disable", true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,5 +45,5 @@ public class ErrorPropertyEditor extends PropertyEditorSupport {
|
|||
@Override
|
||||
public boolean supportsCustomEditor() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -481,12 +481,39 @@ public class HTMLUtilities {
|
|||
}
|
||||
|
||||
/**
|
||||
* This is just a convenience call to {@link #friendlyEncodeHTML(String, boolean)} with a
|
||||
* value of <tt>true</tt>.
|
||||
* Converts any special or reserved characters in the specified string into HTML-escaped
|
||||
* entities. Use this method when you have content containing HTML that you do not want
|
||||
* interpreted as HTML, such as when displaying text that uses angle brackets around words.
|
||||
*
|
||||
* <P>For example, consider the following<br><br>
|
||||
*
|
||||
* <table border=1>
|
||||
* <tr>
|
||||
* <th>Input</th><th>Output</th><th>Rendered as</th><th>(Without Friendly Encoding)</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>
|
||||
* Hi <b>mom </b>
|
||||
* </td>
|
||||
* <td>
|
||||
* Hi<font color="green">
|
||||
* &nbsp;<b>&lt;</b></font>b<font color="green"><b>&gt;</b></font>mom
|
||||
* <font color="green">&nbsp;<b>&lt;</b></font>/b<font color="green"><b>&gt;</b>
|
||||
* </font>
|
||||
* </td>
|
||||
* <td>
|
||||
* Hi <b>mom </b>
|
||||
* </td>
|
||||
* <td>
|
||||
* Hi <b>mom </b>
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <br><br><br>
|
||||
*
|
||||
* @param text string to be encoded
|
||||
* @return the encoded HTML string
|
||||
* @see #friendlyEncodeHTML(String, boolean)
|
||||
*/
|
||||
public static String friendlyEncodeHTML(String text) {
|
||||
return friendlyEncodeHTML(text, true);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,8 +17,6 @@ package ghidra.util.layout;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* This layout arranges components in columns, putting as many components as possible in a
|
||||
* column and using as many columns as necessary.
|
||||
|
@ -42,117 +39,97 @@ public class ColumnLayout implements LayoutManager {
|
|||
this.vgap = vgap;
|
||||
this.preferredNumCols = preferredNumCols;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#addLayoutComponent(String, Component)
|
||||
*/
|
||||
@Override
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#removeLayoutComponent(Component)
|
||||
*/
|
||||
@Override
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#preferredLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
int n = parent.getComponentCount();
|
||||
computeComponentSize(parent);
|
||||
|
||||
int numRows = (n + preferredNumCols-1) / preferredNumCols;
|
||||
int numCols = (n+numRows-1) / numRows;
|
||||
|
||||
int height = numRows*compHeight + (numRows-1)*vgap;
|
||||
int width = numCols*compWidth + (numCols-1)*hgap;
|
||||
Dimension d = new Dimension(width+insets.left+insets.right+2,
|
||||
height+insets.top + insets.bottom+2);
|
||||
|
||||
int numRows = (n + preferredNumCols - 1) / preferredNumCols;
|
||||
int numCols = (n + numRows - 1) / numRows;
|
||||
|
||||
int height = numRows * compHeight + (numRows - 1) * vgap;
|
||||
int width = numCols * compWidth + (numCols - 1) * hgap;
|
||||
Dimension d = new Dimension(width + insets.left + insets.right + 2,
|
||||
height + insets.top + insets.bottom + 2);
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#minimumLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
return new Dimension(compWidth + insets.left + insets.right,
|
||||
compHeight+insets.top+insets.bottom);
|
||||
compHeight + insets.top + insets.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#layoutContainer(Container)
|
||||
*/
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
int n = parent.getComponentCount();
|
||||
if (n == 0) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
computeComponentSize(parent);
|
||||
Dimension d = parent.getSize();
|
||||
Insets insets = parent.getInsets();
|
||||
int parentWidth = d.width - insets.left - insets.right;
|
||||
int parentHeight = d.height - insets.top - insets.bottom;
|
||||
int maxRows = (parentHeight +vgap)/compHeight+vgap;
|
||||
int maxRows = (parentHeight + vgap) / compHeight + vgap;
|
||||
if (maxRows == 0) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
int numCols = (n + maxRows -1) / maxRows;
|
||||
int numRows = (n + numCols -1) / numCols;
|
||||
int left = insets.left + (parentWidth - numCols*compWidth- (numCols-1)*hgap)/2;
|
||||
int numCols = (n + maxRows - 1) / maxRows;
|
||||
int numRows = (n + numCols - 1) / numCols;
|
||||
int left = insets.left + (parentWidth - numCols * compWidth - (numCols - 1) * hgap) / 2;
|
||||
int top = insets.top;
|
||||
|
||||
for(int i = 0;i<numRows;i++) {
|
||||
for(int j = 0;j<numCols;j++) {
|
||||
int x = left + j*(compWidth+hgap);
|
||||
int y = top + i*(compHeight+vgap);
|
||||
int k = j*numRows+i;
|
||||
|
||||
for (int i = 0; i < numRows; i++) {
|
||||
for (int j = 0; j < numCols; j++) {
|
||||
int x = left + j * (compWidth + hgap);
|
||||
int y = top + i * (compHeight + vgap);
|
||||
int k = j * numRows + i;
|
||||
if (k < n) {
|
||||
Component c= parent.getComponent(k);
|
||||
Component c = parent.getComponent(k);
|
||||
c.setBounds(x, y, compWidth, compHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test main
|
||||
* @param args execution arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
System.out.println("Error loading L&F: " + exc);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Test");
|
||||
JPanel panel = new JPanel(new ColumnLayout(0,0,2));
|
||||
panel.add(new JLabel("One ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Two ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Three ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Four ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("This is a test of the ",SwingConstants.LEFT));
|
||||
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
private void computeComponentSize(Container parent) {
|
||||
int n = parent.getComponentCount();
|
||||
compWidth = 0;
|
||||
compHeight = 0;
|
||||
|
||||
|
||||
for(int i=0;i<n;i++) {
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
Component c = parent.getComponent(i);
|
||||
Dimension d = c.getPreferredSize();
|
||||
compWidth = Math.max(compWidth, d.width);
|
||||
compHeight = Math.max(compHeight, d.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,15 +17,13 @@ package ghidra.util.layout;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* LayoutManager for arranging components in a single row. All components
|
||||
* retain their preferred widths, but are sized to the same height.
|
||||
*/
|
||||
public class HorizontalLayout implements LayoutManager {
|
||||
int hgap;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for HorizontalLayout.
|
||||
* @param hgap gap (in pixels) between components.
|
||||
|
@ -34,39 +31,45 @@ public class HorizontalLayout implements LayoutManager {
|
|||
public HorizontalLayout(int hgap) {
|
||||
this.hgap = hgap;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see LayoutManager#addLayoutComponent(String, Component)
|
||||
*/
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
@Override
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#removeLayoutComponent(Component)
|
||||
*/
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
@Override
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#preferredLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
int n = parent.getComponentCount();
|
||||
int height = 0;
|
||||
int width = n > 1 ? (n-1)*hgap : 0;
|
||||
int width = n > 1 ? (n - 1) * hgap : 0;
|
||||
|
||||
for(int i=0;i<n;i++) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
Component c = parent.getComponent(i);
|
||||
Dimension d = c.getPreferredSize();
|
||||
width += d.width;
|
||||
height = Math.max(height, d.height);
|
||||
}
|
||||
return new Dimension(width+insets.left+insets.right,
|
||||
height+insets.top + insets.bottom);
|
||||
}
|
||||
}
|
||||
return new Dimension(width + insets.left + insets.right,
|
||||
height + insets.top + insets.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#minimumLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return preferredLayoutSize(parent);
|
||||
}
|
||||
|
@ -74,6 +77,7 @@ public class HorizontalLayout implements LayoutManager {
|
|||
/**
|
||||
* @see LayoutManager#layoutContainer(Container)
|
||||
*/
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
int n = parent.getComponentCount();
|
||||
Dimension d = parent.getSize();
|
||||
|
@ -82,36 +86,13 @@ public class HorizontalLayout implements LayoutManager {
|
|||
|
||||
int x = insets.left;
|
||||
int y = insets.top;
|
||||
|
||||
for(int i=0;i<n;i++) {
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
Component c = parent.getComponent(i);
|
||||
d = c.getPreferredSize();
|
||||
c.setBounds(x,y,d.width,height);
|
||||
c.setBounds(x, y, d.width, height);
|
||||
x += d.width + hgap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test main
|
||||
* @param args execution parameters
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
System.out.println("Error loading L&F: " + exc);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Test");
|
||||
JPanel panel = new JPanel(new HorizontalLayout(10));
|
||||
panel.add(new JLabel("One",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Two",SwingConstants.RIGHT));
|
||||
panel.add(new JLabel("Three",SwingConstants.CENTER));
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,8 +17,6 @@ package ghidra.util.layout;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* <CODE>MaximizeSpecificColumnGridLayout</CODE> is a row oriented grid type of layout.
|
||||
* It lays out rows of information in a table format using a specific number of columns.
|
||||
|
@ -181,9 +178,9 @@ public class MaximizeSpecificColumnGridLayout implements LayoutManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
averageMaximizedWidth =
|
||||
(remainingMaximizedCount > 0) ? (remainingMaximizedWidth / remainingMaximizedCount)
|
||||
: 0;
|
||||
averageMaximizedWidth = (remainingMaximizedCount > 0)
|
||||
? (remainingMaximizedWidth / remainingMaximizedCount)
|
||||
: 0;
|
||||
}
|
||||
|
||||
// Now just divide up whatever width remains among whatever maximized columns remain.
|
||||
|
@ -283,175 +280,4 @@ public class MaximizeSpecificColumnGridLayout implements LayoutManager {
|
|||
public void removeLayoutComponent(Component comp) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
/**
|
||||
* Test main
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
System.out.println("Error loading L&F: " + exc);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Test");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
MaximizeSpecificColumnGridLayout layout = new MaximizeSpecificColumnGridLayout(5, 5, 3);
|
||||
layout.maximizeColumn(0);
|
||||
layout.maximizeColumn(2);
|
||||
JPanel panel = new JPanel(layout);
|
||||
panel.add(new MyLabel("<HTML><B><U>Version</U></B></HTML>", SwingConstants.LEFT));
|
||||
panel.add(new MyLabel("<HTML><B><U>Description</U></B></HTML>", SwingConstants.LEFT));
|
||||
panel.add(new MyLabel("<HTML><B><U>Other</U></B></HTML>", SwingConstants.LEFT));
|
||||
panel.add(new MyRadioButton("Latest"));
|
||||
panel.add(new MyLabel("What else?", SwingConstants.LEFT));
|
||||
panel.add(new MyLabel("Some sample text.\nOnce upon a time in a land far far away",
|
||||
SwingConstants.LEFT));
|
||||
panel.add(new MyRadioButton("CheckedOut"));
|
||||
panel.add(new MyLabel("Six", SwingConstants.LEFT));
|
||||
panel.add(new MyLabel("Seven", SwingConstants.LEFT));
|
||||
panel.add(new MyCheckBox("Test Check Box"));
|
||||
panel.add(new MyLabel("AAA", SwingConstants.LEFT));
|
||||
panel.add(new MyLabel("BBB", SwingConstants.LEFT));
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(8, 25, 10, 10));
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class MyCheckBox extends JCheckBox {
|
||||
|
||||
public MyCheckBox() {
|
||||
super();
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyCheckBox(Action a) {
|
||||
super(a);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyCheckBox(Icon icon, boolean selected) {
|
||||
super(icon, selected);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyCheckBox(Icon icon) {
|
||||
super(icon);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyCheckBox(String text, boolean selected) {
|
||||
super(text, selected);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyCheckBox(String text, Icon icon, boolean selected) {
|
||||
super(text, icon, selected);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyCheckBox(String text, Icon icon) {
|
||||
super(text, icon);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyCheckBox(String text) {
|
||||
super(text);
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
setVerticalAlignment(SwingConstants.TOP);
|
||||
setToolTipText(getText());
|
||||
}
|
||||
}
|
||||
|
||||
class MyRadioButton extends JRadioButton {
|
||||
|
||||
public MyRadioButton() {
|
||||
super();
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyRadioButton(Action a) {
|
||||
super(a);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyRadioButton(Icon icon, boolean selected) {
|
||||
super(icon, selected);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyRadioButton(Icon icon) {
|
||||
super(icon);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyRadioButton(String text, boolean selected) {
|
||||
super(text, selected);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyRadioButton(String text, Icon icon, boolean selected) {
|
||||
super(text, icon, selected);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyRadioButton(String text, Icon icon) {
|
||||
super(text, icon);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyRadioButton(String text) {
|
||||
super(text);
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
setVerticalAlignment(SwingConstants.TOP);
|
||||
setToolTipText(getText());
|
||||
}
|
||||
}
|
||||
|
||||
class MyLabel extends JLabel {
|
||||
|
||||
public MyLabel() {
|
||||
super();
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyLabel(Icon image, int horizontalAlignment) {
|
||||
super(image, horizontalAlignment);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyLabel(Icon image) {
|
||||
super(image);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyLabel(String text, Icon icon, int horizontalAlignment) {
|
||||
super(text, icon, horizontalAlignment);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyLabel(String text, int horizontalAlignment) {
|
||||
super(text, horizontalAlignment);
|
||||
initialize();
|
||||
}
|
||||
|
||||
public MyLabel(String text) {
|
||||
super(text);
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
setVerticalAlignment(SwingConstants.TOP);
|
||||
setToolTipText(getText());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,8 +17,6 @@ package ghidra.util.layout;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* LayoutManger for arranging components into exactly two columns. The right column and the
|
||||
* left column may have differing widths. Also, each row is the same height,
|
||||
|
@ -29,15 +26,15 @@ public class PairLayout implements LayoutManager {
|
|||
private static final int MINIMUM_RIGHT_COLUMN_WIDTH = 80;
|
||||
private int vgap;
|
||||
private int hgap;
|
||||
|
||||
private int preferredRightColumnWidth;
|
||||
|
||||
private int preferredRightColumnWidth;
|
||||
private int leftColumnWidth;
|
||||
private int rowHeight;
|
||||
|
||||
|
||||
public PairLayout() {
|
||||
this(0,0,MINIMUM_RIGHT_COLUMN_WIDTH);
|
||||
this(0, 0, MINIMUM_RIGHT_COLUMN_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new PairLayout.
|
||||
* @param vgap the gap (in pixels) between rows.
|
||||
|
@ -46,7 +43,7 @@ public class PairLayout implements LayoutManager {
|
|||
public PairLayout(int vgap, int hgap) {
|
||||
this(vgap, hgap, MINIMUM_RIGHT_COLUMN_WIDTH);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a new PairLayout.
|
||||
* @param vgap the gap (in pixels) between rows.
|
||||
|
@ -58,51 +55,59 @@ public class PairLayout implements LayoutManager {
|
|||
this.hgap = hgap;
|
||||
this.preferredRightColumnWidth = minimumRightColumnWidth;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @see LayoutManager#addLayoutComponent(String, Component)
|
||||
*/
|
||||
public void addLayoutComponent(String name, Component comp) {}
|
||||
@Override
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#removeLayoutComponent(Component)
|
||||
*/
|
||||
public void removeLayoutComponent(Component comp) {}
|
||||
@Override
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#preferredLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
computeSizes(parent);
|
||||
int rowCount = (parent.getComponentCount() + 1) / 2;
|
||||
Insets insets = parent.getInsets();
|
||||
Dimension d = new Dimension(0,0);
|
||||
Dimension d = new Dimension(0, 0);
|
||||
d.width = leftColumnWidth + hgap + preferredRightColumnWidth + insets.left + insets.right;
|
||||
d.height = rowHeight * rowCount + vgap * (rowCount-1) + insets.top + insets.bottom;
|
||||
d.height = rowHeight * rowCount + vgap * (rowCount - 1) + insets.top + insets.bottom;
|
||||
return d;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return preferredLayoutSize(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
computeSizes(parent);
|
||||
int componentCount = parent.getComponentCount();
|
||||
int rowCount = (componentCount+1) / 2;
|
||||
int rowCount = (componentCount + 1) / 2;
|
||||
Dimension d = parent.getSize();
|
||||
Insets insets = parent.getInsets();
|
||||
int width = d.width - (insets.left + insets.right);
|
||||
int x = insets.left;
|
||||
int y = insets.top;
|
||||
int rightColumnWidth = width - (leftColumnWidth + hgap);
|
||||
int rightColumnWidth = width - (leftColumnWidth + hgap);
|
||||
|
||||
for(int i=0;i<rowCount;i++) {
|
||||
Component leftColumnComponent = parent.getComponent(i*2);
|
||||
leftColumnComponent.setBounds(x,y,leftColumnWidth,rowHeight);
|
||||
if (componentCount > i*2+1) {
|
||||
Component rightColumnComponent = parent.getComponent(i*2+1);
|
||||
rightColumnComponent.setBounds(x+leftColumnWidth+hgap, y, rightColumnWidth, rowHeight);
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
Component leftColumnComponent = parent.getComponent(i * 2);
|
||||
leftColumnComponent.setBounds(x, y, leftColumnWidth, rowHeight);
|
||||
if (componentCount > i * 2 + 1) {
|
||||
Component rightColumnComponent = parent.getComponent(i * 2 + 1);
|
||||
rightColumnComponent.setBounds(x + leftColumnWidth + hgap, y, rightColumnWidth,
|
||||
rowHeight);
|
||||
y += rowHeight + vgap;
|
||||
}
|
||||
}
|
||||
|
@ -110,52 +115,25 @@ public class PairLayout implements LayoutManager {
|
|||
|
||||
private void computeSizes(Container parent) {
|
||||
int componentCount = parent.getComponentCount();
|
||||
int rowCount = (componentCount+1) / 2;
|
||||
int rowCount = (componentCount + 1) / 2;
|
||||
|
||||
leftColumnWidth = 0;
|
||||
rowHeight = 0;
|
||||
rowHeight = 0;
|
||||
|
||||
for( int i = 0; i < rowCount; i++ ) {
|
||||
Component leftColumnComponent = parent.getComponent(i*2);
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
Component leftColumnComponent = parent.getComponent(i * 2);
|
||||
Dimension d = leftColumnComponent.getPreferredSize();
|
||||
leftColumnWidth = Math.max(leftColumnWidth, d.width);
|
||||
rowHeight = Math.max(rowHeight, d.height);
|
||||
|
||||
if ( componentCount > i*2+1 ) {
|
||||
Component rightColumnComponent = parent.getComponent(i*2+1);
|
||||
|
||||
if (componentCount > i * 2 + 1) {
|
||||
Component rightColumnComponent = parent.getComponent(i * 2 + 1);
|
||||
d = rightColumnComponent.getPreferredSize();
|
||||
rowHeight = Math.max(rowHeight, d.height);
|
||||
preferredRightColumnWidth = Math.max(preferredRightColumnWidth, d.width);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test main
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
System.out.println("Error loading L&F: " + exc);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Test");
|
||||
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
|
||||
JPanel panel = new JPanel(new PairLayout(10,20,100));
|
||||
panel.add(new JLabel("One",SwingConstants.RIGHT));
|
||||
panel.add(new JTextField());
|
||||
panel.add(new JLabel("Two",SwingConstants.RIGHT));
|
||||
panel.add(new JTextField());
|
||||
panel.add(new JLabel("Three",SwingConstants.RIGHT));
|
||||
panel.add(new JTextField());
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(8,25,10,10));
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -53,62 +52,68 @@ public class RowColumnLayout implements LayoutManager {
|
|||
this.maxSize = maxSize;
|
||||
this.fillOrder = LEFT_TO_RIGHT;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#addLayoutComponent(String, Component)
|
||||
*/
|
||||
@Override
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#removeLayoutComponent(Component)
|
||||
*/
|
||||
@Override
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#preferredLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
int n = parent.getComponentCount();
|
||||
computeComponentSize(parent);
|
||||
|
||||
|
||||
int numRows = 1;
|
||||
int numCols = 1;
|
||||
|
||||
|
||||
if (orientation == ROW) {
|
||||
int width = Math.max(maxSize-insets.left-insets.right, compWidth);
|
||||
numCols = (width+hgap)/(compWidth + hgap);
|
||||
numRows = (n+numCols-1) / numCols;
|
||||
numCols = (n+numRows-1) / numRows;
|
||||
int width = Math.max(maxSize - insets.left - insets.right, compWidth);
|
||||
numCols = (width + hgap) / (compWidth + hgap);
|
||||
numRows = (n + numCols - 1) / numCols;
|
||||
numCols = (n + numRows - 1) / numRows;
|
||||
}
|
||||
else {
|
||||
int height = Math.max(maxSize-insets.top-insets.left, compHeight);
|
||||
numRows = (height+vgap)/(compHeight + vgap);
|
||||
numCols = (n+numRows-1) / numRows;
|
||||
numRows = (n+numCols-1) / numCols;
|
||||
else {
|
||||
int height = Math.max(maxSize - insets.top - insets.left, compHeight);
|
||||
numRows = (height + vgap) / (compHeight + vgap);
|
||||
numCols = (n + numRows - 1) / numRows;
|
||||
numRows = (n + numCols - 1) / numCols;
|
||||
}
|
||||
|
||||
int height = numRows*compHeight + (numRows-1)*vgap;
|
||||
int width = numCols*compWidth + (numCols-1)*hgap;
|
||||
Dimension d = new Dimension(width+insets.left+insets.right+2,
|
||||
height+insets.top + insets.bottom+2);
|
||||
|
||||
int height = numRows * compHeight + (numRows - 1) * vgap;
|
||||
int width = numCols * compWidth + (numCols - 1) * hgap;
|
||||
Dimension d = new Dimension(width + insets.left + insets.right + 2,
|
||||
height + insets.top + insets.bottom + 2);
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#minimumLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
return new Dimension(compWidth + insets.left + insets.right,
|
||||
compHeight+insets.top+insets.bottom);
|
||||
compHeight + insets.top + insets.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#layoutContainer(Container)
|
||||
*/
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
|
||||
computeComponentSize(parent);
|
||||
|
@ -117,83 +122,61 @@ public class RowColumnLayout implements LayoutManager {
|
|||
Insets insets = parent.getInsets();
|
||||
int parentWidth = d.width - insets.left - insets.right;
|
||||
int parentHeight = d.height - insets.top - insets.bottom;
|
||||
|
||||
|
||||
int numRows = 1;
|
||||
int numCols = 1;
|
||||
if (orientation == ROW) {
|
||||
numCols = (parentWidth +hgap)/(compWidth+hgap);
|
||||
if (numCols < 1) numCols = 1;
|
||||
numRows = (n + numCols -1) / numCols;
|
||||
numCols = (n + numRows -1) / numRows;
|
||||
numCols = (parentWidth + hgap) / (compWidth + hgap);
|
||||
if (numCols < 1) {
|
||||
numCols = 1;
|
||||
}
|
||||
numRows = (n + numCols - 1) / numCols;
|
||||
numCols = (n + numRows - 1) / numRows;
|
||||
}
|
||||
else {
|
||||
numRows = (parentHeight +vgap)/(compHeight+vgap);
|
||||
if (numRows < 1) numRows = 1;
|
||||
numCols = (n + numRows -1) / numRows;
|
||||
numRows = (n + numCols -1) / numCols;
|
||||
numRows = (parentHeight + vgap) / (compHeight + vgap);
|
||||
if (numRows < 1) {
|
||||
numRows = 1;
|
||||
}
|
||||
numCols = (n + numRows - 1) / numRows;
|
||||
numRows = (n + numCols - 1) / numCols;
|
||||
}
|
||||
|
||||
|
||||
// int left = insets.left + (parentWidth - numCols*compWidth- (numCols-1)*hgap)/2;
|
||||
// int top = insets.top + (parentHeight - numRows*compHeight - (numRows-1)*vgap)/2;
|
||||
int left = insets.left;
|
||||
int top = insets.top;
|
||||
|
||||
for(int i = 0;i<numRows;i++) {
|
||||
for(int j = 0;j<numCols;j++) {
|
||||
int x = left + j*(compWidth+hgap);
|
||||
int y = top + i*(compHeight+vgap);
|
||||
int k = fillOrder == LEFT_TO_RIGHT ? i*numCols+j : j*numRows+i;
|
||||
|
||||
for (int i = 0; i < numRows; i++) {
|
||||
for (int j = 0; j < numCols; j++) {
|
||||
int x = left + j * (compWidth + hgap);
|
||||
int y = top + i * (compHeight + vgap);
|
||||
int k = fillOrder == LEFT_TO_RIGHT ? i * numCols + j : j * numRows + i;
|
||||
if (k < n) {
|
||||
Component c= parent.getComponent(k);
|
||||
Component c = parent.getComponent(k);
|
||||
c.setBounds(x, y, compWidth, compHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * Test main
|
||||
// * @param args execution arguments
|
||||
// */
|
||||
// public static void main(String[] args) {
|
||||
// try {
|
||||
// UIManager.setLookAndFeel(
|
||||
// UIManager.getSystemLookAndFeelClassName());
|
||||
// }
|
||||
// catch (Exception exc) {
|
||||
// System.out.println("Error loading L&F: " + exc);
|
||||
// }
|
||||
//
|
||||
// JFrame frame = new JFrame("Test");
|
||||
// JPanel panel = new JPanel(new RowColumnLayout(0,0,2));
|
||||
// panel.add(new JLabel("One ",JLabel.LEFT));
|
||||
// panel.add(new JLabel("Two ",JLabel.LEFT));
|
||||
// panel.add(new JLabel("Three ",JLabel.LEFT));
|
||||
// panel.add(new JLabel("Four ",JLabel.LEFT));
|
||||
// panel.add(new JLabel("This is a test of the ",JLabel.LEFT));
|
||||
//
|
||||
// panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||
// frame.getContentPane().add(panel);
|
||||
// frame.pack();
|
||||
// frame.show();
|
||||
// }
|
||||
|
||||
private void computeComponentSize(Container parent) {
|
||||
int n = parent.getComponentCount();
|
||||
compWidth = 0;
|
||||
compHeight = 0;
|
||||
|
||||
|
||||
for(int i=0;i<n;i++) {
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
Component c = parent.getComponent(i);
|
||||
Dimension d = c.getPreferredSize();
|
||||
compWidth = Math.max(compWidth, d.width);
|
||||
compHeight = Math.max(compHeight, d.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param maxSize
|
||||
*/
|
||||
public void setMaxSize(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
this.maxSize = maxSize;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,8 +17,6 @@ package ghidra.util.layout;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* This layout arranges components in rows, putting as many components as possible on a
|
||||
* row and using as many rows as necessary.
|
||||
|
@ -42,49 +39,55 @@ public class RowLayout implements LayoutManager {
|
|||
this.vgap = vgap;
|
||||
this.preferredNumRows = preferredNumRows;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#addLayoutComponent(String, Component)
|
||||
*/
|
||||
@Override
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#removeLayoutComponent(Component)
|
||||
*/
|
||||
@Override
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#preferredLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
int n = parent.getComponentCount();
|
||||
computeComponentSize(parent);
|
||||
|
||||
int numCols = (n + preferredNumRows-1) / preferredNumRows;
|
||||
int numRows = (n+numCols-1) / numCols;
|
||||
|
||||
int height = numRows*compHeight + (numRows-1)*vgap;
|
||||
int width = numCols*compWidth + (numCols-1)*hgap;
|
||||
Dimension d = new Dimension(width+insets.left+insets.right+2,
|
||||
height+insets.top + insets.bottom+2);
|
||||
|
||||
int numCols = (n + preferredNumRows - 1) / preferredNumRows;
|
||||
int numRows = (n + numCols - 1) / numCols;
|
||||
|
||||
int height = numRows * compHeight + (numRows - 1) * vgap;
|
||||
int width = numCols * compWidth + (numCols - 1) * hgap;
|
||||
Dimension d = new Dimension(width + insets.left + insets.right + 2,
|
||||
height + insets.top + insets.bottom + 2);
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#minimumLayoutSize(Container)
|
||||
*/
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
Insets insets = parent.getInsets();
|
||||
return new Dimension(compWidth + insets.left + insets.right,
|
||||
compHeight+insets.top+insets.bottom);
|
||||
compHeight + insets.top + insets.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see LayoutManager#layoutContainer(Container)
|
||||
*/
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
|
||||
computeComponentSize(parent);
|
||||
|
@ -94,61 +97,35 @@ public class RowLayout implements LayoutManager {
|
|||
int parentWidth = d.width - insets.left - insets.right;
|
||||
//int parentHeight = d.height - insets.top - insets.bottom;
|
||||
|
||||
int maxCols = (parentWidth +hgap)/(compWidth+hgap);
|
||||
int numRows = (n + maxCols -1) / maxCols;
|
||||
int numCols = (n + numRows -1) / numRows;
|
||||
int left = insets.left + (parentWidth - numCols*compWidth- (numCols-1)*hgap)/2;
|
||||
int maxCols = (parentWidth + hgap) / (compWidth + hgap);
|
||||
int numRows = (n + maxCols - 1) / maxCols;
|
||||
int numCols = (n + numRows - 1) / numRows;
|
||||
int left = insets.left + (parentWidth - numCols * compWidth - (numCols - 1) * hgap) / 2;
|
||||
int top = insets.top;
|
||||
|
||||
for(int i = 0;i<numRows;i++) {
|
||||
for(int j = 0;j<numCols;j++) {
|
||||
int x = left + j*(compWidth+hgap);
|
||||
int y = top + i*(compHeight+vgap);
|
||||
int k = i*numCols+j;
|
||||
|
||||
for (int i = 0; i < numRows; i++) {
|
||||
for (int j = 0; j < numCols; j++) {
|
||||
int x = left + j * (compWidth + hgap);
|
||||
int y = top + i * (compHeight + vgap);
|
||||
int k = i * numCols + j;
|
||||
if (k < n) {
|
||||
Component c= parent.getComponent(k);
|
||||
Component c = parent.getComponent(k);
|
||||
c.setBounds(x, y, compWidth, compHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Test main
|
||||
* @param args execution arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
System.out.println("Error loading L&F: " + exc);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Test");
|
||||
JPanel panel = new JPanel(new RowLayout(0,0,2));
|
||||
panel.add(new JLabel("One ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Two ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Three ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Four ",SwingConstants.LEFT));
|
||||
panel.add(new JLabel("This is a test of the ",SwingConstants.LEFT));
|
||||
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
private void computeComponentSize(Container parent) {
|
||||
int n = parent.getComponentCount();
|
||||
compWidth = 0;
|
||||
compHeight = 0;
|
||||
|
||||
|
||||
for(int i=0;i<n;i++) {
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
Component c = parent.getComponent(i);
|
||||
Dimension d = c.getPreferredSize();
|
||||
compWidth = Math.max(compWidth, d.width);
|
||||
compHeight = Math.max(compHeight, d.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,148 +17,124 @@ package ghidra.util.layout;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
public class VariableRowHeightGridLayout implements LayoutManager {
|
||||
|
||||
private int vgap;
|
||||
private int hgap;
|
||||
private final int columnCount;
|
||||
|
||||
public VariableRowHeightGridLayout( int columnCount ) {
|
||||
this(0,0,columnCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new PairLayout.
|
||||
* @param vgap the gap (in pixels) between rows.
|
||||
* @param hgap the gap (in pixels) between the two columns.
|
||||
* @param columnCount the number of columns in this grid
|
||||
*/
|
||||
public VariableRowHeightGridLayout(int vgap, int hgap, int columnCount) {
|
||||
this.vgap = vgap;
|
||||
this.hgap = hgap;
|
||||
|
||||
if ( columnCount <= 0 ) {
|
||||
columnCount = 1;
|
||||
}
|
||||
|
||||
this.columnCount = columnCount;
|
||||
}
|
||||
private int vgap;
|
||||
private int hgap;
|
||||
private final int columnCount;
|
||||
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
int componentCount = parent.getComponentCount();
|
||||
int rowCount = (componentCount + (columnCount-1) ) / columnCount;
|
||||
Insets insets = parent.getInsets();
|
||||
Dimension d = new Dimension(0,0);
|
||||
int totalComponentHeight = 0;
|
||||
for ( int i = 0; i < rowCount; i++ ) {
|
||||
totalComponentHeight += getRowHeight( parent, i );
|
||||
}
|
||||
|
||||
int totalColumns = Math.min( columnCount, componentCount );
|
||||
int totalComponentWidth = getPreferredColumnWidth( parent ) * totalColumns;
|
||||
d.width = totalComponentWidth + hgap * (columnCount-1) + insets.left + insets.right;
|
||||
d.height = totalComponentHeight + vgap * (rowCount-1) + insets.top + insets.bottom;
|
||||
return d;
|
||||
}
|
||||
|
||||
private int getRowHeight( Container parent, int row ) {
|
||||
int rowHeight = 0;
|
||||
int componentCount = parent.getComponentCount();
|
||||
for ( int i = 0; i < columnCount; i++ ) {
|
||||
int ordinal = row * columnCount + i;
|
||||
if ( ordinal >= componentCount ) {
|
||||
// this implies uneven components (can't fill the last row)
|
||||
return rowHeight;
|
||||
}
|
||||
|
||||
Component component = parent.getComponent( ordinal );
|
||||
Dimension d = component.getPreferredSize();
|
||||
rowHeight = Math.max( rowHeight, d.height );
|
||||
}
|
||||
return rowHeight;
|
||||
}
|
||||
|
||||
private int getPreferredColumnWidth( Container parent ) {
|
||||
int width = 0;
|
||||
int componentCount = parent.getComponentCount();
|
||||
for ( int i = 0; i < componentCount; i++ ) {
|
||||
Component component = parent.getComponent( i );
|
||||
Dimension d = component.getPreferredSize();
|
||||
width = Math.max( width, d.width );
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return preferredLayoutSize(parent);
|
||||
}
|
||||
public VariableRowHeightGridLayout(int columnCount) {
|
||||
this(0, 0, columnCount);
|
||||
}
|
||||
|
||||
public void layoutContainer(Container parent) {
|
||||
int componentCount = parent.getComponentCount();
|
||||
int rowCount = (componentCount + (columnCount-1) ) / columnCount;
|
||||
Dimension d = parent.getSize();
|
||||
Insets insets = parent.getInsets();
|
||||
int width = d.width - (insets.left + insets.right);
|
||||
int totalColumns = Math.min( columnCount, componentCount );
|
||||
int availableColumnWidth = (width - (columnCount - 1) * hgap) / totalColumns;
|
||||
int columnWidth = getColumnWidth( parent, availableColumnWidth );
|
||||
int y = insets.top;
|
||||
for ( int i = 0; i < rowCount; i++ ) {
|
||||
int x = insets.left;
|
||||
int rowHeight = getRowHeight( parent, i );
|
||||
for ( int j = 0; j < columnCount; j++ ) {
|
||||
int ordinal = i * columnCount + j;
|
||||
if ( ordinal >= componentCount ) {
|
||||
// this implies uneven components (can't fill the last row)
|
||||
break;
|
||||
}
|
||||
Component component = parent.getComponent( ordinal );
|
||||
component.setBounds( x, y, columnWidth, rowHeight );
|
||||
x += columnWidth + hgap;
|
||||
}
|
||||
y += rowHeight + vgap;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Constructs a new PairLayout.
|
||||
* @param vgap the gap (in pixels) between rows.
|
||||
* @param hgap the gap (in pixels) between the two columns.
|
||||
* @param columnCount the number of columns in this grid
|
||||
*/
|
||||
public VariableRowHeightGridLayout(int vgap, int hgap, int columnCount) {
|
||||
this.vgap = vgap;
|
||||
this.hgap = hgap;
|
||||
|
||||
private int getColumnWidth( Container parent, int availableColumnWidth ) {
|
||||
return availableColumnWidth;
|
||||
}
|
||||
if (columnCount <= 0) {
|
||||
columnCount = 1;
|
||||
}
|
||||
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
// ignore
|
||||
}
|
||||
this.columnCount = columnCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension preferredLayoutSize(Container parent) {
|
||||
int componentCount = parent.getComponentCount();
|
||||
int rowCount = (componentCount + (columnCount - 1)) / columnCount;
|
||||
Insets insets = parent.getInsets();
|
||||
Dimension d = new Dimension(0, 0);
|
||||
int totalComponentHeight = 0;
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
totalComponentHeight += getRowHeight(parent, i);
|
||||
}
|
||||
|
||||
int totalColumns = Math.min(columnCount, componentCount);
|
||||
int totalComponentWidth = getPreferredColumnWidth(parent) * totalColumns;
|
||||
d.width = totalComponentWidth + hgap * (columnCount - 1) + insets.left + insets.right;
|
||||
d.height = totalComponentHeight + vgap * (rowCount - 1) + insets.top + insets.bottom;
|
||||
return d;
|
||||
}
|
||||
|
||||
private int getRowHeight(Container parent, int row) {
|
||||
int rowHeight = 0;
|
||||
int componentCount = parent.getComponentCount();
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
int ordinal = row * columnCount + i;
|
||||
if (ordinal >= componentCount) {
|
||||
// this implies uneven components (can't fill the last row)
|
||||
return rowHeight;
|
||||
}
|
||||
|
||||
Component component = parent.getComponent(ordinal);
|
||||
Dimension d = component.getPreferredSize();
|
||||
rowHeight = Math.max(rowHeight, d.height);
|
||||
}
|
||||
return rowHeight;
|
||||
}
|
||||
|
||||
private int getPreferredColumnWidth(Container parent) {
|
||||
int width = 0;
|
||||
int componentCount = parent.getComponentCount();
|
||||
for (int i = 0; i < componentCount; i++) {
|
||||
Component component = parent.getComponent(i);
|
||||
Dimension d = component.getPreferredSize();
|
||||
width = Math.max(width, d.width);
|
||||
}
|
||||
return width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension minimumLayoutSize(Container parent) {
|
||||
return preferredLayoutSize(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void layoutContainer(Container parent) {
|
||||
int componentCount = parent.getComponentCount();
|
||||
int rowCount = (componentCount + (columnCount - 1)) / columnCount;
|
||||
Dimension d = parent.getSize();
|
||||
Insets insets = parent.getInsets();
|
||||
int width = d.width - (insets.left + insets.right);
|
||||
int totalColumns = Math.min(columnCount, componentCount);
|
||||
int availableColumnWidth = (width - (columnCount - 1) * hgap) / totalColumns;
|
||||
int columnWidth = getColumnWidth(parent, availableColumnWidth);
|
||||
int y = insets.top;
|
||||
for (int i = 0; i < rowCount; i++) {
|
||||
int x = insets.left;
|
||||
int rowHeight = getRowHeight(parent, i);
|
||||
for (int j = 0; j < columnCount; j++) {
|
||||
int ordinal = i * columnCount + j;
|
||||
if (ordinal >= componentCount) {
|
||||
// this implies uneven components (can't fill the last row)
|
||||
break;
|
||||
}
|
||||
Component component = parent.getComponent(ordinal);
|
||||
component.setBounds(x, y, columnWidth, rowHeight);
|
||||
x += columnWidth + hgap;
|
||||
}
|
||||
y += rowHeight + vgap;
|
||||
}
|
||||
}
|
||||
|
||||
private int getColumnWidth(Container parent, int availableColumnWidth) {
|
||||
return availableColumnWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addLayoutComponent(String name, Component comp) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
public void removeLayoutComponent(Component comp) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
/**
|
||||
* Test main
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(
|
||||
UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
System.out.println("Error loading L&F: " + exc);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Test");
|
||||
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
|
||||
JPanel panel = new JPanel(new VariableRowHeightGridLayout(1, 5, 15));
|
||||
panel.add(new JLabel("One",SwingConstants.RIGHT));
|
||||
panel.add(new JTextField());
|
||||
panel.add(new JLabel("Two",SwingConstants.RIGHT));
|
||||
panel.add(new JTextField());
|
||||
panel.add(new JLabel("Three",SwingConstants.RIGHT));
|
||||
panel.add(new JTextField());
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(8,25,10,10));
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -18,8 +17,6 @@ package ghidra.util.layout;
|
|||
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
/**
|
||||
* LayoutManager for arranging components in a single column. All components
|
||||
* retain their preferred heights, but are sized to the same width.
|
||||
|
@ -67,8 +64,8 @@ public class VerticalLayout implements LayoutManager {
|
|||
width = Math.max(width, d.width);
|
||||
height += d.height;
|
||||
}
|
||||
return new Dimension(width + insets.left + insets.right, height + insets.top +
|
||||
insets.bottom);
|
||||
return new Dimension(width + insets.left + insets.right,
|
||||
height + insets.top + insets.bottom);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,26 +98,4 @@ public class VerticalLayout implements LayoutManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test main
|
||||
* @param args execution arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception exc) {
|
||||
System.out.println("Error loading L&F: " + exc);
|
||||
}
|
||||
|
||||
JFrame frame = new JFrame("Test");
|
||||
JPanel panel = new JPanel(new VerticalLayout(10));
|
||||
panel.add(new JLabel("One", SwingConstants.LEFT));
|
||||
panel.add(new JLabel("Two", SwingConstants.RIGHT));
|
||||
panel.add(new JLabel("Three", SwingConstants.CENTER));
|
||||
panel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
frame.getContentPane().add(panel);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue