下面列出了javax.swing.JPanel#setBounds ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void createDeitiesPanel(World world, int infoPanelWidth, int infoPanelHeight, JPanel infoPanel) {
JPanel deitiesPanel = JPanelFactory.createJPanel("Deities");
deitiesPanel.setLayout(null);
deitiesPanel.setBounds(510, 363, infoPanelWidth + 5, infoPanelHeight);
infoPanel.add(deitiesPanel, DEITIES_KEY);
DeityAttributes deityAttributes = GroupPropertyUtils.getVillagersOrganization(world).getProperty(Constants.DEITY_ATTRIBUTES);
String deityTooltip = "deity hapiness indicator: if a deity becomes unhappy, they may lash out against the population";
for(int i=0; i<Deity.ALL_DEITIES.size(); i++) {
Deity deity = Deity.ALL_DEITIES.get(i);
Image image = imageInfoReader.getImage(deity.getBoonImageId(), null);
JLabel nameLabel = JLabelFactory.createJLabel(deity.getName(), image);
nameLabel.setBounds(15, 30 + 40 * i, 150, 50);
nameLabel.setHorizontalAlignment(SwingConstants.LEFT);
nameLabel.setToolTipText(deityTooltip);
deitiesPanel.add(nameLabel);
JProgressBar relationshipProgresBar = JProgressBarFactory.createHorizontalJProgressBar(deityAttributes.getMinHapinessValue(), deityAttributes.getMaxHapinessValue(), imageInfoReader);
relationshipProgresBar.setBounds(175, 40 + 40 * i, 300, 30);
relationshipProgresBar.setValue(deityAttributes.getHappiness(deity));
relationshipProgresBar.setToolTipText(deityTooltip);
deitiesPanel.add(relationshipProgresBar);
}
}
private void addPerformancePanel(KeyBindings keyBindings) {
JPanel performancePanel = JPanelFactory.createJPanel("Performance");
performancePanel.setOpaque(false);
performancePanel.setBounds(15, 310, 368, 100);
performancePanel.setLayout(null);
JLabel lblAnimationSpeed = JLabelFactory.createJLabel("Animation Speed:");
lblAnimationSpeed.setToolTipText(ANIMATION_SPEED_TOOL_TIP);
lblAnimationSpeed.setOpaque(false);
lblAnimationSpeed.setBounds(12, 25, 137, 25);
performancePanel.add(lblAnimationSpeed);
JComboBox<AnimationSpeed> cmbAnimationSpeed = JComboBoxFactory.createJComboBox(AnimationSpeed.values(), imageInfoReader);
cmbAnimationSpeed.setForeground(Color.BLACK);
cmbAnimationSpeed.setToolTipText(ANIMATION_SPEED_TOOL_TIP);
cmbAnimationSpeed.setSelectedItem(keyBindings.getAnimationSpeed());
cmbAnimationSpeed.setOpaque(false);
cmbAnimationSpeed.setBounds(228, 25, 127, 25);
performancePanel.add(cmbAnimationSpeed);
cmbAnimationSpeed.addActionListener(e -> keyBindings.setAnimationSpeed((AnimationSpeed)cmbAnimationSpeed.getSelectedItem()));
addComponent(performancePanel);
}
private void createToggleButtonPanel(SoundIdReader soundIdReader, int infoPanelWidth, CardLayout cardLayout, JPanel infoPanel) {
JPanel toggleButtonPanel = JPanelFactory.createBorderlessPanel();
toggleButtonPanel.setBounds(5, 5, infoPanelWidth, 40);
toggleButtonPanel.setLayout(new FlowLayout());
contentPanel.add(toggleButtonPanel);
ButtonGroup buttonGroup = new ButtonGroup();
JToggleButton familyButton = createToggleButton("Family", FAMILY_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows family members of the player character");
createToggleButton("Acquaintances", ACQUAINTANCES_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows acquaintances of the player character");
createToggleButton("Player Character Ranks", RANKS_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows group memberships of the player character");
createToggleButton("Organizations", ORGANIZATIONS_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows an overview of all organizations and their members");
createToggleButton("Deities", DEITIES_KEY, soundIdReader, cardLayout, infoPanel, buttonGroup, toggleButtonPanel, "Shows an overview of all deities and their happiness");
buttonGroup.setSelected(familyButton.getModel(), true);
}
/**
* Create the panel.
*/
public LogManagerPanel() {
setBounds(0, 0, 1165, 725);
setLayout(null);
JButton btnNewButton = new JButton("日志刷新");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//重新加载日志
initData();
}
});
btnNewButton.setBounds(29, 29, 93, 23);
add(btnNewButton);
JPanel panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setBounds(10, 81, 1145, 611);
panel.setBorder(BorderFactory.createTitledBorder("日志列表:"));
add(panel);
panel.setLayout(null);
textArea = new JTextArea();
textArea.setForeground(Color.GREEN);
textArea.setBackground(Color.BLACK);
textArea.setFont(new Font("Monospaced", Font.PLAIN, 17));
JScrollPane js = new JScrollPane(textArea);
js.setBounds(25, 25, 1100, 570);
panel.add(js);
initData();
}
/**
*
*/
@Override
public void refreshLayoutOfGrid() {
int runningLayoutHeight = 0;
for (JPanel fractionCommonLeadManager : fractionCommonLeadManagers) {
int fractionPanelHeight = ((TripoliFractionCommonLeadManager) fractionCommonLeadManager).isExpandedView() ? GRID_ELEMENT_HEIGHT : 25;//.getHeightIntialPbModelDataView();// .isExpandedView() ? GRID_ELEMENT_HEIGHT : 25;
fractionCommonLeadManager.setBounds(2, runningLayoutHeight, width - 25, fractionPanelHeight);
((TripoliFractionCommonLeadManager) fractionCommonLeadManager).fillParameterFields();
runningLayoutHeight += fractionPanelHeight;
}
this.validate();
setPreferredSize(new Dimension(width - 25, runningLayoutHeight + 50));
}
/**
* Constructor of the PeriodicTablePanel object
*/
public PeriodicTablePanel() {
super();
setLayout(new BorderLayout());
layeredPane = new JLayeredPane();
layeredPane.setPreferredSize(new Dimension(581, 435));
JPanel tp = PTPanel();
tp.setBounds(8, 85, 570, 340);
panel = CreateLabelProperties(null);
layeredPane.add(tp, new Integer(0));
layeredPane.add(panel, new Integer(1));
add(layeredPane);
}
public TextInputDialog(boolean numericInputOnly, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader, JFrame parentFrame) {
super(500, 190, imageInfoReader);
this.imageInfoReader = imageInfoReader;
textPane = JTextPaneFactory.createJTextPane(imageInfoReader);
textPane.setEditable(false);
textPane.setBounds(16, 16, 465, 50);
addComponent(textPane);
textField = numericInputOnly ? JTextFieldFactory.createIntegerOnlyJTextField() : JTextFieldFactory.createJTextField();
textField.setBounds(16, 70, 465, 30);
addComponent(textField);
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttonPane.setOpaque(false);
buttonPane.setBounds(16, 133, 475, 50);
addComponent(buttonPane);
JButton cancelButton = JButtonFactory.createButton("Cancel", imageInfoReader, soundIdReader);
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
JButton okButton = JButtonFactory.createButton(" OK ", imageInfoReader, soundIdReader);
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
addActions(okButton, cancelButton);
this.addWindowListener(new WindowAdapter() {
public void windowOpened(WindowEvent e) {
textField.requestFocus();
}
});
DialogUtils.createDialogBackPanel(this, parentFrame.getContentPane());
}
private void initializeGui(Component parent, List<KnowledgeDescription> knowledgeDescriptions, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader, JFrame parentFrame) {
knowledgeTable = JTableFactory.createJTable(new KnowledgeModel(knowledgeDescriptions));
knowledgeTable.setDefaultRenderer(ImageIds.class, new ImageCellRenderer(imageInfoReader));
knowledgeTable.setDefaultRenderer(String.class, new DefaultTableCellRenderer());
knowledgeTable.setRowHeight(50);
knowledgeTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
knowledgeTable.getColumnModel().getColumn(0).setPreferredWidth(30);
knowledgeTable.getColumnModel().getColumn(1).setPreferredWidth(50);
knowledgeTable.getColumnModel().getColumn(2).setPreferredWidth(500);
knowledgeTable.getColumnModel().getColumn(0).setHeaderValue(" ");
knowledgeTable.getColumnModel().getColumn(1).setHeaderValue(" ");
knowledgeTable.getColumnModel().getColumn(2).setHeaderValue(" ");
knowledgeTable.getTableHeader().setReorderingAllowed(false);
JScrollPane scrollPane = JScrollPaneFactory.createScrollPane(knowledgeTable);
scrollPane.setBounds(5, 5, 585, 510);
this.addComponent(scrollPane);
SwingUtils.makeTransparant(knowledgeTable, scrollPane);
JPanel buttonPane = new JPanel(new BorderLayout());
buttonPane.setBounds(5, 540, 585, 40);
buttonPane.setOpaque(false);
this.addComponent(buttonPane);
okButton = JButtonFactory.createButton("OK", imageInfoReader, soundIdReader);
okButton.setActionCommand("OK");
buttonPane.add(okButton, BorderLayout.EAST);
getRootPane().setDefaultButton(okButton);
DialogUtils.createDialogBackPanel(this, parentFrame.getContentPane());
}
/**
* Create the frame.
*/
@SuppressWarnings("serial")
public QRCodeFrame(final String filePath) {
setBackground(Color.WHITE);
this.setResizable(false);
this.setTitle("\u8BF7\u7528\u624B\u673A\u626B\u63CF\u5FAE\u4FE1\u4E8C\u7EF4\u7801");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(100, 100, 297, 362);
this.contentPane = new JPanel() ;
contentPane.setBackground(new Color(102, 153, 255));
this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
this.setContentPane(contentPane);
contentPane.setLayout(null);
JPanel qrcodePanel = new JPanel(){
public void paintComponent(Graphics g) {
ImageIcon icon = new ImageIcon(filePath);
// 图片随窗体大小而变化
g.drawImage(icon.getImage(), 0, 0, 301, 301, this);
}
};
qrcodePanel.setBounds(0, 0, 295, 295);
JLabel tipLable = new JLabel("扫描二维码登录微信");
tipLable.setFont(new Font("微软雅黑", Font.PLAIN, 18));
tipLable.setHorizontalAlignment(SwingConstants.CENTER);
tipLable.setBounds(0, 297, 291, 37);
contentPane.add(qrcodePanel);
contentPane.add(tipLable);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
private void initModels() {
setSize(375, openModels.size() * 265 + 50);
setTitle("Manage Plots Seawater/Open Sys Isochrons");
setAlwaysOnTop(true);
JPanel modelsPanel = new JPanel(null);
modelsPanel.setSize(300, openModels.size() * 250);
modelsPanel.setBackground(new Color(249, 237, 189));
modelsPanel.setPreferredSize(new Dimension(300, openModels.size() * 265 + 25));
int count = 0;
for (OpenSystemIsochronTableModel osm : openModels) {
JPanel openPanel = new OpenSystemModelDataView(osm);
openPanel.setBounds(10, count * 245 + 10, 300, 235);
modelsPanel.add(openPanel);
count++;
}
JButton okButton = new ET_JButton("OK");
okButton.setBounds(15, count * 245 + 10, 290, 25);
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
modelsPanel.add(okButton);
JScrollPane modelsScroll = new JScrollPane(modelsPanel);
modelsScroll.setSize(300, openModels.size() * 265);
setContentPane(modelsScroll);
}
/**
*
* Domain and Range axes need to share the same unit (e.g. mm)
*
* @param myChart
* @return
*/
public static double calcWidthToHeight(ChartPanel myChart, double chartHeight) {
makeChartResizable(myChart);
// paint on a ghost panel
JPanel parent = (JPanel) myChart.getParent();
JPanel p = new JPanel();
p.removeAll();
p.add(myChart, BorderLayout.CENTER);
p.setBounds(myChart.getBounds());
myChart.paintImmediately(myChart.getBounds());
p.removeAll();
parent.add(myChart);
XYPlot plot = (XYPlot) myChart.getChart().getPlot();
ChartRenderingInfo info = myChart.getChartRenderingInfo();
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
Rectangle2D chartArea = info.getChartArea();
// calc title space: will be added later to the right plot size
double titleWidth = chartArea.getWidth() - dataArea.getWidth();
double titleHeight = chartArea.getHeight() - dataArea.getHeight();
// calc right plot size with axis dim.
// real plot width is given by factor;
double realPH = chartHeight - titleHeight;
// ranges
ValueAxis domainAxis = plot.getDomainAxis();
org.jfree.data.Range x = domainAxis.getRange();
ValueAxis rangeAxis = plot.getRangeAxis();
org.jfree.data.Range y = rangeAxis.getRange();
// real plot height can be calculated by
double realPW = realPH / y.getLength() * x.getLength();
double width = realPW + titleWidth;
return width;
}
public StatusMessageDialog(List<StatusMessage> statusMessages, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader, JFrame parentFrame) {
super(700, 475, imageInfoReader);
JScrollPane scrollPane = JScrollPaneFactory.createScrollPane();
scrollPane.setBounds(16, 16, 665, 380);
addComponent(scrollPane);
JList<StatusMessage> list = JListFactory.createJList(statusMessages.toArray(new StatusMessage[0]));
list.setSelectedIndex(statusMessages.size() - 1);
list.setCellRenderer(new StatusMessageListRenderer());
scrollPane.setViewportView(list);
list.ensureIndexIsVisible(list.getSelectedIndex());
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BorderLayout());
buttonPane.setOpaque(false);
buttonPane.setBounds(16, 417, 665, 40);
addComponent(buttonPane);
JButton okButton = JButtonFactory.createButton(" OK ", imageInfoReader, soundIdReader);
okButton.setActionCommand("OK");
buttonPane.add(okButton, BorderLayout.EAST);
getRootPane().setDefaultButton(okButton);
addActions(list, okButton);
DialogUtils.createDialogBackPanel(this, parentFrame.getContentPane());
}
public void initializeGUI(Consumer<int[]> setPricesAction, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader) {
PricesModel worldModel = new PricesModel(pricesOnPlayer);
JTable table = JTableFactory.createJTable(worldModel);
table.setDefaultRenderer(ImageIds.class, new ImageTableRenderer(imageInfoReader));
table.setRowHeight(50);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getColumnModel().getColumn(0).setPreferredWidth(100);
table.getColumnModel().getColumn(1).setPreferredWidth(250);
table.getColumnModel().getColumn(2).setPreferredWidth(100);
JTableFactory.applyImageToHeaderColumn(table, table.getColumnModel().getColumn(2), ImageIds.SMALL_GOLD_COIN, imageInfoReader);
table.setAutoCreateRowSorter(true);
table.getRowSorter().toggleSortOrder(1);
JScrollPane scrollPane = JScrollPaneFactory.createScrollPane(table);
scrollPane.setBounds(15, 15, 468, 700);
addComponent(scrollPane);
JPanel buttonPane = new JPanel();
buttonPane.setOpaque(false);
buttonPane.setBounds(0, 730, 488, 75);
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
addComponent(buttonPane);
JButton okButton = JButtonFactory.createButton("OK", imageInfoReader, soundIdReader);
okButton.setActionCommand("OK");
buttonPane.add(okButton);
addActionHandlers(setPricesAction, okButton, worldModel, this, pricesOnPlayer);
getRootPane().setDefaultButton(okButton);
SwingUtils.makeTransparant(table, scrollPane);
}
private void init() {
setUndecorated(true);
try {
if (GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
if (!Config.getInstance().isNoTransparency())
setOpacity(0.85f);
}
} catch (Exception e) {
Logger.log(e);
}
setIconImage(ImageResource.getImage("icon.png"));
setSize(getScaledInt(350), getScaledInt(200));
setLocationRelativeTo(null);
setResizable(false);
getContentPane().setLayout(null);
getContentPane().setBackground(ColorResource.getDarkestBgColor());
titlePanel = new TitlePanel(null, this);
titlePanel.setOpaque(false);
titlePanel.setBounds(0, 0, getScaledInt(350), getScaledInt(50));
closeBtn = new CustomButton();
closeBtn.setBounds(getScaledInt(320), getScaledInt(5), getScaledInt(24), getScaledInt(24));
closeBtn.setIcon(ImageResource.getIcon("title_close.png",20,20));
closeBtn.setBackground(ColorResource.getDarkestBgColor());
closeBtn.setBorderPainted(false);
closeBtn.setFocusPainted(false);
closeBtn.setName("CLOSE");
closeBtn.addActionListener(this);
minBtn = new CustomButton();
minBtn.setBounds(getScaledInt(296), getScaledInt(5), getScaledInt(24), getScaledInt(24));
minBtn.setIcon(ImageResource.getIcon("title_min.png",20,20));
minBtn.setBackground(ColorResource.getDarkestBgColor());
minBtn.setBorderPainted(false);
minBtn.setFocusPainted(false);
minBtn.setName("MIN");
minBtn.addActionListener(this);
titleLbl = new JLabel(StringResource.get("TITLE_CONVERT"));
titleLbl.setFont(FontResource.getBiggerFont());
titleLbl.setForeground(ColorResource.getSelectionColor());
titleLbl.setBounds(getScaledInt(25), getScaledInt(15), getScaledInt(250), getScaledInt(30));
JLabel lineLbl = new JLabel();
lineLbl.setBackground(ColorResource.getSelectionColor());
lineLbl.setBounds(0, getScaledInt(55), getScaledInt(400), 2);
lineLbl.setOpaque(true);
prg = new JProgressBar();
prg.setBounds(getScaledInt(20), getScaledInt(85), getScaledInt(350) - getScaledInt(40), getScaledInt(5));
statLbl = new JLabel();
statLbl.setForeground(Color.WHITE);
statLbl.setBounds(getScaledInt(20), getScaledInt(100), getScaledInt(350) - getScaledInt(40), getScaledInt(25));
titlePanel.add(titleLbl);
titlePanel.add(minBtn);
titlePanel.add(closeBtn);
add(lineLbl);
add(titlePanel);
add(prg);
add(statLbl);
panel = new JPanel(null);
panel.setBounds(0, getScaledInt(150), getScaledInt(350), getScaledInt(50));
panel.setBackground(Color.DARK_GRAY);
btnCN = new CustomButton(StringResource.get("MENU_PAUSE"));
btnCN.setBounds(0, 1, getScaledInt(350), getScaledInt(50));
btnCN.setName("CLOSE");
applyStyle(btnCN);
panel.add(btnCN);
add(panel);
}
private void init() {
setUndecorated(true);
try {
if (GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.isWindowTranslucencySupported(WindowTranslucency.TRANSLUCENT)) {
if (!Config.getInstance().isNoTransparency())
setOpacity(0.85f);
}
} catch (Exception e) {
Logger.log(e);
}
setIconImage(ImageResource.getImage("icon.png"));
setSize(getScaledInt(350), getScaledInt(200));
setLocationRelativeTo(null);
setResizable(false);
getContentPane().setLayout(null);
getContentPane().setBackground(ColorResource.getDarkestBgColor());
titlePanel = new TitlePanel(null, this);
titlePanel.setOpaque(false);
titlePanel.setBounds(0, 0, getScaledInt(350), getScaledInt(50));
closeBtn = new CustomButton();
closeBtn.setBounds(getScaledInt(320), getScaledInt(5), getScaledInt(24), getScaledInt(24));
closeBtn.setIcon(ImageResource.getIcon("title_close.png",20,20));
closeBtn.setBackground(ColorResource.getDarkestBgColor());
closeBtn.setBorderPainted(false);
closeBtn.setFocusPainted(false);
closeBtn.setName("CLOSE");
closeBtn.addActionListener(this);
minBtn = new CustomButton();
minBtn.setBounds(getScaledInt(296), getScaledInt(5), getScaledInt(24), getScaledInt(24));
minBtn.setIcon(ImageResource.getIcon("title_min.png",20,20));
minBtn.setBackground(ColorResource.getDarkestBgColor());
minBtn.setBorderPainted(false);
minBtn.setFocusPainted(false);
minBtn.setName("MIN");
minBtn.addActionListener(this);
titleLbl = new JLabel(StringResource.get("TITLE_CONVERT"));
titleLbl.setFont(FontResource.getBiggerFont());
titleLbl.setForeground(ColorResource.getSelectionColor());
titleLbl.setBounds(getScaledInt(25), getScaledInt(15), getScaledInt(250), getScaledInt(30));
JLabel lineLbl = new JLabel();
lineLbl.setBackground(ColorResource.getSelectionColor());
lineLbl.setBounds(0, getScaledInt(55), getScaledInt(400), 2);
lineLbl.setOpaque(true);
prg = new JProgressBar();
prg.setBounds(getScaledInt(20), getScaledInt(85), getScaledInt(350) - getScaledInt(40), getScaledInt(5));
statLbl = new JLabel();
statLbl.setForeground(Color.WHITE);
statLbl.setBounds(getScaledInt(20), getScaledInt(100), getScaledInt(350) - getScaledInt(40), getScaledInt(25));
titlePanel.add(titleLbl);
titlePanel.add(minBtn);
titlePanel.add(closeBtn);
add(lineLbl);
add(titlePanel);
add(prg);
add(statLbl);
panel = new JPanel(null);
panel.setBounds(getScaledInt(0), getScaledInt(150), getScaledInt(350), getScaledInt(50));
panel.setBackground(Color.DARK_GRAY);
btnCN = new CustomButton(StringResource.get("MENU_PAUSE"));
btnCN.setBounds(0, 1, getScaledInt(350), getScaledInt(50));
btnCN.setName("CLOSE");
applyStyle(btnCN);
panel.add(btnCN);
add(panel);
}
public AboutPage(XDMFrame xframe) {
super(StringResource.get("TITLE_ABOUT"), getScaledInt(350), xframe);
int y = 0;
int h = 0;
JPanel panel = new JPanel();
panel.setLayout(null);
panel.setOpaque(false);
y += getScaledInt(10);
h = getScaledInt(50);
JLabel lblTitle = new JLabel(StringResource.get("FULL_NAME"));
lblTitle.setFont(FontResource.getBiggerFont());
lblTitle.setForeground(Color.WHITE);
lblTitle.setBounds(getScaledInt(15), y, getScaledInt(350) - getScaledInt(30), h);
panel.add(lblTitle);
y += h;
y += getScaledInt(20);
String details = String.format(
"Version %s with Java %s on %s\n\nCreated by: Subhra Das Gupta\n\n%s\nCopyright (C) 2020, All rights reserved.",
XDMApp.APP_VERSION, (System.getProperty("java.vendor") + " " + System.getProperty("java.version")),
System.getProperty("os.name"), "https://github.com/subhra74/xdm");
h = getScaledInt(250);
JTextArea lblDetails = new JTextArea();
lblDetails.setOpaque(false);
lblDetails.setWrapStyleWord(true);
lblDetails.setLineWrap(true);
lblDetails.setEditable(false);
lblDetails.setForeground(Color.WHITE);
lblDetails.setText(details);
lblDetails.setFont(FontResource.getBigFont());
lblDetails.setBounds(getScaledInt(15), y, getScaledInt(350) - getScaledInt(30), h);
panel.add(lblDetails);
y += h;
panel.setPreferredSize(new Dimension(getScaledInt(350), y));
panel.setBounds(0, 0, getScaledInt(350), y);
jsp.setViewportView(panel);
}
public static void main(String[] args) throws Exception {
// solution found. Create GUI.
final JFrame frame = new JFrame();
frame.setAlwaysOnTop(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
/** Once opened: load up the images. */
public void windowOpened(WindowEvent e) {
System.out.println("Loading card images...");
cardImages = CardImagesLoader.getDeck(e.getWindow());
}
});
frame.setSize(808,350);
JList<IMove> list = new JList<IMove>();
// add widgets at proper location
frame.setLayout(null);
// top row:
JPanel topLeft = new JPanel();
topLeft.setBounds(0, 0, 400, 40);
topLeft.add(new JLabel("Select Game:"));
final JTextField jtf = new JTextField (7);
topLeft.add(jtf);
frame.add(topLeft);
JPanel topRight = new JPanel();
topRight.setBounds(400, 0, 400, 40);
String instructions = "Select moves from below list to see game state at that moment.";
topRight.add(new JLabel(instructions));
frame.add(topRight);
// bottom row
FreeCellDrawing drawer = new FreeCellDrawing();
drawer.setBounds (0, 40, 400, 275);
drawer.setBackground(new java.awt.Color (0,128,0));
frame.add(drawer);
// Create the GUI and put it in the window with scrollbars.
JScrollPane scrollingPane = new JScrollPane(list);
scrollingPane.setAutoscrolls(true);
scrollingPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
scrollingPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
scrollingPane.setBounds(400, 40, 400, 275);
frame.add(scrollingPane);
// set up listeners and show everything
jtf.addActionListener(new DealController(frame, drawer, list));
frame.setVisible(true);
}
private void initializeGui(Component parent, List<WorldObject> disguiseWorldObjects, ImageInfoReader imageInfoReader, JFrame parentFrame) {
int width = 274;
int height = 502;
setBounds(100, 100, width, height);
contentPanel.setPreferredSize(getSize());
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
setUndecorated(true);
IconUtils.setIcon(this);
setCursor(Cursors.CURSOR);
noDisguiseRadioButton = JRadioButtonFactory.createJRadioButton("No disguise");
noDisguiseRadioButton.setOpaque(false);
buttonGroup.add(noDisguiseRadioButton);
noDisguiseRadioButton.setBounds(21, 19, 231, 25);
contentPanel.add(noDisguiseRadioButton);
chooseExistingPersonRadioButton = JRadioButtonFactory.createJRadioButton("Choose existing Person:");
chooseExistingPersonRadioButton.setOpaque(false);
buttonGroup.add(chooseExistingPersonRadioButton);
chooseExistingPersonRadioButton.setBounds(21, 49, 299, 25);
contentPanel.add(chooseExistingPersonRadioButton);
personList = new WorldObjectList(imageInfoReader, disguiseWorldObjects);
personList.setBounds(40, 88, 193, 330);
contentPanel.add(personList);
JPanel buttonPane = new JPanel();
buttonPane.setOpaque(false);
buttonPane.setBounds(0, 455, 274, 44);
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
contentPanel.add(buttonPane);
okButton = JButtonFactory.createButton("OK", imageInfoReader, soundIdReader);
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
this.setLocationRelativeTo(parent);
SwingUtils.installEscapeCloseOperation(this);
DialogUtils.createDialogBackPanel(this, parentFrame.getContentPane());
}
public RespondToQuestionDialog(int id, int conversationId, int historyItemId, int additionalValue, int additionalValue2, Questioner questioner, Conversations conversations, ImageIds imageIdPerformer, ImageIds imageIdTarget, String performerName, String targetName, ImageInfoReader imageInfoReader, SoundIdReader soundIdReader, JFrame parentFrame) {
super(600, 300, imageInfoReader);
this.imageInfoReader = imageInfoReader;
ImageSubstituter imageSubstituter = new ImageSubstituter(imageInfoReader);
conversationFormatter = new ConversationFormatterImpl(imageSubstituter);
KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
rootPane.registerKeyboardAction(new CloseDialogAction(), stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
JPanel buttonPane = new JPanel();
buttonPane.setBounds(470, 205, 112, 48);
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
buttonPane.setOpaque(false);
addComponent(buttonPane);
JButton cancelButton = JButtonFactory.createButton("Cancel", imageInfoReader, soundIdReader);
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
JButton okButton = JButtonFactory.createButton("OK", imageInfoReader, soundIdReader);
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
JLabel targetLabel = JLabelFactory.createJLabel(imageInfoReader.getImage(imageIdTarget, null));
targetLabel.setToolTipText(targetName);
targetLabel.setBounds(6, 90, 32, 48);
addComponent(targetLabel);
comboBoxResponse = createResponseComboBox(id, conversationId, historyItemId, conversations, questioner, additionalValue, additionalValue2);
comboBoxResponse.setBounds(44, 86, 515, 55);
comboBoxResponse.setForeground(ColorPalette.FOREGROUND_COLOR);
SwingUtils.setComboBoxSelectionColor(comboBoxResponse, ColorPalette.FOREGROUND_COLOR);
addComponent(comboBoxResponse);
JLabel performerLabel = JLabelFactory.createJLabel(imageInfoReader.getImage(imageIdPerformer, null));
performerLabel.setToolTipText(performerName);
performerLabel.setBounds(6, 17, 32, 48);
addComponent(performerLabel);
String questionPhrase = questioner.getQuestionPhrase(conversationFormatter);
label = JLabelFactory.createJLabel("<html>"+ questionPhrase +"</html>");
label.setBounds(44, 27, 515, 46);
addComponent(label);
JLabel relationshipLabel = JLabelFactory.createJLabel("Relationship:");
relationshipLabel.setToolTipText("Relationship with " + performerName);
relationshipLabel.setBounds(6, 210, 100, 30);
addComponent(relationshipLabel);
relationshipProgresBar = JProgressBarFactory.createHorizontalJProgressBar(-1000, 1000, imageInfoReader);
relationshipProgresBar.setBounds(109, 210, 340, 30);
relationshipProgresBar.setValue(questioner.getRelationshipValue());
relationshipProgresBar.setToolTipText("Relationship with " + performerName);
addComponent(relationshipProgresBar);
okButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
selectedResponse = comboBoxResponse.getSelectedIndex();
}
});
okButton.addActionListener(new CloseDialogAction());
cancelButton.addActionListener(new CloseDialogAction());
DialogUtils.createDialogBackPanel(this, parentFrame.getContentPane());
}
/**
* Returns dimensions for limiting factor width or height
*
* @param myChart
* @return
*/
public static Dimension calcMaxSize(ChartPanel myChart, double chartWidth, double chartHeight) {
makeChartResizable(myChart);
// paint on a ghost panel
JPanel parent = (JPanel) myChart.getParent();
JPanel p = new JPanel();
p.removeAll();
p.add(myChart, BorderLayout.CENTER);
p.setBounds(myChart.getBounds());
myChart.paintImmediately(myChart.getBounds());
p.removeAll();
parent.add(myChart);
XYPlot plot = (XYPlot) myChart.getChart().getPlot();
ChartRenderingInfo info = myChart.getChartRenderingInfo();
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
Rectangle2D chartArea = info.getChartArea();
// calc title space: will be added later to the right plot size
double titleWidth = chartArea.getWidth() - dataArea.getWidth();
double titleHeight = chartArea.getHeight() - dataArea.getHeight();
// calculatig width for max height
// calc right plot size with axis dim.
// real plot width is given by factor;
double realPH = chartHeight - titleHeight;
// ranges
ValueAxis domainAxis = plot.getDomainAxis();
org.jfree.data.Range x = domainAxis.getRange();
ValueAxis rangeAxis = plot.getRangeAxis();
org.jfree.data.Range y = rangeAxis.getRange();
// real plot height can be calculated by
double realPW = realPH / y.getLength() * x.getLength();
double width = realPW + titleWidth;
// if width is higher than given chartWidth then calc height for chartWidth
if (width > chartWidth) {
// calc right plot size with axis dim.
// real plot width is given by factor;
realPW = chartWidth - titleWidth;
// real plot height can be calculated by
realPH = realPW / x.getLength() * y.getLength();
double height = realPH + titleHeight;
// Return size
return new Dimension((int) chartWidth, (int) height);
} else {
// Return size
return new Dimension((int) width, (int) chartHeight);
}
}