📄 inputpanel.java
字号:
filterchooser.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
int index = ((JComboBox) event.getSource()).getSelectedIndex();
switch (index) {
case 0:
optionFilterPanel.removeAll();
optionFilterPanel.add(new JLabel(FILTER_NEXT_STEP),BorderLayout.SOUTH);
optionFilterPanel.revalidate();
optionFilterPanel.repaint();
break;
case 1:
optionFilterPanel.removeAll();
optionFilterPanel.add(createRandomOptionPanel(),BorderLayout.CENTER);
optionFilterPanel.add(new JLabel(FILTER_NEXT_STEP),BorderLayout.SOUTH);
optionFilterPanel.revalidate();
optionFilterPanel.repaint();
break;
case 2:
optionFilterPanel.removeAll();
optionFilterPanel.add(createIntervalOptionPanel(),BorderLayout.CENTER);
optionFilterPanel.add(new JLabel(FILTER_NEXT_STEP),BorderLayout.SOUTH);
optionFilterPanel.revalidate();
optionFilterPanel.repaint();
break;
}
}
});
filterchooser.setSelectedIndex(0);
}
/**
* Creates or returns the random option panel
* @return random option panel
*/
private JPanel createRandomOptionPanel() {
if (randomOptionPanel == null) {
// Creazione del pannello alla prima chiamata
randomOptionPanel = new JPanel();
randomNObs = new JSpinner(new SpinnerNumberModel(0,0,0,1));
randomNObs.setPreferredSize(new Dimension(70, 25));
randomOptionPanel.add(new JLabel("Number of observations:"),
BorderLayout.NORTH);
randomOptionPanel.add(randomNObs, BorderLayout.SOUTH);
}else{
if(obsNumb == -1){
randomNObs.setModel(new SpinnerNumberModel(0,0,0,1));
}else{
randomNObs.setModel(new SpinnerNumberModel(1,1,obsNumb,1));
}
}
return randomOptionPanel;
}
/**
* Creates or returns the interval option panel
* @return interval option panel
*/
private JPanel createIntervalOptionPanel() {
if (intervalOptionPanel == null) {
intervalOptionPanel = new JPanel(new BorderLayout());
JPanel fromPanel = new JPanel(new GridLayout(1,2));
JLabel fromLabel = new JLabel("From observation #: ",JLabel.RIGHT);
//fromLabel.setPreferredSize(new Dimension(70, 25));
fromPanel.add(fromLabel);
intervalFromObs = new JSpinner(new SpinnerNumberModel(0,0,0,1));
intervalFromObs.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e) {
if(((SpinnerNumberModel)intervalFromObs.getModel()).getNumber().longValue()
>=
((SpinnerNumberModel)intervalToObs.getModel()).getNumber().longValue())
((SpinnerNumberModel)intervalToObs.getModel())
.setValue(new Integer(((SpinnerNumberModel)intervalFromObs.getModel()).getNumber().intValue() + 1));
}
});
intervalFromObs.setPreferredSize(new Dimension(70,25));
JPanel fromPan = new JPanel(new FlowLayout(FlowLayout.LEFT));
fromPan.add(intervalFromObs);
fromPanel.add(fromPan);
JPanel toPanel = new JPanel(new GridLayout(1,2));
JLabel toLabel = new JLabel("To observation #: ",JLabel.RIGHT);
toLabel.setPreferredSize(new Dimension(70, 25));
toPanel.add(toLabel);
intervalToObs = new JSpinner(new SpinnerNumberModel(0,0,0,1));
intervalToObs.setPreferredSize(new Dimension(70,25));
JPanel toPan = new JPanel(new FlowLayout(FlowLayout.LEFT));
toPan.add(intervalToObs);
toPanel.add(toPan);
JPanel temp = new JPanel(new GridLayout(2,1,0,10));
temp.add(fromPanel, BorderLayout.NORTH);
temp.add(toPanel, BorderLayout.SOUTH);
intervalOptionPanel.add(temp,BorderLayout.NORTH);
}else{
if(obsNumb == -1){
intervalFromObs.setModel(new SpinnerNumberModel(0,0,0,1));
intervalToObs.setModel(new SpinnerNumberModel(0,0,0,1));
}else{
intervalFromObs.setModel(new SpinnerNumberModel(1,1,obsNumb-1,1));
intervalToObs.setModel(new SpinnerNumberModel(2,2,obsNumb,1));
}
}
return intervalOptionPanel;
}
/********** MENUBAR, TOOLBAR AND ACTIONS ***********/
/**
* Sets up workload analysis toolbar
*/
/* private void initToolBar(){
JToolBar toolbar = model.getParent().getWorkloadToolBar();
Action[] items = new Action[]{
FILE_NEW, FILE_SAVE, null,
HELP_SHOWHELP
};
String[] iconNames = new String[]{
"New", "Save", "Help"
};
for(int i=0, j=0; i<items.length; i++, j++){
// Tis is a particularcase as it's a toggle button
if(items[i] != null){
JButton button = new JButton(items[i]);
button.setText("");
button.setRolloverEnabled(true);
button.setBorderPainted(false);
button.setFocusPainted(false);
button.setContentAreaFilled(false);
button.setPressedIcon(ImageLoader.loadImage(iconNames[j]+"P"));
button.setRolloverIcon(ImageLoader.loadImage(iconNames[j]+"RO"));
button.setBorder(new EmptyBorder(0,0,0,0));
button.setMaximumSize(getMinimumSize());
toolbar.add(button);
}else{
toolbar.addSeparator();
j--;
}
}
}*/
/**
* Sets up workload analysis menubar
*/
/*private void initMenuBar(){
JMenuBar menuBar = model.getParent().getWorkloadMenuBar();
Action[][] menus = new Action[][]{
//File menu
{FILE_NEW, FILE_SAVE, null, FILE_EXIT},
//Help Menu
{HELP_SHOWHELP, null, HELP_CREDITS}
};
String[] menuNames = new String[]{"File","?"};
char[] mnemChars = new char[]{'f','?'};
for(int i=0; i<menus.length; i++){
//initialize menu
JMenu menu = new JMenu(menuNames[i]);
menu.setMnemonic(mnemChars[i]);
for(int j=0; j<menus[i].length;j++){
if(menus[i][j]!=null){
menu.add(new JMenuItem(menus[i][j]));
}else menu.addSeparator();
}
menuBar.add(menu);
}
}*/
/********** WIZARD MANAGEMENT FUNCTIONS **********/
// TODO controllare validita dei dati forniti nel pannello e creazione e passaggio informazioni al modello per il prossimo panello
// Chiamata prima di passare al prossimo pannello
public boolean canGoForward() {
return canGoOn;
}
// TODO controllare con Fuma cosa fare
// Chiamata quando dal pannello si torna indietro
public boolean canGoBack() {
if (JOptionPane.showConfirmDialog(this,"Are you sure want to go back to start screen ?",
"Back operation", JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE)
== JOptionPane.NO_OPTION)
return false;
//model.getParent().removeWorkload();
return true;
}
private class InputStatusListener implements ProgressStatusListener
{
public void statusEvent(EventStatus e) {
switch(e.getType()){
case EventStatus.ABORT_EVENT: abortEvent((EventFinishAbort)e);
break;
case EventStatus.DONE_EVENT: finishedEvent((EventFinishLoad)e);
break;
}
}
//Abort caricamento file input
private void abortEvent(EventFinishAbort e) {
JOptionPane.showMessageDialog(InputPanel.this,e.getMessage(),"LOADING ABORTED!!",JOptionPane.WARNING_MESSAGE);
loadOnRun = false;
canGoOn=false;
((JWatWizard)getParentWizard()).setEnableButton("Next >",false);
((JWatWizard)getParentWizard()).setEnableButton("Solve",false);
}
// dati caricati
private void finishedEvent(final EventFinishLoad e) {
JButton[] optBtn=new JButton[3];
JOptionPane pane;
optBtn[0]=new JButton("Continue");
optBtn[1]=new JButton("Show Log");
optBtn[2]=new JButton("Cancel");
pane = new JOptionPane("# observations processed: "+ e.valToRead()+"\n# correct observations "+ e.valReaded()+ "\nTo see errors press Show Log",JOptionPane.QUESTION_MESSAGE,JOptionPane.DEFAULT_OPTION,null,optBtn,null);
final JDialog dialog= pane.createDialog(InputPanel.this.getParentWizard(), "Loading Complete");
pane.selectInitialValue();
optBtn[0].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev) {
dialog.dispose();
try{
model.setMatrix(e.getMatrix());
}catch(OutOfMemoryError err){
JOptionPane.showMessageDialog(InputPanel.this,"Out of Memory error. Try with more memory","Error",JOptionPane.ERROR_MESSAGE);
loadOnRun = false;
return;
}
((JWatWizard)getParentWizard()).setEnableButton("Next >",true);
((JWatWizard)getParentWizard()).setEnableButton("Solve",false);
loadOnRun = false;
canGoOn=true;
((JWatWizard)getParentWizard()).showNextPanel();
}
});
optBtn[1].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev) {
dialog.setVisible(false);
final JDialog f=new JDialog();
f.setModal(true);
f.setTitle("Error log");
f.setSize(new Dimension(400,400));
f.setContentPane(new LogVisualizer(f));
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e) {
dialog.setVisible(true);
}
public void windowClosed(WindowEvent e) {
dialog.setVisible(true);
}
});
f.setVisible(true);
}
});
optBtn[2].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ev) {
dialog.dispose();
loadOnRun = false;
canGoOn=false;
System.gc();
((JWatWizard)getParentWizard()).setEnableButton("Next >",false);
((JWatWizard)getParentWizard()).setEnableButton("Solve",false);
}
});
dialog.show();
}
}
private static final String helpText = "<html>In this panel you can choose input data file and define or select a file format.<br><br>" +
"To load a file:" +
"<UL><LI> Select input file</LI>" +
"<LI> Select or define a format for the input file</LI>" +
"<LI> Select a sampling method (<I>if necessary</I>)</LI>" +
"<LI> Press Load button</LI></UL>" +
" To edit values, double-click on the desired cell" +
" and start typing.<br> <b>For a list of the available operations right-click" +
" on the table</b>.<br>" +
" Pressing DELETE removes all selected classes from the system.</html>";
public void help() {
JOptionPane.showMessageDialog(this, helpText, "Help", JOptionPane.INFORMATION_MESSAGE);
}
public void gotFocus(){
// Chiedere a utente se cancellare tutto
if(model.getMatrix() != null){
if(JOptionPane.showConfirmDialog(this,"This operation resets all data. Continue ?",
"WARNING",JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
model.resetModel();
resetOnNew();
((JWatWizard)getParentWizard()).setEnableButton("Solve",false);
}else{
parent.setLastPanel();
}
}else{
((JWatWizard)getParentWizard()).setEnableButton("Solve",false);
}
}
public void lostFocus(){
parent.setLastPanel(0);
}
public void resetOnNew(){
canGoOn = false;
((JWatVariableInputTableModel)inputTable.getModel()).resetTable();
inputTable.tableChanged(new TableModelEvent(inputTable.getModel()));
filechooser.setSelectedIndex(-1);
formatchooser.setSelectedIndex(-1);
filterchooser.setSelectedIndex(0);
numOfVars.setValue(new Integer(0));
observationNumb.setText(obsNumbString);
fileName.setText(obsFileName);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -