~ubuntu-branches/ubuntu/precise/arduino/precise

« back to all changes in this revision

Viewing changes to src/processing/app/tools/format/src/AutoFormat.java

  • Committer: Bazaar Package Importer
  • Author(s): Scott Howard
  • Date: 2010-04-13 22:32:24 UTC
  • Revision ID: james.westby@ubuntu.com-20100413223224-jduxnd0xxnkkda02
Tags: upstream-0018+dfsg
ImportĀ upstreamĀ versionĀ 0018+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
 
2
 
 
3
/*
 
4
  Part of the Processing project - http://processing.org
 
5
 
 
6
  Copyright (c) 2006 Ben Fry and Casey Reas
 
7
 
 
8
  This program is free software; you can redistribute it and/or modify
 
9
  it under the terms of the GNU General Public License as published by
 
10
  the Free Software Foundation; either version 2 of the License, or
 
11
  (at your option) any later version.
 
12
 
 
13
  This program is distributed in the hope that it will be useful,
 
14
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
  GNU General Public License for more details.
 
17
 
 
18
  You should have received a copy of the GNU General Public License
 
19
  along with this program; if not, write to the Free Software Foundation,
 
20
  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
*/
 
22
 
 
23
package processing.app.tools;
 
24
 
 
25
import processing.app.*;
 
26
import processing.core.*;
 
27
 
 
28
import java.io.*;
 
29
 
 
30
 
 
31
/**
 
32
 * Tool for auto-formatting code that interfaces to
 
33
 * <A HREF="http://jalopy.sourceforge.net/">Jalopy</A>. This is to replace
 
34
 * the buggy code formatter found in previous releases.
 
35
 */
 
36
public class AutoFormat {
 
37
  Editor editor;
 
38
 
 
39
 
 
40
  public AutoFormat(Editor editor) {
 
41
    this.editor = editor;
 
42
  }
 
43
 
 
44
 
 
45
  public void show() {
 
46
    String originalText = editor.textarea.getText();
 
47
    int indentSize = Preferences.getInteger("editor.tabs.size");
 
48
 
 
49
    //
 
50
 
 
51
    String formattedText = null; //strOut.toString();
 
52
    if (formattedText.equals(originalText)) {
 
53
      editor.message("No changes necessary for Auto Format.");
 
54
 
 
55
    } else {
 
56
      // replace with new bootiful text
 
57
      // selectionEnd hopefully at least in the neighborhood
 
58
      editor.setText(formattedText, selectionEnd, selectionEnd);
 
59
      editor.sketch.setModified(true);
 
60
 
 
61
      /*
 
62
      // warn user if there are too many parens in either direction
 
63
      if (paren != 0) {
 
64
        editor.error("Warning: Too many " +
 
65
                     ((paren < 0) ? "right" : "left") +
 
66
                     " parentheses.");
 
67
 
 
68
      } else if (c_level != 0) {  // check braces only if parens are ok
 
69
        editor.error("Warning: Too many " +
 
70
                     ((c_level < 0) ? "right" : "left") +
 
71
                     " curly braces.");
 
72
      } else {
 
73
        editor.message("Auto Format finished.");
 
74
      }
 
75
      */
 
76
    }
 
77
  }
 
78
 
 
79
 
 
80
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
 
81
 
 
82
 
 
83
  private static class PluginImpl extends AbstractPlugin {
 
84
    JEditStatusBar statusBar;
 
85
    Project project;
 
86
 
 
87
 
 
88
    /**
 
89
     * Creates a new PluginImpl object.
 
90
     */
 
91
    public PluginImpl()
 
92
    {
 
93
      super(new JEditAppender());
 
94
    }
 
95
 
 
96
 
 
97
    public Project getActiveProject()
 
98
    {
 
99
      if (this.project == null)
 
100
        {
 
101
          this.project = new JEditProject();
 
102
        }
 
103
 
 
104
      return this.project;
 
105
    }
 
106
 
 
107
 
 
108
    public FileFormat getFileFormat()
 
109
    {
 
110
      // there is a bug(?) in jEdit's text area whereas inserting text with
 
111
      // DOS file format results in displaying EOF characters, so we always
 
112
      // use UNIX format and let jEdit handle the specified file format upon
 
113
      // file saving
 
114
      return FileFormat.UNIX;
 
115
    }
 
116
 
 
117
 
 
118
    public Frame getMainWindow()
 
119
    {
 
120
      return jEdit.getActiveView();
 
121
    }
 
122
 
 
123
 
 
124
    public StatusBar getStatusBar()
 
125
    {
 
126
      return this.statusBar;
 
127
    }
 
128
 
 
129
 
 
130
    public void afterEnd()
 
131
    {
 
132
      super.afterEnd();
 
133
      MessageView.getInstance().update();
 
134
    }
 
135
 
 
136
 
 
137
    /**
 
138
     * Formats the currently active buffer.
 
139
     */
 
140
    public void formatActive()
 
141
    {
 
142
      // only perform the action if the current Buffer contains
 
143
      // a Java source file
 
144
      //if (isJava(jEdit.getActiveView().getBuffer()))
 
145
      //{
 
146
      performAction(Action.FORMAT_ACTIVE);
 
147
      //}
 
148
    }
 
149
 
 
150
 
 
151
    /**
 
152
     * Formats the currently open buffers.
 
153
     */
 
154
    public void formatOpen()
 
155
    {
 
156
      performAction(Action.FORMAT_OPEN);
 
157
    }
 
158
  }
 
159
}