Extension:Painting/Code/Wikipainting.java

/*     

import java.io.*; import java.net.*; import java.applet.Applet; import java.awt.event.*; import java.awt.*; import java.awt.image.*; import javax.swing.*; import javax.imageio.*; import java.util.*; import javax.swing.event.*; import java.lang.Math;

public class Wikipainting extends Applet implements MouseListener,MouseMotionListener,MouseWheelListener,ActionListener,DocumentListener,KeyListener {

final String appletTitle = "Wikipainting applet v1.5.9"; int appmx,appmy,imgmx,imgmy; // sizes int mode=0,painting=0,small=0; double zoom=1; int rev_i=0,rev_max=0; String title,baseurl; // title of the painting Image db; // double buffer BufferedImage img,imgundo; BufferedImage[] imghist; // painting Graphics2D db2d; // double buffer graphics Graphics2D img2d,imgundo2d; JButton b_edit,b_hist,b_save,b_undo,b_lhis; JScrollBar b_rad,b_alp,b_red,b_grn,b_blue,b_hue,b_sat,b_lum,b_zoom,b_dx,b_dy,b_rev; JTextField b_comm,b_titl; JCheckBox b_line; String[] rev_contrib,rev_date,rev_comm; java.util.Timer t; int edition_clock=0;

boolean readdistant_failed=false; private BufferedImage readdistant(String urltxt) {	BufferedImage imgloaded; Cursor cur; readdistant_failed=false; this.showStatus("Reading image "+urltxt); cur = getCursor; setCursor(new Cursor(Cursor.WAIT_CURSOR)); img2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1)); System.out.println("Reading image "+urltxt); try { imgloaded = ImageIO.read(new URL(urltxt)); } catch (Exception er) { 		Graphics2D gtmp; imgloaded = new BufferedImage(imgmx,imgmy,BufferedImage.TYPE_INT_RGB); gtmp = (Graphics2D)imgloaded.getGraphics; gtmp.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON); gtmp.setBackground(Color.white); gtmp.clearRect(0,0,imgmx,imgmy); gtmp.setColor(Color.black); gtmp.setFont(new Font("Arial",Font.PLAIN,16)); gtmp.drawString("Image not available",10,30); gtmp.dispose; readdistant_failed=true; }	img2d.drawImage(imgloaded,0,0,this); setCursor(cur); this.showStatus(""); return imgloaded; }

public void init { super.init; requestFocus; addMouseListener(this); addMouseMotionListener(this); addMouseWheelListener(this); addKeyListener(this); appmx = this.getWidth; // size of the Applet appmy = this.getHeight; imgmx = this.getParameter("imgmx") == null ? appmx-200 : (new Integer(this.getParameter("imgmx"))).intValue; imgmy = this.getParameter("imgmy") == null ? appmy-20 : (new Integer(this.getParameter("imgmy"))).intValue; if (imgmy < appmy-20) small = 1; title = this.getParameter("Title"); baseurl = this.getParameter("URL"); int loaded=1; img = new BufferedImage(imgmx,imgmy,BufferedImage.TYPE_INT_RGB); img2d = (Graphics2D)img.getGraphics; img2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); imgundo = new BufferedImage(imgmx,imgmy,BufferedImage.TYPE_INT_RGB); imgundo2d = (Graphics2D)imgundo.getGraphics; db = createImage(appmx,appmy); db2d = (Graphics2D)db.getGraphics; readdistant(baseurl+"/paintings/"+title+".png"); if (readdistant_failed) { img2d.setBackground(Color.white); img2d.clearRect(0,0,imgmx,imgmy); } db2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON); db2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); setLayout(null); b_edit = new JButton("Edit"); b_edit.setBounds(appmx-350,2,75,16); add(b_edit); b_edit.setFocusable(false); b_edit.addActionListener(this); b_hist = new JButton("History"); b_hist.setBounds(appmx-275,2,75,16); add(b_hist); b_hist.setFocusable(false); b_hist.addActionListener(this); b_save = new JButton("Save to wiki"); b_save.setBounds(appmx-180,350,160,16); b_save.setVisible(false); add(b_save); b_save.setFocusable(false); b_save.addActionListener(this); b_undo = new JButton("Undo"); b_undo.setBounds(appmx-90,280,70,16); b_undo.setVisible(false); add(b_undo); b_undo.setFocusable(false); b_undo.addActionListener(this); b_lhis = new JButton("Load history"); b_lhis.setBounds(appmx-180,300,160,16); b_lhis.setVisible(false); add(b_lhis); b_lhis.setFocusable(false); b_lhis.addActionListener(this); b_line = new JCheckBox("Draw lines"); b_line.setBounds(appmx-180,260,160,16); b_line.setVisible(false); b_line.setContentAreaFilled(false); add(b_line); b_line.setFocusable(false); b_line.addActionListener(this); b_comm = new JTextField(""); b_comm.setVisible(false); b_comm.setBounds(appmx-152,310,150,18); b_comm.setToolTipText("Edit summary"); add(b_comm); b_titl = new JTextField(title); b_titl.setBounds(appmx-152,330,150,18); b_titl.setFont(new Font("Arial",Font.PLAIN,15)); b_titl.setToolTipText("Title (modify to save as another name)"); b_titl.setVisible(false); add(b_titl); b_titl.getDocument.addDocumentListener(this); b_rad = new JScrollBar(JScrollBar.HORIZONTAL,3,0,1,100); b_rad.setBounds(appmx-195,22,95,16); b_rad.setVisible(false); b_rad.setMaximum(100); add(b_rad); b_rad.setFocusable(false); b_alp = new JScrollBar(JScrollBar.HORIZONTAL,70,0,1,100); b_alp.setBounds(appmx-195,42,95,16); b_alp.setVisible(false); add(b_alp); b_alp.setFocusable(false); b_red = new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255); b_red.setBounds(appmx-195,72,95,16); b_red.setVisible(false); add(b_red); b_red.setFocusable(false); b_grn = new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255); b_grn.setBounds(appmx-195,92,95,16); b_grn.setVisible(false); add(b_grn); b_grn.setFocusable(false); b_blue = new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255); b_blue.setBounds(appmx-195,112,95,16); b_blue.setVisible(false); add(b_blue); b_blue.setFocusable(false); b_hue = new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255); b_hue.setBounds(appmx-195,142,95,16); b_hue.setVisible(false); add(b_hue); b_hue.setFocusable(false); b_sat = new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255); b_sat.setBounds(appmx-195,162,95,16); b_sat.setVisible(false); add(b_sat); b_sat.setFocusable(false); b_lum = new JScrollBar(JScrollBar.HORIZONTAL,0,0,0,255); b_lum.setBounds(appmx-195,182,95,16); b_lum.setVisible(false); add(b_lum); b_lum.setFocusable(false); b_zoom = new JScrollBar(JScrollBar.HORIZONTAL,0,1,0,5); b_zoom.setBounds(appmx-195,212,95,16); b_zoom.setVisible(false); add(b_zoom); b_zoom.setFocusable(false); b_dx = new JScrollBar(JScrollBar.HORIZONTAL,0,1,0,4); b_dx.setBounds(0,appmy-20,appmx-220,20); b_dx.setVisible(false); add(b_dx); b_dx.setFocusable(false); b_dy = new JScrollBar(JScrollBar.VERTICAL,0,1,0,4); b_dy.setBounds(appmx-220,20,20,appmy-40); b_dy.setVisible(false); add(b_dy); b_dy.setFocusable(false); b_rev = new JScrollBar(JScrollBar.HORIZONTAL); b_rev.setBounds(appmx-195,82,185,16); b_rev.setVisible(false); add(b_rev); b_rev.setFocusable(false);

AdjustmentListener listener = new AdjustmentListener { public void adjustmentValueChanged(AdjustmentEvent e) { JScrollBar scrollbar = (JScrollBar)e.getSource; updateFrom(scrollbar); } };

b_rad.addAdjustmentListener(listener); b_zoom.addAdjustmentListener(listener); b_red.addAdjustmentListener(listener); b_grn.addAdjustmentListener(listener); b_blue.addAdjustmentListener(listener); b_hue.addAdjustmentListener(listener); b_sat.addAdjustmentListener(listener); b_lum.addAdjustmentListener(listener); b_dx.addAdjustmentListener(listener); b_dy.addAdjustmentListener(listener); b_rev.addAdjustmentListener(listener); t = new java.util.Timer; t.schedule(new Clock, 0, 1*1000); }

class Clock extends TimerTask { public void run { if (mode==1) edition_clock++; }   }

public void changedUpdate(DocumentEvent e) { removeUpdate(e); } public void insertUpdate(DocumentEvent e) { removeUpdate(e); }

private boolean alreadyWarnedAboutSavingAs=false;

public void removeUpdate(DocumentEvent e) { boolean newtitle = title.compareTo(b_titl.getText) != 0; b_titl.setBackground(new Color(!newtitle ? 0xFFFFFF:0xFFA0A0)); this.showStatus("Original title was \""+title+"\". "+(newtitle?"WARNING : You are saving as another name.":"")); if (!alreadyWarnedAboutSavingAs) {		MsgBox message = new MsgBox(new Frame("") ,"Wikipainting - WARNING","If you modify the title of the painting, make sure the wiki has a reference to the new title (you can add the reference later). See FAQ for more details", false); alreadyWarnedAboutSavingAs = true; } }

private String readProperty(String prop) { try { return System.getProperty(prop); } catch(Exception e) { return "N/A"; } }

public void actionPerformed(ActionEvent e) { painting=0; if (e.getSource == b_edit) { mode = 1-mode; b_edit.setText(mode==0?"Edit":"Stop"); b_hist.setVisible(mode==0); setCursor(mode==0?new Cursor(Cursor.DEFAULT_CURSOR):new Cursor(Cursor.CROSSHAIR_CURSOR)); b_rad.setVisible(mode==1); b_alp.setVisible(mode==1); b_red.setVisible(mode==1); b_grn.setVisible(mode==1); b_blue.setVisible(mode==1); b_hue.setVisible(mode==1); b_sat.setVisible(mode==1); b_lum.setVisible(mode==1); b_line.setVisible(mode==1); b_undo.setVisible(false); b_save.setVisible(false); b_comm.setVisible(false); b_titl.setVisible(false); b_zoom.setVisible(mode==1); b_zoom.setValue(0); } if (e.getSource == b_hist) { mode = 2-mode; b_hist.setText(mode==0?"History":"Stop"); b_edit.setVisible(mode==0); b_lhis.setVisible(false); b_rev.setVisible(false); if (mode==2) {		try {        	URL url = new URL(baseurl+"/paintings/"+title+".txt"); String contribs = new String(""),dates = new String(""),comms = new String(""); BufferedReader rd = new BufferedReader(new InputStreamReader(url.openStream)); String line; rev_max=-1; while ((line = rd.readLine) != null) // read a line of the history text { 			rev_max++; System.out.println(line); String[] tab = line.split("\t"); contribs = contribs + tab[1]+"\t"; dates = dates + tab[4]+"\t"; if (tab.length>=8) comms = comms + tab[7]; comms = comms + " \t"; }       	rd.close; rev_contrib = contribs.split("\t"); rev_date = dates.split("\t"); rev_comm = comms.split("\t"); imghist = new BufferedImage[rev_max+1]; for (int i=0;i0) { b_rev.setVisible(true); b_rev.setValues(rev_max,1,0,rev_max+1); b_lhis.setVisible(true); } if (rev_max>=0) { updateFrom_ignore = 0; updateFrom(b_rev); } } catch (Exception er) {rev_i=-1; rev_max=-1; System.out.println("Failed : "+er.toString); } }		}	if (e.getSource == b_save) { setCursor(new Cursor(Cursor.WAIT_CURSOR)); try{ ByteArrayOutputStream out = new ByteArrayOutputStream; ImageIO.write(img, "jpg", (OutputStream)out); String bitmap = out.toString("ISO-8859-1"); String bitmaputf = URLEncoder.encode(bitmap,"ISO-8859-1"); // was previously UTF8 System.out.println("Encoding image : "+bitmap.length+" -> "+(bitmaputf.getBytes).length+" bytes"); String env = readProperty("java.vm.vendor")+" Java "+ readProperty("java.vm.version")+" under "+ readProperty("os.name")+" "+ readProperty("os.version")+" on "+ readProperty("os.arch");

// Construct data for POST method on a PHP distant script String data = URLEncoder.encode("title", "UTF-8") + "=" + URLEncoder.encode(b_titl.getText, "UTF-8"); data += "&" + URLEncoder.encode("user", "UTF-8") + "=" + URLEncoder.encode(this.getParameter("User"),"UTF-8"); data += "&" + URLEncoder.encode("time", "UTF-8") + "=" + URLEncoder.encode((new Integer(edition_clock)).toString,"UTF-8"); data += "&" + URLEncoder.encode("pagetitle", "UTF-8") + "=" + URLEncoder.encode(this.getParameter("PageTitle"),"UTF-8"); data += "&" + URLEncoder.encode("comment", "UTF-8") + "=" + URLEncoder.encode(b_comm.getText,"UTF-8"); data += "&" + URLEncoder.encode("originsize", "UTF-8") + "=" + URLEncoder.encode(new Integer(bitmap.length).toString,"UTF-8"); data += "&" + URLEncoder.encode("env", "UTF-8") + "=" + URLEncoder.encode(env,"UTF-8"); data += "&" + URLEncoder.encode("bitmap", "UTF-8") + "=" + bitmaputf; URL url = new URL(baseurl+"/savepainting.php"); URLConnection conn = url.openConnection; conn.setDoOutput(true); conn.setDoInput(true); conn.setUseCaches(false); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream); wr.write(data); wr.flush; wr.close; // Get the response BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream)); String line,lastline=null; while ((line = rd.readLine) != null) { this.showStatus(line); System.out.println(line); lastline=line; } rd.close; edition_clock=0; b_save.setVisible(false); b_comm.setVisible(false); MsgBox message = new MsgBox(new Frame("") ,"Server response",lastline, false); } catch (Exception er) { System.out.println("Exception : "+er); MsgBox message = new MsgBox(new Frame(""), "Exception",er.toString, false); } setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); }	if (e.getSource == b_undo) {		img2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1)); img2d.drawImage(imgundo,0,0,this); }	if (e.getSource == b_lhis) {		for (int i=0;i<rev_max;i++) if (imghist[i] == null) imghist[i] = readdistant(baseurl+"/paintings/"+title+"-"+i+".png"); updateFrom(b_rev); }	if (e.getSource == b_line) omiceix = -1; repaint; }

public void keyPressed(KeyEvent e) { }

public void keyReleased(KeyEvent e) { }

public void keyTyped(KeyEvent e) { char c = e.getKeyChar; //System.out.println(e); if (c == 'P' || c == 'p') { b_lum.setValue(0); b_rad.setValue(1); b_alp.setValue(100); updateFrom(b_lum); } if (c == 'B' || c == 'b') { b_rad.setValue(10); b_alp.setValue(4); } if (c == '-') { b_rad.setValue(Math.max(b_rad.getValue-1,1)); } if (c == '+') { b_rad.setValue(Math.min(b_rad.getValue+1,100)); } }

private float Hue_2_RGB(float v1,float v2,float H )            //Function Hue_2_RGB {  float vH = H;   while ( vH < 0 ) vH ++; while ( vH > 1 ) vH --; if ( 6 * vH < 1 ) return v1 + ( v2 - v1 ) * 6 * vH; if ( 2 * vH < 1 ) return v2; if ( 3 * vH < 2 ) return v1 + ( v2 - v1 ) * ( ( 2 / 3.f ) - vH ) * 6; return v1; }

int updateFrom_ignore=0;

private void updateFrom(JScrollBar sb) {	if (sb == b_zoom) {		int cx,cy;

if (zoom == 1) { cx = imgmx/2; cy = imgmy/2; } else { cx = (int)(b_dx.getValue+(appmx-220)/zoom/2); cy = (int)(b_dy.getValue+(appmy-40)/zoom/2); } if (small==0) zoom = 1< 1) // keep the center {			int depx,depy; depx = (int)(cx-(appmx-220)/zoom/2); depy = (int)(cy-(appmy-40)/zoom/2); depx = (int)Math.min(Math.max(depx,0),imgmx-(appmx-220)/zoom); depy = (int)Math.min(Math.max(depy,0),imgmy-(appmy-40)/zoom); b_dx.setValues(depx,(int)((appmx-220)/zoom),0,imgmx); b_dy.setValues(depy,(int)((appmy-40)/zoom),0,imgmy); }		else {			b_dx.setValue(0); b_dy.setValue(0); }		b_dx.setVisible(b_zoom.getValue!=0); b_dy.setVisible(b_zoom.getValue!=0); repaint; return; }	if (sb == b_rev) {		rev_i = b_rev.getValue; if (imghist[rev_i] == null) imghist[rev_i] = readdistant(baseurl+"/paintings/"+title+"-"+rev_i+".png"); else img2d.drawImage(imghist[rev_i],0,0,this); repaint; return; }	if (updateFrom_ignore>0) { updateFrom_ignore--; return; }

if (sb == b_red || sb == b_grn || sb == b_blue) { float H=0,S=0; float var_R = b_red.getValue / 255.0f; float var_G = b_grn.getValue / 255.0f; float var_B = b_blue.getValue / 255.0f;

float var_Min = Math.min(Math.min( var_R, var_G), var_B );   //Min. value of RGB float var_Max = Math.max(Math.max( var_R, var_G), var_B );   //Max. value of RGB float del_Max = var_Max - var_Min;            //Delta RGB value

float L = ( var_Max + var_Min ) / 2;

if ( del_Max != 0 )                    //Chroma {	  		if ( L < 0.5 ) S = del_Max / ( var_Max + var_Min ); else          S = del_Max / ( 2 - var_Max - var_Min );

float del_R = ( ( ( var_Max - var_R ) / 6 ) + ( del_Max / 2 ) ) / del_Max; float del_G = ( ( ( var_Max - var_G ) / 6 ) + ( del_Max / 2 ) ) / del_Max; float del_B = ( ( ( var_Max - var_B ) / 6 ) + ( del_Max / 2 ) ) / del_Max;

if     ( var_R == var_Max ) H = del_B - del_G; else if ( var_G == var_Max ) H = ( 1 / 3.f ) + del_R - del_B; else if ( var_B == var_Max ) H = ( 2 / 3.f ) + del_G - del_R; if ( H < 0 ) H += 1; if ( H > 1 ) H -= 1; }		updateFrom_ignore=3; b_hue.setValue((int)(H*255)); b_sat.setValue((int)(S*255)); b_lum.setValue((int)(L*255)); }	if (sb == b_hue || sb == b_sat || sb == b_lum) { float R,G,B,H=b_hue.getValue/255.0f, S=b_sat.getValue/255.0f, L=b_lum.getValue/255.0f,var_2; if (S == 0) R = G = B = L * 255; else {	  		if ( L < 0.5 ) var_2 = L * ( 1 + S ); else          var_2 = ( L + S ) - ( S * L );

float var_1 = 2 * L - var_2; R = 255 * Hue_2_RGB( var_1, var_2, H + ( 1 / 3.f ) ); G = 255 * Hue_2_RGB( var_1, var_2, H ); B = 255 * Hue_2_RGB( var_1, var_2, H - ( 1 / 3.f ) ); }		updateFrom_ignore=3; b_red.setValue((int)R); b_grn.setValue((int)G); b_blue.setValue((int)B); }	repaint; }

public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mouseReleased(MouseEvent e) { }

public void mouseWheelMoved(MouseWheelEvent e) { if (mode==1) {	int sens = -e.getWheelRotation; int bz = b_zoom.getValue; if (bz > 0 && sens < 0) b_zoom.setValue(bz-1); if (bz < 5 && sens > 0) b_zoom.setValue(bz+1); } }

int omiceix=-1,omiceiy; int miceix,miceiy; boolean miceinside;

public void mouseGetcoords(int micex,int micey) // convert from applets coords to img coords {	miceix = micex-1; miceiy = micey-19; if (zoom>1) { miceix = (int)(miceix/zoom)+b_dx.getValue; miceiy = (int)(miceiy/zoom)+b_dy.getValue; } miceinside = (miceix>=0 && miceix=0 && miceiy=1 && micex <= appmx-19 && micey>=19 && micey <= appmy-1); }

public void mouseMoved(MouseEvent e) { mouseGetcoords(e.getX,e.getY); if (mode == 1) {		if (miceinside) this.showStatus("X: "+miceix+"     Y:"+miceiy); else this.showStatus(" "); if (b_line.isSelected) { painting=1; repaint; } }	if (miceinside && !this.hasFocus) this.requestFocus; }

private void _moveto(int miceix,int miceiy) {	img2d.setColor(new Color(b_red.getValue,b_grn.getValue,b_blue.getValue)); img2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,b_alp.getValue/100.0f)); int rad = b_rad.getValue; if (b_line.isSelected == false) img2d.fillOval(miceix-rad/2,miceiy-rad/2,rad,rad); if (b_save.isVisible == false) {		b_save.setVisible(true); b_undo.setVisible(true); b_comm.setVisible(true); b_titl.setVisible(true); this.invalidate; }	else painting=1; repaint; omiceix=miceix;omiceiy=miceiy; }

private void _lineto(int miceix,int miceiy) {	img2d.setColor(new Color(b_red.getValue,b_grn.getValue,b_blue.getValue)); img2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,b_alp.getValue/100.0f)); int rad = b_rad.getValue; if (b_line.isSelected == false) img2d.fillOval(miceix-rad/2,miceiy-rad/2,rad,rad); img2d.setStroke(new BasicStroke(rad)); img2d.drawLine(miceix,miceiy,omiceix,omiceiy); painting=1; repaint; omiceix=miceix;omiceiy=miceiy; }

public void mouseDragged(MouseEvent e) { if (mode!=1) return; if ((e.getModifiers & InputEvent.BUTTON3_MASK) != 0) return; mouseGetcoords(e.getX,e.getY); if (miceinside) if (b_line.isSelected == false) _lineto(miceix,miceiy); }

public void mousePressed(MouseEvent e) { if (mode!=1) return; mouseGetcoords(e.getX,e.getY); if (miceinside) {		if ((e.getModifiers & InputEvent.BUTTON3_MASK) != 0) // pick color {			int pix = img.getRGB(miceix,miceiy); b_red.setValue((pix >> 16) & 0x000000FF); b_grn.setValue((pix >> 8) & 0x000000FF); b_blue.setValue(pix & 0x000000FF); updateFrom_ignore = 0; updateFrom(b_red); repaint; return; }		imgundo2d.drawImage(img,0,0,this); if (b_line.isSelected == false || omiceix==-1) _moveto(miceix,miceiy); else 	{ _lineto(miceix,miceiy); omiceix = -1; } }	}

public void update(Graphics g)	{ paint(g); }

public void paint(Graphics g) { db2d.setColor(Color.black); if (mode==0 || mode==2) {		db2d.clearRect(0,0,appmx,appmy); super.paint(db2d); db2d.setFont(new Font("Arial",Font.PLAIN,15)); if (mode==2 && rev_max!=-1) db2d.drawString("Revision "+(rev_i+1)+" / "+(rev_max+1),imgmx+30,64); if (mode==2 && rev_max==-1) db2d.drawString("No history",imgmx+30,64); if (mode==2 && rev_max!=-1) db2d.drawString(rev_contrib[rev_i],imgmx+20,124); if (mode==2 && rev_max!=-1) db2d.drawString(rev_date[rev_i],imgmx+20,144); if (mode==2 && rev_max!=-1) db2d.drawString(rev_comm[rev_i],imgmx+20,164); db2d.drawImage(img,1,19,this); db2d.drawRect(0,18,imgmx+1,imgmy+1); db2d.setFont(new Font("Arial",Font.PLAIN,12)); db2d.drawString(appletTitle,2,15); g.drawImage(db,0,0,this); return; }	if (painting!=0) {		painting=0; if (omiceix!=-1 && b_line.isSelected) // draw of the line tool {			if (zoom==1) db2d.drawImage(img,1,19,this); // first, blit the image on db2d else db2d.drawImage(img,1,19,appmx-220,appmy-21,				b_dx.getValue,b_dy.getValue,				b_dx.getValue+(int)((appmx-220)/zoom),				b_dy.getValue+(int)((appmy-40)/zoom),this); db2d.setColor(new Color(b_red.getValue,b_grn.getValue,b_blue.getValue)); // Chosen color db2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,b_alp.getValue/100.0f)); db2d.setStroke(new BasicStroke((int)(b_rad.getValue*zoom))); db2d.drawLine((int)((miceix-b_dx.getValue)*zoom)+1,				  (int)((miceiy-b_dy.getValue)*zoom)+19,				   (int)((omiceix-b_dx.getValue)*zoom)+1,				   (int)((omiceiy-b_dy.getValue)*zoom)+19); if (small==0 || zoom>1) g.drawImage(db,1,19,appmx-199-(zoom>1?21:0),appmy-1-(zoom>1?20:0),				      1,19,appmx-199-(zoom>1?21:0),appmy-1-(zoom>1?20:0),this); else g.drawImage(db,1,19,imgmx+1,imgmy+19,				      1,19,imgmx+1,imgmy+19,this); db2d.setStroke(new BasicStroke(1)); // parameters by default db2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,1)); }		else // just blit the image on g		if (zoom==1) g.drawImage(img,1,19,this); else g.drawImage(img,1,19,appmx-220,appmy-21,			b_dx.getValue,b_dy.getValue,			b_dx.getValue+(int)((appmx-220)/zoom),			b_dy.getValue+(int)((appmy-40)/zoom),this); return; }	db2d.clearRect(0,0,appmx,appmy); db2d.setFont(new Font("Arial",Font.PLAIN,15)); db2d.drawString("Width : "+b_rad.getValue,appmx-90,34); db2d.drawString("Alpha",appmx-90,54); db2d.drawString("Red",appmx-90,84); db2d.drawString("Green",appmx-90,104); db2d.drawString("Blue",appmx-90,124); db2d.drawString("Hue",appmx-90,154); db2d.drawString("Saturation",appmx-90,174); db2d.drawString("Luminesc.",appmx-90,194); db2d.drawString("Zoom x"+zoom,appmx-90,224); db2d.setFont(new Font("Arial",Font.PLAIN,12)); db2d.drawString("Right click to pick a color",appmx-170,243); db2d.drawString(appletTitle,2,15);

if (b_save.isVisible) {		db2d.setFont(new Font("Arial",Font.PLAIN,9)); db2d.drawString("Summary",appmx-195,324); db2d.drawString("Save as",appmx-195,344); }	db2d.setColor(new Color(b_red.getValue,b_grn.getValue,b_blue.getValue)); // Chosen color db2d.fillRect(appmx-180,280,60,16); db2d.setColor(Color.black); db2d.drawRect(appmx-180,280,60,16);

super.paint(db2d); // swing paint if (small==0 || zoom == 1) db2d.drawRect(0,18,imgmx+1,imgmy+1); // border of the image else db2d.drawRect(0,18,appmx-199,appmy-19);

if (zoom==1) db2d.drawImage(img,1,19,this); else db2d.drawImage(img,1,19,appmx-220,appmy-21,		b_dx.getValue,b_dy.getValue,		b_dx.getValue+(int)((appmx-220)/zoom),		b_dy.getValue+(int)((appmy-40)/zoom),this); g.drawImage(db,0,0,this); }

}