hello

package com.lmig.swing;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Locale;
import java.util.Scanner;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
public class Swing_Ldif_Generator extends JFrame {
static String stringPath = null;
static String savedPath = null;
static String oPstring = null, tempFile = null, stringOpen = null;
static StringBuffer stringBuffer = new StringBuffer();
public static int bMe=0;
static boolean incrementB=false;
public static void main(String[] args) {
new Swing_Ldif_Generator();
}

public static void centreWindow(Window frame) {
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() – frame.getWidth()) / 150);
int y = (int) ((dimension.getHeight() – frame.getHeight()) / 275);
frame.setLocation(x, y);
}

public Swing_Ldif_Generator() {
final JFrame window = new JFrame();

centreWindow(window);

window.setLayout(new GridBagLayout());
JButton open = new JButton(“Import File”), save = new JButton(
“Output Path”), extract = new JButton(“Generate LDIF”), values = new JButton(
“Append Data”), view = new JButton(“Modify Specific Data”);

final JPanel top = new JPanel();
final JPanel middle = new JPanel();
final JPanel bottom = new JPanel();

middle.setBackground(Color.GRAY);
bottom.setBackground(Color.gray);

bottom.add(open);
bottom.add(save);
bottom.add(extract);
bottom.add(values);
bottom.add(view);

final JTextField jTextField = new JTextField(
“Please Paste the list of Dn’s below or Click Input File and Choose the desired file”,
50);
jTextField.setEditable(false);
top.setBackground(Color.gray);

final JTextArea display = new JTextArea(35,50);
display.setBackground(Color.DARK_GRAY);
display.setForeground(Color.white);
display.setEditable(true);
JScrollPane scroll = new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scroll);
JButton buttonChange = new JButton(“Generate LDIF”);
middle.add(buttonChange);
final JTextArea displayChange = new JTextArea(35, 50);
displayChange.setBackground(Color.DARK_GRAY);
displayChange.setForeground(Color.white);
displayChange.setEditable(true);
JScrollPane scrollCahnge = new JScrollPane(displayChange);
scrollCahnge.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scrollCahnge.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scrollCahnge);
values.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
middle.removeAll();
middle.updateUI();
final JTextArea display1 = new JTextArea(5, 25);
display1.setText(“Sample Text”);
display1.setBackground(Color.DARK_GRAY);
display1.setForeground(Color.white);
display1.setEditable(true); //
JScrollPane scroll1 = new JScrollPane(display1);
scroll1.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll1.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scroll1);

JButton buttonChange = new JButton(“Append the Common Data”);
middle.add(buttonChange);
final JTextArea display = new JTextArea(18, 80);
display.setText(oPstring);
display.setBackground(Color.DARK_GRAY);
display.setForeground(Color.white);
display.setEditable(true); //
JScrollPane scroll = new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scroll);
buttonChange.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
String[] lines = display1.getText().split(“\\n”);
try {
new Append().appendLogic(lines);
try {
if (new File(Append.file + “changeupdate”
+ “.txt”).length() != 0) {
oPstring = readFile(Append.file
+ “changeupdate” + “.txt”);
display.setText(oPstring);
}
} catch (IOException e) {
e.printStackTrace();
}

} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
});
JButton button4 = new JButton(“Save the Content to file”);
middle.add(button4);
button4.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
PrintWriter printer = null;
String s[] = display.getText().split(“\\r?\\n”);
ArrayList<String> arrList = new ArrayList<String>(
Arrays.asList(s));
try {
printer = new PrintWriter(new File(Append.file
+ “changeupdate2” + “.txt”));
Iterator<String> iterator = arrList.iterator();
while (iterator.hasNext()) {
printer.write(iterator.next());
printer.write(System.lineSeparator());
}
printer.flush();
printer.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
});
}
});
view.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
middle.removeAll();
middle.updateUI();
final JTextField field = new JTextField(“Old Value”, 30);
Font font = new Font(“Courier”, Font.BOLD, 12);
field.setFont(font);
final JTextField field2 = new JTextField(“New Value”, 30);
Font font2 = new Font(“Courier”, Font.BOLD, 12);
field2.setFont(font2);
middle.add(field);
middle.add(field2);
String ops[] = {“Edit Existing Feild”,
“Edit Existing Value”, “Add New Feild”,
“Add New Value”, “Delete Existing Value”,
“Delete Existing Value” };

final JComboBox cb = new JComboBox(ops);
cb.setBounds(50, 50, 100, 30);
middle.add(cb);
JButton buttonChange = new JButton(“change here”);
middle.add(buttonChange);
final JTextArea display = new JTextArea(20, 80);
try {
if(bMe!=1){
oPstring = readFile(Append.file + “changeupdate2”
+ “.txt”);
tempFile = Append.file + “changeupdate2” + “.txt”;
}else{
oPstring = readFile( Swing_Ldif_Generator.savedPath+”append2.txt”);
tempFile = Swing_Ldif_Generator.savedPath+”append2.txt”;

}
/*if (new File({Append.file + “changeupdate2” + “.txt”)
*
.length() != 0) {
oPstring = readFile(Append.file + “changeupdate2”
+ “.txt”);
tempFile = Append.file + “changeupdate2” + “.txt”;
} else if (new File(Append.file + “changeupdate” + “.txt”)
.length() != 0) {
oPstring = readFile(Append.file + “changeupdate”
+ “.txt”);
tempFile = Append.file + “changeupdate” + “.txt”;
} else if (new File(NewDesign.savedPath + “change” + “.txt”)
.length() != 0) {
oPstring = readFile(NewDesign.savedPath + “change”
+ “.txt”);
tempFile = NewDesign.savedPath + “change” + “.txt”;
} else if (new File(NewDesign.savedPath + “.txt”).length() != 0) {
oPstring = readFile(NewDesign.savedPath + “.txt”);
tempFile = NewDesign.savedPath + “.txt”;
} else {
oPstring = readFile(NewDesign.stringPath + “.txt”);
tempFile = NewDesign.stringPath + “.txt”;
}
if(bMe==1){*/

// }
} catch (IOException e) {
e.printStackTrace();
}
display.setText(oPstring);
display.setBackground(Color.DARK_GRAY);
display.setForeground(Color.white);
display.setEditable(true); //
JScrollPane scroll = new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scroll);
JButton button4 = new JButton(“Save the Content to file”);
buttonChange.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
String string = field.getText();
String string2 = field2.getText();
String string3 = String.valueOf(cb.getSelectedItem());
try {
Append.AddDeleteAppend(string, string2, string3,
tempFile);
try {
oPstring = readFile(Append.tempFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
display.setText(oPstring);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

});
button4.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
PrintWriter printer = null;
String s[] = display.getText().split(“\\r?\\n”);
ArrayList<String> arrList = new ArrayList<String>(
Arrays.asList(s));
try {
printer = new PrintWriter(new File(
Swing_Ldif_Generator.savedPath + “append2.txt”));
Iterator<String> iterator = arrList.iterator();
while (iterator.hasNext()) {
printer.write(iterator.next());
printer.write(System.lineSeparator());
}
bMe=1;
printer.flush();
printer.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
});
middle.add(button4);
}
});

extract.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
writeLogic();
if (stringPath != null) {
try {
String string = readFile(Swing_Ldif_Generator.savedPath +”one”+”.txt”);
middle.removeAll();
middle.updateUI();
middle.setBorder(new TitledBorder(new EtchedBorder()));
final JTextArea display = new JTextArea(25, 80);
display.setText(string);
display.setBackground(Color.DARK_GRAY);
display.setForeground(Color.white);
display.setEditable(true); //
JScrollPane scroll = new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scroll);

JButton button = new JButton(“Save the Content to file”);
button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
PrintWriter printer = null;
String s[] = display.getText().split(“\\r?\\n”);
ArrayList<String> arrList = new ArrayList<String>(
Arrays.asList(s));
try {
printer = new PrintWriter(new File(
Swing_Ldif_Generator.savedPath + “change”
+ “.txt”));
Iterator<String> iterator = arrList
.iterator();
while (iterator.hasNext()) {
printer.write(iterator.next());
printer.write(System.lineSeparator());
}
printer.flush();
printer.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
});
middle.add(button);
} catch (IOException e1) {
e1.printStackTrace();
}
}
}

private void writeLogic() {
PrintWriter printer = null;
String s[] = display.getText().split(“\\r?\\n”);
ArrayList<String> arrList = new ArrayList<String>(
Arrays.asList(s));
try {
printer = new PrintWriter(new File(
Swing_Ldif_Generator.savedPath + “one”
+ “.txt”));
Iterator<String> iterator = arrList
.iterator();
while (iterator.hasNext()) {
printer.write(iterator.next());
printer.write(System.lineSeparator());
}
printer.flush();
printer.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
}
});

open.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stringOpen=display.getText();
middle.removeAll();
middle.updateUI();
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setPreferredSize(new Dimension(800, 400));
int value = jFileChooser.showSaveDialog(middle);
jFileChooser.setVisible(true);
jTextField.setVisible(true);
if (value == JFileChooser.APPROVE_OPTION) {
stringPath = jFileChooser.getCurrentDirectory() + “\\”
+ jFileChooser.getSelectedFile().getName();
stringPath = stringPath.replace(“.txt”, “”);
jTextField.setText(stringPath);
if (stringPath != null) {
String string = null;
try {
string = readFile(Swing_Ldif_Generator.stringPath + “.txt”);
} catch (IOException e1) {
e1.printStackTrace();
}
logic(string);
}
}
if (value == JFileChooser.CANCEL_OPTION) {
jTextField.setText(“Please Choose the file”);
if (stringOpen != null) {
logic(stringOpen);
} else {
logic(“Empty Data”);
}
}
if (display.getText().toString() != null) {
stringOpen = display.getText();
System.out.println(stringOpen);
}

}

private void logic(String stringOpen) {
middle.removeAll();
middle.updateUI();
middle.setBorder(new TitledBorder(new EtchedBorder()));
display.setText(stringOpen);
display.setBackground(Color.DARK_GRAY);
display.setForeground(Color.white);
display.setEditable(true); //
JScrollPane scroll = new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scroll);
}
});

save.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stringOpen=display.getText();
middle.removeAll();
middle.updateUI();
JFileChooser jFileChooser = new JFileChooser();
jFileChooser.setPreferredSize(new Dimension(800, 400));
int value = jFileChooser.showSaveDialog(middle);
jFileChooser.setVisible(true);
jTextField.setVisible(true);
if (value == JFileChooser.APPROVE_OPTION) {
savedPath = jFileChooser.getCurrentDirectory() + “\\”
+ jFileChooser.getSelectedFile().getName();
jTextField.setText(savedPath);
System.out.println(savedPath);
if (stringPath != null && stringOpen==null) {
String string = null;
try {
string = readFile(Swing_Ldif_Generator.stringPath + “.txt”);
} catch (IOException e1) {
e1.printStackTrace();
}
logic(string);
} else if (stringOpen != null) {
logic(stringOpen);
} else {
logic(“Empty Data”);
}

}
if (value == JFileChooser.CANCEL_OPTION) {
jTextField.setText(“Please Choose the file”);
if (stringOpen != null) {
logic(stringOpen);
} else {
logic(“Empty Data”);
}
}
}

private void logic(String stringOpen) {
middle.removeAll();
middle.updateUI();
middle.setBorder(new TitledBorder(new EtchedBorder()));
display.setText(stringOpen);
display.setBackground(Color.DARK_GRAY);
display.setForeground(Color.white);
display.setEditable(true); //
JScrollPane scroll = new JScrollPane(display);
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
middle.add(scroll);
}
});
top.add(jTextField);

GridBagConstraints c = new GridBagConstraints();
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 0.90;
c.gridy = 1;
window.add(middle, c);
c.weightx = 1;
c.weighty = 0.05;
c.gridy = 0;
window.add(top, c);
c.weighty = 0.05;
c.gridy = 2;
window.add(bottom, c);

GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();

window.setSize(width-50, height-50);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setVisible(true);
}

String readFile(String fileName) throws IOException {
BufferedReader br = new BufferedReader(new FileReader(fileName));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();

while (line != null) {
sb.append(line);
sb.append(“\n”);
line = br.readLine();
}
return sb.toString();
} finally {
br.close();
}
}

}

 

jjj

package me;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class IDTransfer {
static ArrayList<String> arrayList = new ArrayList<>();
static ArrayList<String> arrayList2 = new ArrayList<>();
static ArrayList<String> commonList = new ArrayList<>();
static String path2 = “E:\\input2.txt”;
static String path1 = “E:\\input1.txt”;

public static void main(String[] args) throws IOException {
arrayList=readMethod(path1);
arrayList2=readMethod2(path2);
commonRetrun(arrayList, arrayList2);
System.out.println(commonList);
FileWriter writer = new FileWriter(“E:\\outputend.txt”);
for(String string:commonList){
writer.write(string);
writer.write(System.lineSeparator());
}
writer.flush();writer.close();
}

private static void commonRetrun(ArrayList<String> arrayListone, ArrayList<String> arrayListtwo) {
commonList = new ArrayList<String>(arrayListone);
commonList.retainAll(arrayListtwo);
}

private static ArrayList<String> readMethod(String path) throws FileNotFoundException {
Scanner s = new Scanner(new File(path));
while (s.hasNext()) {
arrayList.add(s.next());
}
s.close();
return arrayList;
}

private static ArrayList<String> readMethod2(String path) throws FileNotFoundException {
Scanner s = new Scanner(new File(path));
int a0, b0, c0, d0;
String line, line4 = null;
while (s.hasNext()) {
line = s.nextLine();
b0 = line.indexOf(“uid=”);
c0 = line.indexOf(“ou=people”);
line4 = line.substring(b0 + 4, c0-1);
arrayList2.add(line4);
}
s.close();
return arrayList2;
}
}