Creating an "Undo" method
Our prof. gave us a photo editing program skeleton, mostly GUI, written in java which we had to implement a couple of features. That was a couple of days ago. I've been toying around with it trying to add some other things.
One of the things I wanted to add was an undo command, such that when you click the Undo button, the image reverts back to whatever it was previously.
When a button is clicked this code executes:
protected void applyCommand ()
Pixmap p = myCanvas.getPixmap();//PixmapCanvas myCanvas, holds the canvas
if(!(myCommand.getName().equals("Undo")))//my additions
myCanvas.store(p);
System.out.println("Creating Backup");
}//end of my additions
myCommand.execute(p);
myCanvas.refresh();
}Here is the store method:
public void store(Pixmap p)
oneBack = new Pixmap(p);
}Here is where I'm stuck, in the undo command, I'm not quite sure how to access oneBack in PixmapCanvas. I'm sure there are ways to do it but I'm trying to keep this as elegant as possible, I don't want to change the structure of all of the other commands.
public void execute(Pixmap target)
target = new Pixmap("I need to get oneBack" );
}
Ok well here's something else I tried and it still doesn't work. I'll try and be more descriptive of my code.
Main:
// create GUI components
PixmapCanvas canvas = new PixmapCanvas(frame);
ButtonPanel commands = new ButtonPanel(canvas);
// more commands
commands.add(new Undo(canvas));ButtonPanel:
public class ButtonPanel extends JPanel
private PixmapCanvas myView;
public ButtonPanel (PixmapCanvas view)
myView = view;
public void add (Command c)
add(new CommandButton(c, myView));
class CommandButton extends JButton
private PixmapCanvas myCanvas;
private Command myCommand;
public CommandButton (Command command, PixmapCanvas canvas)
super(command.getName());
myCanvas = canvas;
myCommand = command;
// perform command when button is clicked
addActionListener(new ActionListener()
public void actionPerformed (ActionEvent e)
applyCommand();
protected void applyCommand ()
Pixmap p = myCanvas.getPixmap();
if(!(myCommand.getName().equals("Undo")))
myCanvas.store(p);//So every command should store the current pixmap
myCommand.execute(p);
myCanvas.refresh();
}PixmapCanvas (important parts of it):
public class PixmapCanvas extends JPanel
private Pixmap myPixmap;
public Pixmap oneBack;
public PixmapCanvas (JFrame container, String pixName)
setBorder(BorderFactory.createLoweredBevelBorder());
myContainer = container;
myPixmap = new Pixmap(pixName);
refresh();
public void store(Pixmap p)
oneBack = new Pixmap(p);
public void refresh ()
if (! myPixmap.getSize().equals(getSize()))
setSize(myPixmap.getSize());
myContainer.setTitle(myPixmap.getName());
myContainer.pack();
repaint();
public void paintComponent (Graphics pen)
super.paintComponent(pen);
myPixmap.paint(pen);
}Undo:
public class Undo extends Command
PixmapCanvas ref;
public Undo(PixmapCanvas c)
super("Undo");
ref = c;
public void execute(Pixmap target)
target = new Pixmap(ref.oneBack);
}Edited by: JFactor2004 on Sep 20, 2007 7:26 PM
Similar Messages
-
Can't create new undo tablespace while undo tablespace is crushed
We currently encounter an emergent error on our productive database. The undo tablespace on this database looks like crushed. And insert /update operations can't be executed because of the undo tablespace error.
we tried to create a new undo tablespace to replace this broken tablespace, but the database reports ORA-00376 and ORA-00376 error.
We have already deleted rollback segments which status is "NEED RECOVERY".
Now we run our database in manual undo tablespace management mode. and add a new datafile into current broken undo tablespace. Then create a new rollback segment for public user. Now, user can insert /update data. But we are not sure if this method would occur any other problems.
I really appreciate if you have any good suggestions.Hi,
Actually ORA-00376 is the following cause and take action.
cause: An attempt was made to read from a file that is not readable. Most likely the file is offline.
Action: Check the state of the file. Bring it online.
Again setup ur DB automatic UNDO MANAGEMENT and check status of the ur undo tablespace. and bring it online.
and create another undo tablespac and switching the undo tablespace.
Regards.. -
Error while creating a overwrite method in class
Hello.
I'm trying to create an overwrite method in the class CL_HREIC_EECONTACT2SRCHV_IMPL but it just won't let me. Every time I try I get the message "The class has not yet been converted to the new class-local types" and I cannot create it.The thing is I've tried to create overwrite methods in diferent classes and sometimes I get the message and sometimes I don't, so it seems to depend on the class I'm trying to enhance, but I don't seem to be able to see any pattern in it.
Any help?
ThanksHello i had the same problem and i couldn't create enhancement pre or post methods.
The message was:
The class has not yet been converted to the new class-local types
Exception of class CX_ENH_OLD_LOCAL_CLASS_TYPES
This can be fixed by entering in SE24 transaction: Change class. From menu choose: Utilities -> Convert class-local types.
After that activate the class.
Now the class can be enhanced.
However this action requires change of the class
Regards,
Rosen -
How to create the custom method and make it available to clients:
Hello, Can any one help me with this problem ASAP??
I am trying to work on an example of "Customizing the Query and Creating an Associated Custom Method"
from http://helponline.oracle.com/jdeveloper/help/topics/jdeveloper/developing_mvc_applications/adf_pviewcustommethod.html?tp=true#method. To do that, the first task is to create the custom method and make it available to clients.
Following instructions in the helponline documentation, I completed the three steps: (1) "Specify a custom query for the View Object definition for EmployeesView", (2) "Add the custom method to the application module Java class", and (3) "Make the method available to clients".
The following is the error message I got to test the application module. Can anyone tell me what the message really means and what I should do. I am wondering if there is any mistakes in the document.
(oracle.jbo.SQLStmtException) JBO-27122: SQL error during statement preparation. Statement: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID FROM EMPLOYEES Employees WHERE Employees.SALARY > :1 and Employees.DEPARTMENT_ID = :2
----- LEVEL 1: DETAIL 0 -----
(java.sql.SQLException) ORA-01008: not all variables boundYou need to set values for the parameters in your query before you try to execute the query in the view object.
So you need to call the setBindVars method before the query. -
Creating a new method in an enhanced component class implemetation
Hello Experts,
I am trying to create a new method in the enhanced component(BT115IT_SLSO) implementation class ( ZL_BT115IT__ITEMS_IMPL)to run our custom functionality. But somehow when I put a breakpoint and debug while I add a product to the sales order the method doesnt get trigerred.
Is there some thing which I have to do get this trigerred ? I just added a ned method and placed some custom code in it. Do I have to invoke it anywhere ?
Pls help me out. I am new to Web UI.
ThanksHi Mavrick,
As you are performing some action like item addition , there you need a method called as " event handler " to handle the event and perform the required actions.
Place a break point in DO_HANDLE_EVENT method , and you will know the exact event handler method which is getting triggered . or if you are defining a new event ( by adding any new button) you should create a event handler method using wizard giving the same name which is defined on_click field of the button as it is case sensitive.
Regards,
Nithish -
View not copied or enhanced with wizard Error while creating Event Handler method in Z Component
Hello Friends,
In one Z Component (Custom Component), in one of the views, while creating event handler, it gave me error message that view not copied or enhanced with wizard.
I am aware that in Standard Component, if we want to create the event handler method then we need to first Enhance the Component and then we need to enhance the view.
But, in the Z Component (Custom Component), how to create event handler method in one of the views as while creating event handler method i am getting view not copied or enhanced with wizard error.Hi,
Add a method in views impl class with naming convention eh_on__* with htmt and html_ex parameters. I dont have have the system right now. Please check any existing event import export parameters.
Check out do handle event method in the same class.
Redefine that method. Call that event method in this handle method. See existing code for reference.
Attach that event to the button on click event in .htm page.
Regards,
Bhushan -
Creating Properties and Methods for an exe built in LabVIEW
Hi all,
How do we create properties and methods for an executable built in LabVIEW.
I know when building an exe, the "Enable ActiveX server" option in advanced has to be enabled.
But after that how do we create Properties and methods for the activeX component.
Your help is greatly appreciated.
Regards,
Muthuraman S
Regards,
MuthuramanYou cannot build your own COM specific properties and methods for the ActiveX interface in LabVIEW, the only thing exposed are the normal VI server properties and methods.
Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas
LabVIEW, programming like it should be! -
Garbage collection of objects created inside a method
I have method and inside the method I create new Objects I mean I instantiate objects using new and call some methods on these objects.
once the method execution is completed and control goes to caller of the method will all the object created inside the method will be garbage collected ?
here with code
public List<StgAuditGeneral> getAudits(
List<StgAuditGeneral> audits= new ArrayList<StgAuditGeneral>();
for(Map<String, String> result :results ){
audits.add(new MapToObject<StgAuditGeneral>() {
@Override
public StgAuditGeneral getObject() {
StgAuditGeneral stg= new StgAuditGeneral();
return stg;
}.getObject());
}in the above method I cam creating tons of objects wil they be garbage collected immediatedly after jvm leaves the method ?user11138293 wrote:
I have method and inside the method I create new Objects I mean I instantiate objects using new and call some methods on these objects.
once the method execution is completed and control goes to caller of the method will all the object created inside the method will be garbage collected ?If there are no reachable references, to those objects, then when the method ends, they become eligible for GC. If and when they are actually collected is something we can't know or control, and generally don't care about. The only guarantee is that everything that can be collected will be collected before an OutOfMemoryError is thrown. So from our perspective, once it's eligible for collection, it is effectively collected.
If you pass references to those objects to something else that holds onto them after the method ends, then they are still reachable, and not eligible for collection.
However, you almost never need to even think about whether something is eligible for GC or not. It works pretty intuitively. -
How to create an init method with executeEmptyRowSet() in task flow
hi i try this <method-call id="Empty">
<method>executeEmptyRowSet()</method>
</method-call> in my task flow but am geting error
am in jdeveloper 11.1.1.6.01) In your Application module, create a public method in service class.
2) In that method you do your executeEmptyRowSet() on the view objects you want to.
3) Expose the method (AM > Services > Client interface).
4) Drag the method from your DataControl onto you taskflow.
5) Right click that method > Mark Activity > Default -
How to create dynamically a method of a class??
I would like to create dynamically a method of a class. Is this possible?
By means of a report I would like to choose a class, to which the defined method should be added and after that I would like to define the name of the method and its parameters. The result should be, that the method is added to the selected class.
How to do this?
Regards
ChristianChristian,
looks like an interesting development project. Though I share the doubts Rich has.
Anyway, what you could possibly do is, start a runtime analysis for SE24, open an existing class, create a new method including desired interface parameters.
Then analyze it and see what functions/methods are used.
But It might be more complex than expected.
Regards,
Clemens -
Creating a static method returning Logger Object inside class
Hello,
Instead of creating Logger Instance in every class , can i do like this way by creating a static method in some class returning a Logger object , and using that method for getting instance of Logger in another class through that method
Regards
Mayur MitkariOn a related note, if you want to make it simpler, never do this:
if (a == true)Instead, just do if (a)It's pointless and cluttersome to use == or != with true or false.
// wrong
if (a == true)
if (a != false)
// right
if (a)
// wrong
if (a == false)
if (a != true)
// right
if (!a)Also, note that
if (x) {
return true;
else {
return false;
}can be simplified to return x;If you do that and change your variable to something a bit more meaningful, like trueCount or numTrue or something, your code would be
int trueCount = 0;
if (a) trueCount++;
if (b) trueCount++;
if (c) trueCount++;
return trueCount >= 2;which is about as simple and clear as it can get, IMHO. Using less code doesn't necessarily make the code simpler or clearer. The idea is that someone reading the code can easily understand what it does.
And note that the above can be easily generalized to "Are there at least M true values in this array/list of N booleans?" and still be concise and clear. -
Error in Creating Custom Business Methods using ADF Business Comp. Tutorial
I've been working with Jdev 10g Preview for a while. Now that we have Jdev 10g, I have to unlearn some of the Preview methods and learn the "real" way of doing things. To that end, I went out to the "Creating Custom Business Methods using ADF Business Components" tutorial. Unfortunately, I've found what I think is a mistake in the example code.
Specifially, ADF treats the default iterator on View Objects differently than previous BC4J versions. In the older versions, the iterator was positioned before the first row when you first executed a query. In that case, the hasNext() method was used to see if you had any rows at all. In ADF, however, the default iterator is positioned at the first row. So, if your query only returns one row, then the hasNext() method returns false!
Here's the code posted in the tutorial:
public Number getDeptSalaryTotal(String dept_id)
// get a department view object
DepartmentsViewImpl dept = getDepartmentsView1();
dept.setWhereClause("DEPARTMENT_ID = " + dept_id);
dept.executeQuery();
dept.first();
EmployeesViewImpl emps = getEmployeesView3();
Number salaryTotal = new Number(0);
while (emps.hasNext() )
Row empsRow = emps.next();
salaryTotal =
salaryTotal.add((Number)(empsRow.getAttribute("Salary")));
return salaryTotal;
As you can see, this is coded using the pre-10g semantics. It checks hasNext() at the top of the while loop. If there is only one Employee in the Department, hasNext() will return false since the emps View Object will already be positioned at the first and only row. There won't be a next row. So, the salaryTotal will be zero instead of the correct value. Alternatively, if there is more than one row, then hasNext() will be true, but the routine will skip the first row and start totalling salaries from the second row on.
The routine should be recoded as follows:
public Number getDeptSalaryTotal(String dept_id)
// get a department view object
DepartmentsViewImpl dept = getDepartmentsView1();
dept.setWhereClause("DEPARTMENT_ID = " + dept_id);
dept.executeQuery();
dept.first();
EmployeesViewImpl emps = getEmployeesView3();
Number salaryTotal = new Number(0);
Row empsRow = emps.first(); // Get the first row
while (empsRow != null ) // while we have a row
salaryTotal =
salaryTotal.add((Number)(empsRow.getAttribute("Salary"))); // add in the salary
empsRow = emps.next(); // get the next row
return salaryTotal;
I haven't actually executed this code, so there may be a typo or two in there. However, the basic idea is sound -- I think!
Please update the tutorial so we don't mislead people right at the start! :-)Gary:
I have two questions for you:
1) Could you post the preferred code here?
2) Why is it the preferred method? I would think that creating and destroying another object (the temporary iterator) would be a bad thing. -
Can the window created by Create_decision_popup method be made to resizable
Hi experts,
Is it possible to create a pop up with resizable option for a pop up created using create_decision_popup method .
We do not want to use window.open( ) option as it is giving some issue.
Thanks
Swapna.Hello,
In the end the CREATE_DECISION_POPUP method of the IF_BSP_WD_WINDOW_MANAGER interface will generate a javascript call to create the popup window. This popup window is still created with the window.open() javascript command.
If you want to change this behaviour (for descision popup the width and height are fixed) this means that you have to change the SAP standard javascript (.js) files and thus make a correction in the SAP namespace, which is never advisable.
I think the .js file is stored in the MIME repository under this location (on a SAPCRM 7.0 system):
SAP>BC>BSP>SAP>PUBLIC>BC>XHTMLB-->xcontrols_ie5.js
When javascripts are adapted be sure to clean the HTTP server cache (SMICM>Goto>HTTP Server Cache>Invalidate)>Global in system) and browser's client cache.
Hope this helps you in the right direction,
Regards,
Joost -
Error when creating Before Phase method
Hi,
I am using Jdeveloper 11.1.1.3.0. I wanted to create Phase Event method. I did by going to the view and opened the editor for Before Phase. Created a new Bean and the method. I gave application scope.
Once it is created, I get the error saying the reference method_name not found.
I didn't receive this error in earlier version. Can anyone guide me on this?
Thanks
SRHi,
not sure why this happens but what is the reason to put this into application scope. Is your phase listener keeping state ? Note that if you define it on the f:view component then it is used for this page only. So it can be in request scope
Frank -
Trying to create an equals method
So I need to create an equals method within a class that and object can call with a second object to test equivalence. I mean whether or not the object's instance variable are all the same. Here's the snippets of code:
public class Circle implements Shape
double radius;
Point position;
Color color;
boolean filled;
public boolean equals(Object o)
if(!(o instanceof Point)) {
return false;
Point p = (Point) o;
return ((radius == p.radius) && (position == p.position) && (color == p.color) && (filled == p.filled));
}Obviously there's other methods going on in between the instance variables, but the constructor only sets the instance variables, nothing more. So the first error I'm getting is "cannot find symbol - variable radius", but clearly, it's there. What am I doing wrong?
I may have other questions when I get frther in my project.sublimeph03nix wrote:
public boolean equals(Object o)
if(!(o instanceof Point)) {
return false;
}Not actually always desirable, that. Yes, yes, yes, it prevents a ClassCastException, but on the downside, it prevents a ClassCastException. What do I mean? Well, in situations where you know that nothing other than a Point object should be passed into this method - that's your intended behaviour - the presence of anything else here indicates a bug. Better to let the bug bring the app down than for it to continue doing the wrong thing. Testing will expose the bug, as long as you don't just ignore it.
Of course, this isn't always the case. It's one of those things you should consider on a case-by-case basis, rather than apply one idiom or the other all the time
Maybe you are looking for
-
AP INVOICES CREDITMEMO/DEBITMEMO CONVERSION
Hello Guys, I am doing AP credit memo/debit memo conversion,while running import Program i.e. Payables Open Interface Import we will encounter the parameter SOURCE,what value to be submitted to this Parameter. I have submitted the Source value as 'Ex
-
Excise Base value wrong in MIGO
Hello , PB00 and some Z condition types are used in Pricing Procedure....And Excise is calculted on the addition of PBoo+Z condition types, The BED and ECS and SECess is calculted correctly While capturing the excise invoice in MIGO We are using Ecc
-
Issue related to second stage dealer(excise)
Hi Expert i need to pay vendor amount is 754800( 74000+14800 (2% cst). FI document at the time if migo my base value + cst (670110+14800)=684910.00 when i simulate at the time r miro i got the following entries 1.vendor a/c debit rs 824690 2. GR/Ir a
-
Project Server 2010 Business Intelligence performance issue
Hello, We've setup a Project Server 2010 Business intelligence center and everything seems to be working fine. The next day when users attempt to open Sample reports an error occurs that when we apply the "refresh all Data connections" a couple of ti
-
Usb superdrive just ejects disks on retina yosemite
Would appreciate some advice and help PLEASE Just purchased a USB SUPERDRIVE to go into my Macbook 15" retina with Yosemite, it just clunks a few times and ejects the disk, the disk is an installation disk for the OED Version 3.1 CD ROM. Over 25 mile