2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.openapi
.wm
.impl
.status
;
18 import com
.intellij
.ide
.DataManager
;
19 import com
.intellij
.ide
.util
.GotoLineNumberDialog
;
20 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
21 import com
.intellij
.openapi
.command
.CommandProcessor
;
22 import com
.intellij
.openapi
.editor
.Editor
;
23 import com
.intellij
.openapi
.editor
.LogicalPosition
;
24 import com
.intellij
.openapi
.editor
.SelectionModel
;
25 import com
.intellij
.openapi
.fileEditor
.FileEditorManager
;
26 import com
.intellij
.openapi
.fileEditor
.ex
.IdeDocumentHistory
;
27 import com
.intellij
.openapi
.project
.Project
;
28 import com
.intellij
.openapi
.wm
.StatusBar
;
29 import com
.intellij
.ui
.UIBundle
;
32 import java
.awt
.event
.MouseAdapter
;
33 import java
.awt
.event
.MouseEvent
;
35 class PositionPanel
extends TextPanel
implements StatusBarPatch
{
36 public PositionPanel(StatusBar statusBar
) {
37 super(false, "#############");
39 addMouseListener(new MouseAdapter() {
40 public void mouseClicked(final MouseEvent e
) {
41 if (e
.getClickCount() == 2) {
42 final Project project
= getProject();
43 if (project
== null) return;
44 final Editor editor
= getEditor(project
);
45 if (editor
== null) return;
46 final CommandProcessor processor
= CommandProcessor
.getInstance();
47 processor
.executeCommand(
48 project
, new Runnable(){
50 final GotoLineNumberDialog dialog
= new GotoLineNumberDialog(project
, editor
);
52 IdeDocumentHistory
.getInstance(project
).includeCurrentCommandAsNavigation();
55 UIBundle
.message("go.to.line.command.name"),
62 StatusBarTooltipper
.install(this, statusBar
);
65 public JComponent
getComponent() {
69 public String
updateStatusBar(final Editor editor
, final JComponent componentSelected
) {
71 SwingUtilities
.invokeLater(new Runnable() {
73 if (!editor
.isDisposed()) {
74 StringBuilder message
= new StringBuilder();
76 SelectionModel selectionModel
= editor
.getSelectionModel();
77 if (selectionModel
.hasBlockSelection()) {
78 LogicalPosition start
= selectionModel
.getBlockStart();
79 LogicalPosition end
= selectionModel
.getBlockEnd();
80 appendLogicalPosition(start
, message
);
82 appendLogicalPosition(new LogicalPosition(Math
.abs(end
.line
- start
.line
), Math
.abs(end
.column
- start
.column
) - 1), message
);
85 LogicalPosition caret
= editor
.getCaretModel().getLogicalPosition();
87 appendLogicalPosition(caret
, message
);
88 if (selectionModel
.hasSelection()) {
89 int len
= Math
.abs(selectionModel
.getSelectionStart() - selectionModel
.getSelectionEnd());
95 setText(message
.toString());
99 return UIBundle
.message("go.to.line.command.double.click");
105 private static void appendLogicalPosition(LogicalPosition caret
, StringBuilder message
) {
106 message
.append(caret
.line
+ 1);
108 message
.append(caret
.column
+ 1);
111 public void clear() {
115 private static Editor
getEditor(final Project project
) {
116 return FileEditorManager
.getInstance(project
).getSelectedTextEditor();
119 private Project
getProject() {
120 return PlatformDataKeys
.PROJECT
.getData(DataManager
.getInstance().getDataContext(this));