Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 16th, 2009, 01:53 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
SCOM connector using Java

Hi,

I am trying to create a connector for Microsoft SCOM(2007) . The wsdl is accessible at server and able to generate stub using JWSDP. But When i try to connect using the generated stub, I am getting an error,

Error..The security context token is expired or is not valid. The message was not processed.
javax.xml.ws.soap.SOAPFaultException: The security context token is expired or is not valid. The message was not processed.
at com.sun.xml.ws.encoding.soap.ClientEncoderDecoder. toMessageInfo(ClientEncoderDecoder.java:80)
at com.sun.xml.ws.encoding.soap.client.SOAPXMLDecoder .toMessageInfo(SOAPXMLDecoder.java:200)
at com.sun.xml.ws.protocol.soap.client.SOAPMessageDis patcher.receive(SOAPMessageDispatcher.java:549)
at com.sun.xml.ws.protocol.soap.client.SOAPMessageDis patcher.doSend(SOAPMessageDispatcher.java:288)
at com.sun.xml.ws.protocol.soap.client.SOAPMessageDis patcher.send(SOAPMessageDispatcher.java:153)
at com.sun.xml.ws.encoding.soap.internal.DelegateBase .send(DelegateBase.java:85)
at com.sun.xml.ws.client.EndpointIFInvocationHandler. implementSEIMethod(EndpointIFInvocationHandler.jav a:176)
at com.sun.xml.ws.client.EndpointIFInvocationHandler. invoke(EndpointIFInvocationHandler.java:105)
at $Proxy27.setup(Unknown Source)
at Test.OmcfProxy.main(OmcfProxy.java:238)



below is the code part:

ConnectorFrameworkDataAccess connectorFrameworkDataAccess = new ConnectorFrameworkDataAccess(new URL(""),new QName("","ConnectorFrameworkDataAccess"));
IConnectorFramework port = (IConnectorFramework)connectorFrameworkDataAccess. getPort(IConnectorFramework.class);
connectorInfo.setName(objectFactory.createConnecto rInfoName("Test OMCF"));
String connectionResult = port.setup(ObjectFactory.createConnectorInfo(conne ctorInfo));

Thanks for any help,
Thej

Reply With Quote
  #2  
Old October 30th, 2009, 08:27 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
file choose demo

package com.nal;

import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Scanner;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;


public class FileChooseDemo extends JPanel
implements ActionListener {
static private final String newline = "\n";
JButton openButton, saveButton;
JTextArea log;
JTable jTable;
JFileChooser fc;
File file;
Hashtable table = new Hashtable();
String[] columnNames = {"Component",
"Reliability"};


Object[][] data = {
{"P11", "0.1"},
{"P12", "0.2"},
{"P13", "0.3"},
{"P21", "0.4"},
{"p22", "0.5"}
};

public FileChooseDemo() {
super(new BorderLayout());


jTable = new JTable(data, columnNames);
jTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
jTable.setFillsViewportHeight(true);

//Create the log first, because the action listeners
//need to refer to it.
log = new JTextArea(5,20);
log.setMargin(new Insets(5,5,5,5));
log.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(jTable);

//Create a file chooser
fc = new JFileChooser();

openButton = new JButton("Open a File...");
openButton.addActionListener(this);
saveButton = new JButton("Save a File...");
saveButton.addActionListener(this);

//For layout purposes, put the buttons in a separate panel
JPanel buttonPanel = new JPanel(); //use FlowLayout
buttonPanel.add(openButton);
buttonPanel.add(saveButton);

//Add the buttons and the log to this panel.
add(buttonPanel, BorderLayout.PAGE_START);
add(logScrollPane, BorderLayout.CENTER);
}

public void actionPerformed(ActionEvent e) {

//Handle open button action.
if (e.getSource() == openButton) {
int returnVal = fc.showOpenDialog(FileChooseDemo.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
System.out.println(file.getPath());
try {
processLineByLine();
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//This is where a real application would open the file.
log.append("Opening: " + file.getName() + "." + newline);
} else {
log.append("Open command cancelled by user." + newline);
}
log.setCaretPosition(log.getDocument().getLength() );

//Handle save button action.
} else if (e.getSource() == saveButton) {
int returnVal = fc.showSaveDialog(FileChooseDemo.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would save the file.
log.append("Saving: " + file.getName() + "." + newline);
} else {
log.append("Save command cancelled by user." + newline);
}
log.setCaretPosition(log.getDocument().getLength() );
}
}


public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(file);
try {
//first use a Scanner to get each line
while ( scanner.hasNextLine() ){
processLine( scanner.nextLine() );
}
System.out.println("HashTable"+ table.values());
System.out.println("HashTable"+ table.keys());
}
finally {
//ensure the underlying stream is always closed
scanner.close();
}
}
//table.CopyTo(Array array, 0);
protected void processLine(String aLine){
//use a second Scanner to parse the content of each line
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter("=");
Object [][] a2 = new Object[10][2];
int i = 0,j=0;
if ( scanner.hasNext() ){
String name = scanner.next();
String value = scanner.next();
System.out.println("Name is : " + quote(name.trim()) + ", and Value is : " + quote(value.trim()));

table.put(quote(name.trim()), quote(value.trim()));
}
else {
System.out.println("Empty or invalid line. Unable to process.");
}
//(no need for finally here, since String is source)
scanner.close();
}

private String quote(String aText){
String QUOTE = "'";
return QUOTE + aText + QUOTE;
}



private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FileChooserDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

//Add content to the window.
frame.add(new FileChooseDemo());

//Display the window.
frame.pack();
frame.setVisible(true);
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}

Last edited by Thej : November 2nd, 2009 at 03:42 AM. Reason: modified

Reply With Quote
  #3  
Old November 2nd, 2009, 05:40 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
string tokenizer

package com.nal;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringExtractor {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

List listOfStrings = new ArrayList();
String[] words = null;
String token = "((P11+P12+P13)*(p21+P22+P23))";
StringTokenizer strToken = null;
String temp = token.substring(token.indexOf("(") + 1, token
.lastIndexOf(")"));
// System.out.println("index:"+token.indexOf("(")+":"+ token.lastIndexOf(")"));
// System.out.println(token.substring(token.indexOf("(")+1, token.lastIndexOf(")")));

final Pattern p = Pattern.compile("(\\(.*?\\))");
final Matcher m = p.matcher(temp);
while (m.find()) {
System.out.println(m.group());
listOfStrings.add(m.group().substring(m.group().in dexOf("(") + 1,
m.group().lastIndexOf(")")));
}

/* for (Iterator<String> i = listOfStrings.iterator( ); i.hasNext( ); ) {
System.out.println("List contains"+i.next());
}*/

for (Iterator<String> i = listOfStrings.iterator(); i.hasNext() {
String s = i.next();
strToken = new StringTokenizer(s, "+");
int j=0;
System.out.println(strToken.countTokens());
while (strToken.hasMoreTokens()) {
System.out.println(strToken.nextToken());
}
}

}

}

Reply With Quote
  #4  
Old November 2nd, 2009, 08:39 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
SystemSafety

package com.nal;


import java.awt.*;
import java.awt.event.*;
import java.util.Enumeration;
import java.util.Hashtable;

import javax.swing.*;

public class ComboBoxDemo extends JPanel
implements ActionListener {
JLabel picture;

public ComboBoxDemo() {
super(new BorderLayout());

JLabel mainLabel1 = new JLabel("Enter Safety Value Of X:");
String[] petStrings = { "Safety(0)", "Hazardous(1)", "Unsafe(2)"};

JPanel buttonPanela = new JPanel(new FlowLayout());
JComboBox petList = new JComboBox(petStrings);
buttonPanela.add(mainLabel1);
buttonPanela.add(petList);

//petList.setSelectedIndex(4);
petList.addActionListener(this);

JButton calculate = new JButton("Calculate Safety");
JButton Reset = new JButton("Reset Values");
JButton Save = new JButton("Save To File");
JPanel buttonPanelb = new JPanel(new FlowLayout()); //use FlowLayout
buttonPanelb.add(calculate);
buttonPanelb.add(Reset);
buttonPanelb.add(Save);

JLabel lbl1 = new JLabel("Safe");
JLabel lbl2 = new JLabel("Hazardous");
JLabel lbl3 = new JLabel("UnSafe");

JButton chk1 = new JButton();
chk1.setBounds(0, 0, 5, 10);
chk1.setBackground(Color.GREEN);
chk1.setEnabled(false);
JButton chk2 = new JButton();
chk2.setBounds(0, 0, 10, 10);
chk2.setBackground(Color.ORANGE);
chk2.setEnabled(false);
JButton chk3 = new JButton();
chk3.setBounds(0, 0, 10, 10);
chk3.setBackground(Color.RED);
chk3.setEnabled(false);



JPanel buttonPanel2 = new JPanel(new FlowLayout()); //use FlowLayout
buttonPanel2.add(chk1);
buttonPanel2.add(lbl1);
buttonPanel2.add(chk2);
buttonPanel2.add(lbl2);
buttonPanel2.add(chk3);
buttonPanel2.add(lbl3);

//Lay out the demo.
add(buttonPanela, BorderLayout.PAGE_START);
add(buttonPanelb,BorderLayout.CENTER);
add(buttonPanel2, BorderLayout.PAGE_END);

setBorder(BorderFactory.createEmptyBorder(20,20,20 ,20));
}

/** Listens to the combo box. */
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
String petName = (String)cb.getSelectedItem();

}


/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
static Hashtable table = new Hashtable();
public static void createSystemSafety(Hashtable table2){

Enumeration e = table.elements();

while(e.hasMoreElements())
{

JPanel buttonPanel4 = new JPanel(new FlowLayout()); //use FlowLayout
JLabel lbl6 = new JLabel(e.nextElement().toString());
buttonPanel4.add(lbl6);
System.out.println(e.nextElement());
}

}

private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("ComboBox");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

//Create and set up the content pane.
JComponent newContentPane = new ComboBoxDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setSize(500,400);
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

Reply With Quote
  #5  
Old November 8th, 2009, 06:27 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
SystemReliability

package com.nal;

import java.io.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;

public class SystemReliability extends JPanel implements ActionListener {
static private final String newline = "\n";
JButton openButton, saveButton, enterButton, reliableButton;
JLabel lbl,reliableLbl;
JPanel buttonPanel, buttonPanel2, buttonPanel4;
static JPanel buttonPanel3;
JTextField jtf,jtf2;
JTextArea log;
JTable jTable;
static JTable tableC;
JFileChooser fc;
File file;
String token;
Hashtable table = new Hashtable();
String[] columnNames = { "Component", "Reliability" };
List component = new ArrayList();

Object[][] data = { { "P11", "0.1" }, { "P12", "0.2" }, { "P13", "0.3" },
{ "P21", "0.4" }, { "p22", "0.5" } };
Object rowData[][];

public SystemReliability() {
super(new BorderLayout());

jTable = new JTable(data, columnNames);
jTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
jTable.setFillsViewportHeight(true);

//Create the log first, because the action listeners
//need to refer to it.
log = new JTextArea(5, 20);
log.setMargin(new Insets(5, 5, 5, 5));
log.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(jTable);

//Create a file chooser
fc = new JFileChooser();

lbl = new JLabel("Enter System Algebra");
jtf = new JTextField(15);
reliableLbl = new JLabel("System Reliability");
jtf2 = new JTextField(15);
openButton = new JButton("From File");
openButton.addActionListener(this);
saveButton = new JButton("Save a File...");
saveButton.addActionListener(this);

enterButton = new JButton("Enter");
enterButton.addActionListener(this);

reliableButton = new JButton("Get Reliability");
reliableButton.addActionListener(this);

//For layout purposes, put the buttons in a separate panel
buttonPanel = new JPanel(); //use FlowLayout
buttonPanel.add(lbl);
buttonPanel.add(jtf);

buttonPanel.add(openButton);
buttonPanel.add(enterButton);

//buttonPanel.add(saveButton);

//Add the buttons and the log to this panel.
add(buttonPanel, BorderLayout.PAGE_START);

buttonPanel2 = new JPanel(new FlowLayout()); //use FlowLayout
buttonPanel3 = new JPanel(new FlowLayout()); //use FlowLayout
buttonPanel4 = new JPanel(new FlowLayout()); //use FlowLayout

JLabel lbl1 = new JLabel("Safe");
JLabel lbl2 = new JLabel("Hazardous");
JLabel lbl3 = new JLabel("UnSafe");

JButton chk1 = new JButton();
chk1.setBounds(0, 0, 5, 10);
chk1.setBackground(Color.GREEN);
chk1.setEnabled(false);
JButton chk2 = new JButton();
chk2.setBounds(0, 0, 10, 10);
chk2.setBackground(Color.ORANGE);
chk2.setEnabled(false);
JButton chk3 = new JButton();
chk3.setBounds(0, 0, 10, 10);
chk3.setBackground(Color.RED);
chk3.setEnabled(false);

buttonPanel2.add(chk1);
buttonPanel2.add(lbl1);
buttonPanel2.add(chk2);
buttonPanel2.add(lbl2);
buttonPanel2.add(chk3);
buttonPanel2.add(lbl3);

buttonPanel4.add(reliableButton);
buttonPanel4.add(reliableLbl);
buttonPanel4.add(jtf2);
add(buttonPanel3, BorderLayout.CENTER);
add(buttonPanel4, BorderLayout.PAGE_END);
}

public void actionPerformed(ActionEvent e) {

//Handle open button action.
if (e.getSource() == openButton) {
int returnVal = fc.showOpenDialog(SystemReliability.this);

if (returnVal == JFileChooser.APPROVE_OPTION) {
file = fc.getSelectedFile();
System.out.println(file.getPath());
try {
processLineByLine();

Object rowData[][] = getArrayInfo(component2);
//System.out.println("Row data"+rowData);

/* for (int r = 0; r < rowData.length; r++) {
for (int c = 0; c < rowData[r].length; c++) {
System.out.print(" " + rowData[r][c]);
}
System.out.println("");
}*/

JTableCreator(rowData);
updateUI();

} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//This is where a real application would open the file.
log.append("Opening: " + file.getName() + "." + newline);
} else {
log.append("Open command cancelled by user." + newline);
}
log.setCaretPosition(log.getDocument().getLength() );

//Handle save button action.
} else if (e.getSource() == saveButton) {
int returnVal = fc.showSaveDialog(SystemReliability.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//This is where a real application would save the file.
log.append("Saving: " + file.getName() + "." + newline);
} else {
log.append("Save command cancelled by user." + newline);
}
log.setCaretPosition(log.getDocument().getLength() );
}
else if (e.getSource() == reliableButton) {
List l1 = new ArrayList ();
int s = GetDataLength(tableC);
for(int i = 0; i<s;i++){
Object obj1 = GetData(tableC, i, 1);
l1.add(GetData(tableC, i, 1));
}
System.out.println(l1);
}

else if (e.getSource() == enterButton) {

List listOfStrings = new ArrayList();
List component = new ArrayList();

String[] words = null;
token = "((P11+P12+P13)*(p21+P22))";
StringTokenizer strToken = null;
String temp = token.substring(token.indexOf("(") + 1, token
.lastIndexOf(")"));
// System.out.println("index:"+token.indexOf("(")+":"+ token.lastIndexOf(")"));
// System.out.println(token.substring(token.indexOf("(")+1, token.lastIndexOf(")")));

final Pattern p = Pattern.compile("(\\(.*?\\))");
final Matcher m = p.matcher(temp);
while (m.find()) {
//System.out.println(m.group());
listOfStrings
.add(m.group().substring(m.group().indexOf("(") + 1,
m.group().lastIndexOf(")")));
}

for (Iterator<String> i = listOfStrings.iterator(); i.hasNext() {
String s = i.next();
strToken = new StringTokenizer(s, "+");
int j = 0;

//System.out.println(strToken.countTokens());
while (strToken.hasMoreTokens()) {
component.add(strToken.nextToken());
//System.out.println(strToken.nextToken());
}
}
System.out.println("List" + component);
Object rowData[][] = getArrayInfo(component);
//System.out.println("Row data"+rowData);

for (int r = 0; r < rowData.length; r++) {
for (int c = 0; c < rowData[r].length; c++) {
System.out.print(" " + rowData[r][c]);
}
System.out.println("");
}

JTableCreator(rowData);
updateUI();

}
}

public Object GetData(JTable table, int row_index, int col_index){
return table.getModel().getValueAt(row_index, col_index);
}

public int GetDataLength(JTable table){
return table.getModel().getRowCount();
}

public static String[][] getArrayInfo(List comp) {
String info[][];
info = new String[comp.size()][2];
for (int i = 0; i < comp.size(); i++) {
for (int j = 0; j < info[i].length; j++) {

info[i][j] = comp.get(i).toString();

}
}
return info;
}

public static void JTableCreator(Object[][] rowData) {

String col[] = { "Component", "Reliability" };
DefaultTableModel model = new DefaultTableModel(rowData, col);
tableC = new JTable(model);
JTableHeader header = tableC.getTableHeader();
header.setBackground(Color.yellow);
JScrollPane pane = new JScrollPane(tableC);
buttonPanel3.add(tableC, BorderLayout.CENTER);
}

public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(file);
try {
//first use a Scanner to get each line
while (scanner.hasNextLine()) {
processLine(scanner.nextLine());
}

} finally {
//ensure the underlying stream is always closed
scanner.close();
}
}

List component2 = new ArrayList();

//table.CopyTo(Array array, 0);
protected void processLine(String aLine) {
//use a second Scanner to parse the content of each line
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter("=");
Object[][] a2 = new Object[10][2];
int i = 0, j = 0;
if (scanner.hasNext()) {
String name = scanner.next();
String value = scanner.next();
System.out.println("Name is : " + quote(name.trim())
+ ", and Value is : " + quote(value.trim()));

table.put(quote(name.trim()), quote(value.trim()));
component2.add(quote(name.trim()));
} else {
System.out.println("Empty or invalid line. Unable to process.");
}
System.out.println("Table" +table);
//(no need for finally here, since String is source)
scanner.close();
}

private String quote(String aText) {
String QUOTE = "'";
return QUOTE + aText + QUOTE;
}

private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("FileChooserDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setSize(500, 500);
//Add content to the window.
frame.add(new SystemReliability());

//Display the window.
//frame.pack();
frame.setVisible(true);
}

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event dispatch thread.
*/
public static void main(String[] args) {
//Schedule a job for the event dispatch thread:
//creating and showing this application's GUI.
SwingUtilities.invokeLater(new Runnable() {
public void run() {
//Turn off metal's use of bold fonts
UIManager.put("swing.boldMetal", Boolean.FALSE);
createAndShowGUI();
}
});
}
}

Reply With Quote
  #6  
Old November 8th, 2009, 08:03 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
SystemSafetyWorking

package com.nal;

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;


public class SystemSafetyWorking implements ActionListener{


/*
* A 1.4 application that uses SpringLayout to create a forms-type layout.
* Other files required: SpringUtilities.java.
*/

/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
static JButton calculate,Reset,Save,Browse;
static JComboBox petList;
static JFileChooser fc;
static ArrayList<String> component2 = new ArrayList<String>();

private static void createAndShowGUI() {
String[] petStrings = { "Safety(0)", "Hazardous(1)", "Unsafe(2)"};
ArrayList<String> arrayList = new ArrayList<String>();
/* arrayList.add("P1");
arrayList.add("P2");
arrayList.add("P3");
arrayList.add("P4");
arrayList.add("P5");*/

fc = new JFileChooser();

int numPairs = component2.size();
String[] labels3 = new String[numPairs];
labels3 = component2.toArray(labels3);
//Create and populate the panel.
JPanel p = new JPanel(new SpringLayout());
for (int i = 0; i < numPairs; i++) {

JLabel l1 = new JLabel("-->Sub System : "+labels3[i], JLabel.TRAILING);
p.add(l1);

JLabel l = new JLabel("Enter Safety Value of "+labels3[i], JLabel.TRAILING);
p.add(l);
JTextField textField = new JTextField(10);
petList = new JComboBox(petStrings);
petList.addActionListener(new SystemSafetyWorking());

l.setLabelFor(petList);
p.add(petList);
}

JPanel browsePanel = new JPanel(new FlowLayout()); //use FlowLayout
Browse = new JButton("Browse File");
Browse.addActionListener(new SystemSafetyWorking());
browsePanel.add(Browse);

calculate = new JButton("Calculate Safety");
calculate.addActionListener(new SystemSafetyWorking());
Reset = new JButton("Reset Values");
Reset.addActionListener(new SystemSafetyWorking());
Save = new JButton("Save To File");
Save.addActionListener(new SystemSafetyWorking());
JPanel buttonPanelb = new JPanel(new FlowLayout()); //use FlowLayout
buttonPanelb.add(calculate);
buttonPanelb.add(Reset);
buttonPanelb.add(Save);

JLabel lbl1 = new JLabel("Safe");
JLabel lbl2 = new JLabel("Hazardous");
JLabel lbl3 = new JLabel("UnSafe");

JButton chk1 = new JButton();
chk1.setBounds(0, 0, 5, 10);
chk1.setBackground(Color.GREEN);
chk1.setEnabled(false);
JButton chk2 = new JButton();
chk2.setBounds(0, 0, 10, 10);
chk2.setBackground(Color.ORANGE);
chk2.setEnabled(false);
JButton chk3 = new JButton();
chk3.setBounds(0, 0, 10, 10);
chk3.setBackground(Color.RED);
chk3.setEnabled(false);



JPanel buttonPanel2 = new JPanel(new FlowLayout()); //use FlowLayout
buttonPanel2.add(chk1);
buttonPanel2.add(lbl1);
buttonPanel2.add(chk2);
buttonPanel2.add(lbl2);
buttonPanel2.add(chk3);
buttonPanel2.add(lbl3);

//Lay out the panel.
SpringUtilities.makeCompactGrid(p,
numPairs, 3, //rows, cols
6, 6, //initX, initY
6, 6); //xPad, yPad


//Create and set up the window.
JFrame frame = new JFrame("Calculate System Safety");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.setVisible(false);
frame.setSize(500,500);
//Set up the content pane.
// p.setOpaque(true); //content panes must be opaque
//frame.setContentPane(p);
Container contentPane = frame.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(browsePanel);
contentPane.add(p);
contentPane.add(buttonPanelb);
contentPane.add(buttonPanel2);
//Display the window.
// frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}

protected void processLine(String aLine) {
//use a second Scanner to parse the content of each line
Scanner scanner = new Scanner(aLine);
scanner.useDelimiter("=");
Object[][] a2 = new Object[10][2];
int i = 0, j = 0;
if (scanner.hasNext()) {
String name = scanner.next();
String value = scanner.next();
System.out.println("Name is : " + quote(name.trim())
+ ", and Value is : " + quote(value.trim()));
component2.add(quote(name.trim()));
} else {
System.out.println("Empty or invalid line. Unable to process.");
}
//(no need for finally here, since String is source)
scanner.close();
}

private String quote(String aText) {
String QUOTE = "'";
return QUOTE + aText + QUOTE;
}

public final void processLineByLine() throws FileNotFoundException {
Scanner scanner = new Scanner(file);
try {
//first use a Scanner to get each line
while (scanner.hasNextLine()) {
processLine(scanner.nextLine());
}

} finally {
//ensure the underlying stream is always closed
scanner.close();
}
}

File file;

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == calculate) {


}
else if (e.getSource() == Reset) {
System.out.println("Reset");
//petList.setSelectedIndex(0);
}
else if (e.getSource() == Save) {


}
else if (e.getSource() == Browse) {
int returnVal = fc.showOpenDialog(SystemSafetyWorking.Browse);

if (true) {
file = fc.getSelectedFile();
try {
processLineByLine();
createAndShowGUI();

} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//This is where a real application would open the file.

} else {

}

}
}
}

Reply With Quote
  #7  
Old November 8th, 2009, 08:04 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
SpringUtilities.java

package com.nal;

import javax.swing.*;
import javax.swing.SpringLayout;
import java.awt.*;

/**
* A 1.4 file that provides utility methods for
* creating form- or grid-style layouts with SpringLayout.
* These utilities are used by several programs, such as
* SpringBox and SpringCompactGrid.
*/
public class SpringUtilities {
/**
* A debugging utility that prints to stdout the component's
* minimum, preferred, and maximum sizes.
*/
public static void printSizes(Component c) {
System.out.println("minimumSize = " + c.getMinimumSize());
System.out.println("preferredSize = " + c.getPreferredSize());
System.out.println("maximumSize = " + c.getMaximumSize());
}

/**
* Aligns the first <code>rows</code> * <code>cols</code>
* components of <code>parent</code> in
* a grid. Each component is as big as the maximum
* preferred width and height of the components.
* The parent is made just big enough to fit them all.
*
* @param rows number of rows
* @param cols number of columns
* @param initialX x location to start the grid at
* @param initialY y location to start the grid at
* @param xPad x padding between cells
* @param yPad y padding between cells
*/
public static void makeGrid(Container parent,
int rows, int cols,
int initialX, int initialY,
int xPad, int yPad) {
SpringLayout layout;
try {
layout = (SpringLayout)parent.getLayout();
} catch (ClassCastException exc) {
System.err.println("The first argument to makeGrid must use SpringLayout.");
return;
}

Spring xPadSpring = Spring.constant(xPad);
Spring yPadSpring = Spring.constant(yPad);
Spring initialXSpring = Spring.constant(initialX);
Spring initialYSpring = Spring.constant(initialY);
int max = rows * cols;

//Calculate Springs that are the max of the width/height so that all
//cells have the same size.
Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)).
getWidth();
Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)).
getWidth();
for (int i = 1; i < max; i++) {
SpringLayout.Constraints cons = layout.getConstraints(
parent.getComponent(i));

maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth());
maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight());
}

//Apply the new width/height Spring. This forces all the
//components to have the same size.
for (int i = 0; i < max; i++) {
SpringLayout.Constraints cons = layout.getConstraints(
parent.getComponent(i));

cons.setWidth(maxWidthSpring);
cons.setHeight(maxHeightSpring);
}

//Then adjust the x/y constraints of all the cells so that they
//are aligned in a grid.
SpringLayout.Constraints lastCons = null;
SpringLayout.Constraints lastRowCons = null;
for (int i = 0; i < max; i++) {
SpringLayout.Constraints cons = layout.getConstraints(
parent.getComponent(i));
if (i % cols == 0) { //start of new row
lastRowCons = lastCons;
cons.setX(initialXSpring);
} else { //x position depends on previous component
cons.setX(Spring.sum(lastCons.getConstraint(Spring Layout.EAST),
xPadSpring));
}

if (i / cols == 0) { //first row
cons.setY(initialYSpring);
} else { //y position depends on previous row
cons.setY(Spring.sum(lastRowCons.getConstraint(Spr ingLayout.SOUTH),
yPadSpring));
}
lastCons = cons;
}

//Set the parent's size.
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH,
Spring.sum(
Spring.constant(yPad),
lastCons.getConstraint(SpringLayout.SOUTH)));
pCons.setConstraint(SpringLayout.EAST,
Spring.sum(
Spring.constant(xPad),
lastCons.getConstraint(SpringLayout.EAST)));
}

/* Used by makeCompactGrid. */
private static SpringLayout.Constraints getConstraintsForCell(
int row, int col,
Container parent,
int cols) {
SpringLayout layout = (SpringLayout) parent.getLayout();
Component c = parent.getComponent(row * cols + col);
return layout.getConstraints(c);
}

/**
* Aligns the first <code>rows</code> * <code>cols</code>
* components of <code>parent</code> in
* a grid. Each component in a column is as wide as the maximum
* preferred width of the components in that column;
* height is similarly determined for each row.
* The parent is made just big enough to fit them all.
*
* @param rows number of rows
* @param cols number of columns
* @param initialX x location to start the grid at
* @param initialY y location to start the grid at
* @param xPad x padding between cells
* @param yPad y padding between cells
*/
public static void makeCompactGrid(Container parent,
int rows, int cols,
int initialX, int initialY,
int xPad, int yPad) {
SpringLayout layout;
try {
layout = (SpringLayout)parent.getLayout();
} catch (ClassCastException exc) {
System.err.println("The first argument to makeCompactGrid must use SpringLayout.");
return;
}

//Align all cells in each column and make them the same width.
Spring x = Spring.constant(initialX);
for (int c = 0; c < cols; c++) {
Spring width = Spring.constant(0);
for (int r = 0; r < rows; r++) {
width = Spring.max(width,
getConstraintsForCell(r, c, parent, cols).
getWidth());
}
for (int r = 0; r < rows; r++) {
SpringLayout.Constraints constraints =
getConstraintsForCell(r, c, parent, cols);
constraints.setX(x);
constraints.setWidth(width);
}
x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad)));
}

//Align all cells in each row and make them the same height.
Spring y = Spring.constant(initialY);
for (int r = 0; r < rows; r++) {
Spring height = Spring.constant(0);
for (int c = 0; c < cols; c++) {
height = Spring.max(height,
getConstraintsForCell(r, c, parent, cols).
getHeight());
}
for (int c = 0; c < cols; c++) {
SpringLayout.Constraints constraints =
getConstraintsForCell(r, c, parent, cols);
constraints.setY(y);
constraints.setHeight(height);
}
y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad)));
}

//Set the parent's size.
SpringLayout.Constraints pCons = layout.getConstraints(parent);
pCons.setConstraint(SpringLayout.SOUTH, y);
pCons.setConstraint(SpringLayout.EAST, x);
}
}

Reply With Quote
  #8  
Old November 8th, 2009, 08:05 AM
Thej Thej is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 8 Thej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 m 19 sec
Reputation Power: 0
Test.txt

p11 = 0.1
p12 = 0.2
p13 = 0.3
p21 = 0.4
p22 = 0.5

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > SCOM connector using Java


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap