use of java.awt.Insets in project pcgen by PCGen.
the class ThumbnailPane method paintComponent.
@Override
protected void paintComponent(Graphics g) {
if (portrait == null || cropRect == null) {
return;
}
Insets insets = getInsets();
g.drawImage(portrait.getSubimage(cropRect.x, cropRect.y, cropRect.width, cropRect.height), insets.left, insets.top, Constants.THUMBNAIL_SIZE, Constants.THUMBNAIL_SIZE, this);
}
use of java.awt.Insets in project pcgen by PCGen.
the class RunConvertPanel method setupDisplay.
/**
* @see pcgen.gui2.converter.panel.ConvertSubPanel#setupDisplay(javax.swing.JPanel, pcgen.cdom.base.CDOMObject)
*/
@Override
public void setupDisplay(JPanel panel, CDOMObject pc) {
panel.setLayout(new GridBagLayout());
JLabel introLabel = new JLabel("Conversion in progress");
GridBagConstraints gbc = new GridBagConstraints();
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 10, 5, 10);
panel.add(introLabel, gbc);
JLabel explainLabel = new JLabel("<html>The LST data is being converted. In the log, " + "LSTERROR rows are errors that need to be manually corrected in the source data. " + "LSTWARN rows indicate changes the converter is making. " + "See " + changeLogFile.getAbsolutePath() + " for a log of all data changes.</html>");
explainLabel.setFocusable(true);
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(0, 10, 5, 10);
panel.add(explainLabel, gbc);
progressBar = getProgressBar();
Dimension d = progressBar.getPreferredSize();
d.width = 400;
progressBar.setPreferredSize(d);
progressBar.setStringPainted(true);
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0);
gbc.fill = GridBagConstraints.HORIZONTAL;
panel.add(progressBar, gbc);
messageAreaContainer = new JScrollPane(getMessageArea());
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0);
gbc.fill = GridBagConstraints.BOTH;
panel.add(messageAreaContainer, gbc);
panel.setPreferredSize(new Dimension(800, 500));
}
use of java.awt.Insets in project pcgen by PCGen.
the class SourceSelectionPanel method setupDisplay.
@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
panel.setLayout(new GridBagLayout());
JLabel label = new JLabel("Please select the Source Directory to Convert: ");
GridBagConstraints gbc = new GridBagConstraints();
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
gbc.insets = new Insets(50, 25, 10, 25);
panel.add(label, gbc);
JButton button = new JButton("Browse...");
button.setMnemonic('r');
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser(SourceFolder.OTHER.getFile());
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
chooser.setSelectedFile(path);
while (true) {
int open = chooser.showOpenDialog(null);
if (open == JFileChooser.APPROVE_OPTION) {
File fileToOpen = chooser.getSelectedFile();
if (fileToOpen.isDirectory()) {
path = fileToOpen;
SourceFolder.OTHER.setFile(fileToOpen);
pc.put(ObjectKey.DIRECTORY, path);
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path.getAbsolutePath());
JRadioButton button = radioButtons[SourceFolder.OTHER.ordinal()];
button.setSelected(true);
button.setText(buildFolderText(SourceFolder.OTHER, fileToOpen.getAbsolutePath()));
break;
}
JOptionPane.showMessageDialog(null, "Selection must be a valid Directory");
chooser.setSelectedFile(path);
} else if (open == JFileChooser.CANCEL_OPTION) {
break;
}
}
}
});
radioButtons = new JRadioButton[SourceFolder.values().length];
String selectedPath = null;
File selectedFile = pc.get(ObjectKey.DIRECTORY);
if (selectedFile != null) {
selectedPath = selectedFile.getAbsolutePath();
} else {
PCGenSettings context = PCGenSettings.getInstance();
selectedPath = context.getProperty(PCGenSettings.CONVERT_INPUT_PATH, null);
}
ButtonGroup group = new ButtonGroup();
boolean haveSelected = false;
Font font = panel.getFont();
font = FontManipulation.plain(font);
for (SourceFolder folder : SourceFolder.values()) {
JRadioButton pathButton = new JRadioButton();
final SourceFolder buttonFolder = folder;
pathButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, buttonFolder.getFile().getAbsolutePath());
pc.put(ObjectKey.DIRECTORY, buttonFolder.getFile());
}
});
String path;
if (folder.getFile() == null) {
path = "Undefined";
pathButton.setEnabled(false);
} else {
path = folder.getFile().getAbsolutePath();
if (path.equals(selectedPath)) {
pathButton.setSelected(true);
haveSelected = true;
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path);
selectedFile = folder.getFile();
}
}
pathButton.setText(buildFolderText(folder, path));
pathButton.setFont(font);
radioButtons[folder.ordinal()] = pathButton;
group.add(pathButton);
if (folder == SourceFolder.OTHER) {
Utility.buildRelativeConstraints(gbc, 1, GridBagConstraints.REMAINDER, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
} else {
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
}
gbc.insets = new Insets(10, 25, 10, 25);
panel.add(pathButton, gbc);
if (folder == SourceFolder.OTHER) {
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
gbc.insets = new Insets(10, 25, 10, 25);
panel.add(button, gbc);
}
}
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);
panel.add(new JLabel(" "), gbc);
if (!haveSelected) {
if (selectedPath != null) {
JRadioButton btn = radioButtons[SourceFolder.OTHER.ordinal()];
btn.setSelected(true);
selectedFile = new File(selectedPath);
SourceFolder.OTHER.setFile(selectedFile);
path = selectedFile;
btn.setText(buildFolderText(SourceFolder.OTHER, selectedFile.getAbsolutePath()));
} else if (radioButtons[SourceFolder.VENDORDATA.ordinal()].isEnabled()) {
JRadioButton btn = radioButtons[SourceFolder.VENDORDATA.ordinal()];
btn.setSelected(true);
selectedFile = SourceFolder.VENDORDATA.getFile();
} else if (radioButtons[SourceFolder.HOMEBREWDATA.ordinal()].isEnabled()) {
JRadioButton btn = radioButtons[SourceFolder.HOMEBREWDATA.ordinal()];
btn.setSelected(true);
selectedFile = SourceFolder.HOMEBREWDATA.getFile();
} else {
JRadioButton btn = radioButtons[SourceFolder.DATA.ordinal()];
btn.setSelected(true);
selectedFile = SourceFolder.DATA.getFile();
}
}
pc.put(ObjectKey.DIRECTORY, selectedFile);
}
use of java.awt.Insets in project pcgen by PCGen.
the class CampaignPanel method setupDisplay.
/**
* @see pcgen.gui2.converter.panel.ConvertSubPanel#setupDisplay(javax.swing.JPanel, pcgen.cdom.base.CDOMObject)
*/
@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
panel.setLayout(new GridBagLayout());
JLabel introLabel = new JLabel("Please select the Campaign(s) to Convert:");
GridBagConstraints gbc = new GridBagConstraints();
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
gbc.insets = new Insets(25, 25, 5, 25);
panel.add(introLabel, gbc);
final CampaignTableModel model = new CampaignTableModel(gameModeCampaigns, folderName);
final JTable table = new JTable(model) {
//Implement table cell tool tips.
@Override
public String getToolTipText(MouseEvent e) {
java.awt.Point p = e.getPoint();
int rowIndex = rowAtPoint(p);
int colIndex = columnAtPoint(p);
String tip = String.valueOf(getValueAt(rowIndex, colIndex));
return tip;
}
};
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent event) {
pc.removeListFor(ListKey.CAMPAIGN);
int[] selRows = table.getSelectedRows();
if (selRows.length == 0) {
saveSourceSelection(pc);
fireProgressEvent(ProgressEvent.NOT_ALLOWED);
} else {
for (int row : selRows) {
Campaign selCampaign = (Campaign) model.getValueAt(row, 0);
pc.addToListFor(ListKey.CAMPAIGN, selCampaign);
}
saveSourceSelection(pc);
fireProgressEvent(ProgressEvent.ALLOWED);
}
}
});
JScrollPane listScroller = new JScrollPane(table);
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0);
gbc.fill = GridBagConstraints.BOTH;
panel.add(listScroller, gbc);
initSourceSelection(model, table);
}
use of java.awt.Insets in project pcgen by PCGen.
the class PCGenFrame method buildMessageLabelPanel.
//TODO: This should be in a utility class.
/**
* Builds a JPanel containing the supplied message, split at each new
* line and an optional checkbox, suitable for use in a showMessageDialog
* call. This is generally useful for showing messges which can turned
* off either in preferences or when they are displayed.
*
* @param message The message to be displayed.
* @param checkbox The optional checkbox to be added - may be null.
* @return JPanel A panel containing the message and the checkbox.
*/
public static JPanel buildMessageLabelPanel(String message, JCheckBox checkbox) {
JPanel panel = new JPanel();
JLabel label;
String part;
panel.setLayout(new GridBagLayout());
GridBagConstraints cons = new GridBagConstraints();
cons.gridx = cons.gridy = 0;
cons.gridwidth = GridBagConstraints.REMAINDER;
cons.gridheight = 1;
cons.anchor = GridBagConstraints.WEST;
cons.insets = new Insets(0, 0, 3, 0);
cons.weightx = 1;
cons.weighty = 0;
cons.fill = GridBagConstraints.NONE;
int start = 0;
int sepPos = -1;
do {
//$NON-NLS-1$
sepPos = message.indexOf("\n", start);
if (sepPos >= 0) {
part = message.substring(start, sepPos);
start = sepPos + 1;
} else {
part = message.substring(start);
start = -1;
}
label = new JLabel(part, SwingConstants.LEADING);
panel.add(label, cons);
cons.gridy++;
} while (start >= 0);
if (checkbox != null) {
//$NON-NLS-1$
label = new JLabel("", SwingConstants.LEADING);
panel.add(label, cons);
cons.gridy++;
panel.add(checkbox, cons);
cons.gridy++;
}
return panel;
}
Aggregations