Skip to content

Commit

Permalink
Merge pull request #7171 from neilcsmith-net/editor-bg-actions
Browse files Browse the repository at this point in the history
Add common actions with shortcuts to editor background
  • Loading branch information
neilcsmith-net authored Mar 26, 2024
2 parents ab9751f + 44f5f7f commit 39e4b5f
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@
# {1} project name
CTL_MainWindow_Title={1} - Apache NetBeans IDE @@metabuild.ComputedTitleVersion@@
CTL_MainWindow_Title_No_Project=Apache NetBeans IDE @@metabuild.ComputedTitleVersion@@

LBL_NoShortcut=-
1 change: 1 addition & 0 deletions nb/ide.branding/licenseinfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<file>release/netbeans.icns</file>
<file>release/shortcuts.pdf</file>
<file>release/shortcuts_mac.pdf</file>
<file>src/org/netbeans/modules/ide/branding/apache-netbeans.png</file>
<license ref="Apache-2.0-ASF" />
<comment type="COMMENT_UNSUPPORTED" />
</fileset>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions nb/ide.branding/src/org/netbeans/modules/ide/branding/layer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,37 @@
<folder name="Editors">
<attr name="currentFontColorProfile" stringvalue="FlatLaf Light" />
</folder>

<folder name="Windows2">
<folder name="Background">
<attr name="backgroundImage" stringvalue="org/netbeans/modules/ide/branding/apache-netbeans.png" />
<folder name="Actions">
<file name="org-netbeans-modules-project-ui-NewProject.shadow">
<attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-NewProject.instance"/>
<attr name="position" intvalue="100"/>
</file>
<file name="org-netbeans-modules-project-ui-OpenProject.shadow">
<attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-OpenProject.instance"/>
<attr name="position" intvalue="200"/>
</file>
<file name="org-netbeans-modules-project-ui-NewFile.shadow">
<attr name="originalFile" stringvalue="Actions/Project/org-netbeans-modules-project-ui-NewFile.instance"/>
<attr name="position" intvalue="300"/>
</file>
<file name="org-netbeans-modules-openfile-OpenFileAction.shadow">
<attr name="originalFile" stringvalue="Actions/System/org-netbeans-modules-openfile-OpenFileAction.instance"/>
<attr name="position" intvalue="400"/>
</file>
<file name="org-netbeans-modules-jumpto-file-FileSearchAction.shadow">
<attr name="originalFile" stringvalue="Actions/Tools/org-netbeans-modules-jumpto-file-FileSearchAction.instance"/>
<attr name="position" intvalue="500"/>
</file>
<file name="org-netbeans-modules-welcome-ShowWelcomeAction.shadow">
<attr name="originalFile" stringvalue="Actions/Help/org-netbeans-modules-welcome-ShowWelcomeAction.instance"/>
<attr name="position" intvalue="600"/>
</file>
</folder>
</folder>
</folder>

</filesystem>
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void setShowOnStartup( boolean show ) {
}

public boolean isShowOnStartup() {
return prefs().getBoolean(PROP_SHOW_ON_STARTUP, !Boolean.getBoolean("netbeans.full.hack"));
return prefs().getBoolean(PROP_SHOW_ON_STARTUP, false);
}

public void setLastActiveTab( int tabIndex ) {
Expand Down
190 changes: 165 additions & 25 deletions platform/core.windows/src/org/netbeans/core/windows/view/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,14 @@
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.border.TitledBorder;
import org.netbeans.core.windows.*;
import org.netbeans.core.windows.view.dnd.*;
import org.netbeans.core.windows.view.ui.MainWindow;
import org.openide.awt.Actions;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.util.*;
import org.openide.windows.*;

Expand Down Expand Up @@ -174,6 +180,7 @@ private static class EditorAreaComponent extends JPanel
implements TopComponentDroppable {

private final EditorView editorView;
private final JComponent backgroundComponent;

// XXX PENDING
private final WindowDnDManager windowDnDManager;
Expand All @@ -184,6 +191,7 @@ private static class EditorAreaComponent extends JPanel
public EditorAreaComponent(EditorView editorView, WindowDnDManager windowDnDManager) {
this.editorView = editorView;
this.windowDnDManager = windowDnDManager;
this.backgroundComponent = initBackgroundComponent();

init();
}
Expand All @@ -197,20 +205,6 @@ private void init() {
// setBackground((Color)UIManager.get("nb_workplace_fill"));
// }

// PENDING Adding image into empty area.
String imageSource = Constants.SWITCH_IMAGE_SOURCE; // NOI18N
if(imageSource != null) {
Image image = ImageUtilities.loadImage(imageSource);
if(image != null) {
JLabel label = new JLabel(ImageUtilities.image2Icon(image));
label.setMinimumSize(new Dimension(0, 0)); // XXX To be able shrink the area.
add(label, BorderLayout.CENTER);
} else {
Logger.getLogger(EditorView.class.getName()).log(Level.WARNING, null,
new java.lang.NullPointerException("Image not found at " +
imageSource)); // NOI18N
}
}
//listen to files being dragged over the editor area
DropTarget dropTarget = new DropTarget( this, new DropTargetListener() {
@Override
Expand Down Expand Up @@ -257,6 +251,64 @@ public void dropActionChanged(DropTargetDragEvent dtde) {
setOpaque( false);
}

private JComponent initBackgroundComponent() {
JComponent imageComponent = null;
String imageSource = Constants.SWITCH_IMAGE_SOURCE; // NOI18N
if (imageSource == null) {
FileObject config = FileUtil.getConfigFile("Windows2/Background");
if (config != null) {
Object attr = config.getAttribute("backgroundImage");
if (attr instanceof String) {
imageSource = (String) attr;
}
}
}
if (imageSource != null) {
Image image = ImageUtilities.loadImage(imageSource);
if (image != null) {
JLabel label = new JLabel(ImageUtilities.image2Icon(image));
label.setMinimumSize(new Dimension(0, 0)); // XXX To be able shrink the area.
imageComponent = label;
} else {
Logger.getLogger(EditorView.class.getName()).log(Level.WARNING, null,
new NullPointerException("Image not found at "
+ imageSource)); // NOI18N
}
}
JComponent actionsComponent = initBackgroundActions();
if (actionsComponent != null) {
JPanel panel = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.ipadx = 50;
if (imageComponent != null) {
panel.add(imageComponent, gbc);
}
panel.add(actionsComponent, gbc);
return panel;
} else {
return imageComponent;
}
}

private JComponent initBackgroundActions() {
java.util.List<? extends Action> actions
= Utilities.actionsForPath("Windows2/Background/Actions");
if (actions.isEmpty()) {
return null;
}

JComponent panel = new JPanel(new GridLayout(0,1));
for (Action action : actions) {
if (action == null) {
// ignore separators?
continue;
}
BackgroundActionButton button = new BackgroundActionButton(action);
panel.add(button);
}
return panel;
}

@Override
public void updateUI() {
super.updateUI();
Expand All @@ -270,24 +322,33 @@ public void updateUI() {
}

public void setAreaComponent(Component areaComponent) {
if(this.areaComponent == areaComponent) {
if (this.areaComponent == areaComponent) {
// XXX PENDING revise how to better manipulate with components
// so there don't happen unneeded removals.
if(areaComponent != null
&& !Arrays.asList(getComponents()).contains(areaComponent)) {
if (areaComponent != null
&& !Arrays.asList(getComponents()).contains(areaComponent)) {
if (backgroundComponent != null) {
remove(backgroundComponent);
}
add(areaComponent, BorderLayout.CENTER);
}

return;
}
if(this.areaComponent != null) {

if (this.areaComponent != null) {
remove(this.areaComponent);
if (areaComponent == null && backgroundComponent != null) {
add(backgroundComponent, BorderLayout.CENTER);
}
}

this.areaComponent = areaComponent;

if(this.areaComponent != null) {

if (this.areaComponent != null) {
if (backgroundComponent != null) {
remove(backgroundComponent);
}
add(this.areaComponent, BorderLayout.CENTER);
}

Expand Down Expand Up @@ -408,6 +469,85 @@ public int getKind() {

} // End of EditorAreaComponent class.


}
private static class BackgroundActionButton extends JButton {

private final TitledBorder shortcut;

private BackgroundActionButton(Action action) {
super();
setContentAreaFilled(false);
setRolloverEnabled(true);
setHorizontalAlignment(SwingConstants.LEFT);
Color textColor = UIManager.getColor("EditorTab.foreground");
if (textColor != null) {
setForeground(textColor);
}
shortcut = new TitledBorder(new EmptyBorder(2, 20, 2, 40), "",
TitledBorder.LEFT, TitledBorder.ABOVE_BOTTOM);
Color shortcutColor = UIManager.getColor("EditorTab.underlineColor");
if (shortcutColor != null) {
shortcut.setTitleColor(shortcutColor);
}
Font font = getFont();
if (font != null) {
shortcut.setTitleFont(font.deriveFont(0.9f * font.getSize()));
}
setBorder(shortcut);
setAction(action);
}

@Override
protected void actionPropertyChanged(Action action, String propertyName) {
if (Action.NAME.equals(propertyName)) {
configureText(action);
} else if (Action.ACCELERATOR_KEY.equals(propertyName)) {
configureShortcut(action);
}
repaint();
}

@Override
protected void configurePropertiesFromAction(Action a) {
configureText(a);
configureShortcut(a);
setIcon(null);
}

@Override
public void paint(Graphics g) {
if (getModel().isRollover()) {
Color hoverColor = UIManager.getColor("EditorTab.hoverBackground");
if (hoverColor != null) {
g.setColor(hoverColor);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
super.paint(g);
}

private void configureShortcut(Action action) {
KeyStroke ks = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
if (ks != null) {
String shortcutText = Actions.keyStrokeToString(ks);
shortcut.setTitle(shortcutText);
} else {
// use bundle from core.windows.view.ui for future development
String noShortcut = NbBundle.getMessage(MainWindow.class, "LBL_NoShortcut");
if (noShortcut.isEmpty()) {
noShortcut = " ";
}
shortcut.setTitle(noShortcut);
}
}

private void configureText(Action action) {
String raw = (String) action.getValue(Action.NAME);
if (raw == null) {
raw = "";
}
setText(Actions.cutAmpersand(raw));
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
# EditorAreaFrame
LBL_EditorAreaFrameTitle=Editor

# Editor view background
LBL_NoShortcut=

# MainWindow
ACSD_MainWindow=Main Window
# {0} build number
Expand Down

0 comments on commit 39e4b5f

Please sign in to comment.