Eclipse removing white spaces when saving - eclipse

I have a big issue. I develop in eclipse ide environment, mostly on windows but also on linux. This seems to be a general issue.
Before I save my project on eclipse I have certain spaces between functions or in the code somewhere. I don't want to reformat the code that is in place.
However, every single time I try to save my project. Those spaces disappear, and I cannot find the place where I should change this auto-formatting in my eclipse properties.
Please see example bellow:
First of all I don't touch the code but I receive it as bellow and have to make modifications elsewhere. So at the initial state of my file I have somewhere in the code two functions [functionOne, functionTwo]. Those two functions are separated by a new line [NL] and 6 spaces. The problem appears when I save my project and as you can see the two functions are not separated anymore by the same number of spaces.
Before saving my project:
public void functionOne(){
int i = 0;
while(i<150)
{
//blabla...
}
}
NL:123456
public void functionTwo(){
int i = 0;
while(i<150)
{
//blabla...
}
}
After saving my project:
public void functionOne(){
int i = 0;
while(i<150)
{
//blabla...
}
}
NL:1
public void functionTwo(){
int i = 0;
while(i<150)
{
//blabla...
}
}
I'm starting to be sick of this issue and really need help to solve this.
Not forgetting to mention that absolutely no "Save actions" is enabled!
I don't see anything on my format options neither, but I could be wrong.
Could someone please help me to find a solutions to this problem?
Best regards,
Greg

So that wasn't the "Save actions" but some plugin that I was using. Didn't had the time to check which one it is I just uninstalled the rarely/unused once. And for the moment it seems to work. I'll check later if the problem remains/reappears.
Thanks for your help.
Best regards,
Gregory

Related

Rendering a single point in a JFreeChart based on the current Value of a Slider

I'm not yet as much into Java as I'd like to be, so I find my current task to be quite a bit challenging:
A chart showing data gathered in another class.
A slider whose end value is determined by the last entry of in the dataset used in the chart.
The playbutton currently doesn't do anything except letting the slider tick in steps of 5 until it is paused again.
My problem right now is: I am supposed to highlight one item at a time in the chart based on which value the slider currently shows.
And to be honest... I'm not yet used to renderers yet.
If I understood it correctly I would need to use
renderer.drawItem(java.awt.Graphics2D g2,
XYItemRendererState state,
java.awt.geom.Rectangle2D dataArea,
PlotRenderingInfo info,
XYPlot plot,
ValueAxis domainAxis,
ValueAxis rangeAxis,
XYDataset dataset,
int series,
int item,
CrosshairState crosshairState,
int pass)
but I am totally inexperienced with as well the method as its arguments and got no idea how to initialize them.
I mean... I got a plot, a dataset, and 2 series from the chart, I also suggest "item" would be the index of the item to highlight in the series, which I could convert from the slider-value.
Unfortunately plaguing google about it turned out to be rather frustrating since all I got was the very code I posted above on about 50 different pages (I gave up after).
I would like to know ... first of all if I am even about to use the correct method and, as ashamed as I am to ask like this... how to use it.
Well... looking forward to some answers and... thanks in advance.
Well, I now solved my problem in a different way than I intended to but it works out just fine for me.
Instead of highlighting a point in the curves I just simply add a Domainmarker that would adjust based on the value the slider currently shows.
class1 TestSlider
private HashSet<SliderListener> sliderListenerSet = new HashSet<SliderListener>();
public void addSliderListener(SliderListener Listener){
sliderListenerSet.add(Listener);
}
slider.addChangeListener(this);
public void stateChanged(ChangeEvent e) {
// TODO Auto-generated method stub
JSlider source = (JSlider)e.getSource();
if (!source.getValueIsAdjusting()) {
fireSliderChanged();
}
}
public void fireSliderChanged(){
for (SliderListener currentListener : sliderListenerSet)
currentListener.sliderValueChanged();
}
class2 SliderListener
public interface SliderListener extends EventListener{
public void SliderValueChanged();
}
class3 Chart
Marker marker = new ValueMarker(0);
plot.addDomainMarker(marker); //so that it would be there at the beginning
TestSlider ts = new TestSlider();
ts.addSliderListener(new SliderListener(){
#Override
public void sliderValueChanged() {
plot.removeDomainMarker(marker); //I only want one of them at a time - the one with the value the slider is currently showing so remove the old one...
marker = new ValueMarker(ts.slider.getValue());
plot.addDomainMarker(marker); // ... and add the one with the new value
}
});
}
I tried to keep it as short and universal as I could and I hope I didnt cut out anything important.
Well, I'm still new to this site, so... in case I did a mistake somewhere feel free to tell me.

condition not working sometimes with gwt

I'm having a rare issue in my code, I have a method that makes a very simple validation based on a string variable:
private void showNextStep(String psCondition,String poStepName){
int liCurrentStep=Integer.valueOf(poStepName);
String lsNextTrueStep=moSteps[liCurrentStep][4];
String liNextFalseStep=moSteps[liCurrentStep][5];
if ("Yes".equals(psCondition)){
moFrmStepsContainer.getField(liNextFalseStep).hide();
moFrmStepsContainer.getField(lsNextTrueStep).show();
}else{
moFrmStepsContainer.getField(liNextFalseStep).show();
moFrmStepsContainer.getField(lsNextTrueStep).hide();
}
}
Now, here is the ticky part: if I execute the application without debugging mode, it does the validation right all the time, how ever if don't it always goes to the else block (or at least I think) I tried to use JS alerts (I have a class that calls JS methods) to debug manually and check the valors of the variables; the valors where all right and the validation was also good. This means that only debugging or putting alerts before at the beggining of the IF block it does the validation right, otherwise it always goes to the ELSE, what do you think it could be?
It might be worth mentioning this is a web application made in netbeans 6.9, using the framework GWT 2.1. This application runs in firefox 25.0.1
Thank you!
UPDATE
Here is the code of the event that calls my method
final ComboBoxItem loYesNo=new ComboBoxItem("cmbYesNo" + moSteps[liStepIndex][0],"");
loYesNo.setValueMap("Yes","No");
loYesNo.setVisible(false);
loYesNo.setAttribute("parent", liStepIndex);
loYesNo.addChangedHandler(new ChangedHandler() {
public void onChanged(ChangedEvent poEvent){
String lsStepName=loYesNo.getName();
FormItem loItem=moFrmStepsContainer.getField(lsStepName);
String liStepNumber=String.valueOf(loItem.getAttributeAsInt("parent"));
showNextStep((String)poEvent.getItem().getValue(),liStepNumber);
}
});

Coping with GridBagLayout produced by Netbeans and modifying generated code to get what I couldn't make Netbeans give me

I have no question, just sharing 3 days of frustration and ultimate success.
The above is what I got from Netbeans using its GridBagLayout mode. Below is what I wanted.
I couldn't get what I wanted within a reasonable time using Netbeans, so I thought I would be able to cut, paste, and modify the generated code to make the form look like what I want.
I was right and the time spent in getting what I wanted was minimal, using the Netbeans "outline" that I started late last night.
Here's my code:
public class DoThis extends JFrame {
... (variable declarations removed)
public DoThis() {
initComponents();
}
private void initComponents() {
GridBagConstraints gridBagConstraints;
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
getContentPane().setLayout(new GridBagLayout());
pnlFileStuff = new JPanel();
pnlFileStuff.setBorder(BorderFactory.createEtchedBorder());
pnlFileStuff.setLayout(new GridBagLayout());
lblRootNode = new JLabel("Root node:");
gridBagConstraints = new GridBagConstraints();
pnlFileStuff.add(lblRootNode, gridBagConstraints);
txtRootNode = new JTextField("C:\\Users");
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.ipadx = 520; // One key
gridBagConstraints.anchor = GridBagConstraints.WEST;
pnlFileStuff.add(txtRootNode, gridBagConstraints);
btnBrowse = new JButton("Browse...");
gridBagConstraints = new GridBagConstraints();
pnlFileStuff.add(btnBrowse, gridBagConstraints);
lblFilenamePattern = new JLabel("Filename pattern:");
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
pnlFileStuff.add(lblFilenamePattern, gridBagConstraints);
txtFilenamePattern = new JTextField("*.*");
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.ipadx = 250; // the other key
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = GridBagConstraints.WEST;
pnlFileStuff.add(txtFilenamePattern, gridBagConstraints);
getContentPane().add(pnlFileStuff, new GridBagConstraints());
pack();
}
public static void main(String args[]) {
invokeLater(new Runnable() {
public void run() {
new DoThis().setVisible(true);
}
});
}
}
As it turns out, I only needed to do one additional thing in Netbeans--only one of the ipadx instances labeled "key" in the code. Sort of embarrassing to admit. And I didn't have to!
Just call it a learning experience that I decided to share, for better or worse. I think some newbie might profit from this post.
"Lessons" "learned":
(1) It's hard as heck to use Netbeans in "GridBagLayout mode". It's too far from WYSIWYG and far from intutitive. (This from a guy who had never used GridBayLayout and had never read about it until several days ago.) As one link suggested by S.O. that I followed stated, "Unfortunately, GridBagLayout is infernally awkward and error-prone to use." No argument here.
(2) Spending enough time struggling with Netbeans was worth it, in that, without it, it was almost impossible to read textbooks and tutorials and get anything close to desired outcome (YMMV).
(3) The code Netbeans generates in "GridBagLayout mode" is MUCH closer to human-written code than the usual incomprehensible hundreds of lines of krazy kode (that it generates in "free design" mode), which is virtually impossible to follow, let alone cut, paste, and edit (though I've had minimal success doing so). (Never again.)
(4) The generated GridBagLayout code is reasonably easy to cut, paste, and edit to generate the desired outcome (given that it was in the ballpark to begin with, and ignoring ample frustration with its quirks).
Most importantly (for ME), I finally feel free from Netbeans and may be on the way to developing some skill at writing GUI code from scratch, something I've avoided like the plague for months!!
I would be remiss not to revisit this thread and state that learning how to use GridBagLayout without Netbeans GUI builder is attainable by anyone. In less than a week of learning and getting help and advice from SO, I have finally arrived at creating a GUI that (unlike that generated by Netbeans) is easily editable and extendable--because I wrote the code by hand. The GUI that I'd been using and bugging SO with questions about for months (e.g., how to keep display from flashing during execution, which led to SwingWorker and other complications) has been replaced by the one below, which I created in a night and "perfected" the next day (today):
I'm not bragging; far from it. I barely know squat. Like "perfected" means "got output, and it doesn't flash, and it's readable, but it's ugly as sin."
Just providing hope for other newbies, I hope.

silverstripe dopublish function for ModelAdmin managed Pages

in the silverstripe backend I´m managing certain PageTypes via a ModelAdmin. That works fine so far, the only thing i can´t figure out is how to make a Page being "Published" when saving it.
Thats my code:
class ProjectPage extends Page {
public function onAfterWrite() {
$this->doPublish();
parent::onAfterWrite();
}
}
At the moment I can still see the ModelAdmin-created Pages in the Sitetree and I can see they are in Draft Mode. If I use the code above I get this error:
Maximum execution time of 30 seconds exceeded in
.../framework/model/DataList.php
Many thx,
Florian
the reason why you get "Maximum execution time exceeded" is because $this->doPublish(); calls $this->write(); which then calls $this->onAfterWrite();. And there you have your endless loop.
So doing this in onAfterWrite() or write() doesn't really work
you should just display the save & publish button instead of the save button
But I guess its easier said than done.
Well adding a button is actually just a few lines, but we also need a provide the functions that do what the button says it does.
This sounds like the perfect call for creating a new Module that allows proper handling of Pages in model admin. I have done this in SS2.4, and I have a pretty good idea of how to do it in SS3, but no time this week, poke me on the silverstripe irc channel on the weekend, maybe I have time on the weekend.
I found the same need/lack and I built a workaround that seems to work for me, maybe it can be useful.
public function onAfterWrite()
{
if(!$this->isPublished() || $this->getIsModifiedOnStage())
{
$this->publish('Stage', 'Live');
Controller::curr()->redirectBack();
}
parent::onAfterWrite();
}
Create a class that extends ModelAdmin and define an updateEditForm function to add a publish button to the actions in the GridFieldDetailForm component of the GridField.
public function updateEditForm($form) {
if ( ! singleton($this->owner->modelClass)->hasExtension('Versioned') ) return;
$gridField = $form->Fields()->fieldByName($this->owner->modelClass);
$gridField->getConfig()->getComponentByType('GridFieldDetailForm')->setItemEditFormCallback(function ($form) {
$form->Actions()->push(FormAction::create('doPublish', 'Save & Publish'));
});
}
Then create a class that extends GridFieldDetailForm_ItemRequest to provide an action handler for your publish button.
public function doPublish($data, $form) {
$return = $this->owner->doSave($data, $form);
$this->owner->record->publish('Stage', 'Live');
return $return;
}
Make sure the extensions are applied and you're done.
Or, you could just grab all the code you need from GitHub.

Lua: require() not working on iPhone

I am working on a shooting game on iPhone and I need lua for scripting levels, enemies, and etc.
So I wrote a bullet script like this:
-- circular_bullet.lua
local time_between_bullets = 0.2;
...
function InitializeCircularBullet(objectName)
...
end
and an enemy script:
-- level1_D2.lua
require("circular_bullet.lua");
...
But it turned out that the enemy script can't "require" the bullet script.
I tried to look into lua library, and found out that in loadlib.c :
static int ll_require (lua_State *L) {
...
if (lua_isfunction(L, -1)) /* did it find module? */
break; /* module loaded sucessfully */
else if (lua_isstring(L, -1)) /* loader returned error message? */
lua_concat(L, 2); /* accumulate it */
else
lua_pop(L, 1);
...
}
It would enter the "else if" branch, which means some error happened, but I have no idea how to read that error message.
If I comment out the "require" line, the enemy "level1_D2" would work as intend without shooting bullet. I also did try copy the whole circular_bullet.lua into level1_D2.lua, and it worked, so the problem must be the require statement.
Those two files are under root directory of the package. (I don't know how to make them in different directory, thus I had found out that Diner Dash kept its scripts in different directory.)
However the two files are not in the same group in my Xcode project. I tried putting them in same group but nothing happened.
Anyone knows what the problem is? Thanks a lot!
Finally I got the answer!!!
the lua require function searches "./scrips" directory for require files, so I got to put those script in the directory!
Yet I still don't know how to change that searching path, but it did work.
I've got a snippet here which might help you to change that path:
// Initialize library path
lua_pushstring(L,"package");
lua_gettable(L, LUA_GLOBALSINDEX);
string path = string(Globals::GetPathPrefix())+"?.lua";
lua_pushstring(L, "path");
lua_pushstring(L, path.c_str());
lua_settable(L, -3);
lua_pop(L,1);
I also had this when I was new to Lua. I don't know this also appears on iPhone, but on Windows I had to remove the '.lua' So just remove the extension.