Skip to content

Commit

Permalink
misc
Browse files Browse the repository at this point in the history
  • Loading branch information
subhra74 committed Oct 3, 2019
1 parent de8cf5d commit 451804a
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 77 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package snowflake.components.common;

import javax.swing.*;
import java.awt.*;

public class RoundedButtonPainter {
private Painter<JButton> normalPainter, hotPainter, pressedPainter;
private GradientPaint normalGradient, hotGradient, pressedGradient;
private Color borderColor;

public RoundedButtonPainter() {
this.normalGradient = new GradientPaint(0, 0,
new Color(245, 245, 245),
0, 50,
new Color(235, 235, 235));
this.hotGradient = new GradientPaint(0, 0,
new Color(255, 255, 255),
0, 50,
new Color(230, 230, 230));
this.pressedGradient = new GradientPaint(0, 0,
new Color(230, 230, 230),
0, 50,
new Color(180, 180, 180));
this.borderColor = new Color(230, 230, 230);

normalPainter = (Graphics2D g, JButton object, int width, int height) -> {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setPaint(normalGradient);
g.fillRoundRect(1, 1, width - 2, height - 2, 7, 7);
g.setColor(borderColor);
g.drawRoundRect(1, 1, width - 2, height - 2, 7, 7);
};

hotPainter = (Graphics2D g, JButton object, int width, int height) -> {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setPaint(hotGradient);
g.fillRoundRect(1, 1, width - 2, height - 2, 7, 7);
g.setColor(borderColor);
g.drawRoundRect(1, 1, width - 2, height - 2, 7, 7);
};

pressedPainter = (Graphics2D g, JButton object, int width, int height) -> {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setPaint(pressedGradient);
g.fillRoundRect(1, 1, width - 2, height - 2, 7, 7);
g.setColor(borderColor);
g.drawRoundRect(1, 1, width - 2, height - 2, 7, 7);
};
}

public Painter<JButton> getNormalPainter() {
return normalPainter;
}

public Painter<JButton> getHotPainter() {
return hotPainter;
}

public Painter<JButton> getPressedPainter() {
return pressedPainter;
}
}
81 changes: 78 additions & 3 deletions src/main/java/snowflake/components/files/FileComponentHolder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package snowflake.components.files;

import snowflake.App;
import snowflake.common.FileInfo;
import snowflake.common.FileSystem;
import snowflake.common.local.files.LocalFileSystem;
Expand All @@ -23,10 +24,10 @@
import snowflake.utils.PlatformAppLauncher;

import javax.swing.*;
import javax.swing.Timer;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -197,6 +198,7 @@ private void processQueue() {

public void disableUi() {
SwingUtilities.invokeLater(() -> {
this.disabledPanel.startAnimation();
this.disabledPanel.btn.setVisible(false);
this.rootPane.setGlassPane(this.disabledPanel);
this.disabledPanel.setVisible(true);
Expand All @@ -205,6 +207,7 @@ public void disableUi() {

public void disableUi(AtomicBoolean stopFlag) {
SwingUtilities.invokeLater(() -> {
this.disabledPanel.startAnimation();
this.disabledPanel.stopFlag = stopFlag;
this.disabledPanel.btn.setVisible(true);
this.rootPane.setGlassPane(this.disabledPanel);
Expand All @@ -214,6 +217,7 @@ public void disableUi(AtomicBoolean stopFlag) {

public void enableUi() {
SwingUtilities.invokeLater(() -> {
this.disabledPanel.stopAnimation();
this.disabledPanel.setVisible(false);
});
}
Expand Down Expand Up @@ -381,15 +385,86 @@ public AtomicBoolean isCloseRequested() {
}

class DisabledPanel extends JPanel {
JButton btn = new JButton("Stop");
double angle = 0.0;
JButton btn = new JButton();
AtomicBoolean stopFlag;
Color c1 = new Color(3, 155, 229);
Stroke basicStroke = new BasicStroke(5);
Timer timer;
AlphaComposite alphaComposite = AlphaComposite.SrcOver.derive(0.65f);
AlphaComposite alphaComposite1 = AlphaComposite.SrcOver.derive(0.85f);

public DisabledPanel() {
setBorder(null);
BoxLayout layout = new BoxLayout(this, BoxLayout.PAGE_AXIS);
setLayout(layout);
btn.setContentAreaFilled(false);
btn.setBorderPainted(false);
btn.setFont(App.getFontAwesomeFont().deriveFont(20.0f));
btn.setForeground(Color.WHITE);
btn.setText("\uf00d");
btn.setAlignmentX(Box.CENTER_ALIGNMENT);
setOpaque(false);
btn.addActionListener(e -> {
if (stopFlag != null) {
stopFlag.set(true);
}
});
add(Box.createVerticalGlue());
add(btn);
add(Box.createVerticalGlue());
timer = new Timer(20, e -> {
angle += Math.toRadians(5); // 5 degrees per 100 ms = 50 degrees/second
while (angle > 2 * Math.PI)
angle -= 2 * Math.PI; // keep angle in reasonable range.
int x = getWidth() / 2 - 70 / 2;
int y = getHeight() / 2 - 70 / 2;
repaint(x, y, 70, 70);
});
addMouseListener(new MouseAdapter() {
});
addMouseMotionListener(new MouseAdapter() {
});
addKeyListener(new KeyAdapter() {
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
requestFocusInWindow();
}
});
setFocusTraversalKeysEnabled(false);
}

public void startAnimation() {
timer.start();
}

public void stopAnimation() {
timer.stop();
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setComposite(alphaComposite);
g2.setColor(Color.BLACK);
Rectangle r = g.getClipBounds();
g2.fillRect(r.x, r.y, r.width, r.height);
g2.setComposite(alphaComposite1);
g2.setStroke(basicStroke);
int x = getWidth() / 2 - 70 / 2;
int y = getHeight() / 2 - 70 / 2;
if (btn.isVisible()) {
g2.setColor(Color.BLACK);
g2.fillOval(x + 5, y + 5, 70 - 10, 70 - 10);
}
g2.setColor(c1);
g2.rotate(angle, getWidth() / 2, getHeight() / 2);
g2.drawArc(x + 5, y + 5, 70 - 10, 70 - 10, 0, 90);
g2.rotate(-angle, getWidth() / 2, getHeight() / 2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public AbstractFileBrowserView(JRootPane rootPane, FileComponentHolder holder, P
}
if (text != null && text.length() > 0) {
addBack(this.path);
render(text);
render(text, App.getGlobalSettings().isDirectoryCache());
}
});
Box smallToolbar = Box.createHorizontalBox();
Expand All @@ -74,7 +74,7 @@ public void actionPerformed(ActionEvent e) {
btnBack.addActionListener(e -> {
String item = history.prevElement();
addNext(this.path);
render(item);
render(item, App.getGlobalSettings().isDirectoryCache());
});


Expand All @@ -86,7 +86,7 @@ public void actionPerformed(ActionEvent e) {
btnNext.addActionListener(e -> {
String item = history.nextElement();
addBack(this.path);
render(item);
render(item, App.getGlobalSettings().isDirectoryCache());
});


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public SshFileBrowserView(FileBrowser fileBrowser,
this.addressPopup = menuHandler.createAddressPopup();
if (initialPath == null) {
this.path = holder.getInfo().getRemoteFolder();
System.out.println("Path: " + path);
} else {
this.path = initialPath;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
package snowflake.components.files.transfer;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseAdapter;

public class TransferProgressPanel extends JPanel {
private JProgressBar prg;
private JButton stop;
private FileTransfer transfer;
private int dragSource;
private AlphaComposite alphaComposite = AlphaComposite.SrcOver.derive(0.65f);
private AlphaComposite alphaComposite1 = AlphaComposite.SrcOver.derive(1.0f);
private Box b12 = Box.createVerticalBox();

public TransferProgressPanel(FileTransfer transfer, int dragSource) {
super();
BoxLayout layout = new BoxLayout(this, BoxLayout.PAGE_AXIS);
setLayout(layout);
setOpaque(false);
Box b1 = Box.createHorizontalBox();
b1.setOpaque(true);
b1.setMaximumSize(new Dimension(300, 50));
b1.setAlignmentX(Box.LEFT_ALIGNMENT);
this.transfer = transfer;
this.dragSource = dragSource;
prg = new JProgressBar();
add(prg);
b1.add(prg);
b1.add(Box.createHorizontalStrut(10));
stop = new JButton("Stop");
stop.addActionListener(e -> {
transfer.stop();
});
add(stop);
b1.add(stop);
add(Box.createVerticalGlue());
JLabel label = new JLabel("Copying files");
label.setAlignmentX(Box.LEFT_ALIGNMENT);
b12.add(label);
b12.add(b1);
b12.setBorder(new EmptyBorder(10, 10, 10, 10));
b12.setAlignmentX(Box.CENTER_ALIGNMENT);
add(b12);
add(Box.createVerticalGlue());
addMouseListener(new MouseAdapter() {
});
addMouseMotionListener(new MouseAdapter() {
});
addKeyListener(new KeyAdapter() {
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentShown(ComponentEvent e) {
requestFocusInWindow();
}
});
setFocusTraversalKeysEnabled(false);
}

public void clear() {
Expand All @@ -36,4 +74,21 @@ public int getSource() {
public void setSource(int source) {
this.dragSource = source;
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.setComposite(alphaComposite);
g2.setColor(Color.BLACK);
g2.fillRect(0, 0, getWidth(), getHeight());
int x = b12.getX();
int y = b12.getY();
int w = b12.getWidth();
int h = b12.getHeight();
g2.setComposite(alphaComposite1);
g2.setColor(Color.WHITE);
g.fillRoundRect(x - 10, y - 10, w + 20, h + 20, 5, 5);
}
}
13 changes: 6 additions & 7 deletions src/main/java/snowflake/components/newsession/NewSessionDlg.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.awt.*;
import java.util.UUID;

import static snowflake.utils.GraphicsUtils.createButton;

public class NewSessionDlg extends JDialog
implements ActionListener, TreeSelectionListener, TreeModelListener {
Expand Down Expand Up @@ -83,29 +82,29 @@ public void windowClosing(WindowEvent e) {
jsp = new JScrollPane(tree);

//btnNewHost = new JButton(TextHolder.getString("session.newHost"));
btnNewHost = createButton("New site");
btnNewHost = new JButton("New site");
btnNewHost.addActionListener(this);
btnNewHost.putClientProperty("button.name", "btnNewHost");
//btnNewHost.setFont(Utility.getFont(Constants.SMALL));
btnNewFolder = createButton("New folder");//new JButton(TextHolder.getString("session.newFolder"));
btnNewFolder = new JButton("New folder");//new JButton(TextHolder.getString("session.newFolder"));
btnNewFolder.addActionListener(this);
btnNewFolder.putClientProperty("button.name", "btnNewFolder");
//btnNewFolder.setFont(Utility.getFont(Constants.SMALL));
btnDel = createButton("Remove");//new JButton(TextHolder.getString("session.remove"));
btnDel = new JButton("Remove");//new JButton(TextHolder.getString("session.remove"));
btnDel.addActionListener(this);
btnDel.putClientProperty("button.name", "btnDel");
//btnDel.setFont(Utility.getFont(Constants.SMALL));
btnDup = createButton("Duplicate");// new JButton(TextHolder.getString("session.duplicate"));
btnDup = new JButton("Duplicate");// new JButton(TextHolder.getString("session.duplicate"));
btnDup.addActionListener(this);
btnDup.putClientProperty("button.name", "btnDup");
//btnDup.setFont(Utility.getFont(Constants.SMALL));

btnConnect = createButton("Connect");// new JButton(TextHolder.getString("session.connect"));
btnConnect = new JButton("Connect");// new JButton(TextHolder.getString("session.connect"));
btnConnect.addActionListener(this);
btnConnect.putClientProperty("button.name", "btnConnect");
//btnConnect.setFont(Utility.getFont(Constants.SMALL));

btnCancel = createButton("Cancel");// new JButton(TextHolder.getString("session.cancel"));
btnCancel = new JButton("Cancel");// new JButton(TextHolder.getString("session.cancel"));
btnCancel.addActionListener(this);
btnCancel.putClientProperty("button.name", "btnCancel");
//btnCancel.setFont(Utility.getFont(Constants.SMALL));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import javax.swing.event.*;
import java.awt.*;

import static snowflake.utils.GraphicsUtils.createButton;

public class SessionInfoPanel extends JPanel {

private static final long serialVersionUID = 6679029920589652547L;
Expand Down Expand Up @@ -235,7 +233,7 @@ private void updateFolder() {
}
});

inpLocalBrowse = createButton("Browse");
inpLocalBrowse = new JButton("Browse");
inpLocalBrowse.addActionListener(e -> {
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
Expand Down Expand Up @@ -267,7 +265,7 @@ private void updateKeyFile() {
}
});

inpKeyBrowse = GraphicsUtils.createButton("Browse");// new JButton(TextHolder.getString("host.browse"));
inpKeyBrowse = new JButton("Browse");// new JButton(TextHolder.getString("host.browse"));
inpKeyBrowse.addActionListener(e -> {
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.FILES_ONLY);
Expand Down
Loading

0 comments on commit 451804a

Please sign in to comment.