use of java.awt.Component in project OpenNotebook by jaltekruse.
the class ProblemListPanel method createPanelForProblems.
public JPanel createPanelForProblems() {
ProblemList panel = new ProblemList();
JPanel tempPanel;
GridBagConstraints con = new GridBagConstraints();
JComboBox frequencyChoices;
Component[] othersInRow = new Component[2];
;
int numProblemsToShow = notebookPanel.getDatabase().getAllProblems().size();
if (numProblemsToShow > 20) {
// limit the number of problems in the list
// to 20 at a time
numProblemsToShow = 20;
}
con.gridy = 0;
panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
panel.setLayout(new GridBagLayout());
for (final ProblemGenerator g : notebookPanel.getDatabase().getAllProblems()) {
// add checkbox
con.fill = GridBagConstraints.NONE;
con.gridx = 0;
con.gridwidth = 1;
con.weightx = 0;
con.insets = new Insets(0, 0, 0, 0);
final JCheckBox checkbox = new JCheckBox();
checkbox.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ev) {
if (ev.getStateChange() == ItemEvent.SELECTED) {
selectedFrequencies.add(10);
selectedProblems.add(g);
} else {
selectedFrequencies.remove(selectedProblems.indexOf(g));
selectedProblems.remove(g);
}
previewPanel.getDoc().getPage(0).removeAllObjects();
// set the page size big to prevent problem generation from spawning pages
previewPanel.getDoc().setHeight(5000);
previewPanel.getDoc().setWidth(5000);
previewPanel.getDoc().generateProblem(g);
previewPanel.resizeViewWindow();
MathObject mObj = previewPanel.getDoc().getPage(0).getObjects().get(0);
previewPanel.getDoc().setWidth(mObj.getWidth() + 2 * problemBuffer);
previewPanel.getDoc().setHeight(mObj.getHeight() + 2 * problemBuffer);
mObj.setxPos(problemBuffer);
mObj.setyPos(problemBuffer);
previewPanel.resizeViewWindow();
}
});
frequencyChoices = new JComboBox(frequencies);
panel.add(checkbox, con);
othersInRow[0] = checkbox;
othersInRow[1] = frequencyChoices;
con.fill = GridBagConstraints.HORIZONTAL;
con.insets = new Insets(0, 5, 0, 0);
con.weightx = 1;
con.gridx = 1;
tempPanel = new ProblemDescriptionPanel(g, othersInRow);
tempPanel.addMouseListener(new MouseListener() {
public void mouseClicked(MouseEvent arg0) {
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
@Override
public void mousePressed(MouseEvent arg0) {
checkbox.setSelected(!checkbox.isSelected());
}
public void mouseReleased(MouseEvent arg0) {
}
});
panel.add(tempPanel, con);
// // add frequency selection menu
// con.fill = GridBagConstraints.NONE;
// con.gridx = 2;
// con.weightx = 0;
// con.insets = new Insets(0, 5, 0, 5);
// frequencyChoices.setSelectedItem(AVERAGE);
// panel.add(frequencyChoices, con);
con.gridy++;
con.gridx = 0;
con.gridwidth = 2;
con.insets = new Insets(0, 0, 0, 0);
panel.add(new JSeparator(), con);
con.gridy++;
}
return panel;
}
use of java.awt.Component in project OpenNotebook by jaltekruse.
the class ModifiedFlowLayout method computeMinSize.
private Dimension computeMinSize(Container target) {
synchronized (target.getTreeLock()) {
int minx = Integer.MAX_VALUE;
int miny = Integer.MIN_VALUE;
boolean found_one = false;
int n = target.getComponentCount();
for (int i = 0; i < n; i++) {
Component c = target.getComponent(i);
if (c.isVisible()) {
found_one = true;
Dimension d = c.getPreferredSize();
minx = Math.min(minx, d.width);
miny = Math.min(miny, d.height);
}
}
if (found_one) {
return new Dimension(minx, miny);
}
return new Dimension(0, 0);
}
}
use of java.awt.Component in project screenbird by adamhub.
the class RecorderPanel method showUploadMessage.
/*
* Upload methods
*/
/**
* Displays a message on the upload form, formatted with a text color.
* @param message
* @param type
*/
public void showUploadMessage(String message, Color type) {
int start = 0;
int end = 0;
Component focusedComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
if (focusedComponent instanceof JTextComponent) {
end = ((JTextComponent) focusedComponent).getSelectionEnd();
start = ((JTextComponent) focusedComponent).getSelectionStart();
}
Dimension size = new Dimension(160, 14);
this.lblUploadMessage.setPreferredSize(size);
this.lblUploadMessage.setMinimumSize(size);
this.lblUploadMessage.setMaximumSize(size);
this.lblUploadMessage.setSize(size);
this.pbEncoding.setVisible(true);
this.pbEncoding.setForeground(type);
this.lblUploadMessage.validate();
this.lblUploadMessage.setText(message);
this.lblUploadMessage.setVisible(true);
this.lblUploadMessage.setForeground(type);
((JFrame) this.getParent().getParent().getParent().getParent()).pack();
this.redrawWindow();
if (focusedComponent instanceof JTextComponent) {
((JTextComponent) focusedComponent).grabFocus();
((JTextComponent) focusedComponent).setSelectionStart(start);
((JTextComponent) focusedComponent).setSelectionEnd(end);
}
}
use of java.awt.Component in project hackpad by dropbox.
the class RunProxy method updateToolTip.
/**
* Updates the tool tip contents.
*/
private void updateToolTip() {
// Try to set tool tip on frame. On Mac OS X 10.5,
// the number of components is different, so try to be safe.
int n = getComponentCount() - 1;
if (n > 1) {
n = 1;
} else if (n < 0) {
return;
}
Component c = getComponent(n);
// this will work at least for Metal L&F
if (c != null && c instanceof JComponent) {
((JComponent) c).setToolTipText(getUrl());
}
}
use of java.awt.Component in project 12306-hunter by xautlx.
the class TicketMainFrame method bindUItoModel.
/**
* 绑定UI数据到模型对象
* @return
*/
private TicketData bindUItoModel() {
TicketData ticketData = new TicketData();
ticketData.setTrainFrom(textTrainFrom.getText());
ticketData.setTrainTo(textTrainTo.getText());
ticketData.setPrimaryTrainDate(textPrimaryTrainDate.getText());
ticketData.setExtraTrainDates(textExtraTrainDates.getText());
for (Component component : userPanelContainer.getComponents()) {
ticketData.getUserDatas().add(((UserPanel) component).bindUItoModel());
}
for (Component component : passengerPanelContainer.getComponents()) {
ticketData.getPassengerDatas().add(((PassengerPanel) component).bindUItoModel());
}
return ticketData;
}
Aggregations