Implementing a Launcher Framework - disabled Apply button on dialog - eclipse-plugin

I am working on a eclipse plugin and implementing a custom launcher as per the link https://eclipse.org/articles/Article-Launch-Framework/launch.html .
I have implemented a class BrowsersTab which extends AbstractLaunchConfigurationTab and implemented all the methods. The problem is that when I call the updateLaunchConfigurationDialog(); on the selection event , the 'Apply' Button remains disabled.
Code :
public class BrowsersTab extends AbstractLaunchConfigurationTab {
private Button chrome;
private Button firefox;
private Button safari;
private Button ie;
private Button opera;
private Button android;
private Button ios;
#Override
public void createControl(Composite parent) {
Composite comp = new Composite(parent, SWT.NONE);
setControl(comp);
GridLayout topLayout = new GridLayout();
comp.setLayout(topLayout);
Group fGroup = new Group(comp, SWT.NONE);
fGroup.setFont(parent.getFont());
fGroup.setLayout(new GridLayout(2, true));
fGroup.setText(DialogMessages.browserSelection);
chrome = new Button(fGroup, SWT.CHECK);
chrome.setText("Google Chrome");
chrome.addSelectionListener(new SelectionListener() {
public void widgetSelected(SelectionEvent e) {
System.out.println("chrome selected");
updateLaunchConfigurationDialog();
}
public void widgetDefaultSelected(SelectionEvent e) {
// TODO Auto-generated method stub
}
});
Image chromeIcon= getBrowserIcon("chrome-browser-24X24.png");
if(null!=chromeIcon)
chrome.setImage(chromeIcon);
Combo comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
firefox = new Button(fGroup, SWT.CHECK);
firefox.setText("Mozilla Firefox");
Image firefoxIcon= getBrowserIcon("Firefox-icon.png");
if(null!=firefoxIcon)
firefox.setImage(firefoxIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
safari = new Button(fGroup, SWT.CHECK);
safari.setText("Apple Safari");
Image safariIcon= getBrowserIcon("Safari-icon.png");
if(null!=safariIcon)
safari.setImage(safariIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
ie = new Button(fGroup, SWT.CHECK);
ie.setText("Internet Explorer");
Image ieIcon= getBrowserIcon("Internet-Explorer-icon.png");
if(null!=ieIcon)
ie.setImage(ieIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
opera= new Button(fGroup, SWT.CHECK);
opera.setText("Opera");
Image operaIcon= getBrowserIcon("browser-opera-icon.png");
if(null!=operaIcon)
opera.setImage(operaIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
android= new Button(fGroup, SWT.CHECK);
android.setText("Android");
Image androidIcon= getBrowserIcon("android-platform-icon.png");
if(null!=androidIcon)
android.setImage(androidIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
ios= new Button(fGroup, SWT.CHECK);
ios.setText("Mobile Safari");
Image iosIcon= getBrowserIcon("Apple-grey-icon.png");
if(null!=iosIcon)
ios.setImage(iosIcon);
comboDropDown = new Combo(fGroup, SWT.DROP_DOWN | SWT.BORDER);
comboDropDown.setText("Version");
}
#Override
public String getName() {
return "Browsers";
}
public Image getBrowserIcon(String name){
Image icon=null;
try {
icon = AbstractUIPlugin.imageDescriptorFromPlugin("SuitACore","icons/"+name).createImage();
} catch (Exception e) {
// Swallow it; we'll do without images
}
return icon;
}
public Image getImage() {
Image tab=null;
try {
tab = AbstractUIPlugin.imageDescriptorFromPlugin("SuitACore","icons/browser.png").createImage();
} catch (Exception e) {
// Swallow it; we'll do without images
}
return tab;
}
public void initializeFrom(ILaunchConfiguration configuration) {
try {
List<String> browsersDefaults = new ArrayList<String>();
browsersDefaults.add("chrome");
List<String> browsers =configuration.getAttribute("browsers", browsersDefaults);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
chrome.setSelection(true);
}
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
List<String> browsers = new ArrayList<String>();
browsers.add("chrome");
configuration.setAttribute("browser",browsers );
}
public void setDefaults(ILaunchConfigurationWorkingCopy arg0) {
}
}

You must call updateLaunchConfigurationDialog() whenever anything changes that might update the Apply button - so all checkboxes and combos.
You must also save everything that changes in the ILaunchConfigurationWorkingCopy in the performApply method. The Apply button state is determined by checking that the working copy is different from the original configuration.

Related

How to identify whether the text is boxed in PDF using PDFBOX?

I am trying to check whether the text is BOXED using apache PDFBOX. for few PDF the below code wont work.
public class PDFBoxReader extends PDFGraphicsStreamEngine {
private static ArrayList<Rectangle2D> recList = new ArrayList<Rectangle2D>();
public PDFBoxReader(PDPage page) {
super(page);
}
public static boolean isTextBoxed(PDDocument document, String text) {
StingBuffer boxedText = new StringBuffer();
for (PDPage page : document.getPages()) {
PDFBoxReader reader = new PDFBoxReader(page);
try {
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
rectList = new ArrayList<Rectangle2D>();
reader.processPage(page);
for (Rectangle2D react : rectList) {
Double y = page.cropBox().getUpperRightY() - rect.getY() - rect.getHeight();
rect.setRect(rect.getX(), y, rect.getWidth(), rect.getWidth(), rect.getHeight());
stripper.addRegion("box", rect);
stripper.extractRegions(page);
boxedText.append(stripper.getTextForRegion("box"));
}
if (isTextMatched(text, stripper.getTextForRegion("box"))) {
return true;
}
} catch (IoException exception) {
// exception is handled here
}
}
}
// some more methods here
}
PDF dont have any acroform. it has a paragraph in a bordered box at the end of the page.

When merging PDF files using itext the result pdf show 0 bytes in android studio

My code is here; I was selecting PDF files from a SD card or internal phone memory using the showFileChooser() method then from onActivityResult(), the files go to mergePdfFiles(View view) method, and from there the files go to createPdf(String[] srcs).
Here is the complete code of my activity:
//Below is onCreate();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mergedpdf);
adapter = new ArrayAdapter<>(this,
android.R.layout.simple_list_item_1, locations);
// public void fileSelected(File file ) {
// locations.add(file.toString());
// adapter.notifyDataSetChanged();
// }
NewText = (TextView)findViewById(R.id.textView);
AdView mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
listView = (ListView)findViewById(R.id.list_items);
btn = (ImageView) findViewById(R.id.imageView8);
btnconvert = (ImageView) findViewById(R.id.imageView11);
btnconvert.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// btTag=((Button)v).getTag().toString();
try {
createPdf( locations);
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//Toast.makeText(Mergedpdf.this, "button clicked", Toast.LENGTH_SHORT).show();
}
});
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// btTag=((Button)v).getTag().toString();
showFileChooser();
NewText.setText("Below Files are Selected");
}
});
}
//this is mergedfiles();
public void mergePdfFiles(View view){
Toast.makeText(Mergedpdf.this, "merge function", Toast.LENGTH_SHORT).show();
try {String[] srcs= new String[locations.size()];
for(int i = 0;i<locations.size();i++) {
srcs[i] = locations.get(i);
}
// String[] srcs = {txt1.getText().toString(), txt2.getText().toString()};
createPdf(srcs);
}catch (Exception e){e.printStackTrace();}
}
//This method create merged pdf file
public void createPdf (String[] srcs) {
try {
// Create document object
File docsFolder = new File(Environment.getExternalStorageDirectory() + "/Merged-PDFFiles");
if (!docsFolder.exists()) {
docsFolder.mkdir();
Log.i(TAG, "Created a new directory for PDF");
}
Date date = new Date();
#SuppressLint("SimpleDateFormat") final String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(date);
Document document = new Document();
// pdfCopy = new File(docsFolder.getAbsolutePath(),pdf+"Images.pdf");
// Document document = new Document();
//PdfWriter.getInstance(document, output);
// Create pdf copy object to copy current document to the output mergedresult file
PdfCopy copy = new PdfCopy(document, new FileOutputStream(docsFolder + "/" + timeStamp +"combine.pdf"));
Toast.makeText(Mergedpdf.this, "merged pdf saved", Toast.LENGTH_SHORT).show();
// Open the document
document.open();
PdfReader pr;
int n;
for (int i = 0; i < srcs.length; i++) {
// Create pdf reader object to read each input pdf file
pr = new PdfReader(srcs[i].toString());
// Get the number of pages of the pdf file
n = pr.getNumberOfPages();
for (int page = 1; page <= n; page++) {
// Import all pages from the file to PdfCopy
copy.addPage(copy.getImportedPage(pr, page));
}
}
document.close(); // close the document
} catch (Exception e) {
e.printStackTrace();
}
}
//below is showfilechooser(); method
private void showFileChooser () {
Log.e("AA", "bttag=" + btTag);
String folderPath = Environment.getExternalStorageDirectory() + "/";
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
Uri myUri = Uri.parse(folderPath);
intent.setDataAndType(myUri, "application/pdf");
Intent intentChooser = Intent.createChooser(intent, "Select a file");
startActivityForResult(intentChooser,PICKFILE_RESULT_CODE);
}
//below is onActivityResult(); method
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (data != null) {
if (requestCode == PICKFILE_RESULT_CODE) {
if (resultCode == RESULT_OK) {
String FilePath = data.getData().getPath();
locations.add(FilePath);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.listview,locations);
listView.setAdapter(adapter);
}
}
}
}
//And my declared variables before oncreate().
public com.itextpdf.text.Document Document;
public PdfCopy Copy;
public ByteArrayOutputStream ms;
TextView NewText;
private TextView txt1;
private Button bt1, bt2,bt3;
private Handler handler;
ListView listView;
ArrayList<String> locations = new ArrayList<>();
ArrayAdapter<String> adapter;
ImageView btn, btnconvert, btn3;
private static final String TAG = "PdfCreator";
private final int PICKFILE_RESULT_CODE=10;
private String btTag = "";

saving arraylists to internal storage

I am writing a program which calculates and shows Installed program's data usage.
I want to save My variables and reload them.
I have checked other questions about this but i didn't find my answer.
I have 5 Arraylists in my code to save these items:
"Application Name","Application Icon","Received Data","Sent Data" and "Total Data".
I get these informations and convert Arraylists to String arrays whith "for loop" and show them with my custom Adapter and a listview.
My problem is that my application force stops when i run it on my phone.
I save some variables with SharedPreferences and save Arraylists into internal storage.
I have also tried to save Arraylists with SharedPreferences and i could save them. but when i want to reload and set them to arraylists, i get error.
Here is my "onCreate" method code:
public class MainActivity extends AppCompatActivity {
private static final String MyPREFERENCES="MyPrefs";
private SharedPreferences myPrefs;
int first;
List<String> list=new ArrayList<>();
List<String> s=new ArrayList<>();
List<String> r=new ArrayList<>();
List<String> t=new ArrayList<>();
List<Drawable> ic=new ArrayList<>();
List<Double> StartRx=new ArrayList<>();
List<Double> StartTx=new ArrayList<>();
private long StartTotal;
private long TotalDataUsage;
private long prevData;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView1=(ListView)findViewById(R.id.mainListView1);
registerForContextMenu(listView1);
myPrefs=getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
first=myPrefs.getInt("FirstCall",0);
StartTotal=myPrefs.getLong("StartData",0);
TotalDataUsage=myPrefs.getLong("TotalData",0);
prevData=myPrefs.getLong("prevData",0);
try {
list=(ArrayList<String>) InternalStorage.readObject(this,"NamesList");
r=(ArrayList<String>) InternalStorage.readObject(this,"ReceivedData");
s=(ArrayList<String>) InternalStorage.readObject(this,"SentData");
t=(ArrayList<String>) InternalStorage.readObject(this,"TotalData");
ic=(ArrayList<Drawable>) InternalStorage.readObject(this,"IconsList");
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();***
}
DataUsage();
int l=list.size();
if (l>0) {
String[] Names = new String[l];
String[] DReceived = new String[l];
String[] DSent = new String[l];
String[] DTotal = new String[l];
Drawable[] icons = new Drawable[l];
for (int i = 0; i < l; i++) {
Names[i] = list.get(i);
DReceived[i] = r.get(i);
DSent[i] = s.get(i);
DTotal[i] = t.get(i);
icons[i] = ic.get(i);
}
assert listView1 != null;
listView1.setAdapter(new CustomAdapter(this, Names, DReceived, DSent, DTotal, icons));
}
}
and "onResume" method code is:
protected void onPause() {
super.onPause();
try {
InternalStorage.writeObject(this,"NamesList",list);
InternalStorage.writeObject(this,"ReceivedData",r);
InternalStorage.writeObject(this,"SentData",s);
InternalStorage.writeObject(this,"TotalData",t);
InternalStorage.writeObject(this,"IconsList",ic);
} catch (IOException e) {
e.printStackTrace();
}
SharedPreferences.Editor edit = myPrefs.edit();
edit.putInt("FirstCall", first);
edit.putLong("TotalData",TotalDataUsage);
edit.putLong("StartData", StartTotal);
edit.putLong("prevData", prevData);
edit.commit();
}
and the "InternalStorage" class is:
public final class InternalStorage {
private InternalStorage() {}
public static void writeObject(Context context,String fileName,Object object) throws IOException {
FileOutputStream fos=context.openFileOutput(fileName,Context.MODE_PRIVATE);
ObjectOutputStream oos=new ObjectOutputStream(fos);
oos.writeObject(object);
oos.close();
fos.close();
}
public static Object readObject(Context context,String fileName) throws IOException, ClassNotFoundException {
FileInputStream fis=context.openFileInput(fileName);
ObjectInputStream ois=new ObjectInputStream(fis);
return ois.readObject();
}
}
I didn't get any error from android studio.
I know that the problem is with below codes because when i delete them, it works!
try {
list=(ArrayList<String>) InternalStorage.readObject(this,"NamesList");
r=(ArrayList<String>) InternalStorage.readObject(this,"ReceivedData");
s=(ArrayList<String>) InternalStorage.readObject(this,"SentData");
t=(ArrayList<String>) InternalStorage.readObject(this,"TotalData");
ic=(ArrayList<Drawable>) InternalStorage.readObject(this,"IconsList");
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
and this code:
try {
InternalStorage.writeObject(this,"NamesList",list);
InternalStorage.writeObject(this,"ReceivedData",r);
InternalStorage.writeObject(this,"SentData",s);
InternalStorage.writeObject(this,"TotalData",t);
InternalStorage.writeObject(this,"IconsList",ic);
} catch (IOException e) {
e.printStackTrace();
}
CAN ANYONE HELP ME PLEASE?!!

adding JDatepicker in Jframe

I want to develop a Swing desktop application with jlabel, JDateChooser and a submit button.
I am using below code :
public class Homeg {
public static void main(String args[]) {
JFrame frame=new JFrame("date display");
JDatePickerImpl datePicker;
UtilDateModel model = new UtilDateModel();
model.setDate(1990, 8, 24);
model.setSelected(true);
JDatePanelImpl datePanel = new JDatePanelImpl(model,null);
datePicker = new JDatePickerImpl(datePanel, null);
frame.setLayout(new FlowLayout());
JLabel label=new JLabel("Date");
JButton submit=new JButton("SUBMIT");
frame.add(label);
frame.add(datePicker);
frame.add(submit);
frame.setSize(400,400);
frame.setVisible(true);
}
}
And it is giving output having only JDatechooser.
Instead I wanted a output which must have a JLabel, JDatePicker and a submit button. Here it is showing only JDatePicker.
You should always call pack() before making a call to setVisible();
{
...
frame.setSize(400,400);
frame.pack();
frame.setVisible(true);
}
Then to actuall make the date the submit button submit the date use:
JButton submit= new JButton("SUBMIT");
submit.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
Date date = (Date) datePicker.getModel().getValue();
/* do something with 'date' */
}
});

saving a text file using JFileChooser

I am writing a small program where are user enters some information into text fields and then has the option to save that information using JFileChooser. I have not been able to figure out how to get it to save. What am I doing wrong? Thank you in advance.
public class Program implements ActionListener{
JMenuItem loadMenuItem, saveMenuItem, quitMenuItem;
JFrame frame;
JPanel mainPanel, inputPanel, listPanel;
JLabel firstNameLabel, lastNameLabel, rentLabel, listLabel;
JTextField firstNameTextField, lastNameTextField, rentTextField;
JButton addButton;
JList list;
DefaultListModel<TenantInfo> listModel;
JScrollPane scrollPane;
public ArrayList<TenantInfo>tenantInfo;
private void saveFile() {
// TODO Auto-generated method stub
JFileChooser jfc = new JFileChooser();
int userSelected = jfc.showSaveDialog(null);
if(userSelected == JFileChooser.APPROVE_OPTION){
try{
FileOutputStream fos = new FileOutputStream(jfc.getSelectedFile());
ObjectOutputStream oos = new ObjectOutputStream(fos);
for(TenantInfo t : tenantInfo){
oos.writeObject(t);
}
oos.writeObject(tenantInfo.get(0));
oos.close();
fos.close();
}catch(Exception ex){
ex.printStackTrace();
}
}