use of java.awt.Dimension in project pcgen by PCGen.
the class StatTableModel method install.
public void install() {
table.setModel(this);
table.setDefaultRenderer(Object.class, renderer);
TableColumn abilityColumn = table.getColumn(ABILITY_COLUMN_ID);
int columnIndex = abilityColumn.getModelIndex();
int maxWidth = 0;
for (StatFacade aStat : stats) {
Component cell = renderer.getTableCellRendererComponent(table, aStat, false, false, -1, columnIndex);
maxWidth = Math.max(maxWidth, cell.getPreferredSize().width);
}
//we add some extra spacing to prevent ellipses from showing
abilityColumn.setPreferredWidth(maxWidth + 4);
TableColumn column = table.getColumn(EDITABLE_COLUMN_ID);
column.setCellRenderer(new TableCellUtilities.SpinnerRenderer());
column.setCellEditor(editor);
Dimension size = table.getPreferredSize();
size.width = table.getTableHeader().getPreferredSize().width;
JScrollPane scrollPane = (JScrollPane) table.getParent().getParent();
//we want to add room for the vertical scroll bar so it doesn't
//overlap with the table when it shows
int vbarWidth = scrollPane.getVerticalScrollBar().getPreferredSize().width;
size.width += vbarWidth;
table.setPreferredScrollableViewportSize(size);
//because of the extra viewport size in the table it will
//always look a bit off center, adding a row header to
//the scroll pane fixes this
scrollPane.setRowHeaderView(Box.createHorizontalStrut(vbarWidth));
for (StatFacade aStat : stats) {
character.getScoreBaseRef(aStat).addReferenceListener(this);
}
}
use of java.awt.Dimension in project pcgen by PCGen.
the class Utility method centerComponent.
/**
* Centers a {@code Component} to the screen.
*
* @param dialog JDialog dialog to center
*/
public static void centerComponent(Component dialog) {
// since the Toolkit.getScreenSize() method is broken in the Linux implementation
// of Java 5 (it returns double the screen size under xinerama), this method is
// encapsulated to accomodate this with a hack.
// TODO: remove the hack, once Java fixed this.
// final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
final Rectangle screenSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
final Dimension dialogSize = dialog.getSize();
if (dialogSize.height > screenSize.height) {
dialogSize.height = screenSize.height;
}
if (dialogSize.width > screenSize.width) {
dialogSize.width = screenSize.width;
}
dialog.setSize(dialogSize);
dialog.setLocation(screenSize.x + ((screenSize.width - dialogSize.width) / 2), screenSize.y + ((screenSize.height - dialogSize.height) / 2));
}
use of java.awt.Dimension in project pcgen by PCGen.
the class Utility method resizeComponentToScreen.
/**
* Update the size of the dialog to ensure it will fit on the screen.
*
* @param dialog The dialog to be resized.
*/
public static void resizeComponentToScreen(Component dialog) {
// Get the maximum window size to account for taskbars etc
Rectangle screenBounds = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
final Dimension dialogSize = dialog.getSize();
if (dialogSize.height > screenBounds.height) {
dialogSize.height = screenBounds.height;
}
if (dialogSize.width > screenBounds.width) {
dialogSize.width = screenBounds.width;
}
dialog.setSize(dialogSize);
}
use of java.awt.Dimension in project pcgen by PCGen.
the class PreferencesPluginsPanel method getCenter.
@Override
protected JComponent getCenter() {
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode characterNode;
DefaultMutableTreeNode pcGenNode;
DefaultMutableTreeNode appearanceNode;
DefaultMutableTreeNode gameModeNode;
panelList = new ArrayList<>(15);
// Build the settings panel
settingsPanel = new JPanel();
settingsPanel.setLayout(new CardLayout());
settingsPanel.setPreferredSize(new Dimension(780, 420));
// Build the selection tree
characterNode = new DefaultMutableTreeNode(in_character);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_charTip")), in_character);
characterStatsPanel = new CharacterStatsPanel(this);
addPanelToTree(characterNode, characterStatsPanel);
hitPointsPanel = new HitPointsPanel();
addPanelToTree(characterNode, hitPointsPanel);
houseRulesPanel = new HouseRulesPanel();
addPanelToTree(characterNode, houseRulesPanel);
monsterPanel = new MonsterPanel();
addPanelToTree(characterNode, monsterPanel);
defaultsPanel = new DefaultsPanel();
addPanelToTree(characterNode, defaultsPanel);
rootNode.add(characterNode);
appearanceNode = new DefaultMutableTreeNode(in_appearance);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_appearanceTip")), in_appearance);
colorsPanel = new ColorsPanel();
addPanelToTree(appearanceNode, colorsPanel);
displayOptionsPanel = new DisplayOptionsPanel();
addPanelToTree(appearanceNode, displayOptionsPanel);
levelUpPanel = new LevelUpPanel();
addPanelToTree(appearanceNode, levelUpPanel);
lookAndFeelPanel = new LookAndFeelPanel(this);
addPanelToTree(appearanceNode, lookAndFeelPanel);
// tabsPanel = new TabsPanel();
// addPanelToTree(appearanceNode, tabsPanel);
rootNode.add(appearanceNode);
pcGenNode = new DefaultMutableTreeNode(Constants.APPLICATION_NAME);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_Prefs_pcgenTip")), Constants.APPLICATION_NAME);
equipmentPanel = new EquipmentPanel();
addPanelToTree(pcGenNode, equipmentPanel);
languagePanel = new LanguagePanel();
addPanelToTree(pcGenNode, languagePanel);
locationPanel = new LocationPanel();
addPanelToTree(pcGenNode, locationPanel);
inputPanel = new InputPanel();
addPanelToTree(pcGenNode, inputPanel);
outputPanel = new OutputPanel();
addPanelToTree(pcGenNode, outputPanel);
sourcesPanel = new SourcesPanel();
addPanelToTree(pcGenNode, sourcesPanel);
rootNode.add(pcGenNode);
String in_gamemode = LanguageBundle.getString("in_mnuSettingsCampaign");
gameModeNode = new DefaultMutableTreeNode(in_gamemode);
settingsPanel.add(buildEmptyPanel("", LanguageBundle.getString("in_mnuSettingsCampaignTip")), in_gamemode);
copySettingsPanel = new CopySettingsPanel();
addPanelToTree(gameModeNode, copySettingsPanel);
rootNode.add(gameModeNode);
DefaultMutableTreeNode pluginNode = new DefaultMutableTreeNode(//$NON-NLS-1$
LanguageBundle.getString("in_Prefs_plugins"));
addPluginPanes(rootNode, pluginNode);
settingsModel = new DefaultTreeModel(rootNode);
settingsTree = new JTree(settingsModel);
settingsTree.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0));
settingsTree.setRootVisible(false);
settingsTree.setShowsRootHandles(true);
settingsTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
settingsScroll = new JScrollPane(settingsTree, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
// Turn off the icons
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
renderer.setClosedIcon(null);
settingsTree.setCellRenderer(renderer);
// Expand all of the branch nodes
settingsTree.expandPath(new TreePath(characterNode.getPath()));
settingsTree.expandPath(new TreePath(pcGenNode.getPath()));
settingsTree.expandPath(new TreePath(appearanceNode.getPath()));
settingsTree.expandPath(new TreePath(gameModeNode.getPath()));
settingsTree.expandPath(new TreePath(pluginNode.getPath()));
// Add the listener which switches panels when a node of the tree is selected
settingsTree.addTreeSelectionListener(new TreeSelectionListener() {
@Override
public void valueChanged(TreeSelectionEvent e) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode) settingsTree.getLastSelectedPathComponent();
if (node == null) {
return;
}
CardLayout cl = (CardLayout) (settingsPanel.getLayout());
cl.show(settingsPanel, String.valueOf(node));
}
});
// Build the split pane
splitPane = new FlippingSplitPane(JSplitPane.HORIZONTAL_SPLIT, settingsScroll, settingsPanel, "Prefs");
splitPane.setOneTouchExpandable(true);
splitPane.setDividerSize(10);
return splitPane;
}
use of java.awt.Dimension in project pcgen by PCGen.
the class PrintPreviewDialog method initLayout.
private void initLayout() {
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
{
//layout top bar
JPanel bar = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.BASELINE;
gbc.insets = new Insets(8, 6, 8, 2);
bar.add(new JLabel("Select Template:"), gbc);
gbc.insets = new Insets(8, 2, 8, 6);
gbc.weightx = 1;
bar.add(sheetBox, gbc);
pane.add(bar, BorderLayout.NORTH);
}
{
Box vbox = Box.createVerticalBox();
previewPanelParent.setPreferredSize(new Dimension(600, 800));
vbox.add(previewPanelParent);
vbox.add(progressBar);
pane.add(vbox, BorderLayout.CENTER);
}
{
Box hbox = Box.createHorizontalBox();
hbox.add(new JLabel("Page:"));
hbox.add(Box.createHorizontalStrut(4));
hbox.add(pageBox);
hbox.add(Box.createHorizontalStrut(10));
hbox.add(new JLabel("Zoom:"));
hbox.add(Box.createHorizontalStrut(4));
hbox.add(zoomBox);
hbox.add(Box.createHorizontalStrut(5));
hbox.add(zoomInButton);
hbox.add(Box.createHorizontalStrut(5));
hbox.add(zoomOutButton);
hbox.add(Box.createHorizontalGlue());
hbox.add(printButton);
hbox.add(Box.createHorizontalStrut(5));
hbox.add(cancelButton);
hbox.setBorder(BorderFactory.createEmptyBorder(8, 5, 8, 5));
pane.add(hbox, BorderLayout.SOUTH);
}
}
Aggregations